Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrimeNumberGenerator pg=new PrimeNumberGenerator(); while(true){ int n=Integer.parseInt(br.readLine()); if(n==0){ break ; } if(pg.isPrime(n)){ System.out.println(0); continue ; } int begin=-1 ; int end=-1 ; for(int i=n-1 ; i>=0 ; i--){ if(pg.isPrime(i)){ begin=i ; break ; } } for(int i=n+1 ; i<2000000 ; i++){ if(pg.isPrime(i)){ end=i ; break ; } } System.out.println(end-begin); } } } class PrimeNumberGenerator { private final int N=2000000 ; private boolean[] isPrime=new boolean[N+1]; public PrimeNumberGenerator(){ Arrays.fill(isPrime,true); isPrime[0]=false ; isPrime[1]=false ; int limit=(int)Math.sqrt(N); for(int i=2 ; i<=limit ; i++){ if(isPrime[i]==false){ continue ; } for(int j=i*2 ; j<=N ; j+=i){ isPrime[j]=false ; } } } public boolean isPrime(int index){ return isPrime[index]; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pg : PrimeNumberGenerator ; pg := PrimeNumberGenerator.newPrimeNumberGenerator() ; while (true) do ( var n : int ; n := (br.readLine())->toInteger() ; if (n = 0) then ( break ) else skip ; if (pg.isPrime(n)) then ( OclFile["System.out"].println(0) ; continue ) else skip ; var begin : int ; begin := -1 ; var end : int ; end := -1 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (pg.isPrime(i)) then ( begin := i ; break ) else skip ) ; i := i - 1 ) ; var i : int ; i := n + 1 ; while i < 2000000 do ( ( if (pg.isPrime(i)) then ( end := i ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(end - begin) ; ) ); } class PrimeNumberGenerator { attribute N : int := 2000000; attribute isPrime : Sequence(boolean) := Integer.subrange(1,N + 1)->collect(false); static operation newPrimeNumberGenerator() : PrimeNumberGenerator pre: true post: true activity: ( var self : PrimeNumberGenerator ; self := createPrimeNumberGenerator(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( isPrime := isPrime->collect(true) ; isPrime[0+1] := false ; isPrime[1+1] := false ; var limit : int ; limit := (N)->sqrt()->oclAsType(int) ; var i : int ; i := 2 ; while i <= limit do ( ( if (isPrime[i+1] = false) then ( continue ) else skip ; var j : int ; j := i * 2 ; while j <= N do ( ( isPrime[j+1] := false ) ; j := j+(i) ) ) ; i := i + 1 ) ; ); operation isPrime( index : int) : boolean pre: true post: true activity: ( return isPrime[index+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long start=sc.nextLong(); long ratio=sc.nextLong(); long max=sc.nextLong(); int m=sc.nextInt(); ArrayListbad=new ArrayList(); for(int i=0 ; imax){ System.out.println("0"); return ; } if(start==0){ if(bad.contains(start)){ System.out.println("0"); return ; } else { System.out.println("inf"); return ; } } if(ratio==1){ if(bad.contains(start)){ System.out.println("0"); return ; } else { System.out.println("inf"); return ; } } if(ratio==-1){ if(bad.contains(start)&& bad.contains(start*(-1))){ System.out.println("0"); return ; } else { System.out.println("inf"); return ; } } if(ratio==0){ if(bad.contains(ratio)==false){ System.out.println("inf"); return ; } else if(bad.contains(start)){ System.out.println("0"); return ; } else { System.out.println("1"); return ; } } int cnt=0 ; while(Math.abs(start)<=max){ if(bad.contains(start)==false){ cnt++; } start*=ratio ; } System.out.println(cnt); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var start : long ; start := sc.getCurrent()->toLong() ; var ratio : long ; ratio := sc.getCurrent()->toLong() ; var max : long ; max := sc.getCurrent()->toLong() ; var m : int ; m := sc.getCurrent()->toInteger() ; var bad : Sequence(long) ; bad := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( bad := bad->including(sc.getCurrent()->toLong()) ) ; i := i + 1 ) ; if (if start < 0 then -(start) else start endif > max) then ( OclFile["System.out"].println("0") ; return ) else skip ; if (start = 0) then ( if (bad->includes(start)) then ( OclFile["System.out"].println("0") ; return ) else ( OclFile["System.out"].println("inf") ; return ) ) else skip ; if (ratio = 1) then ( if (bad->includes(start)) then ( OclFile["System.out"].println("0") ; return ) else ( OclFile["System.out"].println("inf") ; return ) ) else skip ; if (ratio = -1) then ( if (bad->includes(start) & bad->includes(start * (-1))) then ( OclFile["System.out"].println("0") ; return ) else ( OclFile["System.out"].println("inf") ; return ) ) else skip ; if (ratio = 0) then ( if (bad->includes(ratio) = false) then ( OclFile["System.out"].println("inf") ; return ) else if (bad->includes(start)) then ( OclFile["System.out"].println("0") ; return ) else ( OclFile["System.out"].println("1") ; return ) ; ) else skip ; var cnt : int ; cnt := 0 ; while (if start < 0 then -(start) else start endif <= max) do ( if (bad->includes(start) = false) then ( cnt := cnt + 1 ) else skip ; start := start*(ratio) ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void maxProductSum(String str,int m){ int n=str.length(); int maxProd=Integer.MIN_VALUE,maxSum=Integer.MIN_VALUE ; for(int i=0 ; isize() ; var maxProd : int ; maxProd := -2147483648 ; var maxSum : int ; maxSum := -2147483648 ; var i : int ; i := 0 ; while i < n - m do ( ( var product : int ; product := 1 ; var sum : int ; sum := 0 ; var j : int ; j := i ; while j < m + i do ( ( product := product * (str->at(j+1) - ('0')->char2byte()) ; sum := sum + (str->at(j+1) - ('0')->char2byte()) ) ; j := j + 1 ) ; maxProd := Set{maxProd, product}->max() ; maxSum := Set{maxSum, sum}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println("Maximum Product=" + maxProd) ; OclFile["System.out"].print("\nMaximum Sum=" + maxSum) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "3675356291" ; var m : int ; m := 5 ; execute maxProductSum(str, m) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int solve(int a,int b){ int count=0 ; while(a>=b){ count+=a/b ; a=(a % b)+(a/b); } return count ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a,b ; a=sc.nextInt(); b=sc.nextInt(); System.out.println(a+solve(a,b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve( a : int, b : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; while (a >= b) do ( count := count+(a / b) ; a := (a mod b) + (a / b) ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; var b : int ; a := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(a + solve(a, b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); while(true){ String a=stdIn.next(); if(a.equals("#"))break ; if(a.length()==5){ System.out.println(0); continue ; } if(a.length()==4){ System.out.println(90); continue ; } int b=0 ; int c=1 ; int d=a.length()-1 ; if(a.charAt(d)=='h'){ d-=5 ; } else { d-=4 ; b=90 ; } while(true){ if(d<=0)break ; c=c<<1 ; if(a.charAt(d)=='h'){ d-=5 ; b=2*b-90 ; continue ; } else { d-=4 ; b=2*b+90 ; continue ; } } int gcd=gcd(b,c); if(b % c==0){ System.out.println(b/c); } else { System.out.println(b/gcd+"/"+c/gcd); } } } public static int gcd(int b,int c){ if(c==0)return b ; return gcd(c,b % c); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var a : String ; a := stdIn.getCurrent() ; if (a = "#") then break else skip ; if (a->size() = 5) then ( OclFile["System.out"].println(0) ; continue ) else skip ; if (a->size() = 4) then ( OclFile["System.out"].println(90) ; continue ) else skip ; var b : int ; b := 0 ; var c : int ; c := 1 ; var d : int ; d := a->size() - 1 ; if (a->at(d+1) = 'h') then ( d := d-(5) ) else ( d := d-(4) ; b := 90 ) ; while (true) do ( if (d <= 0) then break else skip ; c := (c*(2->pow(1)))->oclAsType(long) ; if (a->at(d+1) = 'h') then ( d := d-(5) ; b := 2 * b - 90 ; continue ) else ( d := d-(4) ; b := 2 * b + 90 ; continue ) ) ; var gcd : int ; gcd := gcd(b, c) ; if (b mod c = 0) then ( OclFile["System.out"].println(b / c) ) else ( OclFile["System.out"].println(b / gcd + "/" + c / gcd) ) ; ) ); static operation gcd( b : int, c : int) : int pre: true post: true activity: ( if (c = 0) then return b else skip ; return gcd(c, b mod c) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in=new Scanner(System.in); static final PrintWriter out=new PrintWriter(System.out,false); static boolean debug=false ; static boolean solve(){ String s=in.next(); if("#".equals(s))return false ; int pos=s.length(),cnt=0 ; double d=-1 ; while(pos>=0){ while(s.charAt(--pos)!='w' && s.charAt(pos)!='n'); if(s.charAt(pos)=='n'){ if(cnt==0)d=0 ; else d-=90.0/(1<0 ; long start=System.nanoTime(); while(solve()); out.flush(); long end=System.nanoTime(); dump((end-start)/1000000+" ms"); in.close(); out.close(); } static void dump(Object...o){ if(debug)System.err.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"], false); static attribute debug : boolean := false; static operation solve() : boolean pre: true post: true activity: ( var s : String ; s := in.getCurrent() ; if ("#" = s) then return false else skip ; var pos : int ; pos := s->size() ; var cnt : int ; cnt := 0 ; var d : double ; d := -1 ; while (pos >= 0) do ( while (s->at((pos - 1)+1) /= 'w' & s->at(pos+1) /= 'n') do ; if (s->at(pos+1) = 'n') then ( if (cnt = 0) then d := 0 ; else d := d-(90.0 / ((1*(2->pow(cnt)))->oclAsType(long))) ; ) else ( if (cnt = 0) then d := 90 ; else d := d+(90.0 / ((1*(2->pow(cnt)))->oclAsType(long))) ; ) ; cnt := cnt + 1 ; pos := pos - 1 ) ; var div : int ; div := 1 ; while (d->oclAsType(int) /= d) do ( d := d*(2) ; div := div*(2) ) ; var ans : int ; ans := d->oclAsType(int) ; skip ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( debug := args->size() > 0 ; var start : long ; start := nanoTime() ; while (solve()) do ; skip ; var end : long ; end := nanoTime() ; execute dump((end - start) / 1000000 + " ms") ; skip ; skip ; ); static operation dump( o : Sequence(OclAny)) : void pre: true post: true activity: ( if (debug) then OclFile["System.err"].println((o + "")) ; else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class Main { static String input ; static int pos ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ input=sc.next(); if(input.equals("#"))break ; pos=0 ; int n=0 ; ListdirList=new ArrayList(); Listlist=new ArrayList(); while(possize()) do ( if (input->at(pos+1) = 'n') then ( dirList := dirList->including("north") ; pos := pos+(5) ) else ( dirList := dirList->including("west") ; pos := pos+(4) ) ; n := n + 1 ) ; dirList := dirList->reverse() ; var i : int ; i := 0 ; while i < n do ( ( var dir : String ; dir := dirList->at(i+1) ; if (dir = "north") then list := list->including(Rational.newRational(-90, 2->pow(i)->oclAsType(long))) ; else list := list->including(Rational.newRational(90, 2->pow(i)->oclAsType(long))) ; ) ; i := i + 1 ) ; var result : Rational ; result := Rational.newRational(0, 1) ; for (rat : list) do ( ( result->excludes(rat) ) ) ; OclFile["System.out"].println(result) ; ) ; skip ); static class Rational { attribute child : long; static operation newRational( c : long, b : long) : Rational pre: true post: true activity: ( var self : Rational ; self := createRational(); self.initialise(c, b); return self ); operation initialise( c : long, b : long) : void pre: true post: true activity: ( child := c ; base := b ); operation toString() : String pre: true post: true activity: ( if (base = 1) then return ((child) + "") else skip ; return child + "/" + base ); operation add( anotherRational : Rational) : void pre: true post: true activity: ( var r : long ; r := anotherRational.base / base ; child := child*(r) ; base := base*(r) ; child := child+(anotherRational.child) ; child := Set{child, 0}->max() ; child := Set{child, base * 90}->min() ; while (child mod 2 = 0 & base mod 2 = 0) do ( child := child/(2) ; base := base/(2) ) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; public class Main { Scanner sc=new Scanner(System.in); public void run(){ while(true){ String s=sc.next(); if(s.equals("#"))break ; calc(s); } } public void calc(String s){ int[] north=new int[20]; int n=0 ; String check=s ; while(check.length()!=0){ String part=check.substring(0,4); if(part.equals("west")){ north[n]=-1 ; check=check.substring(4); } else { north[n]=1 ; check=check.substring(5); } n++; } int ans=0 ; int ansd=1 ; if(north[n-1]==-1)ans=90 ; for(int i=n-2 ; i>=0 ; i--){ if(north[i]==1){ ans=2*ans-90 ; ansd=2*ansd ; if(ans<0){ ans=0 ; ansd=1 ; } } else if(north[i]==-1){ ans=2*ans+90 ; ansd=2*ansd ; } } while(ans % 2==0 && ansd % 2==0){ ans=ans/2 ; ansd=ansd/2 ; } System.out.print(ans); if(ansd!=1)System.out.print("/"+ansd); System.out.println(); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while (true) do ( var s : String ; s := sc.getCurrent() ; if (s = "#") then break else skip ; execute calc(s) ) ); operation calc( s : String) : void pre: true post: true activity: ( var north : Sequence(int) ; north := Integer.subrange(1,20)->collect(0) ; var n : int ; n := 0 ; var check : String ; check := s ; while (check->size() /= 0) do ( var part : String ; part := check.subrange(0+1,4) ; if (part = "west") then ( north[n+1] := -1 ; check := check.subrange(4+1,4) ) else ( north[n+1] := 1 ; check := check.subrange(5+1,5) ) ; n := n + 1 ) ; var ans : int ; ans := 0 ; var ansd : int ; ansd := 1 ; if (north[n - 1+1] = -1) then ans := 90 ; else skip ; var i : int ; i := n - 2 ; while i >= 0 do ( ( if (north[i+1] = 1) then ( ans := 2 * ans - 90 ; ansd := 2 * ansd ; if (ans < 0) then ( ans := 0 ; ansd := 1 ) else skip ) else if (north[i+1] = -1) then ( ans := 2 * ans + 90 ; ansd := 2 * ansd ) else skip ; ) ; i := i - 1 ) ; while (ans mod 2 = 0 & ansd mod 2 = 0) do ( ans := ans / 2 ; ansd := ansd / 2 ) ; OclFile["System.out"].print(ans) ; if (ansd /= 1) then OclFile["System.out"].print("/" + ansd) ; else skip ; OclFile["System.out"].println() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); int x=0 ; int[] idx=new int[n]; int[] arr=new int[n]; int sum=0 ; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.getCurrent()->toInteger() ; var x : int ; x := 0 ; var idx : Sequence(int) ; idx := Integer.subrange(1,n)->collect(0) ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] mod 2 = 0) then ( c := c + 1 ; idx[x+1] := i + 1 ; x := x + 1 ; sum := sum+(arr[i+1]) ) else skip ) ; i := i + 1 ) ; var y : int ; y := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] mod 2 /= 0 & y = 0) then y := i + 1 ; else if (arr[i+1] mod 2 /= 0 & y /= 0) then ( c := c+(2) ; idx[x+1] := y ; x := x + 1 ; idx[x+1] := i + 1 ; x := x + 1 ; sum := sum+(arr[y - 1+1] + arr[i+1]) ; y := 0 ; ) else skip ; ) ; i := i + 1 ) ; if (y /= 0) then ( sum := sum+(arr[y - 1+1]) ; if (not(isPrime(sum))) then ( c := c + 1 ; idx[x+1] := y ) else skip ) else skip ; OclFile["System.out"].println(c) ; var i : int ; i := 0 ; while i < c do ( ( OclFile["System.out"].print(idx[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ; ) ); static operation isPrime( num : int) : boolean pre: true post: true activity: ( if (num <= 1) then return false else skip ; var i : int ; i := 2 ; while i <= num / 2 do ( ( if (num mod i = 0) then return false else skip ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int counDivisors(int X){ int count=0 ; for(int i=1 ; i<=X ; ++i){ if(X % i==0){ count++; } } return count ; } static int countDivisorsMult(int arr[],int n){ int mul=1 ; for(int i=0 ; isize() ; OclFile["System.out"].println(countDivisorsMult(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printRepeating(int arr[],int n){ for(int i=0 ; i1)System.out.println(i+" "); } } public static void main(String args[]){ int arr[]={ 1,6,3,1,3,6,6 }; int arr_size=arr.length ; System.out.println("The repeating elements are: "); printRepeating(arr,arr_size); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printRepeating( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n do ( ( var index : int ; index := arr[i+1] mod n ; arr[index+1] := arr[index+1]+(n) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if ((arr[i+1] / n) > 1) then OclFile["System.out"].println(i + " ") ; else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,6,3,1,3,6,6} ; var arr_size : int ; arr_size := arr->size() ; OclFile["System.out"].println("The repeating elements are: ") ; execute printRepeating(arr, arr_size) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static int gcd(int a,int b){ if(a==0)return b ; else return gcd(b % a,a); } public static void solve(int n,int m,int x,int y,int a,int b){ int k,g ; int x1,y1,x2,y2 ; g=gcd(a,b); a/=g ; b/=g ; k=Math.min(n/a,m/b); x1=x-(k*a-k*a/2); x2=x+k*a/2 ; y1=y-(k*b-k*b/2); y2=y+k*b/2 ; if(x1<0){ x2-=x1 ; x1=0 ; } if(x2>n){ x1-=x2-n ; x2=n ; } if(y1<0){ y2-=y1 ; y1=0 ; } if(y2>m){ y1-=y2-m ; y2=m ; } System.out.println(x1+" "+y1+" "+x2+" "+y2); } public static void main(String args[]){ int n=70,m=10 ; int x=20,y=5 ; int a=5,b=3 ; solve(n,m,x,y,a,b); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then return b else return gcd(b mod a, a) ); static operation solve( n : int, m : int, x : int, y : int, a : int, b : int) : void pre: true post: true activity: ( var k : int ; var g : int ; var x1 : int ; var y1 : int ; var x2 : int ; var y2 : int ; g := gcd(a, b) ; a := a/(g) ; b := b/(g) ; k := Set{n / a, m / b}->min() ; x1 := x - (k * a - k * a / 2) ; x2 := x + k * a / 2 ; y1 := y - (k * b - k * b / 2) ; y2 := y + k * b / 2 ; if (x1 < 0) then ( x2 := x2-(x1) ; x1 := 0 ) else skip ; if (x2 > n) then ( x1 := x1-(x2 - n) ; x2 := n ) else skip ; if (y1 < 0) then ( y2 := y2-(y1) ; y1 := 0 ) else skip ; if (y2 > m) then ( y1 := y1-(y2 - m) ; y2 := m ) else skip ; OclFile["System.out"].println(x1 + " " + y1 + " " + x2 + " " + y2) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 70 ; var m : int ; m := 10 ; var x : int ; x := 20 ; var y : int ; y := 5 ; var a : int ; a := 5 ; var b : int ; b := 3 ; execute solve(n, m, x, y, a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Math.pow ; class GFG { static double sum(int x,int n){ double i,total=1.0 ; for(i=1 ; i<=n ; i++)total=total+(Math.pow(x,i)/i); return total ; } public static void main(String[] args){ int x=2 ; int n=5 ; System.out.printf("%.2f",sum(x,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sum( x : int, n : int) : double pre: true post: true activity: ( var i : double ; var total : double ; total := 1.0 ; i := 1 ; while i <= n do ( total := total + (x->pow(i) / i) ; ; i := i + 1 ) ; return total ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 2 ; var n : int ; n := 5 ; OclFile["System.out"].printf("%.2f", sum(x, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class close_to_n_divisible_m { static int closestNumber(int n,int m){ int q=n/m ; int n1=m*q ; int n2=(n*m)>0 ?(m*(q+1)):(m*(q-1)); if(Math.abs(n-n1) 0 then (m * (q + 1)) else (m * (q - 1)) endif ; if (if n - n1 < 0 then -(n - n1) else n - n1 endif < if n - n2 < 0 then -(n - n2) else n - n2 endif) then return n1 else skip ; return n2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 13 ; var m : int ; m := 4 ; OclFile["System.out"].println(closestNumber(n, m)) ; n := -15 ; m := 6 ; OclFile["System.out"].println(closestNumber(n, m)) ; n := 0 ; m := 8 ; OclFile["System.out"].println(closestNumber(n, m)) ; n := 18 ; m := -7 ; OclFile["System.out"].println(closestNumber(n, m)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.util.Arrays.*; public class Main { int[] as ; void run(){ Scanner in=new Scanner(System.in); ArrayListarr=new ArrayList(); for(int i=1 ; i<=1111 ; i++){ for(int j=i ; j<=1111 ; j++){ arr.add(i*i*i+j*j*j); } } as=new int[arr.size()]; for(int i=0 ; iincluding(i * i * i + j * j * j) ) ; j := j + 1 ) ) ; i := i + 1 ) ; as := Integer.subrange(1,arr->size())->collect(0) ; var i : int ; i := 0 ; while i < as->size() do ( as[i+1] := arr->at(i+1) ; ; i := i + 1 ) ; execute sort(as) ; while true do ( ( var n : int ; n := in.getCurrent()->toInteger() ; if (n = 0) then return else skip ; OclFile["System.out"].println(solve(n)) ) ) ; ); operation solve( z : int) : int pre: true post: true activity: ( var id : int ; id := -2 - binarySearch(as, z * z * z) ; return z * z * z - as[id+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.IOException ; class Main { public static void main(String[] args)throws IOException { int z,n=3 ; Scanner sc=new Scanner(System.in); while(sc.hasNextInt()){ z=sc.nextInt(); if(z==0){ break ; } System.out.println(calc(z,n)); } } private static long calc(int z,int n){ long min=Long.MAX_VALUE,tmp ; for(int x=1 ; mypower(x,n)<=mypower(z,n); x++){ for(int y=x ; mypower(x,n)+mypower(y,n)<=mypower(z,n); y++){ tmp=mypower(z,n)-mypower(x,n)-mypower(y,n); if(tmptoInteger() ; if (z = 0) then ( break ) else skip ; OclFile["System.out"].println(calc(z, n)) ) ); static operation calc( z : int, n : int) : long pre: true post: true activity: ( var min : long ; min := "9223372036854775807"->toLong() ; var tmp : long ; var x : int ; x := 1 ; while mypower(x, n) <= mypower(z, n) do ( ( var y : int ; y := x ; while mypower(x, n) + mypower(y, n) <= mypower(z, n) do ( ( tmp := mypower(z, n) - mypower(x, n) - mypower(y, n) ; if (tmp < min) then ( min := tmp ) else skip ) ; y := y + 1 ) ) ; x := x + 1 ) ; return min ); static operation mypower( base : int, exp : int) : long pre: true post: true activity: ( var p : long ; p := 1 ; var i : int ; i := 0 ; while i < exp do ( ( p := p*(base) ) ; i := i + 1 ) ; return p ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ long[] p=new long[1111]; for(int i=0 ; i<1111 ; i++)p[i]=(long)Math.pow(i,3); Scanner sc=new Scanner(System.in); while(true){ int z=sc.nextInt(); if(z==0)break ; int i=1,j=z ; long max=0 ; while(i<=j){ long val=p[i]+p[j]; if(val<=p[z]){ i++; max=Math.max(max,val); } else j--; } System.out.println(p[z]-max); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var p : Sequence(long) ; p := Integer.subrange(1,1111)->collect(0) ; var i : int ; i := 0 ; while i < 1111 do ( p[i+1] := i->pow(3)->oclAsType(long) ; ; i := i + 1 ) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var z : int ; z := sc.getCurrent()->toInteger() ; if (z = 0) then break else skip ; var i : int ; i := 1 ; var j : int ; j := z ; var max : long ; max := 0 ; while (i <= j) do ( var val : long ; val := p[i+1] + p[j+1] ; if (val <= p[z+1]) then ( i := i + 1 ; max := Set{max, val}->max() ) else j := j - 1 ; ) ; OclFile["System.out"].println(p[z+1] - max) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Collections ; import java.util.LinkedList ; import java.util.ListIterator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long[] pre=new long[1112]; for(int i=0 ; i<1112 ; i++){ long l=i ; l=l*l*l ; pre[i]=l ; } while(true){ final int z=sc.nextInt(); if(z==0){ break ; } long max=0 ; for(int x=1 ; ; x++){ if(pre[z]=(pre[x]+pre[y])){ max=Math.max(max,pre[x]+pre[y]); } } } System.out.println(pre[z]-max); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pre : Sequence(long) ; pre := Integer.subrange(1,1112)->collect(0) ; var i : int ; i := 0 ; while i < 1112 do ( ( var l : long ; l := i ; l := l * l * l ; pre[i+1] := l ) ; i := i + 1 ) ; while (true) do ( var z : int ; z := sc.getCurrent()->toInteger() ; if (z = 0) then ( break ) else skip ; var max : long ; max := 0 ; var x : int ; x := 1 ; while true do ( ( if (pre[z+1] < pre[x+1]) then ( break ) else skip ; var y : int ; y := 1 ; while y <= x do ( ( if (pre[z+1] >= (pre[x+1] + pre[y+1])) then ( max := Set{max, pre[x+1] + pre[y+1]}->max() ) else skip ) ; y := y + 1 ) ) ; x := x + 1 ) ; OclFile["System.out"].println(pre[z+1] - max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args)throws IOException { int end=Integer.parseInt(br.readLine()); while(end!=0){ new Main().cal(end); end=Integer.parseInt(br.readLine()); } } int[] thr ; private void cal(int end)throws IOException { int z=end ; int limit=z*z*z ; int tmp ; int max ; thr=new int[z]; for(int i=1 ; imax){ max=tmp ; } if(tmp>=limit){ break ; } } } System.out.println(limit-max); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var end : int ; end := (br.readLine())->toInteger() ; while (end /= 0) do ( Main.newMain().cal(end) ; end := (br.readLine())->toInteger() ) ); attribute thr : Sequence(int); operation cal( end : int) : void pre: true post: true activity: ( var z : int ; z := end ; var limit : int ; limit := z * z * z ; var tmp : int ; var max : int ; thr := Integer.subrange(1,z)->collect(0) ; var i : int ; i := 1 ; while i < z do ( ( thr[i+1] := i * i * i ) ; i := i + 1 ) ; max := thr[1+1] + thr[1+1] ; var i : int ; i := 1 ; while i < z do ( ( var j : int ; j := 1 ; while j < z do ( ( tmp := thr[i+1] + thr[j+1] ; if (tmp <= limit & tmp > max) then ( max := tmp ) else skip ; if (tmp >= limit) then ( break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(limit - max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class B1602 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int t=0 ; tlist=new ArrayList<>(); boolean change ; do { change=false ; list.add(A); int[] stat=new int[N+1]; for(int a : A){ stat[a]++; } int[] newA=new int[N]; for(int n=0 ; ntoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var n : int ; n := 0 ; while n < N do ( ( A[n+1] := in.getCurrent()->toInteger() ) ; n := n + 1 ) ; var list : Sequence(Sequence(int)) ; list := Sequence{} ; var change : boolean ; while true do (( change := false ; list := list->including(A) ; var stat : Sequence(int) ; stat := Integer.subrange(1,N + 1)->collect(0) ; for (a : A) do ( ( stat[a+1] := stat[a+1] + 1 ) ) ; var newA : Sequence(int) ; newA := Integer.subrange(1,N)->collect(0) ; var n : int ; n := 0 ; while n < N do ( ( var a : int ; a := A[n+1] ; var na : int ; na := stat[a+1] ; newA[n+1] := na ; if (na /= a) then ( change := true ) else skip ) ; n := n + 1 ) ; A := newA ; ) ; if (change) then skip else break) ; var output : String ; output := StringLib.newString() ; var Q : int ; Q := in.getCurrent()->toInteger() ; var q : int ; q := 0 ; while q < Q do ( ( var idx : int ; idx := in.getCurrent()->toInteger() ; var listIdx : int ; listIdx := in.getCurrent()->toInteger() ; var answer : int ; answer := list->at(Set{listIdx, list->size() - 1}->min()+1)[idx - 1+1] ; output := output + StringLib.newString(answer) + StringLib.newString(' ') ) ; q := q + 1 ) ; OclFile["System.out"].print(output) ; ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int find(int a[],int b[],int k,int n1,int n2){ LinkedHashSets=new LinkedHashSet<>(); for(int i=0 ; iincluding(b[i+1]) ; ; i := i + 1 ) ; var missing : int ; missing := 0 ; var i : int ; i := 0 ; while i < n1 do ( ( if (not(s->includes(a[i+1]))) then missing := missing + 1 ; else skip ; if (missing = k) then return a[i+1] else skip ) ; i := i + 1 ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{0,2,4,6,8,10,12,14,15} ; var b : Sequence(int) ; b := Sequence{4,10,6,8,12} ; var n1 : int ; n1 := a->size() ; var n2 : int ; n2 := b->size() ; var k : int ; k := 3 ; OclFile["System.out"].println(find(a, b, k, n1, n2)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int[] s=new int[4]; int[] t=new int[2]; t[0]=sc.nextInt(); s[0]=sc.nextInt(); s[3]=sc.nextInt(); s[1]=sc.nextInt(); s[2]=sc.nextInt(); t[1]=sc.nextInt(); int q=sc.nextInt(); for(int i=0 ; icollect(0) ; var t : Sequence(int) ; t := Integer.subrange(1,2)->collect(0) ; t[0+1] := sc.getCurrent()->toInteger() ; s[0+1] := sc.getCurrent()->toInteger() ; s[3+1] := sc.getCurrent()->toInteger() ; s[1+1] := sc.getCurrent()->toInteger() ; s[2+1] := sc.getCurrent()->toInteger() ; t[1+1] := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var qt : int ; qt := sc.getCurrent()->toInteger() ; var qf : int ; qf := sc.getCurrent()->toInteger() ; var is : int ; is := 0 ; while is < 4 do ( ( if (s[is+1] = qt) then ( if (s[(is + 1) mod 4+1] = qf) then ( OclFile["System.out"].println(t[1+1]) ) else if (s[(is + 3) mod 4+1] = qf) then ( OclFile["System.out"].println(t[0+1]) ) else if (t[0+1] = qf) then ( OclFile["System.out"].println(s[(is + 1) mod 4+1]) ) else ( OclFile["System.out"].println(s[(is + 3) mod 4+1]) ) ; ; ) else skip ) ; is := is + 1 ) ; var is : int ; is := 0 ; while is < 4 do ( ( if (s[is+1] = qf) then ( if (t[0+1] = qt) then ( OclFile["System.out"].println(s[(is + 3) mod 4+1]) ) else if (t[1+1] = qt) then ( OclFile["System.out"].println(s[(is + 1) mod 4+1]) ) else skip ; ) else skip ) ; is := is + 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Random ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int[] d=new int[6]; Dice dice=new Dice(); for(int i=0 ; i<6 ; i++){ d[i]=scanner.nextInt(); dice.num[i]=d[i]; } int q=scanner.nextInt(); for(int i=0 ; icollect(0) ; var dice : Dice ; dice := Dice.newDice() ; var i : int ; i := 0 ; while i < 6 do ( ( d[i+1] := scanner.getCurrent()->toInteger() ; dice.num[i+1] := d[i+1] ) ; i := i + 1 ) ; var q : int ; q := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var head : int ; head := scanner.getCurrent()->toInteger() ; var flont : int ; flont := scanner.getCurrent()->toInteger() ; dice.Roll(head, flont) ; OclFile["System.out"].println(dice.num[2+1]) ) ; i := i + 1 ) ; skip ; ); } class Dice { attribute rand : OclRandom := OclRandom.newOclRandom(); attribute num : Sequence(int); static operation newDice() : Dice pre: true post: true activity: ( var self : Dice ; self := createDice(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( num := Integer.subrange(1,6)->collect(0) ); attribute box : int := 0; operation Roll( head : int, flont : int) : void pre: true post: true activity: ( while (true) do ( if ((head = num[0+1]) & (flont = num[1+1])) then ( break ) else skip ; var random : int ; random := rand.nextInt(4) ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (random) ; if _switchval = 0 then box := num[0+1] ; num[0+1] := num[4+1] ; num[4+1] := num[5+1] ; num[5+1] := num[1+1] ; num[1+1] := box ; break else skip ; if _switchval = 1 then box := num[0+1] ; num[0+1] := num[1+1] ; num[1+1] := num[5+1] ; num[5+1] := num[4+1] ; num[4+1] := box ; break else skip ; if _switchval = 2 then box := num[0+1] ; num[0+1] := num[2+1] ; num[2+1] := num[5+1] ; num[5+1] := num[3+1] ; num[3+1] := box ; break else skip ; if _switchval = 3 then box := num[0+1] ; num[0+1] := num[3+1] ; num[3+1] := num[5+1] ; num[5+1] := num[2+1] ; num[2+1] := box ; break else skip ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String[] line=scanner.nextLine().split(" "); int a1=Integer.parseInt(line[0]); int a2=Integer.parseInt(line[1]); int a3=Integer.parseInt(line[2]); int a4=Integer.parseInt(line[3]); int a5=Integer.parseInt(line[4]); int a6=Integer.parseInt(line[5]); int b=Integer.parseInt(scanner.nextLine()); for(int i=0 ; isplit(" ") ; var a1 : int ; a1 := (line[0+1])->toInteger() ; var a2 : int ; a2 := (line[1+1])->toInteger() ; var a3 : int ; a3 := (line[2+1])->toInteger() ; var a4 : int ; a4 := (line[3+1])->toInteger() ; var a5 : int ; a5 := (line[4+1])->toInteger() ; var a6 : int ; a6 := (line[5+1])->toInteger() ; var b : int ; b := (scanner.nextLine())->toInteger() ; var i : int ; i := 0 ; while i < b do ( ( var c : int ; c := scanner.getCurrent()->toInteger() ; var d : int ; d := scanner.getCurrent()->toInteger() ; var result : int ; result := 0 ; if (c = a1 or c = a6) then if (d = a2) then result := 3 ; else if (d = a3) then result := 5 else if (d = a4) then result := 2 else result := 4 ; ; ; else if (c = a2 or c = a5) then if (d = a1) then result := 4 ; else if (d = a3) then result := 1 else if (d = a4) then result := 6 else result := 3 ; ; ; else ( if (d = a1) then result := 2 ; else if (d = a2) then result := 6 else if (d = a5) then result := 1 else result := 5 ; ; ; ) ; ; if (c = a4 or c = a5 or c = a6) then result := 7 - result ; else skip ; OclFile["System.out"].println(line[result - 1+1]) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; class Main { static int N,M ; static ArrayList>s=new ArrayList<>(); static ArrayListp=new ArrayList<>(); static int[] a ; static int ans=0 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); N=sc.nextInt(); M=sc.nextInt(); for(int i=0 ; isi=new ArrayList<>(); for(int j=0 ; jtoInteger() ; M := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < M do ( ( var k : int ; k := sc.getCurrent()->toInteger() ; var si : Sequence(int) ; si := Sequence{} ; var j : int ; j := 0 ; while j < k do ( ( si := si->including(sc.getCurrent()->toInteger()) ) ; j := j + 1 ) ; s := s->including(si) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( p := p->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; skip ; a := Integer.subrange(1,N)->collect(0) ; execute dfs(0) ; OclFile["System.out"].println(ans) ; ); static operation dfs( pos : int) : void pre: true post: true activity: ( if (pos = N) then ( execute func() ) else ( a[pos+1] := 0 ; execute dfs(pos + 1) ; a[pos+1] := 1 ; execute dfs(pos + 1) ) ); static operation func() : void pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( var cnt1 : int ; cnt1 := 0 ; for (si : s->at(i+1)) do ( ( if (a[si - 1+1] = 1) then ( cnt1 := cnt1 + 1 ) else skip ) ) ; if (cnt1 mod 2 = p->at(i+1)) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; if (count = M) then ( ans := ans + 1 ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GfG { static void pattern(int n){ int p,k=1 ; for(int i=1 ; i<=n ; i++){ p=k ; for(int j=1 ; j<=i ; j++){ System.out.print(p); System.out.print(" "); p=p-(n+j-i); } System.out.println(); k=k+1+n-i ; } } public static void main(String[] args){ int n=5 ; pattern(n); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation pattern( n : int) : void pre: true post: true activity: ( var p : int ; var k : int ; k := 1 ; var i : int ; i := 1 ; while i <= n do ( ( p := k ; var j : int ; j := 1 ; while j <= i do ( ( OclFile["System.out"].print(p) ; OclFile["System.out"].print(" ") ; p := p - (n + j - i) ) ; j := j + 1 ) ; OclFile["System.out"].println() ; k := k + 1 + n - i ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; execute pattern(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] z){ String r ; int n,v,i ; for(Scanner s=new Scanner(System.in); s.hasNext(); System.out.println(r)){ char[] c=s.next().toCharArray(),k={ 46,63,33,32 }; r="" ; if((n=c.length)% 2>0)r="NA" ; else for(i=0 ; i53){ r="NA" ; break ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( z : Sequence(String)) : void pre: true post: true activity: ( var r : String ; var n : int ; var v : int ; var i : int ; var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; while s.hasNext() do ( ( var c : Sequence(String) ; c := s.getCurrent()->characters() ; var k : Sequence(String) ; k := Sequence{46,63,33,32} ; r := "" ; if ((n) mod 2 > 0) then r := "NA" ; else i := 0 ; while i < n do ( if ((v) < 0 or 29 < v or c[i+1] < 49 or c[i+1] > 53) then ( r := "NA" ; break ) else skip ; ; r := r+(if v < 26 then (97 + v)->oclAsType(String) else k[(v)->char2byte() - 26+1] endif) ) ; ) ; OclFile["System.out"].println(r) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); String s ; char[] c,r ; int i ; for(; sc.hasNext(); ){ s=sc.next(); if(s.length()% 2==1)out.println("NA"); else { c=new char[s.length()]; r=new char[s.length()/2]; for(i=0 ; i'6' || c[i]<'1' || c[i+1]>'5' || c[i+1]<'1')break ; r[i/2]=(char)('a'+(c[i]-'1')*5+(c[i+1]-'1')); if(r[i/2]==(char)('a'+26))r[i/2]='.' ; else if(r[i/2]==(char)('a'+27))r[i/2]='?' ; else if(r[i/2]==(char)('a'+28))r[i/2]='!' ; else if(r[i/2]==(char)('a'+29))r[i/2]=' ' ; } if(isize() mod 2 = 1) then out.println("NA") ; else ( c := Integer.subrange(1,s->size())->collect(0) ; r := Integer.subrange(1,s->size() / 2)->collect(0) ; i := 0 ; while i < s->size() do ( c[i+1] := s->at(i+1) ; ; i := i + 1 ) ; i := 0 ; while i < s->size() do ( ( if (c[i+1] > '6' or c[i+1] < '1' or c[i + 1+1] > '5' or c[i + 1+1] < '1') then break else skip ; r[i / 2+1] := ('a' + (c[i+1] - ('1')->char2byte()) * 5 + (c[i + 1+1] - ('1')->char2byte()))->oclAsType(String) ; if (r[i / 2+1] = ('a' + 26)->oclAsType(String)) then r[i / 2+1] := '.' ; else if (r[i / 2+1] = ('a' + 27)->oclAsType(String)) then r[i / 2+1] := '?' else if (r[i / 2+1] = ('a' + 28)->oclAsType(String)) then r[i / 2+1] := '!' else if (r[i / 2+1] = ('a' + 29)->oclAsType(String)) then r[i / 2+1] := ' ' ; else skip ; ; ; ) ; i := i+(2) ) ; if (i < s->size()) then out.println("NA") else ( i := 0 ; while i < s->size() / 2 do ( out.print(r[i+1]) ; ; i := i + 1 ) ; out.println() ) ; ) ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ String[][] encode=new String[][] { { "11","a" },{ "12","b" },{ "13","c" },{ "14","d" },{ "15","e" },{ "21","f" },{ "22","g" },{ "23","h" },{ "24","i" },{ "25","j" },{ "31","k" },{ "32","l" },{ "33","m" },{ "34","n" },{ "35","o" },{ "41","p" },{ "42","q" },{ "43","r" },{ "44","s" },{ "45","t" },{ "51","u" },{ "52","v" },{ "53","w" },{ "54","x" },{ "55","y" },{ "61","z" },{ "62","." },{ "63","?" },{ "64","!" },{ "65"," " } }; Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String in=sc.nextLine(); boolean na ; if(in.length()% 2==1){ System.out.println("NA"); } else { na=true ; int index=0,i=0 ; StringBuilder sb=new StringBuilder(); while(indexsize() mod 2 = 1) then ( OclFile["System.out"].println("NA") ) else ( na := true ; var index : int ; index := 0 ; var i : int ; i := 0 ; var sb : String ; sb := StringLib.newString() ; while (index < in->size()) do ( var enc : String ; enc := in.subrange(index+1,index + 2).replace(encode[i+1][0+1], encode[i+1][1+1]) ; if (enc->size() = 1) then ( i := 0 ; sb := sb + StringLib.newString(enc) ; index := index+(2) ) else ( if (i + 1 < encode->size()) then ( i := i + 1 ) else ( OclFile["System.out"].println("NA") ; na := false ; break ) ) ) ; if (na) then ( OclFile["System.out"].println(sb+"") ) else ( na := true ) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc ; static final int INF=1<<28 ; static final double EPS=1e-9 ; void run(){ sc=new Scanner(System.in); char[][] table={ { 'a','f','k','p','u','z' },{ 'b','g','l','q','v','.' },{ 'c','h','m','r','w','?' },{ 'd','i','n','s','x','!' },{ 'e','j','o','t','y',' ' },}; for(; sc.hasNext(); ){ String s=sc.next(); if(s.length()% 2==1){ println("NA"); continue ; } String ans="" ; for(int i=0 ; i=6 || m<0 || n>=5 || ! Character.isDigit(s.charAt(i*2))|| ! Character.isDigit(s.charAt(i*2+1))){ ans="NA" ; break ; } ans+=table[n][m]; } println(ans); } sc.close(); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static attribute INF : int := (1*(2->pow(28)))->oclAsType(long); static attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var table : Sequence(Sequence(String)) ; table := Sequence{Sequence{'a','f','k','p','u','z'},Sequence{'b','g','l','q','v','.'},Sequence{'c','h','m','r','w','?'},Sequence{'d','i','n','s','x','!'},Sequence{'e','j','o','t','y',' '},} ; while sc.hasNext() do ( ( var s : String ; s := sc.getCurrent() ; if (s->size() mod 2 = 1) then ( execute println("NA") ; continue ) else skip ; var ans : String ; ans := "" ; var i : int ; i := 0 ; while i < s->size() / 2 do ( ( var m : int ; m := s->at(i * 2+1) - ('0')->char2byte() ; var n : int ; n := s->at(i * 2 + 1+1) - ('0')->char2byte() ; m := m - 1 ; n := n - 1 ; if (m < 0 or m >= 6 or m < 0 or n >= 5 or not((s->at(i * 2+1) + "")->isMatch("[0-9]")) or not((s->at(i * 2 + 1+1) + "")->isMatch("[0-9]"))) then ( ans := "NA" ; break ) else skip ; ans := ans+(table[n+1][m+1]) ; ) ; i := i + 1 ) ; execute println(ans) ; ) ) ; skip ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public char[][] code={ { 'a','f','k','p','u','z' },{ 'b','g','l','q','v','.' },{ 'c','h','m','r','w','?' },{ 'd','i','n','s','x','!' },{ 'e','j','o','t','y',' ' } }; public boolean judge(String str){ if(str.length()% 2!=0){ return false ; } for(int i=0 ; i6 || str.charAt(i)-'0'<1){ return false ; } } for(int i=1 ; i5 || str.charAt(i)-'0'<1){ return false ; } } return true ; } public void solve()throws IOException { while(stdIn.hasNext()){ String str=stdIn.next(); if(! judge(str)){ writer.println("NA"); } else { for(int i=0 ; isize() mod 2 /= 0) then ( return false ) else skip ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) - ('0')->char2byte() > 6 or str->at(i+1) - ('0')->char2byte() < 1) then ( return false ) else skip ) ; i := i+(2) ) ; var i : int ; i := 1 ; while i < str->size() do ( ( if (str->at(i+1) - ('0')->char2byte() > 5 or str->at(i+1) - ('0')->char2byte() < 1) then ( return false ) else skip ) ; i := i+(2) ) ; return true ); operation solve() : void pre: true post: true activity: ( while (stdIn.hasNext()) do ( var str : String ; str := stdIn.next() ; if (not(judge(str))) then ( writer.println("NA") ) else ( var i : int ; i := 0 ; while i < str->size() do ( ( var x : int ; x := str->at(i+1) - ('1')->char2byte() ; var y : int ; y := str->at(i + 1+1) - ('1')->char2byte() ; writer.print(code[y+1][x+1]) ) ; i := i+(2) ) ; writer.println() ) ) ; writer.flush() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute stdIn : OclFile; attribute writer : OclFile; operation run() : void pre: true post: true activity: ( stdIn := null ; try ( stdIn := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; writer := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ; skip ; ) catch (e : ProgramException) do ( e.printStackTrace() ; OclProcess.exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long s=sc.nextLong(); long mod=s %((long)Math.pow(10,9)); long x3=(long)Math.pow(10,9)-mod ; if(mod==0)x3=0 ; long y3=(s+x3)/(long)(Math.pow(10,9)); long x1=0 ; long y1=0 ; long x2=(long)Math.pow(10,9); long y2=1 ; System.out.println(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : long ; s := sc.getCurrent()->toLong() ; var mod : long ; mod := s mod (10->pow(9)->oclAsType(long)) ; var x3 : long ; x3 := 10->pow(9)->oclAsType(long) - mod ; if (mod = 0) then x3 := 0 ; else skip ; var y3 : long ; y3 := (s + x3) / (10->pow(9))->oclAsType(long) ; var x1 : long ; x1 := 0 ; var y1 : long ; y1 := 0 ; var x2 : long ; x2 := 10->pow(9)->oclAsType(long) ; var y2 : long ; y2 := 1 ; OclFile["System.out"].println(x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args){ Main main=new Main(); main.solve(); } public void solve(){ Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in))); long S=scan.nextLong(); long x=1000000000 ; long y=1 ; long m=S/x ; if(S % x!=0){ m+=1 ; } long l=m*x-S ; System.out.println("0 0 "+x+" "+y+" "+l+" "+m); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.solve() ); operation solve() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var S : long ; S := scan.getCurrent()->toLong() ; var x : long ; x := 1000000000 ; var y : long ; y := 1 ; var m : long ; m := S / x ; if (S mod x /= 0) then ( m := m+(1) ) else skip ; var l : long ; l := m * x - S ; OclFile["System.out"].println("0 0 " + x + " " + y + " " + l + " " + m) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long S=sc.nextLong(); if(S==1000000000000000000L){ System.out.println("0 0 1000000000 0 0 1000000000"); return ; } if(S<=1000000000){ System.out.println("0 0 1 0 0 "+String.valueOf(S)); } else { int x1=0 ; int y1=0 ; int x2=1 ; int y2=1000000000 ; long a=S/1000000000L ; long b=S % 1000000000L ; int x3=(int)a+1 ; int y3=(int)(1000000000-b); System.out.println(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : long ; S := sc.getCurrent()->toLong() ; if (S = 1000000000000000000L) then ( OclFile["System.out"].println("0 0 1000000000 0 0 1000000000") ; return ) else skip ; if (S <= 1000000000) then ( OclFile["System.out"].println("0 0 1 0 0 " + ((S) + "")) ) else ( var x1 : int ; x1 := 0 ; var y1 : int ; y1 := 0 ; var x2 : int ; x2 := 1 ; var y2 : int ; y2 := 1000000000 ; var a : long ; a := S / 1000000000L ; var b : long ; b := S mod 1000000000L ; var x3 : int ; x3 := a->oclAsType(int) + 1 ; var y3 : int ; y3 := (1000000000 - b)->oclAsType(int) ; OclFile["System.out"].println(x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] i){ long s=Long.parseLong(new Scanner(System.in).next()); int a=1000000000 ; System.out.println("0 0 "+a+" 1 "+(a-s % a)% a+" "+((s-1)/a+1)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( i : Sequence(String)) : void pre: true post: true activity: ( var s : long ; s := (OclFile.newOclFile_Read(OclFile["System.in"]).next())->toLong() ; var a : int ; a := 1000000000 ; OclFile["System.out"].println("0 0 " + a + " 1 " + (a - s mod a) mod a + " " + ((s - 1) / a + 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String args[])throws IOException { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int res=a ; while(a>=b){ int j=a/b ; res+=j ; a=j+(a % b); } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var res : int ; res := a ; while (a >= b) do ( var j : int ; j := a / b ; res := res+(j) ; a := j + (a mod b) ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long s=sc.nextLong(); long x1=0 ; long y1=0 ; long x2=1000000000 ; long y2=1 ; long start=s/x2 ; for(long i=start ; i<=x2 ; i++){ long x3=i*x2-s ; if(x3>=0 && x3<=x2){ System.out.print(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+i); break ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : long ; s := sc.getCurrent()->toLong() ; var x1 : long ; x1 := 0 ; var y1 : long ; y1 := 0 ; var x2 : long ; x2 := 1000000000 ; var y2 : long ; y2 := 1 ; var start : long ; start := s / x2 ; var i : long ; i := start ; while i <= x2 do ( ( var x3 : long ; x3 := i * x2 - s ; if (x3 >= 0 & x3 <= x2) then ( OclFile["System.out"].print(x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + i) ; break ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import com.sun.org.apache.bcel.internal.generic.AALOAD ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.math.BigInteger ; import java.util.*; import java.util.stream.IntStream ; import javafx.util.Pair ; public class Main { static void sort(double a[]){ Random ran=new Random(); for(int i=0 ; ix){ extraA=a-x ; extraA/=2 ; } if(b>y){ extraB=b-y ; extraB/=2 ; } if(c>z){ extraC=c-z ; extraC/=2 ; } if(asize() do ( ( var r : int ; r := ran.nextInt(a->size()) ; var temp : double ; temp := a[r+1] ; a[r+1] := a[i+1] ; a[i+1] := temp ) ; i := i + 1 ) ; a := a->sort() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var extraA : long ; extraA := 0 ; var extraB : long ; extraB := 0 ; var extraC : long ; extraC := 0 ; var NeedA : long ; NeedA := 0 ; var NeedB : long ; NeedB := 0 ; var NeedC : long ; NeedC := 0 ; var a : long ; a := input.getCurrent()->toLong() ; var b : long ; b := input.getCurrent()->toLong() ; var c : long ; c := input.getCurrent()->toLong() ; var x : long ; x := input.getCurrent()->toLong() ; var y : long ; y := input.getCurrent()->toLong() ; var z : long ; z := input.getCurrent()->toLong() ; if ((a + b + c) < (x + y + z)) then ( OclFile["System.out"].println("NO") ) else ( if (a > x) then ( extraA := a - x ; extraA := extraA/(2) ) else skip ; if (b > y) then ( extraB := b - y ; extraB := extraB/(2) ) else skip ; if (c > z) then ( extraC := c - z ; extraC := extraC/(2) ) else skip ; if (a < x) then ( NeedA := x - a ) else skip ; if (b < y) then ( NeedB := y - b ) else skip ; if (c < z) then ( NeedC := z - c ) else skip ; if ((NeedA + NeedB + NeedC) <= (extraA + extraB + extraC)) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static void maxPerimeter(int arr[],int n){ arr=arrRevSort(arr); int maxi=0 ; for(int i=0 ; i0){ System.out.println("Maximum Perimeter is: "+maxi); } else { System.out.println("Triangle formation is not possible."); } } static int[] arrRevSort(int[] arr){ Arrays.sort(arr,0,arr.length); int j=arr.length-1 ; for(int i=0 ; imax() ; break ) else skip ) ; i := i + 1 ) ; if (maxi > 0) then ( OclFile["System.out"].println("Maximum Perimeter is: " + maxi) ) else ( OclFile["System.out"].println("Triangle formation is not possible.") ) ); static operation arrRevSort( arr : Sequence(int)) : Sequence(int) pre: true post: true activity: ( arr := arr.subrange(1,0)^(arr.subrange(0+1,arr->size())->sort())^arr.subrange(arr->size()+1,arr.size) ; var j : int ; j := arr->size() - 1 ; var i : int ; i := 0 ; while i < arr->size() / 2 do ( ( var temp : int ; temp := arr[i+1] ; arr[i+1] := arr[j+1] ; arr[j+1] := temp ) ; i := i + 1 ; j := j - 1 ) ; return arr ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr1 : Sequence(int) ; arr1 := Sequence{6,1,6,5,8,4} ; execute maxPerimeter(arr1, 6) ; var arr2 : Sequence(int) ; arr2 := Sequence{2,20,7,55,1,33,12,4} ; execute maxPerimeter(arr2, 8) ; var arr3 : Sequence(int) ; arr3 := Sequence{33,6,20,1,8,12,5,55,4,9} ; execute maxPerimeter(arr3, 10) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int area_fun(int side){ int area=side*side ; return area ; } public static void main(String arg[]){ int side=4 ; int area=area_fun(side); System.out.println(area); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation area_fun( side : int) : int pre: true post: true activity: ( var area : int ; area := side * side ; return area ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var side : int ; side := 4 ; var area : int ; area := area_fun(side) ; OclFile["System.out"].println(area) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Criminals { public static void main(String[] arg){ Scanner input=new Scanner(System.in); String gogol=input.nextLine(); String pineapple=input.nextLine(); int gLength=gogol.length(); int aLength=pineapple.length(); int count=0 ; if(aLength>gLength)System.out.println(count); else { int test=gLength-aLength+1 ; for(int i=0 ; isize() ; var aLength : int ; aLength := pineapple->size() ; var count : int ; count := 0 ; if (aLength > gLength) then OclFile["System.out"].println(count) else ( var test : int ; test := (gLength)->char2byte() - aLength + 1 ; var i : int ; i := 0 ; while i < test do ( ( if (pineapple = gogol.subrange(i+1,aLength + i)) then ( count := count + 1 ; i := i+(aLength - 1) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class warOfTheCooperations { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s1=sc.next(); String s2=sc.next(); if(s2.length()>s1.length()){ System.out.println("0"); } else { int count=0 ; int i=s1.indexOf(s2); if(i==-1){ System.out.println("0"); } else { int k=0 ; count++; while(true){ k=s1.indexOf(s2,i+s2.length()); if(k==-1){ break ; } count++; i=k ; } System.out.println(count); } } } } ------------------------------------------------------------ OCL File: --------- class warOfTheCooperations { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; if (s2->size() > s1->size()) then ( OclFile["System.out"].println("0") ) else ( var count : int ; count := 0 ; var i : int ; i := s1->indexOf(s2)-1 ; if (i = -1) then ( OclFile["System.out"].println("0") ) else ( var k : int ; k := 0 ; count := count + 1 ; while (true) do ( k := s1.subrange(i + s2->size()+1)->indexOf(s2+"") + i + s2->size() - 1 ; if (k = -1) then ( break ) else skip ; count := count + 1 ; i := k ) ; OclFile["System.out"].println(count) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.StringTokenizer ; public class CF625B { public static void main(String[] args){ FastReader input=new FastReader(); PrintWriter pw=new PrintWriter(System.out); String s1=input.nextLine(); String s2=input.nextLine(); char[] arr=s1.toCharArray(); char[] arr2=s2.toCharArray(); int start=0 ; int ans=0 ; while(startcharacters() ; var arr2 : Sequence(String) ; arr2 := s2->characters() ; var start : int ; start := 0 ; var ans : int ; ans := 0 ; while (start < arr->size()) do ( var con : boolean ; con := false ; var temp : int ; temp := start ; var i : int ; i := 0 ; while i < arr2->size() do ( ( if (temp < arr->size() & arr2[i+1] = arr[temp+1]) then ( temp := temp + 1 ) else ( con := true ; break ) ) ; i := i + 1 ) ; if (not(con)) then ( ans := ans + 1 ; start := temp ) else ( start := start + 1 ) ) ; skip ; skip ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s1=sc.nextLine(),s2=sc.nextLine(); int replace=0 ; for(int i=0 ; i<=s1.length()-s2.length(); i++){ boolean isMatched=true ; if(s1.charAt(i)==s2.charAt(0)){ for(int j=1,k=i+1 ; jsize() - s2->size() do ( ( var isMatched : boolean ; isMatched := true ; if (s1->at(i+1) = s2->at(0+1)) then ( var j : int ; j := 1 ; var k : int ; k := i + 1 ; while j < s2->size() do ( ( if (s1->at(k+1) /= s2->at(j+1)) then ( isMatched := false ; break ) else skip ) ; j := j + 1 ; k := k + 1 ) ) else isMatched := false ; ; if (isMatched) then ( replace := replace + 1 ; i := s2->size() + i - 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(replace) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { int n,m ; int[][] cost ; int[] p ; void solve(){ Scanner sc=new Scanner(System.in); while(true){ n=sc.nextInt(); m=sc.nextInt(); if(n==0 && m==0)break ; cost=new int[m][3]; for(int i=0 ; i(){ public int compare(int[] a,int[] b){ return a[2]-b[2]; } } ); int ans=0 ; for(int i=0 ; itoInteger() ; m := sc.getCurrent()->toInteger() ; if (n = 0 & m = 0) then break else skip ; cost := Integer.subrange(1,m)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < m do ( var j : int ; j := 0 ; while j < 3 do ( cost[i+1][j+1] := sc.getCurrent()->toInteger() ; ; j := j + 1 ) ; ; i := i + 1 ) ; execute init() ; cost := OclComparator.sortWith(cost, OclComparator.newOclComparator()) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := cost[i+1][0+1] ; var b : int ; b := cost[i+1][1+1] ; a := root(a) ; b := root(b) ; if (a = b) then continue else skip ; execute merge(a, b) ; ans := ans+(cost[i+1][2+1]) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); operation init() : void pre: true post: true activity: ( p := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( p[i+1] := i ; ; i := i + 1 ) ); operation root( a : int) : int pre: true post: true activity: ( if (a = p[a+1]) then return a else return p[a+1] ); operation merge( a : int, b : int) : void pre: true post: true activity: ( a := root(a) ; b := root(b) ; p[a+1] := b ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); static int n,m ; static int[][] cost ; static int[] mincost ; static boolean[] used ; public static void main(String[] args){ while(read()){ solve(); } } static boolean read(){ n=sc.nextInt(); m=sc.nextInt(); if(n==0 && m==0)return false ; cost=new int[n][n]; mincost=new int[n]; used=new boolean[n]; for(int[] formatting : cost)Arrays.fill(formatting,1<<29); Arrays.fill(mincost,1<<29); Arrays.fill(used,false); for(int i=0 ; itoInteger() ; m := sc.getCurrent()->toInteger() ; if (n = 0 & m = 0) then return false else skip ; cost := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; mincost := Integer.subrange(1,n)->collect(0) ; used := Integer.subrange(1,n)->collect(false) ; for (formatting : cost) do ( formatting := formatting->collect((1*(2->pow(29)))->oclAsType(long)) ; ) ; mincost := mincost->collect((1*(2->pow(29)))->oclAsType(long)) ; used := used->collect(false) ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; cost[a+1][b+1] := c ; cost[b+1][a+1] := c ; ) ; i := i + 1 ) ; return true ); static operation solve() : void pre: true post: true activity: ( mincost[0+1] := 0 ; var res : int ; res := 0 ; while (true) do ( var v : int ; v := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (not(used[i+1]) & (v = -1 or mincost[i+1] < mincost[v+1])) then v := i ; else skip ) ; i := i + 1 ) ; if (v = -1) then break else skip ; used[v+1] := true ; res := res+(mincost[v+1]) ; var i : int ; i := 0 ; while i < n do ( ( mincost[i+1] := Set{mincost[i+1], cost[v+1][i+1]}->min() ) ; i := i + 1 ) ; ) ; OclFile["System.out"].println(res) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; class GFG { static int getSum(int n){ int sum=0 ; while(n!=0){ sum=sum+n % 10 ; n=n/10 ; } return sum ; } static int largestDigitSumdivisior(int n){ int res=0 ; for(int i=1 ; i<=Math.sqrt(n); i++){ if(n % i==0){ res=Math.max(res,getSum(i)); res=Math.max(res,getSum(n/i)); } } return res ; } public static void main(String args[]){ int n=14 ; System.out.println(largestDigitSumdivisior(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getSum( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; while (n /= 0) do ( sum := sum + n mod 10 ; n := n / 10 ) ; return sum ); static operation largestDigitSumdivisior( n : int) : int pre: true post: true activity: ( var res : int ; res := 0 ; var i : int ; i := 1 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then ( res := Set{res, getSum(i)}->max() ; res := Set{res, getSum(n / i)}->max() ) else skip ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 14 ; OclFile["System.out"].println(largestDigitSumdivisior(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class class465 { public static void main(String arg[]){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int x=sc.nextInt(); int y=sc.nextInt(); int z=sc.nextInt(); int r=0,f=0 ; if(a>x){ f+=(a-x)/2 ; } else { r+=x-a ; } if(b>y){ f+=(b-y)/2 ; } else { r+=y-b ; } if(c>z){ f+=(c-z)/2 ; } else { r+=z-c ; } if(r<=f){ System.out.println("YES"); } else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class class465 { static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var z : int ; z := sc.getCurrent()->toInteger() ; var r : int ; r := 0 ; var f : int ; f := 0 ; if (a > x) then ( f := f+((a - x) / 2) ) else ( r := r+(x - a) ) ; if (b > y) then ( f := f+((b - y) / 2) ) else ( r := r+(y - b) ) ; if (c > z) then ( f := f+((c - z) / 2) ) else ( r := r+(z - c) ) ; if (r <= f) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int M=10000 ; for(; ; ){ int n=in.nextInt(),m=in.nextInt(); if((n | m)==0)return ; int cost[][]=new int[n][n]; int mincost[]=new int[n]; boolean use[]=new boolean[n]; int total=0 ; for(int i=0 ; imincost[j]))v=j ; if(v==-1)break ; total+=mincost[v]; use[v]=true ; for(int j=0 ; jcost[v][j])mincost[j]=cost[v][j]; } } System.out.println(total); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var M : int ; M := 10000 ; while true do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then return else skip ; var cost : Sequence(Sequence(int)) ; cost := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var mincost : Sequence(int) ; mincost := Integer.subrange(1,n)->collect(0) ; var use : Sequence(boolean) ; use := Integer.subrange(1,n)->collect(false) ; var total : int ; total := 0 ; var i : int ; i := 0 ; while i < n do ( cost[i+1] := cost[i+1]->collect(M) ; ; i := i + 1 ) ; mincost := mincost->collect(M) ; use := use->collect(false) ; var i : int ; i := 0 ; while i < n do ( cost[i+1][i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( var s : int ; s := in.getCurrent()->toInteger() ; var t : int ; t := in.getCurrent()->toInteger() ; var c : int ; c := in.getCurrent()->toInteger() ; cost[s+1][t+1] := c ; cost[t+1][s+1] := c ; ) ; i := i + 1 ) ; mincost[0+1] := 0 ; while true do ( ( var v : int ; v := -1 ; var j : int ; j := 0 ; while j < n do ( if (not(use[j+1]) & (v = -1 or mincost[v+1] > mincost[j+1])) then v := j ; else skip ; ; j := j + 1 ) ; if (v = -1) then break else skip ; total := total+(mincost[v+1]) ; use[v+1] := true ; var j : int ; j := 0 ; while j < n do ( ( if (not(use[j+1]) & mincost[j+1] > cost[v+1][j+1]) then mincost[j+1] := cost[v+1][j+1] ; else skip ) ; j := j + 1 ) ; ) ) ; OclFile["System.out"].println(total) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); int M=Integer.parseInt(sc.next()); int[] a=new int[M]; int[] b=new int[M]; int[] c=new int[M]; for(int i=0 ; idist[a[i] ]+c[i]){ dist[b[i] ]=dist[a[i] ]+c[i]; flag=true ; } } if(cnt==N-1){ ans_tmp=dist[N-1]; } if(cnt==2*N){ if(dist[N-1]toInteger() ; var M : int ; M := (sc.getCurrent())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,M)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,M)->collect(0) ; var c : Sequence(int) ; c := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( a[i+1] := (sc.getCurrent())->toInteger() - 1 ; b[i+1] := (sc.getCurrent())->toInteger() - 1 ; c[i+1] := -(sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var dist : Sequence(long) ; dist := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 1 ; while i < N do ( ( dist[i+1] := "9223372036854775807"->toLong() ) ; i := i + 1 ) ; var flag : boolean ; flag := true ; var ans_flag : int ; ans_flag := 0 ; var cnt : int ; cnt := 0 ; var ans_tmp : long ; ans_tmp := 0 ; while (flag) do ( flag := false ; var i : int ; i := 0 ; while i < M do ( ( if (dist[a[i+1]+1] /= "9223372036854775807"->toLong() & dist[b[i+1]+1] > dist[a[i+1]+1] + c[i+1]) then ( dist[b[i+1]+1] := dist[a[i+1]+1] + c[i+1] ; flag := true ) else skip ) ; i := i + 1 ) ; if (cnt = N - 1) then ( ans_tmp := dist[N - 1+1] ) else skip ; if (cnt = 2 * N) then ( if (dist[N - 1+1] < ans_tmp) then ( ans_flag := 1 ) else skip ; break ) else skip ; cnt := cnt + 1 ; ) ; if (ans_flag = 0) then ( OclFile["System.out"].println(-dist[N - 1+1]) ) else if (ans_flag = 1) then ( OclFile["System.out"].println("inf") ) else skip ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int modP=1000000007 ; static long inf=Long.MAX_VALUE ; public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); Listedges=new ArrayList<>(); for(int i=0 ; itoLong(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var edges : Sequence(E) ; edges := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := in.getCurrent()->toInteger() - 1 ; var b : int ; b := in.getCurrent()->toInteger() - 1 ; var c : long ; c := -in.getCurrent()->toInteger() ; var e : E ; e := E.newE(a, b, c) ; edges := edges->including(e) ; ) ; i := i + 1 ) ; var dist : Sequence(long) ; dist := Integer.subrange(1,n)->collect(0) ; dist := dist->collect(inf) ; dist[0+1] := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( for (e : edges) do ( ( if (dist[e.from+1] /= inf & dist[e.from+1] + e.w < dist[e.to+1]) then ( dist[e.to+1] := dist[e.from+1] + e.w ) else skip ) ) ) ; i := i + 1 ) ; var ans : long ; ans := -dist[n - 1+1] ; var i : int ; i := 0 ; while i < n do ( ( for (e : edges) do ( ( if (dist[e.from+1] /= inf & dist[e.from+1] + e.w < dist[e.to+1]) then ( dist[e.to+1] := dist[e.from+1] + e.w ) else skip ) ) ) ; i := i + 1 ) ; if (ans < -dist[n - 1+1]) then ( execute print("inf") ) else ( execute print(ans) ) ; ); static operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation print( i : int) : void pre: true post: true activity: ( OclFile["System.out"].println(i) ); static operation print( i : long) : void pre: true post: true activity: ( OclFile["System.out"].println(i) ); } class E { attribute from : int; attribute w : long; static operation newE( from : int, to : int, w : long) : E pre: true post: true activity: ( var self : E ; self := createE(); self.initialise(from, to,w); return self ); operation initialise( from : int, to : int, w : long) : void pre: true post: true activity: ( self.from := from ; self.to := to ; self.w := w ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; class Main { static int n ; static int m ; static Edge[] e ; static long dis[]; static final long inf=1000000000000000l ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); n=sc.nextInt(); m=sc.nextInt(); e=new Edge[m]; dis=new long[n]; Arrays.fill(dis,inf); dis[0]=0 ; for(int i=0 ; idis[e[j] .from]+e[j] .cost){ dis[e[j] .to]=dis[e[j] .from]+e[j] .cost ; if(i==n && e[j] .to==n-1){ return true ; } } } } return false ; } } class Edge { int from ; int to ; long cost ; Edge(int from,int to,long cost){ this.from=from ; this.to=to ; this.cost=cost ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute n : int; static attribute m : int; static attribute e : Sequence(Edge); static attribute dis : Sequence(long); static attribute inf : long := 1000000000000000l; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; e := Integer.subrange(1,m)->collect(null) ; dis := Integer.subrange(1,n)->collect(0) ; dis := dis->collect(inf) ; dis[0+1] := 0 ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; e[i+1] := Edge.newEdge(a - 1, b - 1, -c) ) ; i := i + 1 ) ; skip ; if (bellmanFord()) then ( OclFile["System.out"].print("inf") ) else ( OclFile["System.out"].println(-dis[n - 1+1]) ) ; ); static operation bellmanFord() : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < n + 1 do ( ( var j : int ; j := 0 ; while j < m do ( ( if (dis[e[j+1].from+1] /= inf & dis[e[j+1].to+1] > dis[e[j+1].from+1] + e[j+1].cost) then ( dis[e[j+1].to+1] := dis[e[j+1].from+1] + e[j+1].cost ; if (i = n & e[j+1].to = n - 1) then ( return true ) else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return false ); } class Edge { attribute from : int; attribute to : int; attribute cost : long; static operation newEdge( from : int, to : int, cost : long) : Edge pre: true post: true activity: ( var self : Edge ; self := createEdge(); self.initialise(from, to,cost); return self ); operation initialise( from : int, to : int, cost : long) : void pre: true post: true activity: ( self.from := from ; self.to := to ; self.cost := cost ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static class edge { int from,to ; long cost ; } public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); int m=Integer.parseInt(str[1]); edge[] es=new edge[m]; for(int i=0 ; isplit(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var m : int ; m := (str[1+1])->toInteger() ; var es : Sequence(edge) ; es := Integer.subrange(1,m)->collect(null) ; var i : int ; i := 0 ; while i < m do ( ( str := br.readLine()->split(" ") ; var ed : edge ; ed := edge.newedge() ; ed.from := (str[0+1])->toInteger() - 1 ; ed.to := (str[1+1])->toInteger() - 1 ; ed.cost := -(str[2+1])->toLong() ; es[i+1] := ed ; ) ; i := i + 1 ) ; var dist : Sequence(long) ; dist := Integer.subrange(1,n)->collect(0) ; dist := dist->collect("9223372036854775807"->toLong() / 2) ; dist[0+1] := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( var ed : edge ; ed := es[j+1] ; if (dist[ed.from+1] < "9223372036854775807"->toLong() / 3) then dist[ed.to+1] := Set{dist[ed.to+1], dist[ed.from+1] + ed.cost}->min() ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : long ; ans := dist[n - 1+1] ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( var ed : edge ; ed := es[j+1] ; if (dist[ed.from+1] < "9223372036854775807"->toLong() / 3) then dist[ed.to+1] := Set{dist[ed.to+1], dist[ed.from+1] + ed.cost}->min() ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (ans /= dist[n - 1+1]) then OclFile["System.out"].println("inf") else OclFile["System.out"].println(-ans) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int M=scanner.nextInt(); final long INF=-1_000_000_000_000_000L ; long[] dist=new long[N]; for(int i=1 ; iINF){ long newValue=dist[from]+cost ; if(newValue>dist[to])dist[to]=newValue ; } } } boolean[] negative=new boolean[N]; for(int i=0 ; iINF && dist[from]+cost>dist[to])negative[from]=true ; if(negative[from])negative[to]=true ; } } if(negative[N-1])System.out.println("inf"); else System.out.println(dist[N-1]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; var M : int ; M := scanner.getCurrent()->toInteger() ; var INF : long ; INF := -1_000_000_000_000_000L ; var dist : Sequence(long) ; dist := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 1 ; while i < N do ( dist[i+1] := INF ; ; i := i + 1 ) ; var edges : Sequence(Sequence(int)) ; edges := Integer.subrange(1,M)->collect(Integer.subrange(1,2)->collect(0)) ; var costs : Sequence(int) ; costs := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( edges[i+1] := Sequence{scanner.getCurrent()->toInteger() - 1,scanner.getCurrent()->toInteger() - 1} ; costs[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( var j : int ; j := 0 ; while j < M do ( ( var from : int ; from := edges[j+1][0+1] ; var to : int ; to := edges[j+1][1+1] ; var cost : int ; cost := costs[j+1] ; if (dist[from+1] > INF) then ( var newValue : long ; newValue := dist[from+1] + cost ; if (newValue > dist[to+1]) then dist[to+1] := newValue ; else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var negative : Sequence(boolean) ; negative := Integer.subrange(1,N)->collect(false) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( var from : int ; from := edges[j+1][0+1] ; var to : int ; to := edges[j+1][1+1] ; var cost : int ; cost := costs[j+1] ; if (dist[from+1] > INF & dist[from+1] + cost > dist[to+1]) then negative[from+1] := true ; else skip ; if (negative[from+1]) then negative[to+1] := true ; else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (negative[N - 1+1]) then OclFile["System.out"].println("inf") else OclFile["System.out"].println(dist[N - 1+1]) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void MinSteps(int SourceX,int SourceY,int DestX,int DestY){ System.out.println(Math.max(Math.abs(SourceX-DestX),Math.abs(SourceY-DestY))); while((SourceX!=DestX)||(SourceY!=DestY)){ if(SourceXDestX){ System.out.println('D'); SourceX--; } if(SourceY>DestY){ System.out.print('L'); SourceY--; } if(SourceYmax()) ; while ((SourceX /= DestX) or (SourceY /= DestY)) do ( if (SourceX < DestX) then ( OclFile["System.out"].print('U') ; SourceX := SourceX + 1 ) else skip ; if (SourceX > DestX) then ( OclFile["System.out"].println('D') ; SourceX := SourceX - 1 ) else skip ; if (SourceY > DestY) then ( OclFile["System.out"].print('L') ; SourceY := SourceY - 1 ) else skip ; if (SourceY < DestY) then ( OclFile["System.out"].print('R') ; SourceY := SourceY + 1 ) else skip ; OclFile["System.out"].println() ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sourceX : int ; sourceX := 4 ; var sourceY : int ; sourceY := 4 ; var destinationX : int ; destinationX := 7 ; var destinationY : int ; destinationY := 0 ; execute MinSteps(sourceX, sourceY, destinationX, destinationY) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B744 { public static void main(String[] args){ List[] L=new List[29]; int[] ans=new int[1009]; Arrays.fill(ans,1000000000); for(int i=0 ; i<20 ; i++)L[i]=new ArrayList(); for(int i=0 ; i<10 ; i++){ int tmp=1<collect(null) ; var ans : Sequence(int) ; ans := Integer.subrange(1,1009)->collect(0) ; ans := ans->collect(1000000000) ; var i : int ; i := 0 ; while i < 20 do ( L[i+1] := Sequence{} ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 10 do ( ( var tmp : int ; tmp := (1*(2->pow(i)))->oclAsType(long) ; var j : int ; j := 1 ; while j < 1024 do ( ( if ((MathLib.bitwiseAnd(tmp,j)) = 0) then L[i+1]->excludes(j) ; else L[i + 10+1]->excludes(j) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < 20 do ( ( var query : Sequence ; query := Sequence{} ; var have : Sequence(int) ; have := Integer.subrange(1,1009)->collect(0) ; have := have->collect(0) ; var j : int ; j := 0 ; while j < L[i+1]->size() do ( if (L[i+1]->at(j+1)->oclAsType(int) <= n) then query := query->including(L[i+1]->at(j+1)) ; else skip ; ; j := j + 1 ) ; if (query->size() = 0) then continue else skip ; OclFile["System.out"].println(query->size()) ; var j : int ; j := 0 ; while j < query->size() do ( if (query->at(j+1)->oclAsType(int) <= n) then ( OclFile["System.out"].print(query->at(j+1) + " ") ; have[query->at(j+1)->oclAsType(int)+1] := 1 ) else skip ; ; j := j + 1 ) ; var j : int ; j := 1 ; while j <= n do ( ( var tmp : int ; tmp := in.getCurrent()->toInteger() ; if (have[j+1] = 0) then ans[j+1] := Set{ans[j+1], tmp}->min() ; else skip ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(-1) ; var i : int ; i := 1 ; while i <= n do ( OclFile["System.out"].print(ans[i+1] + " ") ; ; i := i + 1 ) ; OclFile["System.out"].flush() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(),m=scanner.nextInt(),k=scanner.nextInt(); scanner.nextLine(); int[][][] planets=new int[n][m][3]; for(int i=0 ; i0){ int max=0 ; int maxIndex=-1 ; for(int i=0 ; imax){ max=planetJ[i][1]-planetI[i][0]; maxIndex=i ; } } if(maxIndex<0)break ; flag[maxIndex]=true ; int num=Math.min(planetI[maxIndex][2],k); k-=num ; sum+=num*max ; } return Math.max(sum,maxProfit); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; skip ; var planets : Sequence(Sequence(Sequence(int))) ; planets := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(Integer.subrange(1,3)->collect(0))) ; var i : int ; i := 0 ; while i < n do ( ( var planet : Sequence(Sequence(int)) ; planet := planets[i+1] ; skip ; var j : int ; j := 0 ; while j < m do ( ( planet[j+1][0+1] := scanner.getCurrent()->toInteger() ; planet[j+1][1+1] := scanner.getCurrent()->toInteger() ; planet[j+1][2+1] := scanner.getCurrent()->toInteger() ; skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var maxProfit : int ; maxProfit := 0 ; var i : int ; i := 0 ; while i < planets->size() do ( ( var j : int ; j := 0 ; while j < planets->size() do ( ( if (i = j) then continue else skip ; maxProfit := calProfit(planets[i+1], planets[j+1], maxProfit, k) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(maxProfit) ; ); static operation calProfit( planetI : Sequence(Sequence(int)), planetJ : Sequence(Sequence(int)), maxProfit : int, k : int) : int pre: true post: true activity: ( var flag : Sequence(boolean) ; flag := Integer.subrange(1,planetI->size())->collect(false) ; var sum : int ; sum := 0 ; while (k > 0) do ( var max : int ; max := 0 ; var maxIndex : int ; maxIndex := -1 ; var i : int ; i := 0 ; while i < planetI->size() do ( ( if (flag[i+1]) then continue else skip ; if (planetJ[i+1][1+1] - planetI[i+1][0+1] > max) then ( max := planetJ[i+1][1+1] - planetI[i+1][0+1] ; maxIndex := i ) else skip ) ; i := i + 1 ) ; if (maxIndex < 0) then break else skip ; flag[maxIndex+1] := true ; var num : int ; num := Set{planetI[maxIndex+1][2+1], k}->min() ; k := k-(num) ; sum := sum+(num * max) ; ) ; return Set{sum, maxProfit}->max() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int k ; public static int[][] a=new int[1005][1005]; public static int[][] b=new int[1005][1005]; public static int[][] c=new int[1005][1005]; public static int n ; public static int m ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); n=scanner.nextInt(); m=scanner.nextInt(); k=scanner.nextInt(); int ans=0 ; for(int i=0 ; i0){ int flag=0 ; int maxv=0,maxp=0 ; for(int i=0 ; i0)continue ; if(b[y][i]-a[x][i]>maxv){ maxv=b[y][i]-a[x][i]; maxp=i ; flag=1 ; } } if(flag==0)break ; int num=Math.min(last,c[x][maxp]); ans+=num*maxv ; vis[maxp]=1 ; last-=num ; } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute k : int; static attribute a : Sequence(Sequence(int)) := Integer.subrange(1,1005)->collect(Integer.subrange(1,1005)->collect(0)); static attribute b : Sequence(Sequence(int)) := Integer.subrange(1,1005)->collect(Integer.subrange(1,1005)->collect(0)); static attribute c : Sequence(Sequence(int)) := Integer.subrange(1,1005)->collect(Integer.subrange(1,1005)->collect(0)); static attribute n : int; static attribute m : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := scanner.getCurrent()->toInteger() ; m := scanner.getCurrent()->toInteger() ; k := scanner.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( skip ; var name : String ; name := scanner.nextLine() ; var j : int ; j := 0 ; while j < m do ( ( a[i+1][j+1] := scanner.getCurrent()->toInteger() ; b[i+1][j+1] := scanner.getCurrent()->toInteger() ; c[i+1][j+1] := scanner.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( ans := Set{ans, cal(i, j)}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation cal( x : int, y : int) : int pre: true post: true activity: ( var vis : Sequence(int) ; vis := Integer.subrange(1,1005)->collect(0) ; var last : int ; last := k ; var ans : int ; ans := 0 ; while (last > 0) do ( var flag : int ; flag := 0 ; var maxv : int ; maxv := 0 ; var maxp : int ; maxp := 0 ; var i : int ; i := 0 ; while i < m do ( ( if (vis[i+1] > 0) then continue else skip ; if (b[y+1][i+1] - a[x+1][i+1] > maxv) then ( maxv := b[y+1][i+1] - a[x+1][i+1] ; maxp := i ; flag := 1 ) else skip ) ; i := i + 1 ) ; if (flag = 0) then break else skip ; var num : int ; num := Set{last, c[x+1][maxp+1]}->min() ; ans := ans+(num * maxv) ; vis[maxp+1] := 1 ; last := last-(num) ; ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public String toLowerCase(String str){ return str.toLowerCase(); } } ------------------------------------------------------------ OCL File: --------- class Solution { operation toLowerCase( str : String) : String pre: true post: true activity: ( return str->toLowerCase() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int OR(int a[],int n){ int ans=a[0]; int i ; for(i=1 ; isize() ; OclFile["System.out"].println(OR(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long N=sc.nextLong(); long A=sc.nextLong(); long B=sc.nextLong(); long C=sc.nextLong(); long D=sc.nextLong(); long t=Math.abs(A-B); String ans="NO" ; for(long i=0 ; i<=N-1 ; i++){ if((t<=i*D-(N-1-i)*C)&&(t>=i*C-(N-1-i)*D))ans="YES" ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := sc.getCurrent()->toLong() ; var A : long ; A := sc.getCurrent()->toLong() ; var B : long ; B := sc.getCurrent()->toLong() ; var C : long ; C := sc.getCurrent()->toLong() ; var D : long ; D := sc.getCurrent()->toLong() ; var t : long ; t := if A - B < 0 then -(A - B) else A - B endif ; var ans : String ; ans := "NO" ; var i : long ; i := 0 ; while i <= N - 1 do ( ( if ((t <= i * D - (N - 1 - (i)->char2byte()) * C) & (t >= i * C - (N - 1 - (i)->char2byte()) * D)) then ans := "YES" ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { private static boolean debug=false ; private static boolean elapsed=true ; private static PrintWriter _out=new PrintWriter(System.out); private static PrintWriter _err=new PrintWriter(System.err); private void solve(Scanner sc){ int N=sc.nextInt(); long A=sc.nextInt(); long B=sc.nextInt(); long C=sc.nextInt(); long D=sc.nextInt(); for(int m=0 ; m<=N ; ++m){ long left=C*(N-1-m)-D*m ; long right=-C*m+(N-1-m)*D ; if(left<=B-A && B-A<=right){ _out.println("YES"); return ; } } _out.println("NO"); } private static BigInteger C(long n,long r){ BigInteger res=BigInteger.ONE ; for(long i=n ; i>n-r ; --i){ res=res.multiply(BigInteger.valueOf(i)); } for(long i=r ; i>1 ; --i){ res=res.divide(BigInteger.valueOf(i)); } return res ; } private static BigInteger P(long n,long r){ BigInteger res=BigInteger.ONE ; for(long i=n ; i>n-r ; --i){ res=res.multiply(BigInteger.valueOf(i)); } return res ; } public static void main(String[] args){ long S=System.currentTimeMillis(); Scanner sc=new Scanner(System.in); new Main().solve(sc); _out.flush(); long G=System.currentTimeMillis(); if(elapsed){ _err.println((G-S)+"ms"); } _err.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute debug : boolean := false; static attribute elapsed : boolean := true; static attribute _out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static attribute _err : OclFile := OclFile.newOclFile_Write(OclFile["System.err"]); operation solve( sc : OclFile) : void pre: true post: true activity: ( var N : int ; N := sc.nextInt() ; var A : long ; A := sc.nextInt() ; var B : long ; B := sc.nextInt() ; var C : long ; C := sc.nextInt() ; var D : long ; D := sc.nextInt() ; var m : int ; m := 0 ; while m <= N do ( ( var left : long ; left := C * (N - 1 - m) - D * m ; var right : long ; right := -C * m + (N - 1 - m) * D ; if (left <= B - A & B - A <= right) then ( skip ; return ) else skip ) ; m := m + 1 ) ; skip ; ); static operation C( n : long, r : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; var i : long ; i := n ; while i > n - r do ( ( res := res.multiply((i + "")->toLong()) ) ; i := i - 1 ) ; var i : long ; i := r ; while i > 1 do ( ( res := res.divide((i + "")->toLong()) ) ; i := i - 1 ) ; return res ); static operation P( n : long, r : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; var i : long ; i := n ; while i > n - r do ( ( res := res.multiply((i + "")->toLong()) ) ; i := i - 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : long ; S := OclDate.getSystemTime() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; Main.newMain().solve(sc) ; skip ; var G : long ; G := OclDate.getSystemTime() ; if (elapsed) then ( skip ) else skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Main main=new Main(); main.solveB(); } private void solveB(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long A=sc.nextLong(); long B=sc.nextLong(); long C=sc.nextLong(); long D=sc.nextLong(); if(judge(N,A,B,C,D)){ System.out.println("YES"); } else { System.out.println("NO"); } } private boolean judge(int N,long A,long B,long C,long D){ for(int minus=0 ; minustoInteger() ; var A : long ; A := sc.getCurrent()->toLong() ; var B : long ; B := sc.getCurrent()->toLong() ; var C : long ; C := sc.getCurrent()->toLong() ; var D : long ; D := sc.getCurrent()->toLong() ; if (judge(N, A, B, C, D)) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); operation judge( N : int, A : long, B : long, C : long, D : long) : boolean pre: true post: true activity: ( var minus : int ; minus := 0 ; while minus < N do ( ( var min : long ; min := -D * minus + C * (N - 1 - minus) ; var max : long ; max := -C * minus + D * (N - 1 - minus) ; if (min <= B - A & B - A <= max) then ( return true ) else skip ) ; minus := minus + 1 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] sa=br.readLine().split(" "); long n=Integer.parseInt(sa[0]); long a=Integer.parseInt(sa[1]); long b=Integer.parseInt(sa[2]); long c=Integer.parseInt(sa[3]); long d=Integer.parseInt(sa[4]); br.close(); long ba=b-a ; for(int i=0 ; isplit(" ") ; var n : long ; n := (sa[0+1])->toInteger() ; var a : long ; a := (sa[1+1])->toInteger() ; var b : long ; b := (sa[2+1])->toInteger() ; var c : long ; c := (sa[3+1])->toInteger() ; var d : long ; d := (sa[4+1])->toInteger() ; skip ; var ba : long ; ba := b - a ; var i : int ; i := 0 ; while i < n do ( ( if (c * i - d * (n - 1 - i) <= ba & ba <= d * i - c * (n - 1 - i)) then ( OclFile["System.out"].println("YES") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public void exec()throws IOException { Scanner input=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); long n=input.nextInt(); long a=input.nextInt(); long b=input.nextInt(); long c=input.nextInt(); long d=input.nextInt(); boolean ret=false ; for(long m=0 ; mtoInteger() ; var a : long ; a := input.getCurrent()->toInteger() ; var b : long ; b := input.getCurrent()->toInteger() ; var c : long ; c := input.getCurrent()->toInteger() ; var d : long ; d := input.getCurrent()->toInteger() ; var ret : boolean ; ret := false ; var m : long ; m := 0 ; while m < n do ( ( if (c * (n - 1 - m) - d * m <= b - a & b - a <= d * (n - 1 - m) - c * m) then ( ret := true ; break ) else skip ) ; m := m + 1 ) ; skip ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().exec() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.System.out ; public class pre125 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader obj=new FastReader(); int n=obj.nextInt(),d=obj.nextInt(); int k=obj.nextInt(); while(k--!=0){ int x=obj.nextInt(),y=obj.nextInt(); boolean ans=true ; ans &=(x-y<=d); ans &=(x+y<=2*n-d); ans &=(x-y>=-d); ans &=(x+y>=d); out.println(ans ? "YES" : "NO"); } } } ------------------------------------------------------------ OCL File: --------- class pre125 { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : FastReader ; obj := FastReader.newFastReader() ; var n : int ; n := obj.nextInt() ; var d : int ; d := obj.nextInt() ; var k : int ; k := obj.nextInt() ; while (k /= 0) do ( skip ; ( var x : int ; x := obj.nextInt() ; var y : int ; y := obj.nextInt() ; var ans : boolean ; ans := true ; ans := MathLib.bitwiseAnd(ans, (x - y <= d)) ; ans := MathLib.bitwiseAnd(ans, (x + y <= 2 * n - d)) ; ans := MathLib.bitwiseAnd(ans, (x - y >= -d)) ; ans := MathLib.bitwiseAnd(ans, (x + y >= d)) ; out.println(if ans then "YES" else "NO" endif) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class C { static final int INF=Integer.MAX_VALUE ; public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[][][] value=new int[10][2][n+1]; Listl=new ArrayList<>(); for(int bitpos=0 ; bitpos>bitpos))==bitval)l.add(i); } if(l.isEmpty()){ for(int i=1 ; i<=n ; ++i)value[bitpos][bitval][i]=INF ; } else { System.out.println(l.size()); for(int i : l)System.out.print(i+" "); System.out.println(); for(int i=1 ; i<=n ; ++i)value[bitpos][bitval][i]=in.nextInt(); } } System.out.println(-1); for(int i=1 ; i<=n ; ++i){ int result=INF ; for(int bitpos=0 ; bitpos>bitpos)][i]); System.out.print(result+" "); } } } ------------------------------------------------------------ OCL File: --------- class C { static attribute INF : int := 2147483647; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var value : Sequence(Sequence(Sequence(int))) ; value := Integer.subrange(1,10)->collect(Integer.subrange(1,2)->collect(Integer.subrange(1,n + 1)->collect(0))) ; var l : Sequence(int) ; l := Sequence{} ; var bitpos : int ; bitpos := 0 ; while bitpos < value->size() do ( var bitval : int ; bitval := 0 ; while bitval < 2 do ( ( l := l->intersection(Set{}) ; var i : int ; i := 1 ; while i <= n do ( ( if ((MathLib.bitwiseAnd(1,((i/(2->pow(bitpos)))->oclAsType(long)))) = bitval) then l := l->including(i) ; else skip ) ; i := i + 1 ) ; if (l->isEmpty()) then ( var i : int ; i := 1 ; while i <= n do ( value[bitpos+1][bitval+1][i+1] := INF ; ; i := i + 1 ) ) else ( OclFile["System.out"].println(l->size()) ; for (i : l) do ( OclFile["System.out"].print(i + " ") ; ) ; OclFile["System.out"].println() ; var i : int ; i := 1 ; while i <= n do ( value[bitpos+1][bitval+1][i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ) ) ; bitval := bitval + 1 ) ; ; bitpos := bitpos + 1 ) ; OclFile["System.out"].println(-1) ; var i : int ; i := 1 ; while i <= n do ( ( var result : int ; result := INF ; var bitpos : int ; bitpos := 0 ; while bitpos < value->size() do ( result := Set{result, value[bitpos+1][MathLib.bitwiseAnd(1,-(((i/(2->pow(bitpos)))->oclAsType(long)) + 1))+1][i+1]}->min() ; ; bitpos := bitpos + 1 ) ; OclFile["System.out"].print(result + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class main { public static void main(String[] args){ Scanner c=new Scanner(System.in); double n=c.nextDouble(); double d=c.nextDouble(); double m=c.nextDouble(); double area=Math.abs((Math.sqrt(2)*Math.sqrt(2)*(n-d)*(d))); for(int i=0 ; itoReal() ; var d : double ; d := c.getCurrent()->toReal() ; var m : double ; m := c.getCurrent()->toReal() ; var area : double ; area := if ((2)->sqrt() * (2)->sqrt() * (n - d) * (d)) < 0 then -(((2)->sqrt() * (2)->sqrt() * (n - d) * (d))) else ((2)->sqrt() * (2)->sqrt() * (n - d) * (d)) endif ; var i : int ; i := 0 ; while i < m do ( ( var x : double ; x := c.getCurrent()->toReal() ; var y : double ; y := c.getCurrent()->toReal() ; var area1 : double ; area1 := (if (-(d * x) + (d * d) - (d * y)) < 0 then -((-(d * x) + (d * d) - (d * y))) else (-(d * x) + (d * d) - (d * y)) endif) / 2 ; var area2 : double ; area2 := (if (x * (d - n) + d * (n - d - y) + n * y) < 0 then -((x * (d - n) + d * (n - d - y) + n * y)) else (x * (d - n) + d * (n - d - y) + n * y) endif) / 2 ; var area3 : double ; area3 := (if x * (-d) + n * (n - y) + (n - d) * (y + d - n) < 0 then -(x * (-d) + n * (n - y) + (n - d) * (y + d - n)) else x * (-d) + n * (n - y) + (n - d) * (y + d - n) endif) / 2 ; var area4 : double ; area4 := (if x * (d - n) + (n - d) * (y - d) < 0 then -(x * (d - n) + (n - d) * (y - d)) else x * (d - n) + (n - d) * (y - d) endif) / 2 ; if ((area1 + area2 + area3 + area4) <= area) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class CF_VasyaAndCornfield { static BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out=new PrintWriter(System.out); static void solve()throws Exception { StringTokenizer st=new StringTokenizer(bf.readLine()); int n=Integer.parseInt(st.nextToken()); int d=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(bf.readLine()); for(int i=0 ; i=-d && x-y<=d && x+y>=d && x+y<=2*n-d){ out.println("YES"); } else { out.println("NO"); } } } public static void main(String[] args)throws Exception { int tc=1 ; while(tc-->0){ solve(); } out.flush(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class CF_VasyaAndCornfield { static attribute bf : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation solve() : void pre: true post: true activity: ( var st : OclIterator ; st := OclIterator.newOclIterator_String(bf.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var d : int ; d := (st.next())->toInteger() ; var m : int ; m := (bf.readLine())->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( st := OclIterator.newOclIterator_String(bf.readLine()) ; var x : int ; x := (st.next())->toInteger() ; var y : int ; y := (st.next())->toInteger() ; if (x - y >= -d & x - y <= d & x + y >= d & x + y <= 2 * n - d) then ( skip ) else ( skip ) ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var tc : int ; tc := 1 ; while (tc > 0) do ( tc := tc - 1 ; skip ; ( execute solve() ) ; ) ; skip ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countDigit(long n){ if(n==0)return 0 ; return 1+countDigit(n/10); } public static void main(String[] args){ long n=345289467 ; System.out.print("Number of digits : "+countDigit(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countDigit( n : long) : int pre: true post: true activity: ( if (n = 0) then return 0 else skip ; return 1 + countDigit(n / 10) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 345289467 ; OclFile["System.out"].print("Number of digits : " + countDigit(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countDigit(long n){ int count=0 ; while(n!=0){ n=n/10 ; ++count ; } return count ; } public static void main(String[] args){ long n=345289467 ; System.out.print("Number of digits : "+countDigit(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countDigit( n : long) : int pre: true post: true activity: ( var count : int ; count := 0 ; while (n /= 0) do ( n := n / 10 ; count := count + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 345289467 ; OclFile["System.out"].print("Number of digits : " + countDigit(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _1032A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),k=sc.nextInt(); HashMapm=new HashMap<>(); int maxVal=Integer.MIN_VALUE ; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var m : Map(int,int) ; m := Map{} ; var maxVal : int ; maxVal := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; if (m->keys()->includes(v)) then ( m := m->union(Map{v |-> m->at(v) + 1}) ) else ( m := m->union(Map{v |-> 1}) ) ; maxVal := Set{maxVal, m->at(v)}->max() ) ; i := i + 1 ) ; var count : int ; count := k * ((maxVal + k - 1) / k) * m.size() ; OclFile["System.out"].println(count - n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; class CountDistinctWindow { static void countDistinct(int arr[],int k){ HashMaphM=new HashMap(); int dist_count=0 ; for(int i=0 ; iat(arr[i+1]) = null) then ( hM := hM->union(Map{arr[i+1] |-> 1}) ; dist_count := dist_count + 1 ) else ( var count : int ; count := hM->at(arr[i+1]) ; hM := hM->union(Map{arr[i+1] |-> count + 1}) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dist_count) ; var i : int ; i := k ; while i < arr->size() do ( ( if (hM->at(arr[i - k+1]) = 1) then ( hM := hM->antirestrict(Set{arr[i - k+1]}) ; dist_count := dist_count - 1 ) else ( var count : int ; count := hM->at(arr[i - k+1]) ; hM := hM->union(Map{arr[i - k+1] |-> count - 1}) ) ; if (hM->at(arr[i+1]) = null) then ( hM := hM->union(Map{arr[i+1] |-> 1}) ; dist_count := dist_count + 1 ) else ( var count : int ; count := hM->at(arr[i+1]) ; hM := hM->union(Map{arr[i+1] |-> count + 1}) ) ; OclFile["System.out"].println(dist_count) ) ; i := i + 1 ) ; ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,1,3,4,2,3} ; var k : int ; k := 4 ; execute countDistinct(arr, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countDigit(long n){ return(int)Math.floor(Math.log10(n)+1); } public static void main(String[] args){ long n=345289467 ; System.out.print("Number of digits : "+countDigit(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countDigit( n : long) : int pre: true post: true activity: ( return ((n)->log10() + 1)->floor()->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 345289467 ; OclFile["System.out"].print("Number of digits : " + countDigit(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A1310 { public static void main(String args[])throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); TreeMap>map=new TreeMap<>(); int a[][]=new int[2][n]; for(int i=0 ; i()); } map.get(a[0][i]).add(a[1][i]); } HashMapfreq=new HashMap<>(); TreeSetset=new TreeSet<>(); long time=0,sum=0 ; int curr=0,size=map.size(); while(! set.isEmpty()|| size>0){ if(set.isEmpty()){ curr=map.firstKey(); } else { int max=set.last(); sum-=max ; if(freq.get(max)==1){ set.remove(max); freq.remove(max); } else { freq.put(max,freq.get(max)-1); } time+=sum ; } if(map.containsKey(curr)){ for(int i : map.get(curr)){ set.add(i); sum+=i ; if(! freq.containsKey(i)){ freq.put(i,0); } freq.put(i,freq.get(i)+1); } map.remove(curr); size--; } curr++; } System.out.println(time); } } ------------------------------------------------------------ OCL File: --------- class A1310 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var map : Map(int,Sequence(int)) ; map := Map{} ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,2)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( a[0+1][i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( a[1+1][i+1] := sc.getCurrent()->toInteger() ; if (not(map->keys()->includes(a[0+1][i+1]))) then ( map := map->union(Map{a[0+1][i+1] |-> Sequence{}}) ) else skip ; map->at(a[0+1][i+1])->excludes(a[1+1][i+1]) ) ; i := i + 1 ) ; var freq : Map(int,int) ; freq := Map{} ; var set : Set(int) ; set := Set{} ; var time : long ; time := 0 ; var sum : long ; sum := 0 ; var curr : int ; curr := 0 ; var size : int ; size := map.size() ; while (not(set->isEmpty()) or size > 0) do ( if (set->isEmpty()) then ( curr := map->keys()->min() ) else ( var max : int ; max := set->last() ; sum := sum-(max) ; if (freq->at(max) = 1) then ( set := set->excludingAt(max+1) ; freq := freq->antirestrict(Set{max}) ) else ( freq := freq->union(Map{max |-> freq->at(max) - 1}) ) ; time := time+(sum) ) ; if (map->keys()->includes(curr)) then ( for (i : map->at(curr)) do ( ( set := set->including(i) ; sum := sum+(i) ; if (not(freq->keys()->includes(i))) then ( freq := freq->union(Map{i |-> 0}) ) else skip ; freq := freq->union(Map{i |-> freq->at(i) + 1}) ) ) ; map := map->antirestrict(Set{curr}) ; size := size - 1 ) else skip ; curr := curr + 1 ) ; OclFile["System.out"].println(time) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class reccommendations { public static void main(String[] args){ Scanner x=new Scanner(System.in); int n=x.nextInt(); int[] arr=new int[n]; News[] newsarr=new News[n]; for(int i=0 ; ivalues=new PriorityQueue(); int val=0 ; long sum=0 ; for(int i=0 ; i<=n ; i++){ while(! values.isEmpty()&&(i==n || newsarr[i] .num>val)){ int max=-values.poll(); total-=max ; sum+=total ; val++; } if(i==n)break ; val=newsarr[i] .num ; values.add(-newsarr[i] .cost); total+=newsarr[i] .cost ; } System.out.println(sum); } } class News implements Comparable{ public int num ; public int cost ; public News(int a,int b){ num=a ; cost=b ; } public int compareTo(News other){ return this.num-other.num ; } } ------------------------------------------------------------ OCL File: --------- class reccommendations { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : OclFile ; x := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := x.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var newsarr : Sequence(News) ; newsarr := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := x.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( newsarr[i+1] := News.newNews(arr[i+1], x.getCurrent()->toInteger()) ) ; i := i + 1 ) ; newsarr := newsarr->sort() ; var total : long ; total := 0 ; var values : Sequence(int) ; values := Sequence{} ; var val : int ; val := 0 ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i <= n do ( ( while (not(values->isEmpty()) & (i = n or newsarr[i+1].num > val)) do ( var max : int ; max := -values->min() ; total := total-(max) ; sum := sum+(total) ; val := val + 1 ) ; if (i = n) then break else skip ; val := newsarr[i+1].num ; values := values->including(-newsarr[i+1].cost) ; total := total+(newsarr[i+1].cost) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } class News implements Comparable { attribute num : int; attribute cost : int; static operation newNews( a : int, b : int) : News pre: true post: true activity: ( var self : News ; self := createNews(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( num := a ; cost := b ); operation compareTo( other : News) : int pre: true post: true activity: ( return self.num - other.num ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class A { public static int power(Long a){ int res=0 ; while(a>0){ res++; a=a/10 ; } return res ; } public static long mult(Long a){ int pow=power(a); long max=0 ; for(int j=0 ; j 0) do ( res := res + 1 ; a := a / 10 ) ; return res ); static operation mult( a : long) : long pre: true post: true activity: ( var pow : int ; pow := power(a) ; var max : long ; max := 0 ; var j : int ; j := 0 ; while j < pow do ( ( max := max * 10 + 9 ) ; j := j + 1 ) ; return a * (max - a) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var l : long ; l := in.getCurrent()->toLong() ; var r : long ; r := in.getCurrent()->toLong() ; var res : long ; res := 0 ; var maxxes : Sequence(long) ; maxxes := Integer.subrange(1,10)->collect(0) ; var temp : long ; temp := 0 ; var i : int ; i := 0 ; while i < 10 do ( ( temp := temp * 10 + 9 ; maxxes[i+1] := temp / 2 * (temp - temp / 2) ) ; i := i + 1 ) ; res := Set{mult(l), res}->max() ; res := Set{mult(r), res}->max() ; temp := 0 ; var i : int ; i := 0 ; while i < 10 do ( ( temp := temp * 10 + 9 ; if (l <= temp / 2 & temp / 2 <= r) then res := Set{maxxes[i+1], res}->max() ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); AizuFIbo solver=new AizuFIbo(); solver.solve(1,in,out); out.close(); } static class AizuFIbo { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); if(n==0 || n==1){ out.println("1"); } else { long[] a=new long[n+1]; a[0]=1 ; a[1]=1 ; for(int i=2 ; i<=n ; i++){ a[i]=a[i-1]+a[i-2]; } out.printf("%d\n",a[n]); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : AizuFIbo ; solver := AizuFIbo.newAizuFIbo() ; solver.solve(1, in, out) ; skip ; ); static class AizuFIbo { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; if (n = 0 or n = 1) then ( skip ) else ( var a : Sequence(long) ; a := Integer.subrange(1,n + 1)->collect(0) ; a[0+1] := 1 ; a[1+1] := 1 ; var i : int ; i := 2 ; while i <= n do ( ( a[i+1] := a[i - 1+1] + a[i - 2+1] ) ; i := i + 1 ) ; skip ; ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { private static HashMapfibs=new HashMap<>(); public static void main(String[] args){ fibs.put(0,1); fibs.put(1,1); Scanner in=new Scanner(System.in); int n=in.nextInt(); System.out.println(fibonacci(n)); in.close(); } private static int fibonacci(int n){ if(! fibs.containsKey(n)){ fibs.put(n,fibonacci(n-1)+fibonacci(n-2)); } return fibs.get(n); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute fibs : Map(int,int) := Map{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( fibs := fibs->union(Map{0 |-> 1}) ; fibs := fibs->union(Map{1 |-> 1}) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; OclFile["System.out"].println(fibonacci(n)) ; skip ; ); static operation fibonacci( n : int) : int pre: true post: true activity: ( if (not(fibs->keys()->includes(n))) then ( fibs := fibs->union(Map{n |-> fibonacci(n - 1) + fibonacci(n - 2)}) ) else skip ; return fibs->at(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.Arrays ; import java.util.Scanner ; public class Main { InputStream in=System.in ; PrintStream out=System.out ; public void _main(String[] args){ Scanner sc=new Scanner(in); int n=sc.nextInt(); sc.close(); long[] dp=new long[100]; dp[0]=1 ; dp[1]=1 ; for(int i=2 ; itoInteger() ; skip ; var dp : Sequence(long) ; dp := Integer.subrange(1,100)->collect(0) ; dp[0+1] := 1 ; dp[1+1] := 1 ; var i : int ; i := 2 ; while i < dp->size() do ( ( dp[i+1] := dp[i - 1+1] + dp[i - 2+1] ) ; i := i + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain()._main(args) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { static long fib(int n){ if(n==0)return 1 ; else if(n==1)return 1 ; long val=2 ; long val_pre=1 ; long val_prepre=1 ; for(int i=2 ; itoInteger() ; OclFile["System.out"].println(fib(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int minDiff(int n,int x,int A[]){ int mn=A[0],mx=A[0]; for(int i=0 ; imin() ; mx := Set{mx, A[i+1]}->max() ) ; i := i + 1 ) ; return Set{0, mx - mn - 2 * x}->max() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; var x : int ; x := 3 ; var A : Sequence(int) ; A := Sequence{1,3,6} ; OclFile["System.out"].println(minDiff(n, x, A)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findNthNum(int N){ int bit_L=1,last_num=0 ; while(bit_L*(bit_L+1)/2pow(bit_L)))->oclAsType(long)) + ((1*(2->pow(bit_R)))->oclAsType(long)) + "\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 13 ; execute findNthNum(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p036 implements EulerSolution { public static void main(String[] args){ System.out.println(new p036().run()); } public String run(){ long sum=0 ; for(int i=1 ; i<1000000 ; i++){ if(Library.isPalindrome(Integer.toString(i,10))&& Library.isPalindrome(Integer.toString(i,2)))sum+=i ; } return Long.toString(sum); } } ------------------------------------------------------------ OCL File: --------- class p036 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p036.newp036().run()) ); operation run() : String pre: true post: true activity: ( var sum : long ; sum := 0 ; var i : int ; i := 1 ; while i < 1000000 do ( ( if (Library.isPalindrome(((i) + "")) & Library.isPalindrome(((i) + ""))) then sum := sum+(i) ; else skip ) ; i := i + 1 ) ; return ((sum) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.BigInteger ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); BigInteger MOD=new BigInteger("4294967311"); while(sc.hasNextInt()){ int n=sc.nextInt(); BigInteger ans=BigInteger.ZERO ; for(int i=0 ; i=0){ ans=ans.subtract(MOD); } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var MOD : long ; MOD := long("4294967311") ; while (sc.hasNextInt()) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var o : int ; o := sc.getCurrent()->toInteger() ; var y : long ; y := sc.nextBigInteger() ; if (o = 1) then ( ans := ans->excludes(y).mod(MOD) ) else if (o = 2) then ( ans := ans->excludes(MOD).subtract(y).mod(MOD) ) else if (o = 3) then ( ans := ans.multiply(y).mod(MOD) ) else if (o = 4) then ( ans := ans.multiply(y.modInverse(MOD)).mod(MOD) ) else skip ; ; ; ) ; i := i + 1 ) ; var tmp : long ; tmp := long((((1L*(2->pow(31)))->oclAsType(long)) + "")) ; if (ans->compareTo(tmp) >= 0) then ( ans := ans.subtract(MOD) ) else skip ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.math.BigInteger ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] o=new int[n]; int[] y=new int[n]; BigInteger x=new BigInteger("0"); BigInteger p=new BigInteger("4294967311"); BigInteger d=new BigInteger("2147483648"); for(int i=0 ; itoInteger() ; var o : Sequence(int) ; o := Integer.subrange(1,n)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,n)->collect(0) ; var x : long ; x := long("0") ; var p : long ; p := long("4294967311") ; var d : long ; d := long("2147483648") ; var i : int ; i := 0 ; while i < n do ( ( o[i+1] := in.getCurrent()->toInteger() ; y[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var oo : int ; oo := o[i+1] ; var yy : long ; yy := long(((y[i+1]) + "")) ; if (oo = 1) then ( x := x->excludes(yy) ) else if (oo = 2) then ( x := x.subtract(yy) ) else if (oo = 3) then ( x := x.multiply(yy) ) else if (oo = 4) then ( x := x.multiply(yy.modInverse(p)) ) else skip ; ; ; ; x := x.mod(p) ) ; i := i + 1 ) ; if (x->compareTo(d) = -1) then OclFile["System.out"].println(x) else OclFile["System.out"].println(x.subtract(p)) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { static boolean checkPerfectcube(int n){ int d=(int)Math.cbrt(n); if(d*d*d==n)return true ; return false ; } static int largestPerfectcubeNumber(int a[],int n){ int maxi=-1 ; for(int i=0 ; icbrt()->oclAsType(int) ; if (d * d * d = n) then return true else skip ; return false ); static operation largestPerfectcubeNumber( a : Sequence(int), n : int) : int pre: true post: true activity: ( var maxi : int ; maxi := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (checkPerfectcube(a[i+1])) then maxi := Set{a[i+1], maxi}->max() ; else skip ) ; i := i + 1 ) ; return maxi ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{16,64,25,2,3,10} ; var n : int ; n := a->size() ; OclFile["System.out"].print(largestPerfectcubeNumber(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String...args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; i=0 && a[j]>key){ a[j+1]=a[j]; j--; } a[j+1]=key ; printArray(a); } } public static void printArray(int[] a){ for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute printArray(a) ; var i : int ; i := 1 ; while i < n do ( ( var key : int ; key := a[i+1] ; var j : int ; j := i - 1 ; while (j >= 0 & a[j+1] > key) do ( a[j + 1+1] := a[j+1] ; j := j - 1 ) ; a[j + 1+1] := key ; execute printArray(a) ; ) ; i := i + 1 ) ; ); static operation printArray( a : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < a->size() - 1 do ( ( OclFile["System.out"].print(a[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(a[a->size() - 1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int N=scn.nextInt(); int M=scn.nextInt(); boolean[] exists1toi=new boolean[N+1]; Arrays.fill(exists1toi,false); boolean[] existsitoN=new boolean[N+1]; Arrays.fill(existsitoN,false); for(int i=0 ; itoInteger() ; var M : int ; M := scn.getCurrent()->toInteger() ; var exists1toi : Sequence(boolean) ; exists1toi := Integer.subrange(1,N + 1)->collect(false) ; exists1toi := exists1toi->collect(false) ; var existsitoN : Sequence(boolean) ; existsitoN := Integer.subrange(1,N + 1)->collect(false) ; existsitoN := existsitoN->collect(false) ; var i : int ; i := 0 ; while i < M do ( ( var a : int ; a := scn.getCurrent()->toInteger() ; var b : int ; b := scn.getCurrent()->toInteger() ; if (a = 1) then ( exists1toi[b+1] := true ) else skip ; if (b = 1) then ( exists1toi[a+1] := true ) else skip ; if (a = N) then ( existsitoN[b+1] := true ) else skip ; if (b = N) then ( existsitoN[a+1] := true ) else skip ; ) ; i := i + 1 ) ; var ans : boolean ; ans := false ; var i : int ; i := 1 ; while i <= N do ( ( if (exists1toi[i+1] & existsitoN[i+1]) then ( ans := true ) else skip ) ; i := i + 1 ) ; if (ans) then ( OclFile["System.out"].println("POSSIBLE") ) else ( OclFile["System.out"].println("IMPOSSIBLE") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class Main { private static final String POSSIBLE="POSSIBLE" ; private static final String IMPOSSSIBLE="IMPOSSIBLE" ; public static void main(String[] args){ new Main().execute(); } public void execute(){ Scanner sc=new Scanner(System.in); final int N=sc.nextInt(); final int M=sc.nextInt(); HashSetfromOne=new HashSet<>(); HashSettoN=new HashSet<>(); for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var fromOne : Set(int) ; fromOne := Set{} ; var toN : Set(int) ; toN := Set{} ; var i : int ; i := 0 ; while i < M do ( ( var ai : int ; ai := sc.getCurrent()->toInteger() ; var bi : int ; bi := sc.getCurrent()->toInteger() ; if (ai = 1) then ( fromOne := fromOne->including(bi) ) else skip ; if (bi = N) then ( toN := toN->including(ai) ) else skip ) ; i := i + 1 ) ; skip ; for (n : fromOne) do ( ( if (toN->includes(n)) then ( OclFile["System.out"].println(POSSIBLE) ; return ) else skip ) ) ; OclFile["System.out"].println(IMPOSSSIBLE) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; import java.util.StringTokenizer ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int target,num ; String str=br.readLine(); StringTokenizer st=new StringTokenizer(str); target=Integer.parseInt(st.nextToken()); num=Integer.parseInt(st.nextToken()); boolean A[]=new boolean[200001]; boolean B[]=new boolean[200001]; Arrays.fill(A,false); Arrays.fill(B,false); for(int i=0 ; itoInteger() ; num := (st.next())->toInteger() ; var A : Sequence(boolean) ; A := Integer.subrange(1,200001)->collect(false) ; var B : Sequence(boolean) ; B := Integer.subrange(1,200001)->collect(false) ; A := A->collect(false) ; B := B->collect(false) ; var i : int ; i := 0 ; while i < num do ( ( var tmp1 : int ; var tmp2 : int ; str := br.readLine() ; st := OclIterator.newOclIterator_String(str) ; tmp1 := (st.next())->toInteger() ; tmp2 := (st.next())->toInteger() ; if (tmp1 = 1) then ( A[tmp2+1] := true ) else if (tmp2 = target) then ( B[tmp1+1] := true ) else skip ; ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= 200000 do ( ( if (A[i+1] & B[i+1]) then ( OclFile["System.out"].println("POSSIBLE") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("IMPOSSIBLE") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int m=Integer.parseInt(sc.next()); HashMapmap=new HashMap(); boolean flg=false ; for(int i=0 ; itoInteger() ; var m : int ; m := (sc.getCurrent())->toInteger() ; var map : Map(int,Boolean) ; map := Map{} ; var flg : boolean ; flg := false ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := (sc.getCurrent())->toInteger() ; var b : int ; b := (sc.getCurrent())->toInteger() ; if (a = 1) then ( if (map->keys()->includes(b)) then ( flg := true ; break ) else skip ; map := map->union(Map{b |-> true}) ) else skip ; if (b = n) then ( if (map->keys()->includes(a)) then ( flg := true ; break ) else skip ; map := map->union(Map{a |-> true}) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(if flg then "POSSIBLE" else "IMPOSSIBLE" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.HashSet ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); int a ; int b ; HashSethashFirstTo=new HashSet(); HashSethashSecondFrom=new HashSet(); boolean possible=false ; for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var a : int ; var b : int ; var hashFirstTo : Set(int) ; hashFirstTo := Set{} ; var hashSecondFrom : Set(int) ; hashSecondFrom := Set{} ; var possible : boolean ; possible := false ; var i : int ; i := 0 ; while i < M do ( ( a := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; if (a = 1) then ( hashFirstTo := hashFirstTo->including(b) ) else if (b = N) then ( hashSecondFrom := hashSecondFrom->including(a) ) else skip ; ) ; i := i + 1 ) ; for (firstTo : hashFirstTo) do ( ( if (hashSecondFrom->includes(firstTo)) then ( possible := true ; break ) else skip ) ) ; if (possible = true) then ( OclFile["System.out"].println("POSSIBLE") ) else ( OclFile["System.out"].println("IMPOSSIBLE") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int MinimumCost(int cost[],int n,int W){ Vectorval=new Vector(); Vectorwt=new Vector(); int size=0 ; for(int i=0 ; ij)min_cost[i][j]=min_cost[i-1][j]; else min_cost[i][j]=Math.min(min_cost[i-1][j],min_cost[i][j-wt.get(i-1)]+val.get(i-1)); } } return(min_cost[n][W]==Integer.MAX_VALUE)?-1 : min_cost[n][W]; } public static void main(String[] args){ int cost[]={ 1,2,3,4,5 },W=5 ; int n=cost.length ; System.out.println(MinimumCost(cost,n,W)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation MinimumCost( cost : Sequence(int), n : int, W : int) : int pre: true post: true activity: ( var val : Sequence(int) ; val := Sequence{} ; var wt : Sequence(int) ; wt := Sequence{} ; var size : int ; size := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (cost[i+1] /= -1) then ( val := val->including(cost[i+1]) ; wt := wt->including(i + 1) ; size := size + 1 ) else skip ) ; i := i + 1 ) ; n := size ; var min_cost : Sequence(Sequence(int)) ; min_cost := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,W + 1)->collect(0)) ; var i : int ; i := 0 ; while i <= W do ( min_cost[0+1][i+1] := 2147483647 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( min_cost[i+1][0+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= W do ( ( if (wt->at(i - 1+1) > j) 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->at(i - 1+1)+1] + val->at(i - 1+1)}->min() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return if (min_cost[n+1][W+1] = 2147483647) then -1 else min_cost[n+1][W+1] endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cost : Sequence(int) ; cost := Sequence{1,2,3,4,5} ; var W : int ; W := 5 ; var n : int ; n := cost->size() ; OclFile["System.out"].println(MinimumCost(cost, n, W)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import static java.lang.Math.*; class Quadratic { void findRoots(int a,int b,int c){ if(a==0){ System.out.println("Invalid"); return ; } int d=b*b-4*a*c ; double sqrt_val=sqrt(abs(d)); if(d>0){ System.out.println("Roots are real and different \n"); System.out.println((double)(-b+sqrt_val)/(2*a)+"\n"+(double)(-b-sqrt_val)/(2*a)); } else { System.out.println("Roots are complex \n"); System.out.println(-(double)b/(2*a)+"+i"+sqrt_val+"\n"+-(double)b/(2*a)+"-i"+sqrt_val); } } public static void main(String args[]){ Quadratic obj=new Quadratic(); int a=1,b=-7,c=12 ; obj.findRoots(a,b,c); } } ------------------------------------------------------------ OCL File: --------- class Quadratic { operation findRoots( a : int, b : int, c : int) : void pre: true post: true activity: ( if (a = 0) then ( OclFile["System.out"].println("Invalid") ; return ) else skip ; var d : int ; d := b * b - 4 * a * c ; var sqrt_val : double ; sqrt_val := sqrt(abs(d)) ; if (d > 0) then ( OclFile["System.out"].println("Roots are real and different \n") ; OclFile["System.out"].println((-b + sqrt_val)->oclAsType(double) / (2 * a) + "\n" + (-b - sqrt_val)->oclAsType(double) / (2 * a)) ) else ( OclFile["System.out"].println("Roots are complex \n") ; OclFile["System.out"].println(-b->oclAsType(double) / (2 * a) + "+i" + sqrt_val + "\n" + -b->oclAsType(double) / (2 * a) + "-i" + sqrt_val) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : Quadratic ; obj := Quadratic.newQuadratic() ; var a : int ; a := 1 ; var b : int ; b := -7 ; var c : int ; c := 12 ; obj.findRoots(a, b, c) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Card { String mark ; int num,flag ; public Card(String str,int n,int f){ mark=str ; num=n ; flag=f ; } public void Show(){ System.out.println(mark+" "+num); } } public class Main { static Card[] card=new Card[100001]; static Card swap ; public static int partation(int p,int r){ int x=card[r] .num ; int i=p-1 ; for(int j=p ; jcard[i+1] .flag){ f=1 ; break ; } } if(f==0){ System.out.println("Stable"); } else { System.out.println("Not stable"); } for(i=0 ; icollect(null); static attribute swap : Card; static operation partation( p : int, r : int) : int pre: true post: true activity: ( var x : int ; x := card[r+1].num ; var i : int ; i := p - 1 ; var j : int ; j := p ; while j < r do ( ( if (card[j+1].num <= x) then ( i := i + 1 ; swap := card[i+1] ; card[i+1] := card[j+1] ; card[j+1] := swap ) else skip ) ; j := j + 1 ) ; swap := card[i + 1+1] ; card[i + 1+1] := card[r+1] ; card[r+1] := swap ; return i + 1 ); static operation quicksort( p : int, r : int) : void pre: true post: true activity: ( var q : int ; if (p < r) then ( q := partation(p, r) ; execute quicksort(p, q - 1) ; execute quicksort(q + 1, r) ) else skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var i : int ; var n : int ; var f : int ; f := 0 ; n := scan.getCurrent()->toInteger() ; i := 0 ; while i < n do ( ( card[i+1] := Card.newCard(scan.getCurrent(), scan.getCurrent()->toInteger(), i) ) ; i := i + 1 ) ; execute quicksort(0, n - 1) ; i := 0 ; while i < n - 1 do ( ( if (card[i+1].num = card[i + 1+1].num & card[i+1].flag > card[i + 1+1].flag) then ( f := 1 ; break ) else skip ) ; i := i + 1 ) ; if (f = 0) then ( OclFile["System.out"].println("Stable") ) else ( OclFile["System.out"].println("Not stable") ) ; i := 0 ; while i < n do ( ( card[i+1].Show() ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Round0B { int cases ; int count(String stack){ int flips=0 ; for(int n=1 ; nsize() do ( ( if (stack->at(n - 1+1) /= stack->at(n+1)) then flips := flips + 1 ; else skip ) ; n := n + 1 ) ; return flips ); operation process( scanner : OclFile, out : OclFile) : void pre: true post: true activity: ( cases := scanner.nextInt() ; scanner.nextLine() ; var curCase : int ; curCase := 0 ; while curCase < cases do ( ( var stack : String ; stack := scanner.nextLine()->trim() ; out.println("Case #" + (curCase + 1) + ": " + count(stack + "+")) ) ; curCase := curCase + 1 ) ); static operation newRound0B() : Round0B pre: true post: true activity: ( var self : Round0B ; self := createRound0B(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile("C:\\Users\\Olaf\\Downloads\\B-large.in")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile("out-B-large.txt")) ; execute process(in, out) ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Round0B.newRound0B() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package lab6zp ; import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Lab6ZP { public static void main(String[] args){ Scanner in=new Scanner(System.in); Scanner sin=new Scanner(System.in); int n=Integer.parseInt(sin.next()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := sin.getCurrent() ; s := s+('+') ; var counter : int ; counter := 0 ; var j : int ; j := 0 ; while j < s->size() - 1 do ( ( if (s->at(j+1) /= s->at(j + 1+1)) then ( counter := counter + 1 ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println("Case #" + (i + 1) + ": " + counter) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int array[]=new int[N]; for(int i=0 ; i=0 && array[loc]>base){ array[loc+1]=array[loc]; loc--; } array[loc+1]=base ; out_put(array); } } private static void out_put(int array[]){ int i ; for(i=0 ; itoInteger() ; var array : Sequence(int) ; array := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( array[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute out_put(array) ; var base : int ; var loc : int ; var i : int ; i := 1 ; while i < N do ( ( base := array[i+1] ; loc := i - 1 ; while (loc >= 0 & array[loc+1] > base) do ( array[loc + 1+1] := array[loc+1] ; loc := loc - 1 ) ; array[loc + 1+1] := base ; execute out_put(array) ; ) ; i := i + 1 ) ; ); static operation out_put( array : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < array->size() - 1 do ( ( OclFile["System.out"].print(array[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(array[i+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package gcj2016.qualif ; import java.io.FileNotFoundException ; import java.io.FileReader ; import java.io.PrintWriter ; import java.util.Scanner ; import java.util.logging.Level ; import java.util.logging.Logger ; public class ExoB { public static void main(final String[] args){ final String base="/home/jfortin/workspace-gcj/Codejam2016/q/ExoB/" ; final String input=base+"b1.in" ; final String output=base+"b1.out" ; try { final Scanner sc=new Scanner(new FileReader(input)); final PrintWriter pw=new PrintWriter(output); final int n=sc.nextInt(); sc.nextLine(); for(int c=0 ; ctoInteger() ; skip ; var c : int ; c := 0 ; while c < n do ( ( OclFile["System.out"].println("Test case " + (c + 1) + "...") ; skip ; execute test(sc, pw) ; skip ) ; c := c + 1 ) ; skip ; skip ; skip ; skip ; ) catch (ex : FileNotFoundException) do ( Logger.getLogger(OclType["ExoB"].getName()).log(Level.SEVERE, null, ex) ) ); static operation test( sc : OclFile, pw : OclFile) : void pre: true post: true activity: ( var in : String ; in := sc.getCurrent() ; OclFile["System.out"].println(in) ; var i : int ; i := count(in, in->size(), '+') ; skip ); static operation count( in : String, length : int, c : String) : int pre: true post: true activity: ( if (length = 0) then ( return 0 ) else skip ; if (in->at(length - 1+1) = c) then ( return count(in, length - 1, c) ) else ( return 1 + count(in, length - 1, if c = '+' then '-' else '+' endif) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.concurrent.*; public class B { static BufferedReader br ; static StringTokenizer st ; static PrintWriter pw ; public static void main(String[] args)throws Exception { br=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new BufferedWriter(new FileWriter("b.out"))); final int MAX_CASES=readInt(); for(int casenum=1 ; casenum<=MAX_CASES ; casenum++){ pw.printf("Case #%d: ",casenum); String s=nextToken(); boolean[] good=new boolean[s.length()]; int ret=0 ; boolean last=true ; for(int i=0 ; i0 && last!=good[i]){ ret++; } last=good[i]; } if(! last)ret++; pw.println(ret); } pw.close(); } public static int readInt(){ return Integer.parseInt(nextToken()); } public static long readLong(){ return Long.parseLong(nextToken()); } public static double readDouble(){ return Double.parseDouble(nextToken()); } public static String nextToken(){ while(st==null || ! st.hasMoreTokens()){ try { if(! br.ready()){ pw.close(); System.exit(0); } st=new StringTokenizer(br.readLine()); } catch(IOException e){ System.err.println(e); System.exit(1); } } return st.nextToken(); } public static String readLine(){ st=null ; try { return br.readLine(); } catch(IOException e){ System.err.println(e); System.exit(1); return null ; } } } ------------------------------------------------------------ OCL File: --------- class B { static attribute br : OclFile; static attribute st : OclIterator; static attribute pw : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("b.out")))) ; var MAX_CASES : int ; MAX_CASES := readInt() ; var casenum : int ; casenum := 1 ; while casenum <= MAX_CASES do ( ( skip ; var s : String ; s := nextToken() ; var good : Sequence(boolean) ; good := Integer.subrange(1,s->size())->collect(false) ; var ret : int ; ret := 0 ; var last : boolean ; last := true ; var i : int ; i := 0 ; while i < good->size() do ( ( good[i+1] := s->at(i+1) = '+' ; if (i > 0 & last /= good[i+1]) then ( ret := ret + 1 ) else skip ; last := good[i+1] ) ; i := i + 1 ) ; if (not(last)) then ret := ret + 1 ; else skip ; skip ; ) ; casenum := casenum + 1 ) ; skip ; ); static operation readInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); static operation readLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); static operation readDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); static operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( if (not(br.canRead())) then ( skip ; OclProcess.exit(0) ) else skip ; st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( OclFile["System.err"].println(e) ; OclProcess.exit(1) ) ) ; return st.next() ); static operation readLine() : String pre: true post: true activity: ( st := null ; try ( return br.readLine() ) catch (e : IOException) do ( OclFile["System.err"].println(e) ; OclProcess.exit(1) ; return null ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class revengepancake { private static InputReader in ; private static PrintWriter out ; public static boolean SUBMIT=true ; public static final String NAME="B-large" ; private static void main2()throws IOException { char[] s=in.next().toCharArray(); int n=s.length ; int count=0 ; for(int i=1 ; icharacters() ; var n : int ; n := s->size() ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i < n do ( ( if (s[i+1] /= s[i - 1+1]) then count := count + 1 ; else skip ) ; i := i + 1 ) ; if (s[n - 1+1] = '-') then count := count + 1 ; else skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( if (SUBMIT) then ( in := InputReader.newInputReader(OclFile.newOclFile_Read(OclFile(NAME + ".in"))) ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(NAME + ".out"))) ) else ( in := InputReader.newInputReader(OclFile["System.in"]) ; out := OclFile.newOclFile_Write(OclFile["System.out"], true) ) ; var numCases : int ; numCases := in.nextInt() ; var test : int ; test := 1 ; while test <= numCases do ( ( skip ; execute main2() ) ; test := test + 1 ) ; skip ; OclProcess.exit(0) ; ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printCombination(int n){ System.out.print(1+" "); if((n-2)% 3==0)System.out.print(2+" "+(n-3)); else System.out.print(1+" "+(n-2)); } public static void main(String[] args){ int n=233 ; printCombination(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printCombination( n : int) : void pre: true post: true activity: ( OclFile["System.out"].print(1 + " ") ; if ((n - 2) mod 3 = 0) then OclFile["System.out"].print(2 + " " + (n - 3)) ; else OclFile["System.out"].print(1 + " " + (n - 2)) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 233 ; execute printCombination(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Node { static boolean checkUnimodal(int arr[],int n){ int i=1 ; while(iarr[i-1])++i ; while(i arr[i - 1+1]) do i := i + 1 ; ; while (i < n & arr[i+1] = arr[i - 1+1]) do i := i + 1 ; ; while (i < n & arr[i+1] < arr[i - 1+1]) do i := i + 1 ; ; return (i = n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,5,5,5,4,2} ; var n : int ; n := arr->size() ; if (checkUnimodal(arr, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] a=new long[n+1]; for(int i=1 ; i<=n ; i++){ a[i]=a[i-1]+sc.nextLong(); } long min=Long.MAX_VALUE ; for(int i=1 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := a[i - 1+1] + sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var min : long ; min := "9223372036854775807"->toLong() ; var i : int ; i := 1 ; while i < n do ( ( min := Set{if a[i+1] - a[0+1] - a[n+1] + a[i+1] < 0 then -(a[i+1] - a[0+1] - a[n+1] + a[i+1]) else a[i+1] - a[0+1] - a[n+1] + a[i+1] endif, min}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.StringTokenizer ; public class Main { public static void main(String args[]){ ConsoleScanner cin=new ConsoleScanner(); PrintWriter cout=new PrintWriter(System.out); solve(cin,cout); cout.flush(); } private static void solve(ConsoleScanner cin,PrintWriter cout){ int n=cin.nextInt(); long[] a=new long[n]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < a->size() do ( a[i+1] := cin.nextInt() ; ; i := i + 1 ) ; var ans : long ; ans := solve(n, a) ; skip ; ); static operation solve( n : int, a : Sequence(long)) : long pre: true post: true activity: ( var ans : long ; ans := "9223372036854775807"->toLong() ; var sum : long ; sum := stream(a)->sum() ; var x : long ; x := 0 ; var y : long ; y := sum ; var i : int ; i := 0 ; while i < a->size() - 1 do ( ( x := x+(a[i+1]) ; y := y-(a[i+1]) ; ans := Set{ans, if x - y < 0 then -(x - y) else x - y endif}->min() ) ; i := i + 1 ) ; return ans ); static class ConsoleScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( try ( while (not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ) catch (e : IOException) do ( error AssertionException(e) ) ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int N=stdIn.nextInt(); int[] a=new int[N]; long sumh=0 ; long[] sum=new long[N]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var sumh : long ; sumh := 0 ; var sum : Sequence(long) ; sum := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := stdIn.getCurrent()->toInteger() ; sum[i+1] := sumh + a[i+1] ; sumh := sumh+(a[i+1]) ) ; i := i + 1 ) ; var min : long ; min := if sum[0+1] * 2 - sumh < 0 then -(sum[0+1] * 2 - sumh) else sum[0+1] * 2 - sumh endif ; var i : int ; i := 1 ; while i < N - 1 do ( ( if (if sum[i+1] * 2 - sumh < 0 then -(sum[i+1] * 2 - sumh) else sum[i+1] * 2 - sumh endif < min) then ( min := if sum[i+1] * 2 - sumh < 0 then -(sum[i+1] * 2 - sumh) else sum[i+1] * 2 - sumh endif ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test285 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; j0){ sum+=y % 10 ; y/=10 ; } System.out.println(sum); } else { System.out.println(-1); } } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test285 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < t do ( ( var x : long ; x := in.getCurrent()->toLong() ; if (x mod 2050 = 0) then ( var y : long ; y := x / 2050 ; var sum : int ; sum := 0 ; while (y > 0) do ( sum := sum+(y mod 10) ; y := y/(10) ) ; OclFile["System.out"].println(sum) ) else ( OclFile["System.out"].println(-1) ) ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); C solver=new C(); solver.solve(1,in,out); out.close(); } static class C { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=Integer.parseInt(in.next()); int[] a=new int[n]; long total=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var total : long ; total := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (in.getCurrent())->toInteger() ; total := total+(a[i+1]) ) ; i := i + 1 ) ; var ans : long ; ans := "9223372036854775807"->toLong() ; var x : long ; x := 0 ; var i : int ; i := 0 ; while i < n do ( ( x := x+(a[i+1]) ; if (i + 1 < n) then ans := Set{ans, if total - 2 * x < 0 then -(total - 2 * x) else total - 2 * x endif}->min() ; else skip ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Map.Entry ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=1 ; main : while(t-->0){ int n=sc.nextInt(); TreeMapmap=new TreeMap<>(); for(int i=0 ; i<1<slime=new ArrayList<>(); slime.add(map.lastKey()); for(int i=0 ; iintegerIntegerEntry=map.lowerEntry(slime.get(j)); if(integerIntegerEntry==null){ System.out.println("No"); continue main ; } final Integer value=integerIntegerEntry.getValue(); final Integer key=integerIntegerEntry.getKey(); if(value==1){ map.remove(key); } else { map.replace(key,value-1); } slime.add(key); } } System.out.println("Yes"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < (1*(2->pow(n)))->oclAsType(long) do ( ( var num : int ; num := sc.getCurrent()->toInteger() ; map := map->union(Map{num |-> (if map->keys()->contains(num) then map->at(num) else 0 endif) + 1}) ) ; i := i + 1 ) ; var slime : Sequence(int) ; slime := Sequence{} ; slime := slime->including(map->keys()->max()) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < (1*(2->pow(i)))->oclAsType(long) do ( ( var integerIntegerEntry : Entry ; integerIntegerEntry := map.lowerEntry(slime->at(j+1)) ; if (integerIntegerEntry = null) then ( OclFile["System.out"].println("No") ; continue ) else skip ; var value : int ; value := integerIntegerEntry.getValue() ; var key : int ; key := integerIntegerEntry.getKey() ; if (value = 1) then ( map := map->antirestrict(Set{key}) ) else ( map := map.replace(key, value - 1) ) ; slime := slime->including(key) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int len=Integer.parseInt(br.readLine()); StringTokenizer tokenizer=new StringTokenizer(br.readLine()," "); int[] arr=new int[len]; int i=0 ; while(tokenizer.hasMoreElements()){ arr[i++]=Integer.parseInt((String)tokenizer.nextElement()); } sort(arr); } public static void sort(int[] arr){ printArr(arr); for(int i=1 ; i=1 ; j--){ int current=arr[j]; int prev=arr[j-1]; if(currenttoInteger() ; var tokenizer : OclIterator ; tokenizer := OclIterator.newOclIterator_String_String(br.readLine(), " ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,len)->collect(0) ; var i : int ; i := 0 ; while (tokenizer.hasNext()) do ( arr[i+1] := (tokenizer.next()->oclAsType(String))->toInteger() ; i := i + 1 ) ; execute sort(arr) ; ); static operation sort( arr : Sequence(int)) : void pre: true post: true activity: ( execute printArr(arr) ; var i : int ; i := 1 ; while i < arr->size() do ( ( var j : int ; j := i ; while j >= 1 do ( ( var current : int ; current := arr[j+1] ; var prev : int ; prev := arr[j - 1+1] ; if (current < prev) then ( execute swap(arr, j - 1, j) ) else ( break ) ) ; j := j - 1 ) ; execute printArr(arr) ) ; i := i + 1 ) ); static operation swap( arr : Sequence(int), from : int, to : int) : void pre: true post: true activity: ( var temp : int ; temp := arr[from+1] ; arr[from+1] := arr[to+1] ; arr[to+1] := temp ); static operation printArr( arr : Sequence(int)) : void pre: true post: true activity: ( var msg : String ; msg := "" ; var i : int ; i := 0 ; while i < arr->size() do ( ( msg := msg+(arr[i+1]) ; if (i = arr->size() - 1) then ( break ) else skip ; msg := msg+(" ") ) ; i := i + 1 ) ; OclFile["System.out"].println(msg) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); Long[] a=new Long[N]; long t=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,N)->collect(null) ; var t : long ; t := 0 ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := (sc.getCurrent())->toLong() ; t := t+(a[i+1]) ) ; i := i + 1 ) ; var inf : long ; inf := 2147000009 ; var x : long ; x := 0 ; var y : long ; y := t ; var min : long ; min := inf ; var i : int ; i := 0 ; while i < N do ( ( x := x+(a[i+1]) ; y := y-(a[i+1]) ; if (i < N - 1) then min := Set{min, if x - y < 0 then -(x - y) else x - y endif}->min() ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(min) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Comparator ; import java.util.Collections ; public class Main { public static void main(String[] args){ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); try { ArrayListlist=new ArrayList<>(); int count=Integer.parseInt(reader.readLine()); int duplicate=0 ; for(int i=0 ; itoInteger() ; var duplicate : int ; duplicate := 0 ; var i : int ; i := 0 ; while i < count do ( ( var str : String ; str := reader.readLine() ; var s : Sequence(String) ; s := str->split(" ") ; var w : int ; w := (s[0+1])->toInteger() ; var h : int ; h := (s[1+1])->toInteger() ; var c : int ; c := (s[2+1])->toInteger() ; var data : Data ; data := Data.newData(w, h, c) ; var j : int ; j := 0 ; while j < list->size() do ( ( if (list->at(j+1)->reverse()->indexOf(data)-1) then ( duplicate := duplicate + 1 ; break ) else skip ) ; j := j + 1 ) ; list := list->including(data) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(duplicate) ; skip ; ) catch (e : IOException) do ( e.printStackTrace() ) ); static class Data { attribute num : int := Integer.subrange(1,3)->collect(0); static operation newData( a : int, b : int, c : int) : Data pre: true post: true activity: ( var self : Data ; self := createData(); self.initialise(a, b,c); return self ); operation initialise( a : int, b : int, c : int) : void pre: true post: true activity: ( num[0+1] := a ; num[1+1] := b ; num[2+1] := c ); operation search( d : Data) : boolean pre: true post: true activity: ( var tr : int ; tr := 0 ; var i : int ; i := 0 ; while i < 3 do ( ( var j : int ; j := 0 ; while j < 3 do ( ( if (d.num[i+1] = num[j+1]) then ( tr := tr + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (tr = 3) then ( return true ) else skip ; return false ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; import java.util.HashSet ; public class Main { public static void main(String[] args)throws Exception { Scanner s=new Scanner(System.in); int N=s.nextInt(); int[] n=new int[3]; HashSetset=new HashSet(); for(int i=0 ; itoInteger() ; var n : Sequence(int) ; n := Integer.subrange(1,3)->collect(0) ; var set : Set(String) ; set := Set{} ; var i : int ; i := 0 ; while i < N do ( ( n[0+1] := s.getCurrent()->toInteger() ; n[1+1] := s.getCurrent()->toInteger() ; n[2+1] := s.getCurrent()->toInteger() ; n := n->sort() ; var s1 : String ; s1 := ((n[0+1]) + "") ; var s2 : String ; s2 := ((n[1+1]) + "") ; var s3 : String ; s3 := ((n[2+1]) + "") ; var str : String ; str := s1 + s2 + s3 ; set := set->including(str) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(N - set->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { static final int BASE=1009 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[] p=new int[3]; Setset=new HashSet<>(); int count=0 ; for(int i=0 ; itoInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,3)->collect(0) ; var set : Set(long) ; set := Set{} ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N do ( ( p[0+1] := sc.getCurrent()->toInteger() ; p[1+1] := sc.getCurrent()->toInteger() ; p[2+1] := sc.getCurrent()->toInteger() ; p := p->sort() ; var hash : long ; hash := 0 ; hash := hash+(p[0+1] * BASE * BASE) ; hash := hash+(p[1+1] * BASE) ; hash := hash+(p[2+1]) ; if (set->includes(hash)) then ( count := count + 1 ; continue ) else skip ; set := set->including(hash) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.Collectors ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tcString.valueOf((char)('a'+IntStream.range(0,c.length).filter(i->c[i]==1).findAny().getAsInt()))).collect(Collectors.joining()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var originals : Sequence(String) ; originals := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < originals->size() do ( ( originals[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; var rests : Sequence(String) ; rests := Integer.subrange(1,n - 1)->collect(null) ; var i : int ; i := 0 ; while i < rests->size() do ( ( rests[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(originals, rests)) ; OclFile["System.out"].flush() ; ) ; tc := tc + 1 ) ; skip ); static operation solve( originals : Sequence(String), rests : Sequence(String)) : String pre: true post: true activity: ( var m : int ; m := originals[0+1]->size() ; var counts : Sequence(Sequence(int)) ; counts := Integer.subrange(1,m)->collect(Integer.subrange(1,26)->collect(0)) ; for (original : originals) do ( ( var i : int ; i := 0 ; while i < original->size() do ( ( counts[i+1][original->at(i+1) - ('a')->char2byte()+1] := counts[i+1][original->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ) ) ; for (rest : rests) do ( ( var i : int ; i := 0 ; while i < rest->size() do ( ( counts[i+1][rest->at(i+1) - ('a')->char2byte()+1] := counts[i+1][rest->at(i+1) - ('a')->char2byte()+1] - 1 ) ; i := i + 1 ) ) ) ; return stream(counts)->collect( _x1 | (lambda c : OclAny in ((('a' + Integer.subrange(0, c->size()-1)->select( _x1 | (lambda i : OclAny in c[i+1] = 1)->apply(_x1) )->any(true).getAsInt())->oclAsType(String)) + ""))->apply(_x1) ).collect(Collectors.joining()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countSquares(int m,int n){ if(n ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static int logicOfSequence(int N){ if(N % 2==0)N=N*N ; else N=N*N*N ; return N ; } public static void main(String args[]){ int N=6 ; System.out.println(logicOfSequence(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation logicOfSequence( N : int) : int pre: true post: true activity: ( if (N mod 2 = 0) then N := N * N else N := N * N * N ; ; return N ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 6 ; OclFile["System.out"].println(logicOfSequence(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { static boolean check_char(String st,char ch){ int l=st.length(); for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < l do ( ( if (st->at(i+1) = ch) then return true else skip ) ; i := i + 1 ) ; return false ); static operation find_avg( st : String) : String pre: true post: true activity: ( var i : int ; var sm : int ; sm := 0 ; var l : int ; l := st->size() ; var ch : String ; i := 0 ; while i < l do ( ( ch := st->at(i+1) ; sm := sm + (ch)->oclAsType(int) ) ; i := i + 1 ) ; var avg : int ; avg := ((sm / l)->floor())->oclAsType(int) ; return ((avg)->oclAsType(String)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var st : String ; st := "ag23sdfa" ; var ch : String ; ch := find_avg(st) ; OclFile["System.out"].println(ch) ; if (check_char(st, ch) = true) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class SumMulti { int number ; public SumMulti(int number){ this.number=number ; } public int getNumber(){ return number ; } public void input(long number){ int count=0 ; boolean b=true ; while(true){ count++; String sNumber=""+number ; if(Long.parseLong(sNumber)<2050){ b=false ; break ; } long num=2050*(long)(java.lang.Math.pow(10,sNumber.length()-4)); if(num>number){ num=2050*(long)(java.lang.Math.pow(10,sNumber.length()-5)); } number-=num ; if(number==0){ break ; } } if(b==true){ System.out.println(count); } else { System.out.println(-1); } } public static void main(String[] a){ Scanner input=new Scanner(System.in); int number=input.nextInt(); SumMulti instance=new SumMulti(number); for(int i=0 ; itoLong() < 2050) then ( b := false ; break ) else skip ; var num : long ; num := 2050 * (java.lang.Math.pow(10, sNumber->size() - 4))->oclAsType(long) ; if (num > number) then ( num := 2050 * (java.lang.Math.pow(10, sNumber->size() - 5))->oclAsType(long) ) else skip ; number := number-(num) ; if (number = 0) then ( break ) else skip ; ) ; if (b = true) then ( OclFile["System.out"].println(count) ) else ( OclFile["System.out"].println(-1) ) ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : SumMulti ; instance := SumMulti.newSumMulti(number) ; var i : int ; i := 0 ; while i < instance.getNumber() do ( ( var num : long ; num := input.getCurrent()->toLong() ; instance.input(num) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Main { public static void main(String[] args){ BufferedReader kb=new BufferedReader(new InputStreamReader(System.in)); try { int n=Integer.parseInt(kb.readLine()); String[] nums=kb.readLine().split(" "); int len=nums.length ; int[] A=new int[len]; int i,len2=len-1 ; StringBuilder output=new StringBuilder(100+1); for(i=0 ; itoInteger() ; var nums : Sequence(String) ; nums := kb.readLine()->split(" ") ; var len : int ; len := nums->size() ; var A : Sequence(int) ; A := Integer.subrange(1,len)->collect(0) ; var i : int ; var len2 : int ; len2 := len - 1 ; var output : String ; output := StringLib.newString(100 + 1) ; i := 0 ; while i < len do ( ( A[i+1] := (nums[i+1])->toInteger() ; output := output + StringLib.newString(A[i+1] + " ") ) ; i := i + 1 ) ; output := output->excludingAt(output->lastIndexOf(" ")-1+1) ; output := output + StringLib.newString("\n") ; var key : int ; var j : int ; var k : int ; i := 1 ; while i < len do ( ( key := A[i+1] ; j := i - 1 ; while (0 <= j & key < A[j+1]) do ( A[j + 1+1] := A[j+1] ; j := j - 1 ) ; A[j + 1+1] := key ; k := 0 ; while k < len do ( ( output := output + StringLib.newString(A[k+1] + " ") ) ; k := k + 1 ) ; output := output->excludingAt(output->lastIndexOf(" ")-1+1) ; output := output + StringLib.newString("\n") ; ) ; i := i + 1 ) ; OclFile["System.out"].print(output) ; skip ; ) catch (e : IOException) do ( OclFile["System.err"].println(e) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=100000 ; static int[] divisors=new int[MAX]; static void generateDivisors(int n){ for(int i=1 ; i<=Math.sqrt(n); i++){ if(n % i==0){ if(n/i==i){ divisors[i]++; } else { divisors[i]++; divisors[n/i]++; } } } } static int findMaxMultiples(int[] arr,int n){ int ans=0 ; for(int i=0 ; icollect(0); static operation generateDivisors( n : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then ( if (n / i = i) then ( divisors[i+1] := divisors[i+1] + 1 ) else ( divisors[i+1] := divisors[i+1] + 1 ; divisors[n / i+1] := divisors[n / i+1] + 1 ) ) else skip ) ; i := i + 1 ) ); static operation findMaxMultiples( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( ans := Set{divisors[arr[i+1]+1], ans}->max() ; execute generateDivisors(arr[i+1]) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{8,1,28,4,2,6,7} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(findMaxMultiples(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int __gcd(int a,int b){ if(b==0)return a ; return __gcd(b,a % b); } static int maxProfit(int n,int a,int b,int x,int y){ int res=x*(n/a); res+=y*(n/b); res-=Math.min(x,y)*(n/((a*b)/__gcd(a,b))); return res ; } public static void main(String[] args){ int n=6,a=6,b=2,x=8,y=2 ; System.out.println(maxProfit(n,a,b,x,y)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static 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) ); static operation maxProfit( n : int, a : int, b : int, x : int, y : int) : int pre: true post: true activity: ( var res : int ; res := x * (n / a) ; res := res+(y * (n / b)) ; res := res-(Set{x, y}->min() * (n / ((a * b) / __gcd(a, b)))) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var a : int ; a := 6 ; var b : int ; b := 2 ; var x : int ; x := 8 ; var y : int ; y := 2 ; OclFile["System.out"].println(maxProfit(n, a, b, x, y)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static VectorDiffs(int[] a,int k){ Vectorout=new Vector(); int[] inc,dec ; inc=new int[a.length]; dec=new int[a.length]; int inc_sum=0 ; int dec_sum=0 ; for(int i=0 ; i=0 && j>i-k && a[j+1]>a[j]; --j){ ++inc[j]; ++inc_sum ; } for(int j=i-1 ; j>=0 && j>i-k && a[j+1]=k-1){ if(i>=k){ inc_sum-=inc[i-k]; dec_sum-=dec[i-k]; } out.add(inc_sum-dec_sum); } } return out ; } public static void main(String[] args){ int[] arr={ 10,20,30,15,15 }; Vectorout=Diffs(arr,3); for(int n : out)System.out.print(n+","); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Diffs( a : Sequence(int), k : int) : Sequence(int) pre: true post: true activity: ( var out : Sequence(int) ; out := Sequence{} ; var inc : Sequence(int) ; var dec : Sequence(int) ; inc := Integer.subrange(1,a->size())->collect(0) ; dec := Integer.subrange(1,a->size())->collect(0) ; var inc_sum : int ; inc_sum := 0 ; var dec_sum : int ; dec_sum := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( var j : int ; j := i - 1 ; while j >= 0 & j > i - k & a[j + 1+1] > a[j+1] do ( ( inc[j+1] := inc[j+1] + 1 ; inc_sum := inc_sum + 1 ) ; j := j - 1 ) ; var j : int ; j := i - 1 ; while j >= 0 & j > i - k & a[j + 1+1] < a[j+1] do ( ( dec[j+1] := dec[j+1] + 1 ; dec_sum := dec_sum + 1 ) ; j := j - 1 ) ; if (i >= k - 1) then ( if (i >= k) then ( inc_sum := inc_sum-(inc[i - k+1]) ; dec_sum := dec_sum-(dec[i - k+1]) ) else skip ; out := out->including(inc_sum - dec_sum) ) else skip ) ; i := i + 1 ) ; return out ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,20,30,15,15} ; var out : Sequence(int) ; out := Diffs(arr, 3) ; for (n : out) do ( OclFile["System.out"].print(n + ",") ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.util.Arrays ; import java.util.Scanner ; public class Main { static final long MOD=1000000007 ; static int n ; static int m ; static int[] b ; static long[] dp ; private static long rec(int current){ if(current==n)return 1 ; if(current>n)return 0 ; if(b[current]==1)return 0 ; if(dp[current]==MOD){ dp[current]=(rec(current+1)+rec(current+2))% MOD ; } return dp[current]; } public static void main(String[] args){ java.util.Scanner input=new Scanner(System.in); n=input.nextInt(); m=input.nextInt(); b=new int[n]; dp=new long[n]; for(int i=0 ; i n) then return 0 else skip ; if (b[current+1] = 1) then return 0 else skip ; if (dp[current+1] = MOD) then ( dp[current+1] := (rec(current + 1) + rec(current + 2)) mod MOD ) else skip ; return dp[current+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : Scanner ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := input.nextInt() ; m := input.nextInt() ; b := Integer.subrange(1,n)->collect(0) ; dp := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( dp[i+1] := MOD ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( b[input.nextInt()+1] := 1 ; ; i := i + 1 ) ; var r : long ; r := rec(0) ; OclFile["System.out"].println(r) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int m=Integer.parseInt(sc.next()); Integer[] a=new Integer[m]; Arrays.setAll(a,i->Integer.parseInt(sc.next())); sc.close(); Listlist=new ArrayList<>(); int index=0 ; for(int i=0 ; itoInteger() ; var m : int ; m := (sc.getCurrent())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,m)->collect(null) ; setAll(a, lambda i : OclAny in (sc.getCurrent())->toInteger()) ; skip ; var list : Sequence(int) ; list := Sequence{} ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( var num : int ; num := a[i+1] - index ; index := a[i+1] + 1 ; list := list->including(num) ) ; i := i + 1 ) ; list := list->including(n - index + 1) ; var fibonacci : Sequence(long) ; fibonacci := Integer.subrange(1,100001)->collect(0) ; var MOD : long ; MOD := 1000000007 ; fibonacci[0+1] := 1 ; fibonacci[1+1] := 1 ; var i : int ; i := 2 ; while i < 100001 do ( ( fibonacci[i+1] := (fibonacci[i - 1+1] + fibonacci[i - 2+1]) mod MOD ) ; i := i + 1 ) ; var result : long ; result := 1 ; if (list->includes(0)) then ( result := 0 ) else ( for (num : list) do ( ( result := result*(fibonacci[num - 1+1]) ; result := result mod MOD ) ) ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Integer steps[]; Long results[]; public Main(int n,Integer a[]){ steps=new Integer[n]; results=new Long[n]; for(int i=0 ; i=steps.length){ result=0 ; } else if(prefix==steps.length-1){ result=1 ; } else if(prefix==steps.length-2){ result=1+(((steps[prefix+1]==1)? 1 : 0)); } else { result=(((steps[prefix+1]==1)? calc(prefix+1): 0)+((steps[prefix+2]==1)? calc(prefix+2): 0)); result %=1_000_000_007L ; } results[prefix]=result ; return result ; } } ------------------------------------------------------------ OCL File: --------- class Main { attribute steps : Sequence(int); attribute results : Sequence(long); static operation newMain( n : int, a : Sequence(int)) : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(n, a); return self ); operation initialise( n : int, a : Sequence(int)) : void pre: true post: true activity: ( steps := Integer.subrange(1,n)->collect(null) ; results := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < steps->size() do ( ( steps[i+1] := 1 ; results[i+1] := -1L ) ; i := i + 1 ) ; for (e : a) do ( ( steps[e+1] := 0 ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var m : int ; m := s.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,m)->collect(null) ; var i : int ; i := 0 ; while i < m do ( ( a[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(Main.newMain(n, a).calc(0)) ; ); operation calc( prefix : int) : long pre: true post: true activity: ( var shortcut : long ; shortcut := results[prefix+1] ; var result : long ; if (shortcut /= -1L) then ( return shortcut ) else skip ; if (prefix >= steps->size()) then ( result := 0 ) else if (prefix = steps->size() - 1) then ( result := 1 ) else if (prefix = steps->size() - 2) then ( result := 1 + ((if (steps[prefix + 1+1] = 1) then 1 else 0 endif)) ) else ( result := ((if (steps[prefix + 1+1] = 1) then calc(prefix + 1) else 0 endif) + (if (steps[prefix + 2+1] = 1) then calc(prefix + 2) else 0 endif)) ; result := result mod 1_000_000_007L ) ; ; ; results[prefix+1] := result ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] a=new int[m]; int mod=1000000007 ; for(int i=0 ; i=0){ if(i+1<=n && dp[i+1]>=0){ dp[i+1]+=dp[i] % mod ; } if(i+2<=n && dp[i+2]>=0){ dp[i+2]+=dp[i] % mod ; } } } System.out.print(dp[n] % mod); } static boolean checkswitch(int bit,int[] k,ArrayList>list,int[] p,int m){ for(int i=0 ; isub=list.get(i); int onnum=0 ; for(int j=0 ; jtoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,m)->collect(0) ; var mod : int ; mod := 1000000007 ; var i : int ; i := 0 ; while i < m do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp[0+1] := 1 ; var i : int ; i := 0 ; while i < m do ( ( dp[a[i+1]+1] := -1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= n do ( ( if (dp[i+1] >= 0) then ( if (i + 1 <= n & dp[i + 1+1] >= 0) then ( dp[i + 1+1] := dp[i + 1+1]+(dp[i+1] mod mod) ) else skip ; if (i + 2 <= n & dp[i + 2+1] >= 0) then ( dp[i + 2+1] := dp[i + 2+1]+(dp[i+1] mod mod) ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(dp[n+1] mod mod) ; ); static operation checkswitch( bit : int, k : Sequence(int), list : Sequence(Sequence(int)), p : Sequence(int), m : int) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < m do ( ( var sub : Sequence(int) ; sub := list->at(i+1) ; var onnum : int ; onnum := 0 ; var j : int ; j := 0 ; while j < sub->size() do ( ( if ((bit & ((1*(2->pow(sub->at(j+1))))->oclAsType(long))) /= 0) then ( onnum := onnum + 1 ) else skip ) ; j := j + 1 ) ; if (onnum mod 2 /= p[i+1]) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (b = 0) then ( return a ) else ( return gcd(b, a mod b) ) ); } class Pair implements OclAny { attribute from : int; attribute end : int; operation compareTo( other : OclAny) : int pre: true post: true activity: ( var otherpair : Map ; otherpair := other->oclAsType(Map) ; return otherpair.end - end ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { private static final int MOD=1_000_000_007 ; private static int N ; private static int M ; private static boolean[] a ; private static int[] dp ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); N=sc.nextInt()+1 ; M=sc.nextInt(); a=new boolean[N]; Arrays.fill(a,true); for(int i=0 ; itoInteger() + 1 ; M := sc.getCurrent()->toInteger() ; a := Integer.subrange(1,N)->collect(false) ; a := a->collect(true) ; var i : int ; i := 0 ; while i < M do ( ( a[sc.getCurrent()->toInteger()+1] := false ) ; i := i + 1 ) ; dp := Integer.subrange(1,N)->collect(0) ; dp[0+1] := 1 ; var i : int ; i := 0 ; while i < N do ( ( if (not(a[i+1])) then continue else skip ; if (i + 1 < N) then ( dp[i + 1+1] := (dp[i + 1+1] + dp[i+1]) mod MOD ) else skip ; if (i + 2 < N) then ( dp[i + 2+1] := (dp[i + 2+1] + dp[i+1]) mod MOD ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(dp[N - 1+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c=sc.nextInt(); int max=0 ; int t[]=new int[n]; for(int i=0 ; itoInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var max : int ; max := 0 ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( t[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( max := Set{max, t[i+1] - t[i + 1+1] - c}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class practice2 { static long mod=(int)1e9+7 ; static boolean isPalindrome(String s){ int i=0 ; int j=s.length()-1 ; while(ia){ return gcd(b,a); } if(b==0){ return a ; } return gcd(b,a % b); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; ic)System.out.println(maxi-c); else System.out.println(0); } } ------------------------------------------------------------ OCL File: --------- class practice2 { static attribute mod : long := 1e9->oclAsType(int) + 7; static operation isPalindrome( s : String) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; var j : int ; j := s->size() - 1 ; while (i < j) do ( if (s->at(i+1) /= s->at(j+1)) then return false else skip ; i := i + 1 ; j := j - 1 ) ; return true ); static operation IsPalindrome( arr : Sequence(int), n : int, ele : int) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; var j : int ; j := n - 1 ; while (i < j) do ( if (arr[i+1] = ele) then ( i := i + 1 ) else if (arr[j+1] = ele) then ( j := j - 1 ) else if (arr[i+1] /= arr[j+1]) then return false else ( i := i + 1 ; j := j - 1 ) ; ; ) ; return true ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (b > a) then ( return gcd(b, a) ) else skip ; if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var maxi : int ; maxi := 0 ; var i : int ; i := 1 ; while i < n do ( ( maxi := Set{maxi, arr[i - 1+1] - arr[i+1]}->max() ) ; i := i + 1 ) ; if (maxi > c) then OclFile["System.out"].println(maxi - c) else OclFile["System.out"].println(0) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int arrayLeng=sc.nextInt(); int[] insSort=new int[arrayLeng]; for(int i=0 ; i=0 && insSort[j]>minNum){ insSort[j+1]=insSort[j]; j--; } insSort[j+1]=minNum ; insSortOutPut(); } } public void insSortOutPut(){ System.out.print(insSort[0]); for(int i=1 ; itoInteger() ; var insSort : Sequence(int) ; insSort := Integer.subrange(1,arrayLeng)->collect(0) ; var i : int ; i := 0 ; while i < insSort->size() do ( ( insSort[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var is : InsertionSort ; is := InsertionSort.newInsertionSort(insSort) ; is.insSortOutPut() ; is.numOfChange() ; ); } class InsertionSort { attribute insSort : Sequence(int); static operation newInsertionSort( insSort : Sequence(int)) : InsertionSort pre: true post: true activity: ( var self : InsertionSort ; self := createInsertionSort(); self.initialise(insSort); return self ); operation initialise( insSort : Sequence(int)) : void pre: true post: true activity: ( self.insSort := insSort ); operation numOfChange() : void pre: true post: true activity: ( var minNum : int ; minNum := 0 ; var i : int ; i := 0 ; var j : int ; while i < insSort->size() do ( ( if (i = 0) then ( continue ) else skip ; minNum := insSort[i+1] ; j := i - 1 ; while (j >= 0 & insSort[j+1] > minNum) do ( insSort[j + 1+1] := insSort[j+1] ; j := j - 1 ) ; insSort[j + 1+1] := minNum ; execute insSortOutPut() ; ) ; i := i + 1 ) ); operation insSortOutPut() : void pre: true post: true activity: ( OclFile["System.out"].print(insSort[0+1]) ; var i : int ; i := 1 ; while i < insSort->size() do ( ( OclFile["System.out"].print(" " + insSort[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].print("\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class SumOf2050 { public static void main(String[] args){ Scanner S=new Scanner(System.in); int n=S.nextInt(); while(n-->0){ long ip=S.nextLong(); if(ip % 2050!=0){ System.out.println(-1); } else { int l=(ip+"").length()-4 ; long div=2050L*(long)Math.pow(10,l); int count=0 ; while(ip>=2050){ count+=ip/div ; ip=ip % div ; div/=10 ; } System.out.println(count); } } } } ------------------------------------------------------------ OCL File: --------- class SumOf2050 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : OclFile ; S := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := S.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var ip : long ; ip := S.getCurrent()->toLong() ; if (ip mod 2050 /= 0) then ( OclFile["System.out"].println(-1) ) else ( var l : int ; l := (ip + "")->size() - 4 ; var div : long ; div := 2050L * 10->pow(l)->oclAsType(long) ; var count : int ; count := 0 ; while (ip >= 2050) do ( count := count+(ip / div) ; ip := ip mod div ; div := div/(10) ) ; OclFile["System.out"].println(count) ; ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c=sc.nextInt(); int maxjoy=Integer.MIN_VALUE ; int arr[]=new int[n]; for(int i=0 ; i0 ? maxjoy-c : 0); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var maxjoy : int ; maxjoy := -2147483648 ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( maxjoy := Set{maxjoy, arr[i+1] - arr[i + 1+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(if maxjoy - c > 0 then maxjoy - c else 0 endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MainClass { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c=sc.nextInt(); int[] lst=new int[n]; for(int i=0 ; itoInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var lst : Sequence(int) ; lst := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( lst[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( res := Set{res, lst[i+1] - lst[i + 1+1] - c}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { FastReader fr=new FastReader(); int n=fr.nextInt(); if(n<3){ System.out.println(0); } else { int result=n/3 ; System.out.println(result); } } } class FastReader { BufferedReader br ; StringTokenizer st ; FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fr : FastReader ; fr := FastReader.newFastReader() ; var n : int ; n := fr.nextInt() ; if (n < 3) then ( OclFile["System.out"].println(0) ) else ( var result : int ; result := n / 3 ; OclFile["System.out"].println(result) ) ); } class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; import java.util.ArrayDeque ; import java.util.Queue ; import java.util.LinkedList ; public class Main { public static void main(String[] args){ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); System.out.println(N/3); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(N / 3) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.InputMismatchException ; import java.io.IOException ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.i(); if(n<=2){ out.println(0); return ; } out.println((n-3)/3+1); } } static class InputReader { InputStream is ; private byte[] inbuf=new byte[1024]; public int lenbuf=0 ; public int ptrbuf=0 ; public InputReader(InputStream is){ this.is=is ; } private int readByte(){ if(lenbuf==-1)throw new InputMismatchException(); if(ptrbuf>=lenbuf){ ptrbuf=0 ; try { lenbuf=is.read(inbuf); } catch(IOException e){ throw new InputMismatchException(); } if(lenbuf<=0)return-1 ; } return inbuf[ptrbuf++]; } public int i(){ int num=0,b ; boolean minus=false ; while((b=readByte())!=-1 && !((b>='0' && b<='9')|| b=='-')); if(b=='-'){ minus=true ; b=readByte(); } while(true){ if(b>='0' && b<='9'){ num=num*10+(b-'0'); } else { return minus ?-num : num ; } b=readByte(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskA ; solver := TaskA.newTaskA() ; solver.solve(1, in, out) ; skip ; ); static class TaskA { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.i() ; if (n <= 2) then ( skip ; return ) else skip ; skip ); } static class InputReader { attribute is : OclFile; attribute inbuf : Sequence(int) := Integer.subrange(1,1024)->collect(0); attribute lenbuf : int := 0; attribute ptrbuf : int := 0; static operation newInputReader( is : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(is); return self ); operation initialise( is : OclFile) : void pre: true post: true activity: ( self.is := is ); operation readByte() : int pre: true post: true activity: ( if (lenbuf = -1) then error IncorrectElementException() ; else skip ; if (ptrbuf >= lenbuf) then ( ptrbuf := 0 ; try ( lenbuf := is.read(inbuf) ) catch (e : IOException) do ( error IncorrectElementException() ) if (lenbuf <= 0) then return -1 else skip ) else skip ; return inbuf[ptrbuf+1] ); operation i() : int pre: true post: true activity: ( var num : int ; num := 0 ; var b : int ; var minus : boolean ; minus := false ; b := readByte() ; while ((b) /= -1 & not(((b >= '0' & b <= '9') or b = '-'))) do ( skip ; ; b := readByte() ; ) ; if (b = '-') then ( minus := true ; b := readByte() ) else skip ; while (true) do ( if (b >= '0' & b <= '9') then ( num := num * 10 + (b - ('0')->char2byte()) ) else ( return if minus then -num else num endif ) ; b := readByte() ) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); System.out.println(problem089a(n)); } private static int problem089a(int n){ return n/3 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; OclFile["System.out"].println(problem089a(n)) ); static operation problem089a( n : int) : int pre: true post: true activity: ( return n / 3 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int cnt=0 ; if(n % 3==0){ cnt=n/3 ; } else { while(true){ if(n<3)break ; if(n-3>=3){ n-=3 ; cnt++; } else { cnt++; break ; } } } System.out.println(cnt); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var cnt : int ; cnt := 0 ; if (n mod 3 = 0) then ( cnt := n / 3 ) else ( while (true) do ( if (n < 3) then break else skip ; if (n - 3 >= 3) then ( n := n-(3) ; cnt := cnt + 1 ) else ( cnt := cnt + 1 ; break ) ) ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ new Main().run(); } private Scanner sc=new Scanner(System.in); private void run(){ int N=Integer.parseInt(sc.next()); boolean approved=true ; for(int i=0 ; itoInteger() ; var approved : boolean ; approved := true ; var i : int ; i := 0 ; while i < N do ( ( var num : int ; num := (sc.getCurrent())->toInteger() ; if (num mod 2 = 0) then ( if (not((num mod 3 = 0 or num mod 5 = 0))) then ( approved := false ; break ) else skip ) else skip ) ; i := i + 1 ) ; if (approved) then ( OclFile["System.out"].println("APPROVED") ) else ( OclFile["System.out"].println("DENIED") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A[]=new int[N]; String str="APPROVED" ; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var str : String ; str := "APPROVED" ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ; if (A[i+1] mod 2 = 0) then ( if (A[i+1] mod 3 /= 0 & A[i+1] mod 5 /= 0) then ( str := "DENIED" ) else skip ) else skip ) ; i := i + 1 ) ; skip ; OclFile["System.out"].println(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); int[] k=new int[M]; List[] S=new ArrayList[M]; int[] p=new int[M]; for(int i=0 ; i(); for(int j=0 ; j[] s,int[] p){ int count=0 ; for(int i=0 ; is,int p){ int count=0 ; for(int i=0 ; i>(idx-1))% 2 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var k : Sequence(int) ; k := Integer.subrange(1,M)->collect(0) ; var S : Sequence(Sequence(int)) ; S := Integer.subrange(1,M)->collect(null) ; var p : Sequence(int) ; p := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( k[i+1] := sc.getCurrent()->toInteger() ; S[i+1] := Sequence{} ; var j : int ; j := 0 ; while j < k[i+1] do ( ( S[i+1]->excludes(sc.getCurrent()->toInteger()) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( p[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(N, M, k, S, p)) ; ); static operation solve( N : int, M : int, k : Sequence(int), s : Sequence(Sequence(int)), p : Sequence(int)) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < 2->pow(N) do ( ( var on : boolean ; on := true ; var j : int ; j := 0 ; while j < M do ( ( if (not(isOn(N, i, k[j+1], s[j+1], p[j+1]))) then ( on := false ; break ) else skip ) ; j := j + 1 ) ; if (on) then count := count + 1 ; else skip ) ; i := i + 1 ) ; return count ); static operation isOn( N : int, state : int, k : int, s : Sequence(int), p : int) : boolean pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < k do ( ( count := count+(getStatus(state, s->at(i+1))) ) ; i := i + 1 ) ; return count mod 2 = p ); static operation getStatus( status : int, idx : int) : int pre: true post: true activity: ( return ((status/(2->pow((idx - 1))))->oclAsType(long)) mod 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); boolean approved=true ; for(int i=0 ; itoInteger() ; var approved : boolean ; approved := true ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; if (a mod 2 = 0) then ( if (not((a mod 3 = 0)) & not((a mod 5 = 0))) then ( OclFile["System.out"].println("DENIED") ; return ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("APPROVED") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(bf.readLine()); while(t-->0){ long n=Long.parseLong(bf.readLine()); int sum=0 ; if(n % 2050==0){ n/=2050 ; while(n>0){ sum+=n % 10 ; n/=10 ; } System.out.println(sum); } else { System.out.println(-1); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var t : int ; t := (bf.readLine())->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : long ; n := (bf.readLine())->toLong() ; var sum : int ; sum := 0 ; if (n mod 2050 = 0) then ( n := n/(2050) ; while (n > 0) do ( sum := sum+(n mod 10) ; n := n/(10) ) ; OclFile["System.out"].println(sum) ) else ( OclFile["System.out"].println(-1) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); while(0toInteger() ; while (0 < N) do ( var n : int ; n := in.getCurrent()->toInteger() ; if (n mod 2 = 0 & (n mod 3 /= 0 & n mod 5 /= 0)) then break else skip ; N := N - 1 ) ; OclFile["System.out"].println(if 0 < N then "DENIED" else "APPROVED" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(); int[] h=new int[n]; for(int i=0 ; itoInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( h[i+1] := stdIn.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (h[i+1] mod 2 = 0) then ( if ((h[i+1] mod 3 = 0 or h[i+1] mod 5 = 0)) then skip else ( break ) ) else skip ) ; i := i + 1 ) ; if (i = n) then OclFile["System.out"].println("APPROVED") else OclFile["System.out"].println("DENIED") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int totalOperations(String str,int len){ HashMaph=new HashMap(); for(int i=0 ; i>set=h.entrySet(); HashSeths=new HashSet(); for(Map.Entryme : set)hs.add(me.getValue()); return hs.size(); } public static void main(String[] args){ String str="geeksforgeeks" ; int len=str.length(); System.out.println(totalOperations(str,len)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation totalOperations( str : String, len : int) : int pre: true post: true activity: ( var h : Map(String,int) ; h := Map{} ; var i : int ; i := 0 ; while i < len do ( ( if (h->keys()->includes(str->at(i+1))) then h := h->union(Map{str->at(i+1) |-> h->at(str->at(i+1)) + 1}) ; else h := h->union(Map{str->at(i+1) |-> 1}) ; ) ; i := i + 1 ) ; var set : Set(Map(String,int)) ; set := h->asSet() ; var hs : Set(int) ; hs := Set{} ; for (me : set) do ( hs := hs->including(me.getValue()) ; ) ; return hs->size() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var len : int ; len := str->size() ; OclFile["System.out"].println(totalOperations(str, len)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int count(String s,int k){ int n=s.length(); int d=0,i ; int count=0 ; for(i=0 ; isize() ; var d : int ; d := 0 ; var i : int ; var count : int ; count := 0 ; i := 0 ; while i < n do ( d := d+(s->at(i+1)) ; ; i := i + 1 ) ; if (d mod k = 0) then count := count+(1) ; else skip ; i := k ; while i < n do ( ( var prev : int ; prev := s->at(i - k+1) ; d := d-(prev) ; d := d+(s->at(i+1)) ; if (d mod k = 0) then count := count+(1) ; else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "bcgabc" ; var k : int ; k := 3 ; var ans : int ; ans := count(s, k) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static int Xor_Sum(int[] arr,int n){ int sum=0,index=-1 ; int left_xor=0,right_xor=0 ; for(int i=0 ; isum){ sum=left_xor+right_xor ; index=i ; } } return index+1 ; } public static void main(String[] args){ int[] arr={ 1,4,6,3,8,13,34,2,21,10 }; int n=arr.length ; System.out.println(Xor_Sum(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Xor_Sum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var index : int ; index := -1 ; var left_xor : int ; left_xor := 0 ; var right_xor : int ; right_xor := 0 ; var i : int ; i := 0 ; while i < n do ( ( left_xor := MathLib.bitwiseXor(left_xor,arr[i+1]) ; right_xor := 0 ; var j : int ; j := i + 1 ; while j < n do ( ( right_xor := MathLib.bitwiseXor(right_xor,arr[j+1]) ) ; j := j + 1 ) ; if (left_xor + right_xor > sum) then ( sum := left_xor + right_xor ; index := i ) else skip ) ; i := i + 1 ) ; return index + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,4,6,3,8,13,34,2,21,10} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(Xor_Sum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static double getMaxMedian(int[] arr,int n,int k){ int size=n+k ; Arrays.sort(arr); if(size % 2==0){ double median=(double)(arr[(size/2)-1]+arr[size/2])/2 ; return median ; } double median1=arr[size/2]; return median1 ; } public static void main(String[] args){ int[] arr={ 3,2,3,4,2 }; int n=arr.length ; int k=2 ; System.out.print((int)getMaxMedian(arr,n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getMaxMedian( arr : Sequence(int), n : int, k : int) : double pre: true post: true activity: ( var size : int ; size := n + k ; arr := arr->sort() ; if (size mod 2 = 0) then ( var median : double ; median := (arr[(size / 2) - 1+1] + arr[size / 2+1])->oclAsType(double) / 2 ; return median ) else skip ; var median1 : double ; median1 := arr[size / 2+1] ; return median1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,2,3,4,2} ; var n : int ; n := arr->size() ; var k : int ; k := 2 ; OclFile["System.out"].print(getMaxMedian(arr, n, k)->oclAsType(int)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),a=0,d=0 ; String s=in.next(); for(int i=0 ; id ? "Anton" :(atoInteger() ; var a : int ; a := 0 ; var d : int ; d := 0 ; var s : String ; s := in.getCurrent() ; var i : int ; i := 0 ; while i < n do ( ( if (s->at(i+1) = 'A') then a := a + 1 ; else d := d + 1 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(if a > d then "Anton" else if (a < d) then "Danik" else "Friendship" endif endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class scratch { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String st=br.readLine(); int a=0,b=0 ; for(int i=0 ; ib)System.out.println("Anton"); else if(b>a)System.out.println("Danik"); else System.out.println("Friendship"); } } ------------------------------------------------------------ OCL File: --------- class scratch { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var st : String ; st := br.readLine() ; var a : int ; a := 0 ; var b : int ; b := 0 ; var i : int ; i := 0 ; while i < st->size() do ( ( var ch : String ; ch := st->at(i+1) ; if (ch = 'A') then a := a+(1) ; else b := b+(1) ; ) ; i := i + 1 ) ; if (a > b) then OclFile["System.out"].println("Anton") else if (b > a) then OclFile["System.out"].println("Danik") else OclFile["System.out"].println("Friendship") ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); ArrayListar=new ArrayList<>(); int plus[][]=new int[5][2]; for(int i=0 ; i<5 ; i++){ int set=sc.nextInt(); ar.add(set); plus[i][0]=set ; plus[i][1]=plus[i][0] % 10 ; } Arrays.sort(plus,(a,b)->Integer.compare(a[1],b[1])); int ans=0 ; for(int i=0 ; i<5 ; i++){ if(plus[i][1]==0){ ans+=plus[i][0]; ar.remove(ar.indexOf(plus[i][0])); } } Arrays.sort(plus,(a,b)->Integer.compare(b[1],a[1])); for(int i=0 ; icollect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < 5 do ( ( var set : int ; set := sc.getCurrent()->toInteger() ; ar := ar->including(set) ; plus[i+1][0+1] := set ; plus[i+1][1+1] := plus[i+1][0+1] mod 10 ) ; i := i + 1 ) ; plus := OclComparator.sortWith(plus, lambda (a , b) : OclAny in compare(a[1+1], b[1+1])) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 5 do ( ( if (plus[i+1][1+1] = 0) then ( ans := ans+(plus[i+1][0+1]) ; ar := ar->excludingFirst(ar->indexOf(plus[i+1][0+1])-1) ) else skip ) ; i := i + 1 ) ; plus := OclComparator.sortWith(plus, lambda (a , b) : OclAny in compare(b[1+1], a[1+1])) ; var i : int ; i := 0 ; while i < ar->size() do ( ( if (ans mod 10 = 0) then ( ans := ans+(plus[i+1][0+1]) ) else ( while (ans mod 10 /= 0) do ( ans := ans+(1) ) ; ans := ans+(plus[i+1][0+1]) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char arr[]=sc.next().toCharArray(); int a=0,b=0 ; for(int i=0 ; ib)System.out.println("Anton"); else if(atoInteger() ; var arr : Sequence(String) ; arr := sc.getCurrent()->characters() ; var a : int ; a := 0 ; var b : int ; b := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = 'A') then a := a + 1 ; else b := b + 1 ; ) ; i := i + 1 ) ; if (a > b) then OclFile["System.out"].println("Anton") else if (a < b) then OclFile["System.out"].println("Danik") else OclFile["System.out"].println("Friendship") ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Eleven { public static void main(String[] args){ Scanner inp=new Scanner(System.in); int a=0 ; int d=0 ; int n=inp.nextInt(); String str=inp.next(); for(int i=0 ; id){ System.out.println("Anton"); } else if(d>a){ System.out.println("Danik"); } else if(a==d){ System.out.println("Friendship"); } } } ------------------------------------------------------------ OCL File: --------- class Eleven { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inp : OclFile ; inp := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := 0 ; var d : int ; d := 0 ; var n : int ; n := inp.getCurrent()->toInteger() ; var str : String ; str := inp.getCurrent() ; var i : int ; i := 0 ; while i < n do ( ( if (str->at(i+1) = 'A') then ( a := a + 1 ) else if (str->at(i+1) = 'D') then ( d := d + 1 ) else skip ; ) ; i := i + 1 ) ; if (a > d) then ( OclFile["System.out"].println("Anton") ) else if (d > a) then ( OclFile["System.out"].println("Danik") ) else if (a = d) then ( OclFile["System.out"].println("Friendship") ) else skip ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DisplayTheNumber { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(); if(n % 2==1){ System.out.print(7); n-=3 ; } while(n>0){ System.out.print(1); n-=2 ; } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class DisplayTheNumber { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := sc.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n mod 2 = 1) then ( OclFile["System.out"].print(7) ; n := n-(3) ) else skip ; while (n > 0) do ( OclFile["System.out"].print(1) ; n := n-(2) ) ; OclFile["System.out"].println() ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int size=in.nextInt(); String str=in.next(); int anton=0 ; int danik=0 ; for(int i=0 ; idanik)out.println("Anton"); else if(antonat(i+1) = 'A') then anton := anton + 1 ; else danik := danik + 1 ; ) ; i := i + 1 ) ; if (anton > danik) then skip else if (anton < danik) then ( skip ) else ( skip ) ; ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("sub.in"))) ) catch (ex : FileNotFoundException) do ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (ex : IOException) do skip ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (ex : IOException) do skip return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c=sc.nextInt(); int sum=0,finalSum1=0,finalSum2=0 ; int p[]=new int[n]; int t[]=new int[n]; for(int i=0 ; i=0 ; i--){ sum+=t[i]; int ans=Math.max(0,(p[i]-(sum*c))); finalSum2+=ans ; } if(finalSum1>finalSum2){ System.out.println("Limak"); } else if(finalSum1toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var finalSum1 : int ; finalSum1 := 0 ; var finalSum2 : int ; finalSum2 := 0 ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( t[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(t[i+1]) ; var ans1 : int ; ans1 := Set{0, (p[i+1] - (sum * c))}->max() ; finalSum1 := finalSum1+(ans1) ) ; i := i + 1 ) ; var j : int ; j := 0 ; sum := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( sum := sum+(t[i+1]) ; var ans : int ; ans := Set{0, (p[i+1] - (sum * c))}->max() ; finalSum2 := finalSum2+(ans) ) ; i := i - 1 ) ; if (finalSum1 > finalSum2) then ( OclFile["System.out"].println("Limak") ) else if (finalSum1 < finalSum2) then ( OclFile["System.out"].println("Radewoosh") ) else if (finalSum1 = finalSum2) then ( OclFile["System.out"].println("Tie") ) else skip ; ; ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class P658A_BearAndReverseRadewoosh { public static void main(String[] subhani)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()),c=Integer.parseInt(st.nextToken()); int[] points=new int[n]; st=new StringTokenizer(br.readLine()); for(int i=0 ; i=0 ; --i){ t+=time[i]; radewoosh+=Math.max(0,points[i]-c*t); } if(limak>radewoosh)System.out.println("Limak"); else if(limaktoInteger() ; var c : int ; c := (st.next())->toInteger() ; var points : Sequence(int) ; points := Integer.subrange(1,n)->collect(0) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( points[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; var time : Sequence(int) ; time := Integer.subrange(1,n)->collect(0) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( time[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; execute solve(n, c, points, time) ; ); static operation solve( n : int, c : int, points : Sequence(int), time : Sequence(int)) : void pre: true post: true activity: ( var limak : int ; limak := 0 ; var radewoosh : int ; radewoosh := 0 ; var t : int ; t := 0 ; var i : int ; i := 0 ; while i < n do ( ( t := t+(time[i+1]) ; limak := limak+(Set{0, points[i+1] - c * t}->max()) ) ; i := i + 1 ) ; t := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( t := t+(time[i+1]) ; radewoosh := radewoosh+(Set{0, points[i+1] - c * t}->max()) ) ; i := i - 1 ) ; if (limak > radewoosh) then OclFile["System.out"].println("Limak") else if (limak < radewoosh) then OclFile["System.out"].println("Radewoosh") else OclFile["System.out"].println("Tie") ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A658 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(),c=scanner.nextInt(); int[] p=new int[n],t=new int[n]; for(int i=0 ; i=0 ; i--){ tRade+=t[i]; sumRadewoosh+=Math.max(0,(p[i]-(c*tRade))); } System.out.println(sumLimak>sumRadewoosh ? "Limak" : sumLimaktoInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( t[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var sumLimak : int ; sumLimak := 0 ; var sumRadewoosh : int ; sumRadewoosh := 0 ; var tLimak : int ; tLimak := 0 ; var tRade : int ; tRade := 0 ; var i : int ; i := 0 ; while i < n do ( ( tLimak := tLimak+(t[i+1]) ; sumLimak := sumLimak+(Set{0, (p[i+1] - (c * tLimak))}->max()) ) ; i := i + 1 ) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( tRade := tRade+(t[i+1]) ; sumRadewoosh := sumRadewoosh+(Set{0, (p[i+1] - (c * tRade))}->max()) ) ; i := i - 1 ) ; OclFile["System.out"].println(if sumLimak > sumRadewoosh then "Limak" else if sumLimak < sumRadewoosh then "Radewoosh" else "Tie" endif endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c=sc.nextInt(); int sum=0,sum1=0,finalSum1=0,finalSum2=0 ; int p[]=new int[n]; int t[]=new int[n]; for(int i=0 ; ifinalSum2){ System.out.println("Limak"); } else if(finalSum1toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var sum1 : int ; sum1 := 0 ; var finalSum1 : int ; finalSum1 := 0 ; var finalSum2 : int ; finalSum2 := 0 ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( t[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(t[i+1]) ; sum1 := sum1+(t[n - i - 1+1]) ; var ans1 : int ; ans1 := Set{0, (p[i+1] - (sum * c))}->max() ; var ans2 : int ; ans2 := Set{0, (p[n - i - 1+1] - (sum1 * c))}->max() ; finalSum1 := finalSum1+(ans1) ; finalSum2 := finalSum2+(ans2) ; ) ; i := i + 1 ) ; if (finalSum1 > finalSum2) then ( OclFile["System.out"].println("Limak") ) else if (finalSum1 < finalSum2) then ( OclFile["System.out"].println("Radewoosh") ) else if (finalSum1 = finalSum2) then ( OclFile["System.out"].println("Tie") ) else skip ; ; ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=11 ; static boolean isMultipleof5(int n){ char str[]=new char[MAX]; int len=str.length ; if(str[len-1]=='5' || str[len-1]=='0')return true ; return false ; } public static void main(String[] args){ int n=19 ; if(isMultipleof5(n)==true)System.out.println(n+" is multiple "+"of 5"); else System.out.println(n+" is not a "+"multiple of 5"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 11; static operation isMultipleof5( n : int) : boolean pre: true post: true activity: ( var str : Sequence(String) ; str := Integer.subrange(1,MAX)->collect(0) ; var len : int ; len := str->size() ; if (str[(len)->char2byte() - 1+1] = '5' or str[(len)->char2byte() - 1+1] = '0') then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 19 ; if (isMultipleof5(n) = true) then OclFile["System.out"].println(n + " is multiple " + "of 5") ; else OclFile["System.out"].println(n + " is not a " + "multiple of 5") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Map ; import java.util.HashMap ; import java.util.List ; import java.util.ArrayList ; public class Main { static Scanner sc=new Scanner(System.in); static int n,m ; static MapcostMap ; static Map>itemMap ; public static void main(String args[]){ while(true){ n=sc.nextInt(); if(n==0)break ; costMap=new HashMap(); itemMap=new HashMap>(); for(int i=0 ; ial=new ArrayList(); for(int k=0 ; ktoInteger() ; if (n = 0) then break else skip ; costMap := Map{} ; itemMap := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var item : String ; item := sc.getCurrent() ; var cost : int ; cost := sc.getCurrent()->toInteger() ; costMap := costMap->union(Map{item |-> cost}) ) ; i := i + 1 ) ; m := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < m do ( ( var product : String ; product := sc.getCurrent() ; var materialNum : int ; materialNum := sc.getCurrent()->toInteger() ; var al : Sequence(String) ; al := Sequence{} ; var k : int ; k := 0 ; while k < materialNum do ( ( al := al->including(sc.getCurrent()) ) ; k := k + 1 ) ; itemMap := itemMap->union(Map{product |-> al}) ; ) ; j := j + 1 ) ; var target : String ; target := sc.getCurrent() ; var answer : int ; answer := search(target) ; OclFile["System.out"].println(answer) ; ) ); static operation search( target : String) : int pre: true post: true activity: ( if (itemMap->keys()->includes(target)) then ( var sum : int ; sum := 0 ; for (item : itemMap->at(target)) do ( ( sum := sum+(search(item)) ) ) ; return Set{costMap->at(target), sum}->min() ) else ( return costMap->at(target) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int A=stdIn.nextInt(); int B=stdIn.nextInt(); int C=stdIn.nextInt(); int D=stdIn.nextInt(); int E=stdIn.nextInt(); int a=(A/10+1)*10-A,b=(B/10+1)*10-B,c=(C/10+1)*10-C,d=(D/10+1)*10-D,e=(E/10+1)*10-E ; int max=0 ; if(a>max && a!=10)max=a ; if(a==10)a=0 ; if(b>max && b!=10)max=b ; if(b==10)b=0 ; if(c>max && c!=10)max=c ; if(c==10)c=0 ; if(d>max && d!=10)max=d ; if(d==10)d=0 ; if(e>max && e!=10)max=e ; if(e==10)e=0 ; System.out.println(A+B+C+D+E+a+b+c+d+e-max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; A := stdIn.getCurrent()->toInteger() ; var B : int ; B := stdIn.getCurrent()->toInteger() ; var C : int ; C := stdIn.getCurrent()->toInteger() ; var D : int ; D := stdIn.getCurrent()->toInteger() ; var E : int ; E := stdIn.getCurrent()->toInteger() ; var a : int ; a := (A / 10 + 1) * 10 - A ; var b : int ; b := (B / 10 + 1) * 10 - B ; var c : int ; c := (C / 10 + 1) * 10 - C ; var d : int ; d := (D / 10 + 1) * 10 - D ; var e : int ; e := (E / 10 + 1) * 10 - E ; var max : int ; max := 0 ; if (a > max & a /= 10) then max := a ; else skip ; if (a = 10) then a := 0 ; else skip ; if (b > max & b /= 10) then max := b ; else skip ; if (b = 10) then b := 0 ; else skip ; if (c > max & c /= 10) then max := c ; else skip ; if (c = 10) then c := 0 ; else skip ; if (d > max & d /= 10) then max := d ; else skip ; if (d = 10) then d := 0 ; else skip ; if (e > max & e /= 10) then max := e ; else skip ; if (e = 10) then e := 0 ; else skip ; OclFile["System.out"].println(A + B + C + D + E + a + b + c + d + e - max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; class Main { public static void main(String[] args)throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader reader=new BufferedReader(isr); String string,str[]; int n,m,sum ; while(!(string=reader.readLine()).equals("0")){ n=Integer.valueOf(string); HashMapmap=new HashMap(); for(int i=0 ; isum)map.put(str[0],sum); } System.out.println(map.get(reader.readLine())); } reader.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var reader : OclFile ; reader := OclFile.newOclFile_Read(isr) ; var string : String ; var str : Sequence(void) ; var n : int ; var m : int ; var sum : int ; while (not((string) = "0")) do ( n := (string)->toInteger() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( str := reader.readLine()->split(" ") ; map := map->union(Map{str[0+1] |-> (str[1+1])->toInteger()}) ) ; i := i + 1 ) ; n := (reader.readLine())->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( str := reader.readLine()->split(" ") ; m := (str[1+1])->toInteger() ; sum := 0 ; var j : int ; j := 0 ; while j < m do ( ( sum := sum+(map->at(str[j + 2+1])) ) ; j := j + 1 ) ; if (map->at(str[0+1]) > sum) then map := map->union(Map{str[0+1] |-> sum}) ; else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(map->at(reader.readLine())) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static HashMapdat ; static HashMapmemo ; static String table[][]; static String k[]; static int size[]; static int b ; static int solve(String a){ if(memo.containsKey(a))return memo.get(a); if(! dat.containsKey(a))return 999999999 ; int ret=dat.get(a); for(int i=0 ; i(); memo=new HashMap(); while(true){ a=s.nextInt(); dat.clear(); memo.clear(); if(a==0)System.exit(0); for(int i=0 ; ikeys()->includes(a)) then return memo->at(a) else skip ; if (not(dat->keys()->includes(a))) then return 999999999 else skip ; var ret : int ; ret := dat->at(a) ; var i : int ; i := 0 ; while i < b do ( ( if (k[i+1] = a) then ( var val : int ; val := 0 ; var j : int ; j := 0 ; while j < size[i+1] do ( ( val := val+(solve(table[i+1][j+1])) ) ; j := j + 1 ) ; ret := Set{ret, val}->min() ; break ) else skip ) ; i := i + 1 ) ; memo := memo->union(Map{a |-> ret}) ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; k := Integer.subrange(1,100)->collect(null) ; table := Integer.subrange(1,100)->collect(Integer.subrange(1,100)->collect(null)) ; size := Integer.subrange(1,100)->collect(0) ; dat := Map{} ; memo := Map{} ; while (true) do ( a := s.getCurrent()->toInteger() ; dat := dat->intersection(Map{}) ; memo := memo->intersection(Map{}) ; if (a = 0) then OclProcess.exit(0) ; else skip ; var i : int ; i := 0 ; while i < a do ( ( var str : String ; str := s.getCurrent() ; var p : int ; p := s.getCurrent()->toInteger() ; dat := dat->union(Map{str |-> p}) ) ; i := i + 1 ) ; b := s.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < b do ( ( k[i+1] := s.getCurrent() ; size[i+1] := s.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < size[i+1] do ( table[i+1][j+1] := s.getCurrent() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var m : String ; m := s.getCurrent() ; OclFile["System.out"].println(solve(m)) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; class Alchemy { public static void input_data(int n){ for(int i=0 ; iitem_data=new HashMap(); public static void main(String[] args){ while(sc.hasNext()){ int n=Integer.parseInt(sc.nextLine()); if(n==0){ break ; } Alchemy.input_data(n); int m=Integer.parseInt(sc.nextLine()); Alchemy.input_recipe(m); System.out.println(item_data.get(sc.nextLine())); item_data.clear(); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Alchemy { static operation input_data( n : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n do ( ( var name_cost : Sequence(String) ; name_cost := Main.sc.nextLine()->split(" ") ; var name : String ; name := name_cost[0+1] ; var cost : int ; cost := (name_cost[1+1])->toInteger() ; Main := Main.item_data->union(Map{name |-> cost}) ) ; i := i + 1 ) ); static operation input_recipe( m : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < m do ( ( var recipe : Sequence(String) ; recipe := Main.sc.nextLine()->split(" ") ; var output : String ; output := recipe[0+1] ; var prod_fee : int ; prod_fee := 0 ; var k : int ; k := (recipe[1+1])->toInteger() ; var j : int ; j := 0 ; while j < k do ( ( prod_fee := prod_fee+(Main.item_data->at(recipe[2 + j+1]+1)) ) ; j := j + 1 ) ; Main := Main.item_data->union(Map{output |-> Set{prod_fee, Main.item_data->at(output+1)}->min()}) ; ) ; i := i + 1 ) ); } class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute item_data : Map(String,int) := Map{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (sc.hasNext()) do ( var n : int ; n := (sc.nextLine())->toInteger() ; if (n = 0) then ( break ) else skip ; Alchemy.input_data(n) ; var m : int ; m := (sc.nextLine())->toInteger() ; Alchemy.input_recipe(m) ; OclFile["System.out"].println(item_data->at(sc.nextLine())) ; item_data := item_data->intersection(Map{}) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF1295A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); while(t-->0){ int n=scan.nextInt(); if(n % 2==1){ System.out.print("7"); n-=3 ; } while(n>0){ System.out.print("1"); n-=2 ; } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class CF1295A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scan.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := scan.getCurrent()->toInteger() ; if (n mod 2 = 1) then ( OclFile["System.out"].print("7") ; n := n-(3) ) else skip ; while (n > 0) do ( OclFile["System.out"].print("1") ; n := n-(2) ) ; OclFile["System.out"].println() ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner in=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new AOJ0201(); } class AOJ0201 { HashMap>map ; HashMapprice ; int bfs(String target){ int a=Integer.MAX_VALUE ; int b=0 ; if(price.containsKey(target))a=price.get(target); if(map.containsKey(target)==false)return a ; ArrayListlist=map.get(target); for(int i=0 ; i>(); price=new HashMap(); int n=in.nextInt(); if(n==0)break ; for(int i=0 ; ilist ; if(! map.containsKey(name))list=new ArrayList(); else list=map.get(name); int a=in.nextInt(); for(int s=0 ; skeys()->includes(target)) then a := price->at(target) ; else skip ; if (map->keys()->includes(target) = false) then return a else skip ; var list : Sequence(String) ; list := map->at(target) ; var i : int ; i := 0 ; while i < list->size() do ( if (map->keys()->includes(list->at(i+1)) or price->keys()->includes(list->at(i+1))) then ( b := b+(bfs(list->at(i+1))) ) else skip ; ; i := i + 1 ) ; return Set{a, b}->min() ); static operation newAOJ0201() : AOJ0201 pre: true post: true activity: ( var self : AOJ0201 ; self := createAOJ0201(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( while (true) do ( map := Map{} ; price := Map{} ; var n : int ; n := in.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var i : int ; i := 0 ; while i < n do ( price := price->union(Map{in.getCurrent() |-> in.getCurrent()->toInteger()}) ; ; i := i + 1 ) ; var list_n : int ; list_n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < list_n do ( ( var name : String ; name := in.getCurrent() ; var list : Sequence(String) ; if (not(map->keys()->includes(name))) then list := Sequence{} else list := map->at(name) ; ; var a : int ; a := in.getCurrent()->toInteger() ; var s : int ; s := 0 ; while s < a do ( list := list->including(in.getCurrent()) ; ; s := s + 1 ) ; map := map->union(Map{name |-> list}) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(bfs(in.getCurrent())) ; ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static boolean pd(String s){ if(s.charAt(0)=='@' || s.charAt(s.length()-1)=='@')return false ; for(int i=0 ; iat(0+1) = '@' or s->at(s->size() - 1+1) = '@') then return false else skip ; var i : int ; i := 0 ; while i < s->size() - 1 do ( ( if (s->at(i+1) = '@' & s->at(i + 1+1) = '@') then return false else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s->size() - 2 do ( ( if (s->at(i+1) = '@' & s->at(i + 2+1) = '@') then return false else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; var t : boolean ; t := pd(str) ; var sum : int ; sum := 0 ; var num : int ; num := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = '@') then sum := sum + 1 ; else skip ) ; i := i + 1 ) ; if (sum = 0) then OclFile["System.out"].println("No solution") ; else skip ; if (t) then ( var s : String ; s := "" ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = '@') then ( num := num + 1 ; if (num < sum) then ( OclFile["System.out"].print(s + '@' + str->at(i + 1+1)) ; OclFile["System.out"].print(',') ; i := i + 1 ) else if (num = sum) then ( OclFile["System.out"].print(s + '@') ; var j : int ; j := i + 1 ; while j < str->size() do ( ( OclFile["System.out"].print(str->at(j+1)) ) ; j := j + 1 ) ) else skip ; ; s := "" ; continue ) else skip ; s := s+(str->at(i+1)) ) ; i := i + 1 ) ) else ( OclFile["System.out"].println("No solution") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class B31 { public static void main(String[] args){ Scanner in=new Scanner(System.in); String S=in.next(); boolean ok=! S.startsWith("@")&& ! S.endsWith("@"); Listparts=new ArrayList<>(); if(ok){ int last=-1 ; while(true){ int current=S.indexOf('@',last+1); if(current==-1){ if(parts.isEmpty()){ ok=false ; break ; } parts.add(S.substring(last+1)); break ; } else { String part=S.substring(last+1,current); if(part.length()<2 && ! parts.isEmpty()){ ok=false ; break ; } parts.add(part); last=current ; } } } if(ok){ StringBuilder out=new StringBuilder(); boolean first=true ; for(int i=1 ; ihasPrefix("@")) & not(S->hasSuffix("@")) ; var parts : Sequence(String) ; parts := Sequence{} ; if (ok) then ( var last : int ; last := -1 ; while (true) do ( var current : int ; current := S.subrange(last + 1+1)->indexOf('@'+"") + last + 1 - 1 ; if (current = -1) then ( if (parts->isEmpty()) then ( ok := false ; break ) else skip ; parts := parts->including(S.subrange(last + 1+1,last + 1)) ; break ) else ( var part : String ; part := S.subrange(last + 1+1,current) ; if (part->size() < 2 & not(parts->isEmpty())) then ( ok := false ; break ) else skip ; parts := parts->including(part) ; last := current ) ) ) else skip ; if (ok) then ( var out : String ; out := StringLib.newString() ; var first : boolean ; first := true ; var i : int ; i := 1 ; while i < parts->size() do ( ( if (first) then ( first := false ) else ( out := out + StringLib.newString(',') ) ; var name : String ; name := if (i = 1) then parts->at(0+1) else parts->at(i - 1+1).subrange(1+1,1) endif ; var domain : String ; domain := if (i = parts->size() - 1) then parts->at(i+1) else parts->at(i+1).subrange(0+1,1) endif ; out := out + StringLib.newString(name) + StringLib.newString('@') + StringLib.newString(domain) ) ; i := i + 1 ) ; OclFile["System.out"].println(out) ) else ( OclFile["System.out"].println("No solution") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int countPairs(int arr[],int n){ HashMaphm=new HashMap<>(); for(int i=0 ; iit : hm.entrySet()){ int count=it.getValue(); ans+=(count*(count-1))/2 ; } return ans ; } public static void main(String[] args){ int arr[]=new int[] { 1,2,3,1 }; System.out.println(countPairs(arr,arr.length)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countPairs( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var hm : Map(int,int) ; hm := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (hm->keys()->includes(arr[i+1])) then hm := hm->union(Map{arr[i+1] |-> hm->at(arr[i+1]) + 1}) ; else hm := hm->union(Map{arr[i+1] |-> 1}) ; ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; for (it : hm->asSet()) do ( ( var count : int ; count := it.getValue() ; ans := ans+((count * (count - 1)) / 2) ) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,1} ; OclFile["System.out"].println(countPairs(arr, arr->size())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class CodeforcesSubsequences { public static void main(String[] args)throws IOException { BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); long k=Long.parseLong(r.readLine()); String s="codeforces" ; long[] charCount=new long[] { 1,1,1,1,1,1,1,1,1,1 }; long prod=1 ; int i=0 ; while(prod0){ b.append(c); } } System.out.println(b); } } ------------------------------------------------------------ OCL File: --------- class CodeforcesSubsequences { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var k : long ; k := (r.readLine())->toLong() ; var s : String ; s := "codeforces" ; var charCount : Sequence(long) ; charCount := Sequence{1,1,1,1,1,1,1,1,1,1} ; var prod : long ; prod := 1 ; var i : int ; i := 0 ; while (prod < k) do ( prod := prod/(charCount[i+1]) ; charCount[i+1] := charCount[i+1] + 1 ; prod := prod*(charCount[i+1]) ; i := (i + 1) mod 10 ) ; var b : String ; b := StringLib.newString() ; var t : int ; t := 0 ; while t < 10 do ( ( var c : String ; c := s->at(t+1) ; while (charCount[t+1] > 0) do ( charCount[t+1] := charCount[t+1] - 1 ; skip ; ( b := b + StringLib.newString(c) ) ; ) ) ; t := t + 1 ) ; OclFile["System.out"].println(b) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long k=sc.nextLong(); long cur=1 ; int curMul=1,nextCnt=0 ; while(curtoLong() ; var cur : long ; cur := 1 ; var curMul : int ; curMul := 1 ; var nextCnt : int ; nextCnt := 0 ; while (cur < k) do ( cur := cur / curMul * (curMul + 1) ; if ((nextCnt + 1) = 10) then ( curMul := curMul + 1 ; nextCnt := 0 ) else skip ) ; var i : int ; i := 0 ; while i < 10 do ( ( var j : int ; j := 0 ; var l : int ; l := if i < nextCnt then curMul + 1 else curMul endif ; while j < l do ( ( OclFile["System.out"].print("codeforces"->at(i+1)) ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int a[]=new int[5]; int r[]=new int[5]; TreeMapmap=new TreeMap(); for(int i=0 ; icollect(0) ; var r : Sequence(int) ; r := Integer.subrange(1,5)->collect(0) ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ; r[i+1] := a[i+1] mod 10 ; var b : int ; b := 10 ; if (r[i+1] /= 0) then ( b := 10 - r[i+1] ; map := map->union(Map{b |-> a[i+1]}) ) else skip ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; if (map.size() = 0) then ( var i : int ; i := 0 ; while i < a->size() do ( ( ans := ans+(a[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; return ) else skip ; var last : int ; last := map->at(map->keys()->max()) ; var idx : int ; idx := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( if (a[i+1] = last) then ( idx := i ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < a->size() do ( ( if (i /= idx) then ( if (a[i+1] mod 10 = 0) then ( ans := ans+(a[i+1]) ) else ( ans := ans+(a[i+1] + (10 - r[i+1])) ) ) else skip ) ; i := i + 1 ) ; ans := ans+(last) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void decToOctal(int n){ int[] octalNum=new int[100]; int i=0 ; while(n!=0){ octalNum[i]=n % 8 ; n=n/8 ; i++; } for(int j=i-1 ; j>=0 ; j--)System.out.print(octalNum[j]); } public static void main(String[] args){ int n=33 ; decToOctal(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation decToOctal( n : int) : void pre: true post: true activity: ( var octalNum : Sequence(int) ; octalNum := Integer.subrange(1,100)->collect(0) ; var i : int ; i := 0 ; while (n /= 0) do ( octalNum[i+1] := n mod 8 ; n := n / 8 ; i := i + 1 ) ; var j : int ; j := i - 1 ; while j >= 0 do ( OclFile["System.out"].print(octalNum[j+1]) ; ; j := j - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 33 ; execute decToOctal(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printPermutation(int n,int k){ if(k>=n ||(n % 2==0 && k==0)){ System.out.print(-1); return ; } int per[]=new int[n+1],i ; for(i=1 ; i<=n ; i++){ per[i]=i ; } int cnt=n-1 ; i=2 ; while(ik){ swap(per,i,i+1); cnt-=2 ; } else if(cnt-1==k){ swap(per,1,i); cnt--; } else { break ; } i+=2 ; } for(i=1 ; i<=n ; i++){ System.out.print(per[i]+" "); } } static int[] swap(int[] arr,int i,int j){ int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp ; return arr ; } public static void main(String[] args){ int n=4,k=3 ; printPermutation(n,k); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printPermutation( n : int, k : int) : void pre: true post: true activity: ( if (k >= n or (n mod 2 = 0 & k = 0)) then ( OclFile["System.out"].print(-1) ; return ) else skip ; var per : Sequence(int) ; per := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( per[i+1] := i ) ; i := i + 1 ) ; var cnt : int ; cnt := n - 1 ; i := 2 ; while (i < n) do ( if (cnt - 1 > k) then ( execute swap(per, i, i + 1) ; cnt := cnt-(2) ) else if (cnt - 1 = k) then ( execute swap(per, 1, i) ; cnt := cnt - 1 ) else ( break ) ; ; i := i+(2) ) ; i := 1 ; while i <= n do ( ( OclFile["System.out"].print(per[i+1] + " ") ) ; i := i + 1 ) ; ); static operation swap( arr : Sequence(int), i : int, j : int) : Sequence(int) pre: true post: true activity: ( var temp : int ; temp := arr[i+1] ; arr[i+1] := arr[j+1] ; arr[j+1] := temp ; return arr ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; var k : int ; k := 3 ; execute printPermutation(n, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void checkSolution(int a,int b,int c){ if(((b*b)-(4*a*c))>0)System.out.println("2 solutions"); else if(((b*b)-(4*a*c))==0)System.out.println("1 solution"); else System.out.println("No solutions"); } public static void main(String[] args){ int a=2,b=5,c=2 ; checkSolution(a,b,c); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkSolution( a : int, b : int, c : int) : void pre: true post: true activity: ( if (((b * b) - (4 * a * c)) > 0) then OclFile["System.out"].println("2 solutions") ; else if (((b * b) - (4 * a * c)) = 0) then OclFile["System.out"].println("1 solution") else OclFile["System.out"].println("No solutions") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 2 ; var b : int ; b := 5 ; var c : int ; c := 2 ; execute checkSolution(a, b, c) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class cf1295 { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0 ; i0){ output.append('1'); n-=2 ; } System.out.println(output); } } } ------------------------------------------------------------ OCL File: --------- class cf1295 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scan.getCurrent()->toInteger() ; var output : String ; output := StringLib.newString() ; if (n mod 2 = 1) then ( output := output + StringLib.newString('7') ; n := n-(3) ) else skip ; while (n > 0) do ( output := output + StringLib.newString('1') ; n := n-(2) ) ; OclFile["System.out"].println(output) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(); int[] a=IntStream.range(0,n).map(i->scanner.nextInt()).toArray(); int[] b=IntStream.range(0,n).map(i->scanner.nextInt()).toArray(); int[] na=new int[n],nb=new int[n]; int answer=0 ; for(int k=0 ; k<30 ; k++){ int mask=(1<<(k+1))-1 ; for(int i=0 ; i=0){ int c=(l+r)/2 ; if(v<=a[c]){ r=c-1 ; } else { l=c+1 ; } } return l ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(0, n-1)->collect( _x1 | (lambda i : OclAny in scanner.getCurrent()->toInteger())->apply(_x1) )->asSequence() ; var b : Sequence(int) ; b := Integer.subrange(0, n-1)->collect( _x1 | (lambda i : OclAny in scanner.getCurrent()->toInteger())->apply(_x1) )->asSequence() ; var na : Sequence(int) ; na := Integer.subrange(1,n)->collect(0) ; var nb : Sequence(int) ; nb := Integer.subrange(1,n)->collect(0) ; var answer : int ; answer := 0 ; var k : int ; k := 0 ; while k < 30 do ( ( var mask : int ; mask := ((1*(2->pow((k + 1))))->oclAsType(long)) - 1 ; var i : int ; i := 0 ; while i < n do ( ( na[i+1] := a[i+1] & mask ; nb[i+1] := b[i+1] & mask ) ; i := i + 1 ) ; nb := nb->sort() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( count := count+(lowerBound(nb, ((2*(2->pow(k)))->oclAsType(long)) - na[i+1]) - lowerBound(nb, ((1*(2->pow(k)))->oclAsType(long)) - na[i+1])) ; count := count+(n - lowerBound(nb, ((3*(2->pow(k)))->oclAsType(long)) - na[i+1])) ; count := MathLib.bitwiseAnd(count, 1) ) ; i := i + 1 ) ; if (1 = (MathLib.bitwiseAnd(count,1))) then ( answer := MathLib.bitwiseOr(answer, (1*(2->pow(k)))->oclAsType(long)) ) else skip ; ) ; k := k + 1 ) ; OclFile["System.out"].println(answer) ; )) ); static operation lowerBound( a : Sequence(int), v : int) : int pre: true post: true activity: ( var l : int ; l := 0 ; var r : int ; r := a->size() - 1 ; while (r - l >= 0) do ( var c : int ; c := (l + r) / 2 ; if (v <= a[c+1]) then ( r := c - 1 ) else ( l := c + 1 ) ) ; return l ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Main main=new Main(); main.run(); } public void run(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0 ; i>=1 ; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ans : long ; ans := 0 ; var k : int ; k := 0 ; while k < 29 do ( ( var am : Sequence(int) ; am := Integer.subrange(1,n)->collect(0) ; var bm : Sequence(int) ; bm := Integer.subrange(1,n)->collect(0) ; var t : int ; t := (1*(2->pow((k + 1))))->oclAsType(long) ; var i : int ; i := 0 ; while i < n do ( ( am[i+1] := a[i+1] mod t ; bm[i+1] := b[i+1] mod t ) ; i := i + 1 ) ; am := am->sort() ; var cnt : int ; cnt := 0 ; t := t/(2->pow(1)) ; var i : int ; i := 0 ; while i < n do ( ( cnt := cnt+(lowerBound(am, 2 * t - bm[i+1]) - lowerBound(am, t - bm[i+1])) ; cnt := cnt+(lowerBound(am, 4 * t - bm[i+1]) - lowerBound(am, 3 * t - bm[i+1])) ) ; i := i + 1 ) ; if (cnt mod 2 /= 0) then ( ans := MathLib.bitwiseOr(ans, ((1*(2->pow(k)))->oclAsType(long))) ) else skip ; ) ; k := k + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); operation lowerBound( a : Sequence(int), v : int) : int pre: true post: true activity: ( var l : int ; l := -1 ; var r : int ; r := a->size() ; while (l + 1 < r) do ( var m : int ; m := (l + r) / 2 ; if (a[m+1] < v) then ( l := m ) else ( r := m ) ) ; return r ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(); int[] a=new int[n],b=new int[n]; int[] na=new int[n],nb=new int[n]; IntStream.range(0,n).forEach(i->a[i]=scanner.nextInt()); IntStream.range(0,n).forEach(i->b[i]=scanner.nextInt()); int answer=0 ; for(int k=0 ; k<30 ; k++){ int mask=(1<<(k+1))-1 ; for(int i=0 ; i=0){ int c=(l+r)/2 ; if(v<=a[c]){ r=c-1 ; } else { l=c+1 ; } } return l ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var na : Sequence(int) ; na := Integer.subrange(1,n)->collect(0) ; var nb : Sequence(int) ; nb := Integer.subrange(1,n)->collect(0) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := scanner.getCurrent()->toInteger()) ; for i : Integer.subrange(0, n-1) do ( b[i+1] := scanner.getCurrent()->toInteger()) ; var answer : int ; answer := 0 ; var k : int ; k := 0 ; while k < 30 do ( ( var mask : int ; mask := ((1*(2->pow((k + 1))))->oclAsType(long)) - 1 ; var i : int ; i := 0 ; while i < n do ( ( na[i+1] := a[i+1] & mask ; nb[i+1] := b[i+1] & mask ) ; i := i + 1 ) ; nb := nb->sort() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( count := count+(lowerBound(nb, ((2*(2->pow(k)))->oclAsType(long)) - na[i+1]) - lowerBound(nb, ((1*(2->pow(k)))->oclAsType(long)) - na[i+1])) ; count := count+(n - lowerBound(nb, ((3*(2->pow(k)))->oclAsType(long)) - na[i+1])) ; count := MathLib.bitwiseAnd(count, 1) ) ; i := i + 1 ) ; if (1 = (MathLib.bitwiseAnd(count,1))) then ( answer := MathLib.bitwiseOr(answer, (1*(2->pow(k)))->oclAsType(long)) ) else skip ; ) ; k := k + 1 ) ; OclFile["System.out"].println(answer) ; )) ); static operation lowerBound( a : Sequence(int), v : int) : int pre: true post: true activity: ( var l : int ; l := 0 ; var r : int ; r := a->size() - 1 ; while (r - l >= 0) do ( var c : int ; c := (l + r) / 2 ; if (v <= a[c+1]) then ( r := c - 1 ) else ( l := c + 1 ) ) ; return l ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int lowerBound(int a[],int v){ int l=0,r=a.length-1 ; while(r-l>=0){ int c=(l+r)/2 ; if(v<=a[c]){ r=c-1 ; } else { l=c+1 ; } } return l ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A[]=new int[N],B[]=new int[N]; for(int n=0 ; n=1){ int k3=lowerBound(b,(3<size() - 1 ; while (r - l >= 0) do ( var c : int ; c := (l + r) / 2 ; if (v <= a[c+1]) then ( r := c - 1 ) else ( l := c + 1 ) ) ; return l ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var B : Sequence(void) ; B := Integer.subrange(1,N)->collect(0) ; var n : int ; n := 0 ; while n < N do ( ( A[n+1] := sc.getCurrent()->toInteger() ) ; n := n + 1 ) ; var n : int ; n := 0 ; while n < N do ( ( B[n+1] := sc.getCurrent()->toInteger() ) ; n := n + 1 ) ; var ans : int ; ans := 0 ; var k : int ; k := 0 ; while k < 30 do ( ( var a : Sequence(int) ; a := A.subrange(1,N) ; var b : Sequence(int) ; b := B.subrange(1,N) ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := MathLib.bitwiseAnd(a[i+1], ((1*(2->pow((k + 1))))->oclAsType(long)) - 1) ; b[i+1] := MathLib.bitwiseAnd(b[i+1], ((1*(2->pow((k + 1))))->oclAsType(long)) - 1) ) ; i := i + 1 ) ; var count : int ; count := 0 ; b := b->sort() ; var i : int ; i := 0 ; while i < N do ( ( var k1 : int ; k1 := lowerBound(b, ((1*(2->pow(k)))->oclAsType(long)) - a[i+1]) ; var k2 : int ; k2 := lowerBound(b, ((1*(2->pow((k + 1))))->oclAsType(long)) - a[i+1]) ; count := count+(k2 - k1) ; if (k >= 1) then ( var k3 : int ; k3 := lowerBound(b, ((3*(2->pow(k)))->oclAsType(long)) - a[i+1]) ; count := count+(N - k3) ) else skip ; count := count mod 2 ; ) ; i := i + 1 ) ; if (count mod 2 = 1) then ( ans := MathLib.bitwiseOr(ans, (1*(2->pow(k)))->oclAsType(long)) ) else skip ; ) ; k := k + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int[] a=new int[N]; int[] b=new int[N]; for(int i=0 ; i1){ int mid=(left+right)/2 ; if(b[mid]toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( a[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( b[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; var res : int ; res := 0 ; var k : int ; k := 0 ; while k < 30 do ( ( var m : int ; m := (1*(2->pow((k + 1))))->oclAsType(long) ; var br : Sequence(int) ; br := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( br[i+1] := b[i+1] mod m ; ; i := i + 1 ) ; br := br->sort() ; var br2 : Sequence(int) ; br2 := Integer.subrange(1,N * 2)->collect(0) ; for _x : Integer.subrange(1,N) do br2[0 + _x] := br[0 + _x] ; var i : int ; i := 0 ; while i < N do ( br2[i + N+1] := br[i+1] + m ; ; i := i + 1 ) ; var t : int ; t := (1*(2->pow(k)))->oclAsType(long) ; var count : long ; count := 0 ; var i : int ; i := 0 ; while i < N do ( ( var ar : int ; ar := a[i+1] mod m ; var left : int ; left := find(br2, t * 3 - ar) ; var right : int ; right := find(br2, t * 4 - ar) ; count := count+(right - left) ) ; i := i + 1 ) ; if (count mod 2 = 1) then res := res+((1*(2->pow(k)))->oclAsType(long)) ; else skip ; ) ; k := k + 1 ) ; OclFile["System.out"].println(res) ; ); static operation find( b : Sequence(int), t : int) : int pre: true post: true activity: ( var left : int ; left := -1 ; var right : int ; right := b->size() ; while (right - left > 1) do ( var mid : int ; mid := (left + right) / 2 ; if (b[mid+1] < t) then ( left := mid ) else ( right := mid ) ) ; return left ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int amtTime=0 ; int maxLoss=10 ; int maxLossNum=0 ; boolean a=true ; ListArray=new ArrayList<>(); while(sc.hasNextInt()){ Array.add((Integer)sc.nextInt()); } for(int i=0 ; iArray.get(i)% 10){ maxLoss=Array.get(i)% 10 ; maxLossNum=Array.get(i); }; } for(int j=0 ; j0){ adj=10-rt ; } amtTime+=t+adj ; } } System.out.println(amtTime+maxLossNum); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var amtTime : int ; amtTime := 0 ; var maxLoss : int ; maxLoss := 10 ; var maxLossNum : int ; maxLossNum := 0 ; var a : boolean ; a := true ; var Array : Sequence(int) ; Array := Sequence{} ; while (sc.hasNextInt()) do ( Array := Array->including(sc.getCurrent()->toInteger()->oclAsType(int)) ) ; var i : int ; i := 0 ; while i < (methodCall size ( )) do ( ( if (i[i+1] mod 10 /= 0 & maxLoss > i[i+1] mod 10) then ( maxLoss := i[i+1] mod 10 ; maxLossNum := i[i+1] ) else skip ; ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < (methodCall size ( )) do ( ( if (j[j+1] = maxLossNum & a) then ( a := false ; continue ) else ( var t : int ; t := j[j+1] ; var rt : int ; rt := t mod 10 ; var adj : int ; adj := 0 ; if (rt > 0) then ( adj := 10 - rt ) else skip ; amtTime := amtTime+(t + adj) ; ) ) ; j := j + 1 ) ; OclFile["System.out"].println(amtTime + maxLossNum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static void vowelOrConsonant(char x){ if(x=='a' || x=='e' || x=='i' || x=='o' || x=='u')System.out.println("Vowel"); else System.out.println("Consonant"); } static public void main(String[] args){ vowelOrConsonant('c'); vowelOrConsonant('e'); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation vowelOrConsonant( x : String) : void pre: true post: true activity: ( if (x = 'a' or x = 'e' or x = 'i' or x = 'o' or x = 'u') then OclFile["System.out"].println("Vowel") ; else OclFile["System.out"].println("Consonant") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute vowelOrConsonant('c') ; execute vowelOrConsonant('e') ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void printGroups(int n){ int x=1 ; int y=n*n ; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=n/2 ; j++){ System.out.print("{ "+x+","+y+"} "); x++; y--; } System.out.println(); } } public static void main(String[] args){ int n=4 ; printGroups(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printGroups( n : int) : void pre: true post: true activity: ( var x : int ; x := 1 ; var y : int ; y := n * n ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= n / 2 do ( ( OclFile["System.out"].print("{ " + x + "," + y + "} ") ; x := x + 1 ; y := y - 1 ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; execute printGroups(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findRealAndImag(String s){ int l=s.length(); int i ; if(s.indexOf('+')!=-1){ i=s.indexOf('+'); } else { i=s.indexOf('-'); } String real=s.substring(0,i); String imaginary=s.substring(i+1,l-1); System.out.println("Real part: "+real); System.out.println("Imaginary part: "+imaginary); } public static void main(String[] args){ String s="3+4i" ; findRealAndImag(s); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findRealAndImag( s : String) : void pre: true post: true activity: ( var l : int ; l := s->size() ; var i : int ; if (s->indexOf('+')-1 /= -1) then ( i := s->indexOf('+')-1 ) else ( i := s->indexOf('-')-1 ) ; var real : String ; real := s.subrange(0+1,i) ; var imaginary : String ; imaginary := s.subrange(i + 1+1,l - 1) ; OclFile["System.out"].println("Real part: " + real) ; OclFile["System.out"].println("Imaginary part: " + imaginary) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "3+4i" ; execute findRealAndImag(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int arr[]=new int[n]; int max=-1 ; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var max : int ; max := -1 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ; max := Set{max, arr[i+1]}->max() ) ; i := i + 1 ) ; var count : int ; count := 0 ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = max) then ( count := count + 1 ) else ( ans := Set{ans, count}->max() ; count := 0 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{ans, count}->max()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Main { PrintWriter out=new PrintWriter(System.out); BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok=new StringTokenizer(""); String next()throws IOException { if(! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } int ni()throws IOException { return Integer.parseInt(next()); } long nl()throws IOException { return Long.parseLong(next()); } long mod=1000000007 ; void solve()throws IOException { int n=ni(); int prev=ni(); int max=prev ; int ct=1 ; int maxct=1 ; for(int i=1 ; i0){ if((p & 1)==1)r=(r*a)% mod ; p>>=1 ; a=(a*a)% mod ; } return r ; } public static void main(String[] args)throws IOException { new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); attribute in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute tok : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( if (not(tok.hasNext())) then ( tok := OclIterator.newOclIterator_String(in.readLine()) ) else skip ; return tok.next() ); operation ni() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nl() : long pre: true post: true activity: ( return (next())->toLong() ); attribute mod : long := 1000000007; operation solve() : void pre: true post: true activity: ( var n : int ; n := ni() ; var prev : int ; prev := ni() ; var max : int ; max := prev ; var ct : int ; ct := 1 ; var maxct : int ; maxct := 1 ; var i : int ; i := 1 ; while i < n do ( ( var u : int ; u := ni() ; if (u < max) then ( ct := 0 ; continue ) else skip ; if (u = max) then ( ct := ct + 1 ; maxct := Set{maxct, ct}->max() ; continue ) else skip ; max := u ; ct := 1 ; maxct := 1 ; ) ; i := i + 1 ) ; skip ; skip ; ); operation gcd( a : int, b : int) : int pre: true post: true activity: ( return (if b = 0 then a else gcd(b, a mod b) endif) ); operation gcd( a : long, b : long) : long pre: true post: true activity: ( return (if b = 0 then a else gcd(b, a mod b) endif) ); operation mp( a : long, p : long) : long pre: true post: true activity: ( var r : long ; r := 1 ; while (p > 0) do ( if ((p & 1) = 1) then r := (r * a) mod mod ; else skip ; p := p/(2->pow(1)) ; a := (a * a) mod mod ) ; return r ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.TreeSet ; class GFG { static void printPrevGreater(int[] arr,int n){ TreeSetts=new TreeSet<>(); for(int i=0 ; iincluding(arr[i+1]) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,5,11,10,20,12} ; var n : int ; n := arr->size() ; execute printPrevGreater(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; public class esep { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ int x=sc.nextInt(); if(x % 2!=0){ System.out.print(7); x-=3 ; } for(int i=0 ; itoInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x mod 2 /= 0) then ( OclFile["System.out"].print(7) ; x := x-(3) ) else skip ; var i : int ; i := 0 ; while i < x / 2 do ( ( OclFile["System.out"].print(1) ) ; i := i + 1 ) ; OclFile["System.out"].println() ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static long mod=(long)(1e9+7); public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); int a[]=new int[n]; ArrayListlist=new ArrayList<>(); for(int i=0 ; ioclAsType(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var list : Sequence(int) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ; list := list->including(a[i+1]) ) ; i := i + 1 ) ; list := list->sort() ; var max : int ; max := list->at(n - 1+1) ; var c : int ; c := 1 ; var max_sub : int ; max_sub := 0 ; if (n = 1) then ( max_sub := 1 ) else ( var i : int ; i := 0 ; while i < n - 1 do ( ( if (a[i+1] = max & a[i + 1+1] = max) then ( c := c + 1 ) else ( c := 1 ) ; max_sub := Set{max_sub, c}->max() ) ; i := i + 1 ) ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { boolean main()throws IOException { Scanner sc=new Scanner(systemin); int N=sc.nextInt(); int M=sc.nextInt(); sc.nextLine(); String[] s=new String[N]; int cnt=0 ; for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; skip ; var s : Sequence(String) ; s := Integer.subrange(1,N)->collect(null) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < N do ( ( s[i+1] := sc.nextLine() ; log.printf("%s\n", s[i+1]) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var t : String ; t := sc.nextLine() ; log.printf("%s\n", t) ; var j : int ; j := 0 ; while j < M do ( ( if (s[i+1]->at(j+1) /= t->at(j+1)) then ( cnt := cnt + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].printf("%d\n", cnt) ; skip ; return false ); attribute log : OclFile; attribute result : OclFile := OclFile["System.out"]; attribute systemin : OclFile; static attribute instance : Main := Main.newMain(); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( systemin := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; log := OclFile.newOclFile_Write(OclFile()) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( instance.main() ; instance.systemin.close() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); char[][] field=new char[n][]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var field : Sequence(Sequence(String)) ; field := Integer.subrange(1,n)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < n do ( ( field[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var arr : Sequence(String) ; arr := sc.getCurrent()->characters() ; var j : int ; j := 0 ; while j < m do ( ( if (arr[j+1] /= field[i+1][j+1]) then ( count := count + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static void solve(){ Scanner sc=new Scanner(System.in); int array[]=new int[5]; int plus=0 ; int max=0 ; for(int i=0 ; icollect(0) ; var plus : int ; plus := 0 ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < array->size() do ( ( array[i+1] := sc.getCurrent()->toInteger() ; if (array[i+1] mod 10 /= 0) then ( plus := 10 - array[i+1] mod 10 ; array[i+1] := array[i+1]+(plus) ; max := Set{max, plus}->max() ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(array[0+1] + array[1+1] + array[2+1] + array[3+1] + array[4+1] - max) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForces1536A { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int s=input.nextInt(); int d=input.nextInt(); int c=s ; int ans=s ; int m=0 ; for(int i=1 ; ic){ ans+=s-c ; c=s ; } else { m=(c-s+d-1)/d+1 ; ans+=(m-1)*d+s-c ; if((m-1)*d+s-c==0){ ans+=d ; c=m*d+s ; } else { c=(m-1)*d+s ; } } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class CodeForces1536A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var s : int ; s := input.getCurrent()->toInteger() ; var d : int ; d := input.getCurrent()->toInteger() ; var c : int ; c := s ; var ans : int ; ans := s ; var m : int ; m := 0 ; var i : int ; i := 1 ; while i < n do ( ( s := input.getCurrent()->toInteger() ; d := input.getCurrent()->toInteger() ; if (s > c) then ( ans := ans+(s - c) ; c := s ) else ( m := (c - s + d - 1) / d + 1 ; ans := ans+((m - 1) * d + s - c) ; if ((m - 1) * d + s - c = 0) then ( ans := ans+(d) ; c := m * d + s ) else ( c := (m - 1) * d + s ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class div_2_443_a { public static void main(String args[]){ FScanner in=new FScanner(); PrintWriter out=new PrintWriter(System.out); int n=in.nextInt(); int s[]=new int[n]; int d[]=new int[n]; for(int i=0 ; icollect(0) ; var d : Sequence(int) ; d := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := in.nextInt() ; d[i+1] := in.nextInt() ) ; i := i + 1 ) ; var ans : int ; ans := s[0+1] ; var i : int ; i := 1 ; while i < n do ( ( while (s[i+1] <= s[i - 1+1]) do ( s[i+1] := s[i+1]+(d[i+1]) ) ) ; i := i + 1 ) ; skip ; skip ; ); static class FScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute sb : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(sb.hasNext())) do ( try ( sb := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do skip ) ; return sb.next() ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : IOException) do skip return "" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } _443_a { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FScanner ; in := FScanner.newFScanner() ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.nextInt() ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; var d : Sequence(int) ; d := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := in.nextInt() ; d[i+1] := in.nextInt() ) ; i := i + 1 ) ; var ans : int ; ans := s[0+1] ; var i : int ; i := 1 ; while i < n do ( ( while (s[i+1] <= s[i - 1+1]) do ( s[i+1] := s[i+1]+(d[i+1]) ) ) ; i := i + 1 ) ; skip ; skip ; ); static class FScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute sb : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(sb.hasNext())) do ( try ( sb := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do skip ) ; return sb.next() ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : IOException) do skip return "" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Diagnoz { public static void main(String[] args){ Scanner in=new Scanner(System.in); int nDoctors=in.nextInt(); int nDay=0 ; for(int i=0 ; itoInteger() ; var nDay : int ; nDay := 0 ; var i : int ; i := 0 ; while i < nDoctors do ( ( var startWork : int ; startWork := in.getCurrent()->toInteger() ; var days : int ; days := in.getCurrent()->toInteger() ; while (startWork <= nDay) do startWork := startWork+(days) ; ; nDay := startWork ) ; i := i + 1 ) ; OclFile["System.out"].println(nDay) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication168{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=0 ; int b=0 ; int ck=0 ; for(int i=0 ; i { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := 0 ; var b : int ; b := 0 ; var ck : int ; ck := 0 ; var i : int ; i := 0 ; while i < n do ( ( a := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; while (a <= ck) do ( a := a+(b) ) ; ck := a ) ; i := i + 1 ) ; OclFile["System.out"].println(a) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findX(int A,int B){ int j=0,x=0 ; while(A!=0 || B!=0){ if((A % 2==1)&&(B % 2==1)){ x+=(1<>=1 ; B>>=1 ; j+=1 ; } return x ; } public static void main(String[] args){ int A=2,B=3 ; int X=findX(A,B); System.out.println("X="+X+",Sum="+((A ^ X)+(B ^ X))); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findX( A : int, B : int) : int pre: true post: true activity: ( var j : int ; j := 0 ; var x : int ; x := 0 ; while (A /= 0 or B /= 0) do ( if ((A mod 2 = 1) & (B mod 2 = 1)) then ( x := x+(((1*(2->pow(j)))->oclAsType(long))) ) else skip ; A := A/(2->pow(1)) ; B := B/(2->pow(1)) ; j := j+(1) ) ; return x ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 2 ; var B : int ; B := 3 ; var X : int ; X := findX(A, B) ; OclFile["System.out"].println("X=" + X + ",Sum=" + ((MathLib.bitwiseXor(A,X)) + (MathLib.bitwiseXor(B,X)))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static VectorsplitStrings(String str,char dl){ String word="" ; int num=0 ; str=str+dl ; int l=str.length(); Vectorsubstr_list=new Vector(); for(int i=0 ; ires=splitStrings(str,dl); for(String x : res){ System.out.println(x); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation splitStrings( str : String, dl : String) : Sequence(String) pre: true post: true activity: ( var word : String ; word := "" ; var num : int ; num := 0 ; str := str + dl ; var l : int ; l := str->size() ; var substr_list : Sequence(String) ; substr_list := Sequence{} ; var i : int ; i := 0 ; while i < l do ( ( if (str->at(i+1) /= dl) then ( word := word + str->at(i+1) ) else ( if (word->size()->oclAsType(int) /= 0) then ( substr_list := substr_list->including(word) ) else skip ; word := "" ) ) ; i := i + 1 ) ; return substr_list ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeks;for;geeks" ; var dl : String ; dl := ';' ; var res : Sequence(String) ; res := splitStrings(str, dl) ; for (x : res) do ( ( OclFile["System.out"].println(x) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Test { public static int floorSqrt(int x){ if(x==0 || x==1)return x ; int start=1,end=x,ans=0 ; while(start<=end){ int mid=(start+end)/2 ; if(mid*mid==x)return mid ; if(mid*mid ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long getSum(long n,int d){ if(ndat[j]){ ++num ; int t=dat[j-1]; dat[j-1]=dat[j]; dat[j]=t ; } } } return num ; } public static void main(String[] args){ Scanner s=new Scanner(System.in); while(s.hasNext()){ int n=s.nextInt(); if(n==0)break ; int[] dat=new int[n]; for(int i=0 ; isize() do ( ( var j : int ; j := 1 ; while j < dat->size() - i do ( ( if (dat[j - 1+1] > dat[j+1]) then ( num := num + 1 ; var t : int ; t := dat[j - 1+1] ; dat[j - 1+1] := dat[j+1] ; dat[j+1] := t ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (s.hasNext()) do ( var n : int ; n := s.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var dat : Sequence(int) ; dat := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( dat[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(bubble_sort(dat)) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,i,j,count,tmp ; int[] a ; for(; ; ){ n=sc.nextInt(); if(n==0)break ; a=new int[n]; for(i=0 ; ia[j+1]){ tmp=a[j]; a[j]=a[j+1]; a[j+1]=tmp ; count++; } out.println(count); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var n : int ; var i : int ; var j : int ; var count : int ; var tmp : int ; var a : Sequence(int) ; while true do ( ( n := sc.nextInt() ; if (n = 0) then break else skip ; a := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < n do ( a[i+1] := sc.nextInt() ; ; i := i + 1 ) ; count := 0 ; i := 0 ; while i < n - 1 do ( j := 0 ; while j < n - 1 - i do ( if (a[j+1] > a[j + 1+1]) then ( tmp := a[j+1] ; a[j+1] := a[j + 1+1] ; a[j + 1+1] := tmp ; count := count + 1 ) else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; out.println(count) ; ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPerfectSquare(double x){ double sr=Math.sqrt(x); return((sr-Math.floor(sr))==0); } static boolean isProduct(int num){ int cnt=0 ; for(int i=2 ; cnt<2 && i*i<=num ; ++i){ while(num % i==0){ num/=i ; ++cnt ; } } if(num>1)++cnt ; return cnt==2 ; } static void findNumbers(int N){ Vectorvec=new Vector(); for(int i=1 ; i<=N ; i++){ if(isProduct(i)&& ! isPerfectSquare(i)){ vec.add(i); } } Iteratoritr=vec.iterator(); while(itr.hasNext()){ System.out.print(itr.next()+" "); } } public static void main(String[] args){ int N=30 ; findNumbers(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPerfectSquare( x : double) : boolean pre: true post: true activity: ( var sr : double ; sr := (x)->sqrt() ; return ((sr - (sr)->floor()) = 0) ); static operation isProduct( num : int) : boolean pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := 2 ; while cnt < 2 & i * i <= num do ( ( while (num mod i = 0) do ( num := num/(i) ; cnt := cnt + 1 ) ) ; i := i + 1 ) ; if (num > 1) then cnt := cnt + 1 ; else skip ; return cnt = 2 ); static operation findNumbers( N : int) : void pre: true post: true activity: ( var vec : Sequence(int) ; vec := Sequence{} ; var i : int ; i := 1 ; while i <= N do ( ( if (isProduct(i) & not(isPerfectSquare(i))) then ( vec := vec->including(i) ) else skip ) ; i := i + 1 ) ; var itr : OclIterator ; itr := vec->iterator() ; while (itr.hasNext()) do ( OclFile["System.out"].print(itr.next() + " ") ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 30 ; execute findNumbers(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.util.Arrays.deepToString ; import static java.util.Arrays.fill ; import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } void tr(Object...os){ System.err.println(deepToString(os)); } Scanner sc=new Scanner(System.in); public void run(){ for(; sc.hasNext(); ){ int n=sc.nextInt(); if(n==0)break ; int[] a=new int[n]; for(int i=0 ; ia[j])res++; } } System.out.println(res); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation tr( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while sc.hasNext() do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (a[i+1] > a[j+1]) then res := res + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; while((line=br.readLine())!=null && ! line.isEmpty()){ int n=Integer.parseInt(line); if(n==0){ break ; } int[] array=new int[n]; for(int i=0 ; i0 ; i--){ for(int j=0 ; jarray[j+1]){ int swap=array[j]; array[j]=array[j+1]; array[j+1]=swap ; count++; } } } System.out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := "" ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var n : int ; n := (line)->toInteger() ; if (n = 0) then ( break ) else skip ; var array : Sequence(int) ; array := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( array[i+1] := (br.readLine())->toInteger() ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := (n)->char2byte() - 1 ; while i > 0 do ( ( var j : int ; j := 0 ; while j < i do ( ( if (array[j+1] > array[j + 1+1]) then ( var swap : int ; swap := array[j+1] ; array[j+1] := array[j + 1+1] ; array[j + 1+1] := swap ; count := count + 1 ) else skip ) ; j := j + 1 ) ) ; i := i - 1 ) ; OclFile["System.out"].println(count) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int mergecount(ArrayLista){ int count=0 ; int n=a.size(); if(n>1){ ArrayListb=new ArrayList(); for(int i=0 ; ic=new ArrayList(); for(int i=n/2 ; ial=new ArrayList(); for(int i=0 ; isize() ; if (n > 1) then ( var b : Sequence(int) ; b := Sequence{} ; var i : int ; i := 0 ; while i < n / 2 do ( b := b->including(a->at(i+1)) ; ; i := i + 1 ) ; var c : Sequence(int) ; c := Sequence{} ; var i : int ; i := n / 2 ; while i < n do ( c := c->including(a->at(i+1)) ; ; i := i + 1 ) ; count := count+(mergecount(b)) ; count := count+(mergecount(c)) ; var i : int ; i := 0 ; var j : int ; j := 0 ; var k : int ; k := 0 ; while i < n do ( ( if (k = c->size()) then a := a.setAt(i+1, b->at(j+1)) ; else if (j = b->size()) then a := a.setAt(i+1, c->at(k+1)) else if (b->at(j+1) <= c->at(k+1)) then a := a.setAt(i+1, b->at(j+1)) else ( a := a.setAt(i+1, c->at(k+1)) ; count := count+(n / 2 - j) ) ; ; ) ; i := i + 1 ) ; ) else skip ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var al : Sequence(int) ; al := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( al := al->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; OclFile["System.out"].println(mergecount(al)) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String input[]=br.readLine().split("\\s+"); BigInteger A=new BigInteger(input[0]); BigInteger B=new BigInteger(input[1]); BigInteger ans[]=A.divideAndRemainder(B); System.out.println(ans[1]); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute BIG_NUM : int := 2000000000; static attribute MOD : int := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var input : Sequence(String) ; input := br.readLine()->split("\\s+") ; var A : long ; A := long(input[0+1]) ; var B : long ; B := long(input[1+1]) ; var ans : Sequence(long) ; ans := A.divideAndRemainder(B) ; OclFile["System.out"].println(ans[1+1]) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; import java.util.*; public class Main { public static void main(String[] args){ BigInteger a,b ; Scanner cin=new Scanner(System.in); a=cin.nextBigInteger(); b=cin.nextBigInteger(); System.out.println(a.remainder(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : long ; var b : long ; var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; a := cin.nextBigInteger() ; b := cin.nextBigInteger() ; OclFile["System.out"].println(a.remainder(b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(new BufferedInputStream(System.in)); while(in.hasNext()){ BigInteger a=in.nextBigInteger(),b=in.nextBigInteger(); System.out.println(a.remainder(b)); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (in.hasNext()) do ( var a : long ; a := in.nextBigInteger() ; var b : long ; b := in.nextBigInteger() ; OclFile["System.out"].println(a.remainder(b)) ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); BigInteger a=new BigInteger(str); str=sc.next(); BigInteger b=new BigInteger(str); System.out.println(a.remainder(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; var a : long ; a := long(str) ; str := sc.getCurrent() ; var b : long ; b := long(str) ; OclFile["System.out"].println(a.remainder(b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ String s ; Scanner reader=new Scanner(System.in); s=reader.nextLine(); String[] str ; str=s.split(" "); BigInteger a=new BigInteger(str[0]); BigInteger b=new BigInteger(str[1]); BigInteger c=a.mod(b); System.out.println(c); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile["System.in"]) ; s := reader.nextLine() ; var str : Sequence(String) ; str := s->split(" ") ; var a : long ; a := long(str[0+1]) ; var b : long ; b := long(str[1+1]) ; var c : long ; c := a.mod(b) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String input[]=br.readLine().split("\\s+"); String str_A=input[0],str_B=input[1]; BigInteger A=new BigInteger(input[0]); BigInteger B=new BigInteger(input[1]); BigInteger ans ; ans=A.add(B); System.out.println(ans); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute BIG_NUM : int := 2000000000; static attribute MOD : int := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var input : Sequence(String) ; input := br.readLine()->split("\\s+") ; var str_A : String ; str_A := input[0+1] ; var str_B : String ; str_B := input[1+1] ; var A : long ; A := long(input[0+1]) ; var B : long ; B := long(input[1+1]) ; var ans : long ; ans := A->excludes(B) ; OclFile["System.out"].println(ans) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int OddDivCount(int a,int b){ int res=0 ; for(int i=a ; i<=b ; ++i){ int divCount=0 ; for(int j=1 ; j<=i ; ++j){ if(i % j==0){ ++divCount ; } } if((divCount % 2)!=0){ ++res ; } } return res ; } public static void main(String[] args){ int a=1,b=10 ; System.out.println(OddDivCount(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation OddDivCount( a : int, b : int) : int pre: true post: true activity: ( var res : int ; res := 0 ; var i : int ; i := a ; while i <= b do ( ( var divCount : int ; divCount := 0 ; var j : int ; j := 1 ; while j <= i do ( ( if (i mod j = 0) then ( divCount := divCount + 1 ) else skip ) ; j := j + 1 ) ; if ((divCount mod 2) /= 0) then ( res := res + 1 ) else skip ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 1 ; var b : int ; b := 10 ; OclFile["System.out"].println(OddDivCount(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Test { public static void main(String[] args){ String s="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" ; String[] array=s.split(" "); Scanner input=new Scanner(System.in); int x=input.nextInt(); int y=input.nextInt(); System.out.print(array[x] .charAt(y)); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "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" ; var array : Sequence(String) ; array := s->split(" ") ; var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := input.getCurrent()->toInteger() ; var y : int ; y := input.getCurrent()->toInteger() ; OclFile["System.out"].print(array[x+1]->at(y+1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; import java.util.*; public class Main { public static void main(String[] args){ BigInteger a,b ; Scanner cin=new Scanner(System.in); a=cin.nextBigInteger(); b=cin.nextBigInteger(); System.out.println(a.add(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : long ; var b : long ; var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; a := cin.nextBigInteger() ; b := cin.nextBigInteger() ; OclFile["System.out"].println(a->excludes(b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(new BufferedInputStream(System.in)); while(in.hasNext()){ BigInteger a=in.nextBigInteger(),b=in.nextBigInteger(); System.out.println(a.add(b)); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (in.hasNext()) do ( var a : long ; a := in.nextBigInteger() ; var b : long ; b := in.nextBigInteger() ; OclFile["System.out"].println(a->excludes(b)) ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); BigInteger a=new BigInteger(str); str=sc.next(); BigInteger b=new BigInteger(str); System.out.println(a.add(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; var a : long ; a := long(str) ; str := sc.getCurrent() ; var b : long ; b := long(str) ; OclFile["System.out"].println(a->excludes(b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ String s ; Scanner reader=new Scanner(System.in); s=reader.nextLine(); String[] str ; str=s.split(" "); BigInteger a=new BigInteger(str[0]); BigInteger b=new BigInteger(str[1]); BigInteger c=a.add(b); System.out.println(c); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile["System.in"]) ; s := reader.nextLine() ; var str : Sequence(String) ; str := s->split(" ") ; var a : long ; a := long(str[0+1]) ; var b : long ; b := long(str[1+1]) ; var c : long ; c := a->excludes(b) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int N=(int)1E6 ; static boolean[] fourDiv=new boolean[N+1]; static void fourDistinctFactors(){ boolean[] primeAll=new boolean[N+1]; for(int p=2 ; p*p<=N ; p++){ if(primeAll[p]==false){ for(int i=p*2 ; i<=N ; i+=p)primeAll[i]=true ; } } ArrayListprime=new ArrayList(); for(int p=2 ; p<=N ; p++)if(! primeAll[p])prime.add(p); for(int i=0 ; iN)break ; fourDiv[p*q]=true ; } } } public static void main(String[] args){ fourDistinctFactors(); int num=10 ; if(fourDiv[num])System.out.println("Yes"); else System.out.println("No"); num=12 ; if(fourDiv[num])System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute N : int := 1E6->oclAsType(int); static attribute fourDiv : Sequence(boolean) := Integer.subrange(1,N + 1)->collect(false); static operation fourDistinctFactors() : void pre: true post: true activity: ( var primeAll : Sequence(boolean) ; primeAll := Integer.subrange(1,N + 1)->collect(false) ; var p : int ; p := 2 ; while p * p <= N do ( ( if (primeAll[p+1] = false) then ( var i : int ; i := p * 2 ; while i <= N do ( primeAll[i+1] := true ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ; var prime : Sequence(int) ; prime := Sequence{} ; var p : int ; p := 2 ; while p <= N do ( if (not(primeAll[p+1])) then prime := prime->including(p) ; else skip ; ; p := p + 1 ) ; var i : int ; i := 0 ; while i < prime->size() do ( ( var p : int ; p := prime->at(i+1) ; if (1L * p * p * p <= N) then fourDiv[p * p * p+1] := true ; else skip ; var j : int ; j := i + 1 ; while j < prime->size() do ( ( var q : int ; q := prime->at(j+1) ; if (1L * p * q > N) then break else skip ; fourDiv[p * q+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute fourDistinctFactors() ; var num : int ; num := 10 ; if (fourDiv[num+1]) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; num := 12 ; if (fourDiv[num+1]) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Scanner ; public class FullBinaryTree { public final static String INPUT_FILE_NAME="B-large(1).in" ; public final static String OUTPUT_FILE_NAME="FullBinaryTree.out" ; public static void main(String[] args){ try(Scanner in=new Scanner(new FileReader(INPUT_FILE_NAME)); PrintWriter out=new PrintWriter(new FileWriter(OUTPUT_FILE_NAME))){ int numT=in.nextInt(); for(int t=1 ; t<=numT ; t++){ System.out.println("Case "+t); int numNode=in.nextInt(); ArrayListnodes=new ArrayList<>(); for(int i=0 ; ichildren ; public Node(){ children=new ArrayList<>(); } public void addChild(Node n){ children.add(n); } public int maxChildren(Node parent){ int best=0 ; int best2=0 ; for(Node n : children){ if(n!=parent){ int nv=n.maxChildren(this); if(nv>best){ best2=best ; best=nv ; } else if(nv>best2){ best2=nv ; } } } if(best2==0)return 1 ; return best+best2+1 ; } } } ------------------------------------------------------------ OCL File: --------- class FullBinaryTree { static attribute INPUT_FILE_NAME : String := "B-large(1).in"; static attribute OUTPUT_FILE_NAME : String := "FullBinaryTree.out"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile(INPUT_FILE_NAME))) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile(OUTPUT_FILE_NAME))) ; ( var numT : int ; numT := in.getCurrent()->toInteger() ; var t : int ; t := 1 ; while t <= numT do ( ( OclFile["System.out"].println("Case " + t) ; var numNode : int ; numNode := in.getCurrent()->toInteger() ; var nodes : Sequence(Node) ; nodes := Sequence{} ; var i : int ; i := 0 ; while i < numNode do ( ( nodes := nodes->including(Node.newNode()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < numNode - 1 do ( ( var a : int ; a := in.getCurrent()->toInteger() - 1 ; var b : int ; b := in.getCurrent()->toInteger() - 1 ; nodes->at(a+1).addChild(nodes->at(b+1)) ; nodes->at(b+1).addChild(nodes->at(a+1)) ) ; i := i + 1 ) ; var best : int ; best := 0 ; for (n : nodes) do ( ( best := Set{best, n.maxChildren(null)}->max() ) ) ; var res : int ; res := numNode - best ; skip ; ) ; t := t + 1 ) )) catch (e : IOException) do ( e.printStackTrace() ) ); static class Node { attribute children : Sequence(Node); static operation newNode() : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( children := Sequence{} ); operation addChild( n : Node) : void pre: true post: true activity: ( children := children->including(n) ); operation maxChildren( parent : Node) : int pre: true post: true activity: ( var best : int ; best := 0 ; var best2 : int ; best2 := 0 ; for (n : children) do ( ( if (n /= parent) then ( var nv : int ; nv := n.maxChildren(self) ; if (nv > best) then ( best2 := best ; best := nv ) else if (nv > best2) then ( best2 := nv ) else skip ; ) else skip ) ) ; if (best2 = 0) then return 1 else skip ; return best + best2 + 1 ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashSet ; import java.util.Scanner ; public class FullBinaryTree { public static int ans ; public static int tans ; public static boolean[] vis ; public static ArrayList[] adj ; public static void main(String[] Args)throws FileNotFoundException { Scanner sc=new Scanner(new File("B-large(2).in")); PrintWriter out=new PrintWriter(new File("things.out")); int t=sc.nextInt(),cc=0 ; while(t-->0){ int n=sc.nextInt(); adj=new ArrayList[n]; for(int k=0 ; k(); for(int k=0 ; kal=new ArrayList(); for(Integer i : adj[k])if(! vis[i])al.add(dfs(i)); if(al.size()<2)return 1 ; Collections.sort(al); return 1+al.get(al.size()-1)+al.get(al.size()-2); } private static long make(String s){ return Long.parseLong(s,2); } } ------------------------------------------------------------ OCL File: --------- class FullBinaryTree { static attribute ans : int; static attribute tans : int; static attribute vis : Sequence(boolean); static attribute adj : Sequence(Sequence(int)); static operation main( Args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile("B-large(2).in")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile("things.out")) ; var t : int ; t := sc.getCurrent()->toInteger() ; var cc : int ; cc := 0 ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; adj := Integer.subrange(1,n)->collect(null) ; var k : int ; k := 0 ; while k < n do ( adj[k+1] := Sequence{} ; ; k := k + 1 ) ; var k : int ; k := 0 ; while k < n - 1 do ( ( var a : int ; a := sc.getCurrent()->toInteger() - 1 ; var b : int ; b := sc.getCurrent()->toInteger() - 1 ; adj[a+1]->excludes(b) ; adj[b+1]->excludes(a) ) ; k := k + 1 ) ; vis := Integer.subrange(1,n)->collect(false) ; ans := n ; var k : int ; k := 0 ; while k < n do ( ( vis := vis->collect(false) ; ans := Set{n - dfs(k), ans}->min() ) ; k := k + 1 ) ; skip ; ) ; ) ; skip ; ); static operation dfs( k : int) : int pre: true post: true activity: ( vis[k+1] := true ; var al : Sequence(int) ; al := Sequence{} ; for (i : adj[k+1]) do ( if (not(vis[i+1])) then al := al->including(dfs(i)) ; else skip ; ) ; if (al->size() < 2) then return 1 else skip ; al := al->sort() ; return 1 + al->at(al->size() - 1+1) + al->at(al->size() - 2+1) ); static operation make( s : String) : long pre: true post: true activity: ( return (s)->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printArr(float arr[],int n){ for(int i=0 ; imax)max=arr[i]; } float min=arr[0]; for(int i=0 ; i max) then max := arr[i+1] ; else skip ) ; i := i + 1 ) ; var min : double ; min := arr[0+1] ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] < min) then min := arr[i+1] ; else skip ) ; i := i + 1 ) ; var range : double ; range := max - min ; var coeffOfRange : double ; coeffOfRange := range / (max + min) ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = max) then ( arr[i+1] := coeffOfRange ; break ) else skip ) ; i := i + 1 ) ; execute printArr(arr, n) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(double) ; arr := Sequence{15,16,10,9,6,7,17} ; var n : int ; n := arr->size() ; execute replaceMax(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; public class Codechef3 { public static void main(String[] args){ Scanner h=new Scanner(System.in); int x=h.nextInt(); for(int i=0 ; i(); for(int j=0 ; j<(2*n); j++){ l1.add(h.nextInt()); } Collections.sort(l1); for(int j=0 ; jtoInteger() ; var i : int ; i := 0 ; while i < x do ( ( var n : int ; n := h.getCurrent()->toInteger() ; var l1 : Sequence ; l1 := Sequence{} ; var j : int ; j := 0 ; while j < (2 * n) do ( ( l1 := l1->including(h.getCurrent()->toInteger()) ) ; j := j + 1 ) ; l1 := l1->sort() ; var j : int ; j := 0 ; while j < n do ( ( OclFile["System.out"].print(l1->at(j+1) + " " + l1->at(j + n+1) + " ") ) ; j := j + 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { int n,u ; int[] c,r ; int ans ; boolean[] v ; void dfs(int s,int sum,int depth){ if(u<=sum)ans=depth ; if(ans<=depth)return ; for(int i=0 ; i0)continue ; if((r[i] & s)!=r[i])continue ; int x=s | 1<pow(i)))->oclAsType(long))) > 0) then continue else skip ; if ((r[i+1] & s) /= r[i+1]) then continue else skip ; var x : int ; x := MathLib.bitwiseOr(s,(1*(2->pow(i)))->oclAsType(long)) ; if (v[x+1]) then continue else skip ; v[x+1] := true ; execute dfs(x, sum + c[i+1], depth + 1) ; ) ; i := i + 1 ) ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( n := sc.getCurrent()->toInteger() ; u := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,u)) = 0) then break else skip ; c := Integer.subrange(1,n)->collect(0) ; r := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( c[i+1] := sc.getCurrent()->toInteger() ; var x : int ; x := 0 ; var k : int ; k := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < k do ( x := MathLib.bitwiseOr(x, (1*(2->pow(sc.getCurrent()->toInteger())))->oclAsType(long)) ; ; j := j + 1 ) ; r[i+1] := x ; ) ; i := i + 1 ) ; ans := n ; v := Integer.subrange(1,(1*(2->pow(n)))->oclAsType(long))->collect(false) ; var i : int ; i := 0 ; while i < n do ( if (r[i+1] = 0) then ( v[(1*(2->pow(i)))->oclAsType(long)+1] := true ; execute dfs((1*(2->pow(i)))->oclAsType(long), c[i+1], 1) ) else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B290 { public static void main(String[] args){ String code="111111101010101111100101001111111\n"+"100000100000000001010110001000001\n"+"101110100110110000011010001011101\n"+"101110101011001001111101001011101\n"+"101110101100011000111100101011101\n"+"100000101010101011010000101000001\n"+"111111101010101010101010101111111\n"+"000000001111101111100111100000000\n"+"100010111100100001011110111111001\n"+"110111001111111100100001000101100\n"+"011100111010000101000111010001010\n"+"011110000110001111110101100000011\n"+"111111111111111000111001001011000\n"+"111000010111010011010011010100100\n"+"101010100010110010110101010000010\n"+"101100000101010001111101000000000\n"+"000010100011001101000111101011010\n"+"101001001111101111000101010001110\n"+"101101111111000100100001110001000\n"+"000010011000100110000011010000010\n"+"001101101001101110010010011011000\n"+"011101011010001000111101010100110\n"+"111010100110011101001101000001110\n"+"110001010010101111000101111111000\n"+"001000111011100001010110111110000\n"+"000000001110010110100010100010110\n"+"111111101000101111000110101011010\n"+"100000100111010101111100100011011\n"+"101110101001010000101000111111000\n"+"101110100011010010010111111011010\n"+"101110100100011011110110101110000\n"+"100000100110011001111100111100000\n"+"111111101101000101001101110010001" ; Scanner in=new Scanner(System.in); int row=in.nextInt(); int column=in.nextInt(); char answer=code.split("\n")[row] .charAt(column); System.out.println(answer); } } ------------------------------------------------------------ OCL File: --------- class B290 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var code : String ; code := "111111101010101111100101001111111\n" + "100000100000000001010110001000001\n" + "101110100110110000011010001011101\n" + "101110101011001001111101001011101\n" + "101110101100011000111100101011101\n" + "100000101010101011010000101000001\n" + "111111101010101010101010101111111\n" + "000000001111101111100111100000000\n" + "100010111100100001011110111111001\n" + "110111001111111100100001000101100\n" + "011100111010000101000111010001010\n" + "011110000110001111110101100000011\n" + "111111111111111000111001001011000\n" + "111000010111010011010011010100100\n" + "101010100010110010110101010000010\n" + "101100000101010001111101000000000\n" + "000010100011001101000111101011010\n" + "101001001111101111000101010001110\n" + "101101111111000100100001110001000\n" + "000010011000100110000011010000010\n" + "001101101001101110010010011011000\n" + "011101011010001000111101010100110\n" + "111010100110011101001101000001110\n" + "110001010010101111000101111111000\n" + "001000111011100001010110111110000\n" + "000000001110010110100010100010110\n" + "111111101000101111000110101011010\n" + "100000100111010101111100100011011\n" + "101110101001010000101000111111000\n" + "101110100011010010010111111011010\n" + "101110100100011011110110101110000\n" + "100000100110011001111100111100000\n" + "111111101101000101001101110010001" ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var row : int ; row := in.getCurrent()->toInteger() ; var column : int ; column := in.getCurrent()->toInteger() ; var answer : String ; answer := code->split("\n")[row+1]->at(column+1) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n,t=in.nextInt(),a[]=new int[100]; while(t-->0){ n=in.nextInt(); for(int i=1 ; i<=2*n ; i++)a[i]=in.nextInt(); Arrays.sort(a,1,2*n+1); for(int i=2 ; i<=n ; i++)System.out.printf("%d %d ",a[i],a[i+n]); System.out.printf("%d %d \n",a[1],a[1+n]); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var t : int ; t := in.getCurrent()->toInteger() ; var a : Sequence(void) ; a := Integer.subrange(1,100)->collect(0) ; while (t > 0) do ( t := t - 1 ; skip ; ( n := in.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= 2 * n do ( a[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; a := a.subrange(1,1)^(a.subrange(1+1,2 * n + 1)->sort())^a.subrange(2 * n + 1+1,a.size) ; var i : int ; i := 2 ; while i <= n do ( OclFile["System.out"].printf("%d %d ", a[i+1], a[i + n+1]) ; ; i := i + 1 ) ; OclFile["System.out"].printf("%d %d \n", a[1+1], a[1 + n+1]) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class test303 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,2 * n)->collect(0) ; var i : int ; i := 0 ; while i < 2 * n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var i : int ; i := 0 ; var k : int ; k := 2 * n - 1 ; var l : int ; l := 1 ; while i < n do ( ( if (l = 1) then ( OclFile["System.out"].print(a[i+1] + " ") ) else ( OclFile["System.out"].print(a[k+1] + " ") ) ) ; l := l*(-1) ) ; OclFile["System.out"].println(a[n+1]) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final int TEN=10 ; public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(); System.out.println((0==n % s(n))? "Yes" : "No"); } } private static int s(int n){ int answer=0 ; while(n>0){ answer+=n % TEN ; n/=TEN ; } return answer ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute TEN : int := 10; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(if (0 = n mod s(n)) then "Yes" else "No" endif) )) ); static operation s( n : int) : int pre: true post: true activity: ( var answer : int ; answer := 0 ; while (n > 0) do ( answer := answer+(n mod TEN) ; n := n/(TEN) ) ; return answer ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.io.*; import java.util.*; class Main { public static void main(String args[])throws FileNotFoundException { Scanner sc=new Scanner(System.in); String buf ; buf=sc.nextLine(); String[] sbuf=buf.split(""); int sn=0 ; int n=Integer.parseInt(buf); for(int i=0 ; isplit("") ; var sn : int ; sn := 0 ; var n : int ; n := (buf)->toInteger() ; var i : int ; i := 0 ; while i < sbuf->size() do ( ( sn := sn+((sbuf[i+1])->toInteger()) ) ; i := i + 1 ) ; OclFile["System.out"].println(if (n mod sn = 0) then "Yes" else "No" endif) ; ); static operation disp( data : Sequence(long)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < data->size() do ( ( OclFile["System.out"].printf("%d ", data[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int X=sc.nextInt(); int n=X ; int a=0 ; int sum=0 ; while(n>0){ a=n % 10 ; n=n/10 ; sum=sum+a ; } if(X % sum==0){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : int ; X := sc.getCurrent()->toInteger() ; var n : int ; n := X ; var a : int ; a := 0 ; var sum : int ; sum := 0 ; while (n > 0) do ( a := n mod 10 ; n := n / 10 ; sum := sum + a ) ; if (X mod sum = 0) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new java.util.Scanner(System.in); int N=in.nextInt(); int num=0 ; int tmp=N ; while(N>=10){ num+=N % 10 ; N=N/10 ; } num+=N ; if(tmp % num==0){ System.out.print("Yes"); } else { System.out.print("No"); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := Scanner.newScanner(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; var num : int ; num := 0 ; var tmp : int ; tmp := N ; while (N >= 10) do ( num := num+(N mod 10) ; N := N / 10 ) ; num := num+(N) ; if (tmp mod num = 0) then ( OclFile["System.out"].print("Yes") ) else ( OclFile["System.out"].print("No") ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; import java.util.Random ; import java.util.Collections ; import java.util.ArrayDeque ; import java.util.Queue ; import java.util.Deque ; public class Main { public static void main(String args[]){ Scanner first=new Scanner(System.in); int first_word=first.nextInt(); int hundred=first_word/100 ; first_word=first_word-hundred*100 ; int ten=(first_word)/10 ; first_word=first_word-ten*10 ; int one=first_word ; if(hundred==one){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var first : OclFile ; first := OclFile.newOclFile_Read(OclFile["System.in"]) ; var first_word : int ; first_word := first.getCurrent()->toInteger() ; var hundred : int ; hundred := first_word / 100 ; first_word := first_word - hundred * 100 ; var ten : int ; ten := (first_word) / 10 ; first_word := first_word - ten * 10 ; var one : int ; one := first_word ; if (hundred = one) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.StringTokenizer ; public class Main { public static void main(String args[]){ ConsoleScanner cin=new ConsoleScanner(); PrintWriter cout=new PrintWriter(System.out); solve(cin,cout); cout.flush(); } static long now(){ return System.currentTimeMillis(); } static void trace(Object...objects){ assert null!=System.out.format("trace:%s\n",Arrays.deepToString(objects)); } private static void solve(ConsoleScanner cin,PrintWriter cout){ int n=cin.nextInt(); long start=now(); boolean ans=solve(n); if(ans)cout.println("Yes"); else cout.println("No"); trace("elapsed",now()-start); } private static boolean solve(int n){ return n/100==n % 10 ; } static class ConsoleScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ try { while(! st.hasMoreElements())st=new StringTokenizer(br.readLine()); return st.nextToken(); } catch(IOException e){ throw new AssertionError(e); } } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : ConsoleScanner ; cin := ConsoleScanner.newConsoleScanner() ; var cout : OclFile ; cout := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve(cin, cout) ; skip ); static operation now() : long pre: true post: true activity: ( return OclDate.getSystemTime() ); static operation trace( objects : Sequence(OclAny)) : void pre: true post: true activity: ( assert null /= OclFile["System.out"].format("trace:%s\n", (objects + "")) ); static operation solve( cin : ConsoleScanner, cout : OclFile) : void pre: true post: true activity: ( var n : int ; n := cin.nextInt() ; var start : long ; start := now() ; var ans : boolean ; ans := solve(n) ; if (ans) then skip else skip ; ; execute trace("elapsed", now() - start) ; ); static operation solve( n : int) : boolean pre: true post: true activity: ( return n / 100 = n mod 10 ); static class ConsoleScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( try ( while (not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ) catch (e : IOException) do ( error AssertionException(e) ) ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(in); String s=sc.next(); if(s.charAt(0)==s.charAt(2)){ out.println("Yes"); } else { out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var s : String ; s := sc.getCurrent() ; if (s->at(0+1) = s->at(2+1)) then ( out.println("Yes") ) else ( out.println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NewClass37 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); int p=1 ; while(t-->0){ int n=in.nextInt(); int count=0 ; int x=n ; if(n<10){ System.out.println(n); continue ; } while(x>0){ count++; x/=10 ; } int first=0 ; while(count>0){ first=first*10+1 ; count--; } int sum=0 ; if(first<=n){ sum+=n/first ; } first/=10 ; while(first>0){ sum+=9 ; first/=10 ; } System.out.println(sum); } } } ------------------------------------------------------------ OCL File: --------- class NewClass37 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var p : int ; p := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var count : int ; count := 0 ; var x : int ; x := n ; if (n < 10) then ( OclFile["System.out"].println(n) ; continue ) else skip ; while (x > 0) do ( count := count + 1 ; x := x/(10) ) ; var first : int ; first := 0 ; while (count > 0) do ( first := first * 10 + 1 ; count := count - 1 ) ; var sum : int ; sum := 0 ; if (first <= n) then ( sum := sum+(n / first) ) else skip ; first := first/(10) ; while (first > 0) do ( sum := sum+(9) ; first := first/(10) ) ; OclFile["System.out"].println(sum) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static final int INF=Integer.MAX_VALUE/2-1 ; public static final int MAX=20 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] req_bit=new int[MAX]; int[] amounts=new int[MAX]; int[] DP=new int[1<=U){ continue ; } for(int next=0 ; next=U && DP[i]collect(0) ; var amounts : Sequence(int) ; amounts := Integer.subrange(1,MAX)->collect(0) ; var DP : Sequence(int) ; DP := Integer.subrange(1,(1*(2->pow(MAX)))->oclAsType(long))->collect(0) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var U : int ; U := sc.getCurrent()->toInteger() ; if (n = 0 & U = 0) then ( break ) else skip ; var i : int ; i := 0 ; while i < n do ( ( amounts[i+1] := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var bit : int ; bit := 0 ; var j : int ; j := 0 ; while j < k do ( ( bit := MathLib.bitwiseOr(bit, (1*(2->pow((sc.getCurrent()->toInteger()))))->oclAsType(long)) ) ; j := j + 1 ) ; req_bit[i+1] := bit ; ) ; i := i + 1 ) ; DP := DP->collect(INF) ; DP[0+1] := 0 ; var bit_size : int ; bit_size := (1*(2->pow(n)))->oclAsType(long) ; var bit : int ; bit := 0 ; while bit < bit_size do ( ( if (DP[bit+1] >= U) then ( continue ) else skip ; var next : int ; next := 0 ; while next < n do ( ( if ((MathLib.bitwiseAnd(bit,((1*(2->pow(next)))->oclAsType(long)))) /= 0) then ( continue ) else if ((MathLib.bitwiseAnd(bit,(req_bit[next+1]))) /= req_bit[next+1]) then ( continue ) else skip ; ; DP[MathLib.bitwiseOr(bit,((1*(2->pow(next)))->oclAsType(long)))+1] := Set{DP[MathLib.bitwiseOr(bit,((1*(2->pow(next)))->oclAsType(long)))+1], DP[bit+1] + amounts[next+1]}->min() ) ; next := next + 1 ) ) ; bit := bit + 1 ) ; var min : int ; min := INF ; var i : int ; i := 0 ; while i < bit_size do ( ( if (DP[i+1] >= U & DP[i+1] < INF) then ( min := Set{min, bitCount(i)}->min() ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ String in=br.readLine(); String chr[]=in.split(""); int a=Integer.parseInt(chr[0]); int c=Integer.parseInt(chr[2]); System.out.println(a==c ? "Yes" : "No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var in : String ; in := br.readLine() ; var chr : Sequence(String) ; chr := in->split("") ; var a : int ; a := (chr[0+1])->toInteger() ; var c : int ; c := (chr[2+1])->toInteger() ; OclFile["System.out"].println(if a = c then "Yes" else "No" endif) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner sc=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); String N=sc.next(); if(N.charAt(0)==N.charAt(2)){ out.print("Yes"); } else { out.print("No"); } out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var sc : OclFile ; sc := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var N : String ; N := sc.getCurrent() ; if (N->at(0+1) = N->at(2+1)) then ( skip ) else ( skip ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printCount(int a[][],int n,int m,int z[],int l){ for(int i=0 ; imp=new HashMap<>(); for(int j=0 ; jtoInteger() ; C := sc.getCurrent()->toInteger() ; var N : int ; N := sc.getCurrent()->toInteger() ; var list : Sequence(Terminal) ; list := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( var x1 : int ; x1 := sc.getCurrent()->toInteger() ; var y1 : int ; y1 := sc.getCurrent()->toInteger() ; var x2 : int ; x2 := sc.getCurrent()->toInteger() ; var y2 : int ; y2 := sc.getCurrent()->toInteger() ; if (isOnEdge(x1, y1) & isOnEdge(x2, y2)) then ( list := list->including(Terminal.newTerminal(convert(x1, y1), i)) ; list := list->including(Terminal.newTerminal(convert(x2, y2), i)) ) else skip ; ) ; i := i + 1 ) ; list, OclComparator.newOclComparator() := list, OclComparator.newOclComparator()->sort() ; var stack : Sequence(Terminal) ; stack := Sequence{} ; for (t : list) do ( ( if (not(stack->isEmpty()) & stack->min().idx = t.idx) then stack := stack->front() ; else stack := stack->append(t) ; ) ) ; OclFile["System.out"].println(if stack->isEmpty() then "YES" else "NO" endif) ; skip ; ); static operation isOnEdge( x : int, y : int) : boolean pre: true post: true activity: ( return x = 0 or x = R or y = 0 or y = C ); static operation convert( x : int, y : int) : int pre: true post: true activity: ( if (x = 0) then return y else if (y = C) then return C + x else if (x = R) then return C + R + (C - y) else return C + R + C + (R - x) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); if(a>=b){ System.out.println(1); } if(atoInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (a >= b) then ( OclFile["System.out"].println(1) ) else skip ; if (a < b) then ( if (a = 1) then ( OclFile["System.out"].println(b) ) else ( if (b mod a = 0) then ( OclFile["System.out"].println(b / a) ) else ( OclFile["System.out"].println(b / a + 1) ) ) ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws Exception { try(BufferedReader reader=new BufferedReader(new InputStreamReader(System.in))){ String[] data=reader.readLine().split(" "); Integer numDress=Integer.parseInt(data[0]); Integer numParty=Integer.parseInt(data[1]); Integer result=numParty/numDress ; if(numParty % numDress>0)result+=1 ; System.out.println(result); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var data : Sequence(String) ; data := reader.readLine()->split(" ") ; var numDress : int ; numDress := (data[0+1])->toInteger() ; var numParty : int ; numParty := (data[1+1])->toInteger() ; var result : int ; result := numParty / numDress ; if (numParty mod numDress > 0) then result := result+(1) ; else skip ; OclFile["System.out"].println(result) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ while(sc.hasNext()){ final int A=sc.nextInt(); final int B=sc.nextInt(); int ans=B/A ; if(B % A!=0){ ans++; } System.out.println(ans); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while (sc.hasNext()) do ( var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var ans : int ; ans := B / A ; if (B mod A /= 0) then ( ans := ans + 1 ) else skip ; OclFile["System.out"].println(ans) ; ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int a=sc.nextInt(); int b=sc.nextInt(); for(int i=1 ; i<=100000 ; i++){ if(i*a>=b){ System.out.println(i); break ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= 100000 do ( ( if (i * a >= b) then ( OclFile["System.out"].println(i) ; break ) else skip ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int A,B ; A=sc.nextInt(); B=sc.nextInt(); int ans=0 ; if(A>=B){ ans=1 ; } else if(B % A==0){ ans=B/A ; } else { ans=B/A+1 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; var B : int ; A := sc.getCurrent()->toInteger() ; B := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; if (A >= B) then ( ans := 1 ) else if (B mod A = 0) then ( ans := B / A ) else ( ans := B / A + 1 ) ; ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class OrdinaryNumbers { public static void main(String[] args){ Scanner input=new Scanner(System.in); int t=input.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := input.getCurrent()->toInteger() ; var j : int ; j := 1 ; var count : int ; count := 0 ; while (j <= n) do ( if (j * 9 <= n) then ( count := count+(9) ) else ( count := count+(n / j) ) ; j := j * 10 + 1 ) ; OclFile["System.out"].println(count) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class BaiB { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); int[] h=new int[n]; for(int x=0 ; xtoInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var x : int ; x := 0 ; while x < n do ( ( h[x+1] := scan.getCurrent()->toInteger() ) ; x := x + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < k do ( ( res := res+(h[i+1]) ) ; i := i + 1 ) ; var min : int ; min := res ; var index : int ; index := 1 ; var i : int ; i := k ; while i < n do ( ( res := res+(h[i+1] - h[i - k+1]) ; if (res < min) then ( min := res ; index := i - k + 2 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(index) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Fence { public static void main(String[] args){ FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int num=in.nextInt(); int width=in.nextInt(); int[] arr=new int[num]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < num do ( ( arr[i+1] := in.nextInt() ) ; i := i + 1 ) ; var sum : int ; sum := 2147483647 ; var index : int ; index := 0 ; var temp : int ; temp := 0 ; var j : int ; j := 0 ; while j < width do ( ( temp := temp+(arr[j+1]) ) ; j := j + 1 ) ; var i : int ; i := 0 ; while i + width < num + 1 do ( ( if (temp < sum) then ( sum := temp ; index := i ) else skip ; if (i + width < num) then ( temp := temp-(arr[i+1]) ; temp := temp+(arr[i + width+1]) ) else skip ) ; i := i + 1 ) ; skip ; skip ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("sub.in"))) ) catch (ex : FileNotFoundException) do ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (ex : IOException) do skip ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (ex : IOException) do skip return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n ; int p=2000,j=2000 ; for(int i=0 ; i<3 ; i++){ n=scan.nextInt(); if(ntoInteger() ; if (n < p) then p := n ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 2 do ( ( n := scan.getCurrent()->toInteger() ; if (n < j) then j := n ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println((p + j - 50)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public static void main(String[] args){ java.util.Scanner in=new java.util.Scanner(System.in); String[] str=new String[5]; int[] prs=new int[5]; for(int i=0 ; i<5 ; i++){ str[i]=in.next(); prs[i]=java.lang.Integer.parseInt(str[i]); } int tmp1=2000,tmp2=2000 ; for(int i=0 ; i<5 ; i++){ if(i<3){ if(prs[i]collect(null) ; var prs : Sequence(int) ; prs := Integer.subrange(1,5)->collect(0) ; var i : int ; i := 0 ; while i < 5 do ( ( str[i+1] := in.next() ; prs[i+1] := java.lang.Integer.parseInt(str[i+1]) ) ; i := i + 1 ) ; var tmp1 : int ; tmp1 := 2000 ; var tmp2 : int ; tmp2 := 2000 ; var i : int ; i := 0 ; while i < 5 do ( ( if (i < 3) then ( if (prs[i+1] < tmp1) then tmp1 := prs[i+1] ; else skip ) else if (i < 5) then ( if (prs[i+1] < tmp2) then tmp2 := prs[i+1] ; else skip ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(tmp1 + tmp2 - 50) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); public int pasta(){ int ans=0 ; for(int i=0 ; i<3 ; i++){ int input=sc.nextInt(); if(i==0 || ans>input)ans=input ; } return ans ; } public int juice(){ int ans=0 ; for(int i=0 ; i<2 ; i++){ int input=sc.nextInt(); if(i==0 || ans>input)ans=input ; } return ans ; } public void set(){ int p=pasta(); int j=juice(); int ans=p+j-50 ; System.out.println(ans); } public static void main(String[] args){ new Main().set(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation pasta() : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 3 do ( ( var input : int ; input := sc.getCurrent()->toInteger() ; if (i = 0 or ans > input) then ans := input ; else skip ) ; i := i + 1 ) ; return ans ); operation juice() : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 2 do ( ( var input : int ; input := sc.getCurrent()->toInteger() ; if (i = 0 or ans > input) then ans := input ; else skip ) ; i := i + 1 ) ; return ans ); operation set() : void pre: true post: true activity: ( var p : int ; p := pasta() ; var j : int ; j := juice() ; var ans : int ; ans := p + j - 50 ; OclFile["System.out"].println(ans) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() := Main.newMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Collections ; import java.util.LinkedList ; public class Main { public static void main(String[] args){ Main main=new Main(); main.lunchMinimumValueCalculation(); return ; } private void lunchMinimumValueCalculation(){ BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); LinkedListpastaPriceList=new LinkedList(); LinkedListjuicePriceList=new LinkedList(); try { for(int i=0 ; i<3 ; i++){ String inputStr=bufferedReader.readLine(); pastaPriceList.add(Integer.parseInt(inputStr)); } for(int i=0 ; i<2 ; i++){ String inputStr=bufferedReader.readLine(); juicePriceList.add(Integer.parseInt(inputStr)); } Collections.sort(pastaPriceList); Collections.sort(juicePriceList); int pastaPriceNum=pastaPriceList.get(0); int juicePriceNum=juicePriceList.get(0); System.out.println((pastaPriceNum+juicePriceNum)-50); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.lunchMinimumValueCalculation() ; return ); operation lunchMinimumValueCalculation() : void pre: true post: true activity: ( var bufferedReader : OclFile ; bufferedReader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pastaPriceList : Sequence(int) ; pastaPriceList := Sequence{} ; var juicePriceList : Sequence(int) ; juicePriceList := Sequence{} ; try ( var i : int ; i := 0 ; while i < 3 do ( ( var inputStr : String ; inputStr := bufferedReader.readLine() ; pastaPriceList := pastaPriceList->including((inputStr)->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 2 do ( ( var inputStr : String ; inputStr := bufferedReader.readLine() ; juicePriceList := juicePriceList->including((inputStr)->toInteger()) ) ; i := i + 1 ) ; pastaPriceList := pastaPriceList->sort() ; juicePriceList := juicePriceList->sort() ; var pastaPriceNum : int ; pastaPriceNum := pastaPriceList->at(0+1) ; var juicePriceNum : int ; juicePriceNum := juicePriceList->at(0+1) ; OclFile["System.out"].println((pastaPriceNum + juicePriceNum) - 50) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Round0D { int cases ; void process(Scanner scanner,PrintStream out)throws IOException { cases=scanner.nextInt(); scanner.nextLine(); for(int curCase=0 ; curCasea=new ArrayList<>(); for(int i=0 ; i>i)& 1)==1){ t ^=a.get(i); } } if(p==t){ ans++; } } System.out.println(ans); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.run() ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( a := a->including(0) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( var k : int ; k := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < k do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; s := s - 1 ; a := a.setAt(s+1,a->at(s+1) or ((1*(2->pow(i)))->oclAsType(long))) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var p : int ; p := 0 ; var i : int ; i := 0 ; while i < M do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; p := MathLib.bitwiseOr(p, ((x*(2->pow(i)))->oclAsType(long))) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var s : int ; s := 0 ; while s < ((1*(2->pow(N)))->oclAsType(long)) do ( ( var t : int ; t := 0 ; var i : int ; i := 0 ; while i < N do ( ( if ((((s/(2->pow(i)))->oclAsType(long)) & 1) = 1) then ( t := MathLib.bitwiseXor(t,a->at(i+1)) ) else skip ) ; i := i + 1 ) ; if (p = t) then ( ans := ans + 1 ) else skip ) ; s := s + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package lab6zp ; import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Lab6ZP { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); for(int i=0 ; i0){ long exp=1 ; long total=0 ; while(exptoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var k : long ; k := in.getCurrent()->toInteger() ; var c : long ; c := in.getCurrent()->toInteger() ; var s : int ; s := in.getCurrent()->toInteger() ; OclFile["System.out"].print("Case #" + (i + 1) + ": ") ; if (c * s < k) then ( OclFile["System.out"].println("IMPOSSIBLE") ) else ( var val : long ; val := 0 ; while (s > 0) do ( var exp : long ; exp := 1 ; var total : long ; total := 0 ; while (exp < k->pow(c)) do ( total := total+(val * exp) ; exp := exp*(k) ; if (val < k - 1) then ( val := val + 1 ) else skip ) ; s := s - 1 ; OclFile["System.out"].print(total + 1) ; if (total + 1 = k->pow(c)) then ( s := 0 ) else skip ; if (s /= 0) then ( OclFile["System.out"].print(" ") ) else ( OclFile["System.out"].println() ) ; ) ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); while(true){ n=scanner.nextInt(); u=scanner.nextInt(); if((n | u)==0)break ; need=new int[n]; int all=0 ; unit=new int[n]; for(int i=0 ; i=u){ ans=one ; return ; } if(ans-1==one)return ; for(int i=0 ; itoInteger() ; u := scanner.getCurrent()->toInteger() ; if ((n or u) = 0) then break else skip ; need := Integer.subrange(1,n)->collect(0) ; var all : int ; all := 0 ; unit := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( unit[i+1] := scanner.getCurrent()->toInteger() ; all := all+(unit[i+1]) ; var k : int ; k := scanner.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < k do ( ( var x : int ; x := scanner.getCurrent()->toInteger() ; need[i+1] := MathLib.bitwiseOr(need[i+1], ((1*(2->pow(x)))->oclAsType(long))) ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (all = u) then ( OclFile["System.out"].println(n) ; continue ) else skip ; ans := n ; v := Integer.subrange(1,(1*(2->pow(n)))->oclAsType(long))->collect(false) ; execute slove(0, 0, 0) ; OclFile["System.out"].println(ans) ; ) ); operation slove( bit : int, one : int, have : int) : void pre: true post: true activity: ( if (ans = one) then return else skip ; if (have >= u) then ( ans := one ; return ) else skip ; if (ans - 1 = one) then return else skip ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := MathLib.bitwiseOr(bit,((1*(2->pow(i)))->oclAsType(long))) ; if (v[a+1] or (bit or need[i+1]) /= bit) then continue else skip ; v[a+1] := true ; execute slove(a, one + 1, have + unit[i+1]) ) ; i := i + 1 ) ); attribute n : int; attribute need : Sequence(int); attribute ans : int; attribute v : Sequence(boolean); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class D { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("src/D-large.in")))); String output="" ; int t=sc.nextInt(); for(int i=1 ; i<=t ; i++){ int k=sc.nextInt(); int c=sc.nextInt(); int s=sc.nextInt(); if(s*cnums=new ArrayList(); for(int j=0 ; j=k)break ; long next=0 ; long mult=1 ; for(int m=0 ; m=k)break ; next+=(j*c+m)*mult ; mult*=k ; } next++; nums.add(next); } String toAdd="" ; for(int j=0 ; jtoInteger() ; var i : int ; i := 1 ; while i <= t do ( ( var k : int ; k := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var s : int ; s := sc.getCurrent()->toInteger() ; if (s * c < k) then ( output := output+("Case #" + i + ": IMPOSSIBLE\n") ; continue ) else skip ; var nums : Sequence(long) ; nums := Sequence{} ; var j : int ; j := 0 ; while j < s do ( ( if (j * c >= k) then break else skip ; var next : long ; next := 0 ; var mult : long ; mult := 1 ; var m : int ; m := 0 ; while m < c do ( ( if (j * c + m >= k) then break else skip ; next := next+((j * c + m) * mult) ; mult := mult*(k) ) ; m := m + 1 ) ; next := next + 1 ; nums := nums->including(next) ; ) ; j := j + 1 ) ; var toAdd : String ; toAdd := "" ; var j : int ; j := 0 ; while j < nums->size() do ( ( toAdd := toAdd+(" " + nums->at(j+1)) ) ; j := j + 1 ) ; output := output+("Case #" + i + ":" + toAdd + "\n") ; ) ; i := i + 1 ) ; var bw : OclFile ; bw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("src/D-large.out")), "utf-8")) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.nextLine()); char[] arr=sc.nextLine().toCharArray(); boolean prev=arr[0]=='T' ; for(int i=2 ; itoInteger() ; var arr : Sequence(String) ; arr := sc.nextLine()->characters() ; var prev : boolean ; prev := arr[0+1] = 'T' ; var i : int ; i := 2 ; while i < arr->size() do ( ( prev := check(prev, arr[i+1] = 'T') ) ; i := i+(2) ) ; var ans : String ; if (prev) then ( ans := "T" ) else ( ans := "F" ) ; OclFile["System.out"].println(ans) ; ); static operation check( a : boolean, b : boolean) : boolean pre: true post: true activity: ( if (a & not(b)) then ( return false ) else ( return true ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Map ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),f=sc.nextInt(),c=0 ; Mapmp=new TreeMap<>(); for(int i=0 ; im : mp.entrySet()){ if(m.getValue()>=f){ System.out.println(m.getKey()); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var f : int ; f := sc.getCurrent()->toInteger() ; var c : int ; c := 0 ; var mp : Map(String,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var m : int ; m := sc.getCurrent()->toInteger() ; var v : Sequence(String) ; v := Integer.subrange(1,m)->collect(null) ; var j : int ; j := 0 ; while j < m do ( ( v[j+1] := sc.getCurrent() ; var k : int ; k := 0 ; while k < j do ( ( var t : Sequence(String) ; t := Sequence{v[j+1],v[k+1]} ; t := t->sort() ; var tt : String ; tt := t[0+1] + " " + t[1+1] ; if (mp->keys()->includes(tt)) then ( mp := mp->union(Map{tt |-> mp->at(tt) + 1}) ; if (mp->at(tt) = f) then ( c := c + 1 ) else skip ) else ( mp := mp->union(Map{tt |-> 1}) ; if (f = 1) then c := c + 1 ; else skip ) ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; for (m : mp->asSet()) do ( ( if (m.getValue() >= f) then ( OclFile["System.out"].println(m.getKey()) ) else skip ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int a[][]=new int[n][m]; int i,j ; for(i=0 ; iarr=new ArrayList<>(); boolean res=true ; for(i=0 ; i0){ arr.add(new mine(i,j)); a[i][j]=3 ; a[i][j+1]=3 ; a[i+1][j+1]=3 ; a[i+1][j]=3 ; } } } for(i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var i : int ; var j : int ; i := 0 ; while i < n do ( ( j := 0 ; while j < m do ( ( a[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var vis : Sequence(Sequence(boolean)) ; vis := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(false)) ; var arr : Sequence(mine) ; arr := Sequence{} ; var res : boolean ; res := true ; i := 0 ; while i < n - 1 do ( ( j := 0 ; while j < m - 1 do ( ( if (a[i+1][j+1] * a[i + 1+1][j+1] * a[i + 1+1][j + 1+1] * a[i+1][j + 1+1] > 0) then ( arr := arr->including(mine.newmine(i, j)) ; a[i+1][j+1] := 3 ; a[i+1][j + 1+1] := 3 ; a[i + 1+1][j + 1+1] := 3 ; a[i + 1+1][j+1] := 3 ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; i := 0 ; while i < n do ( ( j := 0 ; while j < m do ( ( if (a[i+1][j+1] = 1) then res := false ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (res = false) then OclFile["System.out"].println("-1") else ( OclFile["System.out"].println(arr->size()) ; for (h : arr) do ( ( OclFile["System.out"].println((h.x + 1) + " " + (h.y + 1)) ) ) ) ; ); } class mine { attribute x : int; attribute y : int; static operation newmine( a : int, b : int) : mine pre: true post: true activity: ( var self : mine ; self := createmine(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( x := a ; y := b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public int countPrimes(int n){ boolean[] isPrime=new boolean[n]; int count=0 ; Arrays.fill(isPrime,true); for(int i=2 ; i=n)break ; if(! isPrime[i])continue ; for(int j=i*i ; jcollect(false) ; var count : int ; count := 0 ; isPrime := isPrime->collect(true) ; var i : int ; i := 2 ; while i < n do ( ( if (i * i >= n) then break else skip ; if (not(isPrime[i+1])) then continue else skip ; var j : int ; j := i * i ; while j < n do ( isPrime[j+1] := false ; ; j := j+(i) ) ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i < n do ( if (isPrime[i+1]) then count := count + 1 ; else skip ; ; i := i + 1 ) ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.Scanner ; public class Main { static long[][] res ; static Scanner sc=new Scanner(System.in); static int vn ; static int en ; static int[] parent ; static boolean BFS(){ boolean[] visited=new boolean[vn]; int pos=0 ; LinkedListq=new LinkedList(); q.add(0); while(! q.isEmpty()){ pos=q.pop(); if(pos==vn-1)return true ; for(int i=0 ; i0 && ! visited[i]){ visited[i]=true ; parent[i]=pos ; q.push(i); } } } return false ; } public static void main(String[] args){ int ans=0 ; vn=sc.nextInt(); en=sc.nextInt(); res=new long[vn][vn]; parent=new int[vn]; for(int i=0 ; icollect(false) ; var pos : int ; pos := 0 ; var q : Sequence(int) ; q := Sequence{} ; q := q->including(0) ; while (not(q->isEmpty())) do ( pos := q->last() ; q := q->front() ; if (pos = vn - 1) then return true else skip ; var i : int ; i := 0 ; while i < vn do ( ( if (res[pos+1][i+1] > 0 & not(visited[i+1])) then ( visited[i+1] := true ; parent[i+1] := pos ; q := q->append(i) ) else skip ) ; i := i + 1 ) ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ans : int ; ans := 0 ; vn := sc.getCurrent()->toInteger() ; en := sc.getCurrent()->toInteger() ; res := Integer.subrange(1,vn)->collect(Integer.subrange(1,vn)->collect(0)) ; parent := Integer.subrange(1,vn)->collect(0) ; var i : int ; i := 0 ; while i < en do ( ( var v1 : int ; v1 := sc.getCurrent()->toInteger() ; var v2 : int ; v2 := sc.getCurrent()->toInteger() ; var cap : int ; cap := sc.getCurrent()->toInteger() ; res[v1+1][v2+1] := cap ) ; i := i + 1 ) ; while (BFS() = true) do ( var minflow : long ; minflow := 9999999999l ; var backtrackpos : int ; backtrackpos := vn - 1 ; while (backtrackpos /= 0) do ( minflow := Set{minflow, res[parent[backtrackpos+1]+1][backtrackpos+1]}->min() ; if (backtrackpos = 0) then break else skip ; backtrackpos := parent[backtrackpos+1] ) ; ans := ans+(minflow) ; backtrackpos := vn - 1 ; while (backtrackpos /= 0) do ( res[parent[backtrackpos+1]+1][backtrackpos+1] := res[parent[backtrackpos+1]+1][backtrackpos+1]-(minflow) ; res[backtrackpos+1][parent[backtrackpos+1]+1] := res[backtrackpos+1][parent[backtrackpos+1]+1]+(minflow) ; backtrackpos := parent[backtrackpos+1] ) ; ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findMinSwaps(String s,int k){ int ans=0 ; int c_one=0,c_zero=0 ; for(int i=s.length()-1 ; i>=0 ; i--){ if(s.charAt(i)=='1')c_one++; if(s.charAt(i)=='0'){ c_zero++; ans+=c_one ; } if(c_zero==k)break ; } if(c_zerosize() - 1 ; while i >= 0 do ( ( if (s->at(i+1) = '1') then c_one := c_one + 1 ; else skip ; if (s->at(i+1) = '0') then ( c_zero := c_zero + 1 ; ans := ans+(c_one) ) else skip ; if (c_zero = k) then break else skip ) ; i := i - 1 ) ; if (c_zero < k) then return -1 else skip ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "100111" ; var k : int ; k := 2 ; OclFile["System.out"].println(findMinSwaps(s, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Ordinary_Numbers { public static void main(String[] args){ long testcase ; Scanner sc=new Scanner(System.in); testcase=sc.nextLong(); for(long i=0 ; itoLong() ; var i : long ; i := 0 ; while i < testcase do ( ( var n : long ; var nearest_leftmost : long ; var nearest_digit : long ; var ordinary : long ; ordinary := 0 ; var near_num : long ; n := sc.getCurrent()->toLong() ; nearest_leftmost := (n / 10->pow(digit(n)->oclAsType(double) - 1)->oclAsType(long)) ; nearest_digit := digit(n) ; near_num := nearest_ordinary_num(nearest_digit, nearest_leftmost) ; if (nearest_leftmost - 1 = 0 & n < near_num) then ( nearest_leftmost := 9 ; nearest_digit := nearest_digit - 1 ) else if (n < near_num) then nearest_leftmost := nearest_leftmost - 1 ; else skip ; ; while (nearest_digit /= 1) do ( ordinary := ordinary+(9) ; nearest_digit := nearest_digit - 1 ) ; ordinary := ordinary+(nearest_leftmost) ; OclFile["System.out"].print(ordinary) ; if (i < testcase - 1) then OclFile["System.out"].print("\n") ; else skip ; ) ; i := i + 1 ) ; skip ; ); static operation digit( x : long) : long pre: true post: true activity: ( var count : long ; count := 0 ; while (x /= 0) do ( x := x/(10) ; count := count + 1 ) ; return count ); static operation nearest_ordinary_num( digit : long, leftmost_num : long) : long pre: true post: true activity: ( var sum : long ; sum := 0 ; while (true) do ( digit := digit - 1 ; sum := sum+(10->pow(digit->oclAsType(double)) * leftmost_num) ; if (digit = 0) then break else skip ) ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class tennis { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),d=in.nextInt(); int sum=0 ; int a[]=new int[n]; for(int i=0 ; i=m)? sum : sum+(n-m)*d); } } ------------------------------------------------------------ OCL File: --------- class tennis { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var d : int ; d := in.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var m : int ; m := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(a[i+1]) ; if (i = m - 1) then break else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(if (n >= m) then sum else sum + (n - m) * d endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import org.w3c.dom.ls.LSOutput ; import java.util.*; import java.util.function.IntBinaryOperator ; public class Example { static long[][] dp ; static int mod=1000000000+7 ; static long[] ans=new long[100000+1]; static List>adj ; static int[] vis ; static int[] dis ; static int row ; static boolean[] chosen ; static Listpermutation ; static int k ; static int count ; static int[][] arr ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int d=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; icollect(0); static attribute adj : Sequence(Sequence(int)); static attribute vis : Sequence(int); static attribute dis : Sequence(int); static attribute row : int; static attribute chosen : Sequence(boolean); static attribute permutation : Sequence(int); static attribute k : int; static attribute count : int; static attribute arr : Sequence(Sequence(int)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; var m : int ; m := sc.getCurrent()->toInteger() ; var profit : int ; profit := 0 ; var i : int ; i := 0 ; while i < m do ( ( if (i < n) then ( profit := profit+(arr[i+1]) ) else ( profit := profit-(d) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(profit) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int N=3,M=3 ; static boolean check(int a[][],int b[][]){ for(int i=1 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int N ; static int W ; static int w0 ; static ArrayList[] v=new ArrayList[4]; static { for(int i=0 ; i(N); } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); N=sc.nextInt(); W=sc.nextInt(); w0=sc.nextInt(); v[0] .add(sc.nextInt()); for(int i=1 ; i=v.length){ return 0 ; } int vi=0 ; int wi=totalW ; int max_v=0 ; for(int n=0 ; n<=numLeft && n<=v[startIndex] .size(); ++n){ if(n>=1){ vi+=v[startIndex] .get(n-1); wi+=w0+startIndex ; } if(wi>W){ break ; } max_v=Integer.max(max_v,vi+solve(startIndex+1,numLeft-n,wi)); } return max_v ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute N : int; static attribute W : int; static attribute w0 : int; static attribute v : Sequence(Sequence(int)) := Integer.subrange(1,4)->collect(null); static operation initialiseClass() pre: true post: true activity: var i : int ; i := 0 ; while i < v->size() do ( ( v[i+1] := Sequence{} ) ; i := i + 1 ) ; ; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := sc.getCurrent()->toInteger() ; W := sc.getCurrent()->toInteger() ; w0 := sc.getCurrent()->toInteger() ; v[0+1]->excludes(sc.getCurrent()->toInteger()) ; var i : int ; i := 1 ; while i < N do ( ( var w : int ; w := sc.getCurrent()->toInteger() ; v[w - w0+1]->excludes(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < v->size() do ( ( v[i+1].sort(Comparator.reverseOrder()) ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(0, N, 0)) ; ); static operation solve( startIndex : int, numLeft : int, totalW : int) : int pre: true post: true activity: ( if (startIndex >= v->size()) then ( return 0 ) else skip ; var vi : int ; vi := 0 ; var wi : int ; wi := totalW ; var max_v : int ; max_v := 0 ; var n : int ; n := 0 ; while n <= numLeft & n <= v[startIndex+1]->size() do ( ( if (n >= 1) then ( vi := vi+(v[startIndex+1]->at(n - 1+1)) ; wi := wi+(w0 + startIndex) ) else skip ; if (wi > W) then ( break ) else skip ; max_v := Set{max_v, vi + solve(startIndex + 1, numLeft - n, wi)}->max() ) ; n := n + 1 ) ; return max_v ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); SimpleKnapsack solver=new SimpleKnapsack(); solver.solve(1,in,out); out.close(); } static class SimpleKnapsack { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); long w=in.nextLong(); long[] weights=new long[n]; long[] values=new long[n]; long[][] dp=new long[n+1][3*n+1]; for(int i=0 ; itoInteger() ; var w : long ; w := in.getCurrent()->toLong() ; var weights : Sequence(long) ; weights := Integer.subrange(1,n)->collect(0) ; var values : Sequence(long) ; values := Integer.subrange(1,n)->collect(0) ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,3 * n + 1)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( weights[i+1] := (in.getCurrent())->toLong() ; values[i+1] := (in.getCurrent())->toLong() ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var diff : int ; diff := (weights[i+1] - weights[0+1])->oclAsType(int) ; var j : int ; j := i ; while 0 <= j do ( ( var k : int ; k := sum ; while 0 <= k do ( ( dp[j + 1+1][k + diff+1] := Set{dp[j + 1+1][k + diff+1], dp[j+1][k+1] + values[i+1]}->max() ) ; k := k - 1 ) ) ; j := j - 1 ) ; sum := sum+(diff) ) ; i := i + 1 ) ; var result : long ; result := 0 ; var i : int ; i := 0 ; while i <= n do ( ( var j : int ; j := 0 ; while j <= sum do ( ( if (w < i * weights[0+1] + j) then ( continue ) else skip ; result := Set{result, dp[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static int calculateSum(String arr[],int n){ if(n==0)return 0 ; String s=arr[0]; int value=Integer.parseInt(s); int sum=value ; for(int i=2 ; itoInteger() ; var sum : int ; sum := value ; var i : int ; i := 2 ; while i < n do ( ( s := arr[i+1] ; value := (s)->toInteger() ; var operation : String ; operation := arr[i - 1+1]->at(0+1) ; if (operation = '+') then sum := sum+(value) ; else sum := sum-(value) ; ) ; i := i + 2 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"3","+","4","-","7","+","13"} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(calculateSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class GFG { public static boolean isFascinating(int num){ int[] freq=new int[10]; String val=""+num+num*2+num*3 ; for(int i=0 ; i0)return false ; else freq[digit]++; } for(int i=1 ; icollect(0) ; var val : String ; val := "" + num + num * 2 + num * 3 ; var i : int ; i := 0 ; while i < val->size() do ( ( var digit : int ; digit := val->at(i+1) - ('0')->char2byte() ; if (freq[digit+1] > 0) then return false else freq[digit+1] := freq[digit+1] + 1 ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < freq->size() do ( ( if (freq[i+1] = 0) then return false else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 192 ; if (num < 100) then OclFile["System.out"].println("No") ; else ( var ans : boolean ; ans := isFascinating(num) ; if (ans) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; int[][] price=new int[3][26]; for(int i=0 ; i<3 ; i++){ for(int j=1 ; j<26 ; j++){ switch(i){ case 0 : price[i][j]=price[i][j-1]+380 ; if(j % 5==0){ price[i][j]-=380 ; } break ; case 1 : price[i][j]=price[i][j-1]+550 ; if(j % 4==0){ price[i][j]-=330 ; } break ; case 2 : price[i][j]=price[i][j-1]+850 ; if(j % 3==0){ price[i][j]-=306 ; } break ; } } } while((line=br.readLine())!=null && ! line.isEmpty()){ int n=Integer.parseInt(line); if(n==0){ break ; } int min=Integer.MAX_VALUE ; for(int i=0 ; icollect(Integer.subrange(1,26)->collect(0)) ; var i : int ; i := 0 ; while i < 3 do ( ( var j : int ; j := 1 ; while j < 26 do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (i) ; if _switchval = 0 then price[i+1][j+1] := price[i+1][j - 1+1] + 380 ; if (j mod 5 = 0) then ( price[i+1][j+1] := price[i+1][j+1]-(380) ) else skip ; break else skip ; if _switchval = 1 then price[i+1][j+1] := price[i+1][j - 1+1] + 550 ; if (j mod 4 = 0) then ( price[i+1][j+1] := price[i+1][j+1]-(330) ) else skip ; break else skip ; if _switchval = 2 then price[i+1][j+1] := price[i+1][j - 1+1] + 850 ; if (j mod 3 = 0) then ( price[i+1][j+1] := price[i+1][j+1]-(306) ) else skip ; break else skip ; ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var n : int ; n := (line)->toInteger() ; if (n = 0) then ( break ) else skip ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while i < n / 200 + 1 do ( ( var j : int ; j := 0 ; while j < n / 300 + 1 do ( ( var k : int ; k := 0 ; while k < n / 500 + 1 do ( ( if (i * 200 + j * 300 + k * 500 = n) then ( var sum : int ; sum := price[0+1][i+1] + price[1+1][j+1] + price[2+1][k+1] ; if (sum < min) then ( min := sum ) else skip ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ) ; line := br.readLine() ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int[] c ; int y,i ; c=new int[51]; for(i=0 ; i<51 ; i++)c[i]=850*200 ; c[0]=0 ; for(i=0 ; i<51 ; i++){ if(i+2<51 && c[i]+380collect(0) ; i := 0 ; while i < 51 do ( c[i+1] := 850 * 200 ; ; i := i + 1 ) ; c[0+1] := 0 ; i := 0 ; while i < 51 do ( ( if (i + 2 < 51 & c[i+1] + 380 < c[i + 2+1]) then c[i + 2+1] := c[i+1] + 380 ; else skip ; if (i + 3 < 51 & c[i+1] + 550 < c[i + 3+1]) then c[i + 3+1] := c[i+1] + 550 ; else skip ; if (i + 5 < 51 & c[i+1] + 850 < c[i + 5+1]) then c[i + 5+1] := c[i+1] + 850 ; else skip ; if (i + 10 < 51 & c[i+1] + 1900 * 8 / 10 < c[i + 10+1]) then c[i + 10+1] := c[i+1] + 1900 * 8 / 10 ; else skip ; if (i + 12 < 51 & c[i+1] + 2200 * 85 / 100 < c[i + 12+1]) then c[i + 12+1] := c[i+1] + 2200 * 85 / 100 ; else skip ; if (i + 15 < 51 & c[i+1] + 2550 * 88 / 100 < c[i + 15+1]) then c[i + 15+1] := c[i+1] + 2550 * 88 / 100 ; else skip ; ) ; i := i + 1 ) ; while true do ( ( y := sc.nextInt() ; if (y = 0) then break else skip ; out.println(c[y / 100+1]) ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.util.*; public class ques { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; i0){ count++; qou=qou/10 ; } int zeroes=1 ; double ones=1 ; for(double j=1 ; j=ones*firstDigit){ ans=ans+1 ; } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class ques { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var count : int ; count := 1 ; var qou : int ; qou := n / 10 ; while (qou > 0) do ( count := count + 1 ; qou := qou / 10 ) ; var zeroes : int ; zeroes := 1 ; var ones : double ; ones := 1 ; var j : double ; j := 1 ; while j < count do ( ( zeroes := 10 * zeroes ; ones := ones + 10->pow(j) ) ; j := j + 1 ) ; var firstDigit : int ; firstDigit := n / (zeroes) ; var ans : int ; ans := (count - 1) * 9 + firstDigit - 1 ; if (n >= ones * firstDigit) then ( ans := ans + 1 ) else skip ; OclFile["System.out"].println(ans) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-9 ; void run(){ int[] a=new int[51]; Arrays.fill(a,INF); for(int k=0 ; toGramme(0,0,k)<=50 ; k++){ for(int j=0 ; toGramme(0,j,k)<=50 ; j++){ for(int i=0 ; toGramme(i,j,k)<=50 ; i++){ int g=toGramme(i,j,k); a[g]=Math.min(a[g],toMoney(i,j,k)); } } } for(; ; ){ int g=sc.nextInt()/100 ; if(g==0){ break ; } println(a[g]+""); } } int toGramme(int i,int j,int k){ return i*2+j*3+k*5 ; } int toMoney(int i,int j,int k){ int sum=0 ; sum+=380*(i-i % 5)*80/100+380*(i % 5); sum+=550*(j-j % 4)*85/100+550*(j % 4); sum+=850*(k-k % 3)*88/100+850*(k % 3); return sum ; } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,51)->collect(0) ; a := a->collect(INF) ; var k : int ; k := 0 ; while toGramme(0, 0, k) <= 50 do ( ( var j : int ; j := 0 ; while toGramme(0, j, k) <= 50 do ( ( var i : int ; i := 0 ; while toGramme(i, j, k) <= 50 do ( ( var g : int ; g := toGramme(i, j, k) ; a[g+1] := Set{a[g+1], toMoney(i, j, k)}->min() ) ; i := i + 1 ) ) ; j := j + 1 ) ) ; k := k + 1 ) ; while true do ( ( var g : int ; g := sc.getCurrent()->toInteger() / 100 ; if (g = 0) then ( break ) else skip ; execute println(a[g+1] + "") ) ) ); operation toGramme( i : int, j : int, k : int) : int pre: true post: true activity: ( return i * 2 + j * 3 + k * 5 ); operation toMoney( i : int, j : int, k : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; sum := sum+(380 * (i - i mod 5) * 80 / 100 + 380 * (i mod 5)) ; sum := sum+(550 * (j - j mod 4) * 85 / 100 + 550 * (j mod 4)) ; sum := sum+(850 * (k - k mod 3) * 88 / 100 + 850 * (k mod 3)) ; return sum ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int min=Integer.MAX_VALUE ; static int w[]={ 200,300,500 }; static int p[]={ 380,550,850 }; static int e[]={ 5,4,3 }; static double r[]={ 0.8,0.85,0.88 }; public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0)break ; min=Integer.MAX_VALUE ; solve(0,n,0); System.out.println((int)min); } } public static void solve(int k,int rest,int cost){ if(rest==0){ min=Math.min(min,cost); return ; } if(k==3 || rest<0)return ; for(int i=0 ; i<=5000/w[k]; i++){ solve(k+1,rest-w[k]*i,cost+(int)((i-i % e[k])*r[k]*p[k]+i % e[k]*p[k])); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute min : int := 2147483647; static attribute w : int := Sequence{200,300,500}; static attribute p : int := Sequence{380,550,850}; static attribute e : int := Sequence{5,4,3}; static attribute r : double := Sequence{0.8,0.85,0.88}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; min := 2147483647 ; execute solve(0, n, 0) ; OclFile["System.out"].println(min->oclAsType(int)) ; ) ); static operation solve( k : int, rest : int, cost : int) : void pre: true post: true activity: ( if (rest = 0) then ( min := Set{min, cost}->min() ; return ) else skip ; if (k = 3 or rest < 0) then return else skip ; var i : int ; i := 0 ; while i <= 5000 / w[k+1] do ( ( execute solve(k + 1, rest - w[k+1] * i, cost + ((i - i mod e[k+1]) * r[k+1] * p[k+1] + i mod e[k+1] * p[k+1])->oclAsType(int)) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n!=0){ System.out.println(min(n)); n=sc.nextInt(); } sc.close(); } static int min(int n){ int min=Integer.MAX_VALUE ; for(int c=n/500 ; c>=0 ; c--){ for(int b=(n-c*500)/300 ; b>=0 ; b--){ if((n-c*500-b*300)% 200==0){ int a=(n-c*500-b*300)/200 ; int cost=cost(a,b,c); if(costtoInteger() ; while (n /= 0) do ( OclFile["System.out"].println(Set{n}->min()) ; n := sc.getCurrent()->toInteger() ) ; skip ); static operation min( n : int) : int pre: true post: true activity: ( var min : int ; min := 2147483647 ; var c : int ; c := n / 500 ; while c >= 0 do ( ( var b : int ; b := (n - c * 500) / 300 ; while b >= 0 do ( ( if ((n - c * 500 - b * 300) mod 200 = 0) then ( var a : int ; a := (n - c * 500 - b * 300) / 200 ; var cost : int ; cost := cost(a, b, c) ; if (cost < min) then ( min := cost ) else skip ) else skip ) ; b := b - 1 ) ) ; c := c - 1 ) ; return min ); static operation cost( a : int, b : int, c : int) : int pre: true post: true activity: ( return (a mod 5) * 380 + (a / 5) * 5 * 380 * 8 / 10 + (b mod 4) * 550 + (b / 4) * 4 * 550 * 85 / 100 + (c mod 3) * 850 + (c / 3) * 3 * 850 * 88 / 100 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); System.out.println("0.00000 0.00000"); kochCalc(0,0,100,0,n); System.out.println("100.00000 0.00000"); } public static void kochCalc(double x1,double y1,double x2,double y2,int n){ if(n==0)return ; double dis=Math.pow(Math.pow(x1-x2,2)+Math.pow(y1-y2,2),.5); double true_dis=dis/3 ; double ang=Math.atan2(y2-y1,x2-x1); double sx=x1+Math.cos(ang)*true_dis ; double sy=y1+Math.sin(ang)*true_dis ; double tx=sx+Math.cos(ang)*true_dis ; double ty=sy+Math.sin(ang)*true_dis ; double ux=sx+Math.cos(ang+Math.PI/3)*true_dis ; double uy=sy+Math.sin(ang+Math.PI/3)*true_dis ; kochCalc(x1,y1,sx,sy,n-1); System.out.printf("%.5f %.5f\n",sx,sy); kochCalc(sx,sy,ux,uy,n-1); System.out.printf("%.5f %.5f\n",ux,uy); kochCalc(ux,uy,tx,ty,n-1); System.out.printf("%.5f %.5f\n",tx,ty); kochCalc(tx,ty,x2,y2,n-1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println("0.00000 0.00000") ; execute kochCalc(0, 0, 100, 0, n) ; OclFile["System.out"].println("100.00000 0.00000") ; ); static operation kochCalc( x1 : double, y1 : double, x2 : double, y2 : double, n : int) : void pre: true post: true activity: ( if (n = 0) then return else skip ; var dis : double ; dis := x1 - x2->pow(2) + y1 - y2->pow(2)->pow(.5) ; var true_dis : double ; true_dis := dis / 3 ; var ang : double ; ang := atan2(y2 - y1, x2 - x1) ; var sx : double ; sx := x1 + (ang)->cos() * true_dis ; var sy : double ; sy := y1 + (ang)->sin() * true_dis ; var tx : double ; tx := sx + (ang)->cos() * true_dis ; var ty : double ; ty := sy + (ang)->sin() * true_dis ; var ux : double ; ux := sx + (ang + 3.141592653589793 / 3)->cos() * true_dis ; var uy : double ; uy := sy + (ang + 3.141592653589793 / 3)->sin() * true_dis ; execute kochCalc(x1, y1, sx, sy, n - 1) ; OclFile["System.out"].printf("%.5f %.5f\n", sx, sy) ; execute kochCalc(sx, sy, ux, uy, n - 1) ; OclFile["System.out"].printf("%.5f %.5f\n", ux, uy) ; execute kochCalc(ux, uy, tx, ty, n - 1) ; OclFile["System.out"].printf("%.5f %.5f\n", tx, ty) ; execute kochCalc(tx, ty, x2, y2, n - 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getMinimumOps(int ar[],int k){ int n=ar.length ; int dp[][]=new int[n][k+1]; dp[0][1]=0 ; for(int i=1 ; ifreqOfMode)freqOfMode=newElementFreq ; } dp[i][1]=(i+1)-freqOfMode ; } else { int freq[]=new int[100000]; int freqOfMode=0 ; for(int it=i ; it>=j-1 ; it--){ freq[ar[it] ]++; int newElementFreq=freq[ar[it] ]; if(newElementFreq>freqOfMode)freqOfMode=newElementFreq ; int elementsToChange=i-it+1 ; elementsToChange-=freqOfMode ; dp[i][j]=Math.min(dp[it-1][j-1]+elementsToChange,dp[i][j]); } } } } return dp[n-1][k]; } public static void main(String args[]){ int k=3 ; int ar[]={ 3,1,3,3,2,1,8,5 }; System.out.println(getMinimumOps(ar,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getMinimumOps( ar : Sequence(int), k : int) : int pre: true post: true activity: ( var n : int ; n := ar->size() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,k + 1)->collect(0)) ; dp[0+1][1+1] := 0 ; var i : int ; i := 1 ; while i < n do ( ( var maxGroups : int ; maxGroups := Set{k, i + 1}->min() ; var j : int ; j := 1 ; while j <= maxGroups do ( ( dp[i+1][j+1] := 2147483647 ; if (j = 1) then ( var freq : Sequence(int) ; freq := Integer.subrange(1,100000)->collect(0) ; var freqOfMode : int ; freqOfMode := 0 ; var it : int ; it := 0 ; while it <= i do ( ( freq[ar[it+1]+1] := freq[ar[it+1]+1] + 1 ; var newElementFreq : int ; newElementFreq := freq[ar[it+1]+1] ; if (newElementFreq > freqOfMode) then freqOfMode := newElementFreq ; else skip ) ; it := it + 1 ) ; dp[i+1][1+1] := (i + 1) - freqOfMode ) else ( var freq : Sequence(int) ; freq := Integer.subrange(1,100000)->collect(0) ; var freqOfMode : int ; freqOfMode := 0 ; var it : int ; it := i ; while it >= j - 1 do ( ( freq[ar[it+1]+1] := freq[ar[it+1]+1] + 1 ; var newElementFreq : int ; newElementFreq := freq[ar[it+1]+1] ; if (newElementFreq > freqOfMode) then freqOfMode := newElementFreq ; else skip ; var elementsToChange : int ; elementsToChange := 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() ; ) ; it := it - 1 ) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[n - 1+1][k+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 3 ; var ar : Sequence(int) ; ar := Sequence{3,1,3,3,2,1,8,5} ; OclFile["System.out"].println(getMinimumOps(ar, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static class Point { double x ; double y ; public Point(double x,double y){ this.x=x ; this.y=y ; } public String toString(){ return x+" "+y ; } } static int n ; public static void main(String[] args){ Scanner scan=new Scanner(System.in); n=scan.nextInt(); Point start=new Point(0.0,0.0); Point end=new Point(100.0,0.0); System.out.println(start); make(start,end,0); System.out.println(end); scan.close(); } public static void make(Point start,Point end,int i){ if(n<=i){ return ; } Point s=new Point((2.0*start.x+1.0*end.x)/3.0,(2.0*start.y+1.0*end.y)/3.0); Point t=new Point((1.0*start.x+2.0*end.x)/3.0,(1.0*start.y+2.0*end.y)/3.0); double ux=(t.x-s.x)*Math.cos(Math.toRadians(60))-(t.y-s.y)*Math.sin(Math.toRadians(60))+s.x ; double uy=(t.x-s.x)*Math.sin(Math.toRadians(60))+(t.y-s.y)*Math.cos(Math.toRadians(60))+s.y ; Point u=new Point(ux,uy); make(start,s,i+1); System.out.println(s); make(s,u,i+1); System.out.println(u); make(u,t,i+1); System.out.println(t); make(t,end,i+1); } } ------------------------------------------------------------ OCL File: --------- class Main { static class Point { attribute x : double; attribute y : double; static operation newPoint( x : double, y : double) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : double, y : double) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation toString() : String pre: true post: true activity: ( return x + " " + y ); } static attribute n : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := scan.getCurrent()->toInteger() ; var start : Point ; start := Point.newPoint(0.0, 0.0) ; var end : Point ; end := Point.newPoint(100.0, 0.0) ; OclFile["System.out"].println(start) ; execute make(start, end, 0) ; OclFile["System.out"].println(end) ; skip ; ); static operation make( start : Point, end : Point, i : int) : void pre: true post: true activity: ( if (n <= i) then ( return ) else skip ; var s : Point ; s := Point.newPoint((2.0 * start.x + 1.0 * end.x) / 3.0, (2.0 * start.y + 1.0 * end.y) / 3.0) ; var t : Point ; t := Point.newPoint((1.0 * start.x + 2.0 * end.x) / 3.0, (1.0 * start.y + 2.0 * end.y) / 3.0) ; var ux : double ; ux := (t.x - s.x) * ((0.017453292519943295*(60)))->cos() - (t.y - s.y) * ((0.017453292519943295*(60)))->sin() + s.x ; var uy : double ; uy := (t.x - s.x) * ((0.017453292519943295*(60)))->sin() + (t.y - s.y) * ((0.017453292519943295*(60)))->cos() + s.y ; var u : Point ; u := Point.newPoint(ux, uy) ; execute make(start, s, i + 1) ; OclFile["System.out"].println(s) ; execute make(s, u, i + 1) ; OclFile["System.out"].println(u) ; execute make(u, t, i + 1) ; OclFile["System.out"].println(t) ; execute make(t, end, i + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import javax.xml.crypto.Data ; import java.util.*; import java.io.*; public class Main { static int n ; static int[] A=new int[50]; static double th=Math.PI*60.0/180.0 ; public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); n=sc.nextInt(); Point P1=new Point(0,0); Point P2=new Point(100,0); System.out.printf("%.8f %.8f\n",P1.x,P1.y); koch(n,P1,P2); System.out.printf("%.8f %.8f\n",P2.x,P2.y); } public static void koch(int d,Point P1,Point P2){ if(d==0)return ; double x1=P1.x ; double y1=P1.y ; double x2=P2.x ; double y2=P2.y ; double sx=(2*x1+x2)/3 ; double sy=(2*y1+y2)/3 ; double tx=(x1+2*x2)/3 ; double ty=(y1+2*y2)/3 ; double ux=sx+(tx-sx)*Math.cos(th)-(ty-sy)*Math.sin(th); double uy=sy+(tx-sx)*Math.sin(th)+(ty-sy)*Math.cos(th); Point S=new Point(sx,sy); Point T=new Point(tx,ty); Point U=new Point(ux,uy); koch(d-1,P1,S); System.out.printf("%.8f %.8f\n",sx,sy); koch(d-1,S,U); System.out.printf("%.8f %.8f\n",ux,uy); koch(d-1,U,T); System.out.printf("%.8f %.8f\n",tx,ty); koch(d-1,T,P2); } } class Point { double x ; double y ; Point(double a,double b){ x=a ; y=b ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute n : int; static attribute A : Sequence(int) := Integer.subrange(1,50)->collect(0); static attribute th : double := 3.141592653589793 * 60.0 / 180.0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; var P1 : Point ; P1 := Point.newPoint(0, 0) ; var P2 : Point ; P2 := Point.newPoint(100, 0) ; OclFile["System.out"].printf("%.8f %.8f\n", P1.x, P1.y) ; execute koch(n, P1, P2) ; OclFile["System.out"].printf("%.8f %.8f\n", P2.x, P2.y) ; ); static operation koch( d : int, P1 : Point, P2 : Point) : void pre: true post: true activity: ( if (d = 0) then return else skip ; var x1 : double ; x1 := P1.x ; var y1 : double ; y1 := P1.y ; var x2 : double ; x2 := P2.x ; var y2 : double ; y2 := P2.y ; var sx : double ; sx := (2 * x1 + x2) / 3 ; var sy : double ; sy := (2 * y1 + y2) / 3 ; var tx : double ; tx := (x1 + 2 * x2) / 3 ; var ty : double ; ty := (y1 + 2 * y2) / 3 ; var ux : double ; ux := sx + (tx - sx) * (th)->cos() - (ty - sy) * (th)->sin() ; var uy : double ; uy := sy + (tx - sx) * (th)->sin() + (ty - sy) * (th)->cos() ; var S : Point ; S := Point.newPoint(sx, sy) ; var T : Point ; T := Point.newPoint(tx, ty) ; var U : Point ; U := Point.newPoint(ux, uy) ; execute koch(d - 1, P1, S) ; OclFile["System.out"].printf("%.8f %.8f\n", sx, sy) ; execute koch(d - 1, S, U) ; OclFile["System.out"].printf("%.8f %.8f\n", ux, uy) ; execute koch(d - 1, U, T) ; OclFile["System.out"].printf("%.8f %.8f\n", tx, ty) ; execute koch(d - 1, T, P2) ; ); } class Point { attribute x : double; attribute y : double; static operation newPoint( a : double, b : double) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(a, b); return self ); operation initialise( a : double, b : double) : void pre: true post: true activity: ( x := a ; y := b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.text.DecimalFormat ; class Main { private static final DecimalFormat fmt=new DecimalFormat("0.########"); private static final StringBuilder sb=new StringBuilder(); public static void main(String[] args)throws IOException { final BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); final int n=Integer.parseInt(br.readLine()); sb.append("0 0\n"); koch(0,0,100,0,n); sb.append("100 0\n"); System.out.print(sb); } private static void koch(double x0,double y0,double x1,double y1,int n){ if(n==0)return ; n--; final double sx=(x0+x0+x1)/3 ; final double sy=(y0+y0+y1)/3 ; final double ux=(x0+x1)/2-(y1-y0)*Math.sqrt(3)/6 ; final double uy=(y0+y1)/2+(x1-x0)*Math.sqrt(3)/6 ; final double tx=(x0+x1+x1)/3 ; final double ty=(y0+y1+y1)/3 ; koch(x0,y0,sx,sy,n); sb.append(fmt.format(sx)).append(' ').append(fmt.format(sy)).append('\n'); koch(sx,sy,ux,uy,n); sb.append(fmt.format(ux)).append(' ').append(fmt.format(uy)).append('\n'); koch(ux,uy,tx,ty,n); sb.append(fmt.format(tx)).append(' ').append(fmt.format(ty)).append('\n'); koch(tx,ty,x1,y1,n); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute fmt : DecimalFormat := DecimalFormat.newDecimalFormat("0.########"); static attribute sb : String := StringLib.newString(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; sb := sb + StringLib.newString("0 0\n") ; execute koch(0, 0, 100, 0, n) ; sb := sb + StringLib.newString("100 0\n") ; OclFile["System.out"].print(sb) ; ); static operation koch( x0 : double, y0 : double, x1 : double, y1 : double, n : int) : void pre: true post: true activity: ( if (n = 0) then return else skip ; n := n - 1 ; var sx : double ; sx := (x0 + x0 + x1) / 3 ; var sy : double ; sy := (y0 + y0 + y1) / 3 ; var ux : double ; ux := (x0 + x1) / 2 - (y1 - y0) * (3)->sqrt() / 6 ; var uy : double ; uy := (y0 + y1) / 2 + (x1 - x0) * (3)->sqrt() / 6 ; var tx : double ; tx := (x0 + x1 + x1) / 3 ; var ty : double ; ty := (y0 + y1 + y1) / 3 ; execute koch(x0, y0, sx, sy, n) ; sb := sb + StringLib.newString(fmt.format(sx)) + StringLib.newString(' ') + StringLib.newString(fmt.format(sy)) + StringLib.newString(' ') ; execute koch(sx, sy, ux, uy, n) ; sb := sb + StringLib.newString(fmt.format(ux)) + StringLib.newString(' ') + StringLib.newString(fmt.format(uy)) + StringLib.newString(' ') ; execute koch(ux, uy, tx, ty, n) ; sb := sb + StringLib.newString(fmt.format(tx)) + StringLib.newString(' ') + StringLib.newString(fmt.format(ty)) + StringLib.newString(' ') ; execute koch(tx, ty, x1, y1, n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.lang.Math ; public class Main { void kochCurve(int n,Point p1,Point p2){ if(n!=0){ Point s=new Point((2*p1.x+p2.x)/3,(2*p1.y+p2.y)/3); Point t=new Point((p1.x+2*p2.x)/3,(p1.y+2*p2.y)/3); Point u=new Point((t.x-s.x)*Math.cos(Math.toRadians(60))-(t.y-s.y)*Math.sin(Math.toRadians(60))+s.x,(t.x-s.x)*Math.sin(Math.toRadians(60))+(t.y-s.y)*Math.cos(Math.toRadians(60))+s.y); kochCurve(n-1,p1,s); s.print(); kochCurve(n-1,s,u); u.print(); kochCurve(n-1,u,t); t.print(); kochCurve(n-1,t,p2); } } void run(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Point p1=new Point(0,0); Point p2=new Point(100,0); p1.print(); kochCurve(n,p1,p2); p2.print(); sc.close(); } public static void main(String[] args){ new Main().run(); } } class Point { double x ; double y ; Point(double x,double y){ this.x=x ; this.y=y ; } void print(){ System.out.printf("%.8f %.8f\n",x,y); } } ------------------------------------------------------------ OCL File: --------- class Main { operation kochCurve( n : int, p1 : Point, p2 : Point) : void pre: true post: true activity: ( if (n /= 0) then ( var s : Point ; s := Point.newPoint((2 * p1.x + p2.x) / 3, (2 * p1.y + p2.y) / 3) ; var t : Point ; t := Point.newPoint((p1.x + 2 * p2.x) / 3, (p1.y + 2 * p2.y) / 3) ; var u : Point ; u := Point.newPoint((t.x - s.x) * ((0.017453292519943295*(60)))->cos() - (t.y - s.y) * ((0.017453292519943295*(60)))->sin() + s.x, (t.x - s.x) * ((0.017453292519943295*(60)))->sin() + (t.y - s.y) * ((0.017453292519943295*(60)))->cos() + s.y) ; execute kochCurve(n - 1, p1, s) ; s.print() ; execute kochCurve(n - 1, s, u) ; u.print() ; execute kochCurve(n - 1, u, t) ; t.print() ; execute kochCurve(n - 1, t, p2) ; ) else skip ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var p1 : Point ; p1 := Point.newPoint(0, 0) ; var p2 : Point ; p2 := Point.newPoint(100, 0) ; p1.print() ; execute kochCurve(n, p1, p2) ; p2.print() ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } class Point { attribute x : double; attribute y : double; static operation newPoint( x : double, y : double) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : double, y : double) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation print() : void pre: true post: true activity: ( OclFile["System.out"].printf("%.8f %.8f\n", x, y) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Gfg { public static int composite_factors(int n){ int count=0 ; int i,j ; int[] a=new int[n+1]; for(i=0 ; icollect(0) ; i := 0 ; while i < n do ( ( a[i+1] := 0 ) ; i := i + 1 ) ; i := 1 ; while i <= n do ( ( if (n mod i = 0) then ( a[i+1] := i ) else skip ) ; i := i + 1 ) ; i := 2 ; while i <= n do ( ( j := 2 ; var p : int ; p := 1 ; while (j < a[i+1]) 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 ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 100 ; OclFile["System.out"].println(composite_factors(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { static int divSum(int n){ int sum=1 ; for(int i=2 ; i*i<=n ; i++)if(n % i==0)sum=sum+i+n/i ; return sum ; } static boolean areEquivalent(int num1,int num2){ return divSum(num1)==divSum(num2); } public static void main(String[] args){ int num1=559 ; int num2=703 ; if(areEquivalent(num1,num2))System.out.println("Equivalent"); else System.out.println("Not Equivalent"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation divSum( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 1 ; var i : int ; i := 2 ; while i * i <= n do ( if (n mod i = 0) then sum := sum + i + n / i ; else skip ; ; i := i + 1 ) ; return sum ); static operation areEquivalent( num1 : int, num2 : int) : boolean pre: true post: true activity: ( return divSum(num1) = divSum(num2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num1 : int ; num1 := 559 ; var num2 : int ; num2 := 703 ; if (areEquivalent(num1, num2)) then OclFile["System.out"].println("Equivalent") ; else OclFile["System.out"].println("Not Equivalent") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; public class GfG { static int findSubarraySum(int arr[],int n,int sum){ HashMapprevSum=new HashMap<>(); int res=0 ; int currsum=0 ; for(int i=0 ; ikeys()->includes(currsum - sum)) then res := res+(prevSum->at(currsum - sum)) ; else skip ; var count : int ; count := prevSum->at(currsum) ; if (count = null) then prevSum := prevSum->union(Map{currsum |-> 1}) else prevSum := prevSum->union(Map{currsum |-> count + 1}) ; ; ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,2,-2,-20,10} ; var sum : int ; sum := -10 ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findSubarraySum(arr, n, sum)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1279_NewYearGarland_math_Round79 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int rows ; rows=sc.nextInt(); int[][] a=new int[rows][3]; for(int i=0 ; itoInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,rows)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < rows do ( ( var j : int ; j := 0 ; while j < 3 do ( ( a[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; var i : int ; i := 0 ; while i < rows do ( ( if ((a[i+1][0+1] + a[i+1][1+1] < a[i+1][2+1] - 1) or (a[i+1][0+1] + a[i+1][2+1] < a[i+1][1+1] - 1) or (a[i+1][1+1] + a[i+1][2+1] < a[i+1][0+1] - 1)) then ( OclFile["System.out"].println("No") ) else ( OclFile["System.out"].println("Yes") ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int q=sc.nextInt(); while(q-->0){ int r=sc.nextInt(); int g=sc.nextInt(); int b=sc.nextInt(); if(r==g && g==b && b==r)System.out.println("YES"); else if((b>=g && b>=r &&(b<=r+g+1))||(g>=r && g>=b &&(g<=r+b+1))||(r>=g && r>=b &&(r<=g+b+1)))System.out.println("YES"); else System.out.println("NO"); } } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := sc.getCurrent()->toInteger() ; while (q > 0) do ( q := q - 1 ; skip ; ( var r : int ; r := sc.getCurrent()->toInteger() ; var g : int ; g := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (r = g & g = b & b = r) then OclFile["System.out"].println("YES") ; else if ((b >= g & b >= r & (b <= r + g + 1)) or (g >= r & g >= b & (g <= r + b + 1)) or (r >= g & r >= b & (r <= g + b + 1))) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; ) ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int arr[]=new int[3]; for(int i=0 ; i<3 ; i++){ arr[i]=sc.nextInt(); } Arrays.sort(arr); if(arr[0]+arr[1]>=(arr[2]-1))System.out.println("YES"); else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var arr : Sequence(int) ; arr := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < 3 do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; if (arr[0+1] + arr[1+1] >= (arr[2+1] - 1)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static boolean primeTable[]=new boolean[10001]; public static void main(String args[]){ Scanner in=new Scanner(System.in); makePrimeCheckTable(10000); while(in.hasNext()){ int n=in.nextInt(); int cnt=0 ; for(int i=1 ; i<=n ; i++){ if(isPrime(i)&& isPrime(n-i+1))cnt++; } System.out.println(cnt); } } private static void makePrimeCheckTable(int n){ for(int i=2 ; i<=n ; i++)primeTable[i]=true ; for(int i=2 ; i*i<=n ; i++){ if(primeTable[i]){ for(int j=i*2 ; j<=n ; j+=i){ primeTable[j]=false ; } } } } private static boolean isPrime(int n){ return primeTable[n]; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute primeTable : boolean := Integer.subrange(1,10001)->collect(false); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; execute makePrimeCheckTable(10000) ; while (in.hasNext()) do ( var n : int ; n := in.getCurrent()->toInteger() ; var cnt : int ; cnt := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (isPrime(i) & isPrime(n - i + 1)) then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ) ); static operation makePrimeCheckTable( n : int) : void pre: true post: true activity: ( var i : int ; i := 2 ; while i <= n do ( primeTable[i+1] := true ; ; i := i + 1 ) ; var i : int ; i := 2 ; while i * i <= n do ( ( if (primeTable[i+1]) then ( var j : int ; j := i * 2 ; while j <= n do ( ( primeTable[j+1] := false ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ); static operation isPrime( n : int) : boolean pre: true post: true activity: ( return primeTable[n+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int CntcontSubs(int a[],int n){ int c=0,d=0,i,sum=1,j ; for(i=0 ; isize() ; OclFile["System.out"].print(CntcontSubs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n ; int i,count ; for(; sc.hasNextInt(); ){ n=sc.nextInt(); count=0 ; for(i=1 ; i<=n ; i++)if(isprime(i)&& isprime(n+1-i))count++; System.out.println(count); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } private static boolean isprime(int p){ int i ; if(p==1)return false ; for(i=2 ; i*i<=p ; i++)if(p % i==0)return false ; return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var n : int ; var i : int ; var count : int ; while sc.hasNextInt() do ( ( n := sc.nextInt() ; count := 0 ; i := 1 ; while i <= n do ( if (isprime(i) & isprime(n + 1 - i)) then count := count + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(count) ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); static operation isprime( p : int) : boolean pre: true post: true activity: ( var i : int ; if (p = 1) then return false else skip ; i := 2 ; while i * i <= p do ( if (p mod i = 0) then return false else skip ; ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; while((line=br.readLine())!=null && ! line.isEmpty()){ int N=parseInt(line); boolean[] primes=primeB(N); int count=0 ; for(int i=1,j=N ; i<=N ; i++,j--){ if(primes[i] && primes[j])count++; } System.out.println(count); } } static boolean[] primeB(int n){ boolean[] ret=new boolean[n+1]; int _n=(int)Math.sqrt(ret.length); Arrays.fill(ret,2,ret.length,true); for(int i=2 ; i<=_n ; i++){ if(ret[i]){ for(int j=i+i ; jisEmpty())) do ( skip ; ( var N : int ; N := parseInt(line) ; var primes : Sequence(boolean) ; primes := primeB(N) ; var count : int ; count := 0 ; var i : int ; i := 1 ; var j : int ; j := N ; while i <= N do ( ( if (primes[i+1] & primes[j+1]) then count := count + 1 ; else skip ) ; i := i + 1 ; j := j - 1 ) ; OclFile["System.out"].println(count) ; ) ; line := br.readLine() ; ) ); static operation primeB( n : int) : Sequence(boolean) pre: true post: true activity: ( var ret : Sequence(boolean) ; ret := Integer.subrange(1,n + 1)->collect(false) ; var _n : int ; _n := (ret->size())->sqrt()->oclAsType(int) ; ret := ret->collect(true) ; var i : int ; i := 2 ; while i <= _n do ( ( if (ret[i+1]) then ( var j : int ; j := i + i ; while j < ret->size() do ( ( if (ret[j+1]) then ret[j+1] := false ; else skip ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; public class Main { Scanner sc=new Scanner(System.in); boolean dp[]; Main(){ dp=new boolean[10001]; Arrays.fill(dp,true); dp[0]=false ; dp[1]=false ; for(int i=2 ; i<100 ; i++){ if(dp[i]){ for(int j=i+i ; j<10001 ; j=j+i){ dp[j]=false ; } } } } void run(){ for(; sc.hasNextInt(); ){ int n=sc.nextInt(); int ans=0 ; for(int i=1 ; icollect(false) ; dp := dp->collect(true) ; dp[0+1] := false ; dp[1+1] := false ; var i : int ; i := 2 ; while i < 100 do ( ( if (dp[i+1]) then ( var j : int ; j := i + i ; while j < 10001 do ( ( dp[j+1] := false ) ; j := j + i ) ) else skip ) ; i := i + 1 ) ; ); operation run() : void pre: true post: true activity: ( while sc.hasNextInt() do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i < n do ( ( if (dp[i+1]) then ( if (dp[n - i + 1+1]) then ( ans := ans + 1 ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static HashSeths=new HashSet<>(); public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ int count=0 ; int n=in.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := i + 1 ; b[i+1] := n - i ) ; i := i + 1 ) ; execute sieveOfEratosthenes(n) ; var i : int ; i := 0 ; while i < n do ( if (hs->includes(a[i+1]) & hs->includes(b[i+1])) then count := count + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) ); static operation sieveOfEratosthenes( n : int) : void pre: true post: true activity: ( var prime : Sequence(long) ; prime := Integer.subrange(1,n + 1)->collect(0) ; var p : int ; p := 2 ; while p * p <= n do ( if (prime[p+1] = 0) then var i : int ; i := p * 2 ; while i <= n do ( prime[i+1] := 1 ; ; i := i+(p) ) ; else skip ; ; p := p + 1 ) ; var i : int ; i := 2 ; while i <= n do ( if (prime[i+1] = 0) then hs := hs->including(i) ; else skip ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int findY(int x){ if(x>2)return x-2 ; return x+2 ; } public static void main(String[] args){ int x=5 ; System.out.println(findY(x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findY( x : int) : int pre: true post: true activity: ( if (x > 2) then return x - 2 else skip ; return x + 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 5 ; OclFile["System.out"].println(findY(x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int M=30000 ; while(true){ int n=sc.nextInt(); if(n==0)break ; Setset=new HashSet(); int[][] p=new int[n][2]; for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; var set : Set(int) ; set := Set{} ; var p : Sequence(Sequence(int)) ; p := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 2 do ( p[i+1][j+1] := sc.getCurrent()->toInteger() + 10000 ; ; j := j + 1 ) ; set := set->including(p[i+1][1+1] * M + p[i+1][0+1]) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var dx : int ; dx := p[j+1][0+1] - p[i+1][0+1] ; var dy : int ; dy := p[j+1][1+1] - p[i+1][1+1] ; if (set->includes((p[i+1][1+1] + dx) * M + p[i+1][0+1] - dy) & set->includes((p[j+1][1+1] + dx) * M + p[j+1][0+1] - dy) or set->includes((p[i+1][1+1] - dx) * M + p[i+1][0+1] + dy) & set->includes((p[j+1][1+1] - dx) * M + p[j+1][0+1] + dy)) then ( max := Set{max, dx * dx + dy * dy}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); for(; ; ){ int n=in.nextInt(); if(n==0)return ; Point p[]=new Point[n]; boolean exist[][]=new boolean[5001][5001]; int max=0 ; for(int i=0 ; i=0 && y2+x2-x1>=0 && x1+y1-y2>=0 && y1+x2-x1>=0)if(x2-y2+y1<=5000 && y2+x2-x1<=5000 && x1+y1-y2<=5000 && y1+x2-x1<=5000)if(exist[x2-y2+y1][y2+x2-x1] && exist[x1+y1-y2][y1+x2-x1])max=Math.max(max,(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } System.out.println(max); } } static public void debug(Object...o){ System.err.println(Arrays.deepToString(o)); } } class Point { int x ; int y ; Point(int x,int y){ this.x=x ; this.y=y ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var n : int ; n := in.getCurrent()->toInteger() ; if (n = 0) then return else skip ; var p : Sequence(Point) ; p := Integer.subrange(1,n)->collect(null) ; var exist : Sequence(Sequence(boolean)) ; exist := Integer.subrange(1,5001)->collect(Integer.subrange(1,5001)->collect(false)) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; p[i+1] := Point.newPoint(x, y) ; exist[x+1][y+1] := true ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < n do ( ( if (i = j) then continue else skip ; var x1 : int ; x1 := p[i+1].x ; var y1 : int ; y1 := p[i+1].y ; var x2 : int ; x2 := p[j+1].x ; var y2 : int ; y2 := p[j+1].y ; if (x2 - y2 + y1 >= 0 & y2 + x2 - x1 >= 0 & x1 + y1 - y2 >= 0 & y1 + x2 - x1 >= 0) then if (x2 - y2 + y1 <= 5000 & y2 + x2 - x1 <= 5000 & x1 + y1 - y2 <= 5000 & y1 + x2 - x1 <= 5000) then if (exist[x2 - y2 + y1+1][y2 + x2 - x1+1] & exist[x1 + y1 - y2+1][y1 + x2 - x1+1]) then max := Set{max, (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)}->max() ; else skip ; else skip ; else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ) ); static operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((o + "")) ); } class Point { attribute x : int; attribute y : int; static operation newPoint( x : int, y : int) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.HashSet ; import java.util.PriorityQueue ; import java.util.Scanner ; import java.util.Set ; public class Main { public static final int MAX=5000 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); boolean[][] is_point=new boolean[MAX+1][MAX+1]; int[] x_pos=new int[3001]; int[] y_pos=new int[3001]; while(true){ final int n=sc.nextInt(); if(n==0){ break ; } for(int i=0 ; i<=MAX ; i++){ Arrays.fill(is_point[i],false); } for(int i=0 ; iMAX || pt_1_y<0 || pt_1_y>MAX){ continue ; } else if(! is_point[pt_1_y][pt_1_x]){ continue ; } int pt_2_x=pt_1_x+diff_x ; int pt_2_y=pt_1_y+diff_y ; if(pt_2_x<0 || pt_2_x>MAX || pt_2_y<0 || pt_2_y>MAX){ continue ; } else if(! is_point[pt_2_y][pt_2_x]){ continue ; } max_size=Math.max(max_size,diff_x*diff_x+diff_y*diff_y); } } System.out.println(max_size); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MAX : int := 5000; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var is_point : Sequence(Sequence(boolean)) ; is_point := Integer.subrange(1,MAX + 1)->collect(Integer.subrange(1,MAX + 1)->collect(false)) ; var x_pos : Sequence(int) ; x_pos := Integer.subrange(1,3001)->collect(0) ; var y_pos : Sequence(int) ; y_pos := Integer.subrange(1,3001)->collect(0) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then ( break ) else skip ; var i : int ; i := 0 ; while i <= MAX do ( ( is_point[i+1] := is_point[i+1]->collect(false) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; is_point[y+1][x+1] := true ; x_pos[i+1] := x ; y_pos[i+1] := y ; ) ; i := i + 1 ) ; var max_size : int ; max_size := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x > MAX or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y > MAX) then ( continue ) else if (not(is_point[pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y+1][pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ;_x < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x > MAX or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y > MAX) then ( continue ) else if (not(is_point[pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y+1][pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ;_x > MAX or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x > MAX or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y > MAX) then ( continue ) else if (not(is_point[pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y+1][pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ;_y < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x > MAX or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y > MAX) then ( continue ) else if (not(is_point[pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y+1][pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ;_y > MAX) then ( continue ) else if (not(is_point[pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x > MAX or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y > MAX) then ( continue ) else if (not(is_point[pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y+1][pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ;_y+1][pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x > MAX or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y < 0 or pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y > MAX) then ( continue ) else if (not(is_point[pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _y+1][pt var j : int ; j := i + 1 ; while j < n do ( ( var x1 : int ; x1 := x_pos[i+1] ; var y1 : int ; y1 := y_pos[i+1] ; var x2 : int ; x2 := x_pos[j+1] ; var y2 : int ; y2 := y_pos[j+1] ; var diff_x : int ; diff_x := x2 - x1 ; var diff_y : int ; diff_y := y2 - y1 ; var pt var ptint_x : int ; ptint_x := x1 + diff_y_x : int ; pt var ptint_x : int ; ptint_x := x1 + diff_y_x := x1 + diff_y ; var pt var ptint_y : int ; ptint_y := y1 - diff_x_y : int ; pt var ptint_y : int ; ptint_y := y1 - diff_x_y := y1 - diff_x ; if (pt_1_x < 0 or pt_1_x > MAX or pt_1_y < 0 or pt_1_y > MAX) then ( continue ) else if (not(is_point[pt_1_y+1][pt_1_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ; _x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ;_x+1])) then ( continue ) else skip ; ; var ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x : int ; ptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x := ptptptptpt var ptptint_x + diff_x_x : int ; ptptint_x + diff_x_x := ptptptptptint_x + diff_x_x_x + diff_x_x_x + diff_x_x + diff_x_x_x + diff_x_x_x + diff_x ; var ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y : int ; ptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y := ptptptptpt var ptptint_y + diff_y_y : int ; ptptint_y + diff_y_y := ptptptptptint_y + diff_y_y_y + diff_y_y_y + diff_y_y + diff_y_y_y + diff_y_y_y + diff_y ; if (pt0_x < 0 or ptMAX_x > MAX or pt0_y < 0 or ptMAX_y > MAX) then ( continue ) else if (not(is_point[ptpt( continue )_x_y+1][pt( continue )_x+1])) then ( continue ) else skip ; ; max_size := Set{max_size, diff_x * diff_x + diff_y * diff_y}->max() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max_size) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0){ break ; } int[] x=new int[n]; int[] y=new int[n]; boolean[][] p=new boolean[5001][5001]; for(int i=0 ; i=0 && x<=5000 && y>=0 && y<=5000){ return p[x][y]; } else { return false ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then ( break ) else skip ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,n)->collect(0) ; var p : Sequence(Sequence(boolean)) ; p := Integer.subrange(1,5001)->collect(Integer.subrange(1,5001)->collect(false)) ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; x[i+1] := a ; y[i+1] := b ; p[a+1][b+1] := true ; ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var vx : int ; vx := x[j+1] - x[i+1] ; var vy : int ; vy := y[j+1] - y[i+1] ; var dist : int ; dist := vx * vx + vy * vy ; if (dist < ans) then ( continue ) else skip ; if ((check(p, x[i+1] + vy, y[i+1] - vx) & check(p, x[j+1] + vy, y[j+1] - vx)) or (check(p, x[i+1] - vy, y[i+1] + vx) & check(p, x[j+1] - vy, y[j+1] + vx))) then ( ans := dist ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); static operation check( p : Sequence(Sequence(boolean)), x : int, y : int) : boolean pre: true post: true activity: ( if (x >= 0 & x <= 5000 & y >= 0 & y <= 5000) then ( return p[x+1][y+1] ) else ( return false ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0)break ; int[] x=new int[n]; int[] y=new int[n]; boolean[][] map=new boolean[5001][5001]; for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,n)->collect(0) ; var map : Sequence(Sequence(boolean)) ; map := Integer.subrange(1,5001)->collect(Integer.subrange(1,5001)->collect(false)) ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := sc.getCurrent()->toInteger() ; y[i+1] := sc.getCurrent()->toInteger() ; map[y[i+1]+1][x[i+1]+1] := true ) ; i := i + 1 ) ; var max : int ; max := 0 ; var p : int ; var q : int ; var a : int ; var b : int ; var c : int ; var d : int ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( p := x[i+1] - x[j+1] ; q := y[i+1] - y[j+1] ; a := y[i+1] + p ; b := x[i+1] - q ; c := y[j+1] + p ; d := x[j+1] - q ; var k : int ; k := 0 ; while k < 2 do ( ( if (0 <= a & a <= 5000 & 0 <= b & b <= 5000 & 0 <= c & c <= 5000 & 0 <= d & d <= 5000) then ( if (map[a+1][b+1] = true & map[c+1][d+1] = true) then ( max := Set{max, p * p + q * q}->max() ; break ) else skip ) else skip ; a := a-(2 * p) ; b := b+(2 * q) ; c := c-(2 * p) ; d := d+(2 * q) ; ) ; k := k + 1 ) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class LychrelNumberTest { private static int MAX_ITERATIONS=20 ; private static boolean isLychrel(long number){ for(int i=0 ; i0){ long remainder=number % 10 ; reverse=(reverse*10)+remainder ; number=number/10 ; } return reverse ; } public static void main(String[] args){ long number=295 ; System.out.println(number+" is lychrel? "+isLychrel(number)); } } ------------------------------------------------------------ OCL File: --------- class LychrelNumberTest { static attribute MAX_ITERATIONS : int := 20; static operation isLychrel( number : long) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < MAX_ITERATIONS do ( ( number := number + reverse(number) ; if (isPalindrome(number)) then return false else skip ) ; i := i + 1 ) ; return true ); static operation isPalindrome( number : long) : boolean pre: true post: true activity: ( return number = reverse(number) ); static operation reverse( number : long) : long pre: true post: true activity: ( var reverse : long ; reverse := 0 ; while (number > 0) do ( var remainder : long ; remainder := number mod 10 ; reverse := (reverse * 10) + remainder ; number := number / 10 ) ; return reverse ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var number : long ; number := 295 ; OclFile["System.out"].println(number + " is lychrel? " + isLychrel(number)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printDiamond(int n){ int space=n-1 ; for(int i=0 ; i0 ; i--){ for(int j=0 ; j 0 do ( ( var j : int ; j := 0 ; while j < space do ( OclFile["System.out"].print(" ") ; ; j := j + 1 ) ; var j : int ; j := 0 ; while j < i do ( OclFile["System.out"].print("*") ; ; j := j + 1 ) ; OclFile["System.out"].print("\n") ; space := space + 1 ) ; i := i - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute printDiamond(5) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class HelloWorld { public static void main(String[] args){ Scanner s=new Scanner(System.in); String str=s.nextLine(); int max=0 ; boolean containsDiff=false ; for(int i=0 ; i+1size() do ( ( if (str->at(i+1) /= str->at(i + 1+1)) then ( containsDiff := true ; break ) else skip ) ; i := i + 1 ) ; if (not(containsDiff)) then ( OclFile["System.out"].println(max) ; return ) else skip ; var start : int ; start := 0 ; var end : int ; end := str->size() - 1 ; var isPali : boolean ; isPali := true ; while (start <= end) do ( if (str->at(start+1) /= str->at(end+1)) then ( isPali := false ; break ) else skip ; start := start + 1 ; end := end - 1 ) ; OclFile["System.out"].println(if isPali then str->size() - 1 else str->size() endif) ; ); static operation isPalindrome( str : String) : boolean pre: true post: true activity: ( var start : int ; start := 0 ; var end : int ; end := str->size() - 1 ; while (start <= end) do ( if (str->at(start+1) /= str->at(end+1)) then return false else skip ; start := start+(1) ; end := end - 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int minCost(int[][] graph,int n){ int cost1=0,cost2=0 ; boolean[] start=new boolean[n+1]; boolean[] end=new boolean[n+1]; for(int i=0 ; icollect(false) ; var end : Sequence(boolean) ; end := Integer.subrange(1,n + 1)->collect(false) ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := graph[i+1][0+1] ; var b : int ; b := graph[i+1][1+1] ; var c : int ; c := 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 ) ) ; i := i + 1 ) ; return Set{cost1, cost2}->min() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var graph : Sequence(Sequence(int)) ; graph := Sequence{Sequence{1,2,7},Sequence{5,1,8},Sequence{5,4,5},Sequence{3,4,1},Sequence{3,2,10}} ; var ans : int ; ans := minCost(graph, n) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static StreamTokenizer in ; static int next()throws Exception { in.nextToken(); return(int)in.nval ; } static PrintWriter out ; static String NAME="a" ; public static void main(String[] args)throws Exception { out=new PrintWriter(new File(NAME+".out")); in=new StreamTokenizer(new BufferedReader(new FileReader(new File(NAME+".in")))); int tests=next(); for(int test=1 ; test<=tests ; test++){ int x=next(); int s=next(); int r=next(); double t=next(); int n=next(); int m=101 ; int[] l=new int[m]; l[0]=x ; for(int i=0 ; ioclAsType(int) ); static attribute out : OclFile; static attribute NAME : String := "a"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( out := OclFile.newOclFile_Write(OclFile(NAME + ".out")) ; in := StreamTokenizer.newStreamTokenizer(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile(NAME + ".in")))) ; var tests : int ; tests := next() ; var test : int ; test := 1 ; while test <= tests do ( ( var x : int ; x := next() ; var s : int ; s := next() ; var r : int ; r := next() ; var t : double ; t := next() ; var n : int ; n := next() ; var m : int ; m := 101 ; var l : Sequence(int) ; l := Integer.subrange(1,m)->collect(0) ; l[0+1] := x ; var i : int ; i := 0 ; while i < n do ( ( var b : int ; b := next() ; var e : int ; e := next() ; l[next()+1] := l[next()+1]+(e - b) ; l[0+1] := l[0+1]-(e - b) ) ; i := i + 1 ) ; var answ : double ; answ := 0 ; var i : int ; i := 0 ; while i < m do ( ( var tt : double ; tt := Set{t, l[i+1]->oclAsType(double) / (i + r)}->min() ; t := t-(tt) ; answ := answ-(tt * (r - s) / (i + s)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( answ := answ+(l[i+1]->oclAsType(double) / (i + s)) ; ; i := i + 1 ) ; skip ; ) ; test := test + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int MOD=1000000007 ; static int modFact(int n,int m){ int result=1 ; for(int i=1 ; i<=m ; i++)result=(result*i)% MOD ; return result ; } public static void main(String[] args){ int n=3,m=2 ; System.out.println(modFact(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MOD : int := 1000000007; static operation modFact( n : int, m : int) : int pre: true post: true activity: ( var result : int ; result := 1 ; var i : int ; i := 1 ; while i <= m do ( result := (result * i) mod MOD ; ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; var m : int ; m := 2 ; OclFile["System.out"].println(modFact(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class A { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int zz=1 ; zz<=T ; zz++){ int X=in.nextInt(); int S=in.nextInt(); int R=in.nextInt(); int t=in.nextInt(); int N=in.nextInt(); int[] length=new int[1000]; int total=X ; for(int i=0 ; itoInteger() ; var zz : int ; zz := 1 ; while zz <= T do ( ( var X : int ; X := in.getCurrent()->toInteger() ; var S : int ; S := in.getCurrent()->toInteger() ; var R : int ; R := in.getCurrent()->toInteger() ; var t : int ; t := in.getCurrent()->toInteger() ; var N : int ; N := in.getCurrent()->toInteger() ; var length : Sequence(int) ; length := Integer.subrange(1,1000)->collect(0) ; var total : int ; total := X ; var i : int ; i := 0 ; while i < N do ( ( var begin : int ; begin := in.getCurrent()->toInteger() ; var end : int ; end := in.getCurrent()->toInteger() ; var speed : int ; speed := in.getCurrent()->toInteger() ; length[speed + S+1] := length[speed + S+1]+(end - begin) ; total := total-(end - begin) ; ) ; i := i + 1 ) ; length[S+1] := length[S+1]+(total) ; var left : double ; left := t ; var ans : double ; ans := 0 ; var i : int ; i := 0 ; while i < length->size() do ( ( var v : double ; v := i ; var nv : double ; nv := v + (R - S) ; var len : double ; len := length[i+1] ; if (len / nv <= left) then ( left := left-(len / nv) ; ans := ans+(len / nv) ) else ( ans := ans+((len - (R - S) * left) / v) ; left := 0 ) ) ; i := i + 1 ) ; OclFile["System.out"].format("Case #%d: %.09f\n", zz, ans) ; ) ; zz := zz + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { class Road implements Comparable{ int add ; int len ; public Road(int len,int add){ this.len=len ; this.add=add ; } public int compareTo(Road other){ return this.add-other.add ; } } public void go()throws Exception { Scanner sc=new Scanner(new FileReader("input.txt")); PrintWriter pw=new PrintWriter(new FileWriter("output.txt")); int caseCnt=sc.nextInt(); for(int caseNum=1 ; caseNum<=caseCnt ; caseNum++){ int X=sc.nextInt(); int S=sc.nextInt(); int R=sc.nextInt(); double t=sc.nextInt(); int N=sc.nextInt(); Road[] r=new Road[N+1]; for(int i=0 ; i { attribute add : int; attribute len : int; static operation newRoad( len : int, add : int) : Road pre: true post: true activity: ( var self : Road ; self := createRoad(); self.initialise(len, add); return self ); operation initialise( len : int, add : int) : void pre: true post: true activity: ( self.len := len ; self.add := add ); operation compareTo( other : Road) : int pre: true post: true activity: ( return self.add - other.add ); } operation go() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) ; var caseCnt : int ; caseCnt := sc.getCurrent()->toInteger() ; var caseNum : int ; caseNum := 1 ; while caseNum <= caseCnt do ( ( var X : int ; X := sc.getCurrent()->toInteger() ; var S : int ; S := sc.getCurrent()->toInteger() ; var R : int ; R := sc.getCurrent()->toInteger() ; var t : double ; t := sc.getCurrent()->toInteger() ; var N : int ; N := sc.getCurrent()->toInteger() ; var r : Sequence(Road) ; r := Integer.subrange(1,N + 1)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( var B : int ; B := sc.getCurrent()->toInteger() ; var E : int ; E := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; r[i+1] := Road.newRoad(E - B, w) ; X := X-(r[i+1].len) ; ) ; i := i + 1 ) ; r[N+1] := Road.newRoad(X, 0) ; r := r->sort() ; var res : double ; res := 0.0 ; var i : int ; i := 0 ; while i < r->size() do ( ( var need : double ; need := r[i+1].len / (R + r[i+1].add)->oclAsType(double) ; if (need < t) then ( t := t-(need) ; res := res+(need) ) else ( var dist : double ; dist := r[i+1].len - (R + r[i+1].add) * t ; res := res+(t) ; t := 0 ; res := res+(dist / (S + r[i+1].add)->oclAsType(double)) ) ) ; i := i + 1 ) ; skip ; ) ; caseNum := caseNum + 1 ) ; skip ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Solution.newSolution()).go() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; import java.text.*; public class a { private static class W implements Comparable{ public int l ; public int w ; public W(int l,int w){ this.l=l ; this.w=w ; } public int compareTo(W o){ return w-o.w ; } } public static void main(String[] args){ Scanner sc=new Scanner(new BufferedInputStream(System.in)); int T=sc.nextInt(); for(int c=1 ; c<=T ; ++c){ int x=sc.nextInt(); double s=sc.nextInt(); double r=sc.nextInt(); int t=sc.nextInt(); int n=sc.nextInt(); W[] ws=new W[n+1]; int sum=0 ; for(int i=0 ; i0){ double tt=w.l/(w.w+r); if(tt { attribute l : int; attribute w : int; static operation newW( l : int, w : int) : W pre: true post: true activity: ( var self : W ; self := createW(); self.initialise(l, w); return self ); operation initialise( l : int, w : int) : void pre: true post: true activity: ( self.l := l ; self.w := w ); operation compareTo( o : W) : int pre: true post: true activity: ( return w - o.w ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var T : int ; T := sc.getCurrent()->toInteger() ; var c : int ; c := 1 ; while c <= T do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var s : double ; s := sc.getCurrent()->toInteger() ; var r : double ; r := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var ws : Sequence(W) ; ws := Integer.subrange(1,n + 1)->collect(null) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var b : int ; b := sc.getCurrent()->toInteger() ; var e : int ; e := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; ws[i+1] := W.newW(e - b, w) ; sum := sum+(e - b) ; ) ; i := i + 1 ) ; ws[n+1] := W.newW(x - sum, 0) ; ws := ws->sort() ; var time : double ; time := 0 ; var remaining_running : double ; remaining_running := t ; var i : int ; i := 0 ; while i <= n do ( ( var w : W ; w := ws[i+1] ; if (remaining_running > 0) then ( var tt : double ; tt := w.l / (w.w + r) ; if (tt < remaining_running) then ( remaining_running := remaining_running-(tt) ; time := time+(tt) ) else ( time := time+(remaining_running) ; time := time+((w.l - (w.w + r) * remaining_running) / (w.w + s)) ; remaining_running := 0 ) ) else ( time := time+(w.l / (w.w + s)) ) ) ; i := i + 1 ) ; OclFile["System.out"].format("Case #%d: %.6f%n", c, time) ; ) ; c := c + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class GeeksforGeeks { public static void StarPattern(int height){ for(int i=0 ; ii ; j--){ System.out.print("*"); } boolean printChar=false ; for(int j=0 ; j<((i*2)+1); j++){ if(printChar){ System.out.print("*"); } else { System.out.print(i+1); } printChar=! printChar ; } for(int j=height-1 ; j>i ; j--){ System.out.print("*"); } System.out.println(); } } public static void main(String args[]){ int height=7 ; StarPattern(height); } } ------------------------------------------------------------ OCL File: --------- class GeeksforGeeks { static operation StarPattern( height : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < height do ( ( var j : int ; j := height - 1 ; while j > i do ( ( OclFile["System.out"].print("*") ) ; j := j - 1 ) ; var printChar : boolean ; printChar := false ; var j : int ; j := 0 ; while j < ((i * 2) + 1) do ( ( if (printChar) then ( OclFile["System.out"].print("*") ) else ( OclFile["System.out"].print(i + 1) ) ; printChar := not(printChar) ) ; j := j + 1 ) ; var j : int ; j := height - 1 ; while j > i do ( ( OclFile["System.out"].print("*") ) ; j := j - 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var height : int ; height := 7 ; execute StarPattern(height) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isPresent(int arr[],int low,int high,int value){ while(low<=high){ int mid=(low+high)/2 ; if(arr[mid]==value)return true ; else if(arr[mid]>value)high=mid-1 ; else low=mid+1 ; } return false ; } static int countPairs(int arr1[],int arr2[],int m,int n,int x){ int count=0 ; for(int i=0 ; isize() do ( ( var j : int ; j := i ; while j <= str->size() do ( ( if (not(isPalindrome(str.subrange(i+1,j)))) then ( max := Set{max, j - i}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); static operation isPalindrome( str : String) : boolean pre: true post: true activity: ( var start : int ; start := 0 ; var end : int ; end := str->size() - 1 ; while (start <= end) do ( if (str->at(start+1) /= str->at(end+1)) then return false else skip ; start := start+(1) ; end := end - 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int size=(1<active=new ArrayList<>(); active.add(S[size-1]); spawned[size-1]=true ; for(int i=0 ; iactivated=new ArrayList<>(); int next=size-1 ; for(int slime : active){ while(next>=0 &&(S[next]>=slime || spawned[next])){ next--; } if(next<0){ System.out.println("No"); return ; } spawned[next]=true ; activated.add(S[next]); } active.addAll(activated); } System.out.println("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var size : int ; size := ((1*(2->pow(N)))->oclAsType(long)) ; var S : Sequence(int) ; S := Integer.subrange(1,size)->collect(0) ; var spawned : Sequence(boolean) ; spawned := Integer.subrange(1,size)->collect(false) ; spawned[size - 1+1] := true ; var i : int ; i := 0 ; while i < size do ( S[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; S := S->sort() ; var active : Sequence(int) ; active := Sequence{} ; active := active->including(S[size - 1+1]) ; spawned[size - 1+1] := true ; var i : int ; i := 0 ; while i < N do ( ( active := active.sort(reverseOrder()) ; var activated : Sequence(int) ; activated := Sequence{} ; var next : int ; next := size - 1 ; for (slime : active) do ( ( while (next >= 0 & (S[next+1] >= slime or spawned[next+1])) do ( next := next - 1 ) ; if (next < 0) then ( OclFile["System.out"].println("No") ; return ) else skip ; spawned[next+1] := true ; activated := activated->including(S[next+1]) ) ) ; active := active->union(activated) ; ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner a=new Scanner(System.in); int n=a.nextInt(); int A[]=new int[n]; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := a.getCurrent()->toInteger() ) ; i := i + 1 ) ; var minj : int ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i <= n - 2 do ( ( minj := i ; var c : int ; c := 0 ; var j : int ; j := i + 1 ; while j <= n - 1 do ( ( if (A[j+1] < A[minj+1]) then ( minj := j ; c := 1 ) else skip ) ; j := j + 1 ) ; if (c = 1) then ( var x : int ; x := A[i+1] ; A[i+1] := A[minj+1] ; A[minj+1] := x ; count := count + 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(A[i+1]) ; if (i < n - 1) then ( OclFile["System.out"].print(" ") ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println() ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static final int maximum=1000 ; static int lcs(String X,String Y,int m,int n,int dp[][]){ if(m==0 || n==0){ return 0 ; } if(dp[m-1][n-1]!=-1){ return dp[m-1][n-1]; } if(X.charAt(m-1)==Y.charAt(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]=Math.max(lcs(X,Y,m,n-1,dp),lcs(X,Y,m-1,n,dp)); return dp[m-1][n-1]; } } public static void main(String[] args){ String X="AGGTAB" ; String Y="GXTXAYB" ; int m=X.length(); int n=Y.length(); int dp[][]=new int[m][maximum]; for(int[] row : dp){ Arrays.fill(row,-1); } System.out.println("Length of LCS: "+lcs(X,Y,m,n,dp)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute maximum : int := 1000; static operation lcs( X : String, Y : String, m : int, n : int, dp : Sequence(Sequence(int))) : int 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->at(m - 1+1) = Y->at(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] ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var X : String ; X := "AGGTAB" ; var Y : String ; Y := "GXTXAYB" ; var m : int ; m := X->size() ; var n : int ; n := Y->size() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,m)->collect(Integer.subrange(1,maximum)->collect(0)) ; for (row : dp) do ( ( row := row->collect(-1) ) ) ; OclFile["System.out"].println("Length of LCS: " + lcs(X, Y, m, n, dp)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.io.*; class GFG { static int N=20 ; static int[] fact=new int[N]; static void pre(){ fact[0]=1 ; for(int i=1 ; icollect(0); static operation pre() : void pre: true post: true activity: ( fact[0+1] := 1 ; var i : int ; i := 1 ; while i < N do ( ( fact[i+1] := i * fact[i - 1+1] ) ; i := i + 1 ) ); static operation CountPermutation( a : Sequence(int), n : int) : int pre: true post: true activity: ( var ways : int ; ways := 1 ; a := a->sort() ; var size : int ; size := 1 ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] = a[i - 1+1]) then ( size := size + 1 ) else ( ways := ways*(fact[size+1]) ; size := 1 ) ) ; i := i + 1 ) ; ways := ways*(fact[size+1]) ; return ways ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,2,4,4,2,4} ; var n : int ; n := a->size() ; execute pre() ; OclFile["System.out"].println(CountPermutation(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { final int MAX=1000000 ; static int breakSum(int n){ int dp[]=new int[n+1]; dp[0]=0 ; dp[1]=1 ; for(int i=2 ; i<=n ; i++)dp[i]=Math.max(dp[i/2]+dp[i/3]+dp[i/4],i); return dp[n]; } public static void main(String[] args){ int n=24 ; System.out.println(breakSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { attribute MAX : int := 1000000; static operation breakSum( n : int) : int pre: true post: true activity: ( var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp[0+1] := 0 ; dp[1+1] := 1 ; var i : int ; i := 2 ; while i <= n do ( dp[i+1] := Set{dp[i / 2+1] + dp[i / 3+1] + dp[i / 4+1], i}->max() ; ; i := i + 1 ) ; return dp[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 24 ; OclFile["System.out"].println(breakSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long countPairs(int arr[],int n){ int countZero=0 ; int countTwo=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(countPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; line=br.readLine(); int H,W ; H=parseInt(line.substring(0,line.indexOf(' '))); W=parseInt(line.substring(line.indexOf(' ')+1)); int[][] forecast=new int[H][W]; for(int i=0 ; iindexOf(' ')-1) + "")->toInteger() ; W := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var forecast : Sequence(Sequence(int)) ; forecast := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var i : int ; i := 0 ; while i < H do ( ( line := br.readLine() ; var j : int ; j := 0 ; while j < W do ( ( if (line->at(j+1) = 'c') then ( forecast[i+1][j+1] := 0 ) else ( if (j = 0) then ( forecast[i+1][j+1] := -1 ) else ( if (forecast[i+1][j - 1+1] = -1) then ( forecast[i+1][j+1] := -1 ) else ( forecast[i+1][j+1] := forecast[i+1][j - 1+1] + 1 ) ) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( if (j = 0) then ( sb := sb + StringLib.newString(forecast[i+1][j+1]) ) else ( sb := sb + StringLib.newString(" " + forecast[i+1][j+1]) ) ) ; j := j + 1 ) ; sb := sb + StringLib.newString("\n") ) ; i := i + 1 ) ; OclFile["System.out"].print(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { int width ; int height ; void printData(int crowd[][]){ for(int i=0 ; i=0 ; k--){ if(crowd[k][i]==0 && crowd[j][i]==-1 && k= 0 do ( ( if (crowd[k+1][i+1] = 0 & crowd[j+1][i+1] = -1 & k < j) then ( crowd[j+1][i+1] := j - k ) else skip ) ; k := k - 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ); operation doIt() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; self.height := sc.getCurrent()->toInteger() ; self.width := sc.getCurrent()->toInteger() ; var c : Sequence(String) ; c := Integer.subrange(1,height)->collect(null) ; var crowd : Sequence(Sequence(int)) ; crowd := Integer.subrange(1,width)->collect(Integer.subrange(1,height)->collect(0)) ; var i : int ; i := 0 ; while i < height do ( ( c[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < height do ( ( var j : int ; j := 0 ; while j < width do ( ( if (c[i+1]->at(j+1) = 'c') then ( crowd[j+1][i+1] := 0 ) else ( crowd[j+1][i+1] := -1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; execute calcCrowd(crowd) ; execute printData(crowd) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class Main { public static int[][] Forec(int h,int w,char[][] wea){ int cnt=-1 ; int forec[][]=new int[h][w]; boolean flag ; for(int i=0 ; icollect(Integer.subrange(1,w)->collect(0)) ; var flag : boolean ; var i : int ; i := 0 ; while i < h do ( ( flag := false ; cnt := -1 ; var k : int ; k := 0 ; while k < w do ( ( if (wea[i+1][k+1] = 'c') then ( cnt := 0 ; flag := true ) else if (flag = true & wea[i+1][k+1] = '.') then cnt := cnt + 1 else if (wea[i+1][k+1] = '.') then cnt := -1 ; else skip ; ; ; forec[i+1][k+1] := cnt ) ; k := k + 1 ) ) ; i := i + 1 ) ; return forec ); operation dolt() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var str : Sequence(Sequence(String)) ; str := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var forec : Sequence(Sequence(int)) ; forec := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( str[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; forec := Forec(h, w, str) ; var i : int ; i := 0 ; while i < h do ( ( var k : int ; k := 0 ; while k < w do ( ( OclFile["System.out"].print(forec[i+1][k+1]) ; if (k + 1 /= w) then OclFile["System.out"].print(" ") ; else skip ) ; k := k + 1 ) ; OclFile["System.out"].println("") ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().dolt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; class Main { static final PrintWriter out=new PrintWriter(System.out); public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; while((line=br.readLine())!=null && ! line.isEmpty()){ StringTokenizer st=new StringTokenizer(line); int h=Integer.parseInt(st.nextToken()); int w=Integer.parseInt(st.nextToken()); int[] wf=new int[w]; for(int i=0 ; iisEmpty())) do ( skip ; ( var st : OclIterator ; st := OclIterator.newOclIterator_String(line) ; var h : int ; h := (st.next())->toInteger() ; var w : int ; w := (st.next())->toInteger() ; var wf : Sequence(int) ; wf := Integer.subrange(1,w)->collect(0) ; var i : int ; i := 0 ; while i < h do ( ( var flag : boolean ; flag := false ; var map : Sequence(String) ; map := br.readLine()->characters() ; var j : int ; j := 0 ; while j < w do ( ( if (map[j+1] = 'c') then ( wf[j+1] := 0 ; flag := true ) else ( if (not(flag)) then wf[j+1] := -1 ; else wf[j+1] := wf[j - 1+1] + 1 ; ) ; if (j = w - 1) then skip ; else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int[][] judge(int x,int y,char[][] c){ int h=x ; int w=y ; int[][] ret=new int[h][w]; for(int i=0 ; icollect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( var cloud : int ; cloud := -1 ; var k : int ; k := 0 ; while k < w do ( ( if (c[i+1][k+1] = 'c') then ( cloud := k ; ret[i+1][k+1] := 0 ) else if (cloud = -1 & c[i+1][k+1] = '.') then ( ret[i+1][k+1] := -1 ) else ( var d : int ; d := k - cloud ; ret[i+1][k+1] := d ) ; ) ; k := k + 1 ) ) ; i := i + 1 ) ; return ret ); operation doIt() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var p : int ; p := 0 ; var weather : Sequence(Sequence(String)) ; weather := Integer.subrange(1,h)->collect(Sequence{}) ; var ans : Sequence(Sequence(int)) ; ans := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( weather[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; ans := judge(h, w, weather) ; var i : int ; i := 0 ; while i < h do ( ( p := 0 ; var k : int ; k := 0 ; while k < w do ( ( if (p = w - 1) then ( OclFile["System.out"].println(ans[i+1][k+1]) ) else ( OclFile["System.out"].print(ans[i+1][k+1]) ; OclFile["System.out"].print(" ") ; p := p + 1 ) ) ; k := k + 1 ) ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { static boolean pali(String s){ for(int i=0 ; isize() do ( ( var j : int ; j := s->size() - i - 1 ; if (s->at(i+1) /= s->at(j+1)) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; if (pali(s) = false) then ( OclFile["System.out"].println(s->size()) ) else ( var sh : String ; sh := s.subrange(0+1,s->size() - 1) ; if (pali(sh) = false) then ( OclFile["System.out"].println(s->size() - 1) ) else ( OclFile["System.out"].println(0) ) ) ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void printArray(int[] A){ int n=A.length ; for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < n - 1 do ( ( OclFile["System.out"].print(A[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].print(A[n - 1+1] + "\n") ); static operation selectionSort( A : Sequence(int)) : void pre: true post: true activity: ( var minPos : int ; var swapTimes : int ; swapTimes := 0 ; var i : int ; i := 0 ; while i < A->size() do ( ( minPos := i ; var j : int ; j := i + 1 ; while j < A->size() do ( ( if (A[j+1] < A[minPos+1]) then minPos := j ; else skip ) ; j := j + 1 ) ; if (i /= minPos) then ( execute swap(A, i, minPos) ; swapTimes := swapTimes + 1 ) else skip ) ; i := i + 1 ) ; execute printArray(A) ; OclFile["System.out"].println(swapTimes) ; ); static operation swap( A : Sequence(int), a : int, b : int) : void pre: true post: true activity: ( var t : int ; t := A[a+1] ; A[a+1] := A[b+1] ; A[b+1] := t ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; execute selectionSort(A) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class B817 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); Integer[] A=new Integer[N]; for(int n=0 ; n=3){ answer=first*(long)(first-1)*(first-2)/6 ; } else { int second=first+1 ; while(second=3){ answer=(second-first)*(long)(second-first-1)/2 ; } else { int third=second+1 ; while(thirdtoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(null) ; var n : int ; n := 0 ; while n < N do ( ( A[n+1] := in.getCurrent()->toInteger() ) ; n := n + 1 ) ; A := A->sort() ; var first : int ; first := 1 ; var answer : long ; while (first < N & A[first+1] = A[0+1]->oclAsType(int)) do first := first + 1 ; ; if (first >= 3) then ( answer := first * (first - 1)->oclAsType(long) * (first - 2) / 6 ) else ( var second : int ; second := first + 1 ; while (second < N & A[second+1] = A[first+1]->oclAsType(int)) do second := second + 1 ; ; if (first = 2) then ( answer := second - first ) else ( if (second >= 3) then ( answer := (second - first) * (second - first - 1)->oclAsType(long) / 2 ) else ( var third : int ; third := second + 1 ; while (third < N & A[third+1] = A[second+1]->oclAsType(int)) do third := third + 1 ; ; answer := third - second ) ) ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; while((line=br.readLine())!=null && ! line.isEmpty()){ int w=parseInt(line); String base3="" ; while(w!=0){ int r=w % 3 ; if(r==0){ base3="0"+base3 ; w/=3 ; } else if(r==1){ base3="+"+base3 ; w/=3 ; } else if(r==2){ base3="-"+base3 ; w/=3 ; w++; } } System.out.println(base3); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var w : int ; w := parseInt(line) ; var base3 : String ; base3 := "" ; while (w /= 0) do ( var r : int ; r := w mod 3 ; if (r = 0) then ( base3 := "0" + base3 ; w := w/(3) ) else if (r = 1) then ( base3 := "+" + base3 ; w := w/(3) ) else if (r = 2) then ( base3 := "-" + base3 ; w := w/(3) ; w := w + 1 ) else skip ; ; ) ; OclFile["System.out"].println(base3) ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int w=scan.nextInt(); String ans="" ; while(w!=0){ int tmp=w % 3 ; if(tmp==0){ ans="0"+ans ; w/=3 ; } else if(tmp==1){ ans="+"+ans ; w/=3 ; } else if(tmp==2){ ans="-"+ans ; w/=3 ; w++; } } System.out.println(ans); scan.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var w : int ; w := scan.getCurrent()->toInteger() ; var ans : String ; ans := "" ; while (w /= 0) do ( var tmp : int ; tmp := w mod 3 ; if (tmp = 0) then ( ans := "0" + ans ; w := w/(3) ) else if (tmp = 1) then ( ans := "+" + ans ; w := w/(3) ) else if (tmp = 2) then ( ans := "-" + ans ; w := w/(3) ; w := w + 1 ) else skip ; ; ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),a[]=new int[15],i=0 ; while(n>0){ a[i++]=(n+1)% 3-1 ; n=(n-a[i-1])/3 ; } while(i-->0)System.out.print((a[i]==0 ? "0" : a[i]>0 ? "+" : "-")+(i==0 ? "\n" : "")); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(void) ; a := Integer.subrange(1,15)->collect(0) ; var i : int ; i := 0 ; while (n > 0) do ( a[i+1] := (n + 1) mod 3 - 1 ; i := i + 1 ; n := (n - a[i - 1+1]) / 3 ) ; while (i > 0) do ( i := i - 1 ; skip ; OclFile["System.out"].print((if a[i+1] = 0 then "0" else if a[i+1] > 0 then "+" else "-" endif endif) + (if i = 0 then "\n" else "" endif)) ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s="" ; while(n>0){ s=(n % 3==0 ? "0" : n % 3==1 ? "+" : "-")+s ; n=n % 3==2 ? n/3+1 : n/3 ; } System.out.println(s); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := "" ; while (n > 0) do ( s := (if n mod 3 = 0 then "0" else if n mod 3 = 1 then "+" else "-" endif endif) + s ; n := if n mod 3 = 2 then n / 3 + 1 else n / 3 endif ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { void solve(){ Scanner sc=new Scanner(System.in); int w=sc.nextInt(); StringBuilder res=new StringBuilder(); while(w>0){ switch(w % 3){ case 0 : res.insert(0,'0'); w/=3 ; break ; case 1 : res.insert(0,'+'); w/=3 ; break ; case 2 : res.insert(0,'-'); w=w/3+1 ; break ; } } System.out.println(res.toString()); } public static void main(String[] a){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var w : int ; w := sc.getCurrent()->toInteger() ; var res : String ; res := StringLib.newString() ; while (w > 0) do ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (w mod 3) ; if _switchval = 0 then res := res.insertAt(0+1, StringLib.newString('0')) ; w := w/(3) ; break else skip ; if _switchval = 1 then res := res.insertAt(0+1, StringLib.newString('+')) ; w := w/(3) ; break else skip ; if _switchval = 2 then res := res.insertAt(0+1, StringLib.newString('-')) ; w := w / 3 + 1 ; break else skip ; ) ) ; OclFile["System.out"].println(res+"") ; ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,Scanner in,PrintWriter out){ int T=1 ; while(T-->0){ solveOne(in,out); } } private void solveOne(Scanner in,PrintWriter out){ int N=in.nextInt(),X=in.nextInt(),T=in.nextInt(); out.println((int)(Math.ceil((double)N/X)*T)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskA ; solver := TaskA.newTaskA() ; solver.solve(1, in, out) ; skip ; ); static class TaskA { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var T : int ; T := 1 ; while (T > 0) do ( T := T - 1 ; skip ; ( execute solveOne(in, out) ) ; ) ); operation solveOne( in : OclFile, out : OclFile) : void pre: true post: true activity: ( var N : int ; N := in.getCurrent()->toInteger() ; var X : int ; X := in.getCurrent()->toInteger() ; var T : int ; T := in.getCurrent()->toInteger() ; skip ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static Scanner inp=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); public static void main(String args[]){ Main g=new Main(); g.main(); out.close(); } void main(){ int n=inp.nextInt(); int x=inp.nextInt(); int t=inp.nextInt(); System.out.println((((n+x-1))/x)*t); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute inp : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var g : Main ; g := Main.newMain() ; g.main() ; skip ); operation main() : void pre: true post: true activity: ( var n : int ; n := inp.getCurrent()->toInteger() ; var x : int ; x := inp.getCurrent()->toInteger() ; var t : int ; t := inp.getCurrent()->toInteger() ; OclFile["System.out"].println((((n + x - 1)) / x) * t) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Integer.*; import static java.lang.Long.*; import static java.lang.System.*; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { static void solve()throws Exception { int n=scanInt(),x=scanInt(),t=scanInt(); out.print(n % x!=0 ?(n/x+1)*t :(n/x)*t); } static int scanInt()throws IOException { return parseInt(scanString()); } static long scanLong()throws IOException { return parseLong(scanString()); } static String scanString()throws IOException { while(tok==null || ! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; public static void main(String[] args){ try { in=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); solve(); in.close(); out.close(); } catch(Throwable e){ e.printStackTrace(); exit(1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve() : void pre: true post: true activity: ( var n : int ; n := scanInt() ; var x : int ; x := scanInt() ; var t : int ; t := scanInt() ; out.print(if n mod x /= 0 then (n / x + 1) * t else (n / x) * t endif) ); static operation scanInt() : int pre: true post: true activity: ( return (scanString() + "")->toInteger() ); static operation scanLong() : long pre: true post: true activity: ( return parseLong(scanString()) ); static operation scanString() : String pre: true post: true activity: ( while (tok = null or not(tok.hasNext())) do ( tok := OclIterator.newOclIterator_String(in.readLine()) ) ; return tok.next() ); static attribute in : OclFile; static attribute out : OclFile; static attribute tok : OclIterator; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ; skip ; ) catch (e : OclException) do ( e.printStackTrace() ; execute exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); ATakoyaki solver=new ATakoyaki(); solver.solve(1,in,out); out.close(); } static class ATakoyaki { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(),x=in.nextInt(),t=in.nextInt(); out.println((((n+x)-1)/x)*t); } } static class InputReader { public final BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : ATakoyaki ; solver := ATakoyaki.newATakoyaki() ; solver.solve(1, in, out) ; skip ; ); static class ATakoyaki { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var x : int ; x := in.nextInt() ; var t : int ; t := in.nextInt() ; skip ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=Integer.parseInt(scanner.nextLine()); int[] a=scanIntArray(scanner); int length=a.length ; int swapCount=0 ; for(int i=0 ; ia[minIndex]){ swap(a,i,minIndex); swapCount++; } } printIntArray(a," "); System.out.println(swapCount); } private static void printIntArray(int[] array,String delimeter){ System.out.println(Arrays.stream(array).mapToObj(String :: valueOf).collect(Collectors.joining(delimeter))); } private static int[] scanIntArray(Scanner scanner){ return Arrays.stream(scanner.nextLine().split(" ",0)).mapToInt(Integer :: parseInt).toArray(); } private static void swap(int[] array,int index1,int index2){ int tmp=array[index1]; array[index1]=array[index2]; array[index2]=tmp ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (scanner.nextLine())->toInteger() ; var a : Sequence(int) ; a := scanIntArray(scanner) ; var length : int ; length := a->size() ; var swapCount : int ; swapCount := 0 ; var i : int ; i := 0 ; while i < length do ( ( var minIndex : int ; minIndex := i ; var j : int ; j := i ; while j < length do ( ( if (a[j+1] < a[minIndex+1]) then ( minIndex := j ) else skip ) ; j := j + 1 ) ; if (a[i+1] > a[minIndex+1]) then ( execute swap(a, i, minIndex) ; swapCount := swapCount + 1 ) else skip ) ; i := i + 1 ) ; execute printIntArray(a, " ") ; OclFile["System.out"].println(swapCount) ; ); static operation printIntArray( array : Sequence(int), delimeter : String) : void pre: true post: true activity: ( OclFile["System.out"].println(stream(array).mapToObj(lambda _pars : OclAny in String.newString().valueOf(_pars)).collect(Collectors.joining(delimeter))) ); static operation scanIntArray( scanner : OclFile) : Sequence(int) pre: true post: true activity: ( return stream(scanner.nextLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ); static operation swap( array : Sequence(int), index1 : int, index2 : int) : void pre: true post: true activity: ( var tmp : int ; tmp := array[index1+1] ; array[index1+1] := array[index2+1] ; array[index2+1] := tmp ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); Solution solution=new Solution(); String s=scanner.nextLine(); System.out.println(solution.run(s)); } public static class Solution { private final int[][] DP=new int[1001][1001]; { for(int[] ints : DP){ Arrays.fill(ints,-1); } } public int run(String s){ int n=s.length(); int max=-1 ; for(int i=0 ; imax){ max=j-i ; } } } } return max+1 ; } public int isPal(String s,int i,int j){ if(i>j)return 1 ; if(DP[i][j]!=-1)return DP[i][j]; if(s.charAt(i)!=s.charAt(j)){ return DP[i][j]=0 ; } return DP[i][j]=isPal(s,i+1,j-1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var solution : Solution ; solution := Solution.newSolution() ; var s : String ; s := scanner.nextLine() ; OclFile["System.out"].println(solution.run(s)) ); static class Solution { attribute DP : Sequence(Sequence(int)) := Integer.subrange(1,1001)->collect(Integer.subrange(1,1001)->collect(0)); operation initialiseInstance() pre: true post: true activity: for (ints : DP) do ( ( ints := ints->collect(-1) ) ) ; ; operation run( s : String) : int pre: true post: true activity: ( var n : int ; n := s->size() ; var max : int ; max := -1 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (isPal(s, i, j) < 1) then ( if (j - i > max) then ( max := j - i ) else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return max + 1 ); operation isPal( s : String, i : int, j : int) : int pre: true post: true activity: ( if (i > j) then return 1 else skip ; if (DP[i+1][j+1] /= -1) then return DP[i+1][j+1] else skip ; if (s->at(i+1) /= s->at(j+1)) then ( return DP[i+1][j+1] ) else skip ; return DP[i+1][j+1] ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void solve(int n,int x,int t){ int joyo=n % x ; int ans=n/x ; System.out.println((ans*t)+(joyo!=0 ? t : 0)); } public static void main(String[] args){ long start=System.currentTimeMillis(); Scanner scanner=new Scanner(System.in); try { int n=scanner.nextInt(); int x=scanner.nextInt(); int t=scanner.nextInt(); scanner.nextLine(); solve(n,x,t); } finally { scanner.close(); } long end=System.currentTimeMillis(); } private static final int[] changeArrayStringToInt(String line){ String[] strArray=line.split(" "); int[] intArray=new int[strArray.length]; for(int i=0 ; itoInteger() ; var x : int ; x := scanner.getCurrent()->toInteger() ; var t : int ; t := scanner.getCurrent()->toInteger() ; skip ; execute solve(n, x, t) ; ) finally ( skip ) var end : long ; end := OclDate.getSystemTime() ); static operation changeArrayStringToInt( line : String) : Sequence(int) pre: true post: true activity: ( var strArray : Sequence(String) ; strArray := line->split(" ") ; var intArray : Sequence(int) ; intArray := Integer.subrange(1,strArray->size())->collect(0) ; var i : int ; i := 0 ; while i < intArray->size() do ( ( intArray[i+1] := (strArray[i+1])->toInteger() ) ; i := i + 1 ) ; return intArray ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A_Crossmarket { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); for(int i=1 ; i<=test ; i++){ int n=sc.nextInt(); int m=sc.nextInt(); System.out.println(n+m+Math.min(n,m)-3+Math.min(Math.max(n,m)-1,1)); } } static void readArray(int a[]){ Scanner in=new Scanner(System.in); for(int i=0 ; ia1){ int[] arr=a1.stream().mapToInt(i->i).toArray(); return arr ; } } ------------------------------------------------------------ OCL File: --------- class A_Crossmarket { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= test do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(n + m + Set{n, m}->min() - 3 + Set{Set{n, m}->max() - 1, 1}->min()) ) ; i := i + 1 ) ); static operation readArray( a : Sequence(int)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ); static operation printArray( a : Sequence(int)) : void pre: true post: true activity: ( for (x : a) do ( ( OclFile["System.out"].print(x + " ") ) ) ); static operation listToArray( a1 : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var arr : Sequence(int) ; arr := a1->collect( _x1 | (lambda i : OclAny in i)->apply(_x1) )->asSequence() ; return arr ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.File ; import java.io.FileReader ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Solution { static PrintWriter pw ; static FastScanner s ; public static void main(String[] args)throws Exception { pw=new PrintWriter(System.out); s=new FastScanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); int m=s.nextInt(); if(n 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.nextInt() ; var m : int ; m := s.nextInt() ; if (n < m) then ( var temp : int ; temp := n ; n := m ; m := temp ) else skip ; if (n = 1 & m = 1) then skip ; else skip ; ) ; ) ; skip ; ); } class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner( s : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newFastScanner( s : String) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile(s))) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CrossMarket { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; im){ if(m!=1 && n!=1){ System.out.println((m-1)+(n-1)+m); } } else if(m>n || m==n){ if(m!=1 && n!=1){ System.out.println((m-1)+(n-1)+n); } } } } } ------------------------------------------------------------ OCL File: --------- class CrossMarket { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if (n = 1 & m = 1) then ( OclFile["System.out"].println("0") ) else if (m = 1 & n /= 1) then ( OclFile["System.out"].println(n) ) else if (m /= 1 & n = 1) then ( OclFile["System.out"].println(m) ) else if (n > m) then ( if (m /= 1 & n /= 1) then ( OclFile["System.out"].println((m - 1) + (n - 1) + m) ) else skip ) else if (m > n or m = n) then ( if (m /= 1 & n /= 1) then ( OclFile["System.out"].println((m - 1) + (n - 1) + n) ) else skip ) else skip ; ; ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1715 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var M : int ; M := in.getCurrent()->toInteger() ; var answer : int ; answer := N - 1 + M - 1 + Set{N, M}->min() - 1 + Set{1, Set{N, M}->max() - 1}->min() ; OclFile["System.out"].println(answer) ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); pw.println(solve(in.nextLong())); pw.close(); } public static int solve(long n){ long sum=(n*(n+1))/2 ; if(sum % 2==0){ return 0 ; } else { return 1 ; } } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip ; skip ); static operation solve( n : long) : int pre: true post: true activity: ( var sum : long ; sum := (n * (n + 1)) / 2 ; if (sum mod 2 = 0) then ( return 0 ) else ( return 1 ) ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long m=n*(n+1); m/=2 ; System.out.println(m % 2); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var m : long ; m := n * (n + 1) ; m := m/(2) ; OclFile["System.out"].println(m mod 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class ProblemA { static HashSetset[]; public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(br.readLine()); System.out.println((n*(n+1)/2)% 2==0 ? 0 : 1); } public static void sort(int arr[]){ ArrayListlist=new ArrayList<>(); for(int it : arr)list.add(it); Collections.sort(list); for(int i=0 ; itoInteger() ; OclFile["System.out"].println(if (n * (n + 1) / 2) mod 2 = 0 then 0 else 1 endif) ); static operation sort( arr : Sequence(int)) : void pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{} ; for (it : arr) do ( list := list->including(it) ; ) ; list := list->sort() ; var i : int ; i := 0 ; while i < list->size() do ( arr[i+1] := list->at(i+1) ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigDecimal ; import java.math.RoundingMode ; import java.util.*; public class ProblemC { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); long n=Integer.parseInt(br.readLine()); if(((n*(n+1))/2)% 2==0)System.out.println(0); else System.out.println(1); } public static void swap(int i,int j,int builder[]){ int t=builder[i]; builder[i]=builder[j]; builder[j]=t ; } } ------------------------------------------------------------ OCL File: --------- class ProblemC { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sb : String ; sb := StringLib.newString() ; var n : long ; n := (br.readLine())->toInteger() ; if (((n * (n + 1)) / 2) mod 2 = 0) then OclFile["System.out"].println(0) ; else OclFile["System.out"].println(1) ; ); static operation swap( i : int, j : int, builder : Sequence(int)) : void pre: true post: true activity: ( var t : int ; t := builder[i+1] ; builder[i+1] := builder[j+1] ; builder[j+1] := t ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void printArr(int[] arr){ String[] ss=new String[arr.length]; for(int i=0 ; isize())->collect(null) ; var i : int ; i := 0 ; while i < arr->size() do ( ( ss[i+1] := ((arr[i+1]) + "") ) ; i := i + 1 ) ; OclFile["System.out"].println(join(" ", ss)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var inputs : Sequence(int) ; inputs := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( inputs[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( var minj : int ; minj := i ; var j : int ; j := i ; while j < n do ( ( if (inputs[j+1] < inputs[minj+1]) then ( minj := j ) else skip ) ; j := j + 1 ) ; if (minj /= i) then ( var tmp : int ; tmp := inputs[minj+1] ; inputs[minj+1] := inputs[i+1] ; inputs[i+1] := tmp ; cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; execute printArr(inputs) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); pw.println(solve(in.nextLong())); pw.close(); } public static int solve(long n){ long sum=(n*(n+1))/2 ; if(sum % 2==0){ return 0 ; } else { return 1 ; } } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip ; skip ); static operation solve( n : long) : int pre: true post: true activity: ( var sum : long ; sum := (n * (n + 1)) / 2 ; if (sum mod 2 = 0) then ( return 0 ) else ( return 1 ) ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class antiPalindrome { static String word ; public static boolean checkAntiPalindrome(char[] str){ boolean flag=true ; int i=0 ; for(int j=str.length-1 ; i<=j ; j--){ if(str[i]!=str[j]){ flag=false ; } i++; } return flag ; } public static void main(String[] args){ Scanner scan=new Scanner(System.in); word=scan.nextLine(); boolean flag1=true ; char[] str=word.toCharArray(); if(checkAntiPalindrome(str)){ for(int k=0 ; k+1size() - 1 ; while i <= j do ( ( if (str[i+1] /= str[j+1]) then ( flag := false ) else skip ; i := i + 1 ) ; j := j - 1 ) ; return flag ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; word := scan.nextLine() ; var flag1 : boolean ; flag1 := true ; var str : Sequence(String) ; str := word->characters() ; if (checkAntiPalindrome(str)) then ( var k : int ; k := 0 ; while k + 1 < str->size() do ( ( if (str[k+1] /= str[k + 1+1]) then ( flag1 := false ) else skip ) ; k := k + 1 ) ; if (flag1) then ( OclFile["System.out"].println("0") ) else ( var n : int ; n := str->size() - 1 ; OclFile["System.out"].println(n) ) ) else ( OclFile["System.out"].println(str->size()) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long andOperator(long a,long b){ while(a=0 ; i--){ if(s.charAt(i)=='0')c++; if(c>=6 && s.charAt(i)=='1')return true ; } return false ; } public static void main(String[] args){ String s="100010001" ; if(checking(s))System.out.println("Possible"); else System.out.println("Not possible"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checking( s : String) : boolean pre: true post: true activity: ( var c : int ; c := 0 ; var n : int ; n := s->size() ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (s->at(i+1) = '0') then c := c + 1 ; else skip ; if (c >= 6 & s->at(i+1) = '1') then return true else skip ) ; i := i - 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "100010001" ; if (checking(s)) then OclFile["System.out"].println("Possible") ; else OclFile["System.out"].println("Not possible") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class AA { @ SuppressWarnings("resource")public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long k=sc.nextLong(); if(k==1){ System.out.print(n); return ; } int u=0 ; while(n>0){ n=n>>1 ; u++; } u--; long sum=1 ; for(int i=0 ; itoLong() ; var k : long ; k := sc.getCurrent()->toLong() ; if (k = 1) then ( OclFile["System.out"].print(n) ; return ) else skip ; var u : int ; u := 0 ; while (n > 0) do ( n := (n/(2->pow(1)))->oclAsType(long) ; u := u + 1 ) ; u := u - 1 ; var sum : long ; sum := 1 ; var i : int ; i := 0 ; while i < u do ( ( sum := (sum*(2->pow(1)))->oclAsType(long) ; sum := sum+(1) ) ; i := i + 1 ) ; OclFile["System.out"].print(sum) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication33 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long k=sc.nextLong(); if(k==1){ System.out.println(n); return ; } long res=1 ; while(res<=n){ res=res<<1 ; } System.out.println(res-1); } } ------------------------------------------------------------ OCL File: --------- class JavaApplication33 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; if (k = 1) then ( OclFile["System.out"].println(n) ; return ) else skip ; var res : long ; res := 1 ; while (res <= n) do ( res := (res*(2->pow(1)))->oclAsType(long) ) ; OclFile["System.out"].println(res - 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class MyClass { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s[]=br.readLine().split(" "); long n=Long.parseLong(s[0]); long k=Long.parseLong(s[1]); if(k==1){ System.out.println(n); return ; } long ans=1 ; while(anssplit(" ") ; var n : long ; n := (s[0+1])->toLong() ; var k : long ; k := (s[1+1])->toLong() ; if (k = 1) then ( OclFile["System.out"].println(n) ; return ) else skip ; var ans : long ; ans := 1 ; while (ans < n) do ( ans := ans * 2 + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Long n=sc.nextLong(); Long k=sc.nextLong(); if(k==1){ System.out.println(n); return ; } ArrayListal=new ArrayList<>(); Long v=1L ; while(v<=n){ al.add(v); v*=2 ; } Long pre=al.get(al.size()-1); Long ans=pre ^(pre-1); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; if (k = 1) then ( OclFile["System.out"].println(n) ; return ) else skip ; var al : Sequence(long) ; al := Sequence{} ; var v : long ; v := 1L ; while (v <= n) do ( al := al->including(v) ; v := v*(2) ) ; var pre : long ; pre := al->at(al->size() - 1+1) ; var ans : long ; ans := MathLib.bitwiseXor(pre,(pre - 1)) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int pairs(int n){ int[][] c=new int[10][10]; int tmp=1 ; for(int i=1 ; i<=n ; i++){ if(i>=tmp*10)tmp*=10 ; c[i/tmp][i % 10]++; } int ans=0 ; for(int i=1 ; i<10 ; i++)for(int j=1 ; j<10 ; j++)ans+=c[i][j]*c[j][i]; return ans ; } public static void main(String[] args){ int n=25 ; System.out.print(pairs(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation pairs( n : int) : int pre: true post: true activity: ( var c : Sequence(Sequence(int)) ; c := Integer.subrange(1,10)->collect(Integer.subrange(1,10)->collect(0)) ; var tmp : int ; tmp := 1 ; var i : int ; i := 1 ; while i <= n do ( ( if (i >= tmp * 10) then tmp := tmp*(10) ; else skip ; c[i / tmp+1][i mod 10+1] := c[i / tmp+1][i mod 10+1] + 1 ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i < 10 do ( var j : int ; j := 1 ; while j < 10 do ( ans := ans+(c[i+1][j+1] * c[j+1][i+1]) ; ; j := j + 1 ) ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 25 ; OclFile["System.out"].print(pairs(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.List ; import java.util.Map ; public final class p151 implements EulerSolution { public static void main(String[] args){ System.out.println(new p151().run()); } public String run(){ ListstartState=Arrays.asList(1); return String.format("%.6f",getExpectedSingles(startState)-2); } private Map,Double>expectedSingles=new HashMap<>(); private double getExpectedSingles(Liststate){ if(expectedSingles.containsKey(state))return expectedSingles.get(state); double result=0 ; if(! state.isEmpty()){ for(int i=0 ; inewState=new ArrayList<>(state); int sheet=state.get(i); newState.remove(i); for(int j=sheet+1 ; j<=5 ; j++)newState.add(j); Collections.sort(newState); result+=getExpectedSingles(newState); } result/=state.size(); if(state.size()==1)result++; } expectedSingles.put(state,result); return result ; } } ------------------------------------------------------------ OCL File: --------- class p151 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p151.newp151().run()) ); operation run() : String pre: true post: true activity: ( var startState : Sequence(int) ; startState := 1 ; return StringLib.format("%.6f",Sequence{getExpectedSingles(startState) - 2}) ); attribute expectedSingles : Map(Sequence(int),double) := Map{}; operation getExpectedSingles( state : Sequence(int)) : double pre: true post: true activity: ( if (expectedSingles->keys()->includes(state)) then return expectedSingles->at(state) else skip ; var result : double ; result := 0 ; if (not(state->isEmpty())) then ( var i : int ; i := 0 ; while i < state->size() do ( ( var newState : Sequence(int) ; newState := Sequence{}->union(state) ; var sheet : int ; sheet := state->at(i+1) ; newState := newState->excludingAt(i+1) ; var j : int ; j := sheet + 1 ; while j <= 5 do ( newState := newState->including(j) ; ; j := j + 1 ) ; newState := newState->sort() ; result := result+(getExpectedSingles(newState)) ; ) ; i := i + 1 ) ; result := result/(state->size()) ; if (state->size() = 1) then result := result + 1 ; else skip ) else skip ; expectedSingles := expectedSingles->union(Map{state |-> result}) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); int N ; int[] A ; int minj,key ; int count=0 ; public void input(){ N=sc.nextInt(); A=new int[N]; for(int i=0 ; itoInteger() ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ); operation selectionsort() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < N - 1 do ( ( minj := i ; var j : int ; j := i ; while j <= N - 1 do ( ( if (A[j+1] < A[minj+1]) then ( minj := j ) else skip ) ; j := j + 1 ) ; key := A[i+1] ; A[i+1] := A[minj+1] ; A[minj+1] := key ; if (i /= minj) then count := count + 1 ; else skip ; ) ; i := i + 1 ) ); operation output() : void pre: true post: true activity: ( OclFile["System.out"].print(A[0+1]) ; var i : int ; i := 1 ; while i < N do ( ( OclFile["System.out"].print(" " + A[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println("\n" + count) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : Main ; obj := Main.newMain() ; obj.input() ; obj.selectionsort() ; obj.output() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class GFG { static int getMax(int arr[],int n){ int max=Integer.MIN_VALUE ; for(int i=0 ; imax)max=arr[i]; return max ; } static int getSum(int arr[],int n){ int total=0 ; for(int i=0 ; imaxLen){ total=arr[i]; numPainters++; } } return numPainters ; } static int partition(int arr[],int n,int k){ int lo=getMax(arr,n); int hi=getSum(arr,n); while(lo max) then max := arr[i+1] ; else skip ; ; i := i + 1 ) ; return max ); static operation getSum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var total : int ; total := 0 ; var i : int ; i := 0 ; while i < n do ( total := total+(arr[i+1]) ; ; i := i + 1 ) ; return total ); static operation numberOfPainters( arr : Sequence(int), n : int, maxLen : int) : int pre: true post: true activity: ( var total : int ; total := 0 ; var numPainters : int ; numPainters := 1 ; var i : int ; i := 0 ; while i < n do ( ( total := total+(arr[i+1]) ; if (total > maxLen) then ( total := arr[i+1] ; numPainters := numPainters + 1 ) else skip ) ; i := i + 1 ) ; return numPainters ); static operation partition( arr : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( var lo : int ; lo := getMax(arr, n) ; var hi : int ; hi := getSum(arr, n) ; while (lo < hi) do ( var mid : int ; mid := lo + (hi - lo) / 2 ; var requiredPainters : int ; requiredPainters := numberOfPainters(arr, n, mid) ; if (requiredPainters <= k) then hi := mid ; else lo := mid + 1 ; ) ; return lo ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5,6,7,8,9} ; var n : int ; n := arr->size() ; var k : int ; k := 3 ; OclFile["System.out"].println(partition(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean checkForElement(int array[],int n){ int sum=0 ; for(int i=0 ; i0)return false ; sum/=2 ; int start=0 ; int end=n-1 ; while(start<=end){ int mid=start+(end-start)/2 ; if(array[mid]==sum)return true ; else if(array[mid]>sum)end=mid-1 ; else start=mid+1 ; } return false ; } public static void main(String[] args){ int array[]={ 1,2,3 }; int n=array.length ; if(checkForElement(array,n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkForElement( array : Sequence(int), n : int) : boolean pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( sum := sum+(array[i+1]) ; ; i := i + 1 ) ; if (sum mod 2 > 0) then return false else skip ; sum := sum/(2) ; var start : int ; start := 0 ; var end : int ; end := n - 1 ; while (start <= end) do ( var mid : int ; mid := start + (end - start) / 2 ; if (array[mid+1] = sum) then return true else if (array[mid+1] > sum) then end := mid - 1 else start := mid + 1 ; ; ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var array : Sequence(int) ; array := Sequence{1,2,3} ; var n : int ; n := array->size() ; if (checkForElement(array, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.security.spec.RSAOtherPrimeInfo ; import java.util.*; import java.lang.*; public class solve { static Scanner sc ; public static void main(String[] args){ sc=new Scanner(System.in); int testCases=sc.nextInt(); while(testCases>0){ justDoIt(); testCases--; } } static void justDoIt(){ int x=sc.nextInt(),y=sc.nextInt(); if(y % x!=0){ System.out.println("0 0"); return ; } System.out.println("1 "+(y/x)); } } ------------------------------------------------------------ OCL File: --------- class solve { static attribute sc : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var testCases : int ; testCases := sc.getCurrent()->toInteger() ; while (testCases > 0) do ( execute justDoIt() ; testCases := testCases - 1 ) ); static operation justDoIt() : void pre: true post: true activity: ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (y mod x /= 0) then ( OclFile["System.out"].println("0 0") ; return ) else skip ; OclFile["System.out"].println("1 " + (y / x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args){ try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int num0=Integer.parseInt(str[0]); int num1=Integer.parseInt(str[1]); int num2=Integer.parseInt(str[2]); if(num0split(" ") ; var num0 : int ; num0 := (str[0+1])->toInteger() ; var num1 : int ; num1 := (str[1+1])->toInteger() ; var num2 : int ; num2 := (str[2+1])->toInteger() ; if (num0 < num1 & num1 < num2) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ) catch (e : IOException) do ( OclFile["System.out"].println(e) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tk=new StringTokenizer(br.readLine()); int num=Integer.parseInt(tk.nextToken()); int num2=Integer.parseInt(tk.nextToken()); int num3=Integer.parseInt(tk.nextToken()); A AAA=(int a,int b,int c)->{ if(atoInteger() ; var num2 : int ; num2 := (tk.next())->toInteger() ; var num3 : int ; num3 := (tk.next())->toInteger() ; var AAA : A ; AAA := lambda a : int, b : int, c : int : OclAny in ( if (a < b & b < c) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ) ; AAA.Judgment(num, num2, num3) ; ); } interface A { operation Judgment( a : int, b : int, c : int) : void pre: true post: true; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args){ String line=new java.util.Scanner(System.in).nextLine(); String[] number=line.split(" ",0); String ans=Range(parseInt(number[0]),parseInt(number[1]),parseInt(number[2])); System.out.println(ans); } public static String Range(int x,int y,int z){ if(xsplit(" ") ; var ans : String ; ans := Range((number[0+1] + "")->toInteger(), (number[1+1] + "")->toInteger(), (number[2+1] + "")->toInteger()) ; OclFile["System.out"].println(ans) ); static operation Range( x : int, y : int, z : int) : String pre: true post: true activity: ( if (x < y & y < z) then ( return "Yes" ) else ( return "No" ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; class Main { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { StringTokenizer st=new StringTokenizer(br.readLine()); int a=Integer.parseInt(st.nextToken()); int b=Integer.parseInt(st.nextToken()); int c=Integer.parseInt(st.nextToken()); if(atoInteger() ; var b : int ; b := (st.next())->toInteger() ; var c : int ; c := (st.next())->toInteger() ; if (a < b & b < c) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); if(atoInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if (a < b) then ( if (b < c) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.HashSet ; import java.util.List ; import java.util.Set ; public class KoalaAndLights { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); Set[] toggleTimes=new HashSet[n]; for(int i=0 ; i(); } boolean[] status=new boolean[n]; char[] temp=br.readLine().toCharArray(); for(int i=0 ; i700){ break ; } toggleTimes[i] .add(b+j*a); } } int res=0 ; for(int time=0 ; time<=700 ; time++){ int countOn=0 ; for(int i=0 ; itoInteger() ; var toggleTimes : Sequence(Set(int)) ; toggleTimes := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( toggleTimes[i+1] := Set{} ) ; i := i + 1 ) ; var status : Sequence(boolean) ; status := Integer.subrange(1,n)->collect(false) ; var temp : Sequence(String) ; temp := br.readLine()->characters() ; var i : int ; i := 0 ; while i < n do ( ( status[i+1] := (if temp[i+1] = '1' then true else false endif) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var time : Sequence(String) ; time := br.readLine()->split(" ") ; var a : int ; a := (time[0+1])->toInteger() ; var b : int ; b := (time[1+1])->toInteger() ; var j : int ; j := 0 ; while j < 1000 do ( ( if (b + j * a > 700) then ( break ) else skip ; toggleTimes[i+1]->excludes(b + j * a) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var res : int ; res := 0 ; var time : int ; time := 0 ; while time <= 700 do ( ( var countOn : int ; countOn := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (toggleTimes[i+1]->includes(time)) then ( status[i+1] := not(status[i+1]) ) else skip ; if (status[i+1]) then ( countOn := countOn + 1 ) else skip ) ; i := i + 1 ) ; res := Set{res, countOn}->max() ) ; time := time + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class B { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n=sc.nextInt(); String s=sc.next(); boolean[][] oo=new boolean[241][n]; int max=0 ; int[] a=new int[n]; int[] b=new int[n]; for(int i=0 ; i=b[j] && i % a[j]==b[j] % a[j])oo[i][j]=! oo[i][j]; if(oo[i][j])num++; } max=Math.max(num,max); } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var oo : Sequence(Sequence(boolean)) ; oo := Integer.subrange(1,241)->collect(Integer.subrange(1,n)->collect(false)) ; var max : int ; max := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( oo[0+1][i+1] := s->at(i+1) = '1' ; if (oo[0+1][i+1]) then max := max + 1 ; else skip ; a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= 240 do ( ( var num : int ; num := 0 ; var j : int ; j := 0 ; while j < n do ( ( oo[i+1][j+1] := oo[i - 1+1][j+1] ; if (i >= b[j+1] & i mod a[j+1] = b[j+1] mod a[j+1]) then oo[i+1][j+1] := not(oo[i+1][j+1]) ; else skip ; if (oo[i+1][j+1]) then num := num + 1 ; else skip ) ; j := j + 1 ) ; max := Set{num, max}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static boolean[] bits ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); boolean[][] input=new boolean[m][n]; bits=new boolean[n]; int[] p=new int[m]; int k ; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var input : Sequence(Sequence(boolean)) ; input := Integer.subrange(1,m)->collect(Integer.subrange(1,n)->collect(false)) ; bits := Integer.subrange(1,n)->collect(false) ; var p : Sequence(int) ; p := Integer.subrange(1,m)->collect(0) ; var k : int ; var i : int ; i := 0 ; while i < m do ( ( k := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < k do ( ( input[i+1][sc.getCurrent()->toInteger() - 1+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( p[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var tmp1 : int ; var tmp2 : boolean ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 2->pow(n) do ( ( tmp2 := true ; var j : int ; j := 0 ; while j < m do ( ( tmp1 := 0 ; var l : int ; l := 0 ; while l < n do ( ( if (input[j+1][l+1] & bits[l+1]) then tmp1 := tmp1 + 1 ; else skip ) ; l := l + 1 ) ; tmp2 := MathLib.bitwiseAnd(tmp2, tmp1 mod 2 = p[j+1]) ) ; j := j + 1 ) ; if (tmp2) then ans := ans + 1 ; else skip ; if (i /= 2->pow(n) - 1) then execute update(0) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation update( pointer : int) : void pre: true post: true activity: ( if (not(bits[pointer+1])) then ( bits[pointer+1] := true ) else ( bits[pointer+1] := false ; execute update(pointer + 1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String input[]=new String[2]; try { input=br.readLine().split("\\s+"); int N=Integer.parseInt(input[0]); int T=Integer.parseInt(input[1]); int table[]=new int[T+1]; for(int i=0 ; icollect(null) ; try ( input := br.readLine()->split("\\s+") ; var N : int ; N := (input[0+1])->toInteger() ; var T : int ; T := (input[1+1])->toInteger() ; var table : Sequence(int) ; table := Integer.subrange(1,T + 1)->collect(0) ; var i : int ; i := 0 ; while i < table->size() do ( ( table[i+1] := 0 ) ; i := i + 1 ) ; var left : int ; var right : int ; var loop : int ; loop := 0 ; while loop < N do ( ( input := br.readLine()->split("\\s+") ; left := (input[0+1])->toInteger() ; right := (input[1+1])->toInteger() ; table[left+1] := table[left+1] + 1 ; table[right+1] := table[right+1] - 1 ; ) ; loop := loop + 1 ) ; var ans : int ; ans := table[0+1] ; var i : int ; i := 1 ; while i < table->size() do ( ( table[i+1] := table[i+1]+(table[i - 1+1]) ; ans := Set{ans, table[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int T=in.nextInt(); int res[]=new int[T+1]; int ini,fin ; for(int i=0 ; imax){ max=res[i]; } } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; var T : int ; T := in.getCurrent()->toInteger() ; var res : Sequence(int) ; res := Integer.subrange(1,T + 1)->collect(0) ; var ini : int ; var fin : int ; var i : int ; i := 0 ; while i < N do ( ( ini := in.getCurrent()->toInteger() ; fin := in.getCurrent()->toInteger() ; var j : int ; j := ini ; while j < fin do ( ( res[j+1] := res[j+1] + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < T do ( ( if (res[i+1] > max) then ( max := res[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); int[] imos=new int[t+2]; for(int i=0 ; itoInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var imos : Sequence(int) ; imos := Integer.subrange(1,t + 2)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( imos[sc.getCurrent()->toInteger()+1] := imos[sc.getCurrent()->toInteger()+1] + 1 ; imos[sc.getCurrent()->toInteger()+1] := imos[sc.getCurrent()->toInteger()+1] - 1 ) ; i := i + 1 ) ; var max : int ; max := imos[0+1] ; var i : int ; i := 1 ; while i <= t do ( ( imos[i+1] := imos[i+1]+(imos[i - 1+1]) ; max := Set{max, imos[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.security.spec.RSAOtherPrimeInfo ; import java.util.*; import java.lang.*; public class solve { static Scanner sc ; public static void main(String[] args){ sc=new Scanner(System.in); int testCases=sc.nextInt(); while(testCases>0){ justDoIt(); testCases--; } } static void justDoIt(){ int x=sc.nextInt(),y=sc.nextInt(); if(y % x!=0){ System.out.println("0 0"); return ; } if(y==x){ System.out.println("1 1"); return ; } Mapmap=new HashMap<>(); int num=(y/x); while(num % 2==0){ map.put(2,map.getOrDefault(2,0)+1); num/=2 ; } for(int i=3 ; i<=Math.sqrt(num); i+=2){ while(num % i==0){ map.put(i,map.getOrDefault(i,0)+1); num/=i ; } } if(num>1)map.put(num,1); int count=-1,ans=1 ; for(Map.Entryentry : map.entrySet()){ if(count!=-1 && count!=entry.getValue()){ count=1 ; ans=y/x ; break ; } if(count==-1)count=entry.getValue(); ans*=entry.getKey(); } System.out.println(count+" "+ans); } } ------------------------------------------------------------ OCL File: --------- class solve { static attribute sc : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var testCases : int ; testCases := sc.getCurrent()->toInteger() ; while (testCases > 0) do ( execute justDoIt() ; testCases := testCases - 1 ) ); static operation justDoIt() : void pre: true post: true activity: ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (y mod x /= 0) then ( OclFile["System.out"].println("0 0") ; return ) else skip ; if (y = x) then ( OclFile["System.out"].println("1 1") ; return ) else skip ; var map : Map(int,int) ; map := Map{} ; var num : int ; num := (y / x) ; while (num mod 2 = 0) do ( map := map->union(Map{2 |-> (if map->keys()->contains(2) then map->at(2) else 0 endif) + 1}) ; num := num/(2) ) ; var i : int ; i := 3 ; while i <= (num)->sqrt() do ( ( while (num mod i = 0) do ( map := map->union(Map{i |-> (if map->keys()->contains(i) then map->at(i) else 0 endif) + 1}) ; num := num/(i) ) ) ; i := i+(2) ) ; if (num > 1) then map := map->union(Map{num |-> 1}) ; else skip ; var count : int ; count := -1 ; var ans : int ; ans := 1 ; for (entry : map->asSet()) do ( ( if (count /= -1 & count /= entry.getValue()) then ( count := 1 ; ans := y / x ; break ) else skip ; if (count = -1) then count := entry.getValue() ; else skip ; ans := ans*(entry.getKey()) ) ) ; OclFile["System.out"].println(count + " " + ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); HashMaphp=new HashMap<>(); hp.put("purple","Power"); hp.put("green","Time"); hp.put("blue","Space"); hp.put("orange","Soul"); hp.put("red","Reality"); hp.put("yellow","Mind"); ListtargetList=new ArrayList<>(hp.values()); ArrayListarr=new ArrayList<>(); ArrayListal=new ArrayList<>(); while(n-->0){ String s1=sc.next(); arr.add(hp.get(s1)); } int total=hp.size(); int occu=arr.size(); System.out.println(total-occu); int iter=targetList.size(); for(int i=0 ; itoInteger() ; var hp : Map(String,String) ; hp := Map{} ; hp := hp->union(Map{"purple" |-> "Power"}) ; hp := hp->union(Map{"green" |-> "Time"}) ; hp := hp->union(Map{"blue" |-> "Space"}) ; hp := hp->union(Map{"orange" |-> "Soul"}) ; hp := hp->union(Map{"red" |-> "Reality"}) ; hp := hp->union(Map{"yellow" |-> "Mind"}) ; var targetList : Sequence(String) ; targetList := Sequence{}->union(hp->values()) ; var arr : Sequence(String) ; arr := Sequence{} ; var al : Sequence(String) ; al := Sequence{} ; while (n > 0) do ( n := n - 1 ; skip ; ( var s1 : String ; s1 := sc.getCurrent() ; arr := arr->including(hp->at(s1)) ) ; ) ; var total : int ; total := hp.size() ; var occu : int ; occu := arr->size() ; OclFile["System.out"].println((total)->char2byte() - occu) ; var iter : int ; iter := targetList->size() ; var i : int ; i := 0 ; while i < iter do ( ( var lol : String ; lol := targetList->at(i+1) ; if (not(arr->includes(lol))) then al := al->including(lol) ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < al->size() do ( ( OclFile["System.out"].println(al->at(i+1)) ) ; i := i + 1 ) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class problem { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String[] c=new String[n]; for(int i=0 ; itoInteger() ; var c : Sequence(String) ; c := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( c[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; var m : int ; m := 6 - n ; OclFile["System.out"].println(m) ; var p : int ; p := 0 ; var r : int ; r := 0 ; var g : int ; g := 0 ; var b : int ; b := 0 ; var o : int ; o := 0 ; var y : int ; y := 0 ; var s1 : String ; s1 := "purple" ; var s2 : String ; s2 := "green" ; var s3 : String ; s3 := "blue" ; var s4 : String ; s4 := "red" ; var s5 : String ; s5 := "orange" ; var i : int ; i := 0 ; while i < n do ( ( if (c[i+1] = s1) then p := p + 1 ; else if (c[i+1] = s2) then g := g + 1 else if (c[i+1] = s3) then b := b + 1 else if (c[i+1] = s4) then r := r + 1 else if (c[i+1] = s5) then o := o + 1 else y := y + 1 ; ; ; ; ; ) ; i := i + 1 ) ; if (p = 0) then OclFile["System.out"].println("Power") ; else skip ; if (g = 0) then OclFile["System.out"].println("Time") ; else skip ; if (b = 0) then OclFile["System.out"].println("Space") ; else skip ; if (r = 0) then OclFile["System.out"].println("Reality") ; else skip ; if (o = 0) then OclFile["System.out"].println("Soul") ; else skip ; if (y = 0) then OclFile["System.out"].println("Mind") ; else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static long n,d ; public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); Mapmap=new HashMap<>(); map.put("purple","Power"); map.put("green","Time"); map.put("blue","Space"); map.put("orange","Soul"); map.put("red","Reality"); map.put("yellow","Mind"); ArrayListlist=new ArrayList<>(); int n=in.nextInt(); for(int i=0 ; iunion(Map{"purple" |-> "Power"}) ; map := map->union(Map{"green" |-> "Time"}) ; map := map->union(Map{"blue" |-> "Space"}) ; map := map->union(Map{"orange" |-> "Soul"}) ; map := map->union(Map{"red" |-> "Reality"}) ; map := map->union(Map{"yellow" |-> "Mind"}) ; var list : Sequence(String) ; list := Sequence{} ; var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var v : String ; v := in.getCurrent() ; map := map->antirestrict(Set{v}) ) ; i := i + 1 ) ; skip ; for (s : map->keys()) do ( ( skip ) ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; class GFG { public static int CountSpecialPalindrome(String str){ int n=str.length(); int result=0 ; int[] sameChar=new int[n]; for(int v=0 ; v0 && j<(n-1)&&(str.charAt(j-1)==str.charAt(j+1)&& str.charAt(j)!=str.charAt(j-1)))result+=Math.min(sameChar[j-1],sameChar[j+1]); } return result-n ; } public static void main(String args[]){ String str="abccba" ; System.out.print(CountSpecialPalindrome(str)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation CountSpecialPalindrome( str : String) : int pre: true post: true activity: ( var n : int ; n := str->size() ; var result : int ; result := 0 ; var sameChar : Sequence(int) ; sameChar := Integer.subrange(1,n)->collect(0) ; var v : int ; v := 0 ; while v < n do ( sameChar[v+1] := 0 ; ; v := v + 1 ) ; var i : int ; i := 0 ; while (i < n) do ( var sameCharCount : int ; sameCharCount := 1 ; var j : int ; j := i + 1 ; while (j < n & str->at(i+1) = str->at(j+1)) do ( sameCharCount := sameCharCount + 1 ; j := j + 1 ) ; result := result+((sameCharCount * (sameCharCount + 1) / 2)) ; sameChar[i+1] := sameCharCount ; i := j ; ) ; var j : int ; j := 1 ; while j < n do ( ( if (str->at(j+1) = str->at(j - 1+1)) then sameChar[j+1] := sameChar[j - 1+1] ; else skip ; if (j > 0 & j < (n - 1) & (str->at(j - 1+1) = str->at(j + 1+1) & str->at(j+1) /= str->at(j - 1+1))) then result := result+(Set{sameChar[j - 1+1], sameChar[j + 1+1]}->min()) ; else skip ) ; j := j + 1 ) ; return result - n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "abccba" ; OclFile["System.out"].print(CountSpecialPalindrome(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isAMultipleOf4(int n){ if((n & 3)==0)return true ; return false ; } public static void main(String[] args){ int n=16 ; System.out.println(isAMultipleOf4(n)? "Yes" : "No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isAMultipleOf4( n : int) : boolean pre: true post: true activity: ( if ((n & 3) = 0) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 16 ; OclFile["System.out"].println(if isAMultipleOf4(n) then "Yes" else "No" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int minOperations(int n,int m,int k,int matrix[][]){ int[] arr=new int[n*m]; int mod=matrix[0][0] % k ; for(int i=0 ; icollect(0) ; var mod : int ; mod := matrix[0+1][0+1] mod k ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m 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 ) ; j := j + 1 ) ) ; i := i + 1 ) ; arr := arr->sort() ; var median : int ; median := arr[(n * m) / 2+1] ; var minOperations : int ; minOperations := 0 ; var i : int ; i := 0 ; while i < n * m do ( minOperations := minOperations+(if arr[i+1] - median < 0 then -(arr[i+1] - median) else arr[i+1] - median endif / k) ; ; i := i + 1 ) ; if ((n * m) mod 2 = 0) then ( var median2 : int ; median2 := arr[(n * m) / 2+1] ; var minOperations2 : int ; minOperations2 := 0 ; var i : int ; i := 0 ; while i < n * m do ( minOperations2 := minOperations2+(if arr[i+1] - median2 < 0 then -(arr[i+1] - median2) else arr[i+1] - median2 endif / k) ; ; i := i + 1 ) ; minOperations := Set{minOperations, minOperations2}->min() ) else skip ; return minOperations ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var matrix : Sequence(Sequence(int)) ; matrix := Sequence{Sequence{2,4,6},Sequence{8,10,12},Sequence{14,16,18},Sequence{20,22,24}} ; var n : int ; n := matrix->size() ; var m : int ; m := matrix[0+1]->size() ; var k : int ; k := 2 ; OclFile["System.out"].println(minOperations(n, m, k, matrix)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); w=scanner.nextInt(); h=scanner.nextInt(); map=new boolean[h+2][w+2]; v=new boolean[h+2][w+2]; for(int i=1 ; i<=h ; i++)for(int j=1 ; j<=w ; j++)map[i][j]=scanner.nextInt()==1 ; System.out.println(slove(0,0)); } private int slove(int y,int x){ v[y][x]=true ; int res=0 ; for(int i=0 ; i<6 ; i++){ int ny=y+dy[i]; int nx=x+(y % 2==1 ? dx1[i] : dx2[i]); if(! isOK(ny,nx))continue ; if(map[ny][nx]){ res++; continue ; } if(v[ny][nx])continue ; res+=slove(ny,nx); } return res ; } private boolean isOK(int ny,int nx){ if(0<=ny && ny<=h+1 && 0<=nx && nx<=w+1)return true ; return false ; } int h,w ; boolean[][] map ; boolean[][] v ; int[] dy={ -1,-1,0,0,1,1 }; int[] dx1={ 0,1,-1,1,0,1 }; int[] dx2={ -1,0,-1,1,-1,0 }; } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; w := scanner.getCurrent()->toInteger() ; h := scanner.getCurrent()->toInteger() ; map := Integer.subrange(1,h + 2)->collect(Integer.subrange(1,w + 2)->collect(false)) ; v := Integer.subrange(1,h + 2)->collect(Integer.subrange(1,w + 2)->collect(false)) ; var i : int ; i := 1 ; while i <= h do ( var j : int ; j := 1 ; while j <= w do ( map[i+1][j+1] := scanner.getCurrent()->toInteger() = 1 ; ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(slove(0, 0)) ; ); operation slove( y : int, x : int) : int pre: true post: true activity: ( v[y+1][x+1] := true ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < 6 do ( ( var ny : int ; ny := y + dy[i+1] ; var nx : int ; nx := x + (if y mod 2 = 1 then dx1[i+1] else dx2[i+1] endif) ; if (not(isOK(ny, nx))) then continue else skip ; if (map[ny+1][nx+1]) then ( res := res + 1 ; continue ) else skip ; if (v[ny+1][nx+1]) then continue else skip ; res := res+(slove(ny, nx)) ; ) ; i := i + 1 ) ; return res ); operation isOK( ny : int, nx : int) : boolean pre: true post: true activity: ( if (0 <= ny & ny <= h + 1 & 0 <= nx & nx <= w + 1) then return true else skip ; return false ); attribute h : int; attribute map : Sequence(Sequence(boolean)); attribute v : Sequence(Sequence(boolean)); attribute dy : Sequence(int) := Sequence{-1,-1,0,0,1,1}; attribute dx1 : Sequence(int) := Sequence{0,1,-1,1,0,1}; attribute dx2 : Sequence(int) := Sequence{-1,0,-1,1,-1,0}; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import javax.naming.InitialContext ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int h=sc.nextInt(); System.out.println((a+b)*h/2); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; OclFile["System.out"].println((a + b) * h / 2) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ try { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); int a=Integer.parseInt(br.readLine()); int b=Integer.parseInt(br.readLine()); int h=Integer.parseInt(br.readLine()); System.out.println((a+b)*h/2); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(isr) ; var a : int ; a := (br.readLine())->toInteger() ; var b : int ; b := (br.readLine())->toInteger() ; var h : int ; h := (br.readLine())->toInteger() ; OclFile["System.out"].println((a + b) * h / 2) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); int b=scanner.nextInt(); int h=scanner.nextInt(); System.out.println((a+b)*h/2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; var h : int ; h := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println((a + b) * h / 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] daikeihen=new int[3]; for(int i=0 ; i<=2 ; i++){ daikeihen[i]=sc.nextInt(); } System.out.println((daikeihen[0]+daikeihen[1])*daikeihen[2]/2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var daikeihen : Sequence(int) ; daikeihen := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i <= 2 do ( ( daikeihen[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println((daikeihen[0+1] + daikeihen[1+1]) * daikeihen[2+1] / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String args[]){ FastScanner input=new FastScanner(); int tc=input.nextInt(); work : while(tc-->0){ int x=input.nextInt(); int y=input.nextInt(); if(y % x!=0){ System.out.println("0 0"); } else { System.out.println("1 "+(y/x)); } } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine()throws IOException { return br.readLine(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : FastScanner ; input := FastScanner.newFastScanner() ; var tc : int ; tc := input.nextInt() ; while (tc > 0) do ( tc := tc - 1 ; skip ; ( var x : int ; x := input.nextInt() ; var y : int ; y := input.nextInt() ; if (y mod x /= 0) then ( OclFile["System.out"].println("0 0") ) else ( OclFile["System.out"].println("1 " + (y / x)) ) ) ; ) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in); ){ solve(sc); } } public static void solve(Scanner sc){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); System.out.println(((a+b)*c)/2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( execute solve(sc) )) ); static operation solve( sc : OclFile) : void pre: true post: true activity: ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(((a + b) * c) / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { final static long MOD=1000000007 ; public static String[] Ws=null ; public static int wsIndx=0 ; public static BufferedReader in=null ; public static long cnt=0 ; public static void main(String[] args)throws Exception { solution(args); if(in!=null){ in.close(); } } public static void solution(String[] args)throws Exception { long N=nextLong(); long K=nextLong(); System.out.println((long)(K*Math.pow(K-1,N-1))); } public static void check()throws Exception { if(in==null){ in=new BufferedReader(new InputStreamReader(System.in)); } if(Ws==null || Ws.length<=wsIndx){ Ws=in.readLine().split(" "); wsIndx=0 ; } } public static int nextInt()throws Exception { check(); return Integer.parseInt(Ws[wsIndx++]); } public static long nextLong()throws Exception { check(); return Long.parseLong(Ws[wsIndx++]); } public static String nextString()throws Exception { check(); return Ws[wsIndx++]; } public static int[] nextInts()throws Exception { check(); int[] tmp=new int[Ws.length]; for(int i=0 ; ipow(N - 1))->oclAsType(long)) ); static operation check() : void pre: true post: true activity: ( if (in = null) then ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) else skip ; if (Ws = null or Ws->size() <= wsIndx) then ( Ws := in.readLine()->split(" ") ; wsIndx := 0 ) else skip ); static operation nextInt() : int pre: true post: true activity: ( execute check() ; return (Ws[wsIndx+1])->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( execute check() ; return (Ws[wsIndx+1])->toLong() ); static operation nextString() : String pre: true post: true activity: ( execute check() ; return Ws[wsIndx+1] ); static operation nextInts() : Sequence(int) pre: true post: true activity: ( execute check() ; var tmp : Sequence(int) ; tmp := Integer.subrange(1,Ws->size())->collect(0) ; var i : int ; i := 0 ; while i < tmp->size() do ( ( tmp[i+1] := (Ws[i+1])->toInteger() ) ; i := i + 1 ) ; wsIndx := Ws->size() ; return tmp ); static operation nextLongs() : Sequence(long) pre: true post: true activity: ( execute check() ; var tmp : Sequence(long) ; tmp := Integer.subrange(1,Ws->size())->collect(0) ; var i : int ; i := 0 ; while i < tmp->size() do ( ( tmp[i+1] := (Ws[i+1])->toLong() ) ; i := i + 1 ) ; wsIndx := Ws->size() ; return tmp ); static operation nextStrings() : Sequence(String) pre: true post: true activity: ( execute check() ; wsIndx := Ws->size() ; return Ws ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); long N=input.nextLong(); long K=input.nextLong(); long ans=K ; K--; N--; for(long ball=1 ; ball<=N ; ball++){ ans*=K ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := input.getCurrent()->toLong() ; var K : long ; K := input.getCurrent()->toLong() ; var ans : long ; ans := K ; K := K - 1 ; N := N - 1 ; var ball : long ; ball := 1 ; while ball <= N do ( ( ans := ans*(K) ) ; ball := ball + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main().run(); } void run(){ int n=sc.nextInt(); int k=sc.nextInt(); int result=0 ; result=((int)Math.pow(k-1,n-1))*k ; System.out.println(result); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var result : int ; result := 0 ; result := (k - 1->pow(n - 1)->oclAsType(int)) * k ; OclFile["System.out"].println(result) ; ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } public String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } } public static void main(String[] args){ FastReader ob=new FastReader(); int n=ob.nextInt(),k=ob.nextInt(); long ways=k ; n--; while(n>0){ ways*=k-1 ; n--; } System.out.println(ways); } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ob : FastReader ; ob := FastReader.newFastReader() ; var n : int ; n := ob.nextInt() ; var k : int ; k := ob.nextInt() ; var ways : long ; ways := k ; n := n - 1 ; while (n > 0) do ( ways := ways*(k - 1) ; n := n - 1 ) ; OclFile["System.out"].println(ways) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static int gyo,retu ; public static int[][] dx={ { 1,0,-1,0,-1,-1 },{ 1,0,-1,0,1,1 } }; public static int[][] dy={ { 0,1,0,-1,1,-1 },{ 0,1,0,-1,-1,1 } }; public static int[][] map=new int[105][105]; public static void main(String[] args){ Scanner in=new Scanner(System.in); retu=in.nextInt(); gyo=in.nextInt(); for(int i=0 ; i<=gyo+1 ; i++){ for(int j=0 ; j<=retu+1 ; j++)map[i][j]=0 ; } for(int i=1 ; i<=gyo ; i++){ for(int j=1 ; j<=retu ; j++)map[i][j]=in.nextInt(); } System.out.println(dfs(0,0)); } public static int dfs(int x,int y){ map[y][x]=9 ; int nx,ny,ans=0 ; for(int i=0 ; i<6 ; i++){ nx=x+dx[y % 2][i]; ny=y+dy[y % 2][i]; if(nx>retu+1 || ny>gyo+1 || nx<0 || ny<0)continue ; if(map[ny][nx]==1)ans++; else if(map[ny][nx]==0)ans+=dfs(nx,ny); } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute gyo : int; static attribute dx : Sequence(Sequence(int)) := Sequence{Sequence{1,0,-1,0,-1,-1},Sequence{1,0,-1,0,1,1}}; static attribute dy : Sequence(Sequence(int)) := Sequence{Sequence{0,1,0,-1,1,-1},Sequence{0,1,0,-1,-1,1}}; static attribute map : Sequence(Sequence(int)) := Integer.subrange(1,105)->collect(Integer.subrange(1,105)->collect(0)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; retu := in.getCurrent()->toInteger() ; gyo := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i <= gyo + 1 do ( ( var j : int ; j := 0 ; while j <= retu + 1 do ( map[i+1][j+1] := 0 ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= gyo do ( ( var j : int ; j := 1 ; while j <= retu do ( map[i+1][j+1] := in.getCurrent()->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dfs(0, 0)) ; ); static operation dfs( x : int, y : int) : int pre: true post: true activity: ( map[y+1][x+1] := 9 ; var nx : int ; var ny : int ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 6 do ( ( nx := x + dx[y mod 2+1][i+1] ; ny := y + dy[y mod 2+1][i+1] ; if (nx > retu + 1 or ny > gyo + 1 or nx < 0 or ny < 0) then continue else skip ; if (map[ny+1][nx+1] = 1) then ans := ans + 1 ; else if (map[ny+1][nx+1] = 0) then ans := ans+(dfs(nx, ny)) ; else skip ; ) ; i := i + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); String[] inputs=input.readLine().split(" "); int N=Integer.parseInt(inputs[0]); int K=Integer.parseInt(inputs[1]); long answer=K ; for(int i=1 ; isplit(" ") ; var N : int ; N := (inputs[0+1])->toInteger() ; var K : int ; K := (inputs[1+1])->toInteger() ; var answer : long ; answer := K ; var i : int ; i := 1 ; while i < N do ( ( answer := answer * (K - 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean ispower(long n){ if(n<125){ return(n==1 || n==5 || n==25); } if(n % 125!=0){ return false ; } else { return ispower(n/125); } } static long number(String s,int i,int j){ long ans=0 ; for(int x=i ; xat(x+1) - ('0')->char2byte()) ) ; x := x + 1 ) ; return ans ); static operation minCuts( s : String, n : int) : int pre: true post: true activity: ( var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp := dp->collect(n + 1) ; dp[0+1] := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (s->at(i - 1+1) = '0') then ( continue ) else skip ; var j : int ; j := 0 ; while j < i do ( ( if (s->at(j+1) = '0') then ( continue ) else skip ; var num : long ; num := number(s, j, i) ; if (not(ispower(num))) then ( continue ) else skip ; dp[i+1] := Set{dp[i+1], dp[j+1] + 1}->min() ) ; j := j + 1 ) ) ; i := i + 1 ) ; return (if (dp[n+1] < n + 1) then dp[n+1] else -1 endif) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "101101101" ; var n : int ; n := s->size() ; OclFile["System.out"].println(minCuts(s, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int gcd(int a,int b){ if(b==0)return a ; return(gcd(b,a % b)); } static void findSmallest(int a,int b){ int lcm=(a*b)/gcd(a,b); System.out.print("x="+lcm/a+"\ny="+lcm/b); } public static void main(String[] args){ int a=25,b=35 ; findSmallest(a,b); } } ------------------------------------------------------------ OCL File: --------- class GFG { static 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)) ); static operation findSmallest( a : int, b : int) : void pre: true post: true activity: ( var lcm : int ; lcm := (a * b) / gcd(a, b) ; OclFile["System.out"].print("x=" + lcm / a + "\ny=" + lcm / b) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 25 ; var b : int ; b := 35 ; execute findSmallest(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); StringBuilder s=new StringBuilder(in.nextLine()); StringBuilder s1=new StringBuilder(); int len=s.length(); for(int i=0 ; i=0 ; i--){ if(s.charAt(i)=='l'){ s1.append(i+1+"\n"); } } System.out.print(s1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := StringLib.newString(in.nextLine()) ; var s1 : String ; s1 := StringLib.newString() ; var len : int ; len := s->size() ; var i : int ; i := 0 ; while i < len do ( ( if (s->at(i+1) = 'r') then ( s1 := s1 + StringLib.newString(i + 1 + "\n") ) else skip ) ; i := i + 1 ) ; var i : int ; i := (len)->char2byte() - 1 ; while i >= 0 do ( ( if (s->at(i+1) = 'l') then ( s1 := s1 + StringLib.newString(i + 1 + "\n") ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].print(s1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] c=new int[n]; for(int i=0 ; i=c[i]){ ans++; index++; } } } System.out.println(ans); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( c[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var a : Sequence(int) ; a := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var index : int ; index := 0 ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (index < m) then ( if (a[index+1] >= c[i+1]) then ( ans := ans + 1 ; index := index + 1 ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class NumberTransformation { public static PrintWriter out ; public static void main(String[] args)throws IOException { Scanner sc=new Scanner(); out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ int x=sc.nextInt(); int y=sc.nextInt(); boolean ans=false ; if(ytoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var ans : boolean ; ans := false ; if (y < x) then ( skip ; continue ) else if (y = x) then ( skip ; continue ) else skip ; ; var i : int ; i := 2 ; while i <= 100 do ( ( var temp : int ; temp := x ; var count : int ; count := 0 ; while (temp < y) do ( temp := temp*(i) ; count := count + 1 ) ; if (temp = y) then ( skip ; ans := true ; break ) else skip ) ; i := i + 1 ) ; if (not(ans)) then ( skip ) else skip ; ) ; ) ; skip ; ); static class Scanner { attribute br : OclFile; attribute st : OclIterator; static operation newScanner() : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class GameShopping { public static void main(String[] args){ Scanner sn=new Scanner(System.in); int n=sn.nextInt(); int m=sn.nextInt(); sn.nextLine(); String costs[]=sn.nextLine().split(" "); String monies[]=sn.nextLine().split(" "); int c[]=new int[n]; int w[]=new int[m]; for(int i=0 ; i=c[i]){ pointer++; if(pointer==m){ break ; } } } System.out.println(pointer); } } ------------------------------------------------------------ OCL File: --------- class GameShopping { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sn : OclFile ; sn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sn.getCurrent()->toInteger() ; var m : int ; m := sn.getCurrent()->toInteger() ; skip ; var costs : Sequence(String) ; costs := sn.nextLine()->split(" ") ; var monies : Sequence(String) ; monies := sn.nextLine()->split(" ") ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var w : Sequence(int) ; w := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < costs->size() do ( ( c[i+1] := (costs[i+1])->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( w[i+1] := (monies[i+1])->toInteger() ) ; i := i + 1 ) ; var pointer : int ; pointer := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (w[pointer+1] >= c[i+1]) then ( pointer := pointer + 1 ; if (pointer = m) then ( break ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(pointer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] a=new int[n]; int[] b=new int[m]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var x : int ; x := 0 ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (x < m & a[i+1] <= b[x+1]) then ( count := count + 1 ; x := x + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int productAtKthLevel(String tree,int k){ int level=-1 ; int product=1 ; int n=tree.length(); for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < n do ( ( if (tree->at(i+1) = '(') then level := level + 1 ; else if (tree->at(i+1) = ')') then level := level - 1 else ( if (level = k) then product := product*((tree->at(i+1) - ('0')->char2byte())) ; else skip ) ; ) ; i := i + 1 ) ; return product ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var tree : String ; tree := "(0(5(6()())(4()(9()())))(7(1()())(3()())))" ; var k : int ; k := 2 ; OclFile["System.out"].println(productAtKthLevel(tree, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int factorial(int n){ if(n==0)return 1 ; return n*factorial(n-1); } static int countNum(int n){ if(n>10)return 0 ; return(9*factorial(9)/factorial(10-n)); } public static void main(String[] args){ int n=3 ; System.out.println(countNum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation factorial( n : int) : int pre: true post: true activity: ( if (n = 0) then return 1 else skip ; return n * factorial(n - 1) ); static operation countNum( n : int) : int pre: true post: true activity: ( if (n > 10) then return 0 else skip ; return (9 * factorial(9) / factorial(10 - n)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(countNum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static int gyo,retu ; public static int[][] dx={ { 1,0,-1,0,-1,-1 },{ 1,0,-1,0,1,1 } }; public static int[][] dy={ { 0,1,0,-1,1,-1 },{ 0,1,0,-1,-1,1 } }; public static int[][] map=new int[105][105]; public static void main(String[] args){ Scanner in=new Scanner(System.in); retu=in.nextInt(); gyo=in.nextInt(); for(int i=0 ; i<=gyo+1 ; i++){ for(int j=0 ; j<=retu+1 ; j++)map[i][j]=0 ; } for(int i=1 ; i<=gyo ; i++){ for(int j=1 ; j<=retu ; j++)map[i][j]=in.nextInt(); } System.out.println(dfs(0,0)); } public static int dfs(int x,int y){ map[y][x]=9 ; int nx,ny,ans=0 ; for(int i=0 ; i<6 ; i++){ nx=x+dx[y % 2][i]; ny=y+dy[y % 2][i]; if(nx>retu+1 || ny>gyo+1 || nx<0 || ny<0)continue ; if(map[ny][nx]==1)ans++; else if(map[ny][nx]==0)ans+=dfs(nx,ny); } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute gyo : int; static attribute dx : Sequence(Sequence(int)) := Sequence{Sequence{1,0,-1,0,-1,-1},Sequence{1,0,-1,0,1,1}}; static attribute dy : Sequence(Sequence(int)) := Sequence{Sequence{0,1,0,-1,1,-1},Sequence{0,1,0,-1,-1,1}}; static attribute map : Sequence(Sequence(int)) := Integer.subrange(1,105)->collect(Integer.subrange(1,105)->collect(0)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; retu := in.getCurrent()->toInteger() ; gyo := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i <= gyo + 1 do ( ( var j : int ; j := 0 ; while j <= retu + 1 do ( map[i+1][j+1] := 0 ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= gyo do ( ( var j : int ; j := 1 ; while j <= retu do ( map[i+1][j+1] := in.getCurrent()->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dfs(0, 0)) ; ); static operation dfs( x : int, y : int) : int pre: true post: true activity: ( map[y+1][x+1] := 9 ; var nx : int ; var ny : int ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 6 do ( ( nx := x + dx[y mod 2+1][i+1] ; ny := y + dy[y mod 2+1][i+1] ; if (nx > retu + 1 or ny > gyo + 1 or nx < 0 or ny < 0) then continue else skip ; if (map[ny+1][nx+1] = 1) then ans := ans + 1 ; else if (map[ny+1][nx+1] = 0) then ans := ans+(dfs(nx, ny)) ; else skip ; ) ; i := i + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); HashMapA=new HashMap(); int N=stdIn.nextInt(); int a[]=new int[N]; int z=0,y=0,x=0,v=0,ans=0 ; while(za[z])ans+=x-a[z]; else ans+=x ; } z++; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : Map(int,int) ; A := Map{} ; var N : int ; N := stdIn.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var z : int ; z := 0 ; var y : int ; y := 0 ; var x : int ; x := 0 ; var v : int ; v := 0 ; var ans : int ; ans := 0 ; while (z < N) do ( y := stdIn.getCurrent()->toInteger() ; if (A->keys()->includes(y)) then x := A->at(y) else ( a[v+1] := y ; v := v + 1 ) ; A := A->union(Map{y |-> x + 1}) ; x := 0 ; z := z + 1 ; ) ; z := 0 ; while (z < v) do ( if (A->keys()->includes(a[z+1])) then ( x := A->at(a[z+1]) ; if (x /= 0 & x /= a[z+1]) then if (x > a[z+1]) then ans := ans+(x - a[z+1]) else ans := ans+(x) ; ; else skip ) else skip ; z := z + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.Arrays ; import java.util.Scanner ; public class Main { InputStream in=System.in ; PrintStream out=System.out ; public void _main(String[] args){ Scanner sc=new Scanner(in); int N=sc.nextInt(); int[] a=nextIntArray(sc,N); sc.close(); Arrays.sort(a); int ans=0 ; int p=0 ; while(pq-p){ ans+=(q-p); } else if(xtoInteger() ; var a : Sequence(int) ; a := nextIntArray(sc, N) ; skip ; a := a->sort() ; var ans : int ; ans := 0 ; var p : int ; p := 0 ; while (p < N) do ( var x : int ; x := a[p+1] ; var q : int ; q := p + 1 ; while (q < N & a[q+1] = x) do ( q := q + 1 ) ; if (q < 0) then ( q := (-q) - 1 ) else skip ; if (x > q - p) then ( ans := ans+((q - p)) ) else if (x < q - p) then ( ans := ans+((q - p) - x) ) else skip ; ; p := q ; ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain()._main(args) ); operation nextIntArray( sc : OclFile, n : int) : Sequence(int) pre: true post: true activity: ( var result : Sequence(int) ; result := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( result[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { static int N ; static HashMapa ; private static void init(){ Scanner scanner=new Scanner(System.in); N=scanner.nextInt(); a=new HashMap<>(); for(int i=0 ; ii){ count+=Math.abs(i-a.get(i)); } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute N : int; static attribute a : Map(int,int); static operation init() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := scanner.getCurrent()->toInteger() ; a := Map{} ; var i : int ; i := 0 ; while i < N do ( ( var number : int ; number := scanner.getCurrent()->toInteger() ; if (a->keys()->includes(number)) then ( var c : int ; c := a->at(number) ; c := c + 1 ; a := a->union(Map{number |-> c}) ) else ( a := a->union(Map{number |-> 1}) ) ) ; i := i + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute init() ; var count : int ; count := 0 ; for (i : a->keys()) do ( ( if (a->at(i) < i) then ( count := count+(a->at(i)) ) else if (a->at(i) > i) then ( count := count+(if i - a->at(i) < 0 then -(i - a->at(i)) else i - a->at(i) endif) ) else skip ; ) ) ; OclFile["System.out"].println(count) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.PriorityQueue ; import java.util.Queue ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); QueueOVER=new LinkedList(); PriorityQueueA=new PriorityQueue(); for(int i=0 ; icount)ans+=count ; else if(temptoInteger() ; var OVER : Sequence(long) ; OVER := Sequence{} ; var A : Sequence(long) ; A := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( var temp : long ; temp := sc.getCurrent()->toLong() ; if (temp <= 10->pow(5)) then A := A->including(temp) ; else OVER := OVER->including(temp) ; ) ; i := i + 1 ) ; skip ; if (A->isEmpty()) then OclFile["System.out"].println(OVER->size()) else ( var size : int ; size := A->size() ; var count : long ; count := 0 ; var ans : int ; ans := 0 ; while (A->isEmpty() /= true) do ( count := 1 ; var temp : long ; temp := A->min() ; while (A->isEmpty() /= true & A->min() = temp) do ( A := A->sort()->tail() ; count := count + 1 ) ; if (temp > count) then ans := ans+(count) ; else if (temp < count) then ans := ans+((count - temp)) ; else skip ; ) ; OclFile["System.out"].println(OVER->size() + ans) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ Mapmap=new HashMap(); Scanner scanner=new Scanner(System.in); int len=Integer.parseInt(scanner.nextLine()); for(int i=0 ; ilist=map.keySet().stream().filter(key->map.get(key)-key!=0).collect(Collectors.toList()); for(Integer i : list){ int n=map.get(i); if(n>i){ ans+=n-i ; } else { ans+=n ; } } System.out.println(ans); scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var map : Map(int,int) ; map := Map{} ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var len : int ; len := (scanner.nextLine())->toInteger() ; var i : int ; i := 0 ; while i < len do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; if (map->at(n) = null) then ( map := map->union(Map{n |-> 1}) ) else ( map := map->union(Map{n |-> map->at(n) + 1}) ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var list : List ; list := map->keys()->select( _x1 | (lambda key : OclAny in map->at(key) - key /= 0)->apply(_x1) ).collect(Collectors.toList()) ; for (i : list) do ( ( var n : int ; n := map->at(i) ; if (n > i) then ( ans := ans+(n - i) ) else ( ans := ans+(n) ) ) ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : String ; a := stdIn.getCurrent() ; var b : Sequence(String) ; b := Integer.subrange(1,10)->collect(0) ; b := a->characters() ; b := b->sort() ; var c : String ; c := (b)->sum() ; var min : int ; min := (c)->toInteger() ; var max : int ; max := 0 ; var j : int ; j := 0 ; while j < 8 do ( ( max := max*(10) ; max := max+(b[7 - j+1] - ('0')->char2byte()) ) ; j := j + 1 ) ; OclFile["System.out"].println(max - (min)->char2byte()) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args){ FastScanner input=new FastScanner(); int tc=input.nextInt(); work : while(tc-->0){ int n=input.nextInt(); String s=input.next(); long ans=n ; for(int i=1 ; i 0) do ( tc := tc - 1 ; skip ; ( var n : int ; n := input.nextInt() ; var s : String ; s := input.next() ; var ans : long ; ans := n ; var i : int ; i := 1 ; while i < s->size() do ( ( if (s->at(i+1) /= s->at(i - 1+1)) then ( ans := ans+((i)) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Listhenkan(String n){ Listm=new ArrayList(); for(int i=0 ; im){ String a="" ; Collections.sort(m); for(int s=m.size()-1 ; s>=0 ; s--)a+=m.get(s); return Integer.parseInt(a); } static int small(Listm){ String a="" ; Collections.sort(m); for(int s=0 ; sm=henkan(input); System.out.println(big(m)-small(m)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation henkan( n : String) : Sequence(int) pre: true post: true activity: ( var m : Sequence(int) ; m := Sequence{} ; var i : int ; i := 0 ; while i < n->size() do ( m := m->including((n->at(i+1) + "")->toInteger()) ; ; i := i + 1 ) ; return m ); static operation big( m : Sequence(int)) : int pre: true post: true activity: ( var a : String ; a := "" ; m := m->sort() ; var s : int ; s := m->size() - 1 ; while s >= 0 do ( a := a+(m->at(s+1)) ; ; s := s - 1 ) ; return (a)->toInteger() ); static operation small( m : Sequence(int)) : int pre: true post: true activity: ( var a : String ; a := "" ; m := m->sort() ; var s : int ; s := 0 ; while s < m->size() do ( a := a+(m->at(s+1)) ; ; s := s + 1 ) ; return (a)->toInteger() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := 0 ; while k < n do ( ( var input : String ; input := in.getCurrent() ; var m : Sequence(int) ; m := henkan(input) ; OclFile["System.out"].println(big(m) - small(m)) ) ; k := k + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Main { public static void main(String args[])throws IOException { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(input.readLine()); for(int i=0 ; ia[k]){ int tmp=a[k-1]; a[k-1]=a[k]; a[k]=tmp ; } if(b[k-1]toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var str : String ; str := input.readLine() ; var a : Sequence(int) ; a := Integer.subrange(1,8)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,8)->collect(0) ; var j : int ; j := 0 ; while j < 8 do ( ( a[j+1] := (str->at(j+1) + "")->toInteger() ; b[j+1] := (str->at(j+1) + "")->toInteger() ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < 8 do ( ( var k : int ; k := 7 ; while j < k do ( ( if (a[k - 1+1] > a[k+1]) then ( var tmp : int ; tmp := a[k - 1+1] ; a[k - 1+1] := a[k+1] ; a[k+1] := tmp ) else skip ; if (b[k - 1+1] < b[k+1]) then ( var tmp : int ; tmp := b[k - 1+1] ; b[k - 1+1] := b[k+1] ; b[k+1] := tmp ) else skip ) ; k := k - 1 ) ) ; j := j + 1 ) ; var sumb : long ; sumb := 0 ; var suma : long ; suma := 0 ; var j : int ; j := 0 ; while j < 8 do ( ( sumb := sumb+(b[j+1] * ((10->pow(7 - j))->oclAsType(int))) ; if (a[j+1] = 0) then continue else skip ; suma := suma+(a[j+1] * ((10->pow(7 - j))->oclAsType(int))) ) ; j := j + 1 ) ; OclFile["System.out"].println(sumb - suma) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static char[] ns=new char[8]; public static char[] perm=new char[8]; public static boolean[] used=new boolean[8]; public static int max,min ; public static void main(String[] args)throws java.io.IOException { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); scan.nextLine(); for(int i=0 ; icollect(0); static attribute perm : Sequence(String) := Integer.subrange(1,8)->collect(0); static attribute used : Sequence(boolean) := Integer.subrange(1,8)->collect(false); static attribute max : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; skip ; var i : int ; i := 0 ; while i < n do ( ( ns := scan.nextLine()->characters() ; max := 0 ; min := 99999999 ; execute permutation(0, 8) ; OclFile["System.out"].println(max - min) ; ) ; i := i + 1 ) ); static operation permutation( pos : int, n : int) : void pre: true post: true activity: ( if (pos = n) then ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( sb := sb + StringLib.newString(perm[i+1]) ) ; i := i + 1 ) ; max := Set{max, (sb+"")->toInteger()}->max() ; min := Set{min, (sb+"")->toInteger()}->min() ; return ) else skip ; var i : int ; i := 0 ; while i < n do ( ( if (not(used[i+1])) then ( perm[pos+1] := ns[i+1] ; used[i+1] := true ; execute permutation(pos + 1, n) ; used[i+1] := false ) else skip ) ; i := i + 1 ) ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.util.ArrayDeque ; import java.util.Queue ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int[] DX1=new int[] { -1,1,0,1,0,1 }; static int[] DX2=new int[] { -1,1,0,-1,0,-1 }; static int[] DY=new int[] { 0,0,1,1,-1,-1 }; public static void main(String[] args){ int W=sc.nextInt(); int H=sc.nextInt(); boolean[][] m=new boolean[H+2][W+2]; for(int i=0 ; iq=new ArrayDeque(); q.add(new Point(0,0)); boolean[][] visited=new boolean[H+2][W+2]; while(! q.isEmpty()){ Point p=q.poll(); int[] DX=p.y % 2!=0 ? DX1 : DX2 ; for(int i=0 ; i<6 ; ++i){ int nx=p.x+DX[i]; int ny=p.y+DY[i]; if(nx<0 || W+1toInteger() ; var H : int ; H := sc.getCurrent()->toInteger() ; var m : Sequence(Sequence(boolean)) ; m := Integer.subrange(1,H + 2)->collect(Integer.subrange(1,W + 2)->collect(false)) ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( m[i + 1+1][j + 1+1] := sc.getCurrent()->at(0+1) = '1' ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var q : Sequence(Point) ; q := ArrayDeque.newArrayDeque() ; q := q->including(Point.newPoint(0, 0)) ; var visited : Sequence(Sequence(boolean)) ; visited := Integer.subrange(1,H + 2)->collect(Integer.subrange(1,W + 2)->collect(false)) ; while (not(q->isEmpty())) do ( var p : Point ; p := q->min() ; var DX : Sequence(int) ; DX := if p.y mod 2 /= 0 then DX1 else DX2 endif ; var i : int ; i := 0 ; while i < 6 do ( ( var nx : int ; nx := p.x + DX[i+1] ; var ny : int ; ny := p.y + DY[i+1] ; if (nx < 0 or W + 1 < nx or ny < 0 or H + 1 < ny or visited[ny+1][nx+1]) then continue else skip ; if (m[ny+1][nx+1]) then ( ans := ans + 1 ; continue ) else skip ; q := q->including(Point.newPoint(nx, ny)) ; visited[ny+1][nx+1] := true ; ) ; i := i + 1 ) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { private static BufferedReader br=null ; static { br=new BufferedReader(new InputStreamReader(System.in)); } public static void main(String[] args){ String strIn=parseStdin(); if(strIn!=null){ int max=Integer.parseInt(strIn); for(int n=0 ; ntoInteger() ; var n : int ; n := 0 ; while n < max do ( ( strIn := parseStdin() ; execute sub(strIn->characters()) ) ; n := n + 1 ) ) else skip ); static operation sub( strIn : Sequence(String)) : void pre: true post: true activity: ( var strMin : String ; strMin := null ; var strMax : String ; strMax := null ; strIn := strIn->sort() ; strMin := ((strIn) + "") ; strMax := reverse(strMin) ; OclFile["System.out"].println((strMax)->toLong() - (strMin)->toLong()) ; ); static operation reverse( str : String) : String pre: true post: true activity: ( var buff : Sequence(String) ; buff := str->characters() ; var nLen : int ; nLen := str->size() ; var c : String ; c := 0 ; var n1 : int ; n1 := 0 ; var n2 : int ; n2 := nLen - 1 ; while n1 < n2 do ( ( c := buff[n1+1] ; buff[n1+1] := buff[n2+1] ; buff[n2+1] := c ) ; n1 := n1 + 1 ; n2 := n2 - 1 ) ; return (buff)->sum() ); static operation parseStdin() : String pre: true post: true activity: ( var strNum : String ; strNum := null ; try ( var line : String ; line := br.readLine() ; if (line /= null) then ( if (not(line->isEmpty())) then ( strNum := line ) else skip ) else skip ) catch (e : IOException) do skip return strNum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class C { public static void main(String[] Z)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stz ; int n=Integer.parseInt(br.readLine()); stz=new StringTokenizer(br.readLine()); int[] arr=new int[n+1]; int sumOdd=0 ; int sumEve=0 ; for(int i=1 ; i<=n ; i++){ arr[i]=Integer.parseInt(stz.nextToken()); if(i % 2==0)sumEve+=arr[i]; else sumOdd+=arr[i]; } int prevOdd=0 ; int prevEve=0 ; int ans=0 ; for(int i=1 ; i<=n ; i++){ int s1=0 ; int s2=0 ; if(i % 2==1){ int nowOdd=sumOdd-arr[i]; s1=prevOdd-prevEve+sumEve ; s2=prevEve-prevOdd+nowOdd ; prevOdd+=arr[i]; } else { int nowEve=sumEve-arr[i]; s1=prevOdd-prevEve+nowEve ; s2=prevEve-prevOdd+sumOdd ; prevEve+=arr[i]; } if(s1==s2)++ans ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class C { static operation main( Z : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var stz : OclIterator ; var n : int ; n := (br.readLine())->toInteger() ; stz := OclIterator.newOclIterator_String(br.readLine()) ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var sumOdd : int ; sumOdd := 0 ; var sumEve : int ; sumEve := 0 ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := (stz.next())->toInteger() ; if (i mod 2 = 0) then sumEve := sumEve+(arr[i+1]) ; else sumOdd := sumOdd+(arr[i+1]) ; ) ; i := i + 1 ) ; var prevOdd : int ; prevOdd := 0 ; var prevEve : int ; prevEve := 0 ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var s1 : int ; s1 := 0 ; var s2 : int ; s2 := 0 ; if (i mod 2 = 1) then ( var nowOdd : int ; nowOdd := sumOdd - arr[i+1] ; s1 := prevOdd - prevEve + sumEve ; s2 := prevEve - prevOdd + nowOdd ; prevOdd := prevOdd+(arr[i+1]) ) else ( var nowEve : int ; nowEve := sumEve - arr[i+1] ; s1 := prevOdd - prevEve + nowEve ; s2 := prevEve - prevOdd + sumOdd ; prevEve := prevEve+(arr[i+1]) ) ; if (s1 = s2) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class GFG { public static ArrayListgetPerfectSquares(int n){ ArrayListperfectSquares=new ArrayList<>(); int current=1,i=1 ; while(current<=n){ perfectSquares.add(current); current=(int)Math.pow(++i,2); } return perfectSquares ; } public static int countTriplets(int n){ ArrayListperfectSquares=getPerfectSquares((int)Math.pow(n,2)); int count=0 ; for(int a=1 ; a<=n ; a++){ int aSquare=(int)Math.pow(a,2); for(int i=0 ; i=a)&&(b<=c)&&(aSquare+bSquare==cSquare))count++; } } return count ; } public static void main(String[] args){ int n=10 ; System.out.println(countTriplets(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getPerfectSquares( n : int) : Sequence(int) pre: true post: true activity: ( var perfectSquares : Sequence(int) ; perfectSquares := Sequence{} ; var current : int ; current := 1 ; var i : int ; i := 1 ; while (current <= n) do ( perfectSquares := perfectSquares->including(current) ; current := (i + 1)->pow(2)->oclAsType(int) ) ; return perfectSquares ); static operation countTriplets( n : int) : int pre: true post: true activity: ( var perfectSquares : Sequence(int) ; perfectSquares := getPerfectSquares(n->pow(2)->oclAsType(int)) ; var count : int ; count := 0 ; var a : int ; a := 1 ; while a <= n do ( ( var aSquare : int ; aSquare := a->pow(2)->oclAsType(int) ; var i : int ; i := 0 ; while i < perfectSquares->size() do ( ( var cSquare : int ; cSquare := perfectSquares->at(i+1) ; var bSquare : int ; bSquare := cSquare - aSquare ; var b : int ; b := (bSquare)->sqrt()->oclAsType(int) ; var c : int ; c := (cSquare)->sqrt()->oclAsType(int) ; if (c < a or not(perfectSquares->includes(bSquare))) then continue else skip ; if ((b >= a) & (b <= c) & (aSquare + bSquare = cSquare)) then count := count + 1 ; else skip ; ) ; i := i + 1 ) ) ; a := a + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println(countTriplets(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int T=sc.nextInt(); int[][] time=new int[N][2]; String[][] name=new String[N][2]; for(int i=0 ; ires=new ArrayList(); for(int i=0 ; i=T)res.add(i); } System.out.println(res.size()); for(int i : res){ System.out.println(name[i][1]+" "+(time[i+1][0]-time[i][1])); } } static int time(String hhmm){ int h=(hhmm.charAt(0)-'0')*10+hhmm.charAt(1)-'0' ; int m=(hhmm.charAt(3)-'0')*10+hhmm.charAt(4)-'0' ; return h*60+m ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; var T : int ; T := sc.getCurrent()->toInteger() ; var time : Sequence(Sequence(int)) ; time := Integer.subrange(1,N)->collect(Integer.subrange(1,2)->collect(0)) ; var name : Sequence(Sequence(String)) ; name := Integer.subrange(1,N)->collect(Integer.subrange(1,2)->collect(null)) ; var i : int ; i := 0 ; while i < N do ( ( time[i+1][0+1] := time(sc.getCurrent()) ; name[i+1][0+1] := sc.getCurrent() ; time[i+1][1+1] := time(sc.getCurrent()) ; name[i+1][1+1] := sc.getCurrent() ) ; i := i + 1 ) ; var res : Sequence(int) ; res := Sequence{} ; var i : int ; i := 0 ; while i < N - 1 do ( ( if (time[i + 1+1][0+1] - time[i+1][1+1] >= T) then res := res->including(i) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res->size()) ; for (i : res) do ( ( OclFile["System.out"].println(name[i+1][1+1] + " " + (time[i + 1+1][0+1] - time[i+1][1+1])) ) ) ; ); static operation time( hhmm : String) : int pre: true post: true activity: ( var h : int ; h := (hhmm->at(0+1) - ('0')->char2byte()) * 10 + hhmm->at(1+1) - ('0')->char2byte() ; var m : int ; m := (hhmm->at(3+1) - ('0')->char2byte()) * 10 + hhmm->at(4+1) - ('0')->char2byte() ; return h * 60 + m ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; line=br.readLine(); int n=parseInt(line.substring(0,line.indexOf(' '))); int t=parseInt(line.substring(line.indexOf(' ')+1)); Liststations=new ArrayList(); int[] opens=new int[n-1]; for(int i=0 ; i0){ opens[i-1]=leave-opens[i-1]; } } int c=0 ; StringBuilder sb=new StringBuilder(); for(int i=0 ; i=t){ c++; sb.append(stations.get(i)+" "+opens[i]+"\n"); } } System.out.println(c); System.out.print(sb.toString()); } static int minutes(String time){ int h=parseInt(time.substring(0,time.indexOf(':'))); int m=parseInt(time.substring(time.indexOf(':')+1)); return h*60+m ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := br.readLine() ; var n : int ; n := parseInt(line.subrange(0+1,line->indexOf(' ')-1)) ; var t : int ; t := parseInt(line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1)) ; var stations : Sequence(String) ; stations := Sequence{} ; var opens : Sequence(int) ; opens := Integer.subrange(1,(n)->char2byte() - 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var tokens : Sequence(String) ; tokens := br.readLine()->split(" ") ; stations := stations->including(tokens[3+1]) ; var arrive : int ; arrive := minutes(tokens[2+1]) ; var leave : int ; leave := minutes(tokens[0+1]) ; if (i < (n)->char2byte() - 1) then ( opens[i+1] := arrive ) else skip ; if (i > 0) then ( opens[i - 1+1] := leave - opens[i - 1+1] ) else skip ; ) ; i := i + 1 ) ; var c : int ; c := 0 ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < (n)->char2byte() - 1 do ( ( if (opens[i+1] >= t) then ( c := c + 1 ; sb := sb + StringLib.newString(stations->at(i+1) + " " + opens[i+1] + "\n") ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; OclFile["System.out"].print(sb+"") ; ); static operation minutes( time : String) : int pre: true post: true activity: ( var h : int ; h := parseInt(time.subrange(0+1,time->indexOf(':')-1)) ; var m : int ; m := parseInt(time.subrange(time->indexOf(':')-1 + 1+1,time->indexOf(':')-1 + 1)) ; return h * 60 + m ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-12 ; void run(){ int n=sc.nextInt(),t=sc.nextInt(); sc.next(); sc.next(); int count=0 ; String line="" ; for(int i=0 ; i=t){ line+=name+" "+(time2-time1)+"\n" ; count++; } } line=count+"\n"+line ; print(line); } int f(String s){ return Integer.parseInt(s.substring(0,2))*60+Integer.parseInt(s.substring(3,5)); } void solve(){ } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute EPS : double := 1e-12; operation run() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; skip ; skip ; var count : int ; count := 0 ; var line : String ; line := "" ; var i : int ; i := 0 ; while i < n - 1 do ( ( var time1 : int ; time1 := f(sc.getCurrent()) ; var name : String ; name := sc.getCurrent() ; var time2 : int ; time2 := f(sc.getCurrent()) ; skip ; if ((time2)->char2byte() - time1 >= t) then ( line := line+(name + " " + ((time2)->char2byte() - time1) + "\n") ; count := count + 1 ) else skip ; ) ; i := i + 1 ) ; line := count + "\n" + line ; execute print(line) ; ); operation f( s : String) : int pre: true post: true activity: ( return (s.subrange(0+1,2))->toInteger() * 60 + (s.subrange(3+1,5))->toInteger() ); operation solve() : void pre: true post: true activity: skip; operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.security.*; import java.math.*; import java.awt.geom.*; import java.io.*; public class Main { public static void main(String[] args)throws NoSuchAlgorithmException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); ArrayListlistA=new ArrayList(); ArrayListlistB=new ArrayList(); sc.next(); sc.next(); for(int i=0 ; i=t){ listA.add(name1); listB.add(time2-time1); } } sc.next(); sc.next(); System.out.println(listA.size()); for(int i=0 ; itoInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var listA : Sequence(String) ; listA := Sequence{} ; var listB : Sequence(int) ; listB := Sequence{} ; skip ; skip ; var i : int ; i := 0 ; while i < n - 1 do ( ( var tt : Sequence(String) ; tt := sc.getCurrent()->split(":") ; var time1 : int ; time1 := (tt[0+1])->toInteger() * 60 + (tt[1+1])->toInteger() ; var name1 : String ; name1 := sc.getCurrent() ; tt := sc.getCurrent()->split(":") ; var time2 : int ; time2 := (tt[0+1])->toInteger() * 60 + (tt[1+1])->toInteger() ; var name2 : String ; name2 := sc.getCurrent() ; if ((time2)->char2byte() - time1 >= t) then ( listA := listA->including(name1) ; listB := listB->including((time2)->char2byte() - time1) ) else skip ; ) ; i := i + 1 ) ; skip ; skip ; OclFile["System.out"].println(listA->size()) ; var i : int ; i := 0 ; while i < listA->size() do ( ( OclFile["System.out"].println(listA->at(i+1) + " " + listB->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void substringConversions(String str,int k,int b){ for(int i=0 ; i+k<=str.length(); i++){ String sub=str.substring(i,i+k); int sum=0,counter=0 ; for(int j=sub.length()-1 ; j>=0 ; j--){ sum=(int)(sum+((sub.charAt(j)-'0')*Math.pow(b,counter))); counter++; } System.out.print(sum+" "); } } public static void main(String[] args){ String str="12212" ; int b=3,k=3 ; substringConversions(str,b,k); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation substringConversions( str : String, k : int, b : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i + k <= str->size() do ( ( var sub : String ; sub := str.subrange(i+1,i + k) ; var sum : int ; sum := 0 ; var counter : int ; counter := 0 ; var j : int ; j := sub->size() - 1 ; while j >= 0 do ( ( sum := (sum + ((sub->at(j+1) - ('0')->char2byte()) * b->pow(counter)))->oclAsType(int) ; counter := counter + 1 ) ; j := j - 1 ) ; OclFile["System.out"].print(sum + " ") ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "12212" ; var b : int ; b := 3 ; var k : int ; k := 3 ; execute substringConversions(str, b, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); double m=sc.nextInt(); System.out.println(m*m*m*4/3*Math.PI); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : double ; m := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(m * m * m * 4 / 3 * 3.141592653589793) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); String pre="" ; int rst=0 ; String[] s=new String[4]; int[] u=new int[4]; ArrayListlist=new ArrayList(); ArrayListtime=new ArrayList(); for(int i=0 ; i=t){ list.add(s[1]); time.add(rst); } } pre=s[2]; } System.out.println(list.size()); for(int i=0 ; itoInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var pre : String ; pre := "" ; var rst : int ; rst := 0 ; var s : Sequence(String) ; s := Integer.subrange(1,4)->collect(null) ; var u : Sequence(int) ; u := Integer.subrange(1,4)->collect(0) ; var list : Sequence(String) ; list := Sequence{} ; var time : Sequence(int) ; time := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 4 do ( s[j+1] := sc.getCurrent() ; ; j := j + 1 ) ; if (i /= 0) then ( u[0+1] := (s[0+1].subrange(0+1,2))->toInteger() ; u[1+1] := (s[0+1].subrange(3+1,5))->toInteger() ; u[2+1] := (pre.subrange(0+1,2))->toInteger() ; u[3+1] := (pre.subrange(3+1,5))->toInteger() ; rst := (u[1+1] - u[3+1]) + (u[0+1] - u[2+1]) * 60 ; if (rst >= t) then ( list := list->including(s[1+1]) ; time := time->including(rst) ) else skip ; ) else skip ; pre := s[2+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(list->size()) ; var i : int ; i := 0 ; while i < list->size() do ( OclFile["System.out"].println(list->at(i+1) + " " + time->at(i+1)) ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int min(int x,int y,int z){ if(xmin() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cost : Sequence(Sequence(int)) ; cost := Sequence{Sequence{1,2,3},Sequence{4,8,2},Sequence{1,5,3}} ; OclFile["System.out"].print(minCost(cost, 2, 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.StringTokenizer ; public class prepformerge { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); ArrayList>lists=new ArrayList>(); int[] a=new int[n+1]; st=new StringTokenizer(br.readLine()); for(int i=1 ; i<=n ; i++){ a[i]=Integer.parseInt(st.nextToken()); } for(int i=1 ; i<=n ; i++){ if(i==1){ ArrayListstart=new ArrayList(); start.add(a[i]); lists.add(start); } else { int lo=0 ; int hi=lists.size()-1 ; if(lists.get(hi).get(lists.get(hi).size()-1)>a[i]){ ArrayListstart=new ArrayList(); start.add(a[i]); lists.add(start); } else { while(lo!=hi){ int mid=(lo+hi)/2 ; if(lists.get(mid).get(lists.get(mid).size()-1)lis : lists){ for(int i=0 ; itoInteger() ; var lists : Sequence(Sequence(int)) ; lists := Sequence{} ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( if (i = 1) then ( var start : Sequence(int) ; start := Sequence{} ; start := start->including(a[i+1]) ; lists := lists->including(start) ) else ( var lo : int ; lo := 0 ; var hi : int ; hi := lists->size() - 1 ; if (lists->at(hi+1)->at(lists->at(hi+1)->size() - 1+1) > a[i+1]) then ( var start : Sequence(int) ; start := Sequence{} ; start := start->including(a[i+1]) ; lists := lists->including(start) ) else ( while (lo /= hi) do ( var mid : int ; mid := (lo + hi) / 2 ; if (lists->at(mid+1)->at(lists->at(mid+1)->size() - 1+1) < a[i+1]) then ( hi := mid ) else ( lo := mid + 1 ) ) ; lists->at(lo+1)->excludes(a[i+1]) ) ) ) ; i := i + 1 ) ; for (lis : lists) do ( ( var i : int ; i := 0 ; while i < lis->size() do ( ( OclFile["System.out"].print(lis->at(i+1) + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int findgcd(int a,int b){ if(b==0)return a ; return findgcd(b,a % b); } static int minimumCuts(int a[],int n){ Arrays.sort(a); int gcd=a[1]-a[0]; int s=gcd ; for(int i=2 ; i0)gcd=findgcd(gcd,360-s); return(360/gcd)-n ; } public static void main(String[] args){ int[] arr=new int[] { 30,60,180 }; int n=arr.length ; System.out.println(minimumCuts(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findgcd( a : int, b : int) : int pre: true post: true activity: ( if (b = 0) then return a else skip ; return findgcd(b, a mod b) ); static operation minimumCuts( a : Sequence(int), n : int) : int pre: true post: true activity: ( a := a->sort() ; var gcd : int ; gcd := a[1+1] - a[0+1] ; var s : int ; s := gcd ; var i : int ; i := 2 ; while i < n do ( ( gcd := findgcd(gcd, a[i+1] - a[i - 1+1]) ; s := s+(a[i+1] - a[i - 1+1]) ) ; i := i + 1 ) ; if (360 - s > 0) then gcd := findgcd(gcd, 360 - s) ; else skip ; return (360 / gcd) - n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{30,60,180} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(minimumCuts(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isVowel(char ch){ if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true ; return false ; } static int lcs(String X,String Y,int m,int n){ int L[][]=new int[m+1][n+1]; int i,j ; for(i=0 ; i<=m ; i++){ for(j=0 ; j<=n ; j++){ if(i==0 || j==0)L[i][j]=0 ; else if((X.charAt(i-1)==Y.charAt(j-1))&& isVowel(X.charAt(i-1)))L[i][j]=L[i-1][j-1]+1 ; else L[i][j]=Math.max(L[i-1][j],L[i][j-1]); } } return L[m][n]; } public static void main(String[] args){ String X="aieef" ; String Y="klaief" ; int m=X.length(); int n=Y.length(); System.out.println("Length of LCS="+lcs(X,Y,m,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isVowel( ch : String) : boolean 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 ); static operation lcs( X : String, Y : String, m : int, n : int) : int pre: true post: true activity: ( var L : Sequence(Sequence(int)) ; L := Integer.subrange(1,m + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; var j : int ; i := 0 ; while i <= m do ( ( j := 0 ; while j <= n do ( ( if (i = 0 or j = 0) then L[i+1][j+1] := 0 ; else if ((X->at(i - 1+1) = Y->at(j - 1+1)) & isVowel(X->at(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() ; ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return L[m+1][n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var X : String ; X := "aieef" ; var Y : String ; Y := "klaief" ; var m : int ; m := X->size() ; var n : int ; n := Y->size() ; OclFile["System.out"].println("Length of LCS=" + lcs(X, Y, m, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Solve s=new Solve(); s.solve(); } } class Solve { Solve(){ } Scanner in=new Scanner(System.in); void solve(){ int n=in.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var c : int ; c := (if a mod b = 0 then b else a mod b endif) ; OclFile["System.out"].println(c) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,k,p ; n=sc.nextInt(); for(; n>0 ; n--){ k=sc.nextInt(); p=sc.nextInt(); k %=p ; if(k==0)k=p ; out.println(k); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var n : int ; var k : int ; var p : int ; n := sc.nextInt() ; while n > 0 do ( ( k := sc.nextInt() ; p := sc.nextInt() ; k := k mod p ; if (k = 0) then k := p ; else skip ; out.println(k) ; ) ; n := n - 1 ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); while(n-->0){ int a=scanner.nextInt(); int b=scanner.nextInt(); int ans=a % b ; System.out.println(ans==0 ? b : ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; var ans : int ; ans := a mod b ; OclFile["System.out"].println(if ans = 0 then b else ans endif) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(is); Integer num=Integer.parseInt(br.readLine()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < num do ( ( var str : String ; if ((str) /= null) then ( var sp : Sequence(String) ; sp := str->split(" ") ; var a : int ; a := (sp[0+1])->toInteger() ; var b : int ; b := (sp[1+1])->toInteger() ; if (a mod b = 0) then ( OclFile["System.out"].println(b) ) else ( OclFile["System.out"].println(a mod b) ) ) else skip ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import javax.xml.crypto.Data ; import java.math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] k=new int[n]; int[] p=new int[n]; for(int i=0 ; itoInteger() ; var k : Sequence(int) ; k := Integer.subrange(1,n)->collect(0) ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( k[i+1] := sc.getCurrent()->toInteger() ; p[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var s : int ; s := k[i+1] ; var now : int ; now := 0 ; while (s /= 0) do ( now := now mod p[i+1] ; now := now + 1 ; s := s - 1 ) ; OclFile["System.out"].println(now) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int q=scanner.nextInt(); int[] member=new int[n]; int m=0 ; int mn=0 ; for(int i=0 ; ia-1)){ mn=a-1 ; } else if(mtoInteger() ; var q : int ; q := scanner.getCurrent()->toInteger() ; var member : Sequence(int) ; member := Integer.subrange(1,n)->collect(0) ; var m : int ; m := 0 ; var mn : int ; mn := 0 ; var i : int ; i := 0 ; while i < q do ( ( var a : int ; a := scanner.getCurrent()->toInteger() ; var v : int ; v := scanner.getCurrent()->toInteger() ; member[a - 1+1] := member[a - 1+1]+(v) ; if (i = 0) then ( m := member[a - 1+1] ; mn := a - 1 ) else ( if (v < 0) then ( mn := most(member) ; m := member[mn+1] ) else if ((member[a - 1+1] = m) & (mn > a - 1)) then ( mn := a - 1 ) else if (m < member[a - 1+1]) then ( m := member[a - 1+1] ; mn := a - 1 ) else skip ; ; ) ; OclFile["System.out"].println((mn + 1) + " " + m) ; ) ; i := i + 1 ) ; ); static operation most( member : Sequence(int)) : int pre: true post: true activity: ( var m : int ; m := member[0+1] ; var n : int ; n := 0 ; var i : int ; i := 1 ; while i < member->size() do ( ( if (m < member[i+1]) then ( m := member[i+1] ; n := i ) else skip ) ; i := i + 1 ) ; return n ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashMap ; import java.util.PriorityQueue ; import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); void run(){ int n=sc.nextInt(); int q=sc.nextInt(); PriorityQueuepq=new PriorityQueue(); HashMapmap=new HashMap(); StringBuilder sb=new StringBuilder(); while(q-->0){ int num=sc.nextInt(); int get=sc.nextInt(); if(! map.containsKey(num)){ Pair p=new Pair(num,get); map.put(num,p); pq.add(p); } else { Pair del=map.get(num); map.remove(num); pq.remove(del); del.cnt+=get ; map.put(num,del); pq.add(del); } Pair max=pq.peek(); sb.append(max.num+" "+max.cnt+"\n"); } System.out.print(sb); } class Pair implements Comparable{ int num ; int cnt ; public Pair(int num,int cnt){ super(); this.num=num ; this.cnt=cnt ; } @ Override public int compareTo(Pair arg0){ if(this.cnt==arg0.cnt)return this.num-arg0.num ; return arg0.cnt-this.cnt ; } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var pq : Sequence(Map) ; pq := Sequence{} ; var map : Map(int,Map) ; map := Map{} ; var sb : String ; sb := StringLib.newString() ; while (q > 0) do ( q := q - 1 ; skip ; ( var num : int ; num := sc.getCurrent()->toInteger() ; var get : int ; get := sc.getCurrent()->toInteger() ; if (not(map->keys()->includes(num))) then ( var p : Map ; p := Map(num, get) ; map := map->union(Map{num |-> p}) ; pq := pq->including(p) ) else ( var del : Map ; del := map->at(num) ; map := map->antirestrict(Set{num}) ; pq := pq->excludingFirst(del) ; del.cnt := del.cnt+(get) ; map := map->union(Map{num |-> del}) ; pq := pq->including(del) ; ) ; var max : Map ; max := pq->min() ; sb := sb + StringLib.newString(max.num + " " + max.cnt + "\n") ; ) ; ) ; OclFile["System.out"].print(sb) ; ); class Pair implements Comparable { attribute num : int; attribute cnt : int; static operation newPair( num : int, cnt : int) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(num, cnt); return self ); operation initialise( num : int, cnt : int) : void pre: true post: true activity: ( execute super() ; self.num := num ; self.cnt := cnt ); operation compareTo( arg0 : Map) : int pre: true post: true activity: ( if (self.cnt = arg0.cnt) then return self.num - arg0.num else skip ; return arg0.cnt - self.cnt ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNextInt()){ int A=sc.nextInt(); int B=sc.nextInt(); System.out.printf("%.10f\n",B*B*B*Math.PI/3.0*4.0); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNextInt()) do ( var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; OclFile["System.out"].printf("%.10f\n", B * B * B * 3.141592653589793 / 3.0 * 4.0) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static float circlearea(double a,double b){ if(a<0 || b<0)return-1 ; float A=(float)((3.14*Math.pow(a,2)*Math.pow(b,2))/(4*(Math.pow(a,2)+Math.pow(b,2)))); return A ; } public static void main(String[] args){ float a=8,b=10 ; System.out.println(circlearea(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation circlearea( a : double, b : double) : double pre: true post: true activity: ( if (a < 0 or b < 0) then return -1 else skip ; var A : double ; A := ((3.14 * a->pow(2) * b->pow(2)) / (4 * (a->pow(2) + b->pow(2))))->oclAsType(double) ; return A ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 8 ; var b : double ; b := 10 ; OclFile["System.out"].println(circlearea(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.ArrayList ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] P_E=br.readLine().split(" "); int PlayerNum=Integer.parseInt(P_E[0]); int EventNum=Integer.parseInt(P_E[1]); int[] Fishes=new int[PlayerNum+1]; Arrays.fill(Fishes,0); int TopPlayerID=0 ; int TopPlayersFishes=0 ; for(int i=0 ; isplit(" ") ; var PlayerNum : int ; PlayerNum := (P_E[0+1])->toInteger() ; var EventNum : int ; EventNum := (P_E[1+1])->toInteger() ; var Fishes : Sequence(int) ; Fishes := Integer.subrange(1,PlayerNum + 1)->collect(0) ; Fishes := Fishes->collect(0) ; var TopPlayerID : int ; TopPlayerID := 0 ; var TopPlayersFishes : int ; TopPlayersFishes := 0 ; var i : int ; i := 0 ; while i < EventNum do ( ( var P_G : Sequence(String) ; P_G := br.readLine()->split(" ") ; var PlayerID : int ; PlayerID := (P_G[0+1])->toInteger() ; var GetFishNum : int ; GetFishNum := (P_G[1+1])->toInteger() ; Fishes[PlayerID+1] := Fishes[PlayerID+1]+(GetFishNum) ; if (TopPlayersFishes < Fishes[PlayerID+1]) then ( TopPlayerID := PlayerID ; TopPlayersFishes := Fishes[PlayerID+1] ) else if (TopPlayersFishes = Fishes[PlayerID+1]) then ( TopPlayerID := if PlayerID < TopPlayerID then PlayerID else TopPlayerID endif ) else ( if (TopPlayerID = PlayerID) then ( var MaxFishes : int ; MaxFishes := 0 ; var p : int ; p := 0 ; while p < Fishes->size() do ( ( if (MaxFishes < Fishes[p+1]) then ( MaxFishes := Fishes[p+1] ; TopPlayerID := p ) else if (MaxFishes = Fishes[p+1]) then ( TopPlayerID := if p < TopPlayerID then p else TopPlayerID endif ) else skip ; ) ; p := p + 1 ) ; TopPlayersFishes := MaxFishes ) else skip ) ; ; OclFile["System.out"].println(TopPlayerID + " " + TopPlayersFishes) ; ) ; i := i + 1 ) ; ); } class TopPlayer { attribute PlayerID : int; attribute Fishes : int; static operation newTopPlayer( InputID : int, InputFishes : int) : TopPlayer pre: true post: true activity: ( var self : TopPlayer ; self := createTopPlayer(); self.initialise(InputID, InputFishes); return self ); operation initialise( InputID : int, InputFishes : int) : void pre: true post: true activity: ( PlayerID := InputID ; Fishes := InputFishes ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class FishingData implements Comparable{ final int id ; int no ; FishingData(final int id){ this.id=id ; } FishingData(final int id,final int no){ this.id=id ; this.no=no ; } public int compareTo(FishingData fd){ if(no!=fd.no){ return no-fd.no ; } else { return fd.id-id ; } } } class MaxContainer { final TreeSetset ; final HashMapmap ; public MaxContainer(){ set=new TreeSet(); map=new HashMap(); } public FishingData getMaxData(){ return set.last(); } public void catchEvent(final int id,final int diff){ if(map.containsKey(id)){ final FishingData fd=map.get(id); set.remove(fd); fd.no+=diff ; set.add(fd); } else { final FishingData fd=new FishingData(id,diff); map.put(id,fd); set.add(fd); } } } class Main { public static void main(String[] args){ final Scanner stdin=new Scanner(System.in); final int n=stdin.nextInt(); final int q=stdin.nextInt(); MaxContainer mc=new MaxContainer(); for(int i=0 ; i { attribute id : int; attribute no : int; static operation newFishingData( id : int) : FishingData pre: true post: true activity: ( var self : FishingData ; self := createFishingData(); self.initialise(id); return self ); operation initialise( id : int) : void pre: true post: true activity: ( self.id := id ); static operation newFishingData( id : int, no : int) : FishingData pre: true post: true activity: ( var self : FishingData ; self := createFishingData(); self.initialise(id, no); return self ); operation initialise( id : int, no : int) : void pre: true post: true activity: ( self.id := id ; self.no := no ); operation compareTo( fd : FishingData) : int pre: true post: true activity: ( if (no /= fd.no) then ( return no - fd.no ) else ( return fd.id - id ) ); } class MaxContainer { attribute set : Set(FishingData); attribute map : Map(int,FishingData); static operation newMaxContainer() : MaxContainer pre: true post: true activity: ( var self : MaxContainer ; self := createMaxContainer(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( set := Set{} ; map := Map{} ); operation getMaxData() : FishingData pre: true post: true activity: ( return set->last() ); operation catchEvent( id : int, diff : int) : void pre: true post: true activity: ( if (map->keys()->includes(id)) then ( var fd : FishingData ; fd := map->at(id) ; set := set->excludingFirst(fd) ; fd.no := fd.no+(diff) ; set := set->including(fd) ) else ( var fd : FishingData ; fd := FishingData.newFishingData(id, diff) ; map := map->union(Map{id |-> fd}) ; set := set->including(fd) ) ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdin : OclFile ; stdin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := stdin.getCurrent()->toInteger() ; var q : int ; q := stdin.getCurrent()->toInteger() ; var mc : MaxContainer ; mc := MaxContainer.newMaxContainer() ; var i : int ; i := 0 ; while i < q do ( ( var id : int ; id := stdin.getCurrent()->toInteger() ; var vol : int ; vol := stdin.getCurrent()->toInteger() ; mc.catchEvent(id, vol) ; var maxFd : FishingData ; maxFd := mc.getMaxData() ; OclFile["System.out"].printf("%d %d\n", maxFd.id, maxFd.no) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private Scanner sc ; public static void main(String[] args){ new Main(); } public Main(){ sc=new Scanner(System.in); String[] nico=sc.nextLine().split(" "); int n=Integer.parseInt(nico[0]); int q=Integer.parseInt(nico[1]); int[] list=new int[n+1]; for(int i=0 ; ij)newno=j ; } else { tmp=list[j]; newno=j ; } } } max=tmp ; no=newno ; } if(max<=list[data[0] ]){ if(max==list[data[0] ]){ if(no>data[0])no=data[0]; } else { max=list[data[0] ]; no=data[0]; } } System.out.println(no+" "+max); } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var nico : Sequence(String) ; nico := sc.nextLine()->split(" ") ; var n : int ; n := (nico[0+1])->toInteger() ; var q : int ; q := (nico[1+1])->toInteger() ; var list : Sequence(int) ; list := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < list->size() do ( ( list[i+1] := 0 ) ; i := i + 1 ) ; var max : int ; max := 0 ; var no : int ; no := 1 ; var i : int ; i := 0 ; while i < q do ( ( var set : Sequence(String) ; set := sc.nextLine()->split(" ") ; var data : Sequence(int) ; data := Integer.subrange(1,set->size())->collect(0) ; var j : int ; j := 0 ; while j < set->size() do ( ( data[j+1] := (set[j+1])->toInteger() ) ; j := j + 1 ) ; list[data[0+1]+1] := list[data[0+1]+1] + data[1+1] ; if ((no = data[0+1]) & (data[1+1] < 0)) then ( var tmp : int ; tmp := list[data[0+1]+1] ; var newno : int ; newno := data[0+1] ; var j : int ; j := 1 ; while j < list->size() do ( ( if (tmp <= list[j+1]) then ( if (tmp = list[j+1]) then ( if (newno > j) then newno := j ; else skip ) else ( tmp := list[j+1] ; newno := j ) ) else skip ) ; j := j + 1 ) ; max := tmp ; no := newno ; ) else skip ; if (max <= list[data[0+1]+1]) then ( if (max = list[data[0+1]+1]) then ( if (no > data[0+1]) then no := data[0+1] ; else skip ) else ( max := list[data[0+1]+1] ; no := data[0+1] ) ) else skip ; OclFile["System.out"].println(no + " " + max) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int avg_of_even_num(int n){ int sum=0 ; for(int i=1 ; i<=n ; i++)sum+=2*i ; return(sum/n); } public static void main(String[] args){ int n=9 ; System.out.print(avg_of_even_num(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation avg_of_even_num( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( sum := sum+(2 * i) ; ; i := i + 1 ) ; return (sum / n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].print(avg_of_even_num(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GeeksforGeeks { static int sumOfDigits(long x){ int sum=0 ; while(x>0){ sum+=(x % 10); x/=10 ; } return sum ; } static void compute(long n){ long answer[]=new long[100]; int pos=0 ; for(int i=0 ; i<=100 ; i++){ long valueOnLeft=Math.abs(n-i)+sumOfDigits(Math.abs(n-i)); long valueOnRight=(n+i)+sumOfDigits(n+i); if(valueOnRight==n)answer[pos++]=(n+i); if(valueOnLeft==n)answer[pos++]=Math.abs(n-i); } if(pos==0)System.out.print(-1); else for(int i=0 ; i=0){ count++; } } System.out.println(count); } } public static int binarySearch(int[] nums,int get){ int ret=-1 ; int i=0 ; int j=nums.length-1 ; while(i<=j){ int c=(i+j)/2 ; if(nums[c]toInteger() ; while (t /= 0) do ( skip ; ( var size : int ; size := (bs.readLine())->toInteger() ; var ip : Sequence(String) ; ip := bs.readLine()->split(" ") ; var d : Sequence(int) ; d := Integer.subrange(1,size)->collect(0) ; var i : int ; i := 0 ; while i < size do ( ( d[i+1] := (ip[i+1])->toInteger() ) ; i := i + 1 ) ; d := d->sort() ; var count : long ; count := 0 ; for (i : d) do ( ( var ind : int ; ind := binarySearch(d, i) ; if (ind >= 0) then ( count := count + 1 ) else skip ) ) ; OclFile["System.out"].println(count) ; ) ; ) ); static operation binarySearch( nums : Sequence(int), get : int) : int pre: true post: true activity: ( var ret : int ; ret := -1 ; var i : int ; i := 0 ; var j : int ; j := nums->size() - 1 ; while (i <= j) do ( var c : int ; c := (i + j) / 2 ; if (nums[c+1] < get) then ( ret := c ; i := c + 1 ) else ( j := c - 1 ) ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { public static void main(String[] args)throws Exception { Scanner scan=new Scanner(System.in); int T=scan.nextInt(); while(T--!=0){ int n=scan.nextInt(); int freq[]=new int[101]; int min=Integer.MAX_VALUE ; for(int i=0 ; itoInteger() ; while (T /= 0) do ( skip ; ( var n : int ; n := scan.getCurrent()->toInteger() ; var freq : Sequence(int) ; freq := Integer.subrange(1,101)->collect(0) ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( var tmp : int ; tmp := scan.getCurrent()->toInteger() ; freq[tmp - 1+1] := freq[tmp - 1+1] + 1 ; min := Set{min, tmp}->min() ) ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i <= 100 do ( ( if (min /= (i + 1)) then ( res := res+(freq[i+1]) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class test269 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var sum : int ; sum := n - 1 ; var i : int ; i := 1 ; while i < n & a[i+1] = a[0+1] do ( ( sum := sum - 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class test177 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var sum : int ; sum := 1 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var p : int ; p := a[0+1] ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] /= p) then ( sum := sum + 1 ) else skip ; p := a[i+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Copy { int number ; HashMapmap=new HashMap<>(); public Copy(int number){ this.number=number ; } public int getNumber(){ return number ; } public void input(int number){ if(map.get(number)==null){ map.put(number,1); } } public void printResult(){ System.out.println(map.size()); map.clear(); } public static void main(String[] a){ Scanner input=new Scanner(System.in); int number=input.nextInt(); Copy instance=new Copy(number); for(int i=0 ; iat(number) = null) then ( map := map->union(Map{number |-> 1}) ) else skip ); operation printResult() : void pre: true post: true activity: ( OclFile["System.out"].println(map.size()) ; map := map->intersection(Map{}) ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : Copy ; instance := Copy.newCopy(number) ; var i : int ; i := 0 ; while i < instance.getNumber() do ( ( var num : int ; num := input.getCurrent()->toInteger() ; var k : int ; k := 0 ; while k < num do ( ( var n : int ; n := input.getCurrent()->toInteger() ; instance.input(n) ) ; k := k + 1 ) ; instance.printResult() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void find(int[] arr,int length,int s){ for(int i=1 ; i<=(Math.pow(2,length)); i++){ int sum=0 ; for(int j=0 ; j>j)& 1)% 2==1)sum+=arr[j]; if(sum==s){ System.out.println("YES"); return ; } } System.out.println("NO"); } public static void main(String[] args){ int sum=5 ; int[] array={ -1,2,4,121 }; int length=array.length ; find(array,length,sum); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation find( arr : Sequence(int), length : int, s : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= (2->pow(length)) do ( ( var sum : int ; sum := 0 ; var j : int ; j := 0 ; while j < length do ( if ((((i/(2->pow(j)))->oclAsType(long)) & 1) mod 2 = 1) then sum := sum+(arr[j+1]) ; else skip ; ; j := j + 1 ) ; if (sum = s) then ( OclFile["System.out"].println("YES") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("NO") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sum : int ; sum := 5 ; var array : Sequence(int) ; array := Sequence{-1,2,4,121} ; var length : int ; length := array->size() ; execute find(array, length, sum) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CopyCopyCopy { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); HashSethash=new LinkedHashSet(); for(int i=0 ; itoInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var hash : Set(int) ; hash := Set{} ; var i : int ; i := 0 ; while i < n do ( ( hash := hash->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; OclFile["System.out"].println(hash->size()) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1325B_CopyCopyCopyCopy { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ int amount=parseInt(input.nextLine()); Setset=new HashSet<>(); for(int i=0 ; i 0) do ( test := test - 1 ; skip ; ( var amount : int ; amount := parseInt(input.nextLine()) ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < amount do ( ( set := set->including(input.getCurrent()->toInteger()) ) ; i := i + 1 ) ; skip ; OclFile["System.out"].println(set->size()) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class NewClass56 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int a=in.nextInt(); long x[]=new long[a]; SetdistinsitElement=new HashSet<>(); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : int ; a := in.getCurrent()->toInteger() ; var x : Sequence(long) ; x := Integer.subrange(1,a)->collect(0) ; var distinsitElement : Set(long) ; distinsitElement := Set{} ; var i : int ; i := 0 ; while i < a do ( ( x[i+1] := in.getCurrent()->toInteger() ; distinsitElement := distinsitElement->including(x[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(distinsitElement->size()) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=Integer.parseInt(in.next()); ListA=new ArrayList<>(); for(int i=0 ; ilower=(x,y)->x.compareTo(y)>=0 ? 1 :-1 ; Comparatorupper=(x,y)->x.compareTo(y)>0 ? 1 :-1 ; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Sequence{} ; var i : int ; i := 0 ; while i < n do ( A := A->including((in.getCurrent())->toInteger()) ; ; i := i + 1 ) ; var q : int ; q := (in.getCurrent())->toInteger() ; var lower : Function(,(,boolean)) ; lower := lambda (x , y) : OclAny in if x->compareTo(y) >= 0 then 1 else -1 endif ; var upper : Function(,(,boolean)) ; upper := lambda (x , y) : OclAny in if x->compareTo(y) > 0 then 1 else -1 endif ; var i : int ; i := 0 ; while i < q do ( ( var key : int ; key := (in.getCurrent())->toInteger() ; skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int n=sc.nextInt(); long[] array=new long[n]; for(int i=0 ; iarray[n-1])System.out.println(n+" "+n); else { System.out.println(lowerBound(array,k)+" "+upperBound(array,k)); } } } } static int lowerBound(long[] array,long target){ int low=0 ; int high=array.length-1 ; while(lowtoInteger() ; var array : Sequence(long) ; array := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( array[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var query : int ; query := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < query do ( ( var k : long ; k := sc.getCurrent()->toLong() ; if (k > array[n - 1+1]) then OclFile["System.out"].println(n + " " + n) ; else ( OclFile["System.out"].println(lowerBound(array, k) + " " + upperBound(array, k)) ) ) ; i := i + 1 ) ; )) ); static operation lowerBound( array : Sequence(long), target : long) : int pre: true post: true activity: ( var low : int ; low := 0 ; var high : int ; high := array->size() - 1 ; while (low < high) do ( var mid : int ; mid := (high + low) / 2 ; if (array[mid+1] = target) then ( while ((mid /= 0) & (array[mid - 1+1] = target)) do mid := mid - 1 ; ; return mid ) else if (array[mid+1] < target) then low := mid + 1 else high := mid ; ; ) ; while ((high /= 0) & (array[high - 1+1] = array[high+1])) do high := high - 1 ; ; return high ); static operation upperBound( array : Sequence(long), target : long) : int pre: true post: true activity: ( var low : int ; low := 0 ; var high : int ; high := array->size() - 1 ; if (array[high+1] <= target) then return array->size() else skip ; while (low < high) do ( var mid : int ; mid := (high + low) / 2 ; if (array[mid+1] <= target) then low := mid + 1 ; else high := mid ; ) ; while ((high /= 0) & (array[high - 1+1] = array[high+1])) do high := high - 1 ; ; return high ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ int i,j,n,q,k,lower_bound,upper_bound ; try(Scanner sc=new Scanner(System.in)){ n=sc.nextInt(); int[] a=new int[n+1]; for(i=0 ; in){ lower_bound=n ; } upper_bound=lower_bound ; } else { upper_bound=lower_bound ; while(lower_bound>=1){ if(a[lower_bound]!=a[lower_bound-1]){ break ; } lower_bound--; } while(upper_bound<=n-1){ if(a[upper_bound]!=a[upper_bound+1]){ upper_bound++; break ; } upper_bound++; } } System.out.println(lower_bound+" "+upper_bound); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var j : int ; var n : int ; var q : int ; var k : int ; var lower_bound : int ; var upper_bound : int ; try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; q := sc.getCurrent()->toInteger() ; i := 0 ; while i < q do ( ( k := sc.getCurrent()->toInteger() ; lower_bound := (a->indexOf(k) - 1) ; if (lower_bound < 0) then ( lower_bound := -lower_bound - 1 ; if (lower_bound > n) then ( lower_bound := n ) else skip ; upper_bound := lower_bound ) else ( upper_bound := lower_bound ; while (lower_bound >= 1) do ( if (a[lower_bound+1] /= a[lower_bound - 1+1]) then ( break ) else skip ; lower_bound := lower_bound - 1 ) ; while (upper_bound <= n - 1) do ( if (a[upper_bound+1] /= a[upper_bound + 1+1]) then ( upper_bound := upper_bound + 1 ; break ) else skip ; upper_bound := upper_bound + 1 ) ) ; OclFile["System.out"].println(lower_bound + " " + upper_bound) ) ; i := i + 1 ) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static StringBuilder sb ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); sb=new StringBuilder(); int num=sc.nextInt(); ArrayListarray=new ArrayList<>(); for(int i=0 ; ilist,int key){ int lower=-1 ; int middle=-1 ; int upper=list.size(); while(upper>lower+1){ middle=lower+(upper-lower)/2 ; if(list.get(middle)>key-1)upper=middle ; else lower=middle ; } return upper ; } public static int UpperBound(Listlist,int key){ int lower=-1 ; int middle=-1 ; int upper=list.size(); while(upper>lower+1){ middle=lower+(upper-lower)/2 ; if(list.get(middle)>key)upper=middle ; else lower=middle ; } return upper ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sb : String; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; sb := StringLib.newString() ; var num : int ; num := sc.getCurrent()->toInteger() ; var array : Sequence(int) ; array := Sequence{} ; var i : int ; i := 0 ; while i < num do ( ( array := array->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var query : int ; query := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < query do ( ( var key : int ; key := sc.getCurrent()->toInteger() ; var lower_bound : int ; lower_bound := LowerBound(array, key) ; if (lower_bound < 0) then sb := sb + StringLib.newString(num) + StringLib.newString(" ") else sb := sb + StringLib.newString(lower_bound) + StringLib.newString(" ") ; ; var upper_bound : int ; upper_bound := UpperBound(array, key) ; if (upper_bound < 0) then sb := sb + StringLib.newString(num) + StringLib.newString("\n") else sb := sb + StringLib.newString(upper_bound) + StringLib.newString("\n") ; ; ) ; i := i + 1 ) ; OclFile["System.out"].print(sb) ; skip ; ); static operation LowerBound( list : Sequence(int), key : int) : int pre: true post: true activity: ( var lower : int ; lower := -1 ; var middle : int ; middle := -1 ; var upper : int ; upper := list->size() ; while (upper > lower + 1) do ( middle := lower + (upper - lower) / 2 ; if (list->at(middle+1) > key - 1) then upper := middle ; else lower := middle ; ) ; return upper ); static operation UpperBound( list : Sequence(int), key : int) : int pre: true post: true activity: ( var lower : int ; lower := -1 ; var middle : int ; middle := -1 ; var upper : int ; upper := list->size() ; while (upper > lower + 1) do ( middle := lower + (upper - lower) / 2 ; if (list->at(middle+1) > key) then upper := middle ; else lower := middle ; ) ; return upper ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); int[] a=new int[n+1]; a[0]=-1000000001 ; str=br.readLine().split(" "); for(int i=0 ; i1){ int mid=lb+(ub-lb)/2 ; if(a[mid]>=k)ub=mid ; else lb=mid ; } System.out.print((ub-1)+" "); lb=0 ; ub=n+1 ; while(ub-lb>1){ int mid=lb+(ub-lb)/2 ; if(a[mid]>k)ub=mid ; else lb=mid ; } System.out.println(ub-1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; a[0+1] := -1000000001 ; str := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( a[i + 1+1] := (str[i+1])->toInteger() ; ; i := i + 1 ) ; str := br.readLine()->split(" ") ; var q : int ; q := (str[0+1])->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( str := br.readLine()->split(" ") ; var k : int ; k := (str[0+1])->toInteger() ; var lb : int ; lb := 0 ; var ub : int ; ub := n + 1 ; while (ub - lb > 1) do ( var mid : int ; mid := lb + (ub - lb) / 2 ; if (a[mid+1] >= k) then ub := mid ; else lb := mid ; ) ; OclFile["System.out"].print((ub - 1) + " ") ; lb := 0 ; ub := n + 1 ; while (ub - lb > 1) do ( var mid : int ; mid := lb + (ub - lb) / 2 ; if (a[mid+1] > k) then ub := mid ; else lb := mid ; ) ; OclFile["System.out"].println(ub - 1) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void countFreq(int[] a,int n){ HashMaphm=new HashMap<>(); for(int i=0 ; ist=new TreeMap<>(); for(HashMap.Entryx : hm.entrySet()){ st.put(x.getKey(),x.getValue()); } int cumul=0 ; for(SortedMap.Entryx : st.entrySet()){ cumul+=x.getValue(); System.out.println(x.getKey()+" "+cumul); } } public static void main(String[] args){ int[] a={ 1,3,2,4,2,1 }; int n=a.length ; countFreq(a,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countFreq( a : Sequence(int), n : int) : void pre: true post: true activity: ( var hm : Map(int,int) ; hm := Map{} ; var i : int ; i := 0 ; while i < n do ( hm := hm->union(Map{a[i+1] |-> if hm->at(a[i+1]) = null then 1 else hm->at(a[i+1]) + 1 endif}) ; ; i := i + 1 ) ; var st : Map(int,int) ; st := Map{} ; for (x : hm->asSet()) do ( ( st := st->union(Map{x.getKey() |-> x.getValue()}) ) ) ; var cumul : int ; cumul := 0 ; for (x : st->asSet()) do ( ( cumul := cumul+(x.getValue()) ; OclFile["System.out"].println(x.getKey() + " " + cumul) ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,3,2,4,2,1} ; var n : int ; n := a->size() ; execute countFreq(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static String K_String(String s,int k){ int n=s.length(); int fre[]=new int[26]; for(int i=0 ; isize() ; var fre : Sequence(int) ; fre := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < n do ( fre[s->at(i+1) - ('a')->char2byte()+1] := fre[s->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var str : String ; str := "" ; var i : int ; i := 0 ; while i < 26 do ( ( if (fre[i+1] mod k = 0) then ( var x : int ; x := fre[i+1] / k ; while (x /= 0) do ( str := str+((i + 'a')->oclAsType(String)) ; x := x - 1 ) ) else ( return "-1" ) ) ; i := i + 1 ) ; return str ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "aabb" ; var k : int ; k := 2 ; OclFile["System.out"].println(K_String(s, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] h=new int[n]; for(int i=0 ; i0 ; i--){ if(h[i-1]>=h[i]){ count++; } else { if(count>max){ max=count ; } count=0 ; } } if(count>max){ max=count ; } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( h[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var count : int ; count := 0 ; var max : int ; max := 0 ; var i : int ; i := n - 1 ; while i > 0 do ( ( if (h[i - 1+1] >= h[i+1]) then ( count := count + 1 ) else ( if (count > max) then ( max := count ) else skip ; count := 0 ) ) ; i := i - 1 ) ; if (count > max) then ( max := count ) else skip ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s1=sc.next(); String s2=sc.next(); String s3=sc.next(); if(s1.equals("rock")&& s2.equals("scissors")&& s2.equals(s3)){ System.out.println("F"); } else if(s1.equals("paper")&& s2.equals("rock")&& s2.equals(s3)){ System.out.println("F"); } else if(s1.equals("scissors")&& s2.equals("paper")&& s2.equals(s3)){ System.out.println("F"); } else if(s2.equals("rock")&& s1.equals("scissors")&& s1.equals(s3)){ System.out.println("M"); } else if(s2.equals("paper")&& s1.equals("rock")&& s1.equals(s3)){ System.out.println("M"); } else if(s2.equals("scissors")&& s1.equals("paper")&& s1.equals(s3)){ System.out.println("M"); } else if(s3.equals("rock")&& s2.equals("scissors")&& s2.equals(s1)){ System.out.println("S"); } else if(s3.equals("paper")&& s2.equals("rock")&& s2.equals(s1)){ System.out.println("S"); } else if(s3.equals("scissors")&& s2.equals("paper")&& s2.equals(s1)){ System.out.println("S"); } else System.out.println("?"); } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; var s3 : String ; s3 := sc.getCurrent() ; if (s1 = "rock" & s2 = "scissors" & s2 = s3) then ( OclFile["System.out"].println("F") ) else if (s1 = "paper" & s2 = "rock" & s2 = s3) then ( OclFile["System.out"].println("F") ) else if (s1 = "scissors" & s2 = "paper" & s2 = s3) then ( OclFile["System.out"].println("F") ) else if (s2 = "rock" & s1 = "scissors" & s1 = s3) then ( OclFile["System.out"].println("M") ) else if (s2 = "paper" & s1 = "rock" & s1 = s3) then ( OclFile["System.out"].println("M") ) else if (s2 = "scissors" & s1 = "paper" & s1 = s3) then ( OclFile["System.out"].println("M") ) else if (s3 = "rock" & s2 = "scissors" & s2 = s1) then ( OclFile["System.out"].println("S") ) else if (s3 = "paper" & s2 = "rock" & s2 = s1) then ( OclFile["System.out"].println("S") ) else if (s3 = "scissors" & s2 = "paper" & s2 = s1) then ( OclFile["System.out"].println("S") ) else OclFile["System.out"].println("?") ; ; ; ; ; ; ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdin=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int N=Integer.parseInt(stdin.next()); int H[]=new int[N]; int max=0 ; int cnt=0 ; for(int i=0 ; i=H[i+1]){ cnt+=1 ; } else if(H[i]toInteger() ; var H : Sequence(int) ; H := Integer.subrange(1,N)->collect(0) ; var max : int ; max := 0 ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < N do ( ( H[i+1] := (stdin.getCurrent())->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( if (H[i+1] >= H[i + 1+1]) then ( cnt := cnt+(1) ) else if (H[i+1] < H[i + 1+1]) then ( if (max < cnt) then ( max := cnt ) else skip ; cnt := 0 ) else skip ; ) ; i := i + 1 ) ; if (max < cnt) then ( max := cnt ) else skip ; OclFile["System.out"].println(max) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int ans=0 ; int N=sc.nextInt(); long now=sc.nextLong(); long next=0 ; int moveNow=0 ; int moveMax=0 ; for(int i=1 ; i=next){ moveNow++; } else { if(moveMaxtoInteger() ; var now : long ; now := sc.getCurrent()->toLong() ; var next : long ; next := 0 ; var moveNow : int ; moveNow := 0 ; var moveMax : int ; moveMax := 0 ; var i : int ; i := 1 ; while i < N do ( ( next := sc.getCurrent()->toLong() ; if (now >= next) then ( moveNow := moveNow + 1 ) else ( if (moveMax < moveNow) then ( moveMax := moveNow ) else skip ; moveNow := 0 ) ; now := next ) ; i := i + 1 ) ; if (moveMax < moveNow) then ( moveMax := moveNow ) else skip ; OclFile["System.out"].println(moveMax) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int ans=0 ; int curH=-1 ; int curMax=0 ; while(N-->0){ int nextH=sc.nextInt(); if(curH>=nextH){ ans++; } else { curMax=Math.max(curMax,ans); ans=0 ; } curH=nextH ; } curMax=Math.max(curMax,ans); System.out.println(curMax); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var curH : int ; curH := -1 ; var curMax : int ; curMax := 0 ; while (N > 0) do ( N := N - 1 ; skip ; ( var nextH : int ; nextH := sc.getCurrent()->toInteger() ; if (curH >= nextH) then ( ans := ans + 1 ) else ( curMax := Set{curMax, ans}->max() ; ans := 0 ) ; curH := nextH ) ; ) ; curMax := Set{curMax, ans}->max() ; OclFile["System.out"].println(curMax) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GfG { static int checkBit(int pattern,int arr[],int n){ int count=0 ; for(int i=0 ; i=0 ; bit--){ count=checkBit(res |(1<=2)res |=(1<size() ; var n2 : int ; n2 := str2->size() ; if (n1 /= n2) then return false else skip ; var ch1 : Sequence(String) ; ch1 := str1->characters() ; var ch2 : Sequence(String) ; ch2 := str2->characters() ; ch1 := ch1->sort() ; ch2 := ch2->sort() ; var i : int ; i := 0 ; while i < n1 do ( if (ch1[i+1] /= ch2[i+1]) then return false else skip ; ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str1 : String ; str1 := "test" ; var str2 : String ; str2 := "ttew" ; if (arePermutation(str1, str2)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true){ int n=Integer.parseInt(br.readLine()); if(n==0){ break ; } String[] tmpArray=br.readLine().split(" "); final int OFF=0 ; final int ON=1 ; int position=OFF ; int right=OFF ; int left=OFF ; int count=0 ; for(int i=0 ; itoInteger() ; if (n = 0) then ( break ) else skip ; var tmpArray : Sequence(String) ; tmpArray := br.readLine()->split(" ") ; var OFF : int ; OFF := 0 ; var ON : int ; ON := 1 ; var position : int ; position := OFF ; var right : int ; right := OFF ; var left : int ; left := OFF ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var com : String ; com := tmpArray[i+1] ; if (com = "lu") then ( left := ON ) else skip ; if (com = "ld") then ( left := OFF ) else skip ; if (com = "ru") then ( right := ON ) else skip ; if (com = "rd") then ( right := OFF ) else skip ; if (left = right & left /= position) then ( position := left ; count := count + 1 ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; import java.util.stream.Stream ; public class Main { public enum pattern { lu,ru,ld,rd,; } static Scanner scan=new Scanner(System.in); public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine().trim())!=null && ! "0".equals(line)){ int ans=0 ; String[] input=line.split(" "); if(Stream.of(pattern.values()).map(e->e.name()).anyMatch(code->code.equals(input[0]))){ for(int i=0 ; itrim() ; while ((line) /= null & not("0" = line)) do ( skip ; ( var ans : int ; ans := 0 ; var input : Sequence(String) ; input := line->split(" ") ; if (Sequence{pattern.allInstances()}->collect( _x1 | (lambda e : OclAny in e.name())->apply(_x1) )->exists( _x2 | (lambda code : OclAny in code = input[0+1])->apply(_x2) )) then ( var i : int ; i := 0 ; while i < input->size() do ( ( if (i < input->size() - 1 & input[i+1].subrange(1+1,1) = "u" = input[i + 1+1].subrange(1+1,1) = "u") then ans := ans + 1 ; else skip ; if (i < input->size() - 1 & input[i+1].subrange(1+1,1) = "d" = input[i + 1+1].subrange(1+1,1) = "d") then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans / 2) ) else skip ) ; line := br.readLine()->trim() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Collections ; import java.util.HashMap ; import java.util.PriorityQueue ; import java.util.Scanner ; import javax.xml.crypto.Data ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0)break ; double[][] dp=new double[n+1][25]; dp[0][0]=1.0 ; double sum=0 ; for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; var dp : Sequence(Sequence(double)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,25)->collect(0.0)) ; dp[0+1][0+1] := 1.0 ; var sum : double ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 24 do ( ( var pp : double ; pp := 2.0->pow(j) ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1]+(dp[i+1][j+1] * 1.0 / pp) ; dp[i + 1+1][0+1] := dp[i + 1+1][0+1]+(dp[i+1][j+1] * (1.0 - (1.0 / pp))) ; sum := sum+(j * dp[i+1][j+1] * (1.0 - (1.0 / pp))) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < 25 do ( ( sum := sum+(j * dp[n+1][j+1]) ) ; j := j + 1 ) ; OclFile["System.out"].printf("%.20f\n", sum) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int l,r,count,n,ud ; String f ; for(; ; ){ n=sc.nextInt(); if(n==0)break ; count=0 ; l=0 ; r=0 ; ud=0 ; for(; n-->0 ; ){ f=sc.next(); if("lu".equals(f)){ if(ud==0 && l==0 && r==1){ count++; ud=1 ; } l=1 ; } else if("ru".equals(f)){ if(ud==0 && l==1 && r==0){ count++; ud=1 ; } r=1 ; } else if("ld".equals(f)){ if(ud==1 && l==1 && r==0){ count++; ud=0 ; } l=0 ; } else { if(ud==1 && l==0 && r==1){ count++; ud=0 ; } r=0 ; } } out.println(count); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var l : int ; var r : int ; var count : int ; var n : int ; var ud : int ; var f : String ; while true do ( ( n := sc.nextInt() ; if (n = 0) then break else skip ; count := 0 ; l := 0 ; r := 0 ; ud := 0 ; while n > 0 do ( ( f := sc.next() ; if ("lu" = f) then ( if (ud = 0 & l = 0 & r = 1) then ( count := count + 1 ; ud := 1 ) else skip ; l := 1 ) else if ("ru" = f) then ( if (ud = 0 & l = 1 & r = 0) then ( count := count + 1 ; ud := 1 ) else skip ; r := 1 ) else if ("ld" = f) then ( if (ud = 1 & l = 1 & r = 0) then ( count := count + 1 ; ud := 0 ) else skip ; l := 0 ) else ( if (ud = 1 & l = 0 & r = 1) then ( count := count + 1 ; ud := 0 ) else skip ; r := 0 ) ; ; ) ) ; out.println(count) ; ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Spliterator ; import java.util.Spliterators ; import java.util.concurrent.ThreadLocalRandom ; import java.util.concurrent.atomic.AtomicInteger ; import java.util.stream.IntStream ; import java.util.stream.Stream ; import java.util.stream.StreamSupport ; public class Main { static final Scanner s=new Scanner(System.in); static final long[] fal_rnd(int size){ AtomicInteger l=new AtomicInteger(-1),r=new AtomicInteger(size); long[] res=new long[size]; INS(size).unordered().parallel().mapToLong(Long :: parseLong).forEach(v->res[ThreadLocalRandom.current().nextBoolean()? l.incrementAndGet(): r.decrementAndGet()]=v); return res ; } static final IntStream REPS(int v){ return IntStream.range(0,v); } static final StreamINS(long size){ return StreamSupport.stream(Spliterators.spliterator(s,size,Spliterator.NONNULL & Spliterator.IMMUTABLE),false).limit(size); } public static void main(String __[]){ int n ; while(true){ n=s.nextInt(); if(n==0)return ; s.nextLine(); String in=s.nextLine().replaceAll("[rl] ","").replaceAll("(uu|dd)","#").replaceAll("[^#] ",""); System.out.println(in.length()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation fal_rnd( size : int) : Sequence(long) pre: true post: true activity: ( var l : int ; l := (-1) ; var r : int ; r := (size) ; var res : Sequence(long) ; res := Integer.subrange(1,size)->collect(0) ; for v : INS(size)->collect( _x1 | (lambda _s : String in _s->toLong())->apply(_x1) ) do ( res[if MathLib.nextBoolean() then l+1 else r-1 endif+1] := v) ; return res ); static operation REPS( v : int) : Sequence(int) pre: true post: true activity: ( return Integer.subrange(0, v-1) ); static operation INS( size : long) : Stream pre: true post: true activity: ( return (OclIterator.newOclIterator_Sequence(s)).elements.subrange(1,size) ); static operation main( __ : Sequence(String)) : void pre: true post: true activity: ( var n : int ; while (true) do ( n := s.getCurrent()->toInteger() ; if (n = 0) then return else skip ; skip ; var in : String ; in := s.nextLine().replaceAllMatches("[rl] ", "" ).replaceAllMatches("(uu|dd)", "#" ).replaceAllMatches("[^#] ", "" ) ; OclFile["System.out"].println(in->size()) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MyClass { public static void main(String args[]){ Scanner in=new Scanner(System.in); String F=in.next(); String M=in.next(); String S=in.next(); int rock=(F.equals("rock")? 1 : 0)+(M.equals("rock")? 1 : 0)+(S.equals("rock")? 1 : 0); int paper=(F.equals("paper")? 1 : 0)+(M.equals("paper")? 1 : 0)+(S.equals("paper")? 1 : 0); int scissors=(F.equals("scissors")? 1 : 0)+(M.equals("scissors")? 1 : 0)+(S.equals("scissors")? 1 : 0); String winner="?" ; if(rock==2 && paper==1){ if(F.equals("paper")){ winner="F" ; } else if(M.equals("paper")){ winner="M" ; } else if(S.equals("paper")){ winner="S" ; } } else if(paper==2 && scissors==1){ if(F.equals("scissors")){ winner="F" ; } else if(M.equals("scissors")){ winner="M" ; } else if(S.equals("scissors")){ winner="S" ; } } else if(scissors==2 && rock==1){ if(F.equals("rock")){ winner="F" ; } else if(M.equals("rock")){ winner="M" ; } else if(S.equals("rock")){ winner="S" ; } } System.out.println(winner); } } ------------------------------------------------------------ OCL File: --------- class MyClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var F : String ; F := in.getCurrent() ; var M : String ; M := in.getCurrent() ; var S : String ; S := in.getCurrent() ; var rock : int ; rock := (if F = "rock" then 1 else 0 endif) + (if M = "rock" then 1 else 0 endif) + (if S = "rock" then 1 else 0 endif) ; var paper : int ; paper := (if F = "paper" then 1 else 0 endif) + (if M = "paper" then 1 else 0 endif) + (if S = "paper" then 1 else 0 endif) ; var scissors : int ; scissors := (if F = "scissors" then 1 else 0 endif) + (if M = "scissors" then 1 else 0 endif) + (if S = "scissors" then 1 else 0 endif) ; var winner : String ; winner := "?" ; if (rock = 2 & paper = 1) then ( if (F = "paper") then ( winner := "F" ) else if (M = "paper") then ( winner := "M" ) else if (S = "paper") then ( winner := "S" ) else skip ; ; ) else if (paper = 2 & scissors = 1) then ( if (F = "scissors") then ( winner := "F" ) else if (M = "scissors") then ( winner := "M" ) else if (S = "scissors") then ( winner := "S" ) else skip ; ; ) else if (scissors = 2 & rock = 1) then ( if (F = "rock") then ( winner := "F" ) else if (M = "rock") then ( winner := "M" ) else if (S = "rock") then ( winner := "S" ) else skip ; ; ) else skip ; ; ; OclFile["System.out"].println(winner) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); for(; ; ){ int input_num=sc.nextInt(); if(input_num==0)break ; int count=0 ; Liststep_list=new ArrayList(); for(int i=0 ; itoInteger() ; if (input_num = 0) then break else skip ; var count : int ; count := 0 ; var step_list : Sequence(String) ; step_list := Sequence{} ; var i : int ; i := 0 ; while i < input_num do ( ( step_list := step_list->including(sc.getCurrent()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < input_num - 1 do ( ( var step : String ; step := step_list->at(i+1) ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (step) ; if _switchval = "lu" then if (step_list->at(i + 1+1) = "ru") then count := count + 1 ; else skip ; break else skip ; if _switchval = "ru" then if (step_list->at(i + 1+1) = "lu") then count := count + 1 ; else skip ; break else skip ; if _switchval = "ld" then if (step_list->at(i + 1+1) = "rd") then count := count + 1 ; else skip ; break else skip ; if _switchval = "rd" then if (step_list->at(i + 1+1) = "ld") then count := count + 1 ; else skip ; break else skip ; ) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),w=sc.nextInt(); int a[]=new int[2*n]; for(int i=0 ; i<2*n ; ++i)a[i]=sc.nextInt(); Arrays.sort(a); long ans=Math.min(3L*Math.min(a[0]*2,a[n])*n,2*w); System.out.printf("%.15g\n",ans/2.0); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,2 * n)->collect(0) ; var i : int ; i := 0 ; while i < 2 * n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; a := a->sort() ; var ans : long ; ans := Set{3L * Set{a[0+1] * 2, a[n+1]}->min() * n, 2 * w}->min() ; OclFile["System.out"].printf("%.15g\n", ans / 2.0) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import com.sun.org.apache.bcel.internal.generic.AALOAD ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; import java.util.stream.IntStream ; import javafx.util.Pair ; public class Main { static void sort(double a[]){ Random ran=new Random(); for(int i=0 ; iw){ System.out.printf("%.6f\n",w); } else { System.out.printf("%.6f\n",total); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation sort( a : Sequence(double)) : void pre: true post: true activity: ( var ran : OclRandom ; ran := OclRandom.newOclRandom() ; var i : int ; i := 0 ; while i < a->size() do ( ( var r : int ; r := ran.nextInt(a->size()) ; var temp : double ; temp := a[r+1] ; a[r+1] := a[i+1] ; a[i+1] := temp ) ; i := i + 1 ) ; a := a->sort() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var w : double ; w := input.getCurrent()->toInteger() ; var a : Sequence(double) ; a := Integer.subrange(1,n * 2)->collect(0.0) ; var i : int ; i := 0 ; while i < n * 2 do ( ( a[i+1] := input.getCurrent()->toReal() ) ; i := i + 1 ) ; execute sort(a) ; var min : double ; min := Set{a[0+1], (a[n+1] / 2.0)}->min() ; var total : double ; total := ((min * n) + (min * 2) * n) ; if (total > w) then ( OclFile["System.out"].printf("%.6f\n", w) ) else ( OclFile["System.out"].printf("%.6f\n", total) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.util.Arrays ; import java.util.Scanner ; import java.util.StringTokenizer ; public class p021 { public static void main(String args[])throws Exception { StringTokenizer stok=new StringTokenizer(new Scanner(System.in).useDelimiter("\\A").next()); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(stok.nextToken()); int w=Integer.parseInt(stok.nextToken()); int[] a=new int[2*n]; for(int i=0 ; i<2*n ; i++){ a[i]=Integer.parseInt(stok.nextToken()); } Arrays.sort(a); int v1=a[0],v2=a[n]; double v=(v2>2*v1)?(double)v1 : v2/(double)2 ; v=v*3*n ; if(v>w)v=w ; System.out.println(v); } } ------------------------------------------------------------ OCL File: --------- class p021 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stok : OclIterator ; stok := OclIterator.newOclIterator_String(OclFile.newOclFile_Read(OclFile["System.in"]).useDelimiter("\\A").next()) ; var sb : String ; sb := StringLib.newString() ; var n : int ; n := (stok.next())->toInteger() ; var w : int ; w := (stok.next())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,2 * n)->collect(0) ; var i : int ; i := 0 ; while i < 2 * n do ( ( a[i+1] := (stok.next())->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var v1 : int ; v1 := a[0+1] ; var v2 : int ; v2 := a[n+1] ; var v : double ; v := if (v2 > 2 * v1) then v1->oclAsType(double) else v2 / 2->oclAsType(double) endif ; v := v * 3 * n ; if (v > w) then v := w ; else skip ; OclFile["System.out"].println(v) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1207 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ int b=scanner.nextInt(); int p=scanner.nextInt(); int f=scanner.nextInt(); int h=scanner.nextInt(); int c=scanner.nextInt(); int ans=0 ; int food1,food2,cost1,cost2 ; if(h>=c){ food1=p ; food2=f ; cost1=h ; cost2=c ; } else { food1=f ; food2=p ; cost1=c ; cost2=h ; } if(b>=food1*2){ ans+=food1*cost1 ; b-=2*food1 ; } else { ans+=(b/2)*cost1 ; b %=2 ; } if(b>=food2*2){ ans+=food2*cost2 ; b-=2*food2 ; } else { ans+=(b/2)*cost2 ; b %=2 ; } System.out.println(ans); } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class A1207 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var b : int ; b := scanner.getCurrent()->toInteger() ; var p : int ; p := scanner.getCurrent()->toInteger() ; var f : int ; f := scanner.getCurrent()->toInteger() ; var h : int ; h := scanner.getCurrent()->toInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var food1 : int ; var food2 : int ; var cost1 : int ; var cost2 : int ; if (h >= c) then ( food1 := p ; food2 := f ; cost1 := h ; cost2 := c ) else ( food1 := f ; food2 := p ; cost1 := c ; cost2 := h ) ; if (b >= food1 * 2) then ( ans := ans+(food1 * cost1) ; b := b-(2 * food1) ) else ( ans := ans+((b / 2) * cost1) ; b := b mod 2 ) ; if (b >= food2 * 2) then ( ans := ans+(food2 * cost2) ; b := b-(2 * food2) ) else ( ans := ans+((b / 2) * cost2) ; b := b mod 2 ) ; OclFile["System.out"].println(ans) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1207 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); while(sc.hasNext()){ int b=sc.nextInt(),p=sc.nextInt(),f=sc.nextInt(); int pa=sc.nextInt(),pb=sc.nextInt(); int sum=0,c=0,d=0 ; b=b/2 ; if(pa>pb){ c=Math.min(b,p); d=Math.min(b-c,f); sum=pa*c+d*pb ; } else { c=Math.min(b,f); d=Math.min(b-c,p); sum=pb*c+d*pa ; } System.out.println(sum); } } } ------------------------------------------------------------ OCL File: --------- class A1207 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; while (sc.hasNext()) do ( var b : int ; b := sc.getCurrent()->toInteger() ; var p : int ; p := sc.getCurrent()->toInteger() ; var f : int ; f := sc.getCurrent()->toInteger() ; var pa : int ; pa := sc.getCurrent()->toInteger() ; var pb : int ; pb := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var c : int ; c := 0 ; var d : int ; d := 0 ; b := b / 2 ; if (pa > pb) then ( c := Set{b, p}->min() ; d := Set{b - c, f}->min() ; sum := pa * c + d * pb ) else ( c := Set{b, f}->min() ; d := Set{b - c, p}->min() ; sum := pb * c + d * pa ) ; OclFile["System.out"].println(sum) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); Mapmemo=new HashMap(); memo.put('N',new int[] { 1,5,2,3,0,4 } ); memo.put('E',new int[] { 3,1,0,5,4,2 } ); memo.put('W',new int[] { 2,1,5,0,4,3 } ); memo.put('S',new int[] { 4,0,2,3,5,1 } ); memo.put('R',new int[] { 0,2,4,1,3,5 } ); memo.put('L',new int[] { 0,3,1,4,2,5 } ); while(true){ int n=scanner.nextInt(); if(n==0)break ; int[] dice=new int[6]; for(int i=0 ; i<6 ; i++)dice[i]=i+1 ; int ans=1 ; for(int i=0 ; iunion(Map{'N' |-> Sequence{1,5,2,3,0,4}}) ; memo := memo->union(Map{'E' |-> Sequence{3,1,0,5,4,2}}) ; memo := memo->union(Map{'W' |-> Sequence{2,1,5,0,4,3}}) ; memo := memo->union(Map{'S' |-> Sequence{4,0,2,3,5,1}}) ; memo := memo->union(Map{'R' |-> Sequence{0,2,4,1,3,5}}) ; memo := memo->union(Map{'L' |-> Sequence{0,3,1,4,2,5}}) ; while (true) do ( var n : int ; n := scanner.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var dice : Sequence(int) ; dice := Integer.subrange(1,6)->collect(0) ; var i : int ; i := 0 ; while i < 6 do ( dice[i+1] := i + 1 ; ; i := i + 1 ) ; var ans : int ; ans := 1 ; var i : int ; i := 0 ; while i < n do ( ( var c : String ; c := scanner.getCurrent()->at(0+1) ; var tmp : Sequence(int) ; tmp := Integer.subrange(1,6)->collect(0) ; var j : int ; j := 0 ; while j < 6 do ( ( tmp[j+1] := dice[memo->at(c)[j+1]+1] ) ; j := j + 1 ) ; dice := tmp ; ans := ans+(dice[0+1]) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { final int MAX_N=100009 ; final int MAX_DEPTH=20 ; double[][] dp=new double[MAX_N][MAX_DEPTH]; double[][] prob=new double[MAX_N][MAX_DEPTH]; void run(){ Scanner in=new Scanner(System.in); init(); for(; ; ){ int n=in.nextInt(); if(n==0)return ; System.out.printf("%.10f\n",solve(n)); } } void init(){ dp[1][1]=1.0 ; prob[1][1]=1.0 ; for(int i=2 ; icollect(Integer.subrange(1,MAX_DEPTH)->collect(0.0)); attribute prob : Sequence(Sequence(double)) := Integer.subrange(1,MAX_N)->collect(Integer.subrange(1,MAX_DEPTH)->collect(0.0)); operation run() : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; execute init() ; while true do ( ( var n : int ; n := in.getCurrent()->toInteger() ; if (n = 0) then return else skip ; OclFile["System.out"].printf("%.10f\n", solve(n)) ) ) ); operation init() : void pre: true post: true activity: ( dp[1+1][1+1] := 1.0 ; prob[1+1][1+1] := 1.0 ; var i : int ; i := 2 ; while i < MAX_N - 1 do ( ( var j : int ; j := 0 ; while j < MAX_DEPTH do ( ( if (j = 0) then ( var k : int ; k := 0 ; while k < MAX_DEPTH do ( ( prob[i+1][j+1] := prob[i+1][j+1]+(prob[i - 1+1][k+1] * (1.0 - 1.0 / ((1*(2->pow(k)))->oclAsType(long)))) ) ; k := k + 1 ) ; var k : int ; k := 0 ; while k < MAX_DEPTH do ( ( dp[i+1][j+1] := dp[i+1][j+1]+(prob[i - 1+1][k+1] * (1.0 - 1.0 / ((1*(2->pow(k)))->oclAsType(long))) * dp[i - 1+1][k+1] / prob[i+1][j+1]) ) ; k := k + 1 ) ) else ( prob[i+1][j+1] := prob[i+1][j+1]+(prob[i - 1+1][j - 1+1] * (1.0 / ((1*(2->pow((j - 1))))->oclAsType(long)))) ; dp[i+1][j+1] := dp[i+1][j+1]+((dp[i - 1+1][j - 1+1] + 1.0)) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ); operation solve( n : int) : double pre: true post: true activity: ( var ret : double ; ret := 0.0 ; var i : int ; i := 0 ; while i < MAX_DEPTH do ( ( ret := ret+(prob[n+1][i+1] * dp[n+1][i+1]) ) ; i := i + 1 ) ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner s=new Scanner(System.in); int a ; while(true){ a=s.nextInt(); if(a==0)System.exit(0); int ret=1 ; int B=5 ; int U=1 ; int R=3 ; int L=4 ; int F=2 ; int D=6 ; for(int i=0 ; itoInteger() ; if (a = 0) then OclProcess.exit(0) ; else skip ; var ret : int ; ret := 1 ; var B : int ; B := 5 ; var U : int ; U := 1 ; var R : int ; R := 3 ; var L : int ; L := 4 ; var F : int ; F := 2 ; var D : int ; D := 6 ; var i : int ; i := 0 ; while i < a do ( ( var str : String ; str := s.getCurrent() ; if (str = "North") then ( var newB : int ; newB := U ; var newU : int ; newU := F ; var newD : int ; newD := B ; var newF : int ; newF := D ; B := newB ; U := newU ; F := newF ; D := newD ; ) else skip ; if (str = "East") then ( var newU : int ; newU := L ; var newL : int ; newL := D ; var newR : int ; newR := U ; var newD : int ; newD := R ; U := newU ; L := newL ; R := newR ; D := newD ; ) else skip ; if (str = "South") then ( var newB : int ; newB := D ; var newU : int ; newU := B ; var newD : int ; newD := F ; var newF : int ; newF := U ; B := newB ; U := newU ; F := newF ; D := newD ; ) else skip ; if (str = "West") then ( var newU : int ; newU := R ; var newL : int ; newL := U ; var newR : int ; newR := D ; var newD : int ; newD := L ; U := newU ; L := newL ; R := newR ; D := newD ; ) else skip ; if (str = "Right") then ( var newF : int ; newF := R ; var newB : int ; newB := L ; var newR : int ; newR := B ; var newL : int ; newL := F ; F := newF ; B := newB ; R := newR ; L := newL ; ) else skip ; if (str = "Left") then ( var newF : int ; newF := L ; var newB : int ; newB := R ; var newR : int ; newR := F ; var newL : int ; newL := B ; F := newF ; B := newB ; R := newR ; L := newL ; ) else skip ; ret := ret+(U) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ret) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=null ; try { scan=new Scanner(System.in); int n ; while((n=scan.nextInt())!=0){ Dice dice=new Dice(); int sum=1 ; for(int i=0 ; itoInteger() ; while ((n) /= 0) do ( skip ; ( var dice : Dice ; dice := Dice.newDice() ; var sum : int ; sum := 1 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(dice.Change(scan.getCurrent()->at(0+1))) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ) ; n := scan.getCurrent()->toInteger() ; ) ) finally ( if (scan /= null) then skip ; else skip ) ); } class Dice { attribute dice : Sequence(int); attribute seven : int := 7; static operation newDice() : Dice pre: true post: true activity: ( var self : Dice ; self := createDice(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( dice := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < dice->size() do ( ( dice[i+1] := i + 1 ) ; i := i + 1 ) ); operation change( i : int, j : int) : void pre: true post: true activity: ( var tmp : int ; tmp := dice[i+1] ; dice[i+1] := dice[j+1] ; dice[j+1] := seven - tmp ); operation North() : int pre: true post: true activity: ( execute change(0, 1) ; return dice[0+1] ); operation East() : int pre: true post: true activity: ( execute change(2, 0) ; return dice[0+1] ); operation West() : int pre: true post: true activity: ( execute change(0, 2) ; return dice[0+1] ); operation South() : int pre: true post: true activity: ( execute change(1, 0) ; return dice[0+1] ); operation Right() : int pre: true post: true activity: ( execute change(1, 2) ; return dice[0+1] ); operation Left() : int pre: true post: true activity: ( execute change(2, 1) ; return dice[0+1] ); operation Change( data : String) : int pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (data) ; if _switchval = 'N' then return North() else skip ; if _switchval = 'E' then return East() else skip ; if _switchval = 'W' then return West() else skip ; if _switchval = 'S' then return South() else skip ; if _switchval = 'R' then return Right() else skip ; if _switchval = 'L' then return Left() else skip ; ) return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String[] s="North:South:East:West:Right:Left".split(":"); int[][] l={ { 0,1,1,2,2,3 },{ 3,2,2,1,1,0 },{ 0,5,2,4,4,5 },{ 0,4,2,5,5,4 },{ 1,4,3,5,4,5 },{ 1,5,3,4,4,5 } }; Mapm=new HashMap<>(); for(int i=0 ; i<6 ; i++){ m.put(s[i],l[i]); } for(; ; ){ int n=sc.nextInt(); if(n==0){ break ; } int sum=1 ; int[] d={ 1,2,6,5,3,4 }; while(n-->0){ int[] t=m.get(sc.next()); for(int i=0 ; isplit(":") ; var l : Sequence(Sequence(int)) ; l := Sequence{Sequence{0,1,1,2,2,3},Sequence{3,2,2,1,1,0},Sequence{0,5,2,4,4,5},Sequence{0,4,2,5,5,4},Sequence{1,4,3,5,4,5},Sequence{1,5,3,4,4,5}} ; var m : Map(String,Sequence(int)) ; m := Map{} ; var i : int ; i := 0 ; while i < 6 do ( ( m := m->union(Map{s[i+1] |-> l[i+1]}) ) ; i := i + 1 ) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then ( break ) else skip ; var sum : int ; sum := 1 ; var d : Sequence(int) ; d := Sequence{1,2,6,5,3,4} ; while (n > 0) do ( n := n - 1 ; skip ; ( var t : Sequence(int) ; t := m->at(sc.getCurrent()) ; var i : int ; i := 0 ; while i < t->size() do ( ( var p : int ; p := d[t[i+1]+1] ; d[t[i+1]+1] := d[t[i + 1+1]+1] ; d[t[i + 1+1]+1] := p ) ; i := i+(2) ) ; sum := sum+(d[0+1]) ) ; ) ; OclFile["System.out"].println(sum) ; ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String rags[]){ Scanner sc=new Scanner(System.in); String f=sc.nextLine(); String m=sc.nextLine(); String s=sc.nextLine(); if(f.equals("rock")&& m.equals("scissors")&& s.equals("scissors"))System.out.println("F"); else if(f.equals("paper")&& m.equals("rock")&& s.equals("rock"))System.out.println("F"); else if(f.equals("scissors")&& m.equals("paper")&& s.equals("paper"))System.out.println("F"); else if(f.equals("rock")&& m.equals("paper")&& s.equals("rock"))System.out.println("M"); else if(f.equals("scissors")&& m.equals("rock")&& s.equals("scissors"))System.out.println("M"); else if(f.equals("paper")&& m.equals("scissors")&& s.equals("paper"))System.out.println("M"); else if(f.equals("rock")&& m.equals("rock")&& s.equals("paper"))System.out.println("S"); else if(f.equals("scissors")&& m.equals("scissors")&& s.equals("rock"))System.out.println("S"); else if(f.equals("paper")&& m.equals("paper")&& s.equals("scissors"))System.out.println("S"); else System.out.println("?"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( rags : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var f : String ; f := sc.nextLine() ; var m : String ; m := sc.nextLine() ; var s : String ; s := sc.nextLine() ; if (f = "rock" & m = "scissors" & s = "scissors") then OclFile["System.out"].println("F") else if (f = "paper" & m = "rock" & s = "rock") then OclFile["System.out"].println("F") else if (f = "scissors" & m = "paper" & s = "paper") then OclFile["System.out"].println("F") else if (f = "rock" & m = "paper" & s = "rock") then OclFile["System.out"].println("M") else if (f = "scissors" & m = "rock" & s = "scissors") then OclFile["System.out"].println("M") else if (f = "paper" & m = "scissors" & s = "paper") then OclFile["System.out"].println("M") else if (f = "rock" & m = "rock" & s = "paper") then OclFile["System.out"].println("S") else if (f = "scissors" & m = "scissors" & s = "rock") then OclFile["System.out"].println("S") else if (f = "paper" & m = "paper" & s = "scissors") then OclFile["System.out"].println("S") else OclFile["System.out"].println("?") ; ; ; ; ; ; ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int cu=1 ; static int cd=6 ; static int n=5 ; static int s=2 ; static int e=4 ; static int w=3 ; public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); while(true){ int k=stdIn.nextInt(); if(k==0){ break ; } cu=1 ; cd=6 ; n=5 ; s=2 ; e=4 ; w=3 ; int ans=1 ; for(int i=0 ; itoInteger() ; if (k = 0) then ( break ) else skip ; cu := 1 ; cd := 6 ; n := 5 ; s := 2 ; e := 4 ; w := 3 ; var ans : int ; ans := 1 ; var i : int ; i := 0 ; while i < k do ( ( var tmp : String ; tmp := stdIn.getCurrent() ; if (tmp = "North") then ( execute north() ) else skip ; if (tmp = "South") then ( execute south() ) else skip ; if (tmp = "East") then ( execute east() ) else skip ; if (tmp = "West") then ( execute west() ) else skip ; if (tmp = "Right") then ( execute right() ) else skip ; if (tmp = "Left") then ( execute left() ) else skip ; ans := ans+(cu) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); static operation north() : void pre: true post: true activity: ( var tmp : int ; tmp := cu ; cu := s ; s := cd ; cd := n ; n := tmp ; ); static operation south() : void pre: true post: true activity: ( var tmp : int ; tmp := cu ; cu := n ; n := cd ; cd := s ; s := tmp ; ); static operation east() : void pre: true post: true activity: ( var tmp : int ; tmp := cu ; cu := e ; e := cd ; cd := w ; w := tmp ; ); static operation west() : void pre: true post: true activity: ( var tmp : int ; tmp := cu ; cu := w ; w := cd ; cd := e ; e := tmp ; ); static operation right() : void pre: true post: true activity: ( var tmp : int ; tmp := n ; n := e ; e := s ; s := w ; w := tmp ; ); static operation left() : void pre: true post: true activity: ( var tmp : int ; tmp := n ; n := w ; w := s ; s := e ; e := tmp ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GfG { static boolean isPerfectSquare(int n){ for(int i=1 ; i*i<=n ; i++){ if((n % i==0)&&(n/i==i)){ return true ; } } return false ; } public static void main(String[] args){ int n=36 ; if(isPerfectSquare(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation isPerfectSquare( n : int) : boolean pre: true post: true activity: ( var i : int ; i := 1 ; while i * i <= n do ( ( if ((n mod i = 0) & (n / i = i)) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 36 ; if (isPerfectSquare(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class prog1 { static int solve(int arr[],int n){ int ans=Integer.MIN_VALUE ; if(n==1){ return 0 ; } int max=Integer.MIN_VALUE,min=Integer.MAX_VALUE ; for(int i=1 ; imax){ max=arr[i]; } } ans=Math.max(max-arr[0],ans); for(int i=0 ; i=0 ; i--){ ans=Math.max(ans,arr[i]-arr[i+1]); } return ans ; } public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=1 ; i<=t ; i++){ int n=sc.nextInt(); int arr[]=new int[n]; for(int j=0 ; j max) then ( max := arr[i+1] ) else skip ) ; i := i + 1 ) ; ans := Set{max - arr[0+1], ans}->max() ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (arr[i+1] < min) then ( min := arr[i+1] ) else skip ) ; i := i + 1 ) ; ans := Set{ans, arr[n - 1+1] - min}->max() ; ans := Set{ans, arr[n - 1+1] - arr[0+1]}->max() ; var i : int ; i := n - 2 ; while i >= 0 do ( ( ans := Set{ans, arr[i+1] - arr[i + 1+1]}->max() ) ; i := i - 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ; var ans : int ; ans := solve(arr, n) ; OclFile["System.out"].println(ans) ; ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.util.*; public class A { public static void main(String[] args){ FastReader fs=new FastReader(); PrintWriter out=new PrintWriter(System.out); int N=fs.nextInt(); for(int p=0 ; pcollect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := fs.nextInt() ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ans := Set{arr[(i - 1 + n) mod n+1] - arr[i+1], ans}->max() ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ans := Set{ans, arr[i+1] - arr[0+1]}->max() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ans := Set{ans, arr[n - 1+1] - arr[i+1]}->max() ; ; i := i + 1 ) ; skip ; ) ; p := p + 1 ) ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Arrays ; public class codeforce { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] array=new int[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var array : Sequence(int) ; array := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( array[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( max := Set{array[i+1] - array[0+1], max}->max() ; max := Set{max, array[n - 1+1] - array[i+1]}->max() ; max := Set{max, array[i+1] - array[(i + 1) mod n+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.text.*; class GFG { static double p=1,f=1 ; static double e(int x,int n){ double r ; if(n==0)return 1 ; r=e(x,n-1); p=p*x ; f=f*n ; return(r+p/f); } public static void main(String[] args){ int x=4,n=15 ; DecimalFormat df=new DecimalFormat("0.######"); System.out.println(df.format(e(x,n))); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute p : double := 1; static operation e( x : int, n : int) : double pre: true post: true activity: ( var r : double ; if (n = 0) then return 1 else skip ; r := e(x, n - 1) ; p := p * x ; f := f * n ; return (r + p / f) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 4 ; var n : int ; n := 15 ; var df : DecimalFormat ; df := DecimalFormat.newDecimalFormat("0.######") ; OclFile["System.out"].println(df.format(e(x, n))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Main main=new Main(); main.run(); } class P implements Comparable

{ long x ; long y ; P(long x,long y){ this.x=x ; this.y=y ; } @ Override public int compareTo(P arg0){ return Long.compare(this.x,arg0.x); } } public void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); long x[]=new long[N]; long y[]=new long[N]; for(int i=0 ; i=x2)continue ; for(int k=0 ; k=y2)continue ; int cnt=0 ; for(int m=0 ; m { attribute x : long; attribute y : long; static operation newP( x : long, y : long) : P pre: true post: true activity: ( var self : P ; self := createP(); self.initialise(x, y); return self ); operation initialise( x : long, y : long) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation compareTo( arg0 : P) : int pre: true post: true activity: ( return compare(self.x, arg0.x) ); } operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var x : Sequence(long) ; x := Integer.subrange(1,N)->collect(0) ; var y : Sequence(long) ; y := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( x[i+1] := sc.getCurrent()->toLong() ; y[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var ans : long ; ans := "9223372036854775807"->toLong() ; var i : int ; i := 0 ; while i < N do ( ( var x1 : long ; x1 := x[i+1] ; var j : int ; j := 0 ; while j < N do ( ( var x2 : long ; x2 := x[j+1] ; if (x1 >= x2) then continue else skip ; var k : int ; k := 0 ; while k < N do ( ( var y1 : long ; y1 := y[k+1] ; var l : int ; l := 0 ; while l < N do ( ( var y2 : long ; y2 := y[l+1] ; if (y1 >= y2) then continue else skip ; var cnt : int ; cnt := 0 ; var m : int ; m := 0 ; while m < N do ( ( if (x1 <= x[m+1] & x[m+1] <= x2 & y1 <= y[m+1] & y[m+1] <= y2) then ( cnt := cnt + 1 ) else skip ) ; m := m + 1 ) ; if (cnt = K) then ( ans := Set{ans, (x2 - x1) * (y2 - y1)}->min() ) else skip ; ) ; l := l + 1 ) ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); HashMaphash=new HashMap<>(); int n=sc.nextInt(); for(int i=0 ; i1){ b=false ; break ; } } if(b)System.out.println("YES"); else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var hash : Map(int,int) ; hash := Map{} ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := sc.getCurrent()->toInteger() ; if (hash->keys()->includes(j)) then hash := hash->union(Map{j |-> 2}) ; else hash := hash->union(Map{j |-> 1}) ; ) ; i := i + 1 ) ; var b : boolean ; b := true ; for (a : hash->values()) do ( ( if (a > 1) then ( b := false ; break ) else skip ) ) ; if (b) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Comparator ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String o="YES" ; int[] a=new int[n]; BinarySearchTree t=new BinarySearchTree(); for(int i=0 ; itoInteger() ; var o : String ; o := "YES" ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var t : BinarySearchTree ; t := BinarySearchTree.newBinarySearchTree() ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; if (t->includes(a[i+1])) then ( o := "NO" ; OclFile["System.out"].println(o) ; return ) else ( t->excludes(a[i+1]) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(o) ; ); } class Node { attribute data : int; attribute left : Node; attribute right : Node; } class BinarySearchTree { attribute root : Node; operation add( data : int) : void pre: true post: true activity: ( if (root = null) then ( root := Node.newNode() ; root.data := data ; return ) else skip ; var current : Node ; current := root ; while (true) do ( if (data < current.data) then ( if (current.left = null) then ( current.left := Node.newNode() ; current.left.data := data ; return ) else skip ; current := current.left ) else if (current.data <= data) then ( if (current.right = null) then ( current.right := Node.newNode() ; current.right.data := data ; return ) else skip ; current := current.right ) else skip ; ) ); operation contains( data : int) : boolean pre: true post: true activity: ( var current : Node ; current := root ; while (current /= null) do ( if (current.data = data) then ( return true ) else if (data < current.data) then ( current := current.left ) else if (current.data < data) then ( current := current.right ) else skip ; ; ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashSet ; import java.util.Set ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int numAll=Integer.parseInt(br.readLine()); String[] numsStr=br.readLine().split(" "); SetnumSet=new HashSet<>(); for(int i=0 ; itoInteger() ; var numsStr : Sequence(String) ; numsStr := br.readLine()->split(" ") ; var numSet : Set(String) ; numSet := Set{} ; var i : int ; i := 0 ; while i < numAll do ( ( numSet := numSet->including(numsStr[i+1]) ) ; i := i + 1 ) ; if (numAll = numSet->size()) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collection ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.List ; import java.util.Map ; import java.util.Map.Entry ; import java.util.Scanner ; public class Main { private static Scanner sc=new Scanner(System.in); static void p(String ans){ System.out.println(ans); }; static void p(int ans){ System.out.println(ans); }; static void p(long ans){ System.out.println(ans); }; public static void main(String[] args){ int n=sc.nextInt(); Mapmap=new HashMap(n); boolean a=true ; for(int i=0 ; itoInteger() ; var map : Map(int,int) ; map := Map{} ; var a : boolean ; a := true ; var i : int ; i := 0 ; while i < n & a do ( ( var A : int ; A := sc.getCurrent()->toInteger() ; if (not(map->keys()->includes(A))) then ( map := map->union(Map{A |-> 1}) ) else ( a := false ) ) ; i := i + 1 ) ; if (a) then ( execute p("YES") ) else ( execute p("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(final String[] args){ final Scanner scanner=new Scanner(System.in); final int n=scanner.nextInt(); final Mapmap=new HashMap<>(); for(int i=0 ; itoInteger() ; var map : Map(int,Boolean) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := scanner.getCurrent()->toInteger() ; if (map->at(a) /= null) then ( OclFile["System.out"].println("NO") ; return ) else ( map := map->union(Map{a |-> true}) ) ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float successiveChange(int arr[],int N){ float var1,var2,result=0 ; var1=arr[0]; var2=arr[1]; result=var1+var2+((var1*var2)/100); for(int i=2 ; isize() ; var result : double ; result := successiveChange(arr, N) ; OclFile["System.out"].println("Percentage change is=" + result + " %") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean checkPalindrome(String s){ for(int i=0 ; isize() do ( ( if (s->at(i+1) /= s->at(s->size() - i - 1+1)) then return false else skip ) ; i := i + 1 ) ; return true ); static operation CheckOdd( s : String) : boolean pre: true post: true activity: ( var n : int ; n := s->size() ; var i : int ; i := 0 ; while i < n do ( ( var x : String ; x := "" ; var j : int ; j := i ; while j < n do ( ( x := x+(s->at(j+1)) ; if (x->size() mod 2 = 0 & checkPalindrome(x) = true) then return false else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "geeksforgeeks" ; if (CheckOdd(s)) then OclFile["System.out"].print("YES") ; else OclFile["System.out"].print("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countPairs(int a[],int n){ int mn=Integer.MAX_VALUE ; int mx=Integer.MIN_VALUE ; for(int i=0 ; imin() ; mx := Set{mx, a[i+1]}->max() ) ; i := i + 1 ) ; var c1 : int ; c1 := 0 ; var c2 : int ; c2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] = mn) then c1 := c1 + 1 ; else skip ; if (a[i+1] = mx) then c2 := c2 + 1 ; else skip ) ; i := i + 1 ) ; if (mn = mx) then return n * (n - 1) / 2 else return c1 * c2 ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{3,2,1,1,3} ; var n : int ; n := a->size() ; OclFile["System.out"].print(countPairs(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int distinctCount(int arr[],int n){ int count=n ; int i=0,j=n-1,sum=0 ; while(isize() ; OclFile["System.out"].println("Count of absolute distinct values : " + distinctCount(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int N ; static double[] exp=new double[100001]; public static void main(String[] args){ precalc(); while(true){ N=sc.nextInt(); if(N==0)break ; System.out.println(solve()); } } static double solve(){ return exp[N]; } static void precalc(){ int pos=0 ; double[][] prob=new double[2][101]; double[][] v=new double[2][101]; prob[pos][0]=1 ; double[] success=new double[101]; success[0]=1 ; for(int i=1 ; icollect(0.0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute precalc() ; while (true) do ( N := sc.getCurrent()->toInteger() ; if (N = 0) then break else skip ; OclFile["System.out"].println(solve()) ) ); static operation solve() : double pre: true post: true activity: ( return exp[N+1] ); static operation precalc() : void pre: true post: true activity: ( var pos : int ; pos := 0 ; var prob : Sequence(Sequence(double)) ; prob := Integer.subrange(1,2)->collect(Integer.subrange(1,101)->collect(0.0)) ; var v : Sequence(Sequence(double)) ; v := Integer.subrange(1,2)->collect(Integer.subrange(1,101)->collect(0.0)) ; prob[pos+1][0+1] := 1 ; var success : Sequence(double) ; success := Integer.subrange(1,101)->collect(0.0) ; success[0+1] := 1 ; var i : int ; i := 1 ; while i < success->size() do ( ( success[i+1] := success[i - 1+1] / 2 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= 100000 do ( ( var sum : double ; sum := 0 ; prob[1 - pos+1] := prob[1 - pos+1]->collect(0) ; v[1 - pos+1] := v[1 - pos+1]->collect(0) ; var j : int ; j := 0 ; while j < 100 do ( ( sum := sum+(v[pos+1][j+1]) ; prob[1 - pos+1][j + 1+1] := prob[1 - pos+1][j + 1+1]+(prob[pos+1][j+1] * success[j+1]) ; prob[1 - pos+1][0+1] := prob[1 - pos+1][0+1]+(prob[pos+1][j+1] * (1 - success[j+1])) ; v[1 - pos+1][j + 1+1] := v[1 - pos+1][j + 1+1]+((v[pos+1][j+1] + prob[pos+1][j+1]) * success[j+1]) ; v[1 - pos+1][0+1] := v[1 - pos+1][0+1]+(v[pos+1][j+1] * (1 - success[j+1])) ; ) ; j := j + 1 ) ; exp[i+1] := sum ; pos := 1 - pos ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { private static final long MAX=(long)(2e10+1); public static void main(String[] args)throws Exception { Scanner scanner=new Scanner(System.in); int V=scanner.nextInt(); int E=scanner.nextInt(); long[][] dist=new long[V][V]; for(int i=0 ; ioclAsType(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var V : int ; V := scanner.getCurrent()->toInteger() ; var E : int ; E := scanner.getCurrent()->toInteger() ; var dist : Sequence(Sequence(long)) ; dist := Integer.subrange(1,V)->collect(Integer.subrange(1,V)->collect(0)) ; var i : int ; i := 0 ; while i < V do ( ( dist[i+1] := dist[i+1]->collect(MAX) ; dist[i+1][i+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < E do ( ( var u : int ; u := scanner.getCurrent()->toInteger() ; var v : int ; v := scanner.getCurrent()->toInteger() ; var weight : int ; weight := scanner.getCurrent()->toInteger() ; dist[u+1][v+1] := weight ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < V do ( ( var i : int ; i := 0 ; while i < V do ( ( var j : int ; j := 0 ; while j < V do ( ( if (dist[i+1][k+1] /= MAX & dist[k+1][j+1] /= MAX & dist[i+1][k+1] + dist[k+1][j+1] < dist[i+1][j+1]) then ( dist[i+1][j+1] := dist[i+1][k+1] + dist[k+1][j+1] ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; k := k + 1 ) ; var i : int ; i := 0 ; while i < V do ( ( if (dist[i+1][i+1] < 0) then ( OclFile["System.out"].println("NEGATIVE CYCLE") ; return ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < V do ( ( var j : int ; j := 0 ; while j < V do ( ( OclFile["System.out"].print(if dist[i+1][j+1] = MAX then "INF" else dist[i+1][j+1] endif) ; if (j /= V - 1) then ( OclFile["System.out"].print(" ") ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println("") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int v=sc.nextInt(); int e=sc.nextInt(); long[][] cost=new long[v][v]; long INF=Long.MAX_VALUE/10 ; for(int i=0 ; icost[i][k]+cost[k][j] && cost[i][k]!=INF && cost[k][j]!=INF)cost[i][j]=cost[i][k]+cost[k][j]; } if(cost[i][i]<0)minor=true ; } } if(minor)System.out.println("NEGATIVE CYCLE"); else { for(int i=0 ; i0)System.out.print(" "); System.out.print((cost[i][j]>=INF)? "INF" : cost[i][j]); } System.out.println(); } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var v : int ; v := sc.getCurrent()->toInteger() ; var e : int ; e := sc.getCurrent()->toInteger() ; var cost : Sequence(Sequence(long)) ; cost := Integer.subrange(1,v)->collect(Integer.subrange(1,v)->collect(0)) ; var INF : long ; INF := "9223372036854775807"->toLong() / 10 ; var i : int ; i := 0 ; while i < v do ( ( var j : int ; j := 0 ; while j < v do ( ( cost[i+1][j+1] := if (i = j) then 0 else INF endif ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < e do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var d : long ; d := sc.getCurrent()->toLong() ; cost[s+1][t+1] := d ) ; i := i + 1 ) ; var minor : boolean ; minor := false ; var k : int ; k := 0 ; while k < v do ( ( var i : int ; i := 0 ; while i < v do ( ( var j : int ; j := 0 ; while j < v do ( ( if (cost[i+1][j+1] > cost[i+1][k+1] + cost[k+1][j+1] & cost[i+1][k+1] /= INF & cost[k+1][j+1] /= INF) then cost[i+1][j+1] := cost[i+1][k+1] + cost[k+1][j+1] ; else skip ) ; j := j + 1 ) ; if (cost[i+1][i+1] < 0) then minor := true ; else skip ) ; i := i + 1 ) ) ; k := k + 1 ) ; if (minor) then OclFile["System.out"].println("NEGATIVE CYCLE") else ( var i : int ; i := 0 ; while i < v do ( ( var j : int ; j := 0 ; while j < v do ( ( if (j > 0) then OclFile["System.out"].print(" ") ; else skip ; OclFile["System.out"].print(if (cost[i+1][j+1] >= INF) then "INF" else cost[i+1][j+1] endif) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static final int INF=Integer.MAX_VALUE ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int en=sc.nextInt(); int[][] d=new int[n][n]; for(int i=0 ; itoInteger() ; var en : int ; en := sc.getCurrent()->toInteger() ; var d : Sequence(Sequence(int)) ; d := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( d[i+1] := d[i+1]->collect(INF) ; d[i+1][i+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < en do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var dist : int ; dist := sc.getCurrent()->toInteger() ; d[s+1][t+1] := dist ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < n do ( ( var i : int ; i := 0 ; while i < n do ( ( if (d[i+1][k+1] = INF) then ( continue ) else skip ; var j : int ; j := 0 ; while j < n do ( ( if (d[k+1][j+1] = INF) then ( continue ) else skip ; d[i+1][j+1] := Set{d[i+1][j+1], d[i+1][k+1] + d[k+1][j+1]}->min() ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; k := k + 1 ) ; if (hasNegativeLoopWF(d)) then ( OclFile["System.out"].println("NEGATIVE CYCLE") ; return ) else skip ; var i : int ; i := 0 ; while i < n do ( ( var res : Sequence(String) ; res := Integer.subrange(1,n)->collect(null) ; var j : int ; j := 0 ; while j < n do ( ( res[j+1] := if d[i+1][j+1] = INF then "INF" else ((d[i+1][j+1]) + "") endif ) ; j := j + 1 ) ; OclFile["System.out"].println(join(" ", res)) ) ; i := i + 1 ) ; ); static operation hasNegativeLoopWF( a : Sequence(Sequence(int))) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < a->size() do ( ( if (a[i+1][i+1] < 0) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { try(Scanner sc=new Scanner(System.in)){ int V=sc.nextInt(); int E=sc.nextInt(); int INF=Integer.MAX_VALUE ; int[][] dis=new int[V][V]; for(int i=0 ; i=INF ? "INF" : dis[i][j])+" "); } System.out.println(dis[i][V-1]>=INF ? "INF" : dis[i][V-1]); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var V : int ; V := sc.getCurrent()->toInteger() ; var E : int ; E := sc.getCurrent()->toInteger() ; var INF : int ; INF := 2147483647 ; var dis : Sequence(Sequence(int)) ; dis := Integer.subrange(1,V)->collect(Integer.subrange(1,V)->collect(0)) ; var i : int ; i := 0 ; while i < V do ( ( var j : int ; j := 0 ; while j < V do ( ( if (i = j) then dis[i+1][j+1] := 0 ; else dis[i+1][j+1] := INF ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < E do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; dis[s+1][t+1] := d ) ; i := i + 1 ) ; var negative : boolean ; negative := false ; var k : int ; k := 0 ; while k < V do ( ( var i : int ; i := 0 ; while i < V do ( ( var j : int ; j := 0 ; while j < V do ( ( if (dis[i+1][k+1] < INF & dis[k+1][j+1] < INF) then ( dis[i+1][j+1] := Set{dis[i+1][j+1], dis[i+1][k+1] + dis[k+1][j+1]}->min() ) else skip ) ; j := j + 1 ) ; if (dis[i+1][i+1] < 0) then negative := true ; else skip ) ; i := i + 1 ) ) ; k := k + 1 ) ; if (negative) then ( OclFile["System.out"].println("NEGATIVE CYCLE") ; return ) else skip ; var i : int ; i := 0 ; while i < V do ( ( var j : int ; j := 0 ; while j < V - 1 do ( ( OclFile["System.out"].print((if dis[i+1][j+1] >= INF then "INF" else dis[i+1][j+1] endif) + " ") ) ; j := j + 1 ) ; OclFile["System.out"].println(if dis[i+1][V - 1+1] >= INF then "INF" else dis[i+1][V - 1+1] endif) ) ; i := i + 1 ) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.Scanner ; class Main { public static void main(String[] args){ new Main().run(); } long INF=Long.MAX_VALUE/10 ; void run(){ Scanner sc=new Scanner(System.in); int V=sc.nextInt(); int E=sc.nextInt(); long[][] D=new long[V][V]; for(int i=0 ; i=INF ? "INF" : D[i][j])+(j==V-1 ? "\n" : " ")); } static void tr(Object...objects){ System.out.println(Arrays.deepToString(objects)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute INF : long := "9223372036854775807"->toLong() / 10; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var V : int ; V := sc.getCurrent()->toInteger() ; var E : int ; E := sc.getCurrent()->toInteger() ; var D : Sequence(Sequence(long)) ; D := Integer.subrange(1,V)->collect(Integer.subrange(1,V)->collect(0)) ; var i : int ; i := 0 ; while i < V do ( ( D[i+1] := D[i+1]->collect(INF) ; D[i+1][i+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < E do ( D[sc.getCurrent()->toInteger()+1][sc.getCurrent()->toInteger()+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var t : int ; t := 1 ; while t < V do ( var i : int ; i := 0 ; while i < V do ( var j : int ; j := 0 ; while j < V do ( var m : int ; m := 0 ; while m < V do ( if (Set{D[i+1][m+1], D[m+1][j+1]}->max() < INF) then D[i+1][j+1] := Set{D[i+1][j+1], D[i+1][m+1] + D[m+1][j+1]}->min() ; else skip ; ; m := m + 1 ) ; ; j := j + 1 ) ; ; i := i + 1 ) ; ; t := t*(2) ) ; var i : int ; i := 0 ; while i < V do ( if (D[i+1][i+1] < 0) then ( OclFile["System.out"].println("NEGATIVE CYCLE") ; return ) else skip ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < V do ( var j : int ; j := 0 ; while j < V do ( OclFile["System.out"].print((if D[i+1][j+1] >= INF then "INF" else D[i+1][j+1] endif) + (if j = V - 1 then "\n" else " " endif)) ; ; j := j + 1 ) ; ; i := i + 1 ) ; ); static operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { InputStream inputStream ; OutputStream outputStream ; inputStream=System.in ; outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); Task solver=new Task(); solver.solve(in,out); out.close(); } static class Task { public void solve(InputReader in,PrintWriter out){ int n ; n=in.nextInt(); long ans=0 ; for(int i=1 ; i<=n ; ++i){ ans+=(long)i*(long)(n-i+1); } for(int i=1 ; iv){ int tmp=u ; u=v ; v=tmp ; } ans-=(long)u*(long)(n-v+1); } out.println(ans); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream)); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=reader.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; var outputStream : OclFile ; inputStream := OclFile["System.in"] ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : Task ; solver := Task.newTask() ; solver.solve(in, out) ; skip ; ); static class Task { operation solve( in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( ans := ans+(i->oclAsType(long) * (n - i + 1)->oclAsType(long)) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var u : int ; var v : int ; u := in.nextInt() ; v := in.nextInt() ; if (u > v) then ( var tmp : int ; tmp := u ; u := v ; v := tmp ) else skip ; ans := ans-(u->oclAsType(long) * (n - v + 1)->oclAsType(long)) ; ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := reader.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void minRange(int arr[],int n,int k){ int l=0,r=n ; for(int i=0 ; is=new HashSet(); int j ; for(j=i ; jincluding(arr[j+1]) ; if (s->size() = k) then ( if ((j - i) < (r - l)) then ( r := j ; l := i ) else skip ; break ) else skip ) ; j := j + 1 ) ; if (j = n) then break else skip ) ; i := i + 1 ) ; if (l = 0 & r = n) then OclFile["System.out"].println("Invalid k") ; else OclFile["System.out"].println(l + " " + r) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5} ; var n : int ; n := arr->size() ; var k : int ; k := 3 ; execute minRange(arr, n, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static long calculate(int bit_cnt){ long res=1 ; while(bit_cnt-->0){ res=res*3 ; } return res ; } static int unset_bit_count(long n){ int count=0 ; while(n>0){ if((n & 1)==0)count++; n=n>>1 ; } return count ; } public static void main(String[] args){ long n ; n=2 ; int count=unset_bit_count(n); long ans=calculate(count); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation calculate( bit_cnt : int) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (bit_cnt > 0) do ( bit_cnt := bit_cnt - 1 ; skip ; ( res := res * 3 ) ; ) ; return res ); static operation unset_bit_count( n : long) : int pre: true post: true activity: ( var count : int ; count := 0 ; while (n > 0) do ( if ((n & 1) = 0) then count := count + 1 ; else skip ; n := (n/(2->pow(1)))->oclAsType(long) ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 2 ; var count : int ; count := unset_bit_count(n) ; var ans : long ; ans := calculate(count) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countSubarray(int arr[],int n,int k){ int count=0 ; for(int i=0 ; isize() ; var count : int ; count := countSubarray(array, size, k) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class modularEquations { public static void main(String[] args){ Kattio io=new Kattio(); int a=io.nextInt(); int b=io.nextInt(); int l=a-b ; if(l==0){ io.println("infinity"); } else { int num=0 ; for(int i=1 ; i<=Math.sqrt(l); i++){ if(l % i==0){ if((l/i)>b){ num++; } if(i>b && i!=(l/i)){ num++; } } } io.println(num); } io.close(); } static class Kattio extends PrintWriter { private BufferedReader r ; private StringTokenizer st ; public Kattio(){ this(System.in,System.out); } public Kattio(InputStream i,OutputStream o){ super(o); r=new BufferedReader(new InputStreamReader(i)); } public Kattio(String problemName)throws IOException { super(problemName+".out"); r=new BufferedReader(new FileReader(problemName+".in")); } public String next(){ try { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(r.readLine()); return st.nextToken(); } catch(Exception e){ } return null ; } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class modularEquations { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : Kattio ; io := Kattio.newKattio() ; var a : int ; a := io.nextInt() ; var b : int ; b := io.nextInt() ; var l : int ; l := a - b ; if (l = 0) then ( io.println("infinity") ) else ( var num : int ; num := 0 ; var i : int ; i := 1 ; while i <= (l)->sqrt() do ( ( if (l mod i = 0) then ( if ((l / i) > b) then ( num := num + 1 ) else skip ; if (i > b & i /= (l / i)) then ( num := num + 1 ) else skip ) else skip ) ; i := i + 1 ) ; io.println(num) ) ; io.close() ; ); static class Kattio extends OclFile { attribute r : OclFile; attribute st : OclIterator; static operation newKattio() : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute this(OclFile["System.in"], OclFile["System.out"]) ); static operation newKattio( i : OclFile, o : OclFile) : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(i, o); return self ); operation initialise( i : OclFile, o : OclFile) : void pre: true post: true activity: ( execute super(o) ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(i)) ); static operation newKattio( problemName : String) : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(problemName); return self ); operation initialise( problemName : String) : void pre: true post: true activity: ( execute super(problemName + ".out") ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(problemName + ".in")) ); operation next() : String pre: true post: true activity: ( try ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(r.readLine()) ; ; return st.next() ) catch (e : ProgramException) do skip return null ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ double EPS=1e-13 ; double[] res=new double[100001]; res[1]=1 ; for(int n=2 ; n<=100000 ; n++){ double p=1,win=0.5 ; int k=1 ; while(EPS

collect(0.0) ; res[1+1] := 1 ; var n : int ; n := 2 ; while n <= 100000 do ( ( var p : double ; p := 1 ; var win : double ; win := 0.5 ; var k : int ; k := 1 ; while (EPS < p & k < n) do ( var not : double ; not := p * (1 - win) ; res[n+1] := res[n+1]+(not * (k + res[Set{0, n - k - 1}->max()+1])) ; p := p*(win) ; win := win/(2) ; k := k + 1 ; ) ; res[n+1] := res[n+1]+(n * p) ) ; n := n + 1 ) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; OclFile["System.out"].printf("%.8f\n", res[n+1]) ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.HashSet ; import java.util.Scanner ; public class ModerateModulo { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=1 ; while(t-->0){ int x=sc.nextInt(); int y=sc.nextInt(); if(x==y){ System.out.println("infinity"); } else if(y>x){ System.out.println(0); } else { int ans=x-y ; HashSetset=new HashSet<>(); set.add(ans); for(int i=1 ; i*i<=ans ; i++){ if(ans % i==0){ set.add(i); set.add(ans/i); } } int res=0 ; for(int val : set){ int mod=x % val ; if(mod==y){ res++; } } System.out.println(res); } } } public static long Find(int x,int y){ long n=x ; if(x==y){ return n ; } else if(y % x==0){ return n ; } else { if(x>y){ } else { } } return n ; } } ------------------------------------------------------------ OCL File: --------- class ModerateModulo { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (x = y) then ( OclFile["System.out"].println("infinity") ) else if (y > x) then ( OclFile["System.out"].println(0) ) else ( var ans : int ; ans := x - y ; var set : Set(int) ; set := Set{} ; set := set->including(ans) ; var i : int ; i := 1 ; while i * i <= ans do ( ( if (ans mod i = 0) then ( set := set->including(i) ; set := set->including(ans / i) ) else skip ) ; i := i + 1 ) ; var res : int ; res := 0 ; for (val : set) do ( ( var mod : int ; mod := x mod val ; if (mod = y) then ( res := res + 1 ) else skip ) ) ; OclFile["System.out"].println(res) ; ) ; ) ; ) ); static operation Find( x : int, y : int) : long pre: true post: true activity: ( var n : long ; n := x ; if (x = y) then ( return n ) else if (y mod x = 0) then ( return n ) else ( if (x > y) then skip else skip ) ; ; return n ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long a=sc.nextLong(); long b=sc.nextLong(); long k=a-b ; if(k==0)System.out.println("infinity"); else if(kb){ if(k/i==i)count++; else count=count+2 ; } else { if((k/i!=i)&&(k/i>b))count++; } } } System.out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var k : long ; k := a - b ; if (k = 0) then OclFile["System.out"].println("infinity") else if (k < b) then OclFile["System.out"].println("0") else ( var count : long ; count := 0 ; var i : long ; i := 1 ; while i <= (k)->sqrt() do ( ( if (k mod i = 0) then ( if (i > b) then ( if (k / i = i) then count := count + 1 ; else count := count + 2 ; ) else ( if ((k / i /= i) & (k / i > b)) then count := count + 1 ; else skip ) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int sum=0 ; int l[]=new int[n]; for(int i=0 ; i=0 ; le--){ length+=l[le]; if(position==n-1 && le==0)continue ; if(length>=low)dp[position+1]=Math.min(dp[position+1],Math.max(length,dp[le])); } } ans=Math.min(ans,dp[n]-low); } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var l : Sequence(int) ; l := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( l[i+1] := sc.getCurrent()->toInteger() ; sum := sum+(l[i+1]) ) ; i := i + 1 ) ; var ans : int ; ans := 2147483647 ; var left : int ; left := 0 ; while left < n do ( ( var low : int ; low := 0 ; var right : int ; right := left ; while right < n do ( ( low := low+(l[right+1]) ; var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp[0+1] := low ; var position : int ; position := 0 ; while position < n do ( ( var length : int ; length := 0 ; dp[position + 1+1] := 2147483647 ; var le : int ; le := position ; while le >= 0 do ( ( length := length+(l[le+1]) ; if (position = n - 1 & le = 0) then continue else skip ; if (length >= low) then dp[position + 1+1] := Set{dp[position + 1+1], Set{length, dp[le+1]}->max()}->min() ; else skip ) ; le := le - 1 ) ) ; position := position + 1 ) ; ans := Set{ans, dp[n+1] - low}->min() ; ) ; right := right + 1 ) ) ; left := left + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int getMinVal(int p,int q){ if(q % p==0)return p ; return-1 ; } public static void main(String[] args){ int p=24,q=48 ; System.out.println(getMinVal(p,q)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getMinVal( p : int, q : int) : int pre: true post: true activity: ( if (q mod p = 0) then return p else skip ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var p : int ; p := 24 ; var q : int ; q := 48 ; OclFile["System.out"].println(getMinVal(p, q)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String isEvenOrOdd(int L,int R){ int oddCount=(R-L)/2 ; if(R % 2==1 || L % 2==1)oddCount++; if(oddCount % 2==0)return "Even" ; else return "Odd" ; } public static void main(String[] args){ int L=5,R=15 ; System.out.println(isEvenOrOdd(L,R)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isEvenOrOdd( L : int, R : int) : String pre: true post: true activity: ( var oddCount : int ; oddCount := (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" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 5 ; var R : int ; R := 15 ; OclFile["System.out"].println(isEvenOrOdd(L, R)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ma=sc.nextInt(); int mb=sc.nextInt(); int[][] dp=new int[401][401]; for(int i=0 ; i<401 ; i++){ Arrays.fill(dp[i],Integer.MAX_VALUE); } dp[0][0]=0 ; for(int i=0 ; i=a ; j--){ for(int k=400 ; k>=b ; k--){ if(dp[j-a][k-b]!=Integer.MAX_VALUE){ dp[j][k]=Math.min(dp[j][k],c+dp[j-a][k-b]); } } } } int ans=Integer.MAX_VALUE ; for(int i=1 ; 401>Math.max(ma,mb)*i ; i++){ if(dp[ma*i][mb*i]!=Integer.MAX_VALUE){ ans=Math.min(ans,dp[ma*i][mb*i]); } } if(ans==Integer.MAX_VALUE){ System.out.println(-1); } else { System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var ma : int ; ma := sc.getCurrent()->toInteger() ; var mb : int ; mb := sc.getCurrent()->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,401)->collect(Integer.subrange(1,401)->collect(0)) ; var i : int ; i := 0 ; while i < 401 do ( ( dp[i+1] := dp[i+1]->collect(2147483647) ) ; i := i + 1 ) ; dp[0+1][0+1] := 0 ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var j : int ; j := 400 ; while j >= a do ( ( var k : int ; k := 400 ; while k >= b do ( ( if (dp[j - a+1][k - b+1] /= 2147483647) then ( dp[j+1][k+1] := Set{dp[j+1][k+1], c + dp[j - a+1][k - b+1]}->min() ) else skip ) ; k := k - 1 ) ) ; j := j - 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 2147483647 ; var i : int ; i := 1 ; while 401 > Set{ma, mb}->max() * i do ( ( if (dp[ma * i+1][mb * i+1] /= 2147483647) then ( ans := Set{ans, dp[ma * i+1][mb * i+1]}->min() ) else skip ) ; i := i + 1 ) ; if (ans = 2147483647) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(ans) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- interface Main { static void main(String[] $){ var s=new java.util.Scanner(System.in); long n=s.nextInt(),a=n++*n++*n--/6,m=n ; while(m-->2){ long u=s.nextInt(),v=s.nextInt(); a-=(u 2) do ( m := m - 1 ; skip ; ( var u : long ; u := s.nextInt() ; var v : long ; v := s.nextInt() ; a := a-((if u < v then u else v endif) * n - u * v) ) ; ) ; OclFile["System.out"].print(a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Comparatorcomparator=new Comparator(){ @ Override public int compare(int[] o1,int[] o2){ return Double.compare((double)o1[0]/o1[1],(double)o2[0]/o2[1]); } }; Scanner sc=new Scanner(System.in); int INF=Integer.MAX_VALUE-500000 ; int N=Integer.parseInt(sc.next()); int Ma=Integer.parseInt(sc.next()); int Mb=Integer.parseInt(sc.next()); int[][] dp=new int[401][401]; for(int i=0 ; i=0 ; i--){ for(int j=400 ; j>=0 ; j--){ if(dp[i][j]!=INF){ dp[i+a][j+b]=Math.min(dp[i+a][j+b],dp[i][j]+c); } } } } int x=Ma ; int y=Mb ; int ans=INF ; while(x<400 && y<400){ ans=Math.min(ans,dp[x][y]); x+=Ma ; y+=Mb ; } if(ans!=INF)System.out.println(ans); else System.out.println(-1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var comparator : Function(,(,boolean)) ; comparator := OclComparator.newOclComparator() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var INF : int ; INF := 2147483647 - 500000 ; var N : int ; N := (sc.getCurrent())->toInteger() ; var Ma : int ; Ma := (sc.getCurrent())->toInteger() ; var Mb : int ; Mb := (sc.getCurrent())->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,401)->collect(Integer.subrange(1,401)->collect(0)) ; var i : int ; i := 0 ; while i < dp->size() do ( ( var j : int ; j := 0 ; while j < dp->size() do ( ( dp[i+1][j+1] := INF ) ; j := j + 1 ) ) ; i := i + 1 ) ; dp[0+1][0+1] := 0 ; var k : int ; k := 0 ; while k < N do ( ( var a : int ; a := (sc.getCurrent())->toInteger() ; var b : int ; b := (sc.getCurrent())->toInteger() ; var c : int ; c := (sc.getCurrent())->toInteger() ; var i : int ; i := 400 ; while i >= 0 do ( ( var j : int ; j := 400 ; while j >= 0 do ( ( if (dp[i+1][j+1] /= INF) then ( dp[i + a+1][j + b+1] := Set{dp[i + a+1][j + b+1], dp[i+1][j+1] + c}->min() ) else skip ) ; j := j - 1 ) ) ; i := i - 1 ) ) ; k := k + 1 ) ; var x : int ; x := Ma ; var y : int ; y := Mb ; var ans : int ; ans := INF ; while (x < 400 & y < 400) do ( ans := Set{ans, dp[x+1][y+1]}->min() ; x := x+(Ma) ; y := y+(Mb) ) ; if (ans /= INF) then OclFile["System.out"].println(ans) else OclFile["System.out"].println(-1) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int gcd(int a,int b){ if(a==0 || b==0)return 0 ; if(a==b)return a ; if(a>b)return gcd(a-b,b); return gcd(a,b-a); } static int cpFact(int x,int y){ while(gcd(x,y)!=1){ x=x/gcd(x,y); } return x ; } public static void main(String[] args){ int x=15 ; int y=3 ; System.out.println(cpFact(x,y)); x=14 ; y=28 ; System.out.println(cpFact(x,y)); x=7 ; y=3 ; System.out.println(cpFact(x,y)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int 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 > b) then return gcd(a - b, b) else skip ; return gcd(a, b - a) ); static operation cpFact( x : int, y : int) : int pre: true post: true activity: ( while (gcd(x, y) /= 1) do ( x := x / gcd(x, y) ) ; return x ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 15 ; var y : int ; y := 3 ; OclFile["System.out"].println(cpFact(x, y)) ; x := 14 ; y := 28 ; OclFile["System.out"].println(cpFact(x, y)) ; x := 7 ; y := 3 ; OclFile["System.out"].println(cpFact(x, y)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); long ans=getCount(n,m); System.out.println(ans); } public static long getCount(int n,int m){ int mod=1000000009 ; long max=myPow(2,m,mod)-1 ; if(n>max){ return 0 ; } long ans=1 ; for(int i=0 ; i0){ result=result*x % mod ; } x=x*x % mod ; n>>=1 ; } return result ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var ans : long ; ans := getCount(n, m) ; OclFile["System.out"].println(ans) ; ); static operation getCount( n : int, m : int) : long pre: true post: true activity: ( var mod : int ; mod := 1000000009 ; var max : long ; max := myPow(2, m, mod) - 1 ; if (n > max) then ( return 0 ) else skip ; var ans : long ; ans := 1 ; var i : int ; i := 0 ; while i < n do ( ( ans := (((ans mod mod) * (max mod mod) mod mod) + mod) mod mod ; max := max - 1 ) ; i := i + 1 ) ; return ans ); static operation myPow( x : long, n : long, mod : int) : long pre: true post: true activity: ( var result : long ; result := 1 ; while (n /= 0) do ( if ((MathLib.bitwiseAnd(n,1)) > 0) then ( result := result * x mod mod ) else skip ; x := x * x mod mod ; n := n/(2->pow(1)) ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.geom.Rectangle2D ; import java.io.IOException ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.HashMap ; import java.util.LinkedList ; import java.util.List ; import java.util.ListIterator ; import java.util.PriorityQueue ; import java.util.Scanner ; public class Main { public static final int MAX=100000 ; public static final int MAX_D=15 ; public static void main(String[] args){ final Scanner sc=new Scanner(System.in); double[][] DP=new double[MAX+1][MAX_D+1]; double[] ans=new double[MAX]; DP[0][0]=1 ; double sum=0 ; for(int day=0 ; daycollect(Integer.subrange(1,MAX_D + 1)->collect(0.0)) ; var ans : Sequence(double) ; ans := Integer.subrange(1,MAX)->collect(0.0) ; DP[0+1][0+1] := 1 ; var sum : double ; sum := 0 ; var day : int ; day := 0 ; while day < MAX do ( ( var suc : int ; suc := 0 ; while suc < MAX_D do ( ( if (DP[day+1][suc+1] <= 0) then ( continue ) else skip ; sum := sum+(DP[day+1][suc+1] * 0.5->pow(suc)) ; if (suc = 0) then ( DP[day + 1+1][suc + 1+1] := DP[day + 1+1][suc + 1+1]+(DP[day+1][suc+1]) ) else ( DP[day + 1+1][0+1] := DP[day + 1+1][0+1]+(DP[day+1][suc+1] * (1 - 0.5->pow(suc))) ; DP[day + 1+1][suc + 1+1] := DP[day + 1+1][suc + 1+1]+(DP[day+1][suc+1] * 0.5->pow(suc)) ) ) ; suc := suc + 1 ) ; ans[day+1] := sum ) ; day := day + 1 ) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then ( break ) else skip ; OclFile["System.out"].println(ans[n - 1+1]) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static long n,m ; static long mod=(long)1e9+9 ; static StringBuffer str=new StringBuffer(); static long mod_mul(long a,long b){ a=a % mod ; b=b % mod ; return(((a*b)% mod)+mod)% mod ; } static long pow(long a,long b){ long res=1 ; while(b>0){ if(b % 2==1){ res=(res*a)% mod ; b--; } else { a=(a*a)% mod ; b=b>>1 ; } } return res ; } static void solve(){ long tot=pow(2,m)-1 ; if(n>tot){ str.append(0); return ; } long ans=1 ; for(int i=1 ; i<=n ; i++)ans=mod_mul(ans,tot--)% mod ; str.append(ans).append("\n"); } public static void main(String[] args)throws java.lang.Exception { BufferedReader bf ; PrintWriter pw ; boolean lenv=false ; if(lenv){ bf=new BufferedReader(new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); } else { bf=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out)); } String st[]=bf.readLine().trim().split("\\s+"); n=Long.parseLong(st[0]); m=Long.parseLong(st[1]); solve(); pw.println(str); pw.flush(); } } ------------------------------------------------------------ OCL File: --------- class Coder { static attribute n : long; static attribute mod : long := 1e9->oclAsType(long) + 9; static attribute str : String := StringLib.newString(); static operation mod_mul( a : long, b : long) : long pre: true post: true activity: ( a := a mod mod ; b := b mod mod ; return (((a * b) mod mod) + mod) mod mod ); static operation pow( a : long, b : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (b > 0) do ( if (b mod 2 = 1) then ( res := (res * a) mod mod ; b := b - 1 ) else ( a := (a * a) mod mod ; b := (b/(2->pow(1)))->oclAsType(long) ) ) ; return res ); static operation solve() : void pre: true post: true activity: ( var tot : long ; tot := pow(2, m) - 1 ; if (n > tot) then ( str := str + StringLib.newString(0) ; return ) else skip ; var ans : long ; ans := 1 ; var i : int ; i := 1 ; while i <= n do ( ans := mod_mul(ans, tot) mod mod ; ; i := i + 1 ) ; str := str + StringLib.newString(ans) + StringLib.newString("\n") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; var pw : OclFile ; var lenv : boolean ; lenv := false ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; var st : Sequence(String) ; st := bf.readLine()->trim()->split("\\s+") ; n := (st[0+1])->toLong() ; m := (st[1+1])->toLong() ; execute solve() ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A238 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int M=in.nextInt(); long mod=1000000009 ; long next=1 ; for(int m=0 ; mtoInteger() ; var M : int ; M := in.getCurrent()->toInteger() ; var mod : long ; mod := 1000000009 ; var next : long ; next := 1 ; var m : int ; m := 0 ; while m < M do ( ( next := next*(2) ; next := next mod mod ) ; m := m + 1 ) ; var answer : long ; answer := 1 ; var n : int ; n := 0 ; while n < N do ( ( next := next - 1 ; answer := answer*(next) ; answer := answer mod mod ) ; n := n + 1 ) ; if (answer < 0) then ( answer := answer+(mod) ) else skip ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static BufferedReader bf ; static PrintWriter pw ; static int n,m ; static long mod=(long)1e9+9 ; static long pow(long a,long b){ long res=1 ; while(b>0){ if(b % 2==1)res=(res*a)% mod ; a=(a*a)% mod ; b=b>>1l ; } return res ; } static void solve(int te)throws Exception { long val=(pow(2,m)-n+mod)% mod ; long ans=val ; for(int i=2 ; i<=n ; i++){ val=(val+1)% mod ; ans=(ans*val)% mod ; } str.append(ans).append("\n"); } public static void main(String[] args)throws java.lang.Exception { boolean lenv=false ; int te=1 ; if(lenv){ bf=new BufferedReader(new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); } else { bf=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out)); } String s[]=bf.readLine().trim().split("\\s+"); n=Integer.parseInt(s[0]); m=Integer.parseInt(s[1]); solve(te); pw.print(str); pw.flush(); } } ------------------------------------------------------------ OCL File: --------- class Coder { static attribute str : String := StringLib.newString(); static attribute bf : OclFile; static attribute pw : OclFile; static attribute n : int; static attribute mod : long := 1e9->oclAsType(long) + 9; static operation pow( a : long, b : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (b > 0) do ( if (b mod 2 = 1) then res := (res * a) mod mod ; else skip ; a := (a * a) mod mod ; b := (b/(2->pow(1l)))->oclAsType(long) ) ; return res ); static operation solve( te : int) : void pre: true post: true activity: ( var val : long ; val := (pow(2, m) - n + mod) mod mod ; var ans : long ; ans := val ; var i : int ; i := 2 ; while i <= n do ( ( val := (val + 1) mod mod ; ans := (ans * val) mod mod ) ; i := i + 1 ) ; str := str + StringLib.newString(ans) + StringLib.newString("\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var lenv : boolean ; lenv := false ; var te : int ; te := 1 ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; var s : Sequence(String) ; s := bf.readLine()->trim()->split("\\s+") ; n := (s[0+1])->toInteger() ; m := (s[1+1])->toInteger() ; execute solve(te) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class TaskB { static final int SIZE=(int)1e5+5 ; static long[] a=new long[SIZE]; public static void solve(InputReader in,PrintWriter out){ long w=in.nextLong(),h=in.nextLong(); long res=0 ; long base=(h/2+1)*(h/2)/2 ; for(int i=2 ; i<=w ; i+=2){ if(h % 2==0){ res+=(w-i+1)*(base*2-h/2); } else { res+=(w-i+1)*(base*2); } } out.println(res); } private static class InputReader { private BufferedReader reader ; private StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public String nextLine(){ String str="" ; try { str=reader.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int T=1 ; for(int i=1 ; i<=T ; ++i){ solve(in,out); } out.close(); } } ------------------------------------------------------------ OCL File: --------- class TaskB { static attribute SIZE : int := 1e5->oclAsType(int) + 5; static attribute a : Sequence(long) := Integer.subrange(1,SIZE)->collect(0); static operation solve( in : InputReader, out : OclFile) : void pre: true post: true activity: ( var w : long ; w := in.nextLong() ; var h : long ; h := in.nextLong() ; var res : long ; res := 0 ; var base : long ; base := (h / 2 + 1) * (h / 2) / 2 ; var i : int ; i := 2 ; while i <= w do ( ( if (h mod 2 = 0) then ( res := res+((w - i + 1) * (base * 2 - h / 2)) ) else ( res := res+((w - i + 1) * (base * 2)) ) ) ; i := i+(2) ) ; out.println(res) ; ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := reader.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : InputReader ; in := InputReader.newInputReader(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var T : int ; T := 1 ; var i : int ; i := 1 ; while i <= T do ( ( execute solve(in, out) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; class GFG { static double PI=3.14159265 ; public static double area_inscribed(double a){ return(a*a*(PI/12)); } public static double perm_inscribed(double a){ return(PI*(a/Math.sqrt(3))); } public static void main(String[] args){ double a=6.0 ; System.out.println("Area of inscribed circle is :"+area_inscribed(a)); System.out.println("\nPerimeter of inscribed circle is :"+perm_inscribed(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute PI : double := 3.14159265; static operation area_inscribed( a : double) : double pre: true post: true activity: ( return (a * a * (PI / 12)) ); static operation perm_inscribed( a : double) : double pre: true post: true activity: ( return (PI * (a / (3)->sqrt())) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 6.0 ; OclFile["System.out"].println("Area of inscribed circle is :" + area_inscribed(a)) ; OclFile["System.out"].println("\nPerimeter of inscribed circle is :" + perm_inscribed(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static class Node { char data ; Node prev ; Node next ; } static Node head=null ; static void rotate(int N){ if(N==0)return ; Node current=head ; int count=1 ; while(count ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; public class BearAndPrime { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Listprimes=new ArrayList<>(); Collections.addAll(primes,3,5,7,11,13,17,19,23,29,31,37,41,43,47); System.out.println(2); String response=br.readLine(); if(response.equals("yes")){ for(int p=2 ; p<=6 ; p++){ System.out.println((int)Math.pow(2,p)); response=br.readLine(); if(response.equals("yes")){ System.out.println("composite"); return ; } } for(int num : primes){ System.out.println(num); response=br.readLine(); if(response.equals("yes")){ System.out.println("composite"); return ; } } System.out.println("prime"); return ; } Listdivisors=new ArrayList<>(); for(int num : primes){ System.out.println(num); response=br.readLine(); if(response.equals("yes")){ divisors.add(num); } } if(divisors.size()>=2){ System.out.println("composite"); return ; } if(divisors.size()==0){ System.out.println("prime"); return ; } int d=divisors.get(0); if(d>=3 && d<=7){ System.out.println(d*d); response=br.readLine(); if(response.equals("yes")){ System.out.println("composite"); return ; } } System.out.println("prime"); return ; } } ------------------------------------------------------------ OCL File: --------- class BearAndPrime { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var primes : Sequence(int) ; primes := Sequence{} ; addAll(primes, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47) ; OclFile["System.out"].println(2) ; var response : String ; response := br.readLine() ; if (response = "yes") then ( var p : int ; p := 2 ; while p <= 6 do ( ( OclFile["System.out"].println(2->pow(p)->oclAsType(int)) ; response := br.readLine() ; if (response = "yes") then ( OclFile["System.out"].println("composite") ; return ) else skip ) ; p := p + 1 ) ; for (num : primes) do ( ( OclFile["System.out"].println(num) ; response := br.readLine() ; if (response = "yes") then ( OclFile["System.out"].println("composite") ; return ) else skip ) ) ; OclFile["System.out"].println("prime") ; return ) else skip ; var divisors : Sequence(int) ; divisors := Sequence{} ; for (num : primes) do ( ( OclFile["System.out"].println(num) ; response := br.readLine() ; if (response = "yes") then ( divisors := divisors->including(num) ) else skip ) ) ; if (divisors->size() >= 2) then ( OclFile["System.out"].println("composite") ; return ) else skip ; if (divisors->size() = 0) then ( OclFile["System.out"].println("prime") ; return ) else skip ; var d : int ; d := divisors->at(0+1) ; if (d >= 3 & d <= 7) then ( OclFile["System.out"].println(d * d) ; response := br.readLine() ; if (response = "yes") then ( OclFile["System.out"].println("composite") ; return ) else skip ) else skip ; OclFile["System.out"].println("prime") ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { MyScanner sc=new MyScanner(); PrintWriter out=new PrintWriter(System.out); int N=sc.nextInt(); long edges=0 ; for(int i=0 ; imin() ; var max : long ; max := Set{a, b}->max() ; edges := edges+(min * (N + 1 - max)) ; ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : long ; i := 1 ; while i <= N do ( ( ans := ans+((i * (i + 1)) / 2) ) ; i := i + 1 ) ; ans := ans-(edges) ; skip ; skip ; ); static class MyScanner { attribute br : OclFile; attribute tokenizer : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String str=sc.next(); for(int i=0 ; itoInteger() ; var str : String ; str := sc.getCurrent() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(str->at(i+1)) ; if (n mod 2 = 0) then ( if (i mod 2 = 1 & i /= (n - 1)) then OclFile["System.out"].print("-") ; else skip ) else if (i mod 2 = 1 & i /= (n - 2)) then OclFile["System.out"].print("-") ; else skip ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); String str=scanner.next(); int i=0 ; int v=(int)(Math.random()*114514)+114514 ; while(itoInteger() ; var str : String ; str := scanner.getCurrent() ; var i : int ; i := 0 ; var v : int ; v := (MathLib.random() * 114514)->oclAsType(int) + 114514 ; while (i < n) do ( if (n - (i)->char2byte() = 3) then ( OclFile["System.out"].printf("%c%c%c", str->at(i+1), str->at(i + 1+1), str->at(i + 2+1)) ) else if (n - (i)->char2byte() = 4) then ( OclFile["System.out"].printf("%c%c-%c%c", str->at(i+1), str->at(i + 1+1), str->at(i + 2+1), str->at(i + 3+1)) ) else if (n - (i)->char2byte() = 2) then ( OclFile["System.out"].printf("%c%c", str->at(i+1), str->at(i + 1+1)) ) else skip ; ; ; if (n - (i)->char2byte() <= 4) then ( break ) else skip ; var j : int ; j := 2 + v mod 2 ; var s : int ; s := 0 ; while s < j do ( ( OclFile["System.out"].printf("%c", str->at(i + s+1)) ) ; s := s + 1 ) ; OclFile["System.out"].printf("-") ; i := i+(j) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int x[]=new int[n+1]; int ji[]=new int[n+1]; int shu[]=new int[n/2]; for(int i=0 ; itoInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n + 1)->collect(0) ; var ji : Sequence(int) ; ji := Integer.subrange(1,n + 1)->collect(0) ; var shu : Sequence(int) ; shu := Integer.subrange(1,n / 2)->collect(0) ; var i : int ; i := 0 ; while i < n / 2 do ( ( shu[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; shu := shu->sort() ; var l1 : int ; l1 := 0 ; var l2 : int ; l2 := 0 ; var i : int ; i := 0 ; while i < n / 2 do ( ( var s1 : int ; s1 := i * 2 + 1 ; var s2 : int ; s2 := i * 2 + 2 ; var id : int ; id := shu[i+1] ; if (id /= s1) then ( l1 := l1 + if s1 - id < 0 then -(s1 - id) else s1 - id endif ) else skip ; if (id /= s2) then ( l2 := l2 + if s2 - id < 0 then -(s2 - id) else s2 - id endif ) else skip ; ) ; i := i + 1 ) ; var min : int ; min := Set{l1, l2}->min() ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int N=stdIn.nextInt(); int count=0 ; int temp=N ; int ans=0 ; while(temp>0){ temp/=10 ; count++; } for(int i=1 ; i<=count ; i++){ if(i==count){ if(i % 2==1){ ans+=(N-Math.pow(10,i-1)+1); } } else { if(i==1){ ans+=9 ; } else if(i % 2==1){ ans+=(Math.pow(10,i)-Math.pow(10,i-1)); } } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := stdIn.getCurrent()->toInteger() ; var count : int ; count := 0 ; var temp : int ; temp := N ; var ans : int ; ans := 0 ; while (temp > 0) do ( temp := temp/(10) ; count := count + 1 ) ; var i : int ; i := 1 ; while i <= count do ( ( if (i = count) then ( if (i mod 2 = 1) then ( ans := ans+((N - 10->pow(i - 1) + 1)) ) else skip ) else ( if (i = 1) then ( ans := ans+(9) ) else if (i mod 2 = 1) then ( ans := ans+((10->pow(i) - 10->pow(i - 1))) ) else skip ; ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); String s=sc.next(); String ans="" ; if(k % 2==0){ for(int i=0 ; itoInteger() ; var s : String ; s := sc.getCurrent() ; var ans : String ; ans := "" ; if (k mod 2 = 0) then ( var i : int ; i := 0 ; while i < s->size() do ( ( if (i + 2 = s->size()) then ( OclFile["System.out"].print(s->at(i+1)) ; OclFile["System.out"].print(s->at(i + 1+1)) ; break ) else ( OclFile["System.out"].print(s->at(i+1)) ; OclFile["System.out"].print(s->at(i + 1+1)) ; OclFile["System.out"].print('-') ) ) ; i := i+(2) ) ) else if (k mod 2 /= 0) then ( var i : int ; i := 0 ; while i < s->size() do ( ( if (i + 2 = s->size() - 1) then ( OclFile["System.out"].print(s->at(i+1)) ; OclFile["System.out"].print(s->at(i + 1+1)) ; OclFile["System.out"].print(s->at(i + 2+1)) ; break ) else ( OclFile["System.out"].print(s->at(i+1)) ; OclFile["System.out"].print(s->at(i + 1+1)) ; OclFile["System.out"].print('-') ) ) ; i := i + 2 ) ) else skip ; ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String str=sc.next(); for(int i=0 ; itoInteger() ; var str : String ; str := sc.getCurrent() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(str->at(i+1)) ; if (n mod 2 = 0) then ( if (i mod 2 = 1 & i /= (n - 1)) then OclFile["System.out"].print("-") ; else skip ) else if (i mod 2 = 1 & i /= (n - 2)) then OclFile["System.out"].print("-") ; else skip ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),q ; long sum=0 ; int[] a=new int[n],x=new int[100001]; for(int i=0 ; itoInteger() ; var q : int ; var sum : long ; sum := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var x : Sequence(int) ; x := Integer.subrange(1,100001)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; x[a[i+1]+1] := x[a[i+1]+1] + 1 ; sum := sum+(a[i+1]->oclAsType(long)) ) ; i := i + 1 ) ; q := sc.getCurrent()->toInteger() ; var b : Sequence(int) ; b := Integer.subrange(1,q)->collect(0) ; var c : Sequence(int) ; c := Integer.subrange(1,q)->collect(0) ; var d : Sequence(int) ; d := Integer.subrange(1,q)->collect(0) ; var i : int ; i := 0 ; while i < q do ( ( b[i+1] := sc.getCurrent()->toInteger() ; c[i+1] := sc.getCurrent()->toInteger() ; d[i+1] := c[i+1] - b[i+1] ; sum := sum + (x[b[i+1]+1] * d[i+1])->oclAsType(long) ; OclFile["System.out"].println(sum) ; x[c[i+1]+1] := x[c[i+1]+1]+(x[b[i+1]+1]) ; x[b[i+1]+1] := 0 ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String hi[])throws Exception { BufferedReader infile=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(infile.readLine()); int N=Integer.parseInt(st.nextToken()); int[] arr=new int[N]; st=new StringTokenizer(infile.readLine()); for(int i=0 ; i0){ st=new StringTokenizer(infile.readLine()); int B=Integer.parseInt(st.nextToken()); int C=Integer.parseInt(st.nextToken()); long lost=(long)B*freq[B]; long gain=(long)C*freq[B]; res+=gain-lost ; freq[C]+=freq[B]; freq[B]=0 ; sb.append(res+"\n"); } System.out.print(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( hi : Sequence(String)) : void pre: true post: true activity: ( var infile : OclFile ; infile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(infile.readLine()) ; var N : int ; N := (st.next())->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; st := OclIterator.newOclIterator_String(infile.readLine()) ; var i : int ; i := 0 ; while i < N do ( arr[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; var res : long ; res := 0L ; for (x : arr) do ( res := res+(x) ; ) ; var freq : Sequence(int) ; freq := Integer.subrange(1,100001)->collect(0) ; for (x : arr) do ( freq[x+1] := freq[x+1] + 1 ; ) ; var sb : String ; sb := StringLib.newString() ; var Q : int ; Q := (infile.readLine())->toInteger() ; while (Q > 0) do ( Q := Q - 1 ; skip ; ( st := OclIterator.newOclIterator_String(infile.readLine()) ; var B : int ; B := (st.next())->toInteger() ; var C : int ; C := (st.next())->toInteger() ; var lost : long ; lost := B->oclAsType(long) * freq[B+1] ; var gain : long ; gain := C->oclAsType(long) * freq[B+1] ; res := res+(gain - lost) ; freq[C+1] := freq[C+1]+(freq[B+1]) ; freq[B+1] := 0 ; sb := sb + StringLib.newString(res + "\n") ; ) ; ) ; OclFile["System.out"].print(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ MyScanner sc=new MyScanner(); int n=sc.nextInt(); long[] cnt=new long[100100]; long sum=0 ; for(int i=0 ; icollect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.nextInt() ; cnt[a+1] := cnt[a+1] + 1 ; sum := sum+(a) ) ; i := i + 1 ) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var q : int ; q := sc.nextInt() ; var i : int ; i := 0 ; while i < q do ( ( var b : int ; b := sc.nextInt() ; var c : int ; c := sc.nextInt() ; sum := sum-(b * cnt[b+1]) ; sum := sum+(c * cnt[b+1]) ; skip ; cnt[c+1] := cnt[c+1]+(cnt[b+1]) ; cnt[b+1] := 0 ; ) ; i := i + 1 ) ; skip ; ); static class MyScanner { attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), (1*(2->pow(15)))->oclAsType(long)); attribute tokenizer : OclIterator; operation next() : String pre: true post: true activity: ( try ( while (tokenizer = null or not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (ignored : IOException) do skip return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public final class Main { public static void main(String[] args){ final Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); final int n=Integer.parseInt(in.nextLine()); Mapfreq=new HashMap<>(); long sum=0 ; for(int i=0 ; itoInteger() ; var freq : Map(int,int) ; freq := Map{} ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var curr : int ; curr := in.getCurrent()->toInteger() ; sum := sum+(curr) ; freq := freq.merge(curr, 1, lambda _pars : OclAny in Integer.newInteger().sum(_pars)) ) ; i := i + 1 ) ; skip ; var q : int ; q := (in.nextLine())->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var num : int ; num := in.getCurrent()->toInteger() ; var val : int ; val := in.getCurrent()->toInteger() ; if (freq->keys()->includes(num)) then ( var count : int ; count := freq->at(num) ; sum := sum+(count->oclAsType(long) * (val - num)) ; freq := freq.merge(val, count, lambda _pars : OclAny in Integer.newInteger().sum(_pars)) ) else skip ; OclFile["System.out"].println(sum) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static StringTokenizer st ; static BufferedReader br ; static PrintWriter out ; static int parent[]; public static void main(String[] args)throws IOException { br=new BufferedReader(new InputStreamReader(System.in)); int N=nextInt(); int[] A=new int[100000+1]; long sum=0 ; for(int x=0 ; xcollect(0) ; var sum : long ; sum := 0 ; var x : int ; x := 0 ; while x < N do ( ( var temp : int ; temp := nextInt() ; A[temp+1] := A[temp+1] + 1 ; sum := sum+(temp) ) ; x := x + 1 ) ; var Q : int ; Q := nextInt() ; var x : int ; x := 0 ; while x < Q do ( ( var B : int ; B := nextInt() ; var C : int ; C := nextInt() ; sum := sum+(C * A[B+1] - B * A[B+1]) ; A[C+1] := A[C+1]+(A[B+1]) ; A[B+1] := 0 ; OclFile["System.out"].println(sum) ; ) ; x := x + 1 ) ; ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); static operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); static operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()->trim()) ; ; return st.next() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B1542 { public static void main(String[] args){ Scanner in=new Scanner(System.in); StringBuilder out=new StringBuilder(); int T=in.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var A : int ; A := in.getCurrent()->toInteger() ; var B : int ; B := in.getCurrent()->toInteger() ; var found : boolean ; found := false ; if (A = 1) then ( found := ((N - 1) mod B) = 0 ) else ( var number : long ; number := 1 ; while (number <= N) do ( if ((N - number) mod B = 0) then ( found := true ; break ) else skip ; number := number*(A) ) ) ; out := out + StringLib.newString(if found then "Yes\n" else "No\n" endif) ; ) ; t := t + 1 ) ; OclFile["System.out"].print(out) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int a=Integer.parseInt(sc.next()); int b=Integer.parseInt(sc.next()); char[] ch=sc.next().toCharArray(); String ans="" ; for(int i=0 ; itoInteger() ; var b : int ; b := (sc.getCurrent())->toInteger() ; var ch : Sequence(String) ; ch := sc.getCurrent()->characters() ; var ans : String ; ans := "" ; var i : int ; i := 0 ; while i < a do ( ( if (i = b - 1) then ( ans := ans+((ch[i+1] + "")->toLowerCase()) ) else ( ans := ans+(ch[i+1]) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws Exception { int num=998244353 ; BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int n=Integer.parseInt(bf.readLine()); long sum=0 ; for(int i=1 ; i<=n ; i++){ sum+=(long)(i)*(long)((n-i+1)); } for(int i=0 ; itoInteger() ; var sum : long ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( ( sum := sum+((i)->oclAsType(long) * ((n - i + 1))->oclAsType(long)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String(bf.readLine()) ; var v1 : int ; v1 := (st.next())->toInteger() ; var v2 : int ; v2 := (st.next())->toInteger() ; var min : int ; min := Set{v1, v2}->min() ; var max : int ; max := Set{v1, v2}->max() ; sum := sum-((min)->oclAsType(long) * ((n - max + 1))->oclAsType(long)) ; ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ exec(); } static void exec(){ PrintWriter out=new PrintWriter(System.out); Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int length=String.valueOf(n).length(); if(length % 2==0){ StringBuilder sb=new StringBuilder(); for(int i=length-1 ; i>0 ; i--){ if(i % 2==0){ sb.append("0"); } else { sb.append("9"); } } out.print(sb); } else if(length==1){ out.print(n); } else { int count=0 ; int base=1 ; for(int i=0 ; i0 ; i--){ if(i % 2==0){ sb.append("0"); } else { sb.append("9"); } } count=count+Integer.parseInt(sb.toString()); out.print(count); } out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute exec() ); static operation exec() : void pre: true post: true activity: ( var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var length : int ; length := ((n) + "")->size() ; if (length mod 2 = 0) then ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := length - 1 ; while i > 0 do ( ( if (i mod 2 = 0) then ( sb := sb + StringLib.newString("0") ) else ( sb := sb + StringLib.newString("9") ) ) ; i := i - 1 ) ; skip ) else if (length = 1) then ( skip ) else ( var count : int ; count := 0 ; var base : int ; base := 1 ; var i : int ; i := 0 ; while i < length - 1 do ( ( base := base * 10 ) ; i := i + 1 ) ; count := count + (n - base) + 1 ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := length - 2 ; while i > 0 do ( ( if (i mod 2 = 0) then ( sb := sb + StringLib.newString("0") ) else ( sb := sb + StringLib.newString("9") ) ) ; i := i - 1 ) ; count := count + (sb+"")->toInteger() ; skip ; ) ; ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); for(int xix=0 ; xixtoInteger() ; var xix : int ; xix := 0 ; while xix < test do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var val : long ; val := 1 ; while (val < n & val mod b /= n mod b & a /= 1) do ( val := val*(a) ) ; if (val mod b = n mod b & val <= n) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ) ; xix := xix + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final long mod=1000000007 ; static final long max=1001 ; static long nCr[][]=new long[1003][1003]; static void preComputeCoeff(){ for(int i=0 ; icollect(Integer.subrange(1,1003)->collect(0)); static operation preComputeCoeff() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < max do ( ( var j : int ; j := 0 ; while j <= i 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 ; ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation computeStringCount( N : int) : long pre: true post: true activity: ( var n : int ; n := N / 2 ; var ans : long ; ans := 0 ; var i : int ; i := 2 ; while i <= n do ( ans := (ans + ((nCr[n+1][i+1] * nCr[n+1][i / 2+1]) mod mod)) mod mod ; ; i := i+(2) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute preComputeCoeff() ; var N : int ; N := 3 ; OclFile["System.out"].println(computeStringCount(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int[] arr=new int[33]; static void balTernary(int ter){ int carry=0,base=10 ; int i=32 ; while(ter>0){ int rem=ter % base ; rem=rem+carry ; if(rem==0){ arr[i--]=0 ; carry=0 ; } else if(rem==1){ arr[i--]=1 ; carry=0 ; } else if(rem==2){ arr[i--]=-1 ; carry=1 ; } else if(rem==3){ arr[i--]=0 ; carry=1 ; } ter=(int)(ter/base); } if(carry==1)arr[i]=1 ; } static int ternary(int number){ int ans=0,rem=1,base=1 ; while(number>0){ rem=number % 3 ; ans=ans+rem*base ; number=(int)(number/3); base=base*10 ; } return ans ; } public static void main(String args[]){ int number=3056 ; int ter=ternary(number); Arrays.fill(arr,0); balTernary(ter); int i=0 ; while(arr[i]==0){ i++; } for(int j=i ; j<=32 ; j++){ if(arr[j]==-1)System.out.print('Z'); else System.out.print(arr[j]); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute arr : Sequence(int) := Integer.subrange(1,33)->collect(0); static operation balTernary( ter : int) : void pre: true post: true activity: ( var carry : int ; carry := 0 ; var base : int ; base := 10 ; var i : int ; i := 32 ; while (ter > 0) do ( var rem : int ; rem := ter mod base ; rem := rem + carry ; if (rem = 0) then ( arr[i+1] := 0 ; i := i - 1 ; carry := 0 ) else if (rem = 1) then ( arr[i+1] := 1 ; i := i - 1 ; carry := 0 ) else if (rem = 2) then ( arr[i+1] := -1 ; i := i - 1 ; carry := 1 ) else if (rem = 3) then ( arr[i+1] := 0 ; i := i - 1 ; carry := 1 ) else skip ; ; ; ; ter := (ter / base)->oclAsType(int) ) ; if (carry = 1) then arr[i+1] := 1 ; else skip ); static operation ternary( number : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var rem : int ; rem := 1 ; var base : int ; base := 1 ; while (number > 0) do ( rem := number mod 3 ; ans := ans + rem * base ; number := (number / 3)->oclAsType(int) ; base := base * 10 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var number : int ; number := 3056 ; var ter : int ; ter := ternary(number) ; arr := arr->collect(0) ; execute balTernary(ter) ; var i : int ; i := 0 ; while (arr[i+1] = 0) do ( i := i + 1 ) ; var j : int ; j := i ; while j <= 32 do ( ( if (arr[j+1] = -1) then OclFile["System.out"].print('Z') ; else OclFile["System.out"].print(arr[j+1]) ; ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Translation { static Scanner sr=new Scanner(System.in); public static void main(String args[]){ String s1=sr.nextLine(); String s2=sr.nextLine(); if(s1.length()!=s2.length()){ System.out.println("NO"); } else { s1=new StringBuilder(s1).reverse().toString(); ; if(s1.equals(s2)){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class Translation { static attribute sr : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s1 : String ; s1 := sr.nextLine() ; var s2 : String ; s2 := sr.nextLine() ; if (s1->size() /= s2->size()) then ( OclFile["System.out"].println("NO") ) else ( s1 := StringLib.newString(s1)->reverse()+"" ; if (s1 = s2) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Codesolver { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String st,st1 ; st=sc.nextLine(); st1=sc.nextLine(); int len=st.length(); int len1=st1.length(); int as=0 ; if(len==len1){ for(int i=0 ; isize() ; var len1 : int ; len1 := st1->size() ; var as : int ; as := 0 ; if (len = len1) then ( var i : int ; i := 0 ; while i < len do ( ( if (st->at(i+1) = st1->at((len)->char2byte() - i - 1+1)) then ( as := as + 1 ) else break ) ; i := i + 1 ) ; if (as /= len) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ) ) else ( OclFile["System.out"].println("NO") ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class code { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); String t=sc.next(); StringBuilder sb=new StringBuilder(s); StringBuilder rev=sb.reverse(); String m=rev.toString(); if(m.equals(t)){ System.out.println("YES"); } else { System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class code { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; var t : String ; t := sc.getCurrent() ; var sb : String ; sb := StringLib.newString(s) ; var rev : String ; rev := sb->reverse() ; var m : String ; m := rev+"" ; if (m = t) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForces { public static void main(String[] args){ Scanner scan=new Scanner(System.in); try { String word=scan.next(); String wordCheck=scan.next(); String reverse_word="" ; for(int i=wordCheck.length()-1 ; i>=0 ; i--){ reverse_word+=word.charAt(i); } if(reverse_word.equals(wordCheck))System.out.println("YES"); else System.out.println("NO"); } catch(Exception e){ System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class CodeForces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; try ( var word : String ; word := scan.getCurrent() ; var wordCheck : String ; wordCheck := scan.getCurrent() ; var reverse_word : String ; reverse_word := "" ; var i : int ; i := wordCheck->size() - 1 ; while i >= 0 do ( ( reverse_word := reverse_word+(word->at(i+1)) ) ; i := i - 1 ) ; if (reverse_word = wordCheck) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) catch (e : ProgramException) do ( OclFile["System.out"].println("NO") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Test3 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String st=sc.next(); String st1=sc.next(); String ts=new StringBuffer(st).reverse().toString(); if(st1.equals(ts)){ System.out.println("YES"); } else { System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class Test3 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var st : String ; st := sc.getCurrent() ; var st1 : String ; st1 := sc.getCurrent() ; var ts : String ; ts := StringLib.newString(st)->reverse()+"" ; if (st1 = ts) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String replaceSpace(String str){ String s="" ; for(int i=0 ; isize() do ( ( if (str->at(i+1) = ' ') then s := s+('-') ; else s := s+(str->at(i+1)) ; ) ; i := i + 1 ) ; return s ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "A computer science portal for geeks" ; OclFile["System.out"].println(replaceSpace(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maxCount(int A[],int N,int K){ int maximum=0 ; int i=0,j=0 ; int start=0 ; int end=0 ; Arrays.sort(A); for(i=0 ; isort() ; i := 0 ; while i < N do ( ( while (j < N & A[j+1] <= A[i+1] + K) do j := j + 1 ; ; if (maximum < (j - i)) then ( maximum := (j - i) ; start := i ; end := j ) else skip ) ; i := i + 1 ) ; return maximum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : Sequence(int) ; A := Sequence{1,26,17,12,15,2} ; var N : int ; N := A->size() ; var K : int ; K := 5 ; OclFile["System.out"].println(maxCount(A, N, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); B solver=new B(); solver.solve(1,in,out); out.close(); } static class B { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=Integer.parseInt(in.next()); int ans=0 ; for(int i=1 ; i<=n ; i++){ if(Integer.toString(i).length()% 2!=0)++ans ; } out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : B ; solver := B.newB() ; solver.solve(1, in, out) ; skip ; ); static class B { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := (in.getCurrent())->toInteger() ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (((i) + "")->size() mod 2 /= 0) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; skip ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Map.Entry ; class Main { static int mod=(int)(Math.pow(10,9)+7); static List>list=new ArrayList>(); public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long ans=0 ; long sum=0 ; for(int i=1 ; ib){ long t=b ; b=a ; a=t ; } sum=sum+i ; ans=ans+sum ; ans=ans-a*(N-b+1); } sum=sum+N ; ans=ans+sum ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute mod : int := (10->pow(9) + 7)->oclAsType(int); static attribute list : Sequence(Sequence(int)) := Sequence{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var ans : long ; ans := 0 ; var sum : long ; sum := 0 ; var i : int ; i := 1 ; while i < N do ( ( var a : long ; a := sc.getCurrent()->toInteger() ; var b : long ; b := sc.getCurrent()->toInteger() ; if (a > b) then ( var t : long ; t := b ; b := a ; a := t ) else skip ; sum := sum + i ; ans := ans + sum ; ans := ans - a * (N - b + 1) ; ) ; i := i + 1 ) ; sum := sum + N ; ans := ans + sum ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); sc.nextLine(); char[][] ch=new char[n][n]; for(int i=0 ; i0 ? x1-1 : x1+1][y1]='*' ; ch[x1>0 ? x1-1 : x1+1][y2]='*' ; } else if(y1==y2){ ch[x1][y1>0 ? y1-1 : y1+1]='*' ; ch[x2][y1>0 ? y1-1 : y1+1]='*' ; } else { ch[x1][y2]='*' ; ch[x2][y1]='*' ; } for(int i=0 ; itoInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var ch : Sequence(Sequence(String)) ; ch := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( ch[i+1] := sc.nextLine()->characters() ) ; i := i + 1 ) ; var x1 : int ; x1 := 0 ; var y1 : int ; y1 := 0 ; var x2 : int ; x2 := 0 ; var y2 : int ; y2 := 0 ; var key : int ; key := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (key = 2) then break else skip ; var j : int ; j := 0 ; while j < n do ( ( if (key = 2) then break else skip ; if (ch[i+1][j+1] = '*') then ( if (key = 0) then ( key := 1 ; x1 := i ; y1 := j ) else ( key := 2 ; x2 := i ; y2 := j ) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (x1 = x2) then ( ch[if x1 > 0 then x1 - 1 else x1 + 1 endif+1][y1+1] := '*' ; ch[if x1 > 0 then x1 - 1 else x1 + 1 endif+1][y2+1] := '*' ) else if (y1 = y2) then ( ch[x1+1][if y1 > 0 then y1 - 1 else y1 + 1 endif+1] := '*' ; ch[x2+1][if y1 > 0 then y1 - 1 else y1 + 1 endif+1] := '*' ) else ( ch[x1+1][y2+1] := '*' ; ch[x2+1][y1+1] := '*' ) ; ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( OclFile["System.out"].print(ch[i+1][j+1]) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); sc.nextLine(); char[][] ch=new char[n][n]; for(int i=0 ; i0 ? x1-1 : x1+1][y1]='*' ; ch[x1>0 ? x1-1 : x1+1][y2]='*' ; } else if(y1==y2){ ch[x1][y1>0 ? y1-1 : y1+1]='*' ; ch[x2][y1>0 ? y1-1 : y1+1]='*' ; } else { ch[x1][y2]='*' ; ch[x2][y1]='*' ; } for(int i=0 ; itoInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var ch : Sequence(Sequence(String)) ; ch := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( ch[i+1] := sc.nextLine()->characters() ) ; i := i + 1 ) ; var x1 : int ; x1 := 0 ; var y1 : int ; y1 := 0 ; var x2 : int ; x2 := 0 ; var y2 : int ; y2 := 0 ; var key : int ; key := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (key = 2) then break else skip ; var j : int ; j := 0 ; while j < n do ( ( if (key = 2) then break else skip ; if (ch[i+1][j+1] = '*') then ( if (key = 0) then ( key := 1 ; x1 := i ; y1 := j ) else ( key := 2 ; x2 := i ; y2 := j ) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (x1 = x2) then ( ch[if x1 > 0 then x1 - 1 else x1 + 1 endif+1][y1+1] := '*' ; ch[if x1 > 0 then x1 - 1 else x1 + 1 endif+1][y2+1] := '*' ) else if (y1 = y2) then ( ch[x1+1][if y1 > 0 then y1 - 1 else y1 + 1 endif+1] := '*' ; ch[x2+1][if y1 > 0 then y1 - 1 else y1 + 1 endif+1] := '*' ) else ( ch[x1+1][y2+1] := '*' ; ch[x2+1][y1+1] := '*' ) ; ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( OclFile["System.out"].print(ch[i+1][j+1]) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maxSubArraySum(int a[],int size){ int max_so_far=Integer.MIN_VALUE,max_ending_here=0 ; for(int i=0 ; ioclAsType(double) / K->oclAsType(double) ; return totalSum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,-2,3} ; var n : int ; n := a->size() ; var K : int ; K := 2 ; OclFile["System.out"].println(minimizedSum(a, n, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileNotFoundException ; import java.util.Scanner ; public class Main { Scanner sc ; void run(){ for(; ; ){ int a=sc.nextInt(); int b=sc.nextInt(); if((a | b)==0){ break ; } int memo[]=new int[b]; int first=a ; int count=0 ; int v1=0 ; int vv=0 ; for(; ; ){ count++; if(memo[first]!=0){ v1=memo[first]-1 ; vv=count-memo[first]; if(first==0){ vv=0 ; } break ; } memo[first]=count ; first=first*10 ; int v=first/b ; int v2=first % b ; first=v2 ; } System.out.println(v1+" "+vv); } } Main(){ sc=new Scanner(System.in); try { sc=new Scanner(new File("")); } catch(FileNotFoundException e){ } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; operation run() : void pre: true post: true activity: ( while true do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(a,b)) = 0) then ( break ) else skip ; var memo : Sequence(int) ; memo := Integer.subrange(1,b)->collect(0) ; var first : int ; first := a ; var count : int ; count := 0 ; var v1 : int ; v1 := 0 ; var vv : int ; vv := 0 ; while true do ( ( count := count + 1 ; if (memo[first+1] /= 0) then ( v1 := memo[first+1] - 1 ; vv := count - memo[first+1] ; if (first = 0) then ( vv := 0 ) else skip ; break ) else skip ; memo[first+1] := count ; first := first * 10 ; var v : int ; v := first / b ; var v2 : int ; v2 := first mod b ; first := v2 ; ) ) ; OclFile["System.out"].println(v1 + " " + vv) ; ) ) ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; try ( sc := OclFile.newOclFile_Read(OclFile("")) ) catch (e : FileNotFoundException) do skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int x=sc.nextInt(),y=sc.nextInt(); if((x | y)==0)break ; int[] a=new int[y]; Arrays.fill(a,-1); a[x]=0 ; int p=0,q=0,r=1 ; for(; ; ){ x=(x*10)% y ; if(x==0){ p=r ; break ; } if(a[x]==-1){ a[x]=r++; } else { p=a[x]; q=r-a[x]; break ; } } System.out.println(p+" "+q); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(x,y)) = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,y)->collect(0) ; a := a->collect(-1) ; a[x+1] := 0 ; var p : int ; p := 0 ; var q : int ; q := 0 ; var r : int ; r := 1 ; while true do ( ( x := (x * 10) mod y ; if (x = 0) then ( p := r ; break ) else skip ; if (a[x+1] = -1) then ( a[x+1] := r ; r := r + 1 ) else ( p := a[x+1] ; q := r - a[x+1] ; break ) ) ) ; OclFile["System.out"].println(p + " " + q) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { void solve(){ Scanner sc=new Scanner(System.in); while(true){ int x=sc.nextInt(); int y=sc.nextInt(); if(x==0 && y==0)break ; int[] appear=new int[1000001]; Arrays.fill(appear,-1); int a=0,b=0 ; for(int i=0 ; ; i++){ x=x % y ; if(appear[x]!=-1){ a=appear[x]; b=i-appear[x]; if(x==0)b=0 ; break ; } else { appear[x]=i ; } x*=10 ; } System.out.println(a+" "+b); } } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (x = 0 & y = 0) then break else skip ; var appear : Sequence(int) ; appear := Integer.subrange(1,1000001)->collect(0) ; appear := appear->collect(-1) ; var a : int ; a := 0 ; var b : int ; b := 0 ; var i : int ; i := 0 ; while true do ( ( x := x mod y ; if (appear[x+1] /= -1) then ( a := appear[x+1] ; b := i - appear[x+1] ; if (x = 0) then b := 0 ; else skip ; break ) else ( appear[x+1] := i ) ; x := x*(10) ) ; i := i + 1 ) ; OclFile["System.out"].println(a + " " + b) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner stdIn=new Scanner(System.in); while(true){ int m=stdIn.nextInt(); int n=stdIn.nextInt(); if(m==0 && n==0)return ; int p=m ; int s=0 ; int t=0 ; int tmpP=m ; int cnt=0 ; while(true){ cnt++; m=m*10 % n ; p=(p*10 % n)*10 % n ; if(m==p){ break ; } } if(p!=0){ p=tmpP % n ; s=1 ; while(m!=p){ s++; m=m*10 % n ; p=p*10 % n ; } p=p*10 % n ; t=s ; while(m!=p){ t++; p=p*10 % n ; } } if(s==0 && t==0){ System.out.println(cnt+" "+t); } else System.out.println((s-1)+" "+(t-s+1)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var m : int ; m := stdIn.getCurrent()->toInteger() ; var n : int ; n := stdIn.getCurrent()->toInteger() ; if (m = 0 & n = 0) then return else skip ; var p : int ; p := m ; var s : int ; s := 0 ; var t : int ; t := 0 ; var tmpP : int ; tmpP := m ; var cnt : int ; cnt := 0 ; while (true) do ( cnt := cnt + 1 ; m := m * 10 mod n ; p := (p * 10 mod n) * 10 mod n ; if (m = p) then ( break ) else skip ) ; if (p /= 0) then ( p := tmpP mod n ; s := 1 ; while (m /= p) do ( s := s + 1 ; m := m * 10 mod n ; p := p * 10 mod n ) ; p := p * 10 mod n ; t := s ; while (m /= p) do ( t := t + 1 ; p := p * 10 mod n ) ; ) else skip ; if (s = 0 & t = 0) then ( OclFile["System.out"].println(cnt + " " + t) ) else OclFile["System.out"].println((s - 1) + " " + (t - s + 1)) ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void noOfMoves(int arr[],int n){ int cnt=0 ; int maxCnt=0 ; for(int i=0 ; imax() ; cnt := 0 ) else skip ) ) ; i := i + 1 ) ; OclFile["System.out"].print(maxCnt + "\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{0,1,1,1,1,0,0,1,1,0,0,1} ; var N : int ; N := arr->size() ; execute noOfMoves(arr, N) ; var arr1 : Sequence(int) ; arr1 := Sequence{1,0,1,0,1,0,1,0} ; N := arr1->size() ; execute noOfMoves(arr1, N) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int minChanges(char[] str,int n){ int count=0,zeros=0,ones=0 ; if(str[0]!='1'){ count++; ones++; } for(int i=1 ; iones){ zeros--; ones++; count++; } } return count ; } public static void main(String[] args){ char[] str="0000".toCharArray(); int n=str.length ; System.out.print(minChanges(str,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minChanges( str : Sequence(String), n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var zeros : int ; zeros := 0 ; var ones : int ; ones := 0 ; if (str[0+1] /= '1') then ( count := count + 1 ; ones := ones + 1 ) else skip ; var i : int ; i := 1 ; while i < n do ( ( if (str[i+1] = '0') then zeros := zeros + 1 else ones := ones + 1 ; ; if (zeros > ones) then ( zeros := zeros - 1 ; ones := ones + 1 ; count := count + 1 ) else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : Sequence(String) ; str := "0000"->characters() ; var n : int ; n := str->size() ; OclFile["System.out"].print(minChanges(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.util.stream.IntStream ; class Main { public static void main(String[] args){ OriginScanner os=new OriginScanner(); PrintWriter pw=new PrintWriter(System.out); int n=os.nextInt(); long count=IntStream.rangeClosed(1,n).filter(i->String.valueOf(i).length()% 2==1).count(); pw.println(count); pw.close(); } static class OriginScanner { StringTokenizer token ; BufferedReader br ; public OriginScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String nextLine(){ String str=null ; try { str=br.readLine(); } catch(IOException e){ System.out.println(e); } return str ; } String next(){ while(token==null || ! token.hasMoreElements()){ token=new StringTokenizer(nextLine()); } return token.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var os : OriginScanner ; os := OriginScanner.newOriginScanner() ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := os.nextInt() ; var count : long ; count := Integer.subrange(1, n)->select( _x1 | (lambda i : OclAny in ((i) + "")->size() mod 2 = 1)->apply(_x1) )->size() ; skip ; skip ; ); static class OriginScanner { attribute token : OclIterator; attribute br : OclFile; static operation newOriginScanner() : OriginScanner pre: true post: true activity: ( var self : OriginScanner ; self := createOriginScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := null ; try ( str := br.readLine() ) catch (e : IOException) do ( OclFile["System.out"].println(e) ) return str ); operation next() : String pre: true post: true activity: ( while (token = null or not(token.hasNext())) do ( token := OclIterator.newOclIterator_String(nextLine()) ) ; return token.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Stack ; public class Main { static Scanner input=new Scanner(System.in); private static void solve(){ int n=input.nextInt(); int[] p=arrayInput(n); input.close(); Stackstack=new Stack<>(); char[] ans=new char[n*2]; int indexAns=0 ; int indexStack=0 ; for(int i=0 ; i=1){ System.out.println(":("); return ; } else { System.out.println(ans); } } public static void main(String[] args){ solve(); } private static int[] arrayInput(int n){ int[] a=new int[n]; for(int i=0 ; itoInteger() ; var p : Sequence(int) ; p := arrayInput(n) ; skip ; var stack : Sequence(int) ; stack := Sequence{} ; var ans : Sequence(String) ; ans := Integer.subrange(1,n * 2)->collect(0) ; var indexAns : int ; indexAns := 0 ; var indexStack : int ; indexStack := 0 ; var i : int ; i := 0 ; while i < n do ( ( while (stack->isEmpty() or stack->min() < p[i+1]) do ( ans[indexAns+1] := '(' ; indexAns := indexAns + 1 ; stack := stack->append((indexStack + 1)) ) ; if (stack->min() /= p[i+1]) then ( OclFile["System.out"].println(":(") ; return ) else skip ; stack := stack->front() ; ans[indexAns+1] := ')' ; indexAns := indexAns + 1 ) ; i := i + 1 ) ; if (stack->size() >= 1) then ( OclFile["System.out"].println(":(") ; return ) else ( OclFile["System.out"].println(ans) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); static operation arrayInput( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] arg){ Scanner in=new Scanner(System.in).useDelimiter("(\\s|,)+"); int case_=0 ; while(in.hasNext()){ int w=in.nextInt(); if(w!=0){ System.out.print("Case "); System.out.print(++case_); System.out.println(":"); int[] pack=new int[w+1]; int n=in.nextInt(); int maxNum=0 ; for(int j=0 ; j=0 ; i--){ pack[i+pw]=Math.max(pack[i+pw],pack[i]+p); if(pack[maxNum]<=pack[i+pw]){ maxNum=i+pw ; } } } System.out.println(pack[maxNum]); System.out.println(maxNum); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]).useDelimiter("(\\s|,)+") ; var case_ : int ; case_ := 0 ; while (in.hasNext()) do ( var w : int ; w := in.getCurrent()->toInteger() ; if (w /= 0) then ( OclFile["System.out"].print("Case ") ; OclFile["System.out"].print((case_ + 1)) ; OclFile["System.out"].println(":") ; var pack : Sequence(int) ; pack := Integer.subrange(1,w + 1)->collect(0) ; var n : int ; n := in.getCurrent()->toInteger() ; var maxNum : int ; maxNum := 0 ; var j : int ; j := 0 ; while j < n do ( ( var p : int ; p := in.getCurrent()->toInteger() ; var pw : int ; pw := in.getCurrent()->toInteger() ; var i : int ; i := w - pw ; while i >= 0 do ( ( pack[i + pw+1] := Set{pack[i + pw+1], pack[i+1] + p}->max() ; if (pack[maxNum+1] <= pack[i + pw+1]) then ( maxNum := i + pw ) else skip ) ; i := i - 1 ) ) ; j := j + 1 ) ; OclFile["System.out"].println(pack[maxNum+1]) ; OclFile["System.out"].println(maxNum) ; ) else skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int gcd(int a,int b){ if(a==0 || b==0)return 0 ; if(a==b)return a ; if(a>b)return gcd(a-b,b); return gcd(a,b-a); } static int squarearea(int l,int b){ if(l<0 || b<0)return-1 ; int n=(l*b)/gcd(l,b); return n*n ; } public static void main(String[] args){ int l=6,b=4 ; System.out.println(squarearea(l,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int 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 > b) then return gcd(a - b, b) else skip ; return gcd(a, b - a) ); static operation squarearea( l : int, b : int) : int pre: true post: true activity: ( if (l < 0 or b < 0) then return -1 else skip ; var n : int ; n := (l * b) / gcd(l, b) ; return n * n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 6 ; var b : int ; b := 4 ; OclFile["System.out"].println(squarearea(l, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MOD=1000000007 ; static int totalSubSets(int n,int l,int r){ int zero=(int)Math.floor((double)r/3)-(int)Math.ceil((double)l/3)+1 ; int one=(int)Math.floor((double)(r-1)/3)-(int)Math.ceil((double)(l-1)/3)+1 ; int two=(int)Math.floor((double)(r-2)/3)-(int)Math.ceil((double)(l-2)/3)+1 ; int[][] dp=new int[n][3]; dp[0][0]=zero ; dp[0][1]=one ; dp[0][2]=two ; for(int i=1 ; ioclAsType(double) / 3)->floor()->oclAsType(int) - (l->oclAsType(double) / 3)->ceil()->oclAsType(int) + 1 ; var one : int ; one := ((r - 1)->oclAsType(double) / 3)->floor()->oclAsType(int) - ((l - 1)->oclAsType(double) / 3)->ceil()->oclAsType(int) + 1 ; var two : int ; two := ((r - 2)->oclAsType(double) / 3)->floor()->oclAsType(int) - ((l - 2)->oclAsType(double) / 3)->ceil()->oclAsType(int) + 1 ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,3)->collect(0)) ; dp[0+1][0+1] := zero ; dp[0+1][1+1] := one ; dp[0+1][2+1] := two ; var i : int ; i := 1 ; while i < n do ( ( dp[i+1][0+1] := ((dp[i - 1+1][0+1] * 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][0+1] * 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][0+1] * two) + (dp[i - 1+1][1+1] * one) + (dp[i - 1+1][2+1] * zero)) mod MOD ) ; i := i + 1 ) ; return dp[n - 1+1][0+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var l : int ; l := 10 ; var r : int ; r := 100 ; OclFile["System.out"].println(totalSubSets(n, l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findDimen(int H,int A){ if(H*H<4*A){ System.out.println("Not Possible"); return ; } double apb=Math.sqrt(H*H+4*A); double asb=Math.sqrt(H*H-4*A); System.out.println("P="+Math.round(((apb-asb)/2.0)*100.0)/100.0); System.out.print("B="+Math.round(((apb+asb)/2.0)*100.0)/100.0); } public static void main(String[] args){ int H=5 ; int A=6 ; findDimen(H,A); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findDimen( H : int, A : int) : void pre: true post: true activity: ( if (H * H < 4 * A) then ( OclFile["System.out"].println("Not Possible") ; return ) else skip ; var apb : double ; apb := (H * H + 4 * A)->sqrt() ; var asb : double ; asb := (H * H - 4 * A)->sqrt() ; OclFile["System.out"].println("P=" + (((apb - asb) / 2.0) * 100.0)->round() / 100.0) ; OclFile["System.out"].print("B=" + (((apb + asb) / 2.0) * 100.0)->round() / 100.0) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var H : int ; H := 5 ; var A : int ; A := 6 ; execute findDimen(H, A) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static int rangesum(int n,int l,int r){ int[] arr=new int[n]; int c=1,i=0 ; while(c<=n){ arr[i++]=c ; c+=2 ; } c=2 ; while(c<=n){ arr[i++]=c ; c+=2 ; } int sum=0 ; for(i=l-1 ; icollect(0) ; var c : int ; c := 1 ; var i : int ; i := 0 ; while (c <= n) do ( arr[i+1] := c ; i := i + 1 ; c := c+(2) ) ; c := 2 ; while (c <= n) do ( arr[i+1] := c ; i := i + 1 ; c := c+(2) ) ; var sum : int ; sum := 0 ; i := l - 1 ; while i < r do ( ( sum := sum+(arr[i+1]) ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12 ; var l : int ; l := 1 ; var r : int ; r := 11 ; OclFile["System.out"].println(rangesum(n, l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main1 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); int a[]=new int[m+1]; for(int i=0 ; ilist=new ArrayList<>(); for(int i=1 ; i<=m ; i++){ if(a[i]==0){ ans++; list.add(i); } } System.out.println(ans); for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,m + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var j : int ; j := l ; while j <= r do ( ( a[j+1] := a[j+1] + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var list : Sequence(int) ; list := Sequence{} ; var i : int ; i := 1 ; while i <= m do ( ( if (a[i+1] = 0) then ( ans := ans + 1 ; list := list->including(i) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; var i : int ; i := 0 ; while i < ans do ( ( OclFile["System.out"].print(list->at(i+1) + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.System.*; import java.util.ArrayList ; import java.util.Scanner ; public class Main { static int[] freq=new int[101]; public static void main(String[] args){ Scanner sc=new Scanner(in); int rows=Integer.parseInt(sc.next()); int end=Integer.parseInt(sc.next()); int[][] arr=new int[rows][2]; ArrayListres_list=new ArrayList<>(); for(int i=0 ; icollect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var rows : int ; rows := (sc.getCurrent())->toInteger() ; var end : int ; end := (sc.getCurrent())->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,rows)->collect(Integer.subrange(1,2)->collect(0)) ; var res_list : Sequence(int) ; res_list := Sequence{} ; var i : int ; i := 0 ; while i < rows do ( ( var j : int ; j := 0 ; while j < 2 do ( ( arr[i+1][j+1] := (sc.getCurrent())->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var x : int ; x := 0 ; while x < rows do ( ( var y : int ; y := 0 ; while y < 1 do ( ( if (arr[x+1][y+1] = arr[x+1][y + 1+1]) then freq[arr[x+1][y+1]+1] := freq[arr[x+1][y+1]+1] + 1 ; else skip ; if (arr[x+1][y+1] < arr[x+1][y + 1+1]) then ( var num : int ; num := arr[x+1][y+1] ; var num2 : int ; num2 := arr[x+1][y + 1+1] ; while (num <= num2) do ( freq[num+1] := freq[num+1] + 1 ; num := num + 1 ; if (num = num2) then ( freq[num2+1] := freq[num2+1] + 1 ; break ) else skip ) ) else skip ) ; y := y + 1 ) ) ; x := x + 1 ) ; var n : int ; n := 1 ; while n <= end do ( ( if (freq[n+1] = 0) then res_list := res_list->including(n) ; else skip ) ; n := n + 1 ) ; if (res_list->size() = 0) then ( out.print(0) ) else ( out.println(res_list->size()) ; var l : int ; l := 0 ; while l < res_list->size() do ( ( out.print(res_list->at(l+1)) ; out.print(" ") ) ; l := l + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class PointsInSegments { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int[] A=new int[101]; for(int i=0 ; ilist=new ArrayList<>(); int x=0 ; for(int i=1 ; i<=m ; i++){ if(A[i]==0){ x++; list.add(i); } } System.out.println(x); for(int i=0 ; itoInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,101)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( skip ; var a : int ; a := scan.getCurrent()->toInteger() ; var b : int ; b := scan.getCurrent()->toInteger() ; var j : int ; j := a ; while j <= b do ( ( A[j+1] := 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var list : Sequence(int) ; list := Sequence{} ; var x : int ; x := 0 ; var i : int ; i := 1 ; while i <= m do ( ( if (A[i+1] = 0) then ( x := x + 1 ; list := list->including(i) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(x) ; var i : int ; i := 0 ; while i < list->size() do ( ( OclFile["System.out"].print(list->at(i+1) + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static int answer(int n){ int count=0 ; count+=Math.min(n,9); if(n>=100){ count+=Math.min(n,999)-99 ; } if(n>=10000){ count+=Math.min(n,99999)-9999 ; } return count ; } public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); scan.close(); System.out.println(answer(n)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation answer( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; count := count+(Set{n, 9}->min()) ; if (n >= 100) then ( count := count+(Set{n, 999}->min() - 99) ) else skip ; if (n >= 10000) then ( count := count+(Set{n, 99999}->min() - 9999) ) else skip ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; skip ; OclFile["System.out"].println(answer(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _1015A_PointsinSegments { public static void main(String[] args){ Scanner input=new Scanner(System.in); final int n=input.nextInt(); final int m=input.nextInt(); Setset=new LinkedHashSet<>(); for(int i=1 ; i<=m ; i++){ set.add(i); } for(int i=0 ; itoInteger() ; var m : int ; m := input.getCurrent()->toInteger() ; var set : Set(int) ; set := Set{} ; var i : int ; i := 1 ; while i <= m do ( ( set := set->including(i) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var first : int ; first := input.getCurrent()->toInteger() ; var last : int ; last := input.getCurrent()->toInteger() ; var k : int ; k := first ; while k <= last do ( ( set := set->excludingAt(k+1) ) ; k := k + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(set->size()) ; OclFile["System.out"].println(set+"".replaceAllMatches("[\\[\\],] ", "" )->trim()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.Set ; import java.util.stream.Collectors ; public class B_Longest_Palindrome { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextInt(); String[] strings=new String[n]; for(int i=0 ; irest=Arrays.stream(strings).collect(Collectors.toSet()); while(! rest.isEmpty()){ String s=rest.iterator().next(); rest.remove(s); String reversed=new StringBuilder(s).reverse().toString(); if(rest.contains(reversed)){ left.append(s); } else if(reversed.equals(s)){ center=s ; } } return String.format("%d\n%s%s%s",left.length()*2+center.length(),left,center,new StringBuilder(left).reverse().toString()); } } ------------------------------------------------------------ OCL File: --------- class B_Longest_Palindrome { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var strings : Sequence(String) ; strings := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < strings->size() do ( ( strings[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(strings)) ; skip ; ); static operation solve( strings : Sequence(String)) : String pre: true post: true activity: ( var left : String ; left := StringLib.newString() ; var center : String ; center := "" ; var rest : Set(String) ; rest := stream(strings).collect(Collectors.toSet()) ; while (not(rest->isEmpty())) do ( var s : String ; s := rest->iterator().next() ; rest := rest->excludingFirst(s) ; var reversed : String ; reversed := StringLib.newString(s)->reverse()+"" ; if (rest->includes(reversed)) then ( left := left + StringLib.newString(s) ) else if (reversed = s) then ( center := s ) else skip ; ) ; return StringLib.format("%d\n%s%s%s",Sequence{left->size() * 2 + center->size(),left,center,StringLib.newString(left)->reverse()+""}) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.lang.reflect.Array ; import java.util.*; class Main { public static void main(String[] args)throws IOException { Scanner in=new Scanner(System.in); int cnt=1 ; while(true){ int W=in.nextInt(); if(W==0)return ; int N=in.nextInt(); int v[]=new int[N+1]; int w[]=new int[N+1]; in.nextLine(); for(int i=1 ; i<=N ; i++){ String[] strs=in.nextLine().split(","); v[i]=Integer.parseInt(strs[0]); w[i]=Integer.parseInt(strs[1]); } System.out.println("Case "+cnt+":"); solve(W,N,v,w); cnt++; } } public static void solve(int W,int N,int[] v,int[] w){ int[][] dp=new int[N+2][W+2]; for(int i=0 ; i=0){ dp[i][j]=Math.max(dp[i-1][j-w[i] ]+v[i],dp[i-1][j]); } } } int ans_V=0 ; int ans_W=Integer.MAX_VALUE/2 ; for(int i=0 ; i<=W ; i++){ if(ans_VtoInteger() ; if (W = 0) then return else skip ; var N : int ; N := in.getCurrent()->toInteger() ; var v : Sequence(int) ; v := Integer.subrange(1,N + 1)->collect(0) ; var w : Sequence(int) ; w := Integer.subrange(1,N + 1)->collect(0) ; skip ; var i : int ; i := 1 ; while i <= N do ( ( var strs : Sequence(String) ; strs := in.nextLine()->split(",") ; v[i+1] := (strs[0+1])->toInteger() ; w[i+1] := (strs[1+1])->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println("Case " + cnt + ":") ; execute solve(W, N, v, w) ; cnt := cnt + 1 ; ) ); static operation solve( W : int, N : int, v : Sequence(int), w : Sequence(int)) : void pre: true post: true activity: ( var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,N + 2)->collect(Integer.subrange(1,W + 2)->collect(0)) ; var i : int ; i := 0 ; while i < N + 2 do ( dp[0+1][i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= N do ( ( var j : int ; j := 1 ; while j <= W do ( ( dp[i+1][j+1] := dp[i - 1+1][j+1] ; if (j - w[i+1] >= 0) then ( dp[i+1][j+1] := Set{dp[i - 1+1][j - w[i+1]+1] + v[i+1], dp[i - 1+1][j+1]}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans_V : int ; ans_V := 0 ; var ans_W : int ; ans_W := 2147483647 / 2 ; var i : int ; i := 0 ; while i <= W do ( ( if (ans_V < dp[N+1][i+1]) then ( ans_V := dp[N+1][i+1] ; ans_W := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans_V) ; OclFile["System.out"].println(ans_W) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.Set ; import java.util.stream.Collectors ; public class B_Longest_Palindrome { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextInt(); String[] strings=new String[n]; for(int i=0 ; irest=Arrays.stream(strings).collect(Collectors.toSet()); while(! rest.isEmpty()){ String s=rest.iterator().next(); rest.remove(s); String reversed=new StringBuilder(s).reverse().toString(); if(rest.contains(reversed)){ left.append(s); } else if(reversed.equals(s)){ center=s ; } } return String.format("%d\n%s%s%s",left.length()*2+center.length(),left,center,new StringBuilder(left).reverse().toString()); } } ------------------------------------------------------------ OCL File: --------- class B_Longest_Palindrome { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var strings : Sequence(String) ; strings := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < strings->size() do ( ( strings[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(strings)) ; skip ; ); static operation solve( strings : Sequence(String)) : String pre: true post: true activity: ( var left : String ; left := StringLib.newString() ; var center : String ; center := "" ; var rest : Set(String) ; rest := stream(strings).collect(Collectors.toSet()) ; while (not(rest->isEmpty())) do ( var s : String ; s := rest->iterator().next() ; rest := rest->excludingFirst(s) ; var reversed : String ; reversed := StringLib.newString(s)->reverse()+"" ; if (rest->includes(reversed)) then ( left := left + StringLib.newString(s) ) else if (reversed = s) then ( center := s ) else skip ; ) ; return StringLib.format("%d\n%s%s%s",Sequence{left->size() * 2 + center->size(),left,center,StringLib.newString(left)->reverse()+""}) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); int m=in.nextInt(); String str1[]=new String[n+10]; String str2[]=new String[n+10]; String ans="" ; for(int i=1 ; i<=n ; i++){ String a=in.next(); String b=new StringBuffer(a).reverse().toString(); str1[i]=a ; str2[i]=b ; if(str1[i] .equals(str2[i]))ans=str1[i]; } for(int i=1 ; i<=n ; i++){ for(int j=i+1 ; j<=n ; j++){ if(str2[i] .equals(str1[j]))ans=str1[i]+ans+str2[i]; } } pw.println(ans.length()); pw.println(ans); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var str1 : Sequence(String) ; str1 := Integer.subrange(1,n + 10)->collect(null) ; var str2 : Sequence(String) ; str2 := Integer.subrange(1,n + 10)->collect(null) ; var ans : String ; ans := "" ; var i : int ; i := 1 ; while i <= n do ( ( var a : String ; a := in.getCurrent() ; var b : String ; b := StringLib.newString(a)->reverse()+"" ; str1[i+1] := a ; str2[i+1] := b ; if (str1[i+1] = str2[i+1]) then ans := str1[i+1] ; else skip ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := i + 1 ; while j <= n do ( ( if (str2[i+1] = str1[j+1]) then ans := str1[i+1] + ans + str2[i+1] ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-10 ; public static void main(String[] args){ new Main().run(); } void run(){ long M=sc.nextLong(); long rd=sc.nextLong(); long rr=sc.nextLong(); long cd=sc.nextLong(); long cr=sc.nextLong(); long r=0 ; long l=1000L*1000L*1000L*1000L+1 ; for(int i=0 ; i<1000 ; i++){ long mid=(r+l)/2 ; if(cd<=rd*mid/100){ l=mid ; } else { r=mid ; } } long x=l ; r=0 ; l=M ; for(int i=0 ; i<1000 ; i++){ long mid=(r+l)/2 ; if(cr<=rr*mid/100){ l=mid ; } else { r=mid ; } } long y=l ; if(x+y>M){ System.out.println(-1); } else { long D=rd*x/100 ; long R=rr*y/100 ; long ans=M-x-y ; if(Dpow(28)))->oclAsType(long); attribute EPS : double := 1e-10; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var M : long ; M := sc.getCurrent()->toLong() ; var rd : long ; rd := sc.getCurrent()->toLong() ; var rr : long ; rr := sc.getCurrent()->toLong() ; var cd : long ; cd := sc.getCurrent()->toLong() ; var cr : long ; cr := sc.getCurrent()->toLong() ; var r : long ; r := 0 ; var l : long ; l := 1000L * 1000L * 1000L * 1000L + 1 ; var i : int ; i := 0 ; while i < 1000 do ( ( var mid : long ; mid := (r + l) / 2 ; if (cd <= rd * mid / 100) then ( l := mid ) else ( r := mid ) ) ; i := i + 1 ) ; var x : long ; x := l ; r := 0 ; l := M ; var i : int ; i := 0 ; while i < 1000 do ( ( var mid : long ; mid := (r + l) / 2 ; if (cr <= rr * mid / 100) then ( l := mid ) else ( r := mid ) ) ; i := i + 1 ) ; var y : long ; y := l ; if (x + y > M) then ( OclFile["System.out"].println(-1) ) else ( var D : long ; D := rd * x / 100 ; var R : long ; R := rr * y / 100 ; var ans : long ; ans := M - x - y ; if (D < cd or R < cr) then ( OclFile["System.out"].println(-1) ) else ( ans := ans+(100 * (D - cd) / rd) ; ans := ans+(100 * (R - cr) / rr) ; OclFile["System.out"].println(ans) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class Main { Scanner sc=new Scanner(System.in); long M ; int rD,rR ; long cD,cR ; void run(){ M=sc.nextLong(); rD=sc.nextInt(); rR=sc.nextInt(); cD=sc.nextLong(); cR=sc.nextLong(); solve(); } void solve(){ long max=-1 ; long D0=(100*cD+rD-1)/rD,C0=(100*cR+rR-1)/rR ; for(int i=0 ; i<100 ; i++){ for(int j=0 ; j<100 ; j++){ long changeD=D0+i,changeR=C0+j ; long jpn=M-changeD-changeR ; if(jpn<0){ continue ; } long remD=changeD*rD/100-cD ; long remR=changeR*rR/100-cR ; jpn+=remD*100/rD+remR*100/rR ; max=max(max,jpn); } } println(max+""); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute M : long; attribute rD : int; attribute cD : long; operation run() : void pre: true post: true activity: ( M := sc.getCurrent()->toLong() ; rD := sc.getCurrent()->toInteger() ; rR := sc.getCurrent()->toInteger() ; cD := sc.getCurrent()->toLong() ; cR := sc.getCurrent()->toLong() ; execute solve() ; ); operation solve() : void pre: true post: true activity: ( var max : long ; max := -1 ; var D0 : long ; D0 := (100 * cD + rD - 1) / rD ; var C0 : long ; C0 := (100 * cR + rR - 1) / rR ; var i : int ; i := 0 ; while i < 100 do ( ( var j : int ; j := 0 ; while j < 100 do ( ( var changeD : long ; changeD := D0 + i ; var changeR : long ; changeR := C0 + j ; var jpn : long ; jpn := M - changeD - changeR ; if (jpn < 0) then ( continue ) else skip ; var remD : long ; remD := changeD * rD / 100 - cD ; var remR : long ; remR := changeR * rR / 100 - cR ; jpn := jpn+(remD * 100 / rD + remR * 100 / rR) ; max := Set{max, jpn}->max() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; execute println(max + "") ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long m=sc.nextLong(); long rd=sc.nextLong(); long rr=sc.nextLong(); long cd=sc.nextLong(); long cr=sc.nextLong(); long d=(cd*100)/rd ; while((d*rd)/100!=cd)d++; long r=(cr*100)/rr ; while((r*rr)/100!=cr)r++; if(m-d-r<0)System.out.println(-1); else System.out.println(m-d-r); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var m : long ; m := sc.getCurrent()->toLong() ; var rd : long ; rd := sc.getCurrent()->toLong() ; var rr : long ; rr := sc.getCurrent()->toLong() ; var cd : long ; cd := sc.getCurrent()->toLong() ; var cr : long ; cr := sc.getCurrent()->toLong() ; var d : long ; d := (cd * 100) / rd ; while ((d * rd) / 100 /= cd) do d := d + 1 ; ; var r : long ; r := (cr * 100) / rr ; while ((r * rr) / 100 /= cr) do r := r + 1 ; ; if (m - d - r < 0) then OclFile["System.out"].println(-1) else OclFile["System.out"].println(m - d - r) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ System.out.println(solve()); } static long solve(){ long M=sc.nextLong(); int rd=sc.nextInt(); int rr=sc.nextInt(); long cd=sc.nextLong(); long cr=sc.nextLong(); long minD=(cd*100+rd-1)/rd ; long minR=(cr*100+rr-1)/rr ; if(MtoLong() ; var rd : int ; rd := sc.getCurrent()->toInteger() ; var rr : int ; rr := sc.getCurrent()->toInteger() ; var cd : long ; cd := sc.getCurrent()->toLong() ; var cr : long ; cr := sc.getCurrent()->toLong() ; var minD : long ; minD := (cd * 100 + rd - 1) / rd ; var minR : long ; minR := (cr * 100 + rr - 1) / rr ; if (M < minD + minR) then return -1 else skip ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < 100 do ( ( var yd : long ; yd := minD + i ; var md : long ; md := yd * rd / 100 ; var j : int ; j := 0 ; while j < 100 do ( ( var yr : long ; yr := minR + j ; if (M < yd + yr) then break else skip ; var mc : long ; mc := yr * rr / 100 ; var rem : long ; rem := M - yd - yr ; rem := rem+((md - cd) * 100 / rd) ; rem := rem+((mc - cr) * 100 / rr) ; ans := Set{ans, rem}->max() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Arrays ; class GFG { static int getMin(int arr[],int n){ return Arrays.stream(arr).min().getAsInt(); } static int getMax(int arr[],int n){ return Arrays.stream(arr).max().getAsInt(); } public static void main(String[] args){ int arr[]={ 12,1234,45,67,1 }; int n=arr.length ; System.out.println("Minimum element of array: "+getMin(arr,n)); System.out.println("Maximum element of array: "+getMax(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getMin( arr : Sequence(int), n : int) : int pre: true post: true activity: ( return stream(arr).min().getAsInt() ); static operation getMax( arr : Sequence(int), n : int) : int pre: true post: true activity: ( return stream(arr).max().getAsInt() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{12,1234,45,67,1} ; var n : int ; n := arr->size() ; OclFile["System.out"].println("Minimum element of array: " + getMin(arr, n)) ; OclFile["System.out"].println("Maximum element of array: " + getMax(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; import static java.util.Arrays.*; import static java.lang.Math.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ while(sc.hasNextInt()){ int a=sc.nextInt(),b=sc.nextInt(),n=sc.nextInt(); String c=new Double((double)a/b).toString(); int[] f=new int[200]; int idx=c.indexOf("."); f[0]=new Integer(c.substring(idx-1,idx)); for(int i=1 ; itoInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var c : String ; c := ("" + (a->oclAsType(double) / b))->toReal()+"" ; var f : Sequence(int) ; f := Integer.subrange(1,200)->collect(0) ; var idx : int ; idx := c->indexOf(".")-1 ; f[0+1] := ("" + (c.subrange(idx - 1+1,idx)))->toInteger() ; var i : int ; i := 1 ; while i < Set{200, c.subrange(idx + 1+1,idx + 1)->size() + 1}->min() do ( ( f[i+1] := ("" + (c.subrange(idx + i+1,idx + i + 1)))->toInteger() ) ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 1 ; while i <= n do ( res := res+(f[i+1]) ; ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); char[] s=sc.next().toCharArray(); int[] c=new int[4]; for(int i=0 ; icharacters() ; var c : Sequence(int) ; c := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s[i+1] = 'K') then c[0+1] := c[0+1] + 1 ; else skip ; if (s[i+1] = 'U') then c[1+1] := c[1+1] + 1 ; else skip ; if (s[i+1] = 'P') then c[2+1] := c[2+1] + 1 ; else skip ; if (s[i+1] = 'C') then c[3+1] := c[3+1] + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{c[0+1], Set{c[1+1], Set{c[2+1], c[3+1]}->min()}->min()}->min()) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int i,tmp ; int[] count=new int[4]; String s=sc.nextLine(); for(i=0 ; icollect(0) ; var s : String ; s := sc.nextLine() ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = 'K') then count[0+1] := count[0+1] + 1 ; else if (s->at(i+1) = 'U') then count[1+1] := count[1+1] + 1 else if (s->at(i+1) = 'P') then count[2+1] := count[2+1] + 1 else if (s->at(i+1) = 'C') then count[3+1] := count[3+1] + 1 ; else skip ; ; ; ) ; i := i + 1 ) ; i := 0 ; while i < 3 do ( if (count[i+1] < count[i + 1+1]) then ( tmp := count[i+1] ; count[i+1] := count[i + 1+1] ; count[i + 1+1] := tmp ) else skip ; ; i := i + 1 ) ; out.println(count[3+1]) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); String inStr=scn.nextLine(); char[] charList=new char[inStr.length()]; for(int i=0 ; isize())->collect(0) ; var i : int ; i := 0 ; while i < charList->size() do ( ( charList[i+1] := inStr->at(i+1) ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; while (true) do ( var isCnt : boolean ; isCnt := false ; var i : int ; i := 0 ; while i < charList->size() do ( ( if ('K' = charList[i+1]) then ( charList[i+1] := 'A' ; var j : int ; j := 0 ; while j < charList->size() do ( ( if ('U' = charList[j+1]) then ( charList[j+1] := 'A' ; var k : int ; k := 0 ; while k < charList->size() do ( ( if ('P' = charList[k+1]) then ( charList[k+1] := 'A' ; var l : int ; l := 0 ; while l < charList->size() do ( ( if ('C' = charList[l+1]) then ( charList[l+1] := 'A' ; cnt := cnt + 1 ; isCnt := true ; break ) else skip ) ; l := l + 1 ) ) else skip ) ; k := k + 1 ) ) else skip ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; if (not(isCnt)) then break else skip ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main(String[] args){ BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); try { for(int cnt=0 ; ; ++cnt){ int w=Integer.parseInt(bf.readLine()); if(w==0)break ; int n=Integer.parseInt(bf.readLine()); int[] vs=new int[n]; int[] ws=new int[n]; for(int i=0 ; i=0)dp[i][j]=Math.max(dp[i-1][j],dp[i-1][j-ws[i] ]+vs[i]); } if(ansvj)){ ansv=dp[i][j]; answ=j ; } } } System.out.println("Case "+(cnt+1)+":\n"+ansv+"\n"+answ); } } catch(IOException ex){ } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var cnt : int ; cnt := 0 ; while true do ( ( var w : int ; w := (bf.readLine())->toInteger() ; if (w = 0) then break else skip ; var n : int ; n := (bf.readLine())->toInteger() ; var vs : Sequence(int) ; vs := Integer.subrange(1,n)->collect(0) ; var ws : Sequence(int) ; ws := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var strs : Sequence(String) ; strs := bf.readLine()->split(",") ; vs[i+1] := (strs[0+1])->toInteger() ; ws[i+1] := (strs[1+1])->toInteger() ) ; i := i + 1 ) ; var ansv : int ; ansv := -1 ; var answ : int ; answ := 0 ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,w + 1)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < w + 1 do ( ( if (i = 0) then dp[i+1][j+1] := if ws[i+1] <= j then vs[i+1] else 0 endif else ( dp[i+1][j+1] := dp[i - 1+1][j+1] ; if (j - ws[i+1] >= 0) then dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i - 1+1][j - ws[i+1]+1] + vs[i+1]}->max() ; else skip ) ; if (ansv < dp[i+1][j+1] or (ansv = dp[i+1][j+1] & answ > j)) then ( ansv := dp[i+1][j+1] ; answ := j ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println("Case " + (cnt + 1) + ":\n" + ansv + "\n" + answ) ; ) ; cnt := cnt + 1 ) ) catch (ex : IOException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; class Main { public static void main(String[] args){ Solve s=new Solve(); s.solve(); } } class Solve { Solve(){ } Scanner in=new Scanner(System.in); void solve(){ String s=in.next(); int k=0,u=0,p=0,c=0 ; for(int i=0 ; isize() do ( ( if (s->at(i+1) = 'K') then k := k + 1 ; else if (s->at(i+1) = 'U') then u := u + 1 else if (s->at(i+1) = 'P') then p := p + 1 else if (s->at(i+1) = 'C') then c := c + 1 ; else skip ; ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{k, Set{u, Set{p, c}->min()}->min()}->min()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); static String line ; public static void main(String[] args){ while(read()){ solve(); } } static boolean read(){ if(! sc.hasNext())return false ; line=sc.next(); return true ; } static void solve(){ int countK=0,countU=0,countP=0,countC=0 ; for(int i=0 ; isize() do ( ( var word : String ; word := line->at(i+1) ; if (word = 'K') then ( countK := countK + 1 ) else if (word = 'U') then ( countU := countU + 1 ) else if (word = 'P') then ( countP := countP + 1 ) else if (word = 'C') then ( countC := countC + 1 ) else skip ; ; ; ) ; i := i + 1 ) ; var res : int ; res := Set{Set{countK, countU}->min(), Set{countP, countC}->min()}->min() ; OclFile["System.out"].println(res) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void findTriplets(int arr[],int n,int sum){ for(int i=0 ; is=new HashSet<>(); for(int j=i+1 ; jincludes(x)) then OclFile["System.out"].printf("%d %d %d\n", x, arr[i+1], arr[j+1]) ; else s := s->including(arr[j+1]) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{0,-1,2,-3,1} ; var sum : int ; sum := -2 ; var n : int ; n := arr->size() ; execute findTriplets(arr, n, sum) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int a[]=new int[m+1]; int b[]=new int[m+1]; int answer=0 ; int maxb=-1 ; int maxidx=-1 ; int work=1 ; boolean flag=true ; boolean hflag=true ; for(int i=1 ; i<=m ; i++){ a[i]=sc.nextInt(); b[i]=sc.nextInt(); } if(n==1){ for(int i=1 ; i<=m ; i++){ if(a[i]==1 && b[i]==1){ flag=false ; break ; } } if(! flag){ System.out.println(1); } else { System.out.println("Impossible"); } } else { while(workmaxb){ maxb=b[i]; maxidx=i ; } } } else { if(a[i]<=work+1){ if(b[i]>maxb){ maxb=b[i]; maxidx=i ; } } } } if(maxb==-1){ flag=false ; break ; } else { answer++; work=maxb ; a[maxidx]=101 ; b[maxidx]=101 ; hflag=false ; } } if(flag){ System.out.println(answer); } else { System.out.println("Impossible"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,m + 1)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,m + 1)->collect(0) ; var answer : int ; answer := 0 ; var maxb : int ; maxb := -1 ; var maxidx : int ; maxidx := -1 ; var work : int ; work := 1 ; var flag : boolean ; flag := true ; var hflag : boolean ; hflag := true ; var i : int ; i := 1 ; while i <= m do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (n = 1) then ( var i : int ; i := 1 ; while i <= m do ( ( if (a[i+1] = 1 & b[i+1] = 1) then ( flag := false ; break ) else skip ) ; i := i + 1 ) ; if (not(flag)) then ( OclFile["System.out"].println(1) ) else ( OclFile["System.out"].println("Impossible") ) ) else ( while (work < n) do ( maxb := -1 ; var i : int ; i := 1 ; while i <= m do ( ( if (hflag) then ( if (a[i+1] <= 1) then ( if (b[i+1] > maxb) then ( maxb := b[i+1] ; maxidx := i ) else skip ) else skip ) else ( if (a[i+1] <= work + 1) then ( if (b[i+1] > maxb) then ( maxb := b[i+1] ; maxidx := i ) else skip ) else skip ) ) ; i := i + 1 ) ; if (maxb = -1) then ( flag := false ; break ) else ( answer := answer + 1 ; work := maxb ; a[maxidx+1] := 101 ; b[maxidx+1] := 101 ; hflag := false ; ) ) ; if (flag) then ( OclFile["System.out"].println(answer) ) else ( OclFile["System.out"].println("Impossible") ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int N,M ; static Prof[] p ; static void solve(){ final int INF=1<<30 ; int[] dp=new int[N+1]; Arrays.fill(dp,INF); dp[0]=0 ; Arrays.sort(p); for(int i=0 ; i{ int a,b ; Prof(int a,int b){ this.a=a ; this.b=b ; } public int compareTo(Prof o){ return this.a-o.a ; } } public static void main(String[] args){ N=sc.nextInt(); M=sc.nextInt(); p=new Prof[M]; for(int i=0 ; ipow(30)))->oclAsType(long) ; var dp : Sequence(int) ; dp := Integer.subrange(1,N + 1)->collect(0) ; dp := dp->collect(INF) ; dp[0+1] := 0 ; p := p->sort() ; var i : int ; i := 0 ; while i < M do ( ( if (dp[p[i+1].a - 1+1] = INF) then ( OclFile["System.out"].println("Impossible") ; return ) else skip ; var count : int ; count := INF ; var j : int ; j := p[i+1].a - 1 ; while j <= p[i+1].b do ( ( count := Set{dp[j+1], count}->min() ) ; j := j + 1 ) ; var j : int ; j := p[i+1].a ; while j <= p[i+1].b do ( ( dp[j+1] := Set{dp[j+1], count + 1}->min() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(if dp[N+1] = INF then "Impossible" else dp[N+1] endif) ; ); static class Prof implements Comparable { attribute a : int; static operation newProf( a : int, b : int) : Prof pre: true post: true activity: ( var self : Prof ; self := createProf(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( self.a := a ; self.b := b ); operation compareTo( o : Prof) : int pre: true post: true activity: ( return self.a - o.a ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( N := sc.getCurrent()->toInteger() ; M := sc.getCurrent()->toInteger() ; p := Integer.subrange(1,M)->collect(null) ; var i : int ; i := 0 ; while i < M do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; p[i+1] := Prof.newProf(a, b) ) ; i := i + 1 ) ; execute solve() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.PriorityQueue ; import java.util.Scanner ; public class Main { class R implements Comparable{ int s,t ; public R(int s,int t){ this.s=s ; this.t=t ; } public int compareTo(R o){ return s-o.s ; } } void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(),M=sc.nextInt(); PriorityQueueq=new PriorityQueue(); while(M--!=0)q.add(new R(sc.nextInt(),sc.nextInt())); int res=0,f=0 ; while(! q.isEmpty()&& f { attribute s : int; static operation newR( s : int, t : int) : R pre: true post: true activity: ( var self : R ; self := createR(); self.initialise(s, t); return self ); operation initialise( s : int, t : int) : void pre: true post: true activity: ( self.s := s ; self.t := t ); operation compareTo( o : R) : int pre: true post: true activity: ( return s - o.s ); } operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var q : Sequence(R) ; q := Sequence{} ; while (M /= 0) do ( skip ; q := q->including(R.newR(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger())) ; ; ) ; var res : int ; res := 0 ; var f : int ; f := 0 ; while (not(q->isEmpty()) & f < N) do ( if (f + 1 < q->min().s) then break else skip ; var max : int ; max := q->min().t ; while (not(q->isEmpty()) & q->min().s <= f + 1) do max := Set{max, q->min().t}->max() ; ; if (f < max) then ( res := res + 1 ; f := max ) else skip ) ; OclFile["System.out"].println(if f = N then res else "Impossible" endif) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintStream ; class Main { public static void main(String[] args)throws IOException { doit(args,System.in,System.out); } static void doit(String[] args,InputStream in,PrintStream out)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(in)); while(true){ String line=reader.readLine(); if(line==null || line.isEmpty()){ break ; } String[] values=line.split(" "); int a=Integer.parseInt(values[0]); int b=Integer.parseInt(values[1]); int n=Integer.parseInt(values[2]); int q=Math.abs(b); int p=Math.abs(a)% q ; int sum=0 ; for(int i=0 ; iisEmpty()) then ( break ) else skip ; var values : Sequence(String) ; values := line->split(" ") ; var a : int ; a := (values[0+1])->toInteger() ; var b : int ; b := (values[1+1])->toInteger() ; var n : int ; n := (values[2+1])->toInteger() ; var q : int ; q := if b < 0 then -(b) else b endif ; var p : int ; p := if a < 0 then -(a) else a endif mod q ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( p := p*(10) ; var f : int ; f := p / q ; if (f = 0) then ( continue ) else skip ; sum := sum+(f) ; p := p mod q ; ) ; i := i + 1 ) ; out.println(sum) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.HashSet ; import java.util.LinkedList ; import java.util.Scanner ; import java.util.TreeSet ; import javax.print.attribute.standard.MediaSize.Other ; import javax.xml.bind.ParseConversionEvent ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); final int N=sc.nextInt(); final int M=sc.nextInt(); int[][] data=new int[M][2]; for(int i=0 ; i=limit){ max=Math.max(max,data[i][1]); } } if(max==Integer.MIN_VALUE){ System.out.println("Impossible"); return ; } else { limit=max+1 ; count++; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var data : Sequence(Sequence(int)) ; data := Integer.subrange(1,M)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < M do ( ( var j : int ; j := 0 ; while j < 2 do ( ( data[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var limit : int ; limit := 1 ; var count : int ; count := 0 ; while (limit <= N) do ( var max : int ; max := -2147483648 ; var i : int ; i := 0 ; while i < M do ( ( if (data[i+1][0+1] <= limit & data[i+1][1+1] >= limit) then ( max := Set{max, data[i+1][1+1]}->max() ) else skip ) ; i := i + 1 ) ; if (max = -2147483648) then ( OclFile["System.out"].println("Impossible") ; return ) else ( limit := max + 1 ; count := count + 1 ) ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getPairs(int a[]){ int n=a.length ; int count=(n*(n-1))/2 ; return count ; } public static void main(String[] args){ int a[]={ 2,4,3,1 }; System.out.println(getPairs(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getPairs( a : Sequence(int)) : int pre: true post: true activity: ( var n : int ; n := a->size() ; var count : int ; count := (n * (n - 1)) / 2 ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,4,3,1} ; OclFile["System.out"].println(getPairs(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=Integer.parseInt(in.next()); ListA=new ArrayList<>(); for(int i=0 ; ilower=(x,y)->x.compareTo(y)>=0 ? 1 :-1 ; for(int i=0 ; i=0)System.out.println(p); else System.out.println(n); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (in.getCurrent())->toInteger() ; var A : Sequence(int) ; A := Sequence{} ; var i : int ; i := 0 ; while i < n do ( A := A->including((in.getCurrent())->toInteger()) ; ; i := i + 1 ) ; var q : int ; q := (in.getCurrent())->toInteger() ; var lower : Function(,(,boolean)) ; lower := lambda (x , y) : OclAny in if x->compareTo(y) >= 0 then 1 else -1 endif ; var i : int ; i := 0 ; while i < q do ( ( var key : int ; key := (in.getCurrent())->toInteger() ; var p : int ; p := -(.binarySearch(A, key, lower) + 1) ; if (p >= 0) then OclFile["System.out"].println(p) ; else OclFile["System.out"].println(n) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private Scanner sc ; public static void main(String[] args){ new Main(); } public Main(){ sc=new Scanner(System.in); int counter=0 ; int maxw=Integer.parseInt(sc.nextLine()); while(maxw!=0){ counter++; int num=Integer.parseInt(sc.nextLine()); int[][] table=new int[num+1][maxw+1]; for(int i=0 ; i=0){ if(table[i][j]>(table[i][j-w]+value))table[i+1][j]=table[i][j]; else table[i+1][j]=table[i][j-w]+value ; } else { table[i+1][j]=table[i][j]; } } } int max=0 ; int index=0 ; for(int i=0 ; itoInteger() ; while (maxw /= 0) do ( counter := counter + 1 ; var num : int ; num := (sc.nextLine())->toInteger() ; var table : Sequence(Sequence(int)) ; table := Integer.subrange(1,num + 1)->collect(Integer.subrange(1,maxw + 1)->collect(0)) ; var i : int ; i := 0 ; while i < table->size() do ( ( var j : int ; j := 0 ; while j < table[0+1]->size() do ( ( table[i+1][j+1] := 0 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var value : int ; var w : int ; var i : int ; i := 0 ; while i < num do ( ( var nico : Sequence(String) ; nico := sc.nextLine()->split(",") ; value := (nico[0+1])->toInteger() ; w := (nico[1+1])->toInteger() ; var j : int ; j := 0 ; while j < table[0+1]->size() do ( ( if ((j - w) >= 0) then ( if (table[i+1][j+1] > (table[i+1][j - w+1] + value)) then table[i + 1+1][j+1] := table[i+1][j+1] ; else table[i + 1+1][j+1] := table[i+1][j - w+1] + value ; ) else ( table[i + 1+1][j+1] := table[i+1][j+1] ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < table[0+1]->size() do ( ( if (max < table[num+1][i+1]) then ( max := table[num+1][i+1] ; index := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Case " + counter + ":") ; OclFile["System.out"].println(max) ; OclFile["System.out"].println(index) ; maxw := (sc.nextLine())->toInteger() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); int[] a=new int[n+1]; a[0]=-1000000001 ; str=br.readLine().split(" "); for(int i=0 ; i1){ int mid=lb+(ub-lb)/2 ; if(a[mid]>=k)ub=mid ; else lb=mid ; } System.out.println(ub-1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; a[0+1] := -1000000001 ; str := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( a[i + 1+1] := (str[i+1])->toInteger() ; ; i := i + 1 ) ; str := br.readLine()->split(" ") ; var q : int ; q := (str[0+1])->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( str := br.readLine()->split(" ") ; var k : int ; k := (str[0+1])->toInteger() ; var lb : int ; lb := 0 ; var ub : int ; ub := n + 1 ; while (ub - lb > 1) do ( var mid : int ; mid := lb + (ub - lb) / 2 ; if (a[mid+1] >= k) then ub := mid ; else lb := mid ; ) ; OclFile["System.out"].println(ub - 1) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { public static void nibutan(int array[],int length,int num){ int pos=-1 ; int lower=0 ; int upper=length-1 ; while(lower<=upper){ int mid=(lower+upper)/2 ; if(array[mid]>=num){ upper=mid ; } else if(array[mid]=num){ pos=upper ; } else if(array[lower]>=num){ pos=0 ; } else { pos=length ; } break ; } if(upper==lower){ if(array[0]= num) then ( upper := mid ) else if (array[mid+1] < num) then ( lower := mid ) else skip ; ; if (upper - lower = 1) then ( if (array[lower+1] < num & array[upper+1] >= num) then ( pos := upper ) else if (array[lower+1] >= num) then ( pos := 0 ) else ( pos := length ) ; ; break ) else skip ; if (upper = lower) then ( if (array[0+1] < num) then ( pos := length ) else ( pos := 0 ) ; break ) else skip ) ; OclFile["System.out"].println(pos) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := stdIn.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := stdIn.getCurrent()->toInteger() ) ; i := i + 1 ) ; var q : int ; q := stdIn.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var k : int ; k := stdIn.getCurrent()->toInteger() ; execute nibutan(a, n, k) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static StringBuilder sb ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); sb=new StringBuilder(); int num=sc.nextInt(); ArrayListarray=new ArrayList<>(); for(int i=0 ; ilist,int key){ int lower=-1 ; int middle=-1 ; int upper=list.size(); while(upper>lower+1){ middle=lower+(upper-lower)/2 ; if(list.get(middle)>key-1)upper=middle ; else lower=middle ; } return upper ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sb : String; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; sb := StringLib.newString() ; var num : int ; num := sc.getCurrent()->toInteger() ; var array : Sequence(int) ; array := Sequence{} ; var i : int ; i := 0 ; while i < num do ( ( array := array->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var query : int ; query := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < query do ( ( var key : int ; key := sc.getCurrent()->toInteger() ; var tmp : int ; tmp := BinarySearch(array, key) ; if (tmp < 0) then sb := sb + StringLib.newString(num) + StringLib.newString("\n") ; else sb := sb + StringLib.newString(tmp) + StringLib.newString("\n") ; ) ; i := i + 1 ) ; OclFile["System.out"].print(sb) ; skip ; ); static operation BinarySearch( list : Sequence(int), key : int) : int pre: true post: true activity: ( var lower : int ; lower := -1 ; var middle : int ; middle := -1 ; var upper : int ; upper := list->size() ; while (upper > lower + 1) do ( middle := lower + (upper - lower) / 2 ; if (list->at(middle+1) > key - 1) then upper := middle ; else lower := middle ; ) ; return upper ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int n=sc.nextInt(); long[] array=new long[n]; for(int i=0 ; iarray[n-1])System.out.println(n); else { System.out.println(lowerBound(array,k)); } } } } static int lowerBound(long[] array,long target){ int low=0 ; int high=array.length-1 ; while(lowtoInteger() ; var array : Sequence(long) ; array := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( array[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var same : boolean ; same := true ; var query : int ; query := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < query do ( ( var k : long ; k := sc.getCurrent()->toLong() ; if (k > array[n - 1+1]) then OclFile["System.out"].println(n) ; else ( OclFile["System.out"].println(lowerBound(array, k)) ) ) ; i := i + 1 ) ; )) ); static operation lowerBound( array : Sequence(long), target : long) : int pre: true post: true activity: ( var low : int ; low := 0 ; var high : int ; high := array->size() - 1 ; while (low < high) do ( var mid : int ; mid := (high + low) / 2 ; if (array[mid+1] = target) then ( while ((mid /= 0) & (array[mid - 1+1] = target)) do mid := mid - 1 ; ; return mid ) else if (array[mid+1] < target) then low := mid + 1 else high := mid ; ; ) ; while ((high /= 0) & (array[high - 1+1] = array[high+1])) do high := high - 1 ; ; return high ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printPalindrome(Vectorleft,String mid,Vectorright){ for(String x : left)System.out.print(x); System.out.print(mid); Collections.reverse(right); for(String x : right)System.out.print(x); System.out.println(); } static void findPalindrome(VectorS,int N,int M){ HashSetdict=new HashSet(); for(int i=0 ; ileft=new Vector(),right=new Vector(); String mid="" ; for(int i=0 ; iS=new Vector(Arrays.asList(arr)); int M=3 ; int N=S.size(); findPalindrome(S,N,M); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printPalindrome( left : Sequence(String), mid : String, right : Sequence(String)) : void pre: true post: true activity: ( for (x : left) do ( OclFile["System.out"].print(x) ; ) ; OclFile["System.out"].print(mid) ; right := right->reverse() ; for (x : right) do ( OclFile["System.out"].print(x) ; ) ; OclFile["System.out"].println() ; ); static operation findPalindrome( S : Sequence(String), N : int, M : int) : void pre: true post: true activity: ( var dict : Set(String) ; dict := Set{} ; var i : int ; i := 0 ; while i < M do ( ( dict := dict->including(S->at(i+1)) ) ; i := i + 1 ) ; var left : Sequence(String) ; left := Sequence{} ; var right : Sequence(String) ; right := Sequence{} ; var mid : String ; mid := "" ; var i : int ; i := 0 ; while i < N do ( ( var t : String ; t := S->at(i+1) ; t := reverse(t) ; if (t = S->at(i+1)) then mid := t ; else if (dict->includes(t)) then ( left := left->including(S->at(i+1)) ; right->excludes(t) ; dict := dict->excludingFirst(S->at(i+1)) ; dict := dict->excludingFirst(t) ) else skip ; ) ; i := i + 1 ) ; execute printPalindrome(left, mid, right) ; ); static operation reverse( input : String) : String pre: true post: true activity: ( var a : Sequence(String) ; a := input->characters() ; var l : int ; var r : int ; r := a->size() - 1 ; l := 0 ; while l < r do ( ( var temp : String ; temp := a[l+1] ; a[l+1] := a[r+1] ; a[r+1] := temp ) ; l := l + 1 ; r := r - 1 ) ; return (a)->sum() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"tab","one","bat"} ; var S : Sequence(String) ; S := Sequence{}->union(arr) ; var M : int ; M := 3 ; var N : int ; N := S->size() ; execute findPalindrome(S, N, M) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); final int N=sc.nextInt(); final int K=sc.nextInt(); Point[] points=new Point[N]; long[] xList=new long[N]; long[] yList=new long[N]; for(int i=0 ; i=K){ ans=Math.min(ans,(xr-xl)*(yu-yb)); } } } } } System.out.println(ans); } static class Point { public Point(long x,long y){ this.x=x ; this.y=y ; } long x ; long y ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var points : Sequence(Point) ; points := Integer.subrange(1,N)->collect(null) ; var xList : Sequence(long) ; xList := Integer.subrange(1,N)->collect(0) ; var yList : Sequence(long) ; yList := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( points[i+1] := Point.newPoint(sc.getCurrent()->toLong(), sc.getCurrent()->toLong()) ; xList[i+1] := points[i+1].x ; yList[i+1] := points[i+1].y ) ; i := i + 1 ) ; skip ; var ans : long ; ans := "9223372036854775807"->toLong() ; xList := xList->sort() ; yList := yList->sort() ; var xi : int ; xi := 0 ; while xi < N do ( ( var xj : int ; xj := xi + 1 ; while xj < N do ( ( var yi : int ; yi := 0 ; while yi < N do ( ( var yj : int ; yj := yi + 1 ; while yj < N do ( ( var xl : long ; xl := xList[xi+1] ; var xr : long ; xr := xList[xj+1] ; var yb : long ; yb := yList[yi+1] ; var yu : long ; yu := yList[yj+1] ; var num : int ; num := 0 ; for (p : points) do ( ( if (xl <= p.x & p.x <= xr & yb <= p.y & p.y <= yu) then ( num := num + 1 ) else skip ) ) ; if (num >= K) then ( ans := Set{ans, (xr - xl) * (yu - yb)}->min() ) else skip ; ) ; yj := yj + 1 ) ) ; yi := yi + 1 ) ) ; xj := xj + 1 ) ) ; xi := xi + 1 ) ; OclFile["System.out"].println(ans) ; ); static class Point { static operation newPoint( x : long, y : long) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : long, y : long) : void pre: true post: true activity: ( self.x := x ; self.y := y ); attribute x : long; attribute y : long; } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int findlargestAfterDel(int arr[],int m,int del[],int n){ HashMapmp=new HashMap(); for(int i=0 ; ikeys()->includes(del[i+1])) then ( mp := mp->union(Map{del[i+1] |-> mp->at(del[i+1]) + 1}) ) else ( mp := mp->union(Map{del[i+1] |-> 1}) ) ) ; i := i + 1 ) ; var largestElement : int ; largestElement := -2147483648 ; var i : int ; i := 0 ; while i < m do ( ( if (mp->keys()->includes(arr[i+1])) then ( mp := mp->union(Map{arr[i+1] |-> mp->at(arr[i+1]) - 1}) ; if (mp->at(arr[i+1]) = 0) then mp := mp->antirestrict(Set{arr[i+1]}) ; else skip ) else largestElement := Set{largestElement, arr[i+1]}->max() ; ) ; i := i + 1 ) ; return largestElement ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var array : Sequence(int) ; array := Sequence{5,12,33,4,56,12,20} ; var m : int ; m := array->size() ; var del : Sequence(int) ; del := Sequence{12,33,56,5} ; var n : int ; n := del->size() ; OclFile["System.out"].println(findlargestAfterDel(array, m, del, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; public final class p100 implements EulerSolution { public static void main(String[] args){ System.out.println(new p100().run()); } public String run(){ BigInteger x0=BigInteger.valueOf(3); BigInteger y0=BigInteger.valueOf(1); BigInteger x=x0 ; BigInteger y=y0 ; while(true){ BigInteger sqrt=Library.sqrt(y.multiply(y).multiply(BigInteger.valueOf(8)).add(BigInteger.ONE)); if(sqrt.testBit(0)){ BigInteger blue=sqrt.add(BigInteger.ONE).divide(BigInteger.valueOf(2)).add(y); if(blue.add(y).compareTo(BigInteger.TEN.pow(12))>0)return blue.toString(); } BigInteger nextx=x.multiply(x0).add(y.multiply(y0).multiply(BigInteger.valueOf(8))); BigInteger nexty=x.multiply(y0).add(y.multiply(x0)); x=nextx ; y=nexty ; } } } ------------------------------------------------------------ OCL File: --------- class p100 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p100.newp100().run()) ); operation run() : String pre: true post: true activity: ( var x0 : long ; x0 := (3 + "")->toLong() ; var y0 : long ; y0 := (1 + "")->toLong() ; var x : long ; x := x0 ; var y : long ; y := y0 ; while (true) do ( var sqrt : long ; sqrt := Library.sqrt(y.multiply(y).multiply((8 + "")->toLong())->excludes(1)) ; if (sqrt.testBit(0)) then ( var blue : long ; blue := sqrt->excludes(1).divide((2 + "")->toLong())->excludes(y) ; if (blue->excludes(y)->compareTo(10.pow(12)) > 0) then return blue+"" else skip ) else skip ; var nextx : long ; nextx := x.multiply(x0)->excludes(y.multiply(y0).multiply((8 + "")->toLong())) ; var nexty : long ; nexty := x.multiply(y0)->excludes(y.multiply(x0)) ; x := nextx ; y := nexty ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class BHungarySequence { public static void main(String[] args)throws IOException { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(buf.readLine()); StringBuilder str=new StringBuilder(); for(int i=t+1 ; i<=2*t ; i++)str.append(i+" "); System.out.println(str); } } ------------------------------------------------------------ OCL File: --------- class BHungarySequence { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var buf : OclFile ; buf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var t : int ; t := (buf.readLine())->toInteger() ; var str : String ; str := StringLib.newString() ; var i : int ; i := t + 1 ; while i <= 2 * t do ( str := str + StringLib.newString(i + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class HungrySequence1 { public static void main(String args[]){ int i,j,k,t,n ; Scanner sc=new Scanner(System.in); n=sc.nextInt(); boolean a[]=new boolean[10000001]; for(i=2 ; i*i<=10000000 ; i++){ if(a[i]==false){ for(j=i*i ; j<=10000000 ; j+=i){ a[j]=true ; } } } int count=0 ; for(i=2 ; ; i++){ if(a[i]==false){ System.out.print(i+" "); count++; } if(count==n){ break ; } } } } ------------------------------------------------------------ OCL File: --------- class HungrySequence1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var j : int ; var k : int ; var t : int ; var n : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; var a : Sequence(boolean) ; a := Integer.subrange(1,10000001)->collect(false) ; i := 2 ; while i * i <= 10000000 do ( ( if (a[i+1] = false) then ( j := i * i ; while j <= 10000000 do ( ( a[j+1] := true ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; var count : int ; count := 0 ; i := 2 ; while true do ( ( if (a[i+1] = false) then ( OclFile["System.out"].print(i + " ") ; count := count + 1 ) else skip ; if (count = n) then ( break ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=n ; i<2*n ; i++){ System.out.print(i+" "); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := n ; while i < 2 * n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; import static java.lang.System.out ; public class Main { public static void main(String args[]){ new Main().run(); } int toInt(String s){ return Integer.parseInt(s); } void run(){ Scanner sc=new Scanner(System.in); int caseNumber=1 ; while(true){ int W=sc.nextInt(); if(W==0)break ; int N=sc.nextInt(); int[] value=new int[N]; int[] weight=new int[N]; sc.skip("\n"); for(int i=0 ; i=0 ; --j){ if(dp[N][j]==ansValue)ansWeight=j ; } out.println("Case "+caseNumber+":"); caseNumber++; out.println(ansValue); out.println(ansWeight); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation toInt( s : String) : int pre: true post: true activity: ( return (s)->toInteger() ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var caseNumber : int ; caseNumber := 1 ; while (true) do ( var W : int ; W := sc.getCurrent()->toInteger() ; if (W = 0) then break else skip ; var N : int ; N := sc.getCurrent()->toInteger() ; var value : Sequence(int) ; value := Integer.subrange(1,N)->collect(0) ; var weight : Sequence(int) ; weight := Integer.subrange(1,N)->collect(0) ; skip ; var i : int ; i := 0 ; while i < N do ( ( var line : String ; line := sc.nextLine() ; value[i+1] := toInt(line->split(",")[0+1]) ; weight[i+1] := toInt(line->split(",")[1+1]) ) ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,N + 1)->collect(Integer.subrange(1,W + 1)->collect(0)) ; var i : int ; i := 0 ; while i < N + 1 do ( var j : int ; j := 0 ; while j < W + 1 do ( dp[i+1][j+1] := 0 ; ; j := j + 1 ) ; ; i := i + 1 ) ; var item : int ; item := 0 ; while item < N do ( ( var cur : int ; cur := 0 ; while cur <= W do ( ( var v : int ; v := value[item+1] ; var w : int ; w := weight[item+1] ; if (w <= cur) then ( dp[item + 1+1][cur+1] := Set{dp[item+1][cur+1], dp[item+1][cur - w+1] + v}->max() ) else ( dp[item + 1+1][cur+1] := dp[item+1][cur+1] ) ) ; cur := cur + 1 ) ) ; item := item + 1 ) ; var ansWeight : int ; ansWeight := W ; var ansValue : int ; ansValue := dp[N+1][W+1] ; var j : int ; j := W ; while j >= 0 do ( ( if (dp[N+1][j+1] = ansValue) then ansWeight := j ; else skip ) ; j := j - 1 ) ; out.println("Case " + caseNumber + ":") ; caseNumber := caseNumber + 1 ; out.println(ansValue) ; out.println(ansWeight) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static boolean isPowerOfTwo(int x){ return x!=0 &&((x &(x-1))==0); } static boolean differAtOneBitPos(int a,int b){ return isPowerOfTwo(a ^ b); } public static void main(String args[]){ int a=13,b=9 ; if(differAtOneBitPos(a,b)==true)System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPowerOfTwo( x : int) : boolean pre: true post: true activity: ( return x /= 0 & ((x & (x - 1)) = 0) ); static operation differAtOneBitPos( a : int, b : int) : boolean pre: true post: true activity: ( return isPowerOfTwo(a xor b) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 13 ; var b : int ; b := 9 ; if (differAtOneBitPos(a, b) = true) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Round671A { public static PrintWriter pw=new PrintWriter(System.out); public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); String num=br.readLine(); int ans=2 ; if(n==2){ if((num.charAt(1)-'0')% 2!=0){ ans=1 ; } } else { if(n>2 && n % 2==0){ for(int i=1 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := (br.readLine())->toInteger() ; var num : String ; num := br.readLine() ; var ans : int ; ans := 2 ; if (n = 2) then ( if ((num->at(1+1) - ('0')->char2byte()) mod 2 /= 0) then ( ans := 1 ) else skip ) else ( if (n > 2 & n mod 2 = 0) then ( var i : int ; i := 1 ; while i < num->size() do ( ( if ((num->at(i+1) - ('0')->char2byte()) mod 2 = 0) then ( ans := 2 ; break ) else skip ; ans := 1 ) ; i := i+(2) ) ) else ( var i : int ; i := 0 ; while i < num->size() do ( ( if ((num->at(i+1) - ('0')->char2byte()) mod 2 /= 0) then ( ans := 1 ; break ) else skip ) ; i := i+(2) ) ) ) ; skip ; ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DigitGame { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(); String s=sc.next(); System.out.println(whoWins(s,n)); } } private static char whoWins(String s,int n){ if(n==1){ return(s.charAt(0)-'0')% 2==0 ? '2' : '1' ; } boolean isOdd=false ; boolean isEven=false ; for(int i=1 ; i<=n ; i++){ int num=s.charAt(i-1)-'0' ; if(i % 2==0){ isEven |=(num % 2==0); } else { isOdd |=(num % 2==1); } } if(n % 2==0){ return isEven ? '2' : '1' ; } return isOdd ? '1' : '2' ; } } ------------------------------------------------------------ OCL File: --------- class DigitGame { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := sc.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; OclFile["System.out"].println(whoWins(s, n)) ) ; ) ); static operation whoWins( s : String, n : int) : String pre: true post: true activity: ( if (n = 1) then ( return if (s->at(0+1) - ('0')->char2byte()) mod 2 = 0 then '2' else '1' endif ) else skip ; var isOdd : boolean ; isOdd := false ; var isEven : boolean ; isEven := false ; var i : int ; i := 1 ; while i <= n do ( ( var num : int ; num := s->at(i - 1+1) - ('0')->char2byte() ; if (i mod 2 = 0) then ( isEven := MathLib.bitwiseOr(isEven, (num mod 2 = 0)) ) else ( isOdd := MathLib.bitwiseOr(isOdd, (num mod 2 = 1)) ) ) ; i := i + 1 ) ; if (n mod 2 = 0) then ( return if isEven then '2' else '1' endif ) else skip ; return if isOdd then '1' else '2' endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.math.RoundingMode ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=null ; int n=0 ; String s=null ; int result=0 ; try { sc=new Scanner(System.in); while(sc.hasNextBigDecimal()){ BigDecimal a=sc.nextBigDecimal(); BigDecimal b=sc.nextBigDecimal(); n=sc.nextInt(); s=String.valueOf(a.divide(b,n,RoundingMode.DOWN)); String[] str=s.substring(s.indexOf(".")+1,s.indexOf(".")+(1+n)).split("(?<=.)"); for(String sum : str){ result+=Integer.parseInt(sum); } System.out.println(result); result=0 ; } } finally { sc.close(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := null ; var n : int ; n := 0 ; var s : String ; s := null ; var result : int ; result := 0 ; try ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNextBigDecimal()) do ( var a : double ; a := sc.nextBigDecimal() ; var b : double ; b := sc.nextBigDecimal() ; n := sc.getCurrent()->toInteger() ; s := ((a.divide(b, n, RoundingMode.DOWN)) + "") ; var str : Sequence(String) ; str := s.subrange(s->indexOf(".")-1 + 1+1,s->indexOf(".")-1 + (1 + n))->split("(?<=.)") ; for (sum : str) do ( ( result := result+((sum)->toInteger()) ) ) ; OclFile["System.out"].println(result) ; result := 0 ; ) ) finally ( skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); String s=sc.next(); int len=s.length(); int evenrazecnt=0 ; int oddrazecnt=0 ; int evenbreachcnt=0 ; int oddbreachcnt=0 ; for(int i=0 ; i0)System.out.println(2); else System.out.println(1); } else { if(oddrazecnt>0)System.out.println(1); else System.out.println(2); } } } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var len : int ; len := s->size() ; var evenrazecnt : int ; evenrazecnt := 0 ; var oddrazecnt : int ; oddrazecnt := 0 ; var evenbreachcnt : int ; evenbreachcnt := 0 ; var oddbreachcnt : int ; oddbreachcnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( var num : int ; num := s->at(i+1) - ('0')->char2byte() ; if ((MathLib.bitwiseAnd(num,1)) = 0) then evenrazecnt := evenrazecnt + 1 ; else oddrazecnt := oddrazecnt + 1 ; ) ; i := i + 2 ) ; var i : int ; i := 1 ; while i < n do ( ( var num : int ; num := s->at(i+1) - ('0')->char2byte() ; if ((MathLib.bitwiseAnd(num,1)) = 0) then evenbreachcnt := evenbreachcnt + 1 ; else oddbreachcnt := oddbreachcnt + 1 ; ) ; i := i + 2 ) ; if ((MathLib.bitwiseAnd(len,1)) = 0) then ( if (evenbreachcnt > 0) then OclFile["System.out"].println(2) ; else OclFile["System.out"].println(1) ; ) else ( if (oddrazecnt > 0) then OclFile["System.out"].println(1) ; else OclFile["System.out"].println(2) ; ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static void main(String[] args){ int a=5,b=7,c=10 ; if(a<=b && a<=c)System.out.println(a+" is the smallest"); else if(b<=a && b<=c)System.out.println(b+" is the smallest"); else System.out.println(c+" is the smallest"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 5 ; var b : int ; b := 7 ; var c : int ; c := 10 ; if (a <= b & a <= c) then OclFile["System.out"].println(a + " is the smallest") ; else if (b <= a & b <= c) then OclFile["System.out"].println(b + " is the smallest") else OclFile["System.out"].println(c + " is the smallest") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static int countNumbers(int N){ return(int)Math.sqrt(N)-1 ; } public static void main(String args[]){ int N=36 ; System.out.println(countNumbers(N)); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation countNumbers( N : int) : int pre: true post: true activity: ( return (N)->sqrt()->oclAsType(int) - 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 36 ; OclFile["System.out"].println(countNumbers(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Dancing { public static void main(String[] args)throws Exception { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int T=Integer.parseInt(in.readLine()); for(int i=0 ; i=p){ ans++; } else if(scores[j]/3==p-1 && scores[j] % 3>0){ ans++; } else if(scores[j]/3==p-1 && scores[j] % 3==0 && S>0){ ans++; S--; } else if(scores[j]/3==p-2 && scores[j] % 3==2 && S>0){ ans++; S--; } } System.out.println("Case #"+(i+1)+": "+ans); } } } ------------------------------------------------------------ OCL File: --------- class Dancing { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var T : int ; T := (in.readLine())->toInteger() ; var i : int ; i := 0 ; while i < T do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String(in.readLine()) ; var N : int ; N := (st.next())->toInteger() ; var S : int ; S := (st.next())->toInteger() ; var p : int ; p := (st.next())->toInteger() ; var scores : Sequence(int) ; scores := Integer.subrange(1,N)->collect(0) ; var j : int ; j := 0 ; while j < N do ( ( scores[j+1] := (st.next())->toInteger() ) ; j := j + 1 ) ; var ans : int ; ans := 0 ; var j : int ; j := 0 ; while j < N do ( ( if (p = 0) then ( ans := ans + 1 ; continue ) else skip ; if (scores[j+1] = 0) then continue else skip ; if (scores[j+1] / 3 >= p) then ( ans := ans + 1 ) else if (scores[j+1] / 3 = p - 1 & scores[j+1] mod 3 > 0) then ( ans := ans + 1 ) else if (scores[j+1] / 3 = p - 1 & scores[j+1] mod 3 = 0 & S > 0) then ( ans := ans + 1 ; S := S - 1 ) else if (scores[j+1] / 3 = p - 2 & scores[j+1] mod 3 = 2 & S > 0) then ( ans := ans + 1 ; S := S - 1 ) else skip ; ; ; ) ; j := j + 1 ) ; OclFile["System.out"].println("Case #" + (i + 1) + ": " + ans) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package j2012qualifier ; import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class B { public static String inputDirectory="src/j2012qualifier/" ; public static String inputFile="B.in" ; public static String outputFile="B.out" ; public static PrintWriter output ; public static void main(String[] args)throws FileNotFoundException { Scanner s=new Scanner(new File(inputDirectory+inputFile)); output=new PrintWriter(new File(inputDirectory+outputFile)); int cases=s.nextInt(); for(int Case=1 ; Case<=cases ; Case++){ s.nextLine(); int googlers=s.nextInt(); int maxSupriseScores=s.nextInt(); int targetScore=s.nextInt(); int normalScores=0 ; int surpriseScores=0 ; for(int i=0 ; iscore){ continue ; } int otherScore=(score-targetScore)/2 ; if(otherScore>=targetScore-1){ normalScores++; } else if(otherScore>=targetScore-2){ surpriseScores++; } } int answer=normalScores+Math.min(surpriseScores,maxSupriseScores); out("Case #"+Case+": "+answer); } output.flush(); } public static void out(String s){ output.println(s); } } ------------------------------------------------------------ OCL File: --------- class B { static attribute inputDirectory : String := "src/j2012qualifier/"; static attribute inputFile : String := "B.in"; static attribute outputFile : String := "B.out"; static attribute output : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile(inputDirectory + inputFile)) ; output := OclFile.newOclFile_Write(OclFile(inputDirectory + outputFile)) ; var cases : int ; cases := s.getCurrent()->toInteger() ; var Case : int ; Case := 1 ; while Case <= cases do ( ( skip ; var googlers : int ; googlers := s.getCurrent()->toInteger() ; var maxSupriseScores : int ; maxSupriseScores := s.getCurrent()->toInteger() ; var targetScore : int ; targetScore := s.getCurrent()->toInteger() ; var normalScores : int ; normalScores := 0 ; var surpriseScores : int ; surpriseScores := 0 ; var i : int ; i := 0 ; while i < googlers do ( ( var score : int ; score := s.getCurrent()->toInteger() ; if (targetScore > score) then ( continue ) else skip ; var otherScore : int ; otherScore := (score - targetScore) / 2 ; if (otherScore >= targetScore - 1) then ( normalScores := normalScores + 1 ) else if (otherScore >= targetScore - 2) then ( surpriseScores := surpriseScores + 1 ) else skip ; ) ; i := i + 1 ) ; var answer : int ; answer := normalScores + Set{surpriseScores, maxSupriseScores}->min() ; execute out("Case #" + Case + ": " + answer) ; ) ; Case := Case + 1 ) ; skip ; ); static operation out( s : String) : void pre: true post: true activity: ( skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class CodeJam2012_Q_B { public int calc(int N,int S,int p,int[] score){ int cnt=0 ; for(int i=0 ; i=p+Math.max(p-1,0)*2){ cnt++; } else if(score[i]>=p+Math.max(p-2,0)*2 && S>0){ cnt++; S--; } } return cnt ; } public static void main(String[] args){ try { (new CodeJam2012_Q_B()).exec("B-large.in","2012_Q_B-large.out"); } catch(Exception ex){ } } public final void exec(String inFileName,String outFileName)throws Exception { BufferedReader inReader=new BufferedReader(new FileReader(inFileName)); PrintWriter outWriter=new PrintWriter(new BufferedWriter(new FileWriter(outFileName))); int caseNums=0 ; caseNums=Integer.parseInt(inReader.readLine()); for(int i=0 ; i= p + Set{p - 1, 0}->max() * 2) then ( cnt := cnt + 1 ) else if (score[i+1] >= p + Set{p - 2, 0}->max() * 2 & S > 0) then ( cnt := cnt + 1 ; S := S - 1 ) else skip ; ) ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( (CodeJam2012_Q_B.newCodeJam2012_Q_B()).exec("B-large.in", "2012_Q_B-large.out") ) catch (ex : ProgramException) do skip ); operation exec( inFileName : String, outFileName : String) : void pre: true post: true activity: ( var inReader : OclFile ; inReader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(inFileName)) ; var outWriter : OclFile ; outWriter := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(outFileName))) ; var caseNums : int ; caseNums := 0 ; caseNums := (inReader.readLine())->toInteger() ; var i : int ; i := 0 ; while i < caseNums do ( ( var input : Sequence(String) ; input := inReader.readLine()->split(" ") ; var N : int ; N := (input[0+1])->toInteger() ; var S : int ; S := (input[1+1])->toInteger() ; var p : int ; p := (input[2+1])->toInteger() ; var score : Sequence(int) ; score := Integer.subrange(1,N)->collect(0) ; var j : int ; j := 0 ; while j < N do ( score[j+1] := (input[j + 3+1])->toInteger() ; ; j := j + 1 ) ; var outStr : int ; outStr := calc(N, S, p, score) ; var fmtOutStr : String ; fmtOutStr := "Case #" + (i + 1) + ": " + outStr ; skip ; OclFile["System.out"].println(fmtOutStr) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(caseNums + " cases complete") ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.HashSet ; import java.util.Map ; import java.util.Scanner ; import java.util.Set ; public class Main { class R { String s ; Setadj ; boolean u ; public R(String s){ this.s=s ; adj=new HashSet(); } int f(){ if(u)return 0 ; u=true ; if(adj.isEmpty())return 1 ; int res=0 ; for(R r : adj)res+=r.f(); return res ; } } Mapref ; R get(String s){ if(ref.containsKey(s))return ref.get(s); R r=new R(s); ref.put(s,r); return r ; } void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int n=sc.nextInt(); if(n==0)break ; ref=new HashMap(); String g="" ; while(n--!=0){ String t=sc.next(); String[] s=t.substring(0,t.length()-1).split(":"); if("".equals(g))g=s[0]; R r=get(s[0]); for(String v : s[1] .split(","))r.adj.add(get(v)); } System.out.println(get(g).f()); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { class R { attribute s : String; attribute adj : Set(R); attribute u : boolean; static operation newR( s : String) : R pre: true post: true activity: ( var self : R ; self := createR(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( self.s := s ; adj := Set{} ); operation f() : int pre: true post: true activity: ( if (u) then return 0 else skip ; u := true ; if (adj->isEmpty()) then return 1 else skip ; var res : int ; res := 0 ; for (r : adj) do ( res := res+(r.f()) ; ) ; return res ); } attribute ref : Map(String,R); operation get( s : String) : R pre: true post: true activity: ( if (ref->keys()->includes(s)) then return ref->at(s) else skip ; var r : R ; r := R.newR(s) ; ref := ref->union(Map{s |-> r}) ; return r ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; ref := Map{} ; var g : String ; g := "" ; while (n /= 0) do ( skip ; ( var t : String ; t := sc.getCurrent() ; var s : Sequence(String) ; s := t.subrange(0+1,t->size() - 1)->split(":") ; if ("" = g) then g := s[0+1] ; else skip ; var r : R ; r := get(s[0+1]) ; for (v : s[1+1]->split(",")) do ( r.adj->excludes(at(v+1)) ; ) ; ) ; ) ; OclFile["System.out"].println(at(g+1).f()) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Double.parseDouble ; import static java.lang.Integer.parseInt ; import static java.lang.Long.parseLong ; import static java.lang.System.exit ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class B { static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; static int test ; static void solve()throws Exception { int n=nextInt(); int s=nextInt(); int p=nextInt(); int ans=0 ; for(int i=0 ; i=p){ ++ans ; } else if(s>0 && t>0 &&(t+4)/3>=p){ --s ; ++ans ; } } printCase(); out.println(ans); } static void printCase(){ out.print("Case #"+test+": "); } static void printlnCase(){ out.println("Case #"+test+":"); } static int nextInt()throws IOException { return parseInt(next()); } static long nextLong()throws IOException { return parseLong(next()); } static double nextDouble()throws IOException { return parseDouble(next()); } static String next()throws IOException { while(tok==null || ! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } public static void main(String[] args){ try { in=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(new OutputStreamWriter(System.out)); int tests=nextInt(); for(test=1 ; test<=tests ; test++){ solve(); } in.close(); out.close(); } catch(Throwable e){ e.printStackTrace(); exit(1); } } } ------------------------------------------------------------ OCL File: --------- class B { static attribute in : OclFile; static attribute out : OclFile; static attribute tok : OclIterator; static attribute test : int; static operation solve() : void pre: true post: true activity: ( var n : int ; n := nextInt() ; var s : int ; s := nextInt() ; var p : int ; p := nextInt() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var t : int ; t := nextInt() ; if ((t + 2) / 3 >= p) then ( ans := ans + 1 ) else if (s > 0 & t > 0 & (t + 4) / 3 >= p) then ( s := s - 1 ; ans := ans + 1 ) else skip ; ) ; i := i + 1 ) ; execute printCase() ; skip ; ); static operation printCase() : void pre: true post: true activity: ( skip ); static operation printlnCase() : void pre: true post: true activity: ( skip ); static operation nextInt() : int pre: true post: true activity: ( return (next() + "")->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return parseLong(next()) ); static operation nextDouble() : double pre: true post: true activity: ( return parseDouble(next()) ); static operation next() : String pre: true post: true activity: ( while (tok = null or not(tok.hasNext())) do ( tok := OclIterator.newOclIterator_String(in.readLine()) ) ; return tok.next() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var tests : int ; tests := nextInt() ; test := 1 ; while test <= tests do ( ( execute solve() ) ; test := test + 1 ) ; skip ; skip ; ) catch (e : OclException) do ( e.printStackTrace() ; execute exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.FileNotFoundException ; import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; public class codejamp2 { public static char[] map ; public static void main(String[] args)throws IOException { readFile(); } public static String getResult(String input){ int resultInt=0 ; String[] splitResult=input.split(" "); int dancerCount=Integer.parseInt(splitResult[0]); int suprising=Integer.parseInt(splitResult[1]); int max=Integer.parseInt(splitResult[2]); for(int i=3 ; i0){ suprising--; resultInt++; } } if(currentmax>=max){ if(remain<=1){ resultInt++; } else if(remain==2){ if(max-ave<=1){ resultInt++; } else if(suprising>0){ suprising--; resultInt++; } } } } return ""+resultInt ; } public static void readFile()throws IOException { FileWriter fstream=new FileWriter("out.txt"); BufferedWriter out=new BufferedWriter(fstream); FileReader input=new FileReader("in.txt"); BufferedReader bufRead=new BufferedReader(input); String line=bufRead.readLine(); String current=getResult(line); int i=1 ; out.write("Case #"+i+": "+current); line=bufRead.readLine(); while(line!=null){ i++; System.out.println("Case #"+i+": "+getResult(line)); out.write('\n'+"Case #"+i+": "+getResult(line)); line=bufRead.readLine(); } bufRead.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class codejamp2 { static attribute map : Sequence(String); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute readFile() ); static operation getResult( input : String) : String pre: true post: true activity: ( var resultInt : int ; resultInt := 0 ; var splitResult : Sequence(String) ; splitResult := input->split(" ") ; var dancerCount : int ; dancerCount := (splitResult[0+1])->toInteger() ; var suprising : int ; suprising := (splitResult[1+1])->toInteger() ; var max : int ; max := (splitResult[2+1])->toInteger() ; var i : int ; i := 3 ; while i < dancerCount + 3 do ( ( var current : int ; current := (splitResult[i+1])->toInteger() ; var ave : int ; ave := current / 3 ; var remain : int ; remain := current - 3 * ave ; var currentmax : int ; currentmax := ave + remain ; if (remain = 0 & (max - currentmax = 1) & current /= 0) then ( if (suprising > 0) then ( suprising := suprising - 1 ; resultInt := resultInt + 1 ) else skip ) else skip ; if (currentmax >= max) then ( if (remain <= 1) then ( resultInt := resultInt + 1 ) else if (remain = 2) then ( if (max - ave <= 1) then ( resultInt := resultInt + 1 ) else if (suprising > 0) then ( suprising := suprising - 1 ; resultInt := resultInt + 1 ) else skip ; ) else skip ; ) else skip ; ) ; i := i + 1 ) ; return "" + resultInt ); static operation readFile() : void pre: true post: true activity: ( var fstream : OclFile ; fstream := OclFile.newOclFile_Write(OclFile.newOclFile("out.txt")) ; var out : OclFile ; out := OclFile.newOclFile_Write(fstream) ; var input : OclFile ; input := OclFile.newOclFile_Read(OclFile.newOclFile("in.txt")) ; var bufRead : OclFile ; bufRead := OclFile.newOclFile_Read(input) ; var line : String ; line := bufRead.readLine() ; var current : String ; current := getResult(line) ; var i : int ; i := 1 ; skip ; line := bufRead.readLine() ; while (line /= null) do ( i := i + 1 ; OclFile["System.out"].println("Case #" + i + ": " + getResult(line)) ; skip ; line := bufRead.readLine() ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class IsDivisible { static boolean check(String str){ int n=str.length(); int oddDigSum=0,evenDigSum=0 ; for(int i=0 ; isize() ; var oddDigSum : int ; oddDigSum := 0 ; var evenDigSum : int ; evenDigSum := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (i mod 2 = 0) then oddDigSum := oddDigSum+((str->at(i+1) - ('0')->char2byte())) ; else evenDigSum := evenDigSum+((str->at(i+1) - ('0')->char2byte())) ; ) ; i := i + 1 ) ; return ((oddDigSum - evenDigSum) mod 11 = 0) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "76945" ; if (check(str)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; class Main { public static void main(String args[]){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String line ; while((line=br.readLine())!=null){ if(line.isEmpty())break ; String[] spl=line.split(" "); int a=Integer.parseInt(spl[0]); int b=Integer.parseInt(spl[1]); int n=Integer.parseInt(spl[2]); double d=a/(b+0.0); int s=0 ; for(int i=0 ; iisEmpty()) then break else skip ; var spl : Sequence(String) ; spl := line->split(" ") ; var a : int ; a := (spl[0+1])->toInteger() ; var b : int ; b := (spl[1+1])->toInteger() ; var n : int ; n := (spl[2+1])->toInteger() ; var d : double ; d := a / (b + 0.0) ; var s : int ; s := 0 ; var i : int ; i := 0 ; while i < n do ( ( a := a*(10) ; s := s+((a / b) mod 10) ; a := a mod b ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; ) ; line := br.readLine() ; ) ; skip ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class A45 { public static void main(String[] args)throws IOException { BufferedReader inp=new BufferedReader(new InputStreamReader(System.in)); int size=Integer.parseInt(inp.readLine()); String[] s1=inp.readLine().split(" "); long[] given=new long[size]; long totalSum=0 ; for(int i=0 ; itoInteger() ; var s1 : Sequence(String) ; s1 := inp.readLine()->split(" ") ; var given : Sequence(long) ; given := Integer.subrange(1,size)->collect(0) ; var totalSum : long ; totalSum := 0 ; var i : int ; i := 0 ; while i < size do ( ( given[i+1] := (s1[i+1])->toInteger() ; totalSum := totalSum+(given[i+1]) ) ; i := i + 1 ) ; var each : long ; each := totalSum / size ; var diff : Sequence(long) ; diff := Integer.subrange(1,size)->collect(0) ; var i : int ; i := 0 ; while i < size do ( ( diff[i+1] := given[i+1] - each ) ; i := i + 1 ) ; var sum : long ; sum := if diff[0+1] < 0 then -(diff[0+1]) else diff[0+1] endif ; var carry : long ; carry := diff[0+1] ; var i : int ; i := 1 ; while i < size do ( ( sum := sum+(if diff[i+1] + carry < 0 then -(diff[i+1] + carry) else diff[i+1] + carry endif) ; carry := carry + diff[i+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Matches { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(in.readLine()); String[] temp=in.readLine().split(" "); long c=0 ; long[] pp=new long[n]; for(int i=0 ; i0){ pp[i]-=u ; pp[i+1]+=u ; y+=u ; } else if(u<0){ pp[i+1]=pp[i+1]-(h-pp[i]); y+=(h-pp[i]); pp[i]=h ; } } System.out.println(y); } } ------------------------------------------------------------ OCL File: --------- class Matches { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (in.readLine())->toInteger() ; var temp : Sequence(String) ; temp := in.readLine()->split(" ") ; var c : long ; c := 0 ; var pp : Sequence(long) ; pp := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var u : int ; u := (temp[i+1])->toInteger() ; c := c+(u) ; pp[i+1] := u ) ; i := i + 1 ) ; var h : long ; h := c / n ; var y : long ; y := 0 ; var i : int ; i := 0 ; while i < pp->size() - 1 do ( ( var u : long ; u := pp[i+1] - h ; if (u > 0) then ( pp[i+1] := pp[i+1]-(u) ; pp[i + 1+1] := pp[i + 1+1]+(u) ; y := y+(u) ) else if (u < 0) then ( pp[i + 1+1] := pp[i + 1+1] - (h - pp[i+1]) ; y := y+((h - pp[i+1])) ; pp[i+1] := h ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(y) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class TheNumberOfProducts { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); int[] a=new int[n]; for(int i=0 ; i0)positiveEnd++; else { long temp=positiveEnd ; positiveEnd=negativeEnd ; negativeEnd=temp ; negativeEnd++; } posTot+=positiveEnd ; negTot+=negativeEnd ; } return negTot+" "+posTot ; } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class TheNumberOfProducts { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; skip ; skip ; ); static operation solve( a : Sequence(int), n : int) : String pre: true post: true activity: ( var positiveEnd : long ; positiveEnd := 0 ; var negativeEnd : long ; negativeEnd := 0 ; var posTot : long ; posTot := 0 ; var negTot : long ; negTot := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] > 0) then positiveEnd := positiveEnd + 1 else ( var temp : long ; temp := positiveEnd ; positiveEnd := negativeEnd ; negativeEnd := temp ; negativeEnd := negativeEnd + 1 ) ; posTot := posTot+(positiveEnd) ; negTot := negTot+(negativeEnd) ) ; i := i + 1 ) ; return negTot + " " + posTot ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static int n ; static int a[]; static void solve(){ Mapmap=new HashMap<>(); int prod=1 ; long pos=0,neg=0 ; for(int i=0 ; i0)pos++; else neg++; if(prod<0){ pos+=map.getOrDefault(-1,0); neg+=map.getOrDefault(1,0); } else { pos+=map.getOrDefault(1,0); neg+=map.getOrDefault(-1,0); } map.put(prod,map.getOrDefault(prod,0)+1); } str.append(neg+" "+pos); } public static void main(String[] args)throws java.lang.Exception { BufferedReader bf ; PrintWriter pw ; boolean lenv=false ; if(lenv){ bf=new BufferedReader(new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); } else { bf=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out)); } n=Integer.parseInt(bf.readLine().trim()); a=new int[n]; String s[]=bf.readLine().trim().split("\\s+"); for(int i=0 ; i0 ? 1 :-1 ; solve(); pw.println(str); pw.flush(); } } ------------------------------------------------------------ OCL File: --------- class Coder { static attribute str : String := StringLib.newString(); static attribute n : int; static attribute a : Sequence(int); static operation solve() : void pre: true post: true activity: ( var map : Map(int,int) ; map := Map{} ; var prod : int ; prod := 1 ; var pos : long ; pos := 0 ; var neg : long ; neg := 0 ; var i : int ; i := 0 ; while i < n do ( ( prod := prod*(a[i+1]) ; if (prod > 0) then pos := pos + 1 else neg := neg + 1 ; ; if (prod < 0) then ( pos := pos+((if map->keys()->contains(-1) then map->at(-1) else 0 endif)) ; neg := neg+((if map->keys()->contains(1) then map->at(1) else 0 endif)) ) else ( pos := pos+((if map->keys()->contains(1) then map->at(1) else 0 endif)) ; neg := neg+((if map->keys()->contains(-1) then map->at(-1) else 0 endif)) ) ; map := map->union(Map{prod |-> (if map->keys()->contains(prod) then map->at(prod) else 0 endif) + 1}) ) ; i := i + 1 ) ; str := str + StringLib.newString(neg + " " + pos) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; var pw : OclFile ; var lenv : boolean ; lenv := false ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; n := (bf.readLine()->trim())->toInteger() ; a := Integer.subrange(1,n)->collect(0) ; var s : Sequence(String) ; s := bf.readLine()->trim()->split("\\s+") ; var i : int ; i := 0 ; while i < n do ( a[i+1] := if (s[i+1])->toInteger() > 0 then 1 else -1 endif ; ; i := i + 1 ) ; execute solve() ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static int n ; static int a[]; static void solve(){ long pos=1,neg=0 ; long val=1 ; for(int i=0 ; itrim())->toInteger() ; a := Integer.subrange(1,n)->collect(0) ; var s : Sequence(String) ; s := bf.readLine()->trim()->split("\\s+") ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (s[i+1])->toInteger() ; ; i := i + 1 ) ; execute solve() ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class TheNumberOfProducts { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); String[] temp=br.readLine().split(" "); int[] nums=new int[n]; for(int i=0 ; itoInteger() ; var temp : Sequence(String) ; temp := br.readLine()->split(" ") ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := (temp[i+1])->toInteger() ) ; i := i + 1 ) ; var preCount : Sequence(int) ; preCount := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( preCount[i + 1+1] := preCount[i+1] + (if nums[i+1] < 0 then 1 else 0 endif) ) ; i := i + 1 ) ; var countPositive : long ; countPositive := 0 ; var countNegative : long ; countNegative := 0 ; var countEven : int ; countEven := 1 ; var countOdd : int ; countOdd := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (preCount[i+1] mod 2 = 0) then ( countNegative := countNegative+(countOdd) ; countPositive := countPositive+(countEven) ; countEven := countEven + 1 ) else ( countNegative := countNegative+(countEven) ; countPositive := countPositive+(countOdd) ; countOdd := countOdd + 1 ) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { static boolean canBeSumofConsec(int n){ return(((n &(n-1))!=0)&& n!=0); } public static void main(String[] args){ int n=15 ; System.out.println(canBeSumofConsec(n)? "true" : "false"); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation canBeSumofConsec( n : int) : boolean pre: true post: true activity: ( return (((n & (n - 1)) /= 0) & n /= 0) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 15 ; OclFile["System.out"].println(if canBeSumofConsec(n) then "true" else "false" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; while((line=br.readLine())!=null && ! line.isEmpty()){ int n=parseInt(line); if(n==0)break ; Map>groups=new HashMap<>(); String first="" ; for(int i=0 ; i()); for(int j=1 ; jisEmpty())) do ( skip ; ( var n : int ; n := parseInt(line) ; if (n = 0) then break else skip ; var groups : Map(String,Set(String)) ; groups := Map{} ; var first : String ; first := "" ; var i : int ; i := 0 ; while i < n do ( ( words := br.readLine().replaceAllMatches("\\.", "" )->split("[:,] ") ; groups := groups->union(Map{words[0+1] |-> Set{}}) ; var j : int ; j := 1 ; while j < words->size() do ( ( groups->at(words[0+1])->excludes(words[j+1]) ) ; j := j + 1 ) ; if (i = 0) then first := words[0+1] ; else skip ) ; i := i + 1 ) ; var changed : boolean ; while true do (( changed := false ; for (group : groups->keys()) do ( ( if (not(group = first) & groups->at(first)->includes(group)) then ( groups := groups->at(first)->excludingFirst(group) ; for (member : groups->at(group)) do ( ( groups->at(first)->excludes(member) ) ) ; changed := true ) else skip ) ) ) ; if (changed) then skip else break) ; OclFile["System.out"].println(groups->at(first)->size()) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class a { public static void main(String[] args){ Scanner input=new Scanner(System.in); int T=input.nextInt(); for(int t=0 ; tmax)return false ; sum+=data[i]; if(sum>max){ count++; sum=data[i]; if(count>3)return false ; } } return count<=3 ; } } ------------------------------------------------------------ OCL File: --------- class a { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := input.getCurrent()->toInteger() ; var t : int ; t := 0 ; while t < T do ( ( OclFile["System.out"].printf("Case #%d: ", t + 1) ; var n : int ; n := input.getCurrent()->toInteger() ; var p : int ; p := input.getCurrent()->toInteger() ; var q : int ; q := input.getCurrent()->toInteger() ; var r : int ; r := input.getCurrent()->toInteger() ; var s : int ; s := input.getCurrent()->toInteger() ; var data : Sequence(int) ; data := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( data[i+1] := ((i->oclAsType(long) * p + q) mod r + s)->oclAsType(int) ) ; i := i + 1 ) ; var lo : long ; lo := 1 ; var hi : long ; hi := 1e13->oclAsType(long) ; while (lo < hi - 1) do ( var mid : long ; mid := (lo + hi) / 2 ; if (canDo(data, mid)) then hi := mid ; else lo := mid ; ) ; if (not(canDo(data, lo))) then lo := lo + 1 ; else skip ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( sum := sum+(data[i+1]) ; ; i := i + 1 ) ; var res : double ; res := 1. * lo / sum ; OclFile["System.out"].printf("%.9f\n", 1 - res) ; ) ; t := t + 1 ) ); static operation canDo( data : Sequence(int), max : long) : boolean pre: true post: true activity: ( var count : long ; count := 1 ; var sum : long ; sum := 0 ; var n : int ; n := data->size() ; var i : int ; i := 0 ; while i < n do ( ( if (data[i+1] > max) then return false else skip ; sum := sum+(data[i+1]) ; if (sum > max) then ( count := count + 1 ; sum := data[i+1] ; if (count > 3) then return false else skip ) else skip ) ; i := i + 1 ) ; return count <= 3 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class TokitsukazeAndMahjong { public static void main(String[] args){ Scanner in=new Scanner(System.in); int a[]=new int[3]; for(int i=0 ; i<3 ; i++){ String s=in.next(); a[i]=(s.charAt(0)-'0')+(s.charAt(1)-'a')*10 ; } Arrays.sort(a); int t1=a[1]-a[0],t2=a[2]-a[1]; if((t2==1 && t1==1)||(t2==0 && t1==0))System.out.println(0); else if(t1<=2 || t2<=2)System.out.println(1); else System.out.println(2); } } ------------------------------------------------------------ OCL File: --------- class TokitsukazeAndMahjong { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : Sequence(int) ; a := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < 3 do ( ( var s : String ; s := in.getCurrent() ; a[i+1] := (s->at(0+1) - ('0')->char2byte()) + (s->at(1+1) - ('a')->char2byte()) * 10 ) ; i := i + 1 ) ; a := a->sort() ; var t1 : int ; t1 := a[1+1] - a[0+1] ; var t2 : int ; t2 := a[2+1] - a[1+1] ; if ((t2 = 1 & t1 = 1) or (t2 = 0 & t1 = 0)) then OclFile["System.out"].println(0) else if (t1 <= 2 or t2 <= 2) then OclFile["System.out"].println(1) else OclFile["System.out"].println(2) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.*; import java.util.*; class Main { static int[] parents ; static int[] weight ; static int[] rank ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int q=scanner.nextInt(); parents=new int[n]; weight=new int[n]; rank=new int[n]; for(int i=0 ; itoInteger() ; var q : int ; q := scanner.getCurrent()->toInteger() ; parents := Integer.subrange(1,n)->collect(0) ; weight := Integer.subrange(1,n)->collect(0) ; rank := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( parents[i+1] := i ) ; i := i + 1 ) ; var type : int ; var x : int ; var y : int ; var z : int ; var i : int ; i := 0 ; while i < q do ( ( type := scanner.getCurrent()->toInteger() ; x := scanner.getCurrent()->toInteger() ; y := scanner.getCurrent()->toInteger() ; if (type = 0) then ( z := scanner.getCurrent()->toInteger() ; execute relate(x, y, z) ) else ( execute diff(x, y) ) ) ; i := i + 1 ) ; ); static operation find( x : int) : int pre: true post: true activity: ( if (x = parents[x+1]) then return x else ( var r : int ; r := find(parents[x+1]) ; weight[x+1] := weight[x+1]+(weight[parents[x+1]+1]) ; return parents[x+1] ) ); static operation weight( x : int) : int pre: true post: true activity: ( execute find(x) ; return weight[x+1] ); static operation relate( x : int, y : int, z : int) : void pre: true post: true activity: ( z := z+(weight(x)) ; z := z-(weight(y)) ; x := find(x) ; y := find(y) ; if (x = y) then return else skip ; if (rank[x+1] < rank[y+1]) then ( var tmp : int ; tmp := x ; x := y ; y := tmp ; z := -z ) else skip ; if (rank[x+1] = rank[y+1]) then ( rank[x+1] := rank[x+1] + 1 ) else skip ; parents[y+1] := x ; weight[y+1] := z ; ); static operation diff( x : int, y : int) : void pre: true post: true activity: ( if (find(x) = find(y)) then ( OclFile["System.out"].println(weight(y) - weight(x)) ) else ( OclFile["System.out"].println("?") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true){ String str=br.readLine(); if(str==null){ break ; } String[] strArray=str.split(" "); int a=Integer.parseInt(strArray[0]); int b=Integer.parseInt(strArray[1]); int n=Integer.parseInt(strArray[2]); Decimal dc=new Decimal(a,b); System.out.println(dc.sumOfDecimal(n)); } } } class Decimal { private int numerator ; private int denominator ; private int[] dplace=new int[101]; public Decimal(int a,int b){ numerator=a ; denominator=b ; initDplace(); } private void initDplace(){ int a=numerator ; int b=denominator ; for(int i=1 ; isplit(" ") ; var a : int ; a := (strArray[0+1])->toInteger() ; var b : int ; b := (strArray[1+1])->toInteger() ; var n : int ; n := (strArray[2+1])->toInteger() ; var dc : Decimal ; dc := Decimal.newDecimal(a, b) ; OclFile["System.out"].println(dc.sumOfDecimal(n)) ; ) ); } class Decimal { attribute numerator : int; attribute denominator : int; attribute dplace : Sequence(int) := Integer.subrange(1,101)->collect(0); static operation newDecimal( a : int, b : int) : Decimal pre: true post: true activity: ( var self : Decimal ; self := createDecimal(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( numerator := a ; denominator := b ; execute initDplace() ); operation initDplace() : void pre: true post: true activity: ( var a : int ; a := numerator ; var b : int ; b := denominator ; var i : int ; i := 1 ; while i < dplace->size() do ( ( dplace[i+1] := (a * 10 / b) mod 10 ; a := a * 10 mod b ) ; i := i + 1 ) ); operation sumOfDecimal( n : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; var i : int ; i := 1 ; while i <= n do ( ( result := result+(dplace[i+1]) ) ; i := i + 1 ) ; return result ); operation print() : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < dplace->size() do ( ( OclFile["System.out"].print(dplace[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class B_Tokitsukaze_and_Mahjong { static Scanner in=new Scanner(System.in); public static void main(String[] amit){ int ans[]=new int[3]; for(int i=0 ; i<3 ; ++i){ String s=in.next(); ans[i]=Integer.parseInt(s.charAt(0)+"")+Integer.parseInt((s.charAt(1)-'a')+"")*10 ; } Arrays.sort(ans); int first=ans[1]-ans[0],second=ans[2]-ans[1]; int third=ans[2]-ans[0]; if(ans[0]==ans[1] && ans[1]==ans[2]){ System.out.print(0); return ; } if(first==second &&(second==1 || first==0)){ System.out.print(0); } else if(first<=2 || second<=2){ System.out.print(1); } else { System.out.print(2); } } } ------------------------------------------------------------ OCL File: --------- class B_Tokitsukaze_and_Mahjong { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( amit : Sequence(String)) : void pre: true post: true activity: ( var ans : Sequence(int) ; ans := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < 3 do ( ( var s : String ; s := in.getCurrent() ; ans[i+1] := (s->at(0+1) + "")->toInteger() + ((s->at(1+1) - ('a')->char2byte()) + "")->toInteger() * 10 ) ; i := i + 1 ) ; ans := ans->sort() ; var first : int ; first := ans[1+1] - ans[0+1] ; var second : int ; second := ans[2+1] - ans[1+1] ; var third : int ; third := ans[2+1] - ans[0+1] ; if (ans[0+1] = ans[1+1] & ans[1+1] = ans[2+1]) then ( OclFile["System.out"].print(0) ; return ) else skip ; if (first = second & (second = 1 or first = 0)) then ( OclFile["System.out"].print(0) ) else if (first <= 2 or second <= 2) then ( OclFile["System.out"].print(1) ) else ( OclFile["System.out"].print(2) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public void exec(){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); if(a>b){ System.out.println("a>b"); } else if(atoInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (a > b) then ( OclFile["System.out"].println("a>b") ) else if (a < b) then ( OclFile["System.out"].println("ab){ System.out.println("a>b"); } else if(a==b){ System.out.println("a==b"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : String ; str := br.readLine() ; var ab : Sequence(String) ; ab := str->split(" ") ; var a : int ; a := (ab[0+1])->toInteger() ; var b : int ; b := (ab[1+1])->toInteger() ; if (a < b) then ( OclFile["System.out"].println("a b) then ( OclFile["System.out"].println("a>b") ) else if (a = b) then ( OclFile["System.out"].println("a==b") ) else skip ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Main { public static void main(String[] args){ InputStreamReader sr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(sr); try { String[] str=br.readLine().split(" "); int a=Integer.parseInt(str[0]); int b=Integer.parseInt(str[1]); if(ab){ System.out.println("a>b"); } else if(a==b){ System.out.println("a==b"); } } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sr : OclFile ; sr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(sr) ; try ( var str : Sequence(String) ; str := br.readLine()->split(" ") ; var a : int ; a := (str[0+1])->toInteger() ; var b : int ; b := (str[1+1])->toInteger() ; if (a < b) then ( OclFile["System.out"].println("a b) then ( OclFile["System.out"].println("a>b") ) else if (a = b) then ( OclFile["System.out"].println("a==b") ) else skip ; ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] intArray=Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer :: parseInt).toArray(); int a=intArray[0]; int b=intArray[1]; if(a==b){ System.out.printf("a==b\n"); } else if(ab\n"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var intArray : Sequence(int) ; intArray := stream(sc.nextLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ; var a : int ; a := intArray[0+1] ; var b : int ; b := intArray[1+1] ; if (a = b) then ( OclFile["System.out"].printf("a==b\n") ) else if (a < b) then ( OclFile["System.out"].printf("ab\n") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { Scanner in=new Scanner(System.in); int x=in.nextInt(); int y=in.nextInt(); evaluation(x,y); in.close(); } public static void evaluation(int a,int b){ if(ab){ System.out.println("a>b"); } else { System.out.println("a==b"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; execute evaluation(x, y) ; skip ; ); static operation evaluation( a : int, b : int) : void pre: true post: true activity: ( if (a < b) then ( OclFile["System.out"].println("a b) then ( OclFile["System.out"].println("a>b") ) else ( OclFile["System.out"].println("a==b") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Stack ; class Main { public static void main(String[] args){ new Main().compute(); } void compute(){ Scanner sc=new Scanner(System.in); sc.useDelimiter("[\\s]+"); while(sc.hasNext()){ int a[]=new int[4]; for(int i=0 ; i<4 ; i++){ a[i]=sc.nextInt(); } int hit=0,blow=0 ; for(int i=0 ; i<4 ; i++){ int b=sc.nextInt(); for(int j=0 ; j<4 ; j++){ if(a[j]==b){ if(i==j){ hit++; } else { blow++; } continue ; } } } System.out.println(hit+" "+blow); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().compute() ); operation compute() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; skip ; while (sc.hasNext()) do ( var a : Sequence(int) ; a := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var hit : int ; hit := 0 ; var blow : int ; blow := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( var b : int ; b := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < 4 do ( ( if (a[j+1] = b) then ( if (i = j) then ( hit := hit + 1 ) else ( blow := blow + 1 ) ; continue ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(hit + " " + blow) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintStream ; class Main { public static void main(String[] args)throws IOException { doit(args,System.in,System.out); } static void doit(String[] args,InputStream in,PrintStream out)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(in)); String line=null ; while((line=reader.readLine())!=null && ! line.isEmpty()){ String[] values=line.split(" "); int[] orders=new int[10]; for(int i=0 ; i<4 ; i++){ orders[Integer.parseInt(values[i])]=i+1 ; } values=reader.readLine().split(" "); int hit=0 ; int blow=0 ; for(int i=0 ; i<4 ; i++){ int order=orders[Integer.parseInt(values[i])]; if(order==i+1){ hit++; } else if(order!=0){ blow++; } } out.println(hit+" "+blow); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute doit(args, OclFile["System.in"], OclFile["System.out"]) ); static operation doit( args : Sequence(String), in : OclFile, out : OclFile) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; var line : String ; line := null ; line := reader.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var values : Sequence(String) ; values := line->split(" ") ; var orders : Sequence(int) ; orders := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( ( orders[(values[i+1])->toInteger()+1] := i + 1 ) ; i := i + 1 ) ; values := reader.readLine()->split(" ") ; var hit : int ; hit := 0 ; var blow : int ; blow := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( var order : int ; order := orders[(values[i+1])->toInteger()+1] ; if (order = i + 1) then ( hit := hit + 1 ) else if (order /= 0) then ( blow := blow + 1 ) else skip ; ) ; i := i + 1 ) ; out.println(hit + " " + blow) ; ) ; line := reader.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; import java.util.ArrayList ; public class Main { Scanner sc ; public void run(){ sc=new Scanner(System.in); while(sc.hasNextInt()){ int n=sc.nextInt(); if(n!=0){ calc(n); } else { break ; } } } public void calc(int n){ HashMapgroups=new HashMap(); HashMapmembers=new HashMap(); int count=0 ; String first="" ; for(int i=0 ; ilist=new ArrayList(); list.add(first); while(list.size()!=0){ String group=list.get(0); list.remove(0); String[] member=groups.get(group); for(int i=0 ; itoInteger() ; if (n /= 0) then ( execute calc(n) ) else ( break ) ) ); operation calc( n : int) : void pre: true post: true activity: ( var groups : Map(String,Sequence(String)) ; groups := Map{} ; var members : Map(String,int) ; members := Map{} ; var count : int ; count := 0 ; var first : String ; first := "" ; var i : int ; i := 0 ; while i < n do ( ( var line : String ; line := sc.getCurrent() ; var lines : String ; lines := line.subrange(0+1,line->size() - 1) ; var g : Sequence(String) ; g := lines->split(":") ; var group : String ; group := g[0+1] ; var member : Sequence(String) ; member := g[1+1]->split(",") ; if (i = 0) then first := group ; else skip ; groups := groups->union(Map{group |-> member}) ; ) ; i := i + 1 ) ; var list : Sequence(String) ; list := Sequence{} ; list := list->including(first) ; while (list->size() /= 0) do ( var group : String ; group := list->at(0+1) ; list := list->excludingAt(0+1) ; var member : Sequence(String) ; member := groups->at(group) ; var i : int ; i := 0 ; while i < member->size() do ( ( var m : String ; m := member[i+1] ; if (groups->keys()->includes(m)) then ( list := list->including(m) ) else if (not(members->keys()->includes(m))) then ( members := members->union(Map{m |-> 1}) ; count := count + 1 ) else skip ; ) ; i := i + 1 ) ; groups := groups->union(Map{group |-> Sequence{}}) ; ) ; OclFile["System.out"].println(count) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc ; static final int INF=1<<28 ; static final double EPS=1e-9 ; void run(){ sc=new Scanner(System.in); for(; sc.hasNext(); ){ LinkedLista=new LinkedList(); LinkedListb=new LinkedList(); for(int i=0 ; i<4 ; i++)a.add(sc.nextInt()); for(int i=0 ; i<4 ; i++)b.add(sc.nextInt()); int hit=0,brow=0 ; for(int i=0 ; i<4 ; i++){ if(a.get(i)==b.get(i))hit++; else if(a.contains(b.get(i)))brow++; } println(hit+" "+brow); } sc.close(); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static attribute INF : int := (1*(2->pow(28)))->oclAsType(long); static attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while sc.hasNext() do ( ( var a : Sequence(int) ; a := Sequence{} ; var b : Sequence(int) ; b := Sequence{} ; var i : int ; i := 0 ; while i < 4 do ( a := a->including(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 4 do ( b := b->including(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; var hit : int ; hit := 0 ; var brow : int ; brow := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( if (a->at(i+1) = b->at(i+1)) then hit := hit + 1 ; else if (a->includes(b->at(i+1))) then brow := brow + 1 ; else skip ; ) ; i := i + 1 ) ; execute println(hit + " " + brow) ; ) ) ; skip ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; i1){ mid=(l+r)/2 ; dec=new int[m]; Arrays.fill(dec,1); nout : for(int i=1 ; i0){ dec[pos-1]++; for(int j=pos ; jtoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; var nodec : boolean ; nodec := true ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] <= a[i - 1+1]) then nodec := false ; else skip ) ; i := i + 1 ) ; if (nodec) then ( OclFile["System.out"].println(1) ; return ) else skip ; var m : int ; m := 500 ; var l : int ; l := 1 ; var r : int ; r := 210000 ; var mid : int ; mid := 2 ; var dec : Sequence(int) ; dec := Integer.subrange(1,m)->collect(0) ; while (r - l > 1) do ( mid := (l + r) / 2 ; dec := Integer.subrange(1,m)->collect(0) ; dec := dec->collect(1) ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] <= a[i - 1+1] & a[i+1] - 1 < m) then ( if (dec[a[i+1] - 1+1] < mid) then ( dec[a[i+1] - 1+1] := dec[a[i+1] - 1+1] + 1 ) else ( var pos : int ; pos := a[i+1] - 1 ; while (pos > 0) do ( dec[pos - 1+1] := dec[pos - 1+1] + 1 ; var j : int ; j := pos ; while j < m do ( ( dec[j+1] := 1 ) ; j := j + 1 ) ; if (dec[pos - 1+1] <= mid) then continue else skip ; pos := pos - 1 ) ; l := mid ; continue ) ) else ( var j : int ; j := a[i+1] - 1 ; while j < m do ( ( dec[j+1] := 1 ) ; j := j + 1 ) ) ) ; i := i + 1 ) ; r := mid ; ) ; OclFile["System.out"].println(r) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; class Main { public static void main(String args[]){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String s[]=new String[2]; while((s[0]=br.readLine())!=null){ s[1]=br.readLine(); StringTokenizer st[]=new StringTokenizer[2]; st[0]=new StringTokenizer(s[0]); st[1]=new StringTokenizer(s[1]); int a[]=new int[4]; int b[]=new int[4]; for(int i=0 ; i<4 ; i++){ a[i]=Integer.parseInt(st[0] .nextToken()); b[i]=Integer.parseInt(st[1] .nextToken()); } int hit=0 ; int blow=0 ; for(int i=0 ; i<4 ; i++){ for(int j=0 ; j<4 ; j++){ if(a[i]==b[j]){ if(i==j)hit++; else blow++; } } } System.out.println(hit+" "+blow); } } catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var s : Sequence(String) ; s := Integer.subrange(1,2)->collect(null) ; s[0+1] := br.readLine() ; while ((s[0+1]) /= null) do ( skip ; ( s[1+1] := br.readLine() ; var st : Sequence(OclIterator) ; st := Integer.subrange(1,2)->collect(null) ; st[0+1] := OclIterator.newOclIterator_String(s[0+1]) ; st[1+1] := OclIterator.newOclIterator_String(s[1+1]) ; var a : Sequence(int) ; a := Integer.subrange(1,4)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( ( a[i+1] := (st[0+1].next())->toInteger() ; b[i+1] := (st[1+1].next())->toInteger() ) ; i := i + 1 ) ; var hit : int ; hit := 0 ; var blow : int ; blow := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( var j : int ; j := 0 ; while j < 4 do ( ( if (a[i+1] = b[j+1]) then ( if (i = j) then hit := hit + 1 ; else blow := blow + 1 ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(hit + " " + blow) ; ) ; s[0+1] := br.readLine() ; ) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static final int HIT=0 ; public static final int BLOW=1 ; public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); ArrayListoutList=new ArrayList<>(); while(sc.hasNextLine()){ int[] answer=getNumberArray(sc.nextLine().split(" ")); int[] expected=getNumberArray(sc.nextLine().split(" ")); int[] hitAndBlow=getHitAndBlow(answer,expected); outList.add(hitAndBlow); } for(int[] hitAndBlow : outList){ System.out.println(hitAndBlow[HIT]+" "+hitAndBlow[BLOW]); } sc.close(); } public static int[] getNumberArray(String[] input){ int[] numbers=new int[10]; Arrays.fill(numbers,0); for(int i=0 ; isplit(" ")) ; var expected : Sequence(int) ; expected := getNumberArray(sc.nextLine()->split(" ")) ; var hitAndBlow : Sequence(int) ; hitAndBlow := getHitAndBlow(answer, expected) ; outList := outList->including(hitAndBlow) ) ; for (hitAndBlow : outList) do ( ( OclFile["System.out"].println(hitAndBlow[HIT+1] + " " + hitAndBlow[BLOW+1]) ) ) ; skip ; ); static operation getNumberArray( input : Sequence(String)) : Sequence(int) pre: true post: true activity: ( var numbers : Sequence(int) ; numbers := Integer.subrange(1,10)->collect(0) ; numbers := numbers->collect(0) ; var i : int ; i := 0 ; while i < input->size() do ( ( var num : int ; num := (input[i+1])->toInteger() ; var j : int ; j := 0 ; while j < 10 do ( ( if (num = j) then ( numbers[j+1] := i + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return numbers ); static operation getHitAndBlow( answer : Sequence(int), expected : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var hitAndBlow : Sequence(int) ; hitAndBlow := Integer.subrange(1,2)->collect(0) ; var i : int ; i := 0 ; while i < 10 do ( ( if (answer[i+1] = 0) then ( continue ) else skip ; if (answer[i+1] = expected[i+1]) then ( hitAndBlow[HIT+1] := hitAndBlow[HIT+1] + 1 ; continue ) else skip ; if (answer[i+1] /= 0 & expected[i+1] /= 0) then ( hitAndBlow[BLOW+1] := hitAndBlow[BLOW+1] + 1 ; continue ) else skip ) ; i := i + 1 ) ; return hitAndBlow ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=Integer.parseInt(scan.nextLine()); String str=scan.nextLine(); String ans=check(n,str); System.out.println(ans); } public static String check(int n,String str){ int[][] forward={ { 1,0,0,0 },{ 0,1,1,0 },{ 0,1,1,1 },{ 0,0,1,1 },{ 1,1,1,0 },{ 1,1,1,1 },{ 1,0,1,1 },{ 1,1,0,0 },{ 1,1,1,1 },{ 1,0,0,1 } }; char[] s=str.toCharArray(); for(int i=0 ; i<4 ; i++){ boolean flag=false ; for(char c : s){ int idx=c-'0' ; if(forward[idx][i]==0){ flag=true ; } } if(! flag){ return "NO" ; } } return "YES" ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (scan.nextLine())->toInteger() ; var str : String ; str := scan.nextLine() ; var ans : String ; ans := check(n, str) ; OclFile["System.out"].println(ans) ; ); static operation check( n : int, str : String) : String pre: true post: true activity: ( var forward : Sequence(Sequence(int)) ; forward := Sequence{Sequence{1,0,0,0},Sequence{0,1,1,0},Sequence{0,1,1,1},Sequence{0,0,1,1},Sequence{1,1,1,0},Sequence{1,1,1,1},Sequence{1,0,1,1},Sequence{1,1,0,0},Sequence{1,1,1,1},Sequence{1,0,0,1}} ; var s : Sequence(String) ; s := str->characters() ; var i : int ; i := 0 ; while i < 4 do ( ( var flag : boolean ; flag := false ; for (c : s) do ( ( var idx : int ; idx := c - ('0')->char2byte() ; if (forward[idx+1][i+1] = 0) then ( flag := true ) else skip ) ) ; if (not(flag)) then ( return "NO" ) else skip ) ; i := i + 1 ) ; return "YES" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class A_Mike_and_Cellphone { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out=new PrintWriter(System.out); static final int[][] MOVES={ { 1,0,0,0 },{ 0,1,1,0 },{ 0,1,1,1 },{ 0,0,1,1 },{ 1,1,1,0 },{ 1,1,1,1 },{ 1,0,1,1 },{ 1,1,0,0 },{ 1,1,1,1 },{ 1,0,0,1 } }; public static void main(String[] args)throws IOException { boolean unique=true ; in.readLine(); char[] n=in.readLine().toCharArray(); for(int i=0 ; i<4 ; i++){ boolean aux=false ; for(char c : n){ if(MOVES[Character.getNumericValue(c)][i]==0){ aux=true ; } } if(! aux){ unique=false ; } } out.println(unique ? "YES" : "NO"); out.close(); } } ------------------------------------------------------------ OCL File: --------- class A_Mike_and_Cellphone { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static attribute MOVES : Sequence(Sequence(int)) := Sequence{Sequence{1,0,0,0},Sequence{0,1,1,0},Sequence{0,1,1,1},Sequence{0,0,1,1},Sequence{1,1,1,0},Sequence{1,1,1,1},Sequence{1,0,1,1},Sequence{1,1,0,0},Sequence{1,1,1,1},Sequence{1,0,0,1}}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var unique : boolean ; unique := true ; skip ; var n : Sequence(String) ; n := in.readLine()->characters() ; var i : int ; i := 0 ; while i < 4 do ( ( var aux : boolean ; aux := false ; for (c : n) do ( ( if (MOVES[("" + c)->toInteger()+1][i+1] = 0) then ( aux := true ) else skip ) ) ; if (not(aux)) then ( unique := false ) else skip ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.util.Arrays ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class A689 { public static void main(String[] args){ Point[] P=new Point[10]; P[0]=new Point(1,3); for(int r=0 ; r<3 ; r++){ for(int c=0 ; c<3 ; c++){ P[3*r+c+1]=new Point(c,r); } } Setall=new HashSet<>(); all.addAll(Arrays.asList(P)); Scanner in=new Scanner(System.in); in.nextInt(); char[] S=in.next().toCharArray(); Setset=new HashSet<>(); for(char c : S){ set.add(P[c-'0']); } boolean unique=true ; outer : for(int dx=-2 ; dx<=2 ; dx++){ for(int dy=-3 ; dy<=3 ; dy++){ if(dx!=0 || dy!=0){ boolean valid=true ; for(Point p : set){ if(! all.contains(new Point(p.x+dx,p.y+dy))){ valid=false ; break ; } } if(valid){ unique=false ; break outer ; } } } } System.out.println(unique ? "YES" : "NO"); } } ------------------------------------------------------------ OCL File: --------- class A689 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var P : Sequence(Point) ; P := Integer.subrange(1,10)->collect(null) ; P[0+1] := Point.newPoint(1, 3) ; var r : int ; r := 0 ; while r < 3 do ( ( var c : int ; c := 0 ; while c < 3 do ( ( P[3 * r + c + 1+1] := Point.newPoint(c, r) ) ; c := c + 1 ) ) ; r := r + 1 ) ; var all : Set(Point) ; all := Set{} ; all := all->union(P) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; skip ; var S : Sequence(String) ; S := in.getCurrent()->characters() ; var set : Set(Point) ; set := Set{} ; for (c : S) do ( ( set := set->including(P[c - ('0')->char2byte()+1]) ) ) ; var unique : boolean ; unique := true ; var dx : int ; dx := -2 ; while dx <= 2 do ( ( var dy : int ; dy := -3 ; while dy <= 3 do ( ( if (dx /= 0 or dy /= 0) then ( var valid : boolean ; valid := true ; for (p : set) do ( ( if (not(all->includes(Point.newPoint(p.x + dx, p.y + dy)))) then ( valid := false ; break ) else skip ) ) ; if (valid) then ( unique := false ; break ) else skip ) else skip ) ; dy := dy + 1 ) ) ; dx := dx + 1 ) ; OclFile["System.out"].println(if unique then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int calculateSum(int n){ return(n*((int)Math.pow(n,2)+3*n+5))/3 ; } public static void main(String arr[]){ int n=25 ; System.out.println(calculateSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation calculateSum( n : int) : int pre: true post: true activity: ( return (n * (n->pow(2)->oclAsType(int) + 3 * n + 5)) / 3 ); static operation main( arr : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 25 ; OclFile["System.out"].println(calculateSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static int calculateSum(int n){ return n*(int)(Math.pow(n,2)+3*n+5)/3 ; } public static void main(String arr[]){ int n=3 ; System.out.println("Sum="+calculateSum(n)); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation calculateSum( n : int) : int pre: true post: true activity: ( return n * (n->pow(2) + 3 * n + 5)->oclAsType(int) / 3 ); static operation main( arr : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println("Sum=" + calculateSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static int calculateSum(int n){ return((int)Math.pow(10,n+1)*(9*n-1)+10)/(int)Math.pow(9,3)-n*(n+1)/18 ; } public static void main(String ar[]){ int n=3 ; System.out.println("Sum="+calculateSum(n)); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation calculateSum( n : int) : int pre: true post: true activity: ( return (10->pow(n + 1)->oclAsType(int) * (9 * n - 1) + 10) / 9->pow(3)->oclAsType(int) - n * (n + 1) / 18 ); static operation main( ar : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println("Sum=" + calculateSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int log_a_to_base_b(int a,int b){ return(int)(Math.log(a)/Math.log(b)); } public static void main(String[] args){ int a=3 ; int b=2 ; System.out.println(log_a_to_base_b(a,b)); a=256 ; b=4 ; System.out.println(log_a_to_base_b(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation log_a_to_base_b( a : int, b : int) : int pre: true post: true activity: ( return ((a)->log() / (b)->log())->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 3 ; var b : int ; b := 2 ; OclFile["System.out"].println(log_a_to_base_b(a, b)) ; a := 256 ; b := 4 ; OclFile["System.out"].println(log_a_to_base_b(a, b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(); int k=stdIn.nextInt(); String s=stdIn.next(); s=s.substring(0,k-1)+(s.substring(k-1,k)).toLowerCase()+s.substring(k,n); System.out.println(s); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := stdIn.getCurrent()->toInteger() ; var k : int ; k := stdIn.getCurrent()->toInteger() ; var s : String ; s := stdIn.getCurrent() ; s := s.subrange(0+1,k - 1) + (s.subrange(k - 1+1,k))->toLowerCase() + s.subrange(k+1,n) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; import java.util.Arrays ; import java.util.TreeMap ; public class Main { private int n ; private int[] a ; private TreeMaps ; public static void main(String[] args){ Main m=new Main(); m.solve(); } private void set(){ try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ n=Integer.parseInt(br.readLine()); a=Arrays.stream(br.readLine().split(" ")).mapToInt(Integer :: parseInt).toArray(); s=new TreeMap<>(); } catch(IOException e){ e.printStackTrace(); } } private void solve(){ set(); int ng=0 ; int ok=n ; while(ok-ng>1){ int k=(ng+ok)/2 ; if(isPossible(k)){ ok=k ; } else { ng=k ; } } System.out.println(ok); } private boolean isPossible(int k){ s.clear(); int current=0 ; for(int ai : a){ if(ai<=current){ if(k==1)return false ; while(! s.isEmpty()&& s.lastKey()>=ai)s.pollLastEntry(); int p=ai-1 ; while(true){ if(p<0)return false ; int sp=s.getOrDefault(p,0)+1 ; s.put(p,sp); if(sp==k){ s.remove(p); p--; } else { break ; } } } current=ai ; } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { attribute n : int; attribute a : Sequence(int); attribute s : Map(int,int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.solve() ); operation set() : void pre: true post: true activity: ( try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( n := (br.readLine())->toInteger() ; a := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ; s := Map{} )) catch (e : IOException) do ( e.printStackTrace() ) ); operation solve() : void pre: true post: true activity: ( execute set() ; var ng : int ; ng := 0 ; var ok : int ; ok := n ; while (ok - ng > 1) do ( var k : int ; k := (ng + ok) / 2 ; if (isPossible(k)) then ( ok := k ) else ( ng := k ) ) ; OclFile["System.out"].println(ok) ; ); operation isPossible( k : int) : boolean pre: true post: true activity: ( s := s->intersection(Map{}) ; var current : int ; current := 0 ; for (ai : a) do ( ( if (ai <= current) then ( if (k = 1) then return false else skip ; while (not(s->isEmpty()) & s->keys()->max() >= ai) do s := s.pollLastEntry() ; ; var p : int ; p := ai - 1 ; while (true) do ( if (p < 0) then return false else skip ; var sp : int ; sp := (if s->keys()->contains(p) then s->at(p) else 0 endif) + 1 ; s := s->union(Map{p |-> sp}) ; if (sp = k) then ( s := s->antirestrict(Set{p}) ; p := p - 1 ) else ( break ) ) ) else skip ; current := ai ) ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Math.*; public class Main { int INF=1<<28 ; double EPS=1e-10 ; V[] G ; boolean[] used ; void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int n=sc.nextInt(); if(n==0)break ; G=new V[n*20]; for(int i=0 ; imap=new HashMap(); int ind=0 ; for(int i=0 ; i{ } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute EPS : double := 1e-10; attribute G : Sequence(V); attribute used : Sequence(boolean); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; G := Integer.subrange(1,n * 20)->collect(null) ; var i : int ; i := 0 ; while i < n * 20 do ( G[i+1] := V.newV() ; ; i := i + 1 ) ; var map : Map(String,int) ; map := Map{} ; var ind : int ; ind := 0 ; var i : int ; i := 0 ; while i < n do ( ( var sp : Sequence(String) ; sp := sc.getCurrent()->split("[:,.] ") ; if (not(map->keys()->includes(sp[0+1]))) then map := map->union(Map{sp[0+1] |-> ind}) ; else skip ; var f : int ; f := map->at(sp[0+1]) ; var j : int ; j := 1 ; while j < sp->size() do ( ( if (not(map->keys()->includes(sp[j+1]))) then map := map->union(Map{sp[j+1] |-> ind}) ; else skip ; var t : int ; t := map->at(sp[j+1]) ; G[f+1]->excludes(t) ) ; j := j + 1 ) ) ; i := i + 1 ) ; used := Integer.subrange(1,n * 20)->collect(false) ; cnt := 0 ; execute dfs(0) ; OclFile["System.out"].println(cnt) ; ) ) ); attribute cnt : int; operation dfs( p : int) : void pre: true post: true activity: ( used[p+1] := true ; if (G[p+1]->size() = 0) then cnt := cnt + 1 ; else skip ; for (i : G[p+1]) do ( if (not(used[i+1])) then execute dfs(i) ; else skip ; ) ); class V extends Sequence(int) { } operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); long K=scanner.nextLong(); long n=1 ; double s=1.d ; for(long i=1 ; i<=K ; i++){ long x=n ; long z=0 ; long y=1 ; while(x>0){ x/=10 ; z=z*10+9 ; y*=10 ; long t=x*y+z ; double ts=sunuke(t); if(ts0){ sum+=i % 10 ; i/=10 ; } return sum ; } private static long numDigits(long i){ long d=0 ; while(i>0){ d++; i/=10 ; } return d ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : long ; K := scanner.getCurrent()->toLong() ; var n : long ; n := 1 ; var s : double ; s := 1.d ; var i : long ; i := 1 ; while i <= K do ( ( var x : long ; x := n ; var z : long ; z := 0 ; var y : long ; y := 1 ; while (x > 0) do ( x := x/(10) ; z := z * 10 + 9 ; y := y*(10) ; var t : long ; t := x * y + z ; var ts : double ; ts := sunuke(t) ; if (ts < s) then ( n := t ; s := ts ) else skip ; ) ; OclFile["System.out"].println(n) ; n := n + 1 ; s := sunuke(n) ; ) ; i := i + 1 ) ; ); static operation sunuke( n : long) : double pre: true post: true activity: ( return n->oclAsType(double) / sumDigits(n) ); static operation sumDigits( i : long) : long pre: true post: true activity: ( var sum : long ; sum := 0 ; while (i > 0) do ( sum := sum+(i mod 10) ; i := i/(10) ) ; return sum ); static operation numDigits( i : long) : long pre: true post: true activity: ( var d : long ; d := 0 ; while (i > 0) do ( d := d + 1 ; i := i/(10) ) ; return d ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws FileNotFoundException { new Main().run(); } void run(){ Scanner sc=new Scanner(System.in); long K=sc.nextLong(); long ans=0 ; long add=1 ; PrintWriter pw=new PrintWriter(System.out); int cnt=0 ; while(cnt++(ans+add*10)*S(ans+add))add=add*10 ; ans+=add ; pw.println(ans); } pw.close(); } long S(long a){ long ret=0 ; while(a>0){ ret+=a % 10 ; a/=10 ; } return ret ; } static void tr(Object...objects){ System.out.println(Arrays.deepToString(objects)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : long ; K := sc.getCurrent()->toLong() ; var ans : long ; ans := 0 ; var add : long ; add := 1 ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var cnt : int ; cnt := 0 ; while (cnt < K) do ( cnt := cnt + 1 ; skip ; ( if ((ans + add) * S(ans + add * 10) > (ans + add * 10) * S(ans + add)) then add := add * 10 ; else skip ; ans := ans+(add) ; skip ) ; ) ; skip ; ); operation S( a : long) : long pre: true post: true activity: ( var ret : long ; ret := 0 ; while (a > 0) do ( ret := ret+(a mod 10) ; a := a/(10) ) ; return ret ); static operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public void main(Scanner sc){ int k=sc.nextInt(); long n=1 ; for(int i=0 ; i(next*1.0/s)){ min=(next*1.0/s); minn=next ; } } } return minn ; } private int s(long n){ int wa=0 ; while(n!=0){ wa+=n % 10 ; n/=10 ; } return wa ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); new Main().main(sc); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation main( sc : OclFile) : void pre: true post: true activity: ( var k : int ; k := sc.nextInt() ; var n : long ; n := 1 ; var i : int ; i := 0 ; while i < k do ( ( OclFile["System.out"].println(n) ; n := next(n + 1) ) ; i := i + 1 ) ); operation next( n : long) : long pre: true post: true activity: ( var min : double ; min := (2 - 2->pow(-52))*(2->pow(1023)) ; var minn : long ; minn := 0 ; var tmp : long ; tmp := 1 ; while tmp <= n do ( ( var i : int ; i := ((n / tmp) mod 10)->oclAsType(int) ; while i <= 9 do ( ( var next : long ; next := ((n / tmp / 10) * 10 + i) * tmp + (tmp - 1) ; var s : int ; s := s(next) ; if (min > (next * 1.0 / s)) then ( min := (next * 1.0 / s) ; minn := next ) else skip ) ; i := i + 1 ) ) ; tmp := tmp*(10) ) ; return minn ); operation s( n : long) : int pre: true post: true activity: ( var wa : int ; wa := 0 ; while (n /= 0) do ( wa := wa+(n mod 10) ; n := n/(10) ) ; return wa ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; Main.newMain().main(sc) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long K=Long.parseLong(sc.next()); long ans=0 ; long ans1,ans2,s1,s2 ; long add=1 ; long count=0 ; boolean flag=true ; int times=9 ; while(count=K){ break ; } } flag=false ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : long ; K := (sc.getCurrent())->toLong() ; var ans : long ; ans := 0 ; var ans1 : long ; var ans2 : long ; var s1 : long ; var s2 : long ; var add : long ; add := 1 ; var count : long ; count := 0 ; var flag : boolean ; flag := true ; var times : int ; times := 9 ; while (count < K) do ( ans1 := ans + add ; s1 := 0 ; var a1 : String ; a1 := ((ans1) + "") ; var i : int ; i := 0 ; while i < a1->size() do ( ( s1 := s1+((((a1->at(i+1)) + ""))->toLong()) ) ; i := i + 1 ) ; ans2 := ans1 + add ; s2 := 0 ; var a2 : String ; a2 := ((ans2) + "") ; var i : int ; i := 0 ; while i < a2->size() do ( ( s2 := s2+((((a2->at(i+1)) + ""))->toLong()) ) ; i := i + 1 ) ; if (ans2 * s1 - ans1 * s2 < 0) then ( add := add*(10) ; flag := true ; continue ) else skip ; if (flag) then ( times := 9 ) else ( times := 10 ) ; var a : String ; a := ((ans + add) + "") ; var i : int ; i := 0 ; while i < times do ( ( ans := ans+(add) ; var ai : String ; ai := ((ans) + "") ; if (a->size() /= ai->size()) then ( ans := ans-(add) ; break ) else skip ; OclFile["System.out"].println(ans) ; count := count + 1 ; if (count >= K) then ( break ) else skip ; ) ; i := i + 1 ) ; flag := false ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedHashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long K=sc.nextLong(); SetsunekeSet=new LinkedHashSet<>(); for(long m=1 ; m<=10e15 ; m*=10){ boolean sunukeCheckFlag=true ; for(int i=1 ; sunukeCheckFlag ; i++){ long x=i*m+m-1 ; long y=(i+1)*m+m-1 ; if(x*Sn(y)<=y*Sn(x)){ sunekeSet.add(x); if(K==sunekeSet.size()){ sunekeSet.stream().forEach(System.out :: println); return ; } } else { sunukeCheckFlag=false ; } } } } public static long Sn(long num){ long Sn=0 ; while(num!=0){ Sn+=num % 10 ; num/=10 ; } return Sn ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : long ; K := sc.getCurrent()->toLong() ; var sunekeSet : Set(long) ; sunekeSet := Set{} ; var m : long ; m := 1 ; while m <= 10e15 do ( ( var sunukeCheckFlag : boolean ; sunukeCheckFlag := true ; var i : int ; i := 1 ; while sunukeCheckFlag do ( ( var x : long ; x := i * m + m - 1 ; var y : long ; y := (i + 1) * m + m - 1 ; if (x * Sn(y) <= y * Sn(x)) then ( sunekeSet := sunekeSet->including(x) ; if (K = sunekeSet->size()) then ( for _forEach : sunekeSet do ( skip ;) ; return ) else skip ) else ( sunukeCheckFlag := false ) ) ; i := i + 1 ) ) ; m := m*(10) ) ); static operation Sn( num : long) : long pre: true post: true activity: ( var Sn : long ; Sn := 0 ; while (num /= 0) do ( Sn := Sn+(num mod 10) ; num := num/(10) ) ; return Sn ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int test=in.nextInt(); for(int t=1 ; t<=test ; t++){ char ch[]=in.next().toCharArray(); HashSetmap=new HashSet<>(); for(int i=0 ; itoInteger() ; var t : int ; t := 1 ; while t <= test do ( ( var ch : Sequence(String) ; ch := in.getCurrent()->characters() ; var map : Set(String) ; map := Set{} ; var i : int ; i := 0 ; while i < ch->size() do ( ( map := map->including(ch[i+1]) ) ; i := i + 1 ) ; if (ch->size() /= map->size()) then ( skip ) else ( ch := ch->sort() ; var flag : boolean ; flag := true ; var i : int ; i := 1 ; while i < ch->size() do ( ( var sub : int ; sub := ch[i+1] - ch[i - 1+1] ; if (sub /= 1) then ( flag := false ; break ) else skip ) ; i := i + 1 ) ; if (flag) then ( skip ) else ( skip ) ) ) ; t := t + 1 ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _1144A_DiverseStrings { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=input.nextInt(); while(test-->0){ String str=input.next(); LinkedListlist=new LinkedList<>(); for(char c : str.toCharArray()){ list.add(c); } Collections.sort(list); char first=list.peekFirst(); char last=list.peekLast(); String sample="" ; for(char c=first ; c<=last ; c++){ sample+=c ; } String real=list.toString().replaceAll("[\\[\\],] ",""); if(sample.equals(real)){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class _1144A_DiverseStrings { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := input.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var str : String ; str := input.getCurrent() ; var list : Sequence(String) ; list := Sequence{} ; for (c : str->characters()) do ( ( list := list->including(c) ) ) ; list := list->sort() ; var first : String ; first := list.peekFirst() ; var last : String ; last := list.peekLast() ; var sample : String ; sample := "" ; var c : String ; c := first ; while c <= last do ( ( sample := sample+(c) ) ; c := c + 1 ) ; var real : String ; real := list+"".replaceAllMatches("[\\[\\],] ", "" ) ; if (sample = real) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t--!=0){ int[] arr1=new int[26]; String s=in.next(); char[] arr=s.toCharArray(); Arrays.sort(arr); int n=s.length(); boolean flag=true ; for(int i=0 ; i0){ if(Math.abs(arr[i-1]-arr[i])!=1)flag=false ; } } for(int e : arr1){ if(e>1){ flag=false ; break ; } } System.out.println(flag ? "YES" : "NO"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var arr1 : Sequence(int) ; arr1 := Integer.subrange(1,26)->collect(0) ; var s : String ; s := in.getCurrent() ; var arr : Sequence(String) ; arr := s->characters() ; arr := arr->sort() ; var n : int ; n := s->size() ; var flag : boolean ; flag := true ; var i : int ; i := 0 ; while i < n do ( ( arr1[s->at(i+1) - ('a')->char2byte()+1] := arr1[s->at(i+1) - ('a')->char2byte()+1] + 1 ; if (i > 0) then ( if (if arr[i - 1+1] - arr[i+1] < 0 then -(arr[i - 1+1] - arr[i+1]) else arr[i - 1+1] - arr[i+1] endif /= 1) then flag := false ; else skip ) else skip ) ; i := i + 1 ) ; for (e : arr1) do ( ( if (e > 1) then ( flag := false ; break ) else skip ) ) ; OclFile["System.out"].println(if flag then "YES" else "NO" endif) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MainClass { public static int count(String s,char value){ int cnt=0 ; for(int i=0 ; i0){ String s=sc.next(); char[] arr=s.toCharArray(); Arrays.sort(arr); boolean check=true ; for(int i=1 ; isize() do ( if (s->at(i+1) = value) then cnt := cnt + 1 ; else skip ; ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t1 : int ; t1 := sc.getCurrent()->toInteger() ; while (t1 > 0) do ( t1 := t1 - 1 ; skip ; ( var s : String ; s := sc.getCurrent() ; var arr : Sequence(String) ; arr := s->characters() ; arr := arr->sort() ; var check : boolean ; check := true ; var i : int ; i := 1 ; while i < arr->size() do ( ( if (arr[i+1] /= arr[i - 1+1] + 1) then ( check := false ; break ) else skip ) ; i := i + 1 ) ; if (check) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { private static BufferedReader br=null ; public static void main(String[] args){ br=new BufferedReader(new InputStreamReader(System.in)); while(true){ try { String line=null ; String[] lines=null ; line=br.readLine(); lines=line.split(" "); int N=Integer.parseInt(lines[0]); int K=Integer.parseInt(lines[1]); if(N==0 && K==0){ return ; } line=br.readLine(); lines=line.split(" "); int[] bloodAmt=new int[K]; for(int i=0 ; isplit(" ") ; var N : int ; N := (lines[0+1])->toInteger() ; var K : int ; K := (lines[1+1])->toInteger() ; if (N = 0 & K = 0) then ( return ) else skip ; line := br.readLine() ; lines := line->split(" ") ; var bloodAmt : Sequence(int) ; bloodAmt := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 0 ; while i < K do ( ( bloodAmt[i+1] := (lines[i+1])->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( line := br.readLine() ; lines := line->split(" ") ; var j : int ; j := 0 ; while j < K do ( ( bloodAmt[j+1] := bloodAmt[j+1]-((lines[j+1])->toInteger()) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < K do ( ( if (bloodAmt[i+1] < 0) then ( OclFile["System.out"].println("No") ; break ) else skip ; if (i = K - 1) then ( OclFile["System.out"].println("Yes") ) else skip ) ; i := i + 1 ) ; ) catch (e : ProgramException) do ( e.printStackTrace() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class MainClass { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); st=new StringTokenizer(br.readLine()); String t=st.nextToken(); String s="" ; int i=0,j=0 ; while(itoInteger() ; st := OclIterator.newOclIterator_String(br.readLine()) ; var t : String ; t := st.next() ; var s : String ; s := "" ; var i : int ; i := 0 ; var j : int ; j := 0 ; while (i < t->size()) do ( s := s+(t->at(i+1)) ; j := j + 1 ; i := i+(j) ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static HashMap>map ; static HashSetdone ; public static void main(String[] args){ while(true){ int N=sc.nextInt(); if(N==0)break ; sc.nextLine(); String firstGroup=null ; map=new HashMap>(); done=new HashSet(); for(int i=0 ; imember=new ArrayList(); for(int j=1 ; jset=new HashSet(); get(set,firstGroup); System.out.println(set.size()); } } static void get(HashSetset,String name){ if(done.contains(name))return ; if(map.containsKey(name)){ for(String c : map.get(name)){ get(set,c); } } else { set.add(name); } done.add(name); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute map : Map(String,Sequence(String)); static attribute done : Set(String); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (true) do ( var N : int ; N := sc.getCurrent()->toInteger() ; if (N = 0) then break else skip ; skip ; var firstGroup : String ; firstGroup := null ; map := Map{} ; done := Set{} ; var i : int ; i := 0 ; while i < N do ( ( var elems : Sequence(String) ; elems := sc.nextLine()->split(":|,|\\.") ; var member : Sequence(String) ; member := Sequence{} ; var j : int ; j := 1 ; while j < elems->size() do ( ( member := member->including(elems[j+1]) ) ; j := j + 1 ) ; map := map->union(Map{elems[0+1] |-> member}) ; if (i = 0) then firstGroup := elems[0+1] ; else skip ; ) ; i := i + 1 ) ; var set : Set(String) ; set := Set{} ; execute get(set, firstGroup) ; OclFile["System.out"].println(set->size()) ; ) ); static operation get( set : Set(String), name : String) : void pre: true post: true activity: ( if (done->includes(name)) then return else skip ; if (map->keys()->includes(name)) then ( for (c : map->at(name)) do ( ( execute get(set, c) ) ) ) else ( set := set->including(name) ) ; done := done->including(name) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String input=sc.next(); String str="" ; int i=0 ; int m=1 ; while(itoInteger() ; var input : String ; input := sc.getCurrent() ; var str : String ; str := "" ; var i : int ; i := 0 ; var m : int ; m := 1 ; while (i < n) do ( str := str+(input->at(i+1)) ; m := m + 1 ; i := i+(m) ) ; OclFile["System.out"].println(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test266 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); char x[]=in.next().toCharArray(); for(int i=0,a=1 ; itoInteger() ; var x : Sequence(String) ; x := in.getCurrent()->characters() ; var i : int ; i := 0 ; var a : int ; a := 1 ; while i < n do ( ( OclFile["System.out"].print(x[i+1]) ) ; a := a+(1) ; i := i+(a) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Repeating { int number ; public Repeating(int number){ this.number=number ; } public int getNumber(){ return number ; } public void input(String s){ int count=1 ; for(int i=0 ; iat(i+1)) ; count := count + 1 ) ; i := i+(count) ) ; OclFile["System.out"].println() ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : Repeating ; instance := Repeating.newRepeating(number) ; var s : String ; s := input.getCurrent() ; instance.input(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CP29 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextLine(); String l=sc.nextLine(); String ans="" ; int k=0,j=0,i=0 ; while(itoInteger() ; skip ; var l : String ; l := sc.nextLine() ; var ans : String ; ans := "" ; var k : int ; k := 0 ; var j : int ; j := 0 ; var i : int ; i := 0 ; while (i < l->size()) do ( ans := ans + "" + l->at(i+1) ; k := j + 1 ; j := j + 1 ; i := i+(k) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); TreeSetset=new TreeSet<>(); int n=in.nextInt(); for(int i=0 ; iitr=set.iterator(); while(itr.hasNext()){ out.println(itr.next()); } out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var set : Set(int) ; set := Set{} ; var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( set := set->including((in.getCurrent())->toInteger()) ) ; i := i + 1 ) ; var m : int ; m := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( var obj : int ; obj := (in.getCurrent())->toInteger() ; if (set->includes(obj)) then set := set->excludingAt(obj+1) ; else set := set->including(obj) ; ) ; i := i + 1 ) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var itr : OclIterator ; itr := set->iterator() ; while (itr.hasNext()) do ( skip ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeSet ; class Main { public static void main(String[] args){ SetsetA=new TreeSet(); SetsetB=new TreeSet(); try(Scanner sc=new Scanner(System.in)){ int times=sc.nextInt(); for(int i=0 ; ia=new ArrayList(setB); for(int i=0 ; i(setA); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < times do ( setA := setA->including(sc.getCurrent()->toLong()) ; ; i := i + 1 ) ; times := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < times do ( setB := setB->including(sc.getCurrent()->toLong()) ; ; i := i + 1 ) ; var a : Sequence(long) ; a := Sequence{}->union(setB) ; var i : int ; i := 0 ; while i < times do ( ( var l : long ; l := a->at(i+1) ; var check : boolean ; check := setA->includes(l) ; if (check) then setA := setA->excludingAt(l+1) ; else setA := setA->including(l) ; ) ; i := i + 1 ) ; a := Sequence{}->union(setA) ; var i : int ; i := 0 ; while i < a->size() do ( OclFile["System.out"].println(a->at(i+1)) ; ; i := i + 1 ) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(); int a[]=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := stdIn.getCurrent()->toInteger() ) ; i := i + 1 ) ; var m : int ; m := stdIn.getCurrent()->toInteger() ; var num : Sequence(int) ; num := Integer.subrange(1,n + m)->collect(0) ; var i : int ; i := 0 ; while i < n + m do ( ( if (i < n) then ( num[i+1] := a[i+1] ) else ( num[i+1] := stdIn.getCurrent()->toInteger() ) ) ; i := i + 1 ) ; num := num->sort() ; var i : int ; i := 0 ; while i < n + m do ( ( if (i = 0) then ( if (num[i+1] /= num[i + 1+1]) then ( OclFile["System.out"].println(num[i+1]) ) else skip ) else if (i = n + m - 1) then ( if (num[i - 1+1] /= num[i+1]) then ( OclFile["System.out"].println(num[i+1]) ) else skip ) else ( if (num[i - 1+1] /= num[i+1] & num[i+1] /= num[i + 1+1]) then ( OclFile["System.out"].println(num[i+1]) ) else skip ) ; ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); TreeSetset=new TreeSet<>(); int a=scan.nextInt(); for(int i=0 ; iset2=new TreeSet<>(); int b=scan.nextInt(); for(int i=0 ; isymDiff=new TreeSet<>(set); symDiff.addAll(set2); TreeSettmp=new TreeSet<>(set); tmp.retainAll(set2); symDiff.removeAll(tmp); for(int i : symDiff){ System.out.println(i); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var set : Set(int) ; set := Set{} ; var a : int ; a := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < a do ( ( var num : int ; num := scan.getCurrent()->toInteger() ; set := set->including(num) ) ; i := i + 1 ) ; var set2 : Set(int) ; set2 := Set{} ; var b : int ; b := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < b do ( ( var num : int ; num := scan.getCurrent()->toInteger() ; set2 := set2->including(num) ) ; i := i + 1 ) ; var symDiff : Set(int) ; symDiff := Set{}->union(set) ; symDiff := symDiff->union(set2) ; var tmp : Set(int) ; tmp := Set{}->union(set) ; tmp := tmp->intersection(set2) ; symDiff := symDiff - tmp ; for (i : symDiff) do ( ( OclFile["System.out"].println(i) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); while(true){ int n=scanner.nextInt(); int k=scanner.nextInt(); if((n | k)==0)break ; int[] num=new int[k]; for(int i=0 ; itoInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,k)) = 0) then break else skip ; var num : Sequence(int) ; num := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < k do ( num[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ans : String ; ans := "Yes" ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < k do ( ( var a : int ; a := scanner.getCurrent()->toInteger() ; num[j+1] := num[j+1]-(a) ; if (num[j+1] < 0) then ans := "No" ; else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] str=br.readLine().split(" "); SetS=new TreeSet(); for(int i=0 ; itoInteger() ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var S : Set(int) ; S := Set{} ; var i : int ; i := 0 ; while i < n do ( ( S := S->including((str[i+1])->toInteger()) ) ; i := i + 1 ) ; var m : int ; m := (br.readLine())->toInteger() ; str := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < m do ( ( var b : int ; b := (str[i+1])->toInteger() ; if (S->includes(b)) then S := S->excludingAt(b+1) ; else S := S->including(b) ; ) ; i := i + 1 ) ; for (num : S) do ( OclFile["System.out"].println(num) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int minimumChanges(int n,int a[]){ int i ; int[] sf=new int[n+1]; sf[n]=0 ; for(i=n-1 ; i>=0 ; i--){ sf[i]=sf[i+1]; if(a[i]<=0)sf[i]++; } int pos=0 ; int mn=n ; for(i=0 ; i=0)pos++; mn=Math.min(mn,pos+sf[i+1]); } return mn ; } public static void main(String[] args){ int[] a={ -1,-2,-3,3,-5,3,4 }; int n=a.length ; System.out.println(minimumChanges(n,a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minimumChanges( n : int, a : Sequence(int)) : int pre: true post: true activity: ( var i : int ; var sf : Sequence(int) ; sf := Integer.subrange(1,n + 1)->collect(0) ; sf[n+1] := 0 ; i := n - 1 ; while i >= 0 do ( ( sf[i+1] := sf[i + 1+1] ; if (a[i+1] <= 0) then sf[i+1] := sf[i+1] + 1 ; else skip ) ; i := i - 1 ) ; var pos : int ; pos := 0 ; var mn : int ; mn := n ; i := 0 ; while i < n - 1 do ( ( if (a[i+1] >= 0) then pos := pos + 1 ; else skip ; mn := Set{mn, pos + sf[i + 1+1]}->min() ) ; i := i + 1 ) ; return mn ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{-1,-2,-3,3,-5,3,4} ; var n : int ; n := a->size() ; OclFile["System.out"].println(minimumChanges(n, a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void decToBinary(int n){ int[] binaryNum=new int[32]; int i=0 ; while(n>0){ binaryNum[i]=n % 2 ; n=n/2 ; i++; } for(int j=i-1 ; j>=0 ; j--)System.out.print(binaryNum[j]); } public static void main(String[] args){ int n=17 ; decToBinary(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation decToBinary( n : int) : void pre: true post: true activity: ( var binaryNum : Sequence(int) ; binaryNum := Integer.subrange(1,32)->collect(0) ; var i : int ; i := 0 ; while (n > 0) do ( binaryNum[i+1] := n mod 2 ; n := n / 2 ; i := i + 1 ) ; var j : int ; j := i - 1 ; while j >= 0 do ( OclFile["System.out"].print(binaryNum[j+1]) ; ; j := j - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 17 ; execute decToBinary(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void printSubArray(int arr[],int start,int end){ System.out.print("["); for(int i=start ; i<=end ; i++)System.out.print(arr[i]+" "); System.out.print("] "); } static boolean divideArray(int arr[],int n){ int sum=0 ; for(int i=0 ; isize() ; execute divideArray(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DreamonAndRankingCollection { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(); int x=sc.nextInt(); int[] nums=new int[n]; for(int i=0 ; i0){ visited[result]=true ; x--; } else if(! visited[result] && x<=0){ break ; } } return result-1 ; } private static int findMax(int[] nums){ int max=Integer.MIN_VALUE ; for(int num : nums){ max=Math.max(max,num); } return max ; } } ------------------------------------------------------------ OCL File: --------- class DreamonAndRankingCollection { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := sc.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(findLargestV(nums, n, x)) ; ) ; ) ); static operation findLargestV( nums : Sequence(int), n : int, x : int) : int pre: true post: true activity: ( var max : int ; max := findMax(nums) ; var visited : Sequence(boolean) ; visited := Integer.subrange(1,max + x + 1)->collect(false) ; var result : int ; result := 0 ; for (num : nums) do ( ( visited[num+1] := true ) ) ; result := 1 ; while result < visited->size() do ( ( if (visited[result+1]) then ( continue ) else if (not(visited[result+1]) & x > 0) then ( visited[result+1] := true ; x := x - 1 ) else if (not(visited[result+1]) & x <= 0) then ( break ) else skip ; ; ) ; result := result + 1 ) ; return result - 1 ); static operation findMax( nums : Sequence(int)) : int pre: true post: true activity: ( var max : int ; max := -2147483648 ; for (num : nums) do ( ( max := Set{max, num}->max() ) ) ; return max ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int x=sc.nextInt(); boolean[] arr=new boolean[201]; for(int i=1 ; i<=n+x ; i++)arr[i]=false ; for(int i=0 ; i0 ; i--){ int v=0 ; for(int j=1 ; j<=i ; j++){ if(! arr[j])v++; } if(v<=x){ System.out.println(i); break ; } } } } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var arr : Sequence(boolean) ; arr := Integer.subrange(1,201)->collect(false) ; var i : int ; i := 1 ; while i <= n + x do ( arr[i+1] := false ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var rank : int ; rank := sc.getCurrent()->toInteger() ; arr[rank+1] := true ) ; i := i + 1 ) ; var i : int ; i := n + x ; while i > 0 do ( ( var v : int ; v := 0 ; var j : int ; j := 1 ; while j <= i do ( ( if (not(arr[j+1])) then v := v + 1 ; else skip ) ; j := j + 1 ) ; if (v <= x) then ( OclFile["System.out"].println(i) ; break ) else skip ) ; i := i - 1 ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); int a=sc.nextInt(); Sets=new HashSet<>(); for(int i=0 ; i=0){ if(s.contains(cnt)){ cnt++; } else { a--; if(a<0)break ; cnt++; } } System.out.println(cnt-1); } } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var s : Set(int) ; s := Set{} ; var i : int ; i := 0 ; while i < n do ( ( s := s->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var cnt : int ; cnt := 1 ; while (a >= 0) do ( if (s->includes(cnt)) then ( cnt := cnt + 1 ) else ( a := a - 1 ; if (a < 0) then break else skip ; cnt := cnt + 1 ) ) ; OclFile["System.out"].println(cnt - 1) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void findGeometricTriplets(int arr[],int n){ for(int j=1 ; j=0 && k<=n-1){ while(i>=0 && arr[j] % arr[i]==0 && arr[k] % arr[j]==0 && arr[j]/arr[i]==arr[k]/arr[j]){ System.out.println(arr[i]+" "+arr[j]+" "+arr[k]); k++; i--; } if(i>=0 && arr[j] % arr[i]==0 && arr[k] % arr[j]==0){ if(i>=0 && arr[j]/arr[i]=0 && arr[j] % arr[i]==0)k++; else i--; } } } public static void main(String[] args){ int arr[]={ 1,2,4,16 }; int n=arr.length ; findGeometricTriplets(arr,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findGeometricTriplets( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var j : int ; j := 1 ; while j < n - 1 do ( ( var i : int ; i := j - 1 ; var k : int ; k := j + 1 ; while (i >= 0 & k <= n - 1) do ( while (i >= 0 & arr[j+1] mod arr[i+1] = 0 & arr[k+1] mod arr[j+1] = 0 & arr[j+1] / arr[i+1] = arr[k+1] / arr[j+1]) do ( OclFile["System.out"].println(arr[i+1] + " " + arr[j+1] + " " + arr[k+1]) ; k := k + 1 ; i := i - 1 ) ; if (i >= 0 & arr[j+1] mod arr[i+1] = 0 & arr[k+1] mod arr[j+1] = 0) then ( if (i >= 0 & arr[j+1] / arr[i+1] < arr[k+1] / arr[j+1]) then i := i - 1 ; else k := k + 1 ; ) else if (i >= 0 & arr[j+1] mod arr[i+1] = 0) then k := k + 1 else i := i - 1 ; ; ) ) ; j := j + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,4,16} ; var n : int ; n := arr->size() ; execute findGeometricTriplets(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class InnaAndAlarmClock { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] x=new int[101]; int[] y=new int[101]; for(int i=0 ; i0)xCounter++; if(y[i]>0)yCounter++; } System.out.println(Math.min(xCounter,yCounter)); } } ------------------------------------------------------------ OCL File: --------- class InnaAndAlarmClock { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,101)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,101)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var tempX : int ; tempX := sc.getCurrent()->toInteger() ; var tempY : int ; tempY := sc.getCurrent()->toInteger() ; x[tempX+1] := x[tempX+1] + 1 ; y[tempY+1] := y[tempY+1] + 1 ) ; i := i + 1 ) ; var xCounter : int ; xCounter := 0 ; var yCounter : int ; yCounter := 0 ; var i : int ; i := 0 ; while i < 101 do ( ( if (x[i+1] > 0) then xCounter := xCounter + 1 ; else skip ; if (y[i+1] > 0) then yCounter := yCounter + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{xCounter, yCounter}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class InnaAndAlarmClock { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] x=new int[101]; int[] y=new int[101]; for(int i=0 ; i0)xCounter++; if(y[i]>0)yCounter++; } System.out.println(Math.min(xCounter,yCounter)); } } ------------------------------------------------------------ OCL File: --------- class InnaAndAlarmClock { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,101)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,101)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var tempX : int ; tempX := sc.getCurrent()->toInteger() ; var tempY : int ; tempY := sc.getCurrent()->toInteger() ; x[tempX+1] := x[tempX+1] + 1 ; y[tempY+1] := y[tempY+1] + 1 ) ; i := i + 1 ) ; skip ; var xCounter : int ; xCounter := 0 ; var yCounter : int ; yCounter := 0 ; var i : int ; i := 0 ; while i < 101 do ( ( if (x[i+1] > 0) then xCounter := xCounter + 1 ; else skip ; if (y[i+1] > 0) then yCounter := yCounter + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{xCounter, yCounter}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Scanner ; class Main { static Scanner s ; public static void main(String args[]){ s=new Scanner(System.in); try { while(true){ int n=s.nextInt(); int k=s.nextInt(); if(n+k==0)return ; System.out.println(solve(n,k)); } } catch(Exception e){ System.err.println(e); } } static String solve(int n,int k){ int supply_array[]=new int[k]; int demand_matrix[][]=new int[n][k]; for(int i=0 ; isupply_array[i])return "No" ; } return "Yes" ; } static void print(int a[]){ for(int i=0 ; itoInteger() ; var k : int ; k := s.getCurrent()->toInteger() ; if (n + k = 0) then return else skip ; OclFile["System.out"].println(solve(n, k)) ) ) catch (e : ProgramException) do ( OclFile["System.err"].println(e) ) ); static operation solve( n : int, k : int) : String pre: true post: true activity: ( var supply_array : Sequence(int) ; supply_array := Integer.subrange(1,k)->collect(0) ; var demand_matrix : Sequence(Sequence(int)) ; demand_matrix := Integer.subrange(1,n)->collect(Integer.subrange(1,k)->collect(0)) ; var i : int ; i := 0 ; while i < k do ( ( supply_array[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < k do ( ( demand_matrix[i+1][j+1] := s.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( ( var demand_sum : int ; demand_sum := 0 ; var j : int ; j := 0 ; while j < n do ( ( demand_sum := demand_sum+(demand_matrix[j+1][i+1]) ) ; j := j + 1 ) ; if (demand_sum > supply_array[i+1]) then return "No" else skip ) ; i := i + 1 ) ; return "Yes" ); static operation print( a : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < a->size() do ( ( OclFile["System.out"].print(a[i+1] + "\t") ) ; i := i + 1 ) ; OclFile["System.out"].println() ); static operation print( m : Sequence(Sequence(int))) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < m->size() do ( ( var j : int ; j := 0 ; while j < m[i+1]->size() do ( ( OclFile["System.out"].print(m[i+1][j+1] + "\t") ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class cp { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int n=scn.nextInt(); Setx=new HashSet(); Sety=new HashSet(); for(int i=0 ; itoInteger() ; var x : Set(int) ; x := Set{} ; var y : Set(int) ; y := Set{} ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := scn.getCurrent()->toInteger() ; var b : int ; b := scn.getCurrent()->toInteger() ; x := x->including(a) ; y := y->including(b) ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{x->size(), y->size()}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countSubstrs(String str,int i,int j,int n){ if(n==1)return 1 ; if(n<=0)return 0 ; int 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.charAt(i)==str.charAt(j))res++; return res ; } public static void main(String[] args){ String str="abcab" ; int n=str.length(); System.out.print(countSubstrs(str,0,n-1,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSubstrs( str : String, i : int, j : int, n : int) : int pre: true post: true activity: ( if (n = 1) then return 1 else skip ; if (n <= 0) then return 0 else skip ; var res : int ; 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->at(i+1) = str->at(j+1)) then res := res + 1 ; else skip ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "abcab" ; var n : int ; n := str->size() ; OclFile["System.out"].print(countSubstrs(str, 0, (n)->char2byte() - 1, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; class GFG { static double PI=3.14159265 ; public static double area_cicumscribed(double a){ return(a*a*(PI/3)); } public static void main(String[] args){ double a=6.0 ; System.out.println("Area of circumscribed circle is :"+area_cicumscribed(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute PI : double := 3.14159265; static operation area_cicumscribed( a : double) : double pre: true post: true activity: ( return (a * a * (PI / 3)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 6.0 ; OclFile["System.out"].println("Area of circumscribed circle is :" + area_cicumscribed(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static void alternate(int a,int b,int x){ x=a+b-x ; System.out.println("After change"+"\n"+" x is : "+x); } public static void main(String args[]){ int a=-10 ; int b=15 ; int x=a ; System.out.println("x is : "+x); alternate(a,b,x); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation alternate( a : int, b : int, x : int) : void pre: true post: true activity: ( x := a + b - x ; OclFile["System.out"].println("After change" + "\n" + " x is : " + x) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := -10 ; var b : int ; b := 15 ; var x : int ; x := a ; OclFile["System.out"].println("x is : " + x) ; execute alternate(a, b, x) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int __gcd(int a,int 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); } static int Parts(int Arr[],int N){ int factor=Arr[1]-Arr[0]; for(int i=2 ; i b) then return __gcd(a - b, b) else skip ; return __gcd(a, b - a) ); static operation Parts( Arr : Sequence(int), N : int) : int pre: true post: true activity: ( var factor : int ; factor := Arr[1+1] - Arr[0+1] ; var i : int ; i := 2 ; while i < N do ( ( factor := __gcd(factor, Arr[i+1] - Arr[i - 1+1]) ) ; i := i + 1 ) ; factor := __gcd(factor, 360 - Arr[N - 1+1] + Arr[0+1]) ; var cuts : int ; cuts := (360 / factor) - N ; return cuts ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var Arr : Sequence(int) ; Arr := Sequence{0,1} ; var N : int ; N := Arr->size() ; OclFile["System.out"].println(Parts(Arr, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args)throws Exception { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String t ; double[] p=new double[12]; double s,r ; while((t=bf.readLine())!=null){ String[] d=t.split(","); for(int i=0 ; i<8 ; i++)p[i]=Double.parseDouble(d[i]); for(int i=0 ; i<4 ; i++)p[i+8]=p[i]; s=((p[3]-p[1])*(p[2]-p[4])-(p[2]-p[0])*(p[3]-p[5])); for(int i=4 ; i<=8 ; i+=2){ r=((p[i+1]-p[i-1])*(p[i]-p[i+2])-(p[i]-p[i-2])*(p[i+1]-p[i+3])); if(s*r<0){ System.out.println("NO"); break ; } if(i==8)System.out.println("YES"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var t : String ; var p : Sequence(double) ; p := Integer.subrange(1,12)->collect(0.0) ; var s : double ; var r : double ; t := bf.readLine() ; while ((t) /= null) do ( skip ; ( var d : Sequence(String) ; d := t->split(",") ; var i : int ; i := 0 ; while i < 8 do ( p[i+1] := (d[i+1])->toReal() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 4 do ( p[i + 8+1] := p[i+1] ; ; i := i + 1 ) ; s := ((p[3+1] - p[1+1]) * (p[2+1] - p[4+1]) - (p[2+1] - p[0+1]) * (p[3+1] - p[5+1])) ; var i : int ; i := 4 ; while i <= 8 do ( ( r := ((p[i + 1+1] - p[i - 1+1]) * (p[i+1] - p[i + 2+1]) - (p[i+1] - p[i - 2+1]) * (p[i + 1+1] - p[i + 3+1])) ; if (s * r < 0) then ( OclFile["System.out"].println("NO") ; break ) else skip ; if (i = 8) then OclFile["System.out"].println("YES") ; else skip ) ; i := i+(2) ) ; ) ; t := bf.readLine() ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc ; static final int INF=1<<28 ; static final double EPS=1e-9 ; void run(){ sc=new Scanner(System.in); for(; sc.hasNext(); ){ String[] s=sc.nextLine().split(","); double[] x=new double[4]; double[] y=new double[4]; for(int i=0 ; i<4 ; i++){ x[i]=Double.parseDouble(s[i*2]); y[i]=Double.parseDouble(s[i*2+1]); } boolean f=true ; int[] signs=new int[4]; for(int k=0 ; k<4 ; k++){ int i=(k+1)% 4 ; int j=(k+3)% 4 ; double vx1=x[i]-x[k]; double vy1=y[i]-y[k]; double vx2=x[j]-x[k]; double vy2=y[j]-y[k]; double det=vx1*vy2-vy1*vx2 ; if(det<-EPS){ signs[i]=-1 ; } else signs[i]=1 ; } for(int i=0 ; i<3 ; i++)if(signs[i]!=signs[i+1]){ f=false ; break ; } println(f ? "YES" : "NO"); } sc.close(); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static attribute INF : int := (1*(2->pow(28)))->oclAsType(long); static attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while sc.hasNext() do ( ( var s : Sequence(String) ; s := sc.nextLine()->split(",") ; var x : Sequence(double) ; x := Integer.subrange(1,4)->collect(0.0) ; var y : Sequence(double) ; y := Integer.subrange(1,4)->collect(0.0) ; var i : int ; i := 0 ; while i < 4 do ( ( x[i+1] := (s[i * 2+1])->toReal() ; y[i+1] := (s[i * 2 + 1+1])->toReal() ) ; i := i + 1 ) ; var f : boolean ; f := true ; var signs : Sequence(int) ; signs := Integer.subrange(1,4)->collect(0) ; var k : int ; k := 0 ; while k < 4 do ( ( var i : int ; i := (k + 1) mod 4 ; var j : int ; j := (k + 3) mod 4 ; var vx1 : double ; vx1 := x[i+1] - x[k+1] ; var vy1 : double ; vy1 := y[i+1] - y[k+1] ; var vx2 : double ; vx2 := x[j+1] - x[k+1] ; var vy2 : double ; vy2 := y[j+1] - y[k+1] ; var det : double ; det := vx1 * vy2 - vy1 * vx2 ; if (det < -EPS) then ( signs[i+1] := -1 ) else signs[i+1] := 1 ; ; ) ; k := k + 1 ) ; var i : int ; i := 0 ; while i < 3 do ( if (signs[i+1] /= signs[i + 1+1]) then ( f := false ; break ) else skip ; ; i := i + 1 ) ; execute println(if f then "YES" else "NO" endif) ; ) ) ; skip ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.geom.Line2D ; import java.awt.geom.Point2D ; import java.util.*; public class Main { Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ while(sc.hasNext()){ new aoj0035().doIt(); } } class aoj0035 { final double EPS=1.0e-08 ; Comparatorcom=new Comparator(){ public int compare(Point2D o1,Point2D o2){ if(o1.getX()o2.getX())return 1 ; else if(o1.getY()o2.getY())return 1 ; else return 0 ; } }; int ccw(Line2D l,Point2D p){ return l.relativeCCW(p); } void doIt(){ int ans=0 ; String str[]=sc.nextLine().split(","); Point2D.Double a[]=new Point2D.Double[4]; for(int i=0 ; i<4 ; i++){ a[i]=new Point2D.Double(Double.parseDouble(str[i*2]),Double.parseDouble(str[i*2+1])); } Line2D.Double b[]=new Line2D.Double[4]; for(int i=0 ; i<4 ; i++){ b[i]=new Line2D.Double(a[i] .getX(),a[i] .getY(),a[(i+1)% 4] .getX(),a[(i+1)% 4] .getY()); ans=ans+ccw(b[i],a[(i+2)% 4]); } if(ans==4 || ans==-4)System.out.println("YES"); else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( while (sc.hasNext()) do ( aoj0035.newaoj0035().doIt() ) ); class aoj0035 { attribute EPS : double := 1.0e-08; attribute com : Function(,(,boolean)) := OclComparator.newOclComparator(); operation ccw( l : Line2D, p : Point2D) : int pre: true post: true activity: ( return l.relativeCCW(p) ); operation doIt() : void pre: true post: true activity: ( var ans : int ; ans := 0 ; var str : Sequence(String) ; str := sc.nextLine()->split(",") ; var a : Sequence(double) ; a := Integer.subrange(1,4)->collect(null) ; var i : int ; i := 0 ; while i < 4 do ( ( a[i+1] := Double.newDouble((str[i * 2+1])->toReal(), (str[i * 2 + 1+1])->toReal()) ) ; i := i + 1 ) ; var b : Sequence(double) ; b := Integer.subrange(1,4)->collect(null) ; var i : int ; i := 0 ; while i < 4 do ( ( b[i+1] := Double.newDouble(a[i+1].getX(), a[i+1].getY(), a[(i + 1) mod 4+1].getX(), a[(i + 1) mod 4+1].getY()) ; ans := ans + ccw(b[i+1], a[(i + 2) mod 4+1]) ) ; i := i + 1 ) ; if (ans = 4 or ans = -4) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] z){ double[] b=new double[8]; for(Scanner s=new Scanner(System.in); s.hasNext(); System.out.println((f(b[0],b[1],b[4],b[5],b[6],b[7])>0 && f(b[4],b[5],b[0],b[1],b[2],b[3])>0 && f(b[2],b[3],b[6],b[7],b[0],b[1])>0 && f(b[6],b[7],b[2],b[3],b[4],b[5])>0)||(f(b[0],b[1],b[4],b[5],b[6],b[7])<0 && f(b[4],b[5],b[0],b[1],b[2],b[3])<0 && f(b[2],b[3],b[6],b[7],b[0],b[1])<0 && f(b[6],b[7],b[2],b[3],b[4],b[5])<0)? "YES" : "NO")){ z=s.next().split(","); for(int i=0 ; i<8 ; ++i)b[i]=new Double(z[i]); } } static double f(double a,double b,double c,double d,double e,double f){ return((d-b)*e+(a-c)*f+c*b-a*d); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( z : Sequence(String)) : void pre: true post: true activity: ( var b : Sequence(double) ; b := Integer.subrange(1,8)->collect(0.0) ; var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; while s.hasNext() do ( ( z := s.getCurrent()->split(",") ; var i : int ; i := 0 ; while i < 8 do ( b[i+1] := ("" + (z[i+1]))->toReal() ; ; i := i + 1 ) ) ; OclFile["System.out"].println(if (f(b[0+1], b[1+1], b[4+1], b[5+1], b[6+1], b[7+1]) > 0 & f(b[4+1], b[5+1], b[0+1], b[1+1], b[2+1], b[3+1]) > 0 & f(b[2+1], b[3+1], b[6+1], b[7+1], b[0+1], b[1+1]) > 0 & f(b[6+1], b[7+1], b[2+1], b[3+1], b[4+1], b[5+1]) > 0) or (f(b[0+1], b[1+1], b[4+1], b[5+1], b[6+1], b[7+1]) < 0 & f(b[4+1], b[5+1], b[0+1], b[1+1], b[2+1], b[3+1]) < 0 & f(b[2+1], b[3+1], b[6+1], b[7+1], b[0+1], b[1+1]) < 0 & f(b[6+1], b[7+1], b[2+1], b[3+1], b[4+1], b[5+1]) < 0) then "YES" else "NO" endif) ) ); static operation f( a : double, b : double, c : double, d : double, e : double, f : double) : double pre: true post: true activity: ( return ((d - b) * e + (a - c) * f + c * b - a * d) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; StringTokenizer st ; StringBuilder sb=new StringBuilder(); int[] stock=new int[100]; int[] needs=new int[100]; next : while((line=br.readLine())!=null && ! line.isEmpty()){ int n=Integer.parseInt(line.substring(0,line.indexOf(' '))); int k=Integer.parseInt(line.substring(line.indexOf(' ')+1)); if((n | k)==0){ break ; } st=new StringTokenizer(br.readLine()); for(int i=0 ; icollect(0) ; var needs : Sequence(int) ; needs := Integer.subrange(1,100)->collect(0) ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var n : int ; n := (line.subrange(0+1,line->indexOf(' ')-1))->toInteger() ; var k : int ; k := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1))->toInteger() ; if ((MathLib.bitwiseOr(n,k)) = 0) then ( break ) else skip ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < k do ( ( stock[i+1] := (st.next())->toInteger() ; needs[i+1] := MathLib.bitwiseXor(needs[i+1],needs[i+1]) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( st := OclIterator.newOclIterator_String(br.readLine()) ; var j : int ; j := 0 ; while j < k do ( ( needs[j+1] := needs[j+1]+((st.next())->toInteger()) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( ( if (stock[i+1] < needs[i+1]) then ( sb := sb + StringLib.newString("No\n") ; continue ) else skip ) ; i := i + 1 ) ; sb := sb + StringLib.newString("Yes\n") ; ) ; line := br.readLine() ; ) ; OclFile["System.out"].print(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String args[]){ Scanner in=new Scanner(System.in); long n=in.nextLong(); long pow3=1 ; while(pow3<=3*n){ if(n % pow3!=0){ System.out.println(n/pow3+1); return ; } pow3=pow3*3 ; } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := in.getCurrent()->toLong() ; var pow3 : long ; pow3 := 1 ; while (pow3 <= 3 * n) do ( if (n mod pow3 /= 0) then ( OclFile["System.out"].println(n / pow3 + 1) ; return ) else skip ; pow3 := pow3 * 3 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String args[]){ Scanner in=new Scanner(System.in); long n=in.nextLong(); long pow3=1 ; while(pow3<=n){ if(n % pow3!=0){ System.out.println(n/pow3+1); return ; } pow3=pow3*3 ; } System.out.println(1); } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := in.getCurrent()->toLong() ; var pow3 : long ; pow3 := 1 ; while (pow3 <= n) do ( if (n mod pow3 /= 0) then ( OclFile["System.out"].println(n / pow3 + 1) ; return ) else skip ; pow3 := pow3 * 3 ) ; OclFile["System.out"].println(1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String args[]){ Scanner in=new Scanner(System.in); long n=in.nextLong(); long maxValue=Long.MAX_VALUE ; int cnt=0 ; while(maxValue>0){ cnt++; maxValue=maxValue/3 ; } long max=0 ; long pow3=1 ; for(int i=1 ; i<=cnt-1 ; i++){ pow3=pow3*3 ; if(n % pow3!=0){ max=Math.max(max,n/pow3+1); } } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := in.getCurrent()->toLong() ; var maxValue : long ; maxValue := "9223372036854775807"->toLong() ; var cnt : int ; cnt := 0 ; while (maxValue > 0) do ( cnt := cnt + 1 ; maxValue := maxValue / 3 ) ; var max : long ; max := 0 ; var pow3 : long ; pow3 := 1 ; var i : int ; i := 1 ; while i <= cnt - 1 do ( ( pow3 := pow3 * 3 ; if (n mod pow3 /= 0) then ( max := Set{max, n / pow3 + 1}->max() ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void drawPattern(int N){ int n=N ; int row=1 ; int nst=1 ; int nsp1=n-1 ; int nsp2=-1 ; int val1=row ; int val2=1 ; while(row<=n){ int csp1=1 ; while(csp1<=nsp1){ System.out.print(" "); csp1=csp1+1 ; } int cst1=1 ; while(cst1<=nst){ System.out.print(val1+" "); val1=val1-1 ; cst1=cst1+1 ; } int csp2=1 ; while(csp2<=nsp2){ System.out.print(" "); csp2=csp2+1 ; } if(row!=1 && row!=n){ int cst2=1 ; while(cst2<=nst){ System.out.print(val2+" "); val2=val2+1 ; cst2=cst2+1 ; } } System.out.println(); 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 ; } } public static void main(String args[]){ int N=7 ; drawPattern(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation drawPattern( N : int) : void pre: true post: true activity: ( var n : int ; n := N ; var row : int ; row := 1 ; var nst : int ; nst := 1 ; var nsp1 : int ; nsp1 := n - 1 ; var nsp2 : int ; nsp2 := -1 ; var val1 : int ; val1 := row ; var val2 : int ; val2 := 1 ; while (row <= n) do ( var csp1 : int ; csp1 := 1 ; while (csp1 <= nsp1) do ( OclFile["System.out"].print(" ") ; csp1 := csp1 + 1 ) ; var cst1 : int ; cst1 := 1 ; while (cst1 <= nst) do ( OclFile["System.out"].print(val1 + " ") ; val1 := val1 - 1 ; cst1 := cst1 + 1 ) ; var csp2 : int ; csp2 := 1 ; while (csp2 <= nsp2) do ( OclFile["System.out"].print(" ") ; csp2 := csp2 + 1 ) ; if (row /= 1 & row /= n) then ( var cst2 : int ; cst2 := 1 ; while (cst2 <= nst) do ( OclFile["System.out"].print(val2 + " ") ; val2 := val2 + 1 ; cst2 := cst2 + 1 ) ) else skip ; OclFile["System.out"].println() ; if (row <= n / 2) 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 ; ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 7 ; execute drawPattern(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class esep { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int cases=sc.nextInt(); while(cases-->0){ int days=sc.nextInt(); int rost=1 ; int bust=0 ; int smert=0 ; for(int i=0 ; i=2){ rost+=5 ; } } else if(x==0){ ++smert ; bust=0 ; if(smert==2){ rost=-1 ; } } } System.out.println(rost); } } } ------------------------------------------------------------ OCL File: --------- class esep { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var cases : int ; cases := sc.getCurrent()->toInteger() ; while (cases > 0) do ( cases := cases - 1 ; skip ; ( var days : int ; days := sc.getCurrent()->toInteger() ; var rost : int ; rost := 1 ; var bust : int ; bust := 0 ; var smert : int ; smert := 0 ; var i : int ; i := 0 ; while i < days do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (rost = -1) then ( continue ) else skip ; if (x = 1) then ( smert := 0 ; bust := bust + 1 ; if (bust < 2) then ( rost := rost + 1 ) else skip ; if (bust >= 2) then ( rost := rost+(5) ) else skip ) else if (x = 0) then ( smert := smert + 1 ; bust := 0 ; if (smert = 2) then ( rost := -1 ) else skip ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(rost) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { int binarySearch(int arr[],int l,int r,int x){ if(r>=l){ int mid=l+(r-l)/2 ; if(arr[mid]==x)return mid ; if(mid>l && 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 ; } public static void main(String args[]){ GFG ob=new GFG(); int arr[]={ 3,2,10,4,40 }; int n=arr.length ; int x=4 ; int result=ob.binarySearch(arr,0,n-1,x); if(result==-1)System.out.println("Element is not present in array"); else System.out.println("Element is present at index "+result); } } ------------------------------------------------------------ OCL File: --------- class GFG { operation binarySearch( arr : Sequence(int), l : int, r : int, x : int) : int pre: true post: true activity: ( if (r >= l) then ( var mid : int ; mid := l + (r - l) / 2 ; if (arr[mid+1] = x) then return mid else skip ; if (mid > l & arr[mid - 1+1] = x) then return (mid - 1) else skip ; if (mid < r & arr[mid + 1+1] = x) then return (mid + 1) else skip ; if (arr[mid+1] > x) then return binarySearch(arr, l, mid - 2, x) else skip ; return binarySearch(arr, mid + 2, r, x) ) else skip ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ob : GFG ; ob := GFG.newGFG() ; var arr : Sequence(int) ; arr := Sequence{3,2,10,4,40} ; var n : int ; n := arr->size() ; var x : int ; x := 4 ; var result : int ; result := ob.binarySearch(arr, 0, n - 1, x) ; if (result = -1) then OclFile["System.out"].println("Element is not present in array") else OclFile["System.out"].println("Element is present at index " + result) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static String solve(int[] arr){ int n=arr.length ; int b1=arr[0]; boolean foundZero=false ; for(int i=1 ; i0){ int n=sc.nextInt(); int[] a=new int[n]; long preSum=0 ; boolean ok=true ; boolean flag=false ; for(int i=0 ; isize() ; var b1 : int ; b1 := arr[0+1] ; var foundZero : boolean ; foundZero := false ; var i : int ; i := 1 ; while i < n do ( ( if (foundZero & arr[i+1] /= 0) then ( return "NO" ) else skip ; b1 := b1+(arr[i+1]) ; if (b1 < 0) then ( return "NO" ) else skip ; if (b1 = 0) then ( foundZero := true ) else skip ) ; i := i + 1 ) ; return "YES" ); static operation main( str : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var preSum : long ; preSum := 0 ; var ok : boolean ; ok := true ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; if (flag & a[i+1] /= 0) then ok := false ; else skip ; preSum := preSum+(a[i+1]) ; if (preSum < 0) then ok := false ; else skip ; if (preSum = 0) then ( flag := true ) else skip ; ) ; i := i + 1 ) ; if (preSum /= 0) then OclFile["System.out"].println("no") else ( if (ok) then OclFile["System.out"].println("yes") ; else OclFile["System.out"].println("no") ; ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] a=new int[n]; long preSum=0 ; boolean ok=true ; boolean flag=false ; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var preSum : long ; preSum := 0 ; var ok : boolean ; ok := true ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; if (flag & a[i+1] /= 0) then ok := false ; else skip ; preSum := preSum+(a[i+1]) ; if (preSum < 0) then ok := false ; else skip ; if (preSum = 0) then ( flag := true ) else skip ; ) ; i := i + 1 ) ; if (preSum /= 0) then OclFile["System.out"].println("no") else ( if (ok) then OclFile["System.out"].println("yes") ; else OclFile["System.out"].println("no") ; ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class A1630 { public static void main(String[] args){ Scanner in=new Scanner(System.in); StringBuilder out=new StringBuilder(); int T=in.nextInt(); for(int t=0 ; tmap=new HashMap<>(); for(int n=0 ; nentry : map.entrySet()){ out.append(entry.getKey()).append(' ').append(entry.getValue()).append('\n'); } } } System.out.print(out); } } ------------------------------------------------------------ OCL File: --------- class A1630 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : String ; out := StringLib.newString() ; var T : int ; T := in.getCurrent()->toInteger() ; var t : int ; t := 0 ; while t < T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; if (N = 4 & K = 3) then ( out := out + StringLib.newString("-1\n") ) else ( var map : Map(int,int) ; map := Map{} ; var n : int ; n := 0 ; while n < N / 2 do ( ( map := map->union(Map{n |-> N - 1 - n}) ) ; n := n + 1 ) ; if (K /= 0) then ( var forLast : int ; forLast := if (K = N - 1) then (N - 2) else K endif ; map := map->antirestrict(Set{forLast}) ; map := map->antirestrict(Set{N - 1 - forLast}) ; map := map->union(Map{0 |-> N - 1 - forLast}) ; map := map->union(Map{forLast |-> N - 1}) ; if (K = N - 1) then ( map := map->antirestrict(Set{3}) ; map := map->union(Map{0 |-> N - 4}) ; map := map->union(Map{1 |-> 3}) ) else skip ; ) else skip ; for (entry : map->asSet()) do ( ( out := out + StringLib.newString(entry.getKey()) + StringLib.newString(' ') + StringLib.newString(entry.getValue()) + StringLib.newString(' ') ) ) ) ) ; t := t + 1 ) ; OclFile["System.out"].print(out) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static class Node { int data ; Node next ; }; static Node push(Node head_ref,int new_data){ Node new_node=new Node(); new_node.data=new_data ; new_node.next=(head_ref); (head_ref)=new_node ; return head_ref ; } static int productOfNodes(Node head){ Node ptr=head ; int product=1 ; while(ptr!=null){ product*=ptr.data ; ptr=ptr.next ; } return product ; } public static void main(String args[]){ Node head=null ; head=push(head,7); head=push(head,6); head=push(head,8); head=push(head,4); head=push(head,1); System.out.println("Product="+productOfNodes(head)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static class Node { attribute data : int; attribute next : Node; } static operation push( head_ref : Node, new_data : int) : Node pre: true post: true activity: ( var new_node : Node ; new_node := Node.newNode() ; new_node.data := new_data ; new_node.next := (head_ref) ; (head_ref) := new_node ; return head_ref ); static operation productOfNodes( head : Node) : int pre: true post: true activity: ( var ptr : Node ; ptr := head ; var product : int ; product := 1 ; while (ptr /= null) do ( product := product*(ptr.data) ; ptr := ptr.next ) ; return product ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var head : Node ; head := null ; head := push(head, 7) ; head := push(head, 6) ; head := push(head, 8) ; head := push(head, 4) ; head := push(head, 1) ; OclFile["System.out"].println("Product=" + productOfNodes(head)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static void solve(int n,int k,int[] needs,int[][] wants){ for(int i=0 ; ineeds[i]){ System.out.println("No"); return ; } } System.out.println("Yes"); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); int k=sc.nextInt(); if(n==0 && k==0)break ; int[] needs=new int[k]; for(int i=0 ; i needs[i+1]) then ( OclFile["System.out"].println("No") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; if (n = 0 & k = 0) then break else skip ; var needs : Sequence(int) ; needs := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < k do ( needs[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var wants : Sequence(Sequence(int)) ; wants := Integer.subrange(1,n)->collect(Integer.subrange(1,k)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < k do ( wants[i+1][j+1] := sc.getCurrent()->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; execute solve(n, k, needs, wants) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ExpansionCoefficient { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] values=new int[n]; for(int i=0 ; itoInteger() ; var values : Sequence(int) ; values := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( values[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var pos : Sequence(int) ; pos := Integer.subrange(1,n)->collect(0) ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( pos[i+1] := values[i+1] / (Set{n - i - 1, i}->max()) ; min := Set{min, pos[i+1]}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class test { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Pair[] a=new Pair[sc.nextInt()]; for(int i=0 ; i(){ public int compare(Pair p1,Pair p2){ return(p1.valtoInteger())->collect(null) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := Map(sc.getCurrent()->toInteger(), i) ) ; i := i + 1 ) ; a := OclComparator.sortWith(a, OclComparator.newOclComparator()) ; var k : int ; k := 2147483647 ; var minIndex : int ; minIndex := a[0+1].originalIndex ; var maxIndex : int ; maxIndex := a[0+1].originalIndex ; var i : int ; i := 1 ; while i < a->size() do ( ( var min : int ; min := Set{a[i+1].val / (if a[i+1].originalIndex - minIndex < 0 then -(a[i+1].originalIndex - minIndex) else a[i+1].originalIndex - minIndex endif), a[i+1].val / (if a[i+1].originalIndex - maxIndex < 0 then -(a[i+1].originalIndex - maxIndex) else a[i+1].originalIndex - maxIndex endif)}->min() ; k := Set{k, min}->min() ; minIndex := Set{minIndex, a[i+1].originalIndex}->min() ; maxIndex := Set{maxIndex, a[i+1].originalIndex}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(k) ; ); } class Pair { attribute val : int; static operation newPair( v : int, oI : int) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(v, oI); return self ); operation initialise( v : int, oI : int) : void pre: true post: true activity: ( self.val := v ; self.originalIndex := oI ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { long INF=Long.MAX_VALUE ; public static void main(String[] args){ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); String X=sc.next(); char[] x=X.toCharArray(); long ans=0 ; long c=0 ; for(int i=0 ; itoLong(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : String ; X := sc.getCurrent() ; var x : Sequence(String) ; x := X->characters() ; var ans : long ; ans := 0 ; var c : long ; c := 0 ; var i : int ; i := 0 ; while i < X->size() do ( ( if (x[i+1] = 'T') then ( c := c - 1 ; if (c < 0) then ( ans := ans + 1 ; c := 0 ) else skip ) else ( c := c + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans + c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Stack ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,InputReader in,PrintWriter out){ Stacks=new Stack<>(); String inp=in.next(); int ans=inp.length(); for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < inp->size() do ( ( if (inp->at(i+1) = 'S') then ( s := s->append(inp->at(i+1)) ) else if (not(s->isEmpty())) then ( s := s->front() ; ans := ans-(2) ) else skip ; ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static boolean[][] used ; static int[] ans ; public static void main(String[] args)throws Exception { FastScanner sc=new FastScanner(System.in); PrintWriter out=new PrintWriter(System.out); char[] s=sc.next().toCharArray(); int cnt=0 ; StringBuilder sb=new StringBuilder(); for(char c : s){ if(c=='T'){ if(cnt==0){ sb.append("T"); } else { cnt--; } } else { cnt++; } } System.out.println(sb.length()+cnt); } } class FastScanner { private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public FastScanner(InputStream in){ reader=new BufferedReader(new InputStreamReader(in)); tokenizer=null ; } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { return reader.readLine(); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong(){ return Long.parseLong(next()); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public int[] nextIntArray(int n){ int[] a=new int[n]; for(int i=0 ; icharacters() ; var cnt : int ; cnt := 0 ; var sb : String ; sb := StringLib.newString() ; for (c : s) do ( ( if (c = 'T') then ( if (cnt = 0) then ( sb := sb + StringLib.newString("T") ) else ( cnt := cnt - 1 ) ) else ( cnt := cnt + 1 ) ) ) ; OclFile["System.out"].println(sb->size() + cnt) ; ); } class FastScanner { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newFastScanner( in : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.next() ); operation nextLine() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( return reader.readLine() ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.nextToken("\n") ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLongArray( n : int) : Sequence(long) pre: true post: true activity: ( var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextLong() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder sb=new StringBuilder(); int t=fs.nextInt(); while(t-->0){ int n=fs.nextInt(); int[] a=fs.readArray(n); int chz=0,cho=0,s=1 ; for(int i=0 ; i=2){ s+=5 ; } } sb.append(s).append("\n"); } System.out.print(sb); out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; i 0) do ( t := t - 1 ; skip ; ( var n : int ; n := fs.nextInt() ; var a : Sequence(int) ; a := fs.readArray(n) ; var chz : int ; chz := 0 ; var cho : int ; cho := 0 ; var s : int ; s := 1 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] = 0) then ( cho := 0 ; chz := chz + 1 ) else ( chz := 0 ; cho := cho + 1 ) ; if (chz = 2) then ( s := -1 ; break ) else skip ; if (cho = 1) then s := s+(1) ; else skip ; if (cho >= 2) then ( s := s+(5) ) else skip ) ; i := i + 1 ) ; sb := sb + StringLib.newString(s) + StringLib.newString("\n") ; ) ; ) ; OclFile["System.out"].print(sb) ; skip ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayDeque ; import java.util.Deque ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str[]=br.readLine().split(""); Dequestack=new ArrayDeque<>(); for(int i=0 ; isplit("") ; var stack : Sequence(String) ; stack := ArrayDeque.newArrayDeque() ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str[i+1] = "S") then ( stack := stack->append(str[i+1]) ) else if (str[i+1] = "T") then ( if (stack->isEmpty()) then ( stack := stack->append(str[i+1]) ) else if (stack->min() = "T") then ( stack := stack->append(str[i+1]) ) else ( stack := stack->front() ) ; ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(stack->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintStream ; import java.util.Arrays ; import java.util.Scanner ; public class Main { static final PrintStream so=System.out ; static final Scanner sc=new Scanner(System.in); public static void main(String[] args){ char[] x=nsToChars(); int len=x.length ; int countST=0 ; int countS=0 ; for(int i=0 ; i0){ countS--; countST++; } } so.println(len-countST*2); } static int ni(){ return sc.nextInt(); } static long nl(){ return sc.nextLong(); } static char[] nsToChars(){ return sc.next().toCharArray(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute so : OclFile := OclFile["System.out"]; static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : Sequence(String) ; x := nsToChars() ; var len : int ; len := x->size() ; var countST : int ; countST := 0 ; var countS : int ; countS := 0 ; var i : int ; i := 0 ; while i < len do ( ( if (x[i+1] = 'S') then ( countS := countS + 1 ) else if (countS > 0) then ( countS := countS - 1 ; countST := countST + 1 ) else skip ; ) ; i := i + 1 ) ; skip ; ); static operation ni() : int pre: true post: true activity: ( return sc.getCurrent()->toInteger() ); static operation nl() : long pre: true post: true activity: ( return sc.getCurrent()->toLong() ); static operation nsToChars() : Sequence(String) pre: true post: true activity: ( return sc.getCurrent()->characters() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int i=1 ; int x=1 ; while(true){ x=sc.nextInt(); if(x==0)break ; System.out.printf("Case %d: %d\n",i,x); i++; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var i : int ; i := 1 ; var x : int ; x := 1 ; while (true) do ( x := sc.getCurrent()->toInteger() ; if (x = 0) then break else skip ; OclFile["System.out"].printf("Case %d: %d\n", i, x) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; class Main { public static void main(String[] args){ int index=0 ; ArrayListar=new ArrayList(); java.util.Scanner scanner=new java.util.Scanner(System.in); while(true){ int num=scanner.nextInt(); ar.add(num); if(num==0){ break ; } index++; } for(int i=0 ; iincluding(num) ; if (num = 0) then ( break ) else skip ; index := index + 1 ) ; var i : int ; i := 0 ; while i < index do ( ( var num : int ; num := i + 1 ; OclFile["System.out"].println("Case " + num + ": " + ar->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); DAxisParallelRectangle solver=new DAxisParallelRectangle(); solver.solve(1,in,out); out.close(); } static class DAxisParallelRectangle { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); int k=in.nextInt(); long[] x=new long[n]; long[] y=new long[n]; for(int i=0 ; i=k){ long s=(x[m]-x[i])*(y[j]-y[l]); min=Math.min(min,s); } } } } } out.println(min); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : DAxisParallelRectangle ; solver := DAxisParallelRectangle.newDAxisParallelRectangle() ; solver.solve(1, in, out) ; skip ; ); static class DAxisParallelRectangle { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var x : Sequence(long) ; x := Integer.subrange(1,n)->collect(0) ; var y : Sequence(long) ; y := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := in.getCurrent()->toLong() ; y[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; var min : long ; min := "9223372036854775807"->toLong() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( var l : int ; l := 0 ; while l < n do ( ( var m : int ; m := 0 ; while m < n do ( ( var cnt : int ; cnt := 0 ; var o : int ; o := 0 ; while o < n do ( ( if (x[i+1] <= x[o+1] & x[o+1] <= x[m+1] & y[l+1] <= y[o+1] & y[o+1] <= y[j+1]) then ( cnt := cnt + 1 ) else skip ) ; o := o + 1 ) ; if (cnt >= k) then ( var s : long ; s := (x[m+1] - x[i+1]) * (y[j+1] - y[l+1]) ; min := Set{min, s}->min() ) else skip ) ; m := m + 1 ) ) ; l := l + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args){ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String buf ; int i=1 ; try { while((buf=reader.readLine())!=null){ int num=Integer.parseInt(buf); if(num==0){ break ; } else { System.out.println("Case "+i+": "+num); i++; } } } catch(IOException e){ System.out.println(e); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var buf : String ; var i : int ; i := 1 ; try ( buf := reader.readLine() ; while ((buf) /= null) do ( skip ; ( var num : int ; num := (buf)->toInteger() ; if (num = 0) then ( break ) else ( OclFile["System.out"].println("Case " + i + ": " + num) ; i := i + 1 ) ) ; buf := reader.readLine() ; ) ) catch (e : IOException) do ( OclFile["System.out"].println(e) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int i=1 ; for(; ; i++){ String str=sc.next(); if(str.equals("0"))break ; else System.out.printf("Case %d: %s\n",i,str); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var i : int ; i := 1 ; while true do ( ( var str : String ; str := sc.getCurrent() ; if (str = "0") then break else OclFile["System.out"].printf("Case %d: %s\n", i, str) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ int[] x=new int[10000000]; int i=0 ; int j ; Scanner sc=new Scanner(System.in); x[0]=sc.nextInt(); for(i=1 ; x[i-1]!=0 ; i++){ x[i]=sc.nextInt(); j=i+1 ; } int k ; for(k=0 ; kcollect(0) ; var i : int ; i := 0 ; var j : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; x[0+1] := sc.getCurrent()->toInteger() ; i := 1 ; while x[i - 1+1] /= 0 do ( ( x[i+1] := sc.getCurrent()->toInteger() ; j := i + 1 ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < i - 1 do ( ( OclFile["System.out"].println("Case " + (k + 1) + ": " + x[k+1]) ) ; k := k + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class amd { public static void main(String args[]){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ String str=s.next(); HashMaphs=new HashMap(); for(int i=0 ; i1){ hs.put(c,hs.get(c)-1); } else { System.out.println(str.substring(i)); break ; } } } } } ------------------------------------------------------------ OCL File: --------- class amd { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var str : String ; str := s.getCurrent() ; var hs : Map(String,int) ; hs := Map{} ; var i : int ; i := 0 ; while i < str->size() do ( ( var c : String ; c := str->at(i+1) ; hs := hs->union(Map{c |-> (if hs->keys()->contains(c) then hs->at(c) else 0 endif) + 1}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < str->size() do ( ( var c : String ; c := str->at(i+1) ; var a : int ; a := hs->at(c) ; if (a > 1) then ( hs := hs->union(Map{c |-> hs->at(c) - 1}) ) else ( OclFile["System.out"].println(str.subrange(i+1,i)) ; break ) ) ; i := i + 1 ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B1654 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int t=0 ; t1){ stat[S[i]-'a']--; i++; } System.out.println(new String(S,i,S.length-i)); } } } ------------------------------------------------------------ OCL File: --------- class B1654 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := in.getCurrent()->toInteger() ; var t : int ; t := 0 ; while t < T do ( ( var S : Sequence(String) ; S := in.getCurrent()->characters() ; var stat : Sequence(int) ; stat := Integer.subrange(1,26)->collect(0) ; for (c : S) do ( ( stat[c - ('a')->char2byte()+1] := stat[c - ('a')->char2byte()+1] + 1 ) ) ; var i : int ; i := 0 ; while (stat[S[i+1] - ('a')->char2byte()+1] > 1) do ( stat[S[i+1] - ('a')->char2byte()+1] := stat[S[i+1] - ('a')->char2byte()+1] - 1 ; i := i + 1 ) ; OclFile["System.out"].println(StringLib.newString(S, i, S->size() - i)) ; ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.nio.ByteBuffer ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[][] f=new int[n][10]; int[][] p=new int[n][11]; for(int i=0 ; i=0 ; j--){ b[j]=mi/(int)Math.pow(2,j); mi-=b[j]*(int)Math.pow(2,j); } for(int j=0 ; jans){ ans=score ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var f : Sequence(Sequence(int)) ; f := Integer.subrange(1,n)->collect(Integer.subrange(1,10)->collect(0)) ; var p : Sequence(Sequence(int)) ; p := Integer.subrange(1,n)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 10 do ( ( f[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 11 do ( ( p[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; var ans : int ; ans := -1000000007 ; var i : int ; i := 1 ; while i < 1024 do ( ( var score : int ; score := 0 ; var num : int ; num := 0 ; var b : Sequence(int) ; b := Integer.subrange(1,10)->collect(0) ; var mi : int ; mi := i ; var j : int ; j := 9 ; while j >= 0 do ( ( b[j+1] := mi / 2->pow(j)->oclAsType(int) ; mi := mi-(b[j+1] * 2->pow(j)->oclAsType(int)) ) ; j := j - 1 ) ; var j : int ; j := 0 ; while j < n do ( ( num := 0 ; var k : int ; k := 0 ; while k < 10 do ( ( if (f[j+1][k+1] = 1 & b[k+1] = 1) then ( num := num + 1 ) else skip ) ; k := k + 1 ) ; score := score+(p[j+1][num+1]) ) ; j := j + 1 ) ; if (score > ans) then ( ans := score ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int a[]=new int[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var len : int ; len := 1 + a[0+1] ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] = 1 & a[i - 1+1] = 1) then ( len := len+(5) ) else if (a[i+1] = 1) then ( len := len+(1) ) else if (a[i+1] = 0 & a[i - 1+1] = 0) then ( len := -1 ; break ) else skip ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(len) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; class Main { public static final int MOD=1000000007 ; public static final int INF=1000000000 ; public static void main(String[] args){ Scanner sc=new Scanner(in); int N=sc.nextInt(); Integer F[][]=new Integer[N][10]; Integer P[][]=new Integer[N][11]; for(int i=0 ; i>j & 1); } tmp+=P[k][count]; } ans=Math.max(ans,tmp); } out.println(ans); } public static int gcd(int a,int b){ if(b==0)return a ; return gcd(b,a % b); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : int := 1000000007; static attribute INF : int := 1000000000; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var N : int ; N := sc.getCurrent()->toInteger() ; var F : Sequence(Sequence(int)) ; F := Integer.subrange(1,N)->collect(Integer.subrange(1,10)->collect(null)) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(null)) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < 10 do ( ( F[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < 11 do ( ( P[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := -INF ; var i : int ; i := 1 ; while i < ((1*(2->pow(10)))->oclAsType(long)) do ( ( var tmp : int ; tmp := 0 ; var k : int ; k := 0 ; while k < N do ( ( var count : int ; count := 0 ; var j : int ; j := 0 ; while j < 10 do ( ( count := count+(F[k+1][j+1] & (MathLib.bitwiseAnd((i/(2->pow(j)))->oclAsType(long),1))) ) ; j := j + 1 ) ; tmp := tmp+(P[k+1][count+1]) ) ; k := k + 1 ) ; ans := Set{ans, tmp}->max() ) ; i := i + 1 ) ; out.println(ans) ; ); static 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) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ int N=Integer.parseInt(br.readLine()); int[] F=new int[N]; for(int i=0 ; itoInteger() ; var F : Sequence(int) ; F := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( F[i+1] := (br.readLine().replaceAllMatches(" ", "" ))->toInteger() ) ; i := i + 1 ) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var mask : int ; mask := 1 ; while mask <= 0b11 try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var N : int ; N := (br.readLine())->toInteger() ; var F : Sequence(int) ; F := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( F[i+1] := (br.readLine().replaceAllMatches(" ", "" ))->toInteger() ) ; i := i + 1 ) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var mask : int ; mask := 1 ; while mask <= 0b11 try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var N : int ; N := (br.readLine())->toInteger() ; var F : Sequence(int) ; F := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( F[i+1] := (br.readLine().replaceAllMatches(" ", "" ))->toInteger() ) ; i := i + 1 ) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var mask : int ; mask := 1 ; while mask <= 0b11_1111_1111 do ( ( var value : int ; value := 0 ; var i : int ; i := 0 ; while i < N do ( ( var order : int ; order := MathLib.bitwiseAnd(mask,F[i+1]) ; value := value+(P[i+1][bitCount(order)+1]) ) ; i := i + 1 ) ; max := Set{max, value}->max() ) ; mask := mask + 1 ) ; OclFile["System.out"].println(max) ; )) 111 try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var N : int ; N := (br.readLine())->toInteger() ; var F : Sequence(int) ; F := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( F[i+1] := (br.readLine().replaceAllMatches(" ", "" ))->toInteger() ) ; i := i + 1 ) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var mask : int ; mask := 1 ; while mask <= 0b11_1111_1111 do ( ( var value : int ; value := 0 ; var i : int ; i := 0 ; while i < N do ( ( var order : int ; order := MathLib.bitwiseAnd(mask,F[i+1]) ; value := value+(P[i+1][bitCount(order)+1]) ) ; i := i + 1 ) ; max := Set{max, value}->max() ) ; mask := mask + 1 ) ; OclFile["System.out"].println(max) ; )) 111 do ( ( var value : int ; value := 0 ; var i : int ; i := 0 ; while i < N do ( ( var order : int ; order := MathLib.bitwiseAnd(mask,F[i+1]) ; value := value+(P[i+1][bitCount(order)+1]) ) ; i := i + 1 ) ; max := Set{max, value}->max() ) ; mask := mask + 1 ) ; OclFile["System.out"].println(max) ; )) 111 try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var N : int ; N := (br.readLine())->toInteger() ; var F : Sequence(int) ; F := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( F[i+1] := (br.readLine().replaceAllMatches(" ", "" ))->toInteger() ) ; i := i + 1 ) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var mask : int ; mask := 1 ; while mask <= 0b11 try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var N : int ; N := (br.readLine())->toInteger() ; var F : Sequence(int) ; F := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( F[i+1] := (br.readLine().replaceAllMatches(" ", "" ))->toInteger() ) ; i := i + 1 ) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var mask : int ; mask := 1 ; while mask <= 0b11_1111_1111 do ( ( var value : int ; value := 0 ; var i : int ; i := 0 ; while i < N do ( ( var order : int ; order := MathLib.bitwiseAnd(mask,F[i+1]) ; value := value+(P[i+1][bitCount(order)+1]) ) ; i := i + 1 ) ; max := Set{max, value}->max() ) ; mask := mask + 1 ) ; OclFile["System.out"].println(max) ; )) 111 try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var N : int ; N := (br.readLine())->toInteger() ; var F : Sequence(int) ; F := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( F[i+1] := (br.readLine().replaceAllMatches(" ", "" ))->toInteger() ) ; i := i + 1 ) ; var P : Sequence(Sequence(int)) ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,11)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := stream(br.readLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var mask : int ; mask := 1 ; while mask <= 0b11_1111_1111 do ( ( var value : int ; value := 0 ; var i : int ; i := 0 ; while i < N do ( ( var order : int ; order := MathLib.bitwiseAnd(mask,F[i+1]) ; value := value+(P[i+1][bitCount(order)+1]) ) ; i := i + 1 ) ; max := Set{max, value}->max() ) ; mask := mask + 1 ) ; OclFile["System.out"].println(max) ; )) 111 do ( ( var value : int ; value := 0 ; var i : int ; i := 0 ; while i < N do ( ( var order : int ; order := MathLib.bitwiseAnd(mask,F[i+1]) ; value := value+(P[i+1][bitCount(order)+1]) ) ; i := i + 1 ) ; max := Set{max, value}->max() ) ; mask := mask + 1 ) ; OclFile["System.out"].println(max) ; )) 111 do ( ( var value : int ; value := 0 ; var i : int ; i := 0 ; while i < N do ( ( var order : int ; order := MathLib.bitwiseAnd(mask,F[i+1]) ; value := value+(P[i+1][bitCount(order)+1]) ) ; i := i + 1 ) ; max := Set{max, value}->max() ) ; mask := mask + 1 ) ; OclFile["System.out"].println(max) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int DAYS=5 ; int TIME=2 ; int[][][] F=new int[N][DAYS][TIME]; for(int n=0 ; n>d1*TIME)& 3 ; for(int t1=0 ; t1

(n/2)){ x+=1<m=new HashMap(); int maxt=1 ; for(int i=0 ; ival : m.entrySet()){ if(maxtkeys()->includes(a[i+1] - i * d)) then ( var freq : int ; freq := m->at(a[i+1] - i * d) ; freq := freq + 1 ; m := m->union(Map{a[i+1] - i * d |-> freq}) ) else ( m := m->union(Map{a[i+1] - i * d |-> 1}) ) ) ; i := i + 1 ) ; for (val : m->asSet()) do ( ( if (maxt < val.getValue()) then maxt := val.getValue() ; else skip ) ) ; return maxt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; var d : int ; d := 3 ; var a : Sequence(int) ; a := Sequence{1,4,2,5,20,11,56,100,20,23} ; OclFile["System.out"].print(maxlenAP(a, n, d) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void type1(int[] arr,int start,int limit){ for(int i=start ; i<=limit ; i++)arr[i]++; } static void type2(int[] arr,int[][] query,int start,int limit){ for(int i=start ; i<=limit ; i++){ if(query[i][0]==1)type1(arr,query[i][1],query[i][2]); else if(query[i][0]==2)type2(arr,query,query[i][1],query[i][2]); } } public static void main(String[] args){ int n=5,m=5 ; int[] arr=new int[n+1]; int[] temp={ 1,1,2,1,4,5,2,1,2,2,1,3,2,3,4 }; int[][] query=new int[6][4]; int j=0 ; for(int i=1 ; i<=m ; i++){ query[i][0]=temp[j++]; query[i][1]=temp[j++]; query[i][2]=temp[j++]; } for(int i=1 ; i<=m ; i++)if(query[i][0]==1)type1(arr,query[i][1],query[i][2]); else if(query[i][0]==2)type2(arr,query,query[i][1],query[i][2]); for(int i=1 ; i<=n ; i++)System.out.print(arr[i]+" "); System.out.println(); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation type1( arr : Sequence(int), start : int, limit : int) : void pre: true post: true activity: ( var i : int ; i := start ; while i <= limit do ( arr[i+1] := arr[i+1] + 1 ; ; i := i + 1 ) ); static operation type2( arr : Sequence(int), query : Sequence(Sequence(int)), start : int, limit : int) : void pre: true post: true activity: ( var i : int ; i := start ; while i <= limit do ( ( if (query[i+1][0+1] = 1) then execute type1(arr, query[i+1][1+1], query[i+1][2+1]) ; else if (query[i+1][0+1] = 2) then execute type2(arr, query, query[i+1][1+1], query[i+1][2+1]) ; else skip ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var m : int ; m := 5 ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var temp : Sequence(int) ; temp := Sequence{1,1,2,1,4,5,2,1,2,2,1,3,2,3,4} ; var query : Sequence(Sequence(int)) ; query := Integer.subrange(1,6)->collect(Integer.subrange(1,4)->collect(0)) ; var j : int ; j := 0 ; var i : int ; i := 1 ; while i <= m do ( ( query[i+1][0+1] := 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 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= m do ( if (query[i+1][0+1] = 1) then execute type1(arr, query[i+1][1+1], query[i+1][2+1]) else if (query[i+1][0+1] = 2) then execute type2(arr, query, query[i+1][1+1], query[i+1][2+1]) ; else skip ; ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class Odd_Selection { public static void main(String[] args)throws Exception { InputStreamReader r=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); PrintWriter p=new PrintWriter(System.out); int test=1 ; me146 : while(test-->0){ String str[]=br.readLine().trim().split(" "); int n=Integer.parseInt(str[0]); str=br.readLine().trim().split(" "); int a[]=new int[n+1]; for(int i=0 ; i=0 ; i--){ if(isPossible(a,i,n)){ answer=i ; break ; } } p.print(answer); } p.flush(); } static boolean isPossible(int a[],int target,int n){ for(int i=0 ; i+target<=n ; i++){ int val=a[i+target]-a[i]; if(val>target*100){ return true ; } } return false ; } } ------------------------------------------------------------ OCL File: --------- class Odd_Selection { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(r) ; var p : OclFile ; p := OclFile.newOclFile_Write(OclFile["System.out"]) ; var test : int ; test := 1 ; while (test > 0) do ( test := test - 1 ; skip ; ( var str : Sequence(String) ; str := br.readLine()->trim()->split(" ") ; var n : int ; n := (str[0+1])->toInteger() ; str := br.readLine()->trim()->split(" ") ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i + 1+1] := (str[i+1])->toInteger() ; a[i + 1+1] := a[i + 1+1]+(a[i+1]) ) ; i := i + 1 ) ; var answer : int ; answer := 0 ; var i : int ; i := n ; while i >= 0 do ( ( if (isPossible(a, i, n)) then ( answer := i ; break ) else skip ) ; i := i - 1 ) ; skip ; ) ; ) ; skip ; ); static operation isPossible( a : Sequence(int), target : int, n : int) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i + target <= n do ( ( var val : int ; val := a[i + target+1] - a[i+1] ; if (val > target * 100) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class DDoS { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); String[] temp=br.readLine().split(" "); int[] nums=new int[n]; for(int i=0 ; i=1 ; len--){ if(check(preSum,len)){ pr.println(len); return ; } } pr.println(0); } public static boolean check(int[] preSum,int len){ int minRequired=len*100 ; int n=preSum.length-1 ; for(int i=0 ; i+len-1minRequired){ return true ; } } return false ; } } ------------------------------------------------------------ OCL File: --------- class DDoS { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pr : OclFile ; pr := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve(br, pr) ; skip ; skip ; ); static operation solve( br : OclFile, pr : OclFile) : void pre: true post: true activity: ( var n : int ; n := (br.readLine())->toInteger() ; var temp : Sequence(String) ; temp := br.readLine()->split(" ") ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := (temp[i+1])->toInteger() ) ; i := i + 1 ) ; var preSum : Sequence(int) ; preSum := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( preSum[i + 1+1] := preSum[i+1] + nums[i+1] ) ; i := i + 1 ) ; var len : int ; len := n ; while len >= 1 do ( ( if (check(preSum, len)) then ( skip ; return ) else skip ) ; len := len - 1 ) ; skip ; ); static operation check( preSum : Sequence(int), len : int) : boolean pre: true post: true activity: ( var minRequired : int ; minRequired := len * 100 ; var n : int ; n := preSum->size() - 1 ; var i : int ; i := 0 ; while i + len - 1 < n do ( ( var sum : int ; sum := preSum[i + len+1] - preSum[i+1] ; if (sum > minRequired) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < T do ( ( var size : int ; size := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,size)->collect(0) ; var j : int ; j := 0 ; while j < size do ( ( arr[j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ; var ans : int ; ans := 1 ; if (arr[0+1] = 1) then ans := ans+(1) ; else skip ; var flag : boolean ; flag := false ; var j : int ; j := 1 ; while j < size do ( ( if (arr[j+1] = 1) then ( if (arr[j - 1+1] = 1) then ( ans := ans+(5) ) else ( ans := ans+(1) ) ) else ( if (arr[j - 1+1] = 0) then ( flag := true ; ans := -1 ; break ) else skip ) ) ; j := j + 1 ) ; if (flag) then ( OclFile["System.out"].println(ans) ) else ( OclFile["System.out"].println(ans) ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ int n=scanner.nextInt(); int c=scanner.nextInt(); if((n | c)==0)break ; int[] a=new int[n]; int[] b=new int[c]; for(int i=0 ; itoInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,c)) = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,c)->collect(0) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < 16 do ( a[i+1] := MathLib.bitwiseOr(a[i+1], ((scanner.getCurrent()->toInteger()*(2->pow(j)))->oclAsType(long))) ; ; j := j + 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < c do ( var j : int ; j := 0 ; while j < 16 do ( b[i+1] := MathLib.bitwiseOr(b[i+1], ((scanner.getCurrent()->toInteger()*(2->pow(j)))->oclAsType(long))) ; ; j := j + 1 ) ; ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,(1*(2->pow(16)))->oclAsType(long))->collect(0)) ; var i : int ; i := 0 ; while i <= n do ( dp[i+1] := dp[i+1]->collect(-1) ; ; i := i + 1 ) ; dp[0+1][0+1] := 0 ; var i : int ; i := 0 ; while i < n do ( ( var S : int ; S := 0 ; while S < (1*(2->pow(16)))->oclAsType(long) do ( ( if (dp[i+1][S+1] = -1) then continue else skip ; var light : int ; light := MathLib.bitwiseOr(S,a[i+1]) ; var j : int ; j := 0 ; while j < c do ( ( var pushed : int ; pushed := MathLib.bitwiseAnd(light,b[j+1]) ; var point : int ; point := bitCount(pushed) ; var nx : int ; nx := MathLib.bitwiseAnd(light,-(b[j+1] + 1)) ; if (dp[i + 1+1][nx+1] < point + dp[i+1][S+1]) then dp[i + 1+1][nx+1] := point + dp[i+1][S+1] ; else skip ) ; j := j + 1 ) ) ; S := S + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < (1*(2->pow(16)))->oclAsType(long) do ( max := Set{max, dp[n+1][i+1]}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ int n=scanner.nextInt(); int c=scanner.nextInt(); if((n | c)==0)break ; int[] a=new int[n]; int[] b=new int[c]; for(int i=0 ; itoInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,c)) = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,c)->collect(0) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < 16 do ( a[i+1] := a[i+1]+(((scanner.getCurrent()->toInteger()*(2->pow(j)))->oclAsType(long))) ; ; j := j + 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < c do ( var j : int ; j := 0 ; while j < 16 do ( b[i+1] := b[i+1]+(((scanner.getCurrent()->toInteger()*(2->pow(j)))->oclAsType(long))) ; ; j := j + 1 ) ; ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,(1*(2->pow(16)))->oclAsType(long))->collect(0)) ; var i : int ; i := 0 ; while i <= n do ( dp[i+1] := dp[i+1]->collect(-1) ; ; i := i + 1 ) ; dp[0+1][0+1] := 0 ; var i : int ; i := 0 ; while i < n do ( ( var S : int ; S := 0 ; while S < (1*(2->pow(16)))->oclAsType(long) do ( ( if (dp[i+1][S+1] = -1) then continue else skip ; var light : int ; light := MathLib.bitwiseOr(S,a[i+1]) ; var j : int ; j := 0 ; while j < c do ( ( var pushed : int ; pushed := MathLib.bitwiseAnd(light,b[j+1]) ; var point : int ; point := bitCount(pushed) ; var nx : int ; nx := MathLib.bitwiseAnd(light,-(b[j+1] + 1)) ; if (dp[i + 1+1][nx+1] < point + dp[i+1][S+1]) then dp[i + 1+1][nx+1] := point + dp[i+1][S+1] ; else skip ) ; j := j + 1 ) ) ; S := S + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < (1*(2->pow(16)))->oclAsType(long) do ( max := Set{max, dp[n+1][i+1]}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.*; import java.util.*; class Main { static int[] parents ; static int[] weight ; static int[] rank ; static int find(int x){ if(x==parents[x])return x ; else { int r=find(parents[x]); weight[x]+=weight[parents[x] ]; return parents[x]=r ; } } static int weight(int x){ find(x); return weight[x]; } static void relate(int x,int y,int z){ z+=weight(x); z-=weight(y); x=find(x); y=find(y); if(x==y)return ; if(rank[x]toInteger() ; var q : int ; q := scanner.getCurrent()->toInteger() ; parents := Integer.subrange(1,n)->collect(0) ; weight := Integer.subrange(1,n)->collect(0) ; rank := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( parents[i+1] := i ) ; i := i + 1 ) ; var type : int ; var x : int ; var y : int ; var z : int ; var i : int ; i := 0 ; while i < q do ( ( type := scanner.getCurrent()->toInteger() ; x := scanner.getCurrent()->toInteger() ; y := scanner.getCurrent()->toInteger() ; if (type = 0) then ( z := scanner.getCurrent()->toInteger() ; execute relate(x, y, z) ) else ( execute diff(x, y) ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxZeros(int n){ if(n==0 ||(n &(n-1))==0){ return-1 ; } byte b=4 ; int setBit=1,prev=0,i ; for(i=1 ; i<=b*8 ; i++){ prev++; if((n & setBit)==setBit){ setBit=setBit<<1 ; break ; } setBit=setBit<<1 ; } int max0=Integer.MIN_VALUE,cur=prev ; for(int j=i+1 ; j<=b*8 ; j++){ cur++; if((n & setBit)==setBit){ if(max0<(cur-prev-1)){ max0=cur-prev-1 ; } prev=cur ; } setBit=setBit<<1 ; } return max0 ; } static public void main(String[] args){ int n=549 ; System.out.println(maxZeros(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxZeros( n : int) : int pre: true post: true activity: ( if (n = 0 or (n & (n - 1)) = 0) then ( return -1 ) else skip ; var b : int ; b := 4 ; var setBit : int ; setBit := 1 ; var prev : int ; prev := 0 ; var i : int ; i := 1 ; while i <= b * 8 do ( ( prev := prev + 1 ; if ((n & setBit) = setBit) then ( setBit := (setBit*(2->pow(1)))->oclAsType(long) ; break ) else skip ; setBit := (setBit*(2->pow(1)))->oclAsType(long) ) ; i := i + 1 ) ; var max0 : int ; max0 := -2147483648 ; var cur : int ; cur := prev ; var j : int ; j := i + 1 ; while j <= b * 8 do ( ( cur := cur + 1 ; if ((n & setBit) = setBit) then ( if (max0 < (cur - prev - 1)) then ( max0 := cur - prev - 1 ) else skip ; prev := cur ) else skip ; setBit := (setBit*(2->pow(1)))->oclAsType(long) ) ; j := j + 1 ) ; return max0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 549 ; OclFile["System.out"].println(maxZeros(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ int n=scanner.nextInt(); int c=scanner.nextInt(); if((n | c)==0)break ; int[] a=new int[n]; int[] b=new int[c]; for(int i=0 ; itoInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,c)) = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,c)->collect(0) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < 16 do ( a[i+1] := a[i+1]+(((scanner.getCurrent()->toInteger()*(2->pow(j)))->oclAsType(long))) ; ; j := j + 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < c do ( var j : int ; j := 0 ; while j < 16 do ( b[i+1] := b[i+1]+(((scanner.getCurrent()->toInteger()*(2->pow(j)))->oclAsType(long))) ; ; j := j + 1 ) ; ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,(1*(2->pow(16)))->oclAsType(long))->collect(0)) ; var i : int ; i := 0 ; while i <= n do ( dp[i+1] := dp[i+1]->collect(-1) ; ; i := i + 1 ) ; dp[0+1][0+1] := 0 ; var i : int ; i := 0 ; while i < n do ( ( var S : int ; S := 0 ; while S < (1*(2->pow(16)))->oclAsType(long) do ( ( if (dp[i+1][S+1] = -1) then continue else skip ; var light : int ; light := MathLib.bitwiseOr(S,a[i+1]) ; var j : int ; j := 0 ; while j < c do ( ( var pushed : int ; pushed := MathLib.bitwiseAnd(light,b[j+1]) ; var point : int ; point := bitCount(pushed) + dp[i+1][S+1] ; var nx : int ; nx := MathLib.bitwiseAnd(light,-(b[j+1] + 1)) ; dp[i + 1+1][nx+1] := Set{dp[i + 1+1][nx+1], point}->max() ) ; j := j + 1 ) ) ; S := S + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < (1*(2->pow(16)))->oclAsType(long) do ( max := Set{max, dp[n+1][i+1]}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int[][] dp=new int[2][1<<16]; for(; ; ){ int n=sc.nextInt(),c=sc.nextInt(); if(n+c==0)break ; int[] a=new int[n],b=new int[c]; for(int i=0 ; icollect(Integer.subrange(1,(1*(2->pow(16)))->oclAsType(long))->collect(0)) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if (n + c = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,c)->collect(0) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < 16 do ( a[i+1] := ((a[i+1]*(2->pow(1)))->oclAsType(long)) + sc.getCurrent()->toInteger() ; ; j := j + 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < c do ( var j : int ; j := 0 ; while j < 16 do ( b[i+1] := ((b[i+1]*(2->pow(1)))->oclAsType(long)) + sc.getCurrent()->toInteger() ; ; j := j + 1 ) ; ; i := i + 1 ) ; dp[0+1] := dp[0+1]->collect(-1) ; dp[0+1][0+1] := 0 ; var X : int ; X := 1 ; var i : int ; i := 0 ; while i < n do ( ( dp[X+1] := dp[X+1]->collect(-1) ; var S : int ; S := 0 ; while S < (1*(2->pow(16)))->oclAsType(long) do ( if (dp[1 - X+1][S+1] /= -1) then ( var light : int ; light := MathLib.bitwiseOr(S,a[i+1]) ; var j : int ; j := 0 ; while j < c do ( ( var pushed : int ; pushed := MathLib.bitwiseAnd(light,b[j+1]) ; var point : int ; point := bitCount(pushed) ; var nx : int ; nx := MathLib.bitwiseAnd(light,-(pushed + 1)) ; dp[X+1][nx+1] := Set{dp[X+1][nx+1], dp[1 - X+1][S+1] + point}->max() ) ; j := j + 1 ) ) else skip ; ; S := S + 1 ) ) ; i := i + 1 ; X := 1 - X ) ; var res : int ; res := 0 ; var S : int ; S := 0 ; while S < (1*(2->pow(16)))->oclAsType(long) do ( res := Set{res, dp[1 - X+1][S+1]}->max() ; ; S := S + 1 ) ; OclFile["System.out"].println(res) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=1000001 ; static int factor[]; static void generatePrimeFactors(){ factor[1]=1 ; for(int i=2 ; icollect(0) ; factor[0+1] := 0 ; execute generatePrimeFactors() ; var a : Sequence(int) ; a := Sequence{10,30,100,450,987} ; var q : int ; q := a->size() ; var i : int ; i := 0 ; while i < q do ( OclFile["System.out"].print(calculateNoOFactors(a[i+1]) + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class p1372B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int d=1 ; for(int i=2 ; i*i<=n ; i++)if(n % i==0)d=Math.max(d,n/i); System.out.println(d+" "+(n-d)); } } } ------------------------------------------------------------ OCL File: --------- class p1372B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var d : int ; d := 1 ; var i : int ; i := 2 ; while i * i <= n do ( if (n mod i = 0) then d := Set{d, n / i}->max() ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(d + " " + (n - d)) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.*; public class vfe { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); int j=n ; for(int i=2 ; i*i<=n ; i++){ if(n % i==0){ j=i ; break ; } } out.println((n/j)+" "+(j-1)*(n/j)); } out.flush(); } } ------------------------------------------------------------ OCL File: --------- class vfe { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var j : int ; j := n ; var i : int ; i := 2 ; while i * i <= n do ( ( if (n mod i = 0) then ( j := i ; break ) else skip ) ; i := i + 1 ) ; skip ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import javafx.beans.property.IntegerProperty ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class LastClassofMath { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t!=0){ solve(br,pr); t--; } pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); if(n % 2==0){ pr.println(n/2+" "+n/2); return ; } else { int b=(int)Math.sqrt(n)+1 ; int largestFactor=1 ; while(b!=1){ if(n % b==0){ largestFactor=Math.max(largestFactor,Math.max(b,n/b)); } b--; } pr.println(largestFactor+" "+(n-largestFactor)); } } } ------------------------------------------------------------ OCL File: --------- class LastClassofMath { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pr : OclFile ; pr := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := (br.readLine())->toInteger() ; while (t /= 0) do ( execute solve(br, pr) ; t := t - 1 ) ; skip ; skip ; ); static operation solve( br : OclFile, pr : OclFile) : void pre: true post: true activity: ( var n : int ; n := (br.readLine())->toInteger() ; if (n mod 2 = 0) then ( skip ; return ) else ( var b : int ; b := (n)->sqrt()->oclAsType(int) + 1 ; var largestFactor : int ; largestFactor := 1 ; while (b /= 1) do ( if (n mod b = 0) then ( largestFactor := Set{largestFactor, Set{b, n / b}->max()}->max() ) else skip ; b := b - 1 ) ; skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static double PI=3.14 ; static double circle_inscribed(int a){ return PI*(a*a)/12 ; } public static void main(String[] args){ int a=4 ; System.out.println(circle_inscribed(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute PI : double := 3.14; static operation circle_inscribed( a : int) : double pre: true post: true activity: ( return PI * (a * a) / 12 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 4 ; OclFile["System.out"].println(circle_inscribed(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int r1=a,x1=1,y1=0,r2=b,x2=0,y2=1,r3,q,x3,y3 ; while(r2!=0){ q=r1/r2 ; r3=r1 % r2 ; x3=x1-q*x2 ; y3=y1-q*y2 ; r1=r2 ; r2=r3 ; x1=x2 ; x2=x3 ; y1=y2 ; y2=y3 ; } System.out.println(x1+" "+y1); } static int gcd(int a,int b){ if(atoInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var r1 : int ; r1 := a ; var x1 : int ; x1 := 1 ; var y1 : int ; y1 := 0 ; var r2 : int ; r2 := b ; var x2 : int ; x2 := 0 ; var y2 : int ; y2 := 1 ; var r3 : int ; var q : int ; var x3 : int ; var y3 : int ; while (r2 /= 0) do ( q := r1 / r2 ; r3 := r1 mod r2 ; x3 := x1 - q * x2 ; y3 := y1 - q * y2 ; r1 := r2 ; r2 := r3 ; x1 := x2 ; x2 := x3 ; y1 := y2 ; y2 := y3 ; ) ; OclFile["System.out"].println(x1 + " " + y1) ; ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a < b) then return gcd(b, a) else skip ; if (b = 0) then return a else skip ; return gcd(a, a mod b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); loop : while(t-->0){ int n=in.nextInt(); int m=in.nextInt(); int i=n,j=m ; int ans=0,l=0 ; if(n>l)!=0 &&(m>>l)!=0){ if(((n>>l)& 1)==1 &&((n>>l)& 1)==1)ans=ans |(1<toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var i : int ; i := n ; var j : int ; j := m ; var ans : int ; ans := 0 ; var l : int ; l := 0 ; if (n < m) then ( OclFile["System.out"].println(MathLib.bitwiseXor(m,n)) ) else ( while (((n/(2->pow(l)))->oclAsType(long)) /= 0 & ((m/(2->pow(l)))->oclAsType(long)) /= 0) do ( if ((((n/(2->pow(l)))->oclAsType(long)) & 1) = 1 & (((n/(2->pow(l)))->oclAsType(long)) & 1) = 1) then ans := MathLib.bitwiseOr(ans,((1*(2->pow(l)))->oclAsType(long))) ; else skip ; l := l + 1 ) ; OclFile["System.out"].println((MathLib.bitwiseXor(n,ans)) + (MathLib.bitwiseXor(m,ans))) ) ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int a,b ; int[] x,y ; x=new int[1]; y=new int[1]; a=sc.nextInt(); b=sc.nextInt(); extgcd(a,b,x,y); out.println(x[0]+" "+y[0]); sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } private static void extgcd(int a,int b,int[] x,int[] y){ int tmp ; x[0]=1 ; y[0]=0 ; if(b!=0){ extgcd(b,a % b,y,x); y[0]-=(a/b)*x[0]; } return ; } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var a : int ; var b : int ; var x : Sequence(int) ; var y : Sequence(int) ; x := Integer.subrange(1,1)->collect(0) ; y := Integer.subrange(1,1)->collect(0) ; a := sc.nextInt() ; b := sc.nextInt() ; execute extgcd(a, b, x, y) ; out.println(x[0+1] + " " + y[0+1]) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); static operation extgcd( a : int, b : int, x : Sequence(int), y : Sequence(int)) : void pre: true post: true activity: ( var tmp : int ; x[0+1] := 1 ; y[0+1] := 0 ; if (b /= 0) then ( execute extgcd(b, a mod b, y, x) ; y[0+1] := y[0+1]-((a / b) * x[0+1]) ) else skip ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long sumPowersK(long n,long k){ long sum=0,num=1 ; while(num<=n){ sum+=num ; num*=k ; } return sum ; } static long getSum(long n,long k){ long pwrK=sumPowersK(n,k); long sumAll=(n*(n+1))/2 ; return(sumAll-pwrK); } public static void main(String[] args){ long n=10,k=3 ; System.out.println(getSum(n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumPowersK( n : long, k : long) : long pre: true post: true activity: ( var sum : long ; sum := 0 ; var num : long ; num := 1 ; while (num <= n) do ( sum := sum+(num) ; num := num*(k) ) ; return sum ); static operation getSum( n : long, k : long) : long pre: true post: true activity: ( var pwrK : long ; pwrK := sumPowersK(n, k) ; var sumAll : long ; sumAll := (n * (n + 1)) / 2 ; return (sumAll - pwrK) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 10 ; var k : long ; k := 3 ; OclFile["System.out"].println(getSum(n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null && ! line.isEmpty()){ int a,b ; a=parseInt(line.substring(0,line.indexOf(' '))); b=parseInt(line.substring(line.indexOf(' ')+1)); int[] res=egcd(a,b); System.out.println(res[0]+" "+res[1]); } } static int[] egcd(int a,int b){ int x1=1,y1=0,r1=a ; int x2=0,y2=1,r2=b ; int x3,y3,r3 ; while(true){ int q=r1/r2 ; r3=r1 % r2 ; x3=x1-q*x2 ; y3=y1-q*y2 ; if(r3==0)break ; x1=x2 ; y1=y2 ; r1=r2 ; x2=x3 ; y2=y3 ; r2=r3 ; } return new int[] { x2,y2 }; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var a : int ; var b : int ; a := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; b := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var res : Sequence(int) ; res := egcd(a, b) ; OclFile["System.out"].println(res[0+1] + " " + res[1+1]) ; ) ; line := br.readLine() ; ) ); static operation egcd( a : int, b : int) : Sequence(int) pre: true post: true activity: ( var x1 : int ; x1 := 1 ; var y1 : int ; y1 := 0 ; var r1 : int ; r1 := a ; var x2 : int ; x2 := 0 ; var y2 : int ; y2 := 1 ; var r2 : int ; r2 := b ; var x3 : int ; var y3 : int ; var r3 : int ; while (true) do ( var q : int ; q := r1 / r2 ; r3 := r1 mod r2 ; x3 := x1 - q * x2 ; y3 := y1 - q * y2 ; if (r3 = 0) then break else skip ; x1 := x2 ; y1 := y2 ; r1 := r2 ; x2 := x3 ; y2 := y3 ; r2 := r3 ; ) ; return Sequence{x2,y2} ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); long a=scan.nextLong(); long b=scan.nextLong(); scan.close(); long[] ans=extendedGCD(a,b); System.out.println(ans[0]+" "+ans[1]); } static long[] extendedGCD(long a,long b){ long s=0,old_s=1 ; long t=1,old_t=0 ; long r=b,old_r=a ; while(r!=0){ long q=old_r/r ; long old_s0=old_s,old_t0=old_t,old_r0=old_r ; old_s=s ; s=old_s0-q*s ; old_t=t ; t=old_t0-q*t ; old_r=r ; r=old_r0-q*r ; } return new long[] { old_s,old_t }; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : long ; a := scan.getCurrent()->toLong() ; var b : long ; b := scan.getCurrent()->toLong() ; skip ; var ans : Sequence(long) ; ans := extendedGCD(a, b) ; OclFile["System.out"].println(ans[0+1] + " " + ans[1+1]) ; ); static operation extendedGCD( a : long, b : long) : Sequence(long) pre: true post: true activity: ( var s : long ; s := 0 ; var old_s : long ; old_s := 1 ; var t : long ; t := 1 ; var old_t : long ; old_t := 0 ; var r : long ; r := b ; var old_r : long ; old_r := a ; while (r /= 0) do ( var q : long ; q := old_r / r ; var old_s0 : long ; old_s0 := old_s ; var old_t0 : long ; old_t0 := old_t ; var old_r0 : long ; old_r0 := old_r ; old_s := s ; s := old_s0 - q * s ; old_t := t ; t := old_t0 - q * t ; old_r := r ; r := old_r0 - q * r ; ) ; return Sequence{old_s,old_t} ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int a=sc.nextInt(); int b=sc.nextInt(); solveEuclid(a,b); } public static void solveEuclid(int a,int b){ int r_0=a,r_1=b ; int a_0=1,a_1=0 ; int b_0=0,b_1=1 ; while(r_1>0){ int q_1=r_0/r_1 ; int r_2=r_0 % r_1 ; int a_2=a_0-q_1*a_1 ; int b_2=b_0-q_1*b_1 ; r_0=r_1 ; r_1=r_2 ; a_0=a_1 ; a_1=a_2 ; b_0=b_1 ; b_1=b_2 ; } System.out.println(a_0+" "+b_0); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; execute solveEuclid(a, b) ); static operation solveEuclid( a : int, b : int) : void pre: true post: true activity: ( var r_0 : int ; r_0 := a ; var r var r var r_0 : int ; r_0 := a : int ; r var r_0 : int ; r_0 := a := b : int ; r var r var r_0 : int ; r_0 := a : int ; r var r_0 : int ; r_0 := a := b := b ; var a_0 : int ; a_0 := 1 ; var a var a var a_0 : int ; a_0 := 1 : int ; a var a_0 : int ; a_0 := 1 := 0 : int ; a var a var a_0 : int ; a_0 := 1 : int ; a var a_0 : int ; a_0 := 1 := 0 := 0 ; var b_0 : int ; b_0 := 0 ; var b var b var b_0 : int ; b_0 := 0 : int ; b var b_0 : int ; b_0 := 0 := 1 : int ; b var b var b_0 : int ; b_0 := 0 : int ; b var b_0 : int ; b_0 := 0 := 1 := 1 ; while (r_1 > 0) do ( var q var qint : int ; qint := r_0 / rr_0 : int ; q var qint : int ; qint := r_0 / rr_0 := r_0 / rr_0 ; var rr_0 mod r var rr_0 mod rint : int ; rr_0 mod rint := r_0 mod rr_0 : int ; rr_0 mod r var rr_0 mod rint : int ; rr_0 mod rint := r_0 mod rr_0 := r_0 mod rr_0 ; var aa_0 - qqa_0 * aqa_0 : int ; aa_0 - qqa_0 * aqa_0 := a_0 - qqa_0 * aqa_0 ; var bb_0 - qqb_0 * bqb_0 : int ; bb_0 - qqb_0 * bqb_0 := b_0 - qqb_0 * bqb_0 ; r_0 := rr_0 ; rr_1 := r_2 ; a_0 := aa_0 ; aa_1 := a_2 ; b_0 := bb_0 ; bb_1 := b_2 ; ) ; OclFile["System.out"].println(a_0 + " " + b_0) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int res=0 ; while(n-->0){ String s=in.next(); int bef=in.nextInt(),aft=in.nextInt(); if(bef>=2400 && beftoInteger() ; var res : int ; res := 0 ; while (n > 0) do ( n := n - 1 ; skip ; ( var s : String ; s := in.getCurrent() ; var bef : int ; bef := in.getCurrent()->toInteger() ; var aft : int ; aft := in.getCurrent()->toInteger() ; if (bef >= 2400 & bef < aft) then ( res := res + 1 ; break ) else skip ) ; ) ; OclFile["System.out"].println(if (res = 0) then "NO" else "YES" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class P681A { public static void main(String[] args)throws IOException { BufferedReader io=new BufferedReader(new InputStreamReader(System.in)); Integer cnt=Integer.valueOf(io.readLine()); String rs="NO" ; while(cnt>0){ cnt--; String[] input=io.readLine().split(" "); if(Integer.valueOf(input[1]).compareTo(2400)>=0 && Integer.valueOf(input[1]).compareTo(Integer.valueOf(input[2]))<0){ rs="YES" ; } } System.out.println(rs); } } ------------------------------------------------------------ OCL File: --------- class P681A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : OclFile ; io := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var cnt : int ; cnt := (io.readLine())->toInteger() ; var rs : String ; rs := "NO" ; while (cnt > 0) do ( cnt := cnt - 1 ; var input : Sequence(String) ; input := io.readLine()->split(" ") ; if ((input[1+1])->toInteger()->compareTo(2400) >= 0 & (input[1+1])->toInteger()->compareTo((input[2+1])->toInteger()) < 0) then ( rs := "YES" ) else skip ) ; OclFile["System.out"].println(rs) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0 ; i=2400 && after>before){ System.out.println("YES"); return ; } } System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var name : String ; name := sc.getCurrent() ; var before : int ; before := sc.getCurrent()->toInteger() ; var after : int ; after := sc.getCurrent()->toInteger() ; if (before >= 2400 & after > before) then ( OclFile["System.out"].println("YES") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("NO") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _681A_GoodContest { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=input.nextInt(); boolean flag=false ; while(test-->0){ String userName=input.next(); int before=input.nextInt(); int after=input.nextInt(); if(before>=2400 && after>before){ flag=true ; } } System.out.println(flag ? "YES" : "NO"); } } ------------------------------------------------------------ OCL File: --------- class _681A_GoodContest { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := input.getCurrent()->toInteger() ; var flag : boolean ; flag := false ; while (test > 0) do ( test := test - 1 ; skip ; ( var userName : String ; userName := input.getCurrent() ; var before : int ; before := input.getCurrent()->toInteger() ; var after : int ; after := input.getCurrent()->toInteger() ; if (before >= 2400 & after > before) then ( flag := true ) else skip ) ; ) ; OclFile["System.out"].println(if flag then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Prog { static String s,s1 ; static int l1,l2 ; static boolean arr[]; static int arr1[]; static boolean isMatching(int index){ Arrays.fill(arr,false); for(int i=0 ; i<=index ; i++)arr[arr1[i]-1]=true ; int j=0 ; for(int i=0 ; i>>1 ; if(isMatching(m)){ ans=m+1 ; l=m+1 ; } else r=m-1 ; } System.out.println(ans); } public static void main(String[] args)throws Exception { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); s=bf.readLine(); s1=bf.readLine(); String ss[]=bf.readLine().trim().split("\\s+"); l1=s.length(); l2=s1.length(); arr1=new int[l1]; for(int i=0 ; icollect(false) ; var i : int ; i := 0 ; while i <= index do ( arr[arr1[i+1] - 1+1] := true ; ; i := i + 1 ) ; var j : int ; j := 0 ; var i : int ; i := 0 ; while i < l1 & j < l2 do ( ( if (arr[i+1]) then continue else skip ; if (s->at(i+1) = s1->at(j+1)) then j := j + 1 ; else skip ) ; i := i + 1 ) ; if (j = l2) then return true else skip ; return false ); static operation answer() : void pre: true post: true activity: ( var ans : int ; ans := 0 ; arr := Integer.subrange(1,l1)->collect(false) ; arr := arr->collect(false) ; var l : int ; l := 0 ; var r : int ; r := l1 - 1 ; while (l <= r) do ( var m : int ; m := ((l + r)/(2->pow(1)))->oclAsType(long) ; if (isMatching(m)) then ( ans := m + 1 ; l := m + 1 ) else r := m - 1 ; ) ; OclFile["System.out"].println(ans) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; s := bf.readLine() ; s1 := bf.readLine() ; var ss : Sequence(String) ; ss := bf.readLine()->trim()->split("\\s+") ; l1 := s->size() ; l2 := s1->size() ; arr1 := Integer.subrange(1,l1)->collect(0) ; var i : int ; i := 0 ; while i < l1 do ( arr1[i+1] := (ss[i+1])->toInteger() ; ; i := i + 1 ) ; execute answer() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class LevkoandTable { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=n ; j++){ if(i==j){ System.out.print(k+" "); } else { System.out.print("0 "); } } } } } ------------------------------------------------------------ OCL File: --------- class LevkoandTable { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= n do ( ( if (i = j) then ( OclFile["System.out"].print(k + " ") ) else ( OclFile["System.out"].print("0 ") ) ) ; j := j + 1 ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class XORwice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testCase=sc.nextInt(); while(testCase-->0){ System.out.println(sc.nextInt()^ sc.nextInt()); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class XORwice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var testCase : int ; testCase := sc.getCurrent()->toInteger() ; while (testCase > 0) do ( testCase := testCase - 1 ; skip ; ( OclFile["System.out"].println(sc.getCurrent()->toInteger() xor sc.getCurrent()->toInteger()) ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static float[] XandYandZintercept(float A,float B,float C,float D){ float rslt[]=new float[3]; float x=-D/A ; float y=-D/B ; float z=-D/C ; rslt[0]=x ; rslt[1]=y ; rslt[2]=z ; return rslt ; } public static void main(String[] args){ int A=2 ; int B=5 ; int C=7 ; int D=8 ; float rslt[]=XandYandZintercept(A,B,C,D); for(int i=0 ; i<3 ; i++){ System.out.print(rslt[i]+" "); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation XandYandZintercept( A : double, B : double, C : double, D : double) : Sequence(double) pre: true post: true activity: ( var rslt : Sequence(double) ; rslt := Integer.subrange(1,3)->collect(0.0) ; var x : double ; x := -D / A ; var y : double ; y := -D / B ; var z : double ; z := -D / C ; rslt[0+1] := x ; rslt[1+1] := y ; rslt[2+1] := z ; return rslt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 2 ; var B : int ; B := 5 ; var C : int ; C := 7 ; var D : int ; D := 8 ; var rslt : Sequence(double) ; rslt := XandYandZintercept(A, B, C, D) ; var i : int ; i := 0 ; while i < 3 do ( ( OclFile["System.out"].print(rslt[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class P2 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (i = j) then OclFile["System.out"].print(k + " ") ; else OclFile["System.out"].print(0 + " ") ; ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Levko_Table { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int k=in.nextInt(); int matrix[][]=new int[n][n]; for(int i=0 ; itoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var matrix : Sequence(Sequence(int)) ; matrix := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( matrix[i+1][i+1] := k ; var j : int ; j := 0 ; while j < n do ( ( OclFile["System.out"].print(matrix[i+1][j+1] + " ") ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class JavaApplication133 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int num1=sc.nextInt(); int num2=sc.nextInt(); for(int i=0 ; itoInteger() ; var num2 : int ; num2 := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < num1 do ( ( var j : int ; j := 0 ; while j < num1 do ( ( if (i = j) then ( OclFile["System.out"].print(num2 + " ") ) else ( OclFile["System.out"].print(0 + " ") ) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p072 implements EulerSolution { public static void main(String[] args){ System.out.println(new p072().run()); } private static final int LIMIT=Library.pow(10,6); public String run(){ long sum=0 ; int[] totients=Library.listTotients(LIMIT); for(int i=2 ; isize() do ( sum := sum+(totients[i+1]) ; ; i := i + 1 ) ; return ((sum) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int __gcd(int a,int 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); } static void Probability(int A,int B){ int C=6-Math.max(A,B); int gcd=__gcd(C,6); System.out.print(C/gcd+"/"+6/gcd); } public static void main(String[] args){ int A=2,B=4 ; Probability(A,B); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation __gcd( a : int, b : int) : int 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 > b) then return __gcd(a - b, b) else skip ; return __gcd(a, b - a) ); static operation Probability( A : int, B : int) : void pre: true post: true activity: ( var C : int ; C := 6 - Set{A, B}->max() ; var gcd : int ; gcd := __gcd(C, 6) ; OclFile["System.out"].print(C / gcd + "/" + 6 / gcd) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 2 ; var B : int ; B := 4 ; execute Probability(A, B) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float Time(float arr[],int n,float Emptypipe){ float fill=0 ; for(int i=0 ; ioclAsType(double)) ; return 1 / fill ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(double) ; arr := Sequence{12,14} ; var Emptypipe : double ; Emptypipe := 30 ; var n : int ; n := arr->size() ; OclFile["System.out"].println((Time(arr, n, Emptypipe))->oclAsType(int) + " Hours") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int numberOfMen(int D,int m,int d){ int Men=(m*(D-d))/d ; return Men ; } public static void main(String args[]){ int D=5,m=4,d=4 ; System.out.println(numberOfMen(D,m,d)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation numberOfMen( D : int, m : int, d : int) : int pre: true post: true activity: ( var Men : int ; Men := (m * (D - d)) / d ; return Men ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var D : int ; D := 5 ; var m : int ; m := 4 ; var d : int ; d := 4 ; OclFile["System.out"].println(numberOfMen(D, m, d)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); int[] array=new int[n]; int[] x=new int[n]; for(int i=0 ; itoInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var array : Sequence(int) ; array := Integer.subrange(1,n)->collect(0) ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( array[i+1] := scan.getCurrent()->toInteger() ; x[i+1] := array[i+1] ) ; i := i + 1 ) ; skip ; x := x->sort() ; var count : int ; count := 0 ; var total : int ; total := 0 ; var i : int ; i := 0 ; while i < n do ( ( count := count+(x[i+1]) ; if (count <= k) then ( total := total + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(total) ; var i : int ; i := 0 ; while i < total do ( ( var j : int ; j := 0 ; while j < n do ( ( if (x[i+1] = array[j+1]) then ( OclFile["System.out"].print(j + 1 + " ") ; array[j+1] := -1 ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int solve(int[] a,int k,Listmylist){ Arrays.sort(a); int count=0 ; int i=0 ; while(ica=new ArrayList<>(); Listmylist=new ArrayList<>(); for(int j : a)ca.add(j); int ans=solve(a,k,mylist); Listres=new ArrayList<>(); for(int i=0 ; isort() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while (i < a->size() & a[i+1] <= k) do ( k := k - a[i+1] ; mylist->excludes(a[i+1]) ; count := count + 1 ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var k : int ; n := sc.getCurrent()->toInteger() ; k := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ca : Sequence(int) ; ca := Sequence{} ; var mylist : Sequence(int) ; mylist := Sequence{} ; for (j : a) do ( ca := ca->including(j) ; ) ; var ans : int ; ans := solve(a, k, mylist) ; var res : Sequence(int) ; res := Sequence{} ; var i : int ; i := 0 ; while i < mylist->size() do ( ( var j : int ; j := 0 ; while j < ca->size() do ( ( if (mylist->at(i+1) = ca->at(j+1) & not(res->includes(j))) then ( res := res->including(j) ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; for (i : res) do ( OclFile["System.out"].print((i + 1) + " ") ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication144 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); ArrayListarr=new ArrayList<>(); ArrayListarra=new ArrayList<>(); ArrayListarraa=new ArrayList<>(); int num=sc.nextInt(); int max=sc.nextInt(); int counter=0 ; for(int i=0 ; i=arra.get(i)){ arraa.add(arr.indexOf(arra.get(i))+1); counter+=arra.get(i); arr.set(arr.indexOf(arra.get(i)),0); } else { break ; } } System.out.println(arraa.size()); for(int i=0 ; itoInteger() ; var max : int ; max := sc.getCurrent()->toInteger() ; var counter : int ; counter := 0 ; var i : int ; i := 0 ; while i < num do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; arr := arr->including(s) ; arra := arra->including(s) ) ; i := i + 1 ) ; arra := arra->sort() ; var i : int ; i := 0 ; while i < num do ( ( if (max - counter >= arra->at(i+1)) then ( arraa := arraa->including(arr->indexOf(arra->at(i+1))-1 + 1) ; counter := counter+(arra->at(i+1)) ; arr := arr.setAt(arr->indexOf(arra->at(i+1))-1+1,0) ) else ( break ) ) ; i := i + 1 ) ; OclFile["System.out"].println(arraa->size()) ; var i : int ; i := 0 ; while i < arraa->size() do ( ( OclFile["System.out"].print(arraa->at(i+1) + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); Solution sol=new Solution(); sol.solve(in,out); out.close(); } private static class Solution { private void solve(InputReader in,PrintWriter out){ int n=in.nextInt(),k=in.nextInt(); int[] logsLength=in.readArray(n); int min=1,max=(int)1e9+1000 ; while(min=0 ; } } private static class InputReader { private BufferedReader reader ; private StringTokenizer tokenizer ; private InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } private String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } private int nextInt(){ return Integer.parseInt(next()); } private int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; ioclAsType(int) + 1000 ; while (min < max) do ( var mid : int ; mid := (min + max) / 2 ; if (nei(mid, logsLength, k)) then max := mid ; else min := mid + 1 ; ) ; skip ; ); operation nei( mid : int, logsLength : Sequence(int), k : int) : boolean pre: true post: true activity: ( for (log : logsLength) do ( k := k-((log + mid - 1) / mid - 1) ; ) ; return k >= 0 ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class B { static int N ; static double ans ; public static void main(String...orange)throws Exception { Scanner input=new Scanner(System.in); int numCases=input.nextInt(); for(int n=0 ; n(),ps,K,0); System.out.printf("Case #%d: ",n+1); System.out.println(ans); } } static void solve(Listkeep,double[] ps,int K,int index){ if(index==ps.length){ if(keep.size()==K)check(keep,K); return ; } solve(keep,ps,K,index+1); keep.add(ps[index]); solve(keep,ps,K,index+1); keep.remove(keep.size()-1); } static void check(Listkeep,int K){ double[][] table=new double[K+1][K+1]; table[0][0]=1 ; for(int i=1 ; i<=K ; i++)for(int yes=0 ; yes<=i ; yes++){ table[i][yes]=table[i-1][yes]*(1-keep.get(i-1)); if(yes>0)table[i][yes]+=table[i-1][yes-1]*keep.get(i-1); } if(table[K][K/2]>ans)ans=table[K][K/2]; } } ------------------------------------------------------------ OCL File: --------- class B { static attribute N : int; static attribute ans : double; static operation main( orange : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numCases : int ; numCases := input.getCurrent()->toInteger() ; var n : int ; n := 0 ; while n < numCases do ( ( N := input.getCurrent()->toInteger() ; var K : int ; K := input.getCurrent()->toInteger() ; var ps : Sequence(double) ; ps := Integer.subrange(1,N)->collect(0.0) ; var i : int ; i := 0 ; while i < N do ( ps[i+1] := input.getCurrent()->toReal() ; ; i := i + 1 ) ; ans := 0 ; execute solve(Sequence{}, ps, K, 0) ; OclFile["System.out"].printf("Case #%d: ", n + 1) ; OclFile["System.out"].println(ans) ; ) ; n := n + 1 ) ); static operation solve( keep : Sequence(double), ps : Sequence(double), K : int, index : int) : void pre: true post: true activity: ( if (index = ps->size()) then ( if (keep->size() = K) then execute check(keep, K) ; else skip ; return ) else skip ; execute solve(keep, ps, K, index + 1) ; keep->excludes(ps[index+1]) ; execute solve(keep, ps, K, index + 1) ; keep := keep->excludingFirst(keep->size() - 1) ; ); static operation check( keep : Sequence(double), K : int) : void pre: true post: true activity: ( var table : Sequence(Sequence(double)) ; table := Integer.subrange(1,K + 1)->collect(Integer.subrange(1,K + 1)->collect(0.0)) ; table[0+1][0+1] := 1 ; var i : int ; i := 1 ; while i <= K do ( var yes : int ; yes := 0 ; while yes <= i do ( ( table[i+1][yes+1] := table[i - 1+1][yes+1] * (1 - keep->at(i - 1+1)) ; if (yes > 0) then table[i+1][yes+1] := table[i+1][yes+1]+(table[i - 1+1][yes - 1+1] * keep->at(i - 1+1)) ; else skip ) ; yes := yes + 1 ) ; ; i := i + 1 ) ; if (table[K+1][K / 2+1] > ans) then ans := table[K+1][K / 2+1] ; else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.String ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String vStr=sc.nextLine(); MapvList=str2List(vStr); int n=vList.get(0); int k=vList.get(1); String s=sc.nextLine(); String sArr[]=s.split(""); switch(sArr[k-1]){ case "A" : sArr[k-1]="a" ; break ; case "B" : sArr[k-1]="b" ; break ; case "C" : sArr[k-1]="c" ; break ; } for(int i=0 ; istr2List(String str){ String[] vArrStr=str.split(" "); Mapret=new HashMap<>(); Integer key=0 ; for(String val : vArrStr){ ret.put(key,Integer.valueOf(val)); key++; } return ret ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var vStr : String ; vStr := sc.nextLine() ; var vList : Map(int,int) ; vList := str2List(vStr) ; var n : int ; n := vList->at(0) ; var k : int ; k := vList->at(1) ; var s : String ; s := sc.nextLine() ; var sArr : Sequence(String) ; sArr := s->split("") ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (sArr[k - 1+1]) ; if _switchval = "A" then sArr[k - 1+1] := "a" ; break else skip ; if _switchval = "B" then sArr[k - 1+1] := "b" ; break else skip ; if _switchval = "C" then sArr[k - 1+1] := "c" ; break else skip ; ) var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(sArr[i+1]) ) ; i := i + 1 ) ; ); static operation str2List( str : String) : Map(int,int) pre: true post: true activity: ( var vArrStr : Sequence(String) ; vArrStr := str->split(" ") ; var ret : Map(int,int) ; ret := Map{} ; var key : int ; key := 0 ; for (val : vArrStr) do ( ( ret := ret->union(Map{key |-> (val)->toInteger()}) ; key := key + 1 ) ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class XORwice { public static void main(String Args[]){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int a=in.nextInt(); int b=in.nextInt(); int temp=a | b ; System.out.println((a ^ temp)+(b ^ temp)); } } } ------------------------------------------------------------ OCL File: --------- class XORwice { static operation main( Args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var temp : int ; temp := MathLib.bitwiseOr(a,b) ; OclFile["System.out"].println((MathLib.bitwiseXor(a,temp)) + (MathLib.bitwiseXor(b,temp))) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p043 implements EulerSolution { public static void main(String[] args){ System.out.println(new p043().run()); } private static int[] DIVISIBILITY_TESTS={ 2,3,5,7,11,13,17 }; public String run(){ long sum=0 ; int[] digits={ 0,1,2,3,4,5,6,7,8,9 }; outer : do { for(int i=0 ; isize() do ( ( if (toInteger(digits, i + 1, 3) mod DIVISIBILITY_TESTS[i+1] /= 0) then continue else skip ) ; i := i + 1 ) ; sum := sum+(toInteger(digits, 0, digits->size())) ) ; if (Library.nextPermutation(digits)) then skip else break) ; return ((sum) + "") ); static operation toInteger( digits : Sequence(int), off : int, len : int) : long pre: true post: true activity: ( var result : long ; result := 0 ; var i : int ; i := off ; while i < off + len do ( result := result * 10 + digits[i+1] ; ; i := i + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static byte longSize=8 ; static int ULL_SIZE=8*longSize ; static boolean bit_anagram_check(long a){ return(Integer.bitCount((int)a)==(ULL_SIZE>>1)); } public static void main(String[] args){ long a=4294967295L ; System.out.println(bit_anagram_check(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute longSize : int := 8; static attribute ULL_SIZE : int := 8 * longSize; static operation bit_anagram_check( a : long) : boolean pre: true post: true activity: ( return (bitCount(a->oclAsType(int)) = ((ULL_SIZE/(2->pow(1)))->oclAsType(long))) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : long ; a := 4294967295L ; OclFile["System.out"].println(bit_anagram_check(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int[][] grid=new int[m][3]; for(int i=0 ; i3 ? 3 : colors>2 ? 2 : 1 ; ans[num-1]=cur ; colors-=cur ; rest--; } } } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var grid : Sequence(Sequence(int)) ; grid := Integer.subrange(1,m)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < m do ( ( var j : int ; j := 0 ; while j < 3 do ( ( grid[i+1][j+1] := scan.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : Sequence(int) ; ans := getDancerColors(n, grid) ; var sb : String ; sb := StringLib.newString() ; for (num : ans) do ( ( sb := sb + StringLib.newString(num) + StringLib.newString(" ") ) ) ; OclFile["System.out"].println(sb) ; ); static operation getDancerColors( n : int, grid : Sequence(Sequence(int))) : Sequence(int) pre: true post: true activity: ( var ans : Sequence(int) ; ans := Integer.subrange(1,n)->collect(0) ; for (dance : grid) do ( ( var colors : int ; colors := 6 ; var rest : int ; rest := 3 ; for (num : dance) do ( ( if (ans[num - 1+1] /= 0) then ( colors := colors-(ans[num - 1+1]) ; rest := rest - 1 ) else skip ) ) ; for (num : dance) do ( ( if (ans[num - 1+1] = 0) then ( var cur : int ; cur := if rest = 1 then colors else if colors > 3 then 3 else if colors > 2 then 2 else 1 endif endif endif ; ans[num - 1+1] := cur ; colors := colors-(cur) ; rest := rest - 1 ) else skip ) ) ) ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long a[]=new long[n]; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var last : long ; last := a[0+1] ; OclFile["System.out"].print(last) ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] = last) then else ( last := a[i+1] ; OclFile["System.out"].print(" " + last) ) ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.regex.Matcher ; import java.util.regex.Pattern ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static final long HUGE_NUM=99999999999999999L ; public static final double EPS=0.000000001 ; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { int N=Integer.parseInt(br.readLine()); String input_str[]=br.readLine().split("\\s+"); StringBuilder ans=new StringBuilder(); ans.append(input_str[0]); String pre=input_str[0]; for(int i=1 ; itoInteger() ; var input_str : Sequence(String) ; input_str := br.readLine()->split("\\s+") ; var ans : String ; ans := StringLib.newString() ; ans := ans + StringLib.newString(input_str[0+1]) ; var pre : String ; pre := input_str[0+1] ; var i : int ; i := 1 ; while i < input_str->size() do ( ( if (input_str[i+1] = pre) then continue else skip ; ans := ans + StringLib.newString(" ") + StringLib.newString(input_str[i+1]) ; pre := input_str[i+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(ans+"") ; ) catch (e : IncorrectElementException) do ( e.printStackTrace() ) catch (e : IOException) do ( e.printStackTrace() ) ); } class UTIL { static operation isNumber( tmp_str : String) : boolean pre: true post: true activity: ( if (tmp_str = null or tmp_str->size() = 0) then ( return false ) else skip ; var pattern : OclRegex ; pattern := OclRegex.compile("\\A[0-9]+\\z") ; var matcher : OclRegex ; matcher := pattern.matcher(tmp_str) ; return matcher.isMatch() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.ListIterator ; import java.util.Scanner ; class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int n=sc.nextInt(); ArrayListA=new ArrayList<>(); for(int i=0 ; iAI=A.listIterator(); int prev=AI.next(); while(AI.hasNext()){ if(prev==AI.next()){ AI.remove(); } else { prev=AI.previous(); AI.next(); } } AI=A.listIterator(); System.out.print(AI.next()); while(AI.hasNext()){ System.out.print(" "+AI.next()); } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( A := A->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var AI : ListIterator ; AI := A->iterator() ; var prev : int ; prev := AI.next() ; while (AI.hasNext()) do ( if (prev = AI.next()) then ( AI := AI.remove() ) else ( prev := AI.previous() ; AI.next() ) ) ; AI := A->iterator() ; OclFile["System.out"].print(AI.next()) ; while (AI.hasNext()) do ( OclFile["System.out"].print(" " + AI.next()) ) ; OclFile["System.out"].println() ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int n=sc.nextInt(); long k=sc.nextLong(); Long[] A=new Long[n]; long tmp=0 ; for(int i=0 ; ix/((x*k/sum)+1)>y/((y*k/sum)+1)? 1 :-1); if(k==0){ System.out.println(A[n-1]); return ; } int[] cutCnt=new int[n]; int cutCntSum=0 ; for(int i=0 ; i=0 ; i--){ if(cutCntSumtoInteger() ; var k : long ; k := sc.getCurrent()->toLong() ; var A : Sequence(long) ; A := Integer.subrange(1,n)->collect(null) ; var tmp : long ; tmp := 0 ; var i : int ; i := 0 ; while i < n do ( ( var next : long ; next := sc.getCurrent()->toLong() ; A[i+1] := next ; tmp := tmp+(next) ) ; i := i + 1 ) ; var sum : long ; sum := tmp ; A := OclComparator.sortWith(A, lambda (x , y) : OclAny in if x / ((x * k / sum) + 1) > y / ((y * k / sum) + 1) then 1 else -1 endif) ; if (k = 0) then ( OclFile["System.out"].println(A[n - 1+1]) ; return ) else skip ; var cutCnt : Sequence(int) ; cutCnt := Integer.subrange(1,n)->collect(0) ; var cutCntSum : int ; cutCntSum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var cnt : long ; cnt := A[i+1] * k / sum ; cutCnt[i+1] := cnt->oclAsType(int) ; cutCntSum := cutCntSum+(cnt->oclAsType(int)) ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (cutCntSum < k) then ( cutCnt[i+1] := cutCnt[i+1] + 1 ; cutCntSum := cutCntSum + 1 ) else skip ; if (cutCnt[i+1] = 0) then ( ans := Set{ans, A[i+1]}->max() ; continue ) else skip ; if (A[i+1] mod cutCnt[i+1] = 0) then ( ans := Set{ans, A[i+1] / (cutCnt[i+1] + 1)}->max() ) else ( ans := Set{ans, A[i+1] / (cutCnt[i+1] + 1) + 1}->max() ) ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int size=in.nextInt(),arr[]=new int[size]; arr[0]=Integer.parseInt(in.next()); int tail=0 ; for(int i=1 ; itoInteger() ; var arr : Sequence(void) ; arr := Integer.subrange(1,size)->collect(0) ; arr[0+1] := (in.getCurrent())->toInteger() ; var tail : int ; tail := 0 ; var i : int ; i := 1 ; while i < size do ( ( var x : int ; x := (in.getCurrent())->toInteger() ; if (x /= arr[tail+1]) then ( tail := tail + 1 ; arr[tail+1] := x ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= tail do ( ( skip ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Setset=new TreeSet<>(); for(int i=0 ; itoInteger() ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( set := set->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; for (num : set) do ( ( sb := sb + StringLib.newString(num + " ") ) ) ; var str : String ; str := sb+"" ; str := str.subrange(0+1,str->size() - 1) ; OclFile["System.out"].println(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.Scanner ; public class Nezzar { int number ; public Nezzar(int number){ this.number=number ; } public int getNumber(){ return number ; } LinkedListlist=new LinkedList<>(); public void input(int number){ list.add(number); } public int maxList(LinkedListlist){ int max=list.get(0); for(int l : list){ if(l>max){ max=l ; } } return max ; } public void printResult(){ int count=1 ; LinkedListlist1=new LinkedList<>(); if(list.size()>1){ for(int i=1 ; iincluding(number) ); operation maxList( list : Sequence(int)) : int pre: true post: true activity: ( var max : int ; max := list->at(0+1) ; for (l : list) do ( ( if (l > max) then ( max := l ) else skip ) ) ; return max ); operation printResult() : void pre: true post: true activity: ( var count : int ; count := 1 ; var list1 : Sequence(int) ; list1 := Sequence{} ; if (list->size() > 1) then ( var i : int ; i := 1 ; while i < list->size() do ( ( if (list->at(i+1) = list->at(i - 1+1)) then ( count := count + 1 ) else ( list1 := list1->including(count) ; count := 1 ) ; if (i = list->size() - 1) then ( list1 := list1->including(count) ) else skip ) ; i := i + 1 ) ) else ( list1 := list1->including(1) ) ; OclFile["System.out"].println(maxList(list1)) ; list := list - list ; ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : Nezzar ; instance := Nezzar.newNezzar(number) ; var i : int ; i := 0 ; while i < instance.getNumber() do ( ( var num : int ; num := input.getCurrent()->toInteger() ; var k : int ; k := 0 ; while k < num do ( ( var n : int ; n := input.getCurrent()->toInteger() ; instance.input(n) ) ; k := k + 1 ) ; instance.printResult() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test299 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( OclFile["System.out"].println(in.getCurrent()->toInteger() xor in.getCurrent()->toInteger()) ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.BigInteger ; import java.io.*; public class codeHundredSixty { public static void main(String[] args){ Scanner input=new Scanner(System.in); int t=input.nextInt(); for(int o=0 ; otoInteger() ; var o : int ; o := 0 ; while o < t do ( ( var n : int ; n := input.getCurrent()->toInteger() ; var arrayOne : Sequence(int) ; arrayOne := Integer.subrange(1,n)->collect(0) ; var arrayTwo : Sequence(int) ; arrayTwo := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arrayOne[i+1] := input.getCurrent()->toInteger() ; arrayTwo[arrayOne[i+1]+1] := arrayTwo[arrayOne[i+1]+1] + 1 ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n + 1 do ( ( if (max < arrayTwo[i+1]) then ( max := arrayTwo[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ; o := o + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static void main(String[] args){ new A().solve(); } Scanner in ; private void solve(){ in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int max=0 ; int n=in.nextInt(); Listlist=new ArrayList<>(n); while(n-->0){ list.add(in.nextInt()); } Setset=new HashSet<>(list); for(Integer element : set){ int frequency=Collections.frequency(list,element); if(frequency>max){ max=frequency ; } } System.out.println(max); } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A.newA().solve() ); attribute in : OclFile; operation solve() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var max : int ; max := 0 ; var n : int ; n := in.getCurrent()->toInteger() ; var list : Sequence(int) ; list := Sequence{} ; while (n > 0) do ( n := n - 1 ; skip ; ( list := list->including(in.getCurrent()->toInteger()) ) ; ) ; var set : Set(int) ; set := Set{}->union(list) ; for (element : set) do ( ( var frequency : int ; frequency := .frequency(list, element) ; if (frequency > max) then ( max := frequency ) else skip ) ) ; OclFile["System.out"].println(max) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tctoInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(a)) ) ; tc := tc + 1 ) ; skip ); static operation solve( a : Sequence(int)) : int pre: true post: true activity: ( var counts : Sequence(int) ; counts := Integer.subrange(1,a->size() + 1)->collect(0) ; for (ai : a) do ( ( counts[ai+1] := counts[ai+1] + 1 ) ) ; return stream(counts).max().getAsInt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test270 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jsum){ sum=x ; } p=a ; } System.out.println(sum); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test270 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var x : int ; x := 1 ; var sum : int ; sum := 1 ; var p : int ; p := in.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i < n do ( ( var a : int ; a := in.getCurrent()->toInteger() ; if (a = p) then ( x := x + 1 ) else ( x := 1 ) ; if (x > sum) then ( sum := x ) else skip ; p := a ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.Scanner ; public class Dense { private int number ; private LinkedListlistNumber=new LinkedList<>(); public Dense(int number){ this.number=number ; } public int getNumber(){ return number ; } public void input(int number){ listNumber.add(number); } public void printResul(){ int count=0 ; for(int i=0 ; iincluding(number) ); operation printResul() : void pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < listNumber->size() - 1 do ( ( var max : double ; max := java.lang.Math->max() ; var min : double ; min := java.lang.Math->min() ; if (max / min <= 2) then ( continue ) else ( min := min * 2 ; count := count + 1 ; while (true) do ( if (max / min <= 2) then ( break ) else ( min := min*(2) ; count := count + 1 ) ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; listNumber := listNumber - listNumber ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : Dense ; instance := Dense.newDense(number) ; var i : int ; i := 0 ; while i < instance.getNumber() do ( ( var num : int ; num := input.getCurrent()->toInteger() ; var k : int ; k := 0 ; while k < num do ( ( var n : int ; n := input.getCurrent()->toInteger() ; instance.input(n) ) ; k := k + 1 ) ; instance.printResul() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test198 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jp){ while(a>2*p){ p*=2 ; sum++; } } else { int b=a ; while(p>2*b){ b*=2 ; sum++; } } p=a ; } System.out.println(sum); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test198 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var p : int ; p := in.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( var a : int ; a := in.getCurrent()->toInteger() ; if (a > p) then ( while (a > 2 * p) do ( p := p*(2) ; sum := sum + 1 ) ) else ( var b : int ; b := a ; while (p > 2 * b) do ( b := b*(2) ; sum := sum + 1 ) ) ; p := a ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import org.omg.CORBA.WrongTransaction ; import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),k=in.nextInt(); int arr[]=new int[n]; for(int i=0 ; ilim)cnt+=(i-1)/lim ; } return cnt<=k ; } static int binarySearch(int n,int k,int[] arr){ int l=1,r=(int)1e9+5,res=r ; while(l<=r){ int mid=l+((r-l)>>1); if(check(n,k,arr,mid)){ res=mid ; r=mid-1 ; } else { l=mid+1 ; } } return res ; } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; skip ; ); static operation check( n : int, k : int, arr : Sequence(int), lim : int) : boolean pre: true post: true activity: ( var cnt : long ; cnt := 0 ; for (i : arr) do ( ( if (i > lim) then cnt := cnt+((i - 1) / lim) ; else skip ) ) ; return cnt <= k ); static operation binarySearch( n : int, k : int, arr : Sequence(int)) : int pre: true post: true activity: ( var l : int ; l := 1 ; var r : int ; r := 1e9->oclAsType(int) + 5 ; var res : int ; res := r ; while (l <= r) do ( var mid : int ; mid := l + (((r - l)/(2->pow(1)))->oclAsType(long)) ; if (check(n, k, arr, mid)) then ( res := mid ; r := mid - 1 ) else ( l := mid + 1 ) ) ; return res ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1490A_DenseArray { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ int len=parseInt(input.nextLine()); int first=input.nextInt(); int result=0 ; for(int i=0 ; i2){ min*=2 ; scale=(double)max/min ; result++; } first=second ; } input.nextLine(); System.out.println(result); } } } ------------------------------------------------------------ OCL File: --------- class _1490A_DenseArray { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; while (test > 0) do ( test := test - 1 ; skip ; ( var len : int ; len := parseInt(input.nextLine()) ; var first : int ; first := input.getCurrent()->toInteger() ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < len - 1 do ( ( var second : int ; second := input.getCurrent()->toInteger() ; var max : int ; max := Set{first, second}->max() ; var min : int ; min := Set{first, second}->min() ; var scale : double ; scale := max->oclAsType(double) / min ; while (scale > 2) do ( min := min*(2) ; scale := max->oclAsType(double) / min ; result := result + 1 ) ; first := second ; ) ; i := i + 1 ) ; skip ; OclFile["System.out"].println(result) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Dense_Array { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testcase=sc.nextInt(); while(testcase!=0){ testcase--; int num=sc.nextInt(),insert=0,mul=0,loop=0,ma,mi ; int arr[]=new int[num]; for(int i=0 ; i2*mi){ while(true){ mi*=2 ; loop++; if(ma<=2*mi)break ; } insert+=loop ; } } System.out.print(insert); if(testcase>0)System.out.println(); } sc.close(); } public static int min(int x,int y){ int m=x ; if(m>y)m=y ; return m ; } public static int max(int x,int y){ int m=x ; if(mtoInteger() ; while (testcase /= 0) do ( testcase := testcase - 1 ; var num : int ; num := sc.getCurrent()->toInteger() ; var insert : int ; insert := 0 ; var mul : int ; mul := 0 ; var loop : int ; loop := 0 ; var ma : int ; var mi : int ; var arr : Sequence(int) ; arr := Integer.subrange(1,num)->collect(0) ; var i : int ; i := 0 ; while i < num do ( arr[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < num - 1 do ( ( loop := 0 ; ma := Set{arr[i+1], arr[i + 1+1]}->max() ; mi := Set{arr[i+1], arr[i + 1+1]}->min() ; if (ma > 2 * mi) then ( while (true) do ( mi := mi*(2) ; loop := loop + 1 ; if (ma <= 2 * mi) then break else skip ) ; insert := insert+(loop) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(insert) ; if (testcase > 0) then OclFile["System.out"].println() ; else skip ; ) ; skip ); static operation min( x : int, y : int) : int pre: true post: true activity: ( var m : int ; m := x ; if (m > y) then m := y ; else skip ; return m ); static operation max( x : int, y : int) : int pre: true post: true activity: ( var m : int ; m := x ; if (m < y) then m := y ; else skip ; return m ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class DenseArray { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int[] a=new int[n]; int count=0 ; for(int i=0 ; imin*2){ while(min*2toInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var max : int ; max := Set{a[i+1], a[i + 1+1]}->max() ; var min : int ; min := Set{a[i+1], a[i + 1+1]}->min() ; if (max > min * 2) then ( while (min * 2 < max) do ( min := min * 2 ; count := count + 1 ) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static public void main(String[] args){ Scanner sc=new Scanner(System.in); long a1=sc.nextLong(); long a2=sc.nextLong(); long a3=sc.nextLong(); long a4=sc.nextLong(); long a5=sc.nextLong(); long a6=sc.nextLong(); long a7=sc.nextLong(); long length=a2 ; if(a1 % 2+a4 % 2+a5 % 2>=2 && a1>0 & a4>0 & a5>0){ length+=3 ; a1-=1 ; a4-=1 ; a5-=1 ; } length+=(a1/2)*2 ; length+=(a4/2)*2 ; length+=(a5/2)*2 ; System.out.println(length); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a1 : long ; a1 := sc.getCurrent()->toLong() ; var a2 : long ; a2 := sc.getCurrent()->toLong() ; var a3 : long ; a3 := sc.getCurrent()->toLong() ; var a4 : long ; a4 := sc.getCurrent()->toLong() ; var a5 : long ; a5 := sc.getCurrent()->toLong() ; var a6 : long ; a6 := sc.getCurrent()->toLong() ; var a7 : long ; a7 := sc.getCurrent()->toLong() ; var length : long ; length := a2 ; if (a1 mod 2 + a4 mod 2 + a5 mod 2 >= 2 & a1 > 0 & a4 > 0 & a5 > 0) then ( length := length+(3) ; a1 := a1-(1) ; a4 := a4-(1) ; a5 := a5-(1) ) else skip ; length := length+((a1 / 2) * 2) ; length := length+((a4 / 2) * 2) ; length := length+((a5 / 2) * 2) ; OclFile["System.out"].println(length) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); CXYetAnotherDieGame solver=new CXYetAnotherDieGame(); solver.solve(1,in,out); out.close(); } static class CXYetAnotherDieGame { public void solve(int testNumber,InputReader in,PrintWriter out){ long x=in.nextLong(); out.println(Math.min(2*((x+10)/11),2*((x-6+10)/11)+1)); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : CXYetAnotherDieGame ; solver := CXYetAnotherDieGame.newCXYetAnotherDieGame() ; solver.solve(1, in, out) ; skip ; ); static class CXYetAnotherDieGame { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var x : long ; x := in.nextLong() ; skip ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.UncheckedIOException ; import java.util.StringTokenizer ; class Main { public static void main(String[] args){ SC sc=new SC(System.in); long I=sc.nextLong(); long O=sc.nextLong(); long T=sc.nextLong(); long J=sc.nextLong(); long L=sc.nextLong(); long S=sc.nextLong(); long Z=sc.nextLong(); long ans=0 ; long tmp=0 ; if(I>0){ ans+=((I-1)/2)*2 ; } ans+=O ; if(J>0){ ans+=((J-1)/2)*2 ; } if(L>0){ ans+=((L-1)/2)*2 ; } if(I>0 && J>0 && L>0){ ans+=3 ; } tmp+=I/2*2 ; tmp+=O ; tmp+=J/2*2 ; tmp+=L/2*2 ; pl(Math.max(ans,tmp)); } static class SC { private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public SC(InputStream in){ reader=new BufferedReader(new InputStreamReader(in)); } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new UncheckedIOException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } } public static void pl(Object o){ System.out.println(o); } public static void pl(){ System.out.println(); } public static void p(Object o){ System.out.print(o); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : SC ; sc := SC.newSC(OclFile["System.in"]) ; var I : long ; I := sc.nextLong() ; var O : long ; O := sc.nextLong() ; var T : long ; T := sc.nextLong() ; var J : long ; J := sc.nextLong() ; var L : long ; L := sc.nextLong() ; var S : long ; S := sc.nextLong() ; var Z : long ; Z := sc.nextLong() ; var ans : long ; ans := 0 ; var tmp : long ; tmp := 0 ; if (I > 0) then ( ans := ans+(((I - 1) / 2) * 2) ) else skip ; ans := ans+(O) ; if (J > 0) then ( ans := ans+(((J - 1) / 2) * 2) ) else skip ; if (L > 0) then ( ans := ans+(((L - 1) / 2) * 2) ) else skip ; if (I > 0 & J > 0 & L > 0) then ( ans := ans+(3) ) else skip ; tmp := tmp+(I / 2 * 2) ; tmp := tmp+(O) ; tmp := tmp+(J / 2 * 2) ; tmp := tmp+(L / 2 * 2) ; execute pl(Set{ans, tmp}->max()) ; ); static class SC { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newSC( in : OclFile) : SC pre: true post: true activity: ( var self : SC ; self := createSC(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ) else skip ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static operation pl( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o) ); static operation pl() : void pre: true post: true activity: ( OclFile["System.out"].println() ); static operation p( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].print(o) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { BufferedReader br ; PrintWriter out ; StringTokenizer st ; boolean eof ; long go(long a,long b,long c){ if(a<0 || b<0 || c<0){ return Long.MIN_VALUE ; } return a+b+c-(a & 1)-(b & 1)-(c & 1); } void solve()throws IOException { long i=nextLong(); long o=nextLong(); long t=nextLong(); long j=nextLong(); long l=nextLong(); long s=nextLong(); long z=nextLong(); long ans=o+Math.max(go(i,j,l),go(i-1,j-1,l-1)+3); out.println(ans); } Main()throws IOException { br=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); solve(); out.close(); } public static void main(String[] args)throws IOException { new Main(); } String nextToken(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(Exception e){ eof=true ; return null ; } } return st.nextToken(); } String nextString(){ try { return br.readLine(); } catch(IOException e){ eof=true ; return null ; } } int nextInt()throws IOException { return Integer.parseInt(nextToken()); } long nextLong()throws IOException { return Long.parseLong(nextToken()); } double nextDouble()throws IOException { return Double.parseDouble(nextToken()); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute br : OclFile; attribute out : OclFile; attribute st : OclIterator; attribute eof : boolean; operation go( a : long, b : long, c : long) : long pre: true post: true activity: ( if (a < 0 or b < 0 or c < 0) then ( return "-9223372036854775808"->toLong() ) else skip ; return a + b + c - (MathLib.bitwiseAnd(a,1)) - (MathLib.bitwiseAnd(b,1)) - (MathLib.bitwiseAnd(c,1)) ); operation solve() : void pre: true post: true activity: ( var i : long ; i := nextLong() ; var o : long ; o := nextLong() ; var t : long ; t := nextLong() ; var j : long ; j := nextLong() ; var l : long ; l := nextLong() ; var s : long ; s := nextLong() ; var z : long ; z := nextLong() ; var ans : long ; ans := o + Set{go(i, j, l), go(i - 1, j - 1, l - 1) + 3}->max() ; skip ; ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : ProgramException) do ( eof := true ; return null ) ) ; return st.next() ); operation nextString() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : IOException) do ( eof := true ; return null ) ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in=new Scanner(System.in); static final PrintWriter out=new PrintWriter(System.out,false); static boolean debug=false ; static void solve(){ int[] a=new int[7]; for(int i=0 ; i<7 ; i++){ a[i]=in.nextInt(); } long ans1=a[1]*2 ; long ans2=ans1 ; ans1+=a[0]/2*4 ; ans1+=a[3]/2*4 ; ans1+=a[4]/2*4 ; if(a[0]>0 && a[3]>0 && a[4]>0){ a[0]--; a[3]--; a[4]--; ans2+=a[0]/2*4 ; ans2+=a[3]/2*4 ; ans2+=a[4]/2*4 ; ans2+=6 ; } out.println(Math.max(ans1,ans2)/2); } public static void main(String[] args){ debug=args.length>0 ; long start=System.nanoTime(); solve(); out.flush(); long end=System.nanoTime(); dump((end-start)/1000000+" ms"); in.close(); out.close(); } static void dump(Object...o){ if(debug)System.err.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"], false); static attribute debug : boolean := false; static operation solve() : void pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,7)->collect(0) ; var i : int ; i := 0 ; while i < 7 do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans1 : long ; ans1 := a[1+1] * 2 ; var ans2 : long ; ans2 := ans1 ; ans1 := ans1+(a[0+1] / 2 * 4) ; ans1 := ans1+(a[3+1] / 2 * 4) ; ans1 := ans1+(a[4+1] / 2 * 4) ; if (a[0+1] > 0 & a[3+1] > 0 & a[4+1] > 0) then ( a[0+1] := a[0+1] - 1 ; a[3+1] := a[3+1] - 1 ; a[4+1] := a[4+1] - 1 ; ans2 := ans2+(a[0+1] / 2 * 4) ; ans2 := ans2+(a[3+1] / 2 * 4) ; ans2 := ans2+(a[4+1] / 2 * 4) ; ans2 := ans2+(6) ; ) else skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( debug := args->size() > 0 ; var start : long ; start := nanoTime() ; execute solve() ; skip ; var end : long ; end := nanoTime() ; execute dump((end - start) / 1000000 + " ms") ; skip ; skip ; ); static operation dump( o : Sequence(OclAny)) : void pre: true post: true activity: ( if (debug) then OclFile["System.err"].println((o + "")) ; else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] sa=br.readLine().split(" "); int i=Integer.parseInt(sa[0]); int o=Integer.parseInt(sa[1]); int j=Integer.parseInt(sa[3]); int l=Integer.parseInt(sa[4]); br.close(); long ans=o ; boolean x=(j!=0); boolean y=(l!=0); boolean z=(i!=0); while((j>0)&&(l>0)&&(i>0)){ ans+=3 ; i--; j--; l--; } if(j==0 && l % 2==1 && i % 2==1 && x){ ans+=1 ; j++; i--; l--; } if(l==0 && j % 2==1 && i % 2==1 && y){ ans+=1 ; l++; i--; j--; } if(i==0 && l % 2==1 && j % 2==1 && z){ ans+=1 ; i++; j--; l--; } ans+=i/2*2 ; ans+=j/2*2 ; ans+=l/2*2 ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sa : Sequence(String) ; sa := br.readLine()->split(" ") ; var i : int ; i := (sa[0+1])->toInteger() ; var o : int ; o := (sa[1+1])->toInteger() ; var j : int ; j := (sa[3+1])->toInteger() ; var l : int ; l := (sa[4+1])->toInteger() ; skip ; var ans : long ; ans := o ; var x : boolean ; x := (j /= 0) ; var y : boolean ; y := (l /= 0) ; var z : boolean ; z := (i /= 0) ; while ((j > 0) & (l > 0) & (i > 0)) do ( ans := ans+(3) ; i := i - 1 ; j := j - 1 ; l := l - 1 ) ; if (j = 0 & l mod 2 = 1 & i mod 2 = 1 & x) then ( ans := ans+(1) ; j := j + 1 ; i := i - 1 ; l := l - 1 ) else skip ; if (l = 0 & j mod 2 = 1 & i mod 2 = 1 & y) then ( ans := ans+(1) ; l := l + 1 ; i := i - 1 ; j := j - 1 ) else skip ; if (i = 0 & l mod 2 = 1 & j mod 2 = 1 & z) then ( ans := ans+(1) ; i := i + 1 ; j := j - 1 ; l := l - 1 ) else skip ; ans := ans+(i / 2 * 2) ; ans := ans+(j / 2 * 2) ; ans := ans+(l / 2 * 2) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String args[])throws IOException { Scanner scan=new Scanner(System.in); int Ans=0 ; int N=scan.nextInt(); int[] P=new int[N]; for(int i=0 ; i0){ ans+=nextS ; } if(i==0 || Ans>ans){ Ans=ans ; } } System.out.println(Ans); scan.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var Ans : int ; Ans := 0 ; var N : int ; N := scan.getCurrent()->toInteger() ; var P : Sequence(int) ; P := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= P[0+1] do ( ( var ans : int ; ans := i ; var nextS : int ; nextS := P[0+1] - i ; var cursor : int ; cursor := 0 ; while cursor < N - 1 do ( ( ans := ans+(nextS * 2) ; nextS := P[cursor + 1+1] - nextS ; if (nextS < 0) then ( nextS := 0 ) else skip ) ; cursor := cursor + 1 ) ; if (nextS > 0) then ( ans := ans+(nextS) ) else skip ; if (i = 0 or Ans > ans) then ( Ans := ans ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(Ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public final class Main { public static void main(String[] args){ final Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); final String[] line=in.nextLine().split(" "); final int n=Integer.parseInt(line[0]); final int k=Integer.parseInt(line[1]); final int[] arr=new int[n]; for(int i=0 ; i>>1 ; int cnt=0 ; for(int i=0 ; isplit(" ") ; var n : int ; n := (line[0+1])->toInteger() ; var k : int ; k := (line[1+1])->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; var low : int ; low := 1 ; var high : int ; high := 1e9->oclAsType(int) ; while (low < high) do ( var mid : int ; mid := (low + high/(2->pow(1)))->oclAsType(long) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( cnt := cnt+((arr[i+1] - 1) / mid) ) ; i := i + 1 ) ; if (k < cnt) then ( low := mid + 1 ) else ( high := mid ) ) ; OclFile["System.out"].println(low) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int[] height=new int[] { 1,2,1,2 }; public static int woodCollected(int n,int m){ int sum=0 ; for(int i=n-1 ; i>=0 ; i--){ if(height[i]-m<=0)break ; sum+=(height[i]-m); } return sum ; } public static int collectKWood(int n,int k){ Arrays.sort(height); int low=0,high=height[n-1]; while(low<=high){ int mid=low+((high-low)/2); int collected=woodCollected(n,mid); if(collected==k)return mid ; if(collected>k)low=mid+1 ; else high=mid-1 ; } return-1 ; } public static void main(String[] args){ int k=2 ; int n=height.length ; System.out.print(collectKWood(n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute height : Sequence(int) := Sequence{1,2,1,2}; static operation woodCollected( n : int, m : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (height[i+1] - m <= 0) then break else skip ; sum := sum+((height[i+1] - m)) ) ; i := i - 1 ) ; return sum ); static operation collectKWood( n : int, k : int) : int pre: true post: true activity: ( height := height->sort() ; var low : int ; low := 0 ; var high : int ; high := height[n - 1+1] ; while (low <= high) do ( var mid : int ; mid := low + ((high - low) / 2) ; var collected : int ; collected := woodCollected(n, mid) ; if (collected = k) then return mid else skip ; if (collected > k) then low := mid + 1 ; else high := mid - 1 ; ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 2 ; var n : int ; n := height->size() ; OclFile["System.out"].print(collectKWood(n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static ArrayList>graph=new ArrayList<>(); ; static int[] values ; static int[] longest ; static int[] ans ; static boolean[] used ; static int n ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); n=sc.nextInt(); values=new int[n]; for(int i=0 ; i()); } longest=new int[n+1]; Arrays.fill(longest,Integer.MAX_VALUE); longest[0]=0 ; ans=new int[n]; used=new boolean[n]; for(int i=0 ; i1){ int m=(left+right)/2 ; if(longest[m]toInteger() ; values := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( values[i+1] := sc.getCurrent()->toInteger() ; graph := graph->including(Sequence{}) ) ; i := i + 1 ) ; longest := Integer.subrange(1,n + 1)->collect(0) ; longest := longest->collect(2147483647) ; longest[0+1] := 0 ; ans := Integer.subrange(1,n)->collect(0) ; used := Integer.subrange(1,n)->collect(false) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var a : int ; a := sc.getCurrent()->toInteger() - 1 ; var b : int ; b := sc.getCurrent()->toInteger() - 1 ; graph->at(a+1)->excludes(b) ; graph->at(b+1)->excludes(a) ) ; i := i + 1 ) ; execute search(0, 0) ; var sb : String ; sb := StringLib.newString() ; for (x : ans) do ( ( sb := sb + StringLib.newString(x) + StringLib.newString("\n") ) ) ; OclFile["System.out"].print(sb) ; ); static operation search( idx : int, max : int) : void pre: true post: true activity: ( if (used[idx+1]) then ( return ) else skip ; used[idx+1] := true ; var left : int ; left := 0 ; var right : int ; right := n + 1 ; while (right - (left)->char2byte() > 1) do ( var m : int ; m := (left + right) / 2 ; if (longest[m+1] < values[idx+1]) then ( left := m ) else ( right := m ) ) ; var save : int ; save := longest[left + 1+1] ; max := Set{max, left + 1}->max() ; longest[left + 1+1] := Set{longest[left + 1+1], values[idx+1]}->min() ; ans[idx+1] := max ; for (x : graph->at(idx+1)) do ( ( execute search(x, max) ) ) ; longest[left + 1+1] := save ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findMinOperations(String S){ S=reverse(S); int n=S.length(); int dp[][]=new int[n+1][2]; if(S.charAt(0)=='0'){ dp[0][0]=0 ; } else { dp[0][0]=1 ; } dp[0][1]=1 ; for(int i=1 ; isize() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,2)->collect(0)) ; if (S->at(0+1) = '0') then ( dp[0+1][0+1] := 0 ) else ( dp[0+1][0+1] := 1 ) ; dp[0+1][1+1] := 1 ; var i : int ; i := 1 ; while i < n do ( ( if (S->at(i+1) = '0') then ( dp[i+1][0+1] := dp[i - 1+1][0+1] ; dp[i+1][1+1] := 1 + Set{dp[i - 1+1][1+1], dp[i - 1+1][0+1]}->min() ) else ( dp[i+1][1+1] := dp[i - 1+1][1+1] ; dp[i+1][0+1] := 1 + Set{dp[i - 1+1][0+1], dp[i - 1+1][1+1]}->min() ) ) ; i := i + 1 ) ; return dp[n - 1+1][0+1] ); static operation reverse( input : String) : String pre: true post: true activity: ( var temparray : Sequence(String) ; temparray := input->characters() ; var left : int ; var right : int ; right := 0 ; right := temparray->size() - 1 ; left := 0 ; while left < right do ( ( var temp : String ; temp := temparray[left+1] ; temparray[left+1] := temparray[right+1] ; temparray[right+1] := temp ) ; left := left + 1 ; right := right - 1 ) ; return (temparray)->sum() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : String ; S := "100" ; OclFile["System.out"].println(findMinOperations(S)) ; S := "111" ; OclFile["System.out"].println(findMinOperations(S)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countNumbers(int n){ if(n % 2==1)return 0 ; return(9*(int)Math.pow(10,n/2-1)); } public static void main(String args[]){ int n=2 ; System.out.print(countNumbers(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumbers( n : int) : int pre: true post: true activity: ( if (n mod 2 = 1) then return 0 else skip ; return (9 * 10->pow(n / 2 - 1)->oclAsType(int)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; OclFile["System.out"].print(countNumbers(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { public static int stopping_station(int p,int n){ int num=1,dem=1,s=p ; while(p!=1){ dem*=p ; p--; } int t=n-s+1 ; while(t!=(n-2*s+1)){ num*=t ; t--; } if((n-s+1)>=s)System.out.print(num/dem); else System.out.print("not possible"); return 0 ; } public static void main(String[] args){ int n,s ; stopping_station(4,12); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation stopping_station( p : int, n : int) : int pre: true post: true activity: ( var num : int ; num := 1 ; var dem : int ; dem := 1 ; var s : int ; s := p ; while (p /= 1) do ( dem := dem*(p) ; p := p - 1 ) ; var t : int ; t := n - s + 1 ; while (t /= (n - 2 * s + 1)) do ( num := num*(t) ; t := t - 1 ) ; if ((n - s + 1) >= s) then OclFile["System.out"].print(num / dem) else OclFile["System.out"].print("not possible") ; ; return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; var s : int ; execute stopping_station(4, 12) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long N=sc.nextLong(); sc.close(); long count=0 ; if(N % 11==0)count=N/11*2 ; else if(N % 11<=6)count=N/11*2+1 ; else count=N/11*2+2 ; System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := sc.getCurrent()->toLong() ; skip ; var count : long ; count := 0 ; if (N mod 11 = 0) then count := N / 11 * 2 else if (N mod 11 <= 6) then count := N / 11 * 2 + 1 else count := N / 11 * 2 + 2 ; ; ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); while(k>0){ System.out.print(n+" "); n--; k--; } for(int i=1 ; i<=n ; i++){ if(i==n)System.out.print(i); else System.out.print(i+" "); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; while (k > 0) do ( OclFile["System.out"].print(n + " ") ; n := n - 1 ; k := k - 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( if (i = n) then OclFile["System.out"].print(i) ; else OclFile["System.out"].print(i + " ") ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.StringTokenizer ; import java.util.TreeSet ; import static java.lang.System.out ; public class pre130 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader obj=new FastReader(); int n=obj.nextInt(),k=obj.nextInt(); if(k==0){ for(int i=1 ; i<=n ; i++)out.print(i+" "); } else { int c=n ; for(int i=1 ; i<=n-k-1 ; i++)out.print(i+" "); for(int i=n ; i>n-k-1 ; i--)out.print(i+" "); } } } ------------------------------------------------------------ OCL File: --------- class pre130 { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : FastReader ; obj := FastReader.newFastReader() ; var n : int ; n := obj.nextInt() ; var k : int ; k := obj.nextInt() ; if (k = 0) then ( var i : int ; i := 1 ; while i <= n do ( out.print(i + " ") ; ; i := i + 1 ) ) else ( var c : int ; c := n ; var i : int ; i := 1 ; while i <= n - k - 1 do ( out.print(i + " ") ; ; i := i + 1 ) ; var i : int ; i := n ; while i > n - k - 1 do ( out.print(i + " ") ; ; i := i - 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ Main ob=new Main(); ob.run(); } private void run(){ int n=nextInt(); int k=nextInt(); for(int i=n ; i>n-k ; i--){ out.print(i+" "); } for(int i=1 ; i<=n-k ; i++){ out.print(i+" "); } out.close(); } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st ; PrintWriter out=new PrintWriter(System.out); String nextLine(){ try { return br.readLine(); } catch(IOException ex){ ex.printStackTrace(); } return "" ; } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ob : Main ; ob := Main.newMain() ; ob.run() ); operation run() : void pre: true post: true activity: ( var n : int ; n := nextInt() ; var k : int ; k := nextInt() ; var i : int ; i := n ; while i > n - k do ( ( out.print(i + " ") ) ; i := i - 1 ) ; var i : int ; i := 1 ; while i <= n - k do ( ( out.print(i + " ") ) ; i := i + 1 ) ; out.close() ; ); attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator; attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (ex : IOException) do ( ex.printStackTrace() ) return "" ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class level2 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); for(int i=1 ; i<=n-(k+1); i++)System.out.print(i+" "); for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n - (k + 1) do ( OclFile["System.out"].print(i + " ") ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k + 1 do ( ( OclFile["System.out"].print((n) + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Map hs=new HashMap(); PrintWriter ou=new PrintWriter(System.out); int n=Integer.parseInt(sc.next()); int k=Integer.parseInt(sc.next()); int[] a=new int[n]; for(int i=0 ; i0.000001){ double now=(le+ri)/2 ; int yono=0 ; for(int i=0 ; ik)le=now ; else ri=now ; } if(ri % 1<0.000001 || ri % 1>0.99999)ou.print((int)Math.round(ri)+"\n"); else ou.print((int)Math.ceil(ri)+"\n"); ou.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var hs : Map ; hs := Map{} ; var ou : OclFile ; ou := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var k : int ; k := (sc.getCurrent())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; skip ; var le : double ; le := 0 ; var ri : double ; ri := 10->pow(9) ; while (ri - le > 0.000001) do ( var now : double ; now := (le + ri) / 2 ; var yono : int ; yono := 0 ; var i : int ; i := 0 ; while i < n do ( ( yono := yono+((a[i+1] / now)->oclAsType(int)) ) ; i := i + 1 ) ; if (yono > k) then le := now ; else ri := now ; ) ; if (ri mod 1 < 0.000001 or ri mod 1 > 0.99999) then ou := ou.print((ri)->round()->oclAsType(int) + "\n") else ou := ou.print((ri)->ceil()->oclAsType(int) + "\n") ; ; ou := ou.flush() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Haversine { static double haversine(double lat1,double lon1,double lat2,double lon2){ double dLat=Math.toRadians(lat2-lat1); double dLon=Math.toRadians(lon2-lon1); lat1=Math.toRadians(lat1); lat2=Math.toRadians(lat2); double a=Math.pow(Math.sin(dLat/2),2)+Math.pow(Math.sin(dLon/2),2)*Math.cos(lat1)*Math.cos(lat2); double rad=6371 ; double c=2*Math.asin(Math.sqrt(a)); return rad*c ; } public static void main(String[] args){ double lat1=51.5007 ; double lon1=0.1246 ; double lat2=40.6892 ; double lon2=74.0445 ; System.out.println(haversine(lat1,lon1,lat2,lon2)+" K.M."); } } ------------------------------------------------------------ OCL File: --------- class Haversine { static operation haversine( lat1 : double, lon1 : double, lat2 : double, lon2 : double) : double pre: true post: true activity: ( var dLat : double ; dLat := (0.017453292519943295*(lat2 - lat1)) ; var dLon : double ; dLon := (0.017453292519943295*(lon2 - lon1)) ; lat1 := (0.017453292519943295*(lat1)) ; lat2 := (0.017453292519943295*(lat2)) ; var a : double ; a := (dLat / 2)->sin()->pow(2) + (dLon / 2)->sin()->pow(2) * (lat1)->cos() * (lat2)->cos() ; var rad : double ; rad := 6371 ; var c : double ; c := 2 * ((a)->sqrt())->asin() ; return rad * c ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var lat1 : double ; lat1 := 51.5007 ; var lon1 : double ; lon1 := 0.1246 ; var lat2 : double ; lat2 := 40.6892 ; var lon2 : double ; lon2 := 74.0445 ; OclFile["System.out"].println(haversine(lat1, lon1, lat2, lon2) + " K.M.") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ try(Scanner in=new Scanner(System.in)){ int M=in.nextInt(); int K=in.nextInt(); if(K==0){ StringBuilder sb=new StringBuilder(); for(int i=0,I=1<<(M); i=0 ; i--){ if(i==K){ continue ; } sb.append(" "+i); } sb.append(" "+K); System.out.println(sb.toString().trim()); } else { System.out.println(-1); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var M : int ; M := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; if (K = 0) then ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; var I : int ; I := (1*(2->pow((M))))->oclAsType(long) ; while i < I do ( ( sb := sb + StringLib.newString(" " + i + " " + i) ) ; i := i + 1 ) ; OclFile["System.out"].println(sb+""->trim()) ; return ) else skip ; var xor : int ; xor := 0 ; var i : int ; i := 0 ; var I : int ; I := (1*(2->pow((M))))->oclAsType(long) ; while i < I do ( ( if (i = K) then ( continue ) else skip ; xor := MathLib.bitwiseXor(xor,i) ) ; i := i + 1 ) ; if (xor = K) then ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; var I : int ; I := (1*(2->pow((M))))->oclAsType(long) ; while i < I do ( ( if (i = K) then ( continue ) else skip ; sb := sb + StringLib.newString(" " + i) ) ; i := i + 1 ) ; sb := sb + StringLib.newString(" " + K) ; var i : int ; i := ((1*(2->pow((M))))->oclAsType(long)) - 1 ; while i >= 0 do ( ( if (i = K) then ( continue ) else skip ; sb := sb + StringLib.newString(" " + i) ) ; i := i - 1 ) ; sb := sb + StringLib.newString(" " + K) ; OclFile["System.out"].println(sb+""->trim()) ; ) else ( OclFile["System.out"].println(-1) ) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class Main { static void impossible(){ System.out.println("-1"); System.exit(0); } static void printList(Listl){ int N=l.size(); int n=0 ; for(int e : l){ n++; System.out.print(e+(n=N)impossible(); if(M==1 && K==1)impossible(); if(M==1 && K==0){ System.out.println("0 0 1 1"); System.exit(0); } LinkedListlist=new LinkedList<>(); list.add(K); for(int n=0 ; nsize() ; var n : int ; n := 0 ; for (e : l) do ( ( n := n + 1 ; OclFile["System.out"].print(e + (if n < N then " " else "\n" endif)) ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var M : int ; M := sc.getCurrent()->toInteger() ; var N : int ; N := (1*(2->pow(M)))->oclAsType(long) ; var K : int ; K := sc.getCurrent()->toInteger() ; if (K >= N) then execute impossible() ; else skip ; if (M = 1 & K = 1) then execute impossible() ; else skip ; if (M = 1 & K = 0) then ( OclFile["System.out"].println("0 0 1 1") ; OclProcess.exit(0) ) else skip ; var list : Sequence(int) ; list := Sequence{} ; list := list->including(K) ; var n : int ; n := 0 ; while n < N do ( if (n /= K) then ( list := list->prepend(n) ; list := list->append(n) ) else skip ; ; n := n + 1 ) ; list := list->append(K) ; execute printList(list) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] $){ Scanner s=new Scanner(System.in); int n=1<=n){ System.out.println(-1); return ; } for(int i=0 ; i=0 ; --i){ if(i!=k)sb.add(String.valueOf(i)); } sb.add(String.valueOf(k)); System.out.println(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (1*(2->pow(s.getCurrent()->toInteger())))->oclAsType(long) ; var k : int ; k := s.getCurrent()->toInteger() ; var sb : StringJoiner ; sb := StringJoiner.newStringJoiner(" ") ; if (n = 2) then ( if (k = 0) then OclFile["System.out"].println("0 0 1 1") else OclFile["System.out"].println(-1) ; ; return ) else skip ; if (k >= n) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var i : int ; i := 0 ; while i < n do ( ( if (i /= k) then sb->excludes(((i) + "")) ; else skip ) ; i := i + 1 ) ; sb->excludes(((k) + "")) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (i /= k) then sb->excludes(((i) + "")) ; else skip ) ; i := i - 1 ) ; sb->excludes(((k) + "")) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); BigInteger v=new BigInteger("11"); BigInteger input=new BigInteger(sc.next()); if(input.compareTo(v)<=0){ if(input.compareTo(new BigInteger("6"))<=0){ System.out.println(1); } else { System.out.println(2); } } else { BigInteger res=new BigInteger("0"); res=input.divide(v).multiply(new BigInteger("2")); if(input.mod(v).equals(new BigInteger("0"))){ } else if(input.mod(v).compareTo(new BigInteger("6"))<=0){ res=res.add(new BigInteger("1")); } else { res=res.add(new BigInteger("2")); } System.out.println(res); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var v : long ; v := long("11") ; var input : long ; input := long(sc.getCurrent()) ; if (input->compareTo(v) <= 0) then ( if (input->compareTo(long("6")) <= 0) then ( OclFile["System.out"].println(1) ) else ( OclFile["System.out"].println(2) ) ) else ( var res : long ; res := long("0") ; res := input.divide(v).multiply(long("2")) ; if (input.mod(v) = long("0")) then skip else if (input.mod(v)->compareTo(long("6")) <= 0) then ( res := res->excludes(long("1")) ) else ( res := res->excludes(long("2")) ) ; ; OclFile["System.out"].println(res) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void CamelCase(ArrayListwords,String pattern){ Map>map=new HashMap>(); for(int i=0 ; i='A' && words.get(i).charAt(j)<='Z'){ str+=words.get(i).charAt(j); map.put(str,list(map.get(str),words.get(i))); } } } boolean wordFound=false ; for(Map.Entry>it : map.entrySet()){ if(it.getKey().equals(pattern)){ wordFound=true ; for(String s : it.getValue())System.out.print(s+"\n"); } } if(! wordFound){ System.out.print("No match found"); } } private static Listlist(Listlist,String str){ Listtemp=new ArrayList(); if(list!=null)temp.addAll(list); temp.add(str); return temp ; } public static void main(String[] args){ String arr[]={ "Hi","Hello","HelloWorld","HiTech","HiGeek","HiTechWorld","HiTechCity","HiTechLab" }; ArrayListwords=new ArrayList(Arrays.asList(arr)); String pattern="HT" ; CamelCase(words,pattern); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation CamelCase( words : Sequence(String), pattern : String) : void pre: true post: true activity: ( var map : Map(String,Sequence(String)) ; map := Map{} ; var i : int ; i := 0 ; while i < words->size() do ( ( var str : String ; str := "" ; var l : int ; l := words->at(i+1)->size() ; var j : int ; j := 0 ; while j < l do ( ( if (words->at(i+1)->at(j+1) >= 'A' & words->at(i+1)->at(j+1) <= 'Z') then ( str := str+(words->at(i+1)->at(j+1)) ; map := map->union(Map{str |-> list(map->at(str), words->at(i+1))}) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var wordFound : boolean ; wordFound := false ; for (it : map->asSet()) do ( ( if (it.getKey() = pattern) then ( wordFound := true ; for (s : it.getValue()) do ( OclFile["System.out"].print(s + "\n") ; ) ) else skip ) ) ; if (not(wordFound)) then ( OclFile["System.out"].print("No match found") ) else skip ; ); static operation list( list : Sequence(String), str : String) : Sequence(String) pre: true post: true activity: ( var temp : Sequence(String) ; temp := Sequence{} ; if (list /= null) then temp := temp->union(list) ; else skip ; temp := temp->including(str) ; return temp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"Hi","Hello","HelloWorld","HiTech","HiGeek","HiTechWorld","HiTechCity","HiTechLab"} ; var words : Sequence(String) ; words := Sequence{}->union(arr) ; var pattern : String ; pattern := "HT" ; execute CamelCase(words, pattern) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int summation(int n){ int sum=0 ; for(int i=1 ; i<=n ; i++){ if(i % 2==1)sum+=(i*i); else sum-=(i*i); } return sum ; } public static void main(String[] args){ int N=2 ; System.out.println(summation(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation summation( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (i mod 2 = 1) then sum := sum+((i * i)) ; else sum := sum-((i * i)) ; ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 2 ; OclFile["System.out"].println(summation(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.Math ; class GFG { private static final int MAX=2147483647 ; static int[][] one=new int[100001][32]; static void make_prefix(int A[],int n){ for(int j=0 ; j<32 ; j++)one[0][j]=0 ; for(int i=1 ; i<=n ; i++){ int a=A[i-1]; for(int j=0 ; j<32 ; j++){ int x=(int)Math.pow(2,j); if((a & x)!=0)one[i][j]=1+one[i-1][j]; else one[i][j]=one[i-1][j]; } } } static int Solve(int L,int R){ int l=L,r=R ; int tot_bits=r-l+1 ; int X=MAX ; for(int i=0 ; i<31 ; i++){ int x=one[r][i]-one[l-1][i]; if(x>=tot_bits-x){ int ith_bit=(int)Math.pow(2,i); X=X ^ ith_bit ; } } return X ; } public static void main(String[] args){ int n=5,q=3 ; int A[]={ 210,11,48,22,133 }; int L[]={ 1,4,2 },R[]={ 3,14,4 }; make_prefix(A,n); for(int j=0 ; jcollect(Integer.subrange(1,32)->collect(0)); static operation make_prefix( A : Sequence(int), n : int) : void pre: true post: true activity: ( var j : int ; j := 0 ; while j < 32 do ( one[0+1][j+1] := 0 ; ; j := j + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( var a : int ; a := A[i - 1+1] ; var j : int ; j := 0 ; while j < 32 do ( ( var x : int ; x := 2->pow(j)->oclAsType(int) ; if ((MathLib.bitwiseAnd(a,x)) /= 0) 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] ; ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation Solve( L : int, R : int) : int pre: true post: true activity: ( var l : int ; l := L ; var r : int ; r := R ; var tot_bits : int ; tot_bits := r - l + 1 ; var X : int ; X := MAX ; var i : int ; i := 0 ; while i < 31 do ( ( var x : int ; x := one[r+1][i+1] - one[l - 1+1][i+1] ; if (x >= tot_bits - x) then ( var ith_bit : int ; ith_bit := 2->pow(i)->oclAsType(int) ; X := MathLib.bitwiseXor(X,ith_bit) ) else skip ) ; i := i + 1 ) ; return X ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var q : int ; q := 3 ; var A : Sequence(int) ; A := Sequence{210,11,48,22,133} ; var L : Sequence(int) ; L := Sequence{1,4,2} ; var R : Sequence(void) ; R := Sequence{3,14,4} ; execute make_prefix(A, n) ; var j : int ; j := 0 ; while j < q do ( OclFile["System.out"].println(Solve(L[j+1], R[j+1])) ; ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void maxSum(int[] a,int n){ Vectorl=new Vector(); int s=0 ; for(int i=0 ; i=0)continue ; if(i==0)l.add(i+1); else { l.add(i+1); l.add(i); } } System.out.println(s); for(int i=0 ; i= 0) then continue else skip ; if (i = 0) then l := l->including(i + 1) ; else ( l := l->including(i + 1) ; l := l->including(i) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; var i : int ; i := 0 ; while i < l->size() do ( OclFile["System.out"].print(l->at(i+1) + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; var a : Sequence(int) ; a := Sequence{1,-2,-3,4} ; execute maxSum(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GfG { static void printArray(int arr[],int n){ for(int i=0 ; icollect(0) ; arr := arr.subrange(1,0)^(arr.subrange(0+1,2 * n)->sort())^arr.subrange(2 * n+1,arr.size) ; var i : int ; i := 0 ; while i < n do ( newArr[i+1] := arr[i + n+1] ; ; i := i + 1 ) ; execute printArray(newArr, n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{4,8,3,1,3,7,0,4} ; var n : int ; n := arr->size() ; execute printMaxMean(arr, n / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void printCompositions(int arr[],int n,int i){ int MAX_POINT=3 ; if(n==0){ printArray(arr,i); } else if(n>0){ for(int k=1 ; k<=MAX_POINT ; k++){ arr[i]=k ; printCompositions(arr,n-k,i+1); } } } static void printArray(int arr[],int m){ for(int i=0 ; i 0) then ( var k : int ; k := 1 ; while k <= MAX_POINT do ( ( arr[i+1] := k ; execute printCompositions(arr, n - k, i + 1) ) ; k := k + 1 ) ) else skip ; ); static operation printArray( arr : Sequence(int), m : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < m do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var size : int ; size := 100 ; var arr : Sequence(int) ; arr := Integer.subrange(1,size)->collect(0) ; OclFile["System.out"].println("Different compositions formed by 1,2 and 3 of " + n + " are") ; execute printCompositions(arr, n, 0) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static String areAllBitsSet(int n){ if(n==0)return "No" ; if(((n+1)& n)==0)return "Yes" ; return "No" ; } public static void main(String[] args){ int n=7 ; System.out.println(areAllBitsSet(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation areAllBitsSet( n : int) : String pre: true post: true activity: ( if (n = 0) then return "No" else skip ; if (((n + 1) & n) = 0) then return "Yes" else skip ; return "No" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 7 ; OclFile["System.out"].println(areAllBitsSet(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static String areAllBitsSet(int n){ if(n==0)return "No" ; while(n>0){ if((n & 1)==0)return "No" ; n=n>>1 ; } return "Yes" ; } public static void main(String[] args){ int n=7 ; System.out.println(areAllBitsSet(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation areAllBitsSet( n : int) : String pre: true post: true activity: ( if (n = 0) then return "No" else skip ; while (n > 0) do ( if ((n & 1) = 0) then return "No" else skip ; n := (n/(2->pow(1)))->oclAsType(long) ) ; return "Yes" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 7 ; OclFile["System.out"].println(areAllBitsSet(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GfG { public static int sumofFactors(int n){ if(n % 2!=0)return 0 ; int res=1 ; for(int i=2 ; i<=Math.sqrt(n); i++){ int count=0,curr_sum=1 ; int curr_term=1 ; while(n % i==0){ count++; n=n/i ; if(i==2 && count==1)curr_sum=0 ; curr_term*=i ; curr_sum+=curr_term ; } res*=curr_sum ; } if(n>=2)res*=(1+n); return res ; } public static void main(String argc[]){ int n=18 ; System.out.println(sumofFactors(n)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation sumofFactors( n : int) : int pre: true post: true activity: ( if (n mod 2 /= 0) then return 0 else skip ; var res : int ; res := 1 ; var i : int ; i := 2 ; while i <= (n)->sqrt() do ( ( var count : int ; count := 0 ; var curr_sum : int ; curr_sum := 1 ; var curr_term : int ; curr_term := 1 ; while (n mod i = 0) do ( count := count + 1 ; n := n / 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) ) ; i := i + 1 ) ; if (n >= 2) then res := res*((1 + n)) ; else skip ; return res ); static operation main( argc : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 18 ; OclFile["System.out"].println(sumofFactors(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1474 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ int n=scanner.nextInt(); String b=scanner.next(); char tempCharD='0' ; StringBuilder a=new StringBuilder(); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var b : String ; b := scanner.getCurrent() ; var tempCharD : String ; tempCharD := '0' ; var a : String ; a := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( var charChecking : String ; charChecking := b->at(i+1) ; if (charChecking = '1') then ( if (tempCharD /= '2') then ( a := a + StringLib.newString('1') ; tempCharD := '2' ) else ( a := a + StringLib.newString('0') ; tempCharD := '1' ) ) else ( if (tempCharD /= '1') then ( a := a + StringLib.newString('1') ; tempCharD := '1' ) else ( a := a + StringLib.newString('0') ; tempCharD := '0' ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(a) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A1474 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int z=0 ; ztoInteger() ; var z : int ; z := 0 ; while z < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; OclFile["System.out"].print(1) ; var last : int ; last := s->at(0+1) - ('0')->char2byte() + 1 ; var i : int ; i := 1 ; while i < n do ( ( if (s->at(i+1) - ('0')->char2byte() + 1 /= last) then ( OclFile["System.out"].print(1) ; last := s->at(i+1) - ('0')->char2byte() + 1 ) else ( OclFile["System.out"].print(0) ; last := s->at(i+1) - ('0')->char2byte() ) ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ; z := z + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.PrintStream ; import java.util.Scanner ; public class Main { public static void main(String[] args){ long input=in.nextLong(); long round=input/11 ; long mod=input % 11 ; long result=round*2 ; if(00){ int n=sc.nextInt(); String num=sc.next(); int pre=0 ; int select=0 ; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var num : String ; num := sc.getCurrent() ; var pre : int ; pre := 0 ; var select : int ; select := 0 ; var i : int ; i := 0 ; while i < n do ( ( if ((num->at(i+1) - ('0')->char2byte() + 1) /= pre) then ( OclFile["System.out"].print(1 + "") ; select := 1 ) else ( OclFile["System.out"].print(0 + "") ; select := 0 ) ; pre := num->at(i+1) - ('0')->char2byte() + select ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < x do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var s : String ; s := sc.nextLine() ; var temp : int ; temp := s->at(0+1) - 48 + 1 ; var res : String ; res := StringLib.newString("1") ; var i1 : int ; i1 := 1 ; while i1 < s->size() do ( ( if ((s->at(i1+1) - 48 + 1) = temp) then ( res := res + StringLib.newString("0") ; temp := s->at(i1+1) - 48 ) else ( res := res + StringLib.newString("1") ; temp := s->at(i1+1) - 48 + 1 ) ) ; i1 := i1 + 1 ) ; OclFile["System.out"].println(res) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(); int k=scanner.nextInt(); int[] x=new int[n],y=new int[n]; IntStream.range(0,n).forEach(i->{ x[i]=scanner.nextInt(); y[i]=scanner.nextInt(); } ); long answer=Long.MAX_VALUE ; int[] sortedX=x.clone(); int[] sortedY=y.clone(); Arrays.sort(sortedX); Arrays.sort(sortedY); for(int xi=0 ; xi=k){ answer=Math.min(answer,1L*(sortedX[xj]-sortedX[xi])*(sortedY[yj]-sortedY[yi])); } } } } } System.out.println(answer); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,n)->collect(0) ; for i : Integer.subrange(0, n-1) do ( skip) ; var answer : long ; answer := "9223372036854775807"->toLong() ; var sortedX : Sequence(int) ; sortedX := x->copy() ; var sortedY : Sequence(int) ; sortedY := y->copy() ; sortedX := sortedX->sort() ; sortedY := sortedY->sort() ; var xi : int ; xi := 0 ; while xi < n do ( ( var xj : int ; xj := xi + 1 ; while xj < n do ( ( var yi : int ; yi := 0 ; while yi < n do ( ( var yj : int ; yj := yi + 1 ; while yj < n do ( ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if ((sortedX[xi+1] <= x[i+1]) & (x[i+1] <= sortedX[xj+1]) & (sortedY[yi+1] <= y[i+1]) & (y[i+1] <= sortedY[yj+1])) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; if (count >= k) then ( answer := Set{answer, 1L * (sortedX[xj+1] - sortedX[xi+1]) * (sortedY[yj+1] - sortedY[yi+1])}->min() ) else skip ) ; yj := yj + 1 ) ) ; yi := yi + 1 ) ) ; xj := xj + 1 ) ) ; xi := xi + 1 ) ; OclFile["System.out"].println(answer) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int q=sc.nextInt(); int[] l=new int[q]; int[] r=new int[q]; for(int i=0 ; itoInteger() ; var l : Sequence(int) ; l := Integer.subrange(1,q)->collect(0) ; var r : Sequence(int) ; r := Integer.subrange(1,q)->collect(0) ; var i : int ; i := 0 ; while i < q do ( ( l[i+1] := sc.getCurrent()->toInteger() ; r[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var isPrimeNum : Sequence(boolean) ; isPrimeNum := Integer.subrange(1,100001)->collect(false) ; var i : int ; i := 1 ; while i <= 100000 do ( ( isPrimeNum[i+1] := true ) ; i := i+(2) ) ; isPrimeNum[0+1] := false ; isPrimeNum[1+1] := false ; isPrimeNum[2+1] := true ; var i : int ; i := 3 ; while i * i <= 100000 do ( ( if (isPrimeNum[i+1] = true) then ( var j : int ; j := i * i ; while j <= 100000 do ( ( isPrimeNum[j+1] := false ) ; j := j+(i * 2) ) ) else skip ) ; i := i+(2) ) ; var numOfLikeNumber : Sequence(int) ; numOfLikeNumber := Integer.subrange(1,100001)->collect(0) ; numOfLikeNumber[1+1] := 0 ; numOfLikeNumber[2+1] := 0 ; numOfLikeNumber[3+1] := 1 ; var i : int ; i := 4 ; while i <= 100000 do ( ( numOfLikeNumber[i+1] := numOfLikeNumber[i - 1+1] ; if (i mod 4 = 1) then ( if (isPrimeNum[i+1] & isPrimeNum[(i + 1) / 2+1]) then ( numOfLikeNumber[i+1] := numOfLikeNumber[i+1] + 1 ) else skip ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( OclFile["System.out"].println(numOfLikeNumber[r[i+1]+1] - numOfLikeNumber[l[i+1] - 1+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { System.setOut(new PrintStream(new BufferedOutputStream(System.out))); ListnumberList=new ArrayList<>(); for(int i=1 ; i<=100000 ; i+=2){ if(isPrime(i)&& isPrime((i+1)/2)){ numberList.add(i); } } int[] numbers=numberList.stream().mapToInt(i->i).toArray(); BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); int q=Integer.parseInt(reader.readLine()); for(int i=0 ; i=0){ return returnValue+1 ; } else { return-returnValue-1 ; } } private static boolean isPrime(int x){ return BigInteger.valueOf(x).isProbablePrime(100); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( setOut(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ; var numberList : Sequence(int) ; numberList := Sequence{} ; var i : int ; i := 1 ; while i <= 100000 do ( ( if (isPrime(i) & isPrime((i + 1) / 2)) then ( numberList := numberList->including(i) ) else skip ) ; i := i+(2) ) ; var numbers : Sequence(int) ; numbers := numberList->collect( _x1 | (lambda i : OclAny in i)->apply(_x1) )->asSequence() ; var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var q : int ; q := (reader.readLine())->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var words : Sequence(String) ; words := reader.readLine()->split(" ") ; var l : int ; l := (words[0+1])->toInteger() ; var r : int ; r := (words[1+1])->toInteger() ; var count : int ; count := count(numbers, r) - count(numbers, l - 1) ; OclFile["System.out"].println(count) ; ) ; i := i + 1 ) ; OclFile["System.out"].flush() ; ); static operation count( xs : Sequence(int), x : int) : int pre: true post: true activity: ( var returnValue : int ; returnValue := (xs->indexOf(x) - 1) ; if (returnValue >= 0) then ( return returnValue + 1 ) else ( return -returnValue - 1 ) ); static operation isPrime( x : int) : boolean pre: true post: true activity: ( return (x + "")->toLong().isProbablePrime(100) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ boolean prime[]=new boolean[100000]; prime[0]=true ; for(int i=1 ; i<100000 ; i++){ if(! prime[i]){ for(int j=1 ; jcollect(false) ; prime[0+1] := true ; var i : int ; i := 1 ; while i < 100000 do ( ( if (not(prime[i+1])) then ( var j : int ; j := 1 ; while j < (100000 / (i + 1))->ceil() do ( ( prime[(i + 1) * (j + 1) - 1+1] := true ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; var count : Sequence(int) ; count := Integer.subrange(1,100000)->collect(0) ; var i : int ; i := 1 ; while i < 100000 do ( ( if ((not((prime[i - 1+1]))) & (not((prime[(i + 1) / 2 - 1+1])))) then ( count[i+1] := count[i+1]+(count[i - 1+1] + 1) ) else ( count[i+1] := count[i - 1+1] ) ) ; i := i + 1 ) ; var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := scan.getCurrent()->toInteger() ; var l : Sequence(int) ; l := Integer.subrange(1,q)->collect(0) ; var r : Sequence(int) ; r := Integer.subrange(1,q)->collect(0) ; var i : int ; i := 0 ; while i < q do ( ( l[i+1] := scan.getCurrent()->toInteger() ; r[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( OclFile["System.out"].println(count[r[i+1]+1] - count[l[i+1] - 1+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.HashSet ; import java.util.List ; import java.util.Set ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int q=Integer.parseInt(br.readLine()); Listsosuu=sosuuList(100000); Setset=new HashSet(); set.addAll(sosuu); int[] sum=new int[1000001]; int cnt=0 ; for(int i=1 ; isosuuList(int n){ Listsosuu=new ArrayList(); for(int i=2 ; i<=n ; i++){ int r=(int)Math.sqrt(i); boolean flg=false ; for(Integer o : sosuu){ if(rtoInteger() ; var sosuu : Sequence(int) ; sosuu := sosuuList(100000) ; var set : Set(int) ; set := Set{} ; set := set->union(sosuu) ; var sum : Sequence(int) ; sum := Integer.subrange(1,1000001)->collect(0) ; var cnt : int ; cnt := 0 ; var i : int ; i := 1 ; while i < sum->size() do ( ( if (i mod 2 = 1 & set->includes(i) & set->includes((i + 1) / 2)) then ( cnt := cnt + 1 ) else skip ; sum[i+1] := cnt ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( var sa : Sequence(String) ; sa := br.readLine()->split(" ") ; var l : int ; l := (sa[0+1])->toInteger() ; var r : int ; r := (sa[1+1])->toInteger() ; OclFile["System.out"].println(sum[r+1] - sum[l - 1+1]) ) ; i := i + 1 ) ; skip ; ); static operation sosuuList( n : int) : Sequence(int) pre: true post: true activity: ( var sosuu : Sequence(int) ; sosuu := Sequence{} ; var i : int ; i := 2 ; while i <= n do ( ( var r : int ; r := (i)->sqrt()->oclAsType(int) ; var flg : boolean ; flg := false ; for (o : sosuu) do ( ( if (r < o) then ( break ) else skip ; if (i mod o = 0) then ( flg := true ; break ) else skip ) ) ; if (not(flg)) then ( sosuu := sosuu->including(i) ) else skip ) ; i := i + 1 ) ; return sosuu ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); boolean[] np=new boolean[100001]; np[0]=true ; np[1]=true ; int[] pc=new int[100001]; int c=0 ; for(int i=2 ; i<=100000 ; i++){ if(! np[i]){ ; if(! np[(i+1)/2])c++; for(int j=2 ; i*j<=100000 ; j++){ np[i*j]=true ; } } pc[i]=c ; } int q=Integer.parseInt(sc.next()); for(int i=0 ; icollect(false) ; np[0+1] := true ; np[1+1] := true ; var pc : Sequence(int) ; pc := Integer.subrange(1,100001)->collect(0) ; var c : int ; c := 0 ; var i : int ; i := 2 ; while i <= 100000 do ( ( if (not(np[i+1])) then ( if (not(np[(i + 1) / 2+1])) then c := c + 1 ; else skip ; var j : int ; j := 2 ; while i * j <= 100000 do ( ( np[i * j+1] := true ) ; j := j + 1 ) ) else skip ; pc[i+1] := c ) ; i := i + 1 ) ; var q : int ; q := (sc.getCurrent())->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int optimalStrategyOfGame(int arr[],int n){ int table[][]=new int[n][n]; int gap,i,j,x,y,z ; for(gap=0 ; gapcollect(Integer.subrange(1,n)->collect(0)) ; var gap : int ; var i : int ; var j : int ; var x : int ; var y : int ; var z : int ; gap := 0 ; while gap < n do ( ( i := 0 ; j := gap ; while j < n do ( ( x := if ((i + 2) <= j) then table[i + 2+1][j+1] else 0 endif ; y := if ((i + 1) <= (j - 1)) then table[i + 1+1][j - 1+1] else 0 endif ; z := if (i <= (j - 2)) then table[i+1][j - 2+1] else 0 endif ; table[i+1][j+1] := Set{arr[i+1] + Set{x, y}->min(), arr[j+1] + Set{y, z}->min()}->max() ) ; i := i + 1 ; j := j + 1 ) ) ; gap := gap + 1 ) ; return table[0+1][n - 1+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr1 : Sequence(int) ; arr1 := Sequence{8,15,3,7} ; var n : int ; n := arr1->size() ; OclFile["System.out"].println("" + optimalStrategyOfGame(arr1, n)) ; var arr2 : Sequence(int) ; arr2 := Sequence{2,2,2,2} ; n := arr2->size() ; OclFile["System.out"].println("" + optimalStrategyOfGame(arr2, n)) ; var arr3 : Sequence(int) ; arr3 := Sequence{20,30,2,2,2,10} ; n := arr3->size() ; OclFile["System.out"].println("" + optimalStrategyOfGame(arr3, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Fibonacci { static int fibonacci(int n){ int a=0 ; int b=1 ; int c=0 ; if(n<=1)return n ; for(int i=2 ; i<=n ; i++){ c=a+b ; a=b ; b=c ; } return c ; } static boolean isMultipleOf10(int n){ int f=fibonacci(30); return(f % 10==0); } public static void main(String[] args){ int n=30 ; if(isMultipleOf10(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class Fibonacci { static operation fibonacci( n : int) : int pre: true post: true activity: ( var a : int ; a := 0 ; var b : int ; b := 1 ; var c : int ; c := 0 ; if (n <= 1) then return n else skip ; var i : int ; i := 2 ; while i <= n do ( ( c := a + b ; a := b ; b := c ) ; i := i + 1 ) ; return c ); static operation isMultipleOf10( n : int) : boolean pre: true post: true activity: ( var f : int ; f := fibonacci(30) ; return (f mod 10 = 0) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 30 ; if (isMultipleOf10(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.regex.Pattern ; import java.util.regex.Matcher ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); String postnumber=sc.next(); Pattern pattern=Pattern.compile("^[0-9] {"+x+"}-[0-9] {"+y+"}$"); Matcher matcher=pattern.matcher(postnumber); if(matcher.find()){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var postnumber : String ; postnumber := sc.getCurrent() ; var pattern : OclRegex ; pattern := OclRegex.compile("^[0-9] {" + x + "}-[0-9] {" + y + "}$") ; var matcher : OclRegex ; matcher := pattern.matcher(postnumber) ; if (matcher.nextMatch()) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.ArrayList ; import java.util.Scanner ; class Main { public static void main(String args[])throws IOException { @ SuppressWarnings("resource")Scanner cin=new Scanner(System.in); ArrayListinLines=new ArrayList(); for(; cin.hasNext(); ){ inLines.add(cin.nextLine()); } Solver solver=new Solver(); solver.solve(inLines); } } class Solver { public void solve(ArrayListinLines){ long x=Long.parseLong(inLines.get(0)); long ans=(x/11)*2 ; if(x % 11!=0){ if(x % 11<=6)ans+=1 ; else ans+=2 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var inLines : Sequence(String) ; inLines := Sequence{} ; while cin.hasNext() do ( ( inLines := inLines->including(cin.nextLine()) ) ) ; var solver : Solver ; solver := Solver.newSolver() ; solver.solve(inLines) ; ); } class Solver { operation solve( inLines : Sequence(String)) : void pre: true post: true activity: ( var x : long ; x := (inLines->at(0+1))->toLong() ; var ans : long ; ans := (x / 11) * 2 ; if (x mod 11 /= 0) then ( if (x mod 11 <= 6) then ans := ans+(1) ; else ans := ans+(2) ; ) else skip ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); String s=sc.next(); sc.close(); for(int i=0 ; ia)&&(s.charAt(i)<'0' || s.charAt(i)>'9')){ System.out.print("No"); return ; } if(i==a && s.charAt(i)!='-'){ System.out.print("No"); return ; } } System.out.print("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; skip ; var i : int ; i := 0 ; while i < s->size() do ( ( if ((i < a or i > a) & (s->at(i+1) < '0' or s->at(i+1) > '9')) then ( OclFile["System.out"].print("No") ; return ) else skip ; if (i = a & s->at(i+1) /= '-') then ( OclFile["System.out"].print("No") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int sumDivisibles(int A,int B,int M){ int sum=0 ; for(int i=A ; i<=B ; i++)if(i % M==0)sum+=i ; return sum ; } public static void main(String[] args){ int A=6,B=15,M=3 ; System.out.print(sumDivisibles(A,B,M)+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumDivisibles( A : int, B : int, M : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := A ; while i <= B do ( if (i mod M = 0) then sum := sum+(i) ; else skip ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 6 ; var B : int ; B := 15 ; var M : int ; M := 3 ; OclFile["System.out"].print(sumDivisibles(A, B, M) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=1000 ; static char[] replaceSpaces(char[] str){ int space_count=0,i=0 ; for(i=0 ; iMAX)return str ; int index=new_length-1 ; char[] new_str=str ; str=new char[new_length]; for(int j=i-1 ; j>=0 ; j--){ if(new_str[j]==' '){ str[index]='0' ; str[index-1]='2' ; str[index-2]='%' ; index=index-3 ; } else { str[index]=new_str[j]; index--; } } return str ; } public static void main(String[] args){ char[] str="Mr John Smith ".toCharArray(); str=replaceSpaces(str); for(int i=0 ; isize() do ( if (str[i+1] = ' ') then space_count := space_count + 1 ; else skip ; ; i := i + 1 ) ; while (str[i - 1+1] = ' ') do ( space_count := space_count - 1 ; i := i - 1 ) ; var new_length : int ; new_length := i + space_count * 2 ; if (new_length > MAX) then return str else skip ; var index : int ; index := new_length - 1 ; var new_str : Sequence(String) ; new_str := str ; str := Integer.subrange(1,new_length)->collect(0) ; var j : int ; j := i - 1 ; while j >= 0 do ( ( if (new_str[j+1] = ' ') then ( str[index+1] := '0' ; str[index - 1+1] := '2' ; str[index - 2+1] := '%' ; index := index - 3 ) else ( str[index+1] := new_str[j+1] ; index := index - 1 ) ) ; j := j - 1 ) ; return str ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : Sequence(String) ; str := "Mr John Smith "->characters() ; str := replaceSpaces(str) ; var i : int ; i := 0 ; while i < str->size() do ( OclFile["System.out"].print(str[i+1]) ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner in=new Scanner(System.in); System.out.println(getData(in.nextInt(),in.nextInt(),in.next())); } public static String getData(int a,int b,String s){ for(int i=0 ; i57)return "No" ; } else if(i==a){ if(s.charAt(i)!='-')return "No" ; } else { if(s.charAt(i)<48 || s.charAt(i)>57)return "No" ; } } return "Yes" ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(getData(in.getCurrent()->toInteger(), in.getCurrent()->toInteger(), in.getCurrent())) ); static operation getData( a : int, b : int, s : String) : String pre: true post: true activity: ( var i : int ; i := 0 ; while i < s->size() do ( ( if (i < a) then ( if (s->at(i+1) < 48 or s->at(i+1) > 57) then return "No" else skip ) else if (i = a) then ( if (s->at(i+1) /= '-') then return "No" else skip ) else ( if (s->at(i+1) < 48 or s->at(i+1) > 57) then return "No" else skip ) ; ) ; i := i + 1 ) ; return "Yes" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int flag=0 ; String s=sc.next(); for(int i=0 ; itoInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var flag : int ; flag := 0 ; var s : String ; s := sc.getCurrent() ; var i : int ; i := 0 ; while i < a do ( ( if (s.subrange(i+1,i + 1) = "-") then ( flag := 1 ) else skip ) ; i := i + 1 ) ; if (not(s.subrange(a+1,a + 1) = "-")) then ( flag := 1 ) else skip ; var i : int ; i := a + 1 ; while i < a + b + 1 do ( ( if (s.subrange(i+1,i + 1) = "-") then ( flag := 1 ) else skip ) ; i := i + 1 ) ; if (flag = 1) then ( OclFile["System.out"].println("No") ) else ( OclFile["System.out"].println("Yes") ) ; ); static operation res( n : int) : int pre: true post: true activity: ( if (n = 1) then ( return 1 ) else skip ; return n + res(n - 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int A=sc.nextInt(); int B=sc.nextInt(); String S=sc.next(); String AS=S.substring(0,A); String haihun=S.substring(A,A+1); String BS=S.substring(A+1,A+B+1); if(! isNumber(AS)|| ! isNumber(BS)){ System.out.println("No"); return ; } if(! haihun.equals("-")){ System.out.println("No"); return ; } System.out.println("Yes"); } public static boolean isNumber(String num){ try { Integer.parseInt(num); return true ; } catch(NumberFormatException e){ return false ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var S : String ; S := sc.getCurrent() ; var AS : String ; AS := S.subrange(0+1,A) ; var haihun : String ; haihun := S.subrange(A+1,A + 1) ; var BS : String ; BS := S.subrange(A + 1+1,A + B + 1) ; if (not(isNumber(AS)) or not(isNumber(BS))) then ( OclFile["System.out"].println("No") ; return ) else skip ; if (not(haihun = "-")) then ( OclFile["System.out"].println("No") ; return ) else skip ; OclFile["System.out"].println("Yes") ; ); static operation isNumber( num : String) : boolean pre: true post: true activity: ( try ( Integer.parseInt(num) ; return true ) catch (e : IncorrectElementException) do ( return false ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static boolean checkfact(int N,int countprime,int prime){ int countfact=0 ; if(prime==2 || prime==3)countfact++; int divide=prime ; while(N/divide!=0){ countfact+=N/divide ; divide=divide*divide ; } if(countfact>=countprime)return true ; else return false ; } static boolean check(int N){ int sumsquares=(N+1)*(2*N+1); int countprime=0 ; for(int i=2 ; i<=Math.sqrt(sumsquares); i++){ int flag=0 ; while(sumsquares % i==0){ flag=1 ; countprime++; sumsquares/=i ; } if(flag==1){ if(! checkfact(N-1,countprime,i))return false ; countprime=0 ; } } if(sumsquares!=1)if(! checkfact(N-1,1,sumsquares))return false ; return true ; } public static void main(String[] args){ int N=5 ; if(check(N))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation checkfact( N : int, countprime : int, prime : int) : boolean pre: true post: true activity: ( var countfact : int ; countfact := 0 ; if (prime = 2 or prime = 3) then countfact := countfact + 1 ; else skip ; var divide : int ; divide := prime ; while (N / divide /= 0) do ( countfact := countfact+(N / divide) ; divide := divide * divide ) ; if (countfact >= countprime) then return true else return false ; ); static operation check( N : int) : boolean pre: true post: true activity: ( var sumsquares : int ; sumsquares := (N + 1) * (2 * N + 1) ; var countprime : int ; countprime := 0 ; var i : int ; i := 2 ; while i <= (sumsquares)->sqrt() do ( ( var flag : int ; flag := 0 ; while (sumsquares mod i = 0) do ( flag := 1 ; countprime := countprime + 1 ; sumsquares := sumsquares/(i) ) ; if (flag = 1) then ( if (not(checkfact(N - 1, countprime, i))) then return false else skip ; countprime := 0 ) else skip ) ; i := i + 1 ) ; if (sumsquares /= 1) then if (not(checkfact(N - 1, 1, sumsquares))) then return false else skip ; else skip ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 5 ; if (check(N)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int GCD(int a,int b){ return b==0 ? a : GCD(b,a % b); } static boolean isSplittable(int n,int m){ int total_sum=(n*(n+1))/2 ; int sum_s1=(total_sum+m)/2 ; int sum_s2=total_sum-sum_s1 ; if(total_sum ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void manipulateString(String str){ char[] str1=str.toCharArray(); for(int i=0 ; icharacters() ; var i : int ; i := 0 ; while i < str->size() do ( ( var asc : int ; asc := str1[i+1] ; var rem : int ; rem := asc - (26 - (str1[i+1] - 97)) ; var m : int ; m := rem mod 26 ; str1[i+1] := (m + 'a')->oclAsType(String) ) ; i := i + 1 ) ; var str2 : String ; str2 := (str1)->sum() ; OclFile["System.out"].println(str2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; execute manipulateString(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Despression { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s=sc.next(); int hr,min ; hr=Integer.parseInt(s.substring(0,2)); min=Integer.parseInt(s.substring(3,5)); if(hr>=12){ hr=hr-12 ; } double ans1=30*hr+0.5*min ; int ans2=6*min ; int n=(int)ans1 ; if(ans1-n==0){ System.out.println(n+" "+ans2); } else System.out.println(ans1+" "+ans2); } } ------------------------------------------------------------ OCL File: --------- class Despression { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; var hr : int ; var min : int ; hr := (s.subrange(0+1,2))->toInteger() ; min := (s.subrange(3+1,5))->toInteger() ; if (hr >= 12) then ( hr := (hr)->char2byte() - 12 ) else skip ; var ans1 : double ; ans1 := 30 * hr + 0.5 * min ; var ans2 : int ; ans2 := 6 * min ; var n : int ; n := ans1->oclAsType(int) ; if (ans1 - n = 0) then ( OclFile["System.out"].println(n + " " + ans2) ) else OclFile["System.out"].println(ans1 + " " + ans2) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Despression { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s=sc.next(); int hr,min ; hr=Integer.parseInt(s.substring(0,2)); min=Integer.parseInt(s.substring(3,5)); if(hr>=12){ hr=hr-12 ; } double ans1=30*hr+0.5*min ; int ans2=6*min ; int n=(int)ans1 ; if(ans1-n==0){ System.out.println(n+" "+ans2); } else System.out.println(ans1+" "+ans2); } } ------------------------------------------------------------ OCL File: --------- class Despression { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; var hr : int ; var min : int ; hr := (s.subrange(0+1,2))->toInteger() ; min := (s.subrange(3+1,5))->toInteger() ; if (hr >= 12) then ( hr := (hr)->char2byte() - 12 ) else skip ; var ans1 : double ; ans1 := 30 * hr + 0.5 * min ; var ans2 : int ; ans2 := 6 * min ; var n : int ; n := ans1->oclAsType(int) ; if (ans1 - n = 0) then ( OclFile["System.out"].println(n + " " + ans2) ) else OclFile["System.out"].println(ans1 + " " + ans2) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CF80B { public static void main(String[] args){ Scanner in=new Scanner(System.in); String[] s=in.next().split(":"); int h=Integer.parseInt(s[0]); int m=Integer.parseInt(s[1]); int nm=(6*m)% 360 ; double nh=(30*h)% 360 ; nh+=m/2.0 ; System.out.println(nh+" "+nm); } } ------------------------------------------------------------ OCL File: --------- class CF80B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : Sequence(String) ; s := in.getCurrent()->split(":") ; var h : int ; h := (s[0+1])->toInteger() ; var m : int ; m := (s[1+1])->toInteger() ; var nm : int ; nm := (6 * m) mod 360 ; var nh : double ; nh := (30 * h) mod 360 ; nh := nh+(m / 2.0) ; OclFile["System.out"].println(nh + " " + nm) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int calgcd(int a,int b){ if(b==0)return a ; return calgcd(b,a % b); } static int getCount(int[] a,int n){ int gcd=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(getCount(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new B().doIt(); } class B { void doIt(){ int n=sc.nextInt(); String str=sc.next(); char ctr[]=str.toCharArray(); int m=sc.nextInt(); int num=n ; StringBuilder sb=new StringBuilder(); for(int i=0 ; itoInteger() ; var str : String ; str := sc.getCurrent() ; var ctr : Sequence(String) ; ctr := str->characters() ; var m : int ; m := sc.getCurrent()->toInteger() ; var num : int ; num := n ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( if (m = 0) then ( sb := sb + StringLib.newString(ctr[i+1]) ) else if (m < num) then ( if (ctr[i+1] = '0') then ( sb := sb + StringLib.newString(1) ; m := m - 1 ) else ( sb := sb + StringLib.newString(1) ) ) else ( if (ctr[i+1] = '0') then sb := sb + StringLib.newString(1) ; else sb := sb + StringLib.newString(0) ; ) ; ; num := num - 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CF80B { public static void main(String[] args){ Scanner in=new Scanner(System.in); String[] s=in.next().split(":"); int h=Integer.parseInt(s[0]); int m=Integer.parseInt(s[1]); int nm=(m*6)% 360 ; double nh=(h*30)% 360 ; nh+=m/2.0 ; System.out.println(nh+" "+nm); } } ------------------------------------------------------------ OCL File: --------- class CF80B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : Sequence(String) ; s := in.getCurrent()->split(":") ; var h : int ; h := (s[0+1])->toInteger() ; var m : int ; m := (s[1+1])->toInteger() ; var nm : int ; nm := (m * 6) mod 360 ; var nh : double ; nh := (h * 30) mod 360 ; nh := nh+(m / 2.0) ; OclFile["System.out"].println(nh + " " + nm) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.geom.Line2D ; import java.awt.geom.Point2D ; import java.util.*; public class Main { Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ while(sc.hasNext()){ new aoj0057().doIt(); } } class aoj0057 { int a[]=new int[10001]; void DP(){ a[0]=1 ; for(int i=1 ; i<=10000 ; i++)a[i]=a[i-1]+i ; } void doIt(){ DP(); int n=sc.nextInt(); System.out.println(a[n]); } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( while (sc.hasNext()) do ( aoj0057.newaoj0057().doIt() ) ); class aoj0057 { attribute a : int := Integer.subrange(1,10001)->collect(0); operation DP() : void pre: true post: true activity: ( a[0+1] := 1 ; var i : int ; i := 1 ; while i <= 10000 do ( a[i+1] := a[i - 1+1] + i ; ; i := i + 1 ) ); operation doIt() : void pre: true post: true activity: ( execute DP() ; var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(a[n+1]) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; class Main { static boolean[] notPrime=new boolean[51000]; static int[] primes=new int[50000]; static int primeNum=0 ; static void setP(){ notPrime[0]=true ; notPrime[1]=true ; int count=0 ; for(int i=2 ; i<51000 ; i++){ if(! notPrime[i]){ primes[count]=i ; count++; } for(int j=2 ; j*i<5100 ; j++){ notPrime[i*j]=true ; } } primeNum=count ; } static boolean isPrime(int n){ return ! notPrime[n]; } public static void main(String args[]){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String line ; setP(); while((line=br.readLine())!=null){ if(line.isEmpty())break ; String[] spl=line.split(" "); int a=Integer.parseInt(spl[0]); if(a==0)break ; int cnt=2 ; for(int i=2 ; i<=a ; i++){ cnt+=1 ; cnt+=i-1 ; } System.out.println(cnt); } br.close(); } catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute notPrime : Sequence(boolean) := Integer.subrange(1,51000)->collect(false); static attribute primes : Sequence(int) := Integer.subrange(1,50000)->collect(0); static attribute primeNum : int := 0; static operation setP() : void pre: true post: true activity: ( notPrime[0+1] := true ; notPrime[1+1] := true ; var count : int ; count := 0 ; var i : int ; i := 2 ; while i < 51000 do ( ( if (not(notPrime[i+1])) then ( primes[count+1] := i ; count := count + 1 ) else skip ; var j : int ; j := 2 ; while j * i < 5100 do ( ( notPrime[i * j+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; primeNum := count ; ); static operation isPrime( n : int) : boolean pre: true post: true activity: ( return not(notPrime[n+1]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var line : String ; execute setP() ; line := br.readLine() ; while ((line) /= null) do ( skip ; ( if (line->isEmpty()) then break else skip ; var spl : Sequence(String) ; spl := line->split(" ") ; var a : int ; a := (spl[0+1])->toInteger() ; if (a = 0) then break else skip ; var cnt : int ; cnt := 2 ; var i : int ; i := 2 ; while i <= a do ( ( cnt := cnt+(1) ; cnt := cnt+(i - 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ) ; line := br.readLine() ; ) ; skip ) catch (e : ProgramException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true){ String str=br.readLine(); if(str==null){ break ; } int n=Integer.parseInt(str); System.out.println(AreaDivider.maximumAreaNum(n)); } } } class AreaDivider { static long maximumAreaNum(int n){ long result=2 ; for(int i=2 ; i<=n ; i++){ result+=i ; } return result ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (true) do ( var str : String ; str := br.readLine() ; if (str = null) then ( break ) else skip ; var n : int ; n := (str)->toInteger() ; OclFile["System.out"].println(AreaDivider.maximumAreaNum(n)) ) ); } class AreaDivider { static operation maximumAreaNum( n : int) : long pre: true post: true activity: ( var result : long ; result := 2 ; var i : int ; i := 2 ; while i <= n do ( ( result := result+(i) ) ; i := i + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public void doIt(){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int sum=1 ; for(int i=1 ; i<=n ; i++){ sum+=i ; } System.out.println(sum); } } public static void main(String[] args){ Main obj=new Main(); obj.doIt(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation doIt() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var sum : int ; sum := 1 ; var i : int ; i := 1 ; while i <= n do ( ( sum := sum+(i) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : Main ; obj := Main.newMain() ; obj.doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static int answer[]; static void makeTable(){ answer=new int[10001]; answer[0]=1 ; for(int i=1 ; i<10001 ; i++){ answer[i]=answer[i-1]+i ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); makeTable(); while(sc.hasNext()){ System.out.println(answer[sc.nextInt()]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute answer : Sequence(int); static operation makeTable() : void pre: true post: true activity: ( answer := Integer.subrange(1,10001)->collect(0) ; answer[0+1] := 1 ; var i : int ; i := 1 ; while i < 10001 do ( ( answer[i+1] := answer[i - 1+1] + i ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; execute makeTable() ; while (sc.hasNext()) do ( OclFile["System.out"].println(answer[sc.getCurrent()->toInteger()+1]) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public int[] sortArrayByParity(int[] A){ int lo=0,hi=A.length-1 ; while(loA[hi] % 2){ int tmp=A[hi]; A[hi]=A[lo]; A[lo]=tmp ; } if(A[lo] % 2==0)lo++; if(A[hi] % 2==1)hi--; } return A ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation sortArrayByParity( A : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var lo : int ; lo := 0 ; var hi : int ; hi := A->size() - 1 ; while (lo < hi) do ( if (A[lo+1] mod 2 > A[hi+1] mod 2) then ( var tmp : int ; tmp := A[hi+1] ; A[hi+1] := A[lo+1] ; A[lo+1] := tmp ) 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 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class pre1 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader obj=new FastReader(); int n=obj.nextInt(),a[]=new int[n],b[]=new int[n]; for(int i=0 ; imp=new HashMap<>(); for(int i=0 ; iset=new TreeSet<>(); int ptr=0 ; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : FastReader ; obj := FastReader.newFastReader() ; var n : int ; n := obj.nextInt() ; var a : Sequence(void) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(void) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := obj.nextInt() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := obj.nextInt() ; ; i := i + 1 ) ; var mp : Map(int,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < n do ( ( mp := mp->union(Map{a[i+1] |-> i}) ) ; i := i + 1 ) ; var set : Set(int) ; set := Set{} ; var ptr : int ; ptr := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (set->includes(b[i+1])) then OclFile["System.out"].print("0 ") ; else ( var idx : int ; idx := mp->at(b[i+1]) ; var count : int ; count := 0 ; while (ptr <= idx) do ( set := set->including(a[i+1]) ; ptr := ptr + 1 ; count := count + 1 ) ; OclFile["System.out"].print(count + " ") ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); boolean v[]=new boolean[n+1]; Arrays.fill(v,true); ArrayDequedq=new ArrayDeque<>(); for(int i=0 ; itoInteger() ; var v : Sequence(boolean) ; v := Integer.subrange(1,n + 1)->collect(false) ; v := v->collect(true) ; var dq : Sequence(int) ; dq := ArrayDeque.newArrayDeque() ; var i : int ; i := 0 ; while i < n do ( ( dq := dq->append(in.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var count : int ; count := 0 ; var x : int ; x := in.getCurrent()->toInteger() ; if (v[x+1]) then ( while (true) do ( var val : int ; val := dq->first() ; v[val+1] := false ; count := count + 1 ; if (x = val) then ( break ) else skip ) ) else skip ; skip ) ; i := i + 1 ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isWordPresent(String sentence,String word){ word=transform(word); sentence=transform(sentence); String[] s=sentence.split(" "); for(String temp : s){ if(temp.compareTo(word)==0){ return true ; } } return false ; } static String transform(String word){ return word.toUpperCase(); } public static void main(String[] args){ String s="Geeks for Geeks" ; String word="geeks" ; if(isWordPresent(s,word))System.out.print("Yes"); else System.out.print("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isWordPresent( sentence : String, word : String) : boolean pre: true post: true activity: ( word := transform(word) ; sentence := transform(sentence) ; var s : Sequence(String) ; s := sentence->split(" ") ; for (temp : s) do ( ( if (temp->compareTo(word) = 0) then ( return true ) else skip ) ) ; return false ); static operation transform( word : String) : String pre: true post: true activity: ( return word->toUpperCase() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "Geeks for Geeks" ; var word : String ; word := "geeks" ; if (isWordPresent(s, word)) then OclFile["System.out"].print("Yes") ; else OclFile["System.out"].print("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); char[] X=sc.next().toCharArray(); char[] next=new char[N]; int D=sc.nextInt(); for(int i=0 ; i=0 ; i--){ if(D!=0 && X[i]=='1'){ next[i]='0' ; D--; } } System.out.println(String.valueOf(next)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var X : Sequence(String) ; X := sc.getCurrent()->characters() ; var next : Sequence(String) ; next := Integer.subrange(1,N)->collect(0) ; var D : int ; D := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < N do ( ( if (D /= 0 & X[i+1] = '0') then ( next[i+1] := '1' ; D := D - 1 ) else ( next[i+1] := X[i+1] ) ) ; i := i + 1 ) ; var i : int ; i := N - 1 ; while i >= 0 do ( ( if (D /= 0 & X[i+1] = '1') then ( next[i+1] := '0' ; D := D - 1 ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println((next)->sum() ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static void print(ArrayLista,int n){ for(int i=0 ; i<=n ; i++)System.out.print(a.get(i)+" "); System.out.println(); } static void sort(ArrayLista,int n){ for(int i=n ; i>=0 ; i--)for(int j=n ; j>n-i ; j--)if(a.get(j)>a.get(j-1)){ int tempswap=a.get(j); a.remove(j); a.add(j,a.get(j-1)); a.remove(j-1); a.add(j-1,tempswap); } print(a,n); } public static void main(String[] args){ int n=6 ; ArrayLista=new ArrayList(); a.add(2); a.add(4); a.add(3); a.add(2); a.add(4); a.add(5); a.add(3); sort(a,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation print( a : Sequence(int), n : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i <= n do ( OclFile["System.out"].print(a->at(i+1) + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ); static operation sort( a : Sequence(int), n : int) : void pre: true post: true activity: ( var i : int ; i := n ; while i >= 0 do ( var j : int ; j := n ; while j > n - i do ( if (a->at(j+1) > a->at(j - 1+1)) then ( var tempswap : int ; tempswap := a->at(j+1) ; a := a->excludingAt(j+1) ; a->excludes(j, a->at(j - 1+1)) ; a := a->excludingFirst(j - 1) ; a->excludes(j - 1, tempswap) ; ) else skip ; ; j := j - 1 ) ; ; i := i - 1 ) ; execute print(a, n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var a : Sequence(int) ; a := Sequence{} ; a := a->including(2) ; a := a->including(4) ; a := a->including(3) ; a := a->including(2) ; a := a->including(4) ; a := a->including(5) ; a := a->including(3) ; execute sort(a, n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int getLeftmostBit(int n){ int m=0 ; while(n>1){ n=n>>1 ; m++; } return m ; } static int getNextLeftmostBit(int n,int m){ int temp=1<>1 ; m--; } return m ; } static int countSetBits(int n){ int m=getLeftmostBit(n); return countSetBits(n,m); } static int countSetBits(int n,int m){ if(n==0)return 0 ; m=getNextLeftmostBit(n,m); if(n==((int)1<<(m+1))-1)return(int)(m+1)*(1< 1) do ( n := (n/(2->pow(1)))->oclAsType(long) ; m := m + 1 ) ; return m ); static operation getNextLeftmostBit( n : int, m : int) : int pre: true post: true activity: ( var temp : int ; temp := (1*(2->pow(m)))->oclAsType(long) ; while (n < temp) do ( temp := (temp/(2->pow(1)))->oclAsType(long) ; m := m - 1 ) ; return m ); static operation countSetBits( n : int) : int pre: true post: true activity: ( var m : int ; m := getLeftmostBit(n) ; return countSetBits(n, m) ); static operation countSetBits( n : int, m : int) : int pre: true post: true activity: ( if (n = 0) then return 0 else skip ; m := getNextLeftmostBit(n, m) ; if (n = ((1->oclAsType(int)*(2->pow((m + 1))))->oclAsType(long)) - 1) then return (m + 1)->oclAsType(int) * ((1*(2->pow(m)))->oclAsType(long)) else skip ; n := n - ((1*(2->pow(m)))->oclAsType(long)) ; return (n + 1) + countSetBits(n) + m * ((1*(2->pow((m - 1))))->oclAsType(long)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 17 ; OclFile["System.out"].println("Total set bit count is " + countSetBits(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String getCount(int N){ if(N % 2==1)return "0" ; String result="9" ; for(int i=1 ; i<=N/2-1 ; i++)result+="0" ; return result ; } public static void main(String[] args){ int N=4 ; System.out.println(getCount(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getCount( N : int) : String pre: true post: true activity: ( if (N mod 2 = 1) then return "0" else skip ; var result : String ; result := "9" ; var i : int ; i := 1 ; while i <= N / 2 - 1 do ( result := result+("0") ; ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 4 ; OclFile["System.out"].println(getCount(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int minCoins(int coins[],int m,int V){ int table[]=new int[V+1]; table[0]=0 ; for(int i=1 ; i<=V ; i++)table[i]=Integer.MAX_VALUE ; for(int i=1 ; i<=V ; i++){ for(int j=0 ; jcollect(0) ; table[0+1] := 0 ; var i : int ; i := 1 ; while i <= V do ( table[i+1] := 2147483647 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= V do ( ( var j : int ; j := 0 ; while j < m do ( if (coins[j+1] <= i) then ( var sub_res : int ; sub_res := table[i - coins[j+1]+1] ; if (sub_res /= 2147483647 & sub_res + 1 < table[i+1]) then table[i+1] := sub_res + 1 ; else skip ) else skip ; ; j := j + 1 ) ) ; i := i + 1 ) ; return table[V+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var coins : Sequence(int) ; coins := Sequence{9,6,5,1} ; var m : int ; m := coins->size() ; var V : int ; V := 11 ; OclFile["System.out"].println("Minimum coins required is " + minCoins(coins, m, V)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class at83 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long a[]=new long[n]; long b[]=new long[n]; int size=0 ; long sum=0,c ; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,n)->collect(0) ; var size : int ; size := 0 ; var sum : long ; sum := 0 ; var c : long ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( c := 1 ; while (i < n - 1 & a[i+1] = a[i + 1+1]) do ( c := c + 1 ; i := i + 1 ) ; b[size+1] := c ; size := size + 1 ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < size do ( ( sum := sum+((b[j+1] * (b[j+1] + 1)) / 2) ) ; j := j + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.LinkedList ; import java.util.StringTokenizer ; import java.util.TreeMap ; import java.util.TreeSet ; import java.util.Vector ; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st ; int n=Integer.parseInt(br.readLine()); long count=0 ; long ans=0 ; int a[]=new int[n]; st=new StringTokenizer(br.readLine()); for(int i=0 ; itoInteger() ; var count : long ; count := 0 ; var ans : long ; ans := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; ans := n->oclAsType(long) ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (a[i+1] = a[i + 1+1]) then ( count := count + 1 ; ans := ans+(count) ) else count := 0 ; ) ; i := i + 1 ) ; OclFile["System.out"].print(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public final class magical_array { static Scanner sc=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); static long sum=0 ; static void solve(long[] a,int n,int i){ if(itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute solve(a, n, 0) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int k=s.nextInt(); int t=s.nextInt(); int a=0 ; if(t>=n)a=k-(t-n); else if(t<=k)a=t ; else a=k ; System.out.println(a); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var k : int ; k := s.getCurrent()->toInteger() ; var t : int ; t := s.getCurrent()->toInteger() ; var a : int ; a := 0 ; if (t >= n) then a := k - (t - n) else if (t <= k) then a := t else a := k ; ; ; OclFile["System.out"].println(a) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int N,D ; char[] X ; N=parseInt(br.readLine()); X=br.readLine().toCharArray(); D=parseInt(br.readLine()); char[] ans=Arrays.copyOf(X,N); for(int i=0 ; i0 && X[i]=='0'){ ans[i]='1' ; D--; } } for(int i=N-1 ; i>=0 ; i--){ if(D==0)break ; if(D>0 && X[i]=='1'){ ans[i]='0' ; D--; } } System.out.println(String.valueOf(ans)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var N : int ; var D : int ; var X : Sequence(String) ; N := (br.readLine() + "")->toInteger() ; X := br.readLine()->characters() ; D := (br.readLine() + "")->toInteger() ; var ans : Sequence(String) ; ans := X.subrange(1,N) ; var i : int ; i := 0 ; while i < N do ( ( if (D = 0) then break else skip ; if (D > 0 & X[i+1] = '0') then ( ans[i+1] := '1' ; D := D - 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := N - 1 ; while i >= 0 do ( ( if (D = 0) then break else skip ; if (D > 0 & X[i+1] = '1') then ( ans[i+1] := '0' ; D := D - 1 ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println((ans)->sum() ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Waves { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long k=sc.nextLong(); long t=sc.nextLong(); if(t<=k)System.out.println(t); else if(t>k && t<=n)System.out.println(k); else { t-=n ; System.out.println((k-t)); } } } ------------------------------------------------------------ OCL File: --------- class Waves { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; var t : long ; t := sc.getCurrent()->toLong() ; if (t <= k) then OclFile["System.out"].println(t) else if (t > k & t <= n) then OclFile["System.out"].println(k) else ( t := t-(n) ; OclFile["System.out"].println((k - t)) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n=Integer.parseInt(f.readLine()); StringTokenizer st=new StringTokenizer(f.readLine()); int[] a=new int[n]; for(int i=0 ; ia[i-1]){ l[i+1]=l[i]+1 ; } else { l[i+1]=1 ; } } int[] r=new int[n]; r[n-2]=1 ; for(int i=n-2 ; i>0 ; i--){ if(a[i]a[i-1]+1){ max=Math.max(max,l[i]+r[i]+1); } } out.println(max); } f.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var f : OclFile ; f := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ; var n : int ; n := (f.readLine())->toInteger() ; var st : OclIterator ; st := OclIterator.newOclIterator_String(f.readLine()) ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; if (n = 1) then ( skip ) else ( var l : Sequence(int) ; l := Integer.subrange(1,n)->collect(0) ; l[1+1] := 1 ; var i : int ; i := 1 ; while i < n - 1 do ( ( if (a[i+1] > a[i - 1+1]) then ( l[i + 1+1] := l[i+1] + 1 ) else ( l[i + 1+1] := 1 ) ) ; i := i + 1 ) ; var r : Sequence(int) ; r := Integer.subrange(1,n)->collect(0) ; r[n - 2+1] := 1 ; var i : int ; i := n - 2 ; while i > 0 do ( ( if (a[i+1] < a[i + 1+1]) then ( r[i - 1+1] := r[i+1] + 1 ) else ( r[i - 1+1] := 1 ) ) ; i := i - 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( max := Set{max, l[i+1] + 1}->max() ; max := Set{max, r[i+1] + 1}->max() ; if (i = 0 or i = n - 1 or a[i + 1+1] > a[i - 1+1] + 1) then ( max := Set{max, l[i+1] + r[i+1] + 1}->max() ) else skip ) ; i := i + 1 ) ; skip ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Iterator ; import java.util.List ; public class Algorithm { public static void main(String[] rgs)throws IOException { BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); StringBuilder stringBuilder=new StringBuilder(); int t=Integer.parseInt(bufferedReader.readLine()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var lemn : int ; lemn := (bufferedReader.readLine())->toInteger() ; var first : String ; first := bufferedReader.readLine() ; var sec : String ; sec := bufferedReader.readLine() ; var ans : String ; ans := "" ; var onecount : int ; onecount := 0 ; var zerocount : int ; zerocount := 0 ; var isequal : boolean ; isequal := true ; var brrok : boolean ; brrok := false ; var j : int ; j := 0 ; while j < first->size() do ( ( var cur : String ; cur := first->at(j+1) ; if (isequal) then ( if (cur = sec->at(j+1)) then ( if (cur = '1') then onecount := onecount+(1) ; else zerocount := zerocount+(1) ; ) else ( if (onecount /= zerocount) then ( stringBuilder := stringBuilder + StringLib.newString("NO\n") ; brrok := true ; break ) else skip ; isequal := false ; onecount := 0 ; zerocount := 0 ; if (cur = '1') then onecount := 1 else zerocount := 1 ; ; ) ) else ( if (cur /= sec->at(j+1)) then ( if (cur = '1') then onecount := onecount+(1) ; else zerocount := zerocount+(1) ; ) else ( if (onecount /= zerocount) then ( stringBuilder := stringBuilder + StringLib.newString("NO\n") ; brrok := true ; break ) else skip ; isequal := true ; onecount := 0 ; zerocount := 0 ; if (cur = '1') then onecount := 1 else zerocount := 1 ; ; ) ) ) ; j := j + 1 ) ; if (brrok) then continue else skip ; if (not(isequal) & onecount /= zerocount) then ( stringBuilder := stringBuilder + StringLib.newString("NO\n") ; continue ) else skip ; stringBuilder := stringBuilder + StringLib.newString("YES\n") ; ) ; i := i + 1 ) ; OclFile["System.out"].println(stringBuilder) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class CF_604A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] points={ 500,1000,1500,2000,2500 }; int[] times=new int[5]; for(int i=0 ; i<5 ; i++)times[i]=sc.nextInt(); sc.nextLine(); int[] wrong=new int[5]; for(int i=0 ; i<5 ; i++)wrong[i]=sc.nextInt(); sc.nextLine(); int h1=sc.nextInt(); int h2=sc.nextInt(); sc.nextLine(); double score=h1*100.0-h2*50.0 ; for(int i=0 ; i<5 ; i++){ double first=0.3*points[i]; double second=(1.0-(times[i]/250.0))*points[i]-50.0*wrong[i]; score+=Math.max(first,second); } System.out.println((int)score); } } ------------------------------------------------------------ OCL File: --------- class CF_604A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var points : Sequence(int) ; points := Sequence{500,1000,1500,2000,2500} ; var times : Sequence(int) ; times := Integer.subrange(1,5)->collect(0) ; var i : int ; i := 0 ; while i < 5 do ( times[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; skip ; var wrong : Sequence(int) ; wrong := Integer.subrange(1,5)->collect(0) ; var i : int ; i := 0 ; while i < 5 do ( wrong[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; skip ; var h1 : int ; h1 := sc.getCurrent()->toInteger() ; var h2 : int ; h2 := sc.getCurrent()->toInteger() ; skip ; var score : double ; score := h1 * 100.0 - h2 * 50.0 ; var i : int ; i := 0 ; while i < 5 do ( ( var first : double ; first := 0.3 * points[i+1] ; var second : double ; second := (1.0 - (times[i+1] / 250.0)) * points[i+1] - 50.0 * wrong[i+1] ; score := score+(Set{first, second}->max()) ) ; i := i + 1 ) ; OclFile["System.out"].println(score->oclAsType(int)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public class uncowedfores { public static void main(String[] args){ Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int[] min=new int[5]; for(int i=0 ; i<5 ; i++){ min[i]=sc.nextInt(); } int[] wrong=new int[5]; for(int i=0 ; i<5 ; i++){ wrong[i]=sc.nextInt(); } int[] max={ 500,1000,1500,2000,2500 }; int hs=sc.nextInt(); int hus=sc.nextInt(); int total=100*hs-50*hus ; for(int i=0 ; i<5 ; i++){ int m=min[i]; int w=wrong[i]; int x=max[i]; total+=Math.max(3*x/10,x-x*m/250-50*w); } System.out.println(total); } } ------------------------------------------------------------ OCL File: --------- class uncowedfores { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var min : Sequence(int) ; min := Integer.subrange(1,5)->collect(0) ; var i : int ; i := 0 ; while i < 5 do ( ( min[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var wrong : Sequence(int) ; wrong := Integer.subrange(1,5)->collect(0) ; var i : int ; i := 0 ; while i < 5 do ( ( wrong[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var max : Sequence(int) ; max := Sequence{500,1000,1500,2000,2500} ; var hs : int ; hs := sc.getCurrent()->toInteger() ; var hus : int ; hus := sc.getCurrent()->toInteger() ; var total : int ; total := 100 * hs - 50 * hus ; var i : int ; i := 0 ; while i < 5 do ( ( var m : int ; m := min[i+1] ; var w : int ; w := wrong[i+1] ; var x : int ; x := max[i+1] ; total := total+(Set{3 * x / 10, x - x * m / 250 - 50 * w}->max()) ) ; i := i + 1 ) ; OclFile["System.out"].println(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication94 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int num1=sc.nextInt(); int num2=sc.nextInt(); int num3=sc.nextInt(); int num4=sc.nextInt(); int num5=sc.nextInt(); int num6=sc.nextInt(); int num7=sc.nextInt(); int num8=sc.nextInt(); int num9=sc.nextInt(); int num10=sc.nextInt(); int num11=sc.nextInt(); int num12=sc.nextInt(); float counter=(((Math.max((float).3*500,(1-((float)num1/250))*500-(50*num6))))+((Math.max((float).3*1000,(1-((float)num2/250))*1000-(50*num7))))+((Math.max((float).3*1500,(1-((float)num3/250))*1500-(50*num8))))+((Math.max((float).3*2000,(1-((float)num4/250))*2000-(50*num9))))+((Math.max((float).3*2500,(1-((float)num5/250))*2500-(50*num10))))+(100*num11)-(50*num12)); System.out.println((int)counter); } } ------------------------------------------------------------ OCL File: --------- class JavaApplication94 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num1 : int ; num1 := sc.getCurrent()->toInteger() ; var num2 : int ; num2 := sc.getCurrent()->toInteger() ; var num3 : int ; num3 := sc.getCurrent()->toInteger() ; var num4 : int ; num4 := sc.getCurrent()->toInteger() ; var num5 : int ; num5 := sc.getCurrent()->toInteger() ; var num6 : int ; num6 := sc.getCurrent()->toInteger() ; var num7 : int ; num7 := sc.getCurrent()->toInteger() ; var num8 : int ; num8 := sc.getCurrent()->toInteger() ; var num9 : int ; num9 := sc.getCurrent()->toInteger() ; var num10 : int ; num10 := sc.getCurrent()->toInteger() ; var num11 : int ; num11 := sc.getCurrent()->toInteger() ; var num12 : int ; num12 := sc.getCurrent()->toInteger() ; var counter : double ; counter := (((Set{.3->oclAsType(double) * 500, (1 - (num1->oclAsType(double) / 250)) * 500 - (50 * num6)}->max())) + ((Set{.3->oclAsType(double) * 1000, (1 - (num2->oclAsType(double) / 250)) * 1000 - (50 * num7)}->max())) + ((Set{.3->oclAsType(double) * 1500, (1 - (num3->oclAsType(double) / 250)) * 1500 - (50 * num8)}->max())) + ((Set{.3->oclAsType(double) * 2000, (1 - (num4->oclAsType(double) / 250)) * 2000 - (50 * num9)}->max())) + ((Set{.3->oclAsType(double) * 2500, (1 - (num5->oclAsType(double) / 250)) * 2500 - (50 * num10)}->max())) + (100 * num11) - (50 * num12)) ; OclFile["System.out"].println(counter->oclAsType(int)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static final int WHITE=0 ; static final int GRAY=1 ; static final int BLACK=2 ; static int v ; static Map>adjList=new HashMap>(); static int color[]; static boolean judge=false ; public static void main(String[] args){ Scanner scan=new Scanner(System.in); v=scan.nextInt(); int e=scan.nextInt(); int start,end=0 ; for(int i=0 ; i()); } adjList.get(start).add(end); } color=new int[v]; for(int i : adjList.keySet()){ dfs(i); } if(judge){ System.out.println(1); } else System.out.println(0); } static void dfs(int u){ color[u]=GRAY ; if(adjList.containsKey(u)){ for(int ne : adjList.get(u)){ if(color[ne]==GRAY){ judge=true ; break ; } if(color[ne]==WHITE)dfs(ne); } } color[u]=BLACK ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute WHITE : int := 0; static attribute GRAY : int := 1; static attribute BLACK : int := 2; static attribute v : int; static attribute adjList : Map(int,Sequence(int)) := Map{}; static attribute color : Sequence(int); static attribute judge : boolean := false; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; v := scan.getCurrent()->toInteger() ; var e : int ; e := scan.getCurrent()->toInteger() ; var start : int ; var end : int ; end := 0 ; var i : int ; i := 0 ; while i < e do ( ( start := scan.getCurrent()->toInteger() ; end := scan.getCurrent()->toInteger() ; if (not(adjList->keys()->includes(start))) then ( adjList := adjList->union(Map{start |-> Sequence{}}) ) else skip ; adjList->at(start)->excludes(end) ) ; i := i + 1 ) ; color := Integer.subrange(1,v)->collect(0) ; for (i : adjList->keys()) do ( ( execute dfs(i) ) ) ; if (judge) then ( OclFile["System.out"].println(1) ) else OclFile["System.out"].println(0) ; ; ); static operation dfs( u : int) : void pre: true post: true activity: ( color[u+1] := GRAY ; if (adjList->keys()->includes(u)) then ( for (ne : adjList->at(u)) do ( ( if (color[ne+1] = GRAY) then ( judge := true ; break ) else skip ; if (color[ne+1] = WHITE) then execute dfs(ne) ; else skip ) ) ) else skip ; color[u+1] := BLACK ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.lang.*; class Main { static class Graph { int vertices ; ArrayList>adjList ; public Graph(int v){ vertices=v ; adjList=new ArrayList>(); for(int i=0 ; i()); } public boolean addEdge(int start,int end){ if(start>vertices)return false ; adjList.get(start).add(end); return true ; } public boolean isCycle(){ boolean visited[]=new boolean[vertices]; boolean recursiveArr[]=new boolean[vertices]; for(int i=0 ; iincluding(Sequence{}) ; ; i := i + 1 ) ); operation addEdge( start : int, end : int) : boolean pre: true post: true activity: ( if (start > vertices) then return false else skip ; adjList->at(start+1)->excludes(end) ; return true ); operation isCycle() : boolean pre: true post: true activity: ( var visited : Sequence(boolean) ; visited := Integer.subrange(1,vertices)->collect(false) ; var recursiveArr : Sequence(boolean) ; recursiveArr := Integer.subrange(1,vertices)->collect(false) ; var i : int ; i := 0 ; while i < vertices do ( ( if (isCycleUtil(i, visited, recursiveArr)) then return true else skip ) ; i := i + 1 ) ; return false ); operation isCycleUtil( vertex : int, visited : Sequence(boolean), recursiveArr : Sequence(boolean)) : boolean pre: true post: true activity: ( visited[vertex+1] := true ; recursiveArr[vertex+1] := true ; var i : int ; i := 0 ; while i < adjList->at(vertex+1)->size() do ( ( var adjVertex : int ; adjVertex := adjList->at(vertex+1)->at(i+1) ; if (not(visited[adjVertex+1]) & isCycleUtil(adjVertex, visited, recursiveArr)) then ( return true ) else if (recursiveArr[adjVertex+1]) then ( return true ) else skip ; ) ; i := i + 1 ) ; recursiveArr[vertex+1] := false ; return false ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numV : int ; numV := scanner.getCurrent()->toInteger() ; var numE : int ; numE := scanner.getCurrent()->toInteger() ; var g : Graph ; g := Graph.newGraph(numV) ; var i : int ; i := 0 ; while i < numE do ( ( g.addEdge(scanner.getCurrent()->toInteger(), scanner.getCurrent()->toInteger()) ) ; i := i + 1 ) ; OclFile["System.out"].println(if g.isCycle() then 1 else 0 endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static int ar[][]; static int nodes ; static String color[]; static int lastCount ; static int parent[]; static int breaker ; static String ans="" ; static void doDfs(int i){ int source=i ; color[source]="grey" ; for(int ii=0 ; iitoInteger() ; var edges : int ; edges := sc.getCurrent()->toInteger() ; ar := Integer.subrange(1,nodes)->collect(Integer.subrange(1,nodes)->collect(0)) ; var i : int ; i := 0 ; while i < edges do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; ar[a+1][b+1] := 1 ) ; i := i + 1 ) ; color := Integer.subrange(1,nodes)->collect(null) ; parent := Integer.subrange(1,nodes)->collect(0) ; var i : int ; i := 0 ; while i < color->size() do ( ( color[i+1] := "white" ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < color->size() do ( ( if (color[i+1] = "white") then ( execute doDfs(i) ; if (breaker = 1) then ( break ) else skip ) else skip ) ; i := i + 1 ) ; if (breaker = 1) then ( OclFile["System.out"].println("1") ) else ( OclFile["System.out"].println("0") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int N,D ; char[] X ; N=parseInt(br.readLine()); X=br.readLine().toCharArray(); D=parseInt(br.readLine()); char[] ans=Arrays.copyOf(X,N); for(int i=0 ; i=0 ; i--){ if(D==0)break ; if(X[i]=='1'){ ans[i]='0' ; D--; } } System.out.println(String.valueOf(ans)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var N : int ; var D : int ; var X : Sequence(String) ; N := (br.readLine() + "")->toInteger() ; X := br.readLine()->characters() ; D := (br.readLine() + "")->toInteger() ; var ans : Sequence(String) ; ans := X.subrange(1,N) ; var i : int ; i := 0 ; while i < N do ( ( if (D = 0) then break else skip ; if (X[i+1] = '0') then ( ans[i+1] := '1' ; D := D - 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := N - 1 ; while i >= 0 do ( ( if (D = 0) then break else skip ; if (X[i+1] = '1') then ( ans[i+1] := '0' ; D := D - 1 ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println((ans)->sum() ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int v=Integer.parseInt(str[0]); int e=Integer.parseInt(str[1]); int[][] map=new int[v][v]; for(int i=0 ; isplit(" ") ; var v : int ; v := (str[0+1])->toInteger() ; var e : int ; e := (str[1+1])->toInteger() ; var map : Sequence(Sequence(int)) ; map := Integer.subrange(1,v)->collect(Integer.subrange(1,v)->collect(0)) ; var i : int ; i := 0 ; while i < v do ( map[i+1] := map[i+1]->collect(-2147483647 / 2) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < v do ( map[i+1][i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < e do ( ( str := br.readLine()->split(" ") ; var s : int ; s := (str[0+1])->toInteger() ; var t : int ; t := (str[1+1])->toInteger() ; map[s+1][t+1] := 1 ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < v do ( ( var i : int ; i := 0 ; while i < v do ( ( var j : int ; j := 0 ; while j < v do ( ( if (map[i+1][j+1] < map[i+1][k+1] + map[k+1][j+1]) then ( map[i+1][j+1] := map[i+1][k+1] + map[k+1][j+1] ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; k := k + 1 ) ; var closed : boolean ; closed := false ; var i : int ; i := 0 ; while i < v do ( ( if (map[i+1][i+1] /= 0) then ( closed := true ; break ) else skip ) ; i := i + 1 ) ; if (not(closed)) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int V=Integer.parseInt(sc.next()); int E=Integer.parseInt(sc.next()); ArrayList>edge=new ArrayList>(); for(int i=0 ; iadd=new ArrayList(); edge.add(add); } int[] indegree=new int[V]; for(int i=0 ; ians=new ArrayList(); ArrayDequequeue=new ArrayDeque(); for(int i=0 ; iV){ flag=1 ; break ; } } if(cnt!=V){ flag=1 ; } System.out.println(flag); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var V : int ; V := (sc.getCurrent())->toInteger() ; var E : int ; E := (sc.getCurrent())->toInteger() ; var edge : Sequence(Sequence(int)) ; edge := Sequence{} ; var i : int ; i := 0 ; while i < V do ( ( var add : Sequence(int) ; add := Sequence{} ; edge := edge->including(add) ) ; i := i + 1 ) ; var indegree : Sequence(int) ; indegree := Integer.subrange(1,V)->collect(0) ; var i : int ; i := 0 ; while i < E do ( ( var s : int ; s := (sc.getCurrent())->toInteger() ; var t : int ; t := (sc.getCurrent())->toInteger() ; edge->at(s+1)->excludes(t) ; indegree[t+1] := indegree[t+1] + 1 ) ; i := i + 1 ) ; var ans : Sequence(int) ; ans := Sequence{} ; var queue : Sequence(int) ; queue := ArrayDeque.newArrayDeque() ; var i : int ; i := 0 ; while i < V do ( ( if (indegree[i+1] = 0) then ( queue := queue->including(i) ; ans := ans->including(i) ) else skip ) ; i := i + 1 ) ; var flag : int ; flag := 0 ; if (queue->isEmpty()) then ( flag := 1 ) else skip ; var cnt : int ; cnt := 0 ; while (not(queue->isEmpty())) do ( var rem : int ; rem := queue.remove() ; for (i : edge->at(rem+1)) do ( ( indegree[i+1] := indegree[i+1] - 1 ; if (indegree[i+1] = 0) then ( queue := queue->including(i) ; ans := ans->including(i) ) else skip ) ) ; cnt := cnt + 1 ; if (cnt > V) then ( flag := 1 ; break ) else skip ) ; if (cnt /= V) then ( flag := 1 ) else skip ; OclFile["System.out"].println(flag) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileNotFoundException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws FileNotFoundException { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); String S=sc.next(); char[] s=S.toCharArray(); for(int i=0 ; itoInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var S : String ; S := sc.getCurrent() ; var s : Sequence(String) ; s := S->characters() ; var i : int ; i := 0 ; while i < S->size() do ( ( if (i = K - 1) then ( s[i+1] := (s[i+1] + "")->toLowerCase() ) else skip ) ; i := i + 1 ) ; S := StringLib.newString(s) ; OclFile["System.out"].println(S) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.HashMap ; import java.util.List ; import java.util.Map ; import java.util.Scanner ; class Main { static class Edge { int to,dis ; Edge(int to,int dis){ this.to=to ; this.dis=dis ; } } static int used[]; static ListedgeList[]; static boolean dfs(int v,int pos){ if(used[v]>Integer.MIN_VALUE)return used[v]==pos ; used[v]=pos ; for(Edge e : edgeList[v]){ if(! dfs(e.to,pos+e.dis))return false ; } return true ; } public static void main(String[] args){ Scanner scan=new Scanner(System.in); int N=scan.nextInt(); int M=scan.nextInt(); edgeList=new ArrayList[N+1]; for(int i=1 ; i<=N ; ++i)edgeList[i]=new ArrayList<>(); used=new int[N+1]; Arrays.fill(used,Integer.MIN_VALUE); for(int i=0 ; iInteger.MIN_VALUE)continue ; if(! dfs(i,0)){ System.out.println("No"); return ; } } System.out.println("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static class Edge { attribute to : int; static operation newEdge( to : int, dis : int) : Edge pre: true post: true activity: ( var self : Edge ; self := createEdge(); self.initialise(to, dis); return self ); operation initialise( to : int, dis : int) : void pre: true post: true activity: ( self.to := to ; self.dis := dis ); } static attribute used : Sequence(int); static attribute edgeList : Sequence(Sequence(Edge)); static operation dfs( v : int, pos : int) : boolean pre: true post: true activity: ( if (used[v+1] > -2147483648) then return used[v+1] = pos else skip ; used[v+1] := pos ; for (e : edgeList[v+1]) do ( ( if (not(dfs(e.to, pos + e.dis))) then return false else skip ) ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scan.getCurrent()->toInteger() ; var M : int ; M := scan.getCurrent()->toInteger() ; edgeList := Integer.subrange(1,N + 1)->collect(null) ; var i : int ; i := 1 ; while i <= N do ( edgeList[i+1] := Sequence{} ; ; i := i + 1 ) ; used := Integer.subrange(1,N + 1)->collect(0) ; used := used->collect(-2147483648) ; var i : int ; i := 0 ; while i < M do ( ( var L : int ; L := scan.getCurrent()->toInteger() ; var R : int ; R := scan.getCurrent()->toInteger() ; var D : int ; D := scan.getCurrent()->toInteger() ; edgeList[L+1]->excludes(Edge.newEdge(R, D)) ; edgeList[R+1]->excludes(Edge.newEdge(L, -D)) ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= N do ( ( if (used[i+1] > -2147483648) then continue else skip ; if (not(dfs(i, 0))) then ( OclFile["System.out"].println("No") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.ArrayList ; public class codforce { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int x=scan.nextInt(); while(x-->0){ int y=scan.nextInt(); int q=scan.nextInt(); int w=scan.nextInt(); int k=0 ; if(y-10*w<=0){ System.out.println("YES"); } else { while(ktoInteger() ; while (x > 0) do ( x := x - 1 ; skip ; ( var y : int ; y := scan.getCurrent()->toInteger() ; var q : int ; q := scan.getCurrent()->toInteger() ; var w : int ; w := scan.getCurrent()->toInteger() ; var k : int ; k := 0 ; if (y - 10 * w <= 0) then ( OclFile["System.out"].println("YES") ) else ( while (k < q) do ( k := k + 1 ; y := y / 2 + 10 ) ; y := y - (w * 10) ; if (y <= 0) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); while(n-->0){ int x=0,y=0,z=0 ; x=scanner.nextInt(); y=scanner.nextInt(); z=scanner.nextInt(); while(y>0 && x>20){ y--; x=x/2+10 ; } if(x<=z*10){ System.out.println("YES"); } else { System.out.println("No"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var x : int ; x := 0 ; var y : int ; y := 0 ; var z : int ; z := 0 ; x := scanner.getCurrent()->toInteger() ; y := scanner.getCurrent()->toInteger() ; z := scanner.getCurrent()->toInteger() ; while (y > 0 & x > 20) do ( y := y - 1 ; x := x / 2 + 10 ) ; if (x <= z * 10) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("No") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); if(n<=20){ if((b*10)>=n){ System.out.println("YES"); } else { System.out.println("NO"); } } else { while(n>20 && a>0){ n/=2 ; n+=10 ; a--; } if(n<=(b*10)){ System.out.println("YES"); } else { System.out.println("NO"); } } } } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (n <= 20) then ( if ((b * 10) >= n) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) else ( while (n > 20 & a > 0) do ( n := n/(2) ; n := n+(10) ; a := a - 1 ) ; if (n <= (b * 10)) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.Scanner ; public class Kana { int number ; LinkedListsResult=new LinkedList<>(); public Kana(int number){ this.number=number ; } public void inputDataTest(int num1,int numb2,int number3){ int number=num1 ; if(number<=10*number3){ number-=(10*number3); } else { for(int i=0 ; i0){ sResult.add("NO"); } else { sResult.add("YES"); } } public void printResult(){ for(String i : sResult){ System.out.println(i); } } public int getNumber(){ return number ; } public static void main(String[] args){ Scanner s=new Scanner(System.in); int numberTest=s.nextInt(); Kana instance=new Kana(numberTest); for(int i=0 ; i 0) then ( sResult := sResult->including("NO") ) else ( sResult := sResult->including("YES") ) ); operation printResult() : void pre: true post: true activity: ( for (i : sResult) do ( ( OclFile["System.out"].println(i) ) ) ); operation getNumber() : int pre: true post: true activity: ( return number ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numberTest : int ; numberTest := s.getCurrent()->toInteger() ; var instance : Kana ; instance := Kana.newKana(numberTest) ; var i : int ; i := 0 ; while i < instance.getNumber() do ( ( var numberOne : int ; numberOne := s.getCurrent()->toInteger() ; var numberTwo : int ; numberTwo := s.getCurrent()->toInteger() ; var numberThree : int ; numberThree := s.getCurrent()->toInteger() ; instance.inputDataTest(numberOne, numberTwo, numberThree) ) ; i := i + 1 ) ; instance.printResult() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Dragon { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int x=sc.nextInt(); int n=sc.nextInt(); int m=sc.nextInt(); while(x>20 && n>0){ x=x/2+10 ; n--; } if(x>0 && m>0){ x=x-(m*10); } if(x<=0){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class Dragon { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; while (x > 20 & n > 0) do ( x := x / 2 + 10 ; n := n - 1 ) ; if (x > 0 & m > 0) then ( x := x - (m * 10) ) else skip ; if (x <= 0) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B172 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int A=in.nextInt(); int B=in.nextInt(); int M=in.nextInt(); int x=in.nextInt(); int[] seen=new int[M]; int index=1 ; while(seen[x]==0){ seen[x]=index ; index++; x=(A*x+B)% M ; } int answer=index-seen[x]; System.out.println(answer); } } ------------------------------------------------------------ OCL File: --------- class B172 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; A := in.getCurrent()->toInteger() ; var B : int ; B := in.getCurrent()->toInteger() ; var M : int ; M := in.getCurrent()->toInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; var seen : Sequence(int) ; seen := Integer.subrange(1,M)->collect(0) ; var index : int ; index := 1 ; while (seen[x+1] = 0) do ( seen[x+1] := index ; index := index + 1 ; x := (A * x + B) mod M ) ; var answer : int ; answer := index - seen[x+1] ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char[] arr=sc.next().toCharArray(); int d=sc.nextInt(); int nd=n-d ; for(int i=0 ; i0){ nd--; } else { arr[i]='0' ; d--; } } else { if(d>0){ d--; arr[i]='1' ; } else { nd--; } } } System.out.println(arr); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(String) ; arr := sc.getCurrent()->characters() ; var d : int ; d := sc.getCurrent()->toInteger() ; var nd : int ; nd := n - d ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = '1') then ( if (nd > 0) then ( nd := nd - 1 ) else ( arr[i+1] := '0' ; d := d - 1 ) ) else ( if (d > 0) then ( d := d - 1 ; arr[i+1] := '1' ) else ( nd := nd - 1 ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(arr) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Solution { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int a=Integer.parseInt(st.nextToken()); int b=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(st.nextToken()); int[] r=new int[1000000]; r[0]=Integer.parseInt(st.nextToken()); for(int i=1 ; i<1000000 ; i++){ r[i]=a*r[i-1]+b ; r[i] %=m ; } int[] place=new int[m]; for(int i=0 ; i<1000000-1 ; i++){ place[r[i] ]=i ; } int rep=1000000-1-place[r[1000000-1] ]; System.out.println(rep); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var a : int ; a := (st.next())->toInteger() ; var b : int ; b := (st.next())->toInteger() ; var m : int ; m := (st.next())->toInteger() ; var r : Sequence(int) ; r := Integer.subrange(1,1000000)->collect(0) ; r[0+1] := (st.next())->toInteger() ; var i : int ; i := 1 ; while i < 1000000 do ( ( r[i+1] := a * r[i - 1+1] + b ; r[i+1] := r[i+1] mod m ) ; i := i + 1 ) ; var place : Sequence(int) ; place := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < 1000000 - 1 do ( ( place[r[i+1]+1] := i ) ; i := i + 1 ) ; var rep : int ; rep := 1000000 - 1 - place[r[1000000 - 1+1]+1] ; OclFile["System.out"].println(rep) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { final static int fact[]=new int[21]; static void preCompute(){ fact[0]=1 ; for(int i=1 ; i<18 ; i++)fact[i]=(fact[i-1]*i); } static void nextFactorial(int N){ for(int i=0 ; i<21 ; i++){ if(Ncollect(0); static operation preCompute() : void pre: true post: true activity: ( fact[0+1] := 1 ; var i : int ; i := 1 ; while i < 18 do ( fact[i+1] := (fact[i - 1+1] * i) ; ; i := i + 1 ) ); static operation nextFactorial( N : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < 21 do ( ( if (N < fact[i+1]) then ( OclFile["System.out"].println(fact[i+1]) ; break ) else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute preCompute() ; var N : int ; N := 120 ; execute nextFactorial(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GeeksforGeeks { static double compute(int a,int b){ double AM,GM,HM ; AM=(a+b)/2 ; GM=Math.sqrt(a*b); HM=(GM*GM)/AM ; return HM ; } public static void main(String args[]){ int a=5,b=15 ; double HM=compute(a,b); String str="" ; str=str+HM ; System.out.print("Harmonic Mean between "+a+" and "+b+" is "+str.substring(0,5)); } } ------------------------------------------------------------ OCL File: --------- class GeeksforGeeks { static operation compute( a : int, b : int) : double pre: true post: true activity: ( var AM : double ; var GM : double ; var HM : double ; AM := (a + b) / 2 ; GM := (a * b)->sqrt() ; HM := (GM * GM) / AM ; return HM ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 5 ; var b : int ; b := 15 ; var HM : double ; HM := compute(a, b) ; var str : String ; str := "" ; str := str + HM ; OclFile["System.out"].print("Harmonic Mean between " + a + " and " + b + " is " + str.subrange(0+1,5)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static int largest(int[] arr,int n){ Arrays.sort(arr); return arr[n-1]; } static public void main(String[] args){ int[] arr={ 10,324,45,90,9808 }; int n=arr.length ; System.out.println(largest(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation largest( arr : Sequence(int), n : int) : int pre: true post: true activity: ( arr := arr->sort() ; return arr[n - 1+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,324,45,90,9808} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(largest(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Main { static int getMedian(int ar1[],int ar2[],int n){ int i=0 ; int j=0 ; int count ; int m1=-1,m2=-1 ; for(count=0 ; count<=n ; count++){ if(i==n){ m1=m2 ; m2=ar2[0]; break ; } else if(j==n){ m1=m2 ; m2=ar1[0]; break ; } if(ar1[i]size() ; var n2 : int ; n2 := ar2->size() ; if (n1 = n2) then OclFile["System.out"].println("Median is " + getMedian(ar1, ar2, n1)) else OclFile["System.out"].println("arrays are of unequal size") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GfG { static boolean validateStackSequence(int pushed[],int popped[],int len){ int j=0 ; Stackst=new Stack<>(); for(int i=0 ; iappend(pushed[i+1]) ; while (not(st->isEmpty()) & j < len & st->min() = popped[j+1]) do ( st := st->front() ; j := j + 1 ) ) ; i := i + 1 ) ; return j = len ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var pushed : Sequence(int) ; pushed := Sequence{1,2,3,4,5} ; var popped : Sequence(int) ; popped := Sequence{4,5,3,2,1} ; var len : int ; len := pushed->size() ; OclFile["System.out"].println((if validateStackSequence(pushed, popped, len) then "True" else "False" endif)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Test { public float computePrice(float h,float n,float c){ int nbrBuns=(int)Math.ceil(h/n); return nbrBuns*c ; } public float computeNewHunger(float h,float d,float minutes){ return(d*minutes)+h ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); float hh,mm ; hh=sc.nextInt(); mm=sc.nextInt(); float h,d,c,n ; h=sc.nextInt(); d=sc.nextInt(); c=sc.nextInt(); n=sc.nextInt(); Test test=new Test(); float withoutDiscount,withDiscount ; if(hh>=20){ withDiscount=test.computePrice(h,n,c)-((test.computePrice(h,n,c)*20)/100); System.out.println(withDiscount); } if(hh<20){ float minutes=((20-hh-1)*60)+(60-mm); float newhunger=test.computeNewHunger(h,d,minutes); float discount=(test.computePrice(newhunger,n,c)*20)/100 ; withDiscount=test.computePrice(newhunger,n,c)-discount ; withoutDiscount=test.computePrice(h,n,c); System.out.println(withDiscountceil()->oclAsType(int) ; return nbrBuns * c ); operation computeNewHunger( h : double, d : double, minutes : double) : double pre: true post: true activity: ( return (d * minutes) + h ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var hh : double ; var mm : double ; hh := sc.getCurrent()->toInteger() ; mm := sc.getCurrent()->toInteger() ; var h : double ; var d : double ; var c : double ; var n : double ; h := sc.getCurrent()->toInteger() ; d := sc.getCurrent()->toInteger() ; c := sc.getCurrent()->toInteger() ; n := sc.getCurrent()->toInteger() ; var test : Test ; test := Test.newTest() ; var withoutDiscount : double ; var withDiscount : double ; if (hh >= 20) then ( withDiscount := test.computePrice(h, n, c) - ((test.computePrice(h, n, c) * 20) / 100) ; OclFile["System.out"].println(withDiscount) ) else skip ; if (hh < 20) then ( var minutes : double ; minutes := ((20 - hh - 1) * 60) + (60 - mm) ; var newhunger : double ; newhunger := test.computeNewHunger(h, d, minutes) ; var discount : double ; discount := (test.computePrice(newhunger, n, c) * 20) / 100 ; withDiscount := test.computePrice(newhunger, n, c) - discount ; withoutDiscount := test.computePrice(h, n, c) ; OclFile["System.out"].println(if withDiscount < withoutDiscount then withDiscount else withoutDiscount endif) ; ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileInputStream ; import java.io.FileNotFoundException ; import java.util.Scanner ; import java.lang.Math.*; public class Oddness { private static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int hh=scanner.nextInt(); int mm=scanner.nextInt(); double inithunger=scanner.nextDouble(); double increhunger=scanner.nextDouble(); double cost=scanner.nextDouble(); double discount=cost*0.8 ; double decrehunger=scanner.nextDouble(); if(hh>=20)System.out.println(Math.ceil(inithunger/decrehunger)*discount); else { int min=(20-hh)*60-mm ; double finalhunger=min*increhunger+inithunger ; double finalcost=Math.ceil(finalhunger/decrehunger)*discount ; double initcost=Math.ceil(inithunger/decrehunger)*cost ; if(initcosttoInteger() ; var mm : int ; mm := scanner.getCurrent()->toInteger() ; var inithunger : double ; inithunger := scanner.getCurrent()->toReal() ; var increhunger : double ; increhunger := scanner.getCurrent()->toReal() ; var cost : double ; cost := scanner.getCurrent()->toReal() ; var discount : double ; discount := cost * 0.8 ; var decrehunger : double ; decrehunger := scanner.getCurrent()->toReal() ; if (hh >= 20) then OclFile["System.out"].println((inithunger / decrehunger)->ceil() * discount) else ( var min : int ; min := (20 - hh) * 60 - mm ; var finalhunger : double ; finalhunger := min * increhunger + inithunger ; var finalcost : double ; finalcost := (finalhunger / decrehunger)->ceil() * discount ; var initcost : double ; initcost := (inithunger / decrehunger)->ceil() * cost ; if (initcost < finalcost) then OclFile["System.out"].println(initcost) else OclFile["System.out"].println(finalcost) ; ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.text.DecimalFormat ; import java.util.*; public class Main { public static void main(String[] args)throws Exception { FastReader reader=new FastReader(); int hh=reader.nextInt(),mm=reader.nextInt(); double h,d,c,n ; h=reader.nextInt(); d=reader.nextInt(); c=reader.nextInt(); n=reader.nextInt(); double fir=Math.ceil(h/n)*c ; double sec ; if(hh>=20){ sec=Math.ceil(h/n)*c ; } else { int min=60-mm ; if(min<60){ min+=(20-1-hh)*60 ; } else min+=(20-hh)*60-60 ; min*=d ; sec=Math.ceil((h+min)/n)*c ; } System.out.println(new DecimalFormat("#0.0000").format(Math.min(fir,sec*0.8))); } static class FastReader { BufferedReader br ; StringTokenizer st ; FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : FastReader ; reader := FastReader.newFastReader() ; var hh : int ; hh := reader.nextInt() ; var mm : int ; mm := reader.nextInt() ; var h : double ; var d : double ; var c : double ; var n : double ; h := reader.nextInt() ; d := reader.nextInt() ; c := reader.nextInt() ; n := reader.nextInt() ; var fir : double ; fir := (h / n)->ceil() * c ; var sec : double ; if (hh >= 20) then ( sec := (h / n)->ceil() * c ) else ( var min : int ; min := 60 - mm ; if (min < 60) then ( min := min+((20 - 1 - hh) * 60) ) else min := min+((20 - hh) * 60 - 60) ; ; min := min*(d) ; sec := ((h + min) / n)->ceil() * c ) ; OclFile["System.out"].println(DecimalFormat.newDecimalFormat("#0.0000").format(Set{fir, sec * 0.8}->min())) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean check(int n){ int m=n ; while(n!=0){ int r=n % 10 ; if(r>0)if((m % r)!=0)return false ; n/=10 ; } return true ; } static int count(int l,int r){ int ans=0 ; for(int i=l ; i<=r ; i++)if(check(i))ans+=1 ; return ans ; } public static void main(String args[]){ int l=10,r=20 ; System.out.println(count(10,20)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation check( n : int) : boolean pre: true post: true activity: ( var m : int ; m := n ; while (n /= 0) do ( var r : int ; r := n mod 10 ; if (r > 0) then if ((m mod r) /= 0) then return false else skip ; else skip ; n := n/(10) ) ; return true ); static operation count( l : int, r : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := l ; while i <= r do ( if (check(i)) then ans := ans+(1) ; else skip ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 10 ; var r : int ; r := 20 ; OclFile["System.out"].println(count(10, 20)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class test { private static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int hh=sc.nextInt(); int mm=sc.nextInt(); int time=hh*60+mm ; int H=sc.nextInt(); int D=sc.nextInt(); int C=sc.nextInt(); int N=sc.nextInt(); if(time>=60*20){ System.out.println((H+N-1)/N*C*0.8); } else { System.out.println(Math.min((H+N-1)/N*C,((60*20-time)*D+H+N-1)/N*C*0.8)); } } } ------------------------------------------------------------ OCL File: --------- class test { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var hh : int ; hh := sc.getCurrent()->toInteger() ; var mm : int ; mm := sc.getCurrent()->toInteger() ; var time : int ; time := hh * 60 + mm ; var H : int ; H := sc.getCurrent()->toInteger() ; var D : int ; D := sc.getCurrent()->toInteger() ; var C : int ; C := sc.getCurrent()->toInteger() ; var N : int ; N := sc.getCurrent()->toInteger() ; if (time >= 60 * 20) then ( OclFile["System.out"].println((H + N - 1) / N * C * 0.8) ) else ( OclFile["System.out"].println(Set{(H + N - 1) / N * C, ((60 * 20 - time) * D + H + N - 1) / N * C * 0.8}->min()) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.*; class GFG { public static double answer(double X,double K){ double i=10 ; double MAX=Math.pow(i,K)-1 ; return(MAX-(MAX % X)); } public static void main(String[] args){ double X=30 ; double K=3 ; System.out.println((int)answer(X,K)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation answer( X : double, K : double) : double pre: true post: true activity: ( var i : double ; i := 10 ; var MAX : double ; MAX := i->pow(K) - 1 ; return (MAX - (MAX mod X)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var X : double ; X := 30 ; var K : double ; K := 3 ; OclFile["System.out"].println(answer(X, K)->oclAsType(int)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int INT_MAX=Integer.MAX_VALUE ; static int min_element(int[] A,int N){ int min=A[0]; int i ; for(i=1 ; iA[i]){ min=A[i]; } } return min ; } static int countPartitions(int[] A,int N){ int count=0 ; int i,j ; for(i=0 ; i A[i+1]) then ( min := A[i+1] ) else skip ) ; i := i + 1 ) ; return min ); static operation countPartitions( A : Sequence(int), N : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; var j : int ; i := 0 ; while i < N do ( ( var min_elem : int ; min_elem := min_element(A, N) ; if (min_elem = INT_MAX) then break else skip ; count := count + 1 ; j := 0 ; while j < N do ( ( if (A[j+1] mod min_elem = 0) then A[j+1] := INT_MAX ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{7,6,5,4,3,2,2,3} ; var N : int ; N := arr->size() ; OclFile["System.out"].println(countPartitions(arr, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int k=sc.nextInt(); char[][] arr=new char[h][w]; PrintWriter out=new PrintWriter(System.out); public static void main(String[] args){ new Main().run(); } void run(){ for(int i=0 ; i>j & 1)==1){ varH++; } } int[] sum=new int[h]; int front=0 ; for(int j=0 ; jk){ if(j==front){ continue label ; } front=j ; Arrays.fill(sum,0); tmpAns++; j--; break inner ; } } } ans=Math.min(ans,tmpAns); } out.println(ans); out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute h : int := sc.getCurrent()->toInteger(); attribute w : int := sc.getCurrent()->toInteger(); attribute k : int := sc.getCurrent()->toInteger(); attribute arr : Sequence(Sequence(String)) := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)); attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < h do ( ( arr[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var ans : int ; ans := 2147483647 ; var i : int ; i := 0 ; while i < (1*(2->pow((h - 1))))->oclAsType(long) do ( ( var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var varH : int ; varH := 0 ; var tmpAns : int ; tmpAns := bitCount(i) ; var j : int ; j := 0 ; while j < h do ( ( var l : int ; l := 0 ; while l < w do ( ( a[varH+1][l+1] := a[varH+1][l+1]+(arr[j+1][l+1] - ('0')->char2byte()) ) ; l := l + 1 ) ; if ((MathLib.bitwiseAnd((i/(2->pow(j)))->oclAsType(long),1)) = 1) then ( varH := varH + 1 ) else skip ) ; j := j + 1 ) ; var sum : Sequence(int) ; sum := Integer.subrange(1,h)->collect(0) ; var front : int ; front := 0 ; var j : int ; j := 0 ; while j < w do ( ( var l : int ; l := 0 ; while l < h do ( ( sum[l+1] := sum[l+1]+(a[l+1][j+1]) ; if (sum[l+1] > k) then ( if (j = front) then ( continue ) else skip ; front := j ; sum := sum->collect(0) ; tmpAns := tmpAns + 1 ; j := j - 1 ; break ) else skip ) ; l := l + 1 ) ; ) ; j := j + 1 ) ; ans := Set{ans, tmpAns}->min() ; ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int H=sc.nextInt(); int W=sc.nextInt(); int K=sc.nextInt(); int[][] s=new int[H][W]; for(int i=0 ; i>j)==1)temp++; } int[] sum=new int[H]; for(int j=0 ; jK)continue LOOP ; sum[k]+=x[k][j]; if(sum[k]>K){ temp++; for(int l=0 ; ltoInteger() ; var W : int ; W := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var s : Sequence(Sequence(int)) ; s := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var i : int ; i := 0 ; while i < H do ( ( var S : String ; S := sc.getCurrent() ; var j : int ; j := 0 ; while j < W do ( s[i+1][j+1] := ("" + S->at(j+1))->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 100000 ; var i : int ; i := 0 ; while i < (1*(2->pow(H)))->oclAsType(long) do ( ( var temp : int ; temp := 0 ; var x : Sequence(Sequence(int)) ; x := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var j : int ; j := 0 ; while j < H do ( ( var k : int ; k := 0 ; while k < W do ( x[temp+1][k+1] := x[temp+1][k+1]+(s[j+1][k+1]) ; ; k := k + 1 ) ; if ((MathLib.bitwiseAnd(1,(i/(2->pow(j)))->oclAsType(long))) = 1) then temp := temp + 1 ; else skip ) ; j := j + 1 ) ; var sum : Sequence(int) ; sum := Integer.subrange(1,H)->collect(0) ; var j : int ; j := 0 ; while j < W do ( ( var k : int ; k := 0 ; while k < H do ( ( if (x[k+1][j+1] > K) then continue else skip ; sum[k+1] := sum[k+1]+(x[k+1][j+1]) ; if (sum[k+1] > K) then ( temp := temp + 1 ; var l : int ; l := 0 ; while l < H do ( sum[l+1] := x[l+1][j+1] ; ; l := l + 1 ) ; break ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ; ans := Set{ans, temp}->min() ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.*; public class Main { public static ArrayListlinkList[][]; public static int dists[]; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); linkList=new ArrayList[N+1][2]; dists=new int[N+1]; for(int i=0 ; i(); linkList[i][1]=new ArrayList(); } for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; linkList := Integer.subrange(1,N + 1)->collect(Integer.subrange(1,2)->collect(null)) ; dists := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N + 1 do ( ( dists[i+1] := -2147483648 ; linkList[i+1][0+1] := Sequence{} ; linkList[i+1][1+1] := Sequence{} ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; linkList[l+1][0+1]->excludes(r) ; linkList[l+1][1+1]->excludes(d) ; linkList[r+1][0+1]->excludes(l) ; linkList[r+1][1+1]->excludes(-d) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( if (dists[i+1] /= -2147483648) then continue else skip ; if (not(dfs(i, 0))) then ( OclFile["System.out"].println("No") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; ); static operation dfs( i : int, dist : int) : boolean pre: true post: true activity: ( if (dists[i+1] /= -2147483648) then return dists[i+1] = dist else skip ; dists[i+1] := dist ; var j : int ; j := 0 ; while j < linkList[i+1][0+1]->size() do ( ( if (not(dfs(linkList[i+1][0+1]->at(j+1), dist + linkList[i+1][1+1]->at(j+1)))) then return false else skip ) ; j := j + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean checkSubarraySum(int[] arr,int n,int k,int sum){ int curr_sum=0 ; for(int i=0 ; isize() ; if (checkSubarraySum(arr, n, k, sum)) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean checkSubarraySum(int arr[],int n,int k,int sum){ for(int i=0 ; isize() ; if (checkSubarraySum(arr, n, k, sum)) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class C { void p(String s){ System.out.println(s); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int zz=1 ; zz<=T ; zz++){ C=sc.nextInt(); N=sc.nextInt(); dp=new double[C+1]; Arrays.fill(dp,-1.0); System.out.println("Case #"+zz+": "+dp(0)); } } static int C,N ; static double[] dp ; public static double dp(int numDiff){ if(numDiff>=C)return 0.0 ; if(dp[numDiff]!=-1.0)return dp[numDiff]; double pr0=((double)choose(numDiff,N))/choose(C,N); double ev=0.0 ; for(int i=1 ; i<=N ; i++){ ev+=(1.0+dp(numDiff+i))*(((double)choose(numDiff,N-i)*choose(C-numDiff,i)))/(choose(C,N)); } double ans=(pr0+ev)/(1-pr0); dp[numDiff]=ans ; return ans ; } public static long choose(int n,int k){ long ans=1 ; ArrayListtoDiv=new ArrayList(); for(int i=2 ; i<=k ; i++)toDiv.add(i); for(int i=n ; i>=n-k+1 ; i--){ ans*=i ; for(int j=0 ; jtoInteger() ; var zz : int ; zz := 1 ; while zz <= T do ( ( C := sc.getCurrent()->toInteger() ; N := sc.getCurrent()->toInteger() ; dp := Integer.subrange(1,C + 1)->collect(0.0) ; dp := dp->collect(-1.0) ; OclFile["System.out"].println("Case #" + zz + ": " + dp(0)) ; ) ; zz := zz + 1 ) ); static attribute C : int; static attribute dp : Sequence(double); static operation dp( numDiff : int) : double pre: true post: true activity: ( if (numDiff >= C) then return 0.0 else skip ; if (dp[numDiff+1] /= -1.0) then return dp[numDiff+1] else skip ; var pr0 : double ; pr0 := (choose(numDiff, N)->oclAsType(double)) / choose(C, N) ; var ev : double ; ev := 0.0 ; var i : int ; i := 1 ; while i <= N do ( ( ev := ev+((1.0 + dp(numDiff + i)) * ((choose(numDiff, N - i)->oclAsType(double) * choose(C - numDiff, i))) / (choose(C, N))) ) ; i := i + 1 ) ; var ans : double ; ans := (pr0 + ev) / (1 - pr0) ; dp[numDiff+1] := ans ; return ans ); static operation choose( n : int, k : int) : long pre: true post: true activity: ( var ans : long ; ans := 1 ; var toDiv : Sequence(int) ; toDiv := Sequence{} ; var i : int ; i := 2 ; while i <= k do ( toDiv := toDiv->including(i) ; ; i := i + 1 ) ; var i : int ; i := n ; while i >= n - k + 1 do ( ( ans := ans*(i) ; var j : int ; j := 0 ; while j < toDiv->size() do ( ( if (ans mod toDiv->at(j+1) = 0) then ( ans := ans/(toDiv->at(j+1)) ; toDiv := toDiv->excludingAt(j+1) ; j := j - 1 ) else skip ) ; j := j + 1 ) ) ; i := i - 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class x { public static void main(String args[])throws Exception { Scanner in=new Scanner(System.in); int t=in.nextInt(); long[][] C=new long[41][41]; for(int i=0 ; i<=40 ; i++){ C[i][0]=1 ; for(int j=1 ; j<=i ; j++)C[i][j]=C[i-1][j]+C[i-1][j-1]; } MathContext mc=new MathContext(50,RoundingMode.HALF_EVEN); for(int tt=1 ; tt<=t ; tt++){ int A=in.nextInt(),N=in.nextInt(); BigDecimal[] E=new BigDecimal[A+1]; E[A]=new BigDecimal(0,mc); for(int i=A-1 ; i>=0 ; i--){ E[i]=new BigDecimal(C[A][N],mc); for(int j=i+1 ; j<=Math.min(A,i+N); j++){ BigDecimal P=new BigDecimal(C[A-i][j-i],mc); P=P.multiply(new BigDecimal(C[i][N-j+i],mc),mc); E[i]=E[i] .add(P.multiply(E[j],mc),mc); } BigDecimal D=new BigDecimal(C[A][N],mc).subtract(new BigDecimal(C[i][N],mc),mc); E[i]=E[i] .divide(D,mc); } System.out.println("Case #"+tt+": "+E[0]); }; }; }; ------------------------------------------------------------ OCL File: --------- class x { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var C : Sequence(Sequence(long)) ; C := Integer.subrange(1,41)->collect(Integer.subrange(1,41)->collect(0)) ; var i : int ; i := 0 ; while i <= 40 do ( ( C[i+1][0+1] := 1 ; var j : int ; j := 1 ; while j <= i do ( C[i+1][j+1] := C[i - 1+1][j+1] + C[i - 1+1][j - 1+1] ; ; j := j + 1 ) ) ; i := i + 1 ) ; var mc : MathContext ; mc := MathContext.newMathContext(50, RoundingMode.HALF_EVEN) ; var tt : int ; tt := 1 ; while tt <= t do ( ( var A : int ; A := in.getCurrent()->toInteger() ; var N : int ; N := in.getCurrent()->toInteger() ; var E : Sequence(double) ; E := Integer.subrange(1,A + 1)->collect(null) ; E[A+1] := double(0, mc) ; var i : int ; i := A - 1 ; while i >= 0 do ( ( E[i+1] := double(C[A+1][N+1], mc) ; var j : int ; j := i + 1 ; while j <= Set{A, i + N}->min() do ( ( var P : double ; P := double(C[A - i+1][j - i+1], mc) ; P := P.multiply(double(C[i+1][N - j + i+1], mc), mc) ; E[i+1] := E[i+1]->excludes(P.multiply(E[j+1], mc), mc) ) ; j := j + 1 ) ; var D : double ; D := double(C[A+1][N+1], mc).subtract(double(C[i+1][N+1], mc), mc) ; E[i+1] := E[i+1].divide(D, mc) ) ; i := i - 1 ) ; OclFile["System.out"].println("Case #" + tt + ": " + E[0+1]) ; ) ; tt := tt + 1 ) ; ); } ; ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MainClass { public static void main(String[] agrs){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); if(a==b){ System.out.println(a*10+1+" "+(a*10+2)); } else if(a+1==b){ System.out.println(a+" "+b); } else if(a+1==b*10)System.out.println(a+" "+b*10); else System.out.println(-1); } } ------------------------------------------------------------ OCL File: --------- class MainClass { static operation main( agrs : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (a = b) then ( OclFile["System.out"].println(a * 10 + 1 + " " + (a * 10 + 2)) ) else if (a + 1 = b) then ( OclFile["System.out"].println(a + " " + b) ) else if (a + 1 = b * 10) then OclFile["System.out"].println(a + " " + b * 10) else OclFile["System.out"].println(-1) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class C { public static void main(String[] args)throws Exception { new C(); } final int oo=(int)1e9 ; double[][] choose=new double[50][50]; int N,C ; double D ; double[] memo=new double[50]; C()throws Exception { for(double[] c : choose)Arrays.fill(c,-1); Scanner in=new Scanner(System.in); for(int T=in.nextInt(),ds=1 ; T-->0 ; ++ds){ C=in.nextInt(); N=in.nextInt(); D=choose(C,N); Arrays.fill(memo,-1); System.out.printf("Case #%d: %.9f%n",ds,go(0)); } } double go(int X){ if(X==C)return 0 ; if(memo[X]>-0.5)return memo[X]; double exp=1 ; for(int i=1 ; i<=N ; ++i){ if(X+i>C)break ; exp+=choose(X,N-i)*choose(C-X,i)/D*go(X+i); } exp/=(1-choose(X,N)*choose(C-X,0)/D); return memo[X]=exp ; } double choose(int n,int k){ if(k==0 || n==k)return 1 ; if(n-0.5)return choose[n][k]; return choose[n][k]=choose(n-1,k-1)+choose(n-1,k); } } ------------------------------------------------------------ OCL File: --------- class C { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( C.newC() ); attribute oo : int := 1e9->oclAsType(int); attribute choose : Sequence(Sequence(double)) := Integer.subrange(1,50)->collect(Integer.subrange(1,50)->collect(0.0)); attribute N : int; attribute D : double; attribute memo : Sequence(double) := Integer.subrange(1,50)->collect(0.0); static operation newC() : C pre: true post: true activity: ( var self : C ; self := createC(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( for (c : choose) do ( c := c->collect(-1) ; ) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := in.getCurrent()->toInteger() ; var ds : int ; ds := 1 ; while T > 0 do ( ( C := in.getCurrent()->toInteger() ; N := in.getCurrent()->toInteger() ; D := choose(C, N) ; memo := memo->collect(-1) ; OclFile["System.out"].printf("Case #%d: %.9f%n", ds, go(0)) ; ) ; ds := ds + 1 ) ); operation go( X : int) : double pre: true post: true activity: ( if (X = C) then return 0 else skip ; if (memo[X+1] > -0.5) then return memo[X+1] else skip ; var exp : double ; exp := 1 ; var i : int ; i := 1 ; while i <= N do ( ( if (X + i > C) then break else skip ; exp := exp+(choose(X, N - i) * choose(C - X, i) / D * go(X + i)) ) ; i := i + 1 ) ; exp := exp/((1 - choose(X, N) * choose(C - X, 0) / D)) ; return memo[X+1] ); operation choose( n : int, k : int) : double pre: true post: true activity: ( if (k = 0 or n = k) then return 1 else skip ; if (n < k) then return 0 else skip ; if (choose[n+1][k+1] > -0.5) then return choose[n+1][k+1] else skip ; return choose[n+1][k+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.PrintStream ; import java.util.Scanner ; public class C { private static String PNAME="C-large" ; public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new FileReader(PNAME+".in")); PrintStream out=new PrintStream(PNAME+".out"); Scanner in=new Scanner(br); int TC=in.nextInt(); for(int tc=1 ; tc<=TC ; tc++){ int c=in.nextInt(); int n=in.nextInt(); out.println("Case #"+tc+": "+solve(c,n)); } br.close(); out.close(); } private static double solve(int c,int n){ for(int i=0 ; i=n){ double p=choose(have,n)*1.0/choose(c,n); ret/=1-p ; } memo[need]=ret ; return ret ; } private static long choose(int n,int k){ long ret=1 ; for(int i=0 ; itoInteger() ; var tc : int ; tc := 1 ; while tc <= TC do ( ( var c : int ; c := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; skip ) ; tc := tc + 1 ) ; skip ; skip ; ); static operation solve( c : int, n : int) : double pre: true post: true activity: ( var i : int ; i := 0 ; while i < memo->size() do ( memo[i+1] := -1 ; ; i := i + 1 ) ; return calc(c, n, c) ); static operation calc( c : int, n : int, need : int) : double pre: true post: true activity: ( if (need = 0) then return 0 else skip ; if (memo[need+1] /= -1) then return memo[need+1] else skip ; var ret : double ; ret := 1 ; var have : int ; have := c - need ; var good : int ; good := 1 ; while good <= Set{n, need}->min() do ( ( var bad : int ; bad := n - good ; var p : double ; p := choose(need, good) ; p := p*(choose(have, bad)) ; p := p/(choose(c, n)) ; ret := ret+(p * calc(c, n, need - good)) ; ) ; good := good + 1 ) ; if (have >= n) then ( var p : double ; p := choose(have, n) * 1.0 / choose(c, n) ; ret := ret/(1 - p) ) else skip ; memo[need+1] := ret ; return ret ); static operation choose( n : int, k : int) : long pre: true post: true activity: ( var ret : long ; ret := 1 ; var i : int ; i := 0 ; while i < k do ( ( ret := ret*(n - i) ; ret := ret/(i + 1) ) ; i := i + 1 ) ; return ret ); static attribute memo : Sequence(double) := Integer.subrange(1,64)->collect(0.0); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MAXN=100 ; static int maxValue(int n,int m,int x[],int y[],int a[]){ int c[][]=new int[MAXN][MAXN]; for(int i=0 ; icollect(Integer.subrange(1,MAXN)->collect(0)) ; var i : int ; i := 0 ; while i < m do ( ( var p : int ; p := 0 ; while p < n do ( ( var q : int ; q := 0 ; while q < n do ( ( var dx : int ; dx := if p - x[i+1] < 0 then -(p - x[i+1]) else p - x[i+1] endif ; var dy : int ; dy := if q - y[i+1] < 0 then -(q - y[i+1]) else q - y[i+1] endif ; var d : int ; d := Set{dx, dy}->max() ; c[p+1][q+1] := c[p+1][q+1]+(Set{0, a[i+1] - d}->max()) ) ; q := q + 1 ) ) ; p := p + 1 ) ) ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( res := Set{res, c[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; var m : int ; m := 2 ; var x : Sequence(int) ; x := Sequence{3,7} ; var y : Sequence(int) ; y := Sequence{3,7} ; var a : Sequence(int) ; a := Sequence{4,3} ; OclFile["System.out"].println(maxValue(n, m, x, y, a)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxSize=50 ; static double dp[]=new double[maxSize]; static int v[]=new int[maxSize]; static double expectedSteps(int x){ if(x==0)return 0 ; if(x<=5)return 6 ; if(v[x]==1)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]; } public static void main(String[] args){ int n=10 ; System.out.println(expectedSteps(n-1)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute maxSize : int := 50; static attribute dp : double := Integer.subrange(1,maxSize)->collect(0.0); static attribute v : int := Integer.subrange(1,maxSize)->collect(0); static operation expectedSteps( x : int) : double 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] = 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] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println(expectedSteps(n - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static FastReader sc=null ; public static void main(String[] args){ sc=new FastReader(); int n=sc.nextInt(); int a[]=sc.readArray(n); int ans=0 ; for(int i=0 ; i+1al=new ArrayList<>(); for(int i : a)al.add(i); Collections.sort(al); for(int i=0 ; imax() + 1) ) ; i := i + 1 ) ; OclFile["System.out"].println("Finite") ; OclFile["System.out"].println(ans) ; ); static operation ruffleSort( a : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var al : Sequence(int) ; al := Sequence{} ; for (i : a) do ( al := al->including(i) ; ) ; al := al->sort() ; var i : int ; i := 0 ; while i < a->size() do ( a[i+1] := al->at(i+1) ; ; i := i + 1 ) ; return a ); static operation print( a : Sequence(int)) : void pre: true post: true activity: ( for (e : a) do ( ( OclFile["System.out"].print(e + " ") ) ) ; OclFile["System.out"].println() ); static class FastReader { attribute st : OclIterator := OclIterator.newOclIterator_String(""); attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.nextInt() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A1156 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (arr[i+1] + arr[i + 1+1] = 5) then ( OclFile["System.out"].println("Infinite") ; return ) else skip ; sum := sum+(arr[i+1] + arr[i + 1+1]) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 2 do ( ( if (arr[i+1] = 3 & arr[i + 1+1] = 1 & arr[i + 2+1] = 2) then sum := sum-(1) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Finite") ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static String reverse(String input){ char[] a=input.toCharArray(); int l,r=0 ; r=a.length-1 ; for(l=0 ; lcharacters() ; var l : int ; var r : int ; r := 0 ; r := a->size() - 1 ; l := 0 ; while l < r do ( ( var temp : String ; temp := a[l+1] ; a[l+1] := a[r+1] ; a[r+1] := temp ) ; l := l + 1 ; r := r - 1 ) ; return (a)->sum() ); static operation isPalindrome( r : String) : boolean pre: true post: true activity: ( var p : String ; p := r ; p := reverse(p) ; return (r = p) ); static operation CheckStr( s : String) : boolean pre: true post: true activity: ( var l : int ; l := s->size() ; var i : int ; i := 2 ; while i <= l do ( ( if (isPalindrome(s.subrange(0+1,i))) then ( break ) else skip ) ; i := i + 1 ) ; if (i = (l + 1)) then ( return false ) else skip ; i := 2 ; i := 2 ; while i <= l do ( ( if (isPalindrome(s.subrange((l)->char2byte() - i+1,l))) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "abccbarfgdbd" ; if (CheckStr(s)) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A1156 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (arr[i+1] + arr[i + 1+1] = 5) then ( OclFile["System.out"].println("Infinite") ; return ) else skip ; sum := sum+(arr[i+1] + arr[i + 1+1]) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 2 do ( ( if (arr[i+1] = 3 & arr[i + 1+1] = 1 & arr[i + 2+1] = 2) then sum := sum-(1) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Finite") ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class InscribedFigures { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); String[] temp=br.readLine().split(" "); int[] nums=new int[n]; for(int i=0 ; i=2 && nums[i]==2 && nums[i-1]==1 && nums[i-2]==3){ countTriple++; } } for(int i=0 ; itoInteger() ; var temp : Sequence(String) ; temp := br.readLine()->split(" ") ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := (temp[i+1])->toInteger() ) ; i := i + 1 ) ; var res : int ; res := 0 ; var countTriple : int ; countTriple := 0 ; var i : int ; i := 2 ; while i < n do ( ( if (i >= 2 & nums[i+1] = 2 & nums[i - 1+1] = 1 & nums[i - 2+1] = 3) then ( countTriple := countTriple + 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var sum : int ; sum := nums[i+1] + nums[i + 1+1] ; if (sum = 5) then ( skip ; return ) else if (sum = 4) then ( res := res+(4) ) else if (sum = 3) then ( res := res+(3) ) else skip ; ; ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class B_822 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); sc.nextLine(); String s=sc.nextLine(); String t=sc.nextLine(); int[] l=new int[m-n+1]; String[] loc=new String[m-n+1]; Arrays.fill(loc,""); for(int i=0 ; i<=m-n ; i++){ int c=0 ; for(int j=i ; jl[i])min_ind=i ; } System.out.println(l[min_ind]); System.out.println(loc[min_ind]); } } ------------------------------------------------------------ OCL File: --------- class B_822 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; skip ; var s : String ; s := sc.nextLine() ; var t : String ; t := sc.nextLine() ; var l : Sequence(int) ; l := Integer.subrange(1,m - n + 1)->collect(0) ; var loc : Sequence(String) ; loc := Integer.subrange(1,m - n + 1)->collect(null) ; loc := loc->collect("") ; var i : int ; i := 0 ; while i <= m - n do ( ( var c : int ; c := 0 ; var j : int ; j := i ; while j < n + i do ( ( if (t->at(j+1) /= s->at(c+1)) then ( l[i+1] := l[i+1] + 1 ; loc[i+1] := loc[i+1]+(((c + 1) + "") + " ") ) else skip ; c := c + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var min_ind : int ; min_ind := 0 ; var i : int ; i := 0 ; while i <= m - n do ( ( if (l[min_ind+1] > l[i+1]) then min_ind := i ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(l[min_ind+1]) ; OclFile["System.out"].println(loc[min_ind+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.util.Arrays ; public class Cv { public static void main(String[] args){ FastScanner in=new FastScanner(); Scanner input=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int da=input.nextInt(); int db=input.nextInt(); if((da>db && da!=9)||(db-da)>1){ out.println(-1); } else if(da!=9){ if((db-da)==1){ out.println(da+" "+db); } else { out.println(da+"1 "+db+"2"); } } if(da==9){ if(db==1){ out.println("9 10"); } else if(db==9){ out.println(da+"1 "+db+"2"); } else { out.println(-1); } } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next(){ while(! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } byte nextByte(){ return Byte.parseByte(next()); } short nextShort(){ return Short.parseShort(next()); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return java.lang.Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } } } ------------------------------------------------------------ OCL File: --------- class Cv { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastScanner ; in := FastScanner.newFastScanner() ; var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var da : int ; da := input.getCurrent()->toInteger() ; var db : int ; db := input.getCurrent()->toInteger() ; if ((da > db & da /= 9) or (db - da) > 1) then ( skip ) else if (da /= 9) then ( if ((db - da) = 1) then ( skip ) else ( skip ) ) else skip ; ; if (da = 9) then ( if (db = 1) then ( skip ) else if (db = 9) then ( skip ) else ( skip ) ; ) else skip ; skip ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextByte() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextShort() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return java.lang.Long.parseLong(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Scanner ; import java.util.TreeMap ; import java.util.TreeSet ; public class trailzero { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); String s1=sc.next(); String s2=sc.next(); int msum=Integer.MAX_VALUE ; int index=0 ; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; var msum : int ; msum := 2147483647 ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < m - n + 1 do ( ( var sum : int ; sum := 0 ; var j : int ; j := 0 ; while j < n do ( ( if (s2->at(j + i+1) /= s1->at(j+1)) then ( sum := sum + 1 ) else skip ) ; j := j + 1 ) ; if (sum < msum) then ( msum := sum ; index := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(msum) ; if (msum /= 0) then ( var j : int ; j := 0 ; while j < n do ( ( if (s2->at(j + index+1) /= s1->at(j+1)) then ( OclFile["System.out"].print((j + 1) + " ") ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println() ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Objects ; import java.util.Scanner ; public class Main { public static void check(String[] a,String[] b){ int flag=0 ; int k=0 ; int min=0 ; int Case=0 ; int mink=0 ; for(int i=0 ; isize() - a->size() + 1 do ( ( k := i ; var j : int ; j := 0 ; while j < a->size() do ( ( if (not(Objects = b[k+1], a[j+1])) then ( flag := flag + 1 ) else skip ; k := k + 1 ) ; j := j + 1 ) ; k := i ; if (Case = 0) then ( min := flag ; Case := Case + 1 ) else skip ; if (flag < min) then ( min := flag ; mink := k ) else skip ; flag := 0 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; var p : int ; p := 0 ; while p < a->size() do ( ( if (not(Objects = b[mink+1], a[p+1])) then ( OclFile["System.out"].printf("%d ", p + 1) ) else skip ; mink := mink + 1 ) ; p := p + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : String ; a := sc.getCurrent() ; var b : String ; b := sc.getCurrent() ; var A : Sequence(String) ; A := a->split("") ; var B : Sequence(String) ; B := b->split("") ; execute check(A, B) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Crossword822B { public static void main(String[] args){ Scanner in=new Scanner(System.in); int s_size=in.nextInt(); int t_size=in.nextInt(); String s=in.next(); String t=in.next(); int size=t_size-s_size ; int max=0,index=0,arr[]=new int[s_size],x=0 ; for(int i=0 ; i<=size ; i++){ int count=0 ; for(int j=0 ; jmax){ max=count ; index=i ; } } for(int i=0 ; itoInteger() ; var t_size : int ; t_size := in.getCurrent()->toInteger() ; var s : String ; s := in.getCurrent() ; var t : String ; t := in.getCurrent() ; var size : int ; size := t_size - s_size ; var max : int ; max := 0 ; var index : int ; index := 0 ; var arr : Sequence(void) ; arr := Integer.subrange(1,s_size)->collect(0) ; var x : int ; x := 0 ; var i : int ; i := 0 ; while i <= size do ( ( var count : int ; count := 0 ; var j : int ; j := 0 ; while j < s_size do ( ( if (t->at(i + j+1) = s->at(j+1)) then count := count + 1 ; else skip ) ; j := j + 1 ) ; if (count > max) then ( max := count ; index := i ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s_size do ( ( if (t->at(index + i+1) /= s->at(i+1)) then ( arr[x+1] := i + 1 ; x := x + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(s_size - max) ; var i : int ; i := 0 ; while i < s_size - max do ( ( if (i = s_size - max - 1) then OclFile["System.out"].println(arr[i+1]) ; else OclFile["System.out"].print(arr[i+1] + " ") ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int test=in.nextInt(); for(int t=1 ; t<=test ; t++){ int n=in.nextInt(); ArrayListlist=new ArrayList<>(); Mapmap=new HashMap<>(); for(int i=0 ; itoInteger() ; var t : int ; t := 1 ; while t <= test do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var list : Sequence(int) ; list := Sequence{} ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := in.getCurrent()->toInteger() ; list := list->including(v) ; if (not(map->keys()->includes(v))) then ( map := map->union(Map{v |-> 1}) ) else ( map := map->union(Map{v |-> map->at(v) + 1}) ) ) ; i := i + 1 ) ; var flag : boolean ; flag := false ; var ind : int ; ind := 0 ; var min : int ; min := 2147483647 ; for (i : map->keys()) do ( ( var val : int ; val := map->at(i) ; if (val = 1) then ( min := Set{i, min}->min() ; flag := true ) else skip ) ) ; if (flag) then ( skip ) else ( skip ) ; ) ; t := t + 1 ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Unique_Bid_Auction_unsolved { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testcase=sc.nextInt(); while(testcase!=0){ testcase--; int len=sc.nextInt(),result=-1 ; int arr[]=new int[len+1],count[]=new int[len+1]; for(int i=0 ; i0)System.out.println(); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Unique_Bid_Auction_unsolved { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var testcase : int ; testcase := sc.getCurrent()->toInteger() ; while (testcase /= 0) do ( testcase := testcase - 1 ; var len : int ; len := sc.getCurrent()->toInteger() ; var result : int ; result := -1 ; var arr : Sequence(int) ; arr := Integer.subrange(1,len + 1)->collect(0) ; var count : Sequence(void) ; count := Integer.subrange(1,len + 1)->collect(0) ; var i : int ; i := 0 ; while i < len do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; count[arr[i+1]+1] := count[arr[i+1]+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= len do ( ( if (count[i+1] = 1) then ( result := i ; break ) else skip ) ; i := i + 1 ) ; if (result /= -1) then ( var i : int ; i := 0 ; while i < len do ( ( if (arr[i+1] = result) then ( result := i + 1 ; break ) else skip ) ; i := i + 1 ) ) else skip ; OclFile["System.out"].print(result) ; if (testcase > 0) then OclFile["System.out"].println() ; else skip ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class CF_1454B_UniqueBidAuction { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int count=scanner.nextInt(); for(int i=0 ; imap=new HashMap(); for(int j=0 ; jentry : map.entrySet()){ if(entry.getValue()==false){ continue ; } if(entry.getKey()toInteger() ; var i : int ; i := 0 ; while i < count do ( ( var min : int ; min := 2147483647 ; var length : int ; length := scanner.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,length)->collect(0) ; var point : int ; point := -1 ; var map : Map(int,Boolean) ; map := Map{} ; var j : int ; j := 0 ; while j < length do ( ( var number : int ; number := scanner.getCurrent()->toInteger() ; arr[j+1] := number ; if (map->at(number) = null) then ( map := map->union(Map{number |-> true}) ) else ( map := map->antirestrict(Set{number}) ; map := map->union(Map{number |-> false}) ) ) ; j := j + 1 ) ; for (entry : map->asSet()) do ( ( if (entry.getValue() = false) then ( continue ) else skip ; if (entry.getKey() < min) then ( min := entry.getKey() ) else skip ) ) ; var j : int ; j := 0 ; while j < length do ( ( if (min = arr[j+1]) then ( point := j + 1 ) else skip ) ; j := j + 1 ) ; if (min = 2147483647) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(point) ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder sb=new StringBuilder(); int t=fs.nextInt(); while(t-->0){ int n=fs.nextInt(); int[] a=fs.readArray(n); int[] b=new int[n+1]; int min=Integer.MAX_VALUE ; for(int i=0 ; ii)min=i ; } int res=0,cnt=0 ; for(int i=0 ; i0 ? res : "-1").append("\n"); } System.out.print(sb); out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; i 0) do ( t := t - 1 ; skip ; ( var n : int ; n := fs.nextInt() ; var a : Sequence(int) ; a := fs.readArray(n) ; var b : Sequence(int) ; b := Integer.subrange(1,n + 1)->collect(0) ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( b[a[i+1]+1] := b[a[i+1]+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= n do ( ( if (b[i+1] = 1 & min > i) then min := i ; else skip ) ; i := i + 1 ) ; var res : int ; res := 0 ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (min = a[i+1]) then ( res := i + 1 ; cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; sb := sb + StringLib.newString(if cnt > 0 then res else "-1" endif) + StringLib.newString("\n") ; ) ; ) ; OclFile["System.out"].print(sb) ; skip ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int w=sc.nextInt(); int h=sc.nextInt(); boolean[] width=new boolean[w]; boolean[] height=new boolean[h]; Arrays.fill(width,false); Arrays.fill(height,false); for(int i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; var width : Sequence(boolean) ; width := Integer.subrange(1,w)->collect(false) ; var height : Sequence(boolean) ; height := Integer.subrange(1,h)->collect(false) ; width := width->collect(false) ; height := height->collect(false) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var wi : int ; wi := sc.getCurrent()->toInteger() ; var j : int ; j := Set{x - wi, 0}->max() ; while j < Set{x + wi, w}->min() do ( width[j+1] := true ; ; j := j + 1 ) ; var j : int ; j := Set{y - wi, 0}->max() ; while j < Set{y + wi, h}->min() do ( height[j+1] := true ; ; j := j + 1 ) ; ) ; i := i + 1 ) ; if (isFilledWithTrue(width) or isFilledWithTrue(height)) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; skip ; ); static operation isFilledWithTrue( bool : Sequence(boolean)) : boolean pre: true post: true activity: ( for (b : bool) do ( if (not(b)) then return false else skip ; ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test227 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() ; a[x+1] := a[x+1] + 1 ; b[x+1] := i + 1 ) ; i := i + 1 ) ; var c : int ; c := -1 ; var i : int ; i := 1 ; while i <= n do ( ( if (a[i+1] = 1) then ( c := b[i+1] ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=100002 ; static int f(int i,int m,char s[],int memoize[][]){ if(i==s.length){ return 0 ; } if(memoize[i][m]!=-1){ return memoize[i][m]; } int x=s[i]-'0' ; int ans=((x+m)% 3==0 && x % 2==0)? 1+f(i+1,(m+x)% 3,s,memoize): f(i+1,(m+x)% 3,s,memoize); memoize[i][m]=ans ; return memoize[i][m]; } static int countDivBy6(char s[]){ int n=s.length ; int[][] memoize=new int[n+1][3]; for(int i=0 ; isize()) then ( return 0 ) else skip ; if (memoize[i+1][m+1] /= -1) then ( return memoize[i+1][m+1] ) else skip ; var x : int ; x := s[i+1] - ('0')->char2byte() ; var ans : int ; ans := if ((x + m) mod 3 = 0 & x mod 2 = 0) then 1 + f(i + 1, (m + x) mod 3, s, memoize) else f(i + 1, (m + x) mod 3, s, memoize) endif ; memoize[i+1][m+1] := ans ; return memoize[i+1][m+1] ); static operation countDivBy6( s : Sequence(String)) : int pre: true post: true activity: ( var n : int ; n := s->size() ; var memoize : Sequence(Sequence(int)) ; memoize := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < n + 1 do ( ( var j : int ; j := 0 ; while j < 3 do ( ( memoize[i+1][j+1] := -1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s[i+1] = '0') then ( ans := ans + 1 ) else ( ans := ans+(f(i, 0, s, memoize)) ) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : Sequence(String) ; s := "4806"->characters() ; OclFile["System.out"].println(countDivBy6(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Random ; import java.util.Scanner ; public class A1225ForgettingThings { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); long a=scanner.nextLong(); long b=scanner.nextLong(); if(b-a==1){ System.out.println(((b*10)-1)+" "+(b*10)); } else if(b-a==0){ System.out.println(((b*10))+" "+((b*10)+1)); } else if(a==9 & b==1){ System.out.println(((b*10)-1)+" "+(b*10)); } else { System.out.println("-1"); } } } ------------------------------------------------------------ OCL File: --------- class A1225ForgettingThings { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : long ; a := scanner.getCurrent()->toLong() ; var b : long ; b := scanner.getCurrent()->toLong() ; if (b - a = 1) then ( OclFile["System.out"].println(((b * 10) - 1) + " " + (b * 10)) ) else if (b - a = 0) then ( OclFile["System.out"].println(((b * 10)) + " " + ((b * 10) + 1)) ) else if (a = 9 & b = 1) then ( OclFile["System.out"].println(((b * 10) - 1) + " " + (b * 10)) ) else ( OclFile["System.out"].println("-1") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static double Min_glass(int n,int k,int[] a){ int sum=0 ; for(int i=0 ; ioclAsType(double) / 100->oclAsType(double))->ceil() ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; var k : int ; k := 3 ; var a : Sequence(int) ; a := Sequence{200,150,140,300} ; a := a->sort() ; OclFile["System.out"].println(Min_glass(n, k, a)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static int n,m ; static boolean vis[]; static List>l=new ArrayList<>(); static StringBuffer str=new StringBuffer(); static void solve(){ long ans=0 ; int dp[]=new int[n+1]; for(int v=1 ; v<=n ; v++){ dp[v]=1 ; for(int u : l.get(v)){ if(u()); for(int i=0 ; icollect(0) ; var v : int ; v := 1 ; while v <= n do ( ( dp[v+1] := 1 ; for (u : l->at(v+1)) do ( ( if (u < v) then ( dp[v+1] := Set{dp[v+1], dp[u+1] + 1}->max() ) else skip ) ) ; ans := Set{ans, dp[v+1] * 1l * l->at(v+1)->size()}->max() ) ; v := v + 1 ) ; str := str + StringLib.newString(ans) + StringLib.newString("\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; var pw : OclFile ; var lenv : boolean ; lenv := false ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; var st : Sequence(String) ; st := bf.readLine()->trim()->split("\\s+") ; n := (st[0+1])->toInteger() ; m := (st[1+1])->toInteger() ; var i : int ; i := 0 ; while i <= n do ( l := l->including(Sequence{}) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( st := bf.readLine()->trim()->split("\\s+") ; var u : int ; u := (st[0+1])->toInteger() ; var v : int ; v := (st[1+1])->toInteger() ; l->at(u+1)->excludes(v) ; l->at(v+1)->excludes(u) ; ) ; i := i + 1 ) ; execute solve() ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GfG { static Boolean check(int n){ int d=(int)Math.sqrt(n); if(d*d==n)return true ; return false ; } static int largestNonPerfectSquareNumber(int a[],int n){ int maxi=-1 ; for(int i=0 ; isqrt()->oclAsType(int) ; if (d * d = n) then return true else skip ; return false ); static operation largestNonPerfectSquareNumber( a : Sequence(int), n : int) : int pre: true post: true activity: ( var maxi : int ; maxi := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (not(check(a[i+1]))) then maxi := Set{a[i+1], maxi}->max() ; else skip ) ; i := i + 1 ) ; return maxi ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{16,20,25,2,3,10} ; var n : int ; n := a->size() ; OclFile["System.out"].println(largestNonPerfectSquareNumber(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; class GFG { static int countDigits(int a,int b){ int count=0 ; int p=Math.abs(a*b); if(p==0)return 1 ; while(p>0){ count++; p=p/10 ; } return count ; } public static void main(String args[]){ int a=33 ; int b=-24 ; System.out.println("Number of digits="+countDigits(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countDigits( a : int, b : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var p : int ; p := if a * b < 0 then -(a * b) else a * b endif ; if (p = 0) then return 1 else skip ; while (p > 0) do ( count := count + 1 ; p := p / 10 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 33 ; var b : int ; b := -24 ; OclFile["System.out"].println("Number of digits=" + countDigits(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int R=3 ; static final int C=3 ; static void swap(int mat[][],int row1,int row2,int col){ for(int i=0 ; ioclAsType(double) / mat[row+1][row+1] ; var i : int ; i := 0 ; while i < rank do ( mat[col+1][i+1] := mat[col+1][i+1]-(mult * mat[row+1][i+1]) ; ; i := i + 1 ) ) else skip ) ; col := col + 1 ) ) else ( var reduce : boolean ; reduce := true ; var i : int ; i := row + 1 ; while i < R do ( ( if (mat[i+1][row+1] /= 0) then ( execute swap(mat, row, i, rank) ; reduce := false ; break ) else skip ) ; i := i + 1 ) ; if (reduce) then ( rank := rank - 1 ; var i : int ; i := 0 ; while i < R do ( mat[i+1][row+1] := mat[i+1][rank+1] ; ; i := i + 1 ) ) else skip ; row := row - 1 ) ) ; row := row + 1 ) ; return rank ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{10,20,10},Sequence{-20,-30,10},Sequence{30,50,0}} ; OclFile["System.out"].print("Rank of the matrix is : " + rankOfMatrix(mat)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner in=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new AOJ0655().doIt(); } class AOJ0655 { void doIt(){ int n=in.nextInt(); Team team[]=new Team[n]; for(int i=0 ; id)team[a-1] .win+=3 ; else if(ctoInteger() ; var team : Sequence(Team) ; team := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( team[i+1] := Team.newTeam() ; ; i := i + 1 ) ; var limit : int ; limit := (n * n - n) / 2 ; var i : int ; i := 0 ; while i < limit do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var c : int ; c := in.getCurrent()->toInteger() ; var d : int ; d := in.getCurrent()->toInteger() ; if (c > d) then team[a - 1+1].win := team[a - 1+1].win+(3) ; else if (c < d) then team[b - 1+1].win := team[b - 1+1].win+(3) else ( team[a - 1+1].win := team[a - 1+1].win + 1 ; team[b - 1+1].win := team[b - 1+1].win + 1 ) ; ) ; i := i + 1 ) ; var result : Sequence(int) ; result := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var cnt : int ; cnt := 1 ; var s : int ; s := 0 ; while s < n do ( if (team[i+1].win < team[s+1].win) then cnt := cnt + 1 ; else skip ; ; s := s + 1 ) ; result[i+1] := cnt ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].println(result[i+1]) ; ; i := i + 1 ) ; ); class Team { attribute win : int; static operation newTeam() : Team pre: true post: true activity: ( var self : Team ; self := createTeam(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( self.win := 0 ); } } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int team=sc.nextInt(); if(team==0)break ; int Maxgame=team*(team-1)/2 ; int[] indexA=new int[Maxgame]; int[] indexB=new int[Maxgame]; int[] pointA=new int[Maxgame]; int[] pointB=new int[Maxgame]; for(int i=0 ; ipointB[i]){ winpoint[indexA[i] ]+=3 ; } else if(pointA[i]toInteger() ; if (team = 0) then break else skip ; var Maxgame : int ; Maxgame := team * (team - 1) / 2 ; var indexA : Sequence(int) ; indexA := Integer.subrange(1,Maxgame)->collect(0) ; var indexB : Sequence(int) ; indexB := Integer.subrange(1,Maxgame)->collect(0) ; var pointA : Sequence(int) ; pointA := Integer.subrange(1,Maxgame)->collect(0) ; var pointB : Sequence(int) ; pointB := Integer.subrange(1,Maxgame)->collect(0) ; var i : int ; i := 0 ; while i < Maxgame do ( ( indexA[i+1] := sc.getCurrent()->toInteger() - 1 ; indexB[i+1] := sc.getCurrent()->toInteger() - 1 ; pointA[i+1] := sc.getCurrent()->toInteger() ; pointB[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var solve : String ; solve := solve(team, indexA, indexB, pointA, pointB) ; OclFile["System.out"].println(solve) ; ) ); static operation solve( team : int, indexA : Sequence(int), indexB : Sequence(int), pointA : Sequence(int), pointB : Sequence(int)) : String pre: true post: true activity: ( var winpoint : Sequence(int) ; winpoint := Integer.subrange(1,team)->collect(0) ; var i : int ; i := 0 ; while i < indexA->size() do ( ( if (pointA[i+1] > pointB[i+1]) then ( winpoint[indexA[i+1]+1] := winpoint[indexA[i+1]+1]+(3) ) else if (pointA[i+1] < pointB[i+1]) then ( winpoint[indexB[i+1]+1] := winpoint[indexB[i+1]+1]+(3) ) else ( winpoint[indexA[i+1]+1] := winpoint[indexA[i+1]+1] + 1 ; winpoint[indexB[i+1]+1] := winpoint[indexB[i+1]+1] + 1 ) ; ) ; i := i + 1 ) ; var rank : Sequence(int) ; rank := Integer.subrange(1,team)->collect(0) ; var i : int ; i := 0 ; while i < winpoint->size() do ( ( var j : int ; j := 0 ; while j < winpoint->size() do ( ( if (winpoint[i+1] < winpoint[j+1]) then rank[i+1] := rank[i+1] + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < rank->size() do ( ( sb := sb + StringLib.newString((rank[i+1] + 1) + "\n") ) ; i := i + 1 ) ; return sb+""->trim() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Map.Entry ; import java.util.Scanner ; import java.util.concurrent.atomic.AtomicInteger ; import java.util.stream.Collectors ; import java.util.stream.IntStream ; public class Main { static final Scanner s=new Scanner(System.in); static IntStream REPS(int v){ return IntStream.range(0,v); } static IntStream REPS(int l,int r){ return IntStream.rangeClosed(l,r); } static IntStream INS(int n){ return REPS(n).map(i->getInt()); } static int getInt(){ return Integer.parseInt(s.next()); } public static void main(String[] $){ int n=getInt(),p[]=new int[n]; for(int l=n*(n-1)/2 ; l>0 ; --l){ int a=getInt()-1,b=getInt()-1,pa=getInt(),pb=getInt(); if(pa>pb)p[a]+=3 ; else if(pap[i-1])).entrySet().stream().sorted(Entry.comparingByKey(Comparator.reverseOrder())).map(Entry :: getValue).forEach(o->{ c.incrementAndGet(); for(int i : o)r[i-1]=c.get(); c.addAndGet(o.size()-1); } ); Arrays.stream(r).forEach(System.out :: println); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation REPS( v : int) : Sequence(int) pre: true post: true activity: ( return Integer.subrange(0, v-1) ); static operation REPS( l : int, r : int) : Sequence(int) pre: true post: true activity: ( return Integer.subrange(l, r) ); static operation INS( n : int) : Sequence(int) pre: true post: true activity: ( return REPS(n)->collect( _x1 | (lambda i : OclAny in getInt())->apply(_x1) ) ); static operation getInt() : int pre: true post: true activity: ( return (s.getCurrent())->toInteger() ); static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := getInt() ; var p : Sequence(void) ; p := Integer.subrange(1,n)->collect(0) ; var l : int ; l := n * (n - 1) / 2 ; while l > 0 do ( ( var a : int ; a := getInt() - 1 ; var b : int ; b := getInt() - 1 ; var pa : int ; pa := getInt() ; var pb : int ; pb := getInt() ; if (pa > pb) then p[a+1] := p[a+1]+(3) ; else if (pa < pb) then p[b+1] := p[b+1]+(3) else ( p[a+1] := p[a+1] + 1 ; p[b+1] := p[b+1] + 1 ) ; ) ; l := l - 1 ) ; var c : int ; c := (0) ; var r : Sequence(int) ; r := Integer.subrange(1,n)->collect(0) ; for o : REPS(1, n).collect(Collectors.groupingBy(lambda i : OclAny in p[i - 1+1]))->asSet()->sort()->collect( _x1 | (lambda _pars : OclAny in Entry.newEntry().getValue(_pars))->apply(_x1) ) do ( skip) ; for _forEach : stream(r) do ( skip ;) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); KotoDistance solver=new KotoDistance(); solver.solve(1,in,out); out.close(); } static class KotoDistance { public void solve(int testNumber,Scanner in,PrintWriter out){ int N=in.nextInt(); int W=in.nextInt(); int H=in.nextInt(); int[] wimos=new int[W+10]; int[] himos=new int[H+10]; for(int i=0 ; itoInteger() ; var W : int ; W := in.getCurrent()->toInteger() ; var H : int ; H := in.getCurrent()->toInteger() ; var wimos : Sequence(int) ; wimos := Integer.subrange(1,W + 10)->collect(0) ; var himos : Sequence(int) ; himos := Integer.subrange(1,H + 10)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; var w : int ; w := in.getCurrent()->toInteger() ; wimos[Set{0, x - w}->max()+1] := wimos[Set{0, x - w}->max()+1] + 1 ; wimos[Set{W, x + w}->min()+1] := wimos[Set{W, x + w}->min()+1] - 1 ; himos[Set{0, y - w}->max()+1] := himos[Set{0, y - w}->max()+1] + 1 ; himos[Set{H, y + w}->min()+1] := himos[Set{H, y + w}->min()+1] - 1 ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= W + 1 do ( ( wimos[i+1] := wimos[i+1]+(wimos[i - 1+1]) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= H + 1 do ( ( himos[i+1] := himos[i+1]+(himos[i - 1+1]) ) ; i := i + 1 ) ; var wng : boolean ; wng := false ; var i : int ; i := 0 ; while i < W do ( ( wng := MathLib.bitwiseOr(wng, (wimos[i+1] = 0)) ) ; i := i + 1 ) ; var hng : boolean ; hng := false ; var i : int ; i := 0 ; while i < H do ( ( hng := MathLib.bitwiseOr(hng, (himos[i+1] = 0)) ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] pointArray=new int[100]; int[] rankArray=new int[100]; int numberOfTeams,maxNumber ; int a,b,aPoint,bPoint ; numberOfTeams=sc.nextInt(); maxNumber=numberOfTeams*(numberOfTeams-1)/2 ; for(int i=0 ; ibPoint){ pointArray[a]+=3 ; } else if(aPointcollect(0) ; var rankArray : Sequence(int) ; rankArray := Integer.subrange(1,100)->collect(0) ; var numberOfTeams : int ; var maxNumber : int ; var a : int ; var b : int ; var aPoint : int ; var bPoint : int ; numberOfTeams := sc.getCurrent()->toInteger() ; maxNumber := numberOfTeams * (numberOfTeams - 1) / 2 ; var i : int ; i := 0 ; while i < numberOfTeams do ( ( pointArray[i+1] := 0 ; rankArray[i+1] := 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < maxNumber do ( ( a := sc.getCurrent()->toInteger() - 1 ; b := sc.getCurrent()->toInteger() - 1 ; aPoint := sc.getCurrent()->toInteger() ; bPoint := sc.getCurrent()->toInteger() ; if (aPoint > bPoint) then ( pointArray[a+1] := pointArray[a+1]+(3) ) else if (aPoint < bPoint) then ( pointArray[b+1] := pointArray[b+1]+(3) ) else ( pointArray[a+1] := pointArray[a+1] + 1 ; pointArray[b+1] := pointArray[b+1] + 1 ) ; ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < numberOfTeams do ( ( var j : int ; j := 0 ; while j < numberOfTeams do ( ( if (pointArray[i+1] < pointArray[j+1]) then ( rankArray[i+1] := rankArray[i+1] + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < numberOfTeams do ( ( OclFile["System.out"].printf("%d\n", rankArray[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countNumbersWith4(int n){ if(n<4)return 0 ; int d=(int)Math.log10(n); int[] a=new int[d+2]; a[0]=0 ; a[1]=1 ; for(int i=2 ; i<=d ; i++)a[i]=a[i-1]*9+(int)Math.ceil(Math.pow(10,i-1)); int p=(int)Math.ceil(Math.pow(10,d)); int 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); } public static void main(String[] args){ int n=328 ; System.out.println("Count of numbers from 1 to "+n+" that have 4 as a digit is "+countNumbersWith4(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumbersWith4( n : int) : int pre: true post: true activity: ( if (n < 4) then return 0 else skip ; var d : int ; d := (n)->log10()->oclAsType(int) ; var a : Sequence(int) ; a := Integer.subrange(1,d + 2)->collect(0) ; a[0+1] := 0 ; a[1+1] := 1 ; var i : int ; i := 2 ; while i <= d do ( a[i+1] := a[i - 1+1] * 9 + (10->pow(i - 1))->ceil()->oclAsType(int) ; ; i := i + 1 ) ; var p : int ; p := (10->pow(d))->ceil()->oclAsType(int) ; var msd : int ; msd := n / 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) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 328 ; OclFile["System.out"].println("Count of numbers from 1 to " + n + " that have 4 as a digit is " + countNumbersWith4(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),k=sc.nextInt(); int x[]=new int[n]; int y[]=new int[n]; int cx[]=new int[n]; int cy[]=new int[n]; for(int i=0 ; i=k){ ans=Math.min(ans,(long)(x2-x1)*(y2-y1)); } } } } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,n)->collect(0) ; var cx : Sequence(int) ; cx := Integer.subrange(1,n)->collect(0) ; var cy : Sequence(int) ; cy := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := sc.getCurrent()->toInteger() ; y[i+1] := sc.getCurrent()->toInteger() ; cx[i+1] := x[i+1] ; cy[i+1] := y[i+1] ) ; i := i + 1 ) ; x := x->sort() ; y := y->sort() ; var ans : long ; ans := "9223372036854775807"->toLong() ; var lx : int ; lx := 0 ; while lx < n do ( ( var rx : int ; rx := lx + 1 ; while rx < n do ( ( var ly : int ; ly := 0 ; while ly < n do ( ( var ry : int ; ry := ly + 1 ; while ry < n do ( ( var x1 : int ; x1 := x[lx+1] ; var x2 : int ; x2 := x[rx+1] ; var y1 : int ; y1 := y[ly+1] ; var y2 : int ; y2 := y[ry+1] ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (x1 <= cx[i+1] & cx[i+1] <= x2 & y1 <= cy[i+1] & cy[i+1] <= y2) then ( cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; if (cnt >= k) then ( ans := Set{ans, (x2 - x1)->oclAsType(long) * (y2 - y1)}->min() ) else skip ; ) ; ry := ry + 1 ) ) ; ly := ly + 1 ) ) ; rx := rx + 1 ) ) ; lx := lx + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); Team[] teams=new Team[n]; for(int i=0 ; id)teams[a] .ten+=3 ; else if(c{ int name,ten ; public Team(int name,int ten){ super(); this.name=name ; this.ten=ten ; } @ Override public int compareTo(Team o){ return o.ten-ten ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var teams : Sequence(Team) ; teams := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( teams[i+1] := Team.newTeam(i, 0) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n * (n - 1) / 2 do ( ( var a : int ; a := scanner.getCurrent()->toInteger() - 1 ; var b : int ; b := scanner.getCurrent()->toInteger() - 1 ; var c : int ; c := scanner.getCurrent()->toInteger() ; var d : int ; d := scanner.getCurrent()->toInteger() ; if (c > d) then teams[a+1].ten := teams[a+1].ten+(3) else if (c < d) then teams[b+1].ten := teams[b+1].ten+(3) else ( teams[a+1].ten := teams[a+1].ten + 1 ; teams[b+1].ten := teams[b+1].ten + 1 ) ; ; ) ; i := i + 1 ) ; teams := teams->sort() ; var rank : Sequence(int) ; rank := Integer.subrange(1,n)->collect(0) ; rank[teams[0+1].name+1] := 1 ; var r : int ; r := 0 ; var i : int ; i := 1 ; while i < n do ( ( if (teams[i+1].ten = teams[i - 1+1].ten) then r := r + 1 else r := 0 ; ; rank[teams[i+1].name+1] := i - r + 1 ) ; i := i + 1 ) ; for (ans : rank) do ( OclFile["System.out"].println(ans) ; ) ; ); class Team implements Comparable { attribute name : int; static operation newTeam( name : int, ten : int) : Team pre: true post: true activity: ( var self : Team ; self := createTeam(); self.initialise(name, ten); return self ); operation initialise( name : int, ten : int) : void pre: true post: true activity: ( execute super() ; self.name := name ; self.ten := ten ); operation compareTo( o : Team) : int pre: true post: true activity: ( return o.ten - ten ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static Node head ; static class Node { int data ; Node next ; }; static Node push(Node head_ref,int new_data){ Node new_node=new Node(); new_node.data=new_data ; new_node.next=head_ref ; head_ref=new_node ; return head=head_ref ; } static int sumOfNodes(Node head){ Node ptr=head ; int sum=0 ; while(ptr!=null){ sum+=ptr.data ; ptr=ptr.next ; } return sum ; } public static void main(String[] args){ push(head,7); push(head,6); push(head,8); push(head,4); push(head,1); System.out.println("Sum of nodes="+sumOfNodes(head)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute head : Node; static class Node { attribute data : int; attribute next : Node; } static operation push( head_ref : Node, new_data : int) : Node pre: true post: true activity: ( var new_node : Node ; new_node := Node.newNode() ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; return head ); static operation sumOfNodes( head : Node) : int pre: true post: true activity: ( var ptr : Node ; ptr := head ; var sum : int ; sum := 0 ; while (ptr /= null) do ( sum := sum+(ptr.data) ; ptr := ptr.next ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute push(head, 7) ; execute push(head, 6) ; execute push(head, 8) ; execute push(head, 4) ; execute push(head, 1) ; OclFile["System.out"].println("Sum of nodes=" + sumOfNodes(head)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int sum=0 ; static class Node { int data ; Node next ; } static Node push(Node head_ref,int new_data){ Node new_node=new Node(); new_node.data=new_data ; new_node.next=(head_ref); (head_ref)=new_node ; return head_ref ; } static void sumOfNodes(Node head){ if(head==null)return ; sumOfNodes(head.next); sum=sum+head.data ; } static int sumOfNodesUtil(Node head){ sum=0 ; sumOfNodes(head); return sum ; } public static void main(String args[]){ Node head=null ; head=push(head,7); head=push(head,6); head=push(head,8); head=push(head,4); head=push(head,1); System.out.println("Sum of nodes="+sumOfNodesUtil(head)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute sum : int := 0; static class Node { attribute data : int; attribute next : Node; } static operation push( head_ref : Node, new_data : int) : Node pre: true post: true activity: ( var new_node : Node ; new_node := Node.newNode() ; new_node.data := new_data ; new_node.next := (head_ref) ; (head_ref) := new_node ; return head_ref ); static operation sumOfNodes( head : Node) : void pre: true post: true activity: ( if (head = null) then return else skip ; execute sumOfNodes(head.next) ; sum := sum + head.data ); static operation sumOfNodesUtil( head : Node) : int pre: true post: true activity: ( sum := 0 ; execute sumOfNodes(head) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var head : Node ; head := null ; head := push(head, 7) ; head := push(head, 6) ; head := push(head, 8) ; head := push(head, 4) ; head := push(head, 1) ; OclFile["System.out"].println("Sum of nodes=" + sumOfNodesUtil(head)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ (new Main()).solve(); } void solve(){ Scanner cin=new Scanner(System.in); int T=cin.nextInt(); for(int C=1 ; C<=T ; ++C){ int P=cin.nextInt(); int Q=cin.nextInt(); int N=cin.nextInt(); int HP[]=new int[N]; int GOLD[]=new int[N]; for(int i=0 ; itoInteger() ; var C : int ; C := 1 ; while C <= T do ( ( var P : int ; P := cin.getCurrent()->toInteger() ; var Q : int ; Q := cin.getCurrent()->toInteger() ; var N : int ; N := cin.getCurrent()->toInteger() ; var HP : Sequence(int) ; HP := Integer.subrange(1,N)->collect(0) ; var GOLD : Sequence(int) ; GOLD := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( HP[i+1] := cin.getCurrent()->toInteger() ; GOLD[i+1] := cin.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println("Case #" + C + ": " + solve(P, Q, HP, GOLD, N)) ; ) ; C := C + 1 ) ); operation solve( P : int, Q : int, HP : Sequence(int), GOLD : Sequence(int), N : int) : int pre: true post: true activity: ( var SIZE : int ; SIZE := N * 10 + 100 ; var score : Sequence(int) ; score := Integer.subrange(1,SIZE)->collect(0) ; score[1+1] := 1 ; var i : int ; i := 0 ; while i < N do ( ( var next : Sequence(int) ; next := Integer.subrange(1,SIZE)->collect(0) ; var turn : int ; turn := HP[i+1] / Q ; var rest : int ; rest := HP[i+1] - Q * turn ; if (rest = 0) then ( rest := Q ; turn := turn - 1 ) else skip ; var req : int ; req := (rest + P - 1) / P ; var j : int ; j := 0 ; while j < SIZE do ( ( if (score[j+1] = 0) then ( continue ) else skip ; var index : int ; index := j + turn + 1 ; next[index+1] := Set{next[index+1], score[j+1]}->max() ; if (req <= j + turn) then ( var index2 : int ; index2 := j + turn - req ; next[index2+1] := Set{next[index2+1], score[j+1] + GOLD[i+1]}->max() ) else skip ) ; j := j + 1 ) ; score := next ; ) ; i := i + 1 ) ; var ret : int ; ret := 0 ; var i : int ; i := 0 ; while i < SIZE do ( ( ret := Set{ret, score[i+1]}->max() ) ; i := i + 1 ) ; return ret - 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package round3 ; import java.io.FileInputStream ; import java.io.FileNotFoundException ; import java.io.FileOutputStream ; public class B { public static void main(String[] args)throws FileNotFoundException { Kattio io ; io=new Kattio(new FileInputStream("round3/B-large-0.in"),new FileOutputStream("round3/B-large-0.out")); int cases=io.getInt(); for(int i=1 ; i<=cases ; i++){ io.print("Case #"+i+": "); System.err.println(i); new B().solve(io); } io.close(); } int myPower,towerPower ; int health[],gold[]; private void solve(Kattio io){ myPower=io.getInt(); towerPower=io.getInt(); int n=io.getInt(); health=new int[n]; gold=new int[n]; for(int i=0 ; i0)return memo[monster][savedTurns]-1 ; int towerShots=(health[monster]+towerPower-1)/towerPower ; int best=go(monster+1,savedTurns+towerShots); int h=health[monster] % towerPower ; if(h==0)h=towerPower ; int shotsReq=(h+myPower-1)/myPower ; savedTurns+=towerShots-1 ; if(shotsReq<=savedTurns){ best=Math.max(best,gold[monster]+go(monster+1,savedTurns-shotsReq)); } memo[monster][orgSavedTurns]=best+1 ; return best ; } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : Kattio ; io := Kattio.newKattio(OclFile.newOclFile_Read(OclFile.newOclFile("round3/B-large-0.in")), OclFile.newOclFile_Write(OclFile.newOclFile("round3/B-large-0.out"))) ; var cases : int ; cases := io.getInt() ; var i : int ; i := 1 ; while i <= cases do ( ( io.print("Case #" + i + ": ") ; OclFile["System.err"].println(i) ; B.newB().solve(io) ) ; i := i + 1 ) ; io.close() ; ); attribute myPower : int; attribute health : int; operation solve( io : Kattio) : void pre: true post: true activity: ( myPower := io.getInt() ; towerPower := io.getInt() ; var n : int ; n := io.getInt() ; health := Integer.subrange(1,n)->collect(0) ; gold := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( health[i+1] := io.getInt() ; gold[i+1] := io.getInt() ) ; i := i + 1 ) ; memo := Integer.subrange(1,n)->collect(Integer.subrange(1,201 * n + 10)->collect(0)) ; io.println(go(0, 1)) ; ); attribute memo : Sequence(Sequence(int)); operation go( monster : int, savedTurns : int) : int pre: true post: true activity: ( if (monster = health->size()) then return 0 else skip ; var orgSavedTurns : int ; orgSavedTurns := savedTurns ; if (memo[monster+1][savedTurns+1] > 0) then return memo[monster+1][savedTurns+1] - 1 else skip ; var towerShots : int ; towerShots := (health[monster+1] + towerPower - 1) / towerPower ; var best : int ; best := go(monster + 1, savedTurns + towerShots) ; var h : int ; h := health[monster+1] mod towerPower ; if (h = 0) then h := towerPower ; else skip ; var shotsReq : int ; shotsReq := (h + myPower - 1) / myPower ; savedTurns := savedTurns+(towerShots - 1) ; if (shotsReq <= savedTurns) then ( best := Set{best, gold[monster+1] + go(monster + 1, savedTurns - shotsReq)}->max() ) else skip ; memo[monster+1][orgSavedTurns+1] := best + 1 ; return best ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; public class CountKSubStr { int countkDist(String str,int k){ int res=0 ; int n=str.length(); int cnt[]=new int[26]; for(int i=0 ; isize() ; var cnt : Sequence(int) ; cnt := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var dist_count : int ; dist_count := 0 ; cnt := cnt->collect(0) ; var j : int ; j := i ; while j < n do ( ( if (cnt[str->at(j+1) - ('a')->char2byte()+1] = 0) then dist_count := dist_count + 1 ; else skip ; cnt[str->at(j+1) - ('a')->char2byte()+1] := cnt[str->at(j+1) - ('a')->char2byte()+1] + 1 ; if (dist_count = k) then res := res + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ob : CountKSubStr ; ob := CountKSubStr.newCountKSubStr() ; var ch : String ; ch := "abcbaa" ; var k : int ; k := 3 ; OclFile["System.out"].println("Total substrings with exactly " + k + " distinct characters : " + ob.countkDist(ch, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Stack ; public class GFG { static boolean checkRedundancy(String s){ Stackst=new Stack<>(); char[] str=s.toCharArray(); for(char ch : str){ if(ch==')'){ char top=st.peek(); st.pop(); boolean flag=true ; while(top!='('){ if(top=='+' || top=='-' || top=='*' || top=='/'){ flag=false ; } top=st.peek(); st.pop(); } if(flag==true){ return true ; } } else { st.push(ch); } } return false ; } static void findRedundant(String str){ boolean ans=checkRedundancy(str); if(ans==true){ System.out.println("Yes"); } else { System.out.println("No"); } } public static void main(String[] args){ String str="((a+b))" ; findRedundant(str); str="(a+(b)/c)" ; findRedundant(str); str="(a+b*(c-d))" ; findRedundant(str); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkRedundancy( s : String) : boolean pre: true post: true activity: ( var st : Sequence(String) ; st := Sequence{} ; var str : Sequence(String) ; str := s->characters() ; for (ch : str) do ( ( if (ch = ')') then ( var top : String ; top := st->min() ; st := st->front() ; var flag : boolean ; flag := true ; while (top /= '(') do ( if (top = '+' or top = '-' or top = '*' or top = '/') then ( flag := false ) else skip ; top := st->min() ; st := st->front() ) ; if (flag = true) then ( return true ) else skip ; ) else ( st := st->append(ch) ) ) ) ; return false ); static operation findRedundant( str : String) : void pre: true post: true activity: ( var ans : boolean ; ans := checkRedundancy(str) ; if (ans = true) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "((a+b))" ; execute findRedundant(str) ; str := "(a+(b)/c)" ; execute findRedundant(str) ; str := "(a+b*(c-d))" ; execute findRedundant(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int binarySearch(int[] searchSpace,int s,int e,int num){ int ans=0 ; while(s<=e){ int mid=(s+e)/2 ; if(searchSpace[mid]>=num){ ans=mid ; e=mid-1 ; } else s=mid+1 ; } return ans ; } static int longestSubArr(int[] arr,int n){ int[] searchSpace=new int[n]; int[] index=new int[n]; int j=0 ; int ans=0 ; for(int i=0 ; i= num) then ( ans := mid ; e := mid - 1 ) else s := mid + 1 ; ) ; return ans ); static operation longestSubArr( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var searchSpace : Sequence(int) ; searchSpace := Integer.subrange(1,n)->collect(0) ; var index : Sequence(int) ; index := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (j = 0 or searchSpace[j - 1+1] < arr[i+1]) then ( searchSpace[j+1] := arr[i+1] ; index[j+1] := i ; j := j + 1 ) else skip ; var idx : int ; idx := binarySearch(searchSpace, 0, j - 1, arr[i+1]) ; ans := Set{ans, i - index[idx+1] + 1}->max() ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-5,-1,7,5,1,-2} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(longestSubArr(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int solveEven(String s){ if(s.length()% 2==1){ return 2 ; } String ls=s.substring(0,s.length()/2); String rs=s.substring(s.length()/2,s.length()); if(ls!=rs){ return 1 ; } return solveEven(ls); } static int solveOdd(String s){ return 2 ; } static int solve(String s){ if(s.length()<=3){ return-1 ; } int cnt[]=new int[25]; for(int i=0 ; i=s.length()-1){ return-1 ; } if(s.length()% 2==0){ return solveEven(s); } if(s.length()% 2==1){ return solveOdd(s); } return Integer.MIN_VALUE ; } public static void main(String[] args){ String s="nolon" ; System.out.println(solve(s)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solveEven( s : String) : int pre: true post: true activity: ( if (s->size() mod 2 = 1) then ( return 2 ) else skip ; var ls : String ; ls := s.subrange(0+1,s->size() / 2) ; var rs : String ; rs := s.subrange(s->size() / 2+1,s->size()) ; if (ls /= rs) then ( return 1 ) else skip ; return solveEven(ls) ); static operation solveOdd( s : String) : int pre: true post: true activity: ( return 2 ); static operation solve( s : String) : int pre: true post: true activity: ( if (s->size() <= 3) then ( return -1 ) else skip ; var cnt : Sequence(int) ; cnt := Integer.subrange(1,25)->collect(0) ; var i : int ; i := 0 ; while i < s->size() do ( ( cnt[s->at(i+1) - ('a')->char2byte()+1] := cnt[s->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; if (stream(cnt).max().getAsInt() >= s->size() - 1) 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 ; return -2147483648 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "nolon" ; OclFile["System.out"].println(solve(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,w,h,i,j,x,y,p ; int[] fw,fh ; n=sc.nextInt(); w=sc.nextInt(); h=sc.nextInt(); fw=new int[w]; fh=new int[h]; j=0 ; for(; n-->0 ; ){ x=sc.nextInt(); y=sc.nextInt(); p=sc.nextInt(); if(x-p<0)fw[0]++; else fw[x-p]++; if(y-p<0)fh[0]++; else fh[y-p]++; if(x+pcollect(0) ; fh := Integer.subrange(1,h)->collect(0) ; j := 0 ; while n > 0 do ( ( x := sc.nextInt() ; y := sc.nextInt() ; p := sc.nextInt() ; if (x - p < 0) then fw[0+1] := fw[0+1] + 1 else fw[x - p+1] := fw[x - p+1] + 1 ; ; if (y - p < 0) then fh[0+1] := fh[0+1] + 1 else fh[y - p+1] := fh[y - p+1] + 1 ; ; if (x + p < w) then fw[x + p+1] := fw[x + p+1] - 1 ; else skip ; if (y + p < h) then fh[y + p+1] := fh[y + p+1] - 1 ; else skip ; ) ) ; i := 1 ; while i < w do ( fw[i+1] := fw[i+1]+(fw[i - 1+1]) ; ; i := i + 1 ) ; i := 1 ; while i < h do ( fh[i+1] := fh[i+1]+(fh[i - 1+1]) ; ; i := i + 1 ) ; i := 0 ; while i < w do ( if (fw[i+1] <= 0) then break else skip ; ; i := i + 1 ) ; j := 0 ; while j < h do ( if (fh[j+1] <= 0) then break else skip ; ; j := j + 1 ) ; if (i = w or j = h) then out.println("Yes") else out.println("No") ; ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int N=scn.nextInt(),K=scn.nextInt(); long[] NCK=new long[N-K+1]; NCK[0]=1 ; long A[]=new long[N]; long MOD=1000000007 ; long min=0 ; long max=0 ; for(int i=0 ; i0){ long t=a/b ; a-=t*b ; buf=a ; a=b ; b=buf ; u-=t*v ; buf=u ; u=v ; v=buf ; } u %=mod ; if(u<0)u+=mod ; return u ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scn.getCurrent()->toInteger() ; var K : int ; K := scn.getCurrent()->toInteger() ; var NCK : Sequence(long) ; NCK := Integer.subrange(1,N - K + 1)->collect(0) ; NCK[0+1] := 1 ; var A : Sequence(long) ; A := Integer.subrange(1,N)->collect(0) ; var MOD : long ; MOD := 1000000007 ; var min : long ; min := 0 ; var max : long ; max := 0 ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := scn.getCurrent()->toLong() ) ; i := i + 1 ) ; A := A->sort() ; var i : int ; i := 1 ; while i < N - K + 1 do ( ( NCK[i+1] := NCK[i - 1+1] * (K + i - 1) ; NCK[i+1] := NCK[i+1] mod MOD ; NCK[i+1] := NCK[i+1]*(modinv(i, MOD)) ; NCK[i+1] := NCK[i+1] mod MOD ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - K + 1 do ( ( min := min+(A[i+1] * NCK[N - K - i+1]) ; min := min mod MOD ; max := max+(A[N - 1 - i+1] * NCK[N - K - i+1]) ; max := max mod MOD ) ; i := i + 1 ) ; var ans : long ; ans := max - min ; ans := ans mod MOD ; ans := ans+(MOD) ; ans := ans mod MOD ; OclFile["System.out"].println(ans) ; ); static operation modinv( a : long, mod : long) : long pre: true post: true activity: ( var b : long ; b := mod ; var u : long ; u := 1 ; var v : long ; v := 0 ; var buf : long ; buf := 0 ; while (b > 0) do ( var t : long ; t := a / b ; a := a-(t * b) ; buf := a ; a := b ; b := buf ; u := u-(t * v) ; buf := u ; u := v ; v := buf ; ) ; u := u mod mod ; if (u < 0) then u := u+(mod) ; else skip ; return u ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void find_set(int n){ if(n<=2){ System.out.println("-1"); return ; } int sum1=(n*(n-1))/2 ; int sum2=n ; System.out.println(sum1+" "+sum2); } public static void main(String[] args){ int n=8 ; find_set(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation find_set( n : int) : void pre: true post: true activity: ( if (n <= 2) then ( OclFile["System.out"].println("-1") ; return ) else skip ; var sum1 : int ; sum1 := (n * (n - 1)) / 2 ; var sum2 : int ; sum2 := n ; OclFile["System.out"].println(sum1 + " " + sum2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 8 ; execute find_set(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String replaceRemove(char[] s,char X,char Y,char Z){ int start=0,end=s.length-1 ; while(start<=end){ if(s[start]==Z){ while(end>=0 && s[end]==Z){ end--; } char temp ; if(end>start){ temp=s[start]; s[start]=s[end]; s[end]=temp ; if(s[start]==X)s[start]=Y ; start++; } } else { if(s[start]==X)s[start]=Y ; start++; } } String new_s=new String(s); while(new_s.length()>0 && new_s.charAt(new_s.length()-1)==Z){ new_s=new_s.substring(0,new_s.length()-1); } return new_s ; } public static void main(String[] args){ String str="batman" ; char X='a',Y='d',Z='b' ; str=replaceRemove(str.toCharArray(),X,Y,Z); if(str.length()==0){ System.out.println(-1); } else { System.out.println(str); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation replaceRemove( s : Sequence(String), X : String, Y : String, Z : String) : String pre: true post: true activity: ( var start : int ; start := 0 ; var end : int ; end := s->size() - 1 ; while (start <= end) do ( if (s[start+1] = Z) then ( while (end >= 0 & s[end+1] = Z) do ( end := end - 1 ) ; var temp : String ; if (end > start) then ( temp := s[start+1] ; s[start+1] := s[end+1] ; s[end+1] := temp ; 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 ) ) ; var new_s : String ; new_s := StringLib.newString(s) ; while (new_s->size() > 0 & new_s->at(new_s->size() - 1+1) = Z) do ( new_s := new_s.subrange(0+1,new_s->size() - 1) ) ; return new_s ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "batman" ; var X : String ; X := 'a' ; var Y : String ; Y := 'd' ; var Z : String ; Z := 'b' ; str := replaceRemove(str->characters(), X, Y, Z) ; if (str->size() = 0) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(str) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static boolean check(int n,int k,int[] a,int[] b){ Arrays.sort(a); Arrays.sort(b); boolean fl=false ; int ind=-1 ; for(int i=0 ; isort() ; b := b->sort() ; var fl : boolean ; fl := false ; var ind : int ; ind := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] /= b[i+1]) then ( if (fl = true) then ( return false ) else skip ; fl := true ; ind := i ) else skip ) ; i := i + 1 ) ; if (ind = -1 or if a[ind+1] - b[ind+1] < 0 then -(a[ind+1] - b[ind+1]) else a[ind+1] - b[ind+1] endif <= k) then ( return true ) else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; var k : int ; k := 4 ; var a : Sequence(int) ; a := Sequence{1,5} ; var b : Sequence(int) ; b := Sequence{1,1} ; if (check(n, k, a, b)) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.*; import java.util.Arrays ; class GFG { static int findMaxNum(int arr[],int n){ Arrays.sort(arr); int num=arr[0]; for(int i=n-1 ; i>=0 ; i--){ num=num*10+arr[i]; } return num ; } public static void main(String[] args){ int arr[]={ 1,2,3,4,5,0 }; int n=arr.length ; System.out.println(findMaxNum(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findMaxNum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( arr := arr->sort() ; var num : int ; num := arr[0+1] ; var i : int ; i := n - 1 ; while i >= 0 do ( ( num := num * 10 + arr[i+1] ) ; i := i - 1 ) ; return num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5,0} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findMaxNum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc ; void run(){ for(; ; ){ int n=ni(); int m=ni(); if((n | m)==0){ break ; } int[] h=new int[n]; int[] w=new int[m]; for(int i=0 ; icollect(0) ; var w : Sequence(int) ; w := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( h[i+1] := ni() ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < m do ( ( w[j+1] := ni() ) ; j := j + 1 ) ; var W : Sequence(int) ; W := Integer.subrange(1,1500 * 1000 + 1)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( var sum : int ; sum := 0 ; var j : int ; j := i ; while j < m do ( ( sum := sum+(w[j+1]) ; W[sum+1] := W[sum+1] + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var sum : int ; sum := 0 ; var j : int ; j := i ; while j < n do ( ( sum := sum+(h[j+1]) ; ans := ans+(W[sum+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ) ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ); operation ni() : int pre: true post: true activity: ( return sc.getCurrent()->toInteger() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Math.*; public class Main { int INF=1<<28 ; double EPS=1e-10 ; void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int n=sc.nextInt(),m=sc.nextInt(); if((n | m)==0)break ; int h[]=new int[n+1],w[]=new int[m+1]; for(int i=0 ; ipow(28)))->oclAsType(long); attribute EPS : double := 1e-10; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then break else skip ; var h : Sequence(int) ; h := Integer.subrange(1,n + 1)->collect(0) ; var w : Sequence(void) ; w := Integer.subrange(1,m + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( h[i + 1+1] := sc.getCurrent()->toInteger() + h[i+1] ; ; i := i + 1 ) ; var j : int ; j := 0 ; while j < m do ( w[j + 1+1] := sc.getCurrent()->toInteger() + w[j+1] ; ; j := j + 1 ) ; var len : Sequence(int) ; len := Integer.subrange(1,1500 * 1000 + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := i + 1 ; while j <= n do ( len[h[j+1] - h[i+1]+1] := len[h[j+1] - h[i+1]+1] + 1 ; ; j := j + 1 ) ; ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < m do ( var j : int ; j := i + 1 ; while j <= m do ( cnt := cnt+(len[w[j+1] - w[i+1]+1]) ; ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ) ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(true){ int[] n=new int[2]; @ SuppressWarnings("unchecked")MultiSet[] set=new MultiSet[2]; for(int i=0 ; i<2 ; i++){ n[i]=in.nextInt(); set[i]=new MultiSet(); } if(n[0]==0 && n[1]==0)break ; for(int i=0 ; i<2 ; i++){ int[] w=new int[n[i] ]; for(int j=0 ; j{ HashMapset ; public MultiSet(){ set=new HashMap(); } public void add(T val){ if(set.containsKey(val)){ set.put(val,set.get(val)+1); } else { set.put(val,1); } } public int get(T val){ if(set.containsKey(val))return set.get(val); return 0 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : Sequence(int) ; n := Integer.subrange(1,2)->collect(0) ; var set : Sequence(MultiSet) ; set := Integer.subrange(1,2)->collect(null) ; var i : int ; i := 0 ; while i < 2 do ( ( n[i+1] := in.getCurrent()->toInteger() ; set[i+1] := MultiSet.newMultiSet() ) ; i := i + 1 ) ; if (n[0+1] = 0 & n[1+1] = 0) then break else skip ; var i : int ; i := 0 ; while i < 2 do ( ( var w : Sequence(int) ; w := Integer.subrange(1,n[i+1])->collect(0) ; var j : int ; j := 0 ; while j < n[i+1] do ( ( w[j+1] := in.getCurrent()->toInteger() ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n[i+1] do ( ( var sum : int ; sum := 0 ; var k : int ; k := j ; while k < n[i+1] do ( ( sum := sum+(w[k+1]) ; set[i+1]->excludes(sum) ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var res : long ; res := 0 ; for (i : set[0+1].set.keySet()) do ( ( if (set[1+1].set.containsKey(i)) then ( res := res+(set[0+1]->at(i+1) * set[1+1]->at(i+1)) ) else skip ) ) ; OclFile["System.out"].println(res) ; ) ); } class MultiSet { attribute set : Map(T,int); static operation newMultiSet() : MultiSet pre: true post: true activity: ( var self : MultiSet ; self := createMultiSet(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( set := Map{} ); operation add( val : T) : void pre: true post: true activity: ( if (set->keys()->includes(val)) then ( set := set->union(Map{val |-> set->at(val) + 1}) ) else ( set := set->union(Map{val |-> 1}) ) ); operation get( val : T) : int pre: true post: true activity: ( if (set->keys()->includes(val)) then return set->at(val) else skip ; return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileInputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintStream ; import java.util.Scanner ; public class Main { static int n,m ; static int[] h,w ; private static int check(int sx,int sy){ int x=sx ; int y=sy ; int count=0 ; int width=w[sx]; int height=h[sy]; while(true){ if(width==height){ count++; x++; if(x>=m)return count ; width+=w[x]; } else if(width=m)return count ; width+=w[x]; } else { y++; if(y>=n)return count ; height+=h[y]; } } } public static void main(String[] args){ Scanner sca=new Scanner(System.in); while(true){ n=sca.nextInt(); m=sca.nextInt(); if(n==0)break ; int i,j,k ; h=new int[n]; for(i=0 ; i= m) then return count else skip ; width := width+(w[x+1]) ) else if (width < height) then ( x := x + 1 ; if (x >= m) then return count else skip ; width := width+(w[x+1]) ) else ( y := y + 1 ; if (y >= n) then return count else skip ; height := height+(h[y+1]) ) ; ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sca : OclFile ; sca := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( n := sca.getCurrent()->toInteger() ; m := sca.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var i : int ; var j : int ; var k : int ; h := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < n do ( h[i+1] := sca.getCurrent()->toInteger() ; ; i := i + 1 ) ; w := Integer.subrange(1,m)->collect(0) ; i := 0 ; while i < m do ( w[i+1] := sca.getCurrent()->toInteger() ; ; i := i + 1 ) ; var count : int ; count := 0 ; var x : int ; var y : int ; y := 0 ; while y < n do ( ( x := 0 ; while x < m do ( ( count := count+(check(x, y)) ) ; x := x + 1 ) ) ; y := y + 1 ) ; OclFile["System.out"].println(count) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A1450 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < T do ( ( skip ; var S : Sequence(String) ; S := in.getCurrent()->characters() ; S := S->sort() ; OclFile["System.out"].println(StringLib.newString(S)) ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static final int MOD=1000000007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; var cmb : Combination ; cmb := Combination.newCombination(n + 1) ; var pSum : long ; pSum := 0 ; var mSum : long ; mSum := 0 ; var i : int ; i := 0 ; while i <= n - k do ( ( var count : long ; count := cmb.getComb(n - i - 1, k - 1) ; mSum := mSum+((arr[i+1] + MOD) mod MOD * count mod MOD) ; mSum := mSum mod MOD ; pSum := pSum+((arr[n - i - 1+1] + MOD) mod MOD * count mod MOD) ; pSum := pSum mod MOD ; ) ; i := i + 1 ) ; OclFile["System.out"].println((pSum - mSum + MOD) mod MOD) ; ); } class Combination { static attribute MOD : int := 1000000007; attribute fac : Sequence(long); attribute finv : Sequence(long); attribute inv : Sequence(long); static operation newCombination( size : int) : Combination pre: true post: true activity: ( var self : Combination ; self := createCombination(); self.initialise(size); return self ); operation initialise( size : int) : void pre: true post: true activity: ( fac := Integer.subrange(1,size)->collect(0) ; finv := Integer.subrange(1,size)->collect(0) ; inv := Integer.subrange(1,size)->collect(0) ; fac[0+1] := 1 ; fac[1+1] := 1 ; finv[0+1] := 1 ; finv[1+1] := 1 ; inv[1+1] := 1 ; var i : int ; i := 2 ; while i < size do ( ( fac[i+1] := fac[i - 1+1] * i mod MOD ; inv[i+1] := MOD - inv[MOD mod i+1] * (MOD / i) mod MOD ; finv[i+1] := finv[i - 1+1] * inv[i+1] mod MOD ) ; i := i + 1 ) ; ); operation getComb( n : int, k : int) : long pre: true post: true activity: ( if (n < k or 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 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.BigDecimal ; import java.awt.geom.*; import static java.util.Arrays.*; class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=Integer.parseInt(stdIn.next()); int W=Integer.parseInt(stdIn.next()); int H=Integer.parseInt(stdIn.next()); int x=0 ; int y=0 ; int w=0 ; int[] width=new int[W+1]; int[] height=new int[H+1]; boolean flag=false ; for(int i=0 ; itoInteger() ; var W : int ; W := (stdIn.getCurrent())->toInteger() ; var H : int ; H := (stdIn.getCurrent())->toInteger() ; var x : int ; x := 0 ; var y : int ; y := 0 ; var w : int ; w := 0 ; var width : Sequence(int) ; width := Integer.subrange(1,W + 1)->collect(0) ; var height : Sequence(int) ; height := Integer.subrange(1,H + 1)->collect(0) ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < n do ( ( x := (stdIn.getCurrent())->toInteger() ; y := (stdIn.getCurrent())->toInteger() ; w := (stdIn.getCurrent())->toInteger() ; var flag1 : boolean ; flag1 := false ; var flag2 : boolean ; flag2 := false ; var lx : int ; lx := Set{0, x - w}->max() ; var hx : int ; hx := Set{W, x + w}->min() ; var ly : int ; ly := Set{0, y - w}->max() ; var hy : int ; hy := Set{H, y + w}->min() ; width[lx+1] := width[lx+1] + 1 ; width[hx+1] := width[hx+1] - 1 ; height[ly+1] := height[ly+1] + 1 ; height[hy+1] := height[hy+1] - 1 ; ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < W do ( ( count := count+(width[i+1]) ; if (count <= 0) then ( flag := true ) else skip ) ; i := i + 1 ) ; count := 0 ; var i : int ; i := 0 ; while i < H do ( ( count := count+(height[i+1]) ; if (count <= 0 & flag) then ( skip ; skip ; return ) else skip ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Arrays ; public class ProblemG12A { public static void main(String[] args)throws Exception { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); PrintWriter writer=new PrintWriter(System.out); int t=Integer.parseInt(reader.readLine()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := (reader.readLine())->toInteger() ; var line : String ; line := reader.readLine() ; var array : Sequence(String) ; array := line->characters() ; array := array->sort() ; var j : int ; j := 0 ; while j < n do ( ( skip ) ; j := j + 1 ) ; skip ; ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class HelloWorld { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); String s=sc.next(); StringBuilder ans=new StringBuilder(); int c=0 ; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var ans : String ; ans := StringLib.newString() ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < n do ( ( var ch : String ; ch := s->at(i+1) ; if (ch /= 't') then ( ans := ans + StringLib.newString(ch) ) else c := c + 1 ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < c do ( ans := ans + StringLib.newString('t') ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Test { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); String str=sc.next(); int rIndices=0 ; String ans="" ; for(int i=0 ; i0){ ans="r"+ans ; } System.out.println(ans); } } } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var str : String ; str := sc.getCurrent() ; var rIndices : int ; rIndices := 0 ; var ans : String ; ans := "" ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = 'r') then rIndices := rIndices+(1) ; else ans := ans+("" + str->at(i+1)) ; ) ; i := i + 1 ) ; while (rIndices > 0) do ( rIndices := rIndices - 1 ; skip ; ( ans := "r" + ans ) ; ) ; OclFile["System.out"].println(ans) ; ) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class BuySweets { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),s=sc.nextInt(); Listxi=new ArrayList<>(); Listyi=new ArrayList<>(); for(int i=0 ; itoInteger() ; var s : int ; s := sc.getCurrent()->toInteger() ; var xi : Sequence(int) ; xi := Sequence{} ; var yi : Sequence(int) ; yi := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( xi := xi->including(sc.getCurrent()->toInteger()) ; yi := yi->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var ans : int ; ans := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (xi->at(i+1) < s & yi->at(i+1) /= 0) then ( ans := Set{ans, 100 - yi->at(i+1)}->max() ) else skip ; if (xi->at(i+1) <= s & yi->at(i+1) = 0) then ( ans := Set{ans, 0}->max() ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class Cf { public static void main(String[] args)throws FileNotFoundException { FastReader in=new FastReader(); PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); int n=in.nextInt(); int s=in.nextInt(); int min=100 ; boolean f=false ; for(int i=0 ; imin() ; f := true ) else if ((x <= s) & (y = 0)) then ( f := true ) else skip ; ) ; i := i + 1 ) ; if (min = 100 & not(f)) then skip else if (min = 100) then skip else skip ; ; ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(if OclProcess.getEnvironmentProperty("ONLINE_JUDGE") = null then OclFile.newOclFile_Read(OclFile.newOclFile("input.txt")) else OclFile["System.in"] endif)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; import java.io.*; public class Hello { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),money=in.nextInt(); Mapmap=new HashMap<>(); for(int i=0 ; itoInteger() ; var money : int ; money := in.getCurrent()->toInteger() ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; var total : int ; total := x * 100 + y ; if (total <= (money * 100)) then ( var sub : int ; sub := 100 - y ; if (sub <= 99) then ( if (not(map->keys()->includes(x))) then ( map := map->union(Map{x |-> sub}) ) else ( map := map->union(Map{x |-> Set{map->at(x), sub}->max()}) ) ) else ( map := map->union(Map{x |-> 0}) ) ) else skip ) ; i := i + 1 ) ; if (map.size() = 0) then ( skip ) else ( var ans : int ; ans := 0 ; for (i : map->values()) do ( ( ans := Set{ans, i}->max() ) ) ; skip ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Asphalting { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int[] h=new int[n+1]; int[] v=new int[n+1]; String res="" ; for(int i=1 ; i<=n*n ; i++){ int ho=scanner.nextInt(); int ve=scanner.nextInt(); if(h[ho]==0 && v[ve]==0){ h[ho]=1 ; v[ve]=1 ; res+=i+" " ; } } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Asphalting { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n + 1)->collect(0) ; var v : Sequence(int) ; v := Integer.subrange(1,n + 1)->collect(0) ; var res : String ; res := "" ; var i : int ; i := 1 ; while i <= n * n do ( ( var ho : int ; ho := scanner.getCurrent()->toInteger() ; var ve : int ; ve := scanner.getCurrent()->toInteger() ; if (h[ho+1] = 0 & v[ve+1] = 0) then ( h[ho+1] := 1 ; v[ve+1] := 1 ; res := res+(i + " ") ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeSet ; public class road { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Sets1=new TreeSet<>(); Sets2=new TreeSet<>(); for(int i=0 ; itoInteger() ; var s1 : Set(int) ; s1 := Set{} ; var s2 : Set(int) ; s2 := Set{} ; var i : int ; i := 0 ; while i < n * n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if ((not(s1->includes(x))) & (not(s2->includes(y)))) then ( OclFile["System.out"].print(i + 1 + " ") ; s1 := s1->including(x) ; s2 := s2->including(y) ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class AsphaltingRoads { public static void main(String[] args)throws FileNotFoundException { FastReader in=new FastReader(); PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); int n=in.nextInt(); boolean[] row=new boolean[51]; boolean[] col=new boolean[51]; for(int i=0 ; icollect(false) ; var col : Sequence(boolean) ; col := Integer.subrange(1,51)->collect(false) ; var i : int ; i := 0 ; while i < n * n do ( ( var x : int ; x := in.nextInt() ; var y : int ; y := in.nextInt() ; if (not(row[x+1]) & not(col[y+1])) then ( row[x+1] := true ; col[y+1] := true ; skip ) else skip ) ; i := i + 1 ) ; skip ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(if OclProcess.getEnvironmentProperty("ONLINE_JUDGE") = null then OclFile.newOclFile_Read(OclFile.newOclFile("input.txt")) else OclFile["System.in"] endif)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int k=scanner.nextInt(); int[] a=new int[n]; for(int i=0 ; i=k-1 ; i++){ temp=(int)((long)(a[n-1-i]-a[i])*comb(n-1-i,k-1)% MOD); result=(result+temp)% MOD ; } while(result<0)result+=MOD ; System.out.println(result); } static final int MOD=1000000007 ; static final int FACT_MAX=100000 ; static int[] FACT=new int[FACT_MAX+1]; static { FACT[0]=1 ; for(int i=1 ; i<=FACT_MAX ; i++){ FACT[i]=(int)((long)FACT[i-1]*i % MOD); } } static int comb(int n,int k){ return(int)((long)FACT[n]*inverse((int)((long)FACT[k]*FACT[n-k] % MOD))% MOD); } static int inverse(int denom){ return power(denom,MOD-2); } static int power(int b,int p){ long res=1 ; for(long a=b % MOD ; p>0 ; a=a*a % MOD,p>>=1)if((p & 1)>0)res=res*a % MOD ; return(int)res ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var result : int ; result := 0 ; var temp : int ; var i : int ; i := 0 ; while n - 1 - i >= k - 1 do ( ( temp := ((a[n - 1 - i+1] - a[i+1])->oclAsType(long) * comb(n - 1 - i, k - 1) mod MOD)->oclAsType(int) ; result := (result + temp) mod MOD ) ; i := i + 1 ) ; while (result < 0) do result := result+(MOD) ; ; OclFile["System.out"].println(result) ; ); static attribute MOD : int := 1000000007; static attribute FACT_MAX : int := 100000; static attribute FACT : Sequence(int) := Integer.subrange(1,FACT_MAX + 1)->collect(0); static operation initialiseClass() pre: true post: true activity: FACT[0+1] := 1 ; var i : int ; i := 1 ; while i <= FACT_MAX do ( ( FACT[i+1] := (FACT[i - 1+1]->oclAsType(long) * i mod MOD)->oclAsType(int) ) ; i := i + 1 ) ; ; static operation comb( n : int, k : int) : int pre: true post: true activity: ( return (FACT[n+1]->oclAsType(long) * inverse((FACT[k+1]->oclAsType(long) * FACT[n - k+1] mod MOD)->oclAsType(int)) mod MOD)->oclAsType(int) ); static operation inverse( denom : int) : int pre: true post: true activity: ( return power(denom, MOD - 2) ); static operation power( b : int, p : int) : int pre: true post: true activity: ( var res : long ; res := 1 ; var a : long ; a := b mod MOD ; while p > 0 do ( if ((p & 1) > 0) then res := res * a mod MOD ; else skip ; ; a := a * a mod MOD ; p := p/(2->pow(1)) ) ; return res->oclAsType(int) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long m=sc.nextLong(); for(long i=0 ; itoLong() ; var i : long ; i := 0 ; while i < m do ( ( var money : long ; money := sc.getCurrent()->toLong() ; var year : long ; year := sc.getCurrent()->toLong() ; var n : long ; n := sc.getCurrent()->toLong() ; var max : long ; max := 0 ; var j : long ; j := 0 ; while j < n do ( ( var way : long ; way := sc.getCurrent()->toLong() ; var p : double ; p := sc.getCurrent()->toReal() ; var cost : long ; cost := sc.getCurrent()->toLong() ; var currentMoney : long ; currentMoney := money ; if (way = 0) then ( var sum : long ; sum := 0 ; var k : long ; k := 0 ; while k < year do ( ( sum := sum+(currentMoney * p) ; currentMoney := currentMoney-(cost) ) ; k := k + 1 ) ; max := Set{max, currentMoney + sum}->max() ) else ( var k : long ; k := 0 ; while k < year do ( ( currentMoney := currentMoney+(currentMoney * p - cost) ) ; k := k + 1 ) ; max := Set{max, currentMoney}->max() ) ; ) ; j := j + 1 ) ; OclFile["System.out"].println(max) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; words=br.readLine().split(" "); int N,W,H ; N=parseInt(words[0]); W=parseInt(words[1]); H=parseInt(words[2]); int[] xs=new int[W]; int[] ys=new int[H]; for(int i=0 ; isplit(" ") ; var N : int ; var W : int ; var H : int ; N := (words[0+1] + "")->toInteger() ; W := (words[1+1] + "")->toInteger() ; H := (words[2+1] + "")->toInteger() ; var xs : Sequence(int) ; xs := Integer.subrange(1,W)->collect(0) ; var ys : Sequence(int) ; ys := Integer.subrange(1,H)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( words := br.readLine()->split(" ") ; var x : int ; var y : int ; var w : int ; x := (words[0+1] + "")->toInteger() ; y := (words[1+1] + "")->toInteger() ; w := (words[2+1] + "")->toInteger() ; if (0 <= x - w) then ( xs[x - w+1] := xs[x - w+1] + 1 ) else ( xs[0+1] := xs[0+1] + 1 ) ; if (x + w < W) then ( xs[x + w+1] := xs[x + w+1] - 1 ) else skip ; if (0 <= y - w) then ( ys[y - w+1] := ys[y - w+1] + 1 ) else ( ys[0+1] := ys[0+1] + 1 ) ; if (y + w < H) then ( ys[y + w+1] := ys[y + w+1] - 1 ) else skip ; ) ; i := i + 1 ) ; var fillW : boolean ; fillW := true ; var fillH : boolean ; fillH := true ; var i : int ; i := 0 ; while i < xs->size() do ( ( if (0 < i) then ( xs[i+1] := xs[i+1]+(xs[i - 1+1]) ) else skip ; if (xs[i+1] = 0) then ( fillW := false ; break ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < ys->size() do ( ( if (0 < i) then ( ys[i+1] := ys[i+1]+(ys[i - 1+1]) ) else skip ; if (ys[i+1] = 0) then ( fillH := false ; break ) else skip ) ; i := i + 1 ) ; if (MathLib.bitwiseOr(fillW,fillH)) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); for(int i=0 ; imaxResult){ maxResult=result ; } } System.out.println(maxResult); } } private static int calcFukuri(int money0,int year,double ratio,int fee){ for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var money0 : int ; money0 := (br.readLine())->toInteger() ; var year : int ; year := (br.readLine())->toInteger() ; var numOfMethod : int ; numOfMethod := (br.readLine())->toInteger() ; var maxResult : int ; maxResult := -1 ; var j : int ; j := 0 ; while j < numOfMethod do ( ( var tmpStr : Sequence(String) ; tmpStr := br.readLine()->split(" ") ; var method : int ; method := (tmpStr[0+1])->toInteger() ; var ratio : double ; ratio := (tmpStr[1+1])->toReal() ; var fee : int ; fee := (tmpStr[2+1])->toInteger() ; var result : int ; result := 0 ; if (method = 0) then ( result := calcTanri(money0, year, ratio, fee) ) else if (method = 1) then ( result := calcFukuri(money0, year, ratio, fee) ) else skip ; ; if (result > maxResult) then ( maxResult := result ) else skip ; ) ; j := j + 1 ) ; OclFile["System.out"].println(maxResult) ; ) ; i := i + 1 ) ); static operation calcFukuri( money0 : int, year : int, ratio : double, fee : int) : int pre: true post: true activity: ( var i : int ; i := 0 ; while i < year do ( ( money0 := money0*((1 + ratio)) ; money0 := money0-(fee) ) ; i := i + 1 ) ; return money0 ); static operation calcTanri( money0 : int, year : int, ratio : double, fee : int) : int pre: true post: true activity: ( var rishiSum : int ; rishiSum := 0 ; var i : int ; i := 0 ; while i < year do ( ( rishiSum := rishiSum+(money0 * ratio) ; money0 := money0-(fee) ) ; i := i + 1 ) ; return money0 + rishiSum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int m=sc.nextInt(); while(m!=0){ int money=sc.nextInt(); int year=sc.nextInt(); int type=sc.nextInt(); int finalAns=0 ; while(type!=0){ int tanri=sc.nextInt(); double rate=sc.nextDouble(); int tesu=sc.nextInt(); int ans=solve(money,year,tanri,rate,tesu); if(ans>finalAns)finalAns=ans ; type--; } System.out.println(finalAns); m--; } } public static int solve(int money,int year,int tanri,double rate,int tesu){ int zandaka=0 ; int ratesum=0 ; if(tanri==1){ while(year!=0){ zandaka=money+(int)(money*rate)-tesu ; money=zandaka ; year--; } } else if(tanri==0){ while(year!=0){ zandaka=money-tesu ; ratesum+=(int)(money*rate); money=zandaka ; year--; } } return zandaka+ratesum ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var m : int ; m := sc.getCurrent()->toInteger() ; while (m /= 0) do ( var money : int ; money := sc.getCurrent()->toInteger() ; var year : int ; year := sc.getCurrent()->toInteger() ; var type : int ; type := sc.getCurrent()->toInteger() ; var finalAns : int ; finalAns := 0 ; while (type /= 0) do ( var tanri : int ; tanri := sc.getCurrent()->toInteger() ; var rate : double ; rate := sc.getCurrent()->toReal() ; var tesu : int ; tesu := sc.getCurrent()->toInteger() ; var ans : int ; ans := solve(money, year, tanri, rate, tesu) ; if (ans > finalAns) then finalAns := ans ; else skip ; type := type - 1 ; ) ; OclFile["System.out"].println(finalAns) ; m := m - 1 ; ) ); static operation solve( money : int, year : int, tanri : int, rate : double, tesu : int) : int pre: true post: true activity: ( var zandaka : int ; zandaka := 0 ; var ratesum : int ; ratesum := 0 ; if (tanri = 1) then ( while (year /= 0) do ( zandaka := money + (money * rate)->oclAsType(int) - tesu ; money := zandaka ; year := year - 1 ) ) else if (tanri = 0) then ( while (year /= 0) do ( zandaka := money - tesu ; ratesum := ratesum+((money * rate)->oclAsType(int)) ; money := zandaka ; year := year - 1 ) ) else skip ; ; return zandaka + ratesum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.math.BigDecimal ; public class Main { Main(){ Scanner sc=new Scanner(System.in); int m=sc.nextInt(); for(int k=0 ; ktoInteger() ; var k : int ; k := 0 ; while k < m do ( ( var str : String ; str := sc.getCurrent() ; var def : double ; def := double(str) ; var y : int ; y := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var bdm : double ; bdm := double(0) ; var i : int ; i := 0 ; while i < n do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; str := sc.getCurrent() ; var bd2 : double ; bd2 := double(str) ; str := sc.getCurrent() ; var bd3 : double ; bd3 := double(str) ; var bd : double ; bd := def ; var bd4 : double ; bd4 := double(0) ; if (s = 1) then ( var j : int ; j := 0 ; while j < y do ( ( bd4 := bd.multiply(bd2) ; bd4 := bd4.setScale(0, ROUND_DOWN) ; bd := bd4->excludes(bd) ; bd := bd.subtract(bd3) ) ; j := j + 1 ) ) else ( var j : int ; j := 0 ; while j < y do ( ( bd4 := bd4->excludes(bd2.multiply(bd)) ; bd4 := bd4.setScale(0, ROUND_DOWN) ; bd := bd.subtract(bd3) ) ; j := j + 1 ) ; bd := bd->excludes(bd4) ) ; if (bdm->compareTo(bd) = -1) then ( bdm := bd ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(bdm+"") ; ) ; k := k + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class RedVsBlue { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int r=sc.nextInt(); int b=sc.nextInt(); int parts=r/(b+1); int remain=r %(b+1); while(r>0){ for(int i=1 ; i<=parts ; i++){ System.out.print("R"); } r-=parts ; if(remain>0){ System.out.print("R"); remain--; r--; } if(b>0){ System.out.print("B"); b--; } } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class RedVsBlue { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var parts : int ; parts := r / (b + 1) ; var remain : int ; remain := r mod (b + 1) ; while (r > 0) do ( var i : int ; i := 1 ; while i <= parts do ( ( OclFile["System.out"].print("R") ) ; i := i + 1 ) ; r := r-(parts) ; if (remain > 0) then ( OclFile["System.out"].print("R") ; remain := remain - 1 ; r := r - 1 ) else skip ; if (b > 0) then ( OclFile["System.out"].print("B") ; b := b - 1 ) else skip ) ; OclFile["System.out"].println() ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class RedVersusBlue { private static Scanner s=new Scanner(System.in); private static void solve(){ int n=s.nextInt(),r=s.nextInt(),b=s.nextInt(); Listsbs=new ArrayList<>(); for(int i=0 ; i0){ solve(); } s.close(); } } ------------------------------------------------------------ OCL File: --------- class RedVersusBlue { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation solve() : void pre: true post: true activity: ( var n : int ; n := s.getCurrent()->toInteger() ; var r : int ; r := s.getCurrent()->toInteger() ; var b : int ; b := s.getCurrent()->toInteger() ; var sbs : Sequence(String) ; sbs := Sequence{} ; var i : int ; i := 0 ; while i < b + 1 do ( ( var sb : String ; sb := StringLib.newString() ; sbs := sbs->including(sb) ) ; i := i + 1 ) ; var start : int ; start := 0 ; var i : int ; i := 0 ; while i < r do ( ( if (start < sbs->size()) then ( sbs := sbs->at(start+1) + StringLib.newString("R") ; start := start + 1 ) else ( start := 0 ; sbs := sbs->at(start+1) + StringLib.newString("R") ; start := start + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < b do ( ( sbs := sbs->at(i+1) + StringLib.newString("B") ) ; i := i + 1 ) ; var res : String ; res := StringLib.newString() ; var i : int ; i := 0 ; while i < sbs->size() do ( res := res + StringLib.newString(sbs->at(i+1)) ; ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( execute solve() ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A_Red_Versus_Blue { static int t,n ; static int r,b ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); t=scanner.nextInt(); while(t>0){ t--; n=scanner.nextInt(); r=scanner.nextInt(); b=scanner.nextInt(); Solve(); Endl(); } } public static void Solve(){ int x=r/(b+1); int cntr=0 ; for(int i=1 ; i<=n ; i++){ if(cntr0){ System.out.print("B"); cntr=0 ; b--; x=r/(b+1); } else System.out.print("R"); } } private static void Endl(){ System.out.println(""); } } ------------------------------------------------------------ OCL File: --------- class A_Red_Versus_Blue { static attribute t : int; static attribute r : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; n := scanner.getCurrent()->toInteger() ; r := scanner.getCurrent()->toInteger() ; b := scanner.getCurrent()->toInteger() ; execute Solve() ; execute Endl() ; ) ); static operation Solve() : void pre: true post: true activity: ( var x : int ; x := r / (b + 1) ; var cntr : int ; cntr := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (cntr < x) then ( OclFile["System.out"].print("R") ; cntr := cntr + 1 ; r := r - 1 ) else if (b > 0) then ( OclFile["System.out"].print("B") ; cntr := 0 ; b := b - 1 ; x := r / (b + 1) ) else OclFile["System.out"].print("R") ; ; ) ; i := i + 1 ) ); static operation Endl() : void pre: true post: true activity: ( OclFile["System.out"].println("") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication115 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int num=sc.nextInt(); ArrayListarr=new ArrayList<>(); ArrayListarra=new ArrayList<>(); int maxdif=0 ; int maxAll=1000000000 ; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Sequence{} ; var arra : Sequence(int) ; arra := Sequence{} ; var maxdif : int ; maxdif := 0 ; var maxAll : int ; maxAll := 1000000000 ; var i : int ; i := 0 ; while i < num do ( ( var h : int ; h := sc.getCurrent()->toInteger() ; arr := arr->including(h) ; arra := arra->including(h) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < num - 1 do ( ( var j : int ; j := 0 ; while j < arr->size() - 1 do ( ( if (j = i) then ( maxdif := Set{if arr->at(j - 1+1) - arr->at(j + 1+1) < 0 then -(arr->at(j - 1+1) - arr->at(j + 1+1)) else arr->at(j - 1+1) - arr->at(j + 1+1) endif, maxdif}->max() ) else ( maxdif := Set{if arr->at(j+1) - arr->at(j + 1+1) < 0 then -(arr->at(j+1) - arr->at(j + 1+1)) else arr->at(j+1) - arr->at(j + 1+1) endif, maxdif}->max() ) ) ; j := j + 1 ) ; maxAll := Set{maxAll, maxdif}->min() ; maxdif := 0 ) ; i := i + 1 ) ; OclFile["System.out"].println(maxAll) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args){ FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder sb=new StringBuilder(); int t=fs.nextInt(); while(t-->0){ long n=fs.nextLong(),k=fs.nextLong(); long fjr=0 ; while(n>0){ if(n % k==0){ n=n/k ; fjr++; } else { fjr+=(n % k); n-=(n % k); } } sb.append(fjr).append("\n"); } out.println(sb); out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; i 0) do ( t := t - 1 ; skip ; ( var n : long ; n := fs.nextLong() ; var k : long ; k := fs.nextLong() ; var fjr : long ; fjr := 0 ; while (n > 0) do ( if (n mod k = 0) then ( n := n / k ; fjr := fjr + 1 ) else ( fjr := fjr+((n mod k)) ; n := n-((n mod k)) ) ) ; sb := sb + StringLib.newString(fjr) + StringLib.newString("\n") ) ; ) ; skip ; skip ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Test { static long whomever(long x,long y){ long count=0 ; while(x>0){ if(x % y==0){ x/=y ; count++; } else { count+=(x % y); x-=(x % y); } } return count ; } public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t ; long n,k ; t=Integer.parseInt(scan.nextLine()); long r[]=new long[t]; for(int i=0 ; i 0) do ( if (x mod y = 0) then ( x := x/(y) ; count := count + 1 ) else ( count := count+((x mod y)) ; x := x-((x mod y)) ) ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; var n : long ; var k : long ; t := (scan.nextLine())->toInteger() ; var r : Sequence(long) ; r := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( var y : Sequence(String) ; y := scan.nextLine()->split(" ") ; n := (y[0+1])->toLong() ; k := (y[1+1])->toLong() ; r[i+1] := whomever(n, k) ) ; i := i + 1 ) ; for (i : r) do ( ( OclFile["System.out"].println(i) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int A,B,X ; A=sc.nextInt(); B=sc.nextInt(); X=sc.nextInt(); if(X % 500!=0){ X+=500-X % 500 ; } int a=0 ; int b=0 ; if(A0)? 1 : 0); } else if(A>2*B){ b=X/500 ; } else { a=X/1000 ; X %=1000 ; b=X/500 ; } System.out.println(A*a+B*b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; var B : int ; var X : int ; A := sc.getCurrent()->toInteger() ; B := sc.getCurrent()->toInteger() ; X := sc.getCurrent()->toInteger() ; if (X mod 500 /= 0) then ( X := X+(500 - X mod 500) ) else skip ; var a : int ; a := 0 ; var b : int ; b := 0 ; if (A < B) then ( a := X / 1000 + (if (X mod 1000 > 0) then 1 else 0 endif) ) else if (A > 2 * B) then ( b := X / 500 ) else ( a := X / 1000 ; X := X mod 1000 ; b := X / 500 ) ; ; OclFile["System.out"].println(A * a + B * b) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class heroZero { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int tc=sc.nextInt(); long n,k ; for(int i=0 ; i0){ if(n % k==0){ n/=k ; count++; } else { long rem=n % k ; count+=rem ; n-=rem ; } } if(n==0)System.out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class heroZero { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tc : int ; tc := sc.getCurrent()->toInteger() ; var n : long ; var k : long ; var i : int ; i := 0 ; while i < tc do ( ( n := sc.getCurrent()->toLong() ; k := sc.getCurrent()->toLong() ; var count : long ; count := 0 ; while (n > 0) do ( if (n mod k = 0) then ( n := n/(k) ; count := count + 1 ) else ( var rem : long ; rem := n mod k ; count := count+(rem) ; n := n-(rem) ) ) ; if (n = 0) then OclFile["System.out"].println(count) ; else skip ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static boolean flipsPossible(int[] a,int n){ int count_odd=0,count_even=0 ; for(int i=0 ; isize() ; if (flipsPossible(a, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long findF_N(long n){ long ans=0 ; for(long i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int minNumber(int a[],int n,int x){ Arrays.sort(a); int k ; for(k=0 ; a[(n)/2]!=x ; k++){ a[n++]=x ; Arrays.sort(a); } return k ; } public static void main(String[] args){ int x=10 ; int a[]={ 10,20,30 }; int n=3 ; System.out.println(minNumber(a,n-1,x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minNumber( a : Sequence(int), n : int, x : int) : int pre: true post: true activity: ( a := a->sort() ; var k : int ; k := 0 ; while a[(n) / 2+1] /= x do ( ( a[n+1] := x ; n := n + 1 ; a := a->sort() ) ; k := k + 1 ) ; return k ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 10 ; var a : Sequence(int) ; a := Sequence{10,20,30} ; var n : int ; n := 3 ; OclFile["System.out"].println(minNumber(a, n - 1, x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MinimumDifficulty { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[] a=new int[n]; a[0]=scan.nextInt(); a[1]=scan.nextInt(); int m=a[1]-a[0]; for(int i=2 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; a[0+1] := scan.getCurrent()->toInteger() ; a[1+1] := scan.getCurrent()->toInteger() ; var m : int ; m := a[1+1] - a[0+1] ; var i : int ; i := 2 ; while i < n do ( ( a[i+1] := scan.getCurrent()->toInteger() ; m := Set{m, a[i+1] - a[i - 1+1]}->max() ) ; i := i + 1 ) ; var k : int ; k := 100000 ; var i : int ; i := 0 ; while i < n - 2 do ( ( k := Set{k, a[i + 2+1] - a[i+1]}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{k, m}->max()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int vis[]; static int dfs(int x,Vector>adj){ int sz=1 ; vis[x]=1 ; for(int i=0 ; i>adj){ int val=0 ; vis=new int[n+1]; for(int i=0 ; i>adj=new Vector>(); Vectorv=new Vector(); v.add(0); v.add(1); Vectorv1=new Vector(); v1.add(1); v1.add(2); adj.add(v); adj.add(v1); adj.add(new Vector()); System.out.println(maxValue(n,adj)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute vis : Sequence(int); static operation dfs( x : int, adj : Sequence(Sequence(int))) : int pre: true post: true activity: ( var sz : int ; sz := 1 ; vis[x+1] := 1 ; var i : int ; i := 0 ; while i < adj->at(x+1)->size() do ( if (vis[adj->at(x+1)->at(i+1)+1] = 0) then sz := sz+(dfs(adj->at(x+1)->at(i+1), adj)) ; else skip ; ; i := i + 1 ) ; return sz ); static operation maxValue( n : int, adj : Sequence(Sequence(int))) : int pre: true post: true activity: ( var val : int ; val := 0 ; vis := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( vis[i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( if (vis[i+1] = 0) then val := val+(dfs(i, adj) - 1) ; else skip ; ; i := i + 1 ) ; return val ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; var adj : Sequence(Sequence(int)) ; adj := Sequence{} ; var v : Sequence(int) ; v := Sequence{} ; v := v->including(0) ; v := v->including(1) ; var v1 : Sequence(int) ; v1 := Sequence{} ; v1 := v1->including(1) ; v1 := v1->including(2) ; adj := adj->including(v) ; adj := adj->including(v1) ; adj := adj->including(Sequence{}) ; OclFile["System.out"].println(maxValue(n, adj)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0 ; ic)System.out.println("No"); else System.out.println("Yes"); } } public static long gcd(long p,long q){ while(q>0){ long t=p % q ; p=q ; q=t ; } return p ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var a : long ; a := in.getCurrent()->toLong() ; var b : long ; b := in.getCurrent()->toLong() ; var c : long ; c := in.getCurrent()->toLong() ; var d : long ; d := in.getCurrent()->toLong() ; execute judge(a, b, c, d) ; ) ; i := i + 1 ) ); static operation judge( a : long, b : long, c : long, d : long) : void pre: true post: true activity: ( if (a < b or d < b) then OclFile["System.out"].println("No") ; else ( var g : long ; g := gcd(b, d) ; var max : long ; max := b - g + a mod g ; if (max > c) then OclFile["System.out"].println("No") ; else OclFile["System.out"].println("Yes") ; ) ); static operation gcd( p : long, q : long) : long pre: true post: true activity: ( while (q > 0) do ( var t : long ; t := p mod q ; p := q ; q := t ) ; return p ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskB solver=new TaskB(); int testCount=Integer.parseInt(in.next()); for(int i=1 ; i<=testCount ; i++)solver.solve(i,in,out); out.close(); } static class TaskB { static final String YES="Yes" ; static final String NO="No" ; public void solve(int testNumber,InputReader in,PrintWriter out){ long a=in.nextLong(); long b=in.nextLong(); long c=in.nextLong(); long d=in.nextLong(); if(a=b-worst){ out.println(YES); } else { out.println(NO); } } private long gcd(long p,long q){ while(q>0){ long t=p % q ; p=q ; q=t ; } return p ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskB ; solver := TaskB.newTaskB() ; var testCount : int ; testCount := (in.next())->toInteger() ; var i : int ; i := 1 ; while i <= testCount do ( solver.solve(i, in, out) ; ; i := i + 1 ) ; skip ; ); static class TaskB { static attribute YES : String := "Yes"; static attribute NO : String := "No"; operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var a : long ; a := in.nextLong() ; var b : long ; b := in.nextLong() ; var c : long ; c := in.nextLong() ; var d : long ; d := in.nextLong() ; if (a < b or d < b) then ( skip ; return ) else skip ; var g : long ; g := gcd(b, d) ; var worst : long ; worst := g - a mod g ; if (c >= b - worst) then ( skip ) else ( skip ) ; ); operation gcd( p : long, q : long) : long pre: true post: true activity: ( while (q > 0) do ( var t : long ; t := p mod q ; p := q ; q := t ) ; return p ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ try(Scanner in=new Scanner(System.in)){ int N=in.nextInt(); int K=in.nextInt(); StringBuilder S=new StringBuilder(in.next()); S.replace(K-1,K,S.substring(K-1,K).toLowerCase()); System.out.println(S); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var N : int ; N := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var S : String ; S := StringLib.newString(in.getCurrent()) ; S.replace(K - 1, K, S.subrange(K - 1+1,K)->toLowerCase()) ; OclFile["System.out"].println(S) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { void solve(){ int A,B,X,ans ; Scanner sc=new Scanner(System.in); A=sc.nextInt(); B=sc.nextInt(); X=sc.nextInt(); if(X % 500!=0)X+=500-X % 500 ; int a=0 ; int b=0 ; if(A0)? 1 : 0); } else if(A>2*B){ b=X/500 ; } else { a=X/1000 ; X %=1000 ; b=X/500 ; } System.out.println(A*a+B*b); } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var A : int ; var B : int ; var X : int ; var ans : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; A := sc.getCurrent()->toInteger() ; B := sc.getCurrent()->toInteger() ; X := sc.getCurrent()->toInteger() ; if (X mod 500 /= 0) then X := X+(500 - X mod 500) ; else skip ; var a : int ; a := 0 ; var b : int ; b := 0 ; if (A < B) then ( a := X / 1000 + (if (X mod 1000 > 0) then 1 else 0 endif) ) else if (A > 2 * B) then ( b := X / 500 ) else ( a := X / 1000 ; X := X mod 1000 ; b := X / 500 ) ; ; OclFile["System.out"].println(A * a + B * b) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int nTests=Integer.parseInt(br.readLine()); for(int t=0 ; tc){ sb.append("No\n"); } else { sb.append("Yes\n"); } } else { if(c+1>b-1){ sb.append("Yes\n"); } else { d+=b ; long div=gcd(b,d); long badLo=(c+1); long badHi=b-1 ; if(badHi-badLo+1>=div){ sb.append("No\n"); } else { long mBadLo=badLo % div ; long mBadHi=badHi % div ; if(mBadLo>mBadHi){ mBadHi+=div ; } long mA=a % div ; if(mA>=mBadLo && mA<=mBadHi){ sb.append("No\n"); } else { sb.append("Yes\n"); } } } } } } } System.out.print(sb); } static long gcd(long a,long b){ return(b==0 ? a : gcd(b,a % b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sb : String ; sb := StringLib.newString() ; var nTests : int ; nTests := (br.readLine())->toInteger() ; var t : int ; t := 0 ; while t < nTests do ( ( var s : Sequence(String) ; s := br.readLine()->split(" ") ; var a : long ; a := (s[0+1])->toLong() ; var b : long ; b := (s[1+1])->toLong() ; var c : long ; c := (s[2+1])->toLong() ; var d : long ; d := (s[3+1])->toLong() ; if (a < b) then ( sb := sb + StringLib.newString("No\n") ) else ( if (d < b) then ( sb := sb + StringLib.newString("No\n") ) else ( d := d mod b ; if (d = 0) then ( if (a mod b > c) then ( sb := sb + StringLib.newString("No\n") ) else ( sb := sb + StringLib.newString("Yes\n") ) ) else ( if (c + 1 > b - 1) then ( sb := sb + StringLib.newString("Yes\n") ) else ( d := d+(b) ; var div : long ; div := gcd(b, d) ; var badLo : long ; badLo := (c + 1) ; var badHi : long ; badHi := b - 1 ; if (badHi - badLo + 1 >= div) then ( sb := sb + StringLib.newString("No\n") ) else ( var mBadLo : long ; mBadLo := badLo mod div ; var mBadHi : long ; mBadHi := badHi mod div ; if (mBadLo > mBadHi) then ( mBadHi := mBadHi+(div) ) else skip ; var mA : long ; mA := a mod div ; if (mA >= mBadLo & mA <= mBadHi) then ( sb := sb + StringLib.newString("No\n") ) else ( sb := sb + StringLib.newString("Yes\n") ) ; ) ; ) ) ) ) ; ) ; t := t + 1 ) ; OclFile["System.out"].print(sb) ; ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( return (if b = 0 then a else gcd(b, a mod b) endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ MyScanner sc=new MyScanner(); PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); int t=sc.nextInt(); for(int i=1 ; i<=t ; i++){ long a=sc.nextLong(); long b=sc.nextLong(); long c=sc.nextLong(); long d=sc.nextLong(); if(a=max)out.println("Yes"); else out.println("No"); } out.close(); } static long gcd(long a,long b){ if(b==0)return a ; else return gcd(b,a % b); } public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : MyScanner ; sc := MyScanner.newMyScanner() ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var t : int ; t := sc.nextInt() ; var i : int ; i := 1 ; while i <= t do ( ( var a : long ; a := sc.nextLong() ; var b : long ; b := sc.nextLong() ; var c : long ; c := sc.nextLong() ; var d : long ; d := sc.nextLong() ; if (a < b or d < b) then ( skip ; continue ) else skip ; var gcd : long ; gcd := gcd(b, d) ; var init : long ; init := a mod gcd ; var max : long ; max := b - gcd + init ; if (c >= max) then skip else skip ; ; ) ; i := i + 1 ) ; skip ; ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (b = 0) then return a else return gcd(b, a mod b) ); static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.math.BigInteger ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] sa=br.readLine().split(" "); int t=Integer.parseInt(sa[0]); for(int i=0 ; id){ System.out.println("No"); } else { long e=BigInteger.valueOf(b).gcd(BigInteger.valueOf(d)).longValue(); long g=a % b ; long h=(c+1-g+e-1)/e ; long min=g+e*h ; if(minsplit(" ") ; var t : int ; t := (sa[0+1])->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( sa := br.readLine()->split(" ") ; var a : long ; a := (sa[0+1])->toLong() ; var b : long ; b := (sa[1+1])->toLong() ; var c : long ; c := (sa[2+1])->toLong() ; var d : long ; d := (sa[3+1])->toLong() ; if (a < b or b > d) then ( OclFile["System.out"].println("No") ) else ( var e : long ; e := (b + "")->toLong().gcd((d + "")->toLong())->oclAsType(long) ; var g : long ; g := a mod b ; var h : long ; h := (c + 1 - g + e - 1) / e ; var min : long ; min := g + e * h ; if (min < b) then ( OclFile["System.out"].println("No") ) else ( OclFile["System.out"].println("Yes") ) ; ) ; ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p132 implements EulerSolution { public static void main(String[] args){ System.out.println(new p132().run()); } public String run(){ int sum=0 ; int count=0 ; for(int i=2 ; count<40 ; i++){ if(Library.isPrime(i)&& repunitMod(1000000000,i)==0){ sum+=i ; count++; } } return Integer.toString(sum); } private static int repunitMod(int k,int m){ return(Library.powMod(10,k,m*9)-1)/9 ; } } ------------------------------------------------------------ OCL File: --------- class p132 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p132.newp132().run()) ); operation run() : String pre: true post: true activity: ( var sum : int ; sum := 0 ; var count : int ; count := 0 ; var i : int ; i := 2 ; while count < 40 do ( ( if (Library.isPrime(i) & repunitMod(1000000000, i) = 0) then ( sum := sum+(i) ; count := count + 1 ) else skip ) ; i := i + 1 ) ; return ((sum) + "") ); static operation repunitMod( k : int, m : int) : int pre: true post: true activity: ( return (Library.powMod(10, k, m * 9) - 1) / 9 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long ans=0 ; for(long i=1 ; i<=n ; i++){ if(i % 3!=0 && i % 5!=0){ ans+=i ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var ans : long ; ans := 0 ; var i : long ; i := 1 ; while i <= n do ( ( if (i mod 3 /= 0 & i mod 5 /= 0) then ( ans := ans+(i) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; imd){ md=Math.abs(arr[j]-arr[h]); } } else { if(Math.abs(arr[j]-arr[j+1])>md){ md=Math.abs(arr[j]-arr[j+1]); } } } } if(mdtoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var md1 : int ; md1 := 1000000 ; var i : int ; i := 1 ; while i < n - 1 do ( ( var md : int ; md := 0 ; var j : int ; j := 0 ; while j < n - 1 do ( ( if (j /= i) then ( if (j + 1 = i) then ( var h : int ; h := j + 2 ; if (if arr[j+1] - arr[h+1] < 0 then -(arr[j+1] - arr[h+1]) else arr[j+1] - arr[h+1] endif > md) then ( md := if arr[j+1] - arr[h+1] < 0 then -(arr[j+1] - arr[h+1]) else arr[j+1] - arr[h+1] endif ) else skip ) else ( if (if arr[j+1] - arr[j + 1+1] < 0 then -(arr[j+1] - arr[j + 1+1]) else arr[j+1] - arr[j + 1+1] endif > md) then ( md := if arr[j+1] - arr[j + 1+1] < 0 then -(arr[j+1] - arr[j + 1+1]) else arr[j+1] - arr[j + 1+1] endif ) else skip ) ) else skip ) ; j := j + 1 ) ; if (md < md1) then md1 := md ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(md1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); long N=scanner.nextLong(); long x=0 ; long y=0 ; long sum=0 ; x=N/15 ; y=N % 15 ; sum=(60+60+120*(x-1))*x/2 ; if(y==1){ sum+=1+15*x ; } else if(y==2 || y==3){ sum+=3+15*x*2 ; } else if(y==4 || y==5 || y==6){ sum+=7+15*x*3 ; } else if(y==7){ sum+=14+15*x*4 ; } else if(y==8 || y==9 || y==10){ sum+=22+15*x*5 ; } else if(y==11 || y==12){ sum+=33+15*x*6 ; } else if(y==13){ sum+=46+15*x*7 ; } else if(y==14){ sum+=60+15*x*8 ; } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := scanner.getCurrent()->toLong() ; var x : long ; x := 0 ; var y : long ; y := 0 ; var sum : long ; sum := 0 ; x := N / 15 ; y := N mod 15 ; sum := (60 + 60 + 120 * (x - 1)) * x / 2 ; if (y = 1) then ( sum := sum+(1 + 15 * x) ) else if (y = 2 or y = 3) then ( sum := sum+(3 + 15 * x * 2) ) else if (y = 4 or y = 5 or y = 6) then ( sum := sum+(7 + 15 * x * 3) ) else if (y = 7) then ( sum := sum+(14 + 15 * x * 4) ) else if (y = 8 or y = 9 or y = 10) then ( sum := sum+(22 + 15 * x * 5) ) else if (y = 11 or y = 12) then ( sum := sum+(33 + 15 * x * 6) ) else if (y = 13) then ( sum := sum+(46 + 15 * x * 7) ) else if (y = 14) then ( sum := sum+(60 + 15 * x * 8) ) else skip ; ; ; ; ; ; ; ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.Collectors ; import java.util.stream.LongStream ; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long N=sc.nextLong(); long res=LongStream.rangeClosed(1,N).filter(p->{ return !((p % 3==0)||(p % 5==0)); } ).sum(); System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := sc.getCurrent()->toLong() ; var res : long ; res := Integer.subrange(1, N)->select( _x1 | (lambda p : OclAny in ( return not(((p mod 3 = 0) or (p mod 5 = 0))) ))->apply(_x1) )->sum() ; OclFile["System.out"].println(res) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ FastReader s=new FastReader(); int N=s.nextInt(); long count=0 ; for(int i=1 ; i<=N ; i++){ if(i % 5==0 || i % 3==0)continue ; else count+=i ; } System.out.println(count); } private static boolean isPrime(int n){ if(n==2)return true ; else if((n % 2==0 && n>2)|| n<2)return false ; else { for(int i=3 ; i<=(int)Math.sqrt(n); i+=2){ if(n % i==0)return false ; } return true ; } } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : FastReader ; s := FastReader.newFastReader() ; var N : int ; N := s.nextInt() ; var count : long ; count := 0 ; var i : int ; i := 1 ; while i <= N do ( ( if (i mod 5 = 0 or i mod 3 = 0) then continue else count := count+(i) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); static operation isPrime( n : int) : boolean pre: true post: true activity: ( if (n = 2) then return true else if ((n mod 2 = 0 & n > 2) or n < 2) then return false else ( var i : int ; i := 3 ; while i <= (n)->sqrt()->oclAsType(int) do ( ( if (n mod i = 0) then return false else skip ) ; i := i+(2) ) ; return true ) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static void log(long i){ System.out.println(i); } static void log(String s){ System.out.println(s); } public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long total=0 ; for(int i=0 ; i<=n ; i++){ if(i % 15==0)continue ; if(i % 3==0)continue ; if(i % 5==0)continue ; total+=i ; } sc.close(); log(total); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation log( i : long) : void pre: true post: true activity: ( OclFile["System.out"].println(i) ); static operation log( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var total : long ; total := 0 ; var i : int ; i := 0 ; while i <= n do ( ( if (i mod 15 = 0) then continue else skip ; if (i mod 3 = 0) then continue else skip ; if (i mod 5 = 0) then continue else skip ; total := total+(i) ) ; i := i + 1 ) ; skip ; execute log(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int ___gcd(int a,int b){ if(a==0 || b==0)return 0 ; if(a==b)return a ; if(a>b)return ___gcd(a-b,b); return ___gcd(a,b-a); } static int findLargest(int arr[],int n){ int gcd=arr[0]; for(int i=1 ; i= X) then ( costmin := Set{costmin, A * i + B * j}->min() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; execute pl(costmin) ; ); static operation pl( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o) ); static operation pl() : void pre: true post: true activity: ( OclFile["System.out"].println() ); static operation p( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].print(o) ); static class SC { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newSC( in : OclFile) : SC pre: true post: true activity: ( var self : SC ; self := createSC(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ) else skip ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; public final class p101 implements EulerSolution { public static void main(String[] args){ System.out.println(new p101().run()); } private static final int DEGREE=10 ; public String run(){ Fraction sum=Fraction.ZERO ; for(int k=1 ; k<=DEGREE ; k++){ for(int n=k+1 ; ; n++){ if(n==DEGREE+2)throw new AssertionError(); Fraction reference=new Fraction(generatingFunction(n)); Fraction term=optimumPolynomial(k,n); if(! term.equals(reference)){ sum=sum.add(term); break ; } } } if(sum.denominator.equals(BigInteger.ONE))return sum.numerator.toString(); else return sum.toString(); } private static Fraction optimumPolynomial(int k,int n){ Fraction sum=Fraction.ZERO ; for(int i=1 ; i<=k ; i++){ Fraction product=new Fraction(generatingFunction(i)); for(int j=1 ; j<=k ; j++){ if(j!=i)product=product.multiply(new Fraction(BigInteger.valueOf(n-j),BigInteger.valueOf(i-j))); } sum=sum.add(product); } return sum ; } private static BigInteger generatingFunction(int n){ BigInteger sum=BigInteger.ZERO ; BigInteger biN=BigInteger.valueOf(-n); for(int i=0 ; i<=DEGREE ; i++)sum=sum.add(biN.pow(i)); return sum ; } } ------------------------------------------------------------ OCL File: --------- class p101 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p101.newp101().run()) ); static attribute DEGREE : int := 10; operation run() : String pre: true post: true activity: ( var sum : Fraction ; sum := Fraction.ZERO ; var k : int ; k := 1 ; while k <= DEGREE do ( ( var n : int ; n := k + 1 ; while true do ( ( if (n = DEGREE + 2) then error AssertionException() ; else skip ; var reference : Fraction ; reference := Fraction.newFraction(generatingFunction(n)) ; var term : Fraction ; term := optimumPolynomial(k, n) ; if (not(term = reference)) then ( sum := sum->excludes(term) ; break ) else skip ) ; n := n + 1 ) ) ; k := k + 1 ) ; if (sum.denominator = 1) then return sum.numerator+"" else return sum+"" ); static operation optimumPolynomial( k : int, n : int) : Fraction pre: true post: true activity: ( var sum : Fraction ; sum := Fraction.ZERO ; var i : int ; i := 1 ; while i <= k do ( ( var product : Fraction ; product := Fraction.newFraction(generatingFunction(i)) ; var j : int ; j := 1 ; while j <= k do ( ( if (j /= i) then product := product.multiply(Fraction.newFraction((n - j + "")->toLong(), (i - j + "")->toLong())) ; else skip ) ; j := j + 1 ) ; sum := sum->excludes(product) ) ; i := i + 1 ) ; return sum ); static operation generatingFunction( n : int) : long pre: true post: true activity: ( var sum : long ; sum := 0 ; var biN : long ; biN := (-n + "")->toLong() ; var i : int ; i := 0 ; while i <= DEGREE do ( sum := sum->excludes(biN.pow(i)) ; ; i := i + 1 ) ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p117 implements EulerSolution { public static void main(String[] args){ System.out.println(new p117().run()); } private static final int LENGTH=50 ; public String run(){ long[] ways=new long[LENGTH+1]; ways[0]=1 ; for(int n=1 ; n<=LENGTH ; n++){ for(int k=1 ; k<=4 && k<=n ; k++)ways[n]+=ways[n-k]; } return Long.toString(ways[LENGTH]); } } ------------------------------------------------------------ OCL File: --------- class p117 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p117.newp117().run()) ); static attribute LENGTH : int := 50; operation run() : String pre: true post: true activity: ( var ways : Sequence(long) ; ways := Integer.subrange(1,LENGTH + 1)->collect(0) ; ways[0+1] := 1 ; var n : int ; n := 1 ; while n <= LENGTH do ( ( var k : int ; k := 1 ; while k <= 4 & k <= n do ( ways[n+1] := ways[n+1]+(ways[n - k+1]) ; ; k := k + 1 ) ) ; n := n + 1 ) ; return ((ways[LENGTH+1]) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p114 implements EulerSolution { public static void main(String[] args){ System.out.println(new p114().run()); } private static final int LENGTH=50 ; public String run(){ long[] ways=new long[LENGTH+1]; ways[0]=1 ; ways[1]=1 ; ways[2]=1 ; for(int n=3 ; n<=LENGTH ; n++){ long sum=ways[n-1]+1 ; for(int k=3 ; kcollect(0) ; ways[0+1] := 1 ; ways[1+1] := 1 ; ways[2+1] := 1 ; var n : int ; n := 3 ; while n <= LENGTH do ( ( var sum : long ; sum := ways[n - 1+1] + 1 ; var k : int ; k := 3 ; while k < n do ( sum := sum+(ways[n - k - 1+1]) ; ; k := k + 1 ) ; ways[n+1] := sum ) ; n := n + 1 ) ; return ((ways[LENGTH+1]) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.BigInteger ; public class Main { public static void solution(int n,ArrayListheights){ int min=1000 ; int current=0 ; int ind=0 ; int ind2=0 ; for(int i=0 ; iheights=new ArrayList<>(); for(int i=0 ; isize() - 1 do ( ( current := if heights->at(i+1) - heights->at(i + 1+1) < 0 then -(heights->at(i+1) - heights->at(i + 1+1)) else heights->at(i+1) - heights->at(i + 1+1) endif ; if (current < min) then ( min := current ; ind := i + 1 ; ind2 := i + 2 ) else skip ) ; i := i + 1 ) ; current := if heights->at(heights->size() - 1+1) - heights->at(0+1) < 0 then -(heights->at(heights->size() - 1+1) - heights->at(0+1)) else heights->at(heights->size() - 1+1) - heights->at(0+1) endif ; if (current < min) then ( min := current ; ind := n ; ind2 := 1 ) else skip ; OclFile["System.out"].println(ind + " " + ind2) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var heights : Sequence(int) ; heights := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( heights := heights->including(input.getCurrent()->toInteger()) ) ; i := i + 1 ) ; execute solution(n, heights) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MinimumDifficulty { public static void main(String[] args){ Scanner sc=new Scanner(System.in); final int n=sc.nextInt(); int[] heights=new int[n]; int maxDifficulty=-1 ; for(int i=0 ; imaxDifficulty){ maxDifficulty=diff ; } if(j==n-2){ if(maxDifficultytoInteger() ; var heights : Sequence(int) ; heights := Integer.subrange(1,n)->collect(0) ; var maxDifficulty : int ; maxDifficulty := -1 ; var i : int ; i := 0 ; while i < n do ( ( heights[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var current : int ; var next : int ; var diff : int ; var elementToRemove : int ; var newDifficulty : int ; newDifficulty := 1000 ; var i : int ; i := 1 ; while i < n - 1 do ( ( elementToRemove := heights[i+1] ; maxDifficulty := -1 ; var j : int ; j := 0 ; while j < n - 1 do ( ( if (heights[j+1] = elementToRemove) then ( current := heights[j - 1+1] ) else ( current := heights[j+1] ) ; if (heights[j + 1+1] = elementToRemove) then ( next := heights[j + 2+1] ) else ( next := heights[j + 1+1] ) ; diff := next - current ; if (diff > maxDifficulty) then ( maxDifficulty := diff ) else skip ; if (j = n - 2) then ( if (maxDifficulty < newDifficulty) then ( newDifficulty := maxDifficulty ) else skip ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(newDifficulty) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class code { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; int diff=0,mindiff=Integer.MAX_VALUE,index1=0,index2=0 ; for(int i=0 ; idiff){ mindiff=diff ; index1=n ; index2=1 ; } } else { diff=Math.abs(arr[i]-arr[i-1]); if(mindiff>diff){ mindiff=diff ; index1=i ; index2=i+1 ; } } } System.out.println(index1+" "+index2); } } ------------------------------------------------------------ OCL File: --------- class code { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var diff : int ; diff := 0 ; var mindiff : int ; mindiff := 2147483647 ; var index1 : int ; index1 := 0 ; var index2 : int ; index2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( if (i = n) then ( diff := if arr[0+1] - arr[n - 1+1] < 0 then -(arr[0+1] - arr[n - 1+1]) else arr[0+1] - arr[n - 1+1] endif ; if (mindiff > diff) then ( mindiff := diff ; index1 := n ; index2 := 1 ) else skip ) else ( diff := if arr[i+1] - arr[i - 1+1] < 0 then -(arr[i+1] - arr[i - 1+1]) else arr[i+1] - arr[i - 1+1] endif ; if (mindiff > diff) then ( mindiff := diff ; index1 := i ; index2 := i + 1 ) else skip ) ) ; i := i + 1 ) ; OclFile["System.out"].println(index1 + " " + index2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Code_34A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; int minValue=Integer.MAX_VALUE ; int idx1=-1,idx2=-1 ; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var minValue : int ; minValue := 2147483647 ; var idx1 : int ; idx1 := -1 ; var idx2 : int ; idx2 := -1 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < arr->size() - 1 do ( ( if (if arr[i+1] - arr[i + 1+1] < 0 then -(arr[i+1] - arr[i + 1+1]) else arr[i+1] - arr[i + 1+1] endif < minValue) then ( idx1 := i + 1 ; idx2 := i + 2 ; minValue := if arr[i+1] - arr[i + 1+1] < 0 then -(arr[i+1] - arr[i + 1+1]) else arr[i+1] - arr[i + 1+1] endif ) else skip ) ; i := i + 1 ) ; if (if arr[0+1] - arr[n - 1+1] < 0 then -(arr[0+1] - arr[n - 1+1]) else arr[0+1] - arr[n - 1+1] endif < minValue) then ( idx1 := 1 ; idx2 := arr->size() ) else skip ; OclFile["System.out"].println(idx1 + " " + idx2) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static int getSum(int arr[],int p){ return arr.length ; } public static void main(String[] args){ int arr[]={ 5,6,8 }; int p=7 ; System.out.print(getSum(arr,p)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getSum( arr : Sequence(int), p : int) : int pre: true post: true activity: ( return arr->size() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{5,6,8} ; var p : int ; p := 7 ; OclFile["System.out"].print(getSum(arr, p)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.Queue ; public class GFG { static int countOfBinaryNumberLessThanN(int N){ Queueq=new LinkedList<>(); q.add(1); int cnt=0 ; int t ; while(q.size()>0){ t=q.peek(); q.remove(); if(t<=N){ cnt++; q.add(t*10); q.add(t*10+1); } } return cnt ; } static public void main(String[] args){ int N=200 ; System.out.println(countOfBinaryNumberLessThanN(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countOfBinaryNumberLessThanN( N : int) : int pre: true post: true activity: ( var q : Sequence(int) ; q := Sequence{} ; q := q->including(1) ; var cnt : int ; cnt := 0 ; var t : int ; while (q->size() > 0) do ( t := q->min() ; q := q.remove() ; if (t <= N) then ( cnt := cnt + 1 ; q := q->including(t * 10) ; q := q->including(t * 10 + 1) ) else skip ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 200 ; OclFile["System.out"].println(countOfBinaryNumberLessThanN(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int fact(int n){ int f=1 ; for(int i=2 ; i<=n ; i++){ f=f*i ; } return f ; } static int npr(int n,int r){ return fact(n)/fact(n-r); } static int countPermutations(String str){ int even=(int)Math.floor((double)(str.length()/2)); int odd=str.length()-even ; int ways=0 ; int[] freq=new int[26]; for(int i=0 ; isize() / 2)->oclAsType(double))->floor()->oclAsType(int) ; var odd : int ; odd := str->size() - even ; var ways : int ; ways := 0 ; var freq : Sequence(int) ; freq := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < str->size() do ( ( freq[(str->at(i+1) - ('a')->char2byte())->oclAsType(int)+1] := freq[(str->at(i+1) - ('a')->char2byte())->oclAsType(int)+1] + 1 ) ; i := i + 1 ) ; var nvowels : int ; nvowels := freq[0+1] + freq[4+1] + freq[8+1] + freq[14+1] + freq[20+1] ; var nconsonants : int ; nconsonants := str->size() - nvowels ; ways := npr(odd, nvowels) * npr(nconsonants, nconsonants) ; return ways ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeks" ; OclFile["System.out"].println(countPermutations(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int check(int n,Listmarks){ Integer x=Collections.max(marks); int bonus=100-x ; int c=0 ; for(int i=0 ; i=50)c+=1 ; } return c ; } public static void main(String[] args){ int n=5 ; Listmarks=Arrays.asList(0,21,83,45,64); System.out.println(check(n,marks)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation check( n : int, marks : Sequence(int)) : int pre: true post: true activity: ( var x : int ; x := .max(marks) ; var bonus : int ; bonus := 100 - x ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (marks->at(i+1) + bonus >= 50) then c := c+(1) ; else skip ) ; i := i + 1 ) ; return c ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var marks : Sequence(int) ; marks := Sequence{0,21,83,45,64} ; OclFile["System.out"].println(check(n, marks)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { static int INF=1<<29 ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int A,B,X ; StringTokenizer st=new StringTokenizer(br.readLine()); A=parseInt(st.nextToken()); B=parseInt(st.nextToken()); X=parseInt(st.nextToken()); int[] dp=new int[X+1000+1]; Arrays.fill(dp,INF); dp[0]=0 ; for(int i=0 ; i<=X ; i++){ if(dp[i+1000]>dp[i]+A){ dp[i+1000]=dp[i]+A ; } } for(int i=0 ; i<=X+500 ; i++){ if(dp[i+500]>dp[i]+B){ dp[i+500]=dp[i]+B ; } } int ans=INF ; for(int i=X+1000 ; i>=X ; i--){ if(dp[i]pow(29)))->oclAsType(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var A : int ; var B : int ; var X : int ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; A := (st.next() + "")->toInteger() ; B := (st.next() + "")->toInteger() ; X := (st.next() + "")->toInteger() ; var dp : Sequence(int) ; dp := Integer.subrange(1,X + 1000 + 1)->collect(0) ; dp := dp->collect(INF) ; dp[0+1] := 0 ; var i : int ; i := 0 ; while i <= X do ( ( if (dp[i + 1000+1] > dp[i+1] + A) then ( dp[i + 1000+1] := dp[i+1] + A ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= X + 500 do ( ( if (dp[i + 500+1] > dp[i+1] + B) then ( dp[i + 500+1] := dp[i+1] + B ) else skip ) ; i := i + 1 ) ; var ans : int ; ans := INF ; var i : int ; i := X + 1000 ; while i >= X do ( ( if (dp[i+1] < ans) then ans := dp[i+1] ; else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countP(int n,int k){ int[][] dp=new int[n+1][k+1]; for(int i=0 ; i<=n ; i++)dp[i][0]=0 ; for(int i=0 ; i<=k ; i++)dp[0][k]=0 ; for(int i=1 ; i<=n ; i++)for(int j=1 ; j<=k ; j++)if(j==1 || i==j)dp[i][j]=1 ; else dp[i][j]=j*dp[i-1][j]+dp[i-1][j-1]; return dp[n][k]; } public static void main(String[] args){ System.out.println(countP(5,2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countP( n : int, k : int) : int pre: true post: true activity: ( var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,k + 1)->collect(0)) ; var i : int ; i := 0 ; while i <= n do ( dp[i+1][0+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= k do ( dp[0+1][k+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( var j : int ; j := 1 ; while j <= k 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] ; ; ; j := j + 1 ) ; ; i := i + 1 ) ; return dp[n+1][k+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(countP(5, 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class hw19 { public static void main(String[] args)throws IOException { Scanner scan=new Scanner(System.in); { } { String in=scan.next(); int i=Integer.parseInt(String.valueOf(in.charAt(in.length()-1))); if(in.length()>1 &&(Integer.parseInt(String.valueOf(in.charAt(in.length()-2)))*10+i)% 4==0){ System.out.println(4); } else if(in.length()==1 && i % 4==0){ System.out.println(4); } else { System.out.println(0); } } } } ------------------------------------------------------------ OCL File: --------- class hw19 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; skip ( var in : String ; in := scan.getCurrent() ; var i : int ; i := (((in->at(in->size() - 1+1)) + ""))->toInteger() ; if (in->size() > 1 & ((((in->at(in->size() - 2+1)) + ""))->toInteger() * 10 + i) mod 4 = 0) then ( OclFile["System.out"].println(4) ) else if (in->size() = 1 & i mod 4 = 0) then ( OclFile["System.out"].println(4) ) else ( OclFile["System.out"].println(0) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; int sum=0 ; while((line=br.readLine())!=null && ! line.isEmpty()){ sum+=parseInt(line)>=40 ? parseInt(line): 40 ; } System.out.println(sum/5); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := "" ; var sum : int ; sum := 0 ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( sum := sum+(if (line + "")->toInteger() >= 40 then (line + "")->toInteger() else 40 endif) ) ; line := br.readLine() ; ) ; OclFile["System.out"].println(sum / 5) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { PrintStream log=new PrintStream(new OutputStream(){ public void write(int b){ } } ); PrintStream result=System.out ; Scanner sc=new Scanner(System.in); void main()throws IOException { int sum=0 ; for(int i=0 ; i<5 ; i++){ int t=sc.nextInt(); sum+=Math.max(t,40); } result.println(sum/5); } public static void main(String[] args)throws IOException { new Main().main(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute log : OclFile := OclFile.newOclFile_Write(OclFile()); attribute result : OclFile := OclFile["System.out"]; attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation main() : void pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 5 do ( ( var t : int ; t := sc.getCurrent()->toInteger() ; sum := sum+(Set{t, 40}->max()) ) ; i := i + 1 ) ; skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().main() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int[] p=new int[5]; for(int i=0 ; i<5 ; i++){ p[i]=stdIn.nextInt(); if(p[i]<40){ p[i]=40 ; } } int sum=0 ; for(int i=0 ; i<5 ; i++){ sum+=p[i]; } System.out.println(sum/5); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var p : Sequence(int) ; p := Integer.subrange(1,5)->collect(0) ; var i : int ; i := 0 ; while i < 5 do ( ( p[i+1] := stdIn.getCurrent()->toInteger() ; if (p[i+1] < 40) then ( p[i+1] := 40 ) else skip ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 5 do ( ( sum := sum+(p[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum / 5) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int total=0 ; for(int i=0 ; i<5 ; i++){ int n=sc.nextInt(); if(n<40){ n=40 ; } total+=n ; } out.println(total/5); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var total : int ; total := 0 ; var i : int ; i := 0 ; while i < 5 do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n < 40) then ( n := 40 ) else skip ; total := total+(n) ) ; i := i + 1 ) ; out.println(total / 5) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findNthDigit(int p,int q,int N){ int res=0 ; while(N>0){ N--; p*=10 ; res=p/q ; p %=q ; } return res ; } public static void main(String args[]){ int p=1,q=2,N=1 ; System.out.println(findNthDigit(p,q,N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findNthDigit( p : int, q : int, N : int) : int pre: true post: true activity: ( var res : int ; res := 0 ; while (N > 0) do ( N := N - 1 ; p := p*(10) ; res := p / q ; p := p mod q ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var p : int ; p := 1 ; var q : int ; q := 2 ; var N : int ; N := 1 ; OclFile["System.out"].println(findNthDigit(p, q, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ int left=scanner.nextInt(); int right=scanner.nextInt(); int down=scanner.nextInt(); int up=scanner.nextInt(); int x=scanner.nextInt(); int y=scanner.nextInt(); int x1=scanner.nextInt(); int y1=scanner.nextInt(); int x2=scanner.nextInt(); int y2=scanner.nextInt(); int finalX=x+right-left ; int finalY=y+up-down ; if(finalXx2 || finalYy2)System.out.println("NO"); else if((x1==x2 &&(left+right)>0)||(y1==y2 &&(up+down)>0))System.out.println("NO"); else System.out.println("YES"); } } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var left : int ; left := scanner.getCurrent()->toInteger() ; var right : int ; right := scanner.getCurrent()->toInteger() ; var down : int ; down := scanner.getCurrent()->toInteger() ; var up : int ; up := scanner.getCurrent()->toInteger() ; var x : int ; x := scanner.getCurrent()->toInteger() ; var y : int ; y := scanner.getCurrent()->toInteger() ; var x1 : int ; x1 := scanner.getCurrent()->toInteger() ; var y1 : int ; y1 := scanner.getCurrent()->toInteger() ; var x2 : int ; x2 := scanner.getCurrent()->toInteger() ; var y2 : int ; y2 := scanner.getCurrent()->toInteger() ; var finalX : int ; finalX := x + right - left ; var finalY : int ; finalY := y + up - down ; if (finalX < x1 or finalX > x2 or finalY < y1 or finalY > y2) then OclFile["System.out"].println("NO") else if ((x1 = x2 & (left + right) > 0) or (y1 = y2 & (up + down) > 0)) then OclFile["System.out"].println("NO") else OclFile["System.out"].println("YES") ; ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[][] arr=new int[n][2]; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1][0+1] := sc.getCurrent()->toInteger() ; arr[i+1][1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : int ; ans := solve(arr, n, k) ; OclFile["System.out"].println(ans) ; ); static operation solve( arr : Sequence(Sequence(int)), n : int, k : int) : int pre: true post: true activity: ( var ans1 : int ; ans1 := -1 ; var ans2 : int ; ans2 := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( if (ans1 < Set{arr[i+1][0+1], arr[i+1][1+1]}->min()) then ( ans1 := Set{arr[i+1][0+1], arr[i+1][1+1]}->min() ) else skip ; if (Set{arr[i+1][0+1], arr[i+1][1+1]}->max() < ans2) then ( ans2 := Set{arr[i+1][0+1], arr[i+1][1+1]}->max() ) else skip ) ; i := i + 1 ) ; if (ans2 < ans1) then ( return -1 ) else skip ; if (k <= ans1) then ( return ans1 - k ) else skip ; if (ans2 <= k) then ( return k - ans2 ) else skip ; return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ String[] tmp=sc.nextLine().split(" "); final int A=Integer.parseInt(tmp[0]); final int B=Integer.parseInt(tmp[1]); final int X=Integer.parseInt(tmp[2]); System.out.println(solve(A,B,X)); } } private static int solve(int a,int b,int x){ int ret=0 ; if(a>=(b*2)){ ret=(x/500)*b ; if(x % 500>0){ ret+=b ; } return ret ; } ret=x/1000*a ; if(a0){ ret+=a ; } return ret ; } if(x % 1000>500){ ret+=a ; } else if(x % 1000>0){ ret+=b ; } return ret ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var tmp : Sequence(String) ; tmp := sc.nextLine()->split(" ") ; var A : int ; A := (tmp[0+1])->toInteger() ; var B : int ; B := (tmp[1+1])->toInteger() ; var X : int ; X := (tmp[2+1])->toInteger() ; OclFile["System.out"].println(solve(A, B, X)) ; )) ); static operation solve( a : int, b : int, x : int) : int pre: true post: true activity: ( var ret : int ; ret := 0 ; if (a >= (b * 2)) then ( ret := (x / 500) * b ; if (x mod 500 > 0) then ( ret := ret+(b) ) else skip ; return ret ) else skip ; ret := x / 1000 * a ; if (a < b) then ( if (x mod 1000 > 0) then ( ret := ret+(a) ) else skip ; return ret ) else skip ; if (x mod 1000 > 500) then ( ret := ret+(a) ) else if (x mod 1000 > 0) then ( ret := ret+(b) ) else skip ; ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),x=in.nextInt(); int left=Integer.MIN_VALUE ; int right=Integer.MAX_VALUE ; int ans=0 ; for(int i=1 ; i<=n ; i++){ int l=in.nextInt(),r=in.nextInt(); if(l>r){ int temp=l ; l=r ; r=temp ; } left=Math.max(l,left); right=Math.min(r,right); } if(left>right){ pw.println(-1); } else if(x>=left && x<=right){ pw.println(0); } else { pw.println(Math.min(Math.abs(x-left),Math.abs(x-right))); } pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; var left : int ; left := -2147483648 ; var right : int ; right := 2147483647 ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var l : int ; l := in.getCurrent()->toInteger() ; var r : int ; r := in.getCurrent()->toInteger() ; if (l > r) then ( var temp : int ; temp := l ; l := r ; r := temp ) else skip ; left := Set{l, left}->max() ; right := Set{r, right}->min() ) ; i := i + 1 ) ; if (left > right) then ( skip ) else if (x >= left & x <= right) then ( skip ) else ( skip ) ; ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); long n=scan.nextLong(); long k=scan.nextLong(); long diploma=(long)(n/(2*(k+1))); long cer=diploma*k ; if(diploma+cer<=(n-(diploma+cer))){ System.out.println(diploma+" "+cer+" "+(n-(diploma+cer))); } else { while(diploma+cer>(n-(diploma+cer))){ diploma--; cer=diploma*k ; } System.out.println(diploma+" "+cer+" "+(n-(diploma+cer))); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := scan.getCurrent()->toLong() ; var k : long ; k := scan.getCurrent()->toLong() ; var diploma : long ; diploma := (n / (2 * (k + 1)))->oclAsType(long) ; var cer : long ; cer := diploma * k ; if (diploma + cer <= (n - (diploma + cer))) then ( OclFile["System.out"].println(diploma + " " + cer + " " + (n - (diploma + cer))) ) else ( while (diploma + cer > (n - (diploma + cer))) do ( diploma := diploma - 1 ; cer := diploma * k ) ; OclFile["System.out"].println(diploma + " " + cer + " " + (n - (diploma + cer))) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.math.BigInteger ; import java.util.Scanner ; public class cf456b { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Scanner in=new Scanner(System.in); BigInteger b ; BigInteger x=new BigInteger("4"); BigInteger y=new BigInteger("0"); b=in.nextBigInteger(); if(b.mod(x).equals(y))System.out.println("4"); else System.out.println("0"); } } ------------------------------------------------------------ OCL File: --------- class cf456b { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var b : long ; var x : long ; x := long("4") ; var y : long ; y := long("0") ; b := in.nextBigInteger() ; if (b.mod(x) = y) then OclFile["System.out"].println("4") else OclFile["System.out"].println("0") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A818 { public static void main(String[] args){ Scanner kbd=new Scanner(System.in); long n=kbd.nextLong(); long k=kbd.nextLong(); long winners=n/2 ; long dip=winners/(k+1); long c=dip*k ; System.out.println(dip+" "+c+" "+(n-dip-c)); } } ------------------------------------------------------------ OCL File: --------- class A818 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var kbd : OclFile ; kbd := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := kbd.getCurrent()->toLong() ; var k : long ; k := kbd.getCurrent()->toLong() ; var winners : long ; winners := n / 2 ; var dip : long ; dip := winners / (k + 1) ; var c : long ; c := dip * k ; OclFile["System.out"].println(dip + " " + c + " " + (n - dip - c)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); long n=input.nextLong(); long k=input.nextLong(); long d=n/(2*(1+k)); long c=d*k ; long e=n-(c+d); System.out.println(d+" "+c+" "+e); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := input.getCurrent()->toLong() ; var k : long ; k := input.getCurrent()->toLong() ; var d : long ; d := n / (2 * (1 + k)) ; var c : long ; c := d * k ; var e : long ; e := n - (c + d) ; OclFile["System.out"].println(d + " " + c + " " + e) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); long n=input.nextLong(); long k=input.nextLong(); long d=n/(2*(1+k)); long c=d*k ; long e=n-(c+d); System.out.println(d+" "+c+" "+e); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := input.getCurrent()->toLong() ; var k : long ; k := input.getCurrent()->toLong() ; var d : long ; d := n / (2 * (1 + k)) ; var c : long ; c := d * k ; var e : long ; e := n - (c + d) ; OclFile["System.out"].println(d + " " + c + " " + e) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { static int top=0 ; public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int[] stack ; String prec ; char c ; stack=new int[200]; top=0 ; for(; ; ){ if(! sc.hasNext())break ; prec=sc.next(); c=prec.charAt(0); if('0'<=c && c<='9'){ push(stack,Integer.parseInt(prec)); } else if(c=='+'){ push(stack,pop(stack)+pop(stack)); } else if(c=='-'){ push(stack,-pop(stack)+pop(stack)); } else if(c=='*'){ push(stack,pop(stack)*pop(stack)); } else { break ; } } System.out.println(pop(stack)); sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } private static int pop(int[] stack){ return stack[--top]; } private static void push(int[] stack,int a){ stack[top++]=a ; return ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute top : int := 0; operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var stack : Sequence(int) ; var prec : String ; var c : String ; stack := Integer.subrange(1,200)->collect(0) ; top := 0 ; while true do ( ( if (not(sc.hasNext())) then break else skip ; prec := sc.next() ; c := prec->at(0+1) ; if ('0' <= c & c <= '9') then ( execute push(stack, (prec)->toInteger()) ) else if (c = '+') then ( execute push(stack, pop(stack) + pop(stack)) ) else if (c = '-') then ( execute push(stack, -pop(stack) + pop(stack)) ) else if (c = '*') then ( execute push(stack, pop(stack) * pop(stack)) ) else ( break ) ; ; ; ) ) ; OclFile["System.out"].println(pop(stack)) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); static operation pop( stack : Sequence(int)) : int pre: true post: true activity: ( return stack[(top - 1)+1] ); static operation push( stack : Sequence(int), a : int) : void pre: true post: true activity: ( stack[top+1] := a ; top := top + 1 ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static class Stack { int A[],head ; Stack(int size){ A=new int[size+1]; head=0 ; } void show(){ for(int i=1 ; icollect(0) ; head := 0 ); operation show() : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < A->size() do ( if (i = A->size() - 1) then OclFile["System.out"].println(A[i+1]) else OclFile["System.out"].print(A[i+1] + " ") ; ; ; i := i + 1 ) ); operation isEmpty() : boolean pre: true post: true activity: ( return head = 0 ); operation isFull() : boolean pre: true post: true activity: ( return head = A->size() - 1 ); operation push( key : int) : void pre: true post: true activity: ( if (isFull()) then return else skip ; head := head + 1 ; A[head+1] := key ); operation pop() : int pre: true post: true activity: ( if (isEmpty()) then return 0 else skip ; return A[head+1] ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var com : String ; var stack : Sequence ; stack := Sequence{} ; while (sc.hasNext()) do ( com := sc.getCurrent() ; if (com = "+") then stack := stack->append(stack->last() + stack->last()) ; else if (com = "-") then stack := stack->append(-1 * stack->last() + stack->last()) else if (com = "*") then stack := stack->append(stack->last() * stack->last()) else stack := stack->append((com)->toInteger()) ; ; ; ) ; OclFile["System.out"].println(stack->last()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int computePolish(String in){ StackpolishStack=new Stack(); Scanner scan=new Scanner(in); while(scan.hasNext()){ String current=scan.next(); switch(current){ case "*" : int mult1=polishStack.pop(); int mult2=polishStack.pop(); polishStack.push(mult1*mult2); break ; case "+" : int plus1=polishStack.pop(); int plus2=polishStack.pop(); polishStack.push(plus1+plus2); break ; case "-" : int subt1=polishStack.pop(); int subt2=polishStack.pop(); polishStack.push(subt2-subt1); break ; default : polishStack.push(Integer.parseInt(current)); break ; } } return polishStack.pop(); } public static void main(String[] args){ Scanner scan=new Scanner(System.in); System.out.println(computePolish(scan.nextLine())); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation computePolish( in : String) : int pre: true post: true activity: ( var polishStack : Sequence(int) ; polishStack := Sequence{} ; var scan : OclFile ; scan := OclFile.newOclFile_Read(in) ; while (scan.hasNext()) do ( var current : String ; current := scan.getCurrent() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (current) ; if _switchval = "*" then var mult1 : int ; mult1 := polishStack->last() ; var mult2 : int ; mult2 := polishStack->last() ; polishStack := polishStack->append(mult1 * mult2) ; break else skip ; if _switchval = "+" then var plus1 : int ; plus1 := polishStack->last() ; var plus2 : int ; plus2 := polishStack->last() ; polishStack := polishStack->append(plus1 + plus2) ; break else skip ; if _switchval = "-" then var subt1 : int ; subt1 := polishStack->last() ; var subt2 : int ; subt2 := polishStack->last() ; polishStack := polishStack->append(subt2 - subt1) ; break else skip ; if true then polishStack := polishStack->append((current)->toInteger()) ; break else skip ; ) ) ; return polishStack->last() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(computePolish(scan.nextLine())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayDeque ; import java.util.Deque ; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] stringArray=br.readLine().split("\\s"); Dequeque=new ArrayDeque<>(); int a=0 ; int b=0 ; for(int i=0 ; isplit("\\s") ; var que : Sequence(int) ; que := ArrayDeque.newArrayDeque() ; var a : int ; a := 0 ; var b : int ; b := 0 ; var i : int ; i := 0 ; while i < stringArray->size() do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (stringArray[i+1]) ; if _switchval = "+" then a := que->first() ; que := que->tail() ; b := que->first() ; que := que->tail() ; que := que->prepend(b + a) ; break else skip ; if _switchval = "-" then a := que->first() ; que := que->tail() ; b := que->first() ; que := que->tail() ; que := que->prepend(b - a) ; break else skip ; if _switchval = "/" then a := que->first() ; que := que->tail() ; b := que->first() ; que := que->tail() ; que := que->prepend(b / a) ; break else skip ; if _switchval = "*" then a := que->first() ; que := que->tail() ; b := que->first() ; que := que->tail() ; que := que->prepend(b * a) ; break else skip ; if true then que := que->prepend((stringArray[i+1])->toInteger()) ; else skip ; ) ) ; i := i + 1 ) ; OclFile["System.out"].println(que->last()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int top=0 ; static int max=110 ; static int[] stack=new int[max]; public static boolean isNum(String str){ try { Integer.parseInt(str); return true ; } catch(NumberFormatException e){ return false ; } } public static void initialize(){ top=0 ; } public static boolean isEmpty(){ return top==0 ; } public static boolean isFull(){ return top>=max-1 ; } public static void push(int x){ if(isFull()){ throw new IllegalArgumentException("aa aa aa"); } else { top++; stack[top]=x ; } } public static int pop(){ if(isEmpty()){ throw new IllegalArgumentException("aa aa aa"); } else { top--; return stack[top+1]; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s="" ; int a ; while(sc.hasNext()){ s=sc.next(); if(isNum(s)){ push(Integer.parseInt(s)); } else if(s.equals("+")){ a=pop()+pop(); push(a); } else if(s.equals("-")){ a=-(pop()-pop()); push(a); } else { a=pop()*pop(); push(a); } } System.out.println(pop()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute top : int := 0; static attribute max : int := 110; static attribute stack : Sequence(int) := Integer.subrange(1,max)->collect(0); static operation isNum( str : String) : boolean pre: true post: true activity: ( try ( Integer.parseInt(str) ; return true ) catch (e : IncorrectElementException) do ( return false ) ); static operation initialize() : void pre: true post: true activity: ( top := 0 ); static operation isEmpty() : boolean pre: true post: true activity: ( return top = 0 ); static operation isFull() : boolean pre: true post: true activity: ( return top >= max - 1 ); static operation push( x : int) : void pre: true post: true activity: ( if (isFull()) then ( error IllegalArgumentException.newIllegalArgumentException("aa aa aa") ) else ( top := top + 1 ; stack[top+1] := x ) ); static operation pop() : int pre: true post: true activity: ( if (isEmpty()) then ( error IllegalArgumentException.newIllegalArgumentException("aa aa aa") ) else ( top := top - 1 ; return stack[top + 1+1] ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := "" ; var a : int ; while (sc.hasNext()) do ( s := sc.getCurrent() ; if (isNum(s)) then ( execute push((s)->toInteger()) ) else if (s = "+") then ( a := pop() + pop() ; execute push(a) ) else if (s = "-") then ( a := -(pop() - pop()) ; execute push(a) ) else ( a := pop() * pop() ; execute push(a) ) ; ; ) ; OclFile["System.out"].println(pop()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int getTotalXorOfSubarrayXors(int arr[],int N){ int res=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(getTotalXorOfSubarrayXors(arr, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int longestSubarray(int arr[],int n){ int i,d ; int hash[][]=new int[2][10]; for(i=0 ; i<2 ; i++)for(int j=0 ; j<10 ; j++)hash[i][j]=0 ; int currRow ; int maxLen=1 ; int len=0 ; int tmp ; tmp=arr[0]; while(tmp>0){ hash[0][tmp % 10]=1 ; tmp/=10 ; } currRow=1 ; for(i=1 ; i0){ hash[currRow][tmp % 10]=1 ; tmp/=10 ; } for(d=0 ; d<=9 ; d++){ if(hash[currRow][d]!=0 && hash[1-currRow][d]!=0){ len++; break ; } } if(d==10){ len=1 ; } maxLen=Math.max(maxLen,len); currRow=1-currRow ; } return maxLen ; } public static void main(String args[]){ int arr[]={ 11,22,33,44,54,56,63 }; int n=arr.length ; System.out.println(longestSubarray(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation longestSubarray( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var i : int ; var d : int ; var hash : Sequence(Sequence(int)) ; hash := Integer.subrange(1,2)->collect(Integer.subrange(1,10)->collect(0)) ; i := 0 ; while i < 2 do ( var j : int ; j := 0 ; while j < 10 do ( hash[i+1][j+1] := 0 ; ; j := j + 1 ) ; ; i := i + 1 ) ; var currRow : int ; var maxLen : int ; maxLen := 1 ; var len : int ; len := 0 ; var tmp : int ; tmp := arr[0+1] ; while (tmp > 0) do ( hash[0+1][tmp mod 10+1] := 1 ; tmp := tmp/(10) ) ; currRow := 1 ; i := 1 ; while i < n do ( ( tmp := arr[i+1] ; d := 0 ; while d <= 9 do ( hash[currRow+1][d+1] := 0 ; ; d := d + 1 ) ; while (tmp > 0) do ( hash[currRow+1][tmp mod 10+1] := 1 ; tmp := tmp/(10) ) ; d := 0 ; while d <= 9 do ( ( if (hash[currRow+1][d+1] /= 0 & hash[1 - currRow+1][d+1] /= 0) then ( len := len + 1 ; break ) else skip ) ; d := d + 1 ) ; if (d = 10) then ( len := 1 ) else skip ; maxLen := Set{maxLen, len}->max() ; currRow := 1 - currRow ; ) ; i := i + 1 ) ; return maxLen ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{11,22,33,44,54,56,63} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(longestSubarray(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MyClass { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; for(int i=0 ; imap=new HashMap(); for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var map : Map(long,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var sum : long ; sum := a[i+1] + a[j+1] ; map := map->union(Map{sum |-> (if map->keys()->contains(sum) then map->at(sum) else 0 endif) + 1}) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; for (key : map->keys()) do ( ( max := Set{map->at(key), max}->max() ) ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.*; public class vfe { public static void main(String[] args){ Scanner in=new Scanner(System.in); int x=in.nextInt(); int y=in.nextInt(); ArrayListlist=new ArrayList<>(); list.add(x); list.add(y); list.add(y-x); int i=2 ; while(!(list.get(i)==y && list.get(i-1)==x || list.get(i)==0 && list.get(i-1)==0)){ list.add(list.get(i)-list.get(i-1)); i++; } int k=in.nextInt(); i-=1 ; k=k % i ; if(k==0){ k=i ; } System.out.println(((list.get(k-1)% 1000000007)+1000000007)% 1000000007); } } ------------------------------------------------------------ OCL File: --------- class vfe { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; var list : Sequence(int) ; list := Sequence{} ; list := list->including(x) ; list := list->including(y) ; list := list->including(y - x) ; var i : int ; i := 2 ; while (not((list->at(i+1) = y & list->at(i - 1+1) = x or list->at(i+1) = 0 & list->at(i - 1+1) = 0))) do ( list := list->including(list->at(i+1) - list->at(i - 1+1)) ; i := i + 1 ) ; var k : int ; k := in.getCurrent()->toInteger() ; i := i-(1) ; k := k mod i ; if (k = 0) then ( k := i ) else skip ; OclFile["System.out"].println(((list->at(k - 1+1) mod 1000000007) + 1000000007) mod 1000000007) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.math.BigInteger ; import java.util.Scanner ; public class FedyaAndMaths { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Scanner in=new Scanner(System.in); BigInteger b ; BigInteger x=new BigInteger("4"); BigInteger y=new BigInteger("0"); b=in.nextBigInteger(); if(b.mod(x).equals(y))System.out.println("4"); else System.out.println("0"); } } ------------------------------------------------------------ OCL File: --------- class FedyaAndMaths { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var b : long ; var x : long ; x := long("4") ; var y : long ; y := long("0") ; b := in.nextBigInteger() ; if (b.mod(x) = y) then OclFile["System.out"].println("4") else OclFile["System.out"].println("0") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void printCubeFree(int n){ boolean[] cubFree=new boolean[n+1]; for(int i=0 ; i<=n ; i++)cubFree[i]=true ; for(int i=2 ; i*i*i<=n ; i++){ if(cubFree[i]){ for(int multiple=1 ; i*i*i*multiple<=n ; multiple++){ cubFree[i*i*i*multiple]=false ; } } } for(int i=2 ; i<=n ; i++){ if(cubFree[i]==true)System.out.print(i+" "); } } public static void main(String[] args){ printCubeFree(20); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printCubeFree( n : int) : void pre: true post: true activity: ( var cubFree : Sequence(boolean) ; cubFree := Integer.subrange(1,n + 1)->collect(false) ; var i : int ; i := 0 ; while i <= n do ( cubFree[i+1] := true ; ; i := i + 1 ) ; var i : int ; i := 2 ; while i * i * i <= n do ( ( if (cubFree[i+1]) then ( var multiple : int ; multiple := 1 ; while i * i * i * multiple <= n do ( ( cubFree[i * i * i * multiple+1] := false ) ; multiple := multiple + 1 ) ) else skip ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= n do ( ( if (cubFree[i+1] = true) then OclFile["System.out"].print(i + " ") ; else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute printCubeFree(20) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.Closeable ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.PriorityQueue ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); final int N=sc.nextInt(); for(int i=1 ; i<10000 ; i++){ int count=0 ; for(int j=1 ; j<=i ; j++){ if(i % j==0){ count++; } } if(count==N){ System.out.println(i); break ; } } } public static class Scanner implements Closeable { private BufferedReader br ; private StringTokenizer tok ; public Scanner(InputStream is)throws IOException { br=new BufferedReader(new InputStreamReader(is)); } private void getLine()throws IOException { while(! hasNext()){ tok=new StringTokenizer(br.readLine()); } } private boolean hasNext(){ return tok!=null && tok.hasMoreTokens(); } public String next()throws IOException { getLine(); return tok.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public void close()throws IOException { br.close(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i < 10000 do ( ( var count : int ; count := 0 ; var j : int ; j := 1 ; while j <= i do ( ( if (i mod j = 0) then ( count := count + 1 ) else skip ) ; j := j + 1 ) ; if (count = N) then ( OclFile["System.out"].println(i) ; break ) else skip ) ; i := i + 1 ) ); static class Scanner implements Closeable { attribute br : OclFile; attribute tok : OclIterator; static operation newScanner( is : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(is); return self ); operation initialise( is : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(is)) ); operation getLine() : void pre: true post: true activity: ( while (not(hasNext())) do ( tok := OclIterator.newOclIterator_String(br.readLine()) ) ); operation hasNext() : boolean pre: true post: true activity: ( return tok /= null & tok.hasNext() ); operation next() : String pre: true post: true activity: ( execute getLine() ; return tok.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation close() : void pre: true post: true activity: ( skip ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner sc=new Scanner(System.in); int[] ans={ 0,1,2,4,6,16,12,64,24,36,48,1024,60 }; int i=sc.nextInt(); System.out.println(ans[i]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ans : Sequence(int) ; ans := Sequence{0,1,2,4,6,16,12,64,24,36,48,1024,60} ; var i : int ; i := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(ans[i+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int N ; N=sc.nextInt(); int count=0 ; for(int i=1 ; ; ++i){ for(int j=1 ; j<=i ; ++j){ if(i % j==0){ count++; } } if(count==N){ System.out.println(i); break ; } count=0 ; } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 1 ; while true do ( ( var j : int ; j := 1 ; while j <= i do ( ( if (i mod j = 0) then ( count := count + 1 ) else skip ) ; j := j + 1 ) ; if (count = N) then ( OclFile["System.out"].println(i) ; break ) else skip ; count := 0 ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int N=scan.nextInt(); int M=scan.nextInt(); Listodd=new ArrayList<>(); Listeven=new ArrayList<>(); for(int i=0 ; i2){ System.out.println("Impossible"); return ; } Listans=new ArrayList<>(); if(odd.size()>=1){ int d=odd.remove(0); System.out.print(d+" "); while(d>1){ ans.add(2); d-=2 ; } } else { int d=even.remove(0); System.out.print(d+" "); ans.add(d-1); } for(int i=0 ; i=1){ int d=odd.remove(0); System.out.print(d+" "); while(d>0){ ans.add(2); d-=2 ; } } else { ans.add(1); } System.out.println(); System.out.println(ans.size()); for(int i : ans)System.out.print(i+" "); System.out.println(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scan.getCurrent()->toInteger() ; var M : int ; M := scan.getCurrent()->toInteger() ; var odd : Sequence(int) ; odd := Sequence{} ; var even : Sequence(int) ; even := Sequence{} ; var i : int ; i := 0 ; while i < M do ( ( var a : int ; a := scan.getCurrent()->toInteger() ; if (a mod 2 = 0) then even := even->including(a) ; else odd := odd->including(a) ; ) ; i := i + 1 ) ; if (odd->size() > 2) then ( OclFile["System.out"].println("Impossible") ; return ) else skip ; var ans : Sequence(int) ; ans := Sequence{} ; if (odd->size() >= 1) then ( var d : int ; d := odd->at(0+1) ; OclFile["System.out"].print(d + " ") ; while (d > 1) do ( ans := ans->including(2) ; d := d-(2) ) ) else ( var d : int ; d := even->at(0+1) ; OclFile["System.out"].print(d + " ") ; ans := ans->including(d - 1) ) ; var i : int ; i := 0 ; while i < even->size() do ( ( ans := ans->including(even->at(i+1)) ; OclFile["System.out"].print(even->at(i+1) + " ") ) ; i := i + 1 ) ; if (odd->size() >= 1) then ( var d : int ; d := odd->at(0+1) ; OclFile["System.out"].print(d + " ") ; while (d > 0) do ( ans := ans->including(2) ; d := d-(2) ) ) else ( ans := ans->including(1) ) ; OclFile["System.out"].println() ; OclFile["System.out"].println(ans->size()) ; for (i : ans) do ( OclFile["System.out"].print(i + " ") ; ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); ArrayListodd=new ArrayList<>(); ArrayListeven=new ArrayList<>(); for(int i=0 ; i2){ System.out.println("Impossible"); } else { ArrayListlist=new ArrayList<>(); if(odd.size()>0)list.add(odd.get(0)); list.addAll(even); if(odd.size()>1)list.add(odd.get(1)); printList(list); if(list.size()==1){ if(list.get(0)>1){ list.set(0,list.get(0)-1); list.add(1); } } else { list.set(0,list.get(0)-1); list.set(list.size()-1,list.get(list.size()-1)-1); list.add(1,2); if(list.get(0)==0)list.remove(0); if(list.get(list.size()-1)==0)list.remove(list.size()-1); } System.out.println(list.size()); printList(list); } sc.close(); } static void printList(ArrayListlist){ for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var odd : Sequence(int) ; odd := Sequence{} ; var even : Sequence(int) ; even := Sequence{} ; var i : int ; i := 0 ; while i < M do ( ( var A : int ; A := sc.getCurrent()->toInteger() ; if (A mod 2 = 0) then even := even->including(A) ; else odd := odd->including(A) ; ) ; i := i + 1 ) ; if (odd->size() > 2) then ( OclFile["System.out"].println("Impossible") ) else ( var list : Sequence(int) ; list := Sequence{} ; if (odd->size() > 0) then list := list->including(odd->at(0+1)) ; else skip ; list := list->union(even) ; if (odd->size() > 1) then list := list->including(odd->at(1+1)) ; else skip ; execute printList(list) ; if (list->size() = 1) then ( if (list->at(0+1) > 1) then ( list := list.setAt(0+1,list->at(0+1) - 1) ; list := list->including(1) ) else skip ) else ( list := list.setAt(0+1,list->at(0+1) - 1) ; list := list.setAt(list->size() - 1+1,list->at(list->size() - 1+1) - 1) ; list := list.insertAt(1+1,2) ; if (list->at(0+1) = 0) then list := list->excludingAt(0+1) ; else skip ; if (list->at(list->size() - 1+1) = 0) then list := list->excludingFirst(list->size() - 1) ; else skip ; ) ; OclFile["System.out"].println(list->size()) ; execute printList(list) ; ) ; skip ; ); static operation printList( list : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < list->size() do ( OclFile["System.out"].print(list->at(i+1) + (if i = list->size() - 1 then "\n" else " " endif)) ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int max_length_substring(String st,int n,int k){ int max_len=0 ; int len=0 ; for(int i=0 ; i1)max_len=Math.max(max_len,pref+suff); return max_len ; } public static void main(String[] args){ int n=6 ; int k=3 ; String st="110010" ; int ans=max_length_substring(st,n,k); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation max_length_substring( st : String, n : int, k : int) : int pre: true post: true activity: ( var max_len : int ; max_len := 0 ; var len : int ; len := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (st->at(i+1) = '0') then len := len + 1 else len := 0 ; ; max_len := Set{max_len, len}->max() ) ; i := i + 1 ) ; if (max_len = n) then return n * k else skip ; var pref : int ; pref := 0 ; var suff : int ; suff := 0 ; var i : int ; i := 0 ; while st->at(i+1) = '0' do ( ; i := i + 1 ; pref := pref + 1 ) ; var i : int ; i := n - 1 ; while st->at(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 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var k : int ; k := 3 ; var st : String ; st := "110010" ; var ans : int ; ans := max_length_substring(st, n, k) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Main main=new Main(); main.solve(); } public void solve(){ Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int N=scan.nextInt(); int[] a=new int[N]; for(int i=0 ; ii==max).count(); long min_count=Arrays.stream(a).filter(i->i==min).count(); if(min_counttoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var min : int ; min := stream(a).min().getAsInt() ; var max : int ; max := stream(a).max().getAsInt() ; if (N = 2) then ( OclFile["System.out"].println("Yes") ; return ) else skip ; if (2 <= max - min) then ( OclFile["System.out"].println("No") ; return ) else skip ; if (max - min = 0) then ( if (max = N - 1 or max * 2 <= N) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; return ) else skip ; var max_count : long ; max_count := stream(a)->select( _x1 | (lambda i : OclAny in i = max)->apply(_x1) )->size() ; var min_count : long ; min_count := stream(a)->select( _x1 | (lambda i : OclAny in i = min)->apply(_x1) )->size() ; if (min_count < max & 2 * (max - min_count) <= max_count) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Map ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int count=0 ; TreeMapmap=new TreeMap<>(); for(int i=0 ; isubM=map.subMap(a,true,b,true); for(Integer x : subM.keySet()){ for(int j=0 ; jtoInteger() ; var count : int ; count := 0 ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var query : int ; query := scan.getCurrent()->toInteger() ; var a : int ; a := scan.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (query) ; if _switchval = 0 then if (not(map->keys()->includes(a))) then map := map->union(Map{a |-> 1}) else map := map->union(Map{a |-> map->at(a) + 1}) ; ; count := count + 1 ; OclFile["System.out"].println(count) ; break else skip ; if _switchval = 1 then if (map->at(a) /= null) then OclFile["System.out"].println(map->at(a)) else OclFile["System.out"].println(0) ; ; break else skip ; if _switchval = 2 then if (map->at(a) /= null) then ( count := count-(map->at(a)) ; map := map->antirestrict(Set{a}) ) else skip ; break else skip ; if _switchval = 3 then var b : int ; b := scan.getCurrent()->toInteger() ; var subM : Map(int,int) ; subM := map->restrict( _key | _key < true & _key >= a ) ; for (x : subM->keys()) do ( ( var j : int ; j := 0 ; while j < map->at(x) do ( ( OclFile["System.out"].println(x) ) ; j := j + 1 ) ) ) ; break else skip ; ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Comparatorcomp=new Comparator(){ public int compare(String a,String b){ for(int i=0 ; ib.charAt(i))return 1-(i % 2)*2 ; } return 0 ; } }; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); String[] a=new String[n]; HashMapids=new HashMap(); for(int i=0 ; i,(,boolean)) := OclComparator.newOclComparator(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(String) ; a := Integer.subrange(1,n)->collect(null) ; var ids : Map(String,int) ; ids := Map{} ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent() ; ids := ids->union(Map{a[i+1] |-> i + 1}) ) ; i := i + 1 ) ; a := OclComparator.sortWith(a, comp) ; for (x : a) do ( ( OclFile["System.out"].print(ids->at(x) + " ") ) ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ DataSet d=new DataSet(); d.input(); int dif=d.max-d.min ; if(dif>1)System.out.println("No"); else if(dif==1){ if(2*(d.max-d.q)<=d.p && d.q<=d.min)System.out.println("Yes"); else System.out.println("No"); } else if(dif==0){ if(d.max==d.N-1 || 2*d.max<=d.N)System.out.println("Yes"); else System.out.println("No"); } } } class DataSet { int N ; int[] a ; int max=0,min=1000000 ; int p=0,q=0 ; public void input(){ Scanner sc=new Scanner(System.in); N=sc.nextInt(); a=new int[N]; for(int i=0 ; i 1) then OclFile["System.out"].println("No") ; else if (dif = 1) then ( if (2 * (d.max - d.q) <= d.p & d.q <= d.min) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ) else if (dif = 0) then ( if (d.max = d.N - 1 or 2 * d.max <= d.N) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ) else skip ; ; ); } class DataSet { attribute N : int; attribute a : Sequence(int); attribute max : int := 0; attribute p : int := 0; operation input() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := sc.getCurrent()->toInteger() ; a := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := sc.getCurrent()->toInteger() ; max := Set{max, a[i+1]}->max() ; min := Set{min, a[i+1]}->min() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( if (a[i+1] = max) then p := p + 1 ; else skip ; if (a[i+1] = min) then q := q + 1 ; else skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); TreeMapmap=new TreeMap(); for(int i=0 ; ikey=new ArrayList(map.keySet()); ArrayListval=new ArrayList(map.values()); int size=key.size(); if(size==1 &&((val.get(0)-1)==key.get(0)||(long)2*key.get(0)<=val.get(0)))flag=true ; if(size==2 && key.get(1)-key.get(0)==1 && val.get(0)toInteger() ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < N do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; if (map->keys()->includes(a)) then map := map->union(Map{a |-> map->at(a) + 1}) ; else map := map->union(Map{a |-> 1}) ; ) ; i := i + 1 ) ; var flag : boolean ; flag := false ; var key : Sequence(int) ; key := Sequence{}->union(map->keys()) ; var val : Sequence(int) ; val := Sequence{}->union(map->values()) ; var size : int ; size := key->size() ; if (size = 1 & ((val->at(0+1) - 1) = key->at(0+1) or 2->oclAsType(long) * key->at(0+1) <= val->at(0+1))) then flag := true ; else skip ; if (size = 2 & key->at(1+1) - key->at(0+1) = 1 & val->at(0+1) < key->at(1+1) & 2 * (key->at(1+1) - val->at(0+1)) <= val->at(1+1)) then flag := true ; else skip ; if (flag) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static double Probability(double p[],int n){ double[][] dp=new double[n+1][n+1]; dp[0][0]=1.0 ; for(int i=1 ; i<=n ; i+=1){ for(int j=0 ; j<=i ; j+=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]; } } double ans=0.0 ; for(int i=(n+1)/2 ; i<=n ; i+=1)ans+=dp[n][i]; return ans ; } public static void main(String[] args){ double p[]={ 0.0,0.3,0.4,0.7 }; int n=p.length-1 ; System.out.println(Probability(p,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Probability( p : Sequence(double), n : int) : double pre: true post: true activity: ( var dp : Sequence(Sequence(double)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0.0)) ; dp[0+1][0+1] := 1.0 ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 0 ; while j <= i 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] ; ) ; j := j+(1) ) ) ; i := i+(1) ) ; var ans : double ; ans := 0.0 ; var i : int ; i := (n + 1) / 2 ; while i <= n do ( ans := ans+(dp[n+1][i+1]) ; ; i := i+(1) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var p : Sequence(double) ; p := Sequence{0.0,0.3,0.4,0.7} ; var n : int ; n := p->size() - 1 ; OclFile["System.out"].println(Probability(p, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner in=new Scanner(new File("Main.in")); PrintWriter out=new PrintWriter(new File("Main.out")); int tests=in.nextInt(); final int MOD=100003 ; int[][] f=new int[512][512]; for(int m=0 ; m<512 ; m++)f[0][m]=1 ; for(int n=1 ; n<512 ; n++){ for(int m=1 ; m<=n ; m++){ f[n][m]=0 ; for(int k=1 ; k<=m ; k++){ f[n][m]=(f[n][m]+f[n-k][m])% MOD ; } } } for(int i=0 ; i<10 ; i++){ for(int j=0 ; j<10 ; j++)System.out.print(f[i][j]+" "); System.out.println(); } for(int test=1 ; test<=tests ; test++){ out.print("Case #"+test+": "); int n=in.nextInt(); int ans=0 ; for(int h=2 ; h<=n ; h++)ans=(ans+f[n-1][h-1])% MOD ; out.println(ans); } out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile("Main.in")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile("Main.out")) ; var tests : int ; tests := in.getCurrent()->toInteger() ; var MOD : int ; MOD := 100003 ; var f : Sequence(Sequence(int)) ; f := Integer.subrange(1,512)->collect(Integer.subrange(1,512)->collect(0)) ; var m : int ; m := 0 ; while m < 512 do ( f[0+1][m+1] := 1 ; ; m := m + 1 ) ; var n : int ; n := 1 ; while n < 512 do ( ( var m : int ; m := 1 ; while m <= n do ( ( f[n+1][m+1] := 0 ; var k : int ; k := 1 ; while k <= m do ( ( f[n+1][m+1] := (f[n+1][m+1] + f[n - k+1][m+1]) mod MOD ) ; k := k + 1 ) ) ; m := m + 1 ) ) ; n := n + 1 ) ; var i : int ; i := 0 ; while i < 10 do ( ( var j : int ; j := 0 ; while j < 10 do ( OclFile["System.out"].print(f[i+1][j+1] + " ") ; ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; var test : int ; test := 1 ; while test <= tests do ( ( skip ; var n : int ; n := in.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var h : int ; h := 2 ; while h <= n do ( ans := (ans + f[n - 1+1][h - 1+1]) mod MOD ; ; h := h + 1 ) ; skip ; ) ; test := test + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class x { static final int MOD=100003 ; static final int MAXN=500 ; public static void main(String args[])throws Exception { Scanner in=new Scanner(System.in); int t=in.nextInt(); int[][] C=new int[MAXN+1][MAXN+1]; for(int i=0 ; i<=MAXN ; i++){ C[i][0]=1 ; for(int j=1 ; j<=i ; j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])% MOD ; } } int[][] D=new int[MAXN+1][MAXN+1]; int[] A=new int[MAXN+1]; D[1][0]=1 ; for(int i=2 ; i<=MAXN ; i++){ for(int j=1 ; j=0 && j-k-1<=i-j-1){ long cur=D[j][k]; cur=(D[i][j]+cur*C[i-j-1][j-k-1])% MOD ; D[i][j]=(int)cur ; } A[i]=(A[i]+D[i][j])% MOD ; } } for(int tt=1 ; tt<=t ; tt++){ int n=in.nextInt(); System.out.println("Case #"+tt+": "+A[n]); }; }; }; ------------------------------------------------------------ OCL File: --------- class x { static attribute MOD : int := 100003; static attribute MAXN : int := 500; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var C : Sequence(Sequence(int)) ; C := Integer.subrange(1,MAXN + 1)->collect(Integer.subrange(1,MAXN + 1)->collect(0)) ; var i : int ; i := 0 ; while i <= MAXN do ( ( C[i+1][0+1] := 1 ; var j : int ; j := 1 ; while j <= i do ( ( C[i+1][j+1] := (C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]) mod MOD ) ; j := j + 1 ) ) ; i := i + 1 ) ; var D : Sequence(Sequence(int)) ; D := Integer.subrange(1,MAXN + 1)->collect(Integer.subrange(1,MAXN + 1)->collect(0)) ; var A : Sequence(int) ; A := Integer.subrange(1,MAXN + 1)->collect(0) ; D[1+1][0+1] := 1 ; var i : int ; i := 2 ; while i <= MAXN do ( ( var j : int ; j := 1 ; while j < i do ( ( var k : int ; k := 0 ; while k < j do ( if (j - k - 1 >= 0 & j - k - 1 <= i - j - 1) then ( var cur : long ; cur := D[j+1][k+1] ; cur := (D[i+1][j+1] + cur * C[i - j - 1+1][j - k - 1+1]) mod MOD ; D[i+1][j+1] := cur->oclAsType(int) ) else skip ; ; k := k + 1 ) ; A[i+1] := (A[i+1] + D[i+1][j+1]) mod MOD ) ; j := j + 1 ) ) ; i := i + 1 ) ; var tt : int ; tt := 1 ; while tt <= t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; OclFile["System.out"].println("Case #" + tt + ": " + A[n+1]) ) ; tt := tt + 1 ) ; ); } ; ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.io.BufferedReader ; import java.io.File ; import java.io.FileInputStream ; import java.io.FileNotFoundException ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintStream ; import java.io.FileOutputStream ; public class Main { public static void main(String[] args){ try { File file=new File("C-large.in"); FileInputStream fis=new FileInputStream(file); BufferedInputStream bis=new BufferedInputStream(fis); BufferedReader dis=new BufferedReader(new InputStreamReader(bis)); File ofile=new File("C-large.out"); if(! ofile.exists()){ ofile.createNewFile(); } PrintStream out=new PrintStream(new FileOutputStream(ofile)); int[][] f=new int[501][501]; for(int i=0 ; i<501 ; i++){ for(int j=0 ; j<501 ; j++){ if(i==0){ f[i][j]=1 ; } else { for(int k=1 ; k<=j ; k++){ if(k>i)break ; f[i][j]+=f[i-k][j]; } f[i][j] %=100003 ; } } } int[] f2=new int[501]; for(int i=1 ; i<501 ; i++){ for(int j=0 ; j<=i ; j++){ f2[i]+=f[j][i-j]; f2[i] %=100003 ; } } int T=Integer.parseInt(dis.readLine()); int c=0 ; while(c++collect(Integer.subrange(1,501)->collect(0)) ; var i : int ; i := 0 ; while i < 501 do ( ( var j : int ; j := 0 ; while j < 501 do ( ( if (i = 0) then ( f[i+1][j+1] := 1 ) else ( var k : int ; k := 1 ; while k <= j do ( ( if (k > i) then break else skip ; f[i+1][j+1] := f[i+1][j+1]+(f[i - k+1][j+1]) ) ; k := k + 1 ) ; f[i+1][j+1] := f[i+1][j+1] mod 100003 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var f2 : Sequence(int) ; f2 := Integer.subrange(1,501)->collect(0) ; var i : int ; i := 1 ; while i < 501 do ( ( var j : int ; j := 0 ; while j <= i do ( ( f2[i+1] := f2[i+1]+(f[j+1][i - j+1]) ; f2[i+1] := f2[i+1] mod 100003 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var T : int ; T := (dis.readLine())->toInteger() ; var c : int ; c := 0 ; while (c < T) do ( c := c + 1 ; skip ; ( skip ; skip ) ; ) ; skip ; skip ; skip ; ) catch (e : FileNotFoundException) do ( e.printStackTrace() ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class C { public static void main(String[] args){ BigInteger[][] combine=new BigInteger[512][512]; BigInteger[][] a=new BigInteger[512][512]; BigInteger[] s=new BigInteger[512]; for(int i=0 ; i<512 ; i++){ combine[i][0]=BigInteger.ONE ; combine[i][i]=BigInteger.ONE ; for(int j=1 ; j=0 && M<=N){ a[n][m]=a[n][m] .add(combine[N][M] .multiply(a[m][k])); } } } for(int m=1 ; mcollect(Integer.subrange(1,512)->collect(null)) ; var a : Sequence(Sequence(long)) ; a := Integer.subrange(1,512)->collect(Integer.subrange(1,512)->collect(null)) ; var s : Sequence(long) ; s := Integer.subrange(1,512)->collect(null) ; var i : int ; i := 0 ; while i < 512 do ( ( combine[i+1][0+1] := 1 ; combine[i+1][i+1] := 1 ; var j : int ; j := 1 ; while j < i do ( ( combine[i+1][j+1] := combine[i - 1+1][j+1]->excludes(combine[i - 1+1][j - 1+1]) ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < 512 do ( a[i+1][j+1] := 0 ; ; j := j + 1 ) ; s[i+1] := 0 ; ) ; i := i + 1 ) ; var n : int ; n := 2 ; while n < 512 do ( ( a[n+1][1+1] := 1 ; var m : int ; m := 2 ; while m < n do ( ( a[n+1][m+1] := 0 ; var k : int ; k := 1 ; while k < m do ( ( var N : int ; N := n - m - 1 ; var M : int ; M := m - k - 1 ; if (M >= 0 & M <= N) then ( a[n+1][m+1] := a[n+1][m+1]->excludes(combine[N+1][M+1].multiply(a[m+1][k+1])) ) else skip ) ; k := k + 1 ) ) ; m := m + 1 ) ; var m : int ; m := 1 ; while m < n do ( ( s[n+1] := s[n+1]->excludes(a[n+1][m+1]) ) ; m := m + 1 ) ) ; n := n + 1 ) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tests : int ; tests := sc.getCurrent()->toInteger() ; var cas : int ; cas := 1 ; while cas <= tests do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println("Case #" + cas + ": " + (s[n+1].mod((100003 + "")->toLong()))) ) ; cas := cas + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class C implements Runnable { private String IFILE="C-large.in" ; private Scanner in ; private PrintWriter out ; private int MOD=100003 ; public void Run()throws IOException { in=new Scanner(new File(IFILE)); out=new PrintWriter("output.txt"); int ntest=in.nextInt(); for(int test=1 ; test<=ntest ; test++){ out.print("Case #"+test+": "); int n=in.nextInt(); long[][] c=new long[n+1][n+1]; c[0][0]=1 ; for(int j=1 ; j<=n ; j++){ c[0][j]=1 ; for(int i=1 ; i<=n ; i++)c[i][j]=(c[i-1][j-1]+c[i][j-1])% MOD ; } long[][] mas=new long[n+1][n+1]; for(int j=2 ; j<=n ; j++)mas[1][j]=1 ; for(int i=2 ; i<=n ; i++)for(int j=i+1 ; j<=n ; j++){ for(int k=1 ; ktoInteger() ; var test : int ; test := 1 ; while test <= ntest do ( ( skip ; var n : int ; n := in.getCurrent()->toInteger() ; var c : Sequence(Sequence(long)) ; c := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; c[0+1][0+1] := 1 ; var j : int ; j := 1 ; while j <= n do ( ( c[0+1][j+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( c[i+1][j+1] := (c[i - 1+1][j - 1+1] + c[i+1][j - 1+1]) mod MOD ; ; i := i + 1 ) ) ; j := j + 1 ) ; var mas : Sequence(Sequence(long)) ; mas := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var j : int ; j := 2 ; while j <= n do ( mas[1+1][j+1] := 1 ; ; j := j + 1 ) ; var i : int ; i := 2 ; while i <= n do ( var j : int ; j := i + 1 ; while j <= n do ( ( var k : int ; k := 1 ; while k < i do ( ( mas[i+1][j+1] := (mas[i+1][j+1] + mas[k+1][i+1] * c[j - i - 1+1][i - k - 1+1]) mod MOD ) ; k := k + 1 ) ) ; j := j + 1 ) ; ; i := i + 1 ) ; var result : long ; result := 0 ; var i : int ; i := 1 ; while i <= n do ( result := (result + mas[i+1][n+1]) mod MOD ; ; i := i + 1 ) ; skip ; ) ; test := test + 1 ) ; skip ; skip ; ); operation run() : void pre: true post: true activity: ( try ( execute Run() ) catch (e : IOException) do skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( C.newC().Run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Count { public static void main(String args[]){ String str="#GeeKs01fOr@gEEks07" ; int upper=0,lower=0,number=0,special=0 ; for(int i=0 ; i='A' && ch<='Z')upper++; else if(ch>='a' && ch<='z')lower++; else if(ch>='0' && ch<='9')number++; else special++; } System.out.println("Lower case letters : "+lower); System.out.println("Upper case letters : "+upper); System.out.println("Number : "+number); System.out.println("Special characters : "+special); } } ------------------------------------------------------------ OCL File: --------- class Count { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "#GeeKs01fOr@gEEks07" ; var upper : int ; upper := 0 ; var lower : int ; lower := 0 ; var number : int ; number := 0 ; var special : int ; special := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( var ch : String ; ch := str->at(i+1) ; if (ch >= 'A' & ch <= 'Z') then upper := upper + 1 ; else if (ch >= 'a' & ch <= 'z') then lower := lower + 1 else if (ch >= '0' & ch <= '9') then number := number + 1 else special := special + 1 ; ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println("Lower case letters : " + lower) ; OclFile["System.out"].println("Upper case letters : " + upper) ; OclFile["System.out"].println("Number : " + number) ; OclFile["System.out"].println("Special characters : " + special) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args){ FastScanner sc=new FastScanner(); PrintWriter pw=new PrintWriter(System.out); int Q=sc.ni(); for(int q=0 ; q=4*B)ans=1-B/A ; else ans=0.5+A/(16*B); pw.println(ans); } pw.close(); } static class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int ni(){ return Integer.parseInt(next()); } long nl(){ return Long.parseLong(next()); } double nd(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastScanner ; sc := FastScanner.newFastScanner() ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var Q : int ; Q := sc.ni() ; var q : int ; q := 0 ; while q < Q do ( ( var A : double ; A := sc.nd() ; var B : double ; B := sc.nd() ; var ans : double ; ans := 0 ; if (A = 0 & B = 0) then ans := 1 else if (A >= 4 * B) then ans := 1 - B / A else ans := 0.5 + A / (16 * B) ; ; ; skip ; ) ; q := q + 1 ) ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation ni() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nl() : long pre: true post: true activity: ( return (next())->toLong() ); operation nd() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class modmath { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String n=scan.next(); if(n.length()>3){ int a=Integer.parseInt(n.substring(n.length()-2,n.length())); if(a % 4==0){ System.out.println(4); } else { System.out.println(0); } } else { int b=Integer.parseInt(n); if(b % 4==0){ System.out.println(4); } else { System.out.println(0); } } } } ------------------------------------------------------------ OCL File: --------- class modmath { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : String ; n := scan.getCurrent() ; if (n->size() > 3) then ( var a : int ; a := (n.subrange(n->size() - 2+1,n->size()))->toInteger() ; if (a mod 4 = 0) then ( OclFile["System.out"].println(4) ) else ( OclFile["System.out"].println(0) ) ) else ( var b : int ; b := (n)->toInteger() ; if (b mod 4 = 0) then ( OclFile["System.out"].println(4) ) else ( OclFile["System.out"].println(0) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); TreeMapmset=new TreeMap<>(); int q=Integer.parseInt(in.next()),size=0 ; for(int i=0 ; isub=mset.subMap(L,true,R,true); Iterator>itr=sub.entrySet().iterator(); while(itr.hasNext()){ NavigableMap.Entryget=itr.next(); int k=get.getKey(),num=get.getValue(); for(int j=0 ; jtoInteger() ; var size : int ; size := 0 ; var i : int ; i := 0 ; while i < q do ( ( var odr : int ; odr := (in.getCurrent())->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (odr) ; if _switchval = 0 then var x0 : int ; x0 := (in.getCurrent())->toInteger() ; var num0 : int ; num0 := mset->at(x0) ; if (num0 /= null) then mset := mset->union(Map{x0 |-> num0 + 1}) else mset := mset->union(Map{x0 |-> 1}) ; ; size := size + 1 ; skip ; break else skip ; if _switchval = 1 then var x1 : int ; x1 := (in.getCurrent())->toInteger() ; var num1 : int ; num1 := mset->at(x1) ; skip ; break else skip ; if _switchval = 2 then var x2 : int ; x2 := (in.getCurrent())->toInteger() ; var num2 : int ; num2 := mset->at(x2) ; if (num2 /= null) then size := size-(num2) ; else skip ; mset := mset->antirestrict(Set{x2}) ; break else skip ; if _switchval = 3 then var L : int ; L := (in.getCurrent())->toInteger() ; var R : int ; R := (in.getCurrent())->toInteger() ; var sub : NavigableMap ; sub := mset->restrict( _key | _key < true & _key >= L ) ; var itr : OclIterator ; itr := sub->asSet()->iterator() ; while (itr.hasNext()) do ( var get : Entry ; get := itr.next() ; var k : int ; k := get.getKey() ; var num : int ; num := get.getValue() ; var j : int ; j := 0 ; while j < num do ( skip ; ; j := j + 1 ) ) ; break else skip ; ) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MAX=100000 ; static int bitscount=32 ; static int[][] prefix_count=new int[bitscount][MAX]; static void findPrefixCount(int arr[],int n){ for(int i=0 ; i>i)& 1); for(int j=1 ; j>i)& 1); prefix_count[i][j]+=prefix_count[i][j-1]; } } } static int rangeOr(int l,int r){ int ans=0 ; for(int i=0 ; icollect(Integer.subrange(1,MAX)->collect(0)); static operation findPrefixCount( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < bitscount do ( ( prefix_count[i+1][0+1] := (((arr[0+1]/(2->pow(i)))->oclAsType(long)) & 1) ; var j : int ; j := 1 ; while j < n do ( ( prefix_count[i+1][j+1] := (((arr[j+1]/(2->pow(i)))->oclAsType(long)) & 1) ; prefix_count[i+1][j+1] := prefix_count[i+1][j+1]+(prefix_count[i+1][j - 1+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation rangeOr( l : int, r : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < bitscount do ( ( var x : int ; 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)))->oclAsType(long)))) ; else skip ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{7,5,3,5,2,3} ; var n : int ; n := arr->size() ; execute findPrefixCount(arr, n) ; var queries : Sequence(Sequence(int)) ; queries := Sequence{Sequence{1,3},Sequence{4,5}} ; var q : int ; q := queries->size() ; var i : int ; i := 0 ; while i < q do ( OclFile["System.out"].println(rangeOr(queries[i+1][0+1], queries[i+1][1+1])) ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MAX=100000 ; static int bitscount=32 ; static int[][] prefix_count=new int[bitscount][MAX]; static void findPrefixCount(int arr[],int n){ for(int i=0 ; i>i)& 1); for(int j=1 ; j>i)& 1); prefix_count[i][j]+=prefix_count[i][j-1]; } } } static int rangeAnd(int l,int r){ int ans=0 ; for(int i=0 ; icollect(Integer.subrange(1,MAX)->collect(0)); static operation findPrefixCount( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < bitscount do ( ( prefix_count[i+1][0+1] := (((arr[0+1]/(2->pow(i)))->oclAsType(long)) & 1) ; var j : int ; j := 1 ; while j < n do ( ( prefix_count[i+1][j+1] := (((arr[j+1]/(2->pow(i)))->oclAsType(long)) & 1) ; prefix_count[i+1][j+1] := prefix_count[i+1][j+1]+(prefix_count[i+1][j - 1+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation rangeAnd( l : int, r : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < bitscount do ( ( var x : int ; 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)))->oclAsType(long)))) ; else skip ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{7,5,3,5,2,3} ; var n : int ; n := arr->size() ; execute findPrefixCount(arr, n) ; var queries : Sequence(Sequence(int)) ; queries := Sequence{Sequence{1,3},Sequence{4,5}} ; var q : int ; q := queries->size() ; var i : int ; i := 0 ; while i < q do ( OclFile["System.out"].println(rangeAnd(queries[i+1][0+1], queries[i+1][1+1])) ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var m : int ; m := sc.getCurrent()->toInteger() ; var v : int ; v := sc.getCurrent()->toInteger() ; var res : long ; res := 0 ; var arr : Sequence(int) ; arr := Integer.subrange(1,m)->collect(0) ; var i1 : int ; i1 := 0 ; while i1 < m do ( ( arr[i1+1] := sc.getCurrent()->toInteger() ; res := res+(arr[i1+1]) ) ; i1 := i1 + 1 ) ; var p : int ; p := v ; var flag : boolean ; flag := true ; while (flag) do ( var i1 : int ; i1 := 0 ; while i1 < m do ( ( if (arr[i1+1] mod v = 0) then ( var a : int ; a := arr[i1+1] / v ; res := res+((a->oclAsType(long) * p)) ; arr[i1+1] := a ) else ( flag := false ; break ) ) ; i1 := i1 + 1 ) ; p := p*(v) ) ; OclFile["System.out"].println(res) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { private void solve(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); Listtasks=new ArrayList(); for(int i=0 ; ia.deadLine-b.deadLine); long timeSum=0 ; String ans="Yes" ; for(Task task : tasks){ timeSum+=task.timeToTake ; if(timeSum>task.deadLine){ ans="No" ; break ; } } System.out.print(ans); } class Task { int timeToTake ; int deadLine ; Task(int timeToTake,int deadLine){ this.timeToTake=timeToTake ; this.deadLine=deadLine ; } } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var tasks : Sequence(Task) ; tasks := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; tasks := tasks->including(Task.newTask(A, B)) ) ; i := i + 1 ) ; tasks := tasks.sort(lambda (a , b) : OclAny in a.deadLine - b.deadLine) ; var timeSum : long ; timeSum := 0 ; var ans : String ; ans := "Yes" ; for (task : tasks) do ( ( timeSum := timeSum+(task.timeToTake) ; if (timeSum > task.deadLine) then ( ans := "No" ; break ) else skip ) ) ; OclFile["System.out"].print(ans) ; ); class Task { attribute timeToTake : int; attribute deadLine : int; static operation newTask( timeToTake : int, deadLine : int) : Task pre: true post: true activity: ( var self : Task ; self := createTask(); self.initialise(timeToTake, deadLine); return self ); operation initialise( timeToTake : int, deadLine : int) : void pre: true post: true activity: ( self.timeToTake := timeToTake ; self.deadLine := deadLine ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Objects ; import java.util.Scanner ; import java.util.Comparator ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); DMegalomania solver=new DMegalomania(); solver.solve(1,in,out); out.close(); } static class DMegalomania { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); ArrayList>alp=new ArrayList<>(); for(int i=0 ; i(in.nextInt(),in.nextInt())); } alp.sort(Comparator.comparing(p->p.u)); int time=0 ; for(Pairp : alp){ if(time+p.t>p.u){ out.println("No"); return ; } time+=p.t ; } out.println("Yes"); } } static class Pair{ public T t ; public U u ; public Pair(T t,U u){ this.t=t ; this.u=u ; } public String toString(){ return "Pair{"+"t="+t.toString()+",u="+u.toString()+'}' ; } public boolean equals(Object o){ if(this==o)return true ; if(o==null || getClass()!=o.getClass())return false ; Pairpair=(Pair)o ; return Objects.equals(t,pair.t)&& Objects.equals(u,pair.u); } public int hashCode(){ return Objects.hash(t,u); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : DMegalomania ; solver := DMegalomania.newDMegalomania() ; solver.solve(1, in, out) ; skip ; ); static class DMegalomania { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var alp : Sequence(Map(String,OclAny)) ; alp := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( alp := alp->including(Tuple(in.getCurrent()->toInteger(), in.getCurrent()->toInteger())) ) ; i := i + 1 ) ; alp := alp.sort(Comparator.comparing(lambda p : OclAny in p.u)) ; var time : int ; time := 0 ; for (p : alp) do ( ( if (time + p.t > p.u) then ( skip ; return ) else skip ; time := time+(p.t) ) ) ; skip ; ); } static class Pair { attribute t : T; attribute u : U; static operation newPair( t : T, u : U) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(t, u); return self ); operation initialise( t : T, u : U) : void pre: true post: true activity: ( self.t := t ; self.u := u ); operation toString() : String pre: true post: true activity: ( return "Pair{" + "t=" + t+"" + ",u=" + u+"" + '}' ); operation equals( o : OclAny) : boolean pre: true post: true activity: ( if (self = o) then return true else skip ; if (o = null or getClass() /= o->oclType()) then return false else skip ; var pair : Map(String,OclAny) ; pair := o->oclAsType(Map(String,OclAny)) ; return Objects = t, pair.t & Objects = u, pair.u ); operation hashCode() : int pre: true post: true activity: ( return Objects.hash(t, u) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ MyScanner sc=new MyScanner(); int n=sc.nextInt(); PriorityQueuequeue=new PriorityQueue<>(new Comparator(){ @ Override public int compare(Task o1,Task o2){ return Integer.compare(o1.b,o2.b); } } ); for(int i=0 ; itask.b){ isFinish=false ; break ; } } System.out.println(isFinish ? "Yes" : "No"); } static class Task { int a,b ; Task(int a,int b){ this.a=a ; this.b=b ; } } static class MyScanner { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in),1<<15); StringTokenizer tokenizer ; String next(){ try { while(tokenizer==null || ! tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } } catch(IOException ignored){ } return tokenizer.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : MyScanner ; sc := MyScanner.newMyScanner() ; var n : int ; n := sc.nextInt() ; var queue : Sequence(Task) ; queue := Sequence{}->union(OclComparator.newOclComparator()) ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.nextInt() ; var b : int ; b := sc.nextInt() ; queue := queue->including(Task.newTask(a, b)) ) ; i := i + 1 ) ; var isFinish : boolean ; isFinish := true ; var time : int ; time := 0 ; while (not(queue->isEmpty())) do ( var task : Task ; task := queue->min() ; time := time+(task.a) ; if (time > task.b) then ( isFinish := false ; break ) else skip ) ; OclFile["System.out"].println(if isFinish then "Yes" else "No" endif) ; ); static class Task { attribute a : int; static operation newTask( a : int, b : int) : Task pre: true post: true activity: ( var self : Task ; self := createTask(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( self.a := a ; self.b := b ); } static class MyScanner { attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), (1*(2->pow(15)))->oclAsType(long)); attribute tokenizer : OclIterator; operation next() : String pre: true post: true activity: ( try ( while (tokenizer = null or not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (ignored : IOException) do skip return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Map ; import java.util.TreeMap ; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); Mapmap=new TreeMap<>(); for(int i=0 ; idist){ System.out.println("No"); return ; } left+=map.get((int)key[count]); count++; } System.out.println("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var map : Map(int,long) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var str : Sequence(String) ; str := br.readLine()->split(" ") ; var a : int ; a := (str[0+1])->toInteger() ; var b : int ; b := (str[1+1])->toInteger() ; if (map->keys()->includes(b)) then map := map->union(Map{b |-> map->at(b) + a}) ; else map := map->union(Map{b |-> (a)->char2byte()}) ; ) ; i := i + 1 ) ; var key : Sequence(OclAny) ; key := map->keys()->asSequence() ; var count : int ; count := 0 ; var left : long ; left := 0 ; for (i : map->values()) do ( ( if (key[count+1]->oclAsType(int) < i) then ( OclFile["System.out"].println("No") ; return ) else skip ; var dist : long ; dist := key[count+1]->oclAsType(int) - left ; if (map->at(key[count+1]->oclAsType(int)) > dist) then ( OclFile["System.out"].println("No") ; return ) else skip ; left := left+(map->at(key[count+1]->oclAsType(int))) ; count := count + 1 ; ) ) ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.*; public class Main { public static void main(String[] args){ solve(System.in,System.out); } private static class Task { long weight ; long deadline ; } static void solve(InputStream is,PrintStream os){ Scanner sc=new Scanner(is); long n=sc.nextLong(); Listtasks=new ArrayList<>(); for(int i=0 ; it.deadline)); long current=0 ; for(int i=0 ; itoLong() ; var tasks : Sequence(Task) ; tasks := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var task : Task ; task := Task.newTask() ; task.weight := sc.getCurrent()->toLong() ; task.deadline := sc.getCurrent()->toLong() ; tasks := tasks->including(task) ) ; i := i + 1 ) ; tasks := tasks.sort(Comparator.comparingLong(lambda t : OclAny in t.deadline)) ; var current : long ; current := 0 ; var i : int ; i := 0 ; while i < n do ( ( var task : Task ; task := tasks->at(i+1) ; current := current+(task.weight) ; if (task.deadline < current) then ( os.println("No") ; return ) else skip ) ; i := i + 1 ) ; os.println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printArr(int arr[],int n){ for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[(MathLib.random() * m)->oclAsType(int)+1] := arr[(MathLib.random() * m)->oclAsType(int)+1] + 1 ) ; i := i + 1 ) ; execute printArr(arr, m) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : int ; m := 4 ; var n : int ; n := 8 ; execute randomList(m, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class cf456B { public static void main(String[] args){ Scanner scan=new Scanner(System.in); BigInteger b ; BigInteger x=new BigInteger("4"); BigInteger y=new BigInteger("0"); b=scan.nextBigInteger(); if(b.mod(x).equals(y)){ System.out.println("4"); } else { System.out.println("0"); } } } ------------------------------------------------------------ OCL File: --------- class cf456B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var b : long ; var x : long ; x := long("4") ; var y : long ; y := long("0") ; b := scan.nextBigInteger() ; if (b.mod(x) = y) then ( OclFile["System.out"].println("4") ) else ( OclFile["System.out"].println("0") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForces578B { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int k=input.nextInt(); int x=input.nextInt(); int[] a=new int[n]; for(int i=0 ; i=0 ; --i)suff[i]=suff[i+1] | a[i]; int powerX=1 ; for(int i=0 ; i0)cur |=pref[i-1]; if(itoInteger() ; var k : int ; k := input.getCurrent()->toInteger() ; var x : int ; x := input.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ; var pref : Sequence(long) ; pref := Integer.subrange(1,n)->collect(0) ; var suff : Sequence(long) ; suff := Integer.subrange(1,n)->collect(0) ; pref[0+1] := a[0+1] ; var i : int ; i := 1 ; while i < n do ( pref[i+1] := pref[i - 1+1] or a[i+1] ; ; i := i + 1 ) ; suff[n - 1+1] := a[n - 1+1] ; var i : int ; i := n - 2 ; while i >= 0 do ( suff[i+1] := suff[i + 1+1] or a[i+1] ; ; i := i - 1 ) ; var powerX : int ; powerX := 1 ; var i : int ; i := 0 ; while i < k do ( powerX := powerX*(x) ; ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var cur : long ; cur := a[i+1]->oclAsType(long) * powerX ; if (i > 0) then cur := MathLib.bitwiseOr(cur, pref[i - 1+1]) ; else skip ; if (i < n - 1) then cur := MathLib.bitwiseOr(cur, suff[i + 1+1]) ; else skip ; ans := Set{ans, cur}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.HashSet ; import java.util.Map ; import java.util.Scanner ; import java.util.Set ; import java.util.SortedMap ; import java.util.SortedSet ; import java.util.TreeMap ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int q=sc.nextInt(); int count=0 ; TreeMapmap=new TreeMap<>(); StringBuilder sb=new StringBuilder(); for(int i=0 ; isubset=map.subMap(y,z).keySet(); for(int num : subset){ int end=map.get(num); for(int j=0 ; jtoInteger() ; var count : int ; count := 0 ; var map : Map(int,int) ; map := Map{} ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < q do ( ( var op : int ; op := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (op) ; if _switchval = 0 then if (not(map->keys()->includes(y))) then ( map := map->union(Map{y |-> 1}) ) else ( map := map->union(Map{y |-> map->at(y) + 1}) ) ; sb := sb + StringLib.newString((count + 1)) ; sb := sb + StringLib.newString(' ') ; break else skip ; if _switchval = 1 then if (map->keys()->includes(y)) then ( sb := sb + StringLib.newString(map->at(y)) ) else ( sb := sb + StringLib.newString('0') ) ; sb := sb + StringLib.newString(' ') ; break else skip ; if _switchval = 2 then if (map->keys()->includes(y)) then ( var num2 : int ; num2 := map->at(y) ; map := map->antirestrict(Set{y}) ; count := count-(num2) ) else skip ; break else skip ; if _switchval = 3 then var z : int ; z := sc.getCurrent()->toInteger() + 1 ; var subset : Set(int) ; subset := map->restrict( _key | _key < z & _key >= y ).keySet() ; for (num : subset) do ( ( var end : int ; end := map->at(num) ; var j : int ; j := 0 ; while j < end do ( ( sb := sb + StringLib.newString(num) ; sb := sb + StringLib.newString(' ') ) ; j := j + 1 ) ) ) ; break else skip ; ) ) ; i := i + 1 ) ; OclFile["System.out"].print(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.util.Arrays ; import java.util.Scanner ; import java.util.StringTokenizer ; public class p013 { public static void main(String args[])throws Exception { StringTokenizer stok=new StringTokenizer(new Scanner(System.in).useDelimiter("\\A").next()); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(stok.nextToken()); int k=Integer.parseInt(stok.nextToken()); long x=Long.parseLong(stok.nextToken()); long[] a=new long[n]; for(int i=0 ; i=1 ; i--)sf[i]=a[i-1] | sf[i+1]; long max=Integer.MIN_VALUE ; for(int i=1 ; i<=n ; i++)max=Math.max(max,pf[i-1] | sf[i+1] |(a[i-1]*xp[k])); System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class p013 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stok : OclIterator ; stok := OclIterator.newOclIterator_String(OclFile.newOclFile_Read(OclFile["System.in"]).useDelimiter("\\A").next()) ; var sb : String ; sb := StringLib.newString() ; var n : int ; n := (stok.next())->toInteger() ; var k : int ; k := (stok.next())->toInteger() ; var x : long ; x := (stok.next())->toLong() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (stok.next())->toLong() ) ; i := i + 1 ) ; var xp : Sequence(long) ; xp := Integer.subrange(1,k + 1)->collect(0) ; xp[0+1] := 1 ; var i : int ; i := 1 ; while i <= k do ( xp[i+1] := x * xp[i - 1+1] ; ; i := i + 1 ) ; var pf : Sequence(long) ; pf := Integer.subrange(1,n + 2)->collect(0) ; var sf : Sequence(long) ; sf := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( pf[i+1] := a[i - 1+1] or pf[i - 1+1] ; ; i := i + 1 ) ; var i : int ; i := n ; while i >= 1 do ( sf[i+1] := a[i - 1+1] or sf[i + 1+1] ; ; i := i - 1 ) ; var max : long ; max := -2147483648 ; var i : int ; i := 1 ; while i <= n do ( max := Set{max, pf[i - 1+1] or sf[i + 1+1] or (a[i - 1+1] * xp[k+1])}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); char[][] m=new char[h][]; for(int i=0 ; i0 && m[i][j-1]!='-')continue ; if(j=h || j2<0 || j2>=w)continue ; if(m[i2][j2]=='x')continue LOOP ; } } ans++; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var m : Sequence(Sequence(String)) ; m := Integer.subrange(1,h)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < h do ( ( m[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( if (m[i+1][j+1] /= '-') then continue else skip ; if (j > 0 & m[i+1][j - 1+1] /= '-') then continue else skip ; if (j < w - 1 & m[i+1][j + 1+1] /= '-') then continue else skip ; var i1 : int ; i1 := -1 ; while i1 <= 1 do ( ( var j1 : int ; j1 := -1 ; while j1 <= 1 do ( ( var i2 : int ; i2 := i + i1 ; var j2 : int ; j2 := j + j1 ; if (i2 < 0 or i2 >= h or j2 < 0 or j2 >= w) then continue else skip ; if (m[i2+1][j2+1] = 'x') then continue else skip ) ; j1 := j1 + 1 ) ) ; i1 := i1 + 1 ) ; ans := ans + 1 ; ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { final int[] a={ 0,0,1,1,1,-1,-1,-1 }; final int[] b={ 1,-1,1,0,-1,1,0,-1 }; void run(){ try(Scanner sc=new Scanner(System.in)){ int m=Integer.parseInt(sc.next()); int n=Integer.parseInt(sc.next()); char[][] map=new char[m][]; for(int i=0 ; i=0 && ny=0 && nxtoInteger() ; var n : int ; n := (sc.getCurrent())->toInteger() ; var map : Sequence(Sequence(String)) ; map := Integer.subrange(1,m)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < m do ( ( map[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var i : int ; i := 1 ; while i < m do ( ( var j : int ; j := 0 ; while j < n do ( ( if (map[i+1][j+1] = '-') then ( var f : boolean ; f := false ; var k : int ; k := 0 ; while k < 8 do ( ( var ny : int ; ny := i + a[k+1] ; var nx : int ; nx := j + b[k+1] ; if (ny >= 0 & ny < m & nx >= 0 & nx < n) then ( if (k < 2 & map[ny+1][nx+1] /= '-' or map[ny+1][nx+1] = 'x') then ( f := true ; break ) else skip ) else skip ) ; k := k + 1 ) ; if (not(f)) then ( cnt := cnt + 1 ) else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; )) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String line ; int M,N ; M=sc.nextInt(); N=sc.nextInt(); boolean[][] seats=new boolean[M+2][N+2]; for(int i=0 ; itoInteger() ; N := sc.getCurrent()->toInteger() ; var seats : Sequence(Sequence(boolean)) ; seats := Integer.subrange(1,M + 2)->collect(Integer.subrange(1,N + 2)->collect(false)) ; var i : int ; i := 0 ; while i < M + 2 do ( ( seats[i+1] := seats[i+1]->collect(true) ) ; i := i + 1 ) ; seats[1+1] := seats[1+1]->collect(false) ; var i : int ; i := 1 ; while i <= M do ( ( var s : String ; s := sc.getCurrent() ; var j : int ; j := 1 ; while j <= N do ( ( var c : String ; c := s->at((j)->char2byte() - 1+1) ; if (c = 'o') then ( var k : int ; k := -1 ; while k <= 1 do ( ( seats[i+1][j + k+1] := false ) ; k := k + 1 ) ) else if (c = 'x') then ( var k : int ; k := -1 ; while k <= 1 do ( ( var l : int ; l := -1 ; while l <= 1 do ( ( seats[i + k+1][j + l+1] := false ) ; l := l + 1 ) ) ; k := k + 1 ) ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= M do ( ( var j : int ; j := 1 ; while j <= N do ( ( if (seats[i+1][j+1]) then ans := ans + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); char[][] field=new char[h][]; for(int i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var field : Sequence(Sequence(String)) ; field := Integer.subrange(1,h)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < h do ( ( field[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var ans : Sequence(Sequence(boolean)) ; ans := Integer.subrange(1,h + 2)->collect(Integer.subrange(1,w + 2)->collect(false)) ; var i : int ; i := 2 ; while i <= h do ( ( ans[i+1] := ans[i+1]->collect(true) ; ans[i+1][0+1] := false ; ans[i+1][w + 1+1] := false ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= h do ( ( var j : int ; j := 1 ; while j <= w do ( ( if (field[i - 1+1][j - 1+1] = 'o') then ( ans[i+1][j - 1+1] := false ; ans[i+1][j+1] := false ; ans[i+1][j + 1+1] := false ) else if (field[i - 1+1][j - 1+1] = 'x') then ( var k : int ; k := i - 1 ; while k <= i + 1 do ( ( var l : int ; l := j - 1 ; while l <= j + 1 do ( ( ans[k+1][l+1] := false ) ; l := l + 1 ) ) ; k := k + 1 ) ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i <= h do ( ( var j : int ; j := 1 ; while j <= w do ( ( if (ans[i+1][j+1]) then ( count := count + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int isPowerOf2(String s){ char[] str=s.toCharArray(); int len_str=s.length(); int num=0 ; if(len_str==1 && str[len_str-1]=='1')return 0 ; while(len_str!=1 || str[len_str-1]!='1'){ if((str[len_str-1]-'0')% 2==1)return 0 ; int j=0 ; for(int i=0 ; icharacters() ; var len_str : int ; len_str := s->size() ; var num : int ; num := 0 ; if (len_str = 1 & str[len_str - 1+1] = '1') then return 0 else skip ; while (len_str /= 1 or str[len_str - 1+1] /= '1') do ( if ((str[len_str - 1+1] - ('0')->char2byte()) mod 2 = 1) then return 0 else skip ; var j : int ; j := 0 ; var i : int ; i := 0 ; while i < len_str do ( ( num := num * 10 + str[i+1]->oclAsType(int) - ('0')->char2byte() ; if (num < 2) then ( if (i /= 0) then str[j+1] := '0' ; j := j + 1 ; else skip ; continue ) else skip ; str[j+1] := ((num / 2)->oclAsType(int) + ('0')->char2byte())->oclAsType(String) ; j := j + 1 ; num := (num) - (num / 2) * 2 ) ; i := i + 1 ) ; str[j+1] := '\0' ; len_str := j ; ) ; return 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str1 : String ; str1 := "124684622466842024680246842024662202000002" ; var str2 : String ; str2 := "1" ; var str3 : String ; str3 := "128" ; OclFile["System.out"].println(isPowerOf2(str1) + "\n" + isPowerOf2(str2) + "\n" + isPowerOf2(str3)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class FindAnagrams { private static void printAnagrams(String arr[]){ HashMap>map=new HashMap<>(); for(int i=0 ; iwords=new ArrayList<>(); words.add(word); map.put(newWord,words); } } for(String s : map.keySet()){ Listvalues=map.get(s); if(values.size()>1){ System.out.print(values); } } } public static void main(String[] args){ String arr[]={ "cat","dog","tac","god","act" }; printAnagrams(arr); } } ------------------------------------------------------------ OCL File: --------- class FindAnagrams { static operation printAnagrams( arr : Sequence(String)) : void pre: true post: true activity: ( var map : Map(String,Sequence(String)) ; map := Map{} ; var i : int ; i := 0 ; while i < arr->size() do ( ( var word : String ; word := arr[i+1] ; var letters : Sequence(String) ; letters := word->characters() ; letters := letters->sort() ; var newWord : String ; newWord := StringLib.newString(letters) ; if (map->keys()->includes(newWord)) then ( map->at(newWord)->excludes(word) ) else ( var words : Sequence(String) ; words := Sequence{} ; words := words->including(word) ; map := map->union(Map{newWord |-> words}) ) ; ) ; i := i + 1 ) ; for (s : map->keys()) do ( ( var values : Sequence(String) ; values := map->at(s) ; if (values->size() > 1) then ( OclFile["System.out"].print(values) ) else skip ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"cat","dog","tac","god","act"} ; execute printAnagrams(arr) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Div2_213A { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),k=in.nextInt(); ArrayListls=new ArrayList<>(); for(int i=0 ; itoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var ls : Sequence(Sequence(String)) ; ls := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var s : Sequence(String) ; s := in.getCurrent()->characters() ; ls := ls->including(s) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var kk : Sequence(int) ; kk := Integer.subrange(1,k + 10)->collect(0) ; var ok : boolean ; ok := true ; var ss : Sequence(String) ; ss := ls->at(i+1) ; var j : int ; j := 0 ; while j < ss->size() do ( ( var v : int ; v := ss[j+1] - ('0')->char2byte() ; try ( kk[v+1] := kk[v+1] + 1 ) catch (e : ProgramException) do ( ok := false ; break ) ) ; j := j + 1 ) ; var l : int ; l := 0 ; while l <= k do ( if (kk[l+1] = 0) then ( ok := false ; break ) else skip ; ; l := l + 1 ) ; if (ok) then ans := ans + 1 ; else skip ; ) ; i := i + 1 ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } 13A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var ls : Sequence(Sequence(String)) ; ls := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var s : Sequence(String) ; s := in.getCurrent()->characters() ; ls := ls->including(s) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var kk : Sequence(int) ; kk := Integer.subrange(1,k + 10)->collect(0) ; var ok : boolean ; ok := true ; var ss : Sequence(String) ; ss := ls->at(i+1) ; var j : int ; j := 0 ; while j < ss->size() do ( ( var v : int ; v := ss[j+1] - ('0')->char2byte() ; try ( kk[v+1] := kk[v+1] + 1 ) catch (e : ProgramException) do ( ok := false ; break ) ) ; j := j + 1 ) ; var l : int ; l := 0 ; while l <= k do ( if (kk[l+1] = 0) then ( ok := false ; break ) else skip ; ; l := l + 1 ) ; if (ok) then ans := ans + 1 ; else skip ; ) ; i := i + 1 ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.StringTokenizer ; import static java.lang.System.*; import static java.lang.Math.*; public class pre5 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader obj=new FastReader(); int k=obj.nextInt(); char str[]=obj.next().toCharArray(); int n=str.length ; Arrays.sort(str); int sum=0 ; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : FastReader ; obj := FastReader.newFastReader() ; var k : int ; k := obj.nextInt() ; var str : Sequence(String) ; str := obj.next()->characters() ; var n : int ; n := str->size() ; str := str->sort() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( sum := sum+((str[i+1] - ('0')->char2byte())) ; ; i := i + 1 ) ; var idx : int ; idx := 0 ; var ans : int ; ans := 0 ; while (idx < n & sum < k) do ( sum := sum-(str[idx+1] - ('0')->char2byte()) ; str[idx+1] := '9' ; sum := sum+(9) ; idx := idx + 1 ; ans := ans + 1 ; ) ; out.println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Div2_213A { public static void main(String[] args){ Scanner input=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int answer=0 ; int N=input.nextInt(); int K=input.nextInt(); main : for(int n=0 ; ntoInteger() ; var K : int ; K := input.getCurrent()->toInteger() ; var n : int ; n := 0 ; while n < N do ( ( var s : String ; s := input.getCurrent() ; var k : int ; k := 0 ; while k <= K do ( ( if (s->indexOf("" + k)-1 = -1) then ( continue ) else skip ) ; k := k + 1 ) ; answer := answer + 1 ) ; n := n + 1 ) ; skip ; skip ; ); } 13A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var answer : int ; answer := 0 ; var N : int ; N := input.getCurrent()->toInteger() ; var K : int ; K := input.getCurrent()->toInteger() ; var n : int ; n := 0 ; while n < N do ( ( var s : String ; s := input.getCurrent() ; var k : int ; k := 0 ; while k <= K do ( ( if (s->indexOf("" + k)-1 = -1) then ( continue ) else skip ) ; k := k + 1 ) ; answer := answer + 1 ) ; n := n + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Set ; import java.util.HashSet ; public class CF365_D2_A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); Setset=new HashSet<>(); int t=scanner.nextInt(); int num=scanner.nextInt(); scanner.nextLine(); int cnt=0 ; while(t--!=0){ set.clear(); String line=scanner.next(); for(int i=0 ; itoInteger() ; var num : int ; num := scanner.getCurrent()->toInteger() ; skip ; var cnt : int ; cnt := 0 ; while (t /= 0) do ( skip ; ( set := set->intersection(Set{}) ; var line : String ; line := scanner.getCurrent() ; var i : int ; i := 0 ; while i < line->size() do ( ( set := set->including((line->at(i+1) + "")->toInteger()) ) ; i := i + 1 ) ; var add : boolean ; add := true ; var i : int ; i := 0 ; while i <= num do ( ( if (not(set->includes(i))) then ( add := false ; break ) else skip ) ; i := i + 1 ) ; if (add) then cnt := cnt + 1 ; else skip ; ) ; ) ; OclFile["System.out"].println(cnt) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ int i,j,q,order,x,counter=0 ; Mapmap=new HashMap(); TreeSetset=new TreeSet(); try(Scanner sc=new Scanner(System.in)){ q=sc.nextInt(); for(i=0 ; iold+1); } else { map.put(x,1); } } System.out.println(counter); break ; case 1 : if(set.contains(x)){ if(map.containsKey(x)){ System.out.println(map.get(x)+1); } else { System.out.println(1); } } else { System.out.println(0); } break ; case 2 : if(set.remove(x)){ counter--; if(map.containsKey(x)){ counter-=map.remove(x); } } break ; case 3 : for(Integer output : set.subSet(x,true,sc.nextInt(),true)){ System.out.println(output); if(map.containsKey(output)){ for(j=0 ; jtoInteger() ; i := 0 ; while i < q do ( ( order := sc.getCurrent()->toInteger() ; x := sc.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (order) ; if _switchval = 0 then counter := counter + 1 ; if (not(set->excludes(x))) then ( if (map->keys()->includes(x)) then ( map := map.compute(x, lambda (key , old) : OclAny in old + 1) ) else ( map := map->union(Map{x |-> 1}) ) ) else skip ; OclFile["System.out"].println(counter) ; break else skip ; if _switchval = 1 then if (set->includes(x)) then ( if (map->keys()->includes(x)) then ( OclFile["System.out"].println(map->at(x) + 1) ) else ( OclFile["System.out"].println(1) ) ) else ( OclFile["System.out"].println(0) ) ; break else skip ; if _switchval = 2 then if (set->includes(x)) then ( counter := counter - 1 ; if (map->keys()->includes(x)) then ( counter := counter - (map->at(x)) ; map := map->excludingFirst(x) ) else skip ) else skip ; break else skip ; if _switchval = 3 then for (output : set->select( _x0 | _x0 >= x & _x0 < true )) do ( ( OclFile["System.out"].println(output) ; if (map->keys()->includes(output)) then ( j := 0 ; while j < map->at(output) do ( ( OclFile["System.out"].println(output) ) ; j := j + 1 ) ) else skip ) ) ; break else skip ; ) ) ; i := i + 1 ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; iset=new HashSet<>(); while(n--!=0){ set.clear(); char[] arr=in.next().toCharArray(); if(arr.length>=k+1){ for(char i : arr){ int temp=Integer.parseInt(i+""); if(temp>=0 && temp<=k)set.add(temp); } count+=set.size()==(k+1)? 1 : 0 ; } } out.println(count); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static attribute in : FastScanner := FastScanner.newFastScanner(); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation s( t : int) : void pre: true post: true activity: ( t := 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var k : int ; k := in.nextInt() ; var count : int ; count := 0 ; var set : Set(int) ; set := Set{} ; while (n /= 0) do ( skip ; ( set := set->intersection(Set{}) ; var arr : Sequence(String) ; arr := in.next()->characters() ; if (arr->size() >= k + 1) then ( for (i : arr) do ( ( var temp : int ; temp := (i + "")->toInteger() ; if (temp >= 0 & temp <= k) then set := set->including(temp) ; else skip ) ) ; count := count+(if set->size() = (k + 1) then 1 else 0 endif) ) else skip ) ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import org.w3c.dom.ranges.Range ; import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int n=in.nextInt(); int k=in.nextInt(); int ans=0 ; for(int i=0 ; icharacters() ; var range : Sequence(boolean) ; range := Integer.subrange(1,k + 1)->collect(false) ; var j : int ; j := 0 ; while j < num->size() do ( ( var current : int ; current := num[j+1] - ('0')->char2byte() ; if (current <= k) then range[current+1] := true ; else skip ) ; j := j + 1 ) ; var flag : boolean ; flag := true ; for (bol : range) do ( ( if (not(bol)) then ( flag := false ; break ) else skip ) ) ; if (flag) then ans := ans + 1 ; else skip ; ) ; i := i + 1 ) ; skip ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("sub.in"))) ) catch (ex : FileNotFoundException) do ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (ex : IOException) do skip ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (ex : IOException) do skip return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class AserejaAndBottle { public static void main(String[] args)throws IOException { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(buf.readLine()); int[] a=new int[n]; int[] b=new int[n]; int r=0 ; while(n-->0){ String[] inp=buf.readLine().split(" "); a[r]=Integer.parseInt(inp[0]); b[r++]=Integer.parseInt(inp[1]); } int ans=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var r : int ; r := 0 ; while (n > 0) do ( n := n - 1 ; skip ; ( var inp : Sequence(String) ; inp := buf.readLine()->split(" ") ; a[r+1] := (inp[0+1])->toInteger() ; b[r+1] := (inp[1+1])->toInteger() ; r := r + 1 ) ; ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( var count : int ; count := 0 ; var j : int ; j := 0 ; while j < b->size() do ( ( if (a[i+1] = b[j+1] & i /= j) then ( count := 1 ; break ) else skip ) ; j := j + 1 ) ; if (count = 0) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class SerejaAndBottles { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int num=scanner.nextInt(); Lista=new ArrayList<>(); Listb=new ArrayList<>(); MapbMap=new HashMap<>(); for(int i=0 ; i=2){ continue ; } else if(value==1){ if(b.get(i).equals(a.get(i))){ res++; } } else { res++; } } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class SerejaAndBottles { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : int ; num := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Sequence{} ; var b : Sequence(int) ; b := Sequence{} ; var bMap : Map(int,int) ; bMap := Map{} ; var i : int ; i := 0 ; while i < num do ( ( a := a->including(scanner.getCurrent()->toInteger()) ; var t : int ; t := scanner.getCurrent()->toInteger() ; b := b->including(t) ; bMap := bMap->union(Map{t |-> (if bMap->keys()->contains(t) then bMap->at(t) else 0 endif) + 1}) ) ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < num do ( ( var value : int ; value := (if bMap->keys()->contains(a->at(i+1)) then bMap->at(a->at(i+1)) else 0 endif) ; if (value >= 2) then ( continue ) else if (value = 1) then ( if (b->at(i+1) = a->at(i+1)) then ( res := res + 1 ) else skip ) else ( res := res + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var size : int ; size := n ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (a[i+1] = b[j+1] & j /= i) then ( size := size - 1 ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(size) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[][] bottles=new int[n][2]; for(int i=0 ; itoInteger() ; var bottles : Sequence(Sequence(int)) ; bottles := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( bottles[i+1][0+1] := sc.getCurrent()->toInteger() ; bottles[i+1][1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var openable : boolean ; openable := false ; var j : int ; j := 0 ; while j < n do ( ( if (j = i) then continue else skip ; if (bottles[j+1][1+1] = bottles[i+1][0+1]) then ( openable := true ; break ) else skip ) ; j := j + 1 ) ; if (not(openable)) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { @ SuppressWarnings("resource")public static void main(String args[]){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); String s=String.valueOf(n); if(n<100){ s="0"+s ; } System.out.println("ABC"+s); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var s : String ; s := ((n) + "") ; if (n < 100) then ( s := "0" + s ) else skip ; OclFile["System.out"].println("ABC" + s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class B { static boolean[] dp ; static int N=(int)1e4+5 ; public static void main(String[] args)throws IOException { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); long k=in.nextLong(); char[] s=in.next().toCharArray(); ArrayListls=new ArrayList<>(); for(int i=0 ; i=k){ pw.println(0); pw.close(); return ; } int op=0 ; for(int i=0 ; i=k){ break ; } } pw.println(op); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class B { static attribute dp : Sequence(boolean); static attribute N : int := 1e4->oclAsType(int) + 5; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var k : long ; k := in.getCurrent()->toLong() ; var s : Sequence(String) ; s := in.getCurrent()->characters() ; var ls : Sequence(int) ; ls := Sequence{} ; var i : int ; i := 0 ; while i < s->size() do ( ls := ls->including(s[i+1] - ('0')->char2byte()) ; ; i := i + 1 ) ; var total : long ; total := 0 ; ls := ls->sort() ; for (x : ls) do ( total := total+(x) ; ) ; if (total >= k) then ( skip ; skip ; return ) else skip ; var op : int ; op := 0 ; var i : int ; i := 0 ; while i < ls->size() do ( ( total := total-(ls->at(i+1)) ; total := total+(9) ; op := op + 1 ; if (total >= k) then ( break ) else skip ) ; i := i + 1 ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line=br.readLine(); System.out.println("ABC"+line); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := br.readLine() ; OclFile["System.out"].println("ABC" + line) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.*; import static java.lang.System.*; public class Main { public static void main(String[] args){ int i,j ; Scanner sc=new Scanner(in); int n=parseInt(sc.next()); sc.close(); out.printf("ABC%03d%n",n); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var j : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var n : int ; n := parseInt(sc.getCurrent()) ; skip ; out.printf("ABC%03d%n", n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Main m=new Main(); m.answer(); } private Scanner scan=new Scanner(System.in); private final int N ; public Main(){ N=Integer.parseInt(scan.next()); scan.close(); } public final void answer(){ System.out.println("ABC"+N); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.answer() ); attribute scan : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute N : int; static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( N := (scan.getCurrent())->toInteger() ; skip ); operation answer() : void pre: true post: true activity: ( OclFile["System.out"].println("ABC" + N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashSet ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ TreeMapS=new TreeMap<>(); int c=0 ; int q=sc.nextInt(); for(int i=0 ; i{ for(int j=0 ; jtoInteger() ; var i : int ; i := 0 ; while i < q do ( ( var cmd : int ; cmd := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; if (cmd = 0) then ( var n : int ; n := (if S->keys()->contains(x) then S->at(x) else 0 endif) ; S := S->union(Map{x |-> n + 1}) ; OclFile["System.out"].println((c + 1)) ) else if (cmd = 1) then ( var n : int ; n := (if S->keys()->contains(x) then S->at(x) else 0 endif) ; OclFile["System.out"].println(n) ) else if (cmd = 2) then ( var n : int ; n := (if S->keys()->contains(x) then S->at(x) else 0 endif) ; S := S->antirestrict(Set{x}) ; c := c-(n) ) else ( var r : int ; r := sc.getCurrent()->toInteger() ; for ,v : S->restrict( _key | _key < true & _key >= x ) do ( skip) ) ; ; ) ; i := i + 1 ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try { Scanner sc=new Scanner(System.in); String a="ABC"+sc.nextInt(); System.out.println(a); } catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : String ; a := "ABC" + sc.getCurrent()->toInteger() ; OclFile["System.out"].println(a) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static void printArr(int arr[],int n){ for(int i=0 ; i0 && lsort() ; execute reverse(arr) ; var freq : Sequence(int) ; freq := Integer.subrange(1,arr[0+1] + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1 ) ; i := i + 1 ) ; var size : int ; size := (n)->sqrt()->oclAsType(int) ; var brr : Sequence(void) ; brr := Integer.subrange(1,size)->collect(0) ; var x : int ; var l : int ; l := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (freq[arr[i+1]+1] > 0 & l < size) then ( brr[l+1] := arr[i+1] ; freq[brr[l+1]+1] := freq[brr[l+1]+1] - 1 ; l := l + 1 ; var j : int ; j := 0 ; while j < l do ( ( if (i /= j) then ( x := __gcd(arr[i+1], brr[j+1]) ; freq[x+1] := freq[x+1]-(2) ) else skip ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; execute printArr(brr, size) ; ); static operation reverse( input : Sequence(int)) : void pre: true post: true activity: ( var last : int ; last := input->size() - 1 ; var middle : int ; middle := input->size() / 2 ; var i : int ; i := 0 ; while i <= middle do ( ( var temp : int ; temp := input[i+1] ; input[i+1] := input[last - i+1] ; input[last - i+1] := temp ) ; i := i + 1 ) ); static 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) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{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} ; var n : int ; n := arr->size() ; execute findNumbers(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : long ; n := scanner.getCurrent()->toLong() ; if (n = 1) then ( OclFile["System.out"].println(2) ; continue ) else skip ; if (n < 10) then ( OclFile["System.out"].println(n) ; continue ) else skip ; while (not(method(n))) do ( n := n + 1 ) ; OclFile["System.out"].println(n) ; ) ; i := i + 1 ) ); static operation method( n : long) : boolean pre: true post: true activity: ( var temp : long ; temp := n ; var sum : long ; sum := 0 ; while (temp /= 0) do ( sum := sum+(temp mod 10) ; temp := temp/(10) ) ; if (sum = 1) then ( return false ) else skip ; if (n mod sum = 0) then ( return true ) else skip ; var i : long ; i := 2 ; while i < sum do ( ( if (n mod i = 0 & sum mod i = 0) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.nio.charset.StandardCharsets ; import java.util.Scanner ; import java.util.concurrent.TransferQueue ; public class ylhgcd { public static void main(String[] args){ Scanner cin=new Scanner(System.in,StandardCharsets.UTF_8.name()); int count=cin.nextInt(); while(count>0){ long num=cin.nextLong(); System.out.println(getYlhgcd(num)); count--; } } private static long getYlhgcd(long num){ long num2,tmp_num ; while(true){ tmp_num=num ; num2=0 ; while(tmp_num!=0){ num2+=tmp_num % 10 ; tmp_num/=10 ; } if(gcd(num,num2)!=1){ break ; } num++; } return num ; } private static long gcd(long num,long num2){ while(num2!=0){ num=num % num2 ; if(num2>num){ long tmp=num ; num=num2 ; num2=tmp ; } } return num ; } } ------------------------------------------------------------ OCL File: --------- class ylhgcd { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"], StandardCharsets.UTF_8.name()) ; var count : int ; count := cin.getCurrent()->toInteger() ; while (count > 0) do ( var num : long ; num := cin.getCurrent()->toLong() ; OclFile["System.out"].println(getYlhgcd(num)) ; count := count - 1 ) ); static operation getYlhgcd( num : long) : long pre: true post: true activity: ( var num2 : long ; var tmp_num : long ; while (true) do ( tmp_num := num ; num2 := 0 ; while (tmp_num /= 0) do ( num2 := num2+(tmp_num mod 10) ; tmp_num := tmp_num/(10) ) ; if (gcd(num, num2) /= 1) then ( break ) else skip ; num := num + 1 ; ) ; return num ); static operation gcd( num : long, num2 : long) : long pre: true post: true activity: ( while (num2 /= 0) do ( num := num mod num2 ; if (num2 > num) then ( var tmp : long ; tmp := num ; num := num2 ; num2 := tmp ) else skip ) ; return num ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class A_GCD_Sum { public static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader reader=new FastReader(); int T=reader.nextInt(); while(T!=0){ T--; long num=reader.nextLong(); while(gcd(num,sumOfDigits(num))==1){ num++; } System.out.println(num); } } public static long gcd(long a,long b){ if(b==0){ return a ; } return gcd(b,a % b); } public static long sumOfDigits(long num){ long sum=0L ; while(num!=0){ sum+=num % 10 ; num=num/10 ; } return sum ; } } ------------------------------------------------------------ OCL File: --------- class A_GCD_Sum { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : FastReader ; reader := FastReader.newFastReader() ; var T : int ; T := reader.nextInt() ; while (T /= 0) do ( T := T - 1 ; var num : long ; num := reader.nextLong() ; while (gcd(num, sumOfDigits(num)) = 1) do ( num := num + 1 ) ; OclFile["System.out"].println(num) ) ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b) ); static operation sumOfDigits( num : long) : long pre: true post: true activity: ( var sum : long ; sum := 0L ; while (num /= 0) do ( sum := sum+(num mod 10) ; num := num / 10 ) ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.nio.charset.StandardCharsets ; import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; import java.util.stream.Collectors ; public class ZuiDaGongYueShuB { public static void main(String[] args){ ListinputDatas=getInputDatas(); ListgongYueShuZu=getGongYueShuZu(inputDatas); gongYueShuZu.stream().forEach(e->System.out.println(calMinZuiDaGongYue(e[0],e[1]))); } static long calMinZuiDaGongYue(long a,long b){ long r=calZuiDaGongYueShu(a,b); while(r<2){ if(a++% 10<9){ b++; } else { b=calMeiYiWeiShuZiZhiHe(a); } r=calZuiDaGongYueShu(a,b); } return a ; } static long calZuiDaGongYueShu(long a,long b){ long r=a % b ; while(r!=0){ a=b ; b=r ; r=a % b ; } return b ; } static ListgetInputDatas(){ Scanner scanner=new Scanner(System.in,StandardCharsets.UTF_8.name()); int lines=Integer.parseInt(scanner.nextLine()); Listresult=new ArrayList(); for(int i=0 ; igetGongYueShuZu(ListinputData){ return inputData.stream().map(ZuiDaGongYueShuB :: transLongToGongYueShuZu).collect(Collectors.toList()); } static long[] transLongToGongYueShuZu(long num){ long[] arr=new long[2]; arr[0]=num ; arr[1]=calMeiYiWeiShuZiZhiHe(num); return arr ; } static long calMeiYiWeiShuZiZhiHe(long num){ long r=0L ; while(num!=0){ r+=num % 10 ; num/=10 ; } return r ; } } ------------------------------------------------------------ OCL File: --------- class ZuiDaGongYueShuB { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputDatas : Sequence(long) ; inputDatas := getInputDatas() ; var gongYueShuZu : Sequence(Sequence(long)) ; gongYueShuZu := getGongYueShuZu(inputDatas) ; for e : gongYueShuZu do ( OclFile["System.out"].println(calMinZuiDaGongYue(e[0+1], e[1+1]))) ); static operation calMinZuiDaGongYue( a : long, b : long) : long pre: true post: true activity: ( var r : long ; r := calZuiDaGongYueShu(a, b) ; while (r < 2) do ( if (a mod 10 < 9) then ( b := b + 1 ) else ( b := calMeiYiWeiShuZiZhiHe(a) ) ; r := calZuiDaGongYueShu(a, b) ) ; return a ); static operation calZuiDaGongYueShu( a : long, b : long) : long pre: true post: true activity: ( var r : long ; r := a mod b ; while (r /= 0) do ( a := b ; b := r ; r := a mod b ) ; return b ); static operation getInputDatas() : Sequence(long) pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"], StandardCharsets.UTF_8.name()) ; var lines : int ; lines := (scanner.nextLine())->toInteger() ; var result : Sequence(long) ; result := Sequence{} ; var i : int ; i := 0 ; while i < lines do ( ( result := result->including((scanner.nextLine())->toLong()) ) ; i := i + 1 ) ; return result ); static operation getGongYueShuZu( inputData : Sequence(long)) : Sequence(Sequence(long)) pre: true post: true activity: ( return inputData->collect( _x1 | (lambda _pars : OclAny in ZuiDaGongYueShuB.newZuiDaGongYueShuB().transLongToGongYueShuZu(_pars))->apply(_x1) ).collect(Collectors.toList()) ); static operation transLongToGongYueShuZu( num : long) : Sequence(long) pre: true post: true activity: ( var arr : Sequence(long) ; arr := Integer.subrange(1,2)->collect(0) ; arr[0+1] := num ; arr[1+1] := calMeiYiWeiShuZiZhiHe(num) ; return arr ); static operation calMeiYiWeiShuZiZhiHe( num : long) : long pre: true post: true activity: ( var r : long ; r := 0L ; while (num /= 0) do ( r := r+(num mod 10) ; num := num/(10) ) ; return r ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class MyClass { static Scanner in=new Scanner(System.in); static long k ; static char a[]; public static void main(String args[]){ k=in.nextLong(); a=in.next().toCharArray(); long sumHave=0 ; for(char i : a){ sumHave+=(i-'0'); } Arrays.sort(a); long ans=0 ; int len=a.length ; while(true){ boolean find=false ; for(int i=0 ; isumHave){ if(9-(a[i]-'0')!=0){ ans++; sumHave+=(9-(a[i]-'0')); a[i]='9' ; } } else { find=true ; break ; } } if(find){ break ; } } System.out.print(ans); } } ------------------------------------------------------------ OCL File: --------- class MyClass { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute k : long; static attribute a : Sequence(String); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( k := in.getCurrent()->toLong() ; a := in.getCurrent()->characters() ; var sumHave : long ; sumHave := 0 ; for (i : a) do ( ( sumHave := sumHave+((i - ('0')->char2byte())) ) ) ; a := a->sort() ; var ans : long ; ans := 0 ; var len : int ; len := a->size() ; while (true) do ( var find : boolean ; find := false ; var i : int ; i := 0 ; while i < len do ( ( if (k > sumHave) then ( if (9 - (a[i+1] - ('0')->char2byte()) /= 0) then ( ans := ans + 1 ; sumHave := sumHave+((9 - (a[i+1] - ('0')->char2byte()))) ; a[i+1] := '9' ) else skip ) else ( find := true ; break ) ) ; i := i + 1 ) ; if (find) then ( break ) else skip ) ; OclFile["System.out"].print(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Solution { static void printAllSubsetsRec(int arr[],int n,Vectorv,int sum){ if(sum==0){ for(int i=0 ; iv1=new Vector(v); v1.add(arr[n-1]); printAllSubsetsRec(arr,n-1,v1,sum-arr[n-1]); } static void printAllSubsets(int arr[],int n,int sum){ Vectorv=new Vector(); printAllSubsetsRec(arr,n,v,sum); } public static void main(String args[]){ int arr[]={ 2,5,8,4,6,11 }; int sum=13 ; int n=arr.length ; printAllSubsets(arr,n,sum); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation printAllSubsetsRec( arr : Sequence(int), n : int, v : Sequence(int), sum : int) : void pre: true post: true activity: ( if (sum = 0) then ( var i : int ; i := 0 ; while i < v->size() do ( OclFile["System.out"].print(v->at(i+1) + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ; return ) else skip ; if (n = 0) then return else skip ; execute printAllSubsetsRec(arr, n - 1, v, sum) ; var v1 : Sequence(int) ; v1 := Sequence{}->union(v) ; v1 := v1->including(arr[n - 1+1]) ; execute printAllSubsetsRec(arr, n - 1, v1, sum - arr[n - 1+1]) ; ); static operation printAllSubsets( arr : Sequence(int), n : int, sum : int) : void pre: true post: true activity: ( var v : Sequence(int) ; v := Sequence{} ; execute printAllSubsetsRec(arr, n, v, sum) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,5,8,4,6,11} ; var sum : int ; sum := 13 ; var n : int ; n := arr->size() ; execute printAllSubsets(arr, n, sum) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); if(s.contains("7")){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; if (s->includes("7")) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String N=br.readLine(); System.out.println(N.contains("7")? "Yes" : "No"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var N : String ; N := br.readLine() ; OclFile["System.out"].println(if N->includes("7") then "Yes" else "No" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ String seven="No" ; try(Scanner scn=new Scanner(System.in)){ final char[] N=scn.next().toCharArray(); for(int i=0 ; icharacters() ; var i : int ; i := 0 ; while i < N->size() do ( ( if (N[i+1] = '7') then ( seven := "Yes" ; break ) else skip ) ; i := i + 1 ) )) OclFile["System.out"].println(seven) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void solve(int N,int K){ int Array[]=new int[N+1]; if(N<=K){ System.out.println("1"); return ; } int i=0 ; int sum=K ; for(i=1 ; i<=K ; ++i){ Array[i]=1 ; } Array[i]=sum ; for(i=K+2 ; i<=N ; ++i){ Array[i]=sum-Array[i-K-1]+Array[i-1]; sum=Array[i]; } System.out.println(Array[N]); } public static void main(String args[]){ int N=4,K=2 ; solve(N,K); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solve( N : int, K : int) : void pre: true post: true activity: ( var Array : Sequence(int) ; Array := Integer.subrange(1,N + 1)->collect(0) ; if (N <= K) then ( OclFile["System.out"].println("1") ; return ) else skip ; var i : int ; i := 0 ; var sum : int ; sum := K ; i := 1 ; while i <= K do ( ( Array[i+1] := 1 ) ; i := i + 1 ) ; Array[i+1] := sum ; i := K + 2 ; while i <= N do ( ( Array[i+1] := sum - Array[i - K - 1+1] + Array[i - 1+1] ; sum := Array[i+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(Array[N+1]) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 4 ; var K : int ; K := 2 ; execute solve(N, K) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int b=sc.nextInt(); if(b==0){ break ; } calculatorResult(b); } } public static void calculatorResult(int b){ int i=1 ; int lowestFloor=1 ; int numberOfFloors=0 ; int sum=0 ; while(true){ if(sum==b){ break ; } if(sumb){ sum-=lowestFloor ; lowestFloor++; numberOfFloors--; } } System.out.println(lowestFloor+" "+numberOfFloors); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var b : int ; b := sc.getCurrent()->toInteger() ; if (b = 0) then ( break ) else skip ; execute calculatorResult(b) ) ); static operation calculatorResult( b : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; var lowestFloor : int ; lowestFloor := 1 ; var numberOfFloors : int ; numberOfFloors := 0 ; var sum : int ; sum := 0 ; while (true) do ( if (sum = b) then ( break ) else skip ; if (sum < b) then ( sum := sum+(i) ; numberOfFloors := numberOfFloors + 1 ; i := i + 1 ) else skip ; if (sum > b) then ( sum := sum-(lowestFloor) ; lowestFloor := lowestFloor + 1 ; numberOfFloors := numberOfFloors - 1 ) else skip ) ; OclFile["System.out"].println(lowestFloor + " " + numberOfFloors) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner a=new Scanner(System.in); int f=a.nextInt(); String s=String.valueOf(f); for(int i=0 ; itoInteger() ; var s : String ; s := ((f) + "") ; var i : int ; i := 0 ; while i < s->size() do ( ( if (("" + s->at(i+1))->toInteger() = 7) then ( OclFile["System.out"].println("Yes") ; break ) else if (i = s->size() - 1 & ("" + s->at(i+1))->toInteger() /= 7) then ( OclFile["System.out"].println("No") ) else skip ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { void run(){ Scanner sc=new Scanner(System.in); String n=sc.next(); boolean ans=false ; for(char c : n.toCharArray()){ if(c=='7'){ ans=true ; } } System.out.println(ans ? "Yes" : "No"); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : String ; n := sc.getCurrent() ; var ans : boolean ; ans := false ; for (c : n->characters()) do ( ( if (c = '7') then ( ans := true ) else skip ) ) ; OclFile["System.out"].println(if ans then "Yes" else "No" endif) ; ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int minMoves(int n){ String s=Integer.toString(n); int ans=Integer.MAX_VALUE ; int len=s.length(); for(int i=0 ; ii)? 1 : 0); k0 ; --k){ swap(t,k,k-1); ++cur ; } long nn=Integer.parseInt(String.valueOf(t)); if(nn % 25==0)ans=Math.min(ans,cur); } } if(ans==Integer.MAX_VALUE)return-1 ; return ans ; } static void swap(char t[],int i,int j){ char temp=t[i]; t[i]=t[j]; t[j]=temp ; } public static void main(String[] args){ int n=509201 ; System.out.println(minMoves(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minMoves( n : int) : int pre: true post: true activity: ( var s : String ; s := ((n) + "") ; var ans : int ; ans := 2147483647 ; var len : int ; len := s->size() ; var i : int ; i := 0 ; while i < len do ( ( var j : int ; j := 0 ; while j < len do ( ( if (i = j) then continue else skip ; var t : Sequence(String) ; t := s->characters() ; var cur : int ; cur := 0 ; var k : int ; k := i ; while k < len - 1 do ( ( execute swap(t, k, k + 1) ; cur := cur + 1 ) ; k := k + 1 ) ; var k : int ; k := j - (if (j > i) then 1 else 0 endif) ; while k < len - 2 do ( ( execute swap(t, k, k + 1) ; cur := cur + 1 ) ; k := k + 1 ) ; var pos : int ; pos := -1 ; var k : int ; k := 0 ; while k < len do ( ( if (t[k+1] /= '0') then ( pos := k ; break ) else skip ) ; k := k + 1 ) ; var k : int ; k := pos ; while k > 0 do ( ( execute swap(t, k, k - 1) ; cur := cur + 1 ) ; k := k - 1 ) ; var nn : long ; nn := (((t) + ""))->toInteger() ; if (nn mod 25 = 0) then ans := Set{ans, cur}->min() ; else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (ans = 2147483647) then return -1 else skip ; return ans ); static operation swap( t : Sequence(String), i : int, j : int) : void pre: true post: true activity: ( var temp : String ; temp := t[i+1] ; t[i+1] := t[j+1] ; t[j+1] := temp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 509201 ; OclFile["System.out"].println(minMoves(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countSubarrays(int a[],int n,int m){ int count=0 ; for(int i=0 ; isize() ; var m : int ; m := 2 ; OclFile["System.out"].println(countSubarrays(a, n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B_main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); char[] n=sc.next().toCharArray(); int[] cnt=new int[10]; int cur=0 ; for(int i=0 ; itoInteger() ; var n : Sequence(String) ; n := sc.getCurrent()->characters() ; var cnt : Sequence(int) ; cnt := Integer.subrange(1,10)->collect(0) ; var cur : int ; cur := 0 ; var i : int ; i := 0 ; while i < n->size() do ( ( var digit : int ; digit := n[i+1] - ('0')->char2byte() ; cnt[digit+1] := cnt[digit+1] + 1 ; cur := cur+(digit) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 9 do ( ( var j : int ; j := 0 ; while j < cnt[i+1] do ( ( if (cur < k) then ( ans := ans + 1 ; cur := cur+(9 - i) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int countSubarrays(int a[],int n,int m){ int count=0 ; int prefix[]=new int[n]; int odd=0 ; for(int i=0 ; i=m)count+=prefix[odd-m]; } return count ; } public static void main(String[] args){ int a[]={ 2,2,5,6,9,2,11 }; int n=a.length ; int m=2 ; System.out.println(countSubarrays(a,n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSubarrays( a : Sequence(int), n : int, m : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var prefix : Sequence(int) ; prefix := Integer.subrange(1,n)->collect(0) ; var odd : int ; odd := 0 ; var i : int ; i := 0 ; while i < n do ( ( prefix[odd+1] := prefix[odd+1] + 1 ; if ((a[i+1] & 1) = 1) then odd := odd + 1 ; else skip ; if (odd >= m) then count := count+(prefix[odd - m+1]) ; else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,2,5,6,9,2,11} ; var n : int ; n := a->size() ; var m : int ; m := 2 ; OclFile["System.out"].println(countSubarrays(a, n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int reverse(int num){ int rev=0 ; while(num>0){ rev=rev*10+num % 10 ; num=num/10 ; } return rev ; } static boolean isPalindrome(int num){ if(num==reverse(num))return true ; return false ; } static void printPalindromes(int d){ if(d<=0)return ; int smallest=(int)Math.pow(10,d-1); int largest=(int)Math.pow(10,d)-1 ; for(int i=smallest ; i<=largest ; i++){ if(isPalindrome(i))System.out.print(i+" "); } } public static void main(String[] args){ int d=2 ; printPalindromes(d); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation reverse( num : int) : int pre: true post: true activity: ( var rev : int ; rev := 0 ; while (num > 0) do ( rev := rev * 10 + num mod 10 ; num := num / 10 ) ; return rev ); static operation isPalindrome( num : int) : boolean pre: true post: true activity: ( if (num = reverse(num)) then return true else skip ; return false ); static operation printPalindromes( d : int) : void pre: true post: true activity: ( if (d <= 0) then return else skip ; var smallest : int ; smallest := 10->pow(d - 1)->oclAsType(int) ; var largest : int ; largest := 10->pow(d)->oclAsType(int) - 1 ; var i : int ; i := smallest ; while i <= largest do ( ( if (isPalindrome(i)) then OclFile["System.out"].print(i + " ") ; else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var d : int ; d := 2 ; execute printPalindromes(d) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class pr11 { public static void main(String[] args){ Scanner scan=new Scanner(System.in); double a=scan.nextDouble(),b=scan.nextDouble(),c=scan.nextDouble(),d=scan.nextDouble(); double p1=(a*d)/(b*c-a*c+a*d); System.out.println(p1); } } ------------------------------------------------------------ OCL File: --------- class pr11 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : double ; a := scan.getCurrent()->toReal() ; var b : double ; b := scan.getCurrent()->toReal() ; var c : double ; c := scan.getCurrent()->toReal() ; var d : double ; d := scan.getCurrent()->toReal() ; var p1 : double ; p1 := (a * d) / (b * c - a * c + a * d) ; OclFile["System.out"].println(p1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); double p1=(double)a/(double)b ; double p2=(1.0-(double)c/(double)d)*(1.0-p1); double ans=0 ; for(int i=0 ; i<10000 ; i++){ ans+=Math.pow(p2,i)*p1 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var p1 : double ; p1 := a->oclAsType(double) / b->oclAsType(double) ; var p2 : double ; p2 := (1.0 - c->oclAsType(double) / d->oclAsType(double)) * (1.0 - p1) ; var ans : double ; ans := 0 ; var i : int ; i := 0 ; while i < 10000 do ( ( ans := ans+(p2->pow(i) * p1) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Archer { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); System.out.println((double)(a*d)/(a*d+b*c-a*c)); } } ------------------------------------------------------------ OCL File: --------- class Archer { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; OclFile["System.out"].println((a * d)->oclAsType(double) / (a * d + b * c - a * c)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.FileReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); BArcher solver=new BArcher(); solver.solve(1,in,out); out.close(); } static class BArcher { public void solve(int testNumber,Scanner sc,PrintWriter pw){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); double per1=1.0*a/b ; double per2=1.0*c/d ; pw.println((per1)/(1-(1-per1)*(1-per2))); } } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner(FileReader r){ br=new BufferedReader(r); } public Scanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public String next(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : BArcher ; solver := BArcher.newBArcher() ; solver.solve(1, in, out) ; skip ; ); static class BArcher { operation solve( testNumber : int, sc : OclFile, pw : OclFile) : void pre: true post: true activity: ( var a : int ; a := sc.nextInt() ; var b : int ; b := sc.nextInt() ; var c : int ; c := sc.nextInt() ; var d : int ; d := sc.nextInt() ; var per1 : double ; per1 := 1.0 * a / b ; var per2 : double ; per2 := 1.0 * c / d ; pw.println((per1) / (1 - (1 - per1) * (1 - per2))) ; ); } static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( r : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(r); return self ); operation initialise( r : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(r) ); static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Scanner ; public class Main { private static long ans=0,low=0 ; public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); long n=in.nextInt(); while(n>0){ ans=0 ; low=0 ; long d=2*n ; for(int i=1 ; i*i<=d ; i++){ if(d % i!=0)continue ; calc(i,d/i); calc(d/i,i); } out.println(low+" "+ans); n=in.nextInt(); } out.flush(); } private static void calc(long x,long y){ if((x-y+1)% 2!=0 ||(x+y-1)% 2!=0)return ; long b=(x+y-1)/2,a=(x-y+1)/2 ; if(b<1 || a<1)return ; if(b-a+1>ans){ ans=b-a+1 ; low=a ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute ans : long := 0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : long ; n := in.getCurrent()->toInteger() ; while (n > 0) do ( ans := 0 ; low := 0 ; var d : long ; d := 2 * n ; var i : int ; i := 1 ; while i * i <= d do ( ( if (d mod i /= 0) then continue else skip ; execute calc(i, d / i) ; execute calc(d / i, i) ) ; i := i + 1 ) ; skip ; n := in.getCurrent()->toInteger() ; ) ; skip ; ); static operation calc( x : long, y : long) : void pre: true post: true activity: ( if ((x - y + 1) mod 2 /= 0 or (x + y - 1) mod 2 /= 0) then return else skip ; var b : long ; b := (x + y - 1) / 2 ; var a : long ; a := (x - y + 1) / 2 ; if (b < 1 or a < 1) then return else skip ; if (b - a + 1 > ans) then ( ans := b - a + 1 ; low := a ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF312B { public static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); double a=scanner.nextInt(); double b=scanner.nextInt(); double c=scanner.nextInt(); double d=scanner.nextInt(); double rWinProb=a/b ; double zWinProb=c/d ; double rMissAndZMissProb=(1-rWinProb)*(1-zWinProb); double total=rWinProb/(1-rMissAndZMissProb); System.out.println(total); } } ------------------------------------------------------------ OCL File: --------- class CF312B { static attribute scanner : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : double ; a := scanner.getCurrent()->toInteger() ; var b : double ; b := scanner.getCurrent()->toInteger() ; var c : double ; c := scanner.getCurrent()->toInteger() ; var d : double ; d := scanner.getCurrent()->toInteger() ; var rWinProb : double ; rWinProb := a / b ; var zWinProb : double ; zWinProb := c / d ; var rMissAndZMissProb : double ; rMissAndZMissProb := (1 - rWinProb) * (1 - zWinProb) ; var total : double ; total := rWinProb / (1 - rMissAndZMissProb) ; OclFile["System.out"].println(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void isHalfReducible(int arr[],int n,int m){ int frequencyHash[]=new int[m+1]; int i ; for(i=0 ; i=n/2)break ; } if(i<=m)System.out.println("Yes"); else System.out.println("No"); } public static void main(String args[]){ int arr[]={ 8,16,32,3,12 }; int n=arr.length ; int m=7 ; isHalfReducible(arr,n,m); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isHalfReducible( arr : Sequence(int), n : int, m : int) : void pre: true post: true activity: ( var frequencyHash : Sequence(int) ; frequencyHash := Integer.subrange(1,m + 1)->collect(0) ; var i : int ; i := 0 ; while i < frequencyHash->size() do ( frequencyHash[i+1] := 0 ; ; i := i + 1 ) ; i := 0 ; while i < n 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 <= m do ( ( if (frequencyHash[i+1] >= n / 2) then break else skip ) ; i := i + 1 ) ; if (i <= m) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{8,16,32,3,12} ; var n : int ; n := arr->size() ; var m : int ; m := 7 ; execute isHalfReducible(arr, n, m) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public int findShortestSubArray(int[] nums){ Mapleft=new HashMap(),right=new HashMap(),count=new HashMap(); for(int i=0 ; isize() do ( ( var x : int ; x := nums[i+1] ; if (left->at(x+1) = null) then left := left->union(Map{x |-> i}) ; else skip ; right := right->union(Map{x |-> i}) ; count := count->union(Map{x |-> count->at(x, 0+1) + 1}) ) ; i := i + 1 ) ; var ans : int ; ans := nums->size() ; var degree : int ; degree := .max(count.allInstances()) ; for (x : count.keySet()) do ( ( if (count->at(x+1) = degree) then ( ans := Set{ans, right->at(x+1) - left->at(x+1) + 1}->min() ) else skip ) ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Number835B { public static void main(String[] args){ Scanner in=new Scanner(System.in); int sum=in.nextInt(); String numbers=in.next(); ArrayListlist=new ArrayList(); int size=numbers.length(); int num_sum=0 ; for(int i=0 ; i=sum){ System.out.println(0); return ; } Collections.sort(list); for(int i=0 ; i=sum){ System.out.println(i+1); return ; } } } } ------------------------------------------------------------ OCL File: --------- class Number835B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sum : int ; sum := in.getCurrent()->toInteger() ; var numbers : String ; numbers := in.getCurrent() ; var list : Sequence(int) ; list := Sequence{} ; var size : int ; size := numbers->size() ; var num_sum : int ; num_sum := 0 ; var i : int ; i := 0 ; while i < size do ( ( list := list->including((((numbers->at(i+1)) + ""))->toInteger()) ; num_sum := num_sum+(list->at(i+1)) ) ; i := i + 1 ) ; if (num_sum >= sum) then ( OclFile["System.out"].println(0) ; return ) else skip ; list := list->sort() ; var i : int ; i := 0 ; while i < size do ( ( num_sum := num_sum+(9 - list->at(i+1)) ; if (num_sum >= sum) then ( OclFile["System.out"].println(i + 1) ; return ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int possibleStrings(int n,int r,int b,int g){ int fact[]=new int[n+1]; fact[0]=1 ; for(int i=1 ; i<=n ; i++)fact[i]=fact[i-1]*i ; int left=n-(r+g+b); int sum=0 ; for(int i=0 ; i<=left ; i++){ for(int j=0 ; j<=left-i ; j++){ int k=left-(i+j); sum=sum+fact[n]/(fact[i+r]*fact[j+b]*fact[k+g]); } } return sum ; } public static void main(String[] args){ int n=4,r=2 ; int b=0,g=1 ; System.out.println(possibleStrings(n,r,b,g)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation possibleStrings( n : int, r : int, b : int, g : int) : int pre: true post: true activity: ( var fact : Sequence(int) ; fact := Integer.subrange(1,n + 1)->collect(0) ; fact[0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( fact[i+1] := fact[i - 1+1] * i ; ; i := i + 1 ) ; var left : int ; left := n - (r + g + b) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i <= left do ( ( var j : int ; j := 0 ; while j <= left - i do ( ( var k : int ; k := left - (i + j) ; sum := sum + fact[n+1] / (fact[i + r+1] * fact[j + b+1] * fact[k + g+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; var r : int ; r := 2 ; var b : int ; b := 0 ; var g : int ; g := 1 ; OclFile["System.out"].println(possibleStrings(n, r, b, g)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MAX=100 ; static void middlesum(int mat[][],int n){ int row_sum=0,col_sum=0 ; for(int i=0 ; itoInteger() ; var str_x : Sequence(String) ; str_x := br.readLine()->split(" ") ; var str_y : Sequence(String) ; str_y := br.readLine()->split(" ") ; var x : Sequence(double) ; x := Integer.subrange(1,n)->collect(0.0) ; var y : Sequence(double) ; y := Integer.subrange(1,n)->collect(0.0) ; var d1 : double ; d1 := 0d ; var d2 : double ; d2 := 0d ; var d3 : double ; d3 := 0d ; var di : double ; di := 0d ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := (str_x[i+1])->toReal() ; y[i+1] := (str_y[i+1])->toReal() ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( d1 := d1+(if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif) ; d2 := d2+(if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif->pow(2)) ; d3 := d3+(if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif->pow(3)) ; if (di < if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif) then ( di := if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif ) else skip ) ; i := i + 1 ) ; sb := sb + StringLib.newString(d1) + StringLib.newString("\n") ; sb := sb + StringLib.newString((d2)->sqrt()) + StringLib.newString("\n") ; sb := sb + StringLib.newString((d3)->cbrt()) + StringLib.newString("\n") ; sb := sb + StringLib.newString(di) + StringLib.newString("\n") ; OclFile["System.out"].print(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Main { public static void main(String[] args){ try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] x_st=br.readLine().split(" "); String[] y_st=br.readLine().split(" "); double[] x=new double[n]; double[] y=new double[n]; double[] distance=new double[n]; double d1=0,d2=0,d3=0,d_infinite=0 ; for(int i=0 ; itoInteger() ; var x_st : Sequence(String) ; x_st := br.readLine()->split(" ") ; var y_st : Sequence(String) ; y_st := br.readLine()->split(" ") ; var x : Sequence(double) ; x := Integer.subrange(1,n)->collect(0.0) ; var y : Sequence(double) ; y := Integer.subrange(1,n)->collect(0.0) ; var distance : Sequence(double) ; distance := Integer.subrange(1,n)->collect(0.0) ; var d1 : double ; d1 := 0 ; var d2 : double ; d2 := 0 ; var d3 : double ; d3 := 0 ; var d_infinite : double ; d_infinite := 0 ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := (x_st[i+1])->toReal() ; y[i+1] := (y_st[i+1])->toReal() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( distance[i+1] := if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif ; d1 := d1+(distance[i+1]) ; d2 := d2+(distance[i+1]->pow(2)) ; d3 := d3+(distance[i+1]->pow(3)) ; if (d_infinite < distance[i+1]) then d_infinite := distance[i+1] ; else skip ; ) ; i := i + 1 ) ; d2 := d2->pow(1. / 2) ; d3 := d3->pow(1. / 3) ; OclFile["System.out"].println(d1 + "\n" + d2 + "\n" + d3 + "\n" + d_infinite) ; ) catch (e : ProgramException) do ( OclFile["System.out"].println(e) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.PrintWriter ; import java.text.DecimalFormat ; import java.util.Scanner ; class Main { private static final Scanner sc=new Scanner(System.in); private static final DecimalFormat fmt=new DecimalFormat("0.########"); private static final PrintWriter out=new PrintWriter(System.out); public static void main(String[] Args)throws IOException { final int n=Integer.parseInt(sc.next()); final int x[]=new int[n]; for(int i=0 ; itoInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( x[i+1] := (sc.getCurrent())->toInteger() ; ; i := i + 1 ) ; var d1 : int ; d1 := 0 ; var d2 : int ; d2 := 0 ; var di : int ; di := 0 ; var d3 : long ; d3 := 0 ; var i : int ; i := 0 ; while i < n do ( ( var y : int ; y := if (sc.getCurrent())->toInteger() - x[i+1] < 0 then -((sc.getCurrent())->toInteger() - x[i+1]) else (sc.getCurrent())->toInteger() - x[i+1] endif ; d1 := d1+(y) ; d2 := d2+(y * y) ; d3 := d3+(y * y * y) ; di := Set{di, y}->max() ; ) ; i := i + 1 ) ; skip ; skip ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; class Main { public static void main(String[] args)throws NumberFormatException,IOException { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[] vect1=new int[n]; int[] vect2=new int[n]; double keisan=0.0 ; double inf=Double.POSITIVE_INFINITY ; for(int i=0 ; ikeisan){ keisan=zet ; } } System.out.println(keisan); keisan=0.0 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var vect1 : Sequence(int) ; vect1 := Integer.subrange(1,n)->collect(0) ; var vect2 : Sequence(int) ; vect2 := Integer.subrange(1,n)->collect(0) ; var keisan : double ; keisan := 0.0 ; var inf : double ; inf := Math_PINFINITY ; var i : int ; i := 0 ; while i < n do ( ( vect1[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( vect2[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var zet : double ; zet := 0 ; zet := vect1[i+1] - vect2[i+1] ; zet := if zet < 0 then -(zet) else zet endif ; zet := zet->pow(1) ; keisan := keisan+(zet) ; ) ; i := i + 1 ) ; keisan := keisan->pow((1.0 / 1.0)) ; OclFile["System.out"].println(keisan) ; keisan := 0.0 ; var i : int ; i := 0 ; while i < n do ( ( var zet : double ; zet := 0 ; zet := vect1[i+1] - vect2[i+1] ; zet := if zet < 0 then -(zet) else zet endif ; zet := zet->pow(2) ; keisan := keisan+(zet) ; ) ; i := i + 1 ) ; keisan := keisan->pow((1.0 / 2.0)) ; OclFile["System.out"].println(keisan) ; keisan := 0.0 ; var i : int ; i := 0 ; while i < n do ( ( var zet : double ; zet := 0 ; zet := vect1[i+1] - vect2[i+1] ; zet := if zet < 0 then -(zet) else zet endif ; zet := zet->pow(3) ; keisan := keisan+(zet) ; ) ; i := i + 1 ) ; keisan := keisan->pow((1.0 / 3.0)) ; OclFile["System.out"].println(keisan) ; keisan := 0.0 ; var i : int ; i := 0 ; while i < n do ( ( var zet : double ; zet := 0 ; zet := vect1[i+1] - vect2[i+1] ; zet := if zet < 0 then -(zet) else zet endif ; if (zet > keisan) then ( keisan := zet ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(keisan) ; keisan := 0.0 ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); double x[]=new double[100]; double y[]=new double[100]; double p_1=0,p_2=0,p_3=0,p_infinity=-1 ; int N=scanner.nextInt(); for(int i=0 ; icollect(0.0) ; var y : Sequence(double) ; y := Integer.subrange(1,100)->collect(0.0) ; var p var pdouble : double ; pdouble := 0 : double ; p var pdouble : double ; pdouble := 0 := 0 ; var p0 : double ; p0 := 0 ; var p_3 : double ; p_3 := 0 ; var p_infinity : double ; p_infinity := -1 ; var N : int ; N := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < N do ( x[i+1] := scanner.getCurrent()->toReal() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( y[i+1] := scanner.getCurrent()->toReal() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( pp_1 := pp_1+(if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif) ; p(x[i+1] - y[i+1]) * (x[i+1] - y[i+1]) := p(x[i+1] - y[i+1]) * (x[i+1] - y[i+1])+((x[i+1] - y[i+1]) * (x[i+1] - y[i+1])) ; p_3 := p_3+(if (x[i+1] - y[i+1]) * (x[i+1] - y[i+1]) * (x[i+1] - y[i+1]) < 0 then -((x[i+1] - y[i+1]) * (x[i+1] - y[i+1]) * (x[i+1] - y[i+1])) else (x[i+1] - y[i+1]) * (x[i+1] - y[i+1]) * (x[i+1] - y[i+1]) endif) ; p_infinity := Set{p_infinity, if x[i+1] - y[i+1] < 0 then -(x[i+1] - y[i+1]) else x[i+1] - y[i+1] endif}->max() ) ; i := i + 1 ) ; OclFile["System.out"].printf("%.10f\n", p"%.10f\n") ; OclFile["System.out"].printf("%.10f\n", (p_2)->sqrt()) ; OclFile["System.out"].printf("%.10f\n", (p_3)->cbrt()) ; OclFile["System.out"].printf("%.10f\n", p_infinity) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int BinarySearch(long low,long high,long b){ long mid=0 ; while(low0 ; size--){ if(b % size!=0)continue ; else if((b/size-size+1)% 2!=0)continue ; a=(int)(b/size-size+1)/2 ; break ; } System.out.println(a+" "+size); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation BinarySearch( low : long, high : long, b : long) : int pre: true post: true activity: ( var mid : long ; mid := 0 ; while (low < high) do ( mid := (low + high) / 2 ; var ans : long ; ans := mid * mid + mid ; if (ans = b) then return mid->oclAsType(int) else if (ans < b) then low := mid + 1 else high := mid ; ; ) ; return mid->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while (true) do ( var b : long ; b := sc.getCurrent()->toLong() ; if (b = 0) then break else skip ; b := b*(2) ; var max : int ; max := BinarySearch(1, (b)->sqrt()->oclAsType(long) + 2, b) ; var size : int ; size := 1 ; var a : int ; a := 0 ; size := max ; while size > 0 do ( ( if (b mod size /= 0) then continue else if ((b / size - size + 1) mod 2 /= 0) then continue else skip ; ; a := (b / size - size + 1)->oclAsType(int) / 2 ; break ) ; size := size - 1 ) ; OclFile["System.out"].println(a + " " + size) ; ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class aliceAndBob { public static long ans2 ; public static void gcd(long i,long j){ if(i==0 || j==0){ ans2=j+i ; return ; } if(i>=j){ gcd(i % j,j); } else { gcd(j % i,i); } } public static void main(String[] args){ Kattio io=new Kattio(); long n=io.nextLong(); long a=io.nextLong(); long max=a ; long gcd=a ; for(long i=1 ; i= j) then ( execute gcd(i mod j, j) ) else ( execute gcd(j mod i, i) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : Kattio ; io := Kattio.newKattio() ; var n : long ; n := io.nextLong() ; var a : long ; a := io.nextLong() ; var max : long ; max := a ; var gcd : long ; gcd := a ; var i : long ; i := 1 ; while i < n do ( ( var b : long ; b := io.nextLong() ; max := Set{max, b}->max() ; ans2 := 0 ; execute gcd(gcd, b) ; gcd := ans2 ; ) ; i := i + 1 ) ; if (((max / gcd) - n) mod 2 = 0) then ( io.print("Bob") ) else ( io.print("Alice") ) ; io.close() ; ); static class Kattio extends OclFile { attribute r : OclFile; attribute st : OclIterator; static operation newKattio() : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute this(OclFile["System.in"], OclFile["System.out"]) ); static operation newKattio( i : OclFile, o : OclFile) : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(i, o); return self ); operation initialise( i : OclFile, o : OclFile) : void pre: true post: true activity: ( execute super(o) ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(i)) ); static operation newKattio( problemName : String) : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(problemName); return self ); operation initialise( problemName : String) : void pre: true post: true activity: ( execute super(problemName + ".out") ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(problemName + ".in")) ); operation next() : String pre: true post: true activity: ( try ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(r.readLine()) ; ; return st.next() ) catch (e : ProgramException) do skip return null ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _835A_KeyRaces { public static void main(String[] args){ Scanner input=new Scanner(System.in); int s=input.nextInt(); int v1=input.nextInt(); int v2=input.nextInt(); int t1=input.nextInt(); int t2=input.nextInt(); int r1=2*t1+s*v1 ; int r2=2*t2+s*v2 ; if(r1toInteger() ; var v1 : int ; v1 := input.getCurrent()->toInteger() ; var v2 : int ; v2 := input.getCurrent()->toInteger() ; var t1 : int ; t1 := input.getCurrent()->toInteger() ; var t2 : int ; t2 := input.getCurrent()->toInteger() ; var r1 : int ; r1 := 2 * t1 + s * v1 ; var r2 : int ; r2 := 2 * t2 + s * v2 ; if (r1 < r2) then ( OclFile["System.out"].println("First") ) else if (r2 < r1) then ( OclFile["System.out"].println("Second") ) else ( OclFile["System.out"].println("Friendship") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B940 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int K=in.nextInt(); long A=in.nextInt(); long B=in.nextInt(); long cost=0 ; while(N!=1){ if(N=(N-N/K)*A){ cost+=(N-1)*A ; break ; } cost+=B ; N/=K ; } System.out.println(cost); } } ------------------------------------------------------------ OCL File: --------- class B940 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var A : long ; A := in.getCurrent()->toInteger() ; var B : long ; B := in.getCurrent()->toInteger() ; var cost : long ; cost := 0 ; while (N /= 1) do ( if (N < K) then ( cost := cost+((N - 1) * A) ; break ) else skip ; var r : int ; r := N mod K ; cost := cost+(r * A) ; N := N-(r) ; if (B >= (N - N / K) * A) then ( cost := cost+((N - 1) * A) ; break ) else skip ; cost := cost+(B) ; N := N/(K) ; ) ; OclFile["System.out"].println(cost) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; import java.util.stream.Collectors ; public class A835 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String line=scanner.nextLine(); Listnums=Arrays.stream(line.split(" ")).map(Integer :: parseInt).collect(Collectors.toList()); int charCount=nums.get(0); int timeOne=nums.get(1); int timeTwo=nums.get(2); int pingOne=nums.get(3); int pingTwo=nums.get(4); if(timeOne*charCount+pingOne*2>timeTwo*charCount+pingTwo*2){ System.out.println("Second"); } else if(timeOne*charCount+pingOne*2split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) ).collect(Collectors.toList()) ; var charCount : int ; charCount := nums->at(0+1) ; var timeOne : int ; timeOne := nums->at(1+1) ; var timeTwo : int ; timeTwo := nums->at(2+1) ; var pingOne : int ; pingOne := nums->at(3+1) ; var pingTwo : int ; pingTwo := nums->at(4+1) ; if (timeOne * charCount + pingOne * 2 > timeTwo * charCount + pingTwo * 2) then ( OclFile["System.out"].println("Second") ) else if (timeOne * charCount + pingOne * 2 < timeTwo * charCount + pingTwo * 2) then ( OclFile["System.out"].println("First") ) else ( OclFile["System.out"].println("Friendship") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.util.Arrays ; import java.util.Scanner ; public class giuhiuhi { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int s=sc.nextInt(); int v1=sc.nextInt(); int v2=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); int sum1=t1*2+s*v1 ; int sum2=t2*2+s*v2 ; if(sum1==sum2){ System.out.println("Friendship"); } else if(sum1>sum2){ System.out.println("Second"); } else { System.out.println("First"); } } } ------------------------------------------------------------ OCL File: --------- class giuhiuhi { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : int ; s := sc.getCurrent()->toInteger() ; var v1 : int ; v1 := sc.getCurrent()->toInteger() ; var v2 : int ; v2 := sc.getCurrent()->toInteger() ; var t1 : int ; t1 := sc.getCurrent()->toInteger() ; var t2 : int ; t2 := sc.getCurrent()->toInteger() ; var sum1 : int ; sum1 := t1 * 2 + s * v1 ; var sum2 : int ; sum2 := t2 * 2 + s * v2 ; if (sum1 = sum2) then ( OclFile["System.out"].println("Friendship") ) else if (sum1 > sum2) then ( OclFile["System.out"].println("Second") ) else ( OclFile["System.out"].println("First") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class _835A_KeyRaces { public static void main(String[] args){ Scanner in=new Scanner(System.in); int s=in.nextInt(); int v1=in.nextInt(); int v2=in.nextInt(); int t1=in.nextInt(); int t2=in.nextInt(); int resF=s*v1+(2*t1); int resS=s*v2+(2*t2); if(resFtoInteger() ; var v1 : int ; v1 := in.getCurrent()->toInteger() ; var v2 : int ; v2 := in.getCurrent()->toInteger() ; var t1 : int ; t1 := in.getCurrent()->toInteger() ; var t2 : int ; t2 := in.getCurrent()->toInteger() ; var resF : int ; resF := s * v1 + (2 * t1) ; var resS : int ; resS := s * v2 + (2 * t2) ; if (resF < resS) then ( OclFile["System.out"].println("First") ) else if (resS < resF) then ( OclFile["System.out"].println("Second") ) else ( OclFile["System.out"].println("Friendship") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long count_of_ways(long n){ long count=0 ; for(int i=0 ; i<=n ; i++)for(int j=0 ; j<=n ; j++)for(int k=0 ; k<=n ; k++)if(i+j+k==n)count++; return count ; } public static void main(String[] args){ long n=3 ; System.out.println(count_of_ways(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count_of_ways( n : long) : long pre: true post: true activity: ( var count : long ; count := 0 ; var i : int ; i := 0 ; while i <= n do ( var j : int ; j := 0 ; while j <= n do ( var k : int ; k := 0 ; while k <= n do ( if (i + j + k = n) then count := count + 1 ; else skip ; ; k := k + 1 ) ; ; j := j + 1 ) ; ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 3 ; OclFile["System.out"].println(count_of_ways(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); System.out.println(solve(s)); sc.close(); } static int solve(String s){ return Math.min(s.length(),(int)s.chars().filter(ch->ch=='a').count()*2-1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; OclFile["System.out"].println(solve(s)) ; skip ); static operation solve( s : String) : int pre: true post: true activity: ( return Set{s->size(), s.chars()->select( _x1 | (lambda ch : OclAny in ch = 'a')->apply(_x1) )->size()->oclAsType(int) * 2 - 1}->min() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MAIN { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String linea=sc.nextLine(); int con=0 ; int total=0 ; for(int i=0 ; i=linea.length())System.out.println(linea.length()); else System.out.println(total); } } ------------------------------------------------------------ OCL File: --------- class MAIN { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var linea : String ; linea := sc.nextLine() ; var con : int ; con := 0 ; var total : int ; total := 0 ; var i : int ; i := 0 ; while i < linea->size() do ( ( if (((linea->at(i+1)) + "") = "a") then con := con + 1 ; else skip ) ; i := i + 1 ) ; total := con + con - 1 ; if (total >= linea->size()) then OclFile["System.out"].println(linea->size()) else OclFile["System.out"].println(total) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); int count=0 ; for(char c : s.toCharArray())if(c=='a')count++; System.out.println(Math.min(s.length(),Math.max(0,2*count-1))); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; var count : int ; count := 0 ; for (c : s->characters()) do ( if (c = 'a') then count := count + 1 ; else skip ; ) ; OclFile["System.out"].println(Set{s->size(), Set{0, 2 * count - 1}->max()}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _1146A_LoveA { public static void main(String[] args){ Scanner input=new Scanner(System.in); String str=input.next(); int a=0 ; int nona=0 ; for(char c : str.toCharArray()){ if(c=='a'){ a++; } else { nona++; } } if(a>nona){ System.out.println(str.length()); } else { System.out.println(2*a-1); } } } ------------------------------------------------------------ OCL File: --------- class _1146A_LoveA { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := input.getCurrent() ; var a : int ; a := 0 ; var nona : int ; nona := 0 ; for (c : str->characters()) do ( ( if (c = 'a') then ( a := a + 1 ) else ( nona := nona + 1 ) ) ) ; if (a > nona) then ( OclFile["System.out"].println(str->size()) ) else ( OclFile["System.out"].println(2 * a - 1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb=new StringBuffer(); while(true){ int n=Integer.parseInt(br.readLine()); if(n==0){ break ; } int from=1 ; int to=calcN(n); long sum=calcSum(to); int m=0 ; int a=0 ; for(int i=calcN(n); i>=1 ; i--){ if(2*n % i==0){ int tmp2a=2*n/i-i+1 ; if(tmp2a % 2==0 && tmp2a>=2){ m=i ; a=tmp2a/2 ; break ; } } } sb.append(a+" "+m+"\n"); } System.out.print(sb); } static int calcN(long sum){ return(int)Math.ceil((-1+Math.sqrt(1+(double)8*sum))/2); } static long calcSum(long n){ return(n*(n+1)/2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sb : String ; sb := StringLib.newString() ; while (true) do ( var n : int ; n := (br.readLine())->toInteger() ; if (n = 0) then ( break ) else skip ; var from : int ; from := 1 ; var to : int ; to := calcN(n) ; var sum : long ; sum := calcSum(to) ; var m : int ; m := 0 ; var a : int ; a := 0 ; var i : int ; i := calcN(n) ; while i >= 1 do ( ( if (2 * n mod i = 0) then ( var tmp2a : int ; tmp2a := 2 * n / i - i + 1 ; if (tmp2a mod 2 = 0 & tmp2a >= 2) then ( m := i ; a := tmp2a / 2 ; break ) else skip ) else skip ) ; i := i - 1 ) ; sb := sb + StringLib.newString(a + " " + m + "\n") ; ) ; OclFile["System.out"].print(sb) ); static operation calcN( sum : long) : int pre: true post: true activity: ( return ((-1 + (1 + 8->oclAsType(double) * sum)->sqrt()) / 2)->ceil()->oclAsType(int) ); static operation calcSum( n : long) : long pre: true post: true activity: ( return (n * (n + 1) / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tcx==0).count(); return zeroCount+((Arrays.stream(a).sum()+zeroCount==0)? 1 : 0); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(a)) ) ; tc := tc + 1 ) ; skip ); static operation solve( a : Sequence(int)) : int pre: true post: true activity: ( var zeroCount : int ; zeroCount := stream(a)->select( _x1 | (lambda x : OclAny in x = 0)->apply(_x1) )->size()->oclAsType(int) ; return zeroCount + (if (stream(a)->sum() + zeroCount = 0) then 1 else 0 endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ProblemB { public static void main(String[] args){ Scanner scn=new Scanner(System.in); long x=scn.nextInt(); long y=scn.nextInt(); long n=scn.nextInt(); int mod=(int)(1e9)+7 ; long[] arr={ x,y,y-x,-x,-y,x-y }; System.out.println(((arr[(int)((n-1)% 6)] % mod)+mod)% mod); } } ------------------------------------------------------------ OCL File: --------- class ProblemB { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : long ; x := scn.getCurrent()->toInteger() ; var y : long ; y := scn.getCurrent()->toInteger() ; var n : long ; n := scn.getCurrent()->toInteger() ; var mod : int ; mod := (1e9)->oclAsType(int) + 7 ; var arr : Sequence(long) ; arr := Sequence{x,y,y - x,-x,-y,x - y} ; OclFile["System.out"].println(((arr[((n - 1) mod 6)->oclAsType(int)+1] mod mod) + mod) mod mod) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class B { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); long n=in.nextLong(),k=in.nextLong(),A=in.nextLong(),B=in.nextLong(); if(k==1){ pw.println((n-1)*A); pw.close(); return ; } long ans=0 ; while(n!=1){ if(n=(n-n/k)*A){ ans+=(n-n/k)*A ; n/=k ; } else { ans+=B ; n/=k ; } } pw.println(ans); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : long ; n := in.getCurrent()->toLong() ; var k : long ; k := in.getCurrent()->toLong() ; var A : long ; A := in.getCurrent()->toLong() ; var B : long ; B := in.getCurrent()->toLong() ; if (k = 1) then ( skip ; skip ; return ) else skip ; var ans : long ; ans := 0 ; while (n /= 1) do ( if (n < k) then ( ans := ans+((n - 1) * A) ; break ) else skip ; ans := ans+((n mod k) * A) ; n := n-((n mod k)) ; if (B >= (n - n / k) * A) then ( ans := ans+((n - n / k) * A) ; n := n/(k) ) else ( ans := ans+(B) ; n := n/(k) ) ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main implements Runnable { BufferedReader in ; PrintWriter out ; StringTokenizer tok=new StringTokenizer(""); public static void main(String[] args){ new Thread(null,new Main(),"",256*(1L<<20)).start(); } public void run(){ try { long t1=System.currentTimeMillis(); if(System.getProperty("ONLINE_JUDGE")!=null){ in=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); } else { in=new BufferedReader(new FileReader("input.txt")); out=new PrintWriter("output.txt"); } Locale.setDefault(Locale.US); solve(); in.close(); out.close(); long t2=System.currentTimeMillis(); System.err.println("Time="+(t2-t1)); } catch(Throwable t){ t.printStackTrace(System.err); System.exit(-1); } } String readString()throws IOException { while(! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt()throws IOException { return Integer.parseInt(readString()); } long readLong()throws IOException { return Long.parseLong(readString()); } double readDouble()throws IOException { return Double.parseDouble(readString()); } void solve()throws IOException { int tests=readInt(); for(int i=0 ; ipow(20)))->oclAsType(long))).start() ); operation run() : void pre: true post: true activity: ( try ( var t1 : long ; t1 := OclDate.getSystemTime() ; if (OclProcess.getEnvironmentProperty("ONLINE_JUDGE") /= null) then ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ) else ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; out := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ) ; Locale.setDefault(Locale.US) ; execute solve() ; skip ; skip ; var t2 : long ; t2 := OclDate.getSystemTime() ; OclFile["System.err"].println("Time=" + (t2 - t1)) ; ) catch (t : OclException) do ( t.printStackTrace(OclFile["System.err"]) ; OclProcess.exit(-1) ) ); operation readString() : String pre: true post: true activity: ( while (not(tok.hasNext())) do ( tok := OclIterator.newOclIterator_String(in.readLine()) ) ; return tok.next() ); operation readInt() : int pre: true post: true activity: ( return (readString())->toInteger() ); operation readLong() : long pre: true post: true activity: ( return (readString())->toLong() ); operation readDouble() : double pre: true post: true activity: ( return (readString())->toReal() ); operation solve() : void pre: true post: true activity: ( var tests : int ; tests := readInt() ; var i : int ; i := 0 ; while i < tests do ( ( var len : int ; len := readInt() ; var sum : int ; sum := 0 ; var ops : int ; ops := 0 ; var j : int ; j := 0 ; while j < len do ( ( var x : int ; x := readInt() ; sum := sum+(x) ; if (x = 0) then ( ops := ops + 1 ; sum := sum + 1 ) else skip ) ; j := j + 1 ) ; if (sum = 0) then ( ops := ops + 1 ) else skip ; skip ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; public class P1300A { public static void main(String[] args)throws IOException { BufferedReader io=new BufferedReader(new InputStreamReader(System.in)); Integer cnt=Integer.valueOf(io.readLine()); Listrs=new ArrayList(); while(cnt>0){ cnt--; Integer len=Integer.valueOf(io.readLine()); String[] input=io.readLine().split(" "); Boolean flag=false ; Integer tmp=0 ; while(! flag){ Integer sum=0 ; boolean allNegative=true ; for(int i=0 ; i0){ allNegative=false ; } } if(sum.compareTo(0)==0){ if(! allNegative){ tmp++; flag=true ; } } else if(sum.compareTo(0)!=0){ flag=true ; } } rs.add(tmp); } for(Integer integer : rs){ System.out.println(integer); } } } ------------------------------------------------------------ OCL File: --------- class P1300A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : OclFile ; io := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var cnt : int ; cnt := (io.readLine())->toInteger() ; var rs : Sequence(int) ; rs := Sequence{} ; while (cnt > 0) do ( cnt := cnt - 1 ; var len : int ; len := (io.readLine())->toInteger() ; var input : Sequence(String) ; input := io.readLine()->split(" ") ; var flag : Boolean ; flag := false ; var tmp : int ; tmp := 0 ; while (not(flag)) do ( var sum : int ; sum := 0 ; var allNegative : boolean ; allNegative := true ; var i : int ; i := 0 ; while i < input->size() do ( ( sum := sum + (input[i+1])->toInteger() ; if (input[i+1] = "0") then ( input[i+1] := "1" ; sum := sum + 1 ; tmp := tmp + 1 ) else skip ; if ((input[i+1])->toInteger()->compareTo(0) > 0) then ( allNegative := false ) else skip ) ; i := i + 1 ) ; if (sum->compareTo(0) = 0) then ( if (not(allNegative)) then ( tmp := tmp + 1 ; flag := true ) else skip ) else if (sum->compareTo(0) /= 0) then ( flag := true ) else skip ; ) ; rs := rs->including(tmp) ; ) ; for (integer : rs) do ( ( OclFile["System.out"].println(integer) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args){ FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder sb=new StringBuilder(); int t=fs.nextInt(); while(t-->0){ int n=fs.nextInt(); int ch=0,res=0 ; for(int i=0 ; i 0) do ( t := t - 1 ; skip ; ( var n : int ; n := fs.nextInt() ; var ch : int ; ch := 0 ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := fs.nextInt() ; if (a = 0) then ( ch := ch + 1 ; res := res + 1 ) else ( res := res+(a) ) ) ; i := i + 1 ) ; if (res = 0) then ch := ch + 1 ; else skip ; sb := sb + StringLib.newString(ch) + StringLib.newString("\n") ; ) ; ) ; skip ; skip ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class _805B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String a="aabb" ; while(a.length()toInteger() ; var a : String ; a := "aabb" ; while (a->size() < n) do ( a := a+(a) ) ; OclFile["System.out"].println(a.subrange(0+1,n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class _3_Palindrome { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); StringBuilder sb=new StringBuilder(); int i=0 ; boolean appendA=true ; while(itoInteger() ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; var appendA : boolean ; appendA := true ; while (i < n & i + 1 < n) do ( if (appendA) then sb := sb + StringLib.newString("aa") else sb := sb + StringLib.newString("bb") ; ; appendA := not(appendA) ; i := i+(2) ) ; if ((i < n)) then ( if (appendA) then ( sb := sb + StringLib.newString("a") ) else ( sb := sb + StringLib.newString("b") ) ) else skip ; OclFile["System.out"].println(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.*; public class B_3_palindrome { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); char[] arr=new char[t]; Arrays.fill(arr,'a'); for(int i=2 ; itoInteger() ; var arr : Sequence(String) ; arr := Integer.subrange(1,t)->collect(0) ; arr := arr->collect('a') ; var i : int ; i := 2 ; while i < arr->size() do ( ( arr[i+1] := 'b' ; if (i + 1 < arr->size()) then arr[i + 1+1] := 'b' ; else skip ) ; i := i+(4) ) ; OclFile["System.out"].println(StringLib.newString(arr)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void pattern(int n){ int i,j ; for(i=n-1 ; i>=0 ; i--){ for(j=n-1 ; j>i ; j--){ System.out.print(" "); } System.out.print((char)(i+65)); for(j=1 ; j<(i*2); j++)System.out.print(" "); if(i>=1)System.out.print((char)(i+65)); System.out.print("\n"); } } public static void main(String args[]){ int n=5 ; pattern(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation pattern( n : int) : void pre: true post: true activity: ( var i : int ; var j : int ; i := n - 1 ; while i >= 0 do ( ( j := n - 1 ; while j > i do ( ( OclFile["System.out"].print(" ") ) ; j := j - 1 ) ; OclFile["System.out"].print((i + 65)->oclAsType(String)) ; j := 1 ; while j < (i * 2) do ( OclFile["System.out"].print(" ") ; ; j := j + 1 ) ; if (i >= 1) then OclFile["System.out"].print((i + 65)->oclAsType(String)) ; else skip ; OclFile["System.out"].print("\n") ; ) ; i := i - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; execute pattern(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void pattern(int n){ int i,j,k=0 ; for(i=n-1 ; i>=0 ; i--){ for(j=n-1 ; j>k ; j--){ System.out.print(" "); } System.out.print((char)(i+65)); for(j=1 ; j<(k*2); j++)System.out.print(" "); if(i= 0 do ( ( j := n - 1 ; while j > k do ( ( OclFile["System.out"].print(" ") ) ; j := j - 1 ) ; OclFile["System.out"].print((i + 65)->oclAsType(String)) ; j := 1 ; while j < (k * 2) do ( OclFile["System.out"].print(" ") ; ; j := j + 1 ) ; if (i < n - 1) then OclFile["System.out"].print((i + 65)->oclAsType(String)) ; else skip ; OclFile["System.out"].print("\n") ; k := k + 1 ; ) ; i := i - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; execute pattern(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int changeTheArray(int arr[],int n){ int minEle=Arrays.stream(arr).min().getAsInt(); int maxEle=Arrays.stream(arr).max().getAsInt(); int minOperations=Integer.MAX_VALUE ; for(int num=minEle ; num<=maxEle ; num++){ int operations=0 ; for(int i=0 ; imin() ) ; num := num + 1 ) ; return minOperations ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,1,4} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(changeTheArray(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { static int B ; static int num ; static int left,right ; public static void main(String args[])throws IOException { Scanner scan=new Scanner(System.in); for(B=scan.nextInt(); B>0 ; B=scan.nextInt()){ left=1 ; right=1 ; num=0 ; for(int i=1 ; ; i++){ num+=i ; right=i ; if(num>=B){ break ; } } while(true){ if(num==B){ System.out.println(left+" "+(right-left+1)); break ; } else if(num>B){ Numdec(); } else if(numB){ left=B ; right=B ; } } public static void Numdec(){ while(num>B){ num-=left ; left++; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute B : int; static attribute num : int; static attribute left : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; B := scan.getCurrent()->toInteger() ; while B > 0 do ( ( left := 1 ; right := 1 ; num := 0 ; var i : int ; i := 1 ; while true do ( ( num := num+(i) ; right := i ; if (num >= B) then ( break ) else skip ) ; i := i + 1 ) ; while (true) do ( if (num = B) then ( OclFile["System.out"].println(left + " " + (right - left + 1)) ; break ) else if (num > B) then ( execute Numdec() ) else if (num < B) then ( execute NumInc() ) else skip ; ; ) ; ) ; B := scan.getCurrent()->toInteger() ) ; skip ); static operation NumInc() : void pre: true post: true activity: ( while (num < B) do ( right := right + 1 ; num := num+(right - left) ; left := left + 1 ) ; if (num / 2 > B) then ( left := B ; right := B ) else skip ); static operation Numdec() : void pre: true post: true activity: ( while (num > B) do ( num := num-(left) ; left := left + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class B { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); long n=in.nextLong(),k=in.nextLong(),A=in.nextLong(),B=in.nextLong(); long ans=0 ; while(n!=1){ if(n=(n-n/k)*A){ ans+=(n-1)*A ; break ; } ans+=B ; n/=k ; } pw.println(ans); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : long ; n := in.getCurrent()->toLong() ; var k : long ; k := in.getCurrent()->toLong() ; var A : long ; A := in.getCurrent()->toLong() ; var B : long ; B := in.getCurrent()->toLong() ; var ans : long ; ans := 0 ; while (n /= 1) do ( if (n < k) then ( ans := ans+((n - 1) * A) ; break ) else skip ; ans := ans+((n mod k) * A) ; n := n-((n mod k)) ; if (B >= (n - n / k) * A) then ( ans := ans+((n - 1) * A) ; break ) else skip ; ans := ans+(B) ; n := n/(k) ; ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForces { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; i0){ a[0]=2 ; a[1]=1 ; c2--; for(int i=2 ; i0){ a[i]=2 ; c2--; } else { a[i]=1 ; } } } else { for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var c2 : int ; c2 := 0 ; var c1 : int ; c1 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = 1) then ( c1 := c1 + 1 ) else ( c2 := c2 + 1 ) ) ; i := i + 1 ) ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; if (c1 = 0) then ( var i : int ; i := 0 ; while i < n do ( ( a[i+1] := 2 ) ; i := i + 1 ) ) else if (c2 = 0) then ( var i : int ; i := 0 ; while i < n do ( ( a[i+1] := 1 ) ; i := i + 1 ) ) else ( if (n = 1) then ( if (arr[0+1] = 2) then ( a[0+1] := 2 ) else ( a[0+1] := 1 ) ) else ( if (c2 > 0) then ( a[0+1] := 2 ; a[1+1] := 1 ; c2 := c2 - 1 ; var i : int ; i := 2 ; while i < n do ( ( if (c2 > 0) then ( a[i+1] := 2 ; c2 := c2 - 1 ) else ( a[i+1] := 1 ) ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < n do ( ( a[i+1] := 1 ) ; i := i + 1 ) ) ) ) ; ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(a[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.awt.Point ; import java.math.BigInteger ; public final class Main { BufferedReader br ; StringTokenizer stk ; public static void main(String[] args)throws Exception { new Main().run(); } { stk=null ; br=new BufferedReader(new InputStreamReader(System.in)); } void run()throws Exception { int n=ni(); int ones=0,twos=0 ; for(int i=0 ; i1){ if(twos>0){ res.append("2").append(" "); twos--; } else { res.append("1").append(" "); ones--; } } else if(i==1){ if(ones>0){ res.append("1").append(" "); ones--; } else { res.append("2").append(" "); twos--; } } } pl(res.deleteCharAt(res.length()-1)); } String nextToken()throws Exception { if(stk==null || ! stk.hasMoreTokens()){ stk=new StringTokenizer(br.readLine()," "); } return stk.nextToken(); } String nt()throws Exception { return nextToken(); } String ns()throws Exception { return br.readLine(); } int ni()throws Exception { return Integer.parseInt(nextToken()); } long nl()throws Exception { return Long.parseLong(nextToken()); } double nd()throws Exception { return Double.parseDouble(nextToken()); } void p(Object o){ System.out.print(o); } void pl(Object o){ System.out.println(o); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute br : OclFile; attribute stk : OclIterator; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation initialiseInstance() pre: true post: true activity: stk := null ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ; operation run() : void pre: true post: true activity: ( var n : int ; n := ni() ; var ones : int ; ones := 0 ; var twos : int ; twos := 0 ; var i : int ; i := 0 ; while i < n do ( ( var num : int ; num := ni() ; if (num = 1) then ( ones := ones + 1 ) else ( twos := twos + 1 ) ) ; i := i + 1 ) ; var res : String ; res := StringLib.newString((n*(2->pow(2)))->oclAsType(long)) ; var i : int ; i := 0 ; while i < n do ( ( if (i = 0 or i > 1) then ( if (twos > 0) then ( res := res + StringLib.newString("2") + StringLib.newString(" ") ; twos := twos - 1 ) else ( res := res + StringLib.newString("1") + StringLib.newString(" ") ; ones := ones - 1 ) ) else if (i = 1) then ( if (ones > 0) then ( res := res + StringLib.newString("1") + StringLib.newString(" ") ; ones := ones - 1 ) else ( res := res + StringLib.newString("2") + StringLib.newString(" ") ; twos := twos - 1 ) ) else skip ; ) ; i := i + 1 ) ; execute pl(res->excludingAt(res->size() - 1+1)) ; ); operation nextToken() : String pre: true post: true activity: ( if (stk = null or not(stk.hasNext())) then ( stk := OclIterator.newOclIterator_String_String(br.readLine(), " ") ) else skip ; return stk.next() ); operation nt() : String pre: true post: true activity: ( return nextToken() ); operation ns() : String pre: true post: true activity: ( return br.readLine() ); operation ni() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nl() : long pre: true post: true activity: ( return (nextToken())->toLong() ); operation nd() : double pre: true post: true activity: ( return (nextToken())->toReal() ); operation p( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].print(o) ); operation pl( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Problem1149A { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; int cnt1=0,cnt2=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var cnt1 : int ; cnt1 := 0 ; var cnt2 : int ; cnt2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; if (a[i+1] = 1) then cnt1 := cnt1 + 1 ; else cnt2 := cnt2 + 1 ; ) ; i := i + 1 ) ; var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; if (cnt1 = 0 or cnt2 = 0) then ( if (cnt1 = 0) then ( var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(a[i+1] + " ") ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(a[i+1] + " ") ) ; i := i + 1 ) ) ) else ( OclFile["System.out"].print(2 + " " + 1 + " ") ; var i : int ; i := 1 ; while i <= cnt2 - 1 do ( ( OclFile["System.out"].print(2 + " ") ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= cnt1 - 1 do ( ( OclFile["System.out"].print(1 + " ") ) ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1149 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int ones=0 ; int twos=0 ; for(int n=0 ; n0){ twos--; output.append("2 "); } if(ones>0){ ones--; output.append("1 "); } while(twos>0){ twos--; output.append("2 "); } while(ones>0){ ones--; output.append("1 "); } System.out.println(output); } } ------------------------------------------------------------ OCL File: --------- class A1149 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; var ones : int ; ones := 0 ; var twos : int ; twos := 0 ; var n : int ; n := 0 ; while n < N do ( ( var a : int ; a := in.getCurrent()->toInteger() ; if (a = 1) then ( ones := ones + 1 ) else ( twos := twos + 1 ) ) ; n := n + 1 ) ; var output : String ; output := StringLib.newString() ; if (twos > 0) then ( twos := twos - 1 ; output := output + StringLib.newString("2 ") ) else skip ; if (ones > 0) then ( ones := ones - 1 ; output := output + StringLib.newString("1 ") ) else skip ; while (twos > 0) do ( twos := twos - 1 ; output := output + StringLib.newString("2 ") ) ; while (ones > 0) do ( ones := ones - 1 ; output := output + StringLib.newString("1 ") ) ; OclFile["System.out"].println(output) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public int nthTerm(int N){ return(N*N*N)+(N*N)+N ; } public static void main(String[] args){ int N=3 ; GFG a=new GFG(); System.out.println(a.nthTerm(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { operation nthTerm( N : int) : int pre: true post: true activity: ( return (N * N * N) + (N * N) + N ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 3 ; var a : GFG ; a := GFG.newGFG() ; OclFile["System.out"].println(a.nthTerm(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Nth { public int nthTerm(int N){ return(N*((N % 2)+(N % 3))); } } class GFG { public static void main(String[] args){ int N=5 ; Nth a=new Nth(); System.out.println("Nth term for N="+N+" : "+a.nthTerm(N)); } } ------------------------------------------------------------ OCL File: --------- class Nth { operation nthTerm( N : int) : int pre: true post: true activity: ( return (N * ((N mod 2) + (N mod 3))) ); } class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 5 ; var a : Nth ; a := Nth.newNth() ; OclFile["System.out"].println("Nth term for N=" + N + " : " + a.nthTerm(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Nth { public int nthTerm(int N){ return(N*((N/2)+((N % 2)*2)+N)); } } class GFG { public static void main(String[] args){ int N=5 ; Nth a=new Nth(); System.out.println("Nth term for N="+N+" : "+a.nthTerm(N)); } } ------------------------------------------------------------ OCL File: --------- class Nth { operation nthTerm( N : int) : int pre: true post: true activity: ( return (N * ((N / 2) + ((N mod 2) * 2) + N)) ); } class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 5 ; var a : Nth ; a := Nth.newNth() ; OclFile["System.out"].println("Nth term for N=" + N + " : " + a.nthTerm(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.util.Arrays ; import java.util.Scanner ; public class Main { private static Scanner scanner=new Scanner(System.in); public static void main(String[] args){ int n=scanner.nextInt(); int[] a=new int[n+1]; for(int i=1 ; i<=n ; i++){ a[i]=scanner.nextInt(); } int[][] f=new int[n+1][n+1]; for(int i=0 ; i<=n ; i++){ Arrays.fill(f[i],(int)1e9); } for(int i=1 ; i<=n ; i++){ f[i][i]=1 ; } for(int len=2 ; len<=n ; len++){ for(int i=1,j=i+len-1 ; j<=n ; i++,j++){ if(a[i]==a[j]){ if(i+1>j-1){ f[i][j]=1 ; } else { f[i][j]=Math.min(f[i][j],f[i+1][j-1]); } } for(int k=i ; ktoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var f : Sequence(Sequence(int)) ; f := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 0 ; while i <= n do ( ( f[i+1] := f[i+1]->collect(1e9->oclAsType(int)) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( f[i+1][i+1] := 1 ) ; i := i + 1 ) ; var len : int ; len := 2 ; while len <= n do ( ( var i : int ; i := 1 ; var j : int ; j := i + len - 1 ; while j <= n do ( ( if (a[i+1] = a[j+1]) then ( if (i + 1 > j - 1) then ( f[i+1][j+1] := 1 ) else ( f[i+1][j+1] := Set{f[i+1][j+1], f[i + 1+1][j - 1+1]}->min() ) ) else skip ; var k : int ; k := i ; while k < j do ( ( f[i+1][j+1] := Set{f[i+1][j+1], f[i+1][k+1] + f[k + 1+1][j+1]}->min() ) ; k := k + 1 ) ) ; i := i + 1 ; j := j + 1 ) ) ; len := len + 1 ) ; OclFile["System.out"].println(f[1+1][n+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Zuma_336B { static int[] nums ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); nums=new int[n]; for(int i=0 ; i-1 ; l--){ if(l==r){ dp[l][r]=1 ; } else { dp[l][r]=dp[l][r-1]+1 ; for(int m=r-1 ; m>=l ; m--){ if(nums[m]!=nums[r])continue ; if(m==r-1){ if(m==l){ dp[l][r]=1 ; } else { dp[l][r]=Math.min(dp[l][r],dp[l][m-1]+1); } } else { if(m==l){ dp[l][r]=Math.min(dp[l][r],dp[m+1][r-1]); } else { dp[l][r]=Math.min(dp[l][r],dp[l][m-1]+dp[m+1][r-1]); } } } } } } System.out.println(dp[0][n-1]); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Zuma_336B { static attribute nums : Sequence(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( nums[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var r : int ; r := 0 ; while r < n do ( ( var l : int ; l := r ; while l > -1 do ( ( if (l = r) then ( dp[l+1][r+1] := 1 ) else ( dp[l+1][r+1] := dp[l+1][r - 1+1] + 1 ; var m : int ; m := r - 1 ; while m >= l do ( ( if (nums[m+1] /= nums[r+1]) then continue else skip ; if (m = r - 1) then ( if (m = l) then ( dp[l+1][r+1] := 1 ) else ( dp[l+1][r+1] := Set{dp[l+1][r+1], dp[l+1][m - 1+1] + 1}->min() ) ) else ( if (m = l) then ( dp[l+1][r+1] := Set{dp[l+1][r+1], dp[m + 1+1][r - 1+1]}->min() ) else ( dp[l+1][r+1] := Set{dp[l+1][r+1], dp[l+1][m - 1+1] + dp[m + 1+1][r - 1+1]}->min() ) ) ) ; m := m - 1 ) ) ) ; l := l - 1 ) ) ; r := r + 1 ) ; OclFile["System.out"].println(dp[0+1][n - 1+1]) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Zuma_336B { static int[][] memo ; static int[] nums ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); nums=new int[n]; for(int i=0 ; ir)return 0 ; if(l==r)return 1 ; if(memo[l][r]!=-1)return memo[l][r]; int res=1+helper(l,r-1); if(nums[r]==nums[r-1])res=Math.min(res,1+helper(l,r-2)); for(int m=l ; mtoInteger() ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( nums[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; memo := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; for (arr : memo) do ( arr := arr->collect(-1) ; ) ; OclFile["System.out"].println(helper(0, n - 1)) ; skip ; ); static operation helper( l : int, r : int) : int pre: true post: true activity: ( if (l > r) then return 0 else skip ; if (l = r) then return 1 else skip ; if (memo[l+1][r+1] /= -1) then return memo[l+1][r+1] else skip ; var res : int ; res := 1 + helper(l, r - 1) ; if (nums[r+1] = nums[r - 1+1]) then res := Set{res, 1 + helper(l, r - 2)}->min() ; else skip ; var m : int ; m := l ; while m < r - 1 do ( ( if (nums[m+1] /= nums[r+1]) then continue else skip ; res := Set{res, helper(l, m - 1) + helper(m + 1, r - 1)}->min() ) ; m := m + 1 ) ; return memo[l+1][r+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class Main { public static void main(String[] args){ Scanner stdin=new Scanner(System.in); while(true){ int[] size=new int[3]; size[0]=stdin.nextInt(); size[1]=stdin.nextInt(); size[2]=stdin.nextInt(); if(size[0]==0 && size[1]==0 && size[2]==0){ break ; } Arrays.sort(size); int n=stdin.nextInt(); for(int i=0 ; icollect(0) ; size[0+1] := stdin.getCurrent()->toInteger() ; size[1+1] := stdin.getCurrent()->toInteger() ; size[2+1] := stdin.getCurrent()->toInteger() ; if (size[0+1] = 0 & size[1+1] = 0 & size[2+1] = 0) then ( break ) else skip ; size := size->sort() ; var n : int ; n := stdin.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var r : int ; r := stdin.getCurrent()->toInteger() ; if (size[0+1] * size[0+1] + size[1+1] * size[1+1] < r * r * 4) then ( OclFile["System.out"].println("OK") ) else ( OclFile["System.out"].println("NA") ) ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ProblemB { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(br.readLine()); String line[]=br.readLine().split(" "); int arr[]=new int[n]; for(int i=0 ; i=k){ ans++; k++; } } System.out.println(ans); } public static void sort(int arr[]){ ArrayListlist=new ArrayList<>(); for(int it : arr)list.add(it); Collections.sort(list); for(int i=0 ; itoInteger() ; var line : Sequence(String) ; line := br.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := (line[i+1])->toInteger() ; ; i := i + 1 ) ; var k : int ; k := 1 ; execute sort(arr) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] >= k) then ( ans := ans + 1 ; k := k + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation sort( arr : Sequence(int)) : void pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{} ; for (it : arr) do ( list := list->including(it) ; ) ; list := list->sort() ; var i : int ; i := 0 ; while i < arr->size() do ( arr[i+1] := list->at(i+1) ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileNotFoundException ; import java.io.FileReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args)throws IOException,InterruptedException { PrintWriter pw=new PrintWriter(System.out); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); TreeMaptm=new TreeMap<>(); for(int i=0 ; itoInteger() ; var tm : Map(int,int) ; tm := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (tm->keys()->includes(x)) then tm := tm.replace(x, tm->at(x) + 1) ; else tm := tm->union(Map{x |-> 1}) ; ) ; i := i + 1 ) ; var c : int ; c := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var re : int ; re := tm.higherKey(i - 1) ; if (re /= null) then ( c := c + 1 ; var v : int ; v := tm->at(re) ; if (v - 1 = 0) then tm := tm->antirestrict(Set{re}) ; else tm := tm.replace(re, v - 1) ; ) else break ) ; i := i + 1 ) ; skip ; skip ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newScanner( file : String) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(file); return self ); operation initialise( file : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(file)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Polycarp { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Integer[] a=new Integer[n]; for(int i=0 ; i=day)day++; } System.out.println(day-1); } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public String nextLine()throws IOException { return br.readLine(); } public double nextDouble()throws IOException { String x=next(); StringBuilder sb=new StringBuilder("0"); double res=0,f=1 ; boolean dec=false,neg=false ; int start=0 ; if(x.charAt(0)=='-'){ neg=true ; start++; } for(int i=start ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; a := a->sort() ; var day : int ; day := 1 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] >= day) then day := day + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(day - 1) ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation nextDouble() : double pre: true post: true activity: ( var x : String ; x := next() ; var sb : String ; sb := StringLib.newString("0") ; var res : double ; res := 0 ; var f : double ; f := 1 ; var dec : boolean ; dec := false ; var neg : boolean ; neg := false ; var start : int ; start := 0 ; if (x->at(0+1) = '-') then ( neg := true ; start := start + 1 ) else skip ; var i : int ; i := start ; while i < x->size() do ( if (x->at(i+1) = '.') then ( res := (sb+"")->toLong() ; sb := StringLib.newString("0") ; dec := true ) else ( sb := sb + StringLib.newString(x->at(i+1)) ; if (dec) then f := f*(10) ; else skip ) ; ; i := i + 1 ) ; res := res+((sb+"")->toLong() / f) ; return res * (if neg then -1 else 1 endif) ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int N ; static int[] color ; static List[] e ; static boolean dfs(int v,int c){ color[v]=c ; for(int i : e[v]){ if(color[i]==c)return false ; if(color[i]==0 && ! dfs(i,-c))return false ; } return true ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int INF=Integer.MAX_VALUE/2 ; N=sc.nextInt(); color=new int[N]; e=new ArrayList[N]; int[][] d=new int[N][N]; for(int i=0 ; i(); String S=sc.next(); for(int j=0 ; jtoInteger() ; color := Integer.subrange(1,N)->collect(0) ; e := Integer.subrange(1,N)->collect(null) ; var d : Sequence(Sequence(int)) ; d := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( e[i+1] := Sequence{} ; var S : String ; S := sc.getCurrent() ; var j : int ; j := 0 ; while j < N do ( ( if (i = j) then continue else skip ; if (S->at(j+1) = '1') then ( e[i+1]->excludes(j) ; d[i+1][j+1] := 1 ) else d[i+1][j+1] := INF ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (not(dfs(0, 1))) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var dmax : int ; dmax := 0 ; var k : int ; k := 0 ; while k < N do ( var i : int ; i := 0 ; while i < N do ( var j : int ; j := 0 ; while j < N do ( d[i+1][j+1] := Set{d[i+1][j+1], d[i+1][k+1] + d[k+1][j+1]}->min() ; ; j := j + 1 ) ; ; i := i + 1 ) ; ; k := k + 1 ) ; var i : int ; i := 0 ; while i < N do ( var j : int ; j := 0 ; while j < N do ( if (d[i+1][j+1] /= INF) then dmax := Set{dmax, d[i+1][j+1]}->max() ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(dmax + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); BGraphPartition solver=new BGraphPartition(); solver.solve(1,in,out); out.close(); } static class BGraphPartition { int n ; boolean[][] a ; int[] ind ; int bfs(int u){ ind[u]=1 ; int[] q=new int[n]; int h=0,t=1 ; q[h]=u ; int ans=1 ; while(hans){ ans=k ; } } out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : BGraphPartition ; solver := BGraphPartition.newBGraphPartition() ; solver.solve(1, in, out) ; skip ; ); static class BGraphPartition { attribute n : int; attribute a : Sequence(Sequence(boolean)); attribute ind : Sequence(int); operation bfs( u : int) : int pre: true post: true activity: ( ind[u+1] := 1 ; var q : Sequence(int) ; q := Integer.subrange(1,n)->collect(0) ; var h : int ; h := 0 ; var t : int ; t := 1 ; q[h+1] := u ; var ans : int ; ans := 1 ; while (h < t) do ( u := q[h+1] ; h := h + 1 ; var v : int ; v := 0 ; while v < n do ( ( if (a[u+1][v+1]) then ( if (ind[v+1] /= 0 & ind[v+1] /= ind[u+1] - 1 & ind[v+1] /= ind[u+1] + 1) then ( return -1 ) else skip ; if (ind[v+1] = 0) then ( q[t+1] := v ; t := t + 1 ; ind[v+1] := ind[u+1] + 1 ; ans := ind[v+1] ) else skip ) else skip ) ; v := v + 1 ) ) ; return ans ); operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( n := in.getCurrent()->toInteger() ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(false)) ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := in.getCurrent() ; var j : int ; j := 0 ; while j < n do ( ( a[i+1][j+1] := s->at(j+1) = '1' ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := -1 ; var i : int ; i := 0 ; while i < n do ( ( ind := Integer.subrange(1,n)->collect(0) ; var k : int ; k := bfs(i) ; if (k > ans) then ( ans := k ) else skip ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int N=scn.nextInt(); int[][] way=new int[N][N]; scn.nextLine(); for(int j=0 ; jthe=new HashSet(); HashSetnext=new HashSet(); int now_g=0 ; next.add(n); while(! next.isEmpty()){ the=new HashSet(); now_g++; for(int j : next){ the.add(j); group[j]=now_g ; } next=new HashSet(); for(int j : the){ for(int i=0 ; itoInteger() ; var way : Sequence(Sequence(int)) ; way := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; skip ; var j : int ; j := 0 ; while j < N do ( ( var ss : Sequence(String) ; ss := scn.nextLine()->characters() ; var i : int ; i := 0 ; while i < N do ( ( way[j+1][i+1] := if (ss[i+1] = 48) then 0 else 1 endif ) ; i := i + 1 ) ) ; j := j + 1 ) ; var ans : int ; ans := -1 ; var n : int ; n := 0 ; while n < N do ( ( var group : Sequence(int) ; group := Integer.subrange(1,N)->collect(0) ; var can : boolean ; can := true ; var the : Set(int) ; the := Set{} ; var next : Set(int) ; next := Set{} ; var now_g : int ; now_g := 0 ; next := next->including(n) ; while (not(next->isEmpty())) do ( the := Set{} ; now_g := now_g + 1 ; for (j : next) do ( ( the := the->including(j) ; group[j+1] := now_g ) ) ; next := Set{} ; for (j : the) do ( ( var i : int ; i := 0 ; while i < N do ( ( if (way[j+1][i+1] /= 1) then continue else skip ; if (group[i+1] /= 0) then ( if (group[i+1] = now_g - 1) then ( continue ) else ( can := false ; break ) ) else skip ; next := next->including(i) ) ; i := i + 1 ) ; if (not(can)) then break else skip ) ) ; ) ; if (can) then ans := Set{now_g, ans}->max() ; else skip ; ) ; n := n + 1 ) ; OclFile["System.out"].println(if (ans < 2) then -1 else ans endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1681A_SpaceNavigation { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ int x=input.nextInt(); int y=input.nextInt(); input.nextLine(); String direction=input.nextLine(); int up=0 ; int right=0 ; int down=0 ; int left=0 ; boolean flag1=false ; boolean flag2=false ; for(char c : direction.toCharArray()){ switch(c){ case 'U' : up++; break ; case 'R' : right++; break ; case 'L' : left--; break ; case 'D' : down--; break ; } if(x==left || x==right){ flag1=true ; } if(y==up || y==down){ flag2=true ; } if(flag1 && flag2){ break ; } } if(flag1 && flag2){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class _1681A_SpaceNavigation { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; while (test > 0) do ( test := test - 1 ; skip ; ( var x : int ; x := input.getCurrent()->toInteger() ; var y : int ; y := input.getCurrent()->toInteger() ; skip ; var direction : String ; direction := input.nextLine() ; var up : int ; up := 0 ; var right : int ; right := 0 ; var down : int ; down := 0 ; var left : int ; left := 0 ; var flag1 : boolean ; flag1 := false ; var flag2 : boolean ; flag2 := false ; for (c : direction->characters()) do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (c) ; if _switchval = 'U' then up := up + 1 ; break else skip ; if _switchval = 'R' then right := right + 1 ; break else skip ; if _switchval = 'L' then left := left - 1 ; break else skip ; if _switchval = 'D' then down := down - 1 ; break else skip ; ) if (x = left or x = right) then ( flag1 := true ) else skip ; if (y = up or y = down) then ( flag2 := true ) else skip ; if (flag1 & flag2) then ( break ) else skip ) ) ; if (flag1 & flag2) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Problem_1481A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); int px,py ; for(int i=0 ; itoInteger() ; var px : int ; var py : int ; var i : int ; i := 0 ; while i < t do ( ( px := scanner.getCurrent()->toInteger() ; py := scanner.getCurrent()->toInteger() ; var u : int ; u := 0 ; var d : int ; d := 0 ; var l : int ; l := 0 ; var r : int ; r := 0 ; var strs : Sequence(String) ; strs := scanner.getCurrent()->characters() ; for (str : strs) do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (str) ; if _switchval = 'U' then u := u + 1 ; break else skip ; if _switchval = 'D' then d := d + 1 ; break else skip ; if _switchval = 'L' then l := l + 1 ; break else skip ; if _switchval = 'R' then r := r + 1 ; break else skip ; ) ) ) ; if (-l <= px & px <= r & -d <= py & py <= u) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int solve(int ang,int n){ if((ang*n)>(180*(n-2))){ return 0 ; } else if((ang*n)% 180!=0){ return 0 ; } int ans=1 ; int freq=(ang*n)/180 ; ans=ans*(n-1-freq); ans=ans*n ; return ans ; } public static void main(String[] args){ int ang=90,n=4 ; System.out.println(solve(ang,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solve( ang : int, n : int) : int pre: true post: true activity: ( if ((ang * n) > (180 * (n - 2))) then ( return 0 ) else if ((ang * n) mod 180 /= 0) then ( return 0 ) else skip ; ; var ans : int ; ans := 1 ; var freq : int ; freq := (ang * n) / 180 ; ans := ans * (n - 1 - freq) ; ans := ans * n ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ang : int ; ang := 90 ; var n : int ; n := 4 ; OclFile["System.out"].println(solve(ang, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test279 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; j=0){ if(x<=r){ b=true ; } } else { if(x>=l){ b=true ; } } if(y>=0){ if(y<=u){ c=true ; } } else { if(y>=d){ c=true ; } } if(c && b){ System.out.println("YES"); } else { System.out.println("NO"); } } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test279 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < t do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; var a : Sequence(String) ; a := in.getCurrent()->characters() ; var u : int ; u := 0 ; var d : int ; d := 0 ; var r : int ; r := 0 ; var l : int ; l := 0 ; var b : boolean ; b := false ; var c : boolean ; c := false ; var i : int ; i := 0 ; while i < a->size() do ( ( if (a[i+1] = 'R') then ( r := r + 1 ) else if (a[i+1] = 'U') then ( u := u + 1 ) else if (a[i+1] = 'D') then ( d := d - 1 ) else ( l := l - 1 ) ; ; ) ; i := i + 1 ) ; if (x >= 0) then ( if (x <= r) then ( b := true ) else skip ) else ( if (x >= l) then ( b := true ) else skip ) ; if (y >= 0) then ( if (y <= u) then ( c := true ) else skip ) else ( if (y >= d) then ( c := true ) else skip ) ; if (c & b) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=null ; Cheese c=null ; Gate g=null ; while(true){ input=br.readLine().split(" "); int height=Integer.parseInt(input[1]); int width=Integer.parseInt(input[0]); int depth=Integer.parseInt(input[2]); if(height+width+depth==0)break ; c=new Cheese(width,height,depth); int numGate=Integer.parseInt(br.readLine()); for(int i=0 ; isplit(" ") ; var height : int ; height := (input[1+1])->toInteger() ; var width : int ; width := (input[0+1])->toInteger() ; var depth : int ; depth := (input[2+1])->toInteger() ; if (height + width + depth = 0) then break else skip ; c := Cheese.newCheese(width, height, depth) ; var numGate : int ; numGate := (br.readLine())->toInteger() ; var i : int ; i := 0 ; while i < numGate do ( ( g := Gate.newGate((br.readLine())->toInteger()) ; OclFile["System.out"].println(if (c.isSmaller(g)) then "OK" else "NA" endif) ) ; i := i + 1 ) ; ) ; ); } class Cheese { attribute width : int; attribute height : int; attribute depth : int; attribute lengthWH : double; attribute lengthHD : double; attribute lengthWD : double; static operation newCheese( width : int, height : int, depth : int) : Cheese pre: true post: true activity: ( var self : Cheese ; self := createCheese(); self.initialise(width, height,depth); return self ); operation initialise( width : int, height : int, depth : int) : void pre: true post: true activity: ( self.width := width ; self.height := height ; self.depth := depth ; self.lengthWH := (self.width * self.width + self.height * self.height)->sqrt() ; self.lengthHD := (self.height * self.height + self.depth * self.depth)->sqrt() ; self.lengthWD := (self.width * self.width + self.depth * self.depth)->sqrt() ; ); operation isSmaller( gate : Gate) : boolean pre: true post: true activity: ( var gateDiameter : int ; gateDiameter := gate.getDiameter() ; return ((self.lengthHD < gateDiameter) or (self.lengthWD < gateDiameter) or (self.lengthWH < gateDiameter)) ); } class Gate { attribute r : int; static operation newGate( r : int) : Gate pre: true post: true activity: ( var self : Gate ; self := createGate(); self.initialise(r); return self ); operation initialise( r : int) : void pre: true post: true activity: ( self.r := r ); operation getDiameter() : int pre: true post: true activity: ( return self.r * 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static Scanner sc=new Scanner(System.in); public static int a,b ; public static void main(String[] args){ while(read()){ solve(); } } public static boolean read(){ if(! sc.hasNext()){ return false ; } a=sc.nextInt(); b=sc.nextInt(); return true ; } public static void solve(){ int d=a/b,r=a % b ; double f=(double)a/b ; System.out.printf("%d %d %.8f\n",d,r,f); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute a : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (read()) do ( execute solve() ) ); static operation read() : boolean pre: true post: true activity: ( if (not(sc.hasNext())) then ( return false ) else skip ; a := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; return true ); static operation solve() : void pre: true post: true activity: ( var d : int ; d := a / b ; var r : int ; r := a mod b ; var f : double ; f := a->oclAsType(double) / b ; OclFile["System.out"].printf("%d %d %.8f\n", d, r, f) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int a=0,b=0 ; try { String str=br.readLine(); a=Integer.parseInt(str.substring(0,str.indexOf(" "))); b=Integer.parseInt(str.substring(str.indexOf(" ")+1,str.length())); } catch(IOException e){ e.printStackTrace(); } catch(NumberFormatException e){ e.printStackTrace(); } System.out.println((int)a/b+" "+a % b+" "+(float)a/b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var a : int ; a := 0 ; var b : int ; b := 0 ; try ( var str : String ; str := br.readLine() ; a := (str.subrange(0+1,str->indexOf(" ")-1))->toInteger() ; b := (str.subrange(str->indexOf(" ")-1 + 1+1,str->size()))->toInteger() ) catch (e : IOException) do ( e.printStackTrace() ) catch (e : IncorrectElementException) do ( e.printStackTrace() ) OclFile["System.out"].println(a->oclAsType(int) / b + " " + a mod b + " " + a->oclAsType(double) / b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.Scanner ; class Main { public static void main(String[] args)throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String line=br.readLine(); String[] ss=line.split(" "); int[] ia={ Integer.parseInt(ss[0]),Integer.parseInt(ss[1])}; double[] da={ Double.parseDouble(ss[0]),Double.parseDouble(ss[1])}; System.out.println(ia[0]/ia[1]+" "+ia[0] % ia[1]+" "+String.format("%f",da[0]/da[1])); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(isr) ; var line : String ; line := br.readLine() ; var ss : Sequence(String) ; ss := line->split(" ") ; var ia : Sequence(int) ; ia := Sequence{(ss[0+1])->toInteger(),(ss[1+1])->toInteger()} ; var da : Sequence(double) ; da := Sequence{(ss[0+1])->toReal(),(ss[1+1])->toReal()} ; OclFile["System.out"].println(ia[0+1] / ia[1+1] + " " + ia[0+1] mod ia[1+1] + " " + StringLib.format("%f",Sequence{da[0+1] / da[1+1]})) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long[] ary=new long[] { sc.nextLong(),sc.nextLong(),sc.nextLong()}; Arrays.sort(ary); System.out.println(ary[0]+" "+ary[1]+" "+ary[2]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ary : Sequence(long) ; ary := Sequence{sc.getCurrent()->toLong(),sc.getCurrent()->toLong(),sc.getCurrent()->toLong()} ; ary := ary->sort() ; OclFile["System.out"].println(ary[0+1] + " " + ary[1+1] + " " + ary[2+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.text.DecimalFormat ; public class Main { public static void main(String[] args){ DecimalFormat df1=new DecimalFormat("0.00000"); java.util.Scanner scan=new java.util.Scanner(System.in); int a=scan.nextInt(); int b=scan.nextInt(); System.out.println(a/b+" "+a % b+" "+df1.format((double)a/b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var df1 : DecimalFormat ; df1 := DecimalFormat.newDecimalFormat("0.00000") ; var scan : Scanner ; scan := Scanner.newScanner(OclFile["System.in"]) ; var a : int ; a := scan.nextInt() ; var b : int ; b := scan.nextInt() ; OclFile["System.out"].println(a / b + " " + a mod b + " " + df1.format(a->oclAsType(double) / b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p002 implements EulerSolution { public static void main(String[] args){ System.out.println(new p002().run()); } public String run(){ int sum=0 ; int x=1 ; int y=2 ; while(x<=4000000){ if(x % 2==0)sum+=x ; int z=x+y ; x=y ; y=z ; } return Integer.toString(sum); } } ------------------------------------------------------------ OCL File: --------- class p002 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p002.newp002().run()) ); operation run() : String pre: true post: true activity: ( var sum : int ; sum := 0 ; var x : int ; x := 1 ; var y : int ; y := 2 ; while (x <= 4000000) do ( if (x mod 2 = 0) then sum := sum+(x) ; else skip ; var z : int ; z := x + y ; x := y ; y := z ) ; return ((sum) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int SIZE=4 ; static boolean productOfSingelDgt(int n){ if(n>=0 && n<=9)return true ; int[] prime={ 2,3,5,7 }; for(int i=0 ; i1 ; i++)while(n % prime[i]==0)n=n/prime[i]; return(n==1); } public static void main(String[] args){ int n=24 ; if(productOfSingelDgt(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute SIZE : int := 4; static operation productOfSingelDgt( n : int) : boolean pre: true post: true activity: ( if (n >= 0 & n <= 9) then return true else skip ; var prime : Sequence(int) ; prime := Sequence{2,3,5,7} ; var i : int ; i := 0 ; while i < SIZE & n > 1 do ( while (n mod prime[i+1] = 0) do n := n / prime[i+1] ; ; ; i := i + 1 ) ; return (n = 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 24 ; if (productOfSingelDgt(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; import java.util.*; import javafx.util.Pair ; public class Main { public static void main(String args[]){ FastScanner input=new FastScanner(); long n=input.nextLong(); int m=input.nextInt(); long k=input.nextLong(); long a[]=new long[m]; long ans=0 ; long stop_area=0 ; for(int i=0 ; icollect(0) ; var ans : long ; ans := 0 ; var stop_area : long ; stop_area := 0 ; var i : int ; i := 0 ; while i < m do ( ( a[i+1] := input.nextLong() - 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (stop_area <= a[i+1]) then ( stop_area := (a[i+1] - i) / k * k + k + i ; ans := ans + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Comparator ; public class A1575 { public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String line=reader.readLine(); int idx=line.indexOf(' '); int N=Integer.parseInt(line.substring(0,idx)); int M=Integer.parseInt(line.substring(idx+1)); Data[] data=new Data[N]; for(int n=0 ; n(){ @ Override public int compare(Data o1,Data o2){ String name1=o1.name ; String name2=o2.name ; int idx=0 ; int diff ; do { char c1=name1.charAt(idx); char c2=name2.charAt(idx); diff=(idx % 2==0)?(c1-c2):(c2-c1); idx++; } while(diff==0); return diff ; } } ); StringBuilder output=new StringBuilder(); for(Data d : data){ output.append(d.id).append(' '); } System.out.println(output); } static class Data { int id ; String name ; } } ------------------------------------------------------------ OCL File: --------- class A1575 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := reader.readLine() ; var idx : int ; idx := line->indexOf(' ')-1 ; var N : int ; N := (line.subrange(0+1,idx))->toInteger() ; var M : int ; M := (line.subrange(idx + 1+1,idx + 1))->toInteger() ; var data : Sequence(Data) ; data := Integer.subrange(1,N)->collect(null) ; var n : int ; n := 0 ; while n < N do ( ( var d : Data ; d := Data.newData() ; d.id := n + 1 ; d.name := reader.readLine() ; data[n+1] := d ) ; n := n + 1 ) ; data := OclComparator.sortWith(data, OclComparator.newOclComparator()) ; var output : String ; output := StringLib.newString() ; for (d : data) do ( ( output := output + StringLib.newString(d.id) + StringLib.newString(' ') ) ) ; OclFile["System.out"].println(output) ; ); static class Data { attribute id : int; attribute name : String; } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.util.*; import java.util.stream.Collectors ; import java.io.*; public class absolute { public static long process(long n,long[] ar,long k){ int i=0,steps=0 ; long stdiv=ar[0]/k,st=(stdiv+((ar[0] % k!=0)? 1 : 0))*k ; if(k==1)return ar.length ; while(i0)? 1 : 0); } return steps ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); int m=sc.nextInt(); long k=sc.nextLong(); long[] ar=new long[m]; for(int i=0 ; isize() else skip ; while (i < ar->size()) do ( var count : int ; count := 0 ; while (i < ar->size() & ar[i+1] <= st) do ( i := i + 1 ; count := count + 1 ) ; if (count = 0) then ( if (ar[i+1] <= st + k) then st := st+(k) ; else ( var div : long ; div := ar[i+1] / k ; if (st mod k = 0) then st := k * (div + 1) ; else ( var prev : long ; prev := st mod k ; st := k * (div) + prev ) ) ) else st := st+(count) ; ; steps := steps + (if (count > 0) then 1 else 0 endif) ) ; return steps ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var m : int ; m := sc.getCurrent()->toInteger() ; var k : long ; k := sc.getCurrent()->toLong() ; var ar : Sequence(long) ; ar := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ar[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; OclFile["System.out"].println(process(n, ar, k)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Ideone { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args)throws java.lang.Exception { FastReader fs=new FastReader(); int n=fs.nextInt(); int[] arr={ 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 }; System.out.println(arr[n-1]); } } ------------------------------------------------------------ OCL File: --------- class Ideone { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fs : FastReader ; fs := FastReader.newFastReader() ; var n : int ; n := fs.nextInt() ; var arr : Sequence(int) ; arr := Sequence{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} ; OclFile["System.out"].println(arr[n - 1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new aoj107().doIt(); } class aoj107 { boolean ans(int a,int b,double r){ for(double i=0 ; i<90 ; i++){ double sin=2*r*Math.sin(Math.toRadians(i)); double cos=2*r*Math.cos(Math.toRadians(i)); if(asin() ; var cos : double ; cos := 2 * r * ((0.017453292519943295*(i)))->cos() ; if (a < sin & b < cos) then return true else skip ) ; i := i + 1 ) ; return false ); operation doIt() : void pre: true post: true activity: ( while (true) do ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if (a + b + c = 0) then break else skip ; var cnt : int ; cnt := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < cnt do ( ( var r : double ; r := sc.getCurrent()->toReal() ; if (ans(a, b, r)) then ( OclFile["System.out"].println("OK") ) else if (ans(b, a, r)) then ( OclFile["System.out"].println("OK") ) else if (ans(c, a, r)) then ( OclFile["System.out"].println("OK") ) else if (ans(a, c, r)) then ( OclFile["System.out"].println("OK") ) else if (ans(c, b, r)) then ( OclFile["System.out"].println("OK") ) else if (ans(b, c, r)) then ( OclFile["System.out"].println("OK") ) else ( OclFile["System.out"].println("NA") ) ; ; ; ; ; ) ; i := i + 1 ) ; ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NumbersJoke { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] resList=new int[] { 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 }; System.out.println(resList[n-1]); } } ------------------------------------------------------------ OCL File: --------- class NumbersJoke { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var resList : Sequence(int) ; resList := Sequence{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} ; OclFile["System.out"].println(resList[n - 1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class a { public static void main(String[] args){ Scanner in=new Scanner(System.in); int[] ans={ 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 }; int a=in.nextInt(); System.out.println(ans[a-1]); } } ------------------------------------------------------------ OCL File: --------- class a { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ans : Sequence(int) ; ans := Sequence{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} ; var a : int ; a := in.getCurrent()->toInteger() ; OclFile["System.out"].println(ans[a - 1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] str)throws IOException { BufferedReader l=new BufferedReader(new InputStreamReader(System.in)); int arr[]={ 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 }; int t=Integer.parseInt(l.readLine()); System.out.println(arr[t-1]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( str : Sequence(String)) : void pre: true post: true activity: ( var l : OclFile ; l := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var arr : Sequence(int) ; arr := Sequence{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} ; var t : int ; t := (l.readLine())->toInteger() ; OclFile["System.out"].println(arr[t - 1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { final static int MAX_CHARS=26 ; static boolean isValid(int count[],int k){ int val=0 ; for(int i=0 ; i0){ val++; } } return(k>=val); } static void kUniques(String s,int k){ int u=0 ; int n=s.length(); int count[]=new int[MAX_CHARS]; Arrays.fill(count,0); for(int i=0 ; imax_window_size){ max_window_size=curr_end-curr_start+1 ; max_window_start=curr_start ; } } System.out.println("Max sustring is : "+s.substring(max_window_start,max_window_size)+" with length "+max_window_size); } static public void main(String[] args){ String s="aabacbebebe" ; int k=3 ; kUniques(s,k); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX_CHARS : int := 26; static operation isValid( count : Sequence(int), k : int) : boolean pre: true post: true activity: ( var val : int ; val := 0 ; var i : int ; i := 0 ; while i < MAX_CHARS do ( ( if (count[i+1] > 0) then ( val := val + 1 ) else skip ) ; i := i + 1 ) ; return (k >= val) ); static operation kUniques( s : String, k : int) : void pre: true post: true activity: ( var u : int ; u := 0 ; var n : int ; n := s->size() ; var count : Sequence(int) ; count := Integer.subrange(1,MAX_CHARS)->collect(0) ; count := count->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( if (count[s->at(i+1) - ('a')->char2byte()+1] = 0) then ( u := u + 1 ) else skip ; count[s->at(i+1) - ('a')->char2byte()+1] := count[s->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; if (u < k) then ( OclFile["System.out"].print("Not enough unique characters") ; return ) else skip ; var curr_start : int ; curr_start := 0 ; var curr_end : int ; curr_end := 0 ; var max_window_size : int ; max_window_size := 1 ; var max_window_start : int ; max_window_start := 0 ; count := count->collect(0) ; count[s->at(0+1) - ('a')->char2byte()+1] := count[s->at(0+1) - ('a')->char2byte()+1] + 1 ; var i : int ; i := 1 ; while i < n do ( ( count[s->at(i+1) - ('a')->char2byte()+1] := count[s->at(i+1) - ('a')->char2byte()+1] + 1 ; curr_end := curr_end + 1 ; while (not(isValid(count, k))) do ( count[s->at(curr_start+1) - ('a')->char2byte()+1] := count[s->at(curr_start+1) - ('a')->char2byte()+1] - 1 ; curr_start := curr_start + 1 ) ; if (curr_end - curr_start + 1 > max_window_size) then ( max_window_size := curr_end - curr_start + 1 ; max_window_start := curr_start ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Max sustring is : " + s.subrange(max_window_start+1,max_window_size) + " with length " + max_window_size) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "aabacbebebe" ; var k : int ; k := 3 ; execute kUniques(s, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Casier { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long m=sc.nextLong(); int a=sc.nextInt(); int b=sc.nextInt(); if(n % m==0)System.out.println("0"); else { long x=b*(n % m); long y=(m-n % m)*a ; if(xtoLong() ; var m : long ; m := sc.getCurrent()->toLong() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (n mod m = 0) then OclFile["System.out"].println("0") else ( var x : long ; x := b * (n mod m) ; var y : long ; y := (m - n mod m) * a ; if (x < y) then OclFile["System.out"].print(x) ; else OclFile["System.out"].print(y) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CommentaryBoxes { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long m=sc.nextLong(); int a=sc.nextInt(); int b=sc.nextInt(); long left=n % m ; long build=(m-left)*a ; long destroy=left*b ; System.out.println(build>destroy ? destroy : build); } } ------------------------------------------------------------ OCL File: --------- class CommentaryBoxes { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var m : long ; m := sc.getCurrent()->toLong() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var left : long ; left := n mod m ; var build : long ; build := (m - left) * a ; var destroy : long ; destroy := left * b ; OclFile["System.out"].println(if build > destroy then destroy else build endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); long n=in.nextLong(),m=in.nextLong(),a=in.nextLong(),b=in.nextLong(); if(n % m==0){ pw.println(0); } else { long ans1=n % m ; ans1=ans1*b ; long div=1+(n/m); div=div*m ; div=div-n ; long ans2=div*a ; pw.println(Math.min(ans2,ans1)); } pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : long ; n := in.getCurrent()->toLong() ; var m : long ; m := in.getCurrent()->toLong() ; var a : long ; a := in.getCurrent()->toLong() ; var b : long ; b := in.getCurrent()->toLong() ; if (n mod m = 0) then ( skip ) else ( var ans1 : long ; ans1 := n mod m ; ans1 := ans1 * b ; var div : long ; div := 1 + (n / m) ; div := div * m ; div := div - n ; var ans2 : long ; ans2 := div * a ; skip ; ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.HashMap ; import java.util.Map ; public class OurTanyaIsCryingOutLoud { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { long n=Integer.parseInt(br.readLine()); long k=Integer.parseInt(br.readLine()); long A=Integer.parseInt(br.readLine()); long B=Integer.parseInt(br.readLine()); if(k==1 || n1){ if(n % k!=0){ long t=n % k ; if(ntoInteger() ; var k : long ; k := (br.readLine())->toInteger() ; var A : long ; A := (br.readLine())->toInteger() ; var B : long ; B := (br.readLine())->toInteger() ; if (k = 1 or n < k) then ( skip ; return ) else skip ; var res : long ; res := 0 ; while (n > 1) do ( if (n mod k /= 0) then ( var t : long ; t := n mod k ; if (n < k) then t := t - 1 ; else skip ; n := n-(t) ; res := res+(A * t) ) else ( var next : long ; next := n / k ; var temp1 : long ; temp1 := (n - next) * A ; var temp2 : long ; temp2 := B ; res := res+(Set{temp1, temp2}->min()) ; n := n/(k) ; ) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX_SIZE=(int)1e6 ; static boolean[] prime=new boolean[MAX_SIZE+1]; static void sieve(){ Arrays.fill(prime,true); for(int p=2 ; p*p<=MAX_SIZE ; p++){ if(prime[p]==true){ for(int i=p*p ; i<=MAX_SIZE ; i+=p)prime[i]=false ; } } } static int kthPrimeGreaterThanN(int n,int k){ int res=-1 ; for(int i=n+1 ; ioclAsType(int); static attribute prime : Sequence(boolean) := Integer.subrange(1,MAX_SIZE + 1)->collect(false); static operation sieve() : void pre: true post: true activity: ( prime := prime->collect(true) ; var p : int ; p := 2 ; while p * p <= MAX_SIZE do ( ( if (prime[p+1] = true) then ( var i : int ; i := p * p ; while i <= MAX_SIZE do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ); static operation kthPrimeGreaterThanN( n : int, k : int) : int pre: true post: true activity: ( var res : int ; res := -1 ; var i : int ; i := n + 1 ; while i < MAX_SIZE do ( ( if (prime[i+1] = true) then k := k - 1 ; else skip ; if (k = 0) then ( res := i ; break ) else skip ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute sieve() ; var n : int ; n := 2 ; var k : int ; k := 15 ; OclFile["System.out"].println(kthPrimeGreaterThanN(n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { static void printFibonacciNumbers(int n){ int f1=0,f2=1,i ; if(n<1)return ; for(i=1 ; i<=n ; i++){ System.out.print(f2+" "); int next=f1+f2 ; f1=f2 ; f2=next ; } } public static void main(String[] args){ printFibonacciNumbers(7); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation printFibonacciNumbers( n : int) : void pre: true post: true activity: ( var f1 : int ; f1 := 0 ; var f2 : int ; f2 := 1 ; var i : int ; if (n < 1) then return else skip ; i := 1 ; while i <= n do ( ( OclFile["System.out"].print(f2 + " ") ; var next : int ; next := f1 + f2 ; f1 := f2 ; f2 := next ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute printFibonacciNumbers(7) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MAX=50 ; static void remove_row_col(int arr[][],int n,int x){ for(int i=x ; icollect(0) ; while (true) do ( len[0+1] := in.getCurrent()->toLong() ; len[1+1] := in.getCurrent()->toLong() ; len[2+1] := in.getCurrent()->toLong() ; if (len[0+1] = 0 & len[1+1] = 0 & len[2+1] = 0) then break else skip ; len := len->sort() ; var min1 : double ; min1 := len[0+1] ; var min2 : double ; min2 := len[1+1] ; var loops : int ; loops := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < loops do ( ( var r : long ; r := in.getCurrent()->toLong() * 2 ; if (min1 * min1 + min2 * min2 < r * r) then ( skip ) else ( skip ) ) ; i := i + 1 ) ; ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Iterator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); String pass="" ; String code=scn.next(); String[] nums=new String[10]; for(int i=0 ; i<10 ; i++)nums[i]=scn.next(); String[] symb=new String[8]; for(int i=0 ; i<8 ; i++){ symb[i]="" ; for(int k=0 ; k<10 ; k++){ symb[i]+=code.charAt(k+i*10); } } for(int i=0 ; i<8 ; i++){ for(int k=0 ; k<10 ; k++){ if(symb[i] .equals(nums[k])){ pass+=k ; break ; } } } System.out.println(pass); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pass : String ; pass := "" ; var code : String ; code := scn.getCurrent() ; var nums : Sequence(String) ; nums := Integer.subrange(1,10)->collect(null) ; var i : int ; i := 0 ; while i < 10 do ( nums[i+1] := scn.getCurrent() ; ; i := i + 1 ) ; var symb : Sequence(String) ; symb := Integer.subrange(1,8)->collect(null) ; var i : int ; i := 0 ; while i < 8 do ( ( symb[i+1] := "" ; var k : int ; k := 0 ; while k < 10 do ( ( symb[i+1] := symb[i+1]+(code->at(k + i * 10+1)) ) ; k := k + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 8 do ( ( var k : int ; k := 0 ; while k < 10 do ( ( if (symb[i+1] = nums[k+1]) then ( pass := pass+(k) ; break ) else skip ) ; k := k + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(pass) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Test { public static void main(String[] args){ Scanner in=new Scanner(System.in); Mappassword=new HashMap<>(); String code=in.next(); for(int i=0 ; i<10 ; i++){ String key=in.next(); password.put(key,i); } for(int i=0 ; i<80 ; i+=10){ String s=code.substring(i,(i+10)); System.out.print(password.get(s)); } } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var password : Map(String,int) ; password := Map{} ; var code : String ; code := in.getCurrent() ; var i : int ; i := 0 ; while i < 10 do ( ( var key : String ; key := in.getCurrent() ; password := password->union(Map{key |-> i}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 80 do ( ( var s : String ; s := code.subrange(i+1,(i + 10)) ; OclFile["System.out"].print(password->at(s)) ) ; i := i+(10) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class RestoringPassword { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String value=scanner.next(); Mapmaps=new HashMap<>(); for(int i=0 ; i<10 ; i++){ maps.put(scanner.next(),i); } for(int i=0 ; i<80 ; i+=10){ System.out.print(maps.get(value.subSequence(i,i+10))); } } } ------------------------------------------------------------ OCL File: --------- class RestoringPassword { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var value : String ; value := scanner.getCurrent() ; var maps : Map(String,int) ; maps := Map{} ; var i : int ; i := 0 ; while i < 10 do ( ( maps := maps->union(Map{scanner.getCurrent() |-> i}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 80 do ( ( OclFile["System.out"].print(maps->at(value.subrange(i+1,i + 10))) ) ; i := i+(10) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication118 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); ArrayListarr=new ArrayList<>(); String s=sc.next(); for(int i=0 ; i<10 ; i++){ arr.add(sc.next()); } for(int i=0 ; i<8 ; i++){ String h=s.subSequence(i*10,(i+1)*10).toString(); for(int j=0 ; jincluding(sc.getCurrent()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 8 do ( ( var h : String ; h := s.subrange(i * 10+1,(i + 1) * 10)+"" ; var j : int ; j := 0 ; while j < arr->size() do ( ( if (h->includes(arr->at(j+1))) then ( OclFile["System.out"].print(j) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; public class Main { public static void main(String[] args)throws IOException { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); int counter=0 ; while(input.ready()){ String[] inputStr=input.readLine().split(" "); final int FROM_YEAR=Integer.parseInt(inputStr[0]); final int TO_YEAR=Integer.parseInt(inputStr[1]); if(TO_YEAR==0){ break ; } if(counter>0){ System.out.println(); } counter++; ArrayListansList=leapYearCount(FROM_YEAR,TO_YEAR); if(ansList.size()==0){ System.out.println("NA"); continue ; } for(Integer each : ansList){ System.out.println(each); } } } private static ArrayListleapYearCount(int fromYear,int toYear){ ArrayListyearList=new ArrayList<>(); for(int i=fromYear ; i<=toYear ; i++){ if(isLeapYear(i)){ yearList.add(i); } } return yearList ; } private static boolean isLeapYear(int year){ if(year % 4!=0){ return false ; } if(year % 100==0){ if(year % 400==0){ return true ; } return false ; } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var counter : int ; counter := 0 ; while (input.canRead()) do ( var inputStr : Sequence(String) ; inputStr := input.readLine()->split(" ") ; var FROM_YEAR : int ; FROM_YEAR := (inputStr[0+1])->toInteger() ; var TO_YEAR : int ; TO_YEAR := (inputStr[1+1])->toInteger() ; if (TO_YEAR = 0) then ( break ) else skip ; if (counter > 0) then ( OclFile["System.out"].println() ) else skip ; counter := counter + 1 ; var ansList : Sequence(int) ; ansList := leapYearCount(FROM_YEAR, TO_YEAR) ; if (ansList->size() = 0) then ( OclFile["System.out"].println("NA") ; continue ) else skip ; for (each : ansList) do ( ( OclFile["System.out"].println(each) ) ) ; ) ); static operation leapYearCount( fromYear : int, toYear : int) : Sequence(int) pre: true post: true activity: ( var yearList : Sequence(int) ; yearList := Sequence{} ; var i : int ; i := fromYear ; while i <= toYear do ( ( if (isLeapYear(i)) then ( yearList := yearList->including(i) ) else skip ) ; i := i + 1 ) ; return yearList ); static operation isLeapYear( year : int) : boolean pre: true post: true activity: ( if (year mod 4 /= 0) then ( return false ) else skip ; if (year mod 100 = 0) then ( if (year mod 400 = 0) then ( return true ) else skip ; return false ) else skip ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class GfG { static int digSum(int n){ int sum=0 ; while(n>0 || sum>9){ if(n==0){ n=sum ; sum=0 ; } sum+=n % 10 ; n/=10 ; } return sum ; } public static void main(String argc[]){ int n=1234 ; System.out.println(digSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation digSum( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 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 ); static operation main( argc : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 1234 ; OclFile["System.out"].println(digSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.concurrent.LinkedBlockingQueue ; class Main { Scanner sc=new Scanner(System.in); public void run(){ boolean[] isuruu=new boolean[3000]; for(int i=0 ; i<3000 ; i++){ isuruu[i]=i % 400==0 ||(i % 100!=0 && i % 4==0); } boolean isFirst=true ; while(true){ int a=sc.nextInt(),b=sc.nextInt(); if(a==0 && b==0)break ; if(! isFirst)ln(); boolean isset=false ; for(int y=a ; y<=b ; y++){ if(isuruu[y]){ ln(y); isset=true ; } } if(! isset)ln("NA"); isFirst=false ; } } public static void main(String[] args){ new Main().run(); } public static void pr(Object o){ System.out.print(o); } public static void ln(Object o){ System.out.println(o); } public static void ln(){ System.out.println(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( var isuruu : Sequence(boolean) ; isuruu := Integer.subrange(1,3000)->collect(false) ; var i : int ; i := 0 ; while i < 3000 do ( ( isuruu[i+1] := i mod 400 = 0 or (i mod 100 /= 0 & i mod 4 = 0) ) ; i := i + 1 ) ; var isFirst : boolean ; isFirst := true ; while (true) do ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (a = 0 & b = 0) then break else skip ; if (not(isFirst)) then execute ln() ; else skip ; var isset : boolean ; isset := false ; var y : int ; y := a ; while y <= b do ( ( if (isuruu[y+1]) then ( execute ln(y) ; isset := true ) else skip ) ; y := y + 1 ) ; if (not(isset)) then execute ln("NA") ; else skip ; isFirst := false ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); static operation pr( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].print(o) ); static operation ln( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o) ); static operation ln() : void pre: true post: true activity: ( OclFile["System.out"].println() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ ArrayListresult=new ArrayList(); String[] s ; int a,b,i ; boolean flg,exst ; Scanner sc=new Scanner(System.in); while(true){ s=sc.nextLine().split("\\s"); a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); if(a+b==0){ break ; } exst=false ; for(i=a ; i<=b ; i++){ flg=false ; if(i % 400==0){ flg=true ; } else if(i % 4==0 && i % 100!=0){ flg=true ; } if(flg){ result.add(String.valueOf(i)); exst=true ; } } if(! exst){ result.add("NA"); } result.add(""); } for(i=0 ; isplit("\\s") ; a := (s[0+1])->toInteger() ; b := (s[1+1])->toInteger() ; if (a + b = 0) then ( break ) else skip ; exst := false ; i := a ; while i <= b do ( ( flg := false ; if (i mod 400 = 0) then ( flg := true ) else if (i mod 4 = 0 & i mod 100 /= 0) then ( flg := true ) else skip ; ; if (flg) then ( result := result->including(((i) + "")) ; exst := true ) else skip ) ; i := i + 1 ) ; if (not(exst)) then ( result := result->including("NA") ) else skip ; result := result->including("") ; ) ; i := 0 ; while i < result->size() - 1 do ( ( OclFile["System.out"].println(result->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.LinkedList ; import java.util.List ; public class Main { public static void main(String[] args){ BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); ListinputDataList=new ArrayList(); String input=null ; try { while((input=in.readLine())!=null){ inputDataList.add(input); } } catch(IOException e){ e.printStackTrace(); } finally { try { in.close(); } catch(IOException e){ e.printStackTrace(); } } boolean firstTry=true ; for(String inputData : inputDataList){ String[] years=inputData.split(" "); int start=Integer.parseInt(years[0]); int end=Integer.parseInt(years[1]); if(start==0 && end==0){ break ; } if(firstTry){ firstTry=false ; } else { System.out.println(); } searchLeapYear(start,end); } } private static void searchLeapYear(int start,int end){ ListleapYearList=new LinkedList(); for(int i=start ; i<=end ; i++){ if(i % 4==0){ if(i % 100!=0){ leapYearList.add(i); } else { if(i % 400==0){ leapYearList.add(i); } } } } if(leapYearList.size()!=0){ for(Integer year : leapYearList){ System.out.println(year); } } else { System.out.println("NA"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var inputDataList : Sequence(String) ; inputDataList := Sequence{} ; var input : String ; input := null ; try ( input := in.readLine() ; while ((input) /= null) do ( skip ; ( inputDataList := inputDataList->including(input) ) ; input := in.readLine() ; ) ) catch (e : IOException) do ( e.printStackTrace() ) finally ( try ( skip ) catch (e : IOException) do ( e.printStackTrace() ) ) var firstTry : boolean ; firstTry := true ; for (inputData : inputDataList) do ( ( var years : Sequence(String) ; years := inputData->split(" ") ; var start : int ; start := (years[0+1])->toInteger() ; var end : int ; end := (years[1+1])->toInteger() ; if (start = 0 & end = 0) then ( break ) else skip ; if (firstTry) then ( firstTry := false ) else ( OclFile["System.out"].println() ) ; execute searchLeapYear(start, end) ; ) ) ; ); static operation searchLeapYear( start : int, end : int) : void pre: true post: true activity: ( var leapYearList : Sequence(int) ; leapYearList := Sequence{} ; var i : int ; i := start ; while i <= end do ( ( if (i mod 4 = 0) then ( if (i mod 100 /= 0) then ( leapYearList := leapYearList->including(i) ) else ( if (i mod 400 = 0) then ( leapYearList := leapYearList->including(i) ) else skip ) ) else skip ) ; i := i + 1 ) ; if (leapYearList->size() /= 0) then ( for (year : leapYearList) do ( ( OclFile["System.out"].println(year) ) ) ) else ( OclFile["System.out"].println("NA") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc ; static final int INF=1<<28 ; static final double EPS=1e-9 ; void run(){ sc=new Scanner(System.in); int y1=sc.nextInt(); int y2=sc.nextInt(); for(; ; ){ boolean f=false ; for(int y=y1 ; y<=y2 ; y++){ if(y % 4==0 &&(y % 100!=0 || y % 400==0)){ println(y+""); f=true ; } } if(! f)println("NA"); y1=sc.nextInt(); y2=sc.nextInt(); if(y1==0 && y2==0)break ; println(""); } sc.close(); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static attribute INF : int := (1*(2->pow(28)))->oclAsType(long); static attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var y1 : int ; y1 := sc.getCurrent()->toInteger() ; var y2 : int ; y2 := sc.getCurrent()->toInteger() ; while true do ( ( var f : boolean ; f := false ; var y : int ; y := y1 ; while y <= y2 do ( ( if (y mod 4 = 0 & (y mod 100 /= 0 or y mod 400 = 0)) then ( execute println(y + "") ; f := true ) else skip ) ; y := y + 1 ) ; if (not(f)) then execute println("NA") ; else skip ; y1 := sc.getCurrent()->toInteger() ; y2 := sc.getCurrent()->toInteger() ; if (y1 = 0 & y2 = 0) then break else skip ; execute println("") ; ) ) ; skip ; ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); List>result=new ArrayList>(); long[] x=new long[3]; for(int i=0 ; i<3 ; i++){ x[i]=stdIn.nextLong(); } while(x[0]!=0 || x[1]!=0 || x[2]!=0){ Listlist=new ArrayList(); for(int i=0 ; i<3 ; i++){ int max=i ; for(int j=i+1 ; j<3 ; j++){ if(x[j]>x[max]){ max=j ; } } long temp=x[max]; x[max]=x[i]; x[i]=temp ; } long r=x[1]*x[1]+x[2]*x[2]; int n=stdIn.nextInt(); for(int i=0 ; ians : result){ for(String str : ans){ System.out.println(str); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var result : Sequence(Sequence(String)) ; result := Sequence{} ; var x : Sequence(long) ; x := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < 3 do ( ( x[i+1] := stdIn.getCurrent()->toLong() ) ; i := i + 1 ) ; while (x[0+1] /= 0 or x[1+1] /= 0 or x[2+1] /= 0) do ( var list : Sequence(String) ; list := Sequence{} ; var i : int ; i := 0 ; while i < 3 do ( ( var max : int ; max := i ; var j : int ; j := i + 1 ; while j < 3 do ( ( if (x[j+1] > x[max+1]) then ( max := j ) else skip ) ; j := j + 1 ) ; var temp : long ; temp := x[max+1] ; x[max+1] := x[i+1] ; x[i+1] := temp ; ) ; i := i + 1 ) ; var r : long ; r := x[1+1] * x[1+1] + x[2+1] * x[2+1] ; var n : int ; n := stdIn.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var m : long ; m := stdIn.getCurrent()->toLong() ; if (4 * m * m <= r) then ( list := list->including("NA") ) else ( list := list->including("OK") ) ) ; i := i + 1 ) ; result := result->including(list) ; x[0+1] := stdIn.getCurrent()->toLong() ; x[1+1] := stdIn.getCurrent()->toLong() ; x[2+1] := stdIn.getCurrent()->toLong() ; ) ; for (ans : result) do ( ( for (str : ans) do ( ( OclFile["System.out"].println(str) ) ) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); final int N=sc.nextInt(); long[] difficults=new long[N]; long[] partial_sum=new long[N]; for(int i=0 ; irate){ System.out.println(purpose<=0 ? "Yes" : "No"); } else { int lower=0 ; int higher=N ; while(lower+1!=higher){ final int mid=(lower+higher)/2 ; if(difficults[mid]<=solver[i]){ lower=mid ; } else { higher=mid ; } } final long score=partial_sum[lower]; System.out.println(score>=purpose ? "Yes" : "No"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var difficults : Sequence(long) ; difficults := Integer.subrange(1,N)->collect(0) ; var partial_sum : Sequence(long) ; partial_sum := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( var a : long ; a := sc.getCurrent()->toLong() ; difficults[i+1] := a ) ; i := i + 1 ) ; difficults := difficults->sort() ; var i : int ; i := 0 ; while i < N do ( ( partial_sum[i+1] := difficults[i+1] + (if i = 0 then 0 else partial_sum[i - 1+1] endif) ) ; i := i + 1 ) ; var M : int ; M := sc.getCurrent()->toInteger() ; var solver : Sequence(int) ; solver := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( var b : int ; b := sc.getCurrent()->toInteger() ; solver[i+1] := b ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( var purpose : long ; purpose := sc.getCurrent()->toLong() ; var rate : int ; rate := solver[i+1] ; if (difficults[0+1] > rate) then ( OclFile["System.out"].println(if purpose <= 0 then "Yes" else "No" endif) ) else ( var lower : int ; lower := 0 ; var higher : int ; higher := N ; while (lower + 1 /= higher) do ( var mid : int ; mid := (lower + higher) / 2 ; if (difficults[mid+1] <= solver[i+1]) then ( lower := mid ) else ( higher := mid ) ) ; var score : long ; score := partial_sum[lower+1] ; OclFile["System.out"].println(if score >= purpose then "Yes" else "No" endif) ; ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner in=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new RitProA().doIt(); } class RitProA { void doIt(){ int N=in.nextInt(); int a[]=new int[N]; long sum[]=new long[1000002]; for(int i=0 ; i=c[i]){ System.out.println("Yes"); } else { System.out.println("No"); } } } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( RitProA.newRitProA().doIt() ); class RitProA { operation doIt() : void pre: true post: true activity: ( var N : int ; N := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var sum : Sequence(long) ; sum := Integer.subrange(1,1000002)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var cnt : long ; cnt := 0 ; var i : int ; i := 0 ; while i < N do ( ( cnt := cnt + a[i+1] ; sum[a[i+1]+1] := cnt ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 1000000 do ( ( if (sum[i + 1+1] = 0) then ( sum[i + 1+1] := sum[i+1] ) else skip ) ; i := i + 1 ) ; var M : int ; M := in.getCurrent()->toInteger() ; var b : Sequence(int) ; b := Integer.subrange(1,M)->collect(0) ; var c : Sequence(long) ; c := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( b[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( c[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( if (sum[b[i+1]+1] >= c[i+1]) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ) ; i := i + 1 ) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; import static java.lang.Long.parseLong ; public class Main { static final int MAX=1_000_001 ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int N=parseInt(br.readLine()); long[] sum=new long[MAX]; StringTokenizer st=new StringTokenizer(br.readLine()); for(int i=0 ; i=c[i]){ sb.append("Yes\n"); } else { sb.append("No\n"); } } System.out.print(sb.toString()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MAX : int := 1_000_001; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var N : int ; N := parseInt(br.readLine()) ; var sum : Sequence(long) ; sum := Integer.subrange(1,MAX)->collect(0) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < N do ( ( var a : int ; a := parseInt(st.next()) ; sum[a+1] := sum[a+1]+(a) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < MAX do ( ( sum[i+1] := sum[i+1]+(sum[i - 1+1]) ) ; i := i + 1 ) ; var M : int ; M := parseInt(br.readLine()) ; var b : Sequence(int) ; b := Integer.subrange(1,M)->collect(0) ; var c : Sequence(long) ; c := Integer.subrange(1,M)->collect(0) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < M do ( ( b[i+1] := (st.next() + "")->toInteger() ) ; i := i + 1 ) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < M do ( ( c[i+1] := parseLong(st.next()) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < M do ( ( if (sum[b[i+1]+1] >= c[i+1]) then ( sb := sb + StringLib.newString("Yes\n") ) else ( sb := sb + StringLib.newString("No\n") ) ) ; i := i + 1 ) ; OclFile["System.out"].print(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeSet ; public class B334 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int[] X=new int[8]; int[] Y=new int[8]; SetxSet=new TreeSet<>(); SetySet=new TreeSet<>(); for(int i=0 ; i<8 ; i++){ int x=in.nextInt(); int y=in.nextInt(); X[i]=x ; Y[i]=y ; xSet.add(x); ySet.add(y); } boolean ok=xSet.size()==3 && ySet.size()==3 ; if(ok){ Integer[] xArray=new Integer[3]; Integer[] yArray=new Integer[3]; xSet.toArray(xArray); ySet.toArray(yArray); for(int x : xArray){ for(int y : yArray){ if(x!=(int)xArray[1] || y!=(int)yArray[1]){ boolean found=false ; for(int i=0 ; i<8 ; i++){ if(X[i]==x && Y[i]==y){ found=true ; } } ok &=found ; } } } } System.out.println(ok ? "respectable" : "ugly"); } } ------------------------------------------------------------ OCL File: --------- class B334 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : Sequence(int) ; X := Integer.subrange(1,8)->collect(0) ; var Y : Sequence(int) ; Y := Integer.subrange(1,8)->collect(0) ; var xSet : Set(int) ; xSet := Set{} ; var ySet : Set(int) ; ySet := Set{} ; var i : int ; i := 0 ; while i < 8 do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; X[i+1] := x ; Y[i+1] := y ; xSet := xSet->including(x) ; ySet := ySet->including(y) ; ) ; i := i + 1 ) ; var ok : boolean ; ok := xSet->size() = 3 & ySet->size() = 3 ; if (ok) then ( var xArray : Sequence(int) ; xArray := Integer.subrange(1,3)->collect(null) ; var yArray : Sequence(int) ; yArray := Integer.subrange(1,3)->collect(null) ; xSet := xSet.toArray(xArray) ; ySet := ySet.toArray(yArray) ; for (x : xArray) do ( ( for (y : yArray) do ( ( if (x /= xArray[1+1]->oclAsType(int) or y /= yArray[1+1]->oclAsType(int)) then ( var found : boolean ; found := false ; var i : int ; i := 0 ; while i < 8 do ( ( if (X[i+1] = x & Y[i+1] = y) then ( found := true ) else skip ) ; i := i + 1 ) ; ok := MathLib.bitwiseAnd(ok, found) ) else skip ) ) ) ) ; ) else skip ; OclFile["System.out"].println(if ok then "respectable" else "ugly" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); AAProblemAboutPolyline solver=new AAProblemAboutPolyline(); solver.solve(1,in,out); out.close(); } static class AAProblemAboutPolyline { public void solve(int testNumber,InputReader in,PrintWriter out){ int a=in.nextInt(),b=in.nextInt(); if(b>a){ out.println(-1); return ; } double x=(double)(a+b)/2 ; int periods=(int)x/b ; x/=periods ; out.println(Util.formatDouble(x)); } } static class Util { public static String formatDouble(double x){ return String.format("%.15f",x); } private Util(){ } } static class InputReader { public final BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : AAProblemAboutPolyline ; solver := AAProblemAboutPolyline.newAAProblemAboutPolyline() ; solver.solve(1, in, out) ; skip ; ); static class AAProblemAboutPolyline { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var a : int ; a := in.nextInt() ; var b : int ; b := in.nextInt() ; if (b > a) then ( skip ; return ) else skip ; var x : double ; x := (a + b)->oclAsType(double) / 2 ; var periods : int ; periods := x->oclAsType(int) / b ; x := x/(periods) ; skip ; ); } static class Util { static operation formatDouble( x : double) : String pre: true post: true activity: ( return StringLib.format("%.15f",Sequence{x}) ); static operation newUtil() : Util pre: true post: true activity: ( var self : Util ; self := createUtil(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: skip; } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); String a=sc.next(),b=sc.next(); int[][] dp=new int[n+1][m+1]; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=m ; j++){ dp[i][j]=Math.max(dp[i][j],Math.max(dp[i-1][j],dp[i][j-1])-1); if(a.charAt(i-1)==b.charAt(j-1)){ dp[i][j]=Math.max(dp[i][j],dp[i-1][j-1]+2); } } } int ans=0 ; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=m ; j++){ ans=Math.max(ans,dp[i][j]); } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : String ; a := sc.getCurrent() ; var b : String ; b := sc.getCurrent() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,m + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= m do ( ( dp[i+1][j+1] := Set{dp[i+1][j+1], Set{dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->max() - 1}->max() ; if (a->at(i - 1+1) = b->at(j - 1+1)) then ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i - 1+1][j - 1+1] + 2}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= m do ( ( ans := Set{ans, dp[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class CF578A extends PrintWriter { CF578A(){ super(System.out,true); } Scanner sc=new Scanner(System.in); public static void main(String[] $){ CF578A o=new CF578A(); o.main(); o.flush(); } void main(){ int x=sc.nextInt(); int y=sc.nextInt(); if(xtoInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (x < y) then ( execute println(-1) ; return ) else skip ; if (x = y) then ( execute println(y) ; return ) else skip ; var z1 : double ; z1 := (x + y)->oclAsType(double) / ((x + y) / (2 * y) * 2) ; var z2 : double ; z2 := (x - y)->oclAsType(double) / ((x - y) / (2 * y) * 2) ; execute printf("%.9f\n", Set{z1, z2}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int count=0 ; public static void main(String[] args){ @ SuppressWarnings("resource")Scanner sc2=new Scanner(System.in); String[] s=sc2.nextLine().split("[\\s]+"); double x=Double.parseDouble(s[0])-Double.parseDouble(s[2]); double y=Double.parseDouble(s[1])-Double.parseDouble(s[3]); System.out.println(Math.sqrt(x*x+y*y)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute count : int := 0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc2 : OclFile ; sc2 := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : Sequence(String) ; s := sc2.nextLine()->split("[\\s]+") ; var x : double ; x := (s[0+1])->toReal() - (s[2+1])->toReal() ; var y : double ; y := (s[1+1])->toReal() - (s[3+1])->toReal() ; OclFile["System.out"].println((x * x + y * y)->sqrt()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in))); double x1=scan.nextDouble(); double y1=scan.nextDouble(); double x2=scan.nextDouble(); double y2=scan.nextDouble(); System.out.printf("%.8f",Math.sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)))); System.out.println(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var x1 : double ; x1 := scan.getCurrent()->toReal() ; var y1 : double ; y1 := scan.getCurrent()->toReal() ; var x2 : double ; x2 := scan.getCurrent()->toReal() ; var y2 : double ; y2 := scan.getCurrent()->toReal() ; OclFile["System.out"].printf("%.8f", (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))->sqrt()) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Point { private double x,y ; public Point(double x,double y){ this.x=x ; this.y=y ; } public double getX(){ return x ; } public double getY(){ return y ; } } public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Point[] points=new Point[2]; for(int i=0 ; i<2 ; i++){ points[i]=new Point(sc.nextDouble(),sc.nextDouble()); } double x=points[0] .getX()-points[1] .getX(); double y=points[0] .getY()-points[1] .getY(); double distance=Math.sqrt(Math.pow(x,2)+Math.pow(y,2)); System.out.printf("%.6f \n",distance); } } ------------------------------------------------------------ OCL File: --------- class Point { attribute x : double; static operation newPoint( x : double, y : double) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : double, y : double) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation getX() : double pre: true post: true activity: ( return x ); operation getY() : double pre: true post: true activity: ( return y ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var points : Sequence(Point) ; points := Integer.subrange(1,2)->collect(null) ; var i : int ; i := 0 ; while i < 2 do ( ( points[i+1] := Point.newPoint(sc.getCurrent()->toReal(), sc.getCurrent()->toReal()) ) ; i := i + 1 ) ; var x : double ; x := points[0+1].getX() - points[1+1].getX() ; var y : double ; y := points[0+1].getY() - points[1+1].getY() ; var distance : double ; distance := (x->pow(2) + y->pow(2))->sqrt() ; OclFile["System.out"].printf("%.6f \n", distance) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()," "); double a=Double.parseDouble(st.nextToken()); double b=Double.parseDouble(st.nextToken()); double c=Double.parseDouble(st.nextToken()); double d=Double.parseDouble(st.nextToken()); System.out.printf("%.8f",Math.sqrt(Math.pow(c-a,2)+Math.pow(d-b,2))); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String_String(br.readLine(), " ") ; var a : double ; a := (st.next())->toReal() ; var b : double ; b := (st.next())->toReal() ; var c : double ; c := (st.next())->toReal() ; var d : double ; d := (st.next())->toReal() ; OclFile["System.out"].printf("%.8f", (c - a->pow(2) + d - b->pow(2))->sqrt()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class JavaApplication173 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String x=sc.next(); String y=sc.next(); for(int i=0 ; isize() do ( ( if (x->at(i+1) < y->at(i+1)) then ( OclFile["System.out"].println("-1") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(y) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { private static long gcd(long a,long b){ if(a==0){ return b ; } return gcd(b % a,a); } public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n=Integer.parseInt(f.readLine()); StringTokenizer st=new StringTokenizer(f.readLine()); int[] c=new int[n]; for(int i=0 ; icycles=new ArrayList<>(); boolean[] visited=new boolean[n]; boolean flag=false ; for(int i=0 ; itoInteger() ; var st : OclIterator ; st := OclIterator.newOclIterator_String(f.readLine()) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( c[i+1] := (st.next())->toInteger() - 1 ) ; i := i + 1 ) ; var cycles : Sequence(int) ; cycles := Sequence{} ; var visited : Sequence(boolean) ; visited := Integer.subrange(1,n)->collect(false) ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < n do ( ( if (not(visited[i+1])) then ( var j : int ; j := i ; var length : int ; length := 0 ; while (not(visited[j+1])) do ( visited[j+1] := true ; j := c[j+1] ; length := length + 1 ) ; if (j /= i) then ( flag := true ; break ) else skip ; cycles := cycles->including(length) ; ) else skip ) ; i := i + 1 ) ; if (flag) then ( skip ) else ( var total : long ; total := 1 ; for (i : cycles) do ( ( var gcd : long ; gcd := gcd(total, i) ; total := total*(i) ; total := total/(gcd) ) ) ; skip ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.text.DecimalFormat ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); double x1=input.nextDouble(); double y1=input.nextDouble(); double x2=input.nextDouble(); double y2=input.nextDouble(); DecimalFormat df=new DecimalFormat("#.#########"); System.out.println(df.format(Math.sqrt(Math.pow((x1-x2),2)+Math.pow(y1-y2,2)))); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x1 : double ; x1 := input.getCurrent()->toReal() ; var y1 : double ; y1 := input.getCurrent()->toReal() ; var x2 : double ; x2 := input.getCurrent()->toReal() ; var y2 : double ; y2 := input.getCurrent()->toReal() ; var df : DecimalFormat ; df := DecimalFormat.newDecimalFormat("#.#########") ; OclFile["System.out"].println(df.format(((x1 - x2)->pow(2) + y1 - y2->pow(2))->sqrt())) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class guessgame { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n,p,p1 ; int x ; n=sc.nextLong(); x=sc.nextInt(); if(x==0){ p=(long)Math.ceil(n/3.0); if(p % 2==0 &&(n % 3==2 || n % 3==0))System.out.println(0); else if(p % 2==1 &&(n % 3==1 || n % 3==2))System.out.println(1); else System.out.println(2); } else if(x==1){ if(n % 3==1)System.out.println(0); else if(n % 3==0)System.out.println(1); else System.out.println(2); } else { p=(long)Math.ceil(n/3.0); if(p % 2==1 &&(n % 3==2 || n % 3==0))System.out.println(0); else if(p % 2==0 &&(n % 3==1 || n % 3==2))System.out.println(1); else System.out.println(2); } } } ------------------------------------------------------------ OCL File: --------- class guessgame { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; var p : long ; var p1 : long ; var x : int ; n := sc.getCurrent()->toLong() ; x := sc.getCurrent()->toInteger() ; if (x = 0) then ( p := (n / 3.0)->ceil()->oclAsType(long) ; if (p mod 2 = 0 & (n mod 3 = 2 or n mod 3 = 0)) then OclFile["System.out"].println(0) ; else if (p mod 2 = 1 & (n mod 3 = 1 or n mod 3 = 2)) then OclFile["System.out"].println(1) else OclFile["System.out"].println(2) ; ; ) else if (x = 1) then ( if (n mod 3 = 1) then OclFile["System.out"].println(0) ; else if (n mod 3 = 0) then OclFile["System.out"].println(1) else OclFile["System.out"].println(2) ; ; ) else ( p := (n / 3.0)->ceil()->oclAsType(long) ; if (p mod 2 = 1 & (n mod 3 = 2 or n mod 3 = 0)) then OclFile["System.out"].println(0) ; else if (p mod 2 = 0 & (n mod 3 = 1 or n mod 3 = 2)) then OclFile["System.out"].println(1) else OclFile["System.out"].println(2) ; ; ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class guessgame { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n,p,p1 ; int x ; n=sc.nextLong(); x=sc.nextInt(); if(x==0){ p=(long)Math.ceil(n/3.0); if(p % 2==0 &&(n % 3==2 || n % 3==0))System.out.println(0); if(p % 2==1 &&(n % 3==1 || n % 3==2))System.out.println(1); if((n/3)% 2==1 &&(n % 3==0 || n % 3==1))System.out.println(2); } else if(x==1){ if(n % 3==1)System.out.println(0); if(n % 3==0)System.out.println(1); if(n % 3==2)System.out.println(2); } else { p=(long)Math.ceil(n/3.0); if(p % 2==1 &&(n % 3==2 || n % 3==0))System.out.println(0); if(p % 2==0 &&(n % 3==1 || n % 3==2))System.out.println(1); if((n/3)% 2==0 &&(n % 3==0 || n % 3==1))System.out.println(2); } } } ------------------------------------------------------------ OCL File: --------- class guessgame { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; var p : long ; var p1 : long ; var x : int ; n := sc.getCurrent()->toLong() ; x := sc.getCurrent()->toInteger() ; if (x = 0) then ( p := (n / 3.0)->ceil()->oclAsType(long) ; if (p mod 2 = 0 & (n mod 3 = 2 or n mod 3 = 0)) then OclFile["System.out"].println(0) ; else skip ; if (p mod 2 = 1 & (n mod 3 = 1 or n mod 3 = 2)) then OclFile["System.out"].println(1) ; else skip ; if ((n / 3) mod 2 = 1 & (n mod 3 = 0 or n mod 3 = 1)) then OclFile["System.out"].println(2) ; else skip ) else if (x = 1) then ( if (n mod 3 = 1) then OclFile["System.out"].println(0) ; else skip ; if (n mod 3 = 0) then OclFile["System.out"].println(1) ; else skip ; if (n mod 3 = 2) then OclFile["System.out"].println(2) ; else skip ) else ( p := (n / 3.0)->ceil()->oclAsType(long) ; if (p mod 2 = 1 & (n mod 3 = 2 or n mod 3 = 0)) then OclFile["System.out"].println(0) ; else skip ; if (p mod 2 = 0 & (n mod 3 = 1 or n mod 3 = 2)) then OclFile["System.out"].println(1) ; else skip ; if ((n / 3) mod 2 = 0 & (n mod 3 = 0 or n mod 3 = 1)) then OclFile["System.out"].println(2) ; else skip ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.io.IOException ; import java.nio.file.Files ; import java.nio.file.Paths ; import java.util.Scanner ; public class Main { static int solve(String a,String b){ char[] cs1=a.toCharArray(); char[] cs2=b.toCharArray(); int[][] dp=new int[a.length()+1][b.length()+1]; int mx=0 ; for(int i=a.length()-1 ; i>=0 ; i--){ for(int j=b.length()-1 ; j>=0 ; j--){ if(cs1[i]==cs2[j]){ dp[i][j]=2+dp[i+1][j+1]; } else { dp[i][j]=Math.max(dp[i+1][j]-1,dp[i][j+1]-1); dp[i][j]=Math.max(0,dp[i][j]); } mx=Math.max(mx,dp[i][j]); } } return mx ; } public static void main(String[] args)throws IOException { if(! isOj()){ System.setIn(Files.newInputStream(Paths.get("src/main/java/input.txt"))); } Scanner sc=new Scanner(new BufferedInputStream(System.in)); sc.nextLine(); String s1=sc.next(); String s2=sc.next(); System.out.println(solve(s1,s2)); } static boolean isOj(){ if(System.getProperty("ONLINE_JUDGE")!=null){ return true ; } return System.getenv("CP_LOCAL_ENV")==null ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve( a : String, b : String) : int pre: true post: true activity: ( var cs1 : Sequence(String) ; cs1 := a->characters() ; var cs2 : Sequence(String) ; cs2 := b->characters() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,a->size() + 1)->collect(Integer.subrange(1,b->size() + 1)->collect(0)) ; var mx : int ; mx := 0 ; var i : int ; i := a->size() - 1 ; while i >= 0 do ( ( var j : int ; j := b->size() - 1 ; while j >= 0 do ( ( if (cs1[i+1] = cs2[j+1]) then ( dp[i+1][j+1] := 2 + dp[i + 1+1][j + 1+1] ) else ( dp[i+1][j+1] := Set{dp[i + 1+1][j+1] - 1, dp[i+1][j + 1+1] - 1}->max() ; dp[i+1][j+1] := Set{0, dp[i+1][j+1]}->max() ) ; mx := Set{mx, dp[i+1][j+1]}->max() ) ; j := j - 1 ) ) ; i := i - 1 ) ; return mx ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( if (not(isOj())) then ( setIn(Files.newInputStream(Paths->at("src/main/java/input.txt"+1))) ) else skip ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; skip ; var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; OclFile["System.out"].println(solve(s1, s2)) ; ); static operation isOj() : boolean pre: true post: true activity: ( if (OclProcess.getEnvironmentProperty("ONLINE_JUDGE") /= null) then ( return true ) else skip ; return OclProcess.getEnvironmentProperty("CP_LOCAL_ENV") = null ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class practice { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int x=in.nextInt(); n=n % 6 ; int l=0 ; int m=1 ; int r=2 ; while(n>0){ if(n % 2==0){ int temp=m ; m=r ; r=temp ; } else { int temp=m ; m=l ; l=temp ; } n--; } if(l==x){ System.out.println(0); } else if(m==x){ System.out.println(1); } else { System.out.println(2); } } } ------------------------------------------------------------ OCL File: --------- class practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; n := n mod 6 ; var l : int ; l := 0 ; var m : int ; m := 1 ; var r : int ; r := 2 ; while (n > 0) do ( if (n mod 2 = 0) then ( var temp : int ; temp := m ; m := r ; r := temp ) else ( var temp : int ; temp := m ; m := l ; l := temp ) ; n := n - 1 ) ; if (l = x) then ( OclFile["System.out"].println(0) ) else if (m = x) then ( OclFile["System.out"].println(1) ) else ( OclFile["System.out"].println(2) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ShellGame { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int x=sc.nextInt(); n=n % 6 ; int[] state={ 0,1,2,2,1,0 }; int pos=0 ; if(x==0){ if(n % 2!=0)pos=5 ; else pos=0 ; } if(x==1){ if(n % 2!=0)pos=1 ; else pos=4 ; } if(x==2){ if(n % 2!=0)pos=3 ; else pos=2 ; } System.out.println(state[(6+pos-n)% 6]); } } ------------------------------------------------------------ OCL File: --------- class ShellGame { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; n := n mod 6 ; var state : Sequence(int) ; state := Sequence{0,1,2,2,1,0} ; var pos : int ; pos := 0 ; if (x = 0) then ( if (n mod 2 /= 0) then pos := 5 ; else pos := 0 ; ) else skip ; if (x = 1) then ( if (n mod 2 /= 0) then pos := 1 ; else pos := 4 ; ) else skip ; if (x = 2) then ( if (n mod 2 /= 0) then pos := 3 ; else pos := 2 ; ) else skip ; OclFile["System.out"].println(state[(6 + pos - n) mod 6+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static int j ; public static int y ; public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); j=stdIn.nextInt(); y=stdIn.nextInt(); solv(0,0,new int[10],0); } public static void solv(int a,int b,int[] c,int d){ if(a==j && b==y){ for(int i=0 ; ij || b>y){ return ; } if((a==5 && b<=3)||(a<=3 && b==5))return ; if(a==5 && b==5)return ; int[] ca=new int[10]; int[] cb=new int[10]; for(int i=0 ; itoInteger() ; y := stdIn.getCurrent()->toInteger() ; execute solv(0, 0, Integer.subrange(1,10)->collect(0), 0) ); static operation solv( a : int, b : int, c : Sequence(int), d : int) : void pre: true post: true activity: ( if (a = j & b = y) then ( var i : int ; i := 0 ; while i < d do ( ( OclFile["System.out"].print(if (c[i+1] = 1) then "A" else "B" endif) ) ; i := i + 1 ) ; OclFile["System.out"].println() ; return ) else skip ; if (a > j or b > y) then ( return ) else skip ; if ((a = 5 & b <= 3) or (a <= 3 & b = 5)) then return else skip ; if (a = 5 & b = 5) then return else skip ; var ca : Sequence(int) ; ca := Integer.subrange(1,10)->collect(0) ; var cb : Sequence(int) ; cb := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < d do ( ( ca[i+1] := c[i+1] ; cb[i+1] := c[i+1] ) ; i := i + 1 ) ; ca[d+1] := 1 ; cb[d+1] := 0 ; execute solv(a + 1, b, ca, d + 1) ; execute solv(a, b + 1, cb, d + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; while((line=br.readLine())!=null && ! line.isEmpty()){ int j,y ; j=parseInt(line.substring(0,line.indexOf(' '))); y=parseInt(line.substring(line.indexOf(' ')+1)); play(0,0,"",j,y); } } static void play(int _j,int _y,String r,int j,int y){ if(_j==j && _y==y){ System.out.println(r); return ; } if(_j>j || _y>y)return ; if((_j>=5 && _y<4)||(_j<4 && _y>=5))return ; play(_j+1,_y,r+"A",j,y); play(_j,_y+1,r+"B",j,y); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var j : int ; var y : int ; j := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; y := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; execute play(0, 0, "", j, y) ) ; line := br.readLine() ; ) ); static operation play( _j : int, _y : int, r : String, j : int, y : int) : void pre: true post: true activity: ( if (_j = j & _y = y) then ( OclFile["System.out"].println(r) ; return ) else skip ; if (_j > j or _y > y) then return else skip ; if ((_j >= 5 & _y < 4) or (_j < 4 & _y >= 5)) then return else skip ; execute play(_j + 1, _y, r + "A", j, y) ; execute play(_j, _y + 1, r + "B", j, y) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Math.*; public class Main { int INF=1<<28 ; void run(){ Scanner sc=new Scanner(System.in); dfs(sc.nextInt(),sc.nextInt(),""); } void dfs(int j,int y,String ans){ if((j | y)==0){ if(ok(ans)){ System.out.println(ans); } } if(j>0)dfs(j-1,y,ans+'A'); if(y>0)dfs(j,y-1,ans+'B'); } boolean ok(String ans){ int jc=0,yc=0 ; for(int i=0,l=ans.length(); i=jc && yc==5)||(3>=yc && jc==5)){ return jc+yc==l ; } if(jc==yc && jc==5){ return jc+yc==l ; } if((jc==4 && yc==6)||(yc==4 && jc==6)){ return jc+yc==l ; } } return true ; } void debug(Object...os){ System.out.println(deepToString(os)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute INF : int := (1*(2->pow(28)))->oclAsType(long); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; execute dfs(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger(), "") ); operation dfs( j : int, y : int, ans : String) : void pre: true post: true activity: ( if ((j or y) = 0) then ( if (ok(ans)) then ( OclFile["System.out"].println(ans) ) else skip ) else skip ; if (j > 0) then execute dfs(j - 1, y, ans + 'A') ; else skip ; if (y > 0) then execute dfs(j, y - 1, ans + 'B') ; else skip ); operation ok( ans : String) : boolean pre: true post: true activity: ( var jc : int ; jc := 0 ; var yc : int ; yc := 0 ; var i : int ; i := 0 ; var l : int ; l := ans->size() ; while i < l do ( ( if (ans->at(i+1) = 'A') then jc := jc + 1 else yc := yc + 1 ; ; if ((3 >= jc & yc = 5) or (3 >= yc & jc = 5)) then ( return jc + yc = l ) else skip ; if (jc = yc & jc = 5) then ( return jc + yc = l ) else skip ; if ((jc = 4 & yc = 6) or (yc = 4 & jc = 6)) then ( return jc + yc = l ) else skip ) ; i := i + 1 ) ; return true ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); a=scanner.nextInt(); b=scanner.nextInt(); slove(0,0,""); } private void slove(int x,int y,String s){ if((x==5 && ytoInteger() ; b := scanner.getCurrent()->toInteger() ; execute slove(0, 0, "") ); operation slove( x : int, y : int, s : String) : void pre: true post: true activity: ( if ((x = 5 & y < b & y /= 4) or y = 5 & x < a & x /= 4) then return else skip ; if (x = a + 1 or y = b + 1) then return else skip ; if (x = a & y = b) then OclFile["System.out"].println(s) ; else skip ; var i : int ; i := 0 ; while i < 2 do ( ( if (i = 0) then ( execute slove(x + 1, y, s + "A") ) else execute slove(x, y + 1, s + "B") ; ) ; i := i + 1 ) ); attribute a : int; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); public Main(){ int j=sc.nextInt(); int y=sc.nextInt(); parse(0,0,j,y,""); } void parse(int a,int b,int j,int y,String p){ if(a==j && b==y){ System.out.println(p); return ; } if(a>=5 && b<=3)return ; if(b>=5 && a<=3)return ; if(a+1<=j && b<=y)parse(a+1,b,j,y,p+"A"); if(a<=j && b+1<=y)parse(a,b+1,j,y,p+"B"); } public static void main(String[] a){ new Main(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( var j : int ; j := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; execute parse(0, 0, j, y, "") ); operation parse( a : int, b : int, j : int, y : int, p : String) : void pre: true post: true activity: ( if (a = j & b = y) then ( OclFile["System.out"].println(p) ; return ) else skip ; if (a >= 5 & b <= 3) then return else skip ; if (b >= 5 & a <= 3) then return else skip ; if (a + 1 <= j & b <= y) then execute parse(a + 1, b, j, y, p + "A") ; else skip ; if (a <= j & b + 1 <= y) then execute parse(a, b + 1, j, y, p + "B") ; else skip ; ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static boolean Div_by_8(int n){ return(((n>>3)<<3)==n); } public static void main(String[] args){ int n=16 ; if(Div_by_8(n))System.out.println("YES"); else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Div_by_8( n : int) : boolean pre: true post: true activity: ( return (((((n/(2->pow(3)))->oclAsType(long))*(2->pow(3)))->oclAsType(long)) = n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 16 ; if (Div_by_8(n)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); double xp0,xp1,yp0,yp1 ; int q ; double[] xp2,yp2 ; int i ; double s1x,s1y,s2x,s2y,s ; xp0=sc.nextDouble(); yp0=sc.nextDouble(); xp1=sc.nextDouble(); yp1=sc.nextDouble(); q=sc.nextInt(); xp2=new double[q]; yp2=new double[q]; s1x=xp1-xp0 ; s1y=yp1-yp0 ; for(i=0 ; i0){ System.out.println("COUNTER_CLOCKWISE"); } else if(s<0){ System.out.println("CLOCKWISE"); } else { if(s1x*s2x<0 || s1y*s2y<0){ System.out.println("ONLINE_BACK"); } else { if(((s1x*s1x)+(s1y*s1y))<((s2x*s2x)+(s2y*s2y))){ System.out.println("ONLINE_FRONT"); } else { System.out.println("ON_SEGMENT"); } } } } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var xp0 : double ; var xp1 : double ; var yp0 : double ; var yp1 : double ; var q : int ; var xp2 : Sequence(double) ; var yp2 : Sequence(double) ; var i : int ; var s1x : double ; var s1y : double ; var s2x : double ; var s2y : double ; var s : double ; xp0 := sc.nextDouble() ; yp0 := sc.nextDouble() ; xp1 := sc.nextDouble() ; yp1 := sc.nextDouble() ; q := sc.nextInt() ; xp2 := Integer.subrange(1,q)->collect(0.0) ; yp2 := Integer.subrange(1,q)->collect(0.0) ; s1x := xp1 - xp0 ; s1y := yp1 - yp0 ; i := 0 ; while i < q do ( ( xp2[i+1] := sc.nextDouble() ; yp2[i+1] := sc.nextDouble() ; s2x := xp2[i+1] - xp0 ; s2y := yp2[i+1] - yp0 ; s := s1x * s2y - s1y * s2x ; if (s > 0) then ( OclFile["System.out"].println("COUNTER_CLOCKWISE") ) else if (s < 0) then ( OclFile["System.out"].println("CLOCKWISE") ) else ( if (s1x * s2x < 0 or s1y * s2y < 0) then ( OclFile["System.out"].println("ONLINE_BACK") ) else ( if (((s1x * s1x) + (s1y * s1y)) < ((s2x * s2x) + (s2y * s2y))) then ( OclFile["System.out"].println("ONLINE_FRONT") ) else ( OclFile["System.out"].println("ON_SEGMENT") ) ) ) ; ; ) ; i := i + 1 ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static String clockwise(Vector v1,Vector v2){ long cross=v1.x*v2.y-v1.y*v2.x ; long value=v1.x*v2.x+v1.y*v2.y ; long len1=v1.x*v1.x+v1.y*v1.y ; long len2=v2.x*v2.x+v2.y*v2.y ; if(cross==0L){ if(value<0L)return "ONLINE_BACK" ; else if(len10L){ return "COUNTER_CLOCKWISE" ; } else { return "CLOCKWISE" ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); Point p0=new Point(sc.nextLong(),sc.nextLong()); Point p1=new Point(sc.nextLong(),sc.nextLong()); Vector v1=new Vector(p0,p1); int q=sc.nextInt(); for(int i=0 ; i 0L) then ( return "COUNTER_CLOCKWISE" ) else ( return "CLOCKWISE" ) ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var p0 : Point ; p0 := Point.newPoint(sc.getCurrent()->toLong(), sc.getCurrent()->toLong()) ; var p1 : Point ; p1 := Point.newPoint(sc.getCurrent()->toLong(), sc.getCurrent()->toLong()) ; var v1 : Sequence ; v1 := Sequence{} ; var q : int ; q := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var p2 : Point ; p2 := Point.newPoint(sc.getCurrent()->toLong(), sc.getCurrent()->toLong()) ; var v2 : Sequence ; v2 := Sequence{} ; OclFile["System.out"].println(clockwise(v1, v2)) ) ; i := i + 1 ) ; ); } class Point { attribute x : long; attribute y : long; static operation newPoint( x : long, y : long) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : long, y : long) : void pre: true post: true activity: ( self.x := x ; self.y := y ); } class Vector { attribute x : long; attribute y : long; static operation newVector( ps : Point, pg : Point) : Vector pre: true post: true activity: ( var self : Vector ; self := createVector(); self.initialise(ps, pg); return self ); operation initialise( ps : Point, pg : Point) : void pre: true post: true activity: ( x := pg.x - ps.x ; y := pg.y - ps.y ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long centered_heptagonal_num(long n){ return(7*n*n-7*n+2)/2 ; } public static void main(String[] args){ long n=5 ; System.out.println(n+"th Centered "+"heptagonal number : "+centered_heptagonal_num(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation centered_heptagonal_num( n : long) : long pre: true post: true activity: ( return (7 * n * n - 7 * n + 2) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 5 ; OclFile["System.out"].println(n + "th Centered " + "heptagonal number : " + centered_heptagonal_num(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); double px,py,x1,y1,x2,y2,angle1,angle2,back,rad,leng1,leng2 ; int q ; px=scan.nextDouble(); py=scan.nextDouble(); x1=scan.nextDouble(); y1=scan.nextDouble(); rad=Math.atan2(y1-py,x1-px); angle1=rad*180/Math.PI ; if(angle1<0)angle1+=360 ; back=angle1+180 ; leng1=Math.sqrt((x1-px)*(x1-px)+(y1-py)*(y1-py)); if(back>=360)back-=360 ; q=scan.nextInt(); for(int i=0 ; iback && angle2angle1){ System.out.println("COUNTER_CLOCKWISE"); } else { System.out.println("CLOCKWISE"); } } } scan.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var px : double ; var py : double ; var x1 : double ; var y1 : double ; var x2 : double ; var y2 : double ; var angle1 : double ; var angle2 : double ; var back : double ; var rad : double ; var leng1 : double ; var leng2 : double ; var q : int ; px := scan.getCurrent()->toReal() ; py := scan.getCurrent()->toReal() ; x1 := scan.getCurrent()->toReal() ; y1 := scan.getCurrent()->toReal() ; rad := atan2(y1 - py, x1 - px) ; angle1 := rad * 180 / 3.141592653589793 ; if (angle1 < 0) then angle1 := angle1+(360) ; else skip ; back := angle1 + 180 ; leng1 := ((x1 - px) * (x1 - px) + (y1 - py) * (y1 - py))->sqrt() ; if (back >= 360) then back := back-(360) ; else skip ; q := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( x2 := scan.getCurrent()->toReal() ; y2 := scan.getCurrent()->toReal() ; rad := atan2(y2 - py, x2 - px) ; angle2 := rad * 180 / 3.141592653589793 ; if (angle2 < 0) then angle2 := angle2+(360) ; else skip ; if (px = x2 & py = y2) then ( OclFile["System.out"].println("ON_SEGMENT") ) else if (angle2 = angle1) then ( leng2 := ((x2 - px) * (x2 - px) + (y2 - py) * (y2 - py))->sqrt() ; if ((leng2 - leng1) <= 0) then ( OclFile["System.out"].println("ON_SEGMENT") ) else ( OclFile["System.out"].println("ONLINE_FRONT") ) ) else if (angle2 = back) then ( OclFile["System.out"].println("ONLINE_BACK") ) else if (back < 180) then ( if (angle2 > back & angle2 < angle1) then ( OclFile["System.out"].println("CLOCKWISE") ) else ( OclFile["System.out"].println("COUNTER_CLOCKWISE") ) ) else ( if (angle2 < back & angle2 > angle1) then ( OclFile["System.out"].println("COUNTER_CLOCKWISE") ) else ( OclFile["System.out"].println("CLOCKWISE") ) ) ; ; ; ; ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); double xp0=sc.nextDouble(); double yp0=sc.nextDouble(); Vector2d p0=new Vector2d(xp0,yp0); double xp1=sc.nextDouble(); double yp1=sc.nextDouble(); Vector2d p1=new Vector2d(xp1,yp1); int q=sc.nextInt(); for(int i=0 ; i1 || v2.y/v1.y>1){ return "ONLINE_FRONT" ; } else { return "ON_SEGMENT" ; } } else if(a>0){ return "COUNTER_CLOCKWISE" ; } else { return "CLOCKWISE" ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var xp0 : double ; xp0 := sc.getCurrent()->toReal() ; var yp0 : double ; yp0 := sc.getCurrent()->toReal() ; var p0 : Vector2d ; p0 := Vector2d.newVector2d(xp0, yp0) ; var xp1 : double ; xp1 := sc.getCurrent()->toReal() ; var yp1 : double ; yp1 := sc.getCurrent()->toReal() ; var p1 : Vector2d ; p1 := Vector2d.newVector2d(xp1, yp1) ; var q : int ; q := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var x : double ; x := sc.getCurrent()->toReal() ; var y : double ; y := sc.getCurrent()->toReal() ; OclFile["System.out"].println(solve(p0, p1, Vector2d.newVector2d(x, y))) ) ; i := i + 1 ) ; skip ; ); static class Vector2d { static operation newVector2d( x : double, y : double) : Vector2d pre: true post: true activity: ( var self : Vector2d ; self := createVector2d(); self.initialise(x, y); return self ); operation initialise( x : double, y : double) : void pre: true post: true activity: ( self.x := x ; self.y := y ); attribute x : double; attribute y : double; operation toString() : String pre: true post: true activity: ( return StringLib.format("%1$.10f %2$.10f",Sequence{x,y}) ); } static operation sub( v1 : Vector2d, v2 : Vector2d) : Vector2d pre: true post: true activity: ( return Vector2d.newVector2d(v2.x - v1.x, v2.y - v1.y) ); static operation solve( p0 : Vector2d, p1 : Vector2d, p2 : Vector2d) : String pre: true post: true activity: ( var v1 : Vector2d ; v1 := sub(p0, p1) ; var v2 : Vector2d ; v2 := sub(p0, p2) ; var a : double ; a := v1.x * v2.y - v1.y * v2.x ; if (a = 0) then ( if (v2.x / v1.x < 0 or v2.y / v1.y < 0) then ( return "ONLINE_BACK" ) else if (v2.x / v1.x > 1 or v2.y / v1.y > 1) then ( return "ONLINE_FRONT" ) else ( return "ON_SEGMENT" ) ; ) else if (a > 0) then ( return "COUNTER_CLOCKWISE" ) else ( return "CLOCKWISE" ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class Main { static final int INF=(1<<31)-1 ; static final int MAXN=11111 ; public static void main(String[] args)throws Exception { Scanner input=new Scanner(System.in); int x0,y0,x1,y1,x2,y2 ; int q ; x0=input.nextInt(); y0=input.nextInt(); x1=input.nextInt(); y1=input.nextInt(); q=input.nextInt(); for(int i=0 ; i0)System.out.println("COUNTER_CLOCKWISE"); else if(d<0)System.out.println("CLOCKWISE"); else { int a2,b2,a1,b1 ; a1=x1-x0 ; b1=y1-y0 ; a2=x2-x0 ; b2=y2-y0 ; if(a1*a2<=0 && b1*b2<=0 &&(a1*a1+b1*b1!=0 && a2*a2+b2*b2!=0))System.out.println("ONLINE_BACK"); else if(Math.hypot(a1,b1)pow(31)))->oclAsType(long)) - 1; static attribute MAXN : int := 11111; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x0 : int ; var y0 : int ; var x1 : int ; var y1 : int ; var x2 : int ; var y2 : int ; var q : int ; x0 := input.getCurrent()->toInteger() ; y0 := input.getCurrent()->toInteger() ; x1 := input.getCurrent()->toInteger() ; y1 := input.getCurrent()->toInteger() ; q := input.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( x2 := input.getCurrent()->toInteger() ; y2 := input.getCurrent()->toInteger() ; var d : int ; d := ccw(x1 - x0, y1 - y0, x2 - x1, y2 - y1) ; if (d > 0) then OclFile["System.out"].println("COUNTER_CLOCKWISE") ; else if (d < 0) then OclFile["System.out"].println("CLOCKWISE") else ( var a2 : int ; var b2 : int ; var a1 : int ; var b1 : int ; a1 := x1 - x0 ; b1 := y1 - y0 ; a2 := x2 - x0 ; b2 := y2 - y0 ; if (a1 * a2 <= 0 & b1 * b2 <= 0 & (a1 * a1 + b1 * b1 /= 0 & a2 * a2 + b2 * b2 /= 0)) then OclFile["System.out"].println("ONLINE_BACK") else if (hypot(a1, b1) < hypot(a2, b2)) then OclFile["System.out"].println("ONLINE_FRONT") else OclFile["System.out"].println("ON_SEGMENT") ; ; ; ) ; ) ; i := i + 1 ) ; ); static operation ccw( a0 : int, b0 : int, a1 : int, b1 : int) : int pre: true post: true activity: ( var d : int ; d := a0 * b1 - a1 * b0 ; return d ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; class GFG { static int MOD=1000000007 ; static long sum(long N){ long val=N*(N+1); val=val % MOD ; return val ; } static int sumX(int N,int M,int K){ for(int i=0 ; ioclAsType(int) ) ; i := i + 1 ) ; N := N mod MOD ; return N ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 1 ; var M : int ; M := 2 ; var K : int ; K := 3 ; OclFile["System.out"].println(sumX(N, M, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { public static int findGCD(int a,int b){ if(b==0)return a ; else return findGCD(b,a % b); } static void findNumbers(int a,int b){ int gcd=findGCD(a,b); System.out.println((a/gcd)+" "+(b/gcd)); } public static void main(String[] args){ int a=12,b=16 ; findNumbers(a,b); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findGCD( a : int, b : int) : int pre: true post: true activity: ( if (b = 0) then return a else return findGCD(b, a mod b) ); static operation findNumbers( a : int, b : int) : void pre: true post: true activity: ( var gcd : int ; gcd := findGCD(a, b) ; OclFile["System.out"].println((a / gcd) + " " + (b / gcd)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 12 ; var b : int ; b := 16 ; execute findNumbers(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean productsDistinct(int N){ String s="" ; while(N>0){ s+=(char)(N % 10+'0'); N/=10 ; } s=reverse(s); int sz=s.length(); HashSetse=new HashSet(); for(int i=0 ; i 0) do ( s := s+((N mod 10 + '0')->oclAsType(String)) ; N := N/(10) ) ; s := reverse(s) ; var sz : int ; sz := s->size() ; var se : Set(int) ; se := Set{} ; var i : int ; i := 0 ; while i < sz do ( ( var product : int ; product := 1 ; var j : int ; j := i ; while j < sz do ( ( product := product*((s->at(j+1) - ('0')->char2byte())->oclAsType(int)) ; if (se->includes(product)) then return false else se := se->including(product) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return true ); static operation reverse( input : String) : String pre: true post: true activity: ( var a : Sequence(String) ; a := input->characters() ; var l : int ; var r : int ; r := a->size() - 1 ; l := 0 ; while l < r do ( ( var temp : String ; temp := a[l+1] ; a[l+1] := a[r+1] ; a[r+1] := temp ) ; l := l + 1 ; r := r - 1 ) ; return (a)->sum() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 2345 ; if (productsDistinct(N)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int[] a=new int[1200]; int[] b=new int[1200]; for(int i=0 ; ib[j])x++; else if(a[j]y)System.out.println("RED"); if(xtoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,1200)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,1200)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var x : int ; x := 0 ; var y : int ; y := 0 ; var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; var j : int ; j := 0 ; while j < n do ( ( a[j+1] := s1->at(j+1) ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( b[j+1] := s2->at(j+1) ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( if (a[j+1] > b[j+1]) then x := x + 1 ; else if (a[j+1] < b[j+1]) then y := y + 1 ; else skip ; ) ; j := j + 1 ) ; if (x > y) then OclFile["System.out"].println("RED") ; else skip ; if (x < y) then OclFile["System.out"].println("BLUE") ; else skip ; if (x = y) then OclFile["System.out"].println("EQUAL") ; else skip ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int W=scan.nextInt(); int H=scan.nextInt(); int C=scan.nextInt(); int g ; int b ; int x ; int t ; int y ; if(W>H){ t=W ; y=H ; while(W % H!=0){ g=W ; W=H ; H=g % H ; } b=H*H ; x=(t*y)/b ; System.out.println(x*C); } else if(WtoInteger() ; var H : int ; H := scan.getCurrent()->toInteger() ; var C : int ; C := scan.getCurrent()->toInteger() ; var g : int ; var b : int ; var x : int ; var t : int ; var y : int ; if (W > H) then ( t := W ; y := H ; while (W mod H /= 0) do ( g := W ; W := H ; H := g mod H ) ; b := H * H ; x := (t * y) / b ; OclFile["System.out"].println(x * C) ; ) else if (W < H) then ( t := W ; y := H ; while (H mod W /= 0) do ( g := H ; H := W ; W := g mod W ) ; b := W * W ; x := (t * y) / b ; OclFile["System.out"].println(x * C) ; ) else if (H = W) then ( OclFile["System.out"].println(C) ) else skip ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int[] a=new int[1200]; int[] b=new int[1200]; for(int i=0 ; ib[j])x++; else if(a[j]y)System.out.println("RED"); if(xtoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,1200)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,1200)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var x : int ; x := 0 ; var y : int ; y := 0 ; var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; var j : int ; j := 0 ; while j < n do ( ( a[j+1] := s1->at(j+1) ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( b[j+1] := s2->at(j+1) ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( if (a[j+1] > b[j+1]) then x := x + 1 ; else if (a[j+1] < b[j+1]) then y := y + 1 ; else skip ; ) ; j := j + 1 ) ; if (x > y) then OclFile["System.out"].println("RED") ; else skip ; if (x < y) then OclFile["System.out"].println("BLUE") ; else skip ; if (x = y) then OclFile["System.out"].println("EQUAL") ; else skip ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); long n=sc.nextLong(); int mod=1000000007 ; int[] arr={ x-y,x,y,y-x,-x,-y,x-y }; int idx=(int)n % 6 ; int val=arr[idx] % mod ; if(val<0)System.out.println(mod+val); else System.out.println(val); } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var n : long ; n := sc.getCurrent()->toLong() ; var mod : int ; mod := 1000000007 ; var arr : Sequence(int) ; arr := Sequence{x - y,x,y,y - x,-x,-y,x - y} ; var idx : int ; idx := n->oclAsType(int) mod 6 ; var val : int ; val := arr[idx+1] mod mod ; if (val < 0) then OclFile["System.out"].println(mod + val) else OclFile["System.out"].println(val) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static int missingNum(int arr[],int n){ Listlist=new ArrayList<>(arr.length); for(int i : arr){ list.add(Integer.valueOf(i)); } int minvalue=Collections.min(list); ; int xornum=0 ; for(int i=0 ; iunion(arr->size()) ; for (i : arr) do ( ( list := list->including((i)->toInteger()) ) ) ; var minvalue : int ; minvalue := .min(list) ; var xornum : int ; xornum := 0 ; var i : int ; i := 0 ; while i < n do ( ( xornum := MathLib.bitwiseXor(xornum,(minvalue) xor arr[i+1]) ; minvalue := minvalue + 1 ) ; i := i + 1 ) ; return MathLib.bitwiseXor(xornum,minvalue) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{13,12,11,15} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(missingNum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); int[] a=new int[1200]; int[] b=new int[1200]; while(t-->0){ int n=in.nextInt(),x=0,y=0 ; String s1=in.next(); String s2=in.next(); for(int i=0 ; ib[i])x++; else if(a[i]y)System.out.println("RED"); if(xtoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,1200)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,1200)->collect(0) ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var x : int ; x := 0 ; var y : int ; y := 0 ; var s1 : String ; s1 := in.getCurrent() ; var s2 : String ; s2 := in.getCurrent() ; var i : int ; i := 0 ; while i < n do ( a[i+1] := s1->at(i+1) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := s2->at(i+1) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] > b[i+1]) then x := x + 1 ; else if (a[i+1] < b[i+1]) then y := y + 1 ; else skip ; ) ; i := i + 1 ) ; if (x > y) then OclFile["System.out"].println("RED") ; else skip ; if (x < y) then OclFile["System.out"].println("BLUE") ; else skip ; if (x = y) then OclFile["System.out"].println("EQUAL") ; else skip ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(),x=0,y=0 ; char[] c1=in.next().toCharArray(); char[] c2=in.next().toCharArray(); for(int i=0 ; ic2[i])x++; else if(c1[i]y)System.out.println("RED"); if(xtoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var x : int ; x := 0 ; var y : int ; y := 0 ; var c1 : Sequence(String) ; c1 := in.getCurrent()->characters() ; var c2 : Sequence(String) ; c2 := in.getCurrent()->characters() ; var i : int ; i := 0 ; while i < n do ( ( if (c1[i+1] > c2[i+1]) then x := x + 1 ; else if (c1[i+1] < c2[i+1]) then y := y + 1 ; else skip ; ) ; i := i + 1 ) ; if (x > y) then OclFile["System.out"].println("RED") ; else skip ; if (x < y) then OclFile["System.out"].println("BLUE") ; else skip ; if (x = y) then OclFile["System.out"].println("EQUAL") ; else skip ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF1459A { public static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int test=scanner.nextInt(); while(test-->0){ int n=scanner.nextInt(); String r=scanner.next(); String b=scanner.next(); int red=0,blue=0 ; for(int i=0 ; iblueCard)red++; else if(redCardblue)System.out.println("RED"); else if(blue>red)System.out.println("BLUE"); else System.out.println("EQUAL"); } } } ------------------------------------------------------------ OCL File: --------- class CF1459A { static attribute scanner : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := scanner.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var r : String ; r := scanner.getCurrent() ; var b : String ; b := scanner.getCurrent() ; var red : int ; red := 0 ; var blue : int ; blue := 0 ; var i : int ; i := 0 ; while i < n do ( ( var redCard : int ; redCard := r->at(i+1) - ('0')->char2byte() ; var blueCard : int ; blueCard := b->at(i+1) - ('0')->char2byte() ; if (redCard > blueCard) then red := red + 1 ; else if (redCard < blueCard) then blue := blue + 1 ; else skip ; ) ; i := i + 1 ) ; if (red > blue) then OclFile["System.out"].println("RED") else if (blue > red) then OclFile["System.out"].println("BLUE") else OclFile["System.out"].println("EQUAL") ; ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void candies(int n,int k){ int count=0 ; int ind=1 ; int[] arr=new int[k]; for(int i=0 ; i0){ int f1=(ind-1)*k ; int f2=ind*k ; int sum1=(f1*(f1+1))/2 ; int sum2=(f2*(f2+1))/2 ; int res=sum2-sum1 ; if(res<=n){ count++; n-=res ; ind++; } else { int i=0 ; int term=((ind-1)*k)+1 ; while(n>0){ if(term<=n){ arr[i++]=term ; n-=term ; term++; } else { arr[i++]=n ; n=0 ; } } } } for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < k do ( arr[i+1] := 0 ; ; i := i + 1 ) ; while (n > 0) do ( var f1 : int ; f1 := (ind - 1) * k ; var f2 : int ; f2 := ind * k ; var sum1 : int ; sum1 := (f1 * (f1 + 1)) / 2 ; var sum2 : int ; sum2 := (f2 * (f2 + 1)) / 2 ; var res : int ; res := sum2 - sum1 ; if (res <= n) then ( count := count + 1 ; n := n-(res) ; ind := ind + 1 ) else ( var i : int ; i := 0 ; var term : int ; term := ((ind - 1) * k) + 1 ; while (n > 0) do ( if (term <= n) then ( arr[i+1] := term ; i := i + 1 ; n := n-(term) ; term := term + 1 ) else ( arr[i+1] := n ; i := i + 1 ; n := 0 ) ) ) ; ) ; var i : int ; i := 0 ; while i < k do ( arr[i+1] := arr[i+1]+((count * (i + 1)) + (k * (count * (count - 1)) / 2)) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; var k : int ; k := 3 ; execute candies(n, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { static final int max_val=257 ; static int PrimeCharacters(String s){ boolean prime[]=new boolean[max_val+1]; for(int i=0 ; i<=max_val ; i++)prime[i]=true ; prime[0]=false ; prime[1]=false ; for(int p=2 ; p*p<=max_val ; p++){ if(prime[p]==true){ for(int i=p*2 ; i<=max_val ; i+=p)prime[i]=false ; } } int count=0 ; for(int i=0 ; icollect(false) ; var i : int ; i := 0 ; while i <= max_val do ( prime[i+1] := true ; ; i := i + 1 ) ; prime[0+1] := false ; prime[1+1] := false ; var p : int ; p := 2 ; while p * p <= max_val do ( ( if (prime[p+1] = true) then ( var i : int ; i := p * 2 ; while i <= max_val do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (prime[(s->at(i+1))->oclAsType(int)+1]) then count := count + 1 ; else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : String ; S := "geeksforgeeks" ; OclFile["System.out"].print(PrimeCharacters(S)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class C_Replacement { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int len=sc.nextInt(); int nums[]=new int[len]; int temp[]=new int[len]; StringBuilder sb=new StringBuilder("1 "); for(int i=0 ; itoInteger() ; var nums : Sequence(int) ; nums := Integer.subrange(1,len)->collect(0) ; var temp : Sequence(int) ; temp := Integer.subrange(1,len)->collect(0) ; var sb : String ; sb := StringLib.newString("1 ") ; var i : int ; i := 0 ; while i < len do ( ( nums[i+1] := sc.getCurrent()->toInteger() ; temp[i+1] := nums[i+1] ) ; i := i + 1 ) ; if (len = 1 & nums[0+1] = 1) then ( OclFile["System.out"].println(2) ; return ) else skip ; temp := temp->sort() ; var i : int ; i := 1 ; while i < len do ( ( if (i = len - 1 & temp[(i)->char2byte() - 1+1] = 1 & temp[i+1] = 1) then sb := sb + StringLib.newString(2) ; else sb := sb + StringLib.newString(temp[(i)->char2byte() - 1+1] + " ") ; ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; if (arr[n - 1+1] = 1) then arr[n - 1+1] := 2 else arr[n - 1+1] := 1 ; ; arr := arr->sort() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(arr[i+1] + " ") ) ; i := i + 1 ) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int minimunMoves(String arr[],int n){ int ans=Integer.MAX_VALUE ; for(int i=0 ; iindexOf(arr[i+1])-1 ; if (index = arr[i+1]->size()) then return -1 else skip ; curr_count := curr_count+(index) ) ; j := j + 1 ) ; ans := Set{curr_count, ans}->min() ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"xzzwo","zwoxz","zzwox","xzzwo"} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(minimunMoves(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static double Area(int b1,int b2,int h){ return((b1+b2)/2)*h ; } public static void main(String[] args){ int base1=8,base2=10,height=6 ; double area=Area(base1,base2,height); System.out.println("Area is: "+area); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Area( b1 : int, b2 : int, h : int) : double pre: true post: true activity: ( return ((b1 + b2) / 2) * h ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var base1 : int ; base1 := 8 ; var base2 : int ; base2 := 10 ; var height : int ; height := 6 ; var area : double ; area := Area(base1, base2, height) ; OclFile["System.out"].println("Area is: " + area) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); try { String str=reader.readLine(); String s[]=str.split(" "); int w=Integer.parseInt(s[0]); int h=Integer.parseInt(s[1]); int c=Integer.parseInt(s[2]); int fee=0 ; int gc=gcd(w,h); int gw=w/gc ; int gh=h/gc ; fee=(gw*gh)*c ; System.out.println(fee); reader.close(); } catch(IOException e){ e.printStackTrace(); } } static int gcd(int a,int b){ return b>0 ? gcd(b,a % b): a ; } static int lcm(int a,int b){ return a*b/gcd(a,b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var str : String ; str := reader.readLine() ; var s : Sequence(String) ; s := str->split(" ") ; var w : int ; w := (s[0+1])->toInteger() ; var h : int ; h := (s[1+1])->toInteger() ; var c : int ; c := (s[2+1])->toInteger() ; var fee : int ; fee := 0 ; var gc : int ; gc := gcd(w, h) ; var gw : int ; gw := w / gc ; var gh : int ; gh := h / gc ; fee := (gw * gh) * c ; OclFile["System.out"].println(fee) ; skip ; ) catch (e : IOException) do ( e.printStackTrace() ) ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if b > 0 then gcd(b, a mod b) else a endif ); static operation lcm( a : int, b : int) : int pre: true post: true activity: ( return a * b / gcd(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void smallestPermute(int n){ char res[]=new char[n+1]; if(n % 2==0){ for(int i=0 ; icollect(0) ; if (n mod 2 = 0) then ( var i : int ; i := 0 ; while i < n do ( ( if (i mod 2 = 0) then res[i+1] := (48 + i + 2)->oclAsType(String) ; else res[i+1] := (48 + i)->oclAsType(String) ; ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < n - 2 do ( ( if (i mod 2 = 0) then res[i+1] := (48 + i + 2)->oclAsType(String) ; else res[i+1] := (48 + i)->oclAsType(String) ; ) ; i := i + 1 ) ; res[n - 1+1] := (48 + n - 2)->oclAsType(String) ; res[n - 2+1] := (48 + n)->oclAsType(String) ; res[n - 3+1] := (48 + n - 1)->oclAsType(String) ) ; res[n+1] := '\0' ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(res[i+1]) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 7 ; execute smallestPermute(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class OddOccurrence { static int getOddOccurrence(int arr[],int arr_size){ int i ; for(i=0 ; isize() ; OclFile["System.out"].println(getOddOccurrence(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { final static int n=4 ; final static int m=4 ; static float calcProbability(int M[][],int k){ float dp[][]=new float[m][n]; float sum[]=new float[n]; for(int j=0 ; jcollect(Integer.subrange(1,n)->collect(0.0)) ; var sum : Sequence(double) ; sum := Integer.subrange(1,n)->collect(0.0) ; var j : int ; j := 0 ; while j < n do ( ( dp[0+1][j+1] := M[0+1][j+1] ; sum[0+1] := sum[0+1] + dp[0+1][j+1] ) ; j := j + 1 ) ; var i : int ; i := 1 ; while i < m do ( ( var j : int ; j := 0 ; while j < n 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]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[n - 1+1][k - 1+1] / sum[n - 1+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var M : Sequence(Sequence(int)) ; M := Sequence{Sequence{1,1,0,3},Sequence{2,3,2,3},Sequence{9,3,0,2},Sequence{2,3,2,2}} ; var k : int ; k := 3 ; OclFile["System.out"].println(calcProbability(M, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[][] A=new int[n][m]; int[] b=new int[m]; int[] Ab=new int[n]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var A : Sequence(Sequence(int)) ; A := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var b : Sequence(int) ; b := Integer.subrange(1,m)->collect(0) ; var Ab : Sequence(int) ; Ab := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( A[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( Ab[i+1] := Ab[i+1]+(A[i+1][j+1] * b[j+1]) ) ; j := j + 1 ) ; OclFile["System.out"].println(Ab[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int n=0 ; int m=0 ; int[][] md ; int[] vd ; String x="" ; try { x=in.readLine(); String[] nm=x.split(" "); n=Integer.parseInt(nm[0]); m=Integer.parseInt(nm[1]); md=new int[n][m]; vd=new int[m]; for(int i=0 ; isplit(" ") ; n := (nm[0+1])->toInteger() ; m := (nm[1+1])->toInteger() ; md := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; vd := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( x := in.readLine() ; var row : Sequence(String) ; row := x->split(" ") ; var j : int ; j := 0 ; while j < m do ( ( md[i+1][j+1] := (row[j+1])->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( x := in.readLine() ; vd[i+1] := (x)->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := 0 ; var j : int ; j := 0 ; while j < m do ( ( v := v + md[i+1][j+1] * vd[j+1] ) ; j := j + 1 ) ; OclFile["System.out"].println(v) ) ; i := i + 1 ) ; ) catch (e : IncorrectElementException) do ( e.printStackTrace() ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int row=scan.nextInt(); int column=scan.nextInt(); int[][] matrix=new int[row][column]; int[] vector=new int[column]; int[] vectorAnswer=new int[row]; for(int rowI=0 ; rowItoInteger() ; var column : int ; column := scan.getCurrent()->toInteger() ; var matrix : Sequence(Sequence(int)) ; matrix := Integer.subrange(1,row)->collect(Integer.subrange(1,column)->collect(0)) ; var vector : Sequence(int) ; vector := Integer.subrange(1,column)->collect(0) ; var vectorAnswer : Sequence(int) ; vectorAnswer := Integer.subrange(1,row)->collect(0) ; var rowI : int ; rowI := 0 ; while rowI < row do ( ( var columnI : int ; columnI := 0 ; while columnI < column do ( ( matrix[rowI+1][columnI+1] := scan.getCurrent()->toInteger() ) ; columnI := columnI + 1 ) ) ; rowI := rowI + 1 ) ; var columnI : int ; columnI := 0 ; while columnI < column do ( ( vector[columnI+1] := scan.getCurrent()->toInteger() ) ; columnI := columnI + 1 ) ; var rowI : int ; rowI := 0 ; while rowI < row do ( ( var columnI : int ; columnI := 0 ; while columnI < column do ( ( vectorAnswer[rowI+1] := vectorAnswer[rowI+1]+(matrix[rowI+1][columnI+1] * vector[columnI+1]) ) ; columnI := columnI + 1 ) ) ; rowI := rowI + 1 ) ; var rowI : int ; rowI := 0 ; while rowI < row do ( ( OclFile["System.out"].println(vectorAnswer[rowI+1]) ) ; rowI := rowI + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] arg){ int rows,cols ; int[][] a,b,c ; Scanner in=new Scanner(System.in); rows=in.nextInt(); cols=in.nextInt(); a=new int[rows][cols]; b=new int[cols][1]; c=new int[rows][1]; in.nextLine(); for(int i=0 ; itoInteger() ; cols := in.getCurrent()->toInteger() ; a := Integer.subrange(1,rows)->collect(Integer.subrange(1,cols)->collect(0)) ; b := Integer.subrange(1,cols)->collect(Integer.subrange(1,1)->collect(0)) ; c := Integer.subrange(1,rows)->collect(Integer.subrange(1,1)->collect(0)) ; skip ; var i : int ; i := 0 ; while i < a->size() do ( ( var j : int ; j := 0 ; while j < a[0+1]->size() do ( ( a[i+1][j+1] := in.getCurrent()->toInteger() ) ; j := j + 1 ) ; skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < b->size() do ( ( b[i+1][0+1] := in.getCurrent()->toInteger() ; skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < a->size() do ( ( var tmp : int ; tmp := 0 ; var j : int ; j := 0 ; while j < a[0+1]->size() do ( tmp := tmp+(a[i+1][j+1] * b[j+1][0+1]) ; ; j := j + 1 ) ; c[i+1][0+1] := tmp ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < c->size() do ( ( OclFile["System.out"].println(c[i+1][0+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Main { public static void main(String[] args)throws NumberFormatException,IOException { int n,m ; String[] str ; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); str=br.readLine().split(" "); n=Integer.parseInt(str[0]); m=Integer.parseInt(str[1]); int[][] arr=new int[n][m]; int[] vec=new int[m]; int[] ans=new int[n]; for(int i=0 ; isplit(" ") ; n := (str[0+1])->toInteger() ; m := (str[1+1])->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var vec : Sequence(int) ; vec := Integer.subrange(1,m)->collect(0) ; var ans : Sequence(int) ; ans := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var str2 : Sequence(String) ; str2 := br.readLine()->split(" ") ; var j : int ; j := 0 ; while j < m do ( ( arr[i+1][j+1] := (str2[j+1])->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( vec[i+1] := (br.readLine())->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( ans[i+1] := ans[i+1]+(arr[i+1][j+1] * vec[j+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; for (num : ans) do ( ( OclFile["System.out"].println(num) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class MinSum { static long findMinSum(long a[],long b[],long n){ Arrays.sort(a); Arrays.sort(b); long sum=0 ; for(int i=0 ; isort() ; b := b->sort() ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( sum := sum + if a[i+1] - b[i+1] < 0 then -(a[i+1] - b[i+1]) else a[i+1] - b[i+1] endif ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(long) ; a := Sequence{4,1,8,7} ; var b : Sequence(long) ; b := Sequence{2,3,6,5} ; var n : int ; n := a->size() ; OclFile["System.out"].println(findMinSum(a, b, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.List ; import java.util.ArrayList ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int Q=scan.nextInt(); Listans=new ArrayList<>(); while(Q-->0){ long A=scan.nextLong(); long B=scan.nextLong(); long r=(long)(Math.sqrt((double)A*B)); if(r*r==A*B && A!=B)--r ; if(r*(r+1)toInteger() ; var ans : Sequence(long) ; ans := Sequence{} ; while (Q > 0) do ( Q := Q - 1 ; skip ; ( var A : long ; A := scan.getCurrent()->toLong() ; var B : long ; B := scan.getCurrent()->toLong() ; var r : long ; r := ((A->oclAsType(double) * B)->sqrt())->oclAsType(long) ; if (r * r = A * B & A /= B) then r := r - 1 ; else skip ; if (r * (r + 1) < A * B) then ( ans := ans->including(2 * r - 1) ) else ( ans := ans->including(2 * (r - 1)) ) ; ) ; ) ; for (i : ans) do ( OclFile["System.out"].println(i) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskD solver=new TaskD(); solver.solve(1,in,out); out.close(); } static class TaskD { public void solve(int testNumber,InputReader in,PrintWriter out){ int N=in.nextInt(); for(int i=0 ; imin() ; var b : long ; b := Set{A, B}->max() ; var ans : long ; if (a = b or a + 1 = b) then ( ans := 2 * (a - 1) ) else ( var c : long ; c := (a * b)->sqrt()->oclAsType(long) ; if (c * c = a * b) then c := c - 1 ; else skip ; if (c * (c + 1) < a * b) then ( ans := 2 * c - 1 ) else ( ans := 2 * c - 2 ) ) ; skip ; ) ; i := i + 1 ) ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class geeks { public static int minOperations(int[] a,int n,int K){ HashMapmap=new HashMap<>(); for(int i=0 ; iat(a[i+1])) then return 1 else skip ) catch (e : ProgramException) do skip try ( map := map->union(Map{a[i+1] |-> true}) ) catch (e : ProgramException) do skip ) ; i := i + 1 ) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := a[i+1] & K ; ; i := i + 1 ) ; map := map->intersection(Map{}) ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] /= b[i+1]) then ( try ( map := map->union(Map{b[i+1] |-> true}) ) catch (e : ProgramException) do skip ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( try ( if (map->at(a[i+1])) then return 1 else skip ) catch (e : ProgramException) do skip ) ; i := i + 1 ) ; map := map->intersection(Map{}) ; var i : int ; i := 0 ; while i < n do ( ( try ( if (map->at(b[i+1])) then return 2 else skip ) catch (e : ProgramException) do skip try ( map := map->union(Map{b[i+1] |-> true}) ) catch (e : ProgramException) do skip ) ; i := i + 1 ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var K : int ; K := 3 ; var a : Sequence(int) ; a := Sequence{1,2,3,7} ; var n : int ; n := a->size() ; OclFile["System.out"].println(minOperations(a, n, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int W,H,C ; StringTokenizer st=new StringTokenizer(br.readLine()); W=parseInt(st.nextToken()); H=parseInt(st.nextToken()); C=parseInt(st.nextToken()); int gcd=gcd(W,H); System.out.println(W*H/gcd/gcd*C); } static int gcd(int a,int b){ if(b==0)return a ; return gcd(b,a % b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var W : int ; var H : int ; var C : int ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; W := (st.next() + "")->toInteger() ; H := (st.next() + "")->toInteger() ; C := (st.next() + "")->toInteger() ; var gcd : int ; gcd := gcd(W, H) ; OclFile["System.out"].println(W * H / gcd / gcd * C) ; ); static 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) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int q=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < q do ( ( var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var rt : long ; rt := ((a * b)->sqrt())->floor()->oclAsType(long) ; var ans : long ; ans := 0 ; if (rt * (rt + 1) < a * b) then ( ans := 2 * rt - 1 ) else if (rt * rt < a * b) then ( ans := 2 * rt - 2 ) else ( ans := 2 * rt - 3 ; if (rt = a & rt = b) then ( ans := ans + 1 ) else skip ) ; ; OclFile["System.out"].println(ans) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Comparator ; import java.util.PriorityQueue ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int q=Integer.parseInt(br.readLine()); for(int i=0 ; ib){ int tmp=a ; a=b ; b=tmp ; } long result=0 ; if(a==b){ result=2*a-2 ; } else if(a+1==b){ result=2*a-2 ; } else { long c=(long)Math.sqrt((long)a*b); if(c*c==(long)a*b){ c--; } if(c*(c+1)>=(long)a*b){ result=2*c-2 ; } else { result=2*c-1 ; } } System.out.println(result); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var q : int ; q := (br.readLine())->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var tmpArray : Sequence(String) ; tmpArray := br.readLine()->split(" ") ; var a : int ; a := (tmpArray[0+1])->toInteger() ; var b : int ; b := (tmpArray[1+1])->toInteger() ; if (a > b) then ( var tmp : int ; tmp := a ; a := b ; b := tmp ) else skip ; var result : long ; result := 0 ; if (a = b) then ( result := 2 * a - 2 ) else if (a + 1 = b) then ( result := 2 * a - 2 ) else ( var c : long ; c := (a->oclAsType(long) * b)->sqrt()->oclAsType(long) ; if (c * c = a->oclAsType(long) * b) then ( c := c - 1 ) else skip ; if (c * (c + 1) >= a->oclAsType(long) * b) then ( result := 2 * c - 2 ) else ( result := 2 * c - 1 ) ) ; ; OclFile["System.out"].println(result) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int q=scanner.nextInt(); for(int i=0 ; ib)return solve(b,a); if(a==b)return 2*a-2 ; if(a+1==b)return 2*a-2 ; long ab=Math.multiplyExact(a,b); long c=findUpperRoot(ab); long cc1=Math.multiplyExact(c,c+1); if(cc1>=ab)return 2*c-2 ; return 2*c-1 ; } private static long findUpperRoot(long n){ long ll=0 ; long ul=(long)Math.sqrt(n)+1 ; while(Math.addExact(ll,1)toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var a : long ; a := scanner.getCurrent()->toLong() ; var b : long ; b := scanner.getCurrent()->toLong() ; OclFile["System.out"].println(solve(a, b)) ) ; i := i + 1 ) ); static operation solve( a : long, b : long) : long pre: true post: true activity: ( if (a > b) then return solve(b, a) else skip ; if (a = b) then return 2 * a - 2 else skip ; if (a + 1 = b) then return 2 * a - 2 else skip ; var ab : long ; ab := multiplyExact(a, b) ; var c : long ; c := findUpperRoot(ab) ; var cc1 : long ; cc1 := multiplyExact(c, c + 1) ; if (cc1 >= ab) then return 2 * c - 2 else skip ; return 2 * c - 1 ); static operation findUpperRoot( n : long) : long pre: true post: true activity: ( var ll : long ; ll := 0 ; var ul : long ; ul := (n)->sqrt()->oclAsType(long) + 1 ; while (addExact(ll, 1) < ul) do ( var mid : long ; mid := addExact(ll, ul) / 2 ; if (multiplyExact(mid, mid) < n) then ( ll := mid ) else ( ul := mid ) ) ; return ll ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printSeriesSum(int N){ double sum=0 ; for(int i=1 ; i<=N ; i++){ if(i % 2==1){ sum+=(double)i/(i+1); } else { sum-=(double)i/(i+1); } } System.out.print(sum+"\n"); } public static void main(String[] args){ int N=10 ; printSeriesSum(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printSeriesSum( N : int) : void pre: true post: true activity: ( var sum : double ; sum := 0 ; var i : int ; i := 1 ; while i <= N do ( ( if (i mod 2 = 1) then ( sum := sum+(i->oclAsType(double) / (i + 1)) ) else ( sum := sum-(i->oclAsType(double) / (i + 1)) ) ) ; i := i + 1 ) ; OclFile["System.out"].print(sum + "\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 10 ; execute printSeriesSum(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printSeriesSum(int N){ long sum=0 ; for(int i=1 ; i<=N ; i++){ sum+=Math.pow(i,i-1); } System.out.print(sum+"\n"); } public static void main(String[] args){ int N=5 ; printSeriesSum(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printSeriesSum( N : int) : void pre: true post: true activity: ( var sum : long ; sum := 0 ; var i : int ; i := 1 ; while i <= N do ( ( sum := sum+(i->pow(i - 1)) ) ; i := i + 1 ) ; OclFile["System.out"].print(sum + "\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 5 ; execute printSeriesSum(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; public final class p053 implements EulerSolution { public static void main(String[] args){ System.out.println(new p053().run()); } public String run(){ BigInteger MILLION=BigInteger.TEN.pow(6); int count=0 ; for(int n=1 ; n<=100 ; n++){ for(int r=0 ; r<=n ; r++){ if(Library.binomial(n,r).compareTo(MILLION)>0)count++; } } return Integer.toString(count); } } ------------------------------------------------------------ OCL File: --------- class p053 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p053.newp053().run()) ); operation run() : String pre: true post: true activity: ( var MILLION : long ; MILLION := 10.pow(6) ; var count : int ; count := 0 ; var n : int ; n := 1 ; while n <= 100 do ( ( var r : int ; r := 0 ; while r <= n do ( ( if (Library.binomial(n, r)->compareTo(MILLION) > 0) then count := count + 1 ; else skip ) ; r := r + 1 ) ) ; n := n + 1 ) ; return ((count) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { static int arr[]=new int[] { 3,7,90,20,10,50,40 }; static void findMinAvgSubarray(int n,int k){ if(nsize(), k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class EqualGames { public static int minStep(int a,int b){ if(a==b){ return 0 ; } int x=1 ; int last=(x*(x+1)/2); int sum=a+b+last ; while((sum & 1)!=0 ||(sum/2toInteger() ; var i : int ; i := 0 ; while i < num do ( ( var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(minStep(a, b)) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; public class T2022081104_1 { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Listsout=new ArrayList<>(); try { int t=Integer.parseInt(br.readLine()); if(t<1 || t>100){ return ; } for(int i=0 ; i1000000000 || b<1 || b>1000000000){ return ; } else { sout.add(printNumber(a,b)+""); } } } catch(IOException ioException){ return ; } finally { for(String i : sout){ System.out.println(i); } } } private static int printNumber(int a,int b){ int tmp=1 ; if(a==b){ return 0 ; } if(a=(a-b)&&(sum+a+b)% 2==0){ break ; } tmp=tmp+1 ; } return tmp ; } } ------------------------------------------------------------ OCL File: --------- class T2022081104_1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sout : Sequence(String) ; sout := Sequence{} ; try ( var t : int ; t := (br.readLine())->toInteger() ; if (t < 1 or t > 100) then ( return ) else skip ; var i : int ; i := 0 ; while i < t do ( ( var tmp1 : Sequence(String) ; tmp1 := br.readLine()->split(" ") ; var a : int ; a := (tmp1[0+1])->toInteger() ; var b : int ; b := (tmp1[1+1])->toInteger() ; if (a < 1 or a > 1000000000 or b < 1 or b > 1000000000) then ( return ) else ( sout := sout->including(printNumber(a, b) + "") ) ) ; i := i + 1 ) ) catch (ioException : IOException) do ( return ) finally ( for (i : sout) do ( ( OclFile["System.out"].println(i) ) ) ) ); static operation printNumber( a : int, b : int) : int pre: true post: true activity: ( var tmp : int ; tmp := 1 ; if (a = b) then ( return 0 ) else skip ; if (a < b) then ( var c : int ; c := a ; a := b ; b := c ) else skip ; while (true) do ( var sum : long ; sum := tmp * (tmp + 1) / 2 ; if (sum >= (a - b) & (sum + a + b) mod 2 = 0) then ( break ) else skip ; tmp := tmp + 1 ) ; return tmp ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { int h,w ; char[][] grid ; Boolean B,W ; int countB,countW ; int[] dx={ 1,-1,0,0 }; int[] dy={ 0,0,1,-1 }; char from,to ; int countGrid ; void solve(){ Scanner sc=new Scanner(System.in); w=sc.nextInt(); while(w!=0){ h=sc.nextInt(); grid=new char[h][w]; for(int i=0 ; i=0 && ny=0){ if(grid[ny][nx]=='B')B=true ; else if(grid[ny][nx]=='W')W=true ; else if(grid[ny][nx]=='.'){ dfs(nx,ny); } } } } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute h : int; attribute grid : Sequence(Sequence(String)); attribute B : Boolean; attribute countB : int; attribute dx : Sequence(int) := Sequence{1,-1,0,0}; attribute dy : Sequence(int) := Sequence{0,0,1,-1}; attribute from : String; attribute countGrid : int; operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; w := sc.getCurrent()->toInteger() ; while (w /= 0) do ( h := sc.getCurrent()->toInteger() ; grid := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( var line : String ; line := sc.getCurrent() ; grid[i+1] := line->characters() ) ; i := i + 1 ) ; countB := 0 ; countW := 0 ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( if (grid[i+1][j+1] = '.') then ( B := false ; W := false ; countGrid := 0 ; execute dfs(j, i) ; if (B & not(W)) then countB := countB+(countGrid) ; else skip ; if (not(B) & W) then countW := countW+(countGrid) ; else skip ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(countB + " " + countW) ; w := sc.getCurrent()->toInteger() ; ) ); operation dfs( x : int, y : int) : void pre: true post: true activity: ( grid[y+1][x+1] := 'x' ; countGrid := countGrid + 1 ; var i : int ; i := 0 ; while i < 4 do ( ( var nx : int ; nx := x + dx[i+1] ; var ny : int ; ny := y + dy[i+1] ; if (nx < w & nx >= 0 & ny < h & ny >= 0) then ( if (grid[ny+1][nx+1] = 'B') then B := true ; else if (grid[ny+1][nx+1] = 'W') then W := true else if (grid[ny+1][nx+1] = '.') then ( execute dfs(nx, ny) ) else skip ; ; ) else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ProblemD { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); int[] result=new int[t]; for(int i=0 ; i=Math.max(a,b)){ result[i]=x ; break ; } x++; } } for(int i=0 ; itoInteger() ; var result : Sequence(int) ; result := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var x : int ; x := 0 ; while (true) do ( var sum : int ; sum := a + b + x * (x + 1) / 2 ; if (sum mod 2 = 0 & sum / 2 >= Set{a, b}->max()) then ( result[i+1] := x ; break ) else skip ; x := x + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t do ( ( OclFile["System.out"].println(result[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static int gcd(int x,int y){ if(y==0){ return x ; } else { return gcd(y,x % y); } } public static void main(String args[]){ Scanner sc=new Scanner(System.in); int W=sc.nextInt(); int H=sc.nextInt(); int WH=gcd(W,H); int C=sc.nextInt(); int a=(W/WH)*(H/WH); System.out.println(a*C); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation gcd( x : int, y : int) : int pre: true post: true activity: ( if (y = 0) then ( return x ) else ( return gcd(y, x mod y) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var W : int ; W := sc.getCurrent()->toInteger() ; var H : int ; H := sc.getCurrent()->toInteger() ; var WH : int ; WH := gcd(W, H) ; var C : int ; C := sc.getCurrent()->toInteger() ; var a : int ; a := (W / WH) * (H / WH) ; OclFile["System.out"].println(a * C) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); for(int i=0 ; i=a && temp/4>=b){ break ; } if((n % 4)% 2==0){ n+=3 ; } else { n++; } } System.out.println(n); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var a : long ; a := scanner.getCurrent()->toInteger() ; var b : long ; b := scanner.getCurrent()->toInteger() ; if (a = b) then ( OclFile["System.out"].println(0) ; continue ) else skip ; var n : long ; n := (2 * if a - b < 0 then -(a - b) else a - b endif)->sqrt()->oclAsType(long) ; if ((a + b) mod 2 = 0) then ( if (n mod 4 = 1 or n mod 4 = 2) then ( n := n+(3 - n mod 4) ) else skip ) else ( if (n mod 4 = 3 or n mod 4 = 0) then ( n := n+(if n mod 4 - 1 < 0 then -(n mod 4 - 1) else n mod 4 - 1 endif) ) else skip ) ; while (true) do ( var temp : long ; temp := n * n + n + 2 * a + 2 * b ; if (temp / 4 >= a & temp / 4 >= b) then ( break ) else skip ; if ((n mod 4) mod 2 = 0) then ( n := n+(3) ) else ( n := n + 1 ) ) ; OclFile["System.out"].println(n) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Security0812D { public static void main(String[] args){ Scanner reader=new Scanner(System.in); int count=0 ; int total=reader.nextInt(); while(reader.hasNextInt()){ int a=reader.nextInt(); int b=reader.nextInt(); System.out.println(process(a,b)); if(++count==total){ break ; } } } private static int process(int a,int b){ int n=Math.abs(a-b); int m=(int)Math.sqrt(n*2); while(m*(m+1)/2toInteger() ; while (reader.hasNextInt()) do ( var a : int ; a := reader.getCurrent()->toInteger() ; var b : int ; b := reader.getCurrent()->toInteger() ; OclFile["System.out"].println(process(a, b)) ; if ((count + 1) = total) then ( break ) else skip ) ); static operation process( a : int, b : int) : int pre: true post: true activity: ( var n : int ; n := if a - b < 0 then -(a - b) else a - b endif ; var m : int ; m := (n * 2)->sqrt()->oclAsType(int) ; while (m * (m + 1) / 2 < n or (m * (m + 1) / 2 - n) mod 2 /= 0) do ( m := m + 1 ) ; return m ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Googlerese { public static void main(String[] args)throws Exception { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String dict="yhesocvxduiglbkrztnwjpfmaq" ; int T=Integer.parseInt(in.readLine()); for(int i=0 ; i122){ ans+=s.charAt(j); } else { ans+=dict.charAt(s.charAt(j)-97); } } System.out.println("Case #"+(i+1)+": "+ans); } } } ------------------------------------------------------------ OCL File: --------- class Googlerese { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var dict : String ; dict := "yhesocvxduiglbkrztnwjpfmaq" ; var T : int ; T := (in.readLine())->toInteger() ; var i : int ; i := 0 ; while i < T do ( ( var s : String ; s := in.readLine() ; var ans : String ; ans := "" ; var j : int ; j := 0 ; while j < s->size() do ( ( if (s->at(j+1) < 97 or s->at(j+1) > 122) then ( ans := ans+(s->at(j+1)) ) else ( ans := ans+(dict->at(s->at(j+1) - 97+1)) ) ) ; j := j + 1 ) ; OclFile["System.out"].println("Case #" + (i + 1) + ": " + ans) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package j2012qualifier ; import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class A { public static String inputDirectory="src/j2012qualifier/" ; public static String inputFile="A.in" ; public static String outputFile="A.out" ; public static PrintWriter output ; public static void main(String[] args)throws FileNotFoundException { Scanner s=new Scanner(new File(inputDirectory+inputFile)); output=new PrintWriter(new File(inputDirectory+outputFile)); MapcodeMap=new HashMap(); String source="qzejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv" ; String result="zqour language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up" ; for(int i=0 ; isize() do ( ( codeMap := codeMap->union(Map{source->at(i+1) |-> result->at(i+1)}) ) ; i := i + 1 ) ; var cases : int ; cases := s.getCurrent()->toInteger() ; skip ; var Case : int ; Case := 1 ; while Case <= cases do ( ( var code : String ; code := s.nextLine() ; var uncoded : Sequence(String) ; uncoded := Integer.subrange(1,code->size())->collect(0) ; var i : int ; i := 0 ; while i < uncoded->size() do ( ( uncoded[i+1] := codeMap->at(code->at(i+1)) ) ; i := i + 1 ) ; var answer : String ; answer := (uncoded)->sum() ; execute out("Case #" + Case + ": " + answer) ; ) ; Case := Case + 1 ) ; skip ; ); static operation out( s : String) : void pre: true post: true activity: ( skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package google.codejam2012.qualification ; import java.io.BufferedReader ; import java.io.InputStreamReader ; public class SpeakingInTongues { private static String TRANSLATER="yhesocvxduiglbkrztnwjpfmaq" ; private static char translate(char ch){ if('a'<=ch & ch<='z')return TRANSLATER.charAt(ch-'a'); else return ch ; } private static String translate(String s){ int l=s.length(); StringBuilder translated=new StringBuilder(l); for(int i=0 ; iat(ch - ('a')->char2byte()+1) else return ch ); static operation translate( s : String) : String pre: true post: true activity: ( var l : int ; l := s->size() ; var translated : String ; translated := StringLib.newString(l) ; var i : int ; i := 0 ; while i < l do ( ( translated := translated + StringLib.newString(translate(s->at(i+1))) ) ; i := i + 1 ) ; return translated+"" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), (64*(2->pow(10)))->oclAsType(long)) ; var testsNumber : int ; testsNumber := (br.readLine()->trim())->toInteger() ; var test : int ; test := 1 ; while test <= testsNumber do ( ( OclFile["System.out"].println("Case #" + test + ":" + translate(br.readLine())) ) ; test := test + 1 ) ) catch (e : ProgramException) do ( OclFile["System.err"].println("Error:" + e.getMessage()) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.PrintStream ; import java.io.OutputStream ; import java.io.IOException ; import java.io.FileOutputStream ; import java.util.Arrays ; import java.io.PrintWriter ; import java.io.FileInputStream ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream ; try { inputStream=new FileInputStream("gcj1.in"); } catch(IOException e){ throw new RuntimeException(e); } OutputStream outputStream ; try { outputStream=new FileOutputStream("gcj1.out"); } catch(IOException e){ throw new RuntimeException(e); } Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); GCJ1 solver=new GCJ1(); solver.solve(1,in,out); out.close(); } } class GCJ1 { public void solve(int testNumber,Scanner in,PrintWriter out){ char[] map={ 'y','h','e','s','o','c','v','x','d','u','i','g','l','b','k','r','z','t','n','w','j','p','f','m','a','q' }; int cases=in.nextInt(); in.nextLine(); for(int i=0 ; itoInteger() ; skip ; var i : int ; i := 0 ; while i < cases do ( ( var input : String ; input := in.nextLine() ; var output : Sequence(String) ; output := Integer.subrange(1,input->size())->collect(0) ; var j : int ; j := 0 ; while j < output->size() do ( ( if (input->at(j+1) = ' ') then output[j+1] := ' ' ; else output[j+1] := map[input->at(j+1) - ('a')->char2byte()+1] ; ) ; j := j + 1 ) ; skip ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf108A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String time=scan.next(); int HH=Integer.parseInt(time.substring(0,2)); int MM=Integer.parseInt(time.substring(3)); while(true){ MM++; if(MM==60){ MM=0 ; HH++; if(HH==24){ System.out.println("00:00"); break ; } } StringBuilder hime=new StringBuilder(); if(HH<10){ hime.append(0); } hime.append(HH); hime.append(':'); if(MM<10){ hime.append(0); } hime.append(MM); if(isPal(hime)){ System.out.println(hime); break ; } } } public static boolean isPal(StringBuilder time){ StringBuilder rev=new StringBuilder(time); rev.reverse(); if(rev.toString().equals(time.toString())){ return true ; } else { return false ; } } } ------------------------------------------------------------ OCL File: --------- class cf108A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var time : String ; time := scan.getCurrent() ; var HH : int ; HH := (time.subrange(0+1,2))->toInteger() ; var MM : int ; MM := (time.subrange(3+1,3))->toInteger() ; while (true) do ( MM := MM + 1 ; if (MM = 60) then ( MM := 0 ; HH := HH + 1 ; if (HH = 24) then ( OclFile["System.out"].println("00:00") ; break ) else skip ) else skip ; var hime : String ; hime := StringLib.newString() ; if (HH < 10) then ( hime := hime + StringLib.newString(0) ) else skip ; hime := hime + StringLib.newString(HH) ; hime := hime + StringLib.newString(':') ; if (MM < 10) then ( hime := hime + StringLib.newString(0) ) else skip ; hime := hime + StringLib.newString(MM) ; if (isPal(hime)) then ( OclFile["System.out"].println(hime) ; break ) else skip ; ) ; ); static operation isPal( time : String) : boolean pre: true post: true activity: ( var rev : String ; rev := StringLib.newString(time) ; rev := rev->reverse() ; if (rev+"" = time+"") then ( return true ) else ( return false ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int h ; static int w ; static int cnt=0 ; static char[][] g ; static boolean[][] v ; static boolean wbool ; static boolean bbool ; static void dfs(int i,int j){ if(v[i][j])return ; if(g[i][j]=='W'){ wbool=true ; return ; } if(g[i][j]=='B'){ bbool=true ; return ; } if(g[i][j]!='.')return ; v[i][j]=true ; cnt++; if(i>0)dfs(i-1,j); if(i0)dfs(i,j-1); if(j 0) then execute dfs(i - 1, j) ; else skip ; if (i < h - 1) then execute dfs(i + 1, j) ; else skip ; if (j > 0) then execute dfs(i, j - 1) ; else skip ; if (j < w - 1) then execute dfs(i, j + 1) ; else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( w := sc.getCurrent()->toInteger() ; h := sc.getCurrent()->toInteger() ; if (w + h = 0) then break else skip ; g := Integer.subrange(1,h + 1)->collect(Integer.subrange(1,w + 1)->collect(0)) ; v := Integer.subrange(1,h + 1)->collect(Integer.subrange(1,w + 1)->collect(false)) ; var i : int ; i := 0 ; while i < h do ( ( g[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var hcnt : int ; hcnt := 0 ; var bcnt : int ; bcnt := 0 ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( if (g[i+1][j+1] = '.' & v[i+1][j+1] = false) then ( wbool := false ; bbool := false ; cnt := 0 ; execute dfs(i, j) ; if (wbool & not(bbool)) then ( hcnt := hcnt+(cnt) ) else skip ; if (bbool & not(wbool)) then ( bcnt := bcnt+(cnt) ) else skip ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(bcnt + " " + hcnt) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf108A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String in=scan.next(); int HH=Integer.parseInt(in.substring(0,2)); int MM=Integer.parseInt(in.substring(3)); while(true){ MM++; if(MM==60){ MM=0 ; HH++; if(HH==24){ System.out.println("00:00"); break ; } } StringBuilder time=new StringBuilder(); if(HH<10){ time.append(0); } time.append(HH); time.append(":"); if(MM<10){ time.append(0); } time.append(MM); if(ispal(time)){ System.out.println(time); break ; } } } public static boolean ispal(StringBuilder time){ StringBuilder rev=new StringBuilder(time); rev.reverse(); if(rev.toString().equals(time.toString())){ return true ; } else { return false ; } } } ------------------------------------------------------------ OCL File: --------- class cf108A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var in : String ; in := scan.getCurrent() ; var HH : int ; HH := (in.subrange(0+1,2))->toInteger() ; var MM : int ; MM := (in.subrange(3+1,3))->toInteger() ; while (true) do ( MM := MM + 1 ; if (MM = 60) then ( MM := 0 ; HH := HH + 1 ; if (HH = 24) then ( OclFile["System.out"].println("00:00") ; break ) else skip ) else skip ; var time : String ; time := StringLib.newString() ; if (HH < 10) then ( time := time + StringLib.newString(0) ) else skip ; time := time + StringLib.newString(HH) ; time := time + StringLib.newString(":") ; if (MM < 10) then ( time := time + StringLib.newString(0) ) else skip ; time := time + StringLib.newString(MM) ; if (ispal(time)) then ( OclFile["System.out"].println(time) ; break ) else skip ; ) ; ); static operation ispal( time : String) : boolean pre: true post: true activity: ( var rev : String ; rev := StringLib.newString(time) ; rev := rev->reverse() ; if (rev+"" = time+"") then ( return true ) else ( return false ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf108A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String in=scan.next(); int HH=Integer.parseInt(in.substring(0,2)); int MM=Integer.parseInt(in.substring(3)); while(true){ MM++; if(MM==60){ MM=0 ; HH++; if(HH==24){ System.out.println("00:00"); break ; } } StringBuilder time=new StringBuilder(); if(HH<10){ time.append(0); } time.append(HH); time.append(':'); if(MM<10){ time.append(0); } time.append(MM); if(isPal(time)){ System.out.println(time); break ; } } } public static boolean isPal(StringBuilder time){ StringBuilder rev=new StringBuilder(time); rev.reverse(); return rev.toString().equals(time.toString()); } } ------------------------------------------------------------ OCL File: --------- class cf108A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var in : String ; in := scan.getCurrent() ; var HH : int ; HH := (in.subrange(0+1,2))->toInteger() ; var MM : int ; MM := (in.subrange(3+1,3))->toInteger() ; while (true) do ( MM := MM + 1 ; if (MM = 60) then ( MM := 0 ; HH := HH + 1 ; if (HH = 24) then ( OclFile["System.out"].println("00:00") ; break ) else skip ) else skip ; var time : String ; time := StringLib.newString() ; if (HH < 10) then ( time := time + StringLib.newString(0) ) else skip ; time := time + StringLib.newString(HH) ; time := time + StringLib.newString(':') ; if (MM < 10) then ( time := time + StringLib.newString(0) ) else skip ; time := time + StringLib.newString(MM) ; if (isPal(time)) then ( OclFile["System.out"].println(time) ; break ) else skip ; ) ; ); static operation isPal( time : String) : boolean pre: true post: true activity: ( var rev : String ; rev := StringLib.newString(time) ; rev := rev->reverse() ; return rev+"" = time+"" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNextInt()){ BigInteger w=sc.nextBigInteger(); BigInteger h=sc.nextBigInteger(); BigInteger c=sc.nextBigInteger(); BigInteger gcd=w.gcd(h); System.out.println(w.divide(gcd).multiply(h.divide(gcd)).multiply(c)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNextInt()) do ( var w : long ; w := sc.nextBigInteger() ; var h : long ; h := sc.nextBigInteger() ; var c : long ; c := sc.nextBigInteger() ; var gcd : long ; gcd := w.gcd(h) ; OclFile["System.out"].println(w.divide(gcd).multiply(h.divide(gcd)).multiply(c)) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); String s1=s.substring(0,2); String s2=s.substring(3); int hh=Integer.parseInt(s1); int mm=Integer.parseInt(s2); do { ++mm ; if(mm==60){ mm=0 ; ++hh ; } if(hh==24)hh=0 ; } while(hh % 10*10+hh/10!=mm); if(hh/10==0 && mm/10==0)System.out.println("0"+hh+":0"+mm); else if(hh/10==0)System.out.println("0"+hh+":"+mm); else if(mm/10==0)System.out.println(hh+":0"+mm); else System.out.println(hh+":"+mm); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.nextLine() ; var s1 : String ; s1 := s.subrange(0+1,2) ; var s2 : String ; s2 := s.subrange(3+1,3) ; var hh : int ; hh := (s1)->toInteger() ; var mm : int ; mm := (s2)->toInteger() ; while true do (( mm := mm + 1 ; if (mm = 60) then ( mm := 0 ; hh := hh + 1 ) else skip ; if (hh = 24) then hh := 0 ; else skip ) ; if (hh mod 10 * 10 + hh / 10 /= mm) then skip else break) ; if (hh / 10 = 0 & mm / 10 = 0) then OclFile["System.out"].println("0" + hh + ":0" + mm) else if (hh / 10 = 0) then OclFile["System.out"].println("0" + hh + ":" + mm) else if (mm / 10 = 0) then OclFile["System.out"].println(hh + ":0" + mm) else OclFile["System.out"].println(hh + ":" + mm) ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findTheNumber(int n){ if(n==1){ System.out.print("Impossible"+"\n"); return ; } for(int i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MainClass { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); if(n<10){ System.out.println(n); continue ; } String s=String.valueOf(n); char[] charArray=new char[s.length()]; Arrays.fill(charArray,s.charAt(0)); String str=new String(charArray); int k=Integer.valueOf(str); int tmp=(int)s.charAt(0)-'0' ; if(ntoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n < 10) then ( OclFile["System.out"].println(n) ; continue ) else skip ; var s : String ; s := ((n) + "") ; var charArray : Sequence(String) ; charArray := Integer.subrange(1,s->size())->collect(0) ; charArray := charArray->collect(s->at(0+1)) ; var str : String ; str := StringLib.newString(charArray) ; var k : int ; k := (str)->toInteger() ; var tmp : int ; tmp := s->at(0+1)->oclAsType(int) - ('0')->char2byte() ; if (n < k) then ( OclFile["System.out"].println((s->size() - 1) * 9 + tmp - 1) ) else ( OclFile["System.out"].println((s->size() - 1) * 9 + tmp) ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A_Happy_Birthday_Polycarp { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tctoInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(solve(n)) ) ; tc := tc + 1 ) ; skip ); static operation solve( n : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; var digit : int ; digit := 1 ; while digit <= 9 do ( ( var beautiful : long ; beautiful := digit ; while (beautiful <= n) do ( result := result + 1 ; beautiful := beautiful * 10 + digit ) ) ; digit := digit + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class HappyBirthdayPolycarp { public static void main(String[] args)throws IOException { Reader in=new Reader(); PrintWriter out=new PrintWriter(System.out); int T=in.nextInt(); for(int t=0 ; tlist=new ArrayList<>(); for(int i : arr){ list.add(i); } Collections.sort(list); for(int i=0 ; itoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var res : int ; res := 0 ; var i : int ; i := 1 ; while i <= 9 do ( ( var n : long ; n := 0 ; var j : int ; j := 1 ; while j <= 9 do ( ( n := n*(10) ; n := n+(i) ; if (n <= N) then ( res := res + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ) ; t := t + 1 ) ; skip ; ); static class Reader { attribute in : OclFile; attribute st : OclIterator; static operation newReader() : Reader pre: true post: true activity: ( var self : Reader ; self := createReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; st := OclIterator.newOclIterator_String("") ); operation nextLine() : String pre: true post: true activity: ( st := OclIterator.newOclIterator_String("") ; return in.readLine() ); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(in.readLine()) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static operation sort( arr : Sequence(int)) : void pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{} ; for (i : arr) do ( ( list := list->including(i) ) ) ; list := list->sort() ; var i : int ; i := 0 ; while i < arr->size() do ( ( arr[i+1] := list->at(i+1) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tctoInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(solve(n)) ) ; tc := tc + 1 ) ; skip ); static operation solve( n : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; var digit : int ; digit := 1 ; while digit <= 9 do ( ( var beautiful : long ; beautiful := digit ; while (beautiful <= n) do ( result := result + 1 ; beautiful := beautiful * 10 + digit ) ) ; digit := digit + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static int countSubstr(String s){ int n=s.length(); int[] auxArr=new int[n]; if(s.charAt(0)=='1')auxArr[0]=1 ; for(int i=1 ; i=0 ; i--)if(s.charAt(i)=='1')count+=auxArr[i]; return count ; } public static void main(String[] args){ String s="1101" ; System.out.println(countSubstr(s)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSubstr( s : String) : int pre: true post: true activity: ( var n : int ; n := s->size() ; var auxArr : Sequence(int) ; auxArr := Integer.subrange(1,n)->collect(0) ; if (s->at(0+1) = '1') then auxArr[0+1] := 1 ; else skip ; var i : int ; i := 1 ; while i < n do ( ( if (s->at(i+1) = '1') then auxArr[i+1] := auxArr[i - 1+1] + 1 ; else auxArr[i+1] := auxArr[i - 1+1] ; ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( if (s->at(i+1) = '1') then count := count+(auxArr[i+1]) ; else skip ; ; i := i - 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "1101" ; OclFile["System.out"].println(countSubstr(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); Book[] a=new Book[n]; for(int i=0 ; i{ private final int pos ; private final String name ; Book(int p,String bookname){ pos=p ; name=bookname ; } int getPos(){ return pos ; } public int compareTo(Book b){ for(int i=0 ; ib.name.charAt(i))return 1-(i % 2)*2 ; } return 0 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(Book) ; a := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( var name : String ; name := sc.getCurrent() ; a[i+1] := Book.newBook(i + 1, name) ) ; i := i + 1 ) ; a := a->sort() ; for (x : a) do ( ( OclFile["System.out"].print(x.getPos() + " ") ) ) ; OclFile["System.out"].println() ; ); } class Book implements Comparable { attribute pos : int; attribute name : String; static operation newBook( p : int, bookname : String) : Book pre: true post: true activity: ( var self : Book ; self := createBook(); self.initialise(p, bookname); return self ); operation initialise( p : int, bookname : String) : void pre: true post: true activity: ( pos := p ; name := bookname ); operation getPos() : int pre: true post: true activity: ( return pos ); operation compareTo( b : Book) : int pre: true post: true activity: ( var i : int ; i := 0 ; while i < name->size() do ( ( if (name->at(i+1) < b.name->at(i+1)) then return -1 + (i mod 2) * 2 else if (name->at(i+1) > b.name->at(i+1)) then return 1 - (i mod 2) * 2 else skip ; ) ; i := i + 1 ) ; return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int x1=in.nextInt(); int y1=in.nextInt(); int x2=in.nextInt(); int y2=in.nextInt(); int x=Math.abs(x2-x1); int y=Math.abs(y2-y1); int dis=Math.min(x,y); int finalDis=dis+Math.abs(x-y); System.out.printf("%d\n",finalDis); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x1 : int ; x1 := in.getCurrent()->toInteger() ; var y1 : int ; y1 := in.getCurrent()->toInteger() ; var x2 : int ; x2 := in.getCurrent()->toInteger() ; var y2 : int ; y2 := in.getCurrent()->toInteger() ; var x : int ; x := if x2 - x1 < 0 then -(x2 - x1) else x2 - x1 endif ; var y : int ; y := if y2 - y1 < 0 then -(y2 - y1) else y2 - y1 endif ; var dis : int ; dis := Set{x, y}->min() ; var finalDis : int ; finalDis := dis + if x - y < 0 then -(x - y) else x - y endif ; OclFile["System.out"].printf("%d\n", finalDis) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int x1=in.nextInt(),y1=in.nextInt(); int x2=in.nextInt(),y2=in.nextInt(); System.out.println(Math.max(Math.abs(x1-x2),Math.abs(y1-y2))); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x1 : int ; x1 := in.getCurrent()->toInteger() ; var y1 : int ; y1 := in.getCurrent()->toInteger() ; var x2 : int ; x2 := in.getCurrent()->toInteger() ; var y2 : int ; y2 := in.getCurrent()->toInteger() ; OclFile["System.out"].println(Set{if x1 - x2 < 0 then -(x1 - x2) else x1 - x2 endif, if y1 - y2 < 0 then -(y1 - y2) else y1 - y2 endif}->max()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.util.stream.*; public class App { static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args)throws Exception { if(System.getProperty("ONLINE_JUDGE")==null){ File inputFile=new File("/Users/vipinjain/self/cp/input.txt"); File outputFile=new File("/Users/vipinjain/self/cp/output.txt"); br=new BufferedReader(new FileReader(inputFile)); bw=new BufferedWriter(new FileWriter(outputFile)); } int tests ; tests=1 ; while(tests-->0){ solve(); } bw.flush(); bw.close(); br.close(); } static boolean isVowel(char c){ return c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y' ; } static void solve()throws Exception { int x1,x2,y1,y2 ; String[] tmp=br.readLine().split(" "); x1=Integer.parseInt(tmp[0]); y1=Integer.parseInt(tmp[1]); tmp=br.readLine().split(" "); x2=Integer.parseInt(tmp[0]); y2=Integer.parseInt(tmp[1]); int ans=Math.max(Math.abs(x2-x1),Math.abs(y2-y1)); bw.write(ans+""); bw.write("\n"); } } ------------------------------------------------------------ OCL File: --------- class App { static attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute bw : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( if (OclProcess.getEnvironmentProperty("ONLINE_JUDGE") = null) then ( var inputFile : OclFile ; inputFile := OclFile("/Users/vipinjain/self/cp/input.txt") ; var outputFile : OclFile ; outputFile := OclFile("/Users/vipinjain/self/cp/output.txt") ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(inputFile)) ; bw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(outputFile)) ) else skip ; var tests : int ; tests := 1 ; while (tests > 0) do ( tests := tests - 1 ; skip ; ( execute solve() ) ; ) ; skip ; skip ; skip ; ); static operation isVowel( c : String) : boolean pre: true post: true activity: ( return c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u' or c = 'y' ); static operation solve() : void pre: true post: true activity: ( var x1 : int ; var x2 : int ; var y1 : int ; var y2 : int ; var tmp : Sequence(String) ; tmp := br.readLine()->split(" ") ; x1 := (tmp[0+1])->toInteger() ; y1 := (tmp[1+1])->toInteger() ; tmp := br.readLine()->split(" ") ; x2 := (tmp[0+1])->toInteger() ; y2 := (tmp[1+1])->toInteger() ; var ans : int ; ans := Set{if x2 - x1 < 0 then -(x2 - x1) else x2 - x1 endif, if y2 - y1 < 0 then -(y2 - y1) else y2 - y1 endif}->max() ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class GFG { static int getNumToAdd(int arr[],int n){ Arrays.sort(arr); int d=arr[1]-arr[0]; int numToAdd=-1 ; boolean numAdded=false ; for(int i=2 ; isort() ; var d : int ; d := arr[1+1] - arr[0+1] ; var numToAdd : int ; numToAdd := -1 ; var numAdded : boolean ; numAdded := false ; var i : int ; i := 2 ; while i < n do ( ( var diff : int ; diff := 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 ) ; i := i + 1 ) ; if (numToAdd = -1) then return (arr[n - 1+1] + d) else skip ; return numToAdd ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,3,5,7,11,13,15} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(getNumToAdd(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(in.readLine()); int xi=Integer.parseInt(st.nextToken()); int yi=Integer.parseInt(st.nextToken()); st=new StringTokenizer(in.readLine()); int xf=Integer.parseInt(st.nextToken()); int yf=Integer.parseInt(st.nextToken()); int dx=Math.abs(xf-xi); int dy=Math.abs(yf-yi); System.out.println(Math.max(dy,dx)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(in.readLine()) ; var xi : int ; xi := (st.next())->toInteger() ; var yi : int ; yi := (st.next())->toInteger() ; st := OclIterator.newOclIterator_String(in.readLine()) ; var xf : int ; xf := (st.next())->toInteger() ; var yf : int ; yf := (st.next())->toInteger() ; var dx : int ; dx := if xf - xi < 0 then -(xf - xi) else xf - xi endif ; var dy : int ; dy := if yf - yi < 0 then -(yf - yi) else yf - yi endif ; OclFile["System.out"].println(Set{dy, dx}->max()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class ProfessorGukiZsRobot { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int x1=Integer.parseInt(str[0]); int y1=Integer.parseInt(str[1]); str=br.readLine().split(" "); int x2=Integer.parseInt(str[0]); int y2=Integer.parseInt(str[1]); System.out.print(Math.max(Math.abs(x1-x2),Math.abs(y2-y1))); } } ------------------------------------------------------------ OCL File: --------- class ProfessorGukiZsRobot { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var x1 : int ; x1 := (str[0+1])->toInteger() ; var y1 : int ; y1 := (str[1+1])->toInteger() ; str := br.readLine()->split(" ") ; var x2 : int ; x2 := (str[0+1])->toInteger() ; var y2 : int ; y2 := (str[1+1])->toInteger() ; OclFile["System.out"].print(Set{if x1 - x2 < 0 then -(x1 - x2) else x1 - x2 endif, if y2 - y1 < 0 then -(y2 - y1) else y2 - y1 endif}->max()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Stack ; import java.util.StringTokenizer ; public class Main { public class Activity implements Comparable{ int start ; int end ; public Activity(int start,int end){ this.start=start ; this.end=end ; } @ Override public int compareTo(Activity o){ if(this.start!=o.start){ return this.start-o.start ; } return this.end-this.end ; } public String toString(){ return String.format("%d-%d",start,end); } } public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(reader.readLine()); Activity[] activities=new Activity[n]; for(int i=0 ; istack=new Stack(); stack.push(activities[0]); for(int i=1 ; ilast.end){ stack.push(acti); } else if(acti.end { attribute start : int; attribute end : int; static operation newActivity( start : int, end : int) : Activity pre: true post: true activity: ( var self : Activity ; self := createActivity(); self.initialise(start, end); return self ); operation initialise( start : int, end : int) : void pre: true post: true activity: ( self.start := start ; self.end := end ); operation compareTo( o : Activity) : int pre: true post: true activity: ( if (self.start /= o.start) then ( return self.start - o.start ) else skip ; return self.end - self.end ); operation toString() : String pre: true post: true activity: ( return StringLib.format("%d-%d",Sequence{start,end}) ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (reader.readLine())->toInteger() ; var activities : Sequence(Activity) ; activities := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String(reader.readLine()) ; var start : int ; start := (st.next())->toInteger() ; var end : int ; end := (st.next())->toInteger() ; activities[i+1] := Activity.newActivity(start, end) ) ; i := i + 1 ) ; skip ; activities := activities->sort() ; var stack : Sequence(Activity) ; stack := Sequence{} ; stack := stack->append(activities[0+1]) ; var i : int ; i := 1 ; while i < n do ( ( var last : Activity ; last := stack->min() ; var acti : Activity ; acti := activities[i+1] ; if (acti.start > last.end) then ( stack := stack->append(acti) ) else if (acti.end < last.end) then ( stack := stack->front() ; stack := stack->append(acti) ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(stack->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Work[] works=new Work[n]; for(int i=0 ; i1){ int m=(left+right)/2 ; if(dp[m]{ int left ; int right ; public Work(int left,int right){ this.left=left ; this.right=right ; } public int compareTo(Work another){ return right-another.right ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var works : Sequence(Work) ; works := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( works[i+1] := Work.newWork(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; works := works->sort() ; var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp := dp->collect(2147483647) ; dp[0+1] := 0 ; var max : int ; max := 0 ; for (w : works) do ( ( var left : int ; left := 0 ; var right : int ; right := max + 1 ; while (right - left > 1) do ( var m : int ; m := (left + right) / 2 ; if (dp[m+1] < w.left) then ( left := m ) else ( right := m ) ) ; dp[left + 1+1] := Set{dp[left + 1+1], w.right}->min() ; max := Set{max, left + 1}->max() ; ) ) ; OclFile["System.out"].println(max) ; ); static class Work implements Comparable { attribute left : int; attribute right : int; static operation newWork( left : int, right : int) : Work pre: true post: true activity: ( var self : Work ; self := createWork(); self.initialise(left, right); return self ); operation initialise( left : int, right : int) : void pre: true post: true activity: ( self.left := left ; self.right := right ); operation compareTo( another : Work) : int pre: true post: true activity: ( return right - another.right ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.PriorityQueue ; import java.util.Scanner ; class Activity implements Comparable{ int s ; int t ; Activity(int s,int t){ this.s=s ; this.t=t ; } public int compareTo(Activity act){ return t-act.t ; } } public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); PriorityQueueque=new PriorityQueue<>(); for(int i=0 ; i=act.s)continue ; res++; time=act.t ; } System.out.println(res); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Activity implements Comparable { attribute s : int; attribute t : int; static operation newActivity( s : int, t : int) : Activity pre: true post: true activity: ( var self : Activity ; self := createActivity(); self.initialise(s, t); return self ); operation initialise( s : int, t : int) : void pre: true post: true activity: ( self.s := s ; self.t := t ); operation compareTo( act : Activity) : int pre: true post: true activity: ( return t - act.t ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var que : Sequence(Activity) ; que := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; que := que->including(Activity.newActivity(s, t)) ) ; i := i + 1 ) ; var res : int ; res := 0 ; var time : int ; time := 0 ; while (not(que->isEmpty())) do ( var act : Activity ; act := que->min() ; if (time >= act.s) then continue else skip ; res := res + 1 ; time := act.t ) ; OclFile["System.out"].println(res) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner s=new Scanner(System.in); static boolean black,white ; static char[][] map ; static int W,H ; public static void main(String[] args){ int count ; while(true){ W=s.nextInt(); H=s.nextInt(); if(W==0 && H==0)break ; int bCount=0,wCount=0 ; map=new char[H][W]; for(int i=0 ; i=H || j<0 || j>=W)return 0 ; if(map[i][j]=='.'){ map[i][j]='x' ; count++; count+=search(i+1,j)+search(i-1,j)+search(i,j+1)+search(i,j-1); } else if(map[i][j]=='B'){ black=true ; } else if(map[i][j]=='W'){ white=true ; } return count ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute black : boolean; static attribute map : Sequence(Sequence(String)); static attribute W : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var count : int ; while (true) do ( W := s.getCurrent()->toInteger() ; H := s.getCurrent()->toInteger() ; if (W = 0 & H = 0) then break else skip ; var bCount : int ; bCount := 0 ; var wCount : int ; wCount := 0 ; map := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var i : int ; i := 0 ; while i < H do ( ( map[i+1] := s.getCurrent()->characters() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( black := false ; white := false ; count := 0 ; if (map[i+1][j+1] = '.') then count := search(i, j) ; else skip ; if (black & not(white)) then bCount := bCount+(count) else if (not(black) & white) then wCount := wCount+(count) ; else skip ; ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(bCount + " " + wCount) ; ) ); static operation search( i : int, j : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; if (i < 0 or i >= H or j < 0 or j >= W) then return 0 else skip ; if (map[i+1][j+1] = '.') then ( map[i+1][j+1] := 'x' ; count := count + 1 ; count := count+(search(i + 1, j) + search(i - 1, j) + search(i, j + 1) + search(i, j - 1)) ) else if (map[i+1][j+1] = 'B') then ( black := true ) else if (map[i+1][j+1] = 'W') then ( white := true ) else skip ; ; ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] tmpArray=br.readLine().split(" "); int n=Integer.parseInt(tmpArray[0]); Activity[] acts=new Activity[n]; for(int i=0 ; i{ int start ; int end ; public Activity(int s,int e){ this.start=s ; this.end=e ; } @ Override public int compareTo(Activity a1){ return this.end-a1.end ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var tmpArray : Sequence(String) ; tmpArray := br.readLine()->split(" ") ; var n : int ; n := (tmpArray[0+1])->toInteger() ; var acts : Sequence(Activity) ; acts := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( tmpArray := br.readLine()->split(" ") ; var start : int ; start := (tmpArray[0+1])->toInteger() ; var end : int ; end := (tmpArray[1+1])->toInteger() ; acts[i+1] := Activity.newActivity(start, end) ) ; i := i + 1 ) ; acts := acts->sort() ; var count : int ; count := 1 ; var currentTime : int ; currentTime := acts[0+1].end ; var i : int ; i := 1 ; while i < n do ( ( if (currentTime < acts[i+1].start) then ( count := count + 1 ; currentTime := acts[i+1].end ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } class Activity implements Comparable { attribute start : int; attribute end : int; static operation newActivity( s : int, e : int) : Activity pre: true post: true activity: ( var self : Activity ; self := createActivity(); self.initialise(s, e); return self ); operation initialise( s : int, e : int) : void pre: true post: true activity: ( self.start := s ; self.end := e ); operation compareTo( a1 : Activity) : int pre: true post: true activity: ( return self.end - a1.end ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayListtoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : int ; a := st.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,a)->collect(0) ; var i : int ; i := 0 ; while i < a do ( ( arr[i+1] := 1 ) ; i := i + 1 ) ; for (i : arr) do ( ( OclFile["System.out"].print(i + " ") ) ) ; OclFile["System.out"].println() ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class pre423 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader obj=new FastReader(); int tc=obj.nextInt(); while(tc--!=0){ int n=obj.nextInt(); for(int i=1 ; n!=0 ; i+=2,n--){ if(i>=1000)i=1 ; System.out.print(i+" "); } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class pre423 { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : FastReader ; obj := FastReader.newFastReader() ; var tc : int ; tc := obj.nextInt() ; while (tc /= 0) do ( skip ; ( var n : int ; n := obj.nextInt() ; var i : int ; i := 1 ; while n /= 0 do ( ( if (i >= 1000) then i := 1 ; else skip ; OclFile["System.out"].print(i + " ") ) ; i := i+(2) ; n := n - 1 ) ; OclFile["System.out"].println() ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A716 { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int c=input.nextInt(); int[] t=new int[n]; for(int i=0 ; i0 && t[i]-t[i-1]<=c){ --i ; s++; } System.out.println(s); } } ------------------------------------------------------------ OCL File: --------- class A716 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var c : int ; c := input.getCurrent()->toInteger() ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( t[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; var s : int ; s := 1 ; var i : int ; i := n - 1 ; while (i > 0 & t[i+1] - t[i - 1+1] <= c) do ( i := i - 1 ; s := s + 1 ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test189 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print("1 ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1372 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n - 1 do ( ( OclFile["System.out"].print(1 + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(1) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Dispatcher { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int q=scan.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < q do ( ( var n : int ; n := scan.getCurrent()->toInteger() ; if (n < 4) then ( OclFile["System.out"].println(4 - n) ) else ( if (n mod 2 /= 0) then OclFile["System.out"].println("1") ; else OclFile["System.out"].println("0") ; ) ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class spich { public static int isCount(int n){ if(n<4)return 4-n ; else if(n % 2==0)return 0 ; else return 1 ; } public static void main(String[] args){ Scanner in=new Scanner(System.in); int cou=in.nextInt(); int[] n=new int[cou]; for(int i=0 ; itoInteger() ; var n : Sequence(int) ; n := Integer.subrange(1,cou)->collect(0) ; var i : int ; i := 0 ; while i < cou do ( ( n[i+1] := in.getCurrent()->toInteger() ; OclFile["System.out"].println(isCount(n[i+1])) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int getLeftMostZero(Queuezero){ if(zero.isEmpty())return-1 ; zero.remove(); return 0 ; } static int getLeftMostOne(Queueone){ if(one.isEmpty())return-1 ; one.remove(); return 1 ; } static int getLeftMostElement(Queuezero,Queueone){ if(zero.isEmpty()&& one.isEmpty())return-1 ; else if(zero.isEmpty()){ one.remove(); return 1 ; } else if(one.isEmpty()){ zero.remove(); return 0 ; } int res=(zero.peek()zero=new LinkedList<>(); Queueone=new LinkedList<>(); for(int i=0 ; iisEmpty()) then return -1 else skip ; zero := zero.remove() ; return 0 ); static operation getLeftMostOne( one : Sequence(int)) : int pre: true post: true activity: ( if (one->isEmpty()) then return -1 else skip ; one := one.remove() ; return 1 ); static operation getLeftMostElement( zero : Sequence(int), one : Sequence(int)) : int pre: true post: true activity: ( if (zero->isEmpty() & one->isEmpty()) then return -1 else if (zero->isEmpty()) then ( one := one.remove() ; return 1 ) else if (one->isEmpty()) then ( zero := zero.remove() ; return 0 ) else skip ; ; ; var res : int ; res := if (zero->min() < one->min()) then 0 else 1 endif ; if (res = 0) then zero := zero.remove() else one := one.remove() ; ; return res ); static operation performQueries( arr : Sequence(int), n : int, queries : Sequence(int), q : int) : void pre: true post: true activity: ( var zero : Sequence(int) ; zero := Sequence{} ; var one : Sequence(int) ; one := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = 0) then zero := zero->including(i) ; else one := one->including(i) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( var type : int ; type := queries[i+1] ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (type) ; if _switchval = 1 then OclFile["System.out"].println(getLeftMostZero(zero)) ; break else skip ; if _switchval = 2 then OclFile["System.out"].println(getLeftMostOne(one)) ; break else skip ; if _switchval = 3 then OclFile["System.out"].println(getLeftMostElement(zero, one)) ; break else skip ; ) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,0,1,1,1} ; var n : int ; n := arr->size() ; var queries : Sequence(int) ; queries := Sequence{1,3,1} ; var q : int ; q := queries->size() ; execute performQueries(arr, n, queries, q) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class main { public static int isCount(int n){ if(n<4)return 4-n ; else if(n % 2==0)return 0 ; else return 1 ; } public static void main(String[] args){ Scanner in=new Scanner(System.in); int cou=in.nextInt(); int[] n=new int[cou]; for(int i=0 ; itoInteger() ; var n : Sequence(int) ; n := Integer.subrange(1,cou)->collect(0) ; var i : int ; i := 0 ; while i < cou do ( ( n[i+1] := in.getCurrent()->toInteger() ; OclFile["System.out"].println(isCount(n[i+1])) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class NewClass4 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; if (n = 1 or n = 2) then OclFile["System.out"].println(2) ; else ( if (n mod 2 = 1) then OclFile["System.out"].println(1) ; else OclFile["System.out"].println(0) ; ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MainClass { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int q=sc.nextInt(); while(q-->0){ int n=sc.nextInt(); if(n==1)System.out.println(3); else if(n==2)System.out.println(2); else System.out.println(n % 2); } } } ------------------------------------------------------------ OCL File: --------- class MainClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := sc.getCurrent()->toInteger() ; while (q > 0) do ( q := q - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 1) then OclFile["System.out"].println(3) ; else if (n = 2) then OclFile["System.out"].println(2) else OclFile["System.out"].println(n mod 2) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); if(t==0)System.out.println("1"); else if((t-1)% 4==0)System.out.println("8"); else if((t-1)% 4==1)System.out.println("4"); else if((t-1)% 4==2)System.out.println("2"); else System.out.println("6"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; if (t = 0) then OclFile["System.out"].println("1") ; else if ((t - 1) mod 4 = 0) then OclFile["System.out"].println("8") else if ((t - 1) mod 4 = 1) then OclFile["System.out"].println("4") else if ((t - 1) mod 4 = 2) then OclFile["System.out"].println("2") else OclFile["System.out"].println("6") ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==0)System.out.println(1); else if((n)% 4==1)System.out.println(8); else if((n)% 4==2)System.out.println(4); else if((n)% 4==3)System.out.println(2); else System.out.println(6); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then OclFile["System.out"].println(1) ; else if ((n) mod 4 = 1) then OclFile["System.out"].println(8) else if ((n) mod 4 = 2) then OclFile["System.out"].println(4) else if ((n) mod 4 = 3) then OclFile["System.out"].println(2) else OclFile["System.out"].println(6) ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==0)System.out.println(1); else if((n-1)% 4==0)System.out.println(8); else if((n-1)% 4==1)System.out.println(4); else if((n-1)% 4==2)System.out.println(2); else System.out.println(6); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then OclFile["System.out"].println(1) ; else if ((n - 1) mod 4 = 0) then OclFile["System.out"].println(8) else if ((n - 1) mod 4 = 1) then OclFile["System.out"].println(4) else if ((n - 1) mod 4 = 2) then OclFile["System.out"].println(2) else OclFile["System.out"].println(6) ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class CrazyComputer { public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(reader.readLine()); int n=Integer.parseInt(st.nextToken()); long c=Long.parseLong(st.nextToken()); int count=1 ; st=new StringTokenizer(reader.readLine()); long now=Long.parseLong(st.nextToken()); for(int i=1 ; ic){ count=1 ; } else count++; now=hehe ; } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class CrazyComputer { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(reader.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var c : long ; c := (st.next())->toLong() ; var count : int ; count := 1 ; st := OclIterator.newOclIterator_String(reader.readLine()) ; var now : long ; now := (st.next())->toLong() ; var i : int ; i := 1 ; while i < n do ( ( var hehe : long ; hehe := (st.next())->toLong() ; if (hehe - now > c) then ( count := 1 ) else count := count + 1 ; ; now := hehe ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==0)System.out.println("1"); else if((n-1)% 4==0)System.out.println("8"); else if((n-1)% 4==1)System.out.println("4"); else if((n-1)% 4==2)System.out.println("2"); else System.out.println("6"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then OclFile["System.out"].println("1") ; else if ((n - 1) mod 4 = 0) then OclFile["System.out"].println("8") else if ((n - 1) mod 4 = 1) then OclFile["System.out"].println("4") else if ((n - 1) mod 4 = 2) then OclFile["System.out"].println("2") else OclFile["System.out"].println("6") ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==0)System.out.println("1"); else if((n-1)% 4==0)System.out.println("8"); else if((n-1)% 4==1)System.out.println("4"); else if((n-1)% 4==2)System.out.println("2"); else System.out.println("6"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then OclFile["System.out"].println("1") ; else if ((n - 1) mod 4 = 0) then OclFile["System.out"].println("8") else if ((n - 1) mod 4 = 1) then OclFile["System.out"].println("4") else if ((n - 1) mod 4 = 2) then OclFile["System.out"].println("2") else OclFile["System.out"].println("6") ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _246A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n<=2)System.out.println(-1); else { while(n!=0){ System.out.print(n+" "); n--; } } } } ------------------------------------------------------------ OCL File: --------- class { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n <= 2) then OclFile["System.out"].println(-1) ; else ( while (n /= 0) do ( OclFile["System.out"].print(n + " ") ; n := n - 1 ) ) ); } 46A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n <= 2) then OclFile["System.out"].println(-1) ; else ( while (n /= 0) do ( OclFile["System.out"].print(n + " ") ; n := n - 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void Vertices(int x,int y){ int val=Math.abs(x)+Math.abs(y); System.out.print(val*(x<0 ?-1 : 1)+" 0 "); System.out.print("0 "+val*(y<0 ?-1 : 1)); } public static void main(String[] args){ int x=3,y=3 ; Vertices(x,y); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Vertices( x : int, y : int) : void pre: true post: true activity: ( var val : int ; val := if x < 0 then -(x) else x endif + if y < 0 then -(y) else y endif ; OclFile["System.out"].print(val * (if x < 0 then -1 else 1 endif) + " 0 ") ; OclFile["System.out"].print("0 " + val * (if y < 0 then -1 else 1 endif)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 3 ; var y : int ; y := 3 ; execute Vertices(x, y) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class BuggySorting_246A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n>2){ for(int i=2 ; i<=n ; i++){ System.out.print(i+" "); } System.out.println(1); } else { System.out.println(-1); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class BuggySorting{ static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n > 2) then ( var i : int ; i := 2 ; while i <= n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(1) ) else ( OclFile["System.out"].println(-1) ) ; skip ); } 46A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n > 2) then ( var i : int ; i := 2 ; while i <= n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(1) ) else ( OclFile["System.out"].println(-1) ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication75 { static boolean prime(int n){ for(int i=2 ; i=1 ; i--)System.out.print(i+" "); } } ------------------------------------------------------------ OCL File: --------- class JavaApplication75 { static operation prime( n : int) : boolean pre: true post: true activity: ( var i : int ; i := 2 ; while i < n do ( if (n mod i = 0) then return true else skip ; ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var read : OclFile ; read := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := read.getCurrent()->toInteger() ; if (n = 1 or n = 2) then ( OclFile["System.out"].println("-1") ; return ) else skip ; var i : int ; i := n ; while i >= 1 do ( OclFile["System.out"].print(i + " ") ; ; i := i - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { static void printPath(int arr[],int idx){ if(idx==1){ System.out.print(idx+" "); return ; } printPath(arr,arr[idx-2]); System.out.print(idx+" "); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n<=2){ System.out.println(-1); return ; } System.out.print(100+" 99 "); for(int i=0 ; itoInteger() ; if (n <= 2) then ( OclFile["System.out"].println(-1) ; return ) else skip ; OclFile["System.out"].print(100 + " 99 ") ; var i : int ; i := 0 ; while i < n - 2 do ( ( OclFile["System.out"].print(i + 1 + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int sum=0 ; for(int i=0 ; itoInteger() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; if (sum mod n = 0) then ( OclFile["System.out"].println(n) ) else ( OclFile["System.out"].println(n - 1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class BIncreaseAndDecrease { public static void main(String[] args)throws IOException { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(buf.readLine()); String[] inp=buf.readLine().split(" "); int[] arr=new int[inp.length]; long sum=0 ; for(int i=0 ; itoInteger() ; var inp : Sequence(String) ; inp := buf.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,inp->size())->collect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < inp->size() do ( sum := sum+((inp[i+1])->toInteger()) ; ; i := i + 1 ) ; if (sum mod arr->size() = 0) then OclFile["System.out"].println(arr->size()) else OclFile["System.out"].println(arr->size() - 1) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),a=0,sum=0 ; for(int i=0 ; itoInteger() ; var a : int ; a := 0 ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( a := in.getCurrent()->toInteger() ; sum := sum+(a) ) ; i := i + 1 ) ; OclFile["System.out"].printf("%d\n", if sum mod n = 0 then n else n - 1 endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ans=0 ; if(n==1)ans=2 ; else if(n==0 || n==2)ans=1 ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; if (n = 1) then ans := 2 else if (n = 0 or n = 2) then ans := 1 ; else skip ; ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.HashSet ; import java.util.Set ; import java.util.StringTokenizer ; public class cp_test2 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine().trim(); } catch(Exception e){ e.printStackTrace(); } return str ; } } static class FastWriter { private final BufferedWriter bw ; public FastWriter(){ this.bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object)throws IOException { bw.append(""+object); } public void println(Object object)throws IOException { print(object); bw.append("\n"); } public void close()throws IOException { bw.close(); } } public static void main(String[] args){ try { FastReader in=new FastReader(); FastWriter out=new FastWriter(); int n=in.nextInt(); long c=in.nextLong(); long[] arr=new long[n]; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine()->trim() ) catch (e : ProgramException) do ( e.printStackTrace() ) return str ); } static class FastWriter { attribute bw : OclFile; static operation newFastWriter() : FastWriter pre: true post: true activity: ( var self : FastWriter ; self := createFastWriter(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( self.bw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ); operation print( object : OclAny) : void pre: true post: true activity: ( skip ); operation println( object : OclAny) : void pre: true post: true activity: ( execute print(object) ; skip ); operation close() : void pre: true post: true activity: ( skip ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : FastReader ; in := FastReader.newFastReader() ; var out : FastWriter ; out := FastWriter.newFastWriter() ; var n : int ; n := in.nextInt() ; var c : long ; c := in.nextLong() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var temp : long ; temp := in.nextLong() ; arr[i+1] := temp ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i < n do ( ( if (arr[i+1] - arr[i - 1+1] <= c) then ( count := count + 1 ) else ( count := 0 ) ) ; i := i + 1 ) ; OclFile["System.out"].print(count + 1) ; ) catch (e : ProgramException) do ( return ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); out.println(solve(sc.nextInt())); sc.close(); } private static int solve(int n){ if(n==0)return 1 ; if(n==1)return 2 ; if(n==2)return 1 ; return 0 ; } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; out.println(solve(sc.nextInt())) ; sc.close() ); static operation solve( n : int) : int pre: true post: true activity: ( if (n = 0) then return 1 else skip ; if (n = 1) then return 2 else skip ; if (n = 2) then return 1 else skip ; return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws IOException { BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in)); String str="" ; int mjs=0 ; str=bfr.readLine(); mjs=Integer.parseInt(str); if(mjs==0){ System.out.println("1"); } else if(mjs==1){ System.out.println("2"); } else if(mjs==2){ System.out.println("1"); } else if(mjs>=3){ System.out.println("0"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bfr : OclFile ; bfr := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : String ; str := "" ; var mjs : int ; mjs := 0 ; str := bfr.readLine() ; mjs := (str)->toInteger() ; if (mjs = 0) then ( OclFile["System.out"].println("1") ) else if (mjs = 1) then ( OclFile["System.out"].println("2") ) else if (mjs = 2) then ( OclFile["System.out"].println("1") ) else if (mjs >= 3) then ( OclFile["System.out"].println("0") ) else skip ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.HashSet ; class GFG { public static void getSum(int[] a,int n){ int[] P=new int[n]; P[0]=a[0]; for(int i=1 ; ihash=new HashMap<>(); for(int i=0 ; ires=new HashSet<>(); for(int i=1 ; i*i<=S ; i++){ if(S % i==0){ boolean pres=true ; int div1=i,div2=S/i ; for(int j=div1 ; j<=S ; j+=div1){ if(hash.get(j)==null || hash.get(j)!=1){ pres=false ; break ; } } if(pres && div1!=S)res.add(div1); pres=true ; for(int j=S/i ; j<=S ; j+=S/i){ if(hash.get(j)==null || hash.get(j)!=1){ pres=false ; break ; } } if(pres && div2!=S)res.add(div2); } } if(res.size()==0){ System.out.println("-1"); return ; } for(int i : res)System.out.print(i+" "); } public static void main(String[] args){ int[] a={ 1,2,1,1,1,2,1,3 }; int n=a.length ; getSum(a,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getSum( a : Sequence(int), n : int) : void pre: true post: true activity: ( var P : Sequence(int) ; P := Integer.subrange(1,n)->collect(0) ; P[0+1] := a[0+1] ; var i : int ; i := 1 ; while i < n do ( P[i+1] := a[i+1] + P[i - 1+1] ; ; i := i + 1 ) ; var S : int ; S := P[n - 1+1] ; var hash : Map(int,int) ; hash := Map{} ; var i : int ; i := 0 ; while i < n do ( hash := hash->union(Map{P[i+1] |-> 1}) ; ; i := i + 1 ) ; var res : Set(int) ; res := Set{} ; var i : int ; i := 1 ; while i * i <= S do ( ( if (S mod i = 0) then ( var pres : boolean ; pres := true ; var div1 : int ; div1 := i ; var div2 : int ; div2 := S / i ; var j : int ; j := div1 ; while j <= S do ( ( if (hash->at(j) = null or hash->at(j) /= 1) then ( pres := false ; break ) else skip ) ; j := j+(div1) ) ; if (pres & div1 /= S) then res := res->including(div1) ; else skip ; pres := true ; var j : int ; j := S / i ; while j <= S do ( ( if (hash->at(j) = null or hash->at(j) /= 1) then ( pres := false ; break ) else skip ) ; j := j+(S / i) ) ; if (pres & div2 /= S) then res := res->including(div2) ; else skip ; ) else skip ) ; i := i + 1 ) ; if (res->size() = 0) then ( OclFile["System.out"].println("-1") ; return ) else skip ; for (i : res) do ( OclFile["System.out"].print(i + " ") ; ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,2,1,1,1,2,1,3} ; var n : int ; n := a->size() ; execute getSum(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); FastDivision solver=new FastDivision(); solver.solve(1,in,out); out.close(); } static class FastDivision { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); int ans=-1 ; if(n==0 || n==2){ ans=1 ; } else if(n==1){ ans=2 ; } else { ans=0 ; } out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : FastDivision ; solver := FastDivision.newFastDivision() ; solver.solve(1, in, out) ; skip ; ); static class FastDivision { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var ans : int ; ans := -1 ; if (n = 0 or n = 2) then ( ans := 1 ) else if (n = 1) then ( ans := 2 ) else ( ans := 0 ) ; ; skip ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); switch(n){ case 0 : System.out.println(1); break ; case 1 : System.out.println(2); break ; case 2 : System.out.println(1); break ; default : System.out.println(0); break ; } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (n) ; if _switchval = 0 then OclFile["System.out"].println(1) ; break else skip ; if _switchval = 1 then OclFile["System.out"].println(2) ; break else skip ; if _switchval = 2 then OclFile["System.out"].println(1) ; break else skip ; if true then OclFile["System.out"].println(0) ; break else skip ; ) skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test210 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var x : int ; x := in.getCurrent()->toInteger() - 1 ; var i : int ; i := 2 ; while i <= x do ( ( if (x mod (x / i) = 0) then ( OclFile["System.out"].println(i + " " + x) ; break ) else skip ) ; i := i + 1 ) ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class A_Gregor_and_Cryptography { public static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader reader=new FastReader(); int T=reader.nextInt(); while(T!=0){ T--; int P=reader.nextInt(); int num=P-1 ; System.out.println(2+" "+num); } } } ------------------------------------------------------------ OCL File: --------- class A_Gregor_and_Cryptography { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : FastReader ; reader := FastReader.newFastReader() ; var T : int ; T := reader.nextInt() ; while (T /= 0) do ( T := T - 1 ; var P : int ; P := reader.nextInt() ; var num : int ; num := P - 1 ; OclFile["System.out"].println(2 + " " + num) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(); System.out.println("2 "+(n % 2==0 ? n : n-1)); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := sc.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println("2 " + (if n mod 2 = 0 then n else n - 1 endif)) ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { boolean main()throws IOException { Scanner sc=new Scanner(systemin); int N=sc.nextInt(); sc.nextLine(); int cnt=0 ; for(int i=0 ; itoInteger() ; skip ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < N do ( ( var s : String ; s := sc.nextLine() ; if (s = "E869120") then ( cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].printf("%d\n", cnt) ; skip ; return false ); attribute log : OclFile; attribute result : OclFile := OclFile["System.out"]; attribute systemin : OclFile; static attribute instance : Main := Main.newMain(); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( systemin := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; log := OclFile.newOclFile_Write(OclFile()) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( instance.main() ; instance.systemin.close() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String target="E869120" ; int count=0 ; for(int i=0 ; itoInteger() ; var target : String ; target := "E869120" ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (target = sc.getCurrent()) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ans=0 ; for(int i=0 ; itoInteger() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( if (sc.getCurrent() = "E869120") then ans := ans + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class cf { public static void main(String[] args){ Scanner css=new Scanner(System.in); int t=css.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := css.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := css.getCurrent()->toInteger() ) ; j := j + 1 ) ; arr := arr->sort() ; var min : int ; min := 2147483647 ; var j : int ; j := 0 ; while j < arr->size() - 2 do ( ( var count : int ; count := 0 ; if ((arr[j+1] = arr[j + 1+1] & arr[j + 1+1] = arr[j + 2+1])) then ( min := 0 ; break ) else ( count := count+((arr[j + 1+1] - arr[j+1]) + (arr[j + 2+1] - arr[j + 1+1])) ; min := Set{min, count}->min() ) ) ; j := j + 1 ) ; OclFile["System.out"].println(min) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int i=sc.nextInt(); System.out.println(n-i+1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(n - i + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); String[] line=br.readLine().split(" "); int a=Integer.parseInt(line[0]); int b=Integer.parseInt(line[1]); out.println(a-b+1); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var line : Sequence(String) ; line := br.readLine()->split(" ") ; var a : int ; a := (line[0+1])->toInteger() ; var b : int ; b := (line[1+1])->toInteger() ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.util.ArrayDeque ; import java.util.Scanner ; import java.util.*; import java.util.Arrays ; import java.util.ArrayList ; import java.util.Set ; import java.util.HashSet ; import java.util.Collection ; public class Main { static final Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int i=sc.nextInt(); System.out.println(N-i+1); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; var i : int ; i := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(N - i + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String[] str=in.readLine().split(" "); int n=Integer.parseInt(str[0]); int i=Integer.parseInt(str[1]); System.out.println(n-i+1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : Sequence(String) ; str := in.readLine()->split(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var i : int ; i := (str[1+1])->toInteger() ; OclFile["System.out"].println(n - i + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println(sc.nextInt()-sc.nextInt()+1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(sc.getCurrent()->toInteger() - sc.getCurrent()->toInteger() + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String ar[]){ Scanner cin=new Scanner(System.in); int n=cin.nextInt(); int ans1=n/30 ; n %=30 ; int ans2=n*2 ; System.out.println(ans1+" "+ans2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( ar : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := cin.getCurrent()->toInteger() ; var ans1 : int ; ans1 := n / 30 ; n := n mod 30 ; var ans2 : int ; ans2 := n * 2 ; OclFile["System.out"].println(ans1 + " " + ans2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int minute=12*60*n/360 ; System.out.println((minute/60)+" "+(minute % 60)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var minute : int ; minute := 12 * 60 * n / 360 ; OclFile["System.out"].println((minute / 60) + " " + (minute mod 60)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Task_467 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int result=0 ; for(int i=0 ; i=2)result++; } System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Task_467 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < n do ( ( var p : int ; p := in.getCurrent()->toInteger() ; var q : int ; q := in.getCurrent()->toInteger() ; if (q - p >= 2) then result := result + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int count=0 ; for(int i=0 ; i=2){ count++; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var t : int ; t := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if ((c - t) >= 2) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Rough { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long arr[][]=new long[(int)n][2]; long count=0 ; for(int i=0 ; i=2){ count++; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Rough { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var arr : Sequence(Sequence(long)) ; arr := Integer.subrange(1,n->oclAsType(int))->collect(Integer.subrange(1,2)->collect(0)) ; var count : long ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 2 do ( ( arr[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var vk : long ; vk := (arr[i+1][1+1] - arr[i+1][0+1]) ; if (vk >= 2) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findElement(int arr[],int size){ int right_mul=1,left_mul=1 ; for(int i=1 ; isize() ; OclFile["System.out"].println(findElement(arr, size)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Solution { static class INT { int data ; INT(int d){ data=d ; } } static void findPostOrderUtil(int pre[],int n,int minval,int maxval,INT preIndex){ if(preIndex.data==n)return ; if(pre[preIndex.data]maxval){ return ; } int val=pre[preIndex.data]; preIndex.data++; findPostOrderUtil(pre,n,minval,val,preIndex); findPostOrderUtil(pre,n,val,maxval,preIndex); System.out.print(val+" "); } static void findPostOrder(int pre[],int n){ INT preIndex=new INT(0); findPostOrderUtil(pre,n,Integer.MIN_VALUE,Integer.MAX_VALUE,preIndex); } public static void main(String args[]){ int pre[]={ 40,30,35,80,100 }; int n=pre.length ; findPostOrder(pre,n); } } ------------------------------------------------------------ OCL File: --------- class Solution { static class INT { attribute data : int; static operation newINT( d : int) : INT pre: true post: true activity: ( var self : INT ; self := createINT(); self.initialise(d); return self ); operation initialise( d : int) : void pre: true post: true activity: ( data := d ); } static operation findPostOrderUtil( pre : Sequence(int), n : int, minval : int, maxval : int, preIndex : INT) : void pre: true post: true activity: ( if (preIndex.data = n) then return else skip ; if (pre[preIndex.data+1] < minval or pre[preIndex.data+1] > maxval) then ( return ) else skip ; var val : int ; val := pre[preIndex.data+1] ; preIndex.data := preIndex.data + 1 ; execute findPostOrderUtil(pre, n, minval, val, preIndex) ; execute findPostOrderUtil(pre, n, val, maxval, preIndex) ; OclFile["System.out"].print(val + " ") ; ); static operation findPostOrder( pre : Sequence(int), n : int) : void pre: true post: true activity: ( var preIndex : INT ; preIndex := INT.newINT(0) ; execute findPostOrderUtil(pre, n, -2147483648, 2147483647, preIndex) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var pre : Sequence(int) ; pre := Sequence{40,30,35,80,100} ; var n : int ; n := pre->size() ; execute findPostOrder(pre, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Vector ; class GFG { static void originalArray(int greater[],int n){ Vectortemp=new Vector(); for(int i=0 ; i<=n ; i++)temp.add(i); int arr[]=new int[n]; for(int i=0 ; iincluding(i) ; ; i := i + 1 ) ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var k : int ; k := n - greater[i+1] - i ; arr[i+1] := temp->at(k+1) ; temp := temp->excludingAt(k+1) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var Arr : Sequence(int) ; Arr := Sequence{6,3,2,1,0,1,0} ; var n : int ; n := Arr->size() ; execute originalArray(Arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testCases=sc.nextInt(); for(int index=0 ; indextoInteger() ; var index : int ; index := 0 ; while index < testCases do ( ( var size : int ; size := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,size)->collect(0) ; var i : int ; i := 0 ; while i < size do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(Main.newMain().getMinimumNumberOfOperations(arr)) ) ; index := index + 1 ) ); operation getMinimumNumberOfOperations( arr : Sequence(int)) : int pre: true post: true activity: ( var min : int ; min := 2147483647 ; arr := arr->sort() ; var i : int ; i := 2 ; while i < arr->size() do ( ( var x : int ; x := if arr[i+1] - arr[i - 1+1] < 0 then -(arr[i+1] - arr[i - 1+1]) else arr[i+1] - arr[i - 1+1] endif + if arr[i - 2+1] - arr[i - 1+1] < 0 then -(arr[i - 2+1] - arr[i - 1+1]) else arr[i - 2+1] - arr[i - 1+1] endif ; min := Set{x, min}->min() ) ; i := i + 1 ) ; return min ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Codeforces { public static void main(String[] args){ Scanner kali=new Scanner(System.in); int rooms=kali.nextInt(); int empty=0 ; for(int i=1 ; i<=rooms ; i++){ int peoples=kali.nextInt(); int max_place=kali.nextInt(); if(max_place-peoples>=2){ empty++; } } System.out.println(empty); } } ------------------------------------------------------------ OCL File: --------- class Codeforces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var kali : OclFile ; kali := OclFile.newOclFile_Read(OclFile["System.in"]) ; var rooms : int ; rooms := kali.getCurrent()->toInteger() ; var empty : int ; empty := 0 ; var i : int ; i := 1 ; while i <= rooms do ( ( var peoples : int ; peoples := kali.getCurrent()->toInteger() ; var max_place : int ; max_place := kali.getCurrent()->toInteger() ; if (max_place - peoples >= 2) then ( empty := empty + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(empty) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int count=0 ; for(int i=0 ; i=2){ count++; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var t : int ; t := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if ((c - t) >= 2) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n % 10==3){ System.out.println("bon"); } else if(n % 10==0 || n % 10==1 || n % 10==6 || n % 10==8){ System.out.println("pon"); } else { System.out.println("hon"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n mod 10 = 3) then ( OclFile["System.out"].println("bon") ) else if (n mod 10 = 0 or n mod 10 = 1 or n mod 10 = 6 or n mod 10 = 8) then ( OclFile["System.out"].println("pon") ) else ( OclFile["System.out"].println("hon") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { static FastReader in=new FastReader(); public static void main(String[] args){ int t=1 ; while(t-->0)solve(); } public static void solve(){ int n=in.nextInt()% 10 ; switch(n){ case 2 : case 4 : case 5 : case 7 : case 9 : System.out.println("hon"); break ; case 0 : case 1 : case 6 : case 8 : System.out.println("pon"); break ; case 3 : System.out.println("bon"); break ; } } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static int max(int a,int b){ return a>b ? a : b ; } public static int min(int a,int b){ return a 0) do ( t := t - 1 ; skip ; execute solve() ; ; ) ); static operation solve() : void pre: true post: true activity: ( var n : int ; n := in.nextInt() mod 10 ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (n) ; if _switchval = 2 or _switchval = 4 or _switchval = 5 or _switchval = 7 or _switchval = 9 then OclFile["System.out"].println("hon") ; break else skip ; if _switchval = 0 or _switchval = 1 or _switchval = 6 or _switchval = 8 then OclFile["System.out"].println("pon") ; break else skip ; if _switchval = 3 then OclFile["System.out"].println("bon") ; break else skip ; ) ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation max( a : int, b : int) : int pre: true post: true activity: ( return if a > b then a else b endif ); static operation min( a : int, b : int) : int pre: true post: true activity: ( return if a < b then a else b endif ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if b = 0 then a else gcd(b, (a mod b)) endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt()% 10 ; if(n==3){ System.out.println("bon"); } else if(n==0 || n==1 || n==6 || n==8){ System.out.println("pon"); } else { System.out.println("hon"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() mod 10 ; if (n = 3) then ( OclFile["System.out"].println("bon") ) else if (n = 0 or n = 1 or n = 6 or n = 8) then ( OclFile["System.out"].println("pon") ) else ( OclFile["System.out"].println("hon") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static Scanner scan=new Scanner(System.in); public static void main(String[] args){ int n=nextInt(); int a=n % 10 ; if(a==2 || a==4 || a==5 || a==7 || a==9){ print("hon"); } else if(a==0 || a==1 || a==6 || a==8){ print("pon"); } else if(a==3){ print("bon"); } } public static int nextInt(){ return Integer.parseInt(scan.next()); } public static long nextLong(){ return Long.parseLong(scan.next()); } public static String next(){ return scan.next(); } public static double nextDouble(){ return Double.parseDouble(scan.next()); } public static float nextFloat(){ return Float.parseFloat(scan.next()); } public static void yesNo(boolean flag){ if(flag)System.out.println("Yes"); else System.out.println("No"); } public static void print(Object a){ System.out.println(a); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scan : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := nextInt() ; var a : int ; a := n mod 10 ; if (a = 2 or a = 4 or a = 5 or a = 7 or a = 9) then ( execute print("hon") ) else if (a = 0 or a = 1 or a = 6 or a = 8) then ( execute print("pon") ) else if (a = 3) then ( execute print("bon") ) else skip ; ; ); static operation nextInt() : int pre: true post: true activity: ( return (scan.getCurrent())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (scan.getCurrent())->toLong() ); static operation next() : String pre: true post: true activity: ( return scan.getCurrent() ); static operation nextDouble() : double pre: true post: true activity: ( return (scan.getCurrent())->toReal() ); static operation nextFloat() : double pre: true post: true activity: ( return parseFloat(scan.getCurrent()) ); static operation yesNo( flag : boolean) : void pre: true post: true activity: ( if (flag) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); static operation print( a : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String num=sc.next(); int n=num.length(); if(num.substring(n-1,n).equals("0")|| num.substring(n-1,n).equals("1")|| num.substring(n-1,n).equals("6")|| num.substring(n-1,n).equals("8")){ System.out.println("pon"); return ; } else if(num.substring(n-1,n).equals("3")){ System.out.println("bon"); return ; } else { System.out.println("hon"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : String ; num := sc.getCurrent() ; var n : int ; n := num->size() ; if (num.subrange((n)->char2byte() - 1+1,n) = "0" or num.subrange((n)->char2byte() - 1+1,n) = "1" or num.subrange((n)->char2byte() - 1+1,n) = "6" or num.subrange((n)->char2byte() - 1+1,n) = "8") then ( OclFile["System.out"].println("pon") ; return ) else if (num.subrange((n)->char2byte() - 1+1,n) = "3") then ( OclFile["System.out"].println("bon") ; return ) else ( OclFile["System.out"].println("hon") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringBuilder stringBuilder=new StringBuilder(); StringTokenizer st ; st=new StringTokenizer(in.readLine()); int n=Integer.parseInt(st.nextToken()); int t=Integer.parseInt(st.nextToken()); if(n==1 && t==10)System.out.println(-1); else { System.out.print(t); if(t==10){ for(int i=0 ; itoInteger() ; var t : int ; t := (st.next())->toInteger() ; if (n = 1 & t = 10) then OclFile["System.out"].println(-1) else ( OclFile["System.out"].print(t) ; if (t = 10) then ( var i : int ; i := 0 ; while i < n - 2 do ( ( OclFile["System.out"].print(0) ) ; i := i + 1 ) ) else var i : int ; i := 0 ; while i < n - 1 do ( ( OclFile["System.out"].print(0) ) ; i := i + 1 ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); if(n==1 && t==10){ System.out.print(-1); } else if(t==10){ for(int i=0 ; itoInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; if (n = 1 & t = 10) then ( OclFile["System.out"].print(-1) ) else if (t = 10) then ( var i : int ; i := 0 ; while i < n - 1 do ( OclFile["System.out"].print(1) ; ; i := i + 1 ) ; OclFile["System.out"].print(0) ; OclProcess.exit(0) ) else ( var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(t) ; ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { try(Scanner sc=new Scanner(System.in)){ int N=sc.nextInt(); int u=sc.nextInt()-1 ; int v=sc.nextInt()-1 ; List[] edges=new List[N]; for(int i=0 ; i(); } for(int i=0 ; iq){ q=e[i]; } } } if(q<=0){ System.out.println(0); } else { System.out.println(q-1); } } } static void dfs(int u,int[] d,List[] edges){ for(Integer nu : edges[u]){ if(d[nu]==Integer.MAX_VALUE){ d[nu]=d[u]+1 ; dfs(nu,d,edges); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var N : int ; N := sc.getCurrent()->toInteger() ; var u : int ; u := sc.getCurrent()->toInteger() - 1 ; var v : int ; v := sc.getCurrent()->toInteger() - 1 ; var edges : Sequence(Sequence(int)) ; edges := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( edges[i+1] := Sequence{} ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( var a : int ; a := sc.getCurrent()->toInteger() - 1 ; var b : int ; b := sc.getCurrent()->toInteger() - 1 ; edges[a+1]->excludes(b) ; edges[b+1]->excludes(a) ) ; i := i + 1 ) ; var d : Sequence(int) ; d := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( d[i+1] := 2147483647 ) ; i := i + 1 ) ; d[u+1] := 0 ; execute dfs(u, d, edges) ; var e : Sequence(int) ; e := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( e[i+1] := 2147483647 ) ; i := i + 1 ) ; e[v+1] := 0 ; execute dfs(v, e, edges) ; var q : int ; q := -1 ; var i : int ; i := 0 ; while i < N do ( ( if (d[i+1] < e[i+1]) then ( if (e[i+1] > q) then ( q := e[i+1] ) else skip ) else skip ) ; i := i + 1 ) ; if (q <= 0) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(q - 1) ) ; )) ); static operation dfs( u : int, d : Sequence(int), edges : Sequence(Sequence(int))) : void pre: true post: true activity: ( for (nu : edges[u+1]) do ( ( if (d[nu+1] = 2147483647) then ( d[nu+1] := d[u+1] + 1 ; execute dfs(nu, d, edges) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String args[])throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); if(t==10){ if(n==1)System.out.println(-1); else { System.out.print(1); for(int i=2 ; i<=n ; i++)System.out.print(0); System.out.println(); } } else { for(int i=0 ; itoInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; if (t = 10) then ( if (n = 1) then OclFile["System.out"].println(-1) ; else ( OclFile["System.out"].print(1) ; var i : int ; i := 2 ; while i <= n do ( OclFile["System.out"].print(0) ; ; i := i + 1 ) ; OclFile["System.out"].println() ) ) else ( var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(t) ; ; i := i + 1 ) ; OclFile["System.out"].println() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ solve(sc); } } static void solve(Scanner sc){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( execute solve(sc) ) ; ) ); static operation solve( sc : OclFile) : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var ans : int ; ans := 2e9->oclAsType(int) ; var i : int ; i := 0 ; while i < n - 2 do ( ( ans := Set{ans, a[i + 2+1] - a[i+1]}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class teest { public static void main(String[] args){ Scanner a=new Scanner(System.in); int n=a.nextInt(),t=a.nextInt(); if(n==1 && t>9)System.out.println(-1); else { StringBuilder s ; if(t==10)s=new StringBuilder("1"); else s=new StringBuilder(String.valueOf(t)); for(int i=1 ; itoInteger() ; var t : int ; t := a.getCurrent()->toInteger() ; if (n = 1 & t > 9) then OclFile["System.out"].println(-1) ; else ( var s : String ; if (t = 10) then s := StringLib.newString("1") else s := StringLib.newString(((t) + "")) ; ; var i : int ; i := 1 ; while i < n do ( ( s := s + StringLib.newString('0') ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); if(n==1 && t==10){ System.out.println(-1); } else if(n>=2 && t==10){ for(int i=1 ; itoInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; if (n = 1 & t = 10) then ( OclFile["System.out"].println(-1) ) else if (n >= 2 & t = 10) then ( var i : int ; i := 1 ; while i < n do ( ( OclFile["System.out"].print(1) ) ; i := i + 1 ) ; OclFile["System.out"].println(0) ) else ( var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].print(t) ) ; i := i + 1 ) ; OclFile["System.out"].println() ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1393 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ int n=scanner.nextInt(); System.out.println(1+n/2); } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class A1393 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(1 + n / 2) ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A1393 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ int t=sc.nextInt(); System.out.println((t>>1)+1); } } } ------------------------------------------------------------ OCL File: --------- class A1393 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var t : int ; t := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(((t/(2->pow(1)))->oclAsType(long)) + 1) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Round662A { public static PrintWriter pw=new PrintWriter(System.out); public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); pw.println((n/2)+1); } pw.close(); } } ------------------------------------------------------------ OCL File: --------- class Round662A { static attribute pw : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := (br.readLine())->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := (br.readLine())->toInteger() ; skip ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class RainbowDashFluttershyandChessColoring { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int t1=1 ; t1<=t ; t1++){ long n=sc.nextLong(); long res=0 ; if(n==1)System.out.println(1); else { if(n>=4)res=(n/2)-1 ; res=res+2 ; System.out.println(res); } } } } ------------------------------------------------------------ OCL File: --------- class RainbowDashFluttershyandChessColoring { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var t1 : int ; t1 := 1 ; while t1 <= t do ( ( var n : long ; n := sc.getCurrent()->toLong() ; var res : long ; res := 0 ; if (n = 1) then OclFile["System.out"].println(1) ; else ( if (n >= 4) then res := (n / 2) - 1 ; else skip ; res := res + 2 ; OclFile["System.out"].println(res) ) ) ; t1 := t1 + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Solution { public static void main(String[] args){ FastReader sc=new FastReader(); StringBuilder sb=new StringBuilder(); int testcases=sc.nextInt(); while(testcases-->0){ int n=sc.nextInt(); if(n==1){ sb.append(-1).append("\n"); } else { sb.append(2); for(int i=1 ; i 0) do ( testcases := testcases - 1 ; skip ; ( var n : int ; n := sc.nextInt() ; if (n = 1) then ( sb := sb + StringLib.newString(-1) + StringLib.newString("\n") ) else ( sb := sb + StringLib.newString(2) ; var i : int ; i := 1 ; while i < n do ( ( sb := sb + StringLib.newString(3) ) ; i := i + 1 ) ; sb := sb + StringLib.newString("\n") ) ) ; ) ; OclFile["System.out"].println(sb) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int k=0 ; ktoInteger() ; var k : int ; k := 0 ; while k < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 1) then OclFile["System.out"].println(-1) ; else if (n = 2) then OclFile["System.out"].println(23) else if (n = 3) then OclFile["System.out"].println(233) else ( var i : int ; i := 1 ; while i <= n - 2 do ( OclFile["System.out"].print(3) ; ; i := i + 1 ) ; OclFile["System.out"].print(2) ; OclFile["System.out"].print(3) ; OclFile["System.out"].println() ) ; ; ) ; k := k + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; public class Main { public static Listpermutation(Listlist,String target,String ans){ if(target.length()<=1){ list.add(ans+target); } else { for(int i=0 ; ilistA=new ArrayList<>(); permutation(listA,number,""); int sum=0 ; for(int j=0 ; jsize() <= 1) then ( list->excludes(ans + target) ) else ( var i : int ; i := 0 ; while i < target->size() do ( ( execute permutation(list, target.subrange(0+1,i) + target.subrange(i + 1+1,i + 1), ans + target->at(i+1)) ) ; i := i + 1 ) ) ; return list ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (scanner.getCurrent())->toInteger() ; var line : Sequence(Sequence(String)) ; line := Integer.subrange(1,2)->collect(Integer.subrange(1,1)->collect(null)) ; var i : int ; i := 0 ; while i < 2 do ( ( line[i+1] := line[i+1]->collect("") ; var j : int ; j := 0 ; while j < n do ( ( line[i+1][0+1] := line[i+1][0+1]+(scanner.getCurrent()) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var number : String ; number := "" ; var i : int ; i := 1 ; while i <= n do ( ( number := number+(i) ) ; i := i + 1 ) ; var listA : Sequence(String) ; listA := Sequence{} ; execute permutation(listA, number, "") ; var sum : int ; sum := 0 ; var j : int ; j := 0 ; while j < line->size() do ( ( var i : int ; i := 0 ; while i < listA->size() do ( ( if (listA->at(i+1) = line[j+1][0+1]) then ( if (sum = 0) then ( sum := sum+(i) ) else ( sum := sum-(i) ) ) else skip ) ; i := i + 1 ) ) ; j := j + 1 ) ; OclFile["System.out"].println(if sum < 0 then -(sum) else sum endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int j,t,n ; ArrayListarr=new ArrayList<>(); for(Integer i=1 ; i<=1670 ; i++){ if(i % 3!=0 && i % 10!=3)arr.add(i); } t=sc.nextInt(); for(j=0 ; jincluding(i) ; else skip ) ; i := i + 1 ) ; t := sc.getCurrent()->toInteger() ; j := 0 ; while j < t do ( ( n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(arr->at(n - 1+1)) ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int j,t,n,i ; t=sc.nextInt(); for(j=0 ; jtoInteger() ; j := 0 ; while j < t do ( ( n := sc.getCurrent()->toInteger() ; i := 1 ; while i <= n do ( ( if (i mod 3 = 0 or i mod 10 = 3) then n := n + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(n) ) ; j := j + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; var max : int ; max := 2147483647 ; var i : int ; i := 0 ; while i < n - 2 do ( ( max := Set{max, if arr[i+1] - arr[i + 1+1] < 0 then -(arr[i+1] - arr[i + 1+1]) else arr[i+1] - arr[i + 1+1] endif + if arr[i + 1+1] - arr[i + 2+1] < 0 then -(arr[i + 1+1] - arr[i + 2+1]) else arr[i + 1+1] - arr[i + 2+1] endif}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test112 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var j : int ; j := 1 ; while true do ( ( if (j mod 3 /= 0 & j mod 10 /= 3) then ( sum := sum + 1 ) else skip ; if (sum = x) then ( OclFile["System.out"].println(j) ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); ArrayLista=new ArrayList<>(); for(int i=1 ; i<=1666 ; i++){ if(i % 3==0 || i % 10==3){ continue ; } a.add(i); } int t=in.nextInt(); while(t--!=0){ int k=in.nextInt(); System.out.println(a.get(k-1)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : Sequence(int) ; a := Sequence{} ; var i : int ; i := 1 ; while i <= 1666 do ( ( if (i mod 3 = 0 or i mod 10 = 3) then ( continue ) else skip ; a := a->including(i) ) ; i := i + 1 ) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var k : int ; k := in.getCurrent()->toInteger() ; OclFile["System.out"].println(a->at(k - 1+1)) ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class dislikes_of_threes { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); for(int i=1 ; ; i++){ if(i % 3==0 || i % 10==3){ continue ; } else { n--; if(n==0){ System.out.println(i); break ; } } } t--; } } } ------------------------------------------------------------ OCL File: --------- class dislikes_of_threes { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while true do ( ( if (i mod 3 = 0 or i mod 10 = 3) then ( continue ) else ( n := n - 1 ; if (n = 0) then ( OclFile["System.out"].println(i) ; break ) else skip ) ) ; i := i + 1 ) ; t := t - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); if(n % 2==0){ System.out.println("0 0 "+n/2); } else System.out.println(-1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println("0 0 " + n / 2) ) else OclFile["System.out"].println(-1) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class Main { public static void main(String[] args){ Scanner mc=new Scanner(System.in); int m=mc.nextInt(); while(m--!=0){ int n=mc.nextInt(); if(n % 2==0)System.out.println("0 0 "+n/2); else System.out.println("-1"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mc : OclFile ; mc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var m : int ; m := mc.getCurrent()->toInteger() ; while (m /= 0) do ( skip ; ( var n : int ; n := mc.getCurrent()->toInteger() ; if (n mod 2 = 0) then OclFile["System.out"].println("0 0 " + n / 2) ; else OclFile["System.out"].println("-1") ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); if((n & 1)==1)System.out.println(-1); else System.out.println(0+" "+n/2+" "+n/2); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; if ((MathLib.bitwiseAnd(n,1)) = 1) then OclFile["System.out"].println(-1) ; else OclFile["System.out"].println(0 + " " + n / 2 + " " + n / 2) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.File ; import java.io.FileReader ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Solution { static PrintWriter pw ; static FastScanner s ; public static void main(String[] args)throws Exception { pw=new PrintWriter(System.out); s=new FastScanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); if(n % 2==1){ pw.println(-1); } else { pw.println("0 0 "+n/2); } } pw.flush(); } } class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public FastScanner(String s)throws Exception { br=new BufferedReader(new FileReader(new File(s))); } public String next()throws Exception { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws Exception { return Integer.parseInt(next()); } public long nextLong()throws Exception { return Long.parseLong(next()); } } ------------------------------------------------------------ OCL File: --------- class Solution { static attribute pw : OclFile; static attribute s : FastScanner; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; s := FastScanner.newFastScanner(OclFile["System.in"]) ; var t : int ; t := s.nextInt() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.nextInt() ; if (n mod 2 = 1) then ( skip ) else ( skip ) ) ; ) ; skip ; ); } class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner( s : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newFastScanner( s : String) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile(s))) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] p=new int[n]; int[] q=new int[n]; IntStream.rangeClosed(1,n).forEach(i->p[i-1]=sc.nextInt()); IntStream.rangeClosed(1,n).forEach(i->q[i-1]=sc.nextInt()); int[] convertedP=convert(p); int[] convertedQ=convert(q); int diff=0 ; for(int i=0 ; i0 ? n :-n ; } public static int pow(int n){ int powNum=1 ; for(int i=1 ; i<=n ; i++){ powNum=powNum*i ; } return powNum ; } public static void print(Object obj){ System.out.println(obj); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var q : Sequence(int) ; q := Integer.subrange(1,n)->collect(0) ; for i : Integer.subrange(1, n) do ( p[i - 1+1] := sc.getCurrent()->toInteger()) ; for i : Integer.subrange(1, n) do ( q[i - 1+1] := sc.getCurrent()->toInteger()) ; var convertedP : Sequence(int) ; convertedP := convert(p) ; var convertedQ : Sequence(int) ; convertedQ := convert(q) ; var diff : int ; diff := 0 ; var i : int ; i := 0 ; while i < n do ( ( diff := diff + (convertedP[i+1] - convertedQ[i+1]) * pow(n - i - 1) ) ; i := i + 1 ) ; execute print(abs(diff)) ; skip ; ); static operation convert( n : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var converted : Sequence(int) ; converted := Integer.subrange(1,n->size())->collect(0) ; var i : int ; i := 0 ; while i < n->size() do ( ( converted[i+1] := n[i+1] ; var order : int ; order := n[i+1] ; var j : int ; j := 0 ; while j < i do ( ( if (n[j+1] < order) then ( converted[i+1] := converted[i+1] - 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return converted ); static operation abs( n : int) : int pre: true post: true activity: ( return if n > 0 then n else -n endif ); static operation pow( n : int) : int pre: true post: true activity: ( var powNum : int ; powNum := 1 ; var i : int ; i := 1 ; while i <= n do ( ( powNum := powNum * i ) ; i := i + 1 ) ; return powNum ); static operation print( obj : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(obj) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class HelloWorld { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); if(n<=2){ for(int i=9 ; i>=0 && n>0 ; i--){ System.out.print(i); n--; } System.out.println(); } else { System.out.print(9); System.out.print(8); System.out.print(9); n-=3 ; for(int i=0 ; itoInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n <= 2) then ( var i : int ; i := 9 ; while i >= 0 & n > 0 do ( ( OclFile["System.out"].print(i) ; n := n - 1 ) ; i := i - 1 ) ; OclFile["System.out"].println() ) else ( OclFile["System.out"].print(9) ; OclFile["System.out"].print(8) ; OclFile["System.out"].print(9) ; n := n-(3) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(i mod 10) ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.util.Arrays ; public class Cv { public static void main(String[] args){ FastScanner in=new FastScanner(); Scanner input=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=input.nextInt(); while(t-->0){ int n=input.nextInt(); int y=0 ; if(n>2){ out.print(989); while((n-3)>0){ out.print(y % 10); y++; n--; } } else if(n==2){ out.print(98); } else { out.print(9); } out.println(); } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next(){ while(! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } byte nextByte(){ return Byte.parseByte(next()); } short nextShort(){ return Short.parseShort(next()); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return java.lang.Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } } } ------------------------------------------------------------ OCL File: --------- class Cv { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastScanner ; in := FastScanner.newFastScanner() ; var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := input.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := input.getCurrent()->toInteger() ; var y : int ; y := 0 ; if (n > 2) then ( skip ; while ((n - 3) > 0) do ( skip ; y := y + 1 ; n := n - 1 ) ) else if (n = 2) then ( skip ) else ( skip ) ; ; skip ) ; ) ; skip ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextByte() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextShort() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return java.lang.Long.parseLong(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MyClass { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int c=0 ; for(int i=0 ; i<=(n/k); ++i){ for(int j=0 ; jtoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i <= (n / k) do ( ( var j : int ; j := 0 ; while j < k do ( ( c := c + 1 ; if (c <= n) then OclFile["System.out"].print((97 + j)->oclAsType(String)) ; else break ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces { static int MOD=1000000007 ; static int[] arr=new int[100001]; public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ solve(s); } } public static void solve(Scanner s){ int n=s.nextInt(); for(int i=1 ; i<=n ; i++)arr[i]=s.nextInt(); Arrays.sort(arr,1,n+1); long ans=Integer.MAX_VALUE ; for(int i=3 ; i<=n ; i++)ans=Math.min(ans,arr[i]-arr[i-2]); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Codeforces { static attribute MOD : int := 1000000007; static attribute arr : Sequence(int) := Integer.subrange(1,100001)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( execute solve(s) ) ; ) ); static operation solve( s : OclFile) : void pre: true post: true activity: ( var n : int ; n := s.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( arr[i+1] := s.getCurrent()->toInteger() ; ; i := i + 1 ) ; arr := arr.subrange(1,1)^(arr.subrange(1+1,n + 1)->sort())^arr.subrange(n + 1+1,arr.size) ; var ans : long ; ans := 2147483647 ; var i : int ; i := 3 ; while i <= n do ( ans := Set{ans, arr[i+1] - arr[i - 2+1]}->min() ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.function.IntPredicate ; import org.omg.CORBA.Current ; import static java.lang.Math.abs ; public class omar { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int k=input.nextInt(); String s="" ; for(int i=0 ; itoInteger() ; var k : int ; k := input.getCurrent()->toInteger() ; var s : String ; s := "" ; var i : int ; i := 0 ; while i < n do ( ( s := s+((('a')->char2byte() + i mod k)->oclAsType(String)) ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int k=in.nextInt(); String out="" ; String[] chars=new String[26]; int[] v=new int[k]; for(int i=0 ; i<26 ; i++){ chars[i]=Character.toString((char)(i+97)); } for(int i=0 ; itoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var out : String ; out := "" ; var chars : Sequence(String) ; chars := Integer.subrange(1,26)->collect(null) ; var v : Sequence(int) ; v := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < 26 do ( ( chars[i+1] := ((i + 97)->oclAsType(String) + "") ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( ( v[i+1] := i ) ; i := i + 1 ) ; while (out->size() < n) do ( if (k = n) then ( var i : int ; i := 0 ; while i < n do ( ( out := out+(chars[i+1]) ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < k do ( ( if (out->size() < n) then ( out := out+(chars[v[i+1]+1]) ) else break ) ; i := i + 1 ) ) ) ; OclFile["System.out"].println(out) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int k=in.nextInt(); String s="" ; for(int i=0 ; itoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var s : String ; s := "" ; var i : int ; i := 0 ; while i < n do ( ( s := s+((('a')->char2byte() + i mod k)->oclAsType(String)) ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); String s="" ; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var s : String ; s := "" ; var i : int ; i := 0 ; while i < n do ( ( s := s+((('a')->char2byte() + (i mod k))->oclAsType(String)) ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class WTLW { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] arr=new String[0]; try { String s=br.readLine(); arr=s.split(" "); } catch(IOException e){ } if(arr.length==0)System.exit(1); long n=Long.valueOf(arr[0]); long t=Long.valueOf(arr[1]); double base=1.000000011 ; System.out.println(n*Math.pow(base,t)); } } ------------------------------------------------------------ OCL File: --------- class WTLW { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var arr : Sequence(String) ; arr := Integer.subrange(1,0)->collect(null) ; try ( var s : String ; s := br.readLine() ; arr := s->split(" ") ) catch (e : IOException) do skip if (arr->size() = 0) then OclProcess.exit(1) ; else skip ; var n : long ; n := (arr[0+1])->toLong() ; var t : long ; t := (arr[1+1])->toLong() ; var base : double ; base := 1.000000011 ; OclFile["System.out"].println(n * base->pow(t)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); System.out.println(n*Math.pow(1.000000011,t)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(n * 1.000000011->pow(t)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main extends PrintWriter { Main(){ super(System.out,true); } Scanner sc=new Scanner(System.in); public static void main(String[] $){ Main o=new Main(); o.main(); o.flush(); } int[] fac ; boolean[] used ; int rank(int[] aa,int n){ Arrays.fill(used,false); int sum=0 ; for(int i=0 ; icollect(false) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var k : int ; k := 0 ; var a : int ; a := 0 ; while a < aa[i+1] do ( if (not(used[a+1])) then k := k + 1 ; else skip ; ; a := a + 1 ) ; sum := sum+(fac[n - 1 - i+1] * k) ; used[aa[i+1]+1] := true ) ; i := i + 1 ) ; return sum ); operation main() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var pp : Sequence(int) ; pp := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( pp[i+1] := sc.getCurrent()->toInteger() - 1 ; ; i := i + 1 ) ; var qq : Sequence(int) ; qq := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( qq[i+1] := sc.getCurrent()->toInteger() - 1 ; ; i := i + 1 ) ; fac := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; var f : int ; f := 1 ; while i < n do ( ( fac[i+1] := f ; f := f*((i + 1)) ) ; i := i + 1 ) ; used := Integer.subrange(1,n)->collect(false) ; execute println(if rank(pp, n) - rank(qq, n) < 0 then -(rank(pp, n) - rank(qq, n)) else rank(pp, n) - rank(qq, n) endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); Scanner input=new Scanner(System.in); int i=input.nextInt(); long num=input.nextLong(); System.out.println(i*Math.pow(1.000000011,num)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var i : int ; i := input.getCurrent()->toInteger() ; var num : long ; num := input.getCurrent()->toLong() ; OclFile["System.out"].println(i * 1.000000011->pow(num)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class smth { public static void main(String[] args)throws IOException { try(BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); ){ String[] strings=reader.readLine().split(" "); double trans=Double.parseDouble(strings[0]); int t=Integer.parseInt(strings[1]); for(int i=0 ; isplit(" ") ; var trans : double ; trans := (strings[0+1])->toReal() ; var t : int ; t := (strings[1+1])->toInteger() ; var i : int ; i := 0 ; while i < t / 100 do ( ( trans := trans*(1.0000011000006015) ) ; i := i + 1 ) ; OclFile["System.out"].println(trans) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Delimost { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int t=in.nextInt(); System.out.println(n*Math.pow(1.000000011,t)); } } ------------------------------------------------------------ OCL File: --------- class Delimost { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var t : int ; t := in.getCurrent()->toInteger() ; OclFile["System.out"].println(n * 1.000000011->pow(t)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ long N=sc.nextLong(),K=sc.nextLong(); long ans=0 ; for(long i=0 ; itoLong() ; var K : long ; K := sc.getCurrent()->toLong() ; var ans : long ; ans := 0 ; var i : long ; i := 0 ; while i < N - 1 do ( ( ans := K * ((ans / (K - 1))->oclAsType(long)) + ans mod (K - 1) + 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int m=4 ; static int n=3 ; static class pair { int first,second ; public pair(int first,int second){ this.first=first ; this.second=second ; } } static int Maze(int matrix[][]){ Queueq=new LinkedList<>(); q.add(new pair(0,0)); int count=0 ; while(! q.isEmpty()){ pair p=q.peek(); q.remove(); if(p.first==n-1 && p.second==m-1)count++; if(p.first+1at("first") := first ; self->at("second") := second ); } static operation Maze( matrix : Sequence(Sequence(int))) : int pre: true post: true activity: ( var q : Sequence(pair) ; q := Sequence{} ; q := q->including(pair.newpair(0, 0)) ; var count : int ; count := 0 ; while (not(q->isEmpty())) do ( var p : pair ; p := q->min() ; q := q.remove() ; if (p->at("first") = n - 1 & p->at("second") = m - 1) then count := count + 1 ; else skip ; if (p->at("first") + 1 < n & matrix[p->at("first") + 1+1][p->at("second")+1] = 1) then ( q := q->including(pair.newpair(p->at("first") + 1, p->at("second"))) ) else skip ; if (p->at("second") + 1 < m & matrix[p->at("first")+1][p->at("second") + 1+1] = 1) then ( q := q->including(pair.newpair(p->at("first"), p->at("second") + 1)) ) else skip ; ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var matrix : Sequence(Sequence(int)) ; matrix := Sequence{Sequence{1,0,0,1},Sequence{1,1,1,1},Sequence{1,0,1,1}} ; OclFile["System.out"].println(Maze(matrix)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); Jail solver=new Jail(); solver.solve(1,in,out); out.close(); } static class Jail { public void solve(int testNumber,Scanner in,PrintWriter out){ long N=in.nextInt(); long K=in.nextInt(); long ans=0 ; for(int i=0 ; itoInteger() ; var K : long ; K := in.getCurrent()->toInteger() ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < N - 1 do ( ( ans := ans+(ans / (K - 1) + 1) ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); long idx=0 ; for(int i=1 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var idx : long ; idx := 0 ; var i : int ; i := 1 ; while i < n do ( ( idx := idx+(idx / (k - 1) + 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(idx) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.*; public class Main { private static long gcd(long a,long b){ if(a==0)return b ; return gcd(b % a,a); } public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=in.nextInt(),k=in.nextInt(); long ans=0 ; for(int i=1 ; itoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i < n do ( ( ans := ans+(ans / (k - 1)) ; ans := ans + 1 ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); System.out.println((n-1)*(m-1)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; OclFile["System.out"].println((n - 1) * (m - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int len=sc.nextInt(); Setset=new HashSet<>(len); for(int i=1 ; i<=len ; i++){ set.add(i); } int a=1 ; for(int i=1 ; i(len); for(int i=1 ; i<=len ; i++){ set.add(i); } int b=1 ; for(int i=1 ; iset,int num){ int ans=0 ; for(int i=1 ; i<=num ; i++){ if(set.contains(i)){ ans++; } } return ans ; } private static int factorial(int num){ int ans=1 ; for(int i=num ; i>=1 ; i--){ ans*=i ; } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var len : int ; len := sc.getCurrent()->toInteger() ; var set : Set(int) ; set := Set{} ; var i : int ; i := 1 ; while i <= len do ( ( set := set->including(i) ) ; i := i + 1 ) ; var a : int ; a := 1 ; var i : int ; i := 1 ; while i < len do ( ( var next : int ; next := sc.getCurrent()->toInteger() ; a := a+(factorial(len - i) * count(set, next) - 1) ; set := set->excludingAt(next+1) ) ; i := i + 1 ) ; skip ; set := Set{} ; var i : int ; i := 1 ; while i <= len do ( ( set := set->including(i) ) ; i := i + 1 ) ; var b : int ; b := 1 ; var i : int ; i := 1 ; while i < len do ( ( var next : int ; next := sc.getCurrent()->toInteger() ; b := b+(factorial(len - i) * count(set, next) - 1) ; set := set->excludingAt(next+1) ) ; i := i + 1 ) ; OclFile["System.out"].print(if b - a < 0 then -(b - a) else b - a endif) ; )) ); static operation count( set : Set(int), num : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= num do ( ( if (set->includes(i)) then ( ans := ans + 1 ) else skip ) ; i := i + 1 ) ; return ans ); static operation factorial( num : int) : int pre: true post: true activity: ( var ans : int ; ans := 1 ; var i : int ; i := num ; while i >= 1 do ( ( ans := ans*(i) ) ; i := i - 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static void solve(){ Scanner sc=new Scanner(System.in); System.out.println((sc.nextInt()-1)*(sc.nextInt()-1)); sc.close(); } public static void main(String args[]){ solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println((sc.getCurrent()->toInteger() - 1) * (sc.getCurrent()->toInteger() - 1)) ; skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); System.out.println((n-1)*(m-1)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; OclFile["System.out"].println((n - 1) * (m - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int m=Integer.parseInt(sc.next()); System.out.println((n-1)*(m-1)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var m : int ; m := (sc.getCurrent())->toInteger() ; OclFile["System.out"].println((n - 1) * (m - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(); if(n % 1000==0){ System.out.println(0); } else { System.out.println(1000-(n % 1000)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := stdIn.getCurrent()->toInteger() ; if (n mod 1000 = 0) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(1000 - (n mod 1000)) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import java.util.*; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } public Character charAt(int i){ return null ; } } public static void main(String[] args)throws IOException { FastReader s=new FastReader(); int n=s.nextInt(); int p=1000,j=0 ; while(n>0){ j=n-p ; n-=p ; } System.out.println(Math.abs(j)); } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation charAt( i : int) : String pre: true post: true activity: ( return null ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : FastReader ; s := FastReader.newFastReader() ; var n : int ; n := s.nextInt() ; var p : int ; p := 1000 ; var j : int ; j := 0 ; while (n > 0) do ( j := n - p ; n := n-(p) ) ; OclFile["System.out"].println(if j < 0 then -(j) else j endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; class GFG { static boolean isPerfectSquare(int num){ int n=(int)(Math.sqrt(num)); return(n*n==num); } static void checkFib(int array[],int n){ int count=0 ; for(int i=0 ; isqrt())->oclAsType(int) ; return (n * n = num) ); static operation checkFib( array : Sequence(int), n : int) : void pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (isPerfectSquare(5 * array[i+1] * array[i+1] + 4) or isPerfectSquare(5 * array[i+1] * array[i+1] - 4)) then ( OclFile["System.out"].print(array[i+1] + " ") ; count := count + 1 ) else skip ) ; i := i + 1 ) ; if (count = 0) then OclFile["System.out"].println("None Present") ; else skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var array : Sequence(int) ; array := Sequence{4,2,8,5,20,1,40,13,23} ; var n : int ; n := array->size() ; execute checkFib(array, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int n=sc.nextInt(); while(n>=1000){ n=n-1000 ; } if(n!=0 && 1000>=n){ n=1000-n ; } out.println(n); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; while (n >= 1000) do ( n := n - 1000 ) ; if (n /= 0 & 1000 >= n) then ( n := 1000 - n ) else skip ; out.println(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); int res=n/1000 ; if(n % 1000!=0)res++; res=(res*1000)-n ; pw.println(res); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var res : int ; res := n / 1000 ; if (n mod 1000 /= 0) then res := res + 1 ; else skip ; res := (res * 1000) - n ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedWriter ; import java.io.FileWriter ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int s=0 ; if(N % 1000==0){ System.out.println(0); } else { s=N % 1000 ; System.out.println(1000-s); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var s : int ; s := 0 ; if (N mod 1000 = 0) then ( OclFile["System.out"].println(0) ) else ( s := N mod 1000 ; OclFile["System.out"].println(1000 - s) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class class1 { public static void main(String arg[]){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int ans=x/2+1 ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class class1 { static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var ans : int ; ans := x / 2 + 1 ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(final String[] args)throws Exception { final Scanner sc=new Scanner(System.in); int N=sc.nextInt(); StringBuffer p=new StringBuffer(); for(int i=0 ; itoInteger() ; var p : String ; p := StringLib.newString() ; var i : int ; i := 0 ; while i < N do ( ( p := p + StringLib.newString(sc.getCurrent()) ) ; i := i + 1 ) ; var q : String ; q := StringLib.newString() ; var i : int ; i := 0 ; while i < N do ( ( q := q + StringLib.newString(sc.getCurrent()) ) ; i := i + 1 ) ; var solver : Solver ; solver := Solver.newSolver(p+"", q+"") ; solver.solve(N) ; ); } class Solver { attribute P : String; attribute Q : String; attribute lessThanP : long := 0; attribute lessThanQ : long := 0; static operation newSolver( P : String, Q : String) : Solver pre: true post: true activity: ( var self : Solver ; self := createSolver(); self.initialise(P, Q); return self ); operation initialise( P : String, Q : String) : void pre: true post: true activity: ( self.P := P ; self.Q := Q ); operation solve( N : int) : void pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 1 ; while i <= N do ( ( sb := sb + StringLib.newString(i) ) ; i := i + 1 ) ; execute permutate(sb, 0, N - 1) ; OclFile["System.out"].println(if lessThanP - lessThanQ < 0 then -(lessThanP - lessThanQ) else lessThanP - lessThanQ endif) ); operation permutate( str : String, l : int, r : int) : void pre: true post: true activity: ( if (l = r) then ( var perm : String ; perm := str+"" ; if (perm->compareTo(P) < 0) then ( lessThanP := lessThanP + 1 ) else skip ; if (perm->compareTo(Q) < 0) then ( lessThanQ := lessThanQ + 1 ) else skip ) else ( var i : int ; i := l ; while i <= r do ( ( execute swap(str, l, i) ; execute permutate(str, l + 1, r) ; execute swap(str, l, i) ) ; i := i + 1 ) ) ); operation swap( s : String, i : int, j : int) : String pre: true post: true activity: ( var tmp : String ; tmp := s->at(j+1) ; s := s.setAt(j+1, s->at(i+1)) ; s := s.setAt(i+1, tmp) ; return s ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Splits { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); System.out.println((n/2)+1); } } ------------------------------------------------------------ OCL File: --------- class Splits { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; OclFile["System.out"].println((n / 2) + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Math.*; public class x964A { public static void main(String[] args)throws IOException { InputStreamReader reader=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(reader); StringTokenizer token=new StringTokenizer(""); InputReader scan=new InputReader(br,token); StringBuilder sb=new StringBuilder(); int X=scan.nextInt(); int result=X/2+1 ; sb.append(result); System.out.println(sb); } static class InputReader { private BufferedReader readfile ; private StringTokenizer token ; InputReader(BufferedReader br,StringTokenizer st){ this.readfile=br ; this.token=st ; } String next(){ while(! this.token.hasMoreTokens()){ try { token=new StringTokenizer(readfile.readLine()); } catch(IOException e){ e.printStackTrace(); } } return this.token.nextToken(); } String nextLine()throws IOException { return readfile.readLine(); } int nextInt(){ return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class x964A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(reader) ; var token : OclIterator ; token := OclIterator.newOclIterator_String("") ; var scan : InputReader ; scan := InputReader.newInputReader(br, token) ; var sb : String ; sb := StringLib.newString() ; var X : int ; X := scan.nextInt() ; var result : int ; result := X / 2 + 1 ; sb := sb + StringLib.newString(result) ; OclFile["System.out"].println(sb) ; ); static class InputReader { attribute readfile : OclFile; attribute token : OclIterator; static operation newInputReader( br : OclFile, st : OclIterator) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(br, st); return self ); operation initialise( br : OclFile, st : OclIterator) : void pre: true post: true activity: ( self.readfile := br ; self.token := st ); operation next() : String pre: true post: true activity: ( while (not(self.token.hasNext())) do ( try ( token := OclIterator.newOclIterator_String(readfile.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return self.token.next() ); operation nextLine() : String pre: true post: true activity: ( return readfile.readLine() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ int n=in.nextInt(); System.out.println(n/2+1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (in.hasNext()) do ( var n : int ; n := in.getCurrent()->toInteger() ; OclFile["System.out"].println(n / 2 + 1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Splits { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); System.out.println(n/2+1); } } ------------------------------------------------------------ OCL File: --------- class Splits { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(n / 2 + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { void solve()throws IOException { int n=ni(),m=ni(); int[] a=nia(m); out.println(n-m-1); } String ns()throws IOException { while(! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()," "); } return tok.nextToken(); } int ni()throws IOException { return Integer.parseInt(ns()); } long nl()throws IOException { return Long.parseLong(ns()); } double nd()throws IOException { return Double.parseDouble(ns()); } String[] nsa(int n)throws IOException { String[] res=new String[n]; for(int i=0 ; itoInteger() ); operation nl() : long pre: true post: true activity: ( return (ns())->toLong() ); operation nd() : double pre: true post: true activity: ( return (ns())->toReal() ); operation nsa( n : int) : Sequence(String) pre: true post: true activity: ( var res : Sequence(String) ; res := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := ns() ) ; i := i + 1 ) ; return res ); operation nia( n : int) : Sequence(int) pre: true post: true activity: ( var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := ni() ) ; i := i + 1 ) ; return res ); operation nla( n : int) : Sequence(long) pre: true post: true activity: ( var res : Sequence(long) ; res := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := nl() ) ; i := i + 1 ) ; return res ); static attribute in : OclFile; static attribute out : OclFile; static attribute tok : OclIterator; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; tok := OclIterator.newOclIterator_String("") ; var main : Main ; main := Main.newMain() ; main.solve() ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.security.NoSuchAlgorithmException ; import java.util.ArrayList ; import java.util.HashMap ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); int[] a=new int[M]; for(int i=0 ; i>(i+1)]; if(nex.length==0)break ; for(int k=0 ; ktoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var hoge : Sequence(boolean) ; hoge := Integer.subrange(1,N)->collect(false) ; var i : int ; i := 0 ; while i < N do ( ( hoge[i+1] := true ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( hoge[a[i+1]+1] := false ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( var nex : Sequence(boolean) ; nex := Integer.subrange(1,(N/(2->pow((i + 1))))->oclAsType(long))->collect(false) ; if (nex->size() = 0) then break else skip ; var k : int ; k := 0 ; while k < hoge->size() do ( ( if (hoge[k+1] & hoge[k + 1+1]) then ( nex[k / 2+1] := true ; sum := sum + 1 ) else if (not(hoge[k+1]) & hoge[k + 1+1] or hoge[k+1] & not(hoge[k + 1+1])) then ( nex[k / 2+1] := true ) else skip ; ) ; k := k+(2) ) ; hoge := nex ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int findNthNumber(int A,int B,int N){ int sum=0 ; for(int i=2 ; itoInteger() - sc.getCurrent()->toInteger() - 1) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Main m=new Main(); m.run(); } Scanner sc=new Scanner(System.in); int rec(int[] b,int left,int right){ if(right-left==2){ if(b[left]==-1 && b[left+1]==-1){ return-1 ; } if(b[left]==-1 || b[left+1]==-1){ return 0 ; } return 1 ; } int mid=(left+right)/2 ; int leftSum=rec(b,left,mid); int rightSum=rec(b,mid,right); if(leftSum==-1 && rightSum==-1){ return-1 ; } if(leftSum==-1 || rightSum==-1){ return leftSum+rightSum+1 ; } return leftSum+rightSum+1 ; } void run(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int a[]=new int[m]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( b[a[i+1]+1] := -1 ) ; i := i + 1 ) ; OclFile["System.out"].println(rec(b, 0, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int count=n-1 ; System.out.println(Math.max(0,n-1-m)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var count : int ; count := n - 1 ; OclFile["System.out"].println(Set{0, n - 1 - m}->max()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class practice { public static void main(String[] args){ Scanner scn=new Scanner(System.in); String s=scn.next(),p ; int k=scn.nextInt(),x=0,y=0,ans=0 ; char a,b ; for(int i=0 ; itoInteger() ; var x : int ; x := 0 ; var y : int ; y := 0 ; var ans : int ; ans := 0 ; var a : String ; var b : String ; var i : int ; i := 0 ; while i < k do ( ( p := scn.getCurrent() ; var j : int ; j := 0 ; while j < s->size() do ( ( if (s->at(j+1) = p->at(0+1)) then ( x := x + 1 ) else if (s->at(j+1) = p->at(1+1)) then ( y := y + 1 ) else ( ans := ans+(Set{x, y}->min()) ; x := 0 ; y := 0 ) ; ) ; j := j + 1 ) ; ans := ans+(Set{x, y}->min()) ; x := 0 ; y := 0 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println((int)Math.pow(sc.nextInt(),3)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(sc.getCurrent()->toInteger()->pow(3)->oclAsType(int)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException,Exception { BufferedReader st=new BufferedReader(new InputStreamReader(System.in)); int n=getInt(st); int ans=n*n*n ; anser(ans); } private static int getInt(BufferedReader st)throws Exception,IOException { int num=Integer.parseInt(st.readLine()); return num ; } private static void anser(int num){ System.out.println(num); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var st : OclFile ; st := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := getInt(st) ; var ans : int ; ans := n * n * n ; execute anser(ans) ); static operation getInt( st : OclFile) : int pre: true post: true activity: ( var num : int ; num := (st.readLine())->toInteger() ; return num ); static operation anser( num : int) : void pre: true post: true activity: ( OclFile["System.out"].println(num) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.*; public class Main { public static void main(String[] args)throws Exception { solve(System.in,System.out); } static void solve(InputStream is,PrintStream os){ Scanner scan=new Scanner(is); int N=scan.nextInt(); int answer=(int)Math.pow((double)N,3.0); os.println(answer); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve(OclFile["System.in"], OclFile["System.out"]) ); static operation solve( is : OclFile, os : OclFile) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(is) ; var N : int ; N := scan.getCurrent()->toInteger() ; var answer : int ; answer := N->oclAsType(double)->pow(3.0)->oclAsType(int) ; os.println(answer) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; import java.io.*; import java.lang.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int res=(int)(Math.pow(n,3)); System.out.println(res); sc.close(); } } class io { public static void YesNo(boolean f){ System.out.println(f ? "Yes" : "No"); } public static void YESNO(boolean f){ System.out.println(f ? "YES" : "NO"); } } class Algo { public static boolean isOdd(int n){ return n % 2==1 ; } public static boolean isEven(int n){ return n % 2==0 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var res : int ; res := (n->pow(3))->oclAsType(int) ; OclFile["System.out"].println(res) ; skip ; ); } class io { static operation YesNo( f : boolean) : void pre: true post: true activity: ( OclFile["System.out"].println(if f then "Yes" else "No" endif) ); static operation YESNO( f : boolean) : void pre: true post: true activity: ( OclFile["System.out"].println(if f then "YES" else "NO" endif) ); } class Algo { static operation isOdd( n : int) : boolean pre: true post: true activity: ( return n mod 2 = 1 ); static operation isEven( n : int) : boolean pre: true post: true activity: ( return n mod 2 = 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); System.out.println((int)Math.pow(N,3)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(N->pow(3)->oclAsType(int)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { boolean main()throws IOException { Scanner sc=new Scanner(systemin); int N=sc.nextInt(); int M=sc.nextInt(); System.out.printf("%d\n",N*M); sc.close(); return false ; } PrintStream log ; PrintStream result=System.out ; BufferedReader systemin ; static Main instance=new Main(); Main(){ systemin=new BufferedReader(new InputStreamReader(System.in)); log=new PrintStream(new OutputStream(){ public void write(int b){ } } ); } public static void main(String[] args)throws IOException { instance.main(); instance.systemin.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation main() : boolean pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(systemin) ; var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; OclFile["System.out"].printf("%d\n", N * M) ; skip ; return false ); attribute log : OclFile; attribute result : OclFile := OclFile["System.out"]; attribute systemin : OclFile; static attribute instance : Main := Main.newMain(); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( systemin := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; log := OclFile.newOclFile_Write(OclFile()) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( instance.main() ; instance.systemin.close() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); System.out.println(m*n); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(m * n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static int findNature(int a,int b,int n){ int[] seq=new int[100]; seq[0]=a ; seq[1]=b ; for(int i=2 ; i<=n ; i++)seq[i]=seq[i-1]+seq[i-2]; if((seq[n] & 1)!=0)return 1 ; else return 0 ; } public static void main(String[] args){ int a=2,b=4 ; int n=3 ; if(findNature(a,b,n)==1)System.out.println("Odd "); else System.out.println("Even "); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findNature( a : int, b : int, n : int) : int pre: true post: true activity: ( var seq : Sequence(int) ; seq := Integer.subrange(1,100)->collect(0) ; seq[0+1] := a ; seq[1+1] := b ; var i : int ; i := 2 ; while i <= n do ( seq[i+1] := seq[i - 1+1] + seq[i - 2+1] ; ; i := i + 1 ) ; if ((seq[n+1] & 1) /= 0) then return 1 else return 0 ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 2 ; var b : int ; b := 4 ; var n : int ; n := 3 ; if (findNature(a, b, n) = 1) then OclFile["System.out"].println("Odd ") ; else OclFile["System.out"].println("Even ") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println(sc.nextInt()*sc.nextInt()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(sc.getCurrent()->toInteger() * sc.getCurrent()->toInteger()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int r=sc.nextInt(); int ans ; if(n>=10){ ans=r ; } else { ans=r+(100*(10-n)); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var ans : int ; if (n >= 10) then ( ans := r ) else ( ans := r + (100 * (10 - n)) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import static java.lang.System.out ; public class Main { static MyReader in=new MyReader(); public static void main(String[] args){ int N,R ; { int[] a=in.ii(); N=a[0]; R=a[1]; } int ans ; if(N>=10){ ans=R ; } else { ans=R+100*(10-N); } out.println(ans); } static class MyReader extends BufferedReader { MyReader(){ super(new InputStreamReader(System.in)); } String s(){ try { return readLine(); } catch(IOException e){ return "" ; } } String[] ss(){ return s().split(" "); } int i(){ return Integer.parseInt(s()); } int[] ii(){ String[] ss=ss(); int[] ii=new int[ss.length]; for(int j=0 ; jli(){ String[] ss=ss(); ArrayListli=new ArrayList<>(); for(int j=0 ; j= 10) then ( ans := R ) else ( ans := R + 100 * (10 - N) ) ; out.println(ans) ; ); static class MyReader extends OclFile { static operation newMyReader() : MyReader pre: true post: true activity: ( var self : MyReader ; self := createMyReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute super(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation s() : String pre: true post: true activity: ( try ( return readLine() ) catch (e : IOException) do ( return "" ) ); operation ss() : Sequence(String) pre: true post: true activity: ( return s()->split(" ") ); operation i() : int pre: true post: true activity: ( return (s())->toInteger() ); operation ii() : Sequence(int) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var ii : Sequence(int) ; ii := Integer.subrange(1,ss->size())->collect(0) ; var j : int ; j := 0 ; while j < ss->size() do ( ii[j+1] := (ss[j+1])->toInteger() ; ; j := j + 1 ) ; return ii ); operation li() : Sequence(int) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var li : Sequence(int) ; li := Sequence{} ; var j : int ; j := 0 ; while j < ss->size() do ( li := li->including((ss[j+1])->toInteger()) ; ; j := j + 1 ) ; return li ); operation l() : long pre: true post: true activity: ( return (s())->toLong() ); operation ll() : Sequence(long) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var ll : Sequence(long) ; ll := Integer.subrange(1,ss->size())->collect(0) ; var j : int ; j := 0 ; while j < ss->size() do ( ll[j+1] := (ss[j+1])->toLong() ; ; j := j + 1 ) ; return ll ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); final int MOD=1000000007 ; final int MAX=Integer.MAX_VALUE ; final long LMAX=Long.MAX_VALUE ; int LEN=(int)1e6+1 ; void doIt(){ int N=sc.nextInt(); int R=sc.nextInt(); System.out.println(R+(100*Math.max(10-N,0))); } public static void main(String[] args){ new Main().doIt(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute MOD : int := 1000000007; attribute MAX : int := 2147483647; attribute LMAX : long := "9223372036854775807"->toLong(); attribute LEN : int := 1e6->oclAsType(int) + 1; operation doIt() : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; var R : int ; R := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(R + (100 * Set{10 - N, 0}->max())) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(final String[] args)throws Exception { final Scanner sc=new Scanner(System.in); long N ; N=sc.nextLong(); long R ; R=sc.nextLong(); final Solver solver=new Solver(); solver.solve(N,R); } } class Solver { public void solve(long N,long R){ if(N<10){ System.out.println(R+(100*(10-N))); } else { System.out.println(R); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := sc.getCurrent()->toLong() ; var R : long ; R := sc.getCurrent()->toLong() ; var solver : Solver ; solver := Solver.newSolver() ; solver.solve(N, R) ; ); } class Solver { operation solve( N : long, R : long) : void pre: true post: true activity: ( if (N < 10) then ( OclFile["System.out"].println(R + (100 * (10 - N))) ) else ( OclFile["System.out"].println(R) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] data=br.readLine().split(" "); int numContest=Integer.parseInt(data[0]); int rate=Integer.parseInt(data[1]); if(numContest<10){ rate=rate+100*(10-numContest); } System.out.println(rate); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var data : Sequence(String) ; data := br.readLine()->split(" ") ; var numContest : int ; numContest := (data[0+1])->toInteger() ; var rate : int ; rate := (data[1+1])->toInteger() ; if (numContest < 10) then ( rate := rate + 100 * (10 - numContest) ) else skip ; OclFile["System.out"].println(rate) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); System.out.println((n*(n-1)/2)+(m*(m-1)/2)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; OclFile["System.out"].println((n * (n - 1) / 2) + (m * (m - 1) / 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.List ; import java.util.Scanner ; public class Main { static void solve(){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int v1=n*(n-1)/2 ; int v2=m*(m-1)/2 ; System.out.println(v1+v2); } public static void main(String[] args){ solve(); } class Counter extends HashMap{ public int get(int k){ return containsKey(k)? super.get(k): 0 ; } public void add(int k,int v){ put(k,get(k)+v); } } static class Node { int val ; Node next ; Node random ; public Node(int val){ this.val=val ; this.next=null ; this.random=null ; } } static class TreeNode { int val ; TreeNode left ; TreeNode right ; TreeNode(int x){ val=x ; } } static class Trie { void add(String word){ } boolean search(String w){ return false ; } } static class Node1 { public int val ; public Listchildren ; public Node1(){ } public Node1(int _val,List_children){ val=_val ; children=_children ; } }; static class TrieNode { } static class KvNode implements Comparable{ String key ; int freq ; public KvNode(String key,int freq){ this.key=key ; this.freq=freq ; } @ Override public int compareTo(KvNode o){ if(this.key.equals(o.key)){ return 0 ; } return Integer.compare(o.freq,this.freq); } } static class ListNode { int val ; ListNode next ; ListNode(int x){ val=x ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var v1 : int ; v1 := n * (n - 1) / 2 ; var v2 : int ; v2 := m * (m - 1) / 2 ; OclFile["System.out"].println(v1 + v2) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); class Counter extends Map(int,int) { operation get( k : int) : int pre: true post: true activity: ( return if containsKey(k) then super->at(k+1) else 0 endif ); operation add( k : int, v : int) : void pre: true post: true activity: ( execute put(k, at(k+1) + v) ); } static class Node { attribute val : int; attribute next : Node; attribute random : Node; static operation newNode( val : int) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(val); return self ); operation initialise( val : int) : void pre: true post: true activity: ( self.val := val ; self.next := null ; self.random := null ); } static class TreeNode { attribute val : int; attribute left : TreeNode; attribute right : TreeNode; static operation newTreeNode( x : int) : TreeNode pre: true post: true activity: ( var self : TreeNode ; self := createTreeNode(); self.initialise(x); return self ); operation initialise( x : int) : void pre: true post: true activity: ( val := x ); } static class Trie { operation add( word : String) : void pre: true post: true activity: skip; operation search( w : String) : boolean pre: true post: true activity: ( return false ); } static class Node1 { attribute val : int; attribute children : Sequence(Node1); static operation newNode1() : Node1 pre: true post: true activity: ( var self : Node1 ; self := createNode1(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: skip; static operation newNode1( _val : int, _children : Sequence(Node1)) : Node1 pre: true post: true activity: ( var self : Node1 ; self := createNode1(); self.initialise(_val, _children); return self ); operation initialise( _val : int, _children : Sequence(Node1)) : void pre: true post: true activity: ( val := _val ; children := _children ); } static class TrieNode { } static class KvNode implements Comparable { attribute key : String; attribute freq : int; static operation newKvNode( key : String, freq : int) : KvNode pre: true post: true activity: ( var self : KvNode ; self := createKvNode(); self.initialise(key, freq); return self ); operation initialise( key : String, freq : int) : void pre: true post: true activity: ( self.key := key ; self.freq := freq ); operation compareTo( o : KvNode) : int pre: true post: true activity: ( if (self.key = o.key) then ( return 0 ) else skip ; return compare(o.freq, self.freq) ); } static class ListNode { attribute val : int; attribute next : ListNode; static operation newListNode( x : int) : ListNode pre: true post: true activity: ( var self : ListNode ; self := createListNode(); self.initialise(x); return self ); operation initialise( x : int) : void pre: true post: true activity: ( val := x ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args)throws java.lang.Exception { Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int M=scanner.nextInt(); int nPlusMChoose2=(N+M)*(N+M-1)/2 ; int oddCombos=N*M ; int result=nPlusMChoose2-oddCombos ; System.out.printf("%d\n",result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; var M : int ; M := scanner.getCurrent()->toInteger() ; var nPlusMChoose2 : int ; nPlusMChoose2 := (N + M) * (N + M - 1) / 2 ; var oddCombos : int ; oddCombos := N * M ; var result : int ; result := nPlusMChoose2 - oddCombos ; OclFile["System.out"].printf("%d\n", result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { static int comb(int m,int n){ int res=1 ; if(n>m-n)n=m-n ; for(int i=0 ; i=2)total_ways+=comb(m,2); if(n>=2)total_ways+=comb(n,2); System.out.println(total_ways); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation comb( m : int, n : int) : int pre: true post: true activity: ( var res : int ; res := 1 ; if (n > m - n) then n := m - n ; else skip ; var i : int ; i := 0 ; while i < n do ( ( res := res*((m - i)) ; res := res/((i + 1)) ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var m : int ; m := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; var total_ways : int ; total_ways := 0 ; if (m >= 2) then total_ways := total_ways+(comb(m, 2)) ; else skip ; if (n >= 2) then total_ways := total_ways+(comb(n, 2)) ; else skip ; OclFile["System.out"].println(total_ways) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); Mapmap=new HashMap<>(); for(int i=0 ; i>list=new ArrayList<>(map.entrySet()); list.sort((e1,e2)->(e1.getValue()-e2.getValue())); int count=0 ; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var count : int ; count := (if map->keys()->contains(a) then map->at(a) else 0 endif) ; map := map->union(Map{a |-> (count + 1)}) ) ; i := i + 1 ) ; if (map.size() <= k) then ( OclFile["System.out"].println(0) ; return ) else skip ; var diff : int ; diff := map.size() - k ; var list : Sequence(Map(int,int)) ; list := Sequence{}->union(map->asSet()) ; list := list.sort(lambda (e1 , e2) : OclAny in (e1.getValue() - e2.getValue())) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < diff do ( ( count := count+(list->at(i+1).getValue()) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int num1=scan.nextInt(); int num2=scan.nextInt(); int n=(num1*(num1-1))/2 ; int m=(num2*(num2-1))/2 ; int sum=n+m ; System.out.println(sum); scan.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num1 : int ; num1 := scan.getCurrent()->toInteger() ; var num2 : int ; num2 := scan.getCurrent()->toInteger() ; var n : int ; n := (num1 * (num1 - 1)) / 2 ; var m : int ; m := (num2 * (num2 - 1)) / 2 ; var sum : int ; sum := n + m ; OclFile["System.out"].println(sum) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Solution { public int findRadius(int[] houses,int[] heaters){ Arrays.sort(heaters); int result=Integer.MIN_VALUE ; for(int house : houses){ int index=Arrays.binarySearch(heaters,house); if(index<0)index=-(index+1); int dist1=index-1>=0 ? house-heaters[index-1] : Integer.MAX_VALUE ; int dist2=indexsort() ; var result : int ; result := -2147483648 ; for (house : houses) do ( ( var index : int ; index := (heaters->indexOf(house) - 1) ; if (index < 0) then index := -(index + 1) ; else skip ; var dist1 : int ; dist1 := if index - 1 >= 0 then house - heaters[index - 1+1] else 2147483647 endif ; var dist2 : int ; dist2 := if index < heaters->size() then heaters[index+1] - house else 2147483647 endif ; result := Set{result, Set{dist1, dist2}->min()}->max() ; ) ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t--!=0){ int n=scanner.nextInt(); int k=scanner.nextInt(); if(n % k==0){ System.out.println(1); continue ; } if(n==1){ System.out.println(k); continue ; } if(ntoInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; if (n mod k = 0) then ( OclFile["System.out"].println(1) ; continue ) else skip ; if (n = 1) then ( OclFile["System.out"].println(k) ; continue ) else skip ; if (n < k) then ( OclFile["System.out"].println(if k mod n = 0 then k / n else k / n + 1 endif) ) else ( OclFile["System.out"].println(((n / k + 1) * k - n) / n + 2) ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class SumD { int number ; public SumD(int number){ this.number=number ; } public int getNumber(){ return number ; } public void input(int n,int k){ int count=n ; int index=0 ; if(k>=n){ count=k ; index++; } while(true){ if(count % k==0){ break ; } if(index==0){ if(2*k>n){ count+=(k*2-n); } else { int c=n-k ; if((c/(double)k)% 1==0){ count=(c/k)*k ; } else { count=((c/k)+1)*k ; } } if(count= n) then ( count := k ; index := index + 1 ) else skip ; while (true) do ( if (count mod k = 0) then ( break ) else skip ; if (index = 0) then ( if (2 * k > n) then ( count := count+((k * 2 - n)) ) else ( var c : int ; c := n - k ; if ((c / k->oclAsType(double)) mod 1 = 0) then ( count := (c / k) * k ) else ( count := ((c / k) + 1) * k ) ) ; if (count < n) then ( count := count+(k) ) else skip ; index := index + 1 ) else ( count := count+(k) ) ) ; if ((count / n->oclAsType(double)) mod 1 = 0) then ( OclFile["System.out"].println(count / n) ) else ( OclFile["System.out"].println((count / n) + 1) ) ; ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : SumD ; instance := SumD.newSumD(number) ; var i : int ; i := 0 ; while i < instance.getNumber() do ( ( var num1 : int ; num1 := input.getCurrent()->toInteger() ; var num2 : int ; num2 := input.getCurrent()->toInteger() ; instance.input(num1, num2) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; ik)System.out.println("2"); else System.out.println(k/n+1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : long ; n := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; if (n mod k = 0) then OclFile["System.out"].println("1") ; else if (k mod n = 0) then OclFile["System.out"].println(k / n) else if (n > k) then OclFile["System.out"].println("2") else OclFile["System.out"].println(k / n + 1) ; ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int prev=sc.nextInt(); int count=0 ; for(int i=1 ; itoInteger() ; var prev : int ; prev := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (prev < x) then ( count := count + 1 ) else skip ; prev := x ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] nums=new int[n]; int ans=0 ; for(int i=0 ; itoInteger() ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( nums[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( if (nums[i+1] < nums[i + 1+1]) then ans := ans + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long m=sc.nextLong(); long count=0 ; long[] array=new long[3]; Arrays.sort(array); System.out.println(1.0*n/m); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var m : long ; m := sc.getCurrent()->toLong() ; var count : long ; count := 0 ; var array : Sequence(long) ; array := Integer.subrange(1,3)->collect(0) ; array := array->sort() ; OclFile["System.out"].println(1.0 * n / m) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.UncheckedIOException ; import java.util.StringTokenizer ; class Main { public static void main(String[] args){ SC sc=new SC(System.in); double T=sc.nextDouble(); double X=sc.nextDouble(); pl(T/X); } public static void pl(Object o){ System.out.println(o); } public static void pl(){ System.out.println(); } public static void p(Object o){ System.out.print(o); } static class SC { private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public SC(InputStream in){ reader=new BufferedReader(new InputStreamReader(in)); } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new UncheckedIOException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public String nextLine(){ try { return reader.readLine(); } catch(IOException e){ throw new UncheckedIOException(e); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : SC ; sc := SC.newSC(OclFile["System.in"]) ; var T : double ; T := sc.nextDouble() ; var X : double ; X := sc.nextDouble() ; execute pl(T / X) ); static operation pl( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o) ); static operation pl() : void pre: true post: true activity: ( OclFile["System.out"].println() ); static operation p( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].print(o) ); static class SC { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newSC( in : OclFile) : SC pre: true post: true activity: ( var self : SC ; self := createSC(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ) else skip ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int x=sc.nextInt(); double ans=(double)t/x ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var ans : double ; ans := t->oclAsType(double) / x ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader r=new BufferedReader(new InputStreamReader(System.in),1); String s=r.readLine(); String[] sl=s.split(" "); int n=Integer.parseInt(sl[0]); int m=Integer.parseInt(sl[1]); System.out.println((double)n/m); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), 1) ; var s : String ; s := r.readLine() ; var sl : Sequence(String) ; sl := s->split(" ") ; var n : int ; n := (sl[0+1])->toInteger() ; var m : int ; m := (sl[1+1])->toInteger() ; OclFile["System.out"].println(n->oclAsType(double) / m) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.util.Collections ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); NotsoDiverse solver=new NotsoDiverse(); solver.solve(1,in,out); out.close(); } static class NotsoDiverse { int[] cnt=new int[200001]; public void solve(int testNumber,InputReader in,PrintWriter out){ int N=in.nextInt(); int K=in.nextInt(); for(int i=0 ; iarr=new ArrayList<>(); for(int i=0 ; i0){ arr.add(cnt[i]); } } Collections.sort(arr); int ans=0 ; for(int i=0 ; icollect(0); operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var N : int ; N := in.nextInt() ; var K : int ; K := in.nextInt() ; var i : int ; i := 0 ; while i < N do ( ( cnt[in.nextInt()+1] := cnt[in.nextInt()+1] + 1 ) ; i := i + 1 ) ; var arr : Sequence(int) ; arr := Sequence{} ; var i : int ; i := 0 ; while i < cnt->size() do ( ( if (cnt[i+1] > 0) then ( arr := arr->including(cnt[i+1]) ) else skip ) ; i := i + 1 ) ; arr := arr->sort() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < arr->size() - K do ( ( ans := ans+(arr->at(i+1)) ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countWays(int n,int arr[],int k){ if(k<=0 || k>=n)return 0 ; Sets=new HashSet(); for(int i=0 ; i= n) then return 0 else skip ; var s : Set(int) ; s := Set{} ; var i : int ; i := 0 ; while i < n do ( s := s->including(arr[i+1]) ; ; i := i + 1 ) ; if (s->size() <= k) then return 0 else skip ; return s->size() - k ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{100,200,400,50} ; var k : int ; k := 3 ; var n : int ; n := arr->size() ; OclFile["System.out"].println(countWays(n, arr, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int[][] move={ { 1,0 },{ 0,1 },{ -1,0 },{ 0,-1 } }; while(true){ int c=sc.nextInt(); int r=sc.nextInt(); if((r | c)==0)break ; int ri=1 ; int rj=1 ; int dir=0 ; while(true){ String cmd=sc.next(); if("STOP".equals(cmd)){ System.out.println(rj+" "+ri); break ; } if("RIGHT".equals(cmd))dir=(dir+1)% 4 ; else if("LEFT".equals(cmd))dir=(dir+3)% 4 ; else if("FORWARD".equals(cmd)){ int k=sc.nextInt(); while(k--!=0){ int ni=ri+move[dir][0]; int nj=rj+move[dir][1]; if(1<=ni && ni<=r && 1<=nj && nj<=c){ ri=ni ; rj=nj ; } else break ; } } else { int k=sc.nextInt(); while(k--!=0){ int ni=ri+move[(dir+2)% 4][0]; int nj=rj+move[(dir+2)% 4][1]; if(1<=ni && ni<=r && 1<=nj && nj<=c){ ri=ni ; rj=nj ; } else break ; } } } } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var move : Sequence(Sequence(int)) ; move := Sequence{Sequence{1,0},Sequence{0,1},Sequence{-1,0},Sequence{0,-1}} ; while (true) do ( var c : int ; c := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(r,c)) = 0) then break else skip ; var ri : int ; ri := 1 ; var rj : int ; rj := 1 ; var dir : int ; dir := 0 ; while (true) do ( var cmd : String ; cmd := sc.getCurrent() ; if ("STOP" = cmd) then ( OclFile["System.out"].println(rj + " " + ri) ; break ) else skip ; if ("RIGHT" = cmd) then dir := (dir + 1) mod 4 ; else if ("LEFT" = cmd) then dir := (dir + 3) mod 4 else if ("FORWARD" = cmd) then ( var k : int ; k := sc.getCurrent()->toInteger() ; while (k /= 0) do ( skip ; ( var ni : int ; ni := ri + move[dir+1][0+1] ; var nj : int ; nj := rj + move[dir+1][1+1] ; if (1 <= ni & ni <= r & 1 <= nj & nj <= c) then ( ri := ni ; rj := nj ) else break ) ; ) ) else ( var k : int ; k := sc.getCurrent()->toInteger() ; while (k /= 0) do ( skip ; ( var ni : int ; ni := ri + move[(dir + 2) mod 4+1][0+1] ; var nj : int ; nj := rj + move[(dir + 2) mod 4+1][1+1] ; if (1 <= ni & ni <= r & 1 <= nj & nj <= c) then ( ri := ni ; rj := nj ) else break ) ; ) ) ; ; ) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println(sc.nextInt()/sc.nextDouble()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(sc.getCurrent()->toInteger() / sc.getCurrent()->toReal()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { boolean main()throws IOException { Scanner sc=new Scanner(systemin); int N=sc.nextInt(); long sum=0 ; for(int i=0 ; itoInteger() ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; sum := sum+(v - i - 1) ) ; i := i + 1 ) ; OclFile["System.out"].printf("%d\n", sum) ; skip ; return false ); attribute log : OclFile; attribute result : OclFile := OclFile["System.out"]; attribute systemin : OclFile; static attribute instance : Main := Main.newMain(); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( systemin := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; log := OclFile.newOclFile_Write(OclFile()) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( instance.main() ; instance.systemin.close() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long total=0 ; for(int i=0 ; itoInteger() ; var total : long ; total := 0 ; var i : int ; i := 0 ; while i < n do ( ( total := total+(sc.getCurrent()->toInteger() - (i + 1)) ) ; i := i + 1 ) ; OclFile["System.out"].println(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextInt(); long ans=0 ; for(int i=0 ; itoInteger() ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ans := ans+(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; OclFile["System.out"].println(ans - n * (n + 1) / 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ solve(); } private static void solve(){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); System.out.println(Math.max(0,n/2)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); static operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(Set{0, n / 2}->max()) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ solve(); } private static void solve(){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int max=0 ; for(int i=1 ; i<=n ; i++){ max=Math.max(0,n/2); } System.out.println(max); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); static operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var max : int ; max := 0 ; var i : int ; i := 1 ; while i <= n do ( ( max := Set{0, n / 2}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class actividad { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(),n ; while(t-->0){ n=in.nextInt(); if(n % 2==0){ System.out.println(n/2); } else { System.out.println((n-1)/2); } } } } ------------------------------------------------------------ OCL File: --------- class actividad { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var n : int ; while (t > 0) do ( t := t - 1 ; skip ; ( n := in.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(n / 2) ) else ( OclFile["System.out"].println((n - 1) / 2) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int k=in.nextInt(); while(k>0){ int n=in.nextInt(); System.out.println((int)Math.floor(n/2)); k--; } in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := in.getCurrent()->toInteger() ; while (k > 0) do ( var n : int ; n := in.getCurrent()->toInteger() ; OclFile["System.out"].println((n / 2)->floor()->oclAsType(int)) ; k := k - 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MaximumGCD1370A { private static int n=1000001 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=Integer.parseInt(sc.nextLine()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := (sc.nextLine())->toInteger() ; OclFile["System.out"].println(n / 2) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class test { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n % 2==0){ System.out.println("0"); } else { System.out.println("1"); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println("0") ) else ( OclFile["System.out"].println("1") ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p130 implements EulerSolution { public static void main(String[] args){ System.out.println(new p130().run()); } public String run(){ int sum=0 ; int found=0 ; for(int i=7 ; found<25 ; i+=2){ if(i % 5!=0 && ! Library.isPrime(i)&&(i-1)% findLeastDivisibleRepunit(i)==0){ sum+=i ; found++; } } return Integer.toString(sum); } private static int findLeastDivisibleRepunit(int n){ if(n % 2==0 || n % 5==0)return 0 ; if(n>Integer.MAX_VALUE/10)throw new IllegalArgumentException("Arithmetic overflow"); int sum=1 ; int pow=1 ; int k=1 ; while(sum % n!=0){ k++; pow=pow*10 % n ; sum=(sum+pow)% n ; } return k ; } } ------------------------------------------------------------ OCL File: --------- class p130 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p130.newp130().run()) ); operation run() : String pre: true post: true activity: ( var sum : int ; sum := 0 ; var found : int ; found := 0 ; var i : int ; i := 7 ; while found < 25 do ( ( if (i mod 5 /= 0 & not(Library.isPrime(i)) & (i - 1) mod findLeastDivisibleRepunit(i) = 0) then ( sum := sum+(i) ; found := found + 1 ) else skip ) ; i := i+(2) ) ; return ((sum) + "") ); static operation findLeastDivisibleRepunit( n : int) : int pre: true post: true activity: ( if (n mod 2 = 0 or n mod 5 = 0) then return 0 else skip ; if (n > 2147483647 / 10) then error IllegalArgumentException.newIllegalArgumentException("Arithmetic overflow") ; else skip ; var sum : int ; sum := 1 ; var pow : int ; pow := 1 ; var k : int ; k := 1 ; while (sum mod n /= 0) do ( k := k + 1 ; pow := pow * 10 mod n ; sum := (sum + pow) mod n ) ; return k ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int NumberOfSolutions(int x,int y,int z,int n){ int ans=0 ; for(int i=0 ; i<=x ; i++){ for(int j=0 ; j<=y ; j++){ int temp=n-i-j ; if(temp>=0){ temp=Math.min(temp,z); ans+=temp+1 ; } } } return ans ; } public static void main(String[] args){ int x=1,y=2,z=3,n=4 ; System.out.println(NumberOfSolutions(x,y,z,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation NumberOfSolutions( x : int, y : int, z : int, n : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i <= x do ( ( var j : int ; j := 0 ; while j <= y do ( ( var temp : int ; temp := n - i - j ; if (temp >= 0) then ( temp := Set{temp, z}->min() ; ans := ans+(temp + 1) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 1 ; var y : int ; y := 2 ; var z : int ; z := 3 ; var n : int ; n := 4 ; OclFile["System.out"].println(NumberOfSolutions(x, y, z, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Map.Entry ; import java.io.*; public class Main { public static void main(String[] args){ MyScanner sc=new MyScanner(); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); int k=sc.nextInt(); TreeMapmap=new TreeMap(); while(n-->0){ int x=sc.nextInt(); map.put(x,map.getOrDefault(x,0)+1); } ArrayListc=new ArrayList(); for(Entrye : map.entrySet()){ c.add(e.getValue()); } if(c.size()<=k)pw.println(0); else { Collections.sort(c); int ans=0 ; for(int i=0 ; i 0) do ( n := n - 1 ; skip ; ( var x : int ; x := sc.nextInt() ; map := map->union(Map{x |-> (if map->keys()->contains(x) then map->at(x) else 0 endif) + 1}) ) ; ) ; var c : Sequence(int) ; c := Sequence{} ; for (e : map->asSet()) do ( ( c := c->including(e.getValue()) ) ) ; if (c->size() <= k) then skip else ( c := c->sort() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < c->size() - k do ( ans := ans+(c->at(i+1)) ; ; i := i + 1 ) ; skip ) ; skip ; skip ; ); static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : ProgramException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); System.out.println(n % 2==0 ? "0" : "1"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; OclFile["System.out"].println(if n mod 2 = 0 then "0" else "1" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int K=sc.nextInt(); System.out.println((K/2)*((K+1)/2)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : int ; K := sc.getCurrent()->toInteger() ; OclFile["System.out"].println((K / 2) * ((K + 1) / 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); int result=(int)Math.pow(k/2,2); if(k % 2==1)result=(k/2)*(k/2+1); System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var result : int ; result := k / 2->pow(2)->oclAsType(int) ; if (k mod 2 = 1) then result := (k / 2) * (k / 2 + 1) ; else skip ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int k=sc.nextInt(); if(k % 2==0){ System.out.println((int)Math.pow((k/2),2)); } else { System.out.println((k/2)*(k/2+1)); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var k : int ; k := sc.getCurrent()->toInteger() ; if (k mod 2 = 0) then ( OclFile["System.out"].println((k / 2)->pow(2)->oclAsType(int)) ) else ( OclFile["System.out"].println((k / 2) * (k / 2 + 1)) ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); System.out.println(n/2*(n/2+n % 2)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; OclFile["System.out"].println(n / 2 * (n / 2 + n mod 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int K=scanner.nextInt(); scanner.close(); int num=0 ; for(int n=1 ; n<=K ; n++){ for(int m=1 ; m<=K ; m++){ if(n<=m){ continue ; } if(n % 2==0){ if(m % 2==1){ num++; } else { continue ; } } else { if(m % 2==0){ num++; } else { continue ; } } } } System.out.println(num); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : int ; K := scanner.getCurrent()->toInteger() ; skip ; var num : int ; num := 0 ; var n : int ; n := 1 ; while n <= K do ( ( var m : int ; m := 1 ; while m <= K do ( ( if (n <= m) then ( continue ) else skip ; if (n mod 2 = 0) then ( if (m mod 2 = 1) then ( num := num + 1 ) else ( continue ) ) else ( if (m mod 2 = 0) then ( num := num + 1 ) else ( continue ) ) ) ; m := m + 1 ) ) ; n := n + 1 ) ; OclFile["System.out"].println(num) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n < 9) then ( OclFile["System.out"].println("0") ) else if (n = 9) then ( OclFile["System.out"].println("1") ) else ( if (n mod 10 = 9) then ( OclFile["System.out"].println(n / 10 + 1) ) else ( OclFile["System.out"].println(n / 10) ) ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.util.*; public class ques { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var ans : int ; ans := n / 10 ; if (n mod 10 = 9) then ( ans := ans + 1 ) else skip ; OclFile["System.out"].println(ans) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] sa=br.readLine().split(" "); long[] a=new long[n]; for(int i=0 ; i0){ cnt[j]+=x % 2 ; x/=2 ; j++; } } long ans=0 ; for(int i=0 ; itoInteger() ; var sa : Sequence(String) ; sa := br.readLine()->split(" ") ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (sa[i+1])->toLong() ) ; i := i + 1 ) ; skip ; var cnt : Sequence(int) ; cnt := Integer.subrange(1,61)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; var x : long ; x := a[i+1] ; while (x > 0) do ( cnt[j+1] := cnt[j+1]+(x mod 2) ; x := x/(2) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < cnt->size() do ( ( var val : long ; val := cnt[i+1]->oclAsType(long) * (n - cnt[i+1]) ; val := val mod 1000000007 ; var val2 : long ; val2 := ((1L*(2->pow(i)))->oclAsType(long)) ; val2 := val2 mod 1000000007 ; val := val*(val2) ; val := val mod 1000000007 ; ans := ans+(val) ; ans := ans mod 1000000007 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); System.out.println((int)((n+1)/10)); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(((n + 1) / 10)->oclAsType(int)) ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1285A_MezoPlayingZoma { public static void main(String[] args){ Scanner input=new Scanner(System.in); int len=parseInt(input.nextLine()); String moves=input.nextLine(); int max=0 ; int min=0 ; for(char c : moves.toCharArray()){ if(c=='R'){ max++; } else if(c=='L'){ min--; } } System.out.println(max-min+1); } } ------------------------------------------------------------ OCL File: --------- class _1285A_MezoPlayingZoma { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var len : int ; len := parseInt(input.nextLine()) ; var moves : String ; moves := input.nextLine() ; var max : int ; max := 0 ; var min : int ; min := 0 ; for (c : moves->characters()) do ( ( if (c = 'R') then ( max := max + 1 ) else if (c = 'L') then ( min := min - 1 ) else skip ; ) ) ; OclFile["System.out"].println((max)->char2byte() - min + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().solve(new Scanner(System.in),new PrintWriter(System.out)); } private void solve(Scanner in,PrintWriter out){ int n=in.nextInt(),k=in.nextInt(); int[] a=new int[n]; for(int i=0 ; isegs=new ArrayList<>(); int size=1 ; for(int i=1 ; i(){ @ Override public int compare(Integer a,Integer b){ return a-b ; } } ); int ans=0 ; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.nextInt() ) ; i := i + 1 ) ; a := a->sort() ; var segs : Sequence(int) ; segs := Sequence{} ; var size : int ; size := 1 ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] = a[i - 1+1]) then ( size := size + 1 ) else ( segs := segs->including(size) ; size := 1 ) ) ; i := i + 1 ) ; segs := segs->including(size) ; segs := segs.sort(OclComparator.newOclComparator()) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < segs->size() - k do ( ( ans := ans+(segs->at(i+1)) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.next(); System.out.println(n+1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; skip ; OclFile["System.out"].println(n + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test237 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); in.next(); System.out.println((n+1)); in.close(); } } ------------------------------------------------------------ OCL File: --------- class test237 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; skip ; OclFile["System.out"].println((n + 1)) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class dice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t,j,x ; t=sc.nextInt(); for(j=1 ; j<=t ; j++){ x=sc.nextInt(); System.out.println((int)Math.ceil(x/7.0)); } } } ------------------------------------------------------------ OCL File: --------- class dice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; var j : int ; var x : int ; t := sc.getCurrent()->toInteger() ; j := 1 ; while j <= t do ( ( x := sc.getCurrent()->toInteger() ; OclFile["System.out"].println((x / 7.0)->ceil()->oclAsType(int)) ) ; j := j + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(x / 2) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int x=sc.nextInt(); if(x>=2 && x<=7)System.out.println(1); else { int temp=x/7 ; System.out.println(temp+1); } } } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x >= 2 & x <= 7) then OclFile["System.out"].println(1) ; else ( var temp : int ; temp := x / 7 ; OclFile["System.out"].println(temp + 1) ) ) ; ) ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DisgnToturial { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); if(n % 2==0){ System.out.println(8+" "+(n-8)); } else { System.out.println(9+" "+(n-9)); } } } ------------------------------------------------------------ OCL File: --------- class DisgnToturial { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(8 + " " + (n - 8)) ) else ( OclFile["System.out"].println(9 + " " + (n - 9)) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.BorderLayout ; import static java.lang.Math.*; import java.math.BigDecimal ; import java.text.DecimalFormat ; import java.util.Scanner ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.BitSet ; import java.util.Collection ; import java.util.Collections ; import java.util.Comparator ; import java.util.Deque ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Iterator ; import java.util.LinkedList ; import java.util.List ; import java.util.Map ; import java.util.Queue ; import java.util.Set ; import java.util.Stack ; import java.util.TreeSet ; import java.util.Vector ; import java.util.concurrent.atomic.AtomicMarkableReference ; import java.util.Scanner ; public class NewClass1 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int a=in.nextInt(); if(a % 2==0)System.out.print("4"+" "+(a-4)); else System.out.println("9"+" "+(a-9)); } } ------------------------------------------------------------ OCL File: --------- class NewClass1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := in.getCurrent()->toInteger() ; if (a mod 2 = 0) then OclFile["System.out"].print("4" + " " + (a - 4)) ; else OclFile["System.out"].println("9" + " " + (a - 9)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintStream ; import java.util.Arrays ; import java.util.Scanner ; public class Main { static final PrintStream out=System.out ; static final Scanner sc=new Scanner(System.in); static final long Mod=1000_000_007L ; public static void main(String[] args){ Main main=new Main(); main.solve(); System.exit(0); } void solve(){ int N=nextInt(); long[] A=new long[3*100000+5]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := nextLong() ) ; i := i + 1 ) ; var res : long ; res := 0 ; var k : int ; k := 0 ; while k < 60 do ( ( var t : long ; t := (1L*(2->pow(k)))->oclAsType(long) ; var x : int ; x := 0 ; var y : int ; y := 0 ; var i : int ; i := 0 ; while i < N do ( ( if ((A[i+1] & t) = t) then x := x + 1 ; else y := y + 1 ; ) ; i := i + 1 ) ; res := res+(t mod Mod * x mod Mod * y mod Mod) ; res := res mod Mod ; ) ; k := k + 1 ) ; skip ; ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLongArray( n : int) : Sequence(long) pre: true post: true activity: ( var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextLong() ; ; i := i + 1 ) ; return a ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation next() : String pre: true post: true activity: ( return sc.getCurrent() ); operation gcd( m : long, n : long) : long pre: true post: true activity: ( if (m < n) then return gcd(n, m) else skip ; if (n = 0) then return m else skip ; return gcd(n, m mod n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Solution { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); for(int i=2 ; itoInteger() ; var i : int ; i := 2 ; while i < n do ( ( if (not((i + "")->toLong().isProbablePrime(100)) & not((n - i + "")->toLong().isProbablePrime(100))) then ( OclFile["System.out"].println(i + " " + (n - i)) ; return ) else skip ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class problem472A { public static void main(String[] args){ new problem472A().solve(); } Scanner in ; private void solve(){ in=new Scanner(System.in); int n=in.nextInt(); if(n % 2==0){ System.out.println(4+" "+(n-4)); } else { System.out.println(9+" "+(n-9)); } } } ------------------------------------------------------------ OCL File: --------- class problem472A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( problem472A.newproblem472A().solve() ); attribute in : OclFile; operation solve() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(4 + " " + (n - 4)) ) else ( OclFile["System.out"].println(9 + " " + (n - 9)) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class CodeForce { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n % 2==0){ System.out.print(4+" "); System.out.println(n-4); } else { System.out.print(9+" "); System.out.println(n-9); } } } ------------------------------------------------------------ OCL File: --------- class CodeForce { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].print(4 + " ") ; OclFile["System.out"].println(n - 4) ) else ( OclFile["System.out"].print(9 + " ") ; OclFile["System.out"].println(n - 9) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { Reader rd=new Reader(System.in); int N=rd.nextInt(); int K=rd.nextInt(); int counter=0 ; int[] aNum=new int[N]; for(int i=0 ; i0)K--; else ans+=aNum[N-i-1]; } System.out.println(ans); } } class Reader { private BufferedReader br ; private StringTokenizer st ; public Reader(InputStream in){ br=new BufferedReader(new InputStreamReader(in)); st=null ; } public String nextString()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(nextString()); } public long nextLong()throws IOException { return Long.parseLong(nextString()); } public double nextDouble()throws IOException { return Double.parseDouble(nextString()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var rd : OclFile ; rd := OclFile(OclFile["System.in"]) ; var N : int ; N := rd.getCurrent()->toInteger() ; var K : int ; K := rd.getCurrent()->toInteger() ; var counter : int ; counter := 0 ; var aNum : Sequence(int) ; aNum := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( aNum[rd.getCurrent()->toInteger() - 1+1] := aNum[rd.getCurrent()->toInteger() - 1+1] + 1 ) ; i := i + 1 ) ; aNum := aNum->sort() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (K > 0) then K := K - 1 ; else ans := ans+(aNum[N - i - 1+1]) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } class Reader { attribute br : OclFile; attribute st : OclIterator; static operation newReader( in : OclFile) : Reader pre: true post: true activity: ( var self : Reader ; self := createReader(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; st := null ); operation nextString() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (nextString())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (nextString())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (nextString())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Mavenproject5 { public static void main(String[] args){ Scanner read=new Scanner(System.in); int width=read.nextInt(); int length=read.nextInt(); int dominos ; dominos=width*length/2 ; System.out.println(dominos); } } ------------------------------------------------------------ OCL File: --------- class Mavenproject5 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var read : OclFile ; read := OclFile.newOclFile_Read(OclFile["System.in"]) ; var width : int ; width := read.getCurrent()->toInteger() ; var length : int ; length := read.getCurrent()->toInteger() ; var dominos : int ; dominos := width * length / 2 ; OclFile["System.out"].println(dominos) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Domino_piling { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int x=sc.nextInt(); int y=sc.nextInt(); int prod=x*y ; if(prod % 2!=0){ System.out.println((prod-1)/2); } else { System.out.println(prod/2); } } } } ------------------------------------------------------------ OCL File: --------- class Domino_piling { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var prod : int ; prod := x * y ; if (prod mod 2 /= 0) then ( OclFile["System.out"].println((prod - 1) / 2) ) else ( OclFile["System.out"].println(prod / 2) ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int M=sc.nextInt(); int N=sc.nextInt(); int s=M*N ; System.out.println(s/2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var M : int ; M := sc.getCurrent()->toInteger() ; var N : int ; N := sc.getCurrent()->toInteger() ; var s : int ; s := M * N ; OclFile["System.out"].println(s / 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); int a=sc.nextInt(); int takes=k*a/2 ; System.out.println(takes); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var takes : int ; takes := k * a / 2 ; OclFile["System.out"].println(takes) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Codeforces { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int k=in.nextInt(); System.out.println((n*k)/2); } } ------------------------------------------------------------ OCL File: --------- class Codeforces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; OclFile["System.out"].println((n * k) / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test140 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var a : int ; a := in.getCurrent()->toInteger() ; if (a mod 2 = 0) then ( OclFile["System.out"].println(a / 2) ) else ( OclFile["System.out"].println((a + 1) / 2) ) ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ long startTime=System.currentTimeMillis(); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long div=(long)Math.pow(10,9)+7 ; long[] A=new long[n]; long ans=0 ; for(int i=0 ; i>i & 1)==1)count1++; } a=a+count1*(n-count1); for(int j=0 ; jtoInteger() ; var div : long ; div := 10->pow(9)->oclAsType(long) + 7 ; var A : Sequence(long) ; A := Integer.subrange(1,n)->collect(0) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 60 do ( ( var a : long ; a := 0 ; var count1 : long ; count1 := 0 ; var j : int ; j := 0 ; while j < n do ( ( if ((MathLib.bitwiseAnd((A[j+1]/(2->pow(i)))->oclAsType(long),1)) = 1) then count1 := count1 + 1 ; else skip ) ; j := j + 1 ) ; a := a + count1 * (n - count1) ; var j : int ; j := 0 ; while j < i do ( ( a := ((a*(2->pow(1)))->oclAsType(long)) mod div ) ; j := j + 1 ) ; ans := ans+(a) ; ans := ans mod div ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; var endTime : long ; endTime := OclDate.getSystemTime() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1371A_MagicalSticks { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ int num=parseInt(input.nextLine()); if(num % 2==0){ System.out.println(num/2); } else { System.out.println(num/2+1); } } } } ------------------------------------------------------------ OCL File: --------- class _1371A_MagicalSticks { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; while (test > 0) do ( test := test - 1 ; skip ; ( var num : int ; num := parseInt(input.nextLine()) ; if (num mod 2 = 0) then ( OclFile["System.out"].println(num / 2) ) else ( OclFile["System.out"].println(num / 2 + 1) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Exersise { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int[] array=new int[n]; for(int i=0 ; itoInteger() ; var array : Sequence(int) ; array := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < array->size() do ( ( array[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < array->size() do ( ( if (array[i+1] mod 2 = 0) then ( OclFile["System.out"].println(array[i+1] / 2) ) else ( OclFile["System.out"].println(array[i+1] / 2 + 1) ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MagicalStick { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); if(n % 2==0){ System.out.println(n/2); } else { System.out.println((n/2)+1); } t--; } } } ------------------------------------------------------------ OCL File: --------- class MagicalStick { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(n / 2) ) else ( OclFile["System.out"].println((n / 2) + 1) ) ; t := t - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NewClass22 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int a=in.nextInt(); if(a % 2==0){ System.out.println(a/2); } else if(a==1){ System.out.println(1); } else System.out.println(a/2+1); } } } ------------------------------------------------------------ OCL File: --------- class NewClass22 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : int ; a := in.getCurrent()->toInteger() ; if (a mod 2 = 0) then ( OclFile["System.out"].println(a / 2) ) else if (a = 1) then ( OclFile["System.out"].println(1) ) else OclFile["System.out"].println(a / 2 + 1) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class LC { static class pair { int l,r ; public pair(int l,int r){ this.l=l ; this.r=r ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayListfirst=new ArrayList<>(); ArrayListsec=new ArrayList<>(); ArrayListmoves=new ArrayList<>(); long sum=0 ; for(int i=0 ; i0){ System.out.println("first"); return ; } else if(sum<0){ System.out.println("second"); return ; } else { for(int i=0 ; isec.get(i)){ System.out.println("first"); return ; } if(sec.get(i)>first.get(i)){ System.out.println("second"); return ; } } } if(moves.get(moves.size()-1)>0)System.out.println("first"); else System.out.println("second"); } } ------------------------------------------------------------ OCL File: --------- class LC { static class pair { attribute l : int; static operation newpair( l : int, r : int) : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(l, r); return self ); operation initialise( l : int, r : int) : void pre: true post: true activity: ( self.l := l ; self.r := r ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var first : Sequence(int) ; first := Sequence{} ; var sec : Sequence(int) ; sec := Sequence{} ; var moves : Sequence(int) ; moves := Sequence{} ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var temp : int ; temp := sc.getCurrent()->toInteger() ; moves := moves->including(temp) ; sum := sum+(temp) ; if (temp < 0) then sec := sec->including(-1 * temp) ; else first := first->including(temp) ; ) ; i := i + 1 ) ; if (sum > 0) then ( OclFile["System.out"].println("first") ; return ) else if (sum < 0) then ( OclFile["System.out"].println("second") ; return ) else ( var i : int ; i := 0 ; while i < first->size() & i < sec->size() do ( ( if (first->at(i+1) > sec->at(i+1)) then ( OclFile["System.out"].println("first") ; return ) else skip ; if (sec->at(i+1) > first->at(i+1)) then ( OclFile["System.out"].println("second") ; return ) else skip ) ; i := i + 1 ) ) ; ; if (moves->at(moves->size() - 1+1) > 0) then OclFile["System.out"].println("first") else OclFile["System.out"].println("second") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long n=sc.nextInt(); for(int i=1 ; i<=n ; i++){ long t=sc.nextInt(); System.out.println(t); } } } ------------------------------------------------------------ OCL File: --------- class test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( var t : long ; t := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(t) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class sol { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(a) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t>0){ int n=scn.nextInt(); System.out.println(n); t--; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scn.getCurrent()->toInteger() ; while (t > 0) do ( var n : int ; n := scn.getCurrent()->toInteger() ; OclFile["System.out"].println(n) ; t := t - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); System.out.println(n); } } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(n) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class A_Bachgold_Problem { public static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader reader=new FastReader(); int N=reader.nextInt(); int count=0 ; if(N % 2==0){ count=N/2 ; System.out.print(count+"\n"); for(int i=1 ; i<=count ; i++){ System.out.print(2+" "); } } else { if(N % 2==1){ count=N/2 ; int num=count-1 ; System.out.print(count+"\n"); for(int i=1 ; i<=num ; i++){ System.out.print(2+" "); } System.out.print(3); } } } } ------------------------------------------------------------ OCL File: --------- class A_Bachgold_Problem { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : FastReader ; reader := FastReader.newFastReader() ; var N : int ; N := reader.nextInt() ; var count : int ; count := 0 ; if (N mod 2 = 0) then ( count := N / 2 ; OclFile["System.out"].print(count + "\n") ; var i : int ; i := 1 ; while i <= count do ( ( OclFile["System.out"].print(2 + " ") ) ; i := i + 1 ) ) else ( if (N mod 2 = 1) then ( count := N / 2 ; var num : int ; num := count - 1 ; OclFile["System.out"].print(count + "\n") ; var i : int ; i := 1 ; while i <= num do ( ( OclFile["System.out"].print(2 + " ") ) ; i := i + 1 ) ; OclFile["System.out"].print(3) ; ) else skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final long MOD=1_000_000_007 ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=Integer.parseInt(scanner.next()); long[] arr=new long[N]; for(int i=0 ; i>k)& 1 ; if(x==0){ x0++; } else { x1++; } } long p=1 ; for(int i=0 ; itoInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( arr[i+1] := (scanner.getCurrent())->toLong() ) ; i := i + 1 ) ; skip ; var ans : long ; ans := 0 ; var k : int ; k := 0 ; while k < 60 do ( ( var x0 : long ; x0 := 0 ; var x1 : long ; x1 := 0 ; var i : int ; i := 0 ; while i < N do ( ( var x : long ; x := MathLib.bitwiseAnd(((arr[i+1]/(2->pow(k)))->oclAsType(long)),1) ; if (x = 0) then ( x0 := x0 + 1 ) else ( x1 := x1 + 1 ) ) ; i := i + 1 ) ; var p : long ; p := 1 ; var i : int ; i := 0 ; while i < k do ( ( p := p*(2) ; p := p mod MOD ) ; i := i + 1 ) ; var count : long ; count := (x0 * x1) mod MOD ; ans := ans+(count * p) ; ans := ans mod MOD ; ) ; k := k + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class HelloWorld { public static void main(String[] args){ Scanner nn=new Scanner(System.in); int n ; n=nn.nextInt(); System.out.println(n/2); while(n>3){ System.out.print(2); System.out.print(' '); n-=2 ; } System.out.print(n); } public static void solve(){ } } ------------------------------------------------------------ OCL File: --------- class HelloWorld { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var nn : OclFile ; nn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := nn.getCurrent()->toInteger() ; OclFile["System.out"].println(n / 2) ; while (n > 3) do ( OclFile["System.out"].print(2) ; OclFile["System.out"].print(' ') ; n := n-(2) ) ; OclFile["System.out"].print(n) ; ); static operation solve() : void pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test138 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int x=in.nextInt(); if(x % 2==0){ System.out.println(x/2); for(int i=0 ; itoInteger() ; if (x mod 2 = 0) then ( OclFile["System.out"].println(x / 2) ; var i : int ; i := 0 ; while i < x / 2 do ( ( OclFile["System.out"].print(2 + " ") ) ; i := i + 1 ) ) else ( OclFile["System.out"].println(x / 2) ; var i : int ; i := 0 ; while i < x / 2 - 1 do ( ( OclFile["System.out"].print(2 + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(3) ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class HelloWorld { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); System.out.print(n/2+"\n"); if(n % 2==0){ for(int i=0 ; itoInteger() ; OclFile["System.out"].print(n / 2 + "\n") ; if (n mod 2 = 0) then ( var i : int ; i := 0 ; while i < n / 2 do ( ( OclFile["System.out"].printf("2\t") ) ; i := i + 1 ) ) else skip ; OclFile["System.out"].println() ; if (n mod 2 = 1) then ( var i : int ; i := 0 ; while i < n / 2 - 1 do ( ( OclFile["System.out"].printf("2\t") ) ; i := i + 1 ) ; OclFile["System.out"].println("3") ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NewClass20 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); if(t % 2==0){ System.out.println(t/2); for(int i=0 ; itoInteger() ; if (t mod 2 = 0) then ( OclFile["System.out"].println(t / 2) ; var i : int ; i := 0 ; while i < t / 2 do ( ( OclFile["System.out"].print(2 + " ") ) ; i := i + 1 ) ) else ( var r : int ; r := t - 3 ; OclFile["System.out"].println(r / 2 + 1) ; var i : int ; i := 0 ; while i < r / 2 do ( ( OclFile["System.out"].print(2 + " ") ) ; i := i + 1 ) ; OclFile["System.out"].print(3) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNextInt()){ int W=sc.nextInt(); System.out.println(W*32); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNextInt()) do ( var W : int ; W := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(W * 32) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long firstsum=0 ; long secondsum=0 ; long arr1[]=new long[n]; long arr2[]=new long[n]; boolean turn=false ; int p=0 ; int q=0 ; for(int i=0 ; i0){ turn=true ; arr1[p++]=temp ; firstsum+=temp ; } else { turn=false ; temp*=-1 ; arr2[q++]=temp ; secondsum+=temp ; } } if(firstsum>secondsum){ System.out.println("first"); } else if(firstsumarr2[i] ? "first" : "second" ; System.out.println(ans); return ; } } if(turn){ System.out.println("first"); } else { System.out.println("second"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var firstsum : long ; firstsum := 0 ; var secondsum : long ; secondsum := 0 ; var arr1 : Sequence(long) ; arr1 := Integer.subrange(1,n)->collect(0) ; var arr2 : Sequence(long) ; arr2 := Integer.subrange(1,n)->collect(0) ; var turn : boolean ; turn := false ; var p : int ; p := 0 ; var q : int ; q := 0 ; var i : int ; i := 0 ; while i < n do ( ( var temp : long ; temp := sc.getCurrent()->toLong() ; if (temp > 0) then ( turn := true ; arr1[p+1] := temp ; p := p + 1 ; firstsum := firstsum+(temp) ) else ( turn := false ; temp := temp*(-1) ; arr2[q+1] := temp ; q := q + 1 ; secondsum := secondsum+(temp) ) ) ; i := i + 1 ) ; if (firstsum > secondsum) then ( OclFile["System.out"].println("first") ) else if (firstsum < secondsum) then ( OclFile["System.out"].println("second") ) else ( var i : int ; i := 0 ; while i < Set{p, q}->min() do ( ( if (arr1[i+1] /= arr2[i+1]) then ( var ans : String ; ans := if arr1[i+1] > arr2[i+1] then "first" else "second" endif ; OclFile["System.out"].println(ans) ; return ) else skip ) ; i := i + 1 ) ; if (turn) then ( OclFile["System.out"].println("first") ) else ( OclFile["System.out"].println("second") ) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner sc=new Scanner(System.in); long num=sc.nextInt(); System.out.println(num*32); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : long ; num := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(num * 32) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ out.println(sc.nextInt()*32); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( out.println(sc.getCurrent()->toInteger() * 32) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); System.out.println(32*in.nextInt()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(32 * in.getCurrent()->toInteger()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Random ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println(sc.nextInt()*32); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(sc.getCurrent()->toInteger() * 32) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); final int MOD=1000000007 ; final int MAX=Integer.MAX_VALUE ; final long LMAX=Long.MAX_VALUE ; int LEN=0 ; void doIt(){ int n=sc.nextInt(); long a[]=new long[n]; for(int i=0 ; i>i & 1)==1)one++; else zero++; } long num=zero*one %(long)MOD ; for(int j=0 ; jtoLong(); attribute LEN : int := 0; operation doIt() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i <= 60 do ( ( var zero : long ; zero := 0 ; var one : long ; one := 0 ; var j : int ; j := 0 ; while j < n do ( ( if ((MathLib.bitwiseAnd((a[j+1]/(2->pow(i)))->oclAsType(long),1)) = 1) then one := one + 1 ; else zero := zero + 1 ; ) ; j := j + 1 ) ; var num : long ; num := zero * one mod MOD->oclAsType(long) ; var j : int ; j := 0 ; while j < i do ( ( num := ((num*(2->pow(1)))->oclAsType(long)) mod MOD->oclAsType(long) ) ; j := j + 1 ) ; ans := (ans + num) mod MOD->oclAsType(long) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans mod MOD->oclAsType(long)) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int count=0 ; for(int i=0 ; itoInteger() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (sc.getCurrent()->toInteger() mod 2 = 0) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); long n=s.nextLong(); long m=s.nextLong(); long ans=0 ; ans=(m-1)*n ; if(m==1){ ans=n-1 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := s.getCurrent()->toLong() ; var m : long ; m := s.getCurrent()->toLong() ; var ans : long ; ans := 0 ; ans := (m - 1) * n ; if (m = 1) then ( ans := n - 1 ) else skip ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Dominoes { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long m=sc.nextLong(); if(m==1){ System.out.println(n-1); } else { System.out.println((m-1)*n); } } } ------------------------------------------------------------ OCL File: --------- class Dominoes { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var m : long ; m := sc.getCurrent()->toLong() ; if (m = 1) then ( OclFile["System.out"].println(n - 1) ) else ( OclFile["System.out"].println((m - 1) * n) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextInt(); long m=sc.nextInt(); if(m==1 && n==1)System.out.print(0); else if(m==1)System.out.print(n-1); else if(n==1)System.out.print((m-1)); else System.out.print((m-1)*n); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toInteger() ; var m : long ; m := sc.getCurrent()->toInteger() ; if (m = 1 & n = 1) then OclFile["System.out"].print(0) ; else if (m = 1) then OclFile["System.out"].print(n - 1) else if (n = 1) then OclFile["System.out"].print((m - 1)) else OclFile["System.out"].print((m - 1) * n) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); long n=in.nextInt(),m=in.nextInt(); System.out.println(m==1 ? n-1 :(m-1)*n); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := in.getCurrent()->toInteger() ; var m : long ; m := in.getCurrent()->toInteger() ; OclFile["System.out"].println(if m = 1 then n - 1 else (m - 1) * n endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DominoesICPC { public static void main(String[] args){ Scanner input=new Scanner(System.in); long vertical=input.nextInt(); long horizon=input.nextInt(); if(horizon==1){ System.out.println(vertical-1); } else { System.out.println(vertical*(horizon-1)); } } } ------------------------------------------------------------ OCL File: --------- class DominoesICPC { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var vertical : long ; vertical := input.getCurrent()->toInteger() ; var horizon : long ; horizon := input.getCurrent()->toInteger() ; if (horizon = 1) then ( OclFile["System.out"].println(vertical - 1) ) else ( OclFile["System.out"].println(vertical * (horizon - 1)) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countOddSquares(int n,int m){ return(int)Math.pow(m,0.5)-(int)Math.pow(n-1,0.5); } public static void main(String[] args){ int n=5,m=100 ; System.out.println("Count is "+((m-n+1)-countOddSquares(n,m))); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countOddSquares( n : int, m : int) : int pre: true post: true activity: ( return m->pow(0.5)->oclAsType(int) - n - 1->pow(0.5)->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var m : int ; m := 100 ; OclFile["System.out"].println("Count is " + ((m - n + 1) - countOddSquares(n, m))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int tf=0 ; int f=0 ; int h=0 ; for(int i=0 ; i=1){ f++; tf--; } else { System.out.println("NO"); return ; } } else { if(f>=1 && tf>=1){ tf--; f--; h++; } else if(tf>=3){ tf-=3 ; h++; } else { System.out.println("NO"); return ; } } } System.out.println("YES"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var tf : int ; tf := 0 ; var f : int ; f := 0 ; var h : int ; h := 0 ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; if (v = 25) then ( tf := tf + 1 ) else if (v = 50) then ( if (tf >= 1) then ( f := f + 1 ; tf := tf - 1 ) else ( OclFile["System.out"].println("NO") ; return ) ) else ( if (f >= 1 & tf >= 1) then ( tf := tf - 1 ; f := f - 1 ; h := h + 1 ) else if (tf >= 3) then ( tf := tf-(3) ; h := h + 1 ) else ( OclFile["System.out"].println("NO") ; return ) ; ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Acinemafans { public static void main(String[] args)throws IOException { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); int l=Integer.parseInt(buf.readLine()); String[] inp=buf.readLine().split(" "); int[] arr=new int[inp.length]; for(int i=0 ; itoInteger() ; var inp : Sequence(String) ; inp := buf.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,inp->size())->collect(0) ; var i : int ; i := 0 ; while i < inp->size() do ( ( arr[i+1] := (inp[i+1])->toInteger() ) ; i := i + 1 ) ; var c25 : int ; c25 := 0 ; var c50 : int ; c50 := 0 ; for (i : arr) do ( ( if (i = 25) then ( c25 := c25 + 1 ) else if (i = 50) then ( if (c25 = 0) then ( OclFile["System.out"].println("NO") ; return ) else skip ; c50 := c50 + 1 ; c25 := c25 - 1 ) else ( if (c25 = 0 or c50 = 0 & c25 < 3) then ( OclFile["System.out"].println("NO") ; return ) else skip ; c25 := c25 - 1 ; if (c50 /= 0) then c50 := c50 - 1 ; else c25 := c25-(2) ; ) ; ) ) ; OclFile["System.out"].println("YES") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); int t25=0,t50=0 ; boolean flag=true ; for(int i=0 ; i=1){ t50--; } else { t25-=2 ; } } else { if(t50>=1){ t50--; t25--; } else { t25-=3 ; } } if(t25<0 || t50<0){ flag=false ; } } if(flag){ pw.println("YES"); } else { pw.println("NO"); } pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var t25 : int ; t25 := 0 ; var t50 : int ; t50 := 0 ; var flag : boolean ; flag := true ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := in.getCurrent()->toInteger() ; if (v = 25) then ( t25 := t25 + 1 ) else if (v = 50) then ( t50 := t50 + 1 ; t25 := t25 - 1 ) else if (v = 75) then ( if (t50 >= 1) then ( t50 := t50 - 1 ) else ( t25 := t25-(2) ) ) else ( if (t50 >= 1) then ( t50 := t50 - 1 ; t25 := t25 - 1 ) else ( t25 := t25-(3) ) ) ; ; ; if (t25 < 0 or t50 < 0) then ( flag := false ) else skip ) ; i := i + 1 ) ; if (flag) then ( skip ) else ( skip ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Solution { static int res=0 ; static int checkRecursive(int num,int x,int k,int n){ if(x==0)res++; int r=(int)Math.floor(Math.pow(num,1.0/n)); for(int i=k+1 ; i<=r ; i++){ int a=x-(int)Math.pow(i,n); if(a>=0)checkRecursive(num,x-(int)Math.pow(i,n),i,n); } return res ; } static int check(int x,int n){ return checkRecursive(x,x,0,n); } public static void main(String[] args){ System.out.println(check(10,2)); } } ------------------------------------------------------------ OCL File: --------- class Solution { static attribute res : int := 0; static operation checkRecursive( num : int, x : int, k : int, n : int) : int pre: true post: true activity: ( if (x = 0) then res := res + 1 ; else skip ; var r : int ; r := (num->pow(1.0 / n))->floor()->oclAsType(int) ; var i : int ; i := k + 1 ; while i <= r do ( ( var a : int ; a := x - i->pow(n)->oclAsType(int) ; if (a >= 0) then execute checkRecursive(num, x - i->pow(n)->oclAsType(int), i, n) ; else skip ) ; i := i + 1 ) ; return res ); static operation check( x : int, n : int) : int pre: true post: true activity: ( return checkRecursive(x, x, 0, n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(check(10, 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CinemaLine { int number ; public CinemaLine(int number){ this.number=number ; } public int getNumber(){ return number ; } static int number25=0 ; static int number50=0 ; boolean b=true ; public void input(int num){ if(num==25){ number25++; } else if(num==50 && number25>=1){ number25--; number50++; } else if(num==100 &&((number25>=1 && number50>=1)|| number25>=3)){ if(number50>=1){ number25--; number50--; } else { number25-=3 ; } } else { b=false ; } } public void print(){ if(b==true){ System.out.println("YES"); } else { System.out.println("NO"); } } public static void main(String[] a){ Scanner input=new Scanner(System.in); int number=input.nextInt(); CinemaLine instance=new CinemaLine(number); for(int i=0 ; i= 1) then ( number25 := number25 - 1 ; number50 := number50 + 1 ) else if (num = 100 & ((number25 >= 1 & number50 >= 1) or number25 >= 3)) then ( if (number50 >= 1) then ( number25 := number25 - 1 ; number50 := number50 - 1 ) else ( number25 := number25-(3) ) ) else ( b := false ) ; ; ); operation print() : void pre: true post: true activity: ( if (b = true) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : CinemaLine ; instance := CinemaLine.newCinemaLine(number) ; var i : int ; i := 0 ; while i < instance.getNumber() do ( ( var n : int ; n := input.getCurrent()->toInteger() ; instance.input(n) ) ; i := i + 1 ) ; instance.print() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isFrequencyEqual(String str,int len){ if(len % 2==1){ return false ; } int i,freq[]=new int[26]; for(i=0 ; icollect(0) ; i := 0 ; while i < len do ( ( freq[str->at(i+1) - ('a')->char2byte()+1] := freq[str->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; i := 0 ; while i < 26 do ( ( if (freq[i+1] = len / 2) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var len : int ; len := str->size() ; if (isFrequencyEqual(str, len)) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class jjj { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ long n=sc.nextLong(); if(n<=2)System.out.println(0); else { System.out.println(n % 2==0 ? n/2-1 : n/2); } } } } ------------------------------------------------------------ OCL File: --------- class jjj { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := sc.getCurrent()->toInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( var n : long ; n := sc.getCurrent()->toLong() ; if (n <= 2) then OclFile["System.out"].println(0) ; else ( OclFile["System.out"].println(if n mod 2 = 0 then n / 2 - 1 else n / 2 endif) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ int fw=sc.nextInt(); if(fw<3)System.out.println(0); else if(fw % 2==0){ System.out.println(fw/2-1); } else if(fw % 2!=0){ System.out.println((fw+1)/2-1); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var fw : int ; fw := sc.getCurrent()->toInteger() ; if (fw < 3) then OclFile["System.out"].println(0) ; else if (fw mod 2 = 0) then ( OclFile["System.out"].println(fw / 2 - 1) ) else if (fw mod 2 /= 0) then ( OclFile["System.out"].println((fw + 1) / 2 - 1) ) else skip ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MathsSecondAttempt { public static void main(String[] args){ CandiesandTwoSisters(); } public static void CandiesandTwoSisters(){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scan.getCurrent()->toInteger() ; OclFile["System.out"].println((n - 1) / 2) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CandyAndTwoSister { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int Count=0 ; if(n==1 || n==2){ Count=0 ; } else { Count=(n-1)/2 ; } System.out.println(Count); t--; } } } ------------------------------------------------------------ OCL File: --------- class CandyAndTwoSister { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var Count : int ; Count := 0 ; if (n = 1 or n = 2) then ( Count := 0 ) else ( Count := (n - 1) / 2 ) ; OclFile["System.out"].println(Count) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class A1335 { static FastScanner sc=new FastScanner(); public static void main(String[] args){ int tt=sc.nextInt(); while(tt-->0)solve(); } public static void solve(){ int n=sc.nextInt(); if(n % 2==0){ System.out.println((n/2)-1); } else { System.out.println(n/2); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; i 0) do ( tt := tt - 1 ; skip ; execute solve() ; ; ) ); static operation solve() : void pre: true post: true activity: ( var n : int ; n := sc.nextInt() ; if (n mod 2 = 0) then ( OclFile["System.out"].println((n / 2) - 1) ) else ( OclFile["System.out"].println(n / 2) ) ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countSubArrayProductLessThanK(ArrayLista,long k){ int n=a.size(); long p=1 ; int res=0 ; for(int start=0,end=0 ; end=k)p/=a.get(start++); if(pal=new ArrayList(); al.add(1); al.add(2); al.add(3); al.add(4); System.out.println(countSubArrayProductLessThanK(al,10)); ArrayListal1=new ArrayList(); al1.add(1); al1.add(9); al1.add(2); al1.add(8); al1.add(6); al1.add(4); al1.add(3); System.out.println(countSubArrayProductLessThanK(al1,100)); ArrayListal2=new ArrayList(); al2.add(5); al2.add(3); al2.add(2); System.out.println(countSubArrayProductLessThanK(al2,16)); ArrayListal3=new ArrayList(); al3.add(100); al3.add(200); System.out.println(countSubArrayProductLessThanK(al3,100)); ArrayListal4=new ArrayList(); al4.add(100); al4.add(200); System.out.println(countSubArrayProductLessThanK(al3,101)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSubArrayProductLessThanK( a : Sequence(int), k : long) : int pre: true post: true activity: ( var n : int ; n := a->size() ; var p : long ; p := 1 ; var res : int ; res := 0 ; var start : int ; start := 0 ; var end : int ; end := 0 ; while end < n do ( ( p := p*(a->at(end+1)) ; while (start < end & p >= k) do p := p/(a->at(start+1)) ; ; if (p < k) then ( var len : int ; len := end - start + 1 ; res := res+(len) ) else skip ) ; end := end + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var al : Sequence(int) ; al := Sequence{} ; al := al->including(1) ; al := al->including(2) ; al := al->including(3) ; al := al->including(4) ; OclFile["System.out"].println(countSubArrayProductLessThanK(al, 10)) ; var al1 : Sequence(int) ; al1 := Sequence{} ; al1 := al1->including(1) ; al1 := al1->including(9) ; al1 := al1->including(2) ; al1 := al1->including(8) ; al1 := al1->including(6) ; al1 := al1->including(4) ; al1 := al1->including(3) ; OclFile["System.out"].println(countSubArrayProductLessThanK(al1, 100)) ; var al2 : Sequence(int) ; al2 := Sequence{} ; al2 := al2->including(5) ; al2 := al2->including(3) ; al2 := al2->including(2) ; OclFile["System.out"].println(countSubArrayProductLessThanK(al2, 16)) ; var al3 : Sequence(int) ; al3 := Sequence{} ; al3 := al3->including(100) ; al3 := al3->including(200) ; OclFile["System.out"].println(countSubArrayProductLessThanK(al3, 100)) ; var al4 : Sequence(int) ; al4 := Sequence{} ; al4 := al4->including(100) ; al4 := al4->including(200) ; OclFile["System.out"].println(countSubArrayProductLessThanK(al3, 101)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class caps_lock { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.nextLine(); int count=0 ; int k=0 ; char temp=str.charAt(0); String str1=Character.toString(temp); str1=str1.toLowerCase(); if(str1.charAt(0)!=str.charAt(0)){ k=1 ; count=1 ; } for(int i=1 ; iat(0+1) ; var str1 : String ; str1 := (temp + "") ; str1 := str1->toLowerCase() ; if (str1->at(0+1) /= str->at(0+1)) then ( k := 1 ; count := 1 ) else skip ; var i : int ; i := 1 ; while i < str->size() do ( ( var temp1 : String ; temp1 := str->at(i+1) ; var str12 : String ; str12 := (temp1 + "") ; str12 := str12->toLowerCase() ; if (str12->at(0+1) /= str->at(i+1)) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; if (count = str->size()) then ( OclFile["System.out"].println(str.subrange(0+1,str->size())->toLowerCase()) ) else if (k = 0 & count = str->size() - 1) then ( OclFile["System.out"].println(str.subrange(0+1,1)->toUpperCase() + str.subrange(1+1,str->size())->toLowerCase()) ) else OclFile["System.out"].println(str) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Mridul8 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); String str1=str.substring(1); String str2=str1.toUpperCase(); if(str1.equals(str2)){ if(str.substring(0,1).equals(str.substring(0,1).toLowerCase())){ String str4="" ; str4=str.substring(0,1).toUpperCase()+str.substring(1).toLowerCase(); System.out.println(str4); } else { System.out.println(str.toLowerCase()); } } else { System.out.println(str); } } } ------------------------------------------------------------ OCL File: --------- class Mridul8 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; var str1 : String ; str1 := str.subrange(1+1,1) ; var str2 : String ; str2 := str1->toUpperCase() ; if (str1 = str2) then ( if (str.subrange(0+1,1) = str.subrange(0+1,1)->toLowerCase()) then ( var str4 : String ; str4 := "" ; str4 := str.subrange(0+1,1)->toUpperCase() + str.subrange(1+1,1)->toLowerCase() ; OclFile["System.out"].println(str4) ) else ( OclFile["System.out"].println(str->toLowerCase()) ) ) else ( OclFile["System.out"].println(str) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static String oper ; public static void main(String args[])throws Exception { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); char[] chs=s.toCharArray(); String oper=dfs(chs,1,chs[0]-'0',""); StringBuilder sb=new StringBuilder(); for(int i=0 ; icharacters() ; var oper : String ; oper := dfs(chs, 1, chs[0+1] - ('0')->char2byte(), "") ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < chs->size() do ( ( sb := sb + StringLib.newString(chs[i+1]) ; if (i < chs->size() - 1) then sb := sb + StringLib.newString(oper->at(i+1)) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(sb+"" + "=7") ; ); static operation dfs( chs : Sequence(String), idx : int, cur : int, opers : String) : String pre: true post: true activity: ( if (idx = chs->size()) then ( if (cur = 7) then return opers else return null ) else skip ; var plus : String ; plus := dfs(chs, idx + 1, cur + (chs[idx+1] - ('0')->char2byte()), opers + "+") ; if (plus /= null) then return plus else skip ; var nega : String ; nega := dfs(chs, idx + 1, cur - (chs[idx+1] - ('0')->char2byte()), opers + "-") ; if (nega /= null) then return nega else skip ; return null ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Application { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String word=scan.nextLine(); String up=word.toUpperCase(); String fall=word.substring(0,1).toLowerCase()+word.substring(1).toUpperCase(); if(word.equals(fall)){ System.out.println(word.substring(0,1).toUpperCase()+word.substring(1).toLowerCase()); } else if(word.equals(up)){ System.out.println(word.toLowerCase()); } else { System.out.println(word); } } } ------------------------------------------------------------ OCL File: --------- class Application { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var word : String ; word := scan.nextLine() ; var up : String ; up := word->toUpperCase() ; var fall : String ; fall := word.subrange(0+1,1)->toLowerCase() + word.subrange(1+1,1)->toUpperCase() ; if (word = fall) then ( OclFile["System.out"].println(word.subrange(0+1,1)->toUpperCase() + word.subrange(1+1,1)->toLowerCase()) ) else if (word = up) then ( OclFile["System.out"].println(word->toLowerCase()) ) else ( OclFile["System.out"].println(word) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Capslock { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String assel=sc.next(); String lower=assel.toLowerCase(); boolean all=false ; boolean allexceptfirst=false ; if(assel.length()==1){ if(assel.charAt(0)==lower.charAt(0))allexceptfirst=true ; else all=true ; } else if(lower.charAt(0)-assel.charAt(0)==32){ for(int i=1 ; itoLowerCase() ; var all : boolean ; all := false ; var allexceptfirst : boolean ; allexceptfirst := false ; if (assel->size() = 1) then ( if (assel->at(0+1) = lower->at(0+1)) then allexceptfirst := true ; else all := true ; ) else if (lower->at(0+1) - assel->at(0+1) = 32) then ( var i : int ; i := 1 ; while i < assel->size() do ( ( if (lower->at(i+1) - assel->at(i+1) = 32) then ( all := true ) else ( all := false ; break ) ) ; i := i + 1 ) ) else if (lower->at(0+1) - assel->at(0+1) = 0) then ( var i : int ; i := 1 ; while i < assel->size() do ( ( if (lower->at(i+1) - assel->at(i+1) = 32) then ( allexceptfirst := true ) else ( allexceptfirst := false ; break ) ) ; i := i + 1 ) ) else skip ; ; ; if (all) then OclFile["System.out"].println(lower) else if (allexceptfirst) then ( OclFile["System.out"].println((lower->at(0+1) - 32)->oclAsType(String) + lower.subrange(1+1,lower->size())) ) else OclFile["System.out"].println(assel) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Code_131A { public static String changeCase(String str){ char[] chrArr=str.toCharArray(); for(int i=0 ; i='a' && chrArr[i]<='z')chrArr[i]-=32 ; else if(chrArr[i]>='A' && chrArr[i]<='Z')chrArr[i]+=32 ; } return String.valueOf(chrArr); } public static boolean isCapital(String str){ char[] chrArr=str.toCharArray(); for(int i=1 ; i='a' && chrArr[i]<='z')return false ; } return true ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); if(isCapital(str))str=changeCase(str); System.out.println(str); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Code_131A { static operation changeCase( str : String) : String pre: true post: true activity: ( var chrArr : Sequence(String) ; chrArr := str->characters() ; var i : int ; i := 0 ; while i < chrArr->size() do ( ( if (chrArr[i+1] >= 'a' & chrArr[i+1] <= 'z') then chrArr[i+1] := chrArr[i+1]-(32) ; else if (chrArr[i+1] >= 'A' & chrArr[i+1] <= 'Z') then chrArr[i+1] := chrArr[i+1]+(32) ; else skip ; ) ; i := i + 1 ) ; return (chrArr)->sum() ); static operation isCapital( str : String) : boolean pre: true post: true activity: ( var chrArr : Sequence(String) ; chrArr := str->characters() ; var i : int ; i := 1 ; while i < chrArr->size() do ( ( if (chrArr[i+1] >= 'a' & chrArr[i+1] <= 'z') then return false else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; if (isCapital(str)) then str := changeCase(str) ; else skip ; OclFile["System.out"].println(str) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class App { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); HashSetarr=new HashSet<>(); for(int i=0 ; i3){ System.out.println("NO"); } else { int[] s=new int[3]; int i=0 ; for(int index : arr){ s[i]=index ; i++; } Arrays.sort(s); if(s[1]-s[0]==s[2]-s[1]){ System.out.println("YES"); } else { System.out.println("NO"); } } in.close(); } } ------------------------------------------------------------ OCL File: --------- class App { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var arr : Set(int) ; arr := Set{} ; var i : int ; i := 0 ; while i < n do ( ( arr := arr->including(in.getCurrent()->toInteger()) ) ; i := i + 1 ) ; if (arr->size() < 3) then ( OclFile["System.out"].println("YES") ) else if (arr->size() > 3) then ( OclFile["System.out"].println("NO") ) else ( var s : Sequence(int) ; s := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; for (index : arr) do ( ( s[i+1] := index ; i := i + 1 ) ) ; s := s->sort() ; if (s[1+1] - s[0+1] = s[2+1] - s[1+1]) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class FilyaAndHomework { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); ArrayListls=new ArrayList<>(); for(int i=0 ; ils){ Collections.sort(ls); long min=Collections.min(ls); long max=Collections.max(ls); if(max==min)return true ; long midde=-1 ; for(long v : ls)if(minv){ midde=v ; break ; } if(midde==-1)return true ; long abs=max-midde ; for(long v : ls){ if(v==midde)continue ; long temp=Math.abs(v-midde); if(temp!=abs)return false ; } return true ; } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class FilyaAndHomework { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var ls : Sequence(long) ; ls := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ls := ls->including(in.getCurrent()->toLong()) ; ; i := i + 1 ) ; if (solve(ls)) then skip else skip ; ; skip ; ); static operation solve( ls : Sequence(long)) : boolean pre: true post: true activity: ( ls := ls->sort() ; var min : long ; min := .min(ls) ; var max : long ; max := .max(ls) ; if (max = min) then return true else skip ; var midde : long ; midde := -1 ; for (v : ls) do ( if (min < v & max > v) then ( midde := v ; break ) else skip ; ) ; if (midde = -1) then return true else skip ; var abs : long ; abs := max - midde ; for (v : ls) do ( ( if (v = midde) then continue else skip ; var temp : long ; temp := if v - midde < 0 then -(v - midde) else v - midde endif ; if (temp /= abs) then return false else skip ) ) ; return true ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; Setset=new HashSet<>(); for(int i=0 ; ilist=new ArrayList(set); Collections.sort(list); if(set.size()==1 || set.size()==2)System.out.println("YES"); else if(set.size()==3){ if(2*list.get(1)==list.get(0)+list.get(2))System.out.println("YES"); else System.out.println("NO"); } else System.out.println("NO"); } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; set := set->including(arr[i+1]) ) ; i := i + 1 ) ; var list : Sequence(int) ; list := Sequence{}->union(set) ; list := list->sort() ; if (set->size() = 1 or set->size() = 2) then OclFile["System.out"].println("YES") else if (set->size() = 3) then ( if (2 * list->at(1+1) = list->at(0+1) + list->at(2+1)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ) else OclFile["System.out"].println("NO") ; ; ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void rotateMatrix(int N,int mat[][]){ for(int x=0 ; xN)return 0 ; if(dp[idx][src][dest]!=Integer.MAX_VALUE)return dp[idx][src][dest]; int rem=6-(src+dest); int ans=Integer.MAX_VALUE ; int case1=costs[src-1][dest-1]+mincost(idx+1,src,rem,costs)+mincost(idx+1,rem,dest,costs); int 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=Math.min(case1,case2); dp[idx][src][dest]=ans ; return ans ; } public static void main(String[] args){ int[][] costs={ { 0,1,2 },{ 2,0,1 },{ 3,2,0 } }; initialize(); System.out.print(mincost(1,1,3,costs)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute RODS : int := 3; static attribute N : int := 3; static attribute dp : Sequence(Sequence(Sequence(int))) := Integer.subrange(1,N + 1)->collect(Integer.subrange(1,RODS + 1)->collect(Integer.subrange(1,RODS + 1)->collect(0))); static operation initialize() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i <= N do ( ( var j : int ; j := 1 ; while j <= RODS do ( ( var k : int ; k := 1 ; while k <= RODS do ( ( dp[i+1][j+1][k+1] := 2147483647 ) ; k := k+(1) ) ) ; j := j + 1 ) ) ; i := i+(1) ) ); static operation mincost( idx : int, src : int, dest : int, costs : Sequence(Sequence(int))) : int pre: true post: true activity: ( if (idx > N) then return 0 else skip ; if (dp[idx+1][src+1][dest+1] /= 2147483647) then return dp[idx+1][src+1][dest+1] else skip ; var rem : int ; rem := 6 - (src + dest) ; var ans : int ; ans := 2147483647 ; var case1 : int ; case1 := costs[src - 1+1][dest - 1+1] + mincost(idx + 1, src, rem, costs) + mincost(idx + 1, rem, dest, costs) ; var case2 : int ; case2 := 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 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var costs : Sequence(Sequence(int)) ; costs := Sequence{Sequence{0,1,2},Sequence{2,0,1},Sequence{3,2,0}} ; execute initialize() ; OclFile["System.out"].print(mincost(1, 1, 3, costs)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void printNonDivisible(int[] A,int[] B,int n,int m){ int maxB=0 ; for(int i=0 ; imaxB)maxB=B[i]; int[] mark=new int[maxB+1]; for(int i=0 ; i maxB) then maxB := B[i+1] ; else skip ; ; i := i + 1 ) ; var mark : Sequence(int) ; mark := Integer.subrange(1,maxB + 1)->collect(0) ; var i : int ; i := 0 ; while i < maxB do ( mark[i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( var x : int ; x := A[i+1] ; while x <= maxB do ( mark[x+1] := mark[x+1] + 1 ; ; x := x+(A[i+1]) ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( if (mark[B[i+1]+1] = 0) then OclFile["System.out"].println(B[i+1]) ; else skip ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : Sequence(int) ; A := Sequence{100,200,400,100} ; var n : int ; n := A->size() ; var B : Sequence(int) ; B := Sequence{190,200,87,600,800} ; var m : int ; m := B->size() ; execute printNonDivisible(A, B, n, m) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { public static int sumOfSeries(int n){ int sum=0 ; for(int x=1 ; x<=n ; x++)sum+=x*x*x ; return sum ; } public static void main(String[] args){ int n=5 ; System.out.println(sumOfSeries(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfSeries( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var x : int ; x := 1 ; while x <= n do ( sum := sum+(x * x * x) ; ; x := x + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(sumOfSeries(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static Scanner s=new Scanner(System.in); static int gInt(){ return Integer.parseInt(s.next()); }; public static void main(String[] $){ int[] v=s.next().chars().map(i->i-'0').toArray(); int a=v[0]; int b=v[1]; int c=v[2]; int d=v[3]; if(a+b+c+d==7){ o("+","+","+",a,b,c,d); return ; } if(a-b+c+d==7){ o("-","+","+",a,b,c,d); return ; } if(a+b-c+d==7){ o("+","-","+",a,b,c,d); return ; } if(a+b+c-d==7){ o("+","+","-",a,b,c,d); return ; } if(a-b-c+d==7){ o("-","-","+",a,b,c,d); return ; } if(a-b+c-d==7){ o("-","+","-",a,b,c,d); return ; } if(a+b-c-d==7){ o("+","-","-",a,b,c,d); return ; } if(a-b-c-d==7){ o("-","-","-",a,b,c,d); return ; } } static void o(String s1,String s2,String s3,int a,int b,int c,int d){ System.out.println(a+s1+b+s2+c+s3+d+"=7"); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation gInt() : int pre: true post: true activity: ( return (s.getCurrent())->toInteger() ); static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var v : Sequence(int) ; v := s.getCurrent().chars()->collect( _x1 | (lambda i : OclAny in i - ('0')->char2byte())->apply(_x1) )->asSequence() ; var a : int ; a := v[0+1] ; var b : int ; b := v[1+1] ; var c : int ; c := v[2+1] ; var d : int ; d := v[3+1] ; if (a + b + c + d = 7) then ( execute o("+", "+", "+", a, b, c, d) ; return ) else skip ; if (a - b + c + d = 7) then ( execute o("-", "+", "+", a, b, c, d) ; return ) else skip ; if (a + b - c + d = 7) then ( execute o("+", "-", "+", a, b, c, d) ; return ) else skip ; if (a + b + c - d = 7) then ( execute o("+", "+", "-", a, b, c, d) ; return ) else skip ; if (a - b - c + d = 7) then ( execute o("-", "-", "+", a, b, c, d) ; return ) else skip ; if (a - b + c - d = 7) then ( execute o("-", "+", "-", a, b, c, d) ; return ) else skip ; if (a + b - c - d = 7) then ( execute o("+", "-", "-", a, b, c, d) ; return ) else skip ; if (a - b - c - d = 7) then ( execute o("-", "-", "-", a, b, c, d) ; return ) else skip ; ); static operation o( s1 : String, s2 : String, s3 : String, a : int, b : int, c : int, d : int) : void pre: true post: true activity: ( OclFile["System.out"].println(a + s1 + b + s2 + c + s3 + d + "=7") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { public static int sumOfSeries(int n){ int x=(n*(n+1)/2); return x*x ; } public static void main(String[] args){ int n=5 ; System.out.println(sumOfSeries(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfSeries( n : int) : int pre: true post: true activity: ( var x : int ; x := (n * (n + 1) / 2) ; return x * x ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(sumOfSeries(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { public static int sumOfSeries(int n){ int x ; if(n % 2==0)x=(n/2)*(n+1); else x=((n+1)/2)*n ; return x*x ; } public static void main(String[] args){ int n=5 ; System.out.println(sumOfSeries(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfSeries( n : int) : int pre: true post: true activity: ( var x : int ; if (n mod 2 = 0) then x := (n / 2) * (n + 1) else x := ((n + 1) / 2) * n ; ; return x * x ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(sumOfSeries(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int R=4 ; static int C=4 ; static int getTotalCoverageOfMatrix(int[][] mat){ int res=0 ; for(int i=0 ; i=0 ; j--){ if(mat[i][j]==1)isOne=true ; else if(isOne)res++; } } for(int j=0 ; j=0 ; i--){ if(mat[i][j]==1)isOne=true ; else if(isOne)res++; } } return res ; } static public void main(String[] args){ int[][] mat={ { 0,0,0,0 },{ 1,0,0,1 },{ 0,1,1,0 },{ 0,1,0,0 } }; System.out.println(getTotalCoverageOfMatrix(mat)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute R : int := 4; static attribute C : int := 4; static operation getTotalCoverageOfMatrix( mat : Sequence(Sequence(int))) : int pre: true post: true activity: ( var res : int ; res := 0 ; var i : int ; i := 0 ; while i < R do ( ( var isOne : boolean ; isOne := false ; var j : int ; j := 0 ; while j < C do ( ( if (mat[i+1][j+1] = 1) then isOne := true ; else if (isOne) then res := res + 1 ; else skip ; ) ; j := j + 1 ) ; isOne := false ; var j : int ; j := C - 1 ; while j >= 0 do ( ( if (mat[i+1][j+1] = 1) then isOne := true ; else if (isOne) then res := res + 1 ; else skip ; ) ; j := j - 1 ) ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < C do ( ( var isOne : boolean ; isOne := false ; var i : int ; i := 0 ; while i < R do ( ( if (mat[i+1][j+1] = 1) then isOne := true ; else if (isOne) then res := res + 1 ; else skip ; ) ; i := i + 1 ) ; isOne := false ; var i : int ; i := R - 1 ; while i >= 0 do ( ( if (mat[i+1][j+1] = 1) then isOne := true ; else if (isOne) then res := res + 1 ; else skip ; ) ; i := i - 1 ) ) ; j := j + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{0,0,0,0},Sequence{1,0,0,1},Sequence{0,1,1,0},Sequence{0,1,0,0}} ; OclFile["System.out"].println(getTotalCoverageOfMatrix(mat)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void replace_elements(int arr[],int n){ int pos=0 ; for(int i=0 ; i1 && arr[pos-2]==arr[pos-1]){ pos--; arr[pos-1]++; } } for(int i=0 ; i 1 & arr[pos - 2+1] = arr[pos - 1+1]) do ( pos := pos - 1 ; arr[pos - 1+1] := arr[pos - 1+1] + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < pos do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{6,4,3,4,3,3,5} ; var n : int ; n := arr->size() ; execute replace_elements(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countOnes(int n){ int count=1 ; int rem=1 ; while(rem!=0){ rem=(rem*10+1)% n ; count++; } return count ; } public static void main(String[] args){ int n=13 ; System.out.println(countOnes(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countOnes( n : int) : int pre: true post: true activity: ( var count : int ; count := 1 ; var rem : int ; rem := 1 ; while (rem /= 0) do ( rem := (rem * 10 + 1) mod n ; count := count + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 13 ; OclFile["System.out"].println(countOnes(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.HashSet ; import java.util.Set ; public final class p029 implements EulerSolution { public static void main(String[] args){ System.out.println(new p029().run()); } public String run(){ Setgenerated=new HashSet<>(); for(int a=2 ; a<=100 ; a++){ for(int b=2 ; b<=100 ; b++)generated.add(BigInteger.valueOf(a).pow(b)); } return Integer.toString(generated.size()); } } ------------------------------------------------------------ OCL File: --------- class p029 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p029.newp029().run()) ); operation run() : String pre: true post: true activity: ( var generated : Set(long) ; generated := Set{} ; var a : int ; a := 2 ; while a <= 100 do ( ( var b : int ; b := 2 ; while b <= 100 do ( generated := generated->including((a + "")->toLong().pow(b)) ; ; b := b + 1 ) ) ; a := a + 1 ) ; return ((generated->size()) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int z=0 ; ztoInteger() ; var z : int ; z := 0 ; while z < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,y + 2)->collect(Integer.subrange(1,x + 2)->collect(0)) ; var xx : Sequence(Sequence(boolean)) ; xx := Integer.subrange(1,y + 2)->collect(Integer.subrange(1,x + 2)->collect(false)) ; var yy : Sequence(Sequence(boolean)) ; yy := Integer.subrange(1,y + 2)->collect(Integer.subrange(1,x + 2)->collect(false)) ; var p : int ; p := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,4)->collect(0) ; var b : int ; var i : int ; i := 0 ; while i < p do ( ( var j : int ; j := 0 ; while j < 4 do ( a[j+1] := sc.getCurrent()->toInteger() + 1 ; ; j := j + 1 ) ; if (a[0+1] = a[2+1]) then ( b := Set{a[1+1], a[3+1]}->max() ; yy[b+1][a[0+1]+1] := true ) else ( b := Set{a[0+1], a[2+1]}->max() ; xx[a[1+1]+1][b+1] := true ) ) ; i := i + 1 ) ; dp[1+1][0+1] := 1 ; var i : int ; i := 1 ; while i <= y + 1 do ( ( var j : int ; j := 1 ; while j <= x + 1 do ( ( if (yy[i+1][j+1] = false) then dp[i+1][j+1] := dp[i+1][j+1]+(dp[i - 1+1][j+1]) ; else skip ; if (xx[i+1][j+1] = false) then dp[i+1][j+1] := dp[i+1][j+1]+(dp[i+1][j - 1+1]) ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; b := dp[y + 1+1][x + 1+1] ; if (b = 0) then OclFile["System.out"].println("Miserable Hokusai!") else OclFile["System.out"].println(b) ; ; ) ; z := z + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int nbim=sc.nextInt(); while(nbim-->0){ int gx=sc.nextInt(); int gy=sc.nextInt(); int[][] dp=new int[gy+2][gx+2]; boolean[][][] hasTabis=new boolean[gy+2][gx+2][2]; int p=sc.nextInt(); for(int i=0 ; i

toInteger() ; while (nbim > 0) do ( nbim := nbim - 1 ; skip ; ( var gx : int ; gx := sc.getCurrent()->toInteger() ; var gy : int ; gy := sc.getCurrent()->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,gy + 2)->collect(Integer.subrange(1,gx + 2)->collect(0)) ; var hasTabis : Sequence(Sequence(Sequence(boolean))) ; hasTabis := Integer.subrange(1,gy + 2)->collect(Integer.subrange(1,gx + 2)->collect(Integer.subrange(1,2)->collect(false))) ; var p : int ; p := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < p do ( ( var x : int ; x := sc.getCurrent()->toInteger() + 1 ; var y : int ; y := sc.getCurrent()->toInteger() + 1 ; var x2 : int ; x2 := sc.getCurrent()->toInteger() + 1 ; var y2 : int ; y2 := sc.getCurrent()->toInteger() + 1 ; hasTabis[Set{y, y2}->max()+1][Set{x, x2}->max()+1][if x /= x2 then 0 else 1 endif+1] := true ; ) ; i := i + 1 ) ; dp[0+1][1+1] := 1 ; var i : int ; i := 1 ; while i < gy + 2 do ( ( var j : int ; j := 1 ; while j < gx + 2 do ( ( dp[i+1][j+1] := (if hasTabis[i+1][j+1][1+1] then 0 else dp[i - 1+1][j+1] endif) + (if hasTabis[i+1][j+1][0+1] then 0 else dp[i+1][j - 1+1] endif) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(if dp[gy + 1+1][gx + 1+1] = 0 then "Miserable Hokusai!" else dp[gy + 1+1][gx + 1+1] endif) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class _250B implements Runnable { private BufferedReader in ; private Object solve()throws IOException { StringBuilder sb=new StringBuilder(); for(int i=0,n=nextInt(); isplit(":") ; var k : int ; k := 0 ; var m : int ; m := s->size() - 1 ; if (s[k+1]->isEmpty()) then ( k := k + 1 ) else skip ; if (s[m+1]->isEmpty()) then ( m := m - 1 ) else skip ; var j : int ; j := k ; while j <= m do ( ( if (s[j+1]->isEmpty()) then ( var l : int ; l := 1 ; var lim : int ; lim := 8 - m + k ; while l <= lim do ( ( sb := sb + StringLib.newString("0000") ; if (l < lim) then ( sb := sb + StringLib.newString(':') ) else skip ) ; l := l + 1 ) ) else ( var l : int ; l := s[j+1]->size() ; while l < 4 do ( ( sb := sb + StringLib.newString('0') ) ; l := l + 1 ) ; sb := sb + StringLib.newString(s[j+1]) ) ; if (j < m) then ( sb := sb + StringLib.newString(':') ) else skip ) ; j := j + 1 ) ; sb := sb + StringLib.newString(' ') ; ) ; i := i + 1 ) ; return sb ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( ()50B.new()50B().run() ); operation run() : void pre: true post: true activity: ( try ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; OclFile["System.out"].print(solve()) ; skip ) catch (e : IOException) do ( OclProcess.exit(0) ) ); operation nextToken() : String pre: true post: true activity: ( return in.readLine() ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; public class Main { private static Scanner sc=new Scanner(System.in); static void p(String ans){ System.out.println(ans); }; static void p(int ans){ System.out.println(ans); }; static void p(long ans){ System.out.println(ans); }; static void p(double ans){ System.out.println(ans); }; static String s ; static String g ; static int a[]=new int[4]; public static void main(String[] args){ String N=sc.next(); for(int i=0 ; i<4 ; i++){ a[i]=N.charAt(i)-48 ; } if(dfs(1,a[0],"")){ p(a[0]+""+g.charAt(0)+""+a[1]+""+g.charAt(1)+""+a[2]+""+g.charAt(2)+""+a[3]+"=7"); } } static boolean dfs(int b,int sum,String v){ g=v ; if(b==4)return sum==7 ; if(dfs(b+1,sum+a[b],v+"+"))return true ; if(dfs(b+1,sum-a[b],v+"-"))return true ; return false ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation p( ans : String) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); static operation p( ans : int) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); static operation p( ans : long) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); static operation p( ans : double) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); static attribute s : String; static attribute g : String; static attribute a : int := Integer.subrange(1,4)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : String ; N := sc.getCurrent() ; var i : int ; i := 0 ; while i < 4 do ( ( a[i+1] := N->at(i+1) - 48 ) ; i := i + 1 ) ; if (dfs(1, a[0+1], "")) then ( execute p(a[0+1] + "" + g->at(0+1) + "" + a[1+1] + "" + g->at(1+1) + "" + a[2+1] + "" + g->at(2+1) + "" + a[3+1] + "=7") ) else skip ); static operation dfs( b : int, sum : int, v : String) : boolean pre: true post: true activity: ( g := v ; if (b = 4) then return sum = 7 else skip ; if (dfs(b + 1, sum + a[b+1], v + "+")) then return true else skip ; if (dfs(b + 1, sum - a[b+1], v + "-")) then return true else skip ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=10000 ; static int MAX_ELEMENT=50 ; static int[][][] dp=new int[MAX_ELEMENT][MAX_ELEMENT][MAX]; static int Max_Xor(int arr[],int i,int j,int mask,int n){ if(i>=n){ if(j==0)return mask ; else return 0 ; } if(dp[i][j][mask]!=-1)return dp[i][j][mask]; int ans=0 ; if(j>0)ans=Max_Xor(arr,i+1,j-1,mask ^ arr[i],n); ans=Math.max(ans,Max_Xor(arr,i+1,j,mask,n)); return dp[i][j][mask]=ans ; } public static void main(String[] args){ int arr[]={ 2,5,4,1,3,7,6,8 }; int n=arr.length ; int k=3 ; for(int i=0 ; icollect(Integer.subrange(1,MAX_ELEMENT)->collect(Integer.subrange(1,MAX)->collect(0))); static operation Max_Xor( arr : Sequence(int), i : int, j : int, mask : int, n : int) : int pre: true post: true activity: ( if (i >= n) 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 ; ans := 0 ; if (j > 0) then ans := Max_Xor(arr, i + 1, j - 1, mask xor arr[i+1], n) ; else skip ; ans := Set{ans, Max_Xor(arr, i + 1, j, mask, n)}->max() ; return dp[i+1][j+1][mask+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,5,4,1,3,7,6,8} ; var n : int ; n := arr->size() ; var k : int ; k := 3 ; var i : int ; i := 0 ; while i < MAX_ELEMENT do ( ( var j : int ; j := 0 ; while j < MAX_ELEMENT do ( ( var l : int ; l := 0 ; while l < MAX do ( dp[i+1][j+1][l+1] := -1 ; ; l := l + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Max_Xor(arr, 0, k, 0, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MaxIncreasingSub(int arr[],int n,int k){ int dp[][]=new int[n][k+1],ans=-1 ; for(int i=0 ; icollect(Integer.subrange(1,k + 1)->collect(0)) ; var ans : int ; ans := -1 ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < k + 1 do ( dp[i+1][j+1] := -1 ; ; j := j + 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( dp[i+1][1+1] := arr[i+1] ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := 0 ; while j < i do ( ( if (arr[j+1] < arr[i+1]) then ( var l : int ; l := 1 ; while l <= 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 ) ; l := l + 1 ) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (ans < dp[i+1][k+1]) then ans := dp[i+1][k+1] ; else skip ) ; i := i + 1 ) ; return if (ans = -1) then 0 else ans endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 8 ; var k : int ; k := 3 ; var arr : Sequence(int) ; arr := Sequence{8,5,9,10,5,6,21,8} ; var ans : int ; ans := MaxIncreasingSub(arr, n, k) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class First_Palin { static final int MAX_CHAR=26 ; static char stringPalindrome(String A,String B){ int[] countA=new int[MAX_CHAR]; int[] countB=new int[MAX_CHAR]; int l1=A.length(); int l2=B.length(); for(int i=0 ; i1 && countB[i]==0))return 'A' ; return 'B' ; } public static void main(String args[]){ String a="abcdea" ; String b="bcdesg" ; System.out.println(stringPalindrome(a,b)); } } ------------------------------------------------------------ OCL File: --------- class First_Palin { static attribute MAX_CHAR : int := 26; static operation stringPalindrome( A : String, B : String) : String pre: true post: true activity: ( var countA : Sequence(int) ; countA := Integer.subrange(1,MAX_CHAR)->collect(0) ; var countB : Sequence(int) ; countB := Integer.subrange(1,MAX_CHAR)->collect(0) ; var l1 : int ; l1 := A->size() ; var l2 : int ; l2 := B->size() ; var i : int ; i := 0 ; while i < l1 do ( countA[A->at(i+1) - ('a')->char2byte()+1] := countA[A->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < l2 do ( countB[B->at(i+1) - ('a')->char2byte()+1] := countB[B->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 26 do ( if ((countA[i+1] > 1 & countB[i+1] = 0)) then return 'A' else skip ; ; i := i + 1 ) ; return 'B' ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : String ; a := "abcdea" ; var b : String ; b := "bcdesg" ; OclFile["System.out"].println(stringPalindrome(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countPaths(int n){ int zB=1 ; int zADC=0 ; for(int i=1 ; i<=n ; i++){ int nzB=zADC*3 ; int nzADC=(zADC*2+zB); zB=nzB ; zADC=nzADC ; } return zB ; } public static void main(String[] args){ int n=3 ; System.out.println(countPaths(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countPaths( n : int) : int pre: true post: true activity: ( var zB : int ; zB := 1 ; var zADC : int ; zADC := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var nzB : int ; nzB := zADC * 3 ; var nzADC : int ; nzADC := (zADC * 2 + zB) ; zB := nzB ; zADC := nzADC ) ; i := i + 1 ) ; return zB ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(countPaths(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { cityDay1199A(); } public static void cityDay1199A(){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int x=scan.nextInt(); int y=scan.nextInt(); Boolean isNotsoRainyDay=true ; int[] a=new int[n]; for(int i=0 ; ia[j]){ isNotsoRainyDay=false ; break ; } } for(int k=i-1 ; k>=i-x && k>=0 && isNotsoRainyDay ; k--){ if(a[i]>a[k]){ isNotsoRainyDay=false ; break ; } } if(isNotsoRainyDay){ System.out.println(i+1); break ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute cityDay1199A() ); static operation cityDay1199A() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var x : int ; x := scan.getCurrent()->toInteger() ; var y : int ; y := scan.getCurrent()->toInteger() ; var isNotsoRainyDay : Boolean ; isNotsoRainyDay := true ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( isNotsoRainyDay := true ; var j : int ; j := i + 1 ; while j <= i + y & j < n do ( ( if (a[i+1] > a[j+1]) then ( isNotsoRainyDay := false ; break ) else skip ) ; j := j + 1 ) ; var k : int ; k := i - 1 ; while k >= i - x & k >= 0 & isNotsoRainyDay do ( ( if (a[i+1] > a[k+1]) then ( isNotsoRainyDay := false ; break ) else skip ) ; k := k - 1 ) ; if (isNotsoRainyDay) then ( OclFile["System.out"].println(i + 1) ; break ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class CityDay { public static void main(String[] args){ FastReader fr=new FastReader(); int n=fr.nextInt(); int x=fr.nextInt(); int y=fr.nextInt(); long[] rain=new long[n]; for(int i=0 ; i=i-x && j>=0 ; j--){ if(rain[j]collect(0) ; var i : int ; i := 0 ; while i < n do ( ( rain[i+1] := fr.nextInt() ) ; i := i + 1 ) ; var ans : int ; ans := -1 ; var i : int ; i := 0 ; while i < n do ( ( var left : boolean ; left := true ; var right : boolean ; right := true ; var j : int ; j := i - 1 ; while j >= i - x & j >= 0 do ( ( if (rain[j+1] < rain[i+1]) then ( left := false ) else skip ) ; j := j - 1 ) ; var j : int ; j := i + 1 ; while j <= i + y & j <= n - 1 do ( ( if (rain[j+1] < rain[i+1]) then ( right := false ) else skip ) ; j := j + 1 ) ; if (left & right) then ( ans := i ; break ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans + 1) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.util.*; class GFG { static int minChanges(int[] A,int n){ int cnt=0 ; for(int i=0 ; i=0)&& A[i-1]==1 && A[i+1]==1 && A[i]==0){ A[i+1]=0 ; cnt++; } } return cnt ; } public static void main(String args[]){ int[] A={ 1,1,0,1,1,0,1,0,1,0 }; int n=A.length ; System.out.print(minChanges(A,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minChanges( A : Sequence(int), n : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n - 2 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 ) ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : Sequence(int) ; A := Sequence{1,1,0,1,1,0,1,0,1,0} ; var n : int ; n := A->size() ; OclFile["System.out"].print(minChanges(A, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static String balancedBrackets(String str){ int dep=0 ; int minDep=0 ; for(int i=0 ; idep)minDep=dep ; } if(minDep<0){ for(int i=0 ; isize() do ( ( if (str->at(i+1) = '(') then dep := dep + 1 else dep := dep - 1 ; ; if (minDep > dep) then minDep := dep ; else skip ) ; i := i + 1 ) ; if (minDep < 0) then ( var i : int ; i := 0 ; while i < if minDep < 0 then -(minDep) else minDep endif do ( str := '(' + str ; ; i := i + 1 ) ) else skip ; dep := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = '(') then dep := dep + 1 ; else dep := dep - 1 ; ) ; i := i + 1 ) ; if (dep /= 0) then ( var i : int ; i := 0 ; while i < dep do ( str := str + ')' ; ; i := i + 1 ) ) else skip ; return str ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := ")))()" ; OclFile["System.out"].println(balancedBrackets(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Listdirec=new ArrayList(); direc.add("RIGHT"); direc.add("LEFT"); int n,m ; n=sc.nextInt(); while(n!=0){ int posX=1 ; int posY=1 ; int nowDirec=0 ; m=sc.nextInt(); while(true){ String instruct=sc.next(); if(instruct.equals("STOP")){ break ; } if(direc.contains(instruct)){ if(instruct.equals(direc.get(0))){ nowDirec++; nowDirec %=4 ; } else { nowDirec--; if(nowDirec==-1){ nowDirec=3 ; } } } else { int step=sc.nextInt(); if(instruct.equals("BACKWARD")){ step=-step ; } if(nowDirec==0){ posY+=step ; if(posY>m){ posY=m ; } if(posY<1){ posY=1 ; } } else if(nowDirec==1){ posX+=step ; if(posX>n){ posX=n ; } if(posX<1){ posX=1 ; } } else if(nowDirec==2){ posY-=step ; if(posY>m){ posY=m ; } if(posY<1){ posY=1 ; } } else if(nowDirec==3){ posX-=step ; if(posX>n){ posX=n ; } if(posX<1){ posX=1 ; } } } } System.out.println(posX+" "+posY); n=sc.nextInt(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var direc : Sequence(String) ; direc := Sequence{} ; direc := direc->including("RIGHT") ; direc := direc->including("LEFT") ; var n : int ; var m : int ; n := sc.getCurrent()->toInteger() ; while (n /= 0) do ( var posX : int ; posX := 1 ; var posY : int ; posY := 1 ; var nowDirec : int ; nowDirec := 0 ; m := sc.getCurrent()->toInteger() ; while (true) do ( var instruct : String ; instruct := sc.getCurrent() ; if (instruct = "STOP") then ( break ) else skip ; if (direc->includes(instruct)) then ( if (instruct = direc->at(0+1)) then ( nowDirec := nowDirec + 1 ; nowDirec := nowDirec mod 4 ) else ( nowDirec := nowDirec - 1 ; if (nowDirec = -1) then ( nowDirec := 3 ) else skip ) ) else ( var step : int ; step := sc.getCurrent()->toInteger() ; if (instruct = "BACKWARD") then ( step := -step ) else skip ; if (nowDirec = 0) then ( posY := posY+(step) ; if (posY > m) then ( posY := m ) else skip ; if (posY < 1) then ( posY := 1 ) else skip ) else if (nowDirec = 1) then ( posX := posX+(step) ; if (posX > n) then ( posX := n ) else skip ; if (posX < 1) then ( posX := 1 ) else skip ) else if (nowDirec = 2) then ( posY := posY-(step) ; if (posY > m) then ( posY := m ) else skip ; if (posY < 1) then ( posY := 1 ) else skip ) else if (nowDirec = 3) then ( posX := posX-(step) ; if (posX > n) then ( posX := n ) else skip ; if (posX < 1) then ( posX := 1 ) else skip ) else skip ; ; ; ) ) ; OclFile["System.out"].println(posX + " " + posY) ; n := sc.getCurrent()->toInteger() ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPerfectSquare(int[] arr,int n){ HashMapumap=new HashMap<>(); for(int i=0 ; i>iterator=umap.entrySet().iterator(); while(iterator.hasNext()){ Map.Entryentry=iterator.next(); if(entry.getValue()% 2==1)return false ; } return true ; } public static void main(String[] args){ int arr[]={ 2,2,7,7 }; int n=arr.length ; if(isPerfectSquare(arr,n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPerfectSquare( arr : Sequence(int), n : int) : boolean pre: true post: true activity: ( var umap : Map(int,int) ; umap := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (umap->keys()->includes(arr[i+1])) then umap := umap->union(Map{arr[i+1] |-> umap->at(arr[i+1]) + 1}) ; else umap := umap->union(Map{arr[i+1] |-> 1}) ; ) ; i := i + 1 ) ; var iterator : OclIterator ; iterator := umap->asSet()->iterator() ; while (iterator.hasNext()) do ( var entry : Map(int,int) ; entry := iterator.next() ; if (entry->values->any() mod 2 = 1) then return false else skip ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,2,7,7} ; var n : int ; n := arr->size() ; if (isPerfectSquare(arr, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countOne(int n){ int count=0 ; while(n>0){ n=n &(n-1); count++; } if(count % 2==0)return 1 ; else return 0 ; } static int sumDigits(int n){ int sum=0 ; while(n!=0){ sum+=n % 10 ; n/=10 ; } return sum ; } public static void main(String[] args){ int arr[]={ 4,9,15 }; int n=arr.length ; int total_sum=0 ; for(int i=0 ; i 0) do ( n := n & (n - 1) ; count := count + 1 ) ; if (count mod 2 = 0) then return 1 else return 0 ); static operation sumDigits( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; while (n /= 0) do ( sum := sum+(n mod 10) ; n := n/(10) ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{4,9,15} ; var n : int ; n := arr->size() ; var total_sum : int ; total_sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (countOne(arr[i+1]) = 1) then total_sum := total_sum+(sumDigits(arr[i+1])) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(total_sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int __gcd(int a,int b){ return b==0 ? a : __gcd(b,a % b); } static int digitGCD(int n){ int gcd=0 ; while(n>0){ gcd=__gcd(n % 10,gcd); if(gcd==1)return 1 ; n=n/10 ; } return gcd ; } public static void main(String[] args){ int n=2448 ; System.out.print(digitGCD(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation __gcd( a : int, b : int) : int pre: true post: true activity: ( return if b = 0 then a else __gcd(b, a mod b) endif ); static operation digitGCD( n : int) : int pre: true post: true activity: ( var gcd : int ; gcd := 0 ; while (n > 0) do ( gcd := __gcd(n mod 10, gcd) ; if (gcd = 1) then return 1 else skip ; n := n / 10 ) ; return gcd ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2448 ; OclFile["System.out"].print(digitGCD(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int dx[]={ 1,0 }; int dy[]={ 0,1 }; while(in.hasNext()){ int H=in.nextInt(); int W=in.nextInt(); int cost[][]=new int[H][W]; int map[][]=new int[H][W]; LinkedListque=new LinkedList(); for(int i=0 ; icost[nh][nw]+map[h][w]){ cost[h][w]=cost[nh][nw]+map[h][w]; que.add(h+" "+w); } } } } } System.out.println(cost[H-1][W-1]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var dx : Sequence(int) ; dx := Sequence{1,0} ; var dy : Sequence(int) ; dy := Sequence{0,1} ; while (in.hasNext()) do ( var H : int ; H := in.getCurrent()->toInteger() ; var W : int ; W := in.getCurrent()->toInteger() ; var cost : Sequence(Sequence(int)) ; cost := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var map : Sequence(Sequence(int)) ; map := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var que : Sequence(String) ; que := Sequence{} ; var i : int ; i := 0 ; while i < H do ( ( cost[i+1] := cost[i+1]->collect(1000) ; var st : String ; st := in.getCurrent() ; var j : int ; j := 0 ; while j < W do ( map[i+1][j+1] := (st->at(j+1) - ('0')->char2byte())->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; cost[0+1][0+1] := 0 ; que := que->including(0 + " " + 0) ; while (not(que->isEmpty())) do ( var size : int ; size := que->size() ; var i : int ; i := 0 ; while i < size do ( ( var now : Sequence(String) ; now := que->min()->split(" ") ; var nh : int ; nh := (now[0+1])->toInteger() ; var nw : int ; nw := (now[1+1])->toInteger() ; var j : int ; j := 0 ; while j < 2 do ( ( var h : int ; h := dy[j+1] + nh ; var w : int ; w := dx[j+1] + nw ; if (h < H & w < W) then ( if (cost[h+1][w+1] > cost[nh+1][nw+1] + map[h+1][w+1]) then ( cost[h+1][w+1] := cost[nh+1][nw+1] + map[h+1][w+1] ; que := que->including(h + " " + w) ) else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; OclFile["System.out"].println(cost[H - 1+1][W - 1+1]) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { static int INF=Integer.MAX_VALUE ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; line=br.readLine(); int H,W ; H=parseInt(line.substring(0,line.indexOf(' '))); W=parseInt(line.substring(line.indexOf(' ')+1)); int[][] dp=new int[H+2][W+2]; for(int i=0 ; iindexOf(' ')-1) + "")->toInteger() ; W := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,H + 2)->collect(Integer.subrange(1,W + 2)->collect(0)) ; var i : int ; i := 0 ; while i < H + 2 do ( ( var j : int ; j := 0 ; while j < W + 2 do ( ( dp[i+1][j+1] := INF ) ; j := j + 1 ) ) ; i := i + 1 ) ; dp[0+1][1+1] := 0 ; dp[1+1][0+1] := 0 ; var i : int ; i := 0 ; while i < H do ( ( line := br.readLine() ; var j : int ; j := 0 ; while j < W do ( ( dp[i + 1+1][j + 1+1] := line->at(j+1) - ('0')->char2byte() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= H do ( ( var j : int ; j := 1 ; while j <= W do ( ( dp[i+1][j+1] := dp[i+1][j+1]+(Set{dp[i+1][j - 1+1], dp[i - 1+1][j+1]}->min()) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dp[H+1][W+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); String[] line=s.nextLine().split(" "); int height=Integer.parseInt(line[0]); int width=Integer.parseInt(line[1]); int[][] input=new int[width+1][height+1]; for(int i=1 ; i<=height ; i++){ String str=s.nextLine(); for(int j=1 ; j<=width ; j++){ input[j][i]=Integer.parseInt(str.substring(j-1,j)); } } System.out.println(solve(height,width,input)); } public static int solve(int height,int width,int[][] input){ int[][] result=new int[width+1][height+1]; for(int i=0 ; i<=width ; i++){ result[i][0]=Integer.MAX_VALUE ; } for(int i=0 ; i<=height ; i++){ result[0][i]=Integer.MAX_VALUE ; } result[0][1]=0 ; result[1][0]=0 ; for(int i=1 ; i<=width ; i++){ for(int j=1 ; j<=height ; j++){ if(result[i-1][j]>=result[i][j-1])result[i][j]=result[i][j-1]+input[i][j]; else result[i][j]=result[i-1][j]+input[i][j]; } } return result[width][height]; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var line : Sequence(String) ; line := s.nextLine()->split(" ") ; var height : int ; height := (line[0+1])->toInteger() ; var width : int ; width := (line[1+1])->toInteger() ; var input : Sequence(Sequence(int)) ; input := Integer.subrange(1,width + 1)->collect(Integer.subrange(1,height + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= height do ( ( var str : String ; str := s.nextLine() ; var j : int ; j := 1 ; while j <= width do ( ( input[j+1][i+1] := (str.subrange((j)->char2byte() - 1+1,j))->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(height, width, input)) ; ); static operation solve( height : int, width : int, input : Sequence(Sequence(int))) : int pre: true post: true activity: ( var result : Sequence(Sequence(int)) ; result := Integer.subrange(1,width + 1)->collect(Integer.subrange(1,height + 1)->collect(0)) ; var i : int ; i := 0 ; while i <= width do ( ( result[i+1][0+1] := 2147483647 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= height do ( ( result[0+1][i+1] := 2147483647 ) ; i := i + 1 ) ; result[0+1][1+1] := 0 ; result[1+1][0+1] := 0 ; var i : int ; i := 1 ; while i <= width do ( ( var j : int ; j := 1 ; while j <= height do ( ( if (result[i - 1+1][j+1] >= result[i+1][(j)->char2byte() - 1+1]) then result[i+1][j+1] := result[i+1][(j)->char2byte() - 1+1] + input[i+1][j+1] ; else result[i+1][j+1] := result[i - 1+1][j+1] + input[i+1][j+1] ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return result[width+1][height+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); char[][] m=new char[h][w]; int[][] c=new int[h][w]; for(int i=0 ; i=0 ; j--)dp[h-1][j]=dp[h-1][j+1]+c[h-1][j]; for(int i=h-2 ; i>=0 ; i--)dp[i][w-1]=dp[i+1][w-1]+c[i][w-1]; for(int i=h-2 ; i>=0 ; i--)for(int j=w-2 ; j>=0 ; j--)dp[i][j]=c[i][j]+Math.min(dp[i+1][j],dp[i][j+1]); System.out.println(dp[0][0]); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var m : Sequence(Sequence(String)) ; m := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var c : Sequence(Sequence(int)) ; c := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( m[i+1] := sc.getCurrent()->characters() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < h do ( var j : int ; j := 0 ; while j < w do ( c[i+1][j+1] := m[i+1][j+1] - ('0')->char2byte() ; ; j := j + 1 ) ; ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; dp[h - 1+1][w - 1+1] := c[h - 1+1][w - 1+1] ; var j : int ; j := w - 2 ; while j >= 0 do ( dp[h - 1+1][j+1] := dp[h - 1+1][j + 1+1] + c[h - 1+1][j+1] ; ; j := j - 1 ) ; var i : int ; i := h - 2 ; while i >= 0 do ( dp[i+1][w - 1+1] := dp[i + 1+1][w - 1+1] + c[i+1][w - 1+1] ; ; i := i - 1 ) ; var i : int ; i := h - 2 ; while i >= 0 do ( var j : int ; j := w - 2 ; while j >= 0 do ( dp[i+1][j+1] := c[i+1][j+1] + Set{dp[i + 1+1][j+1], dp[i+1][j + 1+1]}->min() ; ; j := j - 1 ) ; ; i := i - 1 ) ; OclFile["System.out"].println(dp[0+1][0+1]) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int[][] map=new int[h][w]; int[][] cost=new int[h][w]; for(int i=0 ; ix=new ArrayDeque(); ArrayDequey=new ArrayDeque(); x.offer(0); y.offer(0); cost[0][0]=0 ; int p,q ; while(x.size()!=0){ p=x.poll(); q=y.poll(); if(p!=w-1 && cost[q][p]+map[q][p+1]toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var map : Sequence(Sequence(int)) ; map := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var cost : Sequence(Sequence(int)) ; cost := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( var a : Sequence(String) ; a := sc.getCurrent()->characters() ; var j : int ; j := 0 ; while j < w do ( map[i+1][j+1] := a[j+1]->oclAsType(int) - 48 ; ; j := j + 1 ) ; cost[i+1] := cost[i+1]->collect(2147483647) ) ; i := i + 1 ) ; var x : Sequence(int) ; x := ArrayDeque.newArrayDeque() ; var y : Sequence(int) ; y := ArrayDeque.newArrayDeque() ; x := x->including(0) ; y := y->including(0) ; cost[0+1][0+1] := 0 ; var p : int ; var q : int ; while (x->size() /= 0) do ( p := x->min() ; x := x->sort()->tail() ; q := y->min() ; y := y->sort()->tail() ; if (p /= w - 1 & cost[q+1][p+1] + map[q+1][p + 1+1] < cost[q+1][p + 1+1]) then ( x := x->including(p + 1) ; y := y->including(q) ; cost[q+1][p + 1+1] := cost[q+1][p+1] + map[q+1][p + 1+1] ) else skip ; if (q /= h - 1 & cost[q+1][p+1] + map[q + 1+1][p+1] < cost[q + 1+1][p+1]) then ( x := x->including(p) ; y := y->including(q + 1) ; cost[q + 1+1][p+1] := cost[q+1][p+1] + map[q + 1+1][p+1] ) else skip ) ; OclFile["System.out"].println(cost[h - 1+1][w - 1+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class PensAndPencils { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int[][] ans=new int[t][]; for(int i=0 ; itoInteger() ; var ans : Sequence(Sequence(int)) ; ans := Integer.subrange(1,t)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < t do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var pens : int ; pens := a / c ; var pencil : int ; pencil := b / d ; var rem : int ; rem := a mod c ; if (rem /= 0) then pens := pens+(1) ; else skip ; rem := b mod d ; if (rem /= 0) then pencil := pencil+(1) ; else skip ; if (pens + pencil <= k) then ans[i+1] := (Sequence{pens,pencil}) else ans[i+1] := (Sequence{-1}) ; ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < ans->size() do ( ( for (el : ans[i+1]) do ( ( OclFile["System.out"].print(el + " ") ) ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); int k=sc.nextInt(); int pen=1 ; while(c*pentoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var pen : int ; pen := 1 ; while (c * pen < a) do ( pen := pen + 1 ) ; var pencile : int ; pencile := 1 ; while (pencile * d < b) do ( pencile := pencile + 1 ) ; if (pen + pencile <= k) then OclFile["System.out"].println(pen + " " + pencile) else OclFile["System.out"].println(-1) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.function.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int ABCD=s.nextInt(); StringBuilder str=new StringBuilder(); StringBuilder abcd=new StringBuilder(String.format("%04d",ABCD)); for(int i=0 ; i<(1<<3); i++){ int candidate=ABCD/1000 ; int tmp=ABCD ; for(int j=0 ; j<3 ; j++){ if(((i>>j)& 1)==1){ candidate+=tmp % 10 ; str.insert(0,"+"); } else { candidate-=tmp % 10 ; str.insert(0,"-"); } tmp/=10 ; } if(candidate==7){ abcd.insert(1,str.charAt(0)); abcd.insert(3,str.charAt(1)); abcd.insert(5,str.charAt(2)); abcd.append("=7"); System.out.println(abcd.toString()); return ; } str=new StringBuilder(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ABCD : int ; ABCD := s.getCurrent()->toInteger() ; var str : String ; str := StringLib.newString() ; var abcd : String ; abcd := StringLib.newString(StringLib.format("%04d",Sequence{ABCD})) ; var i : int ; i := 0 ; while i < ((1*(2->pow(3)))->oclAsType(long)) do ( ( var candidate : int ; candidate := ABCD / 1000 ; var tmp : int ; tmp := ABCD ; var j : int ; j := 0 ; while j < 3 do ( ( if ((((i/(2->pow(j)))->oclAsType(long)) & 1) = 1) then ( candidate := candidate+(tmp mod 10) ; str := str.insertAt(0+1, StringLib.newString("+")) ) else ( candidate := candidate-(tmp mod 10) ; str := str.insertAt(0+1, StringLib.newString("-")) ) ; tmp := tmp/(10) ) ; j := j + 1 ) ; if (candidate = 7) then ( abcd := abcd.insertAt(1+1, StringLib.newString(str->at(0+1))) ; abcd := abcd.insertAt(3+1, StringLib.newString(str->at(1+1))) ; abcd := abcd.insertAt(5+1, StringLib.newString(str->at(2+1))) ; abcd := abcd + StringLib.newString("=7") ; OclFile["System.out"].println(abcd+"") ; return ) else skip ; str := StringLib.newString() ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int n=sc.nextInt(); int[][] field=new int[h][w]; int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var field : Sequence(Sequence(int)) ; field := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var hh : int ; hh := 0 ; var ww : int ; ww := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < arr[i+1] do ( ( field[hh+1][ww+1] := i + 1 ; if (hh mod 2 = 0) then ( if (ww = w - 1) then ( hh := hh + 1 ) else ( ww := ww + 1 ) ) else ( if (ww = 0) then ( hh := hh + 1 ) else ( ww := ww - 1 ) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( if (j /= 0) then ( sb := sb + StringLib.newString(" ") ) else skip ; sb := sb + StringLib.newString(field[i+1][j+1]) ) ; j := j + 1 ) ; sb := sb + StringLib.newString("\n") ) ; i := i + 1 ) ; OclFile["System.out"].print(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.HashMap ; import java.util.Random ; import java.util.StringTokenizer ; public class B { public static void main(String[] args){ FastScanner fs=new FastScanner(); int n=fs.nextInt(); int[] maxes=new int[1_000_001]; int[] mins=new int[1_000_001]; long withAscent=0 ; for(int i=0 ; iminSeen){ ascent=true ; } minSeen=Math.min(minSeen,next); maxSeen=Math.max(maxSeen,next); } if(ascent){ withAscent++; } else { maxes[maxSeen]++; mins[minSeen]++; } } long ans=0 ; ans+=withAscent*n+(n-withAscent)*withAscent ; long maxSeen=0 ; for(int i=maxes.length-1 ; i>=0 ; i--){ ans+=mins[i]*maxSeen ; maxSeen+=maxes[i]; } System.out.println(ans); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreElements())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fs : FastScanner ; fs := FastScanner.newFastScanner() ; var n : int ; n := fs.nextInt() ; var maxes : Sequence(int) ; maxes := Integer.subrange(1,1_000_001)->collect(0) ; var mins : Sequence(int) ; mins := Integer.subrange(1,1_000_001)->collect(0) ; var withAscent : long ; withAscent := 0 ; var i : int ; i := 0 ; while i < n do ( ( var l : int ; l := fs.nextInt() ; var minSeen : int ; minSeen := 2147483647 ; var maxSeen : int ; maxSeen := -1 ; var ascent : boolean ; ascent := false ; var j : int ; j := 0 ; while j < l do ( ( var next : int ; next := fs.nextInt() ; if (next > minSeen) then ( ascent := true ) else skip ; minSeen := Set{minSeen, next}->min() ; maxSeen := Set{maxSeen, next}->max() ) ; j := j + 1 ) ; if (ascent) then ( withAscent := withAscent + 1 ) else ( maxes[maxSeen+1] := maxes[maxSeen+1] + 1 ; mins[minSeen+1] := mins[minSeen+1] + 1 ) ; ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; ans := ans+(withAscent * n + (n - withAscent) * withAscent) ; var maxSeen : long ; maxSeen := 0 ; var i : int ; i := maxes->size() - 1 ; while i >= 0 do ( ( ans := ans+(mins[i+1] * maxSeen) ; maxSeen := maxSeen+(maxes[i+1]) ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int lcm_fun(int a,int b){ if(b==0)return a ; return lcm_fun(b,a % b); } static int digitLCM(int n){ int lcm=1 ; while(n>0){ lcm=(n % 10*lcm)/lcm_fun(n % 10,lcm); if(lcm==0)return 0 ; n=n/10 ; } return lcm ; } public static void main(String[] args){ int n=397 ; System.out.println(digitLCM(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation lcm_fun( a : int, b : int) : int pre: true post: true activity: ( if (b = 0) then return a else skip ; return lcm_fun(b, a mod b) ); static operation digitLCM( n : int) : int pre: true post: true activity: ( var lcm : int ; lcm := 1 ; while (n > 0) do ( lcm := (n mod 10 * lcm) / lcm_fun(n mod 10, lcm) ; if (lcm = 0) then return 0 else skip ; n := n / 10 ) ; return lcm ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 397 ; OclFile["System.out"].println(digitLCM(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.awt.*; import java.awt.geom.Point2D ; import static java.lang.System.*; import static java.lang.Math.*; public class Main { public static void main(String[] $){ int h=sc.nextInt(); int w=sc.nextInt(); int n=sc.nextInt(); int[] a=new int[n]; Point[] p=new Point[h*w]; for(int i=0 ; icollect(0) ; var p : Sequence(Point) ; p := Integer.subrange(1,h * w)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.nextInt() ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( if (i mod 2 = 0) then ( p[count+1] := Point.newPoint(i, j) ; count := count + 1 ) else ( p[count+1] := Point.newPoint(i, w - 1 - j) ; count := count + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var c : Sequence(Sequence(int)) ; c := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var color : int ; color := i + 1 ; var j : int ; j := 0 ; while j < a[i+1] do ( ( c[p[count+1].x+1][p[count+1].y+1] := color ; count := count + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( out.print(c[i+1][j+1]) ; if (j < w - 1) then out.print(" ") ; else skip ) ; j := j + 1 ) ; out.println() ) ; i := i + 1 ) ; ); static class sc { static attribute s : OclFile := OclFile.newOclFile_Read(in); static operation next() : String pre: true post: true activity: ( return s.getCurrent() ); static operation nextInt() : int pre: true post: true activity: ( return (s.getCurrent())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (s.getCurrent())->toLong() ); static operation nextDouble() : double pre: true post: true activity: ( return (s.getCurrent())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Main m=new Main(); m.answer(); } private Scanner scan=new Scanner(System.in); private int H ; private int W ; private int N ; private int[] a ; public Main(){ H=Integer.parseInt(scan.next()); W=Integer.parseInt(scan.next()); N=Integer.parseInt(scan.next()); a=new int[N]; for(int i=0 ; itoInteger() ; W := (scan.getCurrent())->toInteger() ; N := (scan.getCurrent())->toInteger() ; a := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := (scan.getCurrent())->toInteger() ) ; i := i + 1 ) ; skip ; ); operation answer() : void pre: true post: true activity: ( var number : Sequence(int) ; number := Integer.subrange(1,H * W)->collect(0) ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < a[i+1] do ( ( number[index+1] := i + 1 ; index := index + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var str : String ; str := StringLib.newString() ; var h : int ; h := 0 ; while h < H do ( ( var w : int ; w := 0 ; while w < W do ( ( if (h mod 2 = 0) then ( str := str + StringLib.newString(number[h * W + w+1]) ) else ( str := str + StringLib.newString(number[(h + 1) * W - 1 - w+1]) ) ; if (w < W - 1) then str := str + StringLib.newString(' ') ; else skip ) ; w := w + 1 ) ; str := str + StringLib.newString(' ') ) ; h := h + 1 ) ; OclFile["System.out"].println(str+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int h=scan.nextInt(); int w=scan.nextInt(); int n=scan.nextInt(); int[] c=new int[n]; for(int i=0 ; i>a=new ArrayList>(); for(int i=0 ; ib=new ArrayList(); a.add(b); } int f=1 ; int current=0 ; for(int i=0 ; i0){ ArrayListg=a.get(current); g.add(i+1); current+=f ; if(current==h){ current=h-1 ; f=-1 ; } if(current==-1){ current=0 ; f=1 ; } count-=1 ; } } for(int j=0 ; jm=a.get(j); for(int k=0 ; ktoInteger() ; var w : int ; w := scan.getCurrent()->toInteger() ; var n : int ; n := scan.getCurrent()->toInteger() ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( c[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var a : Sequence(Sequence(int)) ; a := Sequence{} ; var i : int ; i := 0 ; while i < h do ( ( var b : Sequence(int) ; b := Sequence{} ; a := a->including(b) ) ; i := i + 1 ) ; var f : int ; f := 1 ; var current : int ; current := 0 ; var i : int ; i := 0 ; while i < n do ( ( var count : int ; count := c[i+1] ; while (count > 0) do ( var g : Sequence(int) ; g := a->at(current+1) ; g := g->including(i + 1) ; current := current+(f) ; if (current = h) then ( current := h - 1 ; f := -1 ) else skip ; if (current = -1) then ( current := 0 ; f := 1 ) else skip ; count := count-(1) ; ) ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < h do ( ( var m : Sequence(int) ; m := a->at(j+1) ; var k : int ; k := 0 ; while k < w - 1 do ( ( OclFile["System.out"].print(m->at(k+1) + " ") ) ; k := k + 1 ) ; OclFile["System.out"].println(m->at(w - 1+1)) ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int R=input.nextInt(); int C=input.nextInt(); int N=input.nextInt(); int[] arr=new int[N+1]; int[][] ans=new int[R][C]; for(int i=1 ; i<=N ; i++){ arr[i]=input.nextInt(); } int index=1 ; for(int r=0 ; r=0 ; c--){ ans[r][c]=index ; arr[index]--; if(arr[index]==0)index++; } } } for(int i=0 ; itoInteger() ; var C : int ; C := input.getCurrent()->toInteger() ; var N : int ; N := input.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,N + 1)->collect(0) ; var ans : Sequence(Sequence(int)) ; ans := Integer.subrange(1,R)->collect(Integer.subrange(1,C)->collect(0)) ; var i : int ; i := 1 ; while i <= N do ( ( arr[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ; var index : int ; index := 1 ; var r : int ; r := 0 ; while r < R do ( ( if (r mod 2 = 0) then ( var c : int ; c := 0 ; while c < C do ( ( ans[r+1][c+1] := index ; arr[index+1] := arr[index+1] - 1 ; if (arr[index+1] = 0) then index := index + 1 ; else skip ) ; c := c + 1 ) ) else ( var c : int ; c := C - 1 ; while c >= 0 do ( ( ans[r+1][c+1] := index ; arr[index+1] := arr[index+1] - 1 ; if (arr[index+1] = 0) then index := index + 1 ; else skip ) ; c := c - 1 ) ) ) ; r := r + 1 ) ; var i : int ; i := 0 ; while i < R do ( ( var j : int ; j := 0 ; while j < C do ( ( OclFile["System.out"].print(ans[i+1][j+1] + " ") ) ; j := j + 1 ) ; OclFile["System.out"].print("\n") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); int[] arr=new int[n]; for(int i=0 ; ia[1]!=b[1] ? a[1]-b[1] : a[0]-b[0]); StringBuilder sb=new StringBuilder(); while(timea[1]!=b[1] ? a[1]-b[1] : a[0]-b[0]); time++; } System.out.println(set[n-1][1]-set[0][1]+" "+time); System.out.println(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute printOperations(n, k, arr) ; ); static operation printOperations( n : int, k : int, arr : Sequence(int)) : void pre: true post: true activity: ( if (n = 1) then ( OclFile["System.out"].println(0 + " " + 0) ; return ) else skip ; var set : Sequence(Sequence(int)) ; set := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( set[i+1] := Sequence{i + 1,arr[i+1]} ) ; i := i + 1 ) ; var time : int ; time := 0 ; set := OclComparator.sortWith(set, lambda (a , b) : OclAny in if a[1+1] /= b[1+1] then a[1+1] - b[1+1] else a[0+1] - b[0+1] endif) ; var sb : String ; sb := StringLib.newString() ; while (time < k) do ( var max : Sequence(int) ; max := set[n - 1+1] ; var min : Sequence(int) ; min := set[0+1] ; if (max[1+1] - min[1+1] <= 1) then ( break ) else skip ; sb := sb + StringLib.newString(max[0+1]) + StringLib.newString(" ") + StringLib.newString(min[0+1]) + StringLib.newString("\n") ; max[1+1] := max[1+1] - 1 ; min[1+1] := min[1+1] + 1 ; set := OclComparator.sortWith(set, lambda (a , b) : OclAny in if a[1+1] /= b[1+1] then a[1+1] - b[1+1] else a[0+1] - b[0+1] endif) ; time := time + 1 ; ) ; OclFile["System.out"].println(set[n - 1+1][1+1] - set[0+1][1+1] + " " + time) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); int[] arr=new int[n]; for(int i=0 ; iset=new TreeSet<>((a,b)->a[1]!=b[1] ? a[1]-b[1] : a[0]-b[0]); for(int i=0 ; itoInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute printOperations(n, k, arr) ; ); static operation printOperations( n : int, k : int, arr : Sequence(int)) : void pre: true post: true activity: ( if (n = 1) then ( OclFile["System.out"].println(0 + " " + 0) ; return ) else skip ; var set : Set(Sequence(int)) ; set := Set{}->union(lambda (a , b) : OclAny in if a[1+1] /= b[1+1] then a[1+1] - b[1+1] else a[0+1] - b[0+1] endif) ; var i : int ; i := 0 ; while i < n do ( ( set := set->including(Sequence{i + 1,arr[i+1]}) ) ; i := i + 1 ) ; var time : int ; time := 0 ; var diff : int ; diff := 2147483647 ; var sb : String ; sb := StringLib.newString() ; while (time < k) do ( var min : Sequence(int) ; min := set->first() ; var max : Sequence(int) ; max := set->last() ; diff := max[1+1] - min[1+1] ; if (diff <= 1) then ( set := set->including(min) ; set := set->including(max) ; break ) else skip ; sb := sb + StringLib.newString(max[0+1]) + StringLib.newString(" ") + StringLib.newString(min[0+1]) + StringLib.newString("\n") ; max[1+1] := max[1+1] - 1 ; min[1+1] := min[1+1] + 1 ; set := set->including(min) ; set := set->including(max) ; time := time + 1 ; ) ; var min : Sequence(int) ; min := set->first() ; var max : Sequence(int) ; max := set->last() ; diff := max[1+1] - min[1+1] ; OclFile["System.out"].println(diff + " " + time) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class C { public static void main(String[] args)throws Exception { Scanner in=new Scanner(new File("C-large.in")); PrintWriter out=new PrintWriter(new FileWriter(new File("C-large.out"))); int t=in.nextInt(); for(int x=0 ; xangles=new ArrayList(); for(int a=0 ; atoInteger() ; var x : int ; x := 0 ; while x < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var xs : Sequence(int) ; xs := Integer.subrange(1,n)->collect(0) ; var ys : Sequence(int) ; ys := Integer.subrange(1,n)->collect(0) ; var y : int ; y := 0 ; while y < n do ( ( xs[y+1] := in.getCurrent()->toInteger() ; ys[y+1] := in.getCurrent()->toInteger() ) ; y := y + 1 ) ; skip ; var z : int ; z := 0 ; while z < xs->size() do ( ( var angles : Sequence(double) ; angles := Sequence{} ; var a : int ; a := 0 ; while a < xs->size() do ( ( if (a /= z) then ( var current : double ; current := atan2(ys[a+1] - ys[z+1], xs[a+1] - xs[z+1]) ; angles := angles->including(current) ; angles := angles->including(current + 2.0 * 3.141592653589793) ) else skip ) ; a := a + 1 ) ; angles := angles->sort() ; var index : int ; index := 0 ; var result : int ; result := n ; var b : int ; b := 0 ; while b < n do ( ( while (index < angles->size() & angles->at(index+1) < angles->at(b+1) + 3.141592653589793 + 1E-12) do ( index := index + 1 ) ; result := Set{result, n - (index - b) - 1}->min() ) ; b := b + 1 ) ; if (n = 1) then ( skip ) else ( skip ) ; ) ; z := z + 1 ) ; ) ; x := x + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int ABCD=scn.nextInt(); int A=ABCD/1000 ; int B=(ABCD % 1000)/100 ; int C=(ABCD % 100)/10 ; int D=ABCD % 10 ; if(A+B+C+D==7){ System.out.println(A+"+"+B+"+"+C+"+"+D+"="+7); return ; } if(A+B+C-D==7){ System.out.println(A+"+"+B+"+"+C+"-"+D+"="+7); return ; } if(A+B-C+D==7){ System.out.println(A+"+"+B+"-"+C+"+"+D+"="+7); return ; } if(A+B-C-D==7){ System.out.println(A+"+"+B+"-"+C+"-"+D+"="+7); return ; } if(A-B+C+D==7){ System.out.println(A+"-"+B+"+"+C+"+"+D+"="+7); return ; } if(A-B+C-D==7){ System.out.println(A+"-"+B+"+"+C+"-"+D+"="+7); return ; } if(A-B-C+D==7){ System.out.println(A+"-"+B+"-"+C+"+"+D+"="+7); return ; } if(A-B-C-D==7){ System.out.println(A+"-"+B+"-"+C+"-"+D+"="+7); return ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ABCD : int ; ABCD := scn.getCurrent()->toInteger() ; var A : int ; A := ABCD / 1000 ; var B : int ; B := (ABCD mod 1000) / 100 ; var C : int ; C := (ABCD mod 100) / 10 ; var D : int ; D := ABCD mod 10 ; if (A + B + C + D = 7) then ( OclFile["System.out"].println(A + "+" + B + "+" + C + "+" + D + "=" + 7) ; return ) else skip ; if (A + B + C - D = 7) then ( OclFile["System.out"].println(A + "+" + B + "+" + C + "-" + D + "=" + 7) ; return ) else skip ; if (A + B - C + D = 7) then ( OclFile["System.out"].println(A + "+" + B + "-" + C + "+" + D + "=" + 7) ; return ) else skip ; if (A + B - C - D = 7) then ( OclFile["System.out"].println(A + "+" + B + "-" + C + "-" + D + "=" + 7) ; return ) else skip ; if (A - B + C + D = 7) then ( OclFile["System.out"].println(A + "-" + B + "+" + C + "+" + D + "=" + 7) ; return ) else skip ; if (A - B + C - D = 7) then ( OclFile["System.out"].println(A + "-" + B + "+" + C + "-" + D + "=" + 7) ; return ) else skip ; if (A - B - C + D = 7) then ( OclFile["System.out"].println(A + "-" + B + "-" + C + "+" + D + "=" + 7) ; return ) else skip ; if (A - B - C - D = 7) then ( OclFile["System.out"].println(A + "-" + B + "-" + C + "-" + D + "=" + 7) ; return ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static int FindMinNum(int arr[],int n){ int pre[]=new int[n]; pre[0]=arr[0]; for(int i=1 ; i=pre[i])k=Math.min(k,rightSum-pre[i]); } if(k!=Integer.MAX_VALUE)return k ; return-1 ; } public static void main(String[] args){ int arr[]={ 6,7,1,3,8,2,4 }; int n=arr.length ; System.out.println(FindMinNum(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation FindMinNum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var pre : Sequence(int) ; pre := Integer.subrange(1,n)->collect(0) ; pre[0+1] := arr[0+1] ; var i : int ; i := 1 ; while i < n do ( pre[i+1] := pre[i - 1+1] + arr[i+1] ; ; i := i + 1 ) ; var k : int ; k := 2147483647 ; var i : int ; i := 0 ; while i < n - 1 do ( ( var rightSum : int ; rightSum := pre[n - 1+1] - pre[i+1] ; if (rightSum >= pre[i+1]) then k := Set{k, rightSum - pre[i+1]}->min() ; else skip ) ; i := i + 1 ) ; if (k /= 2147483647) then return k else skip ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{6,7,1,3,8,2,4} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(FindMinNum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static long gcd(long a,long b){ if(a==0)return b ; return gcd(b % a,a); } static long divTermCount(long a,long b,long c,long 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)))); } static public void main(String[] arr){ long a=7,b=3,c=5,n=100 ; System.out.println(divTermCount(a,b,c,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation divTermCount( a : long, b : long, c : long, num : long) : long 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)))) ); static operation main( arr : Sequence(String)) : void pre: true post: true activity: ( var a : long ; a := 7 ; var b : long ; b := 3 ; var c : long ; c := 5 ; var n : long ; n := 100 ; OclFile["System.out"].println(divTermCount(a, b, c, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package round3 ; import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.Scanner ; public class D { private int s ; private boolean[][] z ; private int d ; public static void main(String[] args)throws FileNotFoundException { Scanner in=new Scanner(new File(D.class.getSimpleName()+".in")); PrintWriter out=new PrintWriter(new File(D.class.getSimpleName()+".out")); int T=in.nextInt(); for(int i=0 ; i0){ if(z[k][j % d]){ ok=false ; break ; } j/=d ; k++; } if(ok){ j=i ; k=0 ; while(j>0){ z[k][j % d]=true ; j/=d ; k++; } calc(n-i,i); j=i ; k=0 ; while(j>0){ z[k][j % d]=false ; j/=d ; k++; } } } } } ------------------------------------------------------------ OCL File: --------- class D { attribute s : int; attribute z : Sequence(Sequence(boolean)); attribute d : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile(OclType["D"].getSimpleName() + ".in")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile(OclType["D"].getSimpleName() + ".out")) ; var T : int ; T := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < T do ( ( var s : String ; s := "Case #" + (i + 1) + ": " + D.newD().solve(in) ; skip ; OclFile["System.out"].println(s) ) ; i := i + 1 ) ; skip ; ); operation solve( in : OclFile) : String pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; d := in.getCurrent()->toInteger() ; s := 0 ; z := Integer.subrange(1,10)->collect(Integer.subrange(1,d)->collect(false)) ; execute calc(n, 0) ; return "" + s ); operation calc( n : int, p : int) : void pre: true post: true activity: ( if (n = 0) then ( s := s + 1 ; return ) else skip ; var i : int ; i := p + 1 ; while i <= n do ( ( var j : int ; j := i ; var k : int ; k := 0 ; var ok : boolean ; ok := true ; while (j > 0) do ( if (z[k+1][j mod d+1]) then ( ok := false ; break ) else skip ; j := j/(d) ; k := k + 1 ) ; if (ok) then ( j := i ; k := 0 ; while (j > 0) do ( z[k+1][j mod d+1] := true ; j := j/(d) ; k := k + 1 ) ; execute calc((n)->char2byte() - i, i) ; j := i ; k := 0 ; while (j > 0) do ( z[k+1][j mod d+1] := false ; j := j/(d) ; k := k + 1 ) ; ) else skip ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int factorial(int n){ if(n==0)return 1 ; return n*factorial(n-1); } static int LCMOfNeighbourFact(int n){ return factorial(n+1); } public static void main(String args[]){ int N=5 ; System.out.println(LCMOfNeighbourFact(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation factorial( n : int) : int pre: true post: true activity: ( if (n = 0) then return 1 else skip ; return n * factorial(n - 1) ); static operation LCMOfNeighbourFact( n : int) : int pre: true post: true activity: ( return factorial(n + 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 5 ; OclFile["System.out"].println(LCMOfNeighbourFact(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isSubsetSum(int set[],int n,int sum){ if(sum==0)return true ; if(n==0 && sum!=0)return false ; if(set[n-1]>sum)return isSubsetSum(set,n-1,sum); return isSubsetSum(set,n-1,sum)|| isSubsetSum(set,n-1,sum-set[n-1]); } public static void main(String args[]){ int set[]={ 3,34,4,12,5,2 }; int sum=9 ; int n=set.length ; if(isSubsetSum(set,n,sum)==true)System.out.println("Found a subset"+" with given sum"); else System.out.println("No subset with"+" given sum"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isSubsetSum( set : Sequence(int), n : int, sum : int) : boolean 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[n - 1+1] > sum) then return isSubsetSum(set, n - 1, sum) else skip ; return isSubsetSum(set, n - 1, sum) or isSubsetSum(set, n - 1, sum - set[n - 1+1]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var set : Sequence(int) ; set := Sequence{3,34,4,12,5,2} ; var sum : int ; sum := 9 ; var n : int ; n := set->size() ; if (isSubsetSum(set, n, sum) = true) then OclFile["System.out"].println("Found a subset" + " with given sum") ; else OclFile["System.out"].println("No subset with" + " given sum") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { void run(){ int LA=readInt(); int LB=readInt(); int[] A=new int[LA]; int[] B=new int[LB]; for(int i=0 ; icollect(0) ; var B : Sequence(int) ; B := Integer.subrange(1,LB)->collect(0) ; var i : int ; i := 0 ; while i < LA do ( ( A[i+1] := readInt() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < LB do ( ( B[i+1] := readInt() ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < LB do ( ( var p : int ; p := 0 ; var k : int ; k := i ; while (p < LA & k < LB) do ( if (A[p+1] = B[k+1]) then ( k := k + 1 ) else skip ; p := p + 1 ) ; ans := Set{ans, k - i}->max() ) ; i := i + 1 ) ; sysout.println(ans) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute sysout : OclFile := OclFile.newOclFile_Write(OclFile["System.out"], true); attribute in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute buffer : OclIterator := null; operation read() : String pre: true post: true activity: ( if (buffer = null or not(buffer.hasNext())) then ( try ( buffer := OclIterator.newOclIterator_String(in.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return buffer.next() ); operation readInt() : int pre: true post: true activity: ( return (read())->toInteger() ); operation readLong() : long pre: true post: true activity: ( return (read())->toLong() ); operation readDouble() : double pre: true post: true activity: ( return (read())->toReal() ); operation readLine() : String pre: true post: true activity: ( buffer := null ; try ( return in.readLine() ) catch (e : IOException) do ( error ProgramException(e) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.LinkedList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); final int A=sc.nextInt(); final int B=sc.nextInt(); short[] a_array=new short[A]; short[] b_array=new short[B]; for(int i=0 ; itoInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var a_array : Sequence(int) ; a_array := Integer.subrange(1,A)->collect(0) ; var b_array : Sequence(int) ; b_array := Integer.subrange(1,B)->collect(0) ; var i : int ; i := 0 ; while i < A do ( ( a_array[i+1] := sc.nextShort() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < B do ( ( b_array[i+1] := sc.nextShort() ) ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,A + 1)->collect(Integer.subrange(1,B + 1)->collect(0)) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < A do ( ( var j : int ; j := 0 ; while j < B do ( ( if (a_array[i+1] = b_array[j+1]) then ( dp[i + 1+1][j + 1+1] := ((dp[i+1][j+1] + 1) mod 32768) ) else ( dp[i + 1+1][j + 1+1] := dp[i+1][j + 1+1] ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= B do ( ( max := Set{max, dp[A+1][i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; line=br.readLine(); int A,B ; if(line.indexOf(' ')>=0){ A=parseInt(line.substring(0,line.indexOf(' '))); B=parseInt(line.substring(line.indexOf(' ')+1)); } else { A=parseInt(line); B=parseInt(br.readLine()); } int[] CA=new int[A+1]; int[] CB=new int[B+1]; StringTokenizer st ; st=new StringTokenizer(br.readLine()); for(int i=1 ; i<=A ; i++){ CA[i]=parseInt(st.nextToken()); } st=new StringTokenizer(br.readLine()); for(int i=1 ; i<=B ; i++){ CB[i]=parseInt(st.nextToken()); } int[][] dp=new int[A+1][B+1]; int ans=0 ; for(int i=1 ; i<=A ; i++){ for(int j=1 ; j<=B ; j++){ if(CA[i]==CB[j]){ dp[i][j]=dp[i-1][j-1]+1 ; } else { dp[i][j]=dp[i-1][j]; } ans=Math.max(ans,dp[i][j]); } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; line := br.readLine() ; var A : int ; var B : int ; if (line->indexOf(' ')-1 >= 0) then ( A := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; B := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ) else ( A := (line + "")->toInteger() ; B := (br.readLine() + "")->toInteger() ) ; var CA : Sequence(int) ; CA := Integer.subrange(1,A + 1)->collect(0) ; var CB : Sequence(int) ; CB := Integer.subrange(1,B + 1)->collect(0) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 1 ; while i <= A do ( ( CA[i+1] := (st.next() + "")->toInteger() ) ; i := i + 1 ) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 1 ; while i <= B do ( ( CB[i+1] := (st.next() + "")->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,A + 1)->collect(Integer.subrange(1,B + 1)->collect(0)) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= A do ( ( var j : int ; j := 1 ; while j <= B do ( ( if (CA[i+1] = CB[j+1]) then ( dp[i+1][j+1] := dp[i - 1+1][j - 1+1] + 1 ) else ( dp[i+1][j+1] := dp[i - 1+1][j+1] ) ; ans := Set{ans, dp[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { void solve(){ Scanner sc=new Scanner(System.in); int A=sc.nextInt(),B=sc.nextInt(); int[] a=new int[A]; int[] b=new int[B]; for(int i=0 ; ipos){ cnt++; pos=aa[b[i] ][j]; break ; } } if(before==cnt)break ; } max=Math.max(max,cnt); } System.out.println(max); } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,A)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,B)->collect(0) ; var i : int ; i := 0 ; while i < A do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < B do ( b[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var aa : Sequence(Sequence(int)) ; aa := Integer.subrange(1,1001)->collect(Sequence{}) ; var i : int ; i := 1 ; while i <= 1000 do ( ( var cnt : int ; cnt := 0 ; var j : int ; j := 0 ; while j < A do ( if (a[j+1] = i) then cnt := cnt + 1 ; else skip ; ; j := j + 1 ) ; aa[i+1] := Integer.subrange(1,cnt)->collect(0) ; var idx : int ; idx := 0 ; var j : int ; j := 0 ; while j < A do ( if (a[j+1] = i) then aa[i+1][idx+1] := j ; idx := idx + 1 ; else skip ; ; j := j + 1 ) ; ) ; i := i + 1 ) ; var max : int ; max := 0 ; var start : int ; start := 0 ; while start < B do ( ( var cnt : int ; cnt := 0 ; var pos : int ; pos := -1 ; var i : int ; i := start ; while i < B do ( ( var before : int ; before := cnt ; var j : int ; j := 0 ; while j < aa[b[i+1]+1]->size() do ( ( if (aa[b[i+1]+1][j+1] > pos) then ( cnt := cnt + 1 ; pos := aa[b[i+1]+1][j+1] ; break ) else skip ) ; j := j + 1 ) ; if (before = cnt) then break else skip ) ; i := i + 1 ) ; max := Set{max, cnt}->max() ) ; start := start + 1 ) ; OclFile["System.out"].println(max) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int M=sc.nextInt(); int[] A=new int[N]; int[] B=new int[M]; for(int i=0 ; i=0 ; --j){ if(A[i]==B[j]){ dp[j+1]=Math.max(dp[j+1],dp[j]+1); } } } int ans=0 ; for(int i=1 ; i<=M ; ++i){ ans=Math.max(ans,dp[i]); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var B : Sequence(int) ; B := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( B[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,M + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := M - 1 ; while j >= 0 do ( ( if (A[i+1] = B[j+1]) then ( dp[j + 1+1] := Set{dp[j + 1+1], dp[j+1] + 1}->max() ) else skip ) ; j := j - 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= M do ( ( ans := Set{ans, dp[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { public static void main(String[] agrs){ Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=sc.nextInt(); int[] a=new int[n]; float[] b=new float[n]; float total=0 ; for(int i=0 ; i=0 ; k--){ for(int j=0 ; j<10001 ; j++){ if(dp[k][j]==-1)continue ; dp[k+1][j+a[i] ]=(float)Math.max(dp[k+1][j+a[i] ],dp[k][j]+b[i]/2.0); } } } float max=0 ; for(int k=1 ; k<=n ; k++){ max=0 ; for(int j=0 ; j<10001 ; j++){ max=(float)Math.max(max,Math.min(dp[k][j],j)); } out.print(max+" "); } out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( agrs : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(double) ; b := Integer.subrange(1,n)->collect(0.0) ; var total : double ; total := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.nextFloat() ; total := total+(b[i+1] / 2.0) ) ; i := i + 1 ) ; var dp : Sequence(Sequence(double)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,10001)->collect(0.0)) ; var i : int ; i := 0 ; while i <= n do ( dp[i+1] := dp[i+1]->collect(-1) ; ; i := i + 1 ) ; dp[0+1][0+1] := total ; var i : int ; i := 0 ; while i < n do ( ( var k : int ; k := n - 1 ; while k >= 0 do ( ( var j : int ; j := 0 ; while j < 10001 do ( ( if (dp[k+1][j+1] = -1) then continue else skip ; dp[k + 1+1][j + a[i+1]+1] := Set{dp[k + 1+1][j + a[i+1]+1], dp[k+1][j+1] + b[i+1] / 2.0}->max()->oclAsType(double) ) ; j := j + 1 ) ) ; k := k - 1 ) ) ; i := i + 1 ) ; var max : double ; max := 0 ; var k : int ; k := 1 ; while k <= n do ( ( max := 0 ; var j : int ; j := 0 ; while j < 10001 do ( ( max := Set{max, Set{dp[k+1][j+1], j}->min()}->max()->oclAsType(double) ) ; j := j + 1 ) ; skip ) ; k := k + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class dummy { public static void main(String args[])throws IOException { BufferedReader x=new BufferedReader(new InputStreamReader(System.in)); String input[]=(x.readLine()).split(" "); int arr[]=new int[4]; arr[0]=Integer.parseInt(input[0]); arr[1]=Integer.parseInt(input[1]); arr[2]=Integer.parseInt(input[2]); arr[3]=Integer.parseInt(input[3]); int largest=arr[0],middle=arr[1],smallest=arr[2],marsha=arr[3]; if(smallest>marsha*2)System.out.println(-1); else if(marsha>smallest*2)System.out.println(-1); else if(marsha>=middle)System.out.println(-1); else { System.out.println((largest*2)+"\n"+(middle*2)+"\n"+Math.max(smallest,marsha)); } } } ------------------------------------------------------------ OCL File: --------- class dummy { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : OclFile ; x := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var input : Sequence(String) ; input := (x.readLine())->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,4)->collect(0) ; arr[0+1] := (input[0+1])->toInteger() ; arr[1+1] := (input[1+1])->toInteger() ; arr[2+1] := (input[2+1])->toInteger() ; arr[3+1] := (input[3+1])->toInteger() ; var largest : int ; largest := arr[0+1] ; var middle : int ; middle := arr[1+1] ; var smallest : int ; smallest := arr[2+1] ; var marsha : int ; marsha := arr[3+1] ; if (smallest > marsha * 2) then OclFile["System.out"].println(-1) else if (marsha > smallest * 2) then OclFile["System.out"].println(-1) else if (marsha >= middle) then OclFile["System.out"].println(-1) else ( OclFile["System.out"].println((largest * 2) + "\n" + (middle * 2) + "\n" + Set{smallest, marsha}->max()) ) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class mAndBears { public static void main(String[] args){ Scanner in=new Scanner(System.in); int sizeB=in.nextInt(); int sizeMo=in.nextInt(); int sizeS=in.nextInt(); int sizeMa=in.nextInt(); in.close(); int carB=0,carMo=0,carS=0 ; boolean possible=false ; for(int i=sizeS ; i<=sizeS*2 ; i++){ if(sizeMa<=i &&(2*sizeMa)>=i){ carS=i ; possible=true ; break ; } } if(possible){ for(int i=sizeMo ; i<=sizeMo*2 ; i++){ if(i>(carS*2)){ carMo=i ; possible=true ; break ; } else { possible=false ; } } } if(possible){ for(int i=sizeB ; i<=sizeB*2 ; i++){ if(i>carMo){ carB=i ; possible=true ; break ; } else { possible=false ; } } } if(possible){ System.out.println(carB+"\n"+carMo+"\n"+carS); } else { System.out.println("-1"); } } } ------------------------------------------------------------ OCL File: --------- class mAndBears { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sizeB : int ; sizeB := in.getCurrent()->toInteger() ; var sizeMo : int ; sizeMo := in.getCurrent()->toInteger() ; var sizeS : int ; sizeS := in.getCurrent()->toInteger() ; var sizeMa : int ; sizeMa := in.getCurrent()->toInteger() ; skip ; var carB : int ; carB := 0 ; var carMo : int ; carMo := 0 ; var carS : int ; carS := 0 ; var possible : boolean ; possible := false ; var i : int ; i := sizeS ; while i <= sizeS * 2 do ( ( if (sizeMa <= i & (2 * sizeMa) >= i) then ( carS := i ; possible := true ; break ) else skip ) ; i := i + 1 ) ; if (possible) then ( var i : int ; i := sizeMo ; while i <= sizeMo * 2 do ( ( if (i > (carS * 2)) then ( carMo := i ; possible := true ; break ) else ( possible := false ) ) ; i := i + 1 ) ) else skip ; if (possible) then ( var i : int ; i := sizeB ; while i <= sizeB * 2 do ( ( if (i > carMo) then ( carB := i ; possible := true ; break ) else ( possible := false ) ) ; i := i + 1 ) ) else skip ; if (possible) then ( OclFile["System.out"].println(carB + "\n" + carMo + "\n" + carS) ) else ( OclFile["System.out"].println("-1") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(f.readLine()); int big=Integer.parseInt(st.nextToken()); int med=Integer.parseInt(st.nextToken()); int sma=Integer.parseInt(st.nextToken()); int masha=Integer.parseInt(st.nextToken()); if(masha>sma*2 || masha*2=med){ System.out.println(-1); } else { System.out.println(big*2); System.out.println(med*2); if(mashatoInteger() ; var med : int ; med := (st.next())->toInteger() ; var sma : int ; sma := (st.next())->toInteger() ; var masha : int ; masha := (st.next())->toInteger() ; if (masha > sma * 2 or masha * 2 < sma or masha >= med) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(big * 2) ; OclFile["System.out"].println(med * 2) ; if (masha < sma) then ( OclFile["System.out"].println(sma) ) else ( OclFile["System.out"].println(sma * 2) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static StringBuilder sb=new StringBuilder(); public static void main(String args[]){ int n,m ; Scanner s=new Scanner(System.in); n=s.nextInt(); m=s.nextInt(); int ci[]=new int[n+1]; int ti[]=new int[n+1]; int songDuration[]=new int[n+1]; for(int i=1 ; i<=n ; i++){ ci[i]=s.nextInt(); ti[i]=s.nextInt(); songDuration[i]=ci[i]*ti[i]; } for(int i=1 ; i<=n ; i++){ songDuration[i]=songDuration[i]+songDuration[i-1]; } for(int i=1 ; i<=m ; i++){ int target=s.nextInt(); int si=1 ; int ei=n ; int ans=-1 ; while(si<=ei){ int mid=si+(ei-si)/2 ; if(songDuration[mid]>=target){ ei=mid-1 ; ans=mid ; } else { si=mid+1 ; } } sb.append(ans).append("\n"); } System.out.print(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sb : String := StringLib.newString(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; var m : int ; var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := s.getCurrent()->toInteger() ; m := s.getCurrent()->toInteger() ; var ci : Sequence(int) ; ci := Integer.subrange(1,n + 1)->collect(0) ; var ti : Sequence(int) ; ti := Integer.subrange(1,n + 1)->collect(0) ; var songDuration : Sequence(int) ; songDuration := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( ci[i+1] := s.getCurrent()->toInteger() ; ti[i+1] := s.getCurrent()->toInteger() ; songDuration[i+1] := ci[i+1] * ti[i+1] ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( songDuration[i+1] := songDuration[i+1] + songDuration[i - 1+1] ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= m do ( ( var target : int ; target := s.getCurrent()->toInteger() ; var si : int ; si := 1 ; var ei : int ; ei := n ; var ans : int ; ans := -1 ; while (si <= ei) do ( var mid : int ; mid := si + (ei - si) / 2 ; if (songDuration[mid+1] >= target) then ( ei := mid - 1 ; ans := mid ) else ( si := mid + 1 ) ) ; sb := sb + StringLib.newString(ans) + StringLib.newString("\n") ; ) ; i := i + 1 ) ; OclFile["System.out"].print(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); System.out.println(Math.min(n*a,b)); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(Set{n * a, b}->min()) ; ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static StringBuilder sb=new StringBuilder(); public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); long song_for_how_many_minutes[]=new long[n+1]; long t[]=new long[n+1]; long c[]=new long[n+1]; long time_stamp[]=new long[m]; for(int i=1 ; i<=n ; i++){ c[i]=sc.nextLong(); t[i]=sc.nextLong(); } for(int i=1 ; i<=n ; i++){ song_for_how_many_minutes[i]=song_for_how_many_minutes[i-1]+c[i]*t[i]; } for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var song_for_how_many_minutes : Sequence(long) ; song_for_how_many_minutes := Integer.subrange(1,n + 1)->collect(0) ; var t : Sequence(long) ; t := Integer.subrange(1,n + 1)->collect(0) ; var c : Sequence(long) ; c := Integer.subrange(1,n + 1)->collect(0) ; var time_stamp : Sequence(long) ; time_stamp := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( c[i+1] := sc.getCurrent()->toLong() ; t[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( song_for_how_many_minutes[i+1] := song_for_how_many_minutes[i - 1+1] + c[i+1] * t[i+1] ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( time_stamp[i+1] := sc.getCurrent()->toLong() ; var target : long ; target := time_stamp[i+1] ; var s : int ; s := 1 ; var e : int ; e := song_for_how_many_minutes->size() ; var ans : int ; ans := -1 ; while (s <= e) do ( var mid : int ; mid := (s + e) / 2 ; if (song_for_how_many_minutes[mid+1] < target) then ( s := mid + 1 ) else ( ans := mid ; e := mid - 1 ) ) ; sb := sb + StringLib.newString(ans) + StringLib.newString("\n") ; ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); int[] time=new int[n]; int[] times=new int[n]; for(int i=0 ; itoInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var time : Sequence(int) ; time := Integer.subrange(1,n)->collect(0) ; var times : Sequence(int) ; times := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( time[i+1] := in.getCurrent()->toInteger() ; times[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ftime : Sequence(int) ; ftime := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( ftime[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var index : int ; index := 1 ; var stime : int ; stime := time[0+1] * times[0+1] ; var i : int ; i := 0 ; while i < m do ( ( if (ftime[i+1] <= stime) then ( OclFile["System.out"].println(index) ) else ( stime := stime+(time[index+1] * times[index+1]) ; index := index + 1 ; i := i - 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class fibonacci { static int fib(int n){ int f[]=new int[n+2]; int i ; f[0]=0 ; f[1]=1 ; for(i=2 ; i<=n ; i++){ f[i]=f[i-1]+f[i-2]; } return f[n]; } public static void main(String args[]){ int n=9 ; System.out.println(fib(n)); } } ------------------------------------------------------------ OCL File: --------- class fibonacci { static operation fib( n : int) : int pre: true post: true activity: ( var f : Sequence(int) ; f := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; f[0+1] := 0 ; f[1+1] := 1 ; i := 2 ; while i <= n do ( ( f[i+1] := f[i - 1+1] + f[i - 2+1] ) ; i := i + 1 ) ; return f[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].println(fib(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=1000 ; static int f[]; public static int fib(int n){ if(n==0)return 0 ; if(n==1 || n==2)return(f[n]=1); if(f[n]!=0)return f[n]; int k=(n & 1)==1 ?(n+1)/2 : n/2 ; f[n]=(n & 1)==1 ?(fib(k)*fib(k)+fib(k-1)*fib(k-1)):(2*fib(k-1)+fib(k))*fib(k); return f[n]; } public static void main(String[] args){ int n=9 ; f=new int[MAX]; System.out.println(fib(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 1000; static attribute f : Sequence(int); static operation fib( n : int) : int pre: true post: true activity: ( if (n = 0) then return 0 else skip ; if (n = 1 or n = 2) then return (f[n+1]) else skip ; if (f[n+1] /= 0) then return f[n+1] else skip ; var k : int ; k := if (MathLib.bitwiseAnd(n,1)) = 1 then (n + 1) / 2 else n / 2 endif ; f[n+1] := if (n & 1) = 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] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; f := Integer.subrange(1,MAX)->collect(0) ; OclFile["System.out"].println(fib(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.*; import java.awt.geom.*; import java.io.*; import java.util.*; class Main { static int[][] map ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int minN=n ; int maxN=n ; while(true){ boolean mnN=check(minN); boolean mxN=check(maxN); if(mnN){ System.out.println(minN); break ; } if(mxN){ System.out.println(maxN); break ; } minN--; maxN++; } } static boolean check(int a){ char[] A=String.valueOf(a).toCharArray(); char[] B=new char[A.length]; for(int i=0 ; itoInteger() ; var minN : int ; minN := n ; var maxN : int ; maxN := n ; while (true) do ( var mnN : boolean ; mnN := check(minN) ; var mxN : boolean ; mxN := check(maxN) ; if (mnN) then ( OclFile["System.out"].println(minN) ; break ) else skip ; if (mxN) then ( OclFile["System.out"].println(maxN) ; break ) else skip ; minN := minN - 1 ; maxN := maxN + 1 ; ) ; ); static operation check( a : int) : boolean pre: true post: true activity: ( var A : Sequence(String) ; A := ((a) + "")->characters() ; var B : Sequence(String) ; B := Integer.subrange(1,A->size())->collect(0) ; var i : int ; i := 0 ; while i < A->size() do ( ( B[i+1] := A[A->size() - i - 1+1] ) ; i := i + 1 ) ; var b : int ; b := ((B)->sum() )->toInteger() ; return a = b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner rand=new Scanner(System.in); long n=rand.nextLong(); System.out.println(solve(n)); } static int solve(long n){ int[] sum=String.valueOf(n).chars().map(ch->ch-'0').toArray(); for(int i=0 ; i=1 ; i--){ if(sum[i]==19){ sum[i]-=10 ; sum[i-1]++; } } return Arrays.stream(sum).sum(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var rand : OclFile ; rand := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := rand.getCurrent()->toLong() ; OclFile["System.out"].println(solve(n)) ); static operation solve( n : long) : int pre: true post: true activity: ( var sum : Sequence(int) ; sum := ((n) + "").chars()->collect( _x1 | (lambda ch : OclAny in ch - ('0')->char2byte())->apply(_x1) )->asSequence() ; var i : int ; i := 0 ; while i < sum->size() - 1 do ( ( sum[i+1] := sum[i+1] - 1 ; sum[i + 1+1] := sum[i + 1+1]+(10) ) ; i := i + 1 ) ; var i : int ; i := sum->size() - 1 ; while i >= 1 do ( ( if (sum[i+1] = 19) then ( sum[i+1] := sum[i+1]-(10) ; sum[i - 1+1] := sum[i - 1+1] + 1 ) else skip ) ; i := i - 1 ) ; return stream(sum)->sum() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { static boolean[] palindrom=new boolean[10002]; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; for(int i=0 ; i<=9 ; i++){ palindrom[i]=true ; palindrom[i*10+i]=true ; } for(int i=1 ; i<=9 ; i++){ int p=i*101 ; palindrom[p]=true ; for(int j=0 ; j<=9 ; j++){ int q=p+j*10 ; palindrom[q]=true ; } } for(int i=1 ; i<=9 ; i++){ int p=i*1001 ; palindrom[p]=true ; for(int j=0 ; j<=9 ; j++){ int q=p+j*100+j*10 ; palindrom[q]=true ; } } palindrom[10001]=true ; int n=parseInt(br.readLine()); int ans=0 ; for(int i=0 ; ; i++){ if(palindrom[n-i]){ ans=n-i ; break ; } if(palindrom[n+i]){ ans=n+i ; break ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute palindrom : Sequence(boolean) := Integer.subrange(1,10002)->collect(false); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var i : int ; i := 0 ; while i <= 9 do ( ( palindrom[i+1] := true ; palindrom[i * 10 + i+1] := true ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= 9 do ( ( var p : int ; p := i * 101 ; palindrom[p+1] := true ; var j : int ; j := 0 ; while j <= 9 do ( ( var q : int ; q := p + j * 10 ; palindrom[q+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= 9 do ( ( var p : int ; p := i * 1001 ; palindrom[p+1] := true ; var j : int ; j := 0 ; while j <= 9 do ( ( var q : int ; q := p + j * 100 + j * 10 ; palindrom[q+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; palindrom[10001+1] := true ; var n : int ; n := parseInt(br.readLine()) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while true do ( ( if (palindrom[n - i+1]) then ( ans := n - i ; break ) else skip ; if (palindrom[n + i+1]) then ( ans := n + i ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; int n ; void run(){ n=sc.nextInt(); solve(); } void solve(){ for(int i=0 ; ; i++){ String s=(n-i)+"" ; if(n-i>=0 && new StringBuilder(s).reverse().toString().equals(s)){ println(s); return ; } s=(n+i)+"" ; if(new StringBuilder(s).reverse().toString().equals(s)){ println(s); return ; } } } void println(String s){ System.out.println(s); } void debug(Object...os){ System.err.println(deepToString(os)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute n : int; operation run() : void pre: true post: true activity: ( n := sc.getCurrent()->toInteger() ; execute solve() ); operation solve() : void pre: true post: true activity: ( var i : int ; i := 0 ; while true do ( ( var s : String ; s := (n - i) + "" ; if (n - i >= 0 & StringLib.newString(s)->reverse()+"" = s) then ( execute println(s) ; return ) else skip ; s := (n + i) + "" ; if (StringLib.newString(s)->reverse()+"" = s) then ( execute println(s) ; return ) else skip ) ; i := i + 1 ) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashSet ; import java.util.LinkedList ; import java.util.Scanner ; import java.util.TreeSet ; import javax.print.attribute.standard.MediaSize.Other ; import javax.xml.bind.ParseConversionEvent ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); ArrayListpalind=new ArrayList(); for(int i=0 ; i<=9 ; i++){ palind.add(i); } for(int i=0 ; i<=10 ; i++){ for(int pre=1 ; pre<=100 ; pre++){ String p_=pre+"" ; StringBuilder sb=new StringBuilder(); sb.append(p_); sb.reverse(); palind.add(Integer.parseInt(pre+(i==10 ? "" : i+"")+sb.toString())); } } Collections.sort(palind); final int n=sc.nextInt(); int b_search=Collections.binarySearch(palind,n); if(b_search>=0){ System.out.println(n); return ; } int first=-(b_search+1); int second=-(b_search+2); if(second<0){ System.out.println(palind.get(first)); } else { if(Math.abs(n-palind.get(first))including(i) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= 10 do ( ( var pre : int ; pre := 1 ; while pre <= 100 do ( ( var p_ : String ; p_ := pre + "" ; var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString(p_) ; sb := sb->reverse() ; palind := palind->including((pre + (if i = 10 then "" else i + "" endif) + sb+"")->toInteger()) ; ) ; pre := pre + 1 ) ) ; i := i + 1 ) ; palind := palind->sort() ; var n : int ; n := sc.getCurrent()->toInteger() ; var b_search : int ; b_search := .binarySearch(palind, n) ; if (b_search >= 0) then ( OclFile["System.out"].println(n) ; return ) else skip ; var first : int ; first := -(b_search + 1) ; var second : int ; second := -(b_search + 2) ; if (second < 0) then ( OclFile["System.out"].println(palind->at(first+1)) ) else ( if (if (n)->char2byte() - palind->at(first+1) < 0 then -((n)->char2byte() - palind->at(first+1)) else (n)->char2byte() - palind->at(first+1) endif < if (n)->char2byte() - palind->at(second+1) < 0 then -((n)->char2byte() - palind->at(second+1)) else (n)->char2byte() - palind->at(second+1) endif) then ( OclFile["System.out"].println(palind->at(first+1)) ) else ( OclFile["System.out"].println(palind->at(second+1)) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] a=new int[2]; int x=sc.nextInt(); sc.close(); if(isH(x)){ System.out.println(x); System.exit(0); } else { for(int i=x-1 ; i>=0 ; i--){ if(isH(i)){ a[0]=i ; break ; } } for(int i=x+1 ; i<15000 ; i++){ if(isH(i)){ a[1]=i ; break ; } } } if((Math.abs(a[0]-x))>(Math.abs(a[1]-x))){ System.out.println(a[1]); } else if((Math.abs(a[0])-x)==(Math.abs(a[1])-x)){ System.out.println(min(a[0],a[1])); } else { System.out.println(a[0]); } } static boolean isH(int x){ int sum=0 ; int a=0 ; int x1=x ; while(x!=0){ a=x % 10 ; sum=sum*10+a ; x/=10 ; } if(x1==sum)return true ; return false ; } static int min(int x,int y){ if(x>y)return y ; return x ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : Sequence(int) ; a := Integer.subrange(1,2)->collect(0) ; var x : int ; x := sc.getCurrent()->toInteger() ; skip ; if (isH(x)) then ( OclFile["System.out"].println(x) ; OclProcess.exit(0) ) else ( var i : int ; i := x - 1 ; while i >= 0 do ( ( if (isH(i)) then ( a[0+1] := i ; break ) else skip ) ; i := i - 1 ) ; var i : int ; i := x + 1 ; while i < 15000 do ( ( if (isH(i)) then ( a[1+1] := i ; break ) else skip ) ; i := i + 1 ) ) ; if ((if a[0+1] - x < 0 then -(a[0+1] - x) else a[0+1] - x endif) > (if a[1+1] - x < 0 then -(a[1+1] - x) else a[1+1] - x endif)) then ( OclFile["System.out"].println(a[1+1]) ) else if ((if a[0+1] < 0 then -(a[0+1]) else a[0+1] endif - x) = (if a[1+1] < 0 then -(a[1+1]) else a[1+1] endif - x)) then ( OclFile["System.out"].println(Set{a[0+1], a[1+1]}->min()) ) else ( OclFile["System.out"].println(a[0+1]) ) ; ; ); static operation isH( x : int) : boolean pre: true post: true activity: ( var sum : int ; sum := 0 ; var a : int ; a := 0 ; var x1 : int ; x1 := x ; while (x /= 0) do ( a := x mod 10 ; sum := sum * 10 + a ; x := x/(10) ) ; if (x1 = sum) then return true else skip ; return false ); static operation min( x : int, y : int) : int pre: true post: true activity: ( if (x > y) then return y else skip ; return x ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static void removeDuplicates(int[] arr){ LinkedHashSetset=new LinkedHashSet(); for(int i=0 ; isize() do ( set := set->including(arr[i+1]) ; ; i := i + 1 ) ; OclFile["System.out"].print(set) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,5,1,7,2,4,2} ; execute removeDuplicates(arr) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.Scanner ; public class Main { public static void main(String[] args){ resolve(System.in,System.out); } static void resolve(InputStream is,PrintStream pw){ Scanner sc=new Scanner(is); int n=Integer.parseInt(sc.next()); int a=Integer.parseInt(sc.next()); int b=Integer.parseInt(sc.next()); int train=a*n ; int taxi=b ; pw.println(Math.min(train,taxi)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute resolve(OclFile["System.in"], OclFile["System.out"]) ); static operation resolve( is : OclFile, pw : OclFile) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(is) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var a : int ; a := (sc.getCurrent())->toInteger() ; var b : int ; b := (sc.getCurrent())->toInteger() ; var train : int ; train := a * n ; var taxi : int ; taxi := b ; pw.println(Set{train, taxi}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int minOperations(int n,int m){ int a=0,k=1 ; int p=Math.max(n,m); while(n!=m){ float s=(float)(p-n+p-m); float q=(float)((-1+Math.sqrt(8*s+1))/2); if(q-Math.floor(q)==0){ a=(int)q ; n=m ; } p=p+1 ; } return a ; } public static void main(String[] args){ int n=1,m=3 ; System.out.print(minOperations(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minOperations( n : int, m : int) : int pre: true post: true activity: ( var a : int ; a := 0 ; var k : int ; k := 1 ; var p : int ; p := Set{n, m}->max() ; while (n /= m) do ( var s : double ; s := (p - n + p - m)->oclAsType(double) ; var q : double ; q := ((-1 + (8 * s + 1)->sqrt()) / 2)->oclAsType(double) ; if (q - (q)->floor() = 0) then ( a := q->oclAsType(int) ; n := m ) else skip ; p := p + 1 ) ; return a ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 1 ; var m : int ; m := 3 ; OclFile["System.out"].print(minOperations(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isVowel(char x){ x=Character.toLowerCase(x); return(x=='a' || x=='e' || x=='i' || x=='o' || x=='u'); } static String longestVowelSubsequence(String str){ String answer="" ; int n=str.length(); for(int i=0 ; itoLowerCase() ; return (x = 'a' or x = 'e' or x = 'i' or x = 'o' or x = 'u') ); static operation longestVowelSubsequence( str : String) : String pre: true post: true activity: ( var answer : String ; answer := "" ; var n : int ; n := str->size() ; var i : int ; i := 0 ; while i < n do ( ( if (isVowel(str->at(i+1))) then ( answer := answer+(str->at(i+1)) ) else skip ) ; i := i + 1 ) ; return answer ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; OclFile["System.out"].print(longestVowelSubsequence(str) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s="" ; int n=0 ; int t=0 ; while(sc.hasNext()){ s=sc.nextLine(); if(s.startsWith("+")){ n++; } else if(s.startsWith("-")){ n--; } else { String document=s.substring(s.lastIndexOf(":")+1); t+=(n*document.length()); } } System.out.println(t); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := "" ; var n : int ; n := 0 ; var t : int ; t := 0 ; while (sc.hasNext()) do ( s := sc.nextLine() ; if (s->hasPrefix("+")) then ( n := n + 1 ) else if (s->hasPrefix("-")) then ( n := n - 1 ) else ( var document : String ; document := s.subrange(s->lastIndexOf(":")-1 + 1+1,s->lastIndexOf(":")-1 + 1) ; t := t+((n * document->size())) ) ; ) ; OclFile["System.out"].println(t) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class max_sum { public static void main(String args[]){ long s1,s2=0 ; long k=0 ; long n=0 ; int c=0 ; long sum=0 ; Scanner in=new Scanner(System.in); n=in.nextLong(); k=n ; while(k>=1){ c++; k=k/10 ; } for(int i=0 ; i=1){ sum=sum+(s1 % 10); s1=s1/10 ; } while(s2>=1){ sum=sum+(s2 % 10); s2=s2/10 ; } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class max_sum { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s1 : long ; var s2 : long ; s2 := 0 ; var k : long ; k := 0 ; var n : long ; n := 0 ; var c : int ; c := 0 ; var sum : long ; sum := 0 ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := in.getCurrent()->toLong() ; k := n ; while (k >= 1) do ( c := c + 1 ; k := k / 10 ) ; var i : int ; i := 0 ; while i < c - 1 do ( ( s2 := s2 * 10 + 9 ) ; i := i + 1 ) ; s1 := n - s2 ; while (s1 >= 1) do ( sum := sum + (s1 mod 10) ; s1 := s1 / 10 ) ; while (s2 >= 1) do ( sum := sum + (s2 mod 10) ; s2 := s2 / 10 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedWriter ; import java.io.File ; import java.io.FileNotFoundException ; import java.io.FileWriter ; import java.io.IOException ; import java.util.Scanner ; public class Chat_Server_Outgoing_Traffic { public static void main(String[] args)throws IOException { Scanner scan=new Scanner(System.in); int users=0 ; int totalLength=0 ; while(scan.hasNextLine()){ String line=scan.nextLine(); if(line.charAt(0)=='+'){ users++; } else if(line.charAt(0)=='-'){ users--; } else { int temp=line.length()-(line.indexOf(':')+1); totalLength+=temp*users ; } } System.out.println(totalLength); } } ------------------------------------------------------------ OCL File: --------- class Chat_Server_Outgoing_Traffic { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var users : int ; users := 0 ; var totalLength : int ; totalLength := 0 ; while (scan.hasNextLine()) do ( var line : String ; line := scan.nextLine() ; if (line->at(0+1) = '+') then ( users := users + 1 ) else if (line->at(0+1) = '-') then ( users := users - 1 ) else ( var temp : int ; temp := line->size() - (line->indexOf(':')-1 + 1) ; totalLength := totalLength+(temp * users) ) ; ) ; OclFile["System.out"].println(totalLength) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Problem5A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); final String END_INPUT="*" ; byte countCommands=0 ; byte countUsers=0 ; int totalBytes=0 ; while(scanner.hasNextLine()&& countCommands<=100){ String command=scanner.nextLine(); if(command.equals(END_INPUT))break ; countCommands++; if(command.startsWith("+"))countUsers++; else if(command.startsWith("-"))countUsers--; else { int colonIndex=command.indexOf(":"); totalBytes+=(command.length()-colonIndex-1)*countUsers ; } } System.out.print(totalBytes); } } ------------------------------------------------------------ OCL File: --------- class Problem5A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var END_INPUT : String ; END_INPUT := "*" ; var countCommands : int ; countCommands := 0 ; var countUsers : int ; countUsers := 0 ; var totalBytes : int ; totalBytes := 0 ; while (scanner.hasNextLine() & countCommands <= 100) do ( var command : String ; command := scanner.nextLine() ; if (command = END_INPUT) then break else skip ; countCommands := countCommands + 1 ; if (command->hasPrefix("+")) then countUsers := countUsers + 1 ; else if (command->hasPrefix("-")) then countUsers := countUsers - 1 else ( var colonIndex : int ; colonIndex := command->indexOf(":")-1 ; totalBytes := totalBytes+((command->size() - (colonIndex)->char2byte() - 1) * countUsers) ) ; ) ; OclFile["System.out"].print(totalBytes) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Problem5A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); byte countCommands=0 ; byte countUsers=0 ; int totalBytes=0 ; while(scanner.hasNextLine()&& countCommands<=100){ String command=scanner.nextLine(); countCommands++; if(command.startsWith("+"))countUsers++; else if(command.startsWith("-"))countUsers--; else { int colonIndex=command.indexOf(":"); totalBytes+=(command.length()-colonIndex-1)*countUsers ; } } System.out.print(totalBytes); } } ------------------------------------------------------------ OCL File: --------- class Problem5A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var countCommands : int ; countCommands := 0 ; var countUsers : int ; countUsers := 0 ; var totalBytes : int ; totalBytes := 0 ; while (scanner.hasNextLine() & countCommands <= 100) do ( var command : String ; command := scanner.nextLine() ; countCommands := countCommands + 1 ; if (command->hasPrefix("+")) then countUsers := countUsers + 1 ; else if (command->hasPrefix("-")) then countUsers := countUsers - 1 else ( var colonIndex : int ; colonIndex := command->indexOf(":")-1 ; totalBytes := totalBytes+((command->size() - (colonIndex)->char2byte() - 1) * countUsers) ) ; ) ; OclFile["System.out"].print(totalBytes) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.util.*; import java.io.*; public class CodeforcesB { public void solve()throws IOException { FastScanner fs=new FastScanner(); StringBuilder ans=new StringBuilder(""); long n=fs.nextLong(),d=fs.nextLong(),m=fs.nextLong(),l=fs.nextLong(); long x=0 ; while(x*d<=(n-1)*m+l){ long h=x*d % m ; if(h>l)break ; x+=(l-h)/d+1 ; } ans.append(x*d); System.out.println(ans); } public static void main(String[] args)throws IOException { try { new CodeforcesB().solve(); } catch(Exception e){ e.printStackTrace(); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; ichar2byte() - 1) * m + l) do ( var h : long ; h := x * d mod m ; if (h > l) then break else skip ; x := x+(((l)->char2byte() - h) / d + 1) ) ; ans := ans + StringLib.newString(x * d) ; OclFile["System.out"].println(ans) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( CodeforcesB.newCodeforcesB().solve() ) catch (e : ProgramException) do ( e.printStackTrace() ) ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForces18B { public static void main(String[] args){ Scanner input=new Scanner(System.in); long n=input.nextInt(); long d=input.nextInt(); long m=input.nextInt(); long l=input.nextInt(); for(int i=1 ; i<=n ; i++){ long s1=(i-1)*m+l ; long s2=i*m ; long s3=(s1/d)*d+d ; if(i==n || s3toInteger() ; var d : long ; d := input.getCurrent()->toInteger() ; var m : long ; m := input.getCurrent()->toInteger() ; var l : long ; l := input.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( var s1 : long ; s1 := (i - 1) * m + l ; var s2 : long ; s2 := i * m ; var s3 : long ; s3 := (s1 / d) * d + d ; if (i = n or s3 < s2) then ( OclFile["System.out"].println(s3) ; return ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class B18 { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); int d=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(st.nextToken()); int l=Integer.parseInt(st.nextToken()); long start=0 ; long end=l ; long pos=(end/d)*d ; for(int i=1 ; itoInteger() ; var d : int ; d := (st.next())->toInteger() ; var m : int ; m := (st.next())->toInteger() ; var l : int ; l := (st.next())->toInteger() ; var start : long ; start := 0 ; var end : long ; end := l ; var pos : long ; pos := (end / d) * d ; var i : int ; i := 1 ; while i < n do ( ( start := start+(m) ; end := end+(m) ; if (pos + d < start) then ( OclFile["System.out"].println(pos + d) ; return ) else skip ; pos := (end / d) * d ) ; i := i + 1 ) ; OclFile["System.out"].println(pos + d) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner scan=new Scanner(System.in); int num=scan.nextInt(); int train=scan.nextInt(); int taxi=scan.nextInt(); if(num*traintaxi){ System.out.println(taxi); } else { System.out.println(taxi); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : int ; num := scan.getCurrent()->toInteger() ; var train : int ; train := scan.getCurrent()->toInteger() ; var taxi : int ; taxi := scan.getCurrent()->toInteger() ; if (num * train < taxi) then ( OclFile["System.out"].println(num * train) ) else if (num * train > taxi) then ( OclFile["System.out"].println(taxi) ) else ( OclFile["System.out"].println(taxi) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); long n=in.nextLong(),m=in.nextLong(),ans=0 ; char[] a=new char[(int)(n+1)],b=new char[(int)(n+1)]; String s1=in.next(); String s2=in.next(); for(int i=1 ; i<=n ; i++){ a[i]=s1.charAt(i-1); b[i]=s2.charAt(i-1); } long sum=-1 ; int t=1 ; while(t<=n && a[t]==b[t]){ t++; ans++; } int f=1 ; for(int i=t ; i<=n && f==1 ; i++){ sum=sum*2+(int)('b'-a[i])+(int)(b[i]-'a'); if(sum+2>=m){ ans+=(n-i+1)*m ; f=0 ; } else ans+=sum+2 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := in.getCurrent()->toLong() ; var m : long ; m := in.getCurrent()->toLong() ; var ans : long ; ans := 0 ; var a : Sequence(String) ; a := Integer.subrange(1,(n + 1)->oclAsType(int))->collect(0) ; var b : Sequence(String) ; b := Integer.subrange(1,(n + 1)->oclAsType(int))->collect(0) ; var s1 : String ; s1 := in.getCurrent() ; var s2 : String ; s2 := in.getCurrent() ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := s1->at((i)->char2byte() - 1+1) ; b[i+1] := s2->at((i)->char2byte() - 1+1) ) ; i := i + 1 ) ; var sum : long ; sum := -1 ; var t : int ; t := 1 ; while (t <= n & a[t+1] = b[t+1]) do ( t := t + 1 ; ans := ans + 1 ) ; var f : int ; f := 1 ; var i : int ; i := t ; while i <= n & f = 1 do ( ( sum := sum * 2 + (('b')->char2byte() - a[i+1])->oclAsType(int) + (b[i+1] - ('a')->char2byte())->oclAsType(int) ; if (sum + 2 >= m) then ( ans := ans+((n - (i)->char2byte() + 1) * m) ; f := 0 ) else ans := ans+(sum + 2) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.OutputStreamWriter ; import java.io.PrintWriter ; import java.io.StreamTokenizer ; import java.util.Arrays ; import java.util.HashMap ; import java.util.HashSet ; import java.util.PriorityQueue ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeMap ; import java.util.TreeSet ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int n=ini(); int k=ini(); char a[]=ins().toCharArray(); char b[]=ins().toCharArray(); long ans=0 ; long w=1 ; for(int i=0 ; i1000000000)w=1000000000 ; ans+=Math.min(w,k); } out.print(ans); out.flush(); } static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static int ini()throws IOException { in.nextToken(); return(int)in.nval ; } static String ins()throws IOException { in.nextToken(); return in.sval ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := ini() ; var k : int ; k := ini() ; var a : Sequence(String) ; a := ins()->characters() ; var b : Sequence(String) ; b := ins()->characters() ; var ans : long ; ans := 0 ; var w : long ; w := 1 ; var i : int ; i := 0 ; while i < n do ( ( w := (w*(2->pow(1)))->oclAsType(long) ; if (a[i+1] = 'b') then w := w - 1 ; else skip ; if (b[i+1] = 'a') then w := w - 1 ; else skip ; if (w > 1000000000) then w := 1000000000 ; else skip ; ans := ans+(Set{w, k}->min()) ; ) ; i := i + 1 ) ; out.print(ans) ; out.flush() ; ); static attribute in : StreamTokenizer := StreamTokenizer.newStreamTokenizer(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))); static operation ini() : int pre: true post: true activity: ( in.next() ; return in.nval->oclAsType(int) ); static operation ins() : String pre: true post: true activity: ( in.next() ; return in.sval ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.OutputStreamWriter ; import java.io.PrintWriter ; import java.io.StreamTokenizer ; import java.util.Arrays ; import java.util.HashMap ; import java.util.HashSet ; import java.util.PriorityQueue ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeMap ; import java.util.TreeSet ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int n=ini(); int k=ini(); char a[]=ins().toCharArray(); char b[]=ins().toCharArray(); long ans=0 ; long w=1 ; for(int i=0 ; i1000000000)w=1000000000 ; ans+=Math.min(w,k); } out.print(ans); out.flush(); } static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static int ini()throws IOException { in.nextToken(); return(int)in.nval ; } static String ins()throws IOException { in.nextToken(); return in.sval ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := ini() ; var k : int ; k := ini() ; var a : Sequence(String) ; a := ins()->characters() ; var b : Sequence(String) ; b := ins()->characters() ; var ans : long ; ans := 0 ; var w : long ; w := 1 ; var i : int ; i := 0 ; while i < n do ( ( w := (w*(2->pow(1)))->oclAsType(long) ; if (a[i+1] = 'b') then w := w - 1 ; else skip ; if (b[i+1] = 'a') then w := w - 1 ; else skip ; if (w > 1000000000) then w := 1000000000 ; else skip ; ans := ans+(Set{w, k}->min()) ; ) ; i := i + 1 ) ; out.print(ans) ; out.flush() ; ); static attribute in : StreamTokenizer := StreamTokenizer.newStreamTokenizer(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))); static operation ini() : int pre: true post: true activity: ( in.next() ; return in.nval->oclAsType(int) ); static operation ins() : String pre: true post: true activity: ( in.next() ; return in.sval ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class solution { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); long n=Long.parseLong(f.readLine()); int digits=Long.toString(n).length(); long val=0 ; for(int i=0 ; itoLong() ; var digits : int ; digits := ((n) + "")->size() ; var val : long ; val := 0 ; var i : int ; i := 0 ; while i < digits - 1 do ( ( val := val+(10->pow(i)) ) ; i := i + 1 ) ; var ans : int ; ans := 9 * (digits - 1) + sumDig(n - 9 * val) ; OclFile["System.out"].println(ans) ; skip ; ); static operation sumDig( n : long) : int pre: true post: true activity: ( var x : int ; x := '0' ; var s : String ; s := ((n) + "") ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( ans := ans+(s->at(i+1) - x) ) ; i := i + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); int a=2 ; double result=0 ; for(int i=1 ; i<=n ; i++){ a=2 ; if(i<=k-1){ while(a*itoInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var a : int ; a := 2 ; var result : double ; result := 0 ; var i : int ; i := 1 ; while i <= n do ( ( a := 2 ; if (i <= k - 1) then ( while (a * i < k) do ( a := a * 2 ) ; var b2 : double ; b2 := 1->oclAsType(double) / n / a ; result := result+(b2) ) else ( var b1 : double ; b1 := 1->oclAsType(double) / n ; result := result+(b1) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; inputClass in=new inputClass(inputStream); PrintWriter out=new PrintWriter(outputStream); CDiceAndCoin solver=new CDiceAndCoin(); solver.solve(1,in,out); out.close(); } static class CDiceAndCoin { static double pow(double x,long y,int p){ double 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 ; } public void solve(int testNumber,inputClass sc,PrintWriter out){ int n=sc.nextInt(); int k=sc.nextInt(); double res=0 ; double each=1d/n ; for(int i=1 ; i<=n ; i++){ res+=each*pow(0.5,(int)Math.ceil(Math.log((double)k/i)/Math.log(2)),1000000009); } out.println(res); } } static class inputClass { BufferedReader br ; StringTokenizer st ; public inputClass(InputStream in){ br=new BufferedReader(new InputStreamReader(in)); } public String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : inputClass ; in := inputClass.newinputClass(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : CDiceAndCoin ; solver := CDiceAndCoin.newCDiceAndCoin() ; solver.solve(1, in, out) ; skip ; ); static class CDiceAndCoin { static operation pow( x : double, y : long, p : int) : double pre: true post: true activity: ( var res : double ; res := 1 ; x := x mod p ; while (y > 0) do ( if ((y & 1) = 1) then res := (res * x) mod p ; else skip ; y := (y/(2->pow(1)))->oclAsType(long) ; x := (x * x) mod p ) ; return res ); operation solve( testNumber : int, sc : inputClass, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := sc.nextInt() ; var k : int ; k := sc.nextInt() ; var res : double ; res := 0 ; var each : double ; each := 1d / n ; var i : int ; i := 1 ; while i <= n do ( ( res := res+(each * pow(0.5, ((k->oclAsType(double) / i)->log() / (2)->log())->ceil()->oclAsType(int), 1000000009)) ) ; i := i + 1 ) ; skip ; ); } static class inputClass { attribute br : OclFile; attribute st : OclIterator; static operation newinputClass( in : OclFile) : inputClass pre: true post: true activity: ( var self : inputClass ; self := createinputClass(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); double n=sc.nextInt(); double k=sc.nextInt(); double ans[]=new double[(int)n+1]; for(int i=1 ; i<=(int)n ; i++){ double temp=(double)i ; int memo=0 ; while(true){ if(temp>k-1){ break ; } temp*=2 ; memo++; } ans[i]=1/n*pow(0.5,memo); } double res=0 ; for(int i=1 ; i<=(int)n ; i++){ res+=ans[i]; } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : double ; n := sc.getCurrent()->toInteger() ; var k : double ; k := sc.getCurrent()->toInteger() ; var ans : Sequence(double) ; ans := Integer.subrange(1,n->oclAsType(int) + 1)->collect(0.0) ; var i : int ; i := 1 ; while i <= n->oclAsType(int) do ( ( var temp : double ; temp := i->oclAsType(double) ; var memo : int ; memo := 0 ; while (true) do ( if (temp > k - 1) then ( break ) else skip ; temp := temp*(2) ; memo := memo + 1 ) ; ans[i+1] := 1 / n * pow(0.5, memo) ) ; i := i + 1 ) ; var res : double ; res := 0 ; var i : int ; i := 1 ; while i <= n->oclAsType(int) do ( ( res := res+(ans[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); CDiceAndCoin solver=new CDiceAndCoin(); solver.solve(1,in,out); out.close(); } static class CDiceAndCoin { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(),k=in.nextInt(); double ans=0 ; for(int i=1 ; i<=n ; ++i){ double cur=1 ; int val=i ; while(valtoInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void substringConversions(String str,int k,int b){ int i=0,sum=0,counter=k-1 ; for(i=0 ; iat(i+1) - ('0')->char2byte()) * b->pow(counter)))->oclAsType(int) ; counter := counter - 1 ) ; i := i + 1 ) ; OclFile["System.out"].print(sum + " ") ; var prev : int ; prev := sum ; sum := 0 ; counter := 0 ; while i < str->size() do ( ( sum := (prev - ((str->at(i - k+1) - ('0')->char2byte()) * b->pow(k - 1)))->oclAsType(int) ; sum := sum * b ; sum := sum + (str->at(i+1) - ('0')->char2byte()) ; OclFile["System.out"].print(sum + " ") ; prev := sum ; counter := counter + 1 ; ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "12212" ; var b : int ; b := 3 ; var k : int ; k := 3 ; execute substringConversions(str, b, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static float emi_calculator(float p,float r,float t){ float emi ; r=r/(12*100); t=t*12 ; emi=(p*r*(float)Math.pow(1+r,t))/(float)(Math.pow(1+r,t)-1); return(emi); } static public void main(String[] args){ float principal,rate,time,emi ; principal=10000 ; rate=10 ; time=2 ; emi=emi_calculator(principal,rate,time); System.out.println("Monthly EMI is="+emi); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation emi_calculator( p : double, r : double, t : double) : double pre: true post: true activity: ( var emi : double ; r := r / (12 * 100) ; t := t * 12 ; emi := (p * r * 1 + r->pow(t)->oclAsType(double)) / (1 + r->pow(t) - 1)->oclAsType(double) ; return (emi) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var principal : double ; var rate : double ; var time : double ; var emi : double ; principal := 10000 ; rate := 10 ; time := 2 ; emi := emi_calculator(principal, rate, time) ; OclFile["System.out"].println("Monthly EMI is=" + emi) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileNotFoundException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws FileNotFoundException { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A=sc.nextInt(); int B=sc.nextInt(); sc.close(); System.out.println(Math.min(N*A,B)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; skip ; OclFile["System.out"].println(Set{N * A, B}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int count_numbers(int k,int n,boolean flag){ if(n==1){ if(flag){ return(k-1); } else { return 1 ; } } if(flag)return(k-1)*(count_numbers(k,n-1,false)+count_numbers(k,n-1,true)); else return count_numbers(k,n-1,true); } public static void main(String[] args){ int n=3 ; int k=10 ; System.out.println(count_numbers(k,n,true)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count_numbers( k : int, n : int, flag : boolean) : int 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, false) + count_numbers(k, n - 1, true)) else return count_numbers(k, n - 1, true) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; var k : int ; k := 10 ; OclFile["System.out"].println(count_numbers(k, n, true)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc ; long L,R ; private static long MOD=1000000007L ; public Main(){ sc=new Scanner(System.in); } private void calc(){ L=sc.nextLong(); R=sc.nextLong(); System.out.println(count(0,0,63)); System.out.flush(); } private long count(long x,long y,int maskn){ if((x | y)!=0 &&(y>>>1)>=x)return 0L ; if(R>>1)+1L ; long su=count(x | nextBit,y | nextBit,maskn); long sl=count(x,y,maskn); long sm=-1 ; if(x!=y)if(LtoLong() ; R := sc.getCurrent()->toLong() ; OclFile["System.out"].println(count(0, 0, 63)) ; OclFile["System.out"].flush() ); operation count( x : long, y : long, maskn : int) : long pre: true post: true activity: ( if ((x or y) /= 0 & ((y/(2->pow(1)))->oclAsType(long)) >= x) then return 0L else skip ; if (R < x or R < y) then return 0L else skip ; var mask : long ; mask := ((1L*(2->pow(maskn)))->oclAsType(long)) - 1L ; if ((y or mask) < L or (x or mask) < L) then return 0L else skip ; if (L <= x & (y or mask) <= R) then ( if (maskn = 0) then return 1L else skip ; return (3 * count(x, y or mask, maskn - 1)) mod MOD ) else skip ; maskn := maskn - 1 ; var nextBit : long ; nextBit := ((mask/(2->pow(1)))->oclAsType(long)) + 1L ; var su : long ; su := count(x or nextBit, y or nextBit, maskn) ; var sl : long ; sl := count(x, y, maskn) ; var sm : long ; sm := -1 ; if (x /= y) then if (L < x) then sm := su else if ((y or mask) < R) then sm := sl ; else skip ; ; else skip ; if (sm = -1) then sm := count(x, y or nextBit, maskn) ; else skip ; return (sl + sm + su) mod MOD ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().calc() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; import java.io.*; public class Hello { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); long num=in.nextLong(); long nine=0 ; for(int i=0 ; i<=num ; i++){ nine=(10*nine)+9 ; if(nine>=num){ if(nine==num){ nine=nine ; } else { nine=(long)(nine/10); } break ; } } long rem=num-nine ; pw.println(digit_Sum(rem)+digit_Sum(nine)); pw.close(); } static long digit_Sum(long n){ long sum=0 ; while(n!=0){ sum+=n % 10 ; n/=10 ; } return sum ; } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Hello { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var num : long ; num := in.getCurrent()->toLong() ; var nine : long ; nine := 0 ; var i : int ; i := 0 ; while i <= num do ( ( nine := (10 * nine) + 9 ; if (nine >= num) then ( if (nine = num) then ( nine := nine ) else ( nine := (nine / 10)->oclAsType(long) ) ; break ) else skip ) ; i := i + 1 ) ; var rem : long ; rem := num - nine ; skip ; skip ; ); static operation digit_Sum( n : long) : long pre: true post: true activity: ( var sum : long ; sum := 0 ; while (n /= 0) do ( sum := sum+(n mod 10) ; n := n/(10) ) ; return sum ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc ; long L,R ; private static long MOD=1000000007L ; private static final long[] MASK ; static { MASK=new long[64]; MASK[0]=0L ; for(int i=1 ; i<64 ; i++)MASK[i]=MASK[i-1]*2+1 ; } private static final long[] POW3 ; static { POW3=new long[64]; POW3[0]=1L ; for(int i=1 ; i<64 ; i++)POW3[i]=(POW3[i-1]*3L)% MOD ; } public Main(){ sc=new Scanner(System.in); } private void calc(){ L=sc.nextLong(); R=sc.nextLong(); System.out.println(count(0,0,63)); System.out.flush(); } private long count(long x,long y,int maskn){ if((x | y)!=0 &&(y>>>1)>=x)return 0L ; if(Rcollect(0) ; MASK[0+1] := 0L ; var i : int ; i := 1 ; while i < 64 do ( MASK[i+1] := MASK[i - 1+1] * 2 + 1 ; ; i := i + 1 ) ; ; static attribute POW3 : Sequence(long); static operation initialiseClass() pre: true post: true activity: POW3 := Integer.subrange(1,64)->collect(0) ; POW3[0+1] := 1L ; var i : int ; i := 1 ; while i < 64 do ( POW3[i+1] := (POW3[i - 1+1] * 3L) mod MOD ; ; i := i + 1 ) ; ; static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ); operation calc() : void pre: true post: true activity: ( L := sc.getCurrent()->toLong() ; R := sc.getCurrent()->toLong() ; OclFile["System.out"].println(count(0, 0, 63)) ; OclFile["System.out"].flush() ); operation count( x : long, y : long, maskn : int) : long pre: true post: true activity: ( if ((x or y) /= 0 & ((y/(2->pow(1)))->oclAsType(long)) >= x) then return 0L else skip ; if (R < x or R < y) then return 0L else skip ; if ((y or MASK[maskn+1]) < L or (x or MASK[maskn+1]) < L) then return 0L else skip ; if (L <= x & (y or MASK[maskn+1]) <= R) then return POW3[maskn+1] else skip ; maskn := maskn - 1 ; var nextBit : long ; nextBit := MASK[maskn+1] + 1L ; var su : long ; su := count(x or nextBit, y or nextBit, maskn) ; var sl : long ; sl := count(x, y, maskn) ; if (x = y) then return (su + sl + count(x, y or nextBit, maskn)) mod MOD else if (L < x) then return (2 * su + sl) mod MOD else if ((y or MASK[maskn + 1+1]) < R) then return (su + 2 * sl) mod MOD else skip ; ; ; return (su + sl + count(x, y or nextBit, maskn)) mod MOD ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().calc() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.PrintWriter ; import java.util.Scanner ; import java.util.StringTokenizer ; public class SquareTiles { public static void main(String[] args)throws Exception { Scanner in=new Scanner(new File("input.txt")); PrintWriter out=new PrintWriter("output.txt"); int test=Integer.parseInt(in.nextLine()); for(int t=1 ; t<=test ; t++){ String nums=in.nextLine(); StringTokenizer st=new StringTokenizer(nums); int r=Integer.parseInt(st.nextToken()); int c=Integer.parseInt(st.nextToken()); char[][] map=new char[r][c]; for(int i=0 ; itoInteger() ; var t : int ; t := 1 ; while t <= test do ( ( var nums : String ; nums := in.nextLine() ; var st : OclIterator ; st := OclIterator.newOclIterator_String(nums) ; var r : int ; r := (st.next())->toInteger() ; var c : int ; c := (st.next())->toInteger() ; var map : Sequence(Sequence(String)) ; map := Integer.subrange(1,r)->collect(Integer.subrange(1,c)->collect(0)) ; var i : int ; i := 0 ; while i < r do ( ( var row : String ; row := in.nextLine() ; map[i+1] := row->characters() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < r - 1 do ( ( var j : int ; j := 0 ; while j < c - 1 do ( ( if (map[i+1][j+1] = '#' & map[i+1][j + 1+1] = '#' & map[i + 1+1][j+1] = '#' & map[i + 1+1][j + 1+1] = '#') then ( map[i+1][j+1] := '/' ; map[i + 1+1][j + 1+1] := '/' ; map[i+1][j + 1+1] := '\\' ; map[i + 1+1][j+1] := '\\' ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; booleanok := true ; inti := 0 ; while i < r do ( intj := 0 ; while j < c do ( if (map[i+1][j+1] = '#') then ok := false ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; skip ; if (not(ok)) then skip else ( var i : int ; i := 0 ; while i < r do ( ( var j : int ; j := 0 ; while j < c do ( skip ; ; j := j + 1 ) ; skip ) ; i := i + 1 ) ) ; ) ; t := t + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.Scanner ; public class R1CA { public static void main(String[] args){ try { new R1CA().solve(); } catch(Exception e){ e.printStackTrace(); throw new IllegalStateException(); } } private void solve()throws FileNotFoundException { Scanner in=new Scanner(new File("A-large.in")); PrintWriter out=new PrintWriter("A-large.out"); int testCount=in.nextInt(); for(int test=1 ; test<=testCount ; ++test){ int n=in.nextInt(); int m=in.nextInt(); char[][] a=new char[n][]; for(int i=0 ; itoInteger() ; var test : int ; test := 1 ; while test <= testCount do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var a : Sequence(Sequence(String)) ; a := Integer.subrange(1,n)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->characters() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := 0 ; while j < m - 1 do ( ( if (a[i+1][j+1] = '#' & a[i + 1+1][j+1] = '#' & a[i+1][j + 1+1] = '#' & a[i + 1+1][j + 1+1] = '#') then ( var di : int ; di := 0 ; while di < 2 do ( ( var dj : int ; dj := 0 ; while dj < 2 do ( ( a[i + di+1][j + dj+1] := if ((di + dj) mod 2 = 0) then '/' else '\\' endif ) ; dj := dj + 1 ) ) ; di := di + 1 ) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; booleanbad := false ; inti := 0 ; while i < n do ( ( intj := 0 ; while j < m do ( ( if (a[i+1][j+1] = '#') then ( bad := true ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; if (bad) then ( skip ) else ( var i : int ; i := 0 ; while i < n do ( ( skip ) ; i := i + 1 ) ) ; ) ; test := test + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.nio.charset.StandardCharsets ; public class Main { public static void main(String[] args)throws IOException { InputStreamReader reader=new InputStreamReader(System.in,StandardCharsets.UTF_8); BufferedReader in=new BufferedReader(reader); String S=in.readLine(); int k=S.length(); for(int i=1 ; isize() ; var i : int ; i := 1 ; while i < S->size() do ( ( if (S->at(i - 1+1) /= S->at(i+1)) then ( k := Set{k, Set{i, S->size() - i}->max()}->min() ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(k) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { boolean[] bs ; public static void main(String args[]){ new Main().run(); } void run(){ FastReader sc=new FastReader(); char[] cs=sc.next().toCharArray(); bs=new boolean[cs.length]; for(int i=0 ; icharacters() ; bs := Integer.subrange(1,cs->size())->collect(false) ; var i : int ; i := 0 ; while i < cs->size() do ( ( bs[i+1] := cs[i+1] = '1' ) ; i := i + 1 ) ; execute solve() ; ); operation solve() : void pre: true post: true activity: ( var ans : int ; ans := bs->size() ; var i : int ; i := 0 ; while i < bs->size() - 1 do ( ( if (bs[i+1] xor bs[i + 1+1]) then ( ans := Set{ans, Set{i + 1, bs->size() - i - 1}->max()}->min() ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner inp=new Scanner(System.in); do_(inp); inp.close(); } public static void do_(Scanner inp){ int a=inp.nextInt(); int b=inp.nextInt(); int c=inp.nextInt(); System.out.println(Math.min(a*b,c)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inp : OclFile ; inp := OclFile.newOclFile_Read(OclFile["System.in"]) ; execute do_(inp) ; skip ); static operation do_( inp : OclFile) : void pre: true post: true activity: ( var a : int ; a := inp.getCurrent()->toInteger() ; var b : int ; b := inp.getCurrent()->toInteger() ; var c : int ; c := inp.getCurrent()->toInteger() ; OclFile["System.out"].println(Set{a * b, c}->min()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ char[] s=scanner.next().toCharArray(); int n=s.length ; System.out.println(IntStream.range(1,n).filter(i->s[i-1]!=s[i]).map(i->Math.max(i,n-i)).min().orElse(n)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var s : Sequence(String) ; s := scanner.getCurrent()->characters() ; var n : int ; n := s->size() ; OclFile["System.out"].println(Integer.subrange(1, n-1)->select( _x1 | (lambda i : OclAny in s[i - 1+1] /= s[i+1])->apply(_x1) )->collect( _x1 | (lambda i : OclAny in Set{i, n - i}->max())->apply(_x1) ).min().orElse(n)) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean prime(int n){ for(int i=2 ; i*i<=n ; i++){ if(n % i==0)return false ; } return true ; } static void thirdNumber(int a,int b){ int sum=0,temp=0 ; sum=a+b ; temp=1 ; if(sum==0){ temp=2 ; } while(! prime(sum+temp)){ temp+=2 ; } System.out.print(temp); } static public void main(String[] arr){ int a=3,b=5 ; thirdNumber(a,b); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation prime( n : int) : boolean pre: true post: true activity: ( var i : int ; i := 2 ; while i * i <= n do ( ( if (n mod i = 0) then return false else skip ) ; i := i + 1 ) ; return true ); static operation thirdNumber( a : int, b : int) : void pre: true post: true activity: ( var sum : int ; sum := 0 ; var temp : int ; temp := 0 ; sum := a + b ; temp := 1 ; if (sum = 0) then ( temp := 2 ) else skip ; while (not(prime(sum + temp))) do ( temp := temp+(2) ) ; OclFile["System.out"].print(temp) ; ); static operation main( arr : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 3 ; var b : int ; b := 5 ; execute thirdNumber(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.stream.IntStream ; import java.io.UncheckedIOException ; import java.util.Arrays ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; LightScanner in=new LightScanner(inputStream); PrintWriter out=new PrintWriter(outputStream); DWideFlip solver=new DWideFlip(); solver.solve(1,in,out); out.close(); } static class DWideFlip { public void solve(int testNumber,LightScanner in,PrintWriter out){ int[] s=in.string().chars().map(i->i-'0').toArray(); if(Arrays.stream(s).allMatch(i->i==1)){ out.println(s.length); } else if(Arrays.stream(s).allMatch(i->i==0)){ out.println(s.length); } else { int ans=Integer.MAX_VALUE ; for(int i=1 ; icollect( _x1 | (lambda i : OclAny in i - ('0')->char2byte())->apply(_x1) )->asSequence() ; if (stream(s)->forAll( _x2 | (lambda i : OclAny in i = 1)->apply(_x2) )) then ( skip ) else if (stream(s)->forAll( _x2 | (lambda i : OclAny in i = 0)->apply(_x2) )) then ( skip ) else ( var ans : int ; ans := 2147483647 ; var i : int ; i := 1 ; while i < s->size() do ( ( if (s[i - 1+1] /= s[i+1]) then ( ans := Set{ans, Set{i, s->size() - i}->max()}->min() ) else skip ) ; i := i + 1 ) ; skip ) ; ); } static class LightScanner { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newLightScanner( in : OclFile) : LightScanner pre: true post: true activity: ( var self : LightScanner ; self := createLightScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); operation string() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ) else skip ; return tokenizer.next() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main implements Runnable { public static void main(String[] args){ new Thread(null,new Main(),"",128*1024*1024).start(); } public void run(){ Scanner sc=new Scanner(System.in); String s=sc.next(); int size=s.length(); int[] sequence=new int[100000]; int idx=0 ; int prevIdx=0 ; int prev=s.charAt(0)-'0' ; for(int i=1 ; isize() ; var sequence : Sequence(int) ; sequence := Integer.subrange(1,100000)->collect(0) ; var idx : int ; idx := 0 ; var prevIdx : int ; prevIdx := 0 ; var prev : int ; prev := s->at(0+1) - ('0')->char2byte() ; var i : int ; i := 1 ; while i < size do ( ( var current : int ; current := s->at(i+1) - ('0')->char2byte() ; if (current /= prev) then ( sequence[idx+1] := i - prevIdx ; prevIdx := i ; prev := current ; idx := idx + 1 ) else skip ) ; i := i + 1 ) ; sequence[idx+1] := (size)->char2byte() - prevIdx ; var sum : int ; sum := 0 ; var least : int ; least := 2147483647 ; var i : int ; i := 0 ; while i <= idx do ( ( sum := sum+(sequence[i+1]) ; least := Set{Set{sum, (size)->char2byte() - sum}->max(), least}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(least) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countDistinct(int arr[],int n){ int res=1 ; for(int i=1 ; isize() ; OclFile["System.out"].println(countDistinct(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=128 ; static boolean isVowel(char x){ return(x=='a' || x=='e' || x=='i' || x=='o' || x=='u' || x=='A' || x=='E' || x=='I' || x=='O' || x=='U'); } static int KDistinctVowel(String s,int k){ int n=s.length(); int[] c=new int[MAX]; int result=-1 ; for(int i=0,j=-1 ; isize() ; var c : Sequence(int) ; c := Integer.subrange(1,MAX)->collect(0) ; var result : int ; result := -1 ; var i : int ; i := 0 ; var j : int ; j := -1 ; while i < n do ( ( var x : String ; x := s->at(i+1) ; if (isVowel(x)) then ( if ((c[x+1] + 1) = 1) then ( k := k - 1 ) else skip ) else skip ; while (k < 0) do ( x := s->at((j + 1)+1) ; if (isVowel(x)) then ( if ((c[x+1] - 1) = 0) then ( k := k + 1 ) else skip ) else skip ) ; if (k = 0) then ( result := Set{result, i - j}->max() ) else skip ) ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "tHeracEBetwEEntheTwo" ; var k : int ; k := 1 ; OclFile["System.out"].println(KDistinctVowel(s, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces { public static void main(String[] args){ try(Scanner in=new Scanner(System.in)){ int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); int maxX=0,maxY=0,minX=0,minY=0 ; for(int i=0 ; imaxX){ maxX=x1 ; } if(x1maxY){ maxY=y1 ; } if(y1toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var maxX : int ; maxX := 0 ; var maxY : int ; maxY := 0 ; var minX : int ; minX := 0 ; var minY : int ; minY := 0 ; var i : int ; i := 0 ; while i < n do ( ( var x1 : int ; x1 := in.getCurrent()->toInteger() ; var y1 : int ; y1 := in.getCurrent()->toInteger() ; if (x1 > maxX) then ( maxX := x1 ) else skip ; if (x1 < minX) then ( minX := x1 ) else skip ; if (y1 > maxY) then ( maxY := y1 ) else skip ; if (y1 < minY) then ( minY := y1 ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(2 * (maxX + maxY - minY - minX)) ) ; ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class TravelingSalesmanProblem { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testCase=sc.nextInt(); while(testCase-->0){ int tung=0 ; int hoanh=0 ; int xMax=0 ; int yMax=0 ; int xMin=0 ; int yMin=0 ; int result=0 ; int n=sc.nextInt(); for(int i=0 ; ix){ xMin=x ; } if(yMaxy){ yMin=y ; } } if(xMax>0 && xMin<0){ hoanh=(xMax-xMin)*2 ; } else if(xMax<=0 && xMin<0){ hoanh=xMin*(-2); } else if(xMin>=0 && xMax>0){ hoanh=xMax*2 ; } if(yMax>0 && yMin<0){ tung=(yMax-yMin)*2 ; } else if(yMax<=0 && yMin<0){ tung=yMin*(-2); } else if(yMin>=0 && yMax>0){ tung=yMax*2 ; } result=tung+hoanh ; System.out.println(result); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class TravelingSalesmanProblem { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var testCase : int ; testCase := sc.getCurrent()->toInteger() ; while (testCase > 0) do ( testCase := testCase - 1 ; skip ; ( var tung : int ; tung := 0 ; var hoanh : int ; hoanh := 0 ; var xMax : int ; xMax := 0 ; var yMax : int ; yMax := 0 ; var xMin : int ; xMin := 0 ; var yMin : int ; yMin := 0 ; var result : int ; result := 0 ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (xMax < x) then ( xMax := x ) else skip ; if (xMin > x) then ( xMin := x ) else skip ; if (yMax < y) then ( yMax := y ) else skip ; if (yMin > y) then ( yMin := y ) else skip ; ) ; i := i + 1 ) ; if (xMax > 0 & xMin < 0) then ( hoanh := (xMax - xMin) * 2 ) else if (xMax <= 0 & xMin < 0) then ( hoanh := xMin * (-2) ) else if (xMin >= 0 & xMax > 0) then ( hoanh := xMax * 2 ) else skip ; ; ; if (yMax > 0 & yMin < 0) then ( tung := (yMax - yMin) * 2 ) else if (yMax <= 0 & yMin < 0) then ( tung := yMin * (-2) ) else if (yMin >= 0 & yMax > 0) then ( tung := yMax * 2 ) else skip ; ; ; result := tung + hoanh ; OclFile["System.out"].println(result) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int tc=input.nextInt(); work : while(tc-->0){ int n=input.nextInt(); int right=0,left=0,up=0,down=0 ; for(int i=0 ; i0 && y==0){ right=Math.max(right,x); } else if(x<0 && y==0){ left=Math.max(left,-x); } else if(x==0 && y>0){ up=Math.max(up,y); } else { down=Math.max(down,-y); } } System.out.println(2L*(right+left+up+down)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tc : int ; tc := input.getCurrent()->toInteger() ; while (tc > 0) do ( tc := tc - 1 ; skip ; ( var n : int ; n := input.getCurrent()->toInteger() ; var right : int ; right := 0 ; var left : int ; left := 0 ; var up : int ; up := 0 ; var down : int ; down := 0 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := input.getCurrent()->toInteger() ; var y : int ; y := input.getCurrent()->toInteger() ; if (x > 0 & y = 0) then ( right := Set{right, x}->max() ) else if (x < 0 & y = 0) then ( left := Set{left, -x}->max() ) else if (x = 0 & y > 0) then ( up := Set{up, y}->max() ) else ( down := Set{down, -y}->max() ) ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(2L * (right + left + up + down)) ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1713 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var minX : int ; minX := 0 ; var maxX : int ; maxX := 0 ; var minY : int ; minY := 0 ; var maxY : int ; maxY := 0 ; var n : int ; n := 0 ; while n < N do ( ( var x : int ; x := in.getCurrent()->toInteger() ; minX := Set{minX, x}->min() ; maxX := Set{maxX, x}->max() ; var y : int ; y := in.getCurrent()->toInteger() ; minY := Set{minY, y}->min() ; maxY := Set{maxY, y}->max() ; ) ; n := n + 1 ) ; var answer : int ; answer := 2 * (maxX + maxY - minX - minY) ; OclFile["System.out"].println(answer) ; ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int N=parseInt(br.readLine()); Listlist=new ArrayList<>(); line=br.readLine(); list.add(0); char prev=line.charAt(0); int sum=1 ; int max=1 ; for(int i=2 ; iincluding(0) ; var prev : String ; prev := line->at(0+1) ; var sum : int ; sum := 1 ; var max : int ; max := 1 ; var i : int ; i := 2 ; while i < line->size() do ( ( var next : String ; next := line->at(i+1) ; if (prev /= next) then ( sum := sum + 1 ) else ( list := list->including(sum) ; sum := 1 ) ; prev := next ) ; i := i+(2) ) ; list := list->including(sum) ; list := list->including(0) ; var i : int ; i := 1 ; while i < list->size() - 1 do ( ( max := Set{max, list->at((i)->char2byte() - 1+1) + list->at(i+1) + list->at(i + 1+1)}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { static int sum_of_series(int n){ int result=0 ; for(int i=1 ; i<=n ; i++){ if(i % 2==0)result=result-(int)Math.pow(i,2); else result=result+(int)Math.pow(i,2); } return result ; } public static void main(String args[]){ int n=3 ; System.out.println(sum_of_series(n)); n=10 ; System.out.println(sum_of_series(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sum_of_series( n : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (i mod 2 = 0) then result := result - i->pow(2)->oclAsType(int) ; else result := result + i->pow(2)->oclAsType(int) ; ) ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(sum_of_series(n)) ; n := 10 ; OclFile["System.out"].println(sum_of_series(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.StringTokenizer ; public class Mike_Child { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } double nextDouble(){ return Double.parseDouble(next()); } } public static void main(String[] args){ FastReader in=new FastReader(); int n=in.nextInt(); long arr[]=new long[n]; for(int i=0 ; ihs=new HashMap<>(); int max=1 ; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastReader ; in := FastReader.newFastReader() ; var n : int ; n := in.nextInt() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := in.nextLong() ) ; i := i + 1 ) ; var hs : Map(long,int) ; hs := Map{} ; var max : int ; max := 1 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var s : long ; s := arr[i+1] + arr[j+1] ; if (hs->keys()->includes(s)) then ( var get : int ; get := hs->at(s) ; get := get + 1 ; max := Set{max, get}->max() ; hs := hs->union(Map{s |-> get}) ) else ( hs := hs->union(Map{s |-> 1}) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.text.*; public class B { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); Scanner s=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=Integer.parseInt(f.readLine()); for(int cnt=0 ; cnt0 && ! split[i] .equals("")){ secCount++; } } char[] a=line.toCharArray(); String ans="" ; String sofar="" ; char last=0 ; for(int i=0 ; itoInteger() ; var cnt : int ; cnt := 0 ; while cnt < n do ( ( var line : String ; line := f.readLine() ; if (line = "::") then ( skip ; continue ) else skip ; var split : Sequence(String) ; split := line->split(":") ; var secCount : int ; secCount := 0 ; var i : int ; i := 0 ; while i < split->size() do ( ( if (split[i+1]->size() > 0 & not(split[i+1] = "")) then ( secCount := secCount + 1 ) else skip ) ; i := i + 1 ) ; var a : Sequence(String) ; a := line->characters() ; var ans : String ; ans := "" ; var sofar : String ; sofar := "" ; var last : String ; last := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( if (a[i+1] = ':' & last = a[i+1]) then ( var add : int ; add := 8 - secCount ; sofar := "" ; var j : int ; j := 0 ; while j < add do ( sofar := sofar+("0000" + ":") ; ; j := j + 1 ) ; if (i = a->size() - 1) then ans := ans+(sofar.subrange(0+1,sofar->size() - 1)) else ans := ans+(sofar) ; ; sofar := "" ; continue ) else skip ; if (a[i+1] /= ':') then sofar := sofar+(a[i+1]) ; else skip ; if ((a[i+1] = ':' or i = a->size() - 1) & sofar->size() /= 0) then ( while (sofar->size() /= 4) do ( sofar := "0" + sofar ) ; if (i = a->size() - 1) then ans := ans+(sofar) else ans := ans+(sofar + ":") ; ; sofar := "" ) else skip ; last := a[i+1] ) ; i := i + 1 ) ; skip ; skip ; ) ; cnt := cnt + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ long mod=(long)1e9+7 ; Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); sc.close(); ArrayListlen=new ArrayList<>(); int l=1 ; while(l<=n){ int r=n/(n/l); len.add(r-l+1); l=r+1 ; } int q=len.size(); long[] dp=new long[k*(q+1)]; for(int j=1 ; j<=q ; j++){ dp[j]=len.get(j-1)+dp[j-1]; } for(int i=1 ; ioclAsType(long) + 7 ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; skip ; var len : Sequence(int) ; len := Sequence{} ; var l : int ; l := 1 ; while (l <= n) do ( var r : int ; r := n / (n / l) ; len := len->including(r - l + 1) ; l := r + 1 ) ; var q : int ; q := len->size() ; var dp : Sequence(long) ; dp := Integer.subrange(1,k * (q + 1))->collect(0) ; var j : int ; j := 1 ; while j <= q do ( ( dp[j+1] := len->at(j - 1+1) + dp[j - 1+1] ) ; j := j + 1 ) ; var i : int ; i := 1 ; while i < k do ( ( var j : int ; j := 1 ; while j <= q do ( ( dp[i * (q + 1) + j+1] := dp[i * (q + 1) + j - 1+1] + dp[(i - 1) * (q + 1) + q - j + 1+1] * len->at(j - 1+1) ; dp[i * (q + 1) + j+1] := dp[i * (q + 1) + j+1] mod mod ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dp[k * (q + 1) - 1+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int b0=0,b1=0,b2=1 ; int max=1 ; int prev=sc.nextInt(); for(int i=1 ; itoInteger() ; var b0 : int ; b0 := 0 ; var b1 : int ; b1 := 0 ; var b2 : int ; b2 := 1 ; var max : int ; max := 1 ; var prev : int ; prev := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i < N do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x /= prev) then ( b2 := b2 + 1 ) else ( var len : int ; len := b0 + b1 + b2 ; if (max < len) then max := len ; else skip ; b0 := b1 ; b1 := b2 ; b2 := 1 ; ) ; prev := x ) ; i := i + 1 ) ; var len : int ; len := b0 + b1 + b2 ; if (max < len) then max := len ; else skip ; OclFile["System.out"].printf("%d\n", max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean hasEvenNumberOfFactors(int n){ double root_n=Math.sqrt(n); if((root_n*root_n)==n)return false ; return true ; } static void printStatusOfDoors(int n){ for(int i=1 ; i<=n ; i++){ if(hasEvenNumberOfFactors(i))System.out.print("closed"+" "); else System.out.print("open"+" "); } } public static void main(String[] args){ int n=5 ; printStatusOfDoors(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation hasEvenNumberOfFactors( n : int) : boolean pre: true post: true activity: ( var root_n : double ; root_n := (n)->sqrt() ; if ((root_n * root_n) = n) then return false else skip ; return true ); static operation printStatusOfDoors( n : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= n do ( ( if (hasEvenNumberOfFactors(i)) then OclFile["System.out"].print("closed" + " ") ; else OclFile["System.out"].print("open" + " ") ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; execute printStatusOfDoors(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Nth { public int nthTerm(int N){ if(N<=1)return 1 ; int i,fact=1 ; for(i=1 ; isort() ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < n do ( ( result := result+(if arr[i+1] - (i + 1) < 0 then -(arr[i+1] - (i + 1)) else arr[i+1] - (i + 1) endif) ) ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{0,2,3,4,1,6,8,9} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(get_permutation(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int make_permutation(int arr[],int n){ Arrays.sort(arr); int ans=0 ; for(int i=0 ; isort() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ans := ans+(if i + 1 - arr[i+1] < 0 then -(i + 1 - arr[i+1]) else i + 1 - arr[i+1] endif) ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{5,3,8,1,1} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(make_permutation(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { void doIt(){ Scanner stdIn=new Scanner(System.in); while(true){ int n=stdIn.nextInt(); int m=stdIn.nextInt(); if(n==0 && m==0)break ; double[][] table=new double[n][n]; for(int r=0 ; rtoInteger() ; var m : int ; m := stdIn.getCurrent()->toInteger() ; if (n = 0 & m = 0) then break else skip ; var table : Sequence(Sequence(double)) ; table := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0.0)) ; var r : int ; r := 0 ; while r < n do ( ( var c : int ; c := 0 ; while c < n do ( ( table[r+1][c+1] := stdIn.getCurrent()->toReal() ) ; c := c + 1 ) ) ; r := r + 1 ) ; var dp : Sequence(Sequence(double)) ; dp := Integer.subrange(1,m)->collect(Integer.subrange(1,n)->collect(0.0)) ; dp[0+1] := dp[0+1]->collect(1) ; var k : int ; k := 1 ; while k < m do ( ( var r : int ; r := 0 ; while r < n do ( ( var c : int ; c := 0 ; while c < n do ( ( dp[k+1][c+1] := Set{dp[k+1][c+1], dp[k - 1+1][r+1] * table[r+1][c+1]}->max() ) ; c := c + 1 ) ) ; r := r + 1 ) ) ; k := k + 1 ) ; var ans : double ; ans := -1 ; var r : int ; r := 0 ; while r < n do ( ( ans := Set{ans, dp[dp->size() - 1+1][r+1]}->max() ) ; r := r + 1 ) ; OclFile["System.out"].printf("%.2f\n", ans) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); void run(){ for(; ; ){ int n=sc.nextInt(); int m=sc.nextInt(); if((n | m)==0)return ; double[][] g=new double[n][n]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then return else skip ; var g : Sequence(Sequence(double)) ; g := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0.0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( g[i+1][j+1] := sc.getCurrent()->toReal() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var dp : Sequence(Sequence(double)) ; dp := Integer.subrange(1,m)->collect(Integer.subrange(1,n)->collect(0.0)) ; var i : int ; i := 0 ; while i < n do ( dp[0+1][i+1] := 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m - 1 do ( ( var j : int ; j := 0 ; while j < n do ( ( var k : int ; k := 0 ; while k < n do ( ( dp[i + 1+1][k+1] := Set{dp[i + 1+1][k+1], dp[i+1][j+1] * g[j+1][k+1]}->max() ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : double ; max := 0 ; var i : int ; i := 0 ; while i < n do ( max := Set{max, dp[m - 1+1][i+1]}->max() ; ; i := i + 1 ) ; var bd : double ; bd := double(max) ; OclFile["System.out"].println(bd.setScale(2, ROUND_HALF_UP)) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((o + "")) ); operation debug2( array : Sequence(Sequence(double))) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < array->size() do ( ( var j : int ; j := 0 ; while j < array[i+1]->size() do ( ( OclFile["System.out"].print(array[i+1][j+1]) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import static java.lang.Integer.parseInt ; import static java.lang.Double.parseDouble ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null && ! line.isEmpty()){ int n,m ; n=parseInt(line.substring(0,line.indexOf(' '))); m=parseInt(line.substring(line.indexOf(' ')+1)); if(n==0 && m==0)break ; double[][] vs=new double[n][n]; double[][] dp=new double[m][n]; for(int i=0 ; iisEmpty())) do ( skip ; ( var n : int ; var m : int ; n := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; m := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; if (n = 0 & m = 0) then break else skip ; var vs : Sequence(Sequence(double)) ; vs := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0.0)) ; var dp : Sequence(Sequence(double)) ; dp := Integer.subrange(1,m)->collect(Integer.subrange(1,n)->collect(0.0)) ; var i : int ; i := 0 ; while i < n do ( ( var words : Sequence(String) ; words := br.readLine()->split(" ") ; var j : int ; j := 0 ; while j < n do ( ( vs[i+1][j+1] := parseDouble(words[j+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; dp[0+1] := dp[0+1]->collect(1) ; var i : int ; i := 1 ; while i < m do ( ( var j : int ; j := 0 ; while j < n do ( ( var k : int ; k := 0 ; while k < n do ( ( dp[i+1][k+1] := Set{dp[i+1][k+1], dp[i - 1+1][j+1] * vs[j+1][k+1]}->max() ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : double ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( max := Set{max, dp[(m)->char2byte() - 1+1][i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(StringLib.format("%.2f",Sequence{max})) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int day ; static int Hn ; public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ Hn=in.nextInt(); day=in.nextInt(); if(day+Hn==0)break ; double[][] hyou=new double[Hn][Hn]; for(int s=0 ; stoInteger() ; day := in.getCurrent()->toInteger() ; if (day + Hn = 0) then break else skip ; var hyou : Sequence(Sequence(double)) ; hyou := Integer.subrange(1,Hn)->collect(Integer.subrange(1,Hn)->collect(0.0)) ; var s : int ; s := 0 ; while s < Hn do ( var i : int ; i := 0 ; while i < Hn do ( hyou[s+1][i+1] := in.getCurrent()->toReal() ; ; i := i + 1 ) ; ; s := s + 1 ) ; var dp : Sequence(Sequence(double)) ; dp := Integer.subrange(1,Hn)->collect(Integer.subrange(1,day)->collect(0.0)) ; var i : int ; i := 0 ; while i < Hn do ( dp[i+1][0+1] := 1.0 ; ; i := i + 1 ) ; var hi : int ; hi := 1 ; while hi < day do ( ( var i : int ; i := 0 ; while i < Hn do ( ( var max : double ; max := 0 ; var k : int ; k := 0 ; while k < Hn do ( ( max := Set{max, hyou[k+1][i+1] * dp[k+1][hi - 1+1]}->max() ) ; k := k + 1 ) ; dp[i+1][hi+1] := max ) ; i := i + 1 ) ) ; hi := hi + 1 ) ; var max : double ; max := 0 ; var i : int ; i := 0 ; while i < Hn do ( max := Set{max, dp[i+1][day - 1+1]}->max() ; ; i := i + 1 ) ; OclFile["System.out"].printf("%.2f\n", max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { Scanner sc ; Main(){ sc=new Scanner(System.in); } int n,m ; double[][] gl ; double[][] dp ; boolean init(){ n=sc.nextInt(); m=sc.nextInt(); if(n==0 && m==0)return false ; gl=new double[n][n]; for(int i=0 ; itoInteger() ; m := sc.getCurrent()->toInteger() ; if (n = 0 & m = 0) then return false else skip ; gl := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0.0)) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < n do ( gl[i+1][j+1] := sc.getCurrent()->toReal() ; ; j := j + 1 ) ; ; i := i + 1 ) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,m + 1)->collect(0.0)) ; var i : int ; i := 0 ; while i < n do ( dp[i+1] := dp[i+1]->collect(-1) ; ; i := i + 1 ) ; return true ); operation solve( g : double, prev : int, rem : int) : double pre: true post: true activity: ( if (rem = 0) then return g else skip ; if (dp[prev+1][rem+1] /= -1) then return g * dp[prev+1][rem+1] else skip ; var max : double ; max := 0.0 ; var i : int ; i := 0 ; while i < n do ( max := Set{max, solve(gl[prev+1][i+1], i, rem - 1)}->max() ; ; i := i + 1 ) ; dp[prev+1][rem+1] := max ; return g * max ); operation run() : void pre: true post: true activity: ( while (init()) do ( var max : double ; max := 0 ; var i : int ; i := 0 ; while i < n do ( max := Set{max, solve(1.0, i, m - 1)}->max() ; ; i := i + 1 ) ; OclFile["System.out"].printf("%.2f\n", (max * 100)->round() / 100.0) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { static long MOD=1000000007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long k=sc.nextLong(); HashMapmap=new HashMap<>(); ArrayListlist=new ArrayList<>(); for(int i=1 ; i*i<=n ; i++){ if(! map.containsKey(i)){ map.put((long)i,true); list.add((long)i); } if(! map.containsKey(n/i)){ map.put((long)(n/i),true); list.add(n/i); } } Collections.sort(list); int m=list.size(); long[][] dp=new long[(int)k+1][m]; for(int i=0 ; i=0 ; i--){ dp[j+1][i]=(dp[j+1][i+1]+(list.get(m-i-1)-list.get(m-i-2))*dp[j][m-i-1])% MOD ; } } System.out.println(dp[(int)k][0]); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : long := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; var map : Map(long,Boolean) ; map := Map{} ; var list : Sequence(long) ; list := Sequence{} ; var i : int ; i := 1 ; while i * i <= n do ( ( if (not(map->keys()->includes(i))) then ( map := map->union(Map{i->oclAsType(long) |-> true}) ; list := list->including(i->oclAsType(long)) ) else skip ; if (not(map->keys()->includes(n / i))) then ( map := map->union(Map{(n / i)->oclAsType(long) |-> true}) ; list := list->including(n / i) ) else skip ) ; i := i + 1 ) ; list := list->sort() ; var m : int ; m := list->size() ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,k->oclAsType(int) + 1)->collect(Integer.subrange(1,m)->collect(0)) ; var i : int ; i := 0 ; while i < m do ( ( dp[0+1][i+1] := 1 ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < k->oclAsType(int) do ( ( dp[j + 1+1][m - 1+1] := dp[j+1][0+1] ; var i : int ; i := m - 2 ; while i >= 0 do ( ( dp[j + 1+1][i+1] := (dp[j + 1+1][i + 1+1] + (list->at(m - i - 1+1) - list->at(m - i - 2+1)) * dp[j+1][m - i - 1+1]) mod MOD ) ; i := i - 1 ) ) ; j := j + 1 ) ; OclFile["System.out"].println(dp[k->oclAsType(int)+1][0+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { public static void main(String[] $){ Scanner sc=new Scanner(in); int n=sc.nextInt(); int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(); int[] l=new int[n]; for(int i=0 ; i>k)& 1 ; int bit2=(j>>k)& 1 ; if(bit1==1 && bit2==1){ if(la>0)mp+=10 ; la+=l[k]; } else if(bit1==1 && bit2==0){ if(lb>0)mp+=10 ; lb+=l[k]; } else if(bit1==0 && bit2==1){ if(lc>0)mp+=10 ; lc+=l[k]; } } if(la>0 && lb>0 && lc>0){ ans=min(ans,mp+abs(a-la)+abs(b-lb)+abs(c-lc)); } } } out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var l : Sequence(int) ; l := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( l[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ans : int ; ans := 2147483647 ; var i : int ; i := 0 ; while i < ((1*(2->pow(n)))->oclAsType(long)) do ( ( var j : int ; j := 0 ; while j < ((1*(2->pow(n)))->oclAsType(long)) do ( ( var la : int ; la := 0 ; var lb : int ; lb := 0 ; var lc : int ; lc := 0 ; var mp : int ; mp := 0 ; var k : int ; k := 0 ; while k < n do ( ( var bit1 : int ; bit1 := MathLib.bitwiseAnd(((i/(2->pow(k)))->oclAsType(long)),1) ; var bit2 : int ; bit2 := MathLib.bitwiseAnd(((j/(2->pow(k)))->oclAsType(long)),1) ; if (bit1 = 1 & bit2 = 1) then ( if (la > 0) then mp := mp+(10) ; else skip ; la := la+(l[k+1]) ) else if (bit1 = 1 & bit2 = 0) then ( if (lb > 0) then mp := mp+(10) ; else skip ; lb := lb+(l[k+1]) ) else if (bit1 = 0 & bit2 = 1) then ( if (lc > 0) then mp := mp+(10) ; else skip ; lc := lc+(l[k+1]) ) else skip ; ; ) ; k := k + 1 ) ; if (la > 0 & lb > 0 & lc > 0) then ( ans := Set{ans, mp + abs(a - la) + abs(b - lb) + abs(c - lc)}->min() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; out.println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static boolean checkPrime(int numberToCheck){ if(numberToCheck==1){ return false ; } for(int i=2 ; i*i<=numberToCheck ; i++){ if(numberToCheck % i==0){ return false ; } } return true ; } static int primeSum(int l,int r){ int sum=0 ; for(int i=r ; i>=l ; i--){ boolean isPrime=checkPrime(i); if(isPrime){ sum=sum+i ; } } return sum ; } public static void main(String[] args){ int l=4,r=13 ; System.out.println(primeSum(l,r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkPrime( numberToCheck : int) : boolean pre: true post: true activity: ( if (numberToCheck = 1) then ( return false ) else skip ; var i : int ; i := 2 ; while i * i <= numberToCheck do ( ( if (numberToCheck mod i = 0) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); static operation primeSum( l : int, r : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := r ; while i >= l do ( ( var isPrime : boolean ; isPrime := checkPrime(i) ; if (isPrime) then ( sum := sum + i ) else skip ) ; i := i - 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 4 ; var r : int ; r := 13 ; OclFile["System.out"].println(primeSum(l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPrime(int n){ int i ; if(n==1){ return false ; } for(i=2 ; i<=Math.sqrt(n); i++){ if(n % i==0){ return false ; } } return true ; } static boolean check_frequency(char[] s){ HashMapm=new HashMap(); for(int i=0 ; i0 && ! isPrime(m.get(ch))){ return false ; } } return true ; } public static void main(String[] args){ String s="geeksforgeeks" ; if(check_frequency(s.toCharArray())){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPrime( n : int) : boolean pre: true post: true activity: ( var i : int ; if (n = 1) then ( return false ) else skip ; i := 2 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); static operation check_frequency( s : Sequence(String)) : boolean pre: true post: true activity: ( var m : Map(String,int) ; m := Map{} ; var i : int ; i := 0 ; while i < s->size() do ( ( if (m->keys()->includes(s[i+1])) then ( m := m->union(Map{s[i+1] |-> m->at(s[i+1]) + 1}) ) else ( m := m->union(Map{s[i+1] |-> 1}) ) ) ; i := i + 1 ) ; var ch : String ; ch := 'a' ; while ch <= 'z' do ( ( if (m->at(ch) /= null & m->at(ch) > 0 & not(isPrime(m->at(ch)))) then ( return false ) else skip ) ; ch := ch + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "geeksforgeeks" ; if (check_frequency(s->characters())) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class codeforceNastia { public static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int t=sc.nextInt(); for(int i=0 ; iarr[j]){ min=arr[j]; idx=j ; } } int start=1,opration=n/2 ; if(idx % 2!=0){ start=0 ; opration=(n+1)/2 ; } System.out.println(opration); for(int j=0 ; jtoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var prime : long ; prime := 1000000007 ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ; var idx : int ; idx := -1 ; var min : int ; min := 2147483647 ; var j : int ; j := 0 ; while j < n do ( ( if (min > arr[j+1]) then ( min := arr[j+1] ; idx := j ) else skip ) ; j := j + 1 ) ; var start : int ; start := 1 ; var opration : int ; opration := n / 2 ; if (idx mod 2 /= 0) then ( start := 0 ; opration := (n + 1) / 2 ) else skip ; OclFile["System.out"].println(opration) ; var j : int ; j := 0 ; while j < opration do ( ( OclFile["System.out"].print((idx + 1) + " " + (start + 1) + " " + arr[idx+1] + " " + prime) ; start := start+(2) ; OclFile["System.out"].println() ) ; j := j + 1 ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class LetsGoHiking_706B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] nums=new int[n]; for(int i=0 ; inums[i-1]){ ct++; } else { ct=1 ; } if(ct>max){ maxCount=0 ; max=ct ; } if(ct==max)maxCount++; left[i]=ct ; } if(max % 2==0 || maxCount!=1){ System.out.println(0); return ; } ct=1 ; boolean found=false ; for(int i=n-2 ; i>-1 ; i--){ if(nums[i]>nums[i+1]){ ct++; } else { ct=1 ; } if(ct>max || ct==max && left[i]!=max){ System.out.println(0); return ; } if(ct==max)found=true ; } if(found){ System.out.println(1); } else { System.out.println(0); } } } ------------------------------------------------------------ OCL File: --------- class LetsGoHiking_706B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( nums[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; skip ; var left : Sequence(int) ; left := Integer.subrange(1,n)->collect(0) ; var ct : int ; ct := 1 ; var maxCount : int ; maxCount := 1 ; var max : int ; max := 1 ; left[0+1] := 1 ; var i : int ; i := 1 ; while i < n do ( ( if (nums[i+1] > nums[i - 1+1]) then ( ct := ct + 1 ) else ( ct := 1 ) ; if (ct > max) then ( maxCount := 0 ; max := ct ) else skip ; if (ct = max) then maxCount := maxCount + 1 ; else skip ; left[i+1] := ct ) ; i := i + 1 ) ; if (max mod 2 = 0 or maxCount /= 1) then ( OclFile["System.out"].println(0) ; return ) else skip ; ct := 1 ; var found : boolean ; found := false ; var i : int ; i := n - 2 ; while i > -1 do ( ( if (nums[i+1] > nums[i + 1+1]) then ( ct := ct + 1 ) else ( ct := 1 ) ; if (ct > max or ct = max & left[i+1] /= max) then ( OclFile["System.out"].println(0) ; return ) else skip ; if (ct = max) then found := true ; else skip ) ; i := i - 1 ) ; if (found) then ( OclFile["System.out"].println(1) ) else ( OclFile["System.out"].println(0) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n=Integer.parseInt(f.readLine()); StringTokenizer st=new StringTokenizer(f.readLine()); int[] p=new int[n]; for(int i=0 ; ip[i-1]){ left[i]=left[i-1]+1 ; } else { left[i]=1 ; } } int[] right=new int[n]; right[n-1]=1 ; for(int i=n-2 ; i>=0 ; i--){ if(p[i]>p[i+1]){ right[i]=right[i+1]+1 ; } else { right[i]=1 ; } } int max=0 ; boolean flag=false ; for(int i=0 ; imax){ max=temp ; flag=(Math.min(left[i],right[i])+1)/2*2<=temp ; } else if(temp==max){ flag=true ; } } out.println(max % 2==0 || flag ? 0 : 1); f.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var f : OclFile ; f := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ; var n : int ; n := (f.readLine())->toInteger() ; var st : OclIterator ; st := OclIterator.newOclIterator_String(f.readLine()) ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; var left : Sequence(int) ; left := Integer.subrange(1,n)->collect(0) ; left[0+1] := 1 ; var i : int ; i := 1 ; while i < n do ( ( if (p[i+1] > p[i - 1+1]) then ( left[i+1] := left[i - 1+1] + 1 ) else ( left[i+1] := 1 ) ) ; i := i + 1 ) ; var right : Sequence(int) ; right := Integer.subrange(1,n)->collect(0) ; right[n - 1+1] := 1 ; var i : int ; i := n - 2 ; while i >= 0 do ( ( if (p[i+1] > p[i + 1+1]) then ( right[i+1] := right[i + 1+1] + 1 ) else ( right[i+1] := 1 ) ) ; i := i - 1 ) ; var max : int ; max := 0 ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < n do ( ( var temp : int ; temp := Set{left[i+1], right[i+1]}->max() ; if (temp > max) then ( max := temp ; flag := (Set{left[i+1], right[i+1]}->min() + 1) / 2 * 2 <= temp ) else if (temp = max) then ( flag := true ) else skip ; ) ; i := i + 1 ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static SortedSett=new TreeSet(); static void performQueryOne(int num){ t.add(num); } static void performQueryTwo(int num){ t.remove(num); } static int performQueryThree(){ int mini=t.first(); int maxi=t.last(); return maxi-mini ; } public static void main(String[] args){ int num=3 ; performQueryOne(num); num=5 ; performQueryOne(num); num=6 ; performQueryOne(num); num=5 ; performQueryTwo(num); num=2 ; performQueryOne(num); System.out.println(performQueryThree()); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute t : Set(int) := Set{}; static operation performQueryOne( num : int) : void pre: true post: true activity: ( t := t->including(num) ); static operation performQueryTwo( num : int) : void pre: true post: true activity: ( t := t->excludingFirst(num) ); static operation performQueryThree() : int pre: true post: true activity: ( var mini : int ; mini := t->first() ; var maxi : int ; maxi := t->last() ; return maxi - mini ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 3 ; execute performQueryOne(num) ; num := 5 ; execute performQueryOne(num) ; num := 6 ; execute performQueryOne(num) ; num := 5 ; execute performQueryTwo(num) ; num := 2 ; execute performQueryOne(num) ; OclFile["System.out"].println(performQueryThree()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean findGreater(int x,int y){ if(x>y){ return false ; } else { return true ; } } public static void main(String[] args){ int x=4 ; int y=9 ; if(findGreater(x,y))System.out.println("1"); else System.out.println("2"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findGreater( x : int, y : int) : boolean pre: true post: true activity: ( if (x > y) then ( return false ) else ( return true ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 4 ; var y : int ; y := 9 ; if (findGreater(x, y)) then OclFile["System.out"].println("1") ; else OclFile["System.out"].println("2") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int __gcd(int a,int b){ return b==0 ? a : __gcd(b,a % b); } static boolean coprime(int a,int b){ return(__gcd(a,b)==1); } static void pairSum(int n){ int mid=n/2 ; for(int i=mid ; i>=1 ; i--){ if(coprime(i,n-i)==true){ System.out.print(i+" "+(n-i)); break ; } } } public static void main(String args[]){ int n=11 ; pairSum(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation __gcd( a : int, b : int) : int pre: true post: true activity: ( return if b = 0 then a else __gcd(b, a mod b) endif ); static operation coprime( a : int, b : int) : boolean pre: true post: true activity: ( return (__gcd(a, b) = 1) ); static operation pairSum( n : int) : void pre: true post: true activity: ( var mid : int ; mid := n / 2 ; var i : int ; i := mid ; while i >= 1 do ( ( if (coprime(i, n - i) = true) then ( OclFile["System.out"].print(i + " " + (n - i)) ; break ) else skip ) ; i := i - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 11 ; execute pairSum(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int solve(int arr[],int n){ Arrays.sort(arr); int a=0,b=0 ; for(int i=0 ; isort() ; var a : int ; a := 0 ; var b : int ; b := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (i mod 2 /= 0) then a := a * 10 + arr[i+1] ; else b := b * 10 + arr[i+1] ; ) ; i := i + 1 ) ; return a + b ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{6,8,4,5,2,3} ; var n : int ; n := arr->size() ; OclFile["System.out"].print("Sum is " + solve(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class FileName { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String str=sc.next(); int count=0 ; int total=0 ; for(int i=0 ; i=3){ total+=count-2 ; count=0 ; } count=0 ; } } if(count>=3){ total+=count-2 ; count=0 ; } System.out.println(total); } } ------------------------------------------------------------ OCL File: --------- class FileName { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var str : String ; str := sc.getCurrent() ; var count : int ; count := 0 ; var total : int ; total := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = 'x') then ( count := count + 1 ; continue ) else ( if (count >= 3) then ( total := total+((count)->char2byte() - 2) ; count := 0 ) else skip ; count := 0 ) ) ; i := i + 1 ) ; if (count >= 3) then ( total := total+((count)->char2byte() - 2) ; count := 0 ) else skip ; OclFile["System.out"].println(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isPrime(long n){ if(n<2)return false ; for(long i=2 ; i<=Math.sqrt(n); i++){ if(n % i==0)return false ; } return true ; } static String reverse(String s){ String s1="" ; for(int i=s.length()-1 ; i>=0 ; i--)s1+=s.charAt(i); return s1 ; } static long nextPrimePalindrome(long N){ for(long k=1 ; k<1000000l ; k++){ String s=""+k ; String z ; z=reverse(s); long x=Long.parseLong(s+z.substring(1,z.length())); if(x>=N && isPrime(x))return x ; s=""+(k); z=s ; z=reverse(z); x=Long.parseLong(s+z); if(x>=N && isPrime(x))return x ; } return-1 ; } public static void main(String args[]){ long N=7000000000l ; System.out.println(nextPrimePalindrome(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPrime( n : long) : boolean pre: true post: true activity: ( if (n < 2) then return false else skip ; var i : long ; i := 2 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then return false else skip ) ; i := i + 1 ) ; return true ); static operation reverse( s : String) : String pre: true post: true activity: ( var s1 : String ; s1 := "" ; var i : int ; i := s->size() - 1 ; while i >= 0 do ( s1 := s1+(s->at(i+1)) ; ; i := i - 1 ) ; return s1 ); static operation nextPrimePalindrome( N : long) : long pre: true post: true activity: ( var k : long ; k := 1 ; while k < 1000000l do ( ( var s : String ; s := "" + k ; var z : String ; z := reverse(s) ; var x : long ; x := (s + z.subrange(1+1,z->size()))->toLong() ; if (x >= N & isPrime(x)) then return x else skip ; s := "" + (k) ; z := s ; z := reverse(z) ; x := (s + z)->toLong() ; if (x >= N & isPrime(x)) then return x else skip ; ) ; k := k + 1 ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : long ; N := 7000000000l ; OclFile["System.out"].println(nextPrimePalindrome(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int N ; public static int A ; public static int B ; public static int C ; public static int[] l ; public static int mp ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); N=sc.nextInt(); A=sc.nextInt(); B=sc.nextInt(); C=sc.nextInt(); l=new int[N]; for(int i=0 ; itoInteger() ; A := sc.getCurrent()->toInteger() ; B := sc.getCurrent()->toInteger() ; C := sc.getCurrent()->toInteger() ; l := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( l[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; mp := 99999999 ; execute dfs(0, 0, 0, 0, 0, 0, 0) ; OclFile["System.out"].println(mp) ; ); static operation dfs( i : int, a : int, b : int, c : int, acount : int, bcount : int, ccount : int) : void pre: true post: true activity: ( if (i = N) then ( var mp_ : int ; mp_ := 0 ; if (a /= 0 & b /= 0 & c /= 0) then ( if (acount /= 0) then ( mp_ := mp_+((acount - 1) * 10) ) else skip ; if (bcount /= 0) then ( mp_ := mp_+((bcount - 1) * 10) ) else skip ; if (ccount /= 0) then ( mp_ := mp_+((ccount - 1) * 10) ) else skip ; mp_ := mp_+(if a - A < 0 then -(a - A) else a - A endif + if b - B < 0 then -(b - B) else b - B endif + if c - C < 0 then -(c - C) else c - C endif) ; mp := Set{mp, mp_}->min() ; ) else skip ; return ) else skip ; execute dfs(i + 1, a, b, c, acount, bcount, ccount) ; execute dfs(i + 1, a + l[i+1], b, c, acount + 1, bcount, ccount) ; execute dfs(i + 1, a, b + l[i+1], c, acount, bcount + 1, ccount) ; execute dfs(i + 1, a, b, c + l[i+1], acount, bcount, ccount + 1) ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maxLen=30 ; static int findCnt(int arr[],int n,int k){ int ans=0 ; for(int i=1 ; ik || arr[i]<-1*k)ans++; } if(arr[0]>k || arr[0]<-1*k)ans++; Arrays.sort(arr); for(int i=0 ; ielement)high=middle ; else low=middle+1 ; } return low ; } public static void main(String[] args){ int arr[]={ -1,4,-5,6 }; int n=arr.length ; int k=0 ; System.out.println(findCnt(arr,n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute maxLen : int := 30; static operation findCnt( arr : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i < n do ( ( arr[i+1] := arr[i+1]+(arr[i - 1+1]) ; if (arr[i+1] > k or arr[i+1] < -1 * k) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; if (arr[0+1] > k or arr[0+1] < -1 * k) then ans := ans + 1 ; else skip ; arr := arr->sort() ; var i : int ; i := 0 ; while i < n do ( ans := ans+(n - upper_bound(arr, 0, n, arr[i+1] + k)) ; ; i := i + 1 ) ; return ans ); static operation upper_bound( a : Sequence(int), low : int, high : int, element : int) : int pre: true post: true activity: ( while (low < high) do ( var middle : int ; middle := low + (high - low) / 2 ; if (a[middle+1] > element) then high := middle ; else low := middle + 1 ; ) ; return low ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-1,4,-5,6} ; var n : int ; n := arr->size() ; var k : int ; k := 0 ; OclFile["System.out"].println(findCnt(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); try { File file=new File("input.txt"); BufferedReader br=new BufferedReader(new FileReader(file)); String st=br.readLine(); int temp=Integer.parseInt(st); while((st=br.readLine())!=null){ int pos1=Integer.parseInt(st.charAt(0)+""); int pos2=Integer.parseInt(st.charAt(2)+""); if(pos1==temp){ temp=pos2 ; } else if(pos2==temp){ temp=pos1 ; } } PrintWriter out=new PrintWriter(new FileWriter("output.txt")); out.println(temp); out.close(); } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; try ( var file : OclFile ; file := OclFile("input.txt") ; var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(file)) ; var st : String ; st := br.readLine() ; var temp : int ; temp := (st)->toInteger() ; st := br.readLine() ; while ((st) /= null) do ( skip ; ( var pos1 : int ; pos1 := (st->at(0+1) + "")->toInteger() ; var pos2 : int ; pos2 := (st->at(2+1) + "")->toInteger() ; if (pos1 = temp) then ( temp := pos2 ) else if (pos2 = temp) then ( temp := pos1 ) else skip ; ) ; st := br.readLine() ; ) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) ; skip ; skip ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ShellGame { public static void solve(Scanner sc,PrintWriter pw){ int t=sc.nextInt(); int[] board=new int[4]; Arrays.fill(board,0); board[t]=1 ; int a,b,temp ; for(int i=0 ; i<3 ; i++){ a=sc.nextInt(); b=sc.nextInt(); temp=board[a]; board[a]=board[b]; board[b]=temp ; } for(int i=1 ; i<=3 ; i++){ if(board[i]==1){ pw.println(i); return ; } } } public static void main(String[] args)throws Exception { int t ; Scanner sc=new Scanner(new FileReader("input.txt")); PrintWriter pw=new PrintWriter(new FileWriter("output.txt")); solve(sc,pw); pw.flush(); sc.close(); pw.close(); } } ------------------------------------------------------------ OCL File: --------- class ShellGame { static operation solve( sc : OclFile, pw : OclFile) : void pre: true post: true activity: ( var t : int ; t := sc.nextInt() ; var board : Sequence(int) ; board := Integer.subrange(1,4)->collect(0) ; board := board->collect(0) ; board[t+1] := 1 ; var a : int ; var b : int ; var temp : int ; var i : int ; i := 0 ; while i < 3 do ( ( a := sc.nextInt() ; b := sc.nextInt() ; temp := board[a+1] ; board[a+1] := board[b+1] ; board[b+1] := temp ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= 3 do ( ( if (board[i+1] = 1) then ( pw.println(i) ; return ) else skip ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) ; execute solve(sc, pw) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Tests { public static void main(String[] args)throws FileNotFoundException { Scanner in=new Scanner(new FileReader("input.txt")); PrintStream out=new PrintStream(new File("output.txt")); int n=in.nextInt(); for(int i=0 ; i<3 ; i++){ int x=in.nextInt(); int y=in.nextInt(); if(x==n){ n=y ; } else if(y==n){ n=x ; } } out.println(n); } } ------------------------------------------------------------ OCL File: --------- class Tests { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile("output.txt")) ; var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < 3 do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var y : int ; y := in.getCurrent()->toInteger() ; if (x = n) then ( n := y ) else if (y = n) then ( n := x ) else skip ; ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.Scanner ; public class ShellGame { public static void main(String[] args){ Scanner in=null ; PrintWriter out=null ; try { in=new Scanner(new File("input.txt")); OutputStream os=new FileOutputStream("output.txt"); OutputStreamWriter osw=new OutputStreamWriter(os); out=new PrintWriter(osw,true); } catch(IOException x){ System.err.format("IOException: %s%n",x); } int ball=in.nextInt(); int[] pos=new int[3]; pos[0]=1 ; pos[1]=2 ; pos[2]=3 ; for(int i=0 ; i<3 ; i++){ int a=in.nextInt(); int b=in.nextInt(); int tmp=pos[a-1]; pos[a-1]=pos[b-1]; pos[b-1]=tmp ; } for(int i=0 ; i<3 ; i++){ if(pos[i]==ball){ out.printf("%d\n",i+1); break ; } } } } ------------------------------------------------------------ OCL File: --------- class ShellGame { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := null ; var out : OclFile ; out := null ; try ( in := OclFile.newOclFile_Read(OclFile("input.txt")) ; var os : OclFile ; os := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var osw : OclFile ; osw := OclFile.newOclFile_Write(os) ; out := OclFile.newOclFile_Write(osw, true) ) catch (x : IOException) do ( OclFile["System.err"].format("IOException: %s%n", x) ) var ball : int ; ball := in.getCurrent()->toInteger() ; var pos : Sequence(int) ; pos := Integer.subrange(1,3)->collect(0) ; pos[0+1] := 1 ; pos[1+1] := 2 ; pos[2+1] := 3 ; var i : int ; i := 0 ; while i < 3 do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var tmp : int ; tmp := pos[a - 1+1] ; pos[a - 1+1] := pos[b - 1+1] ; pos[b - 1+1] := tmp ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 3 do ( ( if (pos[i+1] = ball) then ( skip ; break ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class CkeckSorted { static int arraySortedOrNot(int arr[],int n){ if(n==1 || n==0)return 1 ; if(arr[n-1]size() ; if (arraySortedOrNot(arr, n) /= 0) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); char[] s=in.nextLine().toCharArray(); in.close(); String chs="HQ9" ; for(int i=0 ; icharacters() ; skip ; var chs : String ; chs := "HQ9" ; var i : int ; i := 0 ; while i < s->size() do ( if (chs->indexOf(s[i+1])-1 /= -1) then ( OclFile["System.out"].println("YES") ; chs := null ; break ) else skip ; ; i := i + 1 ) ; if (chs /= null) then OclFile["System.out"].println("NO") ; else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class HQ9Plus { public static void main(String[] args)throws IOException { FastIO io=new FastIO(); String s=io.nextLine(); boolean doesPrint=false ; for(int i=0 ; isize() do ( ( if (s->at(i+1) = 'H' or s->at(i+1) = 'Q' or s->at(i+1) = '9') then ( doesPrint := true ; break ) else skip ) ; i := i + 1 ) ; io.println(if doesPrint then "YES" else "NO" endif) ; io.close() ; ); static class FastIO extends OclFile { attribute br : OclFile; attribute st : OclIterator; static operation newFastIO() : FastIO pre: true post: true activity: ( var self : FastIO ; self := createFastIO(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute this(OclFile["System.in"], OclFile["System.out"]) ); static operation newFastIO( in : OclFile, out : OclFile) : FastIO pre: true post: true activity: ( var self : FastIO ; self := createFastIO(); self.initialise(in, out); return self ); operation initialise( in : OclFile, out : OclFile) : void pre: true post: true activity: ( execute super(out) ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); static operation newFastIO( problemName : String) : FastIO pre: true post: true activity: ( var self : FastIO ; self := createFastIO(); self.initialise(problemName); return self ); operation initialise( problemName : String) : void pre: true post: true activity: ( execute super(OclFile.newOclFile_Write(problemName + ".out")) ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(problemName + ".in")) ); operation next() : String pre: true post: true activity: ( try ( while (st = null or not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ) catch (e : ProgramException) do skip return null ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : ProgramException) do skip return null ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextBoolean() : boolean pre: true post: true activity: ( return parseBoolean(next()) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static int Squares(int n,int m,int a){ return((m+a-1)/a)*((n+a-1)/a); } public static void main(String arr[]){ int n=6,m=6,a=4 ; System.out.println(Squares(n,m,a)); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation Squares( n : int, m : int, a : int) : int pre: true post: true activity: ( return ((m + a - 1) / a) * ((n + a - 1) / a) ); static operation main( arr : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var m : int ; m := 6 ; var a : int ; a := 4 ; OclFile["System.out"].println(Squares(n, m, a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Codesolver { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str ; str=sc.nextLine(); if(str.contains("Q")|| str.contains("H")|| str.contains("9")){ System.out.println("YES"); } else { System.out.println("NO"); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Codesolver { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.nextLine() ; if (str->includes("Q") or str->includes("H") or str->includes("9")) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import gcj.GCJ ; import java.util.Arrays ; import java.util.Scanner ; public class Osmos { public static void main(String[] args){ Scanner s=GCJ.createScanner('A',true); int T=s.nextInt(); for(int i=1 ; i<=T ; i++){ int size=s.nextInt(); int N=s.nextInt(); int[] m=new int[N]; for(int j=0 ; j1){ int cnt=0 ; for(int j=0 ; jtoInteger() ; var i : int ; i := 1 ; while i <= T do ( ( var size : int ; size := s.getCurrent()->toInteger() ; var N : int ; N := s.getCurrent()->toInteger() ; var m : Sequence(int) ; m := Integer.subrange(1,N)->collect(0) ; var j : int ; j := 0 ; while j < N do ( ( m[j+1] := s.getCurrent()->toInteger() ) ; j := j + 1 ) ; m := m->sort() ; var min : int ; min := N ; if (size > 1) then ( var cnt : int ; cnt := 0 ; var j : int ; j := 0 ; while j < N do ( ( while (size <= m[j+1]) do ( cnt := cnt + 1 ; size := size+(size - 1) ) ; size := size+(m[j+1]) ; min := Set{min, cnt + N - j - 1}->min() ) ; j := j + 1 ) ) else skip ; GCJ.out(i, ((min) + "")) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static class pair { int first,second ; public pair(int first,int second){ this.first=first ; this.second=second ; } } static int countTriplets(int n,Vectorpoints){ Setpts=new HashSet(); int ct=0 ; for(int i=0 ; ipoints=new Vector<>(); points.add(new pair(1,1)); points.add(new pair(2,2)); points.add(new pair(3,3)); int n=points.size(); System.out.println(countTriplets(n,points)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static class pair { attribute first : int; static operation newpair( first : int, second : int) : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(first, second); return self ); operation initialise( first : int, second : int) : void pre: true post: true activity: ( self->at("first") := first ; self->at("second") := second ); } static operation countTriplets( n : int, points : Sequence(pair)) : int pre: true post: true activity: ( var pts : Set(pair) ; pts := Set{} ; var ct : int ; ct := 0 ; var i : int ; i := 0 ; while i < n do ( pts := pts->including(points->at(i+1)) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := i + 1 ; while j < n do ( ( var x : int ; x := points->at(i+1)->at("first") + points->at(j+1)->at("first") ; var y : int ; y := points->at(i+1)->at("second") + points->at(j+1)->at("second") ; if (x mod 2 = 0 & y mod 2 = 0) then if (not(pts->includes(pair.newpair(x / 2, y / 2)))) then ct := ct + 1 ; else skip ; else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; return ct ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var points : Sequence(pair) ; points := Sequence{} ; points := points->including(pair.newpair(1, 1)) ; points := points->including(pair.newpair(2, 2)) ; points := points->including(pair.newpair(3, 3)) ; var n : int ; n := points->size() ; OclFile["System.out"].println(countTriplets(n, points)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int k=sc.nextInt(); k=k % 4 ; if(k==0){ System.out.println("NO"); } else { System.out.println("YES"); for(int i=1 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; k := k mod 4 ; if (k = 0) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ; var i : int ; i := 1 ; while i < n do ( ( if (k = 2 & i mod 4 /= 3) then ( OclFile["System.out"].println((i + 1) + " " + i) ) else ( OclFile["System.out"].println(i + " " + (i + 1)) ) ) ; i := i+(2) ) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static boolean unsat(String str){ boolean check1=false,check2=false,check3=false ; for(int i=0 ; isize() do ( ( if (str->at(i+1) = '3') then check3 := true ; else if (str->at(i+1) = '1') then check1 := true else if (str->at(i+1) = '2') then check2 := true ; else skip ; ; ) ; i := i + 1 ) ; return not((check3 & check1 & check2)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var C : int ; C := sc.getCurrent()->toInteger() ; var l : Sequence(int) ; l := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( l[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ans : int ; ans := 2147483647 ; var i : int ; i := 0 ; while i < ((1*(2->pow((2 * N))))->oclAsType(long)) do ( ( var set : String ; set := ((i) + "") ; while (set->size() < N) do set := "0" + set ; ; if (unsat(set)) then continue else skip ; var tmp : int ; tmp := 0 ; var tmpA : int ; tmpA := 0 ; var tmpB : int ; tmpB := 0 ; var tmpC : int ; tmpC := 0 ; var j : int ; j := 0 ; while j < set->size() do ( ( if (set->at(j+1) = '1') then ( if (tmpA /= 0) then tmp := tmp+(10) ; else skip ; tmpA := tmpA+(l[j+1]) ) else if (set->at(j+1) = '2') then ( if (tmpB /= 0) then tmp := tmp+(10) ; else skip ; tmpB := tmpB+(l[j+1]) ) else if (set->at(j+1) = '3') then ( if (tmpC /= 0) then tmp := tmp+(10) ; else skip ; tmpC := tmpC+(l[j+1]) ) else skip ; ; ) ; j := j + 1 ) ; tmp := tmp+(if (tmpA)->char2byte() - A < 0 then -((tmpA)->char2byte() - A) else (tmpA)->char2byte() - A endif + if (tmpB)->char2byte() - B < 0 then -((tmpB)->char2byte() - B) else (tmpB)->char2byte() - B endif + if (tmpC)->char2byte() - C < 0 then -((tmpC)->char2byte() - C) else (tmpC)->char2byte() - C endif) ; ans := Set{ans, tmp}->min() ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A { private static String fileName=A.class.getSimpleName().replaceFirst("_.*","").toLowerCase(); private static String inputFileName=fileName+".in" ; private static String outputFileName=fileName+".out" ; private static Scanner in ; private static PrintWriter out ; private void solve(){ long s=in.nextInt(); int n=in.nextInt(); long[] a=new long[n]; for(int i=0 ; i=2){ inputFileName=args[0]; outputFileName=args[1]; } in=new Scanner(new FileReader(inputFileName)); out=new PrintWriter(outputFileName); int tests=in.nextInt(); in.nextLine(); for(int t=1 ; t<=tests ; t++){ out.print("Case #"+t+": "); new A().solve(); System.out.println("Case #"+t+": solved"); } in.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class A { static attribute fileName : String := OclType["A"].getSimpleName().replaceFirstMatch("_.*", "")->toLowerCase(); static attribute inputFileName : String := fileName + ".in"; static attribute outputFileName : String := fileName + ".out"; static attribute in : OclFile; static attribute out : OclFile; operation solve() : void pre: true post: true activity: ( var s : long ; s := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var ans : int ; ans := n ; var created : int ; created := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (s = 1) then ( break ) else skip ; while (s <= a[i+1]) do ( created := created + 1 ; s := s+(s - 1) ) ; s := s+(a[i+1]) ; ans := Set{ans, created + n - i - 1}->min() ) ; i := i + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Locale.setDefault(Locale.US) ; if (args->size() >= 2) then ( inputFileName := args[0+1] ; outputFileName := args[1+1] ) else skip ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile(inputFileName))) ; out := OclFile.newOclFile_Write(OclFile.newOclFile(outputFileName)) ; var tests : int ; tests := in.getCurrent()->toInteger() ; skip ; var t : int ; t := 1 ; while t <= tests do ( ( skip ; A.newA().solve() ; OclFile["System.out"].println("Case #" + t + ": solved") ) ; t := t + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package round1b ; import java.io.FileInputStream ; import java.io.FileNotFoundException ; import java.io.FileOutputStream ; import java.util.Arrays ; public class A { public static void main(String[] args)throws FileNotFoundException { Kattio io ; io=new Kattio(new FileInputStream("src/round1b/A-large.in"),new FileOutputStream("src/round1b/A-large.out")); int cases=io.getInt(); for(int i=1 ; i<=cases ; i++){ io.print("Case #"+i+": "); new A().solve(io); } io.close(); } private void solve(Kattio io){ int mySize=io.getInt(); int n=io.getInt(); int size[]=new int[n]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( ( size[i+1] := io.getInt() ) ; i := i + 1 ) ; size := size->sort() ; if (mySize = 1) then ( io.println(n) ; return ) else skip ; var best : int ; best := 2147483647 ; var rem : int ; rem := 0 ; while rem <= n do ( ( var cur : int ; cur := mySize ; var added : int ; added := 0 ; var i : int ; i := 0 ; while i < n - rem do ( ( if (cur <= size[i+1]) then ( cur := cur+((cur - 1)) ; added := added + 1 ; i := i - 1 ) else ( cur := cur+(size[i+1]) ) ) ; i := i + 1 ) ; best := Set{best, rem + added}->min() ) ; rem := rem + 1 ) ; io.println(best) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { static long[][] dp ; public static void main(String[] args)throws Exception { Scanner scan=new Scanner(System.in); int taskCount=scan.nextInt(); dp=new long[101][201]; for(int taskIndex=1 ; taskIndex<=taskCount ; taskIndex++){ int A=scan.nextInt(); int N=scan.nextInt(); int[] arr=new int[N]; for(int i=0 ; i=0){ res=i ; break ; } } System.out.println(String.format("Case #%d: %d",taskIndex,res)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute dp : Sequence(Sequence(long)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var taskCount : int ; taskCount := scan.getCurrent()->toInteger() ; dp := Integer.subrange(1,101)->collect(Integer.subrange(1,201)->collect(0)) ; var taskIndex : int ; taskIndex := 1 ; while taskIndex <= taskCount do ( ( var A : int ; A := scan.getCurrent()->toInteger() ; var N : int ; N := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( arr[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; var i : int ; i := 0 ; while i <= N do ( ( var j : int ; j := 0 ; while j <= 200 do ( ( dp[i+1][j+1] := -1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; dp[0+1][0+1] := A ; var i : int ; i := 1 ; while i <= N do ( ( var current : long ; current := arr[i - 1+1] ; var j : int ; j := 0 ; while j <= 200 do ( ( if (dp[i - 1+1][j+1] = -1) then ( continue ) else skip ; dp[i+1][j + 1+1] := Set{dp[i+1][j + 1+1], dp[i - 1+1][j+1]}->max() ; if (dp[i - 1+1][j+1] <= 1) then ( continue ) else skip ; var temp : long ; temp := dp[i - 1+1][j+1] ; var add : int ; add := 0 ; while (temp <= current) do ( temp := temp+(temp - 1) ; add := add + 1 ) ; dp[i+1][j + add+1] := Set{dp[i+1][j + add+1], temp + current}->max() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var res : int ; res := -1 ; var i : int ; i := 0 ; while i <= 200 do ( ( if (dp[N+1][i+1] >= 0) then ( res := i ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(StringLib.format("Case #%d: %d",Sequence{taskIndex,res})) ; ) ; taskIndex := taskIndex + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A { int calc(int a,int[] b){ int i=0 ; int res=0 ; if(a==1){ return 100000 ; } while(isize()) do ( if (b[i+1] < a) then ( a := a+(b[i+1]) ; i := i + 1 ) else ( a := a+(a - 1) ; res := res + 1 ) ) ; return res ); operation solve( a : int, b : Sequence(int)) : void pre: true post: true activity: ( b := b->sort() ; var best : int ; best := b->size() ; var i : int ; i := 0 ; while i <= b->size() do ( ( best := Set{best, calc(a, b.subrange(1,i)) + (b->size() - i)}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(best) ); operation run() : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var it : int ; it := 0 ; while it < t do ( ( OclFile["System.out"].print("Case #" + (it + 1) + ": ") ; var a : int ; a := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute solve(a, b) ; ) ; it := it + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A.newA().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); try { int N=scan.nextInt(); int M=scan.nextInt(); int[] X_=new int[M]; for(int i=0 ; itoInteger() ; var M : int ; M := scan.getCurrent()->toInteger() ; var X_ : Sequence(int) ; X_ := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( X_[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; X_ := X_->sort() ; var dist : int ; dist := getDistance(X_, M, N) ; OclFile["System.out"].println(dist) ; ) finally ( skip ) ); static operation getDistance( A : Sequence(int), m : int, n : int) : int pre: true post: true activity: ( var B : Sequence(int) ; B := Integer.subrange(1,m - 1)->collect(0) ; var i : int ; i := 0 ; while i < m - 1 do ( ( B[i+1] := A[i + 1+1] - A[i+1] ) ; i := i + 1 ) ; B := B->sort() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < m - n do ( ( sum := sum+(B[i+1]) ) ; i := i + 1 ) ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class TwoRegularPolygons { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(),m=sc.nextInt(); System.out.println((n % m)==0 ? "YES" : "NO"); } } } ------------------------------------------------------------ OCL File: --------- class TwoRegularPolygons { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(if (n mod m) = 0 then "YES" else "NO" endif) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.lang.System.in ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); int[] x=new int[m]; for(int i=0 ; i=m)return 0 ; int[] dif=new int[m-1]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( x[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; x := x->sort() ; var ans : int ; ans := help(n, m, x) ; OclFile["System.out"].println(ans) ; ); static operation help( n : int, m : int, x : Sequence(int)) : int pre: true post: true activity: ( if (n >= m) then return 0 else skip ; var dif : Sequence(int) ; dif := Integer.subrange(1,m - 1)->collect(0) ; var i : int ; i := 0 ; while i < m - 1 do ( dif[i+1] := x[i + 1+1] - x[i+1] ; ; i := i + 1 ) ; var sum : int ; sum := 0 ; dif := dif->sort() ; var i : int ; i := 0 ; while i < m - n do ( sum := sum+(dif[i+1]) ; ; i := i + 1 ) ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in); ){ new Main().solve(sc); } } void solve(Scanner sc){ int n=sc.nextInt(); int m=sc.nextInt(); if(n>=m){ System.out.println(0); return ; } int[] xs=new int[m]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if (n >= m) then ( OclFile["System.out"].println(0) ; return ) else skip ; var xs : Sequence(int) ; xs := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( xs[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; xs := xs->sort() ; var ds : Sequence(int) ; ds := Integer.subrange(1,m - 1)->collect(null) ; var i : int ; i := 0 ; while i < m - 1 do ( ( ds[i+1] := if xs[i + 1+1] - xs[i+1] < 0 then -(xs[i + 1+1] - xs[i+1]) else xs[i + 1+1] - xs[i+1] endif ) ; i := i + 1 ) ; ds := OclComparator.sortWith(ds, reverseOrder()) ; var ans : int ; ans := 0 ; var i : int ; i := n - 1 ; while i < m - 1 do ( ( ans := ans+(ds[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); ArrayListList=new ArrayList<>(); for(int a=0 ; adis_List=new ArrayList<>(); for(int a=0 ; atoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var List : Sequence(int) ; List := Sequence{} ; var a : int ; a := 0 ; while a < M do ( List := List->including(sc.getCurrent()->toInteger()) ; ; a := a + 1 ) ; List, Comparator.reverseOrder() := List, Comparator.reverseOrder()->sort() ; var dis_List : Sequence(int) ; dis_List := Sequence{} ; var a : int ; a := 0 ; while a < List->size() - 1 do ( ( var dis : int ; dis := List->at(a+1) - List->at(a + 1+1) ; dis_List := dis_List->including(dis) ) ; a := a + 1 ) ; dis_List, Comparator.reverseOrder() := dis_List, Comparator.reverseOrder()->sort() ; var a : int ; a := 0 ; while a < N - 1 do ( ( if (dis_List->size() = 0) then break else skip ; dis_List := dis_List->excludingAt(0+1) ) ; a := a + 1 ) ; var sum : int ; sum := 0 ; var a : int ; a := 0 ; while a < dis_List->size() do ( sum := sum+(dis_List->at(a+1)) ; ; a := a + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); if(N>=M){ System.out.println(0); System.exit(0); } int x[]=new int[M]; for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; if (N >= M) then ( OclFile["System.out"].println(0) ; OclProcess.exit(0) ) else skip ; var x : Sequence(int) ; x := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( x[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; x := x->sort() ; var l : Sequence(int) ; l := Integer.subrange(1,M - 1)->collect(0) ; var i : int ; i := 0 ; while i < M - 1 do ( ( l[i+1] := x[i + 1+1] - x[i+1] ) ; i := i + 1 ) ; var length : int ; length := x[M - 1+1] - x[0+1] ; l := l->sort() ; var i : int ; i := 0 ; while i < N - 1 do ( ( length := length - l[M - 2 - i+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(length) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String args[]){ FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=1 ; while(T-->0){ long n=input.nextLong(); long q=input.nextLong(); for(int i=0 ; i 0) do ( T := T - 1 ; skip ; ( var n : long ; n := input.nextLong() ; var q : long ; q := input.nextLong() ; var i : int ; i := 0 ; while i < q do ( ( var x : long ; x := input.nextLong() ; if (x mod 2 /= 0) then ( skip ) else ( var d : long ; d := n - 1 ; var y : long ; y := x / 2 ; d := d - (y - 1) ; while (true) do ( x := x + d ; if (d mod 2 /= 0) then ( break ) else skip ; d := d / 2 ) ; skip ; ) ) ; i := i + 1 ) ) ; ) ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static int sum(Listbamboos){ int ans=0 ; for(int x : bamboos)ans+=x ; return ans ; } static int magicPoint(Listbamboos,int target){ if(bamboos.isEmpty())return 1000000 ; return 10*(bamboos.size()-1)+Math.abs(sum(bamboos)-target); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A=sc.nextInt(); int B=sc.nextInt(); int C=sc.nextInt(); int[] allBamboos=new int[N]; for(int n=0 ; naBamboos=new ArrayList<>(); ListbBamboos=new ArrayList<>(); ListcBamboos=new ArrayList<>(); for(int n=0 ; n>(2*n))& 3){ case 1 : aBamboos.add(allBamboos[n]); break ; case 2 : bBamboos.add(allBamboos[n]); break ; case 3 : cBamboos.add(allBamboos[n]); break ; } } if(aBamboos.isEmpty()&& bBamboos.isEmpty()&& cBamboos.isEmpty())break ; int mp=magicPoint(aBamboos,A)+magicPoint(bBamboos,B)+magicPoint(cBamboos,C); ans=Math.min(ans,mp); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation sum( bamboos : Sequence(int)) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; for (x : bamboos) do ( ans := ans+(x) ; ) ; return ans ); static operation magicPoint( bamboos : Sequence(int), target : int) : int pre: true post: true activity: ( if (bamboos->isEmpty()) then return 1000000 else skip ; return 10 * (bamboos->size() - 1) + if sum(bamboos) - target < 0 then -(sum(bamboos) - target) else sum(bamboos) - target endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var C : int ; C := sc.getCurrent()->toInteger() ; var allBamboos : Sequence(int) ; allBamboos := Integer.subrange(1,N)->collect(0) ; var n : int ; n := 0 ; while n < N do ( allBamboos[n+1] := sc.getCurrent()->toInteger() ; ; n := n + 1 ) ; var ans : int ; ans := 1000000 ; var i : int ; i := 1 ; while i < 65536 do ( ( var aBamboos : Sequence(int) ; aBamboos := Sequence{} ; var bBamboos : Sequence(int) ; bBamboos := Sequence{} ; var cBamboos : Sequence(int) ; cBamboos := Sequence{} ; var n : int ; n := 0 ; while n < N do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (((i/(2->pow((2 * n))))->oclAsType(long)) & 3) ; if _switchval = 1 then aBamboos := aBamboos->including(allBamboos[n+1]) ; break else skip ; if _switchval = 2 then bBamboos := bBamboos->including(allBamboos[n+1]) ; break else skip ; if _switchval = 3 then cBamboos := cBamboos->including(allBamboos[n+1]) ; break else skip ; ) ) ; n := n + 1 ) ; if (aBamboos->isEmpty() & bBamboos->isEmpty() & cBamboos->isEmpty()) then break else skip ; var mp : int ; mp := magicPoint(aBamboos, A) + magicPoint(bBamboos, B) + magicPoint(cBamboos, C) ; ans := Set{ans, mp}->min() ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedOutputStream ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class B949 { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); long[] pow2=new long[61]; pow2[0]=1 ; for(int i=1 ; i<61 ; i++){ pow2[i]=pow2[i-1]*2 ; } StringTokenizer st=new StringTokenizer(br.readLine()); long n=Long.parseLong(st.nextToken()); long total=n*2-1 ; int q=Integer.parseInt(st.nextToken()); for(; q-->0 ; ){ long pos=Long.parseLong(br.readLine()); if(pos % 2==1){ out.println((pos+1)/2); } else { long nr=total-pos+1 ; for(int i=60 ; i>=0 ; i--){ if(nr % pow2[i]==0){ long a=nr/pow2[i]; if(a*pow2[i]-1+pos==total){ out.println((total-a)/2L+1L); break ; } } } } } out.close(); } } ------------------------------------------------------------ OCL File: --------- class B949 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var pow2 : Sequence(long) ; pow2 := Integer.subrange(1,61)->collect(0) ; pow2[0+1] := 1 ; var i : int ; i := 1 ; while i < 61 do ( ( pow2[i+1] := pow2[i - 1+1] * 2 ) ; i := i + 1 ) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var n : long ; n := (st.next())->toLong() ; var total : long ; total := n * 2 - 1 ; var q : int ; q := (st.next())->toInteger() ; while q > 0 do ( ( var pos : long ; pos := (br.readLine())->toLong() ; if (pos mod 2 = 1) then ( skip ) else ( var nr : long ; nr := total - pos + 1 ; var i : int ; i := 60 ; while i >= 0 do ( ( if (nr mod pow2[i+1] = 0) then ( var a : long ; a := nr / pow2[i+1] ; if (a * pow2[i+1] - 1 + pos = total) then ( skip ; break ) else skip ) else skip ) ; i := i - 1 ) ) ) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int numPerson=in.nextInt(); int[] arr1=new int[numPerson]; int[] arr2=new int[numPerson]; String ans="" ; int previous=Integer.MAX_VALUE ; for(int i=0 ; icollect(0) ; var arr2 : Sequence(int) ; arr2 := Integer.subrange(1,numPerson)->collect(0) ; var ans : String ; ans := "" ; var previous : int ; previous := 2147483647 ; var i : int ; i := 0 ; while i < numPerson do ( ( arr1[i+1] := in.nextInt() ; arr2[i+1] := in.nextInt() ; if (arr1[i+1] /= arr2[i+1]) then ( ans := "rated" ; skip ; skip ; OclProcess.exit(0) ) else skip ) ; i := i + 1 ) ; ans := "maybe" ; var i : int ; i := 0 ; while i < numPerson do ( ( if (previous < arr1[i+1]) then ( ans := "unrated" ; break ) else skip ; previous := arr1[i+1] ) ; i := i + 1 ) ; skip ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("sub.in"))) ) catch (ex : FileNotFoundException) do ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (ex : IOException) do skip ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (ex : IOException) do skip return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; int r=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var r : int ; r := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ; if (a[i+1] /= b[i+1]) then r := 1 ; else skip ) ; i := i + 1 ) ; if (r = 1) then ( OclFile["System.out"].println("rated") ; OclProcess.exit(0) ) else skip ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( if (a[i+1] < a[j+1]) then r := -1 ; else skip ; ; j := j + 1 ) ) ; i := i + 1 ) ; if (r = -1) then OclFile["System.out"].println("unrated") else OclFile["System.out"].println("maybe") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; int r=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var r : int ; r := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ; if (a[i+1] /= b[i+1]) then r := 1 ; else skip ) ; i := i + 1 ) ; if (r = 1) then ( OclFile["System.out"].println("rated") ; OclProcess.exit(0) ) else skip ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( if (a[i+1] < a[j+1]) then r := -1 ; else skip ; ; j := j + 1 ) ) ; i := i + 1 ) ; if (r = -1) then OclFile["System.out"].println("unrated") else OclFile["System.out"].println("maybe") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1312 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ int n=scanner.nextInt(); int m=scanner.nextInt(); if(n % m==0 || m % n==0){ System.out.println("YES"); } else { System.out.println("NO"); } } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class A1312 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; if (n mod m = 0 or m mod n = 0) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringBuilder stringBuilder=new StringBuilder(); StringTokenizer st ; int n=parseInt(in.readLine()); int[] a=new int[n]; int[] b=new int[n]; for(int i=0 ; ia[i]){ System.out.println("unrated"); return ; } } System.out.println("maybe"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var stringBuilder : String ; stringBuilder := StringLib.newString() ; var st : OclIterator ; var n : int ; n := parseInt(in.readLine()) ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( st := OclIterator.newOclIterator_String(in.readLine()) ; a[i+1] := (st.next() + "")->toInteger() ; b[i+1] := (st.next() + "")->toInteger() ; if (a[i+1] /= b[i+1]) then ( OclFile["System.out"].println("rated") ; return ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (a[i + 1+1] > a[i+1]) then ( OclFile["System.out"].println("unrated") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("maybe") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; int brr[]=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var brr : Sequence(int) ; brr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; brr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] /= brr[i+1]) then ( flag := 1 ; break ) else skip ) ; i := i + 1 ) ; if (flag = 1) then ( OclFile["System.out"].println("rated") ) else ( var i : int ; i := 0 ; while i < n - 1 do ( ( if (arr[i+1] < arr[i + 1+1]) then ( flag := 2 ; break ) else skip ) ; i := i + 1 ) ; if (flag = 2) then ( OclFile["System.out"].println("unrated") ) else ( OclFile["System.out"].println("maybe") ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findEvenPair(int A[],int N){ int count=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(findEvenPair(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Math.*; import java.util.*; import java.io.*; public class StonedGame { public static void main(String omkar[])throws Exception { BufferedReader infile=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(infile.readLine()); int T=Integer.parseInt(st.nextToken()); StringBuilder sb=new StringBuilder(); while(T-->0){ st=new StringTokenizer(infile.readLine()); int N=Integer.parseInt(st.nextToken()); int[] arr=readArr(N,infile,st); int sum=0 ; for(int x : arr)sum+=x ; Arrays.sort(arr); int max=arr[N-1]; if(sum-maxtoInteger() ; var sb : String ; sb := StringLib.newString() ; while (T > 0) do ( T := T - 1 ; skip ; ( st := OclIterator.newOclIterator_String(infile.readLine()) ; var N : int ; N := (st.next())->toInteger() ; var arr : Sequence(int) ; arr := readArr(N, infile, st) ; var sum : int ; sum := 0 ; for (x : arr) do ( sum := sum+(x) ; ) ; arr := arr->sort() ; var max : int ; max := arr[(N)->char2byte() - 1+1] ; if (sum - max < max) then sb := sb + StringLib.newString("T\n") else ( if (sum mod 2 = 1) then sb := sb + StringLib.newString("T\n") ; else sb := sb + StringLib.newString("HL\n") ; ) ; ) ; ) ; OclFile["System.out"].print(sb) ; ); static operation readArr( N : int, infile : OclFile, st : OclIterator) : Sequence(int) pre: true post: true activity: ( var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; st := OclIterator.newOclIterator_String(infile.readLine()) ; var i : int ; i := 0 ; while i < N do ( arr[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; return arr ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static MyReader scan=new MyReader(); public static void main(String[] args)throws Exception { Main m=new Main(); int q=scan.nextInt(); while(q-->0)m.solve(); } void solve()throws Exception { int n=scan.nextInt(); int[] arr=new int[n]; for(int i=0 ; isum-arr[n-1] || sum % 2==1){ System.out.println("T"); } else { System.out.println("HL"); } } } } class MyReader { private BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer tokenizer=new StringTokenizer(""); private String innerNextLine(){ try { return reader.readLine(); } catch(IOException ex){ return null ; } } public boolean hasNext(){ while(! tokenizer.hasMoreTokens()){ String nextLine=innerNextLine(); if(nextLine==null){ return false ; } tokenizer=new StringTokenizer(nextLine); } return true ; } public String nextLine(){ tokenizer=new StringTokenizer(""); return innerNextLine(); } public String next(){ hasNext(); return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public Long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scan : MyReader := MyReader.newMyReader(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; var q : int ; q := scan.nextInt() ; while (q > 0) do ( q := q - 1 ; skip ; m.solve() ; ; ) ); operation solve() : void pre: true post: true activity: ( var n : int ; n := scan.nextInt() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := scan.nextInt() ) ; i := i + 1 ) ; if (n = 1) then ( OclFile["System.out"].println("T") ) else if (n = 2) then ( if (arr[0+1] = arr[1+1]) then ( OclFile["System.out"].println("HL") ) else ( OclFile["System.out"].println("T") ) ) else ( arr := arr->sort() ; var sum : int ; sum := stream(arr)->sum() ; if (arr[n - 1+1] > sum - arr[n - 1+1] or sum mod 2 = 1) then ( OclFile["System.out"].println("T") ) else ( OclFile["System.out"].println("HL") ) ) ; ); } class MyReader { attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute tokenizer : OclIterator := OclIterator.newOclIterator_String(""); operation innerNextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (ex : IOException) do ( return null ) ); operation hasNext() : boolean pre: true post: true activity: ( while (not(tokenizer.hasNext())) do ( var nextLine : String ; nextLine := innerNextLine() ; if (nextLine = null) then ( return false ) else skip ; tokenizer := OclIterator.newOclIterator_String(nextLine) ) ; return true ); operation nextLine() : String pre: true post: true activity: ( tokenizer := OclIterator.newOclIterator_String("") ; return innerNextLine() ); operation next() : String pre: true post: true activity: ( execute hasNext() ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int cntPairs(int a[],int n){ int odd=0,even=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(cntPairs(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static int minOperations(int n,int m){ if(m % n!=0)return-1 ; int minOperations=0 ; int q=m/n ; while(q % 2==0){ q=q/2 ; minOperations++; } while(q % 3==0){ q=q/3 ; minOperations++; } if(q==1)return minOperations ; return-1 ; } public static void main(String[] args){ int n=120,m=51840 ; System.out.println(minOperations(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation minOperations( n : int, m : int) : int pre: true post: true activity: ( if (m mod n /= 0) then return -1 else skip ; var minOperations : int ; minOperations := 0 ; var q : int ; q := m / n ; while (q mod 2 = 0) do ( q := q / 2 ; minOperations := minOperations + 1 ) ; while (q mod 3 = 0) do ( q := q / 3 ; minOperations := minOperations + 1 ) ; if (q = 1) then return minOperations else skip ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 120 ; var m : int ; m := 51840 ; OclFile["System.out"].println(minOperations(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n+1]; int[] b=new int[n+1]; int count=0 ; int ans=0 ; a[0]=0 ; for(int i=1 ; i<=n ; i++)a[i]=sc.nextInt(); for(int i=n ; i>=1 ; i--){ for(int j=2 ; j*i<=n ; j++){ if(b[i*j]==1)count++; } if(count % 2!=a[i]){ b[i]=1 ; ans++; } count=0 ; } System.out.println(ans); StringBuilder sb=new StringBuilder(); for(int i=1 ; i<=n ; i++){ if(b[i]==1)sb.append(String.valueOf(i)+' '); } System.out.println(new String(sb)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n + 1)->collect(0) ; var count : int ; count := 0 ; var ans : int ; ans := 0 ; a[0+1] := 0 ; var i : int ; i := 1 ; while i <= n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := n ; while i >= 1 do ( ( var j : int ; j := 2 ; while j * i <= n do ( ( if (b[i * j+1] = 1) then count := count + 1 ; else skip ) ; j := j + 1 ) ; if (count mod 2 /= a[i+1]) then ( b[i+1] := 1 ; ans := ans + 1 ) else skip ; count := 0 ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 1 ; while i <= n do ( ( if (b[i+1] = 1) then sb := sb + StringLib.newString(((i) + "") + ' ') ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(StringLib.newString(sb)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner scanner=new Scanner(System.in); static int n ; static boolean[] a ; static Boolean[] memo ; static int count=0 ; public static void main(String[] $){ n=scanner.nextInt(); a=new boolean[n]; memo=new Boolean[n]; for(int i=0 ; itoInteger() ; a := Integer.subrange(1,n)->collect(false) ; memo := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() = 1 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( execute f(i) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; var i : int ; i := 0 ; while i < n do ( ( if (memo[i+1]) then ( OclFile["System.out"].println(i + 1) ) else skip ) ; i := i + 1 ) ; ); static operation f( i : int) : boolean pre: true post: true activity: ( if (memo[i - 1+1] /= null) then ( return memo[i - 1+1] ) else skip ; var b : boolean ; b := a[i - 1+1] ; var j : int ; j := 2 ; while (i * j <= n) do ( if (f(i * j)) then ( b := not(b) ) else skip ; j := j + 1 ) ; if (b) then ( count := count + 1 ) else skip ; return memo[i - 1+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int ii=1 ; ii<=t ; ii++){ int a=in.nextInt(),b=in.nextInt(); if(a % b==0){ System.out.println("YES"); } else { System.out.println("NO"); } } } static boolean isPrime(long num){ if(num<=2){ return false ; } if(num % 2==0){ return false ; } for(int i=3 ; i*i<=num ; i++){ if(num % i==0){ return false ; } } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var ii : int ; ii := 1 ; while ii <= t do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; if (a mod b = 0) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ; ii := ii + 1 ) ); static operation isPrime( num : long) : boolean pre: true post: true activity: ( if (num <= 2) then ( return false ) else skip ; if (num mod 2 = 0) then ( return false ) else skip ; var i : int ; i := 3 ; while i * i <= num do ( ( if (num mod i = 0) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashSet ; class Main { public static void main(String args[])throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); Solver solver=new Solver(); solver.init(); solver.readHead(in.readLine()); solver.readA(in.readLine()); } } class Solver { int N ; int cnt ; public void init(){ N=0 ; cnt=0 ; } public void readHead(String str){ String[] strArr=str.split("\\s+"); N=Integer.parseInt(strArr[0]); } public void readA(String str){ String[] strArr=str.split("\\s+"); int[] A=new int[N+1]; for(int i=1 ; i<=N ; i++)A[i]=Integer.parseInt(strArr[i-1]); HashSetB=new HashSet(); for(int i=N ; i>=1 ; i--){ int b=A[i]; for(int j=i*2 ; j<=N ; j=j+i){ if(B.contains(j)){ if(b==0)b=1 ; else b=0 ; } } if(b==1)B.add(i); } System.out.println(B.size()); String sep="" ; for(int n : B){ System.out.print(sep); if("".equals(sep))sep=" " ; System.out.print(n); } System.out.println(); } public boolean hasNext(){ return cntsplit("\\s+") ; N := (strArr[0+1])->toInteger() ); operation readA( str : String) : void pre: true post: true activity: ( var strArr : Sequence(String) ; strArr := str->split("\\s+") ; var A : Sequence(int) ; A := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i <= N do ( A[i+1] := (strArr[i - 1+1])->toInteger() ; ; i := i + 1 ) ; var B : Set(int) ; B := Set{} ; var i : int ; i := N ; while i >= 1 do ( ( var b : int ; b := A[i+1] ; var j : int ; j := i * 2 ; while j <= N do ( ( if (B->includes(j)) then ( if (b = 0) then b := 1 ; else b := 0 ; ) else skip ) ; j := j + i ) ; if (b = 1) then B := B->including(i) ; else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(B->size()) ; var sep : String ; sep := "" ; for (n : B) do ( ( OclFile["System.out"].print(sep) ; if ("" = sep) then sep := " " ; else skip ; OclFile["System.out"].print(n) ) ) ; OclFile["System.out"].println() ; ); operation hasNext() : boolean pre: true post: true activity: ( return cnt < N ); operation readBody( str : String) : void pre: true post: true activity: ( cnt := cnt + 1 ); operation solve() : void pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int l=sc.nextInt(); Lista=new ArrayList<>(); Listresult=new ArrayList<>(); for(int i=0 ; i0 ; i--){ int loopNum=l/i ; boolean isEven=false ; for(int j=loopNum*i ; j>i ; j-=i){ if(result.get(j-1)){ isEven=isEven ? false : true ; } } result.set(i-1,isEven ^ a.get(i-1)); } int count=0 ; StringBuffer sb=new StringBuffer(); for(int i=0 ; i0){ sb.setLength(sb.length()-1); System.out.println(count); System.out.println(sb.toString()); } else { System.out.println("0"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var l : int ; l := sc.getCurrent()->toInteger() ; var a : Sequence(Boolean) ; a := Sequence{} ; var result : Sequence(Boolean) ; result := Sequence{} ; var i : int ; i := 0 ; while i < l do ( ( a := a->including(if sc.getCurrent()->toInteger() = 1 then true else false endif) ; result := result->including(false) ) ; i := i + 1 ) ; var i : int ; i := l ; while i > 0 do ( ( var loopNum : int ; loopNum := l / i ; var isEven : boolean ; isEven := false ; var j : int ; j := loopNum * i ; while j > i do ( ( if (result->at(j - 1+1)) then ( isEven := if isEven then false else true endif ) else skip ) ; j := j-(i) ) ; result := result.setAt(i - 1+1,MathLib.bitwiseXor(isEven,a->at(i - 1+1))) ) ; i := i - 1 ) ; var count : int ; count := 0 ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < l do ( ( if (result->at(i+1)) then ( count := count + 1 ; sb := sb + StringLib.newString((i + 1) + " ") ) else skip ) ; i := i + 1 ) ; if (sb->size() > 0) then ( sb := sb.subrange(1,sb->size() - 1) ; OclFile["System.out"].println(count) ; OclFile["System.out"].println(sb+"") ) else ( OclFile["System.out"].println("0") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Map.Entry ; class Main { static int mod=(int)(Math.pow(10,9)+7); public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[] a=new int[N]; int[] b=new int[N]; int M=0 ; int k=0 ; for(int i=0 ; i0 ; i--){ int sum=0 ; for(int j=i ; jpow(9) + 7)->oclAsType(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,N)->collect(0) ; var M : int ; M := 0 ; var k : int ; k := 0 ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := N ; while i > 0 do ( ( var sum : int ; sum := 0 ; var j : int ; j := i ; while j < N + 1 do ( ( if (b[j - 1+1] = 1) then ( sum := sum + 1 ) else skip ) ; j := j + i ) ; if (sum mod 2 /= a[i - 1+1]) then ( b[i - 1+1] := 1 ; M := M + 1 ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(M) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < N do ( ( if (b[i+1] = 1) then ( if (i = N - 1) then ( sb := sb + StringLib.newString(i + 1) ) else ( sb := sb + StringLib.newString(i + 1) ; sb := sb + StringLib.newString(" ") ) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isDivisible(int arr[],int n){ int lastDigit=arr[n-1] % 10 ; if(lastDigit==0)return true ; return false ; } static public void main(String[] arg){ int arr[]={ 12,65,46,37,99 }; int n=arr.length ; if(isDivisible(arr,n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isDivisible( arr : Sequence(int), n : int) : boolean pre: true post: true activity: ( var lastDigit : int ; lastDigit := arr[n - 1+1] mod 10 ; if (lastDigit = 0) then return true else skip ; return false ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{12,65,46,37,99} ; var n : int ; n := arr->size() ; if (isDivisible(arr, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.nextLine()); String s=sc.nextLine(); char before=s.charAt(0); int ans=1 ; for(int i=1 ; itoInteger() ; var s : String ; s := sc.nextLine() ; var before : String ; before := s->at(0+1) ; var ans : int ; ans := 1 ; var i : int ; i := 1 ; while i < n do ( ( if (s->at(i+1) /= before) then ( before := s->at(i+1) ; ans := ans + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); String S=sc.next(); sc.close(); StringBuilder sb=new StringBuilder(); String S1=S.substring(0,1); sb.append(S1); for(int i=1 ; itoInteger() ; var S : String ; S := sc.getCurrent() ; skip ; var sb : String ; sb := StringLib.newString() ; var S1 : String ; S1 := S.subrange(0+1,1) ; sb := sb + StringLib.newString(S1) ; var i : int ; i := 1 ; while i < N do ( ( if (not(S1 = S.subrange(i+1,i + 1))) then ( S1 := S.subrange(i+1,i + 1) ; sb := sb + StringLib.newString(S1) ) else skip ) ; i := i + 1 ) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); String s=sc.next(); Stackstack=new Stack<>(); for(int i=0 ; itoInteger() ; var s : String ; s := sc.getCurrent() ; var stack : Sequence(String) ; stack := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( if (stack->isEmpty()) then stack := stack->including(s->at(i+1)) ; else ( var c : String ; c := stack->min() ; if (c /= s->at(i+1)) then stack := stack->including(s->at(i+1)) ; else skip ) ) ; i := i + 1 ) ; OclFile["System.out"].println(stack->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countUnsetBits(int n){ int cnt=0 ; for(int i=1 ; i<=n ; i++){ int temp=i ; while(temp>0){ if(temp % 2==0){ cnt=cnt+1 ; } temp=temp/2 ; } } return cnt ; } public static void main(String[] args){ int n=5 ; System.out.println(countUnsetBits(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countUnsetBits( n : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var temp : int ; temp := i ; while (temp > 0) do ( if (temp mod 2 = 0) then ( cnt := cnt + 1 ) else skip ; temp := temp / 2 ) ) ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(countUnsetBits(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ int count=0 ; boolean sw=false ; int max=Integer.MIN_VALUE ; int min=Integer.MAX_VALUE ; double dMax=Double.MIN_VALUE ; double dMin=Double.MAX_VALUE ; Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); String ss[]=new String[n]; for(int i=0 ; ipow(-1074) ; var dMin : double ; dMin := (2 - 2->pow(-52))*(2->pow(1023)) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var ss : Sequence(String) ; ss := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ss[i+1] := s.subrange(i+1,i + 1) ; ; i := i + 1 ) ; var ans : String ; ans := "" ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (not(ss[i+1] = ss[i + 1+1])) then ( ans := ans+(ss[i+1]) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans->size() + 1) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileNotFoundException ; import java.math.BigInteger ; import java.util.Arrays ; import java.util.Random ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws FileNotFoundException { long startTime=System.currentTimeMillis(); new Main().run(); } void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int ans=0 ; String S=sc.next(); for(int i=0 ; itoInteger() ; var ans : int ; ans := 0 ; var S : String ; S := sc.getCurrent() ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := i ; while (j + 1 < N & S->at(i+1) = S->at(j + 1+1)) do ( j := j + 1 ) ; i := j ; ans := ans + 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class RegularPolygon { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int tc=scanner.nextInt(); while(tc-->0){ int n=scanner.nextInt(); int m=scanner.nextInt(); if(n % m==0){ System.out.println("YES"); } else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class RegularPolygon { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tc : int ; tc := scanner.getCurrent()->toInteger() ; while (tc > 0) do ( tc := tc - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; if (n mod m = 0) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void printPattern(int n,int m,boolean flag){ System.out.print(m+" "); if(flag==false && 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); } public static void main(String[] args){ int n=16 ; printPattern(n,n,true); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printPattern( n : int, m : int, flag : boolean) : void pre: true post: true activity: ( OclFile["System.out"].print(m + " ") ; if (flag = false & n = m) then return else skip ; if (flag) then ( if (m - 5 > 0) then execute printPattern(n, m - 5, true) ; else execute printPattern(n, m - 5, false) ; ) else execute printPattern(n, m + 5, false) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 16 ; execute printPattern(n, n, true) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class B { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),m=in.nextInt(),q=in.nextInt(); int[][] state=new int[n][m]; for(int i=0 ; itoInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var q : int ; q := in.getCurrent()->toInteger() ; var state : Sequence(Sequence(int)) ; state := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( state[i+1][j+1] := in.getCurrent()->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : Sequence(int) ; ans := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ans[i+1] := getConseSum(state, i, m) ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < q do ( ( var i : int ; i := in.getCurrent()->toInteger() - 1 ; var j : int ; j := in.getCurrent()->toInteger() - 1 ; if (state[i+1][j+1] = 0) then ( state[i+1][j+1] := 1 ; ans[i+1] := ans[i+1]+(1) ) else ( state[i+1][j+1] := 0 ; ans[i+1] := ans[i+1]-(1) ) ; ans[i+1] := getConseSum(state, i, m) ; var max : int ; max := 0 ; var ii : int ; ii := 0 ; while ii < n do ( max := Set{max, ans[ii+1]}->max() ; ; ii := ii + 1 ) ; skip ; ) ; k := k + 1 ) ; skip ; ); static operation getConseSum( state : Sequence(Sequence(int)), r : int, m : int) : int pre: true post: true activity: ( var Max : int ; Max := 0 ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < m do ( ( if (state[r+1][i+1] = 1) then cnt := cnt + 1 ; else skip ; if (state[r+1][i+1] = 0) then ( Max := Set{Max, cnt}->max() ; cnt := 0 ) else skip ) ; i := i + 1 ) ; Max := Set{cnt, Max}->max() ; return Max ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B548 { static Scanner sc=null ; public static void main(String[] args){ sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int q=sc.nextInt(); int mat[][]=new int[n+1][m+1]; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=m ; j++){ mat[i][j]=sc.nextInt(); } } int count[]=new int[n+1]; for(int i=1 ; i<=n ; i++){ int ans=0 ; int coun=0 ; for(int j=1 ; j<=m ; j++){ if(mat[i][j]==1){ coun+=1 ; } else { coun=0 ; } ans=Math.max(ans,coun); } count[i]=ans ; } while(q-->0){ int r=sc.nextInt(); int c=sc.nextInt(); if(mat[r][c]==1)mat[r][c]=0 ; else mat[r][c]=1 ; int coun=0 ; int ans=0 ; int ncount[]=new int[n+1]; for(int i=1 ; i<=m ; i++){ if(mat[r][i]==1){ coun+=1 ; } else { coun=0 ; } ans=Math.max(coun,ans); } count[r]=ans ; for(int i=0 ; i<=n ; i++){ ncount[i]=count[i]; } Arrays.sort(ncount); System.out.println(ncount[n]); } } } ------------------------------------------------------------ OCL File: --------- class B548 { static attribute sc : OclFile := null; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var mat : Sequence(Sequence(int)) ; mat := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,m + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= m do ( ( mat[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count : Sequence(int) ; count := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( var ans : int ; ans := 0 ; var coun : int ; coun := 0 ; var j : int ; j := 1 ; while j <= m do ( ( if (mat[i+1][j+1] = 1) then ( coun := coun+(1) ) else ( coun := 0 ) ; ans := Set{ans, coun}->max() ) ; j := j + 1 ) ; count[i+1] := ans ) ; i := i + 1 ) ; while (q > 0) do ( q := q - 1 ; skip ; ( var r : int ; r := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if (mat[r+1][c+1] = 1) then mat[r+1][c+1] := 0 else mat[r+1][c+1] := 1 ; ; var coun : int ; coun := 0 ; var ans : int ; ans := 0 ; var ncount : Sequence(int) ; ncount := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= m do ( ( if (mat[r+1][i+1] = 1) then ( coun := coun+(1) ) else ( coun := 0 ) ; ans := Set{coun, ans}->max() ) ; i := i + 1 ) ; count[r+1] := ans ; var i : int ; i := 0 ; while i <= n do ( ( ncount[i+1] := count[i+1] ) ; i := i + 1 ) ; ncount := ncount->sort() ; OclFile["System.out"].println(ncount[n+1]) ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] c=new int[n]; int[] s=new int[n]; int[] f=new int[n]; for(int i=0 ; itoInteger() ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; var f : Sequence(int) ; f := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( ( c[i+1] := sc.getCurrent()->toInteger() ; s[i+1] := sc.getCurrent()->toInteger() ; f[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; s[n - 1+1] := 2147483647 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; a[n - 1+1] := 0 ; var i : int ; i := 0 ; while i < n do ( ( var t : int ; t := 0 ; var j : int ; j := i ; while j < n - 1 do ( ( if (t <= s[j+1]) then ( t := s[j+1] + c[j+1] ) else ( if (t mod f[j+1] = 0) then t := t+(c[j+1]) ; else t := t+(f[j+1] - (t mod f[j+1]) + c[j+1]) ; ) ) ; j := j + 1 ) ; a[i+1] := t ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(a[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner stdin=new Scanner(System.in); int inN=stdin.nextInt(); int[] inC=new int[inN-1]; int[] inS=new int[inN-1]; int[] inF=new int[inN-1]; for(int i=0 ; i<(inN-1); i++){ inC[i]=stdin.nextInt(); inS[i]=stdin.nextInt(); inF[i]=stdin.nextInt(); } for(int i=0 ; i0){ time+=(inF[station]-(time % inF[station])); } time+=inC[station]; } System.out.println(time); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdin : OclFile ; stdin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var inN : int ; inN := stdin.getCurrent()->toInteger() ; var inC : Sequence(int) ; inC := Integer.subrange(1,inN - 1)->collect(0) ; var inS : Sequence(int) ; inS := Integer.subrange(1,inN - 1)->collect(0) ; var inF : Sequence(int) ; inF := Integer.subrange(1,inN - 1)->collect(0) ; var i : int ; i := 0 ; while i < (inN - 1) do ( ( inC[i+1] := stdin.getCurrent()->toInteger() ; inS[i+1] := stdin.getCurrent()->toInteger() ; inF[i+1] := stdin.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < inN do ( ( var time : int ; time := 0 ; var station : int ; station := i ; while station < (inN - 1) do ( ( if (time <= inS[station+1]) then ( time := inS[station+1] ) else if ((time mod inF[station+1]) > 0) then ( time := time+((inF[station+1] - (time mod inF[station+1]))) ) else skip ; ; time := time+(inC[station+1]) ) ; station := station + 1 ) ; OclFile["System.out"].println(time) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader r=new BufferedReader(new InputStreamReader(System.in),1); Integer n=Integer.parseInt(r.readLine()); int[] c=new int[555]; int[] s=new int[555]; int[] f=new int[555]; int[] a=new int[555]; int goal=n ; for(int i=1 ; itoInteger() ; var c : Sequence(int) ; c := Integer.subrange(1,555)->collect(0) ; var s : Sequence(int) ; s := Integer.subrange(1,555)->collect(0) ; var f : Sequence(int) ; f := Integer.subrange(1,555)->collect(0) ; var a : Sequence(int) ; a := Integer.subrange(1,555)->collect(0) ; var goal : int ; goal := n ; var i : int ; i := 1 ; while i < n do ( ( var z : Sequence(String) ; z := r.readLine()->split("[\\s]+") ; c[i+1] := (z[0+1])->toInteger() ; s[i+1] := (z[1+1])->toInteger() ; f[i+1] := (z[2+1])->toInteger() ) ; i := i + 1 ) ; var start : int ; start := 1 ; while start <= goal do ( ( a[start+1] := 0 ; var now : int ; now := 0 ; var pos : int ; pos := start ; while pos < goal do ( ( if (now < s[pos+1]) then ( now := s[pos+1] + c[pos+1] ) else if (now mod f[pos+1] = 0) then ( now := now+(c[pos+1]) ) else ( now := now+(f[pos+1] - (now mod f[pos+1]) + c[pos+1]) ) ; ) ; pos := pos + 1 ) ; a[start+1] := now ) ; start := start + 1 ) ; var start : int ; start := 1 ; while start <= goal do ( ( OclFile["System.out"].println(a[start+1]) ) ; start := start + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long[][] dig=new long[N-1][3]; int C=0 ; int S=0 ; int F=0 ; long unko=0 ; for(int i=0 ; itoInteger() ; var dig : Sequence(Sequence(long)) ; dig := Integer.subrange(1,N - 1)->collect(Integer.subrange(1,3)->collect(0)) ; var C : int ; C := 0 ; var S : int ; S := 0 ; var F : int ; F := 0 ; var unko : long ; unko := 0 ; var i : int ; i := 0 ; while i < N - 1 do ( ( var j : int ; j := 0 ; while j < 3 do ( ( dig[i+1][j+1] := sc.getCurrent()->toLong() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( unko := 0 ; var j : int ; j := i ; while j < N - 1 do ( ( if (j = i) then ( unko := unko+(dig[j+1][1+1]) ) else skip ; if (unko < dig[j+1][1+1]) then ( unko := dig[j+1][1+1] ) else skip ; unko := (unko + dig[j+1][2+1] - 1) / dig[j+1][2+1] * dig[j+1][2+1] ; unko := unko+(dig[j+1][0+1]) ) ; j := j + 1 ) ; OclFile["System.out"].println(unko) ) ; i := i + 1 ) ; OclFile["System.out"].println("0") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in); ){ solve(sc); } } public static void solve(Scanner sc){ int n=sc.nextInt(); int[] arrivalTime=new int[n]; for(int i=0 ; itoInteger() ; var arrivalTime : Sequence(int) ; arrivalTime := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var spentTime : int ; spentTime := sc.getCurrent()->toInteger() ; var startTime : int ; startTime := sc.getCurrent()->toInteger() ; var frequentTime : int ; frequentTime := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j <= i do ( ( if (arrivalTime[j+1] < startTime) then ( arrivalTime[j+1] := startTime ) else skip ; if (arrivalTime[j+1] mod frequentTime /= 0) then ( arrivalTime[j+1] := arrivalTime[j+1]+(frequentTime - (arrivalTime[j+1] mod frequentTime)) ) else skip ; arrivalTime[j+1] := arrivalTime[j+1]+(spentTime) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(arrivalTime[i+1]) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Arrays ; public final class p104 implements EulerSolution { public static void main(String[] args){ System.out.println(new p104().run()); } public String run(){ int i=0 ; int a=0 ; int b=1 ; while(! isFound(i,a)){ int c=(a+b)% 1000000000 ; a=b ; b=c ; i++; } return Integer.toString(i); } private static boolean isFound(int n,int fibMod){ if(! isPandigital(Integer.toString(fibMod)))return false ; BigInteger fib=fibonacci(n)[0]; if(fib.mod(BigInteger.valueOf(1000000000)).intValue()!=fibMod)throw new AssertionError(); return isPandigital(leading9Digits(fib)); } private static String leading9Digits(BigInteger x){ int log10=(x.bitLength()-1)*3/10 ; x=x.divide(BigInteger.TEN.pow(Math.max(log10+1-9,0))); return x.toString().substring(0,9); } private static boolean isPandigital(String s){ if(s.length()!=9)return false ; char[] temp=s.toCharArray(); Arrays.sort(temp); return new String(temp).equals("123456789"); } private static BigInteger[] fibonacci(int n){ if(n<0)throw new IllegalArgumentException(); else if(n==0)return new BigInteger[] { BigInteger.ZERO,BigInteger.ONE }; else { BigInteger[] ab=fibonacci(n/2); BigInteger a=ab[0]; BigInteger b=ab[1]; BigInteger c=a.multiply(b.shiftLeft(1).subtract(a)); BigInteger d=a.multiply(a).add(b.multiply(b)); if(n % 2==0)return new BigInteger[] { c,d }; else return new BigInteger[] { d,c.add(d)}; } } } ------------------------------------------------------------ OCL File: --------- class p104 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p104.newp104().run()) ); operation run() : String pre: true post: true activity: ( var i : int ; i := 0 ; var a : int ; a := 0 ; var b : int ; b := 1 ; while (not(isFound(i, a))) do ( var c : int ; c := (a + b) mod 1000000000 ; a := b ; b := c ; i := i + 1 ) ; return ((i) + "") ); static operation isFound( n : int, fibMod : int) : boolean pre: true post: true activity: ( if (not(isPandigital(((fibMod) + "")))) then return false else skip ; var fib : long ; fib := fibonacci(n)[0+1] ; if (fib.mod((1000000000 + "")->toLong())->oclAsType(int) /= fibMod) then error AssertionException() ; else skip ; return isPandigital(leading9Digits(fib)) ); static operation leading9Digits( x : long) : String pre: true post: true activity: ( var log10 : int ; log10 := (x.bitLength() - 1) * 3 / 10 ; x := x.divide(10.pow(Set{log10 + 1 - 9, 0}->max())) ; return x+"".subrange(0+1,9) ); static operation isPandigital( s : String) : boolean pre: true post: true activity: ( if (s->size() /= 9) then return false else skip ; var temp : Sequence(String) ; temp := s->characters() ; temp := temp->sort() ; return StringLib.newString(temp) = "123456789" ); static operation fibonacci( n : int) : Sequence(long) pre: true post: true activity: ( if (n < 0) then error IllegalArgumentException.newIllegalArgumentException() ; else if (n = 0) then return Sequence{0,1} else ( var ab : Sequence(long) ; ab := fibonacci(n / 2) ; var a : long ; a := ab[0+1] ; var b : long ; b := ab[1+1] ; var c : long ; c := a.multiply(b.shiftLeft(1).subtract(a)) ; var d : long ; d := a.multiply(a)->excludes(b.multiply(b)) ; if (n mod 2 = 0) then return Sequence{c,d} else return Sequence{d,c->excludes(d)} ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int count_setbits(int N){ int cnt=0 ; while(N>0){ cnt+=(N & 1); N=N>>1 ; } return cnt ; } static int countMultiples(int n){ int multiple[]={ 2,3,5 }; int count=0,mask=(int)Math.pow(2,3); for(int i=1 ; i0)prod=prod*multiple[j]; } if(count_setbits(i)% 2==1)count=count+n/prod ; else count=count-n/prod ; } return count ; } public static void main(String[] args){ int n=10 ; System.out.println(countMultiples(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count_setbits( N : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; while (N > 0) do ( cnt := cnt+((N & 1)) ; N := (N/(2->pow(1)))->oclAsType(long) ) ; return cnt ); static operation countMultiples( n : int) : int pre: true post: true activity: ( var multiple : Sequence(int) ; multiple := Sequence{2,3,5} ; var count : int ; count := 0 ; var mask : int ; mask := 2->pow(3)->oclAsType(int) ; var i : int ; i := 1 ; while i < mask do ( ( var prod : int ; prod := 1 ; var j : int ; j := 0 ; while j < 3 do ( ( if ((MathLib.bitwiseAnd(i,(1*(2->pow(j)))->oclAsType(long))) > 0) then prod := prod * multiple[j+1] ; else skip ) ; j := j + 1 ) ; if (count_setbits(i) mod 2 = 1) then count := count + n / prod ; else count := count - n / prod ; ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println(countMultiples(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.Math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int AG ; AG=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < AG do ( ( var K : int ; K := sc.getCurrent()->toInteger() ; var L : int ; L := sc.getCurrent()->toInteger() ; if (K mod L = 0) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static double areaCuboid(double l,double h,double w){ return(l*h*w); } static double surfaceAreaCuboid(double l,double h,double w){ return(2*l*w+2*w*h+2*l*h); } public static void main(String[] args){ double l=1 ; double h=5 ; double w=7 ; System.out.println("Area="+areaCuboid(l,h,w)); System.out.println("Total Surface Area="+surfaceAreaCuboid(l,h,w)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation areaCuboid( l : double, h : double, w : double) : double pre: true post: true activity: ( return (l * h * w) ); static operation surfaceAreaCuboid( l : double, h : double, w : double) : double pre: true post: true activity: ( return (2 * l * w + 2 * w * h + 2 * l * h) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : double ; l := 1 ; var h : double ; h := 5 ; var w : double ; w := 7 ; OclFile["System.out"].println("Area=" + areaCuboid(l, h, w)) ; OclFile["System.out"].println("Total Surface Area=" + surfaceAreaCuboid(l, h, w)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isEqualBlock(int n){ int first_bit=n % 2 ; int first_count=1 ; n=n/2 ; while(n % 2==first_bit && n>0){ n=n/2 ; first_count++; } if(n==0)return false ; while(n>0){ first_bit=n % 2 ; int curr_count=1 ; n=n/2 ; while(n % 2==first_bit){ n=n/2 ; curr_count++; } if(curr_count!=first_count)return false ; } return true ; } public static void main(String[] args){ int n=51 ; if(isEqualBlock(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isEqualBlock( n : int) : boolean pre: true post: true activity: ( var first_bit : int ; first_bit := n mod 2 ; var first_count : int ; first_count := 1 ; n := n / 2 ; while (n mod 2 = first_bit & n > 0) do ( n := n / 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 ; curr_count := 1 ; n := n / 2 ; while (n mod 2 = first_bit) do ( n := n / 2 ; curr_count := curr_count + 1 ) ; if (curr_count /= first_count) then return false else skip ; ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 51 ; if (isEqualBlock(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.util.*; class GFG { static double countNumbers(int N){ return(Math.pow(10,N)-1)-(Math.pow(10,N)-Math.pow(8,N))/2 ; } static public void main(String args[]){ int n=2 ; System.out.println(countNumbers(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumbers( N : int) : double pre: true post: true activity: ( return (10->pow(N) - 1) - (10->pow(N) - 8->pow(N)) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; OclFile["System.out"].println(countNumbers(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countNumbers(int N){ return(int)(Math.pow(10,N)-Math.pow(8,N))/2 ; } public static void main(String[] args){ int n=5 ; System.out.println(countNumbers(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumbers( N : int) : int pre: true post: true activity: ( return (10->pow(N) - 8->pow(N))->oclAsType(int) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(countNumbers(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPalindrome(String str,int low,int high){ while(lowat(low+1) /= str->at(high+1)) then return false else skip ; low := low + 1 ; high := high - 1 ) ; return true ); static operation possiblePalinByRemovingOneChar( str : String) : int pre: true post: true activity: ( var low : int ; low := 0 ; var high : int ; high := str->size() - 1 ; while (low < high) do ( if (str->at(low+1) = str->at(high+1)) then ( low := low + 1 ; high := high - 1 ) else ( if (isPalindrome(str, low + 1, high)) then return low else skip ; if (isPalindrome(str, low, high - 1)) then return high else skip ; return -1 ) ) ; return -2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "abecbea" ; var idx : int ; idx := possiblePalinByRemovingOneChar(str) ; if (idx = -1) then OclFile["System.out"].println("Not Possible") ; else if (idx = -2) then OclFile["System.out"].println("Possible without " + "removing any character") else OclFile["System.out"].println("Possible by removing" + " character at index " + idx) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countPairsWithDiffK(int arr[],int n,int k){ int count=0 ; Arrays.sort(arr); int l=0 ; int r=0 ; while(rk)l++; else r++; } return count ; } public static void main(String[] args){ int arr[]={ 1,5,3,4,2 }; int n=arr.length ; int k=3 ; System.out.println("Count of pairs with given diff is "+countPairsWithDiffK(arr,n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countPairsWithDiffK( arr : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; arr := arr->sort() ; var l : int ; l := 0 ; var r : int ; r := 0 ; while (r < n) 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] > k) then l := l + 1 else r := r + 1 ; ; ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,5,3,4,2} ; var n : int ; n := arr->size() ; var k : int ; k := 3 ; OclFile["System.out"].println("Count of pairs with given diff is " + countPairsWithDiffK(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class AAA { boolean getsum1(int n,int k){ TreeSety=new TreeSet(); while(true){ if(y.contains(n))return false ; y.add(n); int res=0 ; while(n!=0){ res+=(n % k)*(n % k); n/=k ; } n=res ; if(n==1)return true ; } } TreeMapresult=new TreeMap(); void solve()throws IOException { Scanner in=new Scanner(new FileInputStream("input.txt")); PrintWriter out=new PrintWriter(new FileOutputStream("output.txt")); String s ; int n=in.nextInt(); in.nextLine(); for(int t=1 ; t<=n ; ++t){ s=in.nextLine(); if(s==null)break ; ArrayLista=new ArrayList(); Scanner in2=new Scanner(s); while(in2.hasNextInt())a.add(in2.nextInt()); int mask=0 ; for(int i=0 ; i=0 ; --i)if(! getsum1(tr,a.get(i))){ good=false ; break ; } if(good)break ; tr++; } result.put(mask,tr); } out.println("Case #"+t+": "+tr); out.flush(); } out.close(); } public static void main(String[] args)throws IOException { AAA a=new AAA(); a.solve(); } } ------------------------------------------------------------ OCL File: --------- class AAA { operation getsum1( n : int, k : int) : boolean pre: true post: true activity: ( var y : Set(int) ; y := Set{} ; while (true) do ( if (y->includes(n)) then return false else skip ; y := y->including(n) ; var res : int ; res := 0 ; while (n /= 0) do ( res := res+((n mod k) * (n mod k)) ; n := n/(k) ) ; n := res ; if (n = 1) then return true else skip ; ) ); attribute result : Map(int,int) := Map{}; operation solve() : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) ; var s : String ; var n : int ; n := in.getCurrent()->toInteger() ; skip ; var t : int ; t := 1 ; while t <= n do ( ( s := in.nextLine() ; if (s = null) then break else skip ; var a : Sequence(int) ; a := Sequence{} ; var in2 : OclFile ; in2 := OclFile.newOclFile_Read(OclFile.newOclFile(s)) ; while (in2.hasNextInt()) do a := a->including(in2.getCurrent()->toInteger()) ; ; var mask : int ; mask := 0 ; var i : int ; i := 0 ; while i < a->size() do ( mask := mask+((1*(2->pow(a->at(i+1))))->oclAsType(long)) ; ; i := i + 1 ) ; if (a->size() = 9) then result := result->union(Map{mask |-> 11814485}) ; else skip ; var tr : int ; tr := 2 ; if (result->keys()->includes(mask)) then ( tr := result->at(mask) ) else ( while (true) do ( var good : boolean ; good := true ; var i : int ; i := a->size() - 1 ; while i >= 0 do ( if (not(getsum1(tr, a->at(i+1)))) then ( good := false ; break ) else skip ; ; i := i - 1 ) ; if (good) then break else skip ; tr := tr + 1 ) ; result := result->union(Map{mask |-> tr}) ) ; skip ; skip ; ) ; t := t + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : AAA ; a := AAA.newAAA() ; a.solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { static int N,Q ; static Node[] ns ; static boolean type[]; static int no[]; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true){ String input[]=br.readLine().split("+"); N=new Integer(input[0]); Q=new Integer(input[1]); if(N==0 & Q==0)break ; ns=new Node[N+1]; type=new boolean[Q]; no=new int[Q]; ns[1]=new Node(0); ns[1] .marked=true ; for(int i=2 ; i<=N ; i++){ ns[i]=new Node(new Integer(br.readLine())); } for(int i=0 ; isplit("+") ; N := ("" + (input[0+1]))->toInteger() ; Q := ("" + (input[1+1]))->toInteger() ; if (N = 0 & Q = 0) then break else skip ; ns := Integer.subrange(1,N + 1)->collect(null) ; type := Integer.subrange(1,Q)->collect(false) ; no := Integer.subrange(1,Q)->collect(0) ; ns[1+1] := Node.newNode(0) ; ns[1+1].marked := true ; var i : int ; i := 2 ; while i <= N do ( ( ns[i+1] := Node.newNode(("" + (br.readLine()))->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < Q do ( ( input := br.readLine()->split("+") ; if (input[0+1] = "Q") then ( type[i+1] := true ) else ( type[i+1] := false ) ; no[i+1] := ("" + (input[1+1]))->toInteger() ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < Q do ( ( if (type[i+1]) then ( sum := sum+(findmark(no[i+1])) ) else ( ns[no[i+1]+1].marked := true ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ); static operation findmark( no : int) : int pre: true post: true activity: ( while (true) do ( if (ns[no+1].marked) then return no else no := ns[no+1].par ; ) ); } class Node { attribute par : int; attribute marked : boolean := false; static operation newNode( par : int) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(par); return self ); operation initialise( par : int) : void pre: true post: true activity: ( self.par := par ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int find(int cur_v,int cur_t,int[] time,int[] parent){ if(time[cur_v]qt=new ArrayList(); Listvt=new ArrayList(); for(int i=2 ; i<=n ; i++){ int v=sc.nextInt(); parent[i]=v ; } parent[1]=1 ; long sum=0 ; for(int i=1 ; i<=q ; i++){ String s=sc.next(); int v=sc.nextInt(); if(s.equals("M"))time[v]=Math.min(time[v],i); else { qt.add(i); vt.add(v); } } int q_ct=qt.size(); for(int i=q_ct-1 ; i>=0 ; i--){ int cur_v=vt.get(i); int cur_t=qt.get(i); sum+=find(cur_v,cur_t,time,parent); } System.out.println(sum); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation find( cur_v : int, cur_t : int, time : Sequence(int), parent : Sequence(int)) : int pre: true post: true activity: ( if (time[cur_v+1] < cur_t) then return cur_v else skip ; if (parent[cur_v+1] = cur_v) then return cur_v else skip ; return parent[cur_v+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; if (n = 0 & q = 0) then return else skip ; var parent : Sequence(int) ; parent := Integer.subrange(1,n + 1)->collect(0) ; var time : Sequence(int) ; time := Integer.subrange(1,n + 1)->collect(0) ; time := time->collect(2147483647) ; var qt : Sequence(int) ; qt := Sequence{} ; var vt : Sequence(int) ; vt := Sequence{} ; var i : int ; i := 2 ; while i <= n do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; parent[i+1] := v ) ; i := i + 1 ) ; parent[1+1] := 1 ; var sum : long ; sum := 0 ; var i : int ; i := 1 ; while i <= q do ( ( var s : String ; s := sc.getCurrent() ; var v : int ; v := sc.getCurrent()->toInteger() ; if (s = "M") then time[v+1] := Set{time[v+1], i}->min() ; else ( qt := qt->including(i) ; vt := vt->including(v) ) ) ; i := i + 1 ) ; var q_ct : int ; q_ct := qt->size() ; var i : int ; i := q_ct - 1 ; while i >= 0 do ( ( var cur_v : int ; cur_v := vt->at(i+1) ; var cur_t : int ; cur_t := qt->at(i+1) ; sum := sum+(find(cur_v, cur_t, time, parent)) ) ; i := i - 1 ) ; OclFile["System.out"].println(sum) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Problem1 { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); int t=Integer.parseInt(f.readLine()); while(t-->0){ StringTokenizer st=new StringTokenizer(f.readLine()); long a=Long.parseLong(st.nextToken()); long b=Long.parseLong(st.nextToken()); long diff=Math.abs(b-a); if(Math.min(a,b)b){ a-=2*diff ; b-=diff ; } else { a-=diff ; b-=2*diff ; } if(a % 3==0 && b % 3==0){ out.println("YES"); } else { out.println("NO"); } } out.close(); } } ------------------------------------------------------------ OCL File: --------- class Problem1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var f : OclFile ; f := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var t : int ; t := (f.readLine())->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var st : OclIterator ; st := OclIterator.newOclIterator_String(f.readLine()) ; var a : long ; a := (st.next())->toLong() ; var b : long ; b := (st.next())->toLong() ; var diff : long ; diff := if b - a < 0 then -(b - a) else b - a endif ; if (Set{a, b}->min() < diff) then ( skip ; continue ) else skip ; if (a > b) then ( a := a-(2 * diff) ; b := b-(diff) ) else ( a := a-(diff) ; b := b-(2 * diff) ) ; if (a mod 3 = 0 & b mod 3 = 0) then ( skip ) else ( skip ) ; ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countCubes(int a,int b){ int cnt=0 ; for(int i=a ; i<=b ; i++)for(int j=1 ; j*j*j<=i ; j++)if(j*j*j==i)cnt++; return cnt ; } public static void main(String[] args){ int a=7,b=30 ; System.out.print("Count of Cubes is "+countCubes(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countCubes( a : int, b : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := a ; while i <= b do ( var j : int ; j := 1 ; while j * j * j <= i do ( if (j * j * j = i) then cnt := cnt + 1 ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 7 ; var b : int ; b := 30 ; OclFile["System.out"].print("Count of Cubes is " + countCubes(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; Main main=new Main(); while((line=br.readLine())!=null && ! line.isEmpty()){ int N,Q ; N=parseInt(line.substring(0,line.indexOf(' '))); Q=parseInt(line.substring(line.indexOf(' ')+1)); if((N | Q)==0)break ; Node[] nodes=new Node[N+1]; for(int i=0 ; iisEmpty())) do ( skip ; ( var N : int ; var Q : int ; N := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; Q := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; if ((MathLib.bitwiseOr(N,Q)) = 0) then break else skip ; var nodes : Sequence(Node) ; nodes := Integer.subrange(1,N + 1)->collect(null) ; var i : int ; i := 0 ; while i < nodes->size() do ( ( nodes[i+1] := (main).newNode(i) ) ; i := i + 1 ) ; nodes[1+1].p := nodes[0+1] ; var i : int ; i := 2 ; while i <= N do ( ( var p : int ; p := parseInt(br.readLine()) ; nodes[i+1].p := nodes[p+1] ) ; i := i + 1 ) ; nodes[1+1].marked := true ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < Q do ( ( line := br.readLine() ; var o : String ; o := line->at(0+1) ; var v : int ; v := parseInt(line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1)) ; if (o = 'M') then ( nodes[v+1].marked := true ) else ( var node : Node ; node := nodes[v+1] ; while (node.id /= 0 & not(node.marked)) do ( node := node.p ) ; sum := sum+(node.id) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; line := br.readLine() ; ) ; ); class Node { attribute id : int; attribute marked : boolean := false; attribute p : Node; static operation newNode( id : int) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(id); return self ); operation initialise( id : int) : void pre: true post: true activity: ( self.id := id ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); int q=sc.nextInt(); if((n | q)==0)break ; UnionFind uf=new UnionFind(n); if(n!=1){ for(int i=2 ; i<=n ; i++){ int p=sc.nextInt(); uf.par[i]=p ; } } long ans=0 ; for(int i=0 ; itoInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,q)) = 0) then break else skip ; var uf : UnionFind ; uf := UnionFind.newUnionFind(n) ; if (n /= 1) then ( var i : int ; i := 2 ; while i <= n do ( ( var p : int ; p := sc.getCurrent()->toInteger() ; uf.par[i+1] := p ) ; i := i + 1 ) ) else skip ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < q do ( ( var t : String ; t := sc.getCurrent() ; var v : int ; v := sc.getCurrent()->toInteger() ; if (t = "M") then uf.mark[v+1] := true ; else ans := ans+(uf.find(v)) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } class UnionFind { attribute par : Sequence(int); attribute mark : Sequence(boolean); static operation newUnionFind( n : int) : UnionFind pre: true post: true activity: ( var self : UnionFind ; self := createUnionFind(); self.initialise(n); return self ); operation initialise( n : int) : void pre: true post: true activity: ( par := Integer.subrange(1,n + 1)->collect(0) ; mark := Integer.subrange(1,n + 1)->collect(false) ; mark[0+1] := true ; mark[1+1] := true ; par[1+1] := 1 ; ); operation find( x : int) : int pre: true post: true activity: ( while (true) do ( if (mark[x+1]) then ( return x ) else ( x := par[x+1] ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true){ String input=br.readLine(); if(input==null){ break ; } String[] tmpArray=input.split(" "); int n=Integer.parseInt(tmpArray[0]); int q=Integer.parseInt(tmpArray[1]); if(n==0 && q==0){ break ; } Node[] nodes=new Node[n+1]; nodes[0]=new Node(0,-1); nodes[0] .marked=true ; nodes[1]=new Node(1,0); nodes[1] .marked=true ; for(int i=2 ; i<=n ; i++){ int num=Integer.parseInt(br.readLine()); nodes[i]=new Node(i,num); } long sum=0 ; for(int i=0 ; isplit(" ") ; var n : int ; n := (tmpArray[0+1])->toInteger() ; var q : int ; q := (tmpArray[1+1])->toInteger() ; if (n = 0 & q = 0) then ( break ) else skip ; var nodes : Sequence(Node) ; nodes := Integer.subrange(1,n + 1)->collect(null) ; nodes[0+1] := Node.newNode(0, -1) ; nodes[0+1].marked := true ; nodes[1+1] := Node.newNode(1, 0) ; nodes[1+1].marked := true ; var i : int ; i := 2 ; while i <= n do ( ( var num : int ; num := (br.readLine())->toInteger() ; nodes[i+1] := Node.newNode(i, num) ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < q do ( ( tmpArray := br.readLine()->split(" ") ; var tmp : int ; tmp := (tmpArray[1+1])->toInteger() ; if (tmpArray[0+1] = "M") then ( nodes[tmp+1].marked := true ) else ( sum := sum+(nearest(nodes, tmp)) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ); static operation nearest( nodes : Sequence(Node), id : int) : int pre: true post: true activity: ( while (true) do ( if (nodes[id+1].marked) then ( return id ) else skip ; id := nodes[id+1].parent ) ); } class Node { attribute id : int; attribute parent : int; attribute marked : boolean := false; static operation newNode( id : int, parent : int) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(id, parent); return self ); operation initialise( id : int, parent : int) : void pre: true post: true activity: ( self.id := id ; self.parent := parent ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int factorial(int n){ int f=1 ; for(int i=2 ; i<=n ; i++)f*=i ; return f ; } static void series(int A,int X,int n){ int nFact=factorial(n); for(int i=0 ; ipow(n - i)->oclAsType(int) ; var xPow : int ; xPow := X->pow(i)->oclAsType(int) ; OclFile["System.out"].print((nFact * aPow * xPow) / (niFact * iFact) + " ") ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 3 ; var X : int ; X := 4 ; var n : int ; n := 5 ; execute series(A, X, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int floorSqrt(int x){ if(x==0 || x==1)return x ; int i=1,result=1 ; while(result<=x){ i++; result=i*i ; } return i-1 ; } public static void main(String[] args){ int x=11 ; System.out.print(floorSqrt(x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation floorSqrt( x : int) : int pre: true post: true activity: ( if (x = 0 or x = 1) then return x else skip ; var i : int ; i := 1 ; var result : int ; result := 1 ; while (result <= x) do ( i := i + 1 ; result := i * i ) ; return i - 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 11 ; OclFile["System.out"].print(floorSqrt(x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int a=scan.nextInt(); int b=scan.nextInt(); int c=scan.nextInt(); int d=scan.nextInt(); if(a==b && c==d || a==c && b==d || a==d && c==b){ System.out.println("yes"); } else { System.out.println("no"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := scan.getCurrent()->toInteger() ; var b : int ; b := scan.getCurrent()->toInteger() ; var c : int ; c := scan.getCurrent()->toInteger() ; var d : int ; d := scan.getCurrent()->toInteger() ; if (a = b & c = d or a = c & b = d or a = d & c = b) then ( OclFile["System.out"].println("yes") ) else ( OclFile["System.out"].println("no") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { void solve(){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); if(a==b && c==d || a==c && b==d || a==d && b==c)System.out.println("yes"); else System.out.println("no"); } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; if (a = b & c = d or a = c & b = d or a = d & b = c) then OclFile["System.out"].println("yes") else OclFile["System.out"].println("no") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; StringTokenizer st=new StringTokenizer(br.readLine()); int[] sides=new int[4]; int total=0 ; for(int i=0 ; i<4 ; i++){ sides[i]=parseInt(st.nextToken()); total+=sides[i]; } Arrays.sort(sides); if(sides[0]==sides[1] && sides[2]==sides[3]){ System.out.println("yes"); } else { System.out.println("no"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var sides : Sequence(int) ; sides := Integer.subrange(1,4)->collect(0) ; var total : int ; total := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( sides[i+1] := (st.next() + "")->toInteger() ; total := total+(sides[i+1]) ) ; i := i + 1 ) ; sides := sides->sort() ; if (sides[0+1] = sides[1+1] & sides[2+1] = sides[3+1]) then ( OclFile["System.out"].println("yes") ) else ( OclFile["System.out"].println("no") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Mapm=new HashMap<>(); for(int i=0 ; i<4 ; i++){ int n=sc.nextInt(); if(m.containsKey(n)){ m.put(n,m.get(n)+1); } else { m.put(n,1); } } int c=0 ; for(Map.Entrye : m.entrySet()){ if(e.getValue()==4){ c=2 ; } if(e.getValue()==2){ c++; } } System.out.println(c==2 ? "yes" : "no"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var m : Map(int,int) ; m := Map{} ; var i : int ; i := 0 ; while i < 4 do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (m->keys()->includes(n)) then ( m := m->union(Map{n |-> m->at(n) + 1}) ) else ( m := m->union(Map{n |-> 1}) ) ) ; i := i + 1 ) ; var c : int ; c := 0 ; for (e : m->asSet()) do ( ( if (e.getValue() = 4) then ( c := 2 ) else skip ; if (e.getValue() = 2) then ( c := c + 1 ) else skip ) ) ; OclFile["System.out"].println(if c = 2 then "yes" else "no" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(is); String str ; if((str=br.readLine())!=null){ String[] sp=str.split(" "); int a=Integer.parseInt(sp[0]); int b=Integer.parseInt(sp[1]); int c=Integer.parseInt(sp[2]); int d=Integer.parseInt(sp[3]); if(a==b && c==d){ System.out.println("yes"); } else if(a==c && b==d){ System.out.println("yes"); } else if(a==d && b==c){ System.out.println("yes"); } else { System.out.println("no"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var is : OclFile ; is := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(is) ; var str : String ; if ((str) /= null) then ( var sp : Sequence(String) ; sp := str->split(" ") ; var a : int ; a := (sp[0+1])->toInteger() ; var b : int ; b := (sp[1+1])->toInteger() ; var c : int ; c := (sp[2+1])->toInteger() ; var d : int ; d := (sp[3+1])->toInteger() ; if (a = b & c = d) then ( OclFile["System.out"].println("yes") ) else if (a = c & b = d) then ( OclFile["System.out"].println("yes") ) else if (a = d & b = c) then ( OclFile["System.out"].println("yes") ) else ( OclFile["System.out"].println("no") ) ; ; ; ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B250 { public static void main(String[] args){ Scanner in=new Scanner(System.in); StringBuilder out=new StringBuilder(); int T=in.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var s : String ; s := in.getCurrent() ; var idx : int ; idx := s->indexOf("::")-1 ; if (idx = -1) then ( var parts : Sequence(String) ; parts := s->split(":") ; var i : int ; i := 0 ; while i < parts->size() do ( ( if (i /= 0) then ( out := out + StringLib.newString(':') ) else skip ; out := out + StringLib.newString(process(parts[i+1])) ) ; i := i + 1 ) ) else ( var start : String ; start := s.subrange(0+1,idx) ; var end : String ; end := s.subrange(idx + 2+1,idx + 2) ; var parts1 : Sequence(String) ; parts1 := if start->isEmpty() then Integer.subrange(1,0)->collect(null) else start->split(":") endif ; var parts2 : Sequence(String) ; parts2 := if end->isEmpty() then Integer.subrange(1,0)->collect(null) else end->split(":") endif ; var first : boolean ; first := true ; for (part : parts1) do ( ( if (not(first)) then ( out := out + StringLib.newString(':') ) else skip ; first := false ; out := out + StringLib.newString(process(part)) ) ) ; var i : int ; i := parts1->size() + parts2->size() ; while i < 8 do ( ( if (not(first)) then ( out := out + StringLib.newString(':') ) else skip ; first := false ; out := out + StringLib.newString("0000") ) ; i := i + 1 ) ; for (part : parts2) do ( ( if (not(first)) then ( out := out + StringLib.newString(':') ) else skip ; first := false ; out := out + StringLib.newString(process(part)) ) ) ; ) ; out := out + StringLib.newString(' ') ) ; t := t + 1 ) ; OclFile["System.out"].print(out) ; ); static operation process( part : String) : String pre: true post: true activity: ( while (part->size() < 4) do ( part := '0' + part ) ; return part ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] oddList=new int[100001]; int[] evenList=new int[100001]; for(int i=1 ; i=2)secondmaxOdd=maxOdd ; if(countEven>=2)secondmaxEven=maxEven ; for(int i=1 ; i<100001 ; i++){ if(oddList[i]==maxOdd)oddnum=i ; if(evenList[i]==maxEven)evennum=i ; } if(oddnum==evennum){ if(maxOdd>maxEven){ maxEven=secondmaxEven ; } else if(maxOddtoInteger() ; var oddList : Sequence(int) ; oddList := Integer.subrange(1,100001)->collect(0) ; var evenList : Sequence(int) ; evenList := Integer.subrange(1,100001)->collect(0) ; var i : int ; i := 1 ; while i < n + 1 do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; if (i mod 2 = 1) then oddList[v+1] := oddList[v+1] + 1 ; else skip ; if (i mod 2 = 0) then evenList[v+1] := evenList[v+1] + 1 ; else skip ) ; i := i + 1 ) ; var maxOdd : int ; maxOdd := 0 ; var maxEven : int ; maxEven := 0 ; var secondmaxOdd : int ; secondmaxOdd := 0 ; var secondmaxEven : int ; secondmaxEven := 0 ; var countOdd : int ; countOdd := 0 ; var countEven : int ; countEven := 0 ; var i : int ; i := 1 ; while i < 100001 do ( ( maxOdd := Set{oddList[i+1], maxOdd}->max() ; maxEven := Set{evenList[i+1], maxEven}->max() ) ; i := i + 1 ) ; var oddnum : int ; oddnum := 0 ; var evennum : int ; evennum := 0 ; var i : int ; i := 1 ; while i < 100001 do ( ( if (oddList[i+1] = maxOdd) then ( oddnum := i ; countOdd := countOdd + 1 ) else skip ; if (evenList[i+1] = maxEven) then ( evennum := i ; countEven := countEven + 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < 100001 do ( ( if (oddList[i+1] /= maxOdd) then ( secondmaxOdd := Set{oddList[i+1], secondmaxOdd}->max() ) else skip ; if (evenList[i+1] /= maxEven) then ( secondmaxEven := Set{evenList[i+1], secondmaxEven}->max() ) else skip ) ; i := i + 1 ) ; if (countOdd >= 2) then secondmaxOdd := maxOdd ; else skip ; if (countEven >= 2) then secondmaxEven := maxEven ; else skip ; var i : int ; i := 1 ; while i < 100001 do ( ( if (oddList[i+1] = maxOdd) then oddnum := i ; else skip ; if (evenList[i+1] = maxEven) then evennum := i ; else skip ) ; i := i + 1 ) ; if (oddnum = evennum) then ( if (maxOdd > maxEven) then ( maxEven := secondmaxEven ) else if (maxOdd < maxEven) then ( maxOdd := secondmaxOdd ) else ( maxEven := Set{secondmaxOdd, secondmaxEven}->max() ) ; ) else skip ; var ans : int ; ans := n - maxOdd - maxEven ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int m=sc.nextInt(); while(n!=m && n>0 && m>0){ if(n>m){ int diff=n-m ; if(diff % 2!=0){ diff++; } n-=diff ; m-=diff/2 ; } else if(ntoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; while (n /= m & n > 0 & m > 0) do ( if (n > m) then ( var diff : int ; diff := n - m ; if (diff mod 2 /= 0) then ( diff := diff + 1 ) else skip ; n := n-(diff) ; m := m-(diff / 2) ) else if (n < m) then ( var diff : int ; diff := m - n ; if (diff mod 2 /= 0) then ( diff := diff + 1 ) else skip ; m := m-(diff) ; n := n-(diff / 2) ) else skip ; ) ; if (n = m & n mod 3 = 0) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] a=new int[n+2]; int[] b=new int[n+1]; for(int i=1 ; i<=n+1 ; i++){ a[i]=in.nextInt(); } for(int i=1 ; i<=n ; i++){ b[i]=in.nextInt(); } long beated=0 ; for(int i=1 ; i<=n ; i++){ if(a[i]>=b[i]){ beated+=b[i]; a[i]-=b[i]; b[i]=0 ; } else if(a[i]=b[i]){ beated+=b[i]; a[i+1]-=b[i]; b[i]=0 ; } else if(a[i+1]toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 2)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n + 1 do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( b[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var beated : long ; beated := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (a[i+1] >= b[i+1]) then ( beated := beated+(b[i+1]) ; a[i+1] := a[i+1]-(b[i+1]) ; b[i+1] := 0 ) else if (a[i+1] < b[i+1]) then ( beated := beated+(a[i+1]) ; b[i+1] := b[i+1]-(a[i+1]) ; a[i+1] := 0 ; if (a[i + 1+1] >= b[i+1]) then ( beated := beated+(b[i+1]) ; a[i + 1+1] := a[i + 1+1]-(b[i+1]) ; b[i+1] := 0 ) else if (a[i + 1+1] < b[i+1]) then ( beated := beated+(a[i + 1+1]) ; b[i+1] := b[i+1]-(a[i + 1+1]) ; a[i + 1+1] := 0 ) else skip ; ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(beated) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n+1]; for(int i=0 ; i=0 ; i--){ if(a[i+1]+a[i]toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < b->size() do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; var ans : long ; ans := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (a[i + 1+1] + a[i+1] < b[i+1]) then ( ans := ans+(a[i + 1+1] + a[i+1]) ; a[i+1] := 0 ) else ( ans := ans+(b[i+1]) ; if (a[i + 1+1] < b[i+1]) then ( a[i+1] := a[i+1]-(b[i+1] - a[i + 1+1]) ) else skip ) ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); Long[] A=new Long[N+1]; Long[] B=new Long[N]; for(int i=0 ; i<=N ; i++){ A[i]=sc.nextLong(); } for(int i=0 ; i0){ if(next<=B[i]){ B[i]-=next ; A[i+1]=0L ; } else { A[i+1]-=B[i]; B[i]=0L ; } } count+=current-A[i]+next-A[i+1]; } println(count); } static void println(Object o){ System.out.println(o); } static void print(Object o){ System.out.print(o); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : Sequence(long) ; A := Integer.subrange(1,N + 1)->collect(null) ; var B : Sequence(long) ; B := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i <= N do ( ( A[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( B[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var count : long ; count := 0L ; var i : int ; i := 0 ; while i < N do ( ( var current : long ; current := A[i+1] ; var next : long ; next := A[i + 1+1] ; if (current <= B[i+1]) then ( B[i+1] := B[i+1]-(current) ; A[i+1] := 0L ) else ( A[i+1] := A[i+1]-(B[i+1]) ; B[i+1] := 0L ) ; if (B[i+1] > 0) then ( if (next <= B[i+1]) then ( B[i+1] := B[i+1]-(next) ; A[i + 1+1] := 0L ) else ( A[i + 1+1] := A[i + 1+1]-(B[i+1]) ; B[i+1] := 0L ) ) else skip ; count := count+(current - A[i+1] + next - A[i + 1+1]) ; ) ; i := i + 1 ) ; execute println(count) ; ); static operation println( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o) ); static operation print( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].print(o) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class Main { public static void main(String args[])throws IOException { double n,max=0,i ; Scanner sc=new Scanner(System.in); n=sc.nextDouble(); double a[]=new double[(int)n+1]; double b[]=new double[(int)n]; for(i=0 ; i=0 ; i--){ if(b[(int)i]<=a[(int)i+1]){ max+=b[(int)i]; a[(int)i+1]-=b[(int)i]; b[(int)i]=0 ; } else if(b[(int)i]>a[(int)i+1]){ max+=a[(int)i+1]; b[(int)i]-=a[(int)i+1]; a[(int)i+1]=0 ; if(b[(int)i]<=a[(int)i]){ max+=b[(int)i]; a[(int)i]-=b[(int)i]; b[(int)i]=0 ; } else if(b[(int)i]>a[(int)i]){ max+=a[(int)i]; b[(int)i]-=a[(int)i]; a[(int)i]=0 ; } } } System.out.println((long)max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : double ; var max : double ; max := 0 ; var i : double ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toReal() ; var a : Sequence(double) ; a := Integer.subrange(1,n->oclAsType(int) + 1)->collect(0.0) ; var b : Sequence(double) ; b := Integer.subrange(1,n->oclAsType(int))->collect(0.0) ; i := 0 ; while i < n + 1 do ( ( a[i->oclAsType(int)+1] := sc.getCurrent()->toReal() ) ; i := i + 1 ) ; i := 0 ; while i < n do ( b[i->oclAsType(int)+1] := sc.getCurrent()->toReal() ; ; i := i + 1 ) ; i := n - 1 ; while i >= 0 do ( ( if (b[i->oclAsType(int)+1] <= a[i->oclAsType(int) + 1+1]) then ( max := max+(b[i->oclAsType(int)+1]) ; a[i->oclAsType(int) + 1+1] := a[i->oclAsType(int) + 1+1]-(b[i->oclAsType(int)+1]) ; b[i->oclAsType(int)+1] := 0 ) else if (b[i->oclAsType(int)+1] > a[i->oclAsType(int) + 1+1]) then ( max := max+(a[i->oclAsType(int) + 1+1]) ; b[i->oclAsType(int)+1] := b[i->oclAsType(int)+1]-(a[i->oclAsType(int) + 1+1]) ; a[i->oclAsType(int) + 1+1] := 0 ; if (b[i->oclAsType(int)+1] <= a[i->oclAsType(int)+1]) then ( max := max+(b[i->oclAsType(int)+1]) ; a[i->oclAsType(int)+1] := a[i->oclAsType(int)+1]-(b[i->oclAsType(int)+1]) ; b[i->oclAsType(int)+1] := 0 ) else if (b[i->oclAsType(int)+1] > a[i->oclAsType(int)+1]) then ( max := max+(a[i->oclAsType(int)+1]) ; b[i->oclAsType(int)+1] := b[i->oclAsType(int)+1]-(a[i->oclAsType(int)+1]) ; a[i->oclAsType(int)+1] := 0 ) else skip ; ) else skip ; ) ; i := i - 1 ) ; OclFile["System.out"].println(max->oclAsType(long)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); long[] a=new long[100005]; long[] b=new long[100005]; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,100005)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,100005)->collect(0) ; var i : int ; i := 0 ; while i < n + 1 do ( ( a[i+1] := input.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := input.getCurrent()->toLong() ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] <= b[i+1]) then ( sum := sum+(a[i+1]) ; b[i+1] := b[i+1]-(a[i+1]) ) else ( sum := sum+(b[i+1]) ; b[i+1] := 0 ) ; if (a[i + 1+1] <= b[i+1]) then ( sum := sum+(a[i + 1+1]) ; b[i+1] := b[i+1]-(a[i + 1+1]) ; a[i + 1+1] := 0 ) else ( sum := sum+(b[i+1]) ; a[i + 1+1] := a[i + 1+1]-(b[i+1]) ; b[i+1] := 0 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.stream.IntStream ; import java.util.Arrays ; import java.util.StringTokenizer ; import java.io.IOException ; import java.util.InputMismatchException ; import java.util.BitSet ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskC solver=new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(); int[] a=in.nextIntArray(n); int sum=Arrays.stream(a).sum(); BitSet bitSet=new BitSet(); bitSet.set(sum); for(int i=0 ; isum() ; var bitSet : Sequence(boolean) ; bitSet := MathLib.toBitSequence() ; bitSet := bitSet.setAt(sum+1, true) ; var i : int ; i := 0 ; while i < n do ( ( bitSet := bitSet.or(bitSet->at(a[i+1], sum + 1+1)) ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute in : OclFile; attribute tok : OclIterator; operation nextString() : String pre: true post: true activity: ( while (not(tok.hasNext())) do ( try ( tok := OclIterator.newOclIterator_String_String(in.readLine(), " ") ) catch (e : IOException) do ( error IncorrectElementException() ) ) ; return tok.next() ); operation nextInt() : int pre: true post: true activity: ( return (nextString())->toInteger() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := nextInt() ) ; i := i + 1 ) ; return res ); static operation newInputReader( inputStream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(inputStream); return self ); operation initialise( inputStream : OclFile) : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(inputStream)) ; tok := OclIterator.newOclIterator_String("") ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int[] A=new int[N]; int sum=0 ; for(int i=0 ; i>>(64-A[i] % 64); } exist[j] |=tmp[j]; } exist[A[i]/64] |=1L<<(A[i] % 64); } for(int i=(sum+1)/2 ; ; i++){ if((exist[i/64] &(1L<toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ; sum := sum+(A[i+1]) ) ; i := i + 1 ) ; if (N = 1) then ( OclFile["System.out"].println(sum) ; return ) else skip ; var exist : Sequence(long) ; exist := Integer.subrange(1,(sum + 63) / 64)->collect(0) ; exist[0+1] := 1L ; var tmp : Sequence(long) ; tmp := Integer.subrange(1,exist->size())->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( tmp := tmp->collect(0L) ; var j : int ; j := 0 ; while j < exist->size() do ( ( if (A[i+1] mod 64 = 0) then ( if (j + A[i+1] / 64 < tmp->size()) then tmp[j + A[i+1] / 64+1] := MathLib.bitwiseOr(tmp[j + A[i+1] / 64+1], exist[j+1]) ; else skip ) else ( if (j + A[i+1] / 64 < tmp->size()) then tmp[j + A[i+1] / 64+1] := MathLib.bitwiseOr(tmp[j + A[i+1] / 64+1], (exist[j+1]*(2->pow((A[i+1] mod 64))))->oclAsType(long)) ; else skip ; if (j + A[i+1] / 64 + 1 < tmp->size()) then tmp[j + A[i+1] / 64 + 1+1] := MathLib.bitwiseOr(tmp[j + A[i+1] / 64 + 1+1], (exist[j+1]/(2->pow((64 - A[i+1] mod 64))))->oclAsType(long)) ; else skip ) ; exist[j+1] := MathLib.bitwiseOr(exist[j+1], tmp[j+1]) ) ; j := j + 1 ) ; exist[A[i+1] / 64+1] := MathLib.bitwiseOr(exist[A[i+1] / 64+1], (1L*(2->pow((A[i+1] mod 64))))->oclAsType(long)) ) ; i := i + 1 ) ; var i : int ; i := (sum + 1) / 2 ; while true do ( ( if ((exist[i / 64+1] & ((1L*(2->pow(i mod 64)))->oclAsType(long))) /= 0) then ( OclFile["System.out"].println(i) ; return ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { int n,a[]; private void solve()throws IOException { n=nextInt(); a=new int[n+1]; int sum=0 ; for(int i=1 ; i<=n ; i++){ a[i]=nextInt(); sum+=a[i]; } int maxn=4000000 ; BitSet dp=new BitSet(maxn+1); dp.set(maxn); for(int i=1 ; i<=n ; i++)dp.or(dp.get(a[i],maxn+1)); for(int i=(sum+1)/2 ; i<=maxn ; i++)if(dp.get(maxn-i)){ out.println(i); return ; } } public void run()throws IOException { br=new BufferedReader(new InputStreamReader(System.in)); st=null ; out=new PrintWriter(System.out); solve(); br.close(); out.close(); } public static void main(String args[])throws IOException { new Main().run(); } BufferedReader br ; StringTokenizer st ; PrintWriter out ; String nextToken()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine()throws IOException { return br.readLine(); } int nextInt()throws IOException { return Integer.parseInt(nextToken()); } long nextLong()throws IOException { return Long.parseLong(nextToken()); } double nextDouble()throws IOException { return Double.parseDouble(nextToken()); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute n : int; operation solve() : void pre: true post: true activity: ( n := nextInt() ; a := Integer.subrange(1,n + 1)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := nextInt() ; sum := sum+(a[i+1]) ) ; i := i + 1 ) ; var maxn : int ; maxn := 4000000 ; var dp : Sequence(boolean) ; dp := MathLib.toBitSequence(maxn + 1) ; dp := dp.setAt(maxn+1, true) ; var i : int ; i := 1 ; while i <= n do ( dp := dp.or(dp->at(a[i+1], maxn + 1+1)) ; ; i := i + 1 ) ; var i : int ; i := (sum + 1) / 2 ; while i <= maxn do ( if (dp->at(maxn - i+1)) then ( out.println(i) ; return ) else skip ; ; i := i + 1 ) ; ); operation run() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; st := null ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; br.close() ; out.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute br : OclFile; attribute st : OclIterator; attribute out : OclFile; operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] g){ Scanner c=new Scanner(System.in); int n=c.nextInt(); int[] a=IntStream.range(0,n).map(i->c.nextInt()).toArray(); int s=Arrays.stream(a).sum(); BitSet b=new BitSet(); b.set(s); IntStream.range(0,n).forEach(i->b.or(b.get(a[i],s+1))); System.out.println(b.nextSetBit((s+1)/2)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( g : Sequence(String)) : void pre: true post: true activity: ( var c : OclFile ; c := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := c.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(0, n-1)->collect( _x1 | (lambda i : OclAny in c.getCurrent()->toInteger())->apply(_x1) )->asSequence() ; var s : int ; s := stream(a)->sum() ; var b : Sequence(boolean) ; b := MathLib.toBitSequence() ; b := b.setAt(s+1, true) ; for i : Integer.subrange(0, n-1) do ( b := b.or(b->at(a[i+1], s + 1+1))) ; OclFile["System.out"].println(b.nextSetBit((s + 1) / 2)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.util.stream.Collectors.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); HashMaphashE=new HashMap<>(); HashMaphashO=new HashMap<>(); for(int i=0 ; i>listE=hashE.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(toList()); List>listO=hashO.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(toList()); Map.Entrye1=listE.get(0); Map.Entrye2=1(-1,0); Map.Entryo1=listO.get(0); Map.Entryo2=1(-1,0); if(e1.getKey().equals(o1.getKey())){ System.out.println(n-Math.max(e1.getValue()+o2.getValue(),e2.getValue()+o1.getValue())); } else { System.out.println(n-e1.getValue()-o1.getValue()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var hashE : Map(int,int) ; hashE := Map{} ; var hashO : Map(int,int) ; hashO := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var in : int ; in := sc.getCurrent()->toInteger() ; if (i mod 2 = 0) then ( hashE := hashE->union(Map{in |-> (if hashE->keys()->contains(in) then hashE->at(in) else 0 endif) + 1}) ) else ( hashO := hashO->union(Map{in |-> (if hashO->keys()->contains(in) then hashO->at(in) else 0 endif) + 1}) ) ) ; i := i + 1 ) ; var listE : Sequence(Map(int,int)) ; listE := hashE->asSet()->sort().collect(toList()) ; var listO : Sequence(Map(int,int)) ; listO := hashO->asSet()->sort().collect(toList()) ; var e1 : Map(int,int) ; e1 := listE->at(0+1) ; var e2 : Map(int,int) ; e2 := if 1 < listE->size() then listE->at(1+1) else SimpleEntry.newSimpleEntry(-1, 0) endif ; var o1 : Map(int,int) ; o1 := listO->at(0+1) ; var o2 : Map(int,int) ; o2 := if 1 < listO->size() then listO->at(1+1) else SimpleEntry.newSimpleEntry(-1, 0) endif ; if (e1->keys()->any() = o1->keys()->any()) then ( OclFile["System.out"].println(n - Set{e1->values->any() + o2->values->any(), e2->values->any() + o1->values->any()}->max()) ) else ( OclFile["System.out"].println(n - e1->values->any() - o1->values->any()) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.math.BigInteger ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskC solver=new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(); int[] a=new int[n]; int s=0 ; for(int i=0 ; icollect(0) ; var s : int ; s := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.nextInt() ; s := s+(a[i+1]) ) ; i := i + 1 ) ; var half : int ; half := s / 2 ; var mask : long ; mask := 1.shiftLeft(half + 1).subtract(1) ; var can : long ; can := 1 ; for (x : a) do ( ( can := can.or(can.shiftLeft(x)).and(mask) ) ) ; var x : int ; x := can.bitLength() - 1 ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.sql.Array ; import java.util.*; public class Hi { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ int a=sc.nextInt(); int b=sc.nextInt(); if(Math.max(a,b)>2*Math.min(a,b))System.out.println("no"); else if((a+b)% 3==0)System.out.println("yes"); else System.out.println("no"); } } } ------------------------------------------------------------ OCL File: --------- class Hi { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (Set{a, b}->max() > 2 * Set{a, b}->min()) then OclFile["System.out"].println("no") ; else if ((a + b) mod 3 = 0) then OclFile["System.out"].println("yes") else OclFile["System.out"].println("no") ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int d=sc.nextInt(); if(d==0){ break ; } int n=sc.nextInt(); int m=sc.nextInt(); int[] store=new int[n+1]; store[n]=d ; for(int i=1 ; i=0){ continue ; } else { index++; index*=-1 ; result+=Math.min(deliv[i]-store[index-1],store[index]-deliv[i]); } } return result ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var d : int ; d := sc.getCurrent()->toInteger() ; if (d = 0) then ( break ) else skip ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var store : Sequence(int) ; store := Integer.subrange(1,n + 1)->collect(0) ; store[n+1] := d ; var i : int ; i := 1 ; while i < n do ( ( store[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var deliv : Sequence(int) ; deliv := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( deliv[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(store, deliv, d)) ; ) ); static operation solve( store : Sequence(int), deliv : Sequence(int), d : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; store := store->sort() ; var i : int ; i := 0 ; while i < deliv->size() do ( ( var index : int ; index := (store->indexOf(deliv[i+1]) - 1) ; if (index >= 0) then ( continue ) else ( index := index + 1 ; index := index*(-1) ; result := result+(Set{deliv[i+1] - store[index - 1+1], store[index+1] - deliv[i+1]}->min()) ) ) ; i := i + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null && ! line.isEmpty()){ int d=parseInt(line); if(d==0)break ; int n=parseInt(br.readLine()); int m=parseInt(br.readLine()); int[] stores=new int[n+1]; for(int i=1 ; iisEmpty())) do ( skip ; ( var d : int ; d := parseInt(line) ; if (d = 0) then break else skip ; var n : int ; n := parseInt(br.readLine()) ; var m : int ; m := parseInt(br.readLine()) ; var stores : Sequence(int) ; stores := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i < n do ( ( var pos : int ; pos := parseInt(br.readLine()) ; stores[i+1] := pos ) ; i := i + 1 ) ; stores[n+1] := d ; stores := stores->sort() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < m do ( ( var pos : int ; pos := parseInt(br.readLine()) ; var min : int ; min := 0 ; var max : int ; max := n - 1 ; var mid : int ; while (min <= max) do ( mid := (max + min) / 2 ; if (pos < stores[mid+1]) then ( max := mid - 1 ) else if (stores[mid + 1+1] < pos) then ( min := mid + 1 ) else ( sum := sum+(Set{pos - stores[mid+1], stores[mid + 1+1] - pos}->min()) ; break ) ; ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileNotFoundException ; import java.util.ArrayList ; import java.util.Collections ; import java.util.Comparator ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws FileNotFoundException { Scanner scan=new Scanner(System.in); while(scan.hasNext()){ int d=scan.nextInt(); if(d==0)break ; int n=scan.nextInt(); int m=scan.nextInt(); Piza p=new Piza(d); for(int i=1 ; ik)i-=s ; else if(store.get(i+1)>=k)break ; else i+=s ; if(s>1)s/=2 ; } return(Math.min(k-store.get(i),store.get(i+1)-k)); } public void addStore(int d){ store.add(d); } Liststore=new ArrayList(); } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (scan.hasNext()) do ( var d : int ; d := scan.getCurrent()->toInteger() ; if (d = 0) then break else skip ; var n : int ; n := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var p : Piza ; p := Piza.newPiza(d) ; var i : int ; i := 1 ; while i < n do ( p.addStore(scan.getCurrent()->toInteger()) ; ; i := i + 1 ) ; p.sort() ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < m do ( result := result+(p.addDeliver(scan.getCurrent()->toInteger())) ; ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ) ; skip ; OclProcess.exit(0) ); } class Piza { static operation newPiza( d : int) : Piza pre: true post: true activity: ( var self : Piza ; self := createPiza(); self.initialise(d); return self ); operation initialise( d : int) : void pre: true post: true activity: ( store->excludes(0) ; store->excludes(d) ); operation sort() : void pre: true post: true activity: ( store.sort(null) ); operation addDeliver( k : int) : int pre: true post: true activity: ( var i : int ; i := store->size() / 2 ; var s : int ; s := i / 2 ; while (true) do ( if (store->at(i+1) = k) then break else if (store->at(i+1) > k) then i := i-(s) else if (store->at(i + 1+1) >= k) then break else i := i+(s) ; ; ; ; if (s > 1) then s := s/(2) ; else skip ) ; return (Set{k - store->at(i+1), store->at(i + 1+1) - k}->min()) ); operation addStore( d : int) : void pre: true post: true activity: ( store->excludes(d) ); attribute store : Sequence(int) := Sequence{}; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static int n,a[]; public static void main(String[] args){ Scanner in=new Scanner(System.in); for(; ; ){ int d=in.nextInt(); if(d==0)return ; n=in.nextInt(); int m=in.nextInt(); a=new int[n+1]; int ans=0 ; a[0]=0 ; for(int i=1 ; i=le){ int mid=(le+ri)/2 ; if(a[mid]>ob)ri=mid-1 ; else le=mid+1 ; } res=Math.min(Math.abs(ob-a[ri]),Math.abs(a[le]-ob)); return res ; } static public void debug(Object...o){ System.out.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute n : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var d : int ; d := in.getCurrent()->toInteger() ; if (d = 0) then return else skip ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; a := Integer.subrange(1,n + 1)->collect(0) ; var ans : int ; ans := 0 ; a[0+1] := 0 ; var i : int ; i := 1 ; while i < n do ( a[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; a[n+1] := d ; a := a->sort() ; var i : int ; i := 0 ; while i < m do ( ( var k : int ; k := in.getCurrent()->toInteger() ; ans := ans+(binary(k)) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ) ); static operation binary( ob : int) : int pre: true post: true activity: ( var ri : int ; ri := n - 1 ; var le : int ; le := 0 ; var res : int ; res := 0 ; while (ri >= le) do ( var mid : int ; mid := (le + ri) / 2 ; if (a[mid+1] > ob) then ri := mid - 1 ; else le := mid + 1 ; ) ; res := Set{if ob - a[ri+1] < 0 then -(ob - a[ri+1]) else ob - a[ri+1] endif, if a[le+1] - ob < 0 then -(a[le+1] - ob) else a[le+1] - ob endif}->min() ; return res ); static operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((o + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.Math ; public class GfG { public static boolean is_possible(String s){ int l=s.length(); int one=0,zero=0 ; for(int i=0 ; isize() ; var one : int ; one := 0 ; var zero : int ; zero := 0 ; var i : int ; i := 0 ; while i < l do ( ( if (s->at(i+1) = '0') then zero := zero + 1 ; else one := one + 1 ; ) ; i := i + 1 ) ; if (l mod 2 = 0) then return (one = zero) else return (if one - zero < 0 then -(one - zero) else one - zero endif = 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "100110" ; if (is_possible(s)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class odd_set { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int odd=0 ; int even=0 ; int[] a=new int[2*n]; for(int i=0 ; i<2*n ; i++){ a[i]=sc.nextInt(); } for(int i=0 ; i<2*n ; i++){ if(a[i] % 2==0){ even++; } else { odd++; } } if(even==odd){ System.out.println("Yes"); } else { System.out.println("No"); } t--; } } } ------------------------------------------------------------ OCL File: --------- class odd_set { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var odd : int ; odd := 0 ; var even : int ; even := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,2 * n)->collect(0) ; var i : int ; i := 0 ; while i < 2 * n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 2 * n do ( ( if (a[i+1] mod 2 = 0) then ( even := even + 1 ) else ( odd := odd + 1 ) ) ; i := i + 1 ) ; if (even = odd) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class oddSet { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var c : int ; c := 0 ; var arr : Sequence(int) ; arr := Integer.subrange(1,2 * n)->collect(0) ; var j : int ; j := 0 ; while j < 2 * n do ( ( arr[j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < 2 * n do ( ( if (arr[j+1] mod 2 /= 0) then c := c + 1 ; else skip ) ; j := j + 1 ) ; if (c = n) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int[] v=new int[100010]; for(int i=0 ; itoInteger() ; var v : Sequence(int) ; v := Integer.subrange(1,100010)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( v[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var vo : Sequence(int) ; vo := Integer.subrange(1,100010)->collect(null) ; var ve : Sequence(int) ; ve := Integer.subrange(1,100010)->collect(null) ; var vt : Sequence(int) ; vt := Integer.subrange(1,100010)->collect(null) ; vo := vo->collect(0) ; ve := ve->collect(0) ; vt := vt->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( vt[v[i+1]+1] := vt[v[i+1]+1] + 1 ; if (i mod 2 = 0) then ( ve[v[i+1]+1] := ve[v[i+1]+1] + 1 ) else ( vo[v[i+1]+1] := vo[v[i+1]+1] + 1 ) ) ; i := i + 1 ) ; vo := OclComparator.sortWith(vo, reverseOrder()) ; ve := OclComparator.sortWith(ve, reverseOrder()) ; vt := OclComparator.sortWith(vt, reverseOrder()) ; var ans : int ; ans := 0 ; if (vo[0+1] + ve[0+1] = vt[0+1]) then ( ans := Set{n - vo[0+1] - ve[1+1], n - vo[1+1] - ve[0+1]}->min() ) else ( ans := n - vo[0+1] - ve[0+1] ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test169 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var o : int ; o := 0 ; var e : int ; e := 0 ; var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n * 2 do ( ( if (in.getCurrent()->toInteger() mod 2 = 0) then ( e := e + 1 ) else ( o := o + 1 ) ) ; i := i + 1 ) ; if (o = e) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1542A_OddSet { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ final int len=parseInt(input.nextLine()); int odds=0 ; int evens=0 ; for(int i=0 ; i<2*len ; i++){ int num=input.nextInt(); if(num % 2==0){ evens++; } else { odds++; } } input.nextLine(); if(evens==odds){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class _1542A_OddSet { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; while (test > 0) do ( test := test - 1 ; skip ; ( var len : int ; len := parseInt(input.nextLine()) ; var odds : int ; odds := 0 ; var evens : int ; evens := 0 ; var i : int ; i := 0 ; while i < 2 * len do ( ( var num : int ; num := input.getCurrent()->toInteger() ; if (num mod 2 = 0) then ( evens := evens + 1 ) else ( odds := odds + 1 ) ) ; i := i + 1 ) ; skip ; if (evens = odds) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc ; Main(){ sc=new Scanner(System.in); } void run(){ for(; ; ){ double in=sc.nextDouble(); if(in==0){ break ; } int denom=1 ; boolean ok=false ; for(; ; ){ for(int i=(int)(denom*Math.PI); itoReal() ; if (in = 0) then ( break ) else skip ; var denom : int ; denom := 1 ; var ok : boolean ; ok := false ; while true do ( ( var i : int ; i := (denom * 3.141592653589793)->oclAsType(int) ; while i < denom * 3.141592653589793 + 1 do ( ( if (if i->oclAsType(double) / denom - 3.141592653589793 < 0 then -(i->oclAsType(double) / denom - 3.141592653589793) else i->oclAsType(double) / denom - 3.141592653589793 endif < in) then ( ok := true ) else skip ) ; i := i + 1 ) ; if (ok) then ( break ) else skip ; denom := denom + 1 ) ) ; var min : double ; min := in ; var index : int ; index := 0 ; var i : int ; i := (denom * 3.141592653589793)->oclAsType(int) ; while i < denom * 3.141592653589793 + 1 do ( ( if (if i->oclAsType(double) / denom - 3.141592653589793 < 0 then -(i->oclAsType(double) / denom - 3.141592653589793) else i->oclAsType(double) / denom - 3.141592653589793 endif < min) then ( min := if i->oclAsType(double) / denom - 3.141592653589793 < 0 then -(i->oclAsType(double) / denom - 3.141592653589793) else i->oclAsType(double) / denom - 3.141592653589793 endif ; index := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(index + "/" + denom) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NewClass53 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int s=0 ; int p=0 ; int o=0 ; int u=0 ; int a=in.nextInt(); int x[]=new int[a*2]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var s : int ; s := 0 ; var p : int ; p := 0 ; var o : int ; o := 0 ; var u : int ; u := 0 ; var a : int ; a := in.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,a * 2)->collect(0) ; var i : int ; i := 0 ; while i < a * 2 do ( ( x[i+1] := in.getCurrent()->toInteger() ; if (x[i+1] mod 2 = 0) then s := s + 1 ; else ( p := p + 1 ) ) ; i := i + 1 ) ; if (s = p) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n,v,left=0,color=0 ; n=sc.nextInt(); int[] ans=new int[n]; List>id=new ArrayList<>(); for(int i=0 ; i<=n ; i++){ id.add(new ArrayList<>()); } for(int i=0 ; i0){ System.out.println("Impossible"); return ; } for(int num : id.get(i)){ if(left==0){ left=i ; color++; } ans[num]=color ; left--; } } System.out.println("Possible"); for(int num : ans){ System.out.print(num+" "); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var v : int ; var left : int ; left := 0 ; var color : int ; color := 0 ; n := sc.getCurrent()->toInteger() ; var ans : Sequence(int) ; ans := Integer.subrange(1,n)->collect(0) ; var id : Sequence(Sequence(int)) ; id := Sequence{} ; var i : int ; i := 0 ; while i <= n do ( ( id := id->including(Sequence{}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( v := sc.getCurrent()->toInteger() ; id->at(n - v+1)->excludes(i) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( if (id->at(i+1)->size() mod i > 0) then ( OclFile["System.out"].println("Impossible") ; return ) else skip ; for (num : id->at(i+1)) do ( ( if (left = 0) then ( left := i ; color := color + 1 ) else skip ; ans[num+1] := color ; left := left - 1 ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println("Possible") ; for (num : ans) do ( ( OclFile["System.out"].print(num + " ") ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; public class CF_1081B { public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); List[] id=new ArrayList[n+1]; for(int i=0 ; i(); } for(int i=0 ; i0){ System.out.println("Impossible"); return ; } for(Integer i : id[c]){ if(left==0){ left=c ; color++; } ret[i]=color ; left--; } } StringBuilder str=new StringBuilder("Possible\n"); for(int i : ret)str.append(i).append(' '); System.out.println(str); sc.close(); writer.flush(); writer.close(); reader.close(); } } ------------------------------------------------------------ OCL File: --------- class CF_1081B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var writer : OclFile ; writer := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var id : Sequence(Sequence(int)) ; id := Integer.subrange(1,n + 1)->collect(null) ; var i : int ; i := 0 ; while i < id->size() do ( ( id[i+1] := Sequence{} ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; id[n - v+1]->excludes(i) ) ; i := i + 1 ) ; var left : int ; left := 0 ; var color : int ; color := 0 ; var ret : Sequence(int) ; ret := Integer.subrange(1,n)->collect(0) ; var c : int ; c := 1 ; while c <= n do ( ( if (id[c+1]->size() mod c > 0) then ( OclFile["System.out"].println("Impossible") ; return ) else skip ; for (i : id[c+1]) do ( ( if (left = 0) then ( left := c ; color := color + 1 ) else skip ; ret[i+1] := color ; left := left - 1 ) ) ) ; c := c + 1 ) ; var str : String ; str := StringLib.newString("Possible\n") ; for (i : ret) do ( str := str + StringLib.newString(i) + StringLib.newString(' ') ; ) ; OclFile["System.out"].println(str) ; skip ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class B1081 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); List[] groups=new List[N+1]; for(int n=1 ; n<=N ; n++){ groups[n]=new ArrayList<>(); } for(int n=1 ; n<=N ; n++){ int different=in.nextInt(); int same=N-different ; groups[same] .add(n); } boolean possible=true ; for(int n=1 ; n<=N ; n++){ if(groups[n] .size()% n!=0){ possible=false ; break ; } } if(possible){ System.out.println("Possible"); int lastGroup=0 ; int[] G=new int[N]; for(int n=1 ; n<=N ; n++){ Listgroup=groups[n]; for(int i=0 ; itoInteger() ; var groups : Sequence(Sequence(int)) ; groups := Integer.subrange(1,N + 1)->collect(null) ; var n : int ; n := 1 ; while n <= N do ( ( groups[n+1] := Sequence{} ) ; n := n + 1 ) ; var n : int ; n := 1 ; while n <= N do ( ( var different : int ; different := in.getCurrent()->toInteger() ; var same : int ; same := N - different ; groups[same+1]->excludes(n) ) ; n := n + 1 ) ; var possible : boolean ; possible := true ; var n : int ; n := 1 ; while n <= N do ( ( if (groups[n+1]->size() mod n /= 0) then ( possible := false ; break ) else skip ) ; n := n + 1 ) ; if (possible) then ( OclFile["System.out"].println("Possible") ; var lastGroup : int ; lastGroup := 0 ; var G : Sequence(int) ; G := Integer.subrange(1,N)->collect(0) ; var n : int ; n := 1 ; while n <= N do ( ( var group : Sequence(int) ; group := groups[n+1] ; var i : int ; i := 0 ; while i < group->size() do ( ( if (i mod n = 0) then ( lastGroup := lastGroup + 1 ) else skip ; var member : int ; member := group->at(i+1) ; G[member - 1+1] := lastGroup ) ; i := i + 1 ) ) ; n := n + 1 ) ; var out : String ; out := StringLib.newString() ; for (g : G) do ( ( out := out + StringLib.newString(g) + StringLib.newString(' ') ) ) ; OclFile["System.out"].println(out) ; ) else ( OclFile["System.out"].println("Impossible") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int CountAllPairs(int N,int K){ int count=0 ; if(N>K){ count=N-K ; for(int i=K+1 ; i<=N ; i++)count=count+((N-K)/i); } return count ; } public static void main(String[] args){ int N=11,K=5 ; System.out.println(CountAllPairs(N,K)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation CountAllPairs( N : int, K : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; if (N > K) then ( count := N - K ; var i : int ; i := K + 1 ; while i <= N do ( count := count + ((N - K) / i) ; ; i := i + 1 ) ) else skip ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 11 ; var K : int ; K := 5 ; OclFile["System.out"].println(CountAllPairs(N, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int L=scanner.nextInt(); int N=scanner.nextInt(); int[] x=new int[N]; int[] y=new int[N]; for(int i=0 ; i0 ; n--){ int m=N-n ; max=Math.max(max,Math.max(x2[n-1]-x2[Math.max(n-m-1,0)]+y2[m]-y2[Math.max(m-n,0)]+x[n-1],x2[n]-x2[Math.max(n-m,0)]+y2[m-1]-y2[Math.max(m-n-1,0)]+y[m-1])); } max=Math.max(max,y[N-1]); System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var L : int ; L := scanner.getCurrent()->toInteger() ; var N : int ; N := scanner.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,N)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( x[i+1] := scanner.getCurrent()->toInteger() ; y[N - i - 1+1] := L - x[i+1] ) ; i := i + 1 ) ; var x2 : Sequence(long) ; x2 := Integer.subrange(1,N + 1)->collect(0) ; var y2 : Sequence(long) ; y2 := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i <= N do ( x2[i+1] := x2[i - 1+1] + x[i - 1+1] * 2L ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= N do ( y2[i+1] := y2[i - 1+1] + y[i - 1+1] * 2L ; ; i := i + 1 ) ; var max : long ; max := x[N - 1+1] ; var n : int ; n := N - 1 ; while n > 0 do ( ( var m : int ; m := N - n ; max := Set{max, Set{x2[n - 1+1] - x2[Set{n - m - 1, 0}->max()+1] + y2[m+1] - y2[Set{m - n, 0}->max()+1] + x[n - 1+1], x2[n+1] - x2[Set{n - m, 0}->max()+1] + y2[m - 1+1] - y2[Set{m - n - 1, 0}->max()+1] + y[m - 1+1]}->max()}->max() ) ; n := n - 1 ) ; max := Set{max, y[N - 1+1]}->max() ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int L=scanner.nextInt(); int N=scanner.nextInt(); int[] x=new int[N]; int[] y=new int[N]; for(int i=0 ; i0 ; n--){ int m=N-n ; max=Math.max(max,Math.max(x2[n-1]-x2[Math.max(n-m-1,0)]+y2[m]-y2[Math.max(m-n,0)]+x[n-1],x2[n]-x2[Math.max(n-m,0)]+y2[m-1]-y2[Math.max(m-n-1,0)]+y[m-1])); } max=Math.max(max,y[N-1]); System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var L : int ; L := scanner.getCurrent()->toInteger() ; var N : int ; N := scanner.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,N)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( x[i+1] := scanner.getCurrent()->toInteger() ; y[N - i - 1+1] := L - x[i+1] ) ; i := i + 1 ) ; var x2 : Sequence(long) ; x2 := Integer.subrange(1,N + 1)->collect(0) ; var y2 : Sequence(long) ; y2 := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i <= N do ( x2[i+1] := x2[i - 1+1] + x[i - 1+1] * 2L ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= N do ( y2[i+1] := y2[i - 1+1] + y[i - 1+1] * 2L ; ; i := i + 1 ) ; var max : long ; max := x[N - 1+1] ; var n : int ; n := N - 1 ; while n > 0 do ( ( var m : int ; m := N - n ; max := Set{max, Set{x2[n - 1+1] - x2[Set{n - m - 1, 0}->max()+1] + y2[m+1] - y2[Set{m - n, 0}->max()+1] + x[n - 1+1], x2[n+1] - x2[Set{n - m, 0}->max()+1] + y2[m - 1+1] - y2[Set{m - n - 1, 0}->max()+1] + y[m - 1+1]}->max()}->max() ) ; n := n - 1 ) ; max := Set{max, y[N - 1+1]}->max() ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test193 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); char a[]=in.next().toCharArray(); int sum=0,x=0 ; for(int i=0 ; i2){ sum++; } } System.out.println(sum); in.close(); } } ------------------------------------------------------------ OCL File: --------- class test193 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(String) ; a := in.getCurrent()->characters() ; var sum : int ; sum := 0 ; var x : int ; x := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] = 'x') then ( x := x + 1 ) else ( x := 0 ) ; if (x > 2) then ( sum := sum + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long l=sc.nextLong(); int n=sc.nextInt(); long[] dis=new long[n+1]; long[] sum=new long[n+1]; for(int i=1 ; i<=n ; i++){ dis[i]=sc.nextLong(); sum[i]=sum[i-1]+dis[i]; } long ans=0 ; for(int i=1 ; i<=n ; i++){ int right=Math.min(i-1,n-i); int left=Math.min(i,n-i); ans=Math.max(ans,dis[i]+(sum[i-1]-sum[i-1-right])*2+left*2*l-2*(sum[left+i]-sum[i])); right=Math.min(i-1,n-i+1); left=Math.min(n-i,i-1); ans=Math.max(ans,l-dis[i]+(sum[i-1]-sum[i-1-right])*2+left*2*l-2*(sum[left+i]-sum[i])); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var l : long ; l := sc.getCurrent()->toLong() ; var n : int ; n := sc.getCurrent()->toInteger() ; var dis : Sequence(long) ; dis := Integer.subrange(1,n + 1)->collect(0) ; var sum : Sequence(long) ; sum := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( dis[i+1] := sc.getCurrent()->toLong() ; sum[i+1] := sum[i - 1+1] + dis[i+1] ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var right : int ; right := Set{i - 1, n - i}->min() ; var left : int ; left := Set{i, n - i}->min() ; ans := Set{ans, dis[i+1] + (sum[i - 1+1] - sum[i - 1 - right+1]) * 2 + left * 2 * l - 2 * (sum[left + i+1] - sum[i+1])}->max() ; right := Set{i - 1, n - i + 1}->min() ; left := Set{n - i, i - 1}->min() ; ans := Set{ans, l - dis[i+1] + (sum[i - 1+1] - sum[i - 1 - right+1]) * 2 + left * 2 * l - 2 * (sum[left + i+1] - sum[i+1])}->max() ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.System.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(in); int l=sc.nextInt(); int n=sc.nextInt(); int[] x=new int[n]; for(int i=0 ; itoInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( x[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ans : long ; ans := Set{x[n - 1+1], l - x[0+1]}->max() ; var now : long ; now := x[n - 1+1] ; var i : int ; i := 2 ; while i <= n do ( ( now := now+(l) ; now := now-((x[n - i / 2+1] - x[n - i+1]) * 2) ; if (i mod 2 = 1) then now := now+((x[n - i / 2+1] - x[n - i / 2 - 1+1])) ; else skip ; ans := Set{ans, now}->max() ) ; i := i + 1 ) ; now := l - x[0+1] ; var i : int ; i := 0 ; while i < n - 1 do ( ( now := now+(l) ; now := now-((x[i + 1+1] - x[i / 2+1]) * 2) ; if (i mod 2 = 1) then now := now+((x[i / 2 + 1+1] - x[i / 2+1])) ; else skip ; ans := Set{ans, now}->max() ) ; i := i + 1 ) ; out.println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { final static int N=2 ; final static int M=3 ; static int traverseMatrix(int arr[][],int current_row,int current_col){ if(current_col>=M)return 0 ; if(current_row>=N)return 1 ; System.out.print(arr[current_row][current_col]+","); if(traverseMatrix(arr,current_row,current_col+1)==1)return 1 ; return traverseMatrix(arr,current_row+1,0); } public static void main(String[] args){ int arr[][]={ { 1,2,3 },{ 4,5,6 } }; traverseMatrix(arr,0,0); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute N : int := 2; static attribute M : int := 3; static operation traverseMatrix( arr : Sequence(Sequence(int)), current_row : int, current_col : int) : int pre: true post: true activity: ( if (current_col >= M) then return 0 else skip ; if (current_row >= N) then return 1 else skip ; OclFile["System.out"].print(arr[current_row+1][current_col+1] + ",") ; if (traverseMatrix(arr, current_row, current_col + 1) = 1) then return 1 else skip ; return traverseMatrix(arr, current_row + 1, 0) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(Sequence(int)) ; arr := Sequence{Sequence{1,2,3},Sequence{4,5,6}} ; execute traverseMatrix(arr, 0, 0) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { double pi=Math.PI ; private void doit(){ Scanner sc=new Scanner(System.in); while(true){ double n=sc.nextDouble(); if(n==0.0)break ; for(int i=1 ; ; i++){ double x=pi*i ; int[] res=new int[] { (int)Math.floor(x),(int)Math.ceil(x)}; boolean flg=false ; for(int j=0 ; j<2 ; j++){ double now=Math.abs(pi-((double)res[j]/i)); if(now<=n){ System.out.println(res[j]+"/"+i); flg=true ; break ; } } if(flg)break ; } } } public static void main(String[] args){ new Main().doit(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute pi : double := 3.141592653589793; operation doit() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : double ; n := sc.getCurrent()->toReal() ; if (n = 0.0) then break else skip ; var i : int ; i := 1 ; while true do ( ( var x : double ; x := pi * i ; var res : Sequence(int) ; res := Sequence{(x)->floor()->oclAsType(int),(x)->ceil()->oclAsType(int)} ; var flg : boolean ; flg := false ; var j : int ; j := 0 ; while j < 2 do ( ( var now : double ; now := if pi - (res[j+1]->oclAsType(double) / i) < 0 then -(pi - (res[j+1]->oclAsType(double) / i)) else pi - (res[j+1]->oclAsType(double) / i) endif ; if (now <= n) then ( OclFile["System.out"].println(res[j+1] + "/" + i) ; flg := true ; break ) else skip ) ; j := j + 1 ) ; if (flg) then break else skip ; ) ; i := i + 1 ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static final int N=100005 ; static void SieveOfEratosthenes(boolean prime[],int p_size){ prime[0]=false ; prime[1]=false ; for(int p=2 ; p*p<=p_size ; p++){ if(prime[p]){ for(int i=p*2 ; i<=p_size ; i+=p)prime[i]=false ; } } } static int longestPrimeSubsequence(int arr[],int n){ boolean[] prime=new boolean[N+1]; Arrays.fill(prime,true); SieveOfEratosthenes(prime,N); int answer=0 ; for(int i=0 ; icollect(false) ; prime := prime->collect(true) ; execute SieveOfEratosthenes(prime, N) ; var answer : int ; answer := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (prime[arr[i+1]+1]) then ( answer := answer + 1 ) else skip ) ; i := i + 1 ) ; return answer ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,4,11,2,9,21} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(longestPrimeSubsequence(arr, n) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); long n=s.nextInt(); long a=s.nextInt(); long b=s.nextInt(); long c=s.nextInt(); long needed=4-n % 4 ; long min=0 ; if(needed==0){ System.out.println(0); return ; } else if(needed==3){ min=3*a ; if(min>c)min=c ; if(min>b+a)min=b+a ; } else if(needed==2){ min=2*a ; if(min>b)min=b ; if(min>2*c)min=2*c ; } else if(needed==1){ min=a ; if(min>3*c)min=3*c ; if(min>b+c)min=b+c ; } System.out.println(min); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := s.getCurrent()->toInteger() ; var a : long ; a := s.getCurrent()->toInteger() ; var b : long ; b := s.getCurrent()->toInteger() ; var c : long ; c := s.getCurrent()->toInteger() ; var needed : long ; needed := 4 - n mod 4 ; var min : long ; min := 0 ; if (needed = 0) then ( OclFile["System.out"].println(0) ; return ) else if (needed = 3) then ( min := 3 * a ; if (min > c) then min := c ; else skip ; if (min > b + a) then min := b + a ; else skip ) else if (needed = 2) then ( min := 2 * a ; if (min > b) then min := b ; else skip ; if (min > 2 * c) then min := 2 * c ; else skip ) else if (needed = 1) then ( min := a ; if (min > 3 * c) then min := 3 * c ; else skip ; if (min > b + c) then min := b + c ; else skip ) else skip ; ; ; ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Alyonaandcopybooks { public static void main(String[] args){ Scanner scn=new Scanner(System.in); long n=scn.nextLong(); long a=scn.nextLong(); long b=scn.nextLong(); long c=scn.nextLong(); int remain=(int)(4-(n % 4)); long rob=0 ; switch(remain){ case 0 : rob=0 ; break ; case 1 : rob=Math.min(a,Math.min(b+c,3*c)); break ; case 2 : rob=Math.min(2*a,Math.min(b,2*c)); break ; case 3 : rob=Math.min(3*a,Math.min(a+b,c)); } System.out.println(rob); } } ------------------------------------------------------------ OCL File: --------- class Alyonaandcopybooks { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := scn.getCurrent()->toLong() ; var a : long ; a := scn.getCurrent()->toLong() ; var b : long ; b := scn.getCurrent()->toLong() ; var c : long ; c := scn.getCurrent()->toLong() ; var remain : int ; remain := (4 - (n mod 4))->oclAsType(int) ; var rob : long ; rob := 0 ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (remain) ; if _switchval = 0 then rob := 0 ; break else skip ; if _switchval = 1 then rob := Set{a, Set{b + c, 3 * c}->min()}->min() ; break else skip ; if _switchval = 2 then rob := Set{2 * a, Set{b, 2 * c}->min()}->min() ; break else skip ; if _switchval = 3 then rob := Set{3 * a, Set{a + b, c}->min()}->min() ; else skip ; ) OclFile["System.out"].println(rob) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws java.lang.Exception { Scanner input=new Scanner(System.in); long n=input.nextLong(); long a=input.nextLong(); long b=input.nextLong(); long c=input.nextLong(); long sum=0,min=0 ; if(n % 4==0)min=0 ; else if(n % 4==1){ min=3*a ; if(min>b+a)min=b+a ; if(min>c)min=c ; } else if(n % 4==2){ min=a*2 ; if(min>b*1)min=b ; if(min>c*2)min=c*2 ; if(min>a+b+c)min=a+b+c ; } else { min=a ; if(min>b+c)min=b+c ; if(min>3*c)min=3*c ; } System.out.println(min); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := input.getCurrent()->toLong() ; var a : long ; a := input.getCurrent()->toLong() ; var b : long ; b := input.getCurrent()->toLong() ; var c : long ; c := input.getCurrent()->toLong() ; var sum : long ; sum := 0 ; var min : long ; min := 0 ; if (n mod 4 = 0) then min := 0 else if (n mod 4 = 1) then ( min := 3 * a ; if (min > b + a) then min := b + a ; else skip ; if (min > c) then min := c ; else skip ) else if (n mod 4 = 2) then ( min := a * 2 ; if (min > b * 1) then min := b ; else skip ; if (min > c * 2) then min := c * 2 ; else skip ; if (min > a + b + c) then min := a + b + c ; else skip ) else ( min := a ; if (min > b + c) then min := b + c ; else skip ; if (min > 3 * c) then min := 3 * c ; else skip ) ; ; ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class C { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); long n=in.nextLong(),a=in.nextLong(),b=in.nextLong(),c=in.nextLong(); long ans=Long.MAX_VALUE ; for(long A=0 ; A<4 ; A++){ for(long B=0 ; B<4 ; B++){ for(long C=0 ; C<4 ; C++){ if((n+A+B*2+C*3)% 4==0){ ans=Math.min(ans,A*a+B*b+C*c); } } } } pw.println(ans); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class C { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : long ; n := in.getCurrent()->toLong() ; var a : long ; a := in.getCurrent()->toLong() ; var b : long ; b := in.getCurrent()->toLong() ; var c : long ; c := in.getCurrent()->toLong() ; var ans : long ; ans := "9223372036854775807"->toLong() ; var A : long ; A := 0 ; while A < 4 do ( ( var B : long ; B := 0 ; while B < 4 do ( ( var C : long ; C := 0 ; while C < 4 do ( ( if ((n + A + B * 2 + C * 3) mod 4 = 0) then ( ans := Set{ans, A * a + B * b + C * c}->min() ) else skip ) ; C := C + 1 ) ) ; B := B + 1 ) ) ; A := A + 1 ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n/2]; int[] b=new int[n/2]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n / 2)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n / 2)->collect(0) ; var i : int ; i := 0 ; while i < n / 2 do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans_a1 : int ; ans_a1 := 1 ; var ans_a2 : int ; ans_a2 := 1 ; var ans_b1 : int ; ans_b1 := 1 ; var ans_b2 : int ; ans_b2 := 1 ; a := a->sort() ; b := b->sort() ; var k : int ; k := 1 ; var l : int ; l := 1 ; var x1 : int ; x1 := a[0+1] ; var y1 : int ; y1 := b[0+1] ; var i : int ; i := 1 ; while i < n / 2 do ( ( if (a[i+1] = a[i - 1+1]) then ( k := k + 1 ; if (ans_a1 <= k) then ( ans_a2 := ans_a1 ; ans_a1 := k ; x1 := a[i - 1+1] ) else if (ans_a2 <= k) then ans_a2 := k ; else skip ; ) else k := 1 ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n / 2 do ( ( if (b[i+1] = b[i - 1+1]) then ( l := l + 1 ; if (ans_b1 <= l) then ( ans_b2 := ans_b1 ; ans_b1 := l ; y1 := b[i - 1+1] ) else if (ans_b2 <= l) then ans_b2 := l ; else skip ; ) else l := 1 ; ) ; i := i + 1 ) ; var ans : int ; ans := n - (ans_a1 + ans_b1) ; if (ans_a1 = n / 2) then ans_a2 := 0 ; else skip ; if (ans_b1 = n / 2) then ans_b2 := 0 ; else skip ; if (x1 = y1) then ans := Set{n - (ans_a1 + ans_b2), n - (ans_b1 + ans_a2)}->min() ; else skip ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p120 implements EulerSolution { public static void main(String[] args){ System.out.println(new p120().run()); } public String run(){ int sum=0 ; for(int a=3 ; a<=1000 ; a++)sum+=a*(a-(a % 2==0 ? 2 : 1)); return Integer.toString(sum); } } ------------------------------------------------------------ OCL File: --------- class p120 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p120.newp120().run()) ); operation run() : String pre: true post: true activity: ( var sum : int ; sum := 0 ; var a : int ; a := 3 ; while a <= 1000 do ( sum := sum+(a * (a - (if a mod 2 = 0 then 2 else 1 endif))) ; ; a := a + 1 ) ; return ((sum) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int count_carry(String a,String b){ int carry=0 ; int count=0 ; int len_a=a.length(),len_b=b.length(); while(len_a!=0 || len_b!=0){ int x=0,y=0 ; if(len_a>0){ x=a.charAt(len_a-1)-'0' ; len_a--; } if(len_b>0){ y=b.charAt(len_b-1)-'0' ; len_b--; } int sum=x+y+carry ; if(sum>=10){ carry=1 ; count++; } else carry=0 ; } return count ; } public static void main(String[] args){ String a="9555",b="555" ; int count=count_carry(a,b); if(count==0)System.out.println("0\n"); else if(count==1)System.out.println("1\n"); else System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count_carry( a : String, b : String) : int pre: true post: true activity: ( var carry : int ; carry := 0 ; var count : int ; count := 0 ; var len_a : int ; len_a := a->size() ; var len_b : int ; len_b := b->size() ; while (len_a /= 0 or len_b /= 0) do ( var x : int ; x := 0 ; var y : int ; y := 0 ; if (len_a > 0) then ( x := a->at(len_a - 1+1) - ('0')->char2byte() ; len_a := len_a - 1 ) else skip ; if (len_b > 0) then ( y := b->at(len_b - 1+1) - ('0')->char2byte() ; len_b := len_b - 1 ) else skip ; var sum : int ; sum := x + y + carry ; if (sum >= 10) then ( carry := 1 ; count := count + 1 ) else carry := 0 ; ; ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : String ; a := "9555" ; var b : String ; b := "555" ; var count : int ; count := count_carry(a, b) ; if (count = 0) then OclFile["System.out"].println("0\n") ; else if (count = 1) then OclFile["System.out"].println("1\n") else OclFile["System.out"].println(count) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void shortestDistance(String S,char X){ int prev=Integer.MAX_VALUE ; Vectorans=new Vector<>(); for(int i=0 ; i=0 ; i--){ if(S.charAt(i)==X)prev=i ; ans.set(i,Math.min(ans.get(i),prev-i)); } for(Integer val : ans)System.out.print(val+" "); } public static void main(String[] args){ String S="geeksforgeeks" ; char X='g' ; shortestDistance(S,X); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation shortestDistance( S : String, X : String) : void pre: true post: true activity: ( var prev : int ; prev := 2147483647 ; var ans : Sequence(int) ; ans := Sequence{} ; var i : int ; i := 0 ; while i < S->size() do ( ( if (S->at(i+1) = X) then prev := i ; else skip ; ans := ans->including(i - prev) ) ; i := i + 1 ) ; prev := 2147483647 ; var i : int ; i := S->size() - 1 ; while i >= 0 do ( ( if (S->at(i+1) = X) then prev := i ; else skip ; ans := ans.setAt(i+1,Set{ans->at(i+1), prev - i}->min()) ) ; i := i - 1 ) ; for (val : ans) do ( OclFile["System.out"].print(val + " ") ; ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : String ; S := "geeksforgeeks" ; var X : String ; X := 'g' ; execute shortestDistance(S, X) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int zz=0 ; zzf=new ArrayList<>(); ArrayLists=new ArrayList<>(); boolean x=true ; for(int i=0 ; itoInteger() ; var zz : int ; zz := 0 ; while zz < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var f : Sequence(int) ; f := Sequence{} ; var s : Sequence(int) ; s := Sequence{} ; var x : boolean ; x := true ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := i + 1 ; if (i mod 2 /= 0) then ( if (((a[i+1] + k) * a[i - 1+1]) mod 4 = 0) then ( f := f->including(a[i+1]) ; s := s->including(a[i - 1+1]) ) else if (((a[i - 1+1] + k) * a[i+1]) mod 4 = 0) then ( f := f->including(a[(i - 1)+1]) ; s := s->including(a[i+1]) ) else ( x := false ) ; ) else skip ) ; i := i + 1 ) ; if (x) then ( OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < n / 2 do ( ( OclFile["System.out"].println(f->at(i+1) + " " + s->at(i+1)) ) ; i := i + 1 ) ) else OclFile["System.out"].println("NO") ; ; ) ; zz := zz + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashSet ; import java.util.LinkedList ; import java.util.ListIterator ; import java.util.PriorityQueue ; import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ final String input=sc.next(); if("0.0".equals(input)){ break ; } final double error=Double.parseDouble(input); final double upper_bound=Math.PI+error ; final double lower_bound=Math.PI-error ; for(int denom=1 ; ; denom++){ int lower=(int)(Math.ceil(lower_bound*denom)); int upper=(int)(upper_bound*denom); final double denom_d=(double)denom ; final double low_d=lower/denom_d ; final double high_d=upper/denom_d ; if(upper_bound>=low_d && low_d>=lower_bound){ System.out.println(lower+"/"+denom); break ; } else if(upper_bound>=high_d && high_d>=upper_bound){ System.out.println(upper+"/"+denom); break ; } } } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var input : String ; input := sc.getCurrent() ; if ("0.0" = input) then ( break ) else skip ; var error : double ; error := (input)->toReal() ; var upper_bound : double ; upper_bound := 3.141592653589793 + error ; var lower_bound : double ; lower_bound := 3.141592653589793 - (error)->char2byte() ; var denom : int ; denom := 1 ; while true do ( ( var lower : int ; lower := ((lower_bound * denom)->ceil())->oclAsType(int) ; var upper : int ; upper := (upper_bound * denom)->oclAsType(int) ; var denom_d : double ; denom_d := denom->oclAsType(double) ; var low_d : double ; low_d := lower / denom_d ; var high_d : double ; high_d := upper / denom_d ; if (upper_bound >= low_d & low_d >= lower_bound) then ( OclFile["System.out"].println(lower + "/" + denom) ; break ) else if (upper_bound >= high_d & high_d >= upper_bound) then ( OclFile["System.out"].println(upper + "/" + denom) ; break ) else skip ; ; ) ; denom := denom + 1 ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A_Panoramix_s_Prediction { public static void main(String[] args){ Scanner sn=new Scanner(System.in); int a=sn.nextInt(); int b=sn.nextInt(); int count=0 ; boolean flag=false ; ; if(isPrime(a)&& isPrime(b))flag=true ; for(int i=a ; i<=b ; i++){ if(isPrime(i))count++; } if(count==2 && flag==true)System.out.println("YES"); else System.out.println("NO"); } public static boolean isPrime(int n){ if(n<=1)return false ; else if(n==2)return true ; else if(n % 2==0)return false ; for(int i=3 ; i<=Math.sqrt(n); i+=2){ if(n % i==0)return false ; } return true ; } } ------------------------------------------------------------ OCL File: --------- class A_Panoramix_s_Prediction { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sn : OclFile ; sn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sn.getCurrent()->toInteger() ; var b : int ; b := sn.getCurrent()->toInteger() ; var count : int ; count := 0 ; var flag : boolean ; flag := false ; if (isPrime(a) & isPrime(b)) then flag := true ; else skip ; var i : int ; i := a ; while i <= b do ( ( if (isPrime(i)) then count := count + 1 ; else skip ) ; i := i + 1 ) ; if (count = 2 & flag = true) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); static operation isPrime( n : int) : boolean pre: true post: true activity: ( if (n <= 1) then return false else if (n = 2) then return true else if (n mod 2 = 0) then return false else skip ; ; ; var i : int ; i := 3 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then return false else skip ) ; i := i+(2) ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class code { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int temp=0,flag=1,t=0 ; for(int i=2 ; i<51 ; i++){ flag=1 ; for(int j=2 ; j<=i/2 ; j++){ if(i % j==0){ flag=0 ; break ; } } if(flag==1 && i>n){ if(temp==0)temp=i ; if(i==m && temp==i){ t=1 ; break ; } } } if(t==1)System.out.println("YES"); else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class code { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var temp : int ; temp := 0 ; var flag : int ; flag := 1 ; var t : int ; t := 0 ; var i : int ; i := 2 ; while i < 51 do ( ( flag := 1 ; var j : int ; j := 2 ; while j <= i / 2 do ( ( if (i mod j = 0) then ( flag := 0 ; break ) else skip ) ; j := j + 1 ) ; if (flag = 1 & i > n) then ( if (temp = 0) then temp := i ; else skip ; if (i = m & temp = i) then ( t := 1 ; break ) else skip ) else skip ) ; i := i + 1 ) ; if (t = 1) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class A80 { static Scanner sc=new Scanner(); public static void main(String[] args){ solve(); } public static void solve(){ int n=sc.nextInt(),m=sc.nextInt(); int i=n ; while(true){ int cnt=0 ; i++; for(int k=2 ; ktoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var i : int ; i := n ; while (true) do ( var cnt : int ; cnt := 0 ; i := i + 1 ; var k : int ; k := 2 ; while k < i do ( ( if (i mod k = 0) then ( cnt := cnt + 1 ) else skip ) ; k := k + 1 ) ; if (cnt = 0) then ( break ) else skip ) ; OclFile["System.out"].print(if (i = m) then "YES" else "NO" endif) ); static class Scanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); char[] c=s.toCharArray(); char temp=' ' ; int count1=0 ; int count2=0 ; for(int i=0 ; itoInteger() ; var s : String ; s := sc.getCurrent() ; var c : Sequence(String) ; c := s->characters() ; var temp : String ; temp := ' ' ; var count1 : int ; count1 := 0 ; var count2 : int ; count2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (c[i+1] /= temp) then ( count2 := count2 + 1 ; if (count2 = 2) then ( count1 := count1 + 1 ; count2 := 0 ; temp := ' ' ) else temp := c[i+1] ; ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] f1=new int[100001]; int[] f2=new int[100001]; int[] arr=new int[n]; StringBuffer sb=new StringBuffer(); for(int i=0 ; i=l11){ l11=f1[i]; i11=i ; } if(f2[i]>=l21){ l21=f2[i]; i21=i ; } } for(int i=0 ; i<=100000 ; i++){ if(i!=i11){ if(f1[i]>=l12){ l12=f1[i]; i12=i ; } } if(i!=i21){ if(f2[i]>=l22){ l22=f2[i]; i22=i ; } } } if(i11!=i21)System.out.println(n/2-l11+n/2-l21); else { int x=Math.max(l11+l22,l12+l21); System.out.println(n-x); } } static boolean check(int n){ int x=n % 10 ; n/=10 ; if(n % 10!=x)return false ; n/=10 ; if(n % 10!=x)return false ; return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var f1 : Sequence(int) ; f1 := Integer.subrange(1,100001)->collect(0) ; var f2 : Sequence(int) ; f2 := Integer.subrange(1,100001)->collect(0) ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; if (i mod 2 = 0) then f1[arr[i+1]+1] := f1[arr[i+1]+1] + 1 ; else f2[arr[i+1]+1] := f2[arr[i+1]+1] + 1 ; ) ; i := i + 1 ) ; var l11 : int ; l11 := 0 ; var l12 : int ; l12 := 0 ; var l21 : int ; l21 := 0 ; var l22 : int ; l22 := 0 ; var i11 : int ; i11 := 0 ; var i12 : int ; i12 := 0 ; var i21 : int ; i21 := 0 ; var i22 : int ; i22 := 0 ; var i : int ; i := 0 ; while i <= 100000 do ( ( if (f1[i+1] >= l11) then ( l11 := f1[i+1] ; i11 := i ) else skip ; if (f2[i+1] >= l21) then ( l21 := f2[i+1] ; i21 := i ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= 100000 do ( ( if (i /= i11) then ( if (f1[i+1] >= l12) then ( l12 := f1[i+1] ; i12 := i ) else skip ) else skip ; if (i /= i21) then ( if (f2[i+1] >= l22) then ( l22 := f2[i+1] ; i22 := i ) else skip ) else skip ) ; i := i + 1 ) ; if (i11 /= i21) then OclFile["System.out"].println(n / 2 - l11 + n / 2 - l21) else ( var x : int ; x := Set{l11 + l22, l12 + l21}->max() ; OclFile["System.out"].println(n - x) ) ; ); static operation check( n : int) : boolean pre: true post: true activity: ( var x : int ; x := n mod 10 ; n := n/(10) ; if (n mod 10 /= x) then return false else skip ; n := n/(10) ; if (n mod 10 /= x) then return false else skip ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); String S=sc.next(); Listlist=new ArrayList(); char[] C=S.toCharArray(); for(int i=0 ; itoInteger() ; var S : String ; S := sc.getCurrent() ; var list : Sequence(String) ; list := Sequence{} ; var C : Sequence(String) ; C := S->characters() ; var i : int ; i := 0 ; while i < N do ( ( list := list->including(C[i+1]) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N - 1 do ( ( if (not((list->at(i+1) = list->at(i + 1+1)))) then ( count := count + 1 ; i := i + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int count=0 ; try { String N=br.readLine(); int n=Integer.parseInt(N); String ox=br.readLine(); String[] o_x=ox.split(""); for(int i=0 ; itoInteger() ; var ox : String ; ox := br.readLine() ; var o_x : Sequence(String) ; o_x := ox->split("") ; var i : int ; i := 0 ; while i < ox->size() do ( ( if (i = (n)->char2byte() - 1) then ( continue ) else skip ; if (ox->at(i+1) /= ox->at(i + 1+1)) then ( count := count + 1 ; i := i + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char stmp[]=new char[n]; String str=sc.next(); int count=0 ; for(int i=0 ; itoInteger() ; var stmp : Sequence(String) ; stmp := Integer.subrange(1,n)->collect(0) ; var str : String ; str := sc.getCurrent() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( stmp[i+1] := str->at(i+1) ; ; i := i + 1 ) ; var lastc : String ; lastc := stmp[0+1] ; var i : int ; i := 1 ; while i < n do ( ( if (i = n - 1 & stmp[i+1] /= lastc) then count := count + 1 ; else if (stmp[i+1] /= lastc) then ( count := count + 1 ; lastc := stmp[i + 1+1] ; i := i + 1 ) else lastc := stmp[i+1] ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n,m,r ; n=sc.nextInt(); m=sc.nextInt(); r=sc.nextInt(); if(r-n*m<0){ System.out.println("0"); return ; } BigInteger ZERO=BigInteger.ZERO ; BigInteger ONE=BigInteger.ONE ; BigInteger b=ONE,k ; BigInteger lb=new BigInteger(Integer.toString(r-n*m)); k=new BigInteger(Integer.toString(r-n*m+n-1)); while(k.compareTo(lb)>0){ b=b.multiply(k); k=k.subtract(ONE); } k=new BigInteger(Integer.toString(n-1)); while(k.compareTo(ZERO)>0){ b=b.divide(k); k=k.subtract(ONE); } System.out.println(b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var m : int ; var r : int ; n := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; r := sc.getCurrent()->toInteger() ; if (r - n * m < 0) then ( OclFile["System.out"].println("0") ; return ) else skip ; var ZERO : long ; ZERO := 0 ; var ONE : long ; ONE := 1 ; var b : long ; b := ONE ; var k : long ; var lb : long ; lb := long(((r - n * m) + "")) ; k := long(((r - n * m + n - 1) + "")) ; while (k->compareTo(lb) > 0) do ( b := b.multiply(k) ; k := k.subtract(ONE) ) ; k := long(((n - 1) + "")) ; while (k->compareTo(ZERO) > 0) do ( b := b.divide(k) ; k := k.subtract(ONE) ) ; OclFile["System.out"].println(b) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String input_str[]=new String[3]; input_str=br.readLine().split("\\s+"); int N=Integer.parseInt(input_str[0]); int M=Integer.parseInt(input_str[1]); int R=Integer.parseInt(input_str[2]); if(N*M>R){ System.out.println(0); return ; } int num=R-M*N+N-1 ; int[] bunbo=new int[N]; for(int i=0 ; i=2 ; i--){ tmp=i ; for(int k=0 ; kcollect(null) ; input_str := br.readLine()->split("\\s+") ; var N : int ; N := (input_str[0+1])->toInteger() ; var M : int ; M := (input_str[1+1])->toInteger() ; var R : int ; R := (input_str[2+1])->toInteger() ; if (N * M > R) then ( OclFile["System.out"].println(0) ; return ) else skip ; var num : int ; num := R - M * N + N - 1 ; var bunbo : Sequence(int) ; bunbo := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < (N)->char2byte() - 1 do ( ( bunbo[i+1] := num - i ) ; i := i + 1 ) ; var tmp : int ; var common : int ; var i : int ; i := (N)->char2byte() - 1 ; while i >= 2 do ( ( tmp := i ; var k : int ; k := 0 ; while k < (N)->char2byte() - 1 do ( ( if (bunbo[k+1] = 1) then continue else skip ; common := gcd(tmp, bunbo[k+1]) ; if (common = 1) then continue else skip ; tmp := tmp/(common) ; bunbo[k+1] := bunbo[k+1]/(common) ; if (tmp = 1) then break else skip ; ) ; k := k + 1 ) ) ; i := i - 1 ) ; var ANS : long ; ANS := long("1") ; var i : int ; i := 0 ; while i < (N)->char2byte() - 1 do ( ( ANS := ANS.multiply(long(((bunbo[i+1]) + ""))) ) ; i := i + 1 ) ; OclFile["System.out"].println(ANS+"") ; ) catch (e : IncorrectElementException) do ( e.printStackTrace() ) catch (e : IOException) do ( e.printStackTrace() ) ); static operation gcd( A : int, B : int) : int pre: true post: true activity: ( if (A < B) then ( var tmp : int ; tmp := B ; B := A ; A := tmp ) else skip ; if (B = 0) then ( return A ) else ( return gcd(B, A mod B) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.math.BigDecimal ; class Main { static String permutation(int x,int y,int z){ if(z>y){ int tmp=y ; y=z ; z=tmp ; } BigDecimal result=BigDecimal.ONE ; int counter=1 ; for(int i=y+1 ; i<=x ; i++){ result=result.multiply(new BigDecimal(String.valueOf(i))); if(counter<=z){ result=result.divide(new BigDecimal(String.valueOf(counter))); counter++; } } for(int i=counter ; i<=z ; i++){ result=result.divide(new BigDecimal(String.valueOf(counter))); } return result.toString(); } public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().split(" "); int n=Integer.parseInt(input[0]); int m=Integer.parseInt(input[1]); int r=Integer.parseInt(input[2]); int nm=n*m ; if(r y) then ( var tmp : int ; tmp := y ; y := z ; z := tmp ) else skip ; var result : double ; result := 1.0 ; var counter : int ; counter := 1 ; var i : int ; i := y + 1 ; while i <= x do ( ( result := result.multiply(double(((i) + ""))) ; if (counter <= z) then ( result := result.divide(double(((counter) + ""))) ; counter := counter + 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := counter ; while i <= z do ( ( result := result.divide(double(((counter) + ""))) ) ; i := i + 1 ) ; return result+"" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var input : Sequence(String) ; input := br.readLine()->split(" ") ; var n : int ; n := (input[0+1])->toInteger() ; var m : int ; m := (input[1+1])->toInteger() ; var r : int ; r := (input[2+1])->toInteger() ; var nm : int ; nm := n * m ; if (r < nm) then ( OclFile["System.out"].println("0") ; return ) else skip ; var beads : int ; beads := r - nm ; OclFile["System.out"].println(permutation(beads + n - 1, beads, n - 1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.PrintWriter ; import java.math.BigInteger ; class Main { void solve(){ int N=cin.nextInt(); int M=cin.nextInt(); int R=cin.nextInt(); if(N*M>R){ cout.println(0); return ; } int RR=R-N*M ; BigInteger ans=new BigInteger("1"); for(int i=2 ; i<=RR+N-1 ; i++){ ans=ans.multiply(new BigInteger(""+i)); } for(int i=2 ; i<=RR ; i++){ ans=ans.divide(new BigInteger(""+i)); } for(int i=2 ; i<=N-1 ; i++){ ans=ans.divide(new BigInteger(""+i)); } cout.println(ans); } public static void main(String args[]){ cin=new Inputer(); cout=new PrintWriter(System.out); new Main().solve(); cout.flush(); } static class Inputer { private static Scanner sc ; Inputer(){ sc=new Scanner(System.in); } String next(){ return sc.next(); } int nextInt(){ return Integer.parseInt(sc.next()); } long nextLong(){ return Long.parseLong(sc.next()); } double nextDouble(){ return Double.parseDouble(sc.next()); } char[] nextCharArray(){ return sc.next().toCharArray(); } } private static Inputer cin ; private static PrintWriter cout ; } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var N : int ; N := cin.nextInt() ; var M : int ; M := cin.nextInt() ; var R : int ; R := cin.nextInt() ; if (N * M > R) then ( cout.println(0) ; return ) else skip ; var RR : int ; RR := R - N * M ; var ans : long ; ans := long("1") ; var i : int ; i := 2 ; while i <= RR + N - 1 do ( ( ans := ans.multiply(long("" + i)) ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= RR do ( ( ans := ans.divide(long("" + i)) ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= N - 1 do ( ( ans := ans.divide(long("" + i)) ) ; i := i + 1 ) ; cout.println(ans) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( cin := Inputer.newInputer() ; cout := OclFile.newOclFile_Write(OclFile["System.out"]) ; Main.newMain().solve() ; cout.flush() ); static class Inputer { static attribute sc : OclFile; static operation newInputer() : Inputer pre: true post: true activity: ( var self : Inputer ; self := createInputer(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ); operation next() : String pre: true post: true activity: ( return sc.getCurrent() ); operation nextInt() : int pre: true post: true activity: ( return (sc.getCurrent())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (sc.getCurrent())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (sc.getCurrent())->toReal() ); operation nextCharArray() : Sequence(String) pre: true post: true activity: ( return sc.getCurrent()->characters() ); } static attribute cin : Inputer; static attribute cout : OclFile; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ while(scanner.hasNextLine()){ String[] tmp=scanner.nextLine().split(" "); int n=Integer.valueOf(tmp[0]); int m=Integer.valueOf(tmp[1]); int r=Integer.valueOf(tmp[2]); System.out.println(solver(n,m,r)); } } } private static BigInteger solver(int n,int m,int r){ if(n*m>r){ return new BigInteger("0"); } if(n*m==r){ return new BigInteger("1"); } return hcombination(n,r-(n*m)); } private static BigInteger hcombination(int n,int r){ BigInteger fact_a=fact(n+r-1); BigInteger fact_b=fact(r); BigInteger fact_c=fact(n-1); return fact_a.divide(fact_b.multiply(fact_c)); } private static BigInteger fact(int n){ BigInteger ans=new BigInteger("1"); for(int i=n ; i>1 ; i--){ ans=ans.multiply(new BigInteger(String.valueOf(i))); } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while (scanner.hasNextLine()) do ( var tmp : Sequence(String) ; tmp := scanner.nextLine()->split(" ") ; var n : int ; n := (tmp[0+1])->toInteger() ; var m : int ; m := (tmp[1+1])->toInteger() ; var r : int ; r := (tmp[2+1])->toInteger() ; OclFile["System.out"].println(solver(n, m, r)) ; ) )) ); static operation solver( n : int, m : int, r : int) : long pre: true post: true activity: ( if (n * m > r) then ( return long("0") ) else skip ; if (n * m = r) then ( return long("1") ) else skip ; return hcombination(n, r - (n * m)) ); static operation hcombination( n : int, r : int) : long pre: true post: true activity: ( var fact_a : long ; fact_a := fact(n + r - 1) ; var fact_b : long ; fact_b := fact(r) ; var fact_c : long ; fact_c := fact(n - 1) ; return fact_a.divide(fact_b.multiply(fact_c)) ); static operation fact( n : int) : long pre: true post: true activity: ( var ans : long ; ans := long("1") ; var i : int ; i := n ; while i > 1 do ( ( ans := ans.multiply(long(((i) + ""))) ) ; i := i - 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static void SubString(String str,int n){ for(int i=0 ; isize()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX_INT=1000000 ; static int solve(int[] array,int N){ int[][] pos=new int[5][10000]; int[] pref=new int[5]; if(array[0]==0){ pref[0]=1 ; pos[0][pos[0] .length-1]=0 ; } int ans=MAX_INT ; for(int i=1 ; i0){ pref[array[i] ]++; pos[array[i] ][pos[array[i] ] .length-1]=i ; if(array[i]==4){ int end=i ; int start=i ; for(int j=3 ; j>=0 ; j--){ int s=0 ; int e=pos[j] .length-1 ; int temp=-1 ; while(s<=e){ int m=(s+e)/2 ; if(pos[j][m]<=start){ temp=pos[j][m]; s=m+1 ; } else e=m-1 ; } start=temp ; } ans=Math.min(ans,end-start+1); } } } } return ans ; } public static void main(String[] args){ int[] array={ 0,1,2,3,4,2,0,3,4 }; int N=array.length ; System.out.println(solve(array,N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX_INT : int := 1000000; static operation solve( array : Sequence(int), N : int) : int pre: true post: true activity: ( var pos : Sequence(Sequence(int)) ; pos := Integer.subrange(1,5)->collect(Integer.subrange(1,10000)->collect(0)) ; var pref : Sequence(int) ; pref := Integer.subrange(1,5)->collect(0) ; if (array[0+1] = 0) then ( pref[0+1] := 1 ; pos[0+1][pos[0+1]->size() - 1+1] := 0 ) else skip ; var ans : int ; ans := MAX_INT ; var i : int ; i := 1 ; while i < N do ( ( if (array[i+1] = 0) then ( pref[0+1] := pref[0+1] + 1 ; pos[0+1][pos[0+1]->size() - 1+1] := i ) else ( if (pref[array[i+1] - 1+1] > 0) then ( pref[array[i+1]+1] := pref[array[i+1]+1] + 1 ; pos[array[i+1]+1][pos[array[i+1]+1]->size() - 1+1] := i ; if (array[i+1] = 4) then ( var end : int ; end := i ; var start : int ; start := i ; var j : int ; j := 3 ; while j >= 0 do ( ( var s : int ; s := 0 ; var e : int ; e := pos[j+1]->size() - 1 ; var temp : int ; temp := -1 ; while (s <= e) do ( var m : int ; m := (s + e) / 2 ; if (pos[j+1][m+1] <= start) then ( temp := pos[j+1][m+1] ; s := m + 1 ) else e := m - 1 ; ) ; start := temp ; ) ; j := j - 1 ) ; ans := Set{ans, end - start + 1}->min() ) else skip ) else skip ) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var array : Sequence(int) ; array := Sequence{0,1,2,3,4,2,0,3,4} ; var N : int ; N := array->size() ; OclFile["System.out"].println(solve(array, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void perfectSquares(int l,int r){ for(int i=l ; i<=r ; i++){ if(Math.sqrt(i)==(int)Math.sqrt(i))System.out.print(i+" "); } } public static void main(String[] args){ int l=2,r=24 ; perfectSquares(l,r); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation perfectSquares( l : int, r : int) : void pre: true post: true activity: ( var i : int ; i := l ; while i <= r do ( ( if ((i)->sqrt() = (i)->sqrt()->oclAsType(int)) then OclFile["System.out"].print(i + " ") ; else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 2 ; var r : int ; r := 24 ; execute perfectSquares(l, r) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void solve(long a,long b){ if(a>0 && b>0){ System.out.println("Positive"); } else if(a<=0 && b>=0){ System.out.println("Zero"); } else { long n=Math.abs(a-b)+1 ; if(n % 2==0){ System.out.println("Positive"); } else { System.out.println("Negative"); } } } public static void main(String[] args){ int a=-10,b=-2 ; solve(a,b); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solve( a : long, b : long) : void pre: true post: true activity: ( if (a > 0 & b > 0) then ( OclFile["System.out"].println("Positive") ) else if (a <= 0 & b >= 0) then ( OclFile["System.out"].println("Zero") ) else ( var n : long ; n := if a - b < 0 then -(a - b) else a - b endif + 1 ; if (n mod 2 = 0) then ( OclFile["System.out"].println("Positive") ) else ( OclFile["System.out"].println("Negative") ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := -10 ; var b : int ; b := -2 ; execute solve(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Solution { public static void main(String[] args)throws IOException { BufferedReader bufferReader=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); StringTokenizer st=new StringTokenizer(bufferReader.readLine()); int n=Integer.parseInt(st.nextToken()); int max=0 ; Map>map=new HashMap<>(); MaplastIndex=new HashMap<>(); Listans=new ArrayList<>(); st=new StringTokenizer(bufferReader.readLine()); for(int i=1 ; i<=n ; i++){ int cur=Integer.parseInt(st.nextToken()); max=Math.max(max,cur); if(! map.containsKey(cur)){ map.put(cur,new HashSet<>()); } else { Setindexes=map.get(cur); indexes.add(i-lastIndex.get(cur)); } lastIndex.put(cur,i); } for(int i=1 ; i<=max ; i++){ if(map.containsKey(i)&& map.get(i).size()<=1){ ans.add(new int[] { i,map.get(i).size()==0 ? 0 : map.get(i).iterator().next()} ); } } out.println(ans.size()); for(int[] cur : ans)out.println(cur[0]+" "+cur[1]); out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bufferReader : OclFile ; bufferReader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(bufferReader.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var max : int ; max := 0 ; var map : Map(int,Set(int)) ; map := Map{} ; var lastIndex : Map(int,int) ; lastIndex := Map{} ; var ans : Sequence(Sequence(int)) ; ans := Sequence{} ; st := OclIterator.newOclIterator_String(bufferReader.readLine()) ; var i : int ; i := 1 ; while i <= n do ( ( var cur : int ; cur := (st.next())->toInteger() ; max := Set{max, cur}->max() ; if (not(map->keys()->includes(cur))) then ( map := map->union(Map{cur |-> Set{}}) ) else ( var indexes : Set(int) ; indexes := map->at(cur) ; indexes := indexes->including(i - lastIndex->at(cur)) ) ; lastIndex := lastIndex->union(Map{cur |-> i}) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= max do ( ( if (map->keys()->includes(i) & map->at(i)->size() <= 1) then ( ans := ans->including(Sequence{i,if map->at(i)->size() = 0 then 0 else map->at(i)->iterator().next() endif}) ) else skip ) ; i := i + 1 ) ; skip ; for (cur : ans) do ( skip ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void solve(String s){ String z=s ; int l=s.length(); int i ; String str ; if(s.indexOf('+')!=-1){ i=s.indexOf('+'); str=s.replace('+','-'); } else { i=s.indexOf('-'); str=s.replace('-','+'); } System.out.println("Conjugate of "+z+"="+str); } public static void main(String[] args){ String s="3-4i" ; solve(s); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solve( s : String) : void pre: true post: true activity: ( var z : String ; z := s ; var l : int ; l := s->size() ; var i : int ; var str : String ; if (s->indexOf('+')-1 /= -1) then ( i := s->indexOf('+')-1 ; str := s.replace('+', '-') ) else ( i := s->indexOf('-')-1 ; str := s.replace('-', '+') ) ; OclFile["System.out"].println("Conjugate of " + z + "=" + str) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "3-4i" ; execute solve(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces { public static void main(String[] args){ Scanner kali=new Scanner(System.in); String lucky_num=kali.next(); int count=0 ; for(int i=0 ; isize() do ( ( if (lucky_num->at(i+1) = '4' or lucky_num->at(i+1) = '7') then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; var temp : String ; temp := count + "" ; if (temp->includes("4") or temp->includes("7")) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Codesolver { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n ; n=sc.nextLong(); long carry=0 ; int sum=0 ; while(n!=0){ carry=n % 10 ; if(carry==4 || carry==7){ sum++; } n=n/10 ; } System.out.println((sum==7 || sum==4)? "YES" : "NO"); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Codesolver { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var carry : long ; carry := 0 ; var sum : int ; sum := 0 ; while (n /= 0) do ( carry := n mod 10 ; if (carry = 4 or carry = 7) then ( sum := sum + 1 ) else skip ; n := n / 10 ) ; OclFile["System.out"].println(if (sum = 7 or sum = 4) then "YES" else "NO" endif) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); double EPS=1e-10 ; for(; ; ){ double R=sc.nextDouble(); if(R==0)break ; int n=1,d=1 ; double min=1<<29 ; int an=0,ad=1<<29 ; while(d<=ad){ double r=Math.PI-n*1.0/d ; double e=Math.abs(r); if(etoReal() ; if (R = 0) then break else skip ; var n : int ; n := 1 ; var d : int ; d := 1 ; var min : double ; min := (1*(2->pow(29)))->oclAsType(long) ; var an : int ; an := 0 ; var ad : int ; ad := (1*(2->pow(29)))->oclAsType(long) ; while (d <= ad) do ( var r : double ; r := 3.141592653589793 - n * 1.0 / d ; var e : double ; e := if r < 0 then -(r) else r endif ; if (e < R + EPS & e < min) then ( min := e ; an := n ; ad := d ) else skip ; if (r < 0) then d := d + 1 ; else n := n + 1 ; ) ; OclFile["System.out"].println(an + "/" + ad) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Code_110A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int count=0 ; long n=sc.nextLong(); while(n!=0){ int temp=(int)(n % 10); if(temp==4 || temp==7)count++; n/=10 ; } System.out.println((count==4 || count==7)? "YES" : "NO"); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Code_110A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var count : int ; count := 0 ; var n : long ; n := sc.getCurrent()->toLong() ; while (n /= 0) do ( var temp : int ; temp := (n mod 10)->oclAsType(int) ; if (temp = 4 or temp = 7) then count := count + 1 ; else skip ; n := n/(10) ) ; OclFile["System.out"].println(if (count = 4 or count = 7) then "YES" else "NO" endif) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args)throws Exception { FastReader sc=new FastReader(); long n=sc.nextLong(); boolean flag=true ; int cnt=0 ; while(n!=0){ long res=n % 10 ; if(res==4 || res==7)cnt++; n=n/10 ; } if(cnt==0)flag=false ; while(cnt!=0){ int res=cnt % 10 ; if(!(res==4 || res==7)){ flag=false ; break ; } cnt=cnt/10 ; } if(flag)System.out.println("YES"); else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var n : long ; n := sc.nextLong() ; var flag : boolean ; flag := true ; var cnt : int ; cnt := 0 ; while (n /= 0) do ( var res : long ; res := n mod 10 ; if (res = 4 or res = 7) then cnt := cnt + 1 ; else skip ; n := n / 10 ) ; if (cnt = 0) then flag := false ; else skip ; while (cnt /= 0) do ( var res : int ; res := cnt mod 10 ; if (not((res = 4 or res = 7))) then ( flag := false ; break ) else skip ; cnt := cnt / 10 ) ; if (flag) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isPrime(int n){ if(n<=1)return false ; for(int i=2 ; isize() do ( ( if (a->at(i+1) = '7' or a->at(i+1) = '4') then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; if (count = 7 or count = 4) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B965 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int K=in.nextInt(); boolean[][] grid=new boolean[N][N]; for(int r=0 ; rbest){ best=count ; bestR=r ; bestC=c ; } } } System.out.println((bestR+1)+" "+(bestC+1)); } } ------------------------------------------------------------ OCL File: --------- class B965 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var grid : Sequence(Sequence(boolean)) ; grid := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(false)) ; var r : int ; r := 0 ; while r < N do ( ( var S : Sequence(String) ; S := in.getCurrent()->characters() ; var c : int ; c := 0 ; while c < N do ( ( if (S[c+1] = '.') then ( grid[r+1][c+1] := true ) else skip ) ; c := c + 1 ) ) ; r := r + 1 ) ; var stat : Sequence(Sequence(int)) ; stat := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; var r : int ; r := 0 ; while r < N do ( ( var c : int ; c := 0 ; while c < N do ( ( if (r + K <= N) then ( var ok : boolean ; ok := true ; var k : int ; k := 0 ; while k < K do ( ( ok := MathLib.bitwiseAnd(ok, grid[r + k+1][c+1]) ) ; k := k + 1 ) ; if (ok) then ( var k : int ; k := 0 ; while k < K do ( ( stat[r + k+1][c+1] := stat[r + k+1][c+1] + 1 ) ; k := k + 1 ) ) else skip ) else skip ; if (c + K <= N) then ( var ok : boolean ; ok := true ; var k : int ; k := 0 ; while k < K do ( ( ok := MathLib.bitwiseAnd(ok, grid[r+1][c + k+1]) ) ; k := k + 1 ) ; if (ok) then ( var k : int ; k := 0 ; while k < K do ( ( stat[r+1][c + k+1] := stat[r+1][c + k+1] + 1 ) ; k := k + 1 ) ) else skip ) else skip ) ; c := c + 1 ) ) ; r := r + 1 ) ; var bestR : int ; bestR := -1 ; var bestC : int ; bestC := -1 ; var best : int ; best := -1 ; var r : int ; r := 0 ; while r < N do ( ( var c : int ; c := 0 ; while c < N do ( ( var count : int ; count := stat[r+1][c+1] ; if (count > best) then ( best := count ; bestR := r ; bestC := c ) else skip ) ; c := c + 1 ) ) ; r := r + 1 ) ; OclFile["System.out"].println((bestR + 1) + " " + (bestC + 1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isprime(int x){ for(int i=2 ; i*i<=x ; i++)if(x % i==0)return false ; return true ; } static boolean isNSqMinusnMSqPrime(int m,int n){ if(n-m==1 && isprime(m+n))return true ; else return false ; } public static void main(String[] args){ int m=13,n=16 ; if(isNSqMinusnMSqPrime(m,n))System.out.println("YES"); else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isprime( x : int) : boolean pre: true post: true activity: ( var i : int ; i := 2 ; while i * i <= x do ( if (x mod i = 0) then return false else skip ; ; i := i + 1 ) ; return true ); static operation isNSqMinusnMSqPrime( m : int, n : int) : boolean pre: true post: true activity: ( if (n - m = 1 & isprime(m + n)) then return true else return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : int ; m := 13 ; var n : int ; n := 16 ; if (isNSqMinusnMSqPrime(m, n)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Solution { public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(reader.readLine()); double[] poss=new double[n]; StringTokenizer sToken=new StringTokenizer(reader.readLine()); for(int i=0 ; itoInteger() ; var poss : Sequence(double) ; poss := Integer.subrange(1,n)->collect(0.0) ; var sToken : OclIterator ; sToken := OclIterator.newOclIterator_String(reader.readLine()) ; var i : int ; i := 0 ; while i < n do ( poss[i+1] := (sToken.next())->toReal() ; ; i := i + 1 ) ; var dp : Sequence(Sequence(Sequence(double))) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,n + 1)->collect(Integer.subrange(1,2)->collect(0.0))) ; var max : double ; max := 0.0 ; var i : int ; i := 0 ; while i < n do ( ( var p1 : double ; p1 := poss[i+1] ; var p0 : double ; p0 := 1.0 - poss[i+1] ; var amount : int ; amount := 1 ; while amount <= n do ( ( var res1 : double ; res1 := p1 ; var res0 : double ; res0 := p0 ; var j : int ; j := 0 ; while j < i do ( ( if (res1 < dp[j+1][amount - 1+1][1+1] * p0 + dp[j+1][amount - 1+1][0+1] * p1) then ( res1 := dp[j+1][amount - 1+1][1+1] * p0 + dp[j+1][amount - 1+1][0+1] * p1 ; res0 := dp[j+1][amount - 1+1][0+1] * p0 ) else skip ) ; j := j + 1 ) ; dp[i+1][amount+1] := Sequence{res0,res1} ; max := Set{max, res1}->max() ) ; amount := amount + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { FastScanner in=new FastScanner(System.in); PrintWriter out=new PrintWriter(System.out); new Main().run(in,out); out.close(); } int N ; double[] d ; void run(FastScanner in,PrintWriter out){ N=in.nextInt(); d=new double[N]; for(int i=0 ; i=0 ; i--){ double curr=0 ; for(int j=i ; j<=halfIndex ; j++){ double p=1 ; for(int k=i ; k<=halfIndex ; k++){ if(j==k)p*=d[k]; else p*=(1-d[k]); } curr+=p ; } if(curr>=0.5d)break ; max2=Math.max(max2,curr); } out.println(String.format("%.10f",Math.max(max,max2))); } static class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner(InputStream in){ br=new BufferedReader(new InputStreamReader(in)); st=null ; } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastScanner ; in := FastScanner.newFastScanner(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; Main.newMain().run(in, out) ; skip ); attribute N : int; attribute d : Sequence(double); operation run( in : FastScanner, out : OclFile) : void pre: true post: true activity: ( N := in.nextInt() ; d := Integer.subrange(1,N)->collect(0.0) ; var i : int ; i := 0 ; while i < N do ( d[i+1] := (in.next())->toReal() ; ; i := i + 1 ) ; d := d->sort() ; var max : double ; max := d[N - 1+1] ; var max2 : double ; max2 := 0 ; var i : int ; i := 0 ; i := 0 ; while i < N & d[i+1] <= 0.5d do ( ; i := i + 1 ) ; i := i - 1 ; var halfIndex : int ; halfIndex := i ; while i >= 0 do ( ( var curr : double ; curr := 0 ; var j : int ; j := i ; while j <= halfIndex do ( ( var p : double ; p := 1 ; var k : int ; k := i ; while k <= halfIndex do ( ( if (j = k) then p := p*(d[k+1]) ; else p := p*((1 - d[k+1])) ; ) ; k := k + 1 ) ; curr := curr+(p) ) ; j := j + 1 ) ; if (curr >= 0.5d) then break else skip ; max2 := Set{max2, curr}->max() ) ; i := i - 1 ) ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner( in : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; st := null ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int m,i,h ; while(true){ String c=stdIn.next(); if(c.equals("-"))break ; m=stdIn.nextInt(); for(i=0 ; itoInteger() ; i := 0 ; while i < m do ( ( h := stdIn.getCurrent()->toInteger() ; var t : String ; t := c.subrange(0+1,h) ; c := c.subrange(h+1,c->size()) + t ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static String shuffle(String card,int num){ String ans="" ; for(int i=num ; ians=new ArrayList(); String card ; int shuffle ; while(true){ card=br.readLine(); if(card.equals("-"))break ; shuffle=Integer.parseInt(br.readLine()); for(int i=1 ; i<=shuffle ; i++)card=shuffle(card,Integer.parseInt(br.readLine())); ans.add(card); } for(String s : ans){ System.out.println(s); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation shuffle( card : String, num : int) : String pre: true post: true activity: ( var ans : String ; ans := "" ; var i : int ; i := num ; while i < card->size() do ( ( ans := ans+(card->at(i+1)) ) ; i := i + 1 ) ; return ans + card.subrange(0+1,num) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var ans : Sequence(String) ; ans := Sequence{} ; var card : String ; var shuffle : int ; while (true) do ( card := br.readLine() ; if (card = "-") then break else skip ; shuffle := (br.readLine())->toInteger() ; var i : int ; i := 1 ; while i <= shuffle do ( card := shuffle(card, (br.readLine())->toInteger()) ; ; i := i + 1 ) ; ans := ans->including(card) ; ) ; for (s : ans) do ( ( OclFile["System.out"].println(s) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { private static Scanner sc=new Scanner(System.in); private static ArrayListnumCardsShuffle=new ArrayList(); private static ArrayListresult=new ArrayList(); public static void main(String[] args){ doShuffles(); printResult(result); } public static void doShuffles(){ while(sc.hasNext()){ String cards=getCards(); if(cards==null){ break ; } setShuffleDetail(); result.add(getCardsShuffled(cards,numCardsShuffle)); numCardsShuffle.clear(); } } private static String getCards(){ String cards=sc.next(); if(cards.compareTo("-")==0){ return null ; } return cards ; } private static void setShuffleDetail(){ int numShuffle=sc.nextInt(); for(int i=0 ; inum){ String deck=str ; for(int i=0 ; iresult){ for(int i=0 ; iincluding(getCardsShuffled(cards, numCardsShuffle)) ; numCardsShuffle := numCardsShuffle->intersection(Set{}) ; ) ); static operation getCards() : String pre: true post: true activity: ( var cards : String ; cards := sc.getCurrent() ; if (cards->compareTo("-") = 0) then ( return null ) else skip ; return cards ); static operation setShuffleDetail() : void pre: true post: true activity: ( var numShuffle : int ; numShuffle := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < numShuffle do ( ( numCardsShuffle := numCardsShuffle->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ); static operation getCardsShuffled( str : String, num : Sequence(int)) : String pre: true post: true activity: ( var deck : String ; deck := str ; var i : int ; i := 0 ; while i < num->size() do ( ( var downDeck : String ; downDeck := deck.subrange(0+1,num->at(i+1)) ; var upDeck : String ; upDeck := deck.subrange(num->at(i+1)+1,str->size()) ; deck := upDeck + downDeck ) ; i := i + 1 ) ; return deck ); static operation printResult( result : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < result->size() do ( ( OclFile["System.out"].println(result->at(i+1)) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public static void main(String[] args){ for(int i=1 ; i<10 ; i++){ for(int j=1 ; j<10 ; j++){ System.out.println(i+"x"+j+"="+i*j); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < 10 do ( ( var j : int ; j := 1 ; while j < 10 do ( ( OclFile["System.out"].println(i + "x" + j + "=" + i * j) ) ; j := j + 1 ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args){ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); while(true){ try { String line=reader.readLine(); if(line.charAt(0)=='-')break ; int num=Integer.parseInt(reader.readLine()); for(int i=0 ; iat(0+1) = '-') then break else skip ; var num : int ; num := (reader.readLine())->toInteger() ; var i : int ; i := 0 ; while i < num do ( ( var j : int ; j := (reader.readLine())->toInteger() ; var sub1 : String ; sub1 := line.subrange(0+1,j) ; var sub2 : String ; sub2 := line.subrange(j+1,j) ; line := sub2+sub1 ) ; i := i + 1 ) ; OclFile["System.out"].println(line) ; ) catch (e : IOException) do ( OclFile["System.out"].println(e) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void angleextcycquad(int z){ System.out.print("The exterior angle of the"+" cyclic quadrilateral is "+z+" degrees"); } public static void main(String[] args){ int z=48 ; angleextcycquad(z); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation angleextcycquad( z : int) : void pre: true post: true activity: ( OclFile["System.out"].print("The exterior angle of the" + " cyclic quadrilateral is " + z + " degrees") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var z : int ; z := 48 ; execute angleextcycquad(z) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int length ; int sh ; int a ; StringBuffer sb=new StringBuffer(); while(true){ String str=in.readLine(); if(str.equals("-")==true)break ; length=Integer.parseInt(in.readLine()); sh=0 ; for(int i=0 ; itoInteger() ; sh := 0 ; var i : int ; i := 0 ; while i < length do ( ( sh := sh+((in.readLine())->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < str->size() do ( ( a := (sh + i) mod str->size() ; sb := sb + StringLib.newString(str->at(a+1)) ) ; i := i + 1 ) ; sb := sb + StringLib.newString("\n") ; ) ; OclFile["System.out"].print(sb) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int count=scan.nextInt(); while(count>0){ int[][] arr=new int[count][2]; for(int i=0 ; ilist ; Func(){ mark=(char)arr[ite][1]; switch(arr[ite][1]){ case '+' : case '*' : int deep=arr[ite][0]; ite++; list=new ArrayList<>(); while(itedeep){ list.add(new Func()); } break ; default : ite++; break ; } } int calc(){ int sum=0 ; switch(mark){ case '+' : for(Func _f : list){ sum+=_f.calc(); } return sum ; case '*' : sum=1 ; for(Func _f : list){ sum*=_f.calc(); } return sum ; default : return(int)(mark-'0'); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var count : int ; count := scan.getCurrent()->toInteger() ; while (count > 0) do ( var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,count)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < count do ( ( var input : Sequence(String) ; input := scan.getCurrent()->characters() ; arr[i+1][0+1] := input->size() ; arr[i+1][1+1] := input[input->size() - 1+1] ) ; i := i + 1 ) ; Func.ite := 0 ; Func.arr := arr ; OclFile["System.out"].println(Func.newFunc().calc()) ; count := scan.getCurrent()->toInteger() ; ) ); } class Func { static attribute ite : int; static attribute arr : Sequence(Sequence(int)); attribute mark : String; attribute list : Sequence(Func); static operation newFunc() : Func pre: true post: true activity: ( var self : Func ; self := createFunc(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( mark := arr[ite+1][1+1]->oclAsType(String) ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (arr[ite+1][1+1]) ; if _switchval = '+' or _switchval = '*' then var deep : int ; deep := arr[ite+1][0+1] ; ite := ite + 1 ; list := Sequence{} ; while (ite < arr->size() & arr[ite+1][0+1] > deep) do ( list := list->including(Func.newFunc()) ) ; break else skip ; if true then ite := ite + 1 ; break else skip ; ) ); operation calc() : int pre: true post: true activity: ( var sum : int ; sum := 0 ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (mark) ; if _switchval = '+' then for (_f : list) do ( ( sum := sum+(_f.calc()) ) ) ; return sum else skip ; if _switchval = '*' then sum := 1 ; for (_f : list) do ( ( sum := sum*(_f.calc()) ) ) ; return sum else skip ; if true then return ((mark)->char2byte() - ('0')->char2byte())->oclAsType(int) else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int n ; static char[][] buff=new char[17][10]; static int[] length=new int[17]; static int calc(int line){ char c ; int level,val ; int arg ; level=length[line]-1 ; c=buff[line][level]; if(c=='*'){ line++; val=1 ; while(true){ if(length[line]-1<=level)break ; if(length[line]-1==level+1){ arg=calc(line); val*=arg ; } line++; if(line>=n)break ; } return val ; } else if(c=='+'){ line++; val=0 ; while(true){ if(length[line]-1<=level)break ; if(length[line]-1==level+1){ arg=calc(line); val+=arg ; } line++; if(line>=n)break ; } return val ; } return c-'0' ; } public static void main(String args[]){ try(Scanner sc=new Scanner(System.in)){ while(sc.hasNext()){ n=sc.nextInt(); if(n==0)break ; for(int i=0 ; icollect(Integer.subrange(1,10)->collect(0)); static attribute length : Sequence(int) := Integer.subrange(1,17)->collect(0); static operation calc( line : int) : int pre: true post: true activity: ( var c : String ; var level : int ; var val : int ; var arg : int ; level := length[line+1] - 1 ; c := buff[line+1][level+1] ; if (c = '*') then ( line := line + 1 ; val := 1 ; while (true) do ( if (length[line+1] - 1 <= level) then break else skip ; if (length[line+1] - 1 = level + 1) then ( arg := calc(line) ; val := val*(arg) ) else skip ; line := line + 1 ; if (line >= n) then break else skip ) ; return val ) else if (c = '+') then ( line := line + 1 ; val := 0 ; while (true) do ( if (length[line+1] - 1 <= level) then break else skip ; if (length[line+1] - 1 = level + 1) then ( arg := calc(line) ; val := val+(arg) ) else skip ; line := line + 1 ; if (line >= n) then break else skip ) ; return val ) else skip ; ; return (c)->char2byte() - ('0')->char2byte() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while (sc.hasNext()) do ( n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var i : int ; i := 0 ; while i < n do ( ( var str : String ; str := sc.getCurrent() ; length[i+1] := str->size() ; var j : int ; j := 0 ; while j < str->size() do ( ( buff[i+1][j+1] := str->at(j+1) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(calc(0)) ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); ICPCCalculator solver=new ICPCCalculator(); try { int testNumber=1 ; while(true)solver.solve(testNumber++,in,out); } catch(UnknownError e){ out.close(); } } static class ICPCCalculator { int n ; String[] S ; boolean[] visited ; public void solve(int testNumber,Scanner in,PrintWriter out){ n=in.nextInt(); if(n==0)throw new UnknownError(); S=new String[n]; visited=new boolean[n]; Arrays.fill(visited,false); for(int i=0 ; itoInteger() ; if (n = 0) then error UnknownError.newUnknownError() ; else skip ; S := Integer.subrange(1,n)->collect(null) ; visited := Integer.subrange(1,n)->collect(false) ; visited := visited->collect(false) ; var i : int ; i := 0 ; while i < n do ( ( S[i+1] := in.getCurrent() ) ; i := i + 1 ) ; if (n = 1) then ( skip ; return ) else skip ; skip ; ); operation dfs( now : int, dot : int, ope : boolean) : int pre: true post: true activity: ( var ans : int ; ans := if ope then 1 else 0 endif ; var i : int ; i := now ; while i < n do ( ( if (S[i+1]->size() <= dot) then break else skip ; var c : String ; c := S[i+1]->at(dot+1) ; if ((c + "")->isMatch("[0-9]")) then ( if (ope) then ( ans := ans*((c)->char2byte() - ('0')->char2byte()) ) else ( ans := ans+((c)->char2byte() - ('0')->char2byte()) ) ) else if (c = '+' or c = '*') then ( if (ope) then ( ans := ans*(dfs(i + 1, dot + 1, c = '*')) ) else ( ans := ans+(dfs(i + 1, dot + 1, c = '*')) ) ) else if (c = '.') then ( continue ) else ( error SystemException() ) ; ; ) ; i := i + 1 ) ; return ans ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.Deque ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { private static int n ; private static Deque>stack ; public static void main(String...args){ Scanner scanner=new Scanner(System.in); while((n=scanner.nextInt())!=0){ stack=new ArrayDeque<>(); IntStream.range(0,n).forEach(i->{ String l=scanner.next(); int level=l.replaceFirst("[^.] ","").length(); if(stack.size()<=level){ stack.add(new ArrayDeque()); } calc(level); stack.peekLast().add(l.substring(l.length()-1)); } ); calc(0); System.out.println(stack.pop().pop()); } } private static void calc(int level){ while(stack.size()>level+1){ Dequeargs=stack.pollLast(); if(stack.isEmpty())break ; String operator=stack.peekLast().pollLast(); if(operator.equals("*")){ stack.peekLast().push(String.valueOf(args.stream().reduce(1l,(Long sum,String a)->sum*Long.parseLong(a),(Long a,Long b)->a*b))); } else if(operator.equals("+")){ stack.peekLast().push(String.valueOf(args.stream().reduce(0l,(Long sum,String a)->sum+Long.parseLong(a),(Long a,Long b)->a+b))); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute n : int; static attribute stack : Sequence(Sequence(String)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := scanner.getCurrent()->toInteger() ; while ((n) /= 0) do ( skip ; ( stack := ArrayDeque.newArrayDeque() ; for i : Integer.subrange(0, n-1) do ( skip) ; execute calc(0) ; OclFile["System.out"].println(stack->last()->last()) ) ; n := scanner.getCurrent()->toInteger() ; ) ); static operation calc( level : int) : void pre: true post: true activity: ( while (stack->size() > level + 1) do ( var args : Sequence(String) ; args := stack->last() ; if (stack->isEmpty()) then break else skip ; var operator : String ; operator := stack.peekLast()->last() ; if (operator = "*") then ( stack := stack.peekLast()->append(((args->iterate( _var; _acc : OclAny | 1l, lambda sum : long, a : String : OclAny in sum * (a)->toLong(), lambda a : long, b : long : OclAny in a * b->apply((_acc,_var)) )) + "")) ) else if (operator = "+") then ( stack := stack.peekLast()->append(((args->iterate( _var; _acc : OclAny | 0l, lambda sum : long, a : String : OclAny in sum + (a)->toLong(), lambda a : long, b : long : OclAny in a + b->apply((_acc,_var)) )) + "")) ) else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; import static java.lang.Integer.parseInt ; public class Main { static final char NOOP=' ' ; static final char PLUS='+' ; static final char MULTI='*' ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; Main main=new Main(); while((line=br.readLine())!=null && ! line.isEmpty()){ int n=parseInt(line); if(n==0)break ; Exp exp=main.new Exp(null,-1,PLUS); Exp parent=exp ; for(int i=0 ; i=lv){ parent=parent.parent ; } Exp sub=main.new Exp(parent,lv,c); parent.exps.add(sub); if(c==PLUS || c==MULTI)parent=sub ; } } } System.out.println(exp.value()); } } class Exp { int lv ; char op ; int value ; Exp parent ; Listexps ; Exp(Exp parent,int lv,char c){ this.parent=parent ; this.lv=lv ; if(c!=PLUS && c!=MULTI){ this.op=NOOP ; this.value=c-'0' ; } else { this.op=c ; exps=new ArrayList(); } } int value(){ if(op==PLUS){ value=0 ; for(Exp exp : exps)value+=exp.value(); } else if(op==MULTI){ value=1 ; for(Exp exp : exps)value*=exp.value(); } return value ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute NOOP : String := ' '; static attribute PLUS : String := '+'; static attribute MULTI : String := '*'; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var main : Main ; main := Main.newMain() ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var n : int ; n := parseInt(line) ; if (n = 0) then break else skip ; var exp : Exp ; exp := (main).newExp(null, -1, PLUS) ; var parent : Exp ; parent := exp ; var i : int ; i := 0 ; while i < n do ( ( line := br.readLine() ; var lv : int ; lv := 0 ; for (c : line->characters()) do ( ( if (c = '.') then ( lv := lv + 1 ) else ( while (parent.lv >= lv) do ( parent := parent.parent ) ; var sub : Exp ; sub := (main).newExp(parent, lv, c) ; parent.exps->excludes(sub) ; if (c = PLUS or c = MULTI) then parent := sub ; else skip ) ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(exp.value()) ; ) ; line := br.readLine() ; ) ; ); class Exp { attribute lv : int; attribute op : String; attribute value : int; attribute parent : Exp; attribute exps : Sequence(Exp); static operation newExp( parent : Exp, lv : int, c : String) : Exp pre: true post: true activity: ( var self : Exp ; self := createExp(); self.initialise(parent, lv,c); return self ); operation initialise( parent : Exp, lv : int, c : String) : void pre: true post: true activity: ( self.parent := parent ; self.lv := lv ; if (c /= PLUS & c /= MULTI) then ( self.op := NOOP ; self.value := c - ('0')->char2byte() ) else ( self.op := c ; exps := Sequence{} ) ); operation value() : int pre: true post: true activity: ( if (op = PLUS) then ( value := 0 ; for (exp : exps) do ( value := value+(exp.value()) ; ) ) else if (op = MULTI) then ( value := 1 ; for (exp : exps) do ( value := value*(exp.value()) ; ) ) else skip ; ; return value ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ me=scanner.nextInt(); if(me==0)break ; n=scanner.nextInt(); a=new int[n+2]; for(int i=1 ; i<=n ; i++)a[i]=scanner.nextInt(); n+=2 ; boolean[] vis=new boolean[n]; bfs(0,vis); if(! vis[n-1]){ System.out.println("NG"); continue ; } boolean ok=true ; for(int s=1 ; stoInteger() ; if (me = 0) then break else skip ; n := scanner.getCurrent()->toInteger() ; a := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( a[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; n := n+(2) ; var vis : Sequence(boolean) ; vis := Integer.subrange(1,n)->collect(false) ; execute bfs(0, vis) ; if (not(vis[n - 1+1])) then ( OclFile["System.out"].println("NG") ; continue ) else skip ; var ok : boolean ; ok := true ; var s : int ; s := 1 ; while s < n - 1 do ( ( if (vis[s+1]) then ( var vis2 : Sequence(boolean) ; vis2 := Integer.subrange(1,n)->collect(false) ; execute bfs(s, vis2) ; if (not(vis2[n - 1+1])) then ( ok := false ; break ) else skip ) else skip ) ; s := s + 1 ) ; OclFile["System.out"].println(if ok then "OK" else "NG" endif) ; ) ); operation bfs( s : int, vis : Sequence(boolean)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n do ( vis[i+1] := (i = s) ; ; i := i + 1 ) ; var Q : Sequence(int) ; Q := Integer.subrange(1,n)->collect(0) ; var head : int ; head := 0 ; var tail : int ; tail := 0 ; Q[tail+1] := s ; tail := tail + 1 ; while (head < tail) do ( var x : int ; x := Q[head+1] ; var d : int ; d := 1 ; while d <= me do ( ( var xx : int ; xx := Set{x + d, n - 1}->min() ; xx := Set{Set{xx + a[xx+1], n - 1}->min(), 0}->max() ; if (not(vis[xx+1])) then ( vis[xx+1] := true ; Q[tail+1] := xx ; tail := tail + 1 ) else skip ) ; d := d + 1 ) ) ; ); attribute n : int; attribute a : Sequence(int); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.Deque ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ me=scanner.nextInt(); if(me==0)break ; n=scanner.nextInt(); a=new int[n+2]; for(int i=1 ; i<=n ; i++)a[i]=scanner.nextInt(); n+=2 ; boolean[] vis=new boolean[n]; bfs(0,vis); if(! vis[n-1]){ System.out.println("NG"); continue ; } boolean ok=true ; for(int s=1 ; sdeque=new ArrayDeque(); deque.push(s); while(! deque.isEmpty()){ int x=deque.poll(); for(int d=1 ; d<=me ; d++){ int xx=Math.min(x+d,n-1); xx=Math.max(Math.min(xx+a[xx],n-1),0); if(! vis[xx]){ vis[xx]=true ; deque.push(xx); } } } } int n,me ; int[] a ; } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( me := scanner.getCurrent()->toInteger() ; if (me = 0) then break else skip ; n := scanner.getCurrent()->toInteger() ; a := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( a[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; n := n+(2) ; var vis : Sequence(boolean) ; vis := Integer.subrange(1,n)->collect(false) ; execute bfs(0, vis) ; if (not(vis[n - 1+1])) then ( OclFile["System.out"].println("NG") ; continue ) else skip ; var ok : boolean ; ok := true ; var s : int ; s := 1 ; while s < n - 1 do ( ( if (vis[s+1]) then ( var vis2 : Sequence(boolean) ; vis2 := Integer.subrange(1,n)->collect(false) ; execute bfs(s, vis2) ; if (not(vis2[n - 1+1])) then ( ok := false ; break ) else skip ) else skip ) ; s := s + 1 ) ; OclFile["System.out"].println(if ok then "OK" else "NG" endif) ; ) ); operation bfs( s : int, vis : Sequence(boolean)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n do ( vis[i+1] := (i = s) ; ; i := i + 1 ) ; var deque : Sequence(int) ; deque := ArrayDeque.newArrayDeque() ; deque := deque->append(s) ; while (not(deque->isEmpty())) do ( var x : int ; x := deque->min() ; var d : int ; d := 1 ; while d <= me do ( ( var xx : int ; xx := Set{x + d, n - 1}->min() ; xx := Set{Set{xx + a[xx+1], n - 1}->min(), 0}->max() ; if (not(vis[xx+1])) then ( vis[xx+1] := true ; deque := deque->append(xx) ) else skip ) ; d := d + 1 ) ) ); attribute n : int; attribute a : Sequence(int); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.Deque ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ me=scanner.nextInt(); if(me==0)break ; n=scanner.nextInt(); a=new int[n+2]; for(int i=1 ; i<=n ; i++)a[i]=scanner.nextInt(); n+=2 ; boolean[] vis=new boolean[n]; bfs(0,vis); if(! vis[n-1]){ System.out.println("NG"); continue ; } boolean ok=true ; for(int s=1 ; sdeque=new ArrayDeque(); deque.push(s); while(! deque.isEmpty()){ int x=deque.poll(); for(int d=1 ; d<=me ; d++){ int xx=Math.min(x+d,n-1); xx=Math.max(Math.min(xx+a[xx],n-1),0); if(! vis[xx]){ vis[xx]=true ; deque.push(xx); } } } } int n,me ; int[] a ; } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( me := scanner.getCurrent()->toInteger() ; if (me = 0) then break else skip ; n := scanner.getCurrent()->toInteger() ; a := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( a[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; n := n+(2) ; var vis : Sequence(boolean) ; vis := Integer.subrange(1,n)->collect(false) ; execute bfs(0, vis) ; if (not(vis[n - 1+1])) then ( OclFile["System.out"].println("NG") ; continue ) else skip ; var ok : boolean ; ok := true ; var s : int ; s := 1 ; while s < n - 1 do ( ( if (vis[s+1]) then ( var vis2 : Sequence(boolean) ; vis2 := Integer.subrange(1,n)->collect(false) ; vis2[s+1] := true ; execute bfs(s, vis2) ; if (not(vis2[n - 1+1])) then ( ok := false ; break ) else skip ) else skip ) ; s := s + 1 ) ; OclFile["System.out"].println(if ok then "OK" else "NG" endif) ; ) ); operation bfs( s : int, vis : Sequence(boolean)) : void pre: true post: true activity: ( var deque : Sequence(int) ; deque := ArrayDeque.newArrayDeque() ; deque := deque->append(s) ; while (not(deque->isEmpty())) do ( var x : int ; x := deque->min() ; var d : int ; d := 1 ; while d <= me do ( ( var xx : int ; xx := Set{x + d, n - 1}->min() ; xx := Set{Set{xx + a[xx+1], n - 1}->min(), 0}->max() ; if (not(vis[xx+1])) then ( vis[xx+1] := true ; deque := deque->append(xx) ) else skip ) ; d := d + 1 ) ) ); attribute n : int; attribute a : Sequence(int); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Main { public static void main(String[] a){ for(int i=1 ; i<10 ; i++){ for(int j=1 ; j<10 ; j++){ System.out.println(i+"x"+j+"="+kuku(i,j)); } } } public static int kuku(int a,int b){ return a*b ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < 10 do ( ( var j : int ; j := 1 ; while j < 10 do ( ( OclFile["System.out"].println(i + "x" + j + "=" + kuku(i, j)) ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation kuku( a : int, b : int) : int pre: true post: true activity: ( return a * b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void printMinIndexChar(String str,String patt){ int minIndex=Integer.MAX_VALUE ; int m=str.length(); int n=patt.length(); for(int i=0 ; isize() ; var n : int ; n := patt->size() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( if (patt->at(i+1) = str->at(j+1) & j < minIndex) then ( minIndex := j ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (minIndex /= 2147483647) then OclFile["System.out"].println("Minimum Index Character=" + str->at(minIndex+1)) else OclFile["System.out"].println("No character present") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var patt : String ; patt := "set" ; execute printMinIndexChar(str, patt) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.Deque ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ max=scanner.nextInt(); if(max==0)break ; n=scanner.nextInt(); map=new int[n+2]; for(int i=1 ; i<=n ; i++)map[i]=scanner.nextInt(); n+=2 ; boolean[] vis=new boolean[n]; vis[0]=true ; dfs(0,vis); if(! vis[n-1]){ System.out.println("NG"); continue ; } boolean flag=true ; for(int s=1 ; sdeque=new ArrayDeque(); deque.push(s); while(! deque.isEmpty()){ int x=deque.poll(); for(int i=1 ; i<=max ; i++){ int nx=Math.min(x+i,n-1); nx=Math.max(Math.min(nx+map[nx],n-1),0); if(! vis[nx]){ vis[nx]=true ; deque.push(nx); } } } } int max,n ; int[] map ; } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( max := scanner.getCurrent()->toInteger() ; if (max = 0) then break else skip ; n := scanner.getCurrent()->toInteger() ; map := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( map[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; n := n+(2) ; var vis : Sequence(boolean) ; vis := Integer.subrange(1,n)->collect(false) ; vis[0+1] := true ; execute dfs(0, vis) ; if (not(vis[n - 1+1])) then ( OclFile["System.out"].println("NG") ; continue ) else skip ; var flag : boolean ; flag := true ; var s : int ; s := 1 ; while s < n - 1 do ( ( if (not(vis[s+1])) then continue else skip ; var vis2 : Sequence(boolean) ; vis2 := Integer.subrange(1,n)->collect(false) ; vis2[s+1] := true ; execute dfs(s, vis2) ; if (not(vis2[n - 1+1])) then ( flag := false ; break ) else skip ; ) ; s := s + 1 ) ; OclFile["System.out"].println(if flag then "OK" else "NG" endif) ; ) ); operation dfs( s : int, vis : Sequence(boolean)) : void pre: true post: true activity: ( var deque : Sequence(int) ; deque := ArrayDeque.newArrayDeque() ; deque := deque->append(s) ; while (not(deque->isEmpty())) do ( var x : int ; x := deque->min() ; var i : int ; i := 1 ; while i <= max do ( ( var nx : int ; nx := Set{x + i, n - 1}->min() ; nx := Set{Set{nx + map[nx+1], n - 1}->min(), 0}->max() ; if (not(vis[nx+1])) then ( vis[nx+1] := true ; deque := deque->append(nx) ) else skip ) ; i := i + 1 ) ) ); attribute max : int; attribute map : Sequence(int); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); while(true){ final int max=sc.nextInt(); if(max==0){ break ; } final int n=sc.nextInt(); final int size=n+2 ; int[] map=new int[size]; for(int i=1 ; i<=n ; i++){ map[i]=sc.nextInt(); } boolean[][] adj=new boolean[size][size]; for(int i=0 ; itoInteger() ; if (max = 0) then ( break ) else skip ; var n : int ; n := sc.getCurrent()->toInteger() ; var size : int ; size := n + 2 ; var map : Sequence(int) ; map := Integer.subrange(1,size)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( map[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var adj : Sequence(Sequence(boolean)) ; adj := Integer.subrange(1,size)->collect(Integer.subrange(1,size)->collect(false)) ; var i : int ; i := 0 ; while i < size do ( ( var j : int ; j := 0 ; while j < max do ( ( if (i = size - 1) then ( adj[i+1][i+1] := true ; continue ) else skip ; var num : int ; num := j + 1 ; var to : int ; to := Set{size - 1, Set{0, i + num}->max()}->min() ; var dist : int ; dist := Set{size - 1, Set{0, to + map[to+1]}->max()}->min() ; adj[i+1][dist+1] := true ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < size do ( ( var i : int ; i := 0 ; while i < size do ( ( var j : int ; j := 0 ; while j < size do ( ( adj[i+1][j+1] := adj[i+1][j+1] or (adj[i+1][k+1] & adj[k+1][j+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; k := k + 1 ) ; var flag : boolean ; flag := true ; var i : int ; i := 0 ; while i < size do ( ( if (adj[0+1][i+1] & not(adj[i+1][size - 1+1])) then ( OclFile["System.out"].println("NG") ; flag := false ; break ) else skip ) ; i := i + 1 ) ; if (flag) then ( OclFile["System.out"].println("OK") ) else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner s=new Scanner(System.in); String str=s.nextLine(); char[] ch=str.toCharArray(); int m=s.nextInt(); int frequency[]=new int[(ch.length)/2]; for(int i=0 ; icharacters() ; var m : int ; m := s.getCurrent()->toInteger() ; var frequency : Sequence(int) ; frequency := Integer.subrange(1,(ch->size()) / 2)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( var x : int ; x := s.getCurrent()->toInteger() ; frequency[x - 1+1] := frequency[x - 1+1] + 1 ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < (ch->size()) / 2 do ( ( sum := sum+(frequency[i+1]) ; if (sum mod 2 /= 0) then ( var temp : String ; temp := ch[i+1] ; ch[i+1] := ch[ch->size() - i - 1+1] ; ch[ch->size() - i - 1+1] := temp ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < ch->size() do ( ( OclFile["System.out"].print(ch[i+1] + "") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Mostsociallydistancedsubsequence { public static void main(String args[]){ int i,j,k,t,n ; Scanner sc=new Scanner(System.in); t=sc.nextInt(); while(t-->0){ n=sc.nextInt(); int a[]=new int[n]; for(i=0 ; ihm=new LinkedHashMap<>(); ArrayListlist=new ArrayList(); list.add(a[0]); int fas=0 ; if(a[0]>a[1]){ fas=1 ; } int flag=0 ; for(i=0 ; ia[j-1]){ list.add(a[j-1]); i=j-2 ; fas=0 ; break ; } } if(j==n-1){ flag=1 ; } } if(flag==1){ break ; } } list.add(a[n-1]); System.out.println(list.size()); for(i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var hm : Map(int,int) ; hm := Map{} ; var list : Sequence(int) ; list := Sequence{} ; list := list->including(a[0+1]) ; var fas : int ; fas := 0 ; if (a[0+1] > a[1+1]) then ( fas := 1 ) else skip ; var flag : int ; flag := 0 ; i := 0 ; while i < n do ( ( j := i + 1 ; while j < n do ( ( if (fas = 0) then ( if (a[j+1] < a[j - 1+1]) then ( list := list->including(a[j - 1+1]) ; i := j - 2 ; fas := 1 ; break ) else skip ) else ( if (a[j+1] > a[j - 1+1]) then ( list := list->including(a[j - 1+1]) ; i := j - 2 ; fas := 0 ; break ) else skip ) ; if (j = n - 1) then ( flag := 1 ) else skip ) ; j := j + 1 ) ; if (flag = 1) then ( break ) else skip ) ; i := i + 1 ) ; list := list->including(a[n - 1+1]) ; OclFile["System.out"].println(list->size()) ; i := 0 ; while i < list->size() do ( ( OclFile["System.out"].print(list->at(i+1) + " ") ) ; i := i + 1 ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.File ; import java.io.FileNotFoundException ; import java.util.*; public class Main { public static String s,ans="Yes" ; public static HashMaph=new HashMap(); public static void main(String[] args)throws FileNotFoundException { Scanner in=new Scanner(System.in); s=in.next(); char[] sa=s.toCharArray(); for(char c : sa){ if(! h.containsKey(c))h.put(c,1); else h.put(c,h.get(c)+1); } for(char c : h.keySet()){ if(h.get(c)% 2==1){ ans="No" ; break ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : String; static attribute h : Map(String,int) := Map{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; s := in.getCurrent() ; var sa : Sequence(String) ; sa := s->characters() ; for (c : sa) do ( ( if (not(h->keys()->includes(c))) then h := h->union(Map{c |-> 1}) ; else h := h->union(Map{c |-> h->at(c) + 1}) ; ) ) ; for (c : h->keys()) do ( ( if (h->at(c) mod 2 = 1) then ( ans := "No" ; break ) else skip ) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String keyBoard=sc.next(); int inputSize=keyBoard.length(); boolean beautifulFlag=true ; ListwordList=new ArrayList(); for(int i=0 ; isize() ; var beautifulFlag : boolean ; beautifulFlag := true ; var wordList : Sequence(String) ; wordList := Sequence{} ; var i : int ; i := 0 ; while i < inputSize do ( ( wordList := wordList->including(keyBoard.subrange(i+1,i + 1)) ) ; i := i + 1 ) ; wordList := wordList->sort() ; var i : int ; i := 0 ; while i < wordList->size() do ( ( var word : String ; word := wordList->at(0+1) ; var wordCount : int ; wordCount := wordList->lastIndexOf(word)-1 + 1 ; if (wordCount mod 2 /= 0) then ( OclFile["System.out"].println("No") ; beautifulFlag := false ; break ) else skip ; var j : int ; j := 0 ; while j < wordCount do ( ( wordList := wordList->excludingAt(0+1) ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (beautifulFlag) then ( OclFile["System.out"].println("Yes") ) else skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.Map.Entry ; public class Main { public static void main(String[] args){ try { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String w=br.readLine(); HashMapmap=new HashMap(); for(int i=0 ; ient : map.entrySet()){ int val=ent.getValue(); if(val % 2!=0){ flag=false ; break ; } } if(flag){ System.out.println("Yes"); } else { System.out.println("No"); } } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(isr) ; var w : String ; w := br.readLine() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < w->size() do ( ( var tmp : String ; tmp := w.subrange(i+1,i + 1) ; if (map->keys()->includes(tmp)) then ( var val : int ; val := map->at(tmp) ; map := map->union(Map{tmp |-> val + 1}) ) else ( map := map->union(Map{tmp |-> 1}) ) ) ; i := i + 1 ) ; var flag : boolean ; flag := true ; for (ent : map->asSet()) do ( ( var val : int ; val := ent.getValue() ; if (val mod 2 /= 0) then ( flag := false ; break ) else skip ) ) ; if (flag) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static BufferedReader br=new BufferedReader(new InputStreamReader(System.in),32768); static PrintWriter out=new PrintWriter(System.out); static StringTokenizer t ; static String sn(){ while(t==null || ! t.hasMoreTokens()){ try { t=new StringTokenizer(br.readLine()); } catch(IOException e){ throw new RuntimeException(); } } return t.nextToken(); } static int ni(){ return Integer.parseInt(sn()); } static long nlo(){ return Long.parseLong(sn()); } public static void main(String args[]){ int t=1 ; while(t-->0){ solve(); } out.close(); } static long mod=998244353 ; static long pro(long a,long b){ return(a % mod*b % mod)% mod ; } static long add(long a,long b){ return(a+b)% mod ; } static int maxn=200005 ; static void solve(){ char c[]=sn().toCharArray(); int n=c.length ; int f[]=new int[26]; for(int i=0 ; i0 && f[i] % 2!=0){ ff=1 ; out.println("No"); break ; } } if(ff==0)out.println("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), 32768); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static attribute t : OclIterator; static operation sn() : String pre: true post: true activity: ( while (t = null or not(t.hasNext())) do ( try ( t := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( error ProgramException() ) ) ; return t.next() ); static operation ni() : int pre: true post: true activity: ( return (sn())->toInteger() ); static operation nlo() : long pre: true post: true activity: ( return (sn())->toLong() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( execute solve() ) ; ) ; skip ); static attribute mod : long := 998244353; static operation pro( a : long, b : long) : long pre: true post: true activity: ( return (a mod mod * b mod mod) mod mod ); static operation add( a : long, b : long) : long pre: true post: true activity: ( return (a + b) mod mod ); static attribute maxn : int := 200005; static operation solve() : void pre: true post: true activity: ( var c : Sequence(String) ; c := sn()->characters() ; var n : int ; n := c->size() ; var f : Sequence(int) ; f := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < n do ( f[c[i+1] - ('a')->char2byte()+1] := f[c[i+1] - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var ff : int ; ff := 0 ; var i : int ; i := 0 ; while i < 26 do ( ( if (f[i+1] > 0 & f[i+1] mod 2 /= 0) then ( ff := 1 ; skip ; break ) else skip ) ; i := i + 1 ) ; if (ff = 0) then skip ; else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.HashMap ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String w=sc.next(); char[] c=w.toCharArray(); HashMapmap=new HashMap(); for(int i=0 ; icharacters() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < w->size() do ( ( if (map->keys()->includes(c[i+1])) then ( map := map->union(Map{c[i+1] |-> map->at(c[i+1]) + 1}) ; continue ) else skip ; map := map->union(Map{c[i+1] |-> 1}) ) ; i := i + 1 ) ; for (key : map->keys()) do ( ( if (map->at(key) mod 2 = 1) then ( OclFile["System.out"].println("No") ; return ) else skip ) ) ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class demo1 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt()-1 ; int a=1 ; int b=0 ; String ax=sc.next(); String bx=null ; while(n-->0){ String k=sc.next(); if(! k.equals(ax)){ b++; if(bx==null)bx=k ; } else { a++; } } System.out.println(a>b ? ax : bx); } } ------------------------------------------------------------ OCL File: --------- class demo1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() - 1 ; var a : int ; a := 1 ; var b : int ; b := 0 ; var ax : String ; ax := sc.getCurrent() ; var bx : String ; bx := null ; while (n > 0) do ( n := n - 1 ; skip ; ( var k : String ; k := sc.getCurrent() ; if (not(k = ax)) then ( b := b + 1 ; if (bx = null) then bx := k ; else skip ) else ( a := a + 1 ) ) ; ) ; OclFile["System.out"].println(if a > b then ax else bx endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isPrime(int n){ int flag=1 ; for(int i=2 ; i*i<=n ; i++){ if(n % i==0){ flag=0 ; break ; } } return(flag==1 ? true : false); } static boolean isPerfectSquare(int x){ double sr=Math.sqrt(x); return((sr-Math.floor(sr))==0); } static int countInterestingPrimes(int n){ int answer=0 ; for(int i=2 ; i<=n ; i++){ if(isPrime(i)){ for(int j=1 ; j*j*j*j<=i ; j++){ if(isPerfectSquare(i-j*j*j*j)){ answer++; break ; } } } } return answer ; } public static void main(String[] args){ int N=10 ; System.out.print(countInterestingPrimes(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPrime( n : int) : boolean pre: true post: true activity: ( var flag : int ; flag := 1 ; var i : int ; i := 2 ; while i * i <= n do ( ( if (n mod i = 0) then ( flag := 0 ; break ) else skip ) ; i := i + 1 ) ; return (if flag = 1 then true else false endif) ); static operation isPerfectSquare( x : int) : boolean pre: true post: true activity: ( var sr : double ; sr := (x)->sqrt() ; return ((sr - (sr)->floor()) = 0) ); static operation countInterestingPrimes( n : int) : int pre: true post: true activity: ( var answer : int ; answer := 0 ; var i : int ; i := 2 ; while i <= n do ( ( if (isPrime(i)) then ( var j : int ; j := 1 ; while j * j * j * j <= i do ( ( if (isPerfectSquare(i - j * j * j * j)) then ( answer := answer + 1 ; break ) else skip ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; return answer ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 10 ; OclFile["System.out"].print(countInterestingPrimes(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class B { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); Distance[] dis=new Distance[n+1]; for(int i=1 ; i<=n ; i++)dis[i]=new Distance(); for(int i=0 ; i<2*n ; i++){ int a=in.nextInt(); if(dis[a] .f==0)dis[a] .f=(i+1); else dis[a] .s=(i+1); } long ans=0 ; long prev=1 ; for(int i=1 ; i<=n ; i++){ ans+=Math.abs(dis[i] .f-prev); prev=dis[i] .f ; } prev=1 ; for(int i=1 ; i<=n ; i++){ ans+=Math.abs(dis[i] .s-prev); prev=dis[i] .s ; } pw.println(ans); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } static class Distance { long f,s ; Distance(){ f=0 ; s=0 ; } @ Override public String toString(){ return f+" "+s ; } } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var dis : Sequence(Distance) ; dis := Integer.subrange(1,n + 1)->collect(null) ; var i : int ; i := 1 ; while i <= n do ( dis[i+1] := Distance.newDistance() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 2 * n do ( ( var a : int ; a := in.getCurrent()->toInteger() ; if (dis[a+1].f = 0) then dis[a+1].f := (i + 1) ; else dis[a+1].s := (i + 1) ; ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var prev : long ; prev := 1 ; var i : int ; i := 1 ; while i <= n do ( ( ans := ans+(if dis[i+1].f - prev < 0 then -(dis[i+1].f - prev) else dis[i+1].f - prev endif) ; prev := dis[i+1].f ) ; i := i + 1 ) ; prev := 1 ; var i : int ; i := 1 ; while i <= n do ( ( ans := ans+(if dis[i+1].s - prev < 0 then -(dis[i+1].s - prev) else dis[i+1].s - prev endif) ; prev := dis[i+1].s ) ; i := i + 1 ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); static class Distance { attribute f : long; static operation newDistance() : Distance pre: true post: true activity: ( var self : Distance ; self := createDistance(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( f := 0 ; s := 0 ); operation toString() : String pre: true post: true activity: ( return f + " " + s ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner in=new Scanner(System.in)){ solve(in); } } private static void solve(Scanner in){ for(int i=1 ; i<=9 ; i++){ for(int j=1 ; j<=9 ; j++){ System.out.println(i+"x"+j+"="+i*j); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( execute solve(in) )) ); static operation solve( in : OclFile) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= 9 do ( ( var j : int ; j := 1 ; while j <= 9 do ( ( OclFile["System.out"].println(i + "x" + j + "=" + i * j) ) ; j := j + 1 ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import sun.font.FontRunIterator ; import java.util.*; import java.util.ArrayList ; public class codforce { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int x=scan.nextInt(); String[] arr=new String[x]; for(int i=0 ; icount1){ System.out.println(g); } else { System.out.println(g1); } } } ------------------------------------------------------------ OCL File: --------- class codforce { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := scan.getCurrent()->toInteger() ; var arr : Sequence(String) ; arr := Integer.subrange(1,x)->collect(null) ; var i : int ; i := 0 ; while i < x do ( ( arr[i+1] := scan.getCurrent() ) ; i := i + 1 ) ; arr := arr->sort() ; var g : String ; g := arr[0+1] ; var g1 : String ; g1 := arr[arr->size() - 1+1] ; var count : int ; count := 0 ; var count1 : int ; count1 := 0 ; var i : int ; i := 0 ; while i < arr->size() do ( ( if (arr[i+1] = g) then ( count := count + 1 ) else ( count1 := count1 + 1 ) ) ; i := i + 1 ) ; if (count > count1) then ( OclFile["System.out"].println(g) ) else ( OclFile["System.out"].println(g1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Problem_43A_Football { public static FastScanner fs=new FastScanner(); public static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args){ out.println(solve()); out.close(); } public static String solve(){ int n=fs.nextInt(); String team1=fs.next(); if(n==1)return team1 ; int score1=1,score2=0 ; String team2=new String(); for(int i=2 ; i<=n ; i++){ String teamScored=fs.next(); if(teamScored.equals(team1))score1++; else { team2=teamScored ; score2++; } } if(team2.equals(null))return team1 ; return(score1>score2)? team1 : team2 ; } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; i score2) then team1 else team2 endif ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static operation toString( a : Sequence(String)) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < a->size() do ( ( sb := sb + StringLib.newString(a[i+1]) ) ; i := i + 1 ) ; return sb+"" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; public class string { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); HashMapmap=new HashMap<>(); while(n-->0){ String s=br.readLine(); if(map.containsKey(s)){ map.put(s,map.get(s)+1); } else { map.put(s,1); } } Object[] val=map.values().toArray(); int max=Integer.MIN_VALUE ; for(int i=0 ; imax){ max=(int)val[i]; } } for(String key : map.keySet()){ if(max==map.get(key)){ System.out.println(key); return ; } } } } ------------------------------------------------------------ OCL File: --------- class string { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var map : Map(String,int) ; map := Map{} ; while (n > 0) do ( n := n - 1 ; skip ; ( var s : String ; s := br.readLine() ; if (map->keys()->includes(s)) then ( map := map->union(Map{s |-> map->at(s) + 1}) ) else ( map := map->union(Map{s |-> 1}) ) ) ; ) ; var val : Sequence(OclAny) ; val := map->values()->asSequence() ; var max : int ; max := -2147483648 ; var i : int ; i := 0 ; while i < val->size() do ( ( if (val[i+1]->oclAsType(int) > max) then ( max := val[i+1]->oclAsType(int) ) else skip ) ; i := i + 1 ) ; for (key : map->keys()) do ( ( if (max = map->at(key)) then ( OclFile["System.out"].println(key) ; return ) else skip ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class kfc { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt()-1 ; String str=sc.next(); String tt=null ; int cnt1=0 ; int cnt2=1 ; while(a-->0){ String te=sc.next(); if(! te.equals(str)){ cnt1++; if(tt==null)tt=te ; } else { cnt2++; } } System.out.println(cnt2>cnt1 ? str : tt); } } ------------------------------------------------------------ OCL File: --------- class kfc { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() - 1 ; var str : String ; str := sc.getCurrent() ; var tt : String ; tt := null ; var cnt1 : int ; cnt1 := 0 ; var cnt2 : int ; cnt2 := 1 ; while (a > 0) do ( a := a - 1 ; skip ; ( var te : String ; te := sc.getCurrent() ; if (not(te = str)) then ( cnt1 := cnt1 + 1 ; if (tt = null) then tt := te ; else skip ) else ( cnt2 := cnt2 + 1 ) ) ; ) ; OclFile["System.out"].println(if cnt2 > cnt1 then str else tt endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(true){ int n=in.nextInt(); if(n==0)break ; String W[]=new String[n]; for(int i=0 ; itanku[k]){ ck=false ; break ; } else if(sum==tanku[k]){ k++; sum=0 ; } } if(ck)break ; } System.out.println(i+1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := in.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var W : Sequence(String) ; W := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( W[i+1] := in.getCurrent() ; ; i := i + 1 ) ; var tanku : Sequence(int) ; tanku := Sequence{5,7,5,7,7} ; var i : int ; i := 0 ; while i < n - 4 do ( ( var ck : boolean ; ck := true ; var sum : int ; sum := 0 ; var j : int ; j := i ; var k : int ; k := 0 ; while (true) do ( if (k = 5) then break else skip ; sum := sum+(W[j+1]->size()) ; j := j + 1 ; if (sum > tanku[k+1]) then ( ck := false ; break ) else if (sum = tanku[k+1]) then ( k := k + 1 ; sum := 0 ) else skip ; ) ; if (ck) then break else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(i + 1) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { private static boolean match(int[] pattern,int[] s,int pos){ int sp=0 ; int cr=0 ; for(int i=pos ; isize() do ( ( cr := cr+(s[i+1]) ; if (pattern[sp+1] < cr) then break else skip ; if (pattern[sp+1] = cr) then ( sp := sp + 1 ; cr := 0 ; if (sp = pattern->size()) then return true else skip ) else skip ) ; i := i + 1 ) ; return false ); static operation match( pattern : Sequence(int), s : Sequence(int)) : int pre: true post: true activity: ( var i : int ; i := 0 ; while i < s->size() do ( ( if (match(pattern, s, i)) then return i else skip ) ; i := i + 1 ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : Scanner := Scanner.newScanner(OclFile["System.in"]) ; ( while true do ( ( var w : Sequence(int) ; w := Integer.subrange(1,sc.nextInt())->collect(0) ; if (w->size() = 0) then break else skip ; var i : int ; i := 0 ; while i < w->size() do ( ( w[i+1] := sc.next()->size() ) ; i := i + 1 ) ; OclFile["System.out"].println(match(Sequence{5,7,5,7,7}, w) + 1) ) ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { static final Scanner s=new Scanner(System.in); static int getInt(){ return Integer.parseInt(s.next()); } static IntStream REPS(int l){ return IntStream.range(0,l); } static Listhoge=Arrays.asList(5,12,17,24,31); public static void main(String[] __){ ArrayDequed=new ArrayDeque<>(); cases : while(true){ int n=getInt(); if(n==0)return ; int[] in=REPS(n).map(i->s.next().length()).toArray(); int[] psum=new int[n+1]; for(int i=0 ; ipsum[w]-v).forEach(w->{ if(! d.isEmpty()&& d.peekFirst()==w)d.pollFirst(); } ); if(d.isEmpty()){ System.out.println(i); continue cases ; } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation getInt() : int pre: true post: true activity: ( return (s.getCurrent())->toInteger() ); static operation REPS( l : int) : Sequence(int) pre: true post: true activity: ( return Integer.subrange(0, l-1) ); static attribute hoge : Sequence(int) := Sequence{5,12,17,24,31}; static operation main( __ : Sequence(String)) : void pre: true post: true activity: ( var d : Sequence(int) ; d := ArrayDeque.newArrayDeque() ; while (true) do ( var n : int ; n := getInt() ; if (n = 0) then return else skip ; var in : Sequence(int) ; in := REPS(n)->collect( _x1 | (lambda i : OclAny in s.getCurrent()->size())->apply(_x1) )->asSequence() ; var psum : Sequence(int) ; psum := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( psum[i + 1+1] := in[i+1] ; ; i := i + 1 ) ; parallelPrefix(psum, lambda _pars : OclAny in Integer.newInteger().sum(_pars)) ; var i : int ; i := 1 ; while i <= n do ( ( d := d->intersection(Set{}) ; d := d->union(hoge) ; var v : int ; v := psum[i - 1+1] ; for w : Integer.subrange(i, n)->collect( _x1 | (lambda w : OclAny in psum[w+1] - v)->apply(_x1) ) do ( skip) ; if (d->isEmpty()) then ( OclFile["System.out"].println(i) ; continue ) else skip ; ) ; i := i + 1 ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { static final int CHARS=31 ; static final int[] WORDS=new int[] { 5,7,5,7,7 }; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null && ! line.isEmpty()){ int n=parseInt(line); if(n==0)break ; int[] words=new int[n+1]; for(int i=1 ; i<=n ; i++){ words[i]=br.readLine().length(); words[i]+=words[i-1]; } int k=0 ; outer : for(int i=1 ; i<=n ; i++){ for(int j=n ; j>=i ; j--){ if(words[j]-words[i-1]==CHARS){ if(check(words,i,j)){ k=i ; break outer ; } } } } System.out.println(k); } } static boolean check(int[] words,int from,int to){ boolean ret=true ; int _j=from ; for(int i=0 ; iWORDS[i]){ ret &=false ; } } } return ret ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute CHARS : int := 31; static attribute WORDS : Sequence(int) := Sequence{5,7,5,7,7}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var n : int ; n := parseInt(line) ; if (n = 0) then break else skip ; var words : Sequence(int) ; words := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( words[i+1] := br.readLine()->size() ; words[i+1] := words[i+1]+(words[i - 1+1]) ) ; i := i + 1 ) ; var k : int ; k := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := n ; while j >= i do ( ( if (words[j+1] - words[i - 1+1] = CHARS) then ( if (check(words, i, j)) then ( k := i ; break ) else skip ) else skip ) ; j := j - 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(k) ; ) ; line := br.readLine() ; ) ); static operation check( words : Sequence(int), from : int, to : int) : boolean pre: true post: true activity: ( var ret : boolean ; ret := true ; var _j : int ; _j := from ; var i : int ; i := 0 ; while i < WORDS->size() do ( ( var j : int ; j := _j ; while j <= to do ( ( var len : int ; len := words[j+1] - words[_j - 1+1] ; if (len = WORDS[i+1]) then ( _j := j + 1 ; break ) else if (len > WORDS[i+1]) then ( ret := MathLib.bitwiseAnd(ret, false) ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int check(int[] letters,int start,int type){ int len=0 ; for(int i=start ; isize() & len < type do ( ( len := len+(letters[i+1]) ; if (len = type) then ( return i + 1 ) else skip ) ; i := i + 1 ) ; return -1 ); static operation tanku( letters : Sequence(int), start : int) : boolean pre: true post: true activity: ( var ku : Sequence(int) ; ku := Sequence{5,7,5,7,7} ; for (type : ku) do ( ( start := check(letters, start, type) ; if (start = -1) then return false else skip ) ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var words : Sequence(String) ; words := Integer.subrange(1,n)->collect(null) ; var letters : Sequence(int) ; letters := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( words[i+1] := sc.getCurrent() ; letters[i+1] := words[i+1]->size() ) ; i := i + 1 ) ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < n & flag = 0 do ( ( if (tanku(letters, i)) then ( OclFile["System.out"].println(i + 1) ; flag := -1 ; break ) else skip ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class TwoCakes { public static void main(String[] args){ FastReader in=new FastReader(); int n=in.nextInt(); int a[]=new int[n+1]; int b[]=new int[n+1]; for(int i=1 ; i<=2*n ; i++){ int c=in.nextInt(); if(a[c]==0)a[c]=i ; else b[c]=i ; } long ans=0 ; long p=1,q=1 ; for(int i=1 ; i<=n ; i++){ ans+=Math.abs(p-a[i]); p=a[i]; ans+=Math.abs(q-b[i]); q=b[i]; } System.out.println(ans); } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class TwoCakes { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastReader ; in := FastReader.newFastReader() ; var n : int ; n := in.nextInt() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= 2 * n do ( ( var c : int ; c := in.nextInt() ; if (a[c+1] = 0) then a[c+1] := i ; else b[c+1] := i ; ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var p : long ; p := 1 ; var q : long ; q := 1 ; var i : int ; i := 1 ; while i <= n do ( ( ans := ans+(if p - a[i+1] < 0 then -(p - a[i+1]) else p - a[i+1] endif) ; p := a[i+1] ; ans := ans+(if q - b[i+1] < 0 then -(q - b[i+1]) else q - b[i+1] endif) ; q := b[i+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int n=3 ; static class pair { int first,second ; public pair(int first,int second){ this.first=first ; this.second=second ; } } static void findPrefixCount(int p_arr[][],boolean arr[][]){ for(int i=0 ; i=0 ; j--){ if(arr[i][j])continue ; if(j!=n-1)p_arr[i][j]+=p_arr[i][j+1]; p_arr[i][j]+=(arr[i][j]==false ? 1 : 0); } } static int matrixOrValueOne(boolean arr[][]){ int[][] p_arr=new int[n][n]; findPrefixCount(p_arr,arr); int count_zero_submatrices=0 ; for(int j=0 ; jq=new Stack(); int to_sum=0 ; while(i>=0){ int c=0 ; while(q.size()!=0 && q.peek().first>p_arr[i][j]){ to_sum-=(q.peek().second+1)*(q.peek().first-p_arr[i][j]); c+=q.peek().second+1 ; q.pop(); } to_sum+=p_arr[i][j]; count_zero_submatrices+=to_sum ; q.add(new pair(p_arr[i][j],c)); i--; } } return(n*(n+1)*n*(n+1))/4-count_zero_submatrices ; } public static void main(String[] args){ boolean arr[][]={ { false,false,false },{ false,true,false },{ false,false,false } }; System.out.println(matrixOrValueOne(arr)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute n : int := 3; static class pair { attribute first : int; static operation newpair( first : int, second : int) : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(first, second); return self ); operation initialise( first : int, second : int) : void pre: true post: true activity: ( self->at("first") := first ; self->at("second") := second ); } static operation findPrefixCount( p_arr : Sequence(Sequence(int)), arr : Sequence(Sequence(boolean))) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n do ( var j : int ; j := n - 1 ; while j >= 0 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]+((if arr[i+1][j+1] = false then 1 else 0 endif)) ) ; j := j - 1 ) ; ; i := i + 1 ) ); static operation matrixOrValueOne( arr : Sequence(Sequence(boolean))) : int pre: true post: true activity: ( var p_arr : Sequence(Sequence(int)) ; p_arr := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; execute findPrefixCount(p_arr, arr) ; var count_zero_submatrices : int ; count_zero_submatrices := 0 ; var j : int ; j := 0 ; while j < n do ( ( var i : int ; i := n - 1 ; var q : Sequence(pair) ; q := Sequence{} ; var to_sum : int ; to_sum := 0 ; while (i >= 0) do ( var c : int ; c := 0 ; while (q->size() /= 0 & q->min()->at("first") > p_arr[i+1][j+1]) do ( to_sum := to_sum-((q->min()->at("second") + 1) * (q->min()->at("first") - p_arr[i+1][j+1])) ; c := c+(q->min()->at("second") + 1) ; q := q->front() ) ; to_sum := to_sum+(p_arr[i+1][j+1]) ; count_zero_submatrices := count_zero_submatrices+(to_sum) ; q := q->including(pair.newpair(p_arr[i+1][j+1], c)) ; i := i - 1 ; ) ) ; j := j + 1 ) ; return (n * (n + 1) * n * (n + 1)) / 4 - count_zero_submatrices ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(Sequence(boolean)) ; arr := Sequence{Sequence{false,false,false},Sequence{false,true,false},Sequence{false,false,false}} ; OclFile["System.out"].println(matrixOrValueOne(arr)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Main { public static void main(String[] a){ int x=0 ; int y=0 ; int z=0 ; for(x=1 ; x<=9 ; x++){ for(y=1 ; y<=9 ; y++){ z=x*y ; System.out.println(x+"x"+y+"="+z); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 0 ; var y : int ; y := 0 ; var z : int ; z := 0 ; x := 1 ; while x <= 9 do ( ( y := 1 ; while y <= 9 do ( ( z := x * y ; OclFile["System.out"].println(x + "x" + y + "=" + z) ) ; y := y + 1 ) ) ; x := x + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=1000000 ; boolean[] map=new boolean[N+1]; for(int i=1 ; i<=N ; i*=2){ for(int j=1 ; i*j<=N ; j*=3){ for(int k=1 ; i*j*k<=N ; k*=5){ int s=i*j*k ; map[s]=true ; } } } int c=0 ; int[] num=new int[N+1]; for(int i=1 ; i<=N ; i++){ if(map[i])c++; num[i]=c ; } while(true){ int n=scanner.nextInt(); if(n==0)break ; int m=scanner.nextInt(); System.out.println(num[m]-num[n-1]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := 1000000 ; var map : Sequence(boolean) ; map := Integer.subrange(1,N + 1)->collect(false) ; var i : int ; i := 1 ; while i <= N do ( ( var j : int ; j := 1 ; while i * j <= N do ( ( var k : int ; k := 1 ; while i * j * k <= N do ( ( var s : int ; s := i * j * k ; map[s+1] := true ) ; k := k*(5) ) ) ; j := j*(3) ) ) ; i := i*(2) ) ; var c : int ; c := 0 ; var num : Sequence(int) ; num := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i <= N do ( ( if (map[i+1]) then c := c + 1 ; else skip ; num[i+1] := c ) ; i := i + 1 ) ; while (true) do ( var n : int ; n := scanner.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var m : int ; m := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(num[m+1] - num[n - 1+1]) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.util.Arrays.deepToString ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } void tr(Object...os){ System.err.println(deepToString(os)); } Scanner sc=new Scanner(System.in); public void run(){ final int SIZE=1000000+10 ; boolean[] is=new boolean[SIZE]; is[1]=true ; int[] count=new int[SIZE]; for(int i=1 ; icollect(false) ; is[1+1] := true ; var count : Sequence(int) ; count := Integer.subrange(1,SIZE)->collect(0) ; var i : int ; i := 1 ; while i < SIZE do ( ( if (is[i+1]) then ( if (i * 2 < SIZE) then is[i * 2+1] := true ; else skip ; if (i * 3 < SIZE) then is[i * 3+1] := true ; else skip ; if (i * 5 < SIZE) then is[i * 5+1] := true ; else skip ) else skip ; count[i+1] := count[i - 1+1] + (if is[i+1] then 1 else 0 endif) ) ; i := i + 1 ) ; while sc.hasNext() do ( ( var from : int ; from := sc.getCurrent()->toInteger() ; if (from = 0) then break else skip ; var to : int ; to := sc.getCurrent()->toInteger() ; var ans : int ; ans := count[to+1] - count[from - 1+1] ; OclFile["System.out"].println(ans) ; ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader reader=new BufferedReader(isr); String string ; int count ; boolean hamming[]=new boolean[1000001]; hamming[1]=true ; int num[]=new int[] { 2,3,5 }; for(int i=0 ; i<3 ; i++){ for(int j=1 ; j*num[i]<1000001 ; j++){ if(hamming[j*num[i] ])continue ; if(j*num[i] % num[i]==0 && hamming[j*num[i]/num[i] ])hamming[j*num[i] ]=true ; } } while(!(string=reader.readLine()).equals("0")){ count=0 ; for(int i=Integer.valueOf(string.split(" ")[0]); i<=Integer.valueOf(string.split(" ")[1]); i++){ if(hamming[i])count++; } System.out.println(count); } reader.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var reader : OclFile ; reader := OclFile.newOclFile_Read(isr) ; var string : String ; var count : int ; var hamming : Sequence(boolean) ; hamming := Integer.subrange(1,1000001)->collect(false) ; hamming[1+1] := true ; var num : Sequence(int) ; num := Sequence{2,3,5} ; var i : int ; i := 0 ; while i < 3 do ( ( var j : int ; j := 1 ; while j * num[i+1] < 1000001 do ( ( if (hamming[j * num[i+1]+1]) then continue else skip ; if (j * num[i+1] mod num[i+1] = 0 & hamming[j * num[i+1] / num[i+1]+1]) then hamming[j * num[i+1]+1] := true ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; while (not((string) = "0")) do ( count := 0 ; var i : int ; i := (string->split(" ")[0+1])->toInteger() ; while i <= (string->split(" ")[1+1])->toInteger() do ( ( if (hamming[i+1]) then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-9 ; void run(){ int max=1000001 ; int[] memo=new int[max]; boolean[] f=new boolean[max]; LinkedListque=new LinkedList(); que.offer(1); f[1]=true ; int[] ms={ 2,3,5 }; for(; ! que.isEmpty(); ){ int n=que.poll(); for(int m : ms){ if(n*mpow(28)))->oclAsType(long); attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( var max : int ; max := 1000001 ; var memo : Sequence(int) ; memo := Integer.subrange(1,max)->collect(0) ; var f : Sequence(boolean) ; f := Integer.subrange(1,max)->collect(false) ; var que : Sequence(int) ; que := Sequence{} ; que := que->including(1) ; f[1+1] := true ; var ms : Sequence(int) ; ms := Sequence{2,3,5} ; while not(que->isEmpty()) do ( ( var n : int ; n := que->min() ; for (m : ms) do ( ( if (n * m < max & not(f[m * n+1])) then ( que := que->including(n * m) ; f[n * m+1] := true ) else skip ) ) ) ) ; var i : int ; i := 1 ; while i < max do ( ( memo[i+1] := memo[i - 1+1] + (if f[i+1] then 1 else 0 endif) ) ; i := i + 1 ) ; while true do ( ( var m : int ; m := sc.getCurrent()->toInteger() ; if (m = 0) then ( break ) else skip ; var n : int ; n := sc.getCurrent()->toInteger() ; execute println("" + (memo[n+1] - memo[m - 1+1])) ) ) ; ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); while(stdIn.hasNext()){ int s=stdIn.nextInt(); if(s==0){ break ; } int t=stdIn.nextInt(); Queueque1=new ArrayDeque(); Queueque2=new ArrayDeque(); boolean[] flag1=new boolean[t+1]; boolean[] flag2=new boolean[s+1]; int count1=0 ; int count2=0 ; if(s==1){ ++count1 ; } que1.add(1); while(! que1.isEmpty()){ int n=que1.poll(); if(n*2<=t && ! flag1[n*2]){ flag1[n*2]=true ; que1.add(n*2); ++count1 ; } if(n*3<=t && ! flag1[n*3]){ flag1[n*3]=true ; que1.add(n*3); ++count1 ; } if(n*5<=t && ! flag1[n*5]){ flag1[n*5]=true ; que1.add(n*5); ++count1 ; } } que2.add(1); while(! que2.isEmpty()){ int n=que2.poll(); if(n*2toInteger() ; if (s = 0) then ( break ) else skip ; var t : int ; t := stdIn.getCurrent()->toInteger() ; var que1 : Sequence(int) ; que1 := ArrayDeque.newArrayDeque() ; var que2 : Sequence(int) ; que2 := ArrayDeque.newArrayDeque() ; var flag1 : Sequence(boolean) ; flag1 := Integer.subrange(1,t + 1)->collect(false) ; var flag2 : Sequence(boolean) ; flag2 := Integer.subrange(1,s + 1)->collect(false) ; var count1 : int ; count1 := 0 ; var count2 : int ; count2 := 0 ; if (s = 1) then ( count1 := count1 + 1 ) else skip ; que1 := que1->including(1) ; while (not(que1->isEmpty())) do ( var n : int ; n := que1->min() ; if (n * 2 <= t & not(flag1[n * 2+1])) then ( flag1[n * 2+1] := true ; que1 := que1->including(n * 2) ; count1 := count1 + 1 ) else skip ; if (n * 3 <= t & not(flag1[n * 3+1])) then ( flag1[n * 3+1] := true ; que1 := que1->including(n * 3) ; count1 := count1 + 1 ) else skip ; if (n * 5 <= t & not(flag1[n * 5+1])) then ( flag1[n * 5+1] := true ; que1 := que1->including(n * 5) ; count1 := count1 + 1 ) else skip ) ; que2 := que2->including(1) ; while (not(que2->isEmpty())) do ( var n : int ; n := que2->min() ; if (n * 2 < s & not(flag2[n * 2+1])) then ( flag2[n * 2+1] := true ; que2 := que2->including(n * 2) ; count2 := count2 + 1 ) else skip ; if (n * 3 < s & not(flag2[n * 3+1])) then ( flag2[n * 3+1] := true ; que2 := que2->including(n * 3) ; count2 := count2 + 1 ) else skip ; if (n * 5 < s & not(flag2[n * 5+1])) then ( flag2[n * 5+1] := true ; que2 := que2->including(n * 5) ; count2 := count2 + 1 ) else skip ) ; OclFile["System.out"].println(count1 - count2) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int counter=0 ; int n=sc.nextInt(); int[] s=new int[n]; for(int i=0 ; itoInteger() ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < s->size() do ( ( s[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var q : int ; q := sc.getCurrent()->toInteger() ; var t : Sequence(int) ; t := Integer.subrange(1,q)->collect(0) ; var i : int ; i := 0 ; while i < t->size() do ( ( t[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t->size() do ( ( var j : int ; j := 0 ; while j < s->size() do ( ( if (t[i+1] = s[j+1]) then ( counter := counter + 1 ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int count=0 ; public static void main(String[] args){ @ SuppressWarnings("resource")Scanner sc2=new Scanner(System.in); boolean[] check=new boolean[10000000]; for(int i=0 ; icollect(false) ; var i : int ; i := 0 ; while i < check->size() do ( check[i+1] := false ; ; i := i + 1 ) ; var n : int ; n := (sc2.nextLine())->toInteger() ; var s : Sequence(String) ; s := sc2.nextLine()->split("[\\s]+") ; var i : int ; i := 0 ; while i < n do ( check[(s[i+1])->toInteger()+1] := true ; ; i := i + 1 ) ; var n2 : int ; n2 := (sc2.nextLine())->toInteger() ; var s2 : Sequence(String) ; s2 := sc2.nextLine()->trim()->split("[\\s]+") ; var i : int ; i := 0 ; while i < n2 do ( ( if (check[(s2[i+1])->toInteger()+1]) then ( count := count + 1 ; check[(s2[i+1])->toInteger()+1] := false ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(){ java.util.Scanner sc=new java.util.Scanner(System.in); java.util.Setlis=new java.util.TreeSet(); int res=0 ; int n ; int i ; n=sc.nextInt(); for(i=0 ; i ; lis := TreeSet.newTreeSet() ; var res : int ; res := 0 ; var n : int ; var i : int ; n := sc.nextInt() ; i := 0 ; while i < n do ( lis->excludes(sc.nextInt()) ; ; i := i + 1 ) ; n := sc.nextInt() ; i := 0 ; while i < n do ( if (lis->includes(sc.nextInt())) then res := res + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(res) ; return ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run() ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import java.awt.Point ; import java.io.*; public class Exercise { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int array[][]=new int[2][n+1]; for(int i=1 ; i<=n*2 ; i++){ int nm=sc.nextInt(); if(array[0][nm]==0)array[0][nm]=i ; else array[1][nm]=i ; } int idxo=1,idxt=1 ; long sumo=0,sumt=0 ; for(int i=1 ; i<=n ; i++){ sumo+=abs(array[0][i]-idxo); sumt+=abs(array[1][i]-idxt); idxo=array[0][i]; idxt=array[1][i]; } System.out.println(sumo+sumt); } } ------------------------------------------------------------ OCL File: --------- class Exercise { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var array : Sequence(Sequence(int)) ; array := Integer.subrange(1,2)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= n * 2 do ( ( var nm : int ; nm := sc.getCurrent()->toInteger() ; if (array[0+1][nm+1] = 0) then array[0+1][nm+1] := i ; else array[1+1][nm+1] := i ; ) ; i := i + 1 ) ; var idxo : int ; idxo := 1 ; var idxt : int ; idxt := 1 ; var sumo : long ; sumo := 0 ; var sumt : long ; sumt := 0 ; var i : int ; i := 1 ; while i <= n do ( ( sumo := sumo+(abs(array[0+1][i+1] - idxo)) ; sumt := sumt+(abs(array[1+1][i+1] - idxt)) ; idxo := array[0+1][i+1] ; idxt := array[1+1][i+1] ) ; i := i + 1 ) ; OclFile["System.out"].println(sumo + sumt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.BitSet ; import java.util.Scanner ; public class Main { private static BitSet S=new BitSet(); private static BitSet T=new BitSet(); public static void main(String[] args)throws IOException { S.clear(); T.clear(); Scanner in=new Scanner(System.in); int n=in.nextInt(); while(n-->0){ S.set(in.nextInt()); } int q=in.nextInt(); while(q-->0){ T.set(in.nextInt()); } S.and(T); System.out.println(S.cardinality()); in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute S : Sequence(boolean) := MathLib.toBitSequence(); static attribute T : Sequence(boolean) := MathLib.toBitSequence(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( S := S->intersection(Set{}) ; T := T->intersection(Set{}) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( S := S.setAt(in.getCurrent()->toInteger()+1, true) ) ; ) ; var q : int ; q := in.getCurrent()->toInteger() ; while (q > 0) do ( q := q - 1 ; skip ; ( T := T.setAt(in.getCurrent()->toInteger()+1, true) ) ; ) ; S := S.and(T) ; OclFile["System.out"].println(S.cardinality()) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Main { private static int[] parseIntAll(String[] strings){ int[] result=new int[strings.length]; for(int i=0 ; i=0){ c++; } } System.out.println(c); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation parseIntAll( strings : Sequence(String)) : Sequence(int) pre: true post: true activity: ( var result : Sequence(int) ; result := Integer.subrange(1,strings->size())->collect(0) ; var i : int ; i := 0 ; while i < strings->size() do ( ( result[i+1] := (strings[i+1])->toInteger() ) ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (r.readLine())->toInteger() ; var s : Sequence(int) ; s := parseIntAll(r.readLine()->split(" ")) ; var q : int ; q := (r.readLine())->toInteger() ; var t : Sequence(int) ; t := parseIntAll(r.readLine()->split(" ")) ; s := s->sort() ; var c : int ; c := 0 ; for (x : t) do ( ( if ((s->indexOf(x) - 1) >= 0) then ( c := c + 1 ) else skip ) ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner cin=new Scanner(System.in); solve(); } public static void solve(){ for(int i=1 ; i<=9 ; i++){ for(int j=1 ; j<=9 ; j++){ System.out.printf("%dx%d=%d\n",i,j,i*j); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; execute solve() ); static operation solve() : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= 9 do ( ( var j : int ; j := 1 ; while j <= 9 do ( ( OclFile["System.out"].printf("%dx%d=%d\n", i, j, i * j) ) ; j := j + 1 ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int MOD=32768 ; int T=Integer.parseInt(sc.next()); while(T-->0){ int number=Integer.parseInt(sc.next()); int res=Integer.MAX_VALUE ; for(int add=0 ; add<=15 ; add++){ for(int mul=0 ; mul<=15 ; mul++){ if((number+add)*Math.pow(2,mul)% MOD==0){ res=Math.min(res,add+mul); } } } System.out.println(res); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var MOD : int ; MOD := 32768 ; var T : int ; T := (sc.getCurrent())->toInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( var number : int ; number := (sc.getCurrent())->toInteger() ; var res : int ; res := 2147483647 ; var add : int ; add := 0 ; while add <= 15 do ( ( var mul : int ; mul := 0 ; while mul <= 15 do ( ( if ((number + add) * 2->pow(mul) mod MOD = 0) then ( res := Set{res, add + mul}->min() ) else skip ) ; mul := mul + 1 ) ) ; add := add + 1 ) ; OclFile["System.out"].println(res) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1405 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t,n,i ; t=sc.nextInt(); while(t-->0){ n=sc.nextInt(); int arr[]=new int[n]; for(i=0 ; i=0 ; i--)System.out.print(arr[i]+" "); System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class A1405 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; var n : int ; var i : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < n do ( arr[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; i := n - 1 ; while i >= 0 do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i - 1 ) ; OclFile["System.out"].println() ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication75 { public static void main(String[] args){ Scanner read=new Scanner(System.in); int t=read.nextInt(); while(t-->0){ int n=read.nextInt(); int[] ar=new int[n]; for(int i=0 ; i-1 ; i--)System.out.print(ar[i]+" "); System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class JavaApplication75 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var read : OclFile ; read := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := read.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := read.getCurrent()->toInteger() ; var ar : Sequence(int) ; ar := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ar[i+1] := read.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := n - 1 ; while i > -1 do ( OclFile["System.out"].print(ar[i+1] + " ") ; ; i := i - 1 ) ; OclFile["System.out"].println() ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Test { public static void main(String[] args){ Scanner input=new Scanner(System.in); int t=input.nextInt(); while(t-->0){ int n=input.nextInt(); int[] p=new int[n]; for(int i=0 ; i=0 ; i--){ System.out.print(p[i]+" "); } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := input.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := input.getCurrent()->toInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( OclFile["System.out"].print(p[i+1] + " ") ) ; i := i - 1 ) ; OclFile["System.out"].println() ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1405 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ int n=scanner.nextInt(); int[] p=new int[n]; for(int i=0 ; i=0 ; i--){ System.out.print(p[i]+" "); } System.out.println(); } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class A1405 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( OclFile["System.out"].print(p[i+1] + " ") ) ; i := i - 1 ) ; OclFile["System.out"].println() ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { static int factorial(int n){ if(n==0)return 1 ; return n*factorial(n-1); } public static void main(String[] args){ int num=5 ; System.out.println("Factorial of "+num+" is "+factorial(5)); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation factorial( n : int) : int pre: true post: true activity: ( if (n = 0) then return 1 else skip ; return n * factorial(n - 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 5 ; OclFile["System.out"].println("Factorial of " + num + " is " + factorial(5)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printMaxSum(int arr[],int n){ int dp[]=new int[n]; Arrays.fill(dp,0); for(int i=0 ; imaxi)maxi=dp[j-1]; if(dp[(i+1)/j-1]>maxi && j!=1)maxi=dp[(i+1)/j-1]; } } dp[i]+=maxi ; } for(int i=0 ; icollect(0) ; dp := dp->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( dp[i+1] := arr[i+1] ; var maxi : int ; maxi := 0 ; var j : int ; j := 1 ; while j <= (i + 1)->sqrt() do ( ( if (((i + 1) mod j = 0) & (i + 1) /= j) then ( if (dp[j - 1+1] > maxi) then maxi := dp[j - 1+1] ; else skip ; if (dp[(i + 1) / j - 1+1] > maxi & j /= 1) then maxi := dp[(i + 1) / j - 1+1] ; else skip ) else skip ) ; j := j + 1 ) ; dp[i+1] := dp[i+1]+(maxi) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(dp[i+1] + " ") ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,3,1,4,6,5} ; var n : int ; n := arr->size() ; execute printMaxSum(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static final int MOD=1000000007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); boolean[] isNotPrimes=new boolean[1000001]; isNotPrimes[0]=true ; isNotPrimes[1]=true ; for(int i=2 ; i=2 && arr[i-2]collect(false) ; isNotPrimes[0+1] := true ; isNotPrimes[1+1] := true ; var i : int ; i := 2 ; while i < isNotPrimes->size() do ( ( if (isNotPrimes[i+1]) then ( continue ) else skip ; var j : int ; j := 2 ; while j * i < isNotPrimes->size() do ( ( isNotPrimes[i * j+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; if (not(isNotPrimes[arr[0+1]+1])) then ( dp[0+1][0+1] := 1 ) else skip ; var i : int ; i := 1 ; while i < n do ( ( dp[i+1][1+1] := dp[i+1][1+1]+(dp[i - 1+1][0+1]) ; dp[i+1][1+1] := dp[i+1][1+1] mod MOD ; if (not(isNotPrimes[arr[i+1]+1])) then ( if (i >= 2 & arr[i - 2+1] < arr[i+1]) then ( dp[i+1][0+1] := dp[i+1][0+1]+(dp[i - 1+1][1+1]) ; dp[i+1][0+1] := dp[i+1][0+1] mod MOD ) else skip ; if (arr[i - 1+1] < arr[i+1]) then ( dp[i+1][0+1] := dp[i+1][0+1]+(dp[i - 1+1][0+1]) ; dp[i+1][0+1] := dp[i+1][0+1] mod MOD ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println((dp[n - 1+1][0+1] + dp[n - 1+1][1+1]) mod MOD) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void Cholesky_Decomposition(int[][] matrix,int n){ int[][] lower=new int[n][n]; for(int i=0 ; icollect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j <= i do ( ( var sum : int ; sum := 0 ; if (j = i) then ( var k : int ; k := 0 ; while k < j do ( sum := sum+(lower[j+1][k+1]->pow(2)->oclAsType(int)) ; ; k := k + 1 ) ; lower[j+1][j+1] := (matrix[j+1][j+1] - sum)->sqrt()->oclAsType(int) ) else ( var k : int ; k := 0 ; while k < j do ( sum := sum+((lower[i+1][k+1] * lower[j+1][k+1])) ; ; k := k + 1 ) ; lower[i+1][j+1] := (matrix[i+1][j+1] - sum) / lower[j+1][j+1] ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(" Lower Triangular\t Transpose") ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( OclFile["System.out"].print(lower[i+1][j+1] + "\t") ; ; j := j + 1 ) ; OclFile["System.out"].print("") ; var j : int ; j := 0 ; while j < n do ( OclFile["System.out"].print(lower[j+1][i+1] + "\t") ; ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; var matrix : Sequence(Sequence(int)) ; matrix := Sequence{Sequence{4,12,-16},Sequence{12,37,-43},Sequence{-16,-43,98}} ; execute Cholesky_Decomposition(matrix, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void CheckSubarray(int arr[],int N){ int[] presum=new int[N+1]; for(int i=1 ; i<=N ; i+=1){ presum[i]=presum[i-1]+arr[i-1]; } Vector[] moduloclass=new Vector[N]; for(int i=0 ; i(); } for(int i=1 ; i<=N ; i+=1){ moduloclass[presum[i] % N] .add(i-1); } if(moduloclass[0] .size()>0){ System.out.print(0+" "+moduloclass[0] .get(0)); return ; } for(int i=1 ; i=2){ System.out.print(moduloclass[i] .get(0)+1+" "+moduloclass[i] .get(1)); return ; } } } public static void main(String args[]){ int arr[]={ 7,3,5,2 }; int N=arr.length ; CheckSubarray(arr,N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation CheckSubarray( arr : Sequence(int), N : int) : void pre: true post: true activity: ( var presum : Sequence(int) ; presum := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i <= N do ( ( presum[i+1] := presum[i - 1+1] + arr[i - 1+1] ) ; i := i+(1) ) ; var moduloclass : Sequence(Sequence(int)) ; moduloclass := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( moduloclass[i+1] := Sequence{} ) ; i := i+(1) ) ; var i : int ; i := 1 ; while i <= N do ( ( moduloclass[presum[i+1] mod N+1]->excludes(i - 1) ) ; i := i+(1) ) ; if (moduloclass[0+1]->size() > 0) then ( OclFile["System.out"].print(0 + " " + moduloclass[0+1]->at(0+1)) ; return ) else skip ; var i : int ; i := 1 ; while i < N do ( ( if (moduloclass[i+1]->size() >= 2) then ( OclFile["System.out"].print(moduloclass[i+1]->at(0+1) + 1 + " " + moduloclass[i+1]->at(1+1)) ; return ) else skip ) ; i := i+(1) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{7,3,5,2} ; var N : int ; N := arr->size() ; execute CheckSubarray(arr, N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static void MakePreSum(int[] arr,int[] presum,int n){ presum[0]=arr[0]; for(int i=1 ; i=0 ; i--){ if(pos+(1<log()->oclAsType(int) ; if (x <= presum[0+1]) then return 0 else skip ; var i : int ; i := LOGN ; while i >= 0 do ( ( if (pos + ((1*(2->pow(i)))->oclAsType(long)) < n & presum[pos + ((1*(2->pow(i)))->oclAsType(long))+1] < x) then ( pos := pos+(((1*(2->pow(i)))->oclAsType(long))) ) else skip ) ; i := i - 1 ) ; return pos + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,5,7,1,6,9,12,4,6} ; var x : int ; x := 8 ; var n : int ; n := arr->size() ; var presum : Sequence(int) ; presum := Integer.subrange(1,n)->collect(0) ; presum := presum->collect(0) ; execute MakePreSum(arr, presum, n) ; OclFile["System.out"].println(BinaryLifting(presum, n, x)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); boolean[] num=new boolean[n+1]; int[] prime=new int[n+1]; Arrays.fill(num,true); for(int i=2 ; i<=n/2 ; i++){ if(isPrime(i))for(int j=2*i ; j<=n ; j+=i){ num[j]=false ; } } int j=0 ; for(int i=2 ; i<=n ; i++){ if(num[i])prime[j++]=i ; } int value=0 ; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var num : Sequence(boolean) ; num := Integer.subrange(1,n + 1)->collect(false) ; var prime : Sequence(int) ; prime := Integer.subrange(1,n + 1)->collect(0) ; num := num->collect(true) ; var i : int ; i := 2 ; while i <= n / 2 do ( ( if (isPrime(i)) then var j : int ; j := 2 * i ; while j <= n do ( ( num[j+1] := false ) ; j := j+(i) ) ; else skip ) ; i := i + 1 ) ; var j : int ; j := 0 ; var i : int ; i := 2 ; while i <= n do ( ( if (num[i+1]) then prime[j+1] := i ; j := j + 1 ; else skip ) ; i := i + 1 ) ; var value : int ; value := 0 ; var i : int ; i := 0 ; while i < j do ( ( var z : int ; z := 0 ; while z < i do ( ( if (prime[z+1] + prime[z + 1+1] + 1 = prime[i+1]) then ( value := value + 1 ; break ) else skip ) ; z := z + 1 ) ) ; i := i + 1 ) ; if (value < k) then OclFile["System.out"].println("NO") else OclFile["System.out"].println("YES") ; ; ); static operation isPrime( x : int) : boolean pre: true post: true activity: ( if (x = 2 or x = 3) then return true else skip ; var k : int ; k := 2 ; while k <= (x)->sqrt() do ( ( if (x mod k = 0) then return false else skip ) ; k := k + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); boolean[] num=new boolean[n+1]; int[] prime=new int[n+1]; Arrays.fill(num,true); for(int i=2 ; i<=n/2 ; i++){ if(isPrime(i))for(int j=2*i ; j<=n ; j+=i){ num[j]=false ; } } int j=0 ; for(int i=2 ; i<=n ; i++){ if(num[i])prime[j++]=i ; } int value=0 ; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var num : Sequence(boolean) ; num := Integer.subrange(1,n + 1)->collect(false) ; var prime : Sequence(int) ; prime := Integer.subrange(1,n + 1)->collect(0) ; num := num->collect(true) ; var i : int ; i := 2 ; while i <= n / 2 do ( ( if (isPrime(i)) then var j : int ; j := 2 * i ; while j <= n do ( ( num[j+1] := false ) ; j := j+(i) ) ; else skip ) ; i := i + 1 ) ; var j : int ; j := 0 ; var i : int ; i := 2 ; while i <= n do ( ( if (num[i+1]) then prime[j+1] := i ; j := j + 1 ; else skip ) ; i := i + 1 ) ; var value : int ; value := 0 ; var i : int ; i := 0 ; while i < j do ( ( var z : int ; z := 0 ; while z < i do ( ( if (prime[z+1] + prime[z + 1+1] + 1 = prime[i+1]) then ( value := value + 1 ; break ) else skip ) ; z := z + 1 ) ) ; i := i + 1 ) ; if (value < k) then OclFile["System.out"].println("NO") else OclFile["System.out"].println("YES") ; ; ); static operation isPrime( x : int) : boolean pre: true post: true activity: ( if (x = 2 or x = 3) then return true else skip ; var k : int ; k := 2 ; while k <= (x)->sqrt() do ( ( if (x mod k = 0) then return false else skip ) ; k := k + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int[] nums=new int[10]; String s ; while(sc.hasNext()){ s=sc.next(); for(int i=0 ; i<10 ; i++){ nums[i]=Character.getNumericValue(s.charAt(i)); } for(int i=0 ; i<9 ; i++){ for(int j=0 ; j<9-i ; j++){ nums[j]=(nums[j]+nums[j+1])% 10 ; } } out.println(nums[0]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var nums : Sequence(int) ; nums := Integer.subrange(1,10)->collect(0) ; var s : String ; while (sc.hasNext()) do ( s := sc.getCurrent() ; var i : int ; i := 0 ; while i < 10 do ( ( nums[i+1] := ("" + s->at(i+1))->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 9 do ( ( var j : int ; j := 0 ; while j < 9 - (i)->char2byte() do ( ( nums[j+1] := (nums[j+1] + nums[j + 1+1]) mod 10 ) ; j := j + 1 ) ) ; i := i + 1 ) ; out.println(nums[0+1]) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); String s ; char[] c ; int i,j ; c=new char[10]; for(; sc.hasNext(); ){ s=sc.next(); for(i=0 ; i<10 ; i++)c[i]=(char)(s.charAt(i)-'0'); for(i=0 ; i<10-1 ; i++){ for(j=0 ; j<9-i ; j++){ c[j]+=c[j+1]; c[j]=(char)(c[j] % 10); } } out.println((char)(c[0]+'0')); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var s : String ; var c : Sequence(String) ; var i : int ; var j : int ; c := Integer.subrange(1,10)->collect(0) ; while sc.hasNext() do ( ( s := sc.next() ; i := 0 ; while i < 10 do ( c[i+1] := (s->at(i+1) - ('0')->char2byte())->oclAsType(String) ; ; i := i + 1 ) ; i := 0 ; while i < 10 - 1 do ( ( j := 0 ; while j < 9 - i do ( ( c[j+1] := c[j+1]+(c[j + 1+1]) ; c[j+1] := (c[j+1] mod 10)->oclAsType(String) ) ; j := j + 1 ) ) ; i := i + 1 ) ; out.println((c[0+1] + '0')->oclAsType(String)) ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static int solve(char[] c){ if(c.length==1)return c[0]-'0' ; String ret="" ; for(int i=0 ; isize() = 1) then return c[0+1] - ('0')->char2byte() else skip ; var ret : String ; ret := "" ; var i : int ; i := 0 ; while i < c->size() - 1 do ( ret := ret+(((c[i+1] - ('0')->char2byte()) + (c[i + 1+1] - ('0')->char2byte())) mod 10) ; ; i := i + 1 ) ; return solve(ret->characters()) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := "" ; line := br.readLine() ; while ((line) /= null) do ( skip ; ( OclFile["System.out"].println(solve(line->characters())) ; line := null ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); for(; scanner.hasNext(); ){ String input=scanner.next(); ArrayListn=new ArrayList<>(); for(int i=0 ; im=new ArrayList<>(); for(int i=0 ; isize() do ( ( n := n->including((input.subrange(i+1,i + 1))->toInteger()) ) ; i := i + 1 ) ; while true do ( ( var m : Sequence(int) ; m := Sequence{} ; var i : int ; i := 0 ; while i < n->size() - 1 do ( ( m := m->including((n->at(i+1) + n->at(i + 1+1)) mod 10) ) ; i := i + 1 ) ; n := m ; if (m->size() = 1) then ( OclFile["System.out"].println(m->at(0+1)) ; break ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int[] compute_lps(String s){ int n=s.length(); int[] lps=new int[n]; int len=0 ; lps[0]=0 ; int i=1 ; while(isize() ; var lps : Sequence(int) ; lps := Integer.subrange(1,n)->collect(0) ; var len : int ; len := 0 ; lps[0+1] := 0 ; var i : int ; i := 1 ; while (i < n) do ( if (s->at(i+1) = s->at(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 ); static operation Longestsubstring( s : String) : void pre: true post: true activity: ( var lps : Sequence(int) ; lps := compute_lps(s) ; var n : int ; n := s->size() ; if (lps[n - 1+1] = 0) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (lps[i+1] = lps[n - 1+1]) then ( OclFile["System.out"].println(s.subrange(0+1,lps[i+1])) ; return ) else skip ) ; i := i + 1 ) ; if (lps[lps[n - 1+1] - 1+1] = 0) then OclFile["System.out"].println(-1) else OclFile["System.out"].println(s.subrange(0+1,lps[lps[n - 1+1] - 1+1])) ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "fixprefixsuffix" ; execute Longestsubstring(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ try { System.setIn(new FileInputStream("src/xxxyyyy/input.txt")); System.setOut(new PrintStream(new FileOutputStream("src/xxxyyyy/result.txt"))); } catch(FileNotFoundException e){ } new Main().run(); } void run(){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String s=sc.next(); int array[]=new int[10]; for(int i=0 ; i<10 ; i++){ array[i]=s.charAt(i)-'0' ; } for(int row=1 ; row<10 ; row++){ int next[]=new int[10]; for(int i=0 ; i<10-row ; i++){ next[i]=(array[i]+array[i+1])% 10 ; } array=next ; } System.out.println(array[0]); } } void debug(Object...os){ System.err.println(deepToString(os)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( setIn(OclFile.newOclFile_Read(OclFile.newOclFile("src/xxxyyyy/input.txt"))) ; setOut(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("src/xxxyyyy/result.txt")))) ) catch (e : FileNotFoundException) do skip Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var s : String ; s := sc.getCurrent() ; var array : Sequence(int) ; array := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < 10 do ( ( array[i+1] := s->at(i+1) - ('0')->char2byte() ) ; i := i + 1 ) ; var row : int ; row := 1 ; while row < 10 do ( ( var next : Sequence(int) ; next := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < 10 - row do ( ( next[i+1] := (array[i+1] + array[i + 1+1]) mod 10 ) ; i := i + 1 ) ; array := next ) ; row := row + 1 ) ; OclFile["System.out"].println(array[0+1]) ; ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); String s="qwertyuiopasdfghjkl;zxcvbnm,./" ; String dir=in.next(); String str=in.next(); String res="" ; for(int i=0 ; isize() do ( ( if (dir = "R") then ( res := res+(s->at(s->indexOf(str->at(i+1))-1 - 1+1)) ) else ( res := res+(s->at(s->indexOf(str->at(i+1))-1 + 1+1)) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); char direction=sc.nextLine().charAt(0); String s=sc.nextLine(); StringBuilder org=new StringBuilder(""); String[] kb={ "qwertyuiop","asdfghjkl;","zxcvbnm,./" }; for(int i=0 ; iat(0+1) ; var s : String ; s := sc.nextLine() ; var org : String ; org := StringLib.newString("") ; var kb : Sequence(String) ; kb := Sequence{"qwertyuiop","asdfghjkl;","zxcvbnm,./"} ; var i : int ; i := 0 ; while i < s->size() do ( ( var c : String ; c := s->at(i+1) ; var j : int ; j := 0 ; while j < kb->size() do ( ( var index : int ; index := kb[j+1]->indexOf(c)-1 ; if (index /= -1) then ( if (direction = 'R') then index := index-(1) else index := index+(1) ; ; org := org + StringLib.newString(kb[j+1]->at(index+1)) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(org) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); String S="qwertyuiopasdfghjkl;zxcvbnm,./" ; char D=input.next().charAt(0); String R=input.next(); int a ; char check ; if(D=='R'){ for(int i=0 ; iat(0+1) ; var R : String ; R := input.getCurrent() ; var a : int ; var check : String ; if (D = 'R') then ( var i : int ; i := 0 ; while i < R->size() do ( ( check := R->at(i+1) ; a := S->indexOf(check)-1 - 1 ; OclFile["System.out"].print(S->at(a+1)) ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < R->size() do ( ( check := R->at(i+1) ; a := S->indexOf(check)-1 + 1 ; OclFile["System.out"].print(S->at(a+1)) ) ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int Permutations(int n,int k){ int 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 ; } public static void main(String[] args){ int n=5,k=2 ; System.out.println(Permutations(n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Permutations( n : int, k : int) : int pre: true post: true activity: ( var ans : int ; ans := 1 ; if (k >= 2) then ans := ans+((n) * (n - 1) / 2) ; else skip ; if (k >= 3) then ans := ans+((n) * (n - 1) * (n - 2) * 2 / 6) ; else skip ; if (k >= 4) then ans := ans+((n) * (n - 1) * (n - 2) * (n - 3) * 9 / 24) ; else skip ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var k : int ; k := 2 ; OclFile["System.out"].println(Permutations(n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s="qwertyuiopasdfghjkl;zxcvbnm,./" ; String x=sc.next(); String y=sc.next(); String ans="" ; char temp ; int c ; for(int i=0 ; isize() do ( ( if (x = "R") then ( temp := y->at(i+1) ; var j : int ; j := 0 ; while j < s->size() do ( ( if (temp = s->at(j+1)) then ( c := j - 1 ; ans := ans+(s->at(c+1)) ) else skip ) ; j := j + 1 ) ) else ( temp := y->at(i+1) ; var j : int ; j := 0 ; while j < s->size() do ( ( if (temp = s->at(j+1)) then ( c := j + 1 ; ans := ans+(s->at(c+1)) ) else skip ) ; j := j + 1 ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A474 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String ch=sc.nextLine(); String s=sc.nextLine(); char[] keyboard={ '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',',','.','/' }; if(ch.contains("R")){ for(int i=0 ; iincludes("R")) then ( var i : int ; i := 0 ; while i < s->size() do ( ( var k : int ; k := 0 ; while k < keyboard->size() do ( ( if (s->at(i+1) = keyboard[k+1]) then ( OclFile["System.out"].print(keyboard[k - 1+1]) ) else skip ) ; k := k + 1 ) ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < s->size() do ( ( var k : int ; k := 0 ; while k < keyboard->size() do ( ( if (s->at(i+1) = keyboard[k+1]) then ( OclFile["System.out"].print(keyboard[k + 1+1]) ) else skip ) ; k := k + 1 ) ) ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static final int MAX_CHAR=26 ; static boolean areKAnagrams(String str1,String str2,int k){ int n=str1.length(); if(str2.length()!=n)return false ; int[] hash_str1=new int[MAX_CHAR]; for(int i=0 ; i0)hash_str1[str2.charAt(i)-'a']--; else count++; if(count>k)return false ; } return true ; } public static void main(String args[]){ String str1="fodr" ; String str2="gork" ; int k=2 ; if(areKAnagrams(str1,str2,k)==true)System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX_CHAR : int := 26; static operation areKAnagrams( str1 : String, str2 : String, k : int) : boolean pre: true post: true activity: ( var n : int ; n := str1->size() ; if (str2->size() /= n) then return false else skip ; var hash_str1 : Sequence(int) ; hash_str1 := Integer.subrange(1,MAX_CHAR)->collect(0) ; var i : int ; i := 0 ; while i < n do ( hash_str1[str1->at(i+1) - ('a')->char2byte()+1] := hash_str1[str1->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (hash_str1[str2->at(i+1) - ('a')->char2byte()+1] > 0) then hash_str1[str2->at(i+1) - ('a')->char2byte()+1] := hash_str1[str2->at(i+1) - ('a')->char2byte()+1] - 1 else count := count + 1 ; ; if (count > k) then return false else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str1 : String ; str1 := "fodr" ; var str2 : String ; str2 := "gork" ; var k : int ; k := 2 ; if (areKAnagrams(str1, str2, k) = true) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Main main=new Main(); Scanner sc=new Scanner(System.in); String cases=sc.nextLine(); String[] nums=cases.split(" "); System.out.println(main.solution(Integer.parseInt(nums[0]),Integer.parseInt(nums[1]),Integer.parseInt(nums[2]))); } public int solution(int yellow,int blue,int red){ int counter ; int min=Math.min(Math.min(yellow,blue),red); if(min==red){ counter=(red*3)-3 ; } else if(min==blue){ counter=blue*3 ; } else { counter=(yellow+1==blue)?(blue==red ?(red*3)-3 :(yellow*3)+3):((yellow+1==red)?(red*3)-3 :(yellow*3)+3); } return counter ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var cases : String ; cases := sc.nextLine() ; var nums : Sequence(String) ; nums := cases->split(" ") ; OclFile["System.out"].println(main.solution((nums[0+1])->toInteger(), (nums[1+1])->toInteger(), (nums[2+1])->toInteger())) ; ); operation solution( yellow : int, blue : int, red : int) : int pre: true post: true activity: ( var counter : int ; var min : int ; min := Set{Set{yellow, blue}->min(), red}->min() ; if (min = red) then ( counter := (red * 3) - 3 ) else if (min = blue) then ( counter := blue * 3 ) else ( counter := if (yellow + 1 = blue) then (if blue = red then (red * 3) - 3 else (yellow * 3) + 3 endif) else (if (yellow + 1 = red) then (red * 3) - 3 else (yellow * 3) + 3 endif) endif ) ; ; return counter ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class P1091A { public static void main(String[] args)throws IOException { BufferedReader io=new BufferedReader(new InputStreamReader(System.in)); String[] ybr=io.readLine().split(" "); Integer y=Integer.valueOf(ybr[0]); Integer b=Integer.valueOf(ybr[1]); Integer r=Integer.valueOf(ybr[2]); Integer rs=0 ; for(int i=1 ; i<=y ; i++){ if(!((i+1)<=b &&(i+2)<=r)){ break ; } else { rs=i ; } } System.out.println((rs)*3+3); } } ------------------------------------------------------------ OCL File: --------- class P1091A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : OclFile ; io := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var ybr : Sequence(String) ; ybr := io.readLine()->split(" ") ; var y : int ; y := (ybr[0+1])->toInteger() ; var b : int ; b := (ybr[1+1])->toInteger() ; var r : int ; r := (ybr[2+1])->toInteger() ; var rs : int ; rs := 0 ; var i : int ; i := 1 ; while i <= y do ( ( if (not(((i + 1) <= b & (i + 2) <= r))) then ( break ) else ( rs := i ) ) ; i := i + 1 ) ; OclFile["System.out"].println((rs) * 3 + 3) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); int count=0,max=0 ; for(int i=0 ; i2){ max=max+1 ; } } else { count=0 ; } } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var count : int ; count := 0 ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = 'x') then ( count := count + 1 ; if (count > 2) then ( max := max + 1 ) else skip ) else ( count := 0 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class A { public static void main(String[] args){ FastScanner fs=new FastScanner(); int a=fs.nextInt(); int b=fs.nextInt(); int c=fs.nextInt(); int res=Math.min(a,Math.min(b-1,c-2)); System.out.println(res*3+3); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next(){ while(! st.hasMoreElements())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fs : FastScanner ; fs := FastScanner.newFastScanner() ; var a : int ; a := fs.nextInt() ; var b : int ; b := fs.nextInt() ; var c : int ; c := fs.nextInt() ; var res : int ; res := Set{a, Set{b - 1, c - 2}->min()}->min() ; OclFile["System.out"].println(res * 3 + 3) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int y=sc.nextInt(); int b=sc.nextInt(); int r=sc.nextInt(); int total=0 ; if(y<=b-1 && y<=r-2){ total=3*y+3 ; } else if(b-1<=y && b-1<=r-2){ total=3*b ; } else if(r-2<=y && r-2<=b-1){ total=3*r-3 ; } System.out.println(total); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var y : int ; y := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var total : int ; total := 0 ; if (y <= b - 1 & y <= r - 2) then ( total := 3 * y + 3 ) else if (b - 1 <= y & b - 1 <= r - 2) then ( total := 3 * b ) else if (r - 2 <= y & r - 2 <= b - 1) then ( total := 3 * r - 3 ) else skip ; ; ; OclFile["System.out"].println(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static boolean isComposite(int n){ if(n<=1)return false ; if(n<=3)return false ; if(n % 2==0 || n % 3==0)return true ; for(int i=5 ; i*i<=n ; i=i+6)if(n % i==0 || n %(i+2)==0)return true ; return false ; } static boolean isDigitSumOne(int nm){ while(nm>9){ int sum_digit=0 ; while(nm>0){ int digit=nm % 10 ; sum_digit=sum_digit+digit ; nm=nm/10 ; } nm=sum_digit ; } if(nm==1)return true ; else return false ; } static void printValidNums(int l,int r){ for(int i=l ; i<=r ; i++){ if(isComposite(i)&& isDigitSumOne(i))System.out.print(i+" "); } } public static void main(String arg[]){ int l=10,r=100 ; printValidNums(l,r); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isComposite( n : int) : boolean 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 ; i := 5 ; while i * i <= n do ( if (n mod i = 0 or n mod (i + 2) = 0) then return true else skip ; ; i := i + 6 ) ; return false ); static operation isDigitSumOne( nm : int) : boolean pre: true post: true activity: ( while (nm > 9) do ( var sum_digit : int ; sum_digit := 0 ; while (nm > 0) do ( var digit : int ; digit := nm mod 10 ; sum_digit := sum_digit + digit ; nm := nm / 10 ) ; nm := sum_digit ) ; if (nm = 1) then return true else return false ); static operation printValidNums( l : int, r : int) : void pre: true post: true activity: ( var i : int ; i := l ; while i <= r do ( ( if (isComposite(i) & isDigitSumOne(i)) then OclFile["System.out"].print(i + " ") ; else skip ) ; i := i + 1 ) ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 10 ; var r : int ; r := 100 ; execute printValidNums(l, r) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maxProduct(int arr[],int n){ int ans=-1 ; for(int i=0 ; iarr[k])ans=Math.max(ans,arr[i]*arr[j]*arr[k]); } } } return ans ; } public static void main(String[] args){ int arr[]={ 1,8,3,7 }; int n=arr.length ; System.out.print(maxProduct(arr,n)+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxProduct( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var ans : int ; ans := -1 ; var i : int ; i := 0 ; while i < n - 2 do ( ( var j : int ; j := i + 1 ; while j < n - 1 do ( ( var k : int ; k := j + 1 ; while k < n do ( ( if (arr[i+1] < arr[j+1] & arr[j+1] > arr[k+1]) then ans := Set{ans, arr[i+1] * arr[j+1] * arr[k+1]}->max() ; else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,8,3,7} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(maxProduct(arr, n) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Vector ; class Test { static final int MAXN=100001 ; static int spf[]=new int[MAXN]; static void sieve(){ spf[1]=1 ; for(int i=2 ; igetFactorization(int x){ Vectorret=new Vector<>(); while(x!=1){ ret.add(spf[x]); x=x/spf[x]; } return ret ; } public static void main(String args[]){ sieve(); int x=12246 ; System.out.print("prime factorization for "+x+" : "); Vectorp=getFactorization(x); for(int i=0 ; icollect(0); static operation sieve() : void pre: true post: true activity: ( spf[1+1] := 1 ; var i : int ; i := 2 ; while i < MAXN do ( spf[i+1] := i ; ; i := i + 1 ) ; var i : int ; i := 4 ; while i < MAXN do ( spf[i+1] := 2 ; ; i := i+(2) ) ; var i : int ; i := 3 ; while i * i < MAXN do ( ( if (spf[i+1] = i) then ( var j : int ; j := i * i ; while j < MAXN do ( if (spf[j+1] = j) then spf[j+1] := i ; else skip ; ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ); static operation getFactorization( x : int) : Sequence(int) pre: true post: true activity: ( var ret : Sequence(int) ; ret := Sequence{} ; while (x /= 1) do ( ret := ret->including(spf[x+1]) ; x := x / spf[x+1] ) ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute sieve() ; var x : int ; x := 12246 ; OclFile["System.out"].print("prime factorization for " + x + " : ") ; var p : Sequence(int) ; p := getFactorization(x) ; var i : int ; i := 0 ; while i < p->size() do ( OclFile["System.out"].print(p->at(i+1) + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String args[]){ FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=input.nextInt(); while(T-->0){ int n=input.nextInt(); int m=input.nextInt(); int k=input.nextInt(); int min=n-1 ; long max=(long)n*(long)(n-1)/2 ; if(mmax){ out.println("NO"); } else { k-=2 ; if(n==1){ if(k<0)out.println("NO"); else out.println("YES"); } else { if(m==max){ if(k<1)out.println("NO"); else out.println("YES"); } else { if(k<2)out.println("NO"); else out.println("YES"); } } } } out.close(); } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : FastReader ; input := FastReader.newFastReader() ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var T : int ; T := input.nextInt() ; while (T > 0) do ( T := T - 1 ; skip ; ( var n : int ; n := input.nextInt() ; var m : int ; m := input.nextInt() ; var k : int ; k := input.nextInt() ; var min : int ; min := n - 1 ; var max : long ; max := n->oclAsType(long) * (n - 1)->oclAsType(long) / 2 ; if (m < min or m > max) then ( skip ) else ( k := k-(2) ; if (n = 1) then ( if (k < 0) then skip ; else skip ; ) else ( if (m = max) then ( if (k < 1) then skip ; else skip ; ) else ( if (k < 2) then skip ; else skip ; ) ) ) ; ) ; ) ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Test { private static char findExtraCharacter(String s1,String s2){ String smallStr ; String largeStr ; if(s1.length()>s2.length()){ smallStr=s2 ; largeStr=s1 ; } else { smallStr=s1 ; largeStr=s2 ; } int smallStrCodeTotal=0 ; int largeStrCodeTotal=0 ; int i=0 ; for(; isize() > s2->size()) then ( smallStr := s2 ; largeStr := s1 ) else ( smallStr := s1 ; largeStr := s2 ) ; var smallStrCodeTotal : int ; smallStrCodeTotal := 0 ; var largeStrCodeTotal : int ; largeStrCodeTotal := 0 ; var i : int ; i := 0 ; while i < smallStr->size() do ( ( smallStrCodeTotal := smallStrCodeTotal+(smallStr->at(i+1)) ; largeStrCodeTotal := largeStrCodeTotal+(largeStr->at(i+1)) ) ; i := i + 1 ) ; largeStrCodeTotal := largeStrCodeTotal+(largeStr->at(i+1)) ; var intChar : int ; intChar := largeStrCodeTotal - (smallStrCodeTotal)->char2byte() ; return intChar->oclAsType(String) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s1 : String ; s1 := "abcd" ; var s2 : String ; s2 := "cbdae" ; var extraChar : String ; extraChar := findExtraCharacter(s1, s2) ; OclFile["System.out"].println("Extra character: " + extraChar) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class C { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("src/C-large.in")))); String output="" ; int t=sc.nextInt(); sc.nextLine(); for(int i=1 ; i<=t ; i++){ int n=sc.nextInt(); int j=sc.nextInt(); long num=(1l<<(n-1))+1 ; int count=0 ; output+="Case #"+i+":\n" ; while(countfactors=new ArrayList(); for(int k=2 ; k<=10 ; k++){ BigInteger big=new BigInteger(s,k); if(big.isProbablePrime(10)){ found=false ; break ; } int factor=-1 ; for(int m=3 ; m<1000 ; m+=2){ if(big.mod(new BigInteger(""+m)).equals(BigInteger.ZERO)){ factor=m ; break ; } } if(factor==-1){ found=false ; break ; } factors.add(factor); } if(found){ count++; output+=s ; for(int k : factors){ output+=" "+k ; } output+="\n" ; } num+=2 ; } } BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("src/C-large.out"),"utf-8")); bw.write(output); bw.close(); } } ------------------------------------------------------------ OCL File: --------- class C { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("src/C-large.in"))))) ; var output : String ; output := "" ; var t : int ; t := sc.getCurrent()->toInteger() ; skip ; var i : int ; i := 1 ; while i <= t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var j : int ; j := sc.getCurrent()->toInteger() ; var num : long ; num := ((1l*(2->pow((n - 1))))->oclAsType(long)) + 1 ; var count : int ; count := 0 ; output := output+("Case #" + i + ":\n") ; while (count < j) do ( var s : String ; s := (MathLib.decimal2binary(num) + "") ; var found : boolean ; found := true ; var factors : Sequence(int) ; factors := Sequence{} ; var k : int ; k := 2 ; while k <= 10 do ( ( var big : long ; big := long(s, k) ; if (big.isProbablePrime(10)) then ( found := false ; break ) else skip ; var factor : int ; factor := -1 ; var m : int ; m := 3 ; while m < 1000 do ( ( if (big.mod(long("" + m)) = 0) then ( factor := m ; break ) else skip ) ; m := m+(2) ) ; if (factor = -1) then ( found := false ; break ) else skip ; factors := factors->including(factor) ; ) ; k := k + 1 ) ; if (found) then ( count := count + 1 ; output := output+(s) ; for (k : factors) do ( ( output := output+(" " + k) ) ) ; output := output+("\n") ) else skip ; num := num+(2) ; ) ; ) ; i := i + 1 ) ; var bw : OclFile ; bw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("src/C-large.out")), "utf-8")) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package lab6zp ; import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Lab6ZP { public static String makeit(int i){ String s="11" ; int k=14 ; while(k>0){ k--; if(i % 2==0){ s+="11" ; } else { s+="00" ; } i/=2 ; } s+="11" ; return s ; } public static void main(String[] args){ System.out.println("Case #1:"); for(int i=0 ; i<500 ; i++){ String s=makeit(i); System.out.println(s+" 3 4 5 6 7 8 9 10 11"); } } } ------------------------------------------------------------ OCL File: --------- class Lab6ZP { static operation makeit( i : int) : String pre: true post: true activity: ( var s : String ; s := "11" ; var k : int ; k := 14 ; while (k > 0) do ( k := k - 1 ; if (i mod 2 = 0) then ( s := s+("11") ) else ( s := s+("00") ) ; i := i/(2) ) ; s := s+("11") ; return s ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println("Case #1:") ; var i : int ; i := 0 ; while i < 500 do ( ( var s : String ; s := makeit(i) ; OclFile["System.out"].println(s + " 3 4 5 6 7 8 9 10 11") ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; public class C { public static void main(String[] args){ int N=32 ; int J=500 ; System.out.println("Case #1:"); for(int i=0 ; isize() + 2 < N / 2) do ( bitmask := '0' + bitmask ) ; var divisor : String ; divisor := StringLib.format("1%s1",Sequence{bitmask}) ; var jamcoin : String ; jamcoin := divisor + divisor ; OclFile["System.out"].print(jamcoin) ; var base : int ; base := 2 ; while base <= 10 do ( ( OclFile["System.out"].print(" " + long(divisor, base)) ) ; base := base + 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; if (b < a) then ( OclFile["System.out"].println("Happy Alex") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Poor Alex") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class CoinJam { public static final PrintStream out=System.out ; public static final BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); public int numCases ; public void doCase(int caseNumber)throws Exception { String line=in.readLine(); Scanner scan=new Scanner(line); int N=scan.nextInt(); int J=scan.nextInt(); String divisor="1" ; for(int i=0 ; itoInteger() ; var J : int ; J := scan.getCurrent()->toInteger() ; var divisor : String ; divisor := "1" ; var i : int ; i := 0 ; while i < N / 2 - 1 do ( ( divisor := divisor+("0") ) ; i := i + 1 ) ; divisor := divisor+("1") ; var i : int ; i := 0 ; while i < J do ( ( var coin : String ; coin := "1" ; coin := coin+(pad(((i) + ""), N / 2 - 2)) ; coin := coin+("11") ; coin := coin+(pad(((i) + ""), N / 2 - 2)) ; coin := coin+("1") ; OclFile["System.out"].print(coin) ; var base : int ; base := 2 ; while base <= 10 do ( ( OclFile["System.out"].print(" ") ; OclFile["System.out"].print(long(divisor, base)) ) ; base := base + 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ; ); operation pad( s : String, len : int) : String pre: true post: true activity: ( var res : String ; res := "" ; var i : int ; i := s->size() ; while i < len do ( ( res := res+("0") ) ; i := i + 1 ) ; res := res+(s) ; return res ); operation run() : void pre: true post: true activity: ( numCases := (in.readLine()->trim())->toInteger() ; var i : int ; i := 1 ; while i <= numCases do ( ( skip ; execute doCase(i) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( CoinJam.newCoinJam().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class C { static long value(int i,int m,int b){ long n=1 ; for(int k=0 ; ktoInteger() ; var t : int ; t := 1 ; while t <= T do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var j : int ; j := (st.next())->toInteger() ; skip ; var m : int ; m := n / 2 - 2 ; var i : int ; i := 0 ; while i < j do ( ( var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString("1") ; var k : int ; k := 0 ; while k < m do ( sb := sb + StringLib.newString(if (MathLib.bitwiseAnd(i,(1*(2->pow(k)))->oclAsType(long))) = 0 then "0" else "1" endif) ; ; k := k + 1 ) ; sb := sb + StringLib.newString("11") ; var k : int ; k := 0 ; while k < m do ( sb := sb + StringLib.newString(if (MathLib.bitwiseAnd(i,(1*(2->pow(k)))->oclAsType(long))) = 0 then "0" else "1" endif) ; ; k := k + 1 ) ; sb := sb + StringLib.newString("1") ; var b : int ; b := 2 ; while b <= 10 do ( sb := sb + StringLib.newString(" " + value(i, m, b)) ; ; b := b + 1 ) ; skip ; ) ; i := i + 1 ) ; ) ; t := t + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findMinNumber(int n){ int count=0,ans=1 ; while(n % 2==0){ count++; n/=2 ; } if(count % 3!=0)ans*=Math.pow(2,(count % 3)); for(int i=3 ; i<=Math.sqrt(n); i+=2){ count=0 ; while(n % i==0){ count++; n/=i ; } if(count % 3!=0)ans*=Math.pow(i,(count % 3)); } if(n>2)ans*=n ; return ans ; } public static void main(String[] args){ int n=128 ; System.out.print(findMinNumber(n)+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findMinNumber( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var ans : int ; ans := 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 ; var i : int ; i := 3 ; while i <= (n)->sqrt() 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 ) ; i := i+(2) ) ; if (n > 2) then ans := ans*(n) ; else skip ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 128 ; OclFile["System.out"].print(findMinNumber(n) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findMinNumber(int n){ int count=0,ans=1 ; while(n % 2==0){ count++; n/=2 ; } if(count % 2==1)ans*=2 ; for(int i=3 ; i<=Math.sqrt(n); i+=2){ count=0 ; while(n % i==0){ count++; n/=i ; } if(count % 2==1)ans*=i ; } if(n>2)ans*=n ; return ans ; } public static void main(String[] args){ int n=72 ; System.out.println(findMinNumber(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findMinNumber( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var ans : int ; ans := 1 ; while (n mod 2 = 0) do ( count := count + 1 ; n := n/(2) ) ; if (count mod 2 = 1) then ans := ans*(2) ; else skip ; var i : int ; i := 3 ; while i <= (n)->sqrt() do ( ( count := 0 ; while (n mod i = 0) do ( count := count + 1 ; n := n/(i) ) ; if (count mod 2 = 1) then ans := ans*(i) ; else skip ) ; i := i+(2) ) ; if (n > 2) then ans := ans*(n) ; else skip ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 72 ; OclFile["System.out"].println(findMinNumber(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Eleven { public static void main(String[] args)throws IOException { FastScanner sc=new FastScanner(); int n=sc.nextInt(); Listlist=new ArrayList<>(); list.add(1); int ans=1+1 ; int i=2 ; while(ans<=n){ list.add(ans); ans=list.get(i-1)+list.get(i-2); i++; } HashSetset=new HashSet<>(list); String res="" ; for(int j=1 ; j<=n ; j++){ if(set.contains(j))res+='O' ; else res+='o' ; } System.out.println(res); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; iincluding(1) ; var ans : int ; ans := 1 + 1 ; var i : int ; i := 2 ; while (ans <= n) do ( list := list->including(ans) ; ans := list->at(i - 1+1) + list->at(i - 2+1) ; i := i + 1 ) ; var set : Set(int) ; set := Set{}->union(list) ; var res : String ; res := "" ; var j : int ; j := 1 ; while j <= n do ( ( if (set->includes(j)) then res := res+('O') ; else res := res+('o') ; ) ; j := j + 1 ) ; OclFile["System.out"].println(res) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class FiboName { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=1,b=1 ; String ans="" ; for(int i=1 ; i<=n ; i++){ if(i==b){ ans+='O' ; int temp=b ; b+=a ; a=temp ; } else ans+='o' ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class FiboName { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := 1 ; var b : int ; b := 1 ; var ans : String ; ans := "" ; var i : int ; i := 1 ; while i <= n do ( ( if (i = b) then ( ans := ans+('O') ; var temp : int ; temp := b ; b := b+(a) ; a := temp ) else ans := ans+('o') ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashSet ; import java.util.Set ; public class P918A { public static void main(String[] args)throws IOException { BufferedReader io=new BufferedReader(new InputStreamReader(System.in)); Integer n=Integer.valueOf(io.readLine()); int i=1 ; int j=1 ; Setset=new HashSet(); set.add(1); while(j<=n){ j=i+j ; i=j-i ; set.add(j); } StringBuffer rs=new StringBuffer(); int len=1 ; while(len<=n){ if(set.contains(Integer.valueOf(len))){ rs.append("O"); } else { rs.append("o"); } len++; } System.out.println(rs.toString()); } } ------------------------------------------------------------ OCL File: --------- class P918A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : OclFile ; io := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (io.readLine())->toInteger() ; var i : int ; i := 1 ; var j : int ; j := 1 ; var set : Set(int) ; set := Set{} ; set := set->including(1) ; while (j <= n) do ( j := i + j ; i := j - i ; set := set->including(j) ) ; var rs : String ; rs := StringLib.newString() ; var len : int ; len := 1 ; while (len <= n) do ( if (set->includes((len)->toInteger())) then ( rs := rs + StringLib.newString("O") ) else ( rs := rs + StringLib.newString("o") ) ; len := len + 1 ) ; OclFile["System.out"].println(rs+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void printHutStar(int n){ int i,j ; for(i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findNthRoot(double x,int n){ double low,high ; if(x>=0 && x<=1){ low=x ; high=1 ; } else { low=1 ; high=x ; } double epsilon=0.00000001 ; double guess=(low+high)/2 ; while(Math.abs((Math.pow(guess,n))-x)>=epsilon){ if(Math.pow(guess,n)>x){ high=guess ; } else { low=guess ; } guess=(low+high)/2 ; } System.out.println(guess); } public static void main(String[] args){ double x=5 ; int n=2 ; findNthRoot(x,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findNthRoot( x : double, n : int) : void pre: true post: true activity: ( var low : double ; var high : double ; if (x >= 0 & x <= 1) then ( low := x ; high := 1 ) else ( low := 1 ; high := x ) ; var epsilon : double ; epsilon := 0.00000001 ; var guess : double ; guess := (low + high) / 2 ; while (if (guess->pow(n)) - x < 0 then -((guess->pow(n)) - x) else (guess->pow(n)) - x endif >= epsilon) do ( if (guess->pow(n) > x) then ( high := guess ) else ( low := guess ) ; guess := (low + high) / 2 ) ; OclFile["System.out"].println(guess) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : double ; x := 5 ; var n : int ; n := 2 ; execute findNthRoot(x, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printStrings(String s,int l,int m){ Setc=new LinkedHashSet<>(); s=s+s ; for(int i=0 ; iincluding(s.subrange(i+1,i + m)) ) ; i := i + 1 ) ; var itr : OclIterator ; itr := c->iterator() ; while (itr.hasNext()) do ( var a : String ; a := itr.next()->oclAsType(String) ; OclFile["System.out"].print(a + " ") ) ; c := c->intersection(Set{}) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "saurav" ; var N : int ; N := str->size() ; var M : int ; M := 4 ; execute printStrings(str, N, M) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; if (b < a) then ( OclFile["System.out"].println("Happy Alex") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Poor Alex") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class BinarySearch { int binarySearch(int arr[],int l,int r,int x){ if(r>=l){ int mid=l+(r-l)/2 ; if(arr[mid]==x)return mid ; if(arr[mid]>x)return binarySearch(arr,l,mid-1,x); return binarySearch(arr,mid+1,r,x); } return-1 ; } public static void main(String args[]){ BinarySearch ob=new BinarySearch(); int arr[]={ 2,3,4,10,40 }; int n=arr.length ; int x=10 ; int result=ob.binarySearch(arr,0,n-1,x); if(result==-1)System.out.println("Element not present"); else System.out.println("Element found at index "+result); } } ------------------------------------------------------------ OCL File: --------- class BinarySearch { operation binarySearch( arr : Sequence(int), l : int, r : int, x : int) : int pre: true post: true activity: ( if (r >= l) then ( var mid : int ; mid := l + (r - l) / 2 ; if (arr[mid+1] = x) then return mid else skip ; if (arr[mid+1] > x) then return binarySearch(arr, l, mid - 1, x) else skip ; return binarySearch(arr, mid + 1, r, x) ) else skip ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ob : BinarySearch ; ob := BinarySearch.newBinarySearch() ; var arr : Sequence(int) ; arr := Sequence{2,3,4,10,40} ; var n : int ; n := arr->size() ; var x : int ; x := 10 ; var result : int ; result := ob.binarySearch(arr, 0, n - 1, x) ; if (result = -1) then OclFile["System.out"].println("Element not present") else OclFile["System.out"].println("Element found at index " + result) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class BinarySearch { int binarySearch(int arr[],int x){ int l=0,r=arr.length-1 ; while(l<=r){ int m=l+(r-l)/2 ; if(arr[m]==x)return m ; if(arr[m]size() - 1 ; while (l <= r) do ( var m : int ; m := l + (r - l) / 2 ; if (arr[m+1] = x) then return m else skip ; if (arr[m+1] < x) then l := m + 1 ; else r := m - 1 ; ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ob : BinarySearch ; ob := BinarySearch.newBinarySearch() ; var arr : Sequence(int) ; arr := Sequence{2,3,4,10,40} ; var n : int ; n := arr->size() ; var x : int ; x := 10 ; var result : int ; result := ob.binarySearch(arr, x) ; if (result = -1) then OclFile["System.out"].println("Element not present") else OclFile["System.out"].println("Element found at " + "index " + result) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class A { public static void main(String[] args){ int x=(new Scanner(System.in)).nextInt(); String s=Integer.toString(++x); while(true){ boolean b=false ; for(int i=0 ; isize() do ( ( if (s->at(i+1) = '8') then b := true ; else skip ) ; i := i + 1 ) ; if (b) then break else skip ; s := (((s)->toInteger() + 1) + "") ) ; x := x - 1 ; out.println((s)->toInteger() - (x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Code { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long diff=0 ; boolean flag=false ; for(int i=(int)n+1 ; i0){ long r=n % 10 ; if(r==8){ return true ; } n=n/10 ; } return false ; } } ------------------------------------------------------------ OCL File: --------- class Code { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var diff : long ; diff := 0 ; var flag : boolean ; flag := false ; var i : int ; i := n->oclAsType(int) + 1 ; while i < n + 20 & not(flag) do ( ( flag := isLuckyNumber(i->oclAsType(long)) ; if (flag) then ( diff := i - n ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(diff) ; ); static operation isLuckyNumber( n : long) : boolean pre: true post: true activity: ( n := if n < 0 then -(n) else n endif ; while (n > 0) do ( var r : long ; r := n mod 10 ; if (r = 8) then ( return true ) else skip ; n := n / 10 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Code { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long diff=0 ; boolean flag=false ; for(int i=(int)n+1 ; itoLong() ; var diff : long ; diff := 0 ; var flag : boolean ; flag := false ; var i : int ; i := n->oclAsType(int) + 1 ; while i < n + 20 & not(flag) do ( ( flag := isLuckyNumber(i->oclAsType(long)) ; if (flag) then ( diff := i - n ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(diff) ; ); static operation isLuckyNumber( n : long) : boolean pre: true post: true activity: ( n := if n < 0 then -(n) else n endif ; var str : String ; str := ((n) + "") ; var idx : int ; idx := str->indexOf('8')-1 ; if (idx = -1) then ( return false ) else skip ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); int cnt=0 ; long val=8888888888L ; while(n<=val){ if(check(n)&& cnt>0){ break ; } else { n++; cnt++; } } System.out.println(cnt); } static boolean check(Long n){ if(n<0)n=n*-1 ; while(n>0){ if(n % 10==8)return true ; n=n/10 ; } return false ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var cnt : int ; cnt := 0 ; var val : long ; val := 8888888888L ; while (n <= val) do ( if (check(n) & cnt > 0) then ( break ) else ( n := n + 1 ; cnt := cnt + 1 ) ) ; OclFile["System.out"].println(cnt) ; ); static operation check( n : long) : boolean pre: true post: true activity: ( if (n < 0) then n := n * -1 ; else skip ; while (n > 0) do ( if (n mod 10 = 8) then return true else skip ; n := n / 10 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package fly ; public class Point { public double x ; public double y ; public Point(double x,double y){ this.x=x ; this.y=y ; } } ------------------------------------------------------------ OCL File: --------- class Point { attribute x : double; attribute y : double; static operation newPoint( x : double, y : double) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : double, y : double) : void pre: true post: true activity: ( self.x := x ; self.y := y ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); StringTokenizer st=new StringTokenizer(f.readLine()); long k=Long.parseLong(st.nextToken()); long d=Long.parseLong(st.nextToken()); long t=Long.parseLong(st.nextToken())*2 ; long temp ; if(k<=d){ temp=d ; } else { temp=k/d*d ; if(temptoLong() ; var d : long ; d := (st.next())->toLong() ; var t : long ; t := (st.next())->toLong() * 2 ; var temp : long ; if (k <= d) then ( temp := d ) else ( temp := k / d * d ; if (temp < k) then ( temp := temp+(d) ) else skip ) ; var temp2 : long ; temp2 := k + temp ; var temp3 : long ; temp3 := t / temp2 ; var temp4 : long ; temp4 := t - temp3 * temp2 ; var temp5 : double ; if (temp4 <= k * 2) then ( temp5 := temp4 / 2.0 ) else ( temp5 := temp4 - k ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); int[] memo ; ArrayListlh,lr ; void run(){ for(; ; ){ int n=sc.nextInt(); if(n==0)return ; lh=new ArrayList(); lr=new ArrayList(); for(int i=0 ; itoInteger() ; if (n = 0) then return else skip ; lh := Sequence{} ; lr := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( lh := lh->including(sc.getCurrent()->toInteger()) ; lr->excludes(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( lh := lh->including(sc.getCurrent()->toInteger()) ; lr->excludes(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; memo := Integer.subrange(1,lh->size())->collect(0) ; memo := memo->collect(-1) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < lh->size() do ( max := Set{max, solve(i)}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println((max + 1)) ; ) ) ); operation solve( ii : int) : int pre: true post: true activity: ( if (memo[ii+1] /= -1) then return memo[ii+1] else skip ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < lh->size() do ( ( if (lh->at(i+1) < lh->at(ii+1) & lr->at(i+1) < lr->at(ii+1)) then res := Set{res, solve(i) + 1}->max() ; else skip ) ; i := i + 1 ) ; return memo[ii+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static int __gcd(int a,int b){ if(b==0)return a ; return __gcd(b,a % b); } static int maxNewElements(int[] a,int n){ int gcd=a[0]; int mx=a[0]; for(int i=1 ; imax() ) ; i := i + 1 ) ; var total_terms : int ; total_terms := mx / gcd ; return total_terms - n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{4,6,10} ; var n : int ; n := a->size() ; OclFile["System.out"].print(maxNewElements(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class Main { static ArrayList md=new ArrayList(); public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] a=new int[n]; int[] b=new int[n]; int temp=0 ; int q=0 ; int w=0,e=0 ; boolean f=false ; for(int i=0 ; ib[i]){ f=true ; } q=b[i]; temp=a[i]; } if(temp>a[i]){ if(qw){ w=a[i]; if(b[i]e){ f=true ; } } } if(f==true){ System.out.println("Happy Alex"); } else System.out.println("Poor Alex"); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute md : Sequence := Sequence{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var temp : int ; temp := 0 ; var q : int ; q := 0 ; var w : int ; w := 0 ; var e : int ; e := 0 ; var f : boolean ; f := false ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ; b[i+1] := in.getCurrent()->toInteger() ; if (temp < a[i+1]) then ( if (q > b[i+1]) then ( f := true ) else skip ; q := b[i+1] ; temp := a[i+1] ) else skip ; if (temp > a[i+1]) then ( if (q < b[i+1]) then ( f := true ) else skip ; q := b[i+1] ; temp := a[i+1] ) else skip ; if (a[i+1] > w) then ( w := a[i+1] ; if (b[i+1] < e) then ( f := true ) else skip ; e := b[i+1] ) else skip ; if (a[i+1] < w) then ( if (b[i+1] > e) then ( f := true ) else skip ) else skip ; ) ; i := i + 1 ) ; if (f = true) then ( OclFile["System.out"].println("Happy Alex") ) else OclFile["System.out"].println("Poor Alex") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.util.Arrays ; class GFG { static boolean check(String s,int l){ int freq[]=new int[26]; Arrays.fill(freq,0); for(int i=0 ; i=2)return true ; } return false ; } public static void main(String args[]){ String s="geeksforgeeks" ; int l=s.length(); if(check(s,l))System.out.print("YES"); else System.out.print("NO"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation check( s : String, l : int) : boolean pre: true post: true activity: ( var freq : Sequence(int) ; freq := Integer.subrange(1,26)->collect(0) ; freq := freq->collect(0) ; var i : int ; i := 0 ; while i < l do ( ( freq[s->at(i+1) - ('a')->char2byte()+1] := freq[s->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 26 do ( ( if (freq[i+1] >= 2) then return true else skip ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "geeksforgeeks" ; var l : int ; l := s->size() ; if (check(s, l)) then OclFile["System.out"].print("YES") ; else OclFile["System.out"].print("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); char[] s=sc.next().toCharArray(); int n=s.length ; int[] a=new int[128]; for(int i=0 ; i=2){ System.out.println(0); return ; } long[] fact=new long[41]; fact[0]=1 ; for(int i=1 ; i<=40 ; i++){ fact[i]=fact[i-1]*i ; } long ans=fact[sum]; for(int i=0 ; i<128 ; i++){ ans/=fact[a[i] ]; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var n : int ; n := s->size() ; var a : Sequence(int) ; a := Integer.subrange(1,128)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[s[i+1]+1] := a[s[i+1]+1] + 1 ) ; i := i + 1 ) ; var odd : int ; odd := 0 ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 128 do ( ( if (a[i+1] mod 2 = 1) then ( odd := odd + 1 ; a[i+1] := a[i+1] - 1 ) else skip ; a[i+1] := a[i+1]/(2) ; sum := sum+(a[i+1]) ) ; i := i + 1 ) ; if (odd >= 2) then ( OclFile["System.out"].println(0) ; return ) else skip ; var fact : Sequence(long) ; fact := Integer.subrange(1,41)->collect(0) ; fact[0+1] := 1 ; var i : int ; i := 1 ; while i <= 40 do ( ( fact[i+1] := fact[i - 1+1] * i ) ; i := i + 1 ) ; var ans : long ; ans := fact[sum+1] ; var i : int ; i := 0 ; while i < 128 do ( ( ans := ans/(fact[a[i+1]+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class Main { static BigInteger[] facts ; public static void main(String[] args)throws IOException { facts=new BigInteger[27]; facts[0]=BigInteger.ONE ; for(int i=1 ; i<=26 ; i++){ facts[i]=facts[i-1] .multiply(BigInteger.valueOf(i)); } char[] s=new BufferedReader(new InputStreamReader(System.in)).readLine().toCharArray(); int[] a=new int[26]; for(char c : s){ ++a[c-'a']; } System.out.println(s.length % 2==0 ? evenCase(a): oddCase(a)); } static BigInteger evenCase(int[] a){ BigInteger y=BigInteger.ONE ; int n=0 ; for(int x : a){ if(x % 2!=0){ return BigInteger.ZERO ; } n+=x/2 ; y=y.multiply(facts[x/2]); } return facts[n] .divide(y); } static BigInteger oddCase(int[] a){ for(int i=0 ; i<26 ; i++){ if(a[i] % 2!=1){ continue ; } --a[i]; return evenCase(a); } return BigInteger.ZERO ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute facts : Sequence(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( facts := Integer.subrange(1,27)->collect(null) ; facts[0+1] := 1 ; var i : int ; i := 1 ; while i <= 26 do ( ( facts[i+1] := facts[i - 1+1].multiply((i + "")->toLong()) ) ; i := i + 1 ) ; var s : Sequence(String) ; s := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])).readLine()->characters() ; var a : Sequence(int) ; a := Integer.subrange(1,26)->collect(0) ; for (c : s) do ( ( a[c - ('a')->char2byte()+1] := a[c - ('a')->char2byte()+1] + 1 ) ) ; OclFile["System.out"].println(if s->size() mod 2 = 0 then evenCase(a) else oddCase(a) endif) ; ); static operation evenCase( a : Sequence(int)) : long pre: true post: true activity: ( var y : long ; y := 1 ; var n : int ; n := 0 ; for (x : a) do ( ( if (x mod 2 /= 0) then ( return 0 ) else skip ; n := n+(x / 2) ; y := y.multiply(facts[x / 2+1]) ) ) ; return facts[n+1].divide(y) ); static operation oddCase( a : Sequence(int)) : long pre: true post: true activity: ( var i : int ; i := 0 ; while i < 26 do ( ( if (a[i+1] mod 2 /= 1) then ( continue ) else skip ; a[i+1] := a[i+1] - 1 ; return evenCase(a) ) ; i := i + 1 ) ; return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.lang.StringBuffer ; class Main { public static long fact(int n){ long ret=1 ; for(int i=n ; i>=1 ; i--){ ret*=i ; } return ret ; } public static void main(String[] args){ Scanner in=new Scanner(System.in); String s=new String(in.next()); int[] count=new int[26]; for(int i=0 ; i= 1 do ( ( ret := ret*(i) ) ; i := i - 1 ) ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := StringLib.newString(in.getCurrent()) ; var count : Sequence(int) ; count := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < s->size() do ( ( count[s->at(i+1) - ('a')->char2byte()+1] := count[s->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var nOdd : int ; nOdd := 0 ; var div : long ; div := 1 ; var i : int ; i := 0 ; while i < 26 do ( ( if (count[i+1] mod 2 = 1) then ( nOdd := nOdd + 1 ) else skip ; div := div*(fact(count[i+1] / 2)) ) ; i := i + 1 ) ; if (nOdd /= s->size() mod 2) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(fact(s->size() / 2) / div) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.*; class Main { public static void main(String args[])throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String s=in.readLine(); int[] alpha=new int[30]; for(int i=0 ; i<30 ; i++)alpha[i]=0 ; for(int i=0 ; i=2)break ; } if(cnt>=2){ System.out.println("0"); } else { int n=0 ; int[] counter=new int[28]; int index=0 ; for(int i=0 ; i<28 ; i++){ if(alpha[i]==0)continue ; if(alpha[i] % 2==1)alpha[i]--; counter[index++]=alpha[i]/2 ; n+=alpha[i]/2 ; counter[index]=-1 ; } BigInteger N=new BigInteger("1"); BigInteger abc=new BigInteger("1"); for(int i=2 ; i<=n ; i++)N=N.multiply(new BigInteger(Integer.toString(i))); for(int i=0 ; i<28 ; i++){ if(counter[i]==-1)break ; for(int j=2 ; j<=counter[i]; j++){ abc=abc.multiply(new BigInteger(Integer.toString(j))); } } System.out.println(N.divide(abc)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var s : String ; s := in.readLine() ; var alpha : Sequence(int) ; alpha := Integer.subrange(1,30)->collect(0) ; var i : int ; i := 0 ; while i < 30 do ( alpha[i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s->size() do ( alpha[s->at(i+1) - ('a')->char2byte()+1] := alpha[s->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < 27 do ( ( if (alpha[i+1] mod 2 = 1) then cnt := cnt + 1 ; else skip ; if (cnt >= 2) then break else skip ) ; i := i + 1 ) ; if (cnt >= 2) then ( OclFile["System.out"].println("0") ) else ( var n : int ; n := 0 ; var counter : Sequence(int) ; counter := Integer.subrange(1,28)->collect(0) ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < 28 do ( ( if (alpha[i+1] = 0) then continue else skip ; if (alpha[i+1] mod 2 = 1) then alpha[i+1] := alpha[i+1] - 1 ; else skip ; counter[index+1] := alpha[i+1] / 2 ; index := index + 1 ; n := n+(alpha[i+1] / 2) ; counter[index+1] := -1 ; ) ; i := i + 1 ) ; var N : long ; N := long("1") ; var abc : long ; abc := long("1") ; var i : int ; i := 2 ; while i <= n do ( N := N.multiply(long(((i) + ""))) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 28 do ( ( if (counter[i+1] = -1) then break else skip ; var j : int ; j := 2 ; while j <= counter[i+1] do ( ( abc := abc.multiply(long(((j) + ""))) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(N.divide(abc)) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { long[] kaijo ; int[] a ; String s ; int len ; void init(){ kaijo=new long[21]; kaijo[0]=1 ; for(int i=1 ; i=2)res/=kaijo[a[i]/2]; } } else { int k=0 ; char c='#' ; for(int i=0 ; i=2)res/=kaijo[a[i]/2]; } } return res ; } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute kaijo : Sequence(long); attribute a : Sequence(int); attribute s : String; attribute len : int; operation init() : void pre: true post: true activity: ( kaijo := Integer.subrange(1,21)->collect(0) ; kaijo[0+1] := 1 ; var i : int ; i := 1 ; while i < kaijo->size() do ( ( kaijo[i+1] := kaijo[i - 1+1] * i ) ; i := i + 1 ) ); operation run() : void pre: true post: true activity: ( execute init() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; a := Integer.subrange(1,256)->collect(0) ; s := sc.getCurrent() ; len := s->size() ; var i : int ; i := 0 ; while i < len do ( a[s->at(i+1)+1] := a[s->at(i+1)+1] + 1 ; ; i := i + 1 ) ; OclFile["System.out"].println(count(s)) ; ); operation count( s : String) : long pre: true post: true activity: ( var res : long ; res := kaijo[len / 2+1] ; if (len mod 2 = 0) then ( var i : int ; i := 0 ; while i < a->size() do ( if (a[i+1] mod 2 = 1) then return 0L else skip ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < a->size() do ( ( if (a[i+1] >= 2) then res := res/(kaijo[a[i+1] / 2+1]) ; else skip ) ; i := i + 1 ) ) else ( var k : int ; k := 0 ; var c : String ; c := '#' ; var i : int ; i := 0 ; while i < a->size() do ( ( if (a[i+1] mod 2 = 1) then ( c := i->oclAsType(String) ; k := k + 1 ) else skip ) ; i := i + 1 ) ; if (k /= 1) then return 0L else skip ; a[c+1] := a[c+1] - 1 ; var i : int ; i := 0 ; while i < a->size() do ( ( if (a[i+1] >= 2) then res := res/(kaijo[a[i+1] / 2+1]) ; else skip ) ; i := i + 1 ) ; ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static class Node { int data ; Node next ; }; static Node push(Node head_ref,int new_data){ Node new_node=new Node(); new_node.data=new_data ; new_node.next=head_ref ; head_ref=new_node ; return head_ref ; } static void printList(Node head){ while(head!=null){ System.out.print(head.data+"->"); head=head.next ; } } static void sortlist(int arr[],int N,Node head){ HashMaphash=new HashMap(); Node temp=head ; while(temp!=null){ if(hash.containsKey(temp.data))hash.put(temp.data,hash.get(temp.data)+1); else hash.put(temp.data,1); temp=temp.next ; } temp=head ; for(int i=0 ; i0){ temp.data=arr[i]; temp=temp.next ; } } } public static void main(String[] args){ Node head=null ; int arr[]={ 5,1,3,2,8 }; int N=arr.length ; 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); System.out.print("Sorted List:"+"\n"); printList(head); } } ------------------------------------------------------------ OCL File: --------- class GFG { static class Node { attribute data : int; attribute next : Node; } static operation push( head_ref : Node, new_data : int) : Node pre: true post: true activity: ( var new_node : Node ; new_node := Node.newNode() ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; return head_ref ); static operation printList( head : Node) : void pre: true post: true activity: ( while (head /= null) do ( OclFile["System.out"].print(head.data + "->") ; head := head.next ) ); static operation sortlist( arr : Sequence(int), N : int, head : Node) : void pre: true post: true activity: ( var hash : Map(int,int) ; hash := Map{} ; var temp : Node ; temp := head ; while (temp /= null) do ( if (hash->keys()->includes(temp.data)) then hash := hash->union(Map{temp.data |-> hash->at(temp.data) + 1}) else hash := hash->union(Map{temp.data |-> 1}) ; ; temp := temp.next ) ; temp := head ; var i : int ; i := 0 ; while i < N do ( ( var frequency : int ; frequency := hash->at(arr[i+1]) ; while (frequency > 0) do ( frequency := frequency - 1 ; skip ; ( temp.data := arr[i+1] ; temp := temp.next ) ; ) ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var head : Node ; head := null ; var arr : Sequence(int) ; arr := Sequence{5,1,3,2,8} ; var N : int ; 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) ; execute sortlist(arr, N, head) ; OclFile["System.out"].print("Sorted List:" + "\n") ; execute printList(head) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int k=sc.nextInt(); long a[]=new long[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var b : Sequence(long) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( b[(i + 1) mod k+1] := Set{b[(i + 1) mod k+1], a[i+1]}->max() ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < k do ( ( sum := sum+(b[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class s { public static void main(String[] args)throws Exception { BufferedReader infile=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(infile.readLine()); int t=Integer.parseInt(st.nextToken()); while(t-->0){ st=new StringTokenizer(infile.readLine()); int n=Integer.parseInt(st.nextToken()); int k=Integer.parseInt(st.nextToken()); int[] arr=new int[n]; st=new StringTokenizer(infile.readLine()); for(int i=0 ; ipq=new PriorityQueue<>(); int[] ans=new int[k]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( st := OclIterator.newOclIterator_String(infile.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var k : int ; k := (st.next())->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; st := OclIterator.newOclIterator_String(infile.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; var res : long ; res := 0 ; var pq : Sequence(int) ; pq := Sequence{} ; var ans : Sequence(int) ; ans := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( if (ans[i mod k+1] < arr[i+1]) then ( ans[i mod k+1] := arr[i+1] ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( ( res := res+(ans[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); while(n-->0){ int a=input.nextInt(); int b=input.nextInt(); if(atoInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var a : int ; a := input.getCurrent()->toInteger() ; var b : int ; b := input.getCurrent()->toInteger() ; if (a < b) then ( OclFile["System.out"].println("Happy Alex") ; OclProcess.exit(0) ) else skip ) ; ) ; OclFile["System.out"].println("Poor Alex") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class ConsecutiveSum { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); long output[]=new long[t]; for(int i=0 ; itoInteger() ; var output : Sequence(long) ; output := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( output[i+1] := 0 ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var k : int ; k := sc.getCurrent()->toInteger() ; var elements : Sequence(int) ; elements := Integer.subrange(1,k)->collect(0) ; elements := elements->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( a[j+1] := sc.getCurrent()->toInteger() ; var remainder : int ; remainder := j mod k ; if (elements[remainder+1] < a[j+1]) then ( elements[remainder+1] := a[j+1] ) else skip ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < k do ( ( output[i+1] := output[i+1]+(elements[j+1]) ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t do ( ( OclFile["System.out"].println(output[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int k=sc.nextInt(); long a[]=new long[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var b : Sequence(long) ; b := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( b[i mod k+1] := Set{b[i mod k+1], a[i+1]}->max() ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; for (i : b) do ( sum := sum+(i) ; ) ; OclFile["System.out"].println(sum) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); System.out.print(n+" "); for(int i=1 ; i<=n-1 ; i++){ System.out.println(i+" "); } } } ------------------------------------------------------------ OCL File: --------- class Codeforces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; OclFile["System.out"].print(n + " ") ; var i : int ; i := 1 ; while i <= n - 1 do ( ( OclFile["System.out"].println(i + " ") ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class fiftyfour { public static void main(String args[])throws Exception { BufferedReader inp=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(inp.readLine()); System.out.print(n+" "); for(int i=1 ; itoInteger() ; OclFile["System.out"].print(n + " ") ; var i : int ; i := 1 ; while i < n do ( OclFile["System.out"].print(i + " ") ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; import java.util.SortedSet ; import java.util.TreeSet ; public class ObservationWheel { static Scanner sc ; static PrintWriter out ; public static void main(String[] args)throws IOException { sc=new Scanner(new FileReader("D-small-attempt0.in")); out=new PrintWriter(new FileWriter("D-small-attempt0.out")); int testCases=sc.nextInt(); for(int testCase=1 ; testCase<=testCases ; testCase++){ out.println(String.format("Case #%s: %s",testCase,solveCase())); } out.close(); } static double solveCase(){ String bits=sc.next(); N=bits.length(); memo=new double[1<>exactIndex & 1)==0){ res+=(N-wait+solve(mask | 1<toInteger() ; var testCase : int ; testCase := 1 ; while testCase <= testCases do ( ( skip ) ; testCase := testCase + 1 ) ; skip ; ); static operation solveCase() : double pre: true post: true activity: ( var bits : String ; bits := sc.getCurrent() ; N := bits->size() ; memo := Integer.subrange(1,(1*(2->pow(N)))->oclAsType(long))->collect(0.0) ; memo := memo->collect(-1.0) ; var init : int ; init := 0 ; var i : int ; i := 0 ; while i < N do ( if (bits->at(i+1) = 'X') then init := MathLib.bitwiseOr(init, (1*(2->pow(i)))->oclAsType(long)) ; else skip ; ; i := i + 1 ) ; return solve(init) ); static operation solve( mask : int) : double pre: true post: true activity: ( if (mask = ((1*(2->pow(N)))->oclAsType(long)) - 1) then ( return 0 ) else skip ; if (memo[mask+1] < -0.5) then ( var res : double ; res := 0.0 ; var index : int ; index := 0 ; while index < N do ( ( var wait : int ; wait := 0 ; while wait < N do ( ( var exactIndex : int ; exactIndex := (index + wait) mod N ; if ((MathLib.bitwiseAnd((mask/(2->pow(exactIndex)))->oclAsType(long),1)) = 0) then ( res := res+((N - wait + solve(mask or (1*(2->pow(exactIndex)))->oclAsType(long))) / N) ; break ) else skip ) ; wait := wait + 1 ) ) ; index := index + 1 ) ; memo[mask+1] := res ) else skip ; return memo[mask+1] ); static attribute memo : Sequence(double); static attribute N : int; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class D { static boolean bit_set(int set,int bit){ return((set>>>bit)& 1)==1 ; } static Double[][] DP=new Double[21][1<<20]; static double f(int n,int used){ if(used==(1<pow(bit)))->oclAsType(long)) & 1) = 1 ); static attribute DP : Sequence(Sequence(double)) := Integer.subrange(1,21)->collect(Integer.subrange(1,(1*(2->pow(20)))->oclAsType(long))->collect(null)); static operation f( n : int, used : int) : double pre: true post: true activity: ( if (used = ((1*(2->pow(n)))->oclAsType(long)) - 1) then return 0 else skip ; if (DP[n+1][used+1] /= null) then return DP[n+1][used+1] else skip ; var ans : double ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var nxt : int ; nxt := i ; var money : int ; money := n ; while (bit_set(used, nxt)) do ( nxt := (nxt + 1) mod n ; money := money - 1 ) ; ans := ans+(1.0 / n * (money + f(n, used or (1*(2->pow(nxt)))->oclAsType(long)))) ) ; i := i + 1 ) ; return DP[n+1][used+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := in.getCurrent()->toInteger() ; var cas : int ; cas := 1 ; while cas <= T do ( ( var S : Sequence(String) ; S := in.getCurrent()->characters() ; var used : int ; used := 0 ; var i : int ; i := 0 ; while i < S->size() do ( if (S[i+1] = 'X') then used := MathLib.bitwiseOr(used, (1*(2->pow(i)))->oclAsType(long)) ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].printf("Case #%d: %.10f\n", cas, f(S->size(), used)) ) ; cas := cas + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class D { private static String fileName=D.class.getSimpleName().replaceFirst("_.*","").toLowerCase(); private static String inputFileName=fileName+".in" ; private static String outputFileName=fileName+".out" ; private static Scanner in ; private static PrintWriter out ; private void solve(){ String s=in.next(); int n=s.length(); int init=0 ; for(int i=0 ; i>k)& 1)==1){ break ; } j++; k++; if(k==n){ k=0 ; } } int nm=mask ^(1<=2){ inputFileName=args[0]; outputFileName=args[1]; } in=new Scanner(new File(inputFileName)); out=new PrintWriter(outputFileName); int tests=in.nextInt(); in.nextLine(); for(int t=1 ; t<=tests ; t++){ out.print("Case #"+t+": "); new D().solve(); System.out.println("Case #"+t+": solved"); } in.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class D { static attribute fileName : String := OclType["D"].getSimpleName().replaceFirstMatch("_.*", "")->toLowerCase(); static attribute inputFileName : String := fileName + ".in"; static attribute outputFileName : String := fileName + ".out"; static attribute in : OclFile; static attribute out : OclFile; operation solve() : void pre: true post: true activity: ( var s : String ; s := in.getCurrent() ; var n : int ; n := s->size() ; var init : int ; init := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (s->at(i+1) = '.') then ( init := MathLib.bitwiseOr(init, (1*(2->pow(i)))->oclAsType(long)) ) else skip ) ; i := i + 1 ) ; var a : Sequence(double) ; a := Integer.subrange(1,(1*(2->pow(n)))->oclAsType(long))->collect(0.0) ; var mask : int ; mask := 1 ; while mask <= init do ( ( var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; var k : int ; k := i ; while true do ( ( if ((((mask/(2->pow(k)))->oclAsType(long)) & 1) = 1) then ( break ) else skip ; j := j + 1 ; k := k + 1 ; if (k = n) then ( k := 0 ) else skip ) ) ; var nm : int ; nm := MathLib.bitwiseXor(mask,((1*(2->pow(k)))->oclAsType(long))) ; a[mask+1] := a[mask+1]+(((n)->char2byte() - j + a[nm+1]) / n) ; ) ; i := i + 1 ) ) ; mask := mask + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Locale.setDefault(Locale.US) ; if (args->size() >= 2) then ( inputFileName := args[0+1] ; outputFileName := args[1+1] ) else skip ; in := OclFile.newOclFile_Read(OclFile(inputFileName)) ; out := OclFile.newOclFile_Write(OclFile.newOclFile(outputFileName)) ; var tests : int ; tests := in.getCurrent()->toInteger() ; skip ; var t : int ; t := 1 ; while t <= tests do ( ( skip ; D.newD().solve() ; OclFile["System.out"].println("Case #" + t + ": solved") ) ; t := t + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Math.*; import static java.util.Arrays.*; import java.io.*; import java.util.*; public class D { Scanner sc=new Scanner(System.in); int N ; char[] oc ; void read(){ oc=sc.next().toCharArray(); N=oc.length ; } void solve(){ double[] dp=new double[1<=0 ; i--){ for(int j=0 ; j>((j+k)% N)& 1)==0){ dp[i]+=(dp[i | 1<<((j+k)% N)]+N-k)/N ; break ; } } } int r=0 ; for(int i=0 ; i0 ? args[0] :(D.class.getName()+".in")))); } catch(Exception e){ } new D().run(); } } ------------------------------------------------------------ OCL File: --------- class D { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute N : int; attribute oc : Sequence(String); operation read() : void pre: true post: true activity: ( oc := sc.getCurrent()->characters() ; N := oc->size() ); operation solve() : void pre: true post: true activity: ( var dp : Sequence(double) ; dp := Integer.subrange(1,(1*(2->pow(N)))->oclAsType(long))->collect(0.0) ; var i : int ; i := ((1*(2->pow(N)))->oclAsType(long)) - 1 ; while i >= 0 do ( ( var j : int ; j := 0 ; while j < N do ( ( var k : int ; k := 0 ; while k < N do ( if ((MathLib.bitwiseAnd((i/(2->pow(((j + k) mod N))))->oclAsType(long),1)) = 0) then ( dp[i+1] := dp[i+1]+((dp[MathLib.bitwiseOr(i,(1*(2->pow(((j + k) mod N))))->oclAsType(long))+1] + N - k) / N) ; break ) else skip ; ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i - 1 ) ; var r : int ; r := 0 ; var i : int ; i := 0 ; while i < N do ( if (oc[i+1] = 'X') then r := MathLib.bitwiseOr(r, (1*(2->pow(i)))->oclAsType(long)) ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].printf("%.10f%n", dp[r+1]) ; ); operation run() : void pre: true post: true activity: ( var caseN : int ; caseN := sc.getCurrent()->toInteger() ; var caseID : int ; caseID := 1 ; while caseID <= caseN do ( ( execute read() ; OclFile["System.out"].printf("Case #%d: ", caseID) ; execute solve() ; OclFile["System.out"].flush() ) ; caseID := caseID + 1 ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( setIn(OclFile.newOclFile_Read(OclFile.newOclFile_Read(if args->size() > 0 then args[0+1] else (OclType["D"].getName() + ".in") endif))) ) catch (e : ProgramException) do skip D.newD().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import java.io.*; public class D { public static void p(Object...args){ System.out.println(Arrays.deepToString(args)); } public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int zz=1 ; zz<=T ; zz++){ String start=in.next(); N=start.length(); int st=0 ; for(int i=0 ; itoInteger() ; var zz : int ; zz := 1 ; while zz <= T do ( ( var start : String ; start := in.getCurrent() ; N := start->size() ; var st : int ; st := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (start->at(i+1) = 'X') then st := MathLib.bitwiseOr(st, (1*(2->pow(i)))->oclAsType(long)) ; else skip ) ; i := i + 1 ) ; DP := Integer.subrange(1,(1*(2->pow(N)))->oclAsType(long))->collect(0.0) ; DP := DP->collect(-1) ; DP[((1*(2->pow(N)))->oclAsType(long)) - 1+1] := 0 ; OclFile["System.out"].format("Case #%d: %.12f\n", zz, compute(st)) ; ) ; zz := zz + 1 ) ); static attribute N : int; static attribute DP : Sequence(double); static operation compute( at : int) : double pre: true post: true activity: ( if (DP[at+1] /= -1) then return DP[at+1] else skip ; var ans : double ; ans := 0.0 ; var i : int ; i := 0 ; while i < N do ( ( var cost : int ; cost := N ; var j : int ; j := i ; while (at(at, j+1)) do ( j := j + 1 ; cost := cost - 1 ; if (j = N) then j := 0 ; else skip ) ; ans := ans+(cost + compute(at or ((1*(2->pow(j)))->oclAsType(long)))) ) ; i := i + 1 ) ; ans := ans/(N) ; DP[at+1] := ans ; return ans ); static operation get( num : int, bit : int) : boolean pre: true post: true activity: ( return (num & ((1*(2->pow(bit)))->oclAsType(long))) /= 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean prevPermutation(char[] str){ int n=str.length-1 ; int i=n ; while(i>0 && str[i-1]<=str[i]){ i--; } if(i<=0){ return false ; } int j=i-1 ; while(j+1<=n && str[j+1]<=str[i-1]){ j++; } swap(str,i-1,j); StringBuilder sb=new StringBuilder(String.valueOf(str)); sb.reverse(); str=sb.toString().toCharArray(); return true ; } static String swap(char[] ch,int i,int j){ char temp=ch[i]; ch[i]=ch[j]; ch[j]=temp ; return String.valueOf(ch); } public static void main(String[] args){ char[] str="4321".toCharArray(); if(prevPermutation(str)){ System.out.println("Previous permutation is "+String.valueOf(str)); } else { System.out.println("Previous permutation"+"doesn't exist"); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation prevPermutation( str : Sequence(String)) : boolean pre: true post: true activity: ( var n : int ; n := str->size() - 1 ; var i : int ; i := n ; while (i > 0 & str[i - 1+1] <= str[i+1]) do ( i := i - 1 ) ; if (i <= 0) then ( return false ) else skip ; var j : int ; j := i - 1 ; while (j + 1 <= n & str[j + 1+1] <= str[i - 1+1]) do ( j := j + 1 ) ; execute swap(str, i - 1, j) ; var sb : String ; sb := StringLib.newString(((str) + "")) ; sb := sb->reverse() ; str := sb+""->characters() ; return true ); static operation swap( ch : Sequence(String), i : int, j : int) : String pre: true post: true activity: ( var temp : String ; temp := ch[i+1] ; ch[i+1] := ch[j+1] ; ch[j+1] := temp ; return ((ch) + "") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : Sequence(String) ; str := "4321"->characters() ; if (prevPermutation(str)) then ( OclFile["System.out"].println("Previous permutation is " + (str)->sum() ) ) else ( OclFile["System.out"].println("Previous permutation" + "doesn't exist") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package bribetheprisoners ; import java.io.IOException ; import java.util.Arrays ; public class Main extends Base { int P,Q ; int free[]; int bribe[][]; public static void main(String[] args)throws IOException { Main m=new Main(); m.run("C","large"); } @ Override void init(){ } @ Override void load()throws IOException { String s[]=br.readLine().split(" "); P=Integer.parseInt(s[0]); Q=Integer.parseInt(s[1]); free=new int[Q+2]; free[0]=0 ; free[Q+1]=P+1 ; s=br.readLine().split(" "); for(int i=0 ; i=free.length)break ; compute(i,j); } } printResult(""+bribe[0][Q+1]); } } ------------------------------------------------------------ OCL File: --------- class Main extends Base { attribute P : int; attribute free : Sequence(int); attribute bribe : Sequence(Sequence(int)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run("C", "large") ); operation init() : void pre: true post: true activity: skip; operation load() : void pre: true post: true activity: ( var s : Sequence(String) ; s := br.readLine()->split(" ") ; P := (s[0+1])->toInteger() ; Q := (s[1+1])->toInteger() ; free := Integer.subrange(1,Q + 2)->collect(0) ; free[0+1] := 0 ; free[Q + 1+1] := P + 1 ; s := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < Q do ( ( free[i + 1+1] := (s[i+1])->toInteger() ) ; i := i + 1 ) ; free := free->sort() ; bribe := Integer.subrange(1,free->size())->collect(Integer.subrange(1,free->size())->collect(0)) ; ); operation compute( i : int, j : int) : void pre: true post: true activity: ( if (i = j) then ( bribe[i+1][j+1] := 0 ; return ) else skip ; var best : int ; best := -1 ; var k : int ; k := i + 1 ; while k < j do ( ( var cur : int ; cur := bribe[i+1][k+1] + bribe[k+1][j+1] + (free[j+1] - free[i+1] - 2) ; if (best = -1 or cur <= best) then best := cur ; else skip ) ; k := k + 1 ) ; if (best = -1) then best := 0 ; else skip ; bribe[i+1][j+1] := best ; ); operation solve() : void pre: true post: true activity: ( var iv : int ; iv := 0 ; while iv < free->size() do ( ( var i : int ; i := 0 ; while i < free->size() do ( ( var j : int ; j := i + iv ; if (j >= free->size()) then break else skip ; execute compute(i, j) ) ; i := i + 1 ) ) ; iv := iv + 1 ) ; execute printResult("" + bribe[0+1][Q + 1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; class GFG { static int maxnumber(int n,int k){ for(int j=0 ; j0){ int temp=(n/(i*10))*i+(n % i); i*=10 ; ans=Math.max(ans,temp); } n=ans ; } return n ; } public static void main(String[] args){ int n=6358 ; int k=1 ; System.out.println(maxnumber(n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxnumber( n : int, k : int) : int pre: true post: true activity: ( var j : int ; j := 0 ; while j < k do ( ( var ans : int ; ans := 0 ; var i : int ; i := 1 ; while (n / i > 0) do ( var temp : int ; temp := (n / (i * 10)) * i + (n mod i) ; i := i*(10) ; ans := Set{ans, temp}->max() ) ; n := ans ) ; j := j + 1 ) ; return n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6358 ; var k : int ; k := 1 ; OclFile["System.out"].println(maxnumber(n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); while(true){ int n=scanner.nextInt(); if(n==0)break ; int[][] ns=new int[n][2]; while(n-->0){ ns[n][0]=scanner.nextInt(); ns[n][1]=scanner.nextInt(); } int m=scanner.nextInt(); int[][] ms=new int[m][2]; while(m-->0){ ms[m][0]=scanner.nextInt(); ms[m][1]=scanner.nextInt(); } int len=ns.length+ms.length ; int[][] num=Arrays.copyOf(ns,len); System.arraycopy(ms,0,num,ns.length,ms.length); Arrays.sort(num,new Comparator(){ @ Override public int compare(int[] a,int[] b){ if(a[0]==b[0]){ return a[1]-b[1]; } return a[0]-b[0]; } } ); int[] dp=new int[len]; Arrays.fill(dp,1); for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; var ns : Sequence(Sequence(int)) ; ns := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; while (n > 0) do ( n := n - 1 ; skip ; ( ns[n+1][0+1] := scanner.getCurrent()->toInteger() ; ns[n+1][1+1] := scanner.getCurrent()->toInteger() ) ; ) ; var m : int ; m := scanner.getCurrent()->toInteger() ; var ms : Sequence(Sequence(int)) ; ms := Integer.subrange(1,m)->collect(Integer.subrange(1,2)->collect(0)) ; while (m > 0) do ( m := m - 1 ; skip ; ( ms[m+1][0+1] := scanner.getCurrent()->toInteger() ; ms[m+1][1+1] := scanner.getCurrent()->toInteger() ) ; ) ; var len : int ; len := ns->size() + ms->size() ; var num : Sequence(Sequence(int)) ; num := ns.subrange(1,len) ; for _x : Integer.subrange(1,ms->size()) do num[ns->size() + _x] := ms[0 + _x] ; num := OclComparator.sortWith(num, OclComparator.newOclComparator()) ; var dp : Sequence(int) ; dp := Integer.subrange(1,len)->collect(0) ; dp := dp->collect(1) ; var i : int ; i := 0 ; while i < len do ( ( var j : int ; j := 0 ; while j < i do ( ( if (num[i+1][0+1] <= num[j+1][0+1] or num[i+1][1+1] <= num[j+1][1+1]) then continue else skip ; dp[i+1] := Set{dp[i+1], dp[j+1] + 1}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < len do ( ( ans := Set{ans, dp[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { static int MAX=100001 ; static double dp[]=new double[MAX]; static double probability(int k,int n){ double ans=0.0 ; for(int i=k ; i<=n ; ++i){ double res=dp[n]-dp[i]-dp[n-i]-n ; ans+=Math.pow(2.0,res); } return ans ; } static void precompute(){ for(int i=2 ; icollect(0.0); static operation probability( k : int, n : int) : double pre: true post: true activity: ( var ans : double ; ans := 0.0 ; var i : int ; i := k ; while i <= n do ( ( var res : double ; res := dp[n+1] - dp[i+1] - dp[n - i+1] - n ; ans := ans+(2.0->pow(res)) ) ; i := i + 1 ) ; return ans ); static operation precompute() : void pre: true post: true activity: ( var i : int ; i := 2 ; while i < MAX do ( dp[i+1] := ((i)->log() / (2)->log()) + dp[i - 1+1] ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute precompute() ; OclFile["System.out"].println(probability(2, 3)) ; OclFile["System.out"].println(probability(3, 6)) ; OclFile["System.out"].println(probability(500, 1000)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean find(String s1,String s2){ int len=s1.length(),len_1=s2.length(); if(len!=len_1){ return false ; } int d[]=new int[len]; d[0]=s2.charAt(0)-s1.charAt(0); for(int i=1 ; is2.charAt(i)){ return false ; } else { d[i]=s2.charAt(i)-s1.charAt(i); } } for(int i=0 ; isize() ; var len var len var len : ; len := s1->size() : ; len var len : ; len := s1->size() := s2->size() : int ; len var len var len : ; len := s1->size() : ; len var len : ; len := s1->size() := s2->size() := s2->size() ; if (len /= len_1) then ( return false ) else skip ; var d : Sequence(int) ; d := Integer.subrange(1,len)->collect(0) ; d[0+1] := s2->at(0+1) - s1->at(0+1) ; var i : int ; i := 1 ; while i < len do ( ( if (s1->at(i+1) > s2->at(i+1)) then ( return false ) else ( d[i+1] := s2->at(i+1) - s1->at(i+1) ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < len - 1 do ( ( if (d[i+1] < d[i + 1+1]) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s1 : String ; s1 := "abcd" ; var s2 : String ; s2 := "bcdd" ; if (find(s1, s2)) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int arr[]={ 1,2,3,4,5,6 }; static int multiply(int a[],int n){ if(n==0)return(a[n]); else return(a[n]*multiply(a,n-1)); } public static void main(String[] args){ System.out.println(multiply(arr,arr.length-1)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute arr : int := Sequence{1,2,3,4,5,6}; static operation multiply( a : Sequence(int), n : int) : int pre: true post: true activity: ( if (n = 0) then return (a[n+1]) else return (a[n+1] * multiply(a, n - 1)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(multiply(arr, arr->size() - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static private Scanner sc=new Scanner(System.in); static private int n,k ; static private int[] w ; public static void main(String[] args){ input(); int p=solve(); System.out.println(p); } private static int solve(){ int l=0 ; int r=10000*n/k+10 ; int p ; while(lp){ return false ; } if(c+w[i]<=p){ c+=w[i]; } else { t+=1 ; c=w[i]; } } return t<=k ; } private static void input(){ n=sc.nextInt(); k=sc.nextInt(); w=new int[100000]; for(int i=0 ; i p) then ( return false ) else skip ; if (c + w[i+1] <= p) then ( c := c+(w[i+1]) ) else ( t := t+(1) ; c := w[i+1] ) ) ; i := i + 1 ) ; return t <= k ); static operation input() : void pre: true post: true activity: ( n := sc.getCurrent()->toInteger() ; k := sc.getCurrent()->toInteger() ; w := Integer.subrange(1,100000)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( w[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; public class Main { public static boolean possible(Listw,int n,int k,int P){ int current=0 ; k--; for(int c : w){ if(current+c>P){ if(k>0){ k--; if(c<=P)current=c ; else return false ; } else { return false ; } } else { current+=c ; } } return true ; } public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] line=br.readLine().split(" "); int n=Integer.parseInt(line[0]); int k=Integer.parseInt(line[1]); Listw=new ArrayList(); for(int i=0 ; i1){ int mid=(u+l)/2-1 ; if(possible(w,n,k,mid))u=mid+1 ; else l=mid+1 ; } System.out.println(l); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation possible( w : Sequence(int), n : int, k : int, P : int) : boolean pre: true post: true activity: ( var current : int ; current := 0 ; k := k - 1 ; for (c : w) do ( ( if (current + c > P) then ( if (k > 0) then ( k := k - 1 ; if (c <= P) then current := c ; else return false ) else ( return false ) ) else ( current := current+(c) ) ) ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : Sequence(String) ; line := br.readLine()->split(" ") ; var n : int ; n := (line[0+1])->toInteger() ; var k : int ; k := (line[1+1])->toInteger() ; var w : Sequence(int) ; w := Sequence{} ; var i : int ; i := 0 ; while i < n do ( w := w->including((br.readLine())->toInteger()) ; ; i := i + 1 ) ; var u : int ; u := 1000000000 ; var l : int ; l := 1 ; while (u - l > 1) do ( var mid : int ; mid := (u + l) / 2 - 1 ; if (possible(w, n, k, mid)) then u := mid + 1 ; else l := mid + 1 ; ) ; OclFile["System.out"].println(l) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static ArrayListpackages=new ArrayList<>(); static int trucks ; static int total ; public static void main(String[] args){ Scanner inp=new Scanner(System.in); total=inp.nextInt(); trucks=inp.nextInt(); int sum=0 ; for(int i=0 ; i=trucks)return false ; cntTruck++; if(packages.get(i)>p)return false ; currentTruck=packages.get(i); } } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute packages : Sequence(int) := Sequence{}; static attribute trucks : int; static attribute total : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inp : OclFile ; inp := OclFile.newOclFile_Read(OclFile["System.in"]) ; total := inp.getCurrent()->toInteger() ; trucks := inp.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < total do ( ( var item : int ; item := inp.getCurrent()->toInteger() ; packages := packages->including(item) ; sum := sum+(item) ) ; i := i + 1 ) ; var lower : int ; lower := 0 ; var answer : int ; answer := sum ; while (lower <= sum) do ( var mid : int ; mid := (sum + lower) / 2 ; if (check(mid)) then ( answer := mid ; sum := mid - 1 ) else ( lower := mid + 1 ) ) ; OclFile["System.out"].println(answer) ; ); static operation check( p : int) : boolean pre: true post: true activity: ( var cntTruck : int ; cntTruck := 1 ; var currentTruck : int ; currentTruck := 0 ; var i : int ; i := 0 ; while i < total do ( ( if (currentTruck + packages->at(i+1) <= p) then ( currentTruck := currentTruck+(packages->at(i+1)) ) else ( if (cntTruck >= trucks) then return false else skip ; cntTruck := cntTruck + 1 ; if (packages->at(i+1) > p) then return false else skip ; currentTruck := packages->at(i+1) ) ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=0 ; int k=0 ; int[] weights=null ; try { String[] in=br.readLine().split(" "); n=Integer.parseInt(in[0]); k=Integer.parseInt(in[1]); weights=new int[n]; for(int i=0 ; i0){ long sum=0 ; while(true){ if(index==n){ k=0 ; break ; } sum+=weights[index]; if(sum>p){ k--; break ; } else { index++; } } } return index ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := 0 ; var k : int ; k := 0 ; var weights : Sequence(int) ; weights := null ; try ( var in : Sequence(String) ; in := br.readLine()->split(" ") ; n := (in[0+1])->toInteger() ; k := (in[1+1])->toInteger() ; weights := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( weights[i+1] := (br.readLine())->toInteger() ) ; i := i + 1 ) ; skip ; ) catch (e : IOException) do ( e.printStackTrace() ) var low : int ; low := 0 ; var high : int ; high := 2147483647 ; var mid : int ; mid := 0 ; while (low < high - 1) do ( mid := (low + high) / 2 ; var portable : int ; portable := howManyPortable(weights, n, k, mid) ; if (portable < n) then ( low := mid ) else ( high := mid ) ) ; OclFile["System.out"].println(high) ; ); static operation howManyPortable( weights : Sequence(int), n : int, k : int, p : int) : int pre: true post: true activity: ( var index : int ; index := 0 ; while (k > 0) do ( var sum : long ; sum := 0 ; while (true) do ( if (index = n) then ( k := 0 ; break ) else skip ; sum := sum+(weights[index+1]) ; if (sum > p) then ( k := k - 1 ; break ) else ( index := index + 1 ) ) ) ; return index ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int minimum_cost(int a[],int n){ int mn=Integer.MAX_VALUE ; int sum=0 ; for(int i=0 ; imin() ; sum := sum+(a[i+1]) ) ; i := i + 1 ) ; return mn * (sum - mn) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{4,3,2,5} ; var n : int ; n := a->size() ; OclFile["System.out"].println(minimum_cost(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { PrintStream log=new PrintStream(new OutputStream(){ public void write(int b){ } } ); PrintStream result=System.out ; Scanner sc=new Scanner(System.in); void main()throws IOException { int N=sc.nextInt(); int M=sc.nextInt(); int[] w=new int[N]; for(int i=0 ; i0 ; i--){ if(t[i]>0){ result.println(i+" "+t[i]); } } } public static void main(String[] args)throws IOException { new Main().main(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute log : OclFile := OclFile.newOclFile_Write(OclFile()); attribute result : OclFile := OclFile["System.out"]; attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation main() : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var w : Sequence(int) ; w := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var L : int ; L := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < L do ( ( w[(a + j) mod N+1] := 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var t : Sequence(int) ; t := Integer.subrange(1,N + 1)->collect(0) ; var s : int ; s := 0 ; var f : int ; f := 0 ; var s0 : int ; s0 := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (f = 0 & w[i+1] = 1) then ( s := i ; f := 1 ) else if (f = 1 & w[i+1] = 0) then ( f := 0 ; if (s = 0) then ( s0 := i ) else ( t[i - s+1] := t[i - s+1] + 1 ) ) else skip ; ) ; i := i + 1 ) ; if (f = 1) then ( t[i - s + s0+1] := t[i - s + s0+1] + 1 ) else if (s0 /= 0) then ( t[s0+1] := t[s0+1] + 1 ) else skip ; ; i := N ; while i > 0 do ( ( if (t[i+1] > 0) then ( skip ) else skip ) ; i := i - 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().main() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { static int findTransitionPoint(int arr[],int n){ int lb=0,ub=n-1 ; while(lb<=ub){ int mid=(lb+ub)/2 ; if(arr[mid]==0)lb=mid+1 ; else if(arr[mid]==1){ if(arr[mid-1]==0)return mid ; ub=mid-1 ; } } return-1 ; } public static void main(String args[]){ int arr[]={ 0,0,0,0,1,1 }; int point=findTransitionPoint(arr,arr.length); System.out.println(point>=0 ? "Transition point is "+point : "There is no transition point"); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation findTransitionPoint( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var lb : int ; lb := 0 ; var ub : int ; ub := n - 1 ; while (lb <= ub) do ( var mid : int ; mid := (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 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{0,0,0,0,1,1} ; var point : int ; point := findTransitionPoint(arr, arr->size()) ; OclFile["System.out"].println(if point >= 0 then "Transition point is " + point else "There is no transition point" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); int DP(int xy[][],int DP[][]){ for(int i=1 ; i<1001 ; i++){ for(int j=1 ; j<1001 ; j++){ if(xy[i][j]==1){ if(DP[i][j-1]toInteger() ; if (n = 0) then break else skip ; var xy : Sequence(Sequence(int)) ; xy := Integer.subrange(1,1001)->collect(Integer.subrange(1,1001)->collect(0)) ; var DP : Sequence(Sequence(int)) ; DP := Integer.subrange(1,1001)->collect(Integer.subrange(1,1001)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; xy[a+1][b+1] := 1 ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; xy[a+1][b+1] := 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(DP(xy, DP)) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int dp[][]=new int[n][n]; for(int i=0 ; i0){ int l=sc.nextInt(); int r=sc.nextInt(); System.out.println(dp[r-l][l-1]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( dp[0+1][i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := 0 ; while j < n - i do ( dp[i+1][j+1] := dp[i - 1+1][j+1] xor dp[i - 1+1][j + 1+1] ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := 0 ; while j < n - i do ( dp[i+1][j+1] := Set{dp[i+1][j+1], Set{dp[i - 1+1][j+1], dp[i - 1+1][j + 1+1]}->max()}->max() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var q : int ; q := sc.getCurrent()->toInteger() ; while (q > 0) do ( q := q - 1 ; skip ; ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(dp[r - l+1][l - 1+1]) ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int dp[][]=new int[n][n]; for(int i=0 ; i0){ int l=sc.nextInt(); int r=sc.nextInt(); System.out.println(dp[r-l][l-1]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( dp[0+1][i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := 0 ; while j < n - i do ( dp[i+1][j+1] := dp[i - 1+1][j+1] xor dp[i - 1+1][j + 1+1] ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := 0 ; while j < n - i do ( dp[i+1][j+1] := Set{dp[i+1][j+1], Set{dp[i - 1+1][j+1], dp[i - 1+1][j + 1+1]}->max()}->max() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var q : int ; q := sc.getCurrent()->toInteger() ; while (q > 0) do ( q := q - 1 ; skip ; ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(dp[r - l+1][l - 1+1]) ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String[] args){ int a=2 ; float b=2.0f ; double c=2.0003 ; char d='D' ; System.out.printf("Integer value is=%d",a); System.out.printf("\nFloat value is=%f",b); System.out.printf("\nDouble value is=%f",c); System.out.printf("\nChar value is=%c",d); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 2 ; var b : double ; b := 2.0f ; var c : double ; c := 2.0003 ; var d : String ; d := 'D' ; OclFile["System.out"].printf("Integer value is=%d", a) ; OclFile["System.out"].printf("\nFloat value is=%f", b) ; OclFile["System.out"].printf("\nDouble value is=%f", c) ; OclFile["System.out"].printf("\nChar value is=%c", d) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.PriorityQueue ; import java.util.Scanner ; public class CsAcademy { public static void main(String[] args){ Scanner cin=new Scanner(System.in); String s=cin.next(); int ans=0 ; int i=0 ; int mx=0 ; PriorityQueuequeue=new PriorityQueue<>(); for(i=0 ; i=1){ mx+=2 ; queue.remove(); } } } ans=Math.max(ans,mx); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class CsAcademy { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := cin.getCurrent() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; var mx : int ; mx := 0 ; var queue : Sequence(String) ; queue := Sequence{} ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = '(') then ( queue := queue->including(s->at(i+1)) ) else ( if (queue->size() >= 1) then ( mx := mx+(2) ; queue := queue.remove() ) else skip ) ) ; i := i + 1 ) ; ans := Set{ans, mx}->max() ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.PriorityQueue ; import java.util.Scanner ; public class CsAcademy { public static void main(String[] args){ Scanner cin=new Scanner(System.in); String s=cin.next(); int ans=0 ; int i=0 ; int mx=0 ; PriorityQueuequeue=new PriorityQueue<>(); for(i=0 ; i=1){ mx+=2 ; queue.remove(); } } } ans=Math.max(ans,mx); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class CsAcademy { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := cin.getCurrent() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; var mx : int ; mx := 0 ; var queue : Sequence(String) ; queue := Sequence{} ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = '(') then ( queue := queue->including(s->at(i+1)) ) else ( if (queue->size() >= 1) then ( mx := mx+(2) ; queue := queue.remove() ) else skip ) ) ; i := i + 1 ) ; ans := Set{ans, mx}->max() ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.PriorityQueue ; import java.util.Scanner ; public class CsAcademy { public static void main(String[] args){ Scanner cin=new Scanner(System.in); String s=cin.next(); int dp[]=new int[s.length()]; int ans=0 ; int i=0 ; int mx=0 ; PriorityQueuepriorityQueue=new PriorityQueue<>(); for(i=0 ; i=1){ mx+=2 ; priorityQueue.remove(); } } } System.out.println(mx); } } ------------------------------------------------------------ OCL File: --------- class CsAcademy { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := cin.getCurrent() ; var dp : Sequence(int) ; dp := Integer.subrange(1,s->size())->collect(0) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; var mx : int ; mx := 0 ; var priorityQueue : Sequence(String) ; priorityQueue := Sequence{} ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = '(') then ( priorityQueue := priorityQueue->including(s->at(i+1)) ) else ( if (priorityQueue->size() >= 1) then ( mx := mx+(2) ; priorityQueue := priorityQueue.remove() ) else skip ) ) ; i := i + 1 ) ; OclFile["System.out"].println(mx) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { public static void main(String[] args)throws IOException { FastReader fr=new FastReader(); BufferedWriter output=new BufferedWriter(new OutputStreamWriter(System.out)); StringBuilder sb=new StringBuilder(); String s=fr.next(); int sum1=0,sum2=0,del1=0,del2=0 ; for(int i=0 ; isize() do ( ( if (s->at(i+1) = '(') then sum1 := sum1 + 1 else sum1 := sum1 - 1 ; ; if (sum1 = -1) then ( del1 := del1 + 1 ; sum1 := 0 ) else skip ) ; i := i + 1 ) ; sb := sb + StringLib.newString(s->size() - (sum1 + del1)) ; skip ; skip ; ); } class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class ListB { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n,k,ans=0 ; n=sc.nextInt(); k=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; i=0 ; i-=k){ ans+=(arr[i]-1)*2 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class ListB { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var k : int ; var ans : int ; ans := 0 ; n := sc.getCurrent()->toInteger() ; k := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; arr := arr->sort() ; var i : int ; i := n - 1 ; while i >= 0 do ( ( ans := ans+((arr[i+1] - 1) * 2) ) ; i := i-(k) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); boolean[] painted=new boolean[n]; for(int i=0 ; i=1 ; i--){ if(count[i]>=1){ System.out.println(i+" "+count[i]); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var painted : Sequence(boolean) ; painted := Integer.subrange(1,n)->collect(false) ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var l : int ; l := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < l do ( ( painted[(a + j) mod n+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; var start : int ; start := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (not(painted[i+1])) then ( start := i ; break ) else skip ) ; i := i + 1 ) ; var p2 : Sequence(boolean) ; p2 := Integer.subrange(1,n + 1)->collect(false) ; var i : int ; i := 0 ; while i < n do ( ( p2[i+1] := painted[(start + i) mod n+1] ) ; i := i + 1 ) ; var count : Sequence(int) ; count := Integer.subrange(1,n + 1)->collect(0) ; var len : int ; len := 0 ; var i : int ; i := 0 ; while i <= n do ( ( if (p2[i+1]) then ( len := len + 1 ) else ( count[len+1] := count[len+1] + 1 ; len := 0 ) ) ; i := i + 1 ) ; var i : int ; i := n ; while i >= 1 do ( ( if (count[i+1] >= 1) then ( OclFile["System.out"].println(i + " " + count[i+1]) ) else skip ) ; i := i - 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Test { public static void main(String[] args){ Scanner cin=new Scanner(System.in); int n=cin.nextInt(); int k=cin.nextInt(); int a[]=new int[n]; for(int i=0 ; i=0){ int temp=k ; int start=1 ; while(temp!=0 && begin>=0){ suma+=Math.abs(start-a[begin]); start=a[begin--]; temp--; } suma+=start-1 ; } System.out.println(suma); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := cin.getCurrent()->toInteger() ; var k : int ; k := cin.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := cin.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var suma : int ; suma := 0 ; var begin : int ; begin := n - 1 ; while (begin >= 0) do ( var temp : int ; temp := k ; var start : int ; start := 1 ; while (temp /= 0 & begin >= 0) do ( suma := suma+(if start - a[begin+1] < 0 then -(start - a[begin+1]) else start - a[begin+1] endif) ; start := a[begin+1] ; begin := begin - 1 ; temp := temp - 1 ) ; suma := suma+(start - 1) ) ; OclFile["System.out"].println(suma) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),k=in.nextInt(),sum=0 ; int ara[]=new int[n]; for(int i=0 ; i=0 ; i=i-k){ sum=sum+2*(ara[i]-1); } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var ara : Sequence(int) ; ara := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ara[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; ara := ara->sort() ; var i : int ; i := n - 1 ; while i >= 0 do ( ( sum := sum + 2 * (ara[i+1] - 1) ) ; i := i - k ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0)break ; Listdolls=new ArrayList(); dolls.add(new Doll(0,0)); for(int i=0 ; id2.h && d1.r>d2.r)max=Math.max(max,dp[i][k]); } dp[i+1][j]=max+1 ; ans=Math.max(ans,max+1); } } } System.out.println(ans); } } } class Doll { int h ; int r ; Doll(int h,int r){ this.h=h ; this.r=r ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var dolls : Sequence(Doll) ; dolls := Sequence{} ; dolls := dolls->including(Doll.newDoll(0, 0)) ; var i : int ; i := 0 ; while i < n do ( ( dolls := dolls->including(Doll.newDoll(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( dolls := dolls->including(Doll.newDoll(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + m + 1)->collect(Integer.subrange(1,n + m + 1)->collect(0)) ; var ans : int ; ans := 0 ; dp[1+1] := dp[1+1]->collect(1) ; var i : int ; i := 1 ; while i < n + m do ( ( var j : int ; j := 1 ; while j <= n + m do ( ( if (dp[i+1][j+1] = 0) then ( dp[i + 1+1][j+1] := 0 ) else ( var max : int ; max := 0 ; var d1 : Doll ; d1 := dolls->at(j+1) ; var k : int ; k := 1 ; while k <= n + m do ( ( if (j = k) then continue else skip ; var d2 : Doll ; d2 := dolls->at(k+1) ; if (d1.h > d2.h & d1.r > d2.r) then max := Set{max, dp[i+1][k+1]}->max() ; else skip ) ; k := k + 1 ) ; dp[i + 1+1][j+1] := max + 1 ; ans := Set{ans, max + 1}->max() ; ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } class Doll { attribute h : int; attribute r : int; static operation newDoll( h : int, r : int) : Doll pre: true post: true activity: ( var self : Doll ; self := createDoll(); self.initialise(h, r); return self ); operation initialise( h : int, r : int) : void pre: true post: true activity: ( self.h := h ; self.r := r ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; import java.util.*; import static java.util.Arrays.sort ; import javafx.util.Pair ; public class Main { static void sort(int a[]){ Random ran=new Random(); for(int i=0 ; i=0){ int count=k ; int max=Integer.MIN_VALUE ; while(i>=0 && count-->0){ max=Math.max(max,a[i]); i--; } ans+=((max-1)*2); } System.out.println(ans); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine()throws IOException { return br.readLine(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation sort( a : Sequence(int)) : void pre: true post: true activity: ( var ran : OclRandom ; ran := OclRandom.newOclRandom() ; var i : int ; i := 0 ; while i < a->size() do ( ( var r : int ; r := ran.nextInt(a->size()) ; var temp : int ; temp := a[r+1] ; a[r+1] := a[i+1] ; a[i+1] := temp ) ; i := i + 1 ) ; a := a->sort() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : FastScanner ; input := FastScanner.newFastScanner() ; var n : int ; n := input.nextInt() ; var k : int ; k := input.nextInt() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := input.nextInt() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; execute sort(a) ; var i : int ; i := n - 1 ; while (i >= 0) do ( var count : int ; count := k ; var max : int ; max := -2147483648 ; while (i >= 0 & count > 0) do ( skip ; ( max := Set{max, a[i+1]}->max() ; i := i - 1 ) ; ) ; ans := ans+(((max - 1) * 2)) ) ; OclFile["System.out"].println(ans) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MyClass { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; i=0){ ans+=(arr[i]-1)*2 ; i-=k ; } System.out.println(ans); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class MyClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; arr := arr->sort() ; var i : int ; i := n - 1 ; var ans : int ; ans := 0 ; while (i >= 0) do ( ans := ans+((arr[i+1] - 1) * 2) ; i := i-(k) ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class stem { public static String findstem(String arr[]){ int n=arr.length ; String s=arr[0]; int len=s.length(); String res="" ; for(int i=0 ; isize() ; var s : String ; s := arr[0+1] ; var len : int ; len := s->size() ; var res : String ; res := "" ; var i : int ; i := 0 ; while i < len do ( ( var j : int ; j := i + 1 ; while j <= len do ( ( var stem : String ; stem := s.subrange(i+1,j) ; var k : int ; k := 1 ; k := 1 ; while k < n do ( if (not(arr[k+1]->includes(stem))) then break else skip ; ; k := k + 1 ) ; if (k = n & res->size() < stem->size()) then res := stem ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"grace","graceful","disgraceful","gracefully"} ; var stems : String ; stems := findstem(arr) ; OclFile["System.out"].println(stems) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int Rank(int Edges,int Vertices){ int result=0 ; result=Edges-Vertices+1 ; return result ; } public static void main(String[] args){ int Edges=7,Vertices=5 ; System.out.println("Circuit Rank="+Rank(Edges,Vertices)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Rank( Edges : int, Vertices : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; result := Edges - Vertices + 1 ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var Edges : int ; Edges := 7 ; var Vertices : int ; Vertices := 5 ; OclFile["System.out"].println("Circuit Rank=" + Rank(Edges, Vertices)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),m=(int)Math.pow(2,n)-1 ; PrintWriter out=new PrintWriter(System.out); for(int i=0 ; i<=m ; i++){ String str=Integer.toBinaryString(i); Listls=new ArrayList<>(); for(int j=0 ; jtoInteger() ; var m : int ; m := 2->pow(n)->oclAsType(int) - 1 ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var i : int ; i := 0 ; while i <= m do ( ( var str : String ; str := (MathLib.decimal2binary(i) + "") ; var ls : Sequence(int) ; ls := Sequence{} ; var j : int ; j := 0 ; while j < str->size() do ( ( if (str->at(str->size() - 1 - j+1) = '1') then ls := ls->including(j) ; else skip ) ; j := j + 1 ) ; skip ; var j : int ; j := 0 ; while j < ls->size() do ( skip ; ; j := j + 1 ) ; skip ; ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Deque ; import java.util.HashSet ; import java.util.List ; import java.util.Scanner ; import java.util.Set ; public class Main { static int n ; static int count=0 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); n=sc.nextInt(); System.out.println("0:"); boolean[] array=new boolean[n+1]; int max=0 ; while(max=max){ ++max ; array=new boolean[n+1]; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute n : int; static attribute count : int := 0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; OclFile["System.out"].println("0:") ; var array : Sequence(boolean) ; array := Integer.subrange(1,n + 1)->collect(false) ; var max : int ; max := 0 ; while (max < n) do ( array[max+1] := true ; OclFile["System.out"].print((count + 1) + ": ") ; var index : int ; index := 0 ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < max do ( ( if (array[i+1]) then ( OclFile["System.out"].print(i + " ") ; count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; var i : int ; i := 0 ; while i < max do ( ( if (not(array[i+1])) then ( array[i+1] := true ; index := i ; break ) else skip ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < n - 2 do ( ( var i : int ; i := 0 ; while i < index do ( ( if (array[i+1]) then ( array[i+1] := false ; break ) else skip ) ; i := i + 1 ) ) ; j := j + 1 ) ; if (count >= max) then ( max := max + 1 ; array := Integer.subrange(1,n + 1)->collect(false) ) else skip ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ int n,i,j,factorial ; String str ; try(Scanner sc=new Scanner(System.in)){ n=sc.nextInt(); factorial=(int)(Math.pow(2,n)); char[] cha=new char[n]; for(i=0 ; itoInteger() ; factorial := (2->pow(n))->oclAsType(int) ; var cha : Sequence(String) ; cha := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < factorial do ( ( str := (MathLib.decimal2binary(i) + "") ; j := 0 ; while j < str->size() do ( ( cha[j+1] := str->at(j+1) ) ; j := j + 1 ) ; OclFile["System.out"].print(i + ":") ; j := 0 ; while j < str->size() do ( ( if (cha[str->size() - j - 1+1] = '1') then ( OclFile["System.out"].print(" " + j) ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.LinkedList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); final int N=sc.nextInt(); final int M=sc.nextInt(); boolean[] colored=new boolean[N]; for(int i=0 ; i=0 ; i--){ if(counts[i]>0){ System.out.println(i+" "+counts[i]); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var colored : Sequence(boolean) ; colored := Integer.subrange(1,N)->collect(false) ; var i : int ; i := 0 ; while i < M do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var L : int ; L := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < L do ( ( var index : int ; index := (a + j) mod N ; colored[index+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; var false_pos : int ; false_pos := -1 ; var i : int ; i := 0 ; while i < N do ( ( if (not(colored[i+1])) then ( false_pos := i ; break ) else skip ) ; i := i + 1 ) ; if (false_pos = -1) then ( OclFile["System.out"].println(N + " " + 1) ; return ) else skip ; var counts : Sequence(int) ; counts := Integer.subrange(1,N)->collect(0) ; var count : int ; count := 0 ; var prev : boolean ; prev := false ; var i : int ; i := 0 ; while i < N do ( ( var index : int ; index := (i + false_pos) mod N ; if (colored[index+1]) then ( if (not(prev)) then ( prev := true ) else skip ; count := count + 1 ) else ( if (prev) then ( prev := false ; counts[count+1] := counts[count+1] + 1 ; count := 0 ) else skip ) ) ; i := i + 1 ) ; if (count /= 0) then ( counts[count+1] := counts[count+1] + 1 ; count := 0 ) else skip ; var i : int ; i := N - 1 ; while i >= 0 do ( ( if (counts[i+1] > 0) then ( OclFile["System.out"].println(i + " " + counts[i+1]) ) else skip ) ; i := i - 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long max=(1<0 ; j++){ if(x % 2==1){ sb.append(" ").append(j); } x>>=1 ; } sb.append("\n"); } System.out.print(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var max : long ; max := ((1*(2->pow(n)))->oclAsType(long)) ; var sb : String ; sb := StringLib.newString() ; var i : long ; i := 0 ; while i < max do ( ( sb := sb + StringLib.newString(i) + StringLib.newString(":") ; var x : long ; x := i ; var j : int ; j := 0 ; while j <= 18 & x > 0 do ( ( if (x mod 2 = 1) then ( sb := sb + StringLib.newString(" ") + StringLib.newString(j) ) else skip ; x := x/(2->pow(1)) ) ; j := j + 1 ) ; sb := sb + StringLib.newString("\n") ) ; i := i + 1 ) ; OclFile["System.out"].print(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int n=sc.nextInt(); for(int bit=0 ; bit<(1<>j)& 1)==1){ System.out.print(" "+j); } } System.out.println(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var bit : int ; bit := 0 ; while bit < ((1*(2->pow(n)))->oclAsType(long)) do ( ( OclFile["System.out"].print(bit + ":") ; var j : int ; j := 0 ; while j < n do ( ( if ((((bit/(2->pow(j)))->oclAsType(long)) & 1) = 1) then ( OclFile["System.out"].print(" " + j) ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; bit := bit + 1 ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { static int gcd(int a,int 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); } static int LCM(int x,int y,int z){ int ans=((x*y)/(gcd(x,y))); return((z*ans)/(gcd(ans,z))); } static int findDivisible(int n,int x,int y,int z){ int lcm=LCM(x,y,z); int largestNDigitNum=(int)Math.pow(10,n)-1 ; int remainder=largestNDigitNum % lcm ; if(remainder==0)return largestNDigitNum ; largestNDigitNum-=remainder ; if(largestNDigitNum>=(int)Math.pow(10,n-1))return largestNDigitNum ; else return 0 ; } public static void main(String args[]){ int n=2,x=3,y=4,z=6 ; int res=findDivisible(n,x,y,z); if(res!=0)System.out.println(res); else System.out.println("Not possible"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int 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 > b) then return gcd(a - b, b) else skip ; return gcd(a, b - a) ); static operation LCM( x : int, y : int, z : int) : int pre: true post: true activity: ( var ans : int ; ans := ((x * y) / (gcd(x, y))) ; return ((z * ans) / (gcd(ans, z))) ); static operation findDivisible( n : int, x : int, y : int, z : int) : int pre: true post: true activity: ( var lcm : int ; lcm := LCM(x, y, z) ; var largestNDigitNum : int ; largestNDigitNum := 10->pow(n)->oclAsType(int) - 1 ; var remainder : int ; remainder := largestNDigitNum mod lcm ; if (remainder = 0) then return largestNDigitNum else skip ; largestNDigitNum := largestNDigitNum-(remainder) ; if (largestNDigitNum >= 10->pow(n - 1)->oclAsType(int)) then return largestNDigitNum else return 0 ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; var x : int ; x := 3 ; var y : int ; y := 4 ; var z : int ; z := 6 ; var res : int ; res := findDivisible(n, x, y, z) ; if (res /= 0) then OclFile["System.out"].println(res) ; else OclFile["System.out"].println("Not possible") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { final static int MOD=1000000007 ; static long modInv(long a){ long p=MOD-2 ; long s=1 ; while(p!=1){ if(p % 2==1)s=(s*a)% MOD ; a=(a*a)% MOD ; p/=2 ; } return(a*s)% MOD ; } static long findCnt(char x,String y){ long ans=0 ; long fact[]=new long[y.length()+1]; for(int i=0 ; isize() + 1)->collect(0) ; var i : int ; i := 0 ; while i < y->size() + 1 do ( fact[i+1] := 1 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= y->size() do ( fact[i+1] := (fact[i - 1+1] * i) mod MOD ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < y->size() do ( ( if (y->at(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 ) ; i := i + 1 ) ; ans := ans*(fact[(y->size() - 1)+1]) ; ans := ans mod MOD ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : String ; x := 'a' ; var y : String ; y := "xxayy" ; OclFile["System.out"].println(findCnt(x, y)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Subarray { static int calculate(int a[],int n){ int ans=0 ; for(int i=0 ; isize())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int INF=1<<29 ; int W=sc.nextInt(); int[] A=new int[W]; for(int i=0 ; ipow(29)))->oclAsType(long) ; var W : int ; W := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,W)->collect(0) ; var i : int ; i := 0 ; while i < W do ( ( A[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var c : Sequence(Sequence(int)) ; c := Integer.subrange(1,2)->collect(Integer.subrange(1,W)->collect(0)) ; var loop : int ; loop := 0 ; while loop < 2 do ( ( var exit : int ; exit := -1 ; var time : int ; time := INF ; var i : int ; i := 0 ; while i < W do ( ( if (A[i+1] = 0) then ( exit := i ; time := INF ) else if (A[i+1] < 0) then ( if (exit /= -1) then time := Set{time, -A[i+1] + i - exit}->min() ; else skip ) else ( if (exit /= -1) then c[loop+1][i+1] := Set{0, Set{A[i+1], time - (i - exit)}->min()}->max() ; else skip ) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < W / 2 do ( ( var tmp : int ; tmp := A[i+1] ; A[i+1] := A[W - 1 - i+1] ; A[W - 1 - i+1] := tmp ) ; i := i + 1 ) ) ; loop := loop + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < W do ( ( ans := ans+(Set{c[0+1][i+1], c[1+1][W - 1 - i+1]}->max()) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printBinStr(int[] str,int len){ for(int i=0 ; icollect(0) ; execute generateBinStr(str, n, 0, 0, 0) ; execute generateBinStr(str, n, 0, 0, 1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=26 ; static void performQueries(String str,int q,int type[],char ch[],int freq[]){ int n=str.length(); int[][] L=new int[MAX][n]; int[][] F=new int[MAX][n]; int[] cnt=new int[MAX]; for(int i=0 ; isize() ; var L : Sequence(Sequence(int)) ; L := Integer.subrange(1,MAX)->collect(Integer.subrange(1,n)->collect(0)) ; var F : Sequence(Sequence(int)) ; F := Integer.subrange(1,MAX)->collect(Integer.subrange(1,n)->collect(0)) ; var cnt : Sequence(int) ; cnt := Integer.subrange(1,MAX)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var k : int ; k := str->at(i+1) - ('a')->char2byte() ; cnt[k+1] := cnt[k+1] + 1 ; var j : int ; j := 0 ; while j < MAX 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 ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( if (type[i+1] = 1) then ( OclFile["System.out"].print(L[ch[i+1] - ('a')->char2byte()+1][freq[i+1]+1]) ) else ( OclFile["System.out"].print(F[ch[i+1] - ('a')->char2byte()+1][freq[i+1]+1]) ) ; OclFile["System.out"].print("\n") ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var type : Sequence(int) ; type := Sequence{1,2} ; var ch : Sequence(String) ; ch := Sequence{'e','k'} ; var freq : Sequence(int) ; freq := Sequence{2,2} ; var q : int ; q := type->size() ; execute performQueries(str, q, type, ch, freq) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public static void main(String[] args){ int i,j ; int val=new java.util.Scanner(System.in).nextInt(); int a=2 ; System.out.print(val+":"); while(val>=a*a){ if(val % a==0){ System.out.print(" "+a); val/=a ; } else { a++; } } System.out.println(" "+val); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var j : int ; var val : int ; val := Scanner.newScanner(OclFile["System.in"]).nextInt() ; var a : int ; a := 2 ; OclFile["System.out"].print(val + ":") ; while (val >= a * a) do ( if (val mod a = 0) then ( OclFile["System.out"].print(" " + a) ; val := val/(a) ) else ( a := a + 1 ) ) ; OclFile["System.out"].println(" " + val) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Listunko=new ArrayList(); int unko2=sc.nextInt(); fra(unko2,unko); int[] Ns=new int[32]; int cnt=0 ; for(int i=0 ; i1){ Ns[cnt]=(int)tmp ; cnt++; } } int[] kai=new int[cnt]; for(int i=0 ; ip){ for(int i=2 ; i*i<=a ; i++){ if(a % i==0){ p.add(i); fra(a/i,p); return ; } } p.add(a); } public static void fra(long a,Listp){ for(long i=2 ; i*i<=a ; i++){ if(a % i==0){ p.add(i); fra(a/i,p); return ; } } p.add(a); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var unko : Sequence(long) ; unko := Sequence{} ; var unko2 : int ; unko2 := sc.getCurrent()->toInteger() ; execute fra(unko2, unko) ; var Ns : Sequence(int) ; Ns := Integer.subrange(1,32)->collect(0) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < unko->size() do ( ( var tmp : long ; tmp := unko->at(i+1) ; if (tmp > 1) then ( Ns[cnt+1] := tmp->oclAsType(int) ; cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; var kai : Sequence(int) ; kai := Integer.subrange(1,cnt)->collect(0) ; var i : int ; i := 0 ; while i < cnt do ( ( kai[i+1] := Ns[i+1] ) ; i := i + 1 ) ; kai := kai->sort() ; var buri : String ; buri := "" ; buri := buri + unko2 + ": " ; var i : int ; i := 0 ; while i < cnt - 1 do ( ( buri := buri + kai[i+1] + " " ) ; i := i + 1 ) ; buri := buri + kai[cnt - 1+1] ; OclFile["System.out"].println(buri) ; ); static operation fra( a : int, p : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 2 ; while i * i <= a do ( ( if (a mod i = 0) then ( p->excludes(i) ; execute fra(a / i, p) ; return ) else skip ) ; i := i + 1 ) ; p->excludes(a) ); static operation fra( a : long, p : Sequence(long)) : void pre: true post: true activity: ( var i : long ; i := 2 ; while i * i <= a do ( ( if (a mod i = 0) then ( p->excludes(i) ; execute fra(a / i, p) ; return ) else skip ) ; i := i + 1 ) ; p->excludes(a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner io=new Scanner(System.in); int n=io.nextInt(); int[] a=new int[n+1]; for(int i=1 ; i<=n ; i++){ a[i]=io.nextInt(); } long sum=0 ; long now=0 ; long border=1 ; long end=0 ; long ans_p=0 ; for(int i=1 ; i<=n ; i++){ sum+=a[i]; end=border-sum ; if(border>0){ if(nowend){ ans_p+=Math.abs(now-end); now=end ; } } border=-border ; } sum=0 ; now=0 ; border=-1 ; end=0 ; long ans_m=0 ; for(int i=1 ; i<=n ; i++){ sum+=a[i]; end=border-sum ; if(border>0){ if(nowend){ ans_m+=Math.abs(now-end); now=end ; } } border=-border ; } System.out.println(Math.min(ans_p,ans_m)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : OclFile ; io := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := io.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := io.getCurrent()->toInteger() ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var now : long ; now := 0 ; var border : long ; border := 1 ; var end : long ; end := 0 ; var ans_p : long ; ans_p := 0 ; var i : int ; i := 1 ; while i <= n do ( ( sum := sum+(a[i+1]) ; end := border - sum ; if (border > 0) then ( if (now < end) then ( ans_p := ans_p+(if now - end < 0 then -(now - end) else now - end endif) ; now := end ) else skip ) else ( if (now > end) then ( ans_p := ans_p+(if now - end < 0 then -(now - end) else now - end endif) ; now := end ) else skip ) ; border := -border ) ; i := i + 1 ) ; sum := 0 ; now := 0 ; border := -1 ; end := 0 ; var ans_m : long ; ans_m := 0 ; var i : int ; i := 1 ; while i <= n do ( ( sum := sum+(a[i+1]) ; end := border - sum ; if (border > 0) then ( if (now < end) then ( ans_m := ans_m+(if now - end < 0 then -(now - end) else now - end endif) ; now := end ) else skip ) else ( if (now > end) then ( ans_m := ans_m+(if now - end < 0 then -(now - end) else now - end endif) ; now := end ) else skip ) ; border := -border ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{ans_p, ans_m}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { long n=Long.parseLong(br.readLine()); printFactor(n); } catch(Exception e){ e.printStackTrace(); } } private static void printFactor(long n){ System.out.print(n+":"); factorize(n,3); } private static void factorize(long n,long r){ if(n==1){ System.out.println(); return ; } System.out.print(" "); if(isPrime(n)){ System.out.print(n); System.out.println(); return ; } else if(n % 2==0){ System.out.print(2); n=n/(long)2 ; } else { for(long i=r ; i<=n ; i+=2){ if(n % i==0){ r=i ; System.out.print(i); n=n/i ; break ; } } } factorize(n,r); } private static boolean isPrime(long n){ if(n==2){ return true ; } if(n<2 || n % 2==0){ return false ; } int i=3 ; while(i<=Math.sqrt((double)n)){ if(n % i==0){ return false ; } i=i+2 ; } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var n : long ; n := (br.readLine())->toLong() ; execute printFactor(n) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); static operation printFactor( n : long) : void pre: true post: true activity: ( OclFile["System.out"].print(n + ":") ; execute factorize(n, 3) ); static operation factorize( n : long, r : long) : void pre: true post: true activity: ( if (n = 1) then ( OclFile["System.out"].println() ; return ) else skip ; OclFile["System.out"].print(" ") ; if (isPrime(n)) then ( OclFile["System.out"].print(n) ; OclFile["System.out"].println() ; return ) else if (n mod 2 = 0) then ( OclFile["System.out"].print(2) ; n := n / 2->oclAsType(long) ) else ( var i : long ; i := r ; while i <= n do ( ( if (n mod i = 0) then ( r := i ; OclFile["System.out"].print(i) ; n := n / i ; break ) else skip ) ; i := i+(2) ) ) ; ; execute factorize(n, r) ); static operation isPrime( n : long) : boolean pre: true post: true activity: ( if (n = 2) then ( return true ) else skip ; if (n < 2 or n mod 2 = 0) then ( return false ) else skip ; var i : int ; i := 3 ; while (i <= (n->oclAsType(double))->sqrt()) do ( if (n mod i = 0) then ( return false ) else skip ; i := i + 2 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { PrimeNumberGenerator pg=new PrimeNumberGenerator(); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); ArrayListlist=new ArrayList(); int n2=n ; while(true){ boolean divided=false ; int limit=(int)Math.sqrt(n2); for(int i=2 ; i<=limit ; i++){ if(! pg.isPrime(i)){ continue ; } if(n2 % i==0){ n2/=i ; list.add(i); divided=true ; break ; } } if(! divided){ list.add(n2); break ; } } System.out.print(n+":"); for(int i=0 ; itoInteger() ; var list : Sequence(int) ; list := Sequence{} ; var n2 : int ; n2 := n ; while (true) do ( var divided : boolean ; divided := false ; var limit : int ; limit := (n2)->sqrt()->oclAsType(int) ; var i : int ; i := 2 ; while i <= limit do ( ( if (not(pg.isPrime(i))) then ( continue ) else skip ; if (n2 mod i = 0) then ( n2 := n2/(i) ; list := list->including(i) ; divided := true ; break ) else skip ) ; i := i + 1 ) ; if (not(divided)) then ( list := list->including(n2) ; break ) else skip ) ; OclFile["System.out"].print(n + ":") ; var i : int ; i := 0 ; while i < list->size() do ( ( OclFile["System.out"].print(" " + list->at(i+1)) ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } class PrimeNumberGenerator { attribute isPrime : Sequence(boolean) := Integer.subrange(1,100001)->collect(false); static operation newPrimeNumberGenerator() : PrimeNumberGenerator pre: true post: true activity: ( var self : PrimeNumberGenerator ; self := createPrimeNumberGenerator(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( isPrime := isPrime->collect(true) ; isPrime[0+1] := false ; isPrime[1+1] := false ; isPrime[2+1] := true ; var limit : int ; limit := (isPrime->size())->sqrt()->oclAsType(int) ; var i : int ; i := 3 ; while i <= limit do ( ( if (isPrime[i+1] = false) then ( continue ) else skip ; var j : int ; j := i * 2 ; while j <= isPrime->size() - 1 do ( ( isPrime[j+1] := false ) ; j := j+(i) ) ) ; i := i+(2) ) ; ); operation isPrime( index : int) : boolean pre: true post: true activity: ( if (index mod 2 = 0 & index /= 2) then ( return false ) else skip ; return isPrime[index+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws Exception { FastScanner scanner=new FastScanner(System.in); int n=(int)scanner.nextInt(); StringBuffer str=new StringBuffer(); str.append(n+":"); for(int i=2 ; i*i<=n ; i++){ while(n % i==0){ n=n/i ; str.append(" "+i); } } if(n>1){ str.append(" "+n); } PrintWriter printWriter=new PrintWriter(System.out); printWriter.printf("%s\n",str.toString()); printWriter.close(); } static class FastScanner { private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public FastScanner(InputStream in){ reader=new BufferedReader(new InputStreamReader(in)); tokenizer=null ; } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : FastScanner ; scanner := FastScanner.newFastScanner(OclFile["System.in"]) ; var n : int ; n := scanner.nextInt()->oclAsType(int) ; var str : String ; str := StringLib.newString() ; str := str + StringLib.newString(n + ":") ; var i : int ; i := 2 ; while i * i <= n do ( ( while (n mod i = 0) do ( n := n / i ; str := str + StringLib.newString(" " + i) ) ) ; i := i + 1 ) ; if (n > 1) then ( str := str + StringLib.newString(" " + n) ) else skip ; var printWriter : OclFile ; printWriter := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip ; skip ; ); static class FastScanner { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newFastScanner( in : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.next() ); operation nextInt() : long pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isDigitPresent(int x,int d){ while(x>0){ if(x % 10==d)break ; x=x/10 ; } return(x>0); } static void printNumbers(int n,int d){ for(int i=0 ; i<=n ; i++)if(i==d || isDigitPresent(i,d))System.out.print(i+" "); } public static void main(String[] args){ int n=47,d=7 ; printNumbers(n,d); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isDigitPresent( x : int, d : int) : boolean pre: true post: true activity: ( while (x > 0) do ( if (x mod 10 = d) then break else skip ; x := x / 10 ) ; return (x > 0) ); static operation printNumbers( n : int, d : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i <= n do ( if (i = d or isDigitPresent(i, d)) then OclFile["System.out"].print(i + " ") ; else skip ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 47 ; var d : int ; d := 7 ; execute printNumbers(n, d) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class DegreeOfVertex { static class Graph { int v,e ; int[][] dir ; Graph(int v,int e){ this.v=v ; this.e=e ; dir=new int[v][]; for(int i=0 ; icollect(Sequence{}) ; var i : int ; i := 0 ; while i < v do ( dir[i+1] := Integer.subrange(1,v)->collect(0) ; ; i := i + 1 ) ); } static operation createGraph( v : int, e : int) : Graph pre: true post: true activity: ( var G : Graph ; G := Graph.newGraph(v, e) ; G.dir[0+1][1+1] := 1 ; G.dir[0+1][2+1] := 1 ; G.dir[0+1][3+1] := 1 ; G.dir[1+1][0+1] := 1 ; G.dir[1+1][3+1] := 1 ; G.dir[2+1][0+1] := 1 ; G.dir[2+1][3+1] := 1 ; G.dir[3+1][0+1] := 1 ; G.dir[3+1][1+1] := 1 ; G.dir[3+1][2+1] := 1 ; return G ); static operation findDegree( G : Graph, ver : int) : int pre: true post: true activity: ( var degree : int ; degree := 0 ; var i : int ; i := 0 ; while i < G.v do ( ( if (G.dir[ver+1][i+1] = 1) then degree := degree + 1 ; else skip ) ; i := i + 1 ) ; return degree ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var vertices : int ; vertices := 4 ; var edges : int ; edges := 5 ; var G : Graph ; G := createGraph(vertices, edges) ; var ver : int ; ver := 0 ; var degree : int ; degree := findDegree(G, ver) ; OclFile["System.out"].println(degree) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int findElement(int arr[],int size){ int right_sum=0,left_sum=0 ; for(int i=1 ; isize() ; OclFile["System.out"].println(findElement(arr, size)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Stack ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int[] parent=new int[n+1]; for(int i=2 ; i<=n ; i++){ parent[i]=scanner.nextInt(); } int q=n ; Stackstack=new Stack<>(); while(q!=0){ stack.push(q); q=parent[q]; } while(! stack.isEmpty()){ System.out.print(stack.pop()+" "); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var parent : Sequence(int) ; parent := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 2 ; while i <= n do ( ( parent[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var q : int ; q := n ; var stack : Sequence(int) ; stack := Sequence{} ; while (q /= 0) do ( stack := stack->append(q) ; q := parent[q+1] ) ; while (not(stack->isEmpty())) do ( OclFile["System.out"].print(stack->last() + " ") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class BmailComputerNetwork { public static void main(String args[]){ Scanner scanner=new Scanner(System.in); String number=scanner.nextLine(); int n=Integer.parseInt(number); String[] array=scanner.nextLine().split(" "); int routerNumber=2 ; Map>map=new HashMap<>(); MapvisitedToFrom=new HashMap<>(); for(String str : array){ int routerConnectionTo=Integer.parseInt(str); map.putIfAbsent(routerConnectionTo,new HashSet<>()); map.putIfAbsent(routerNumber,new HashSet<>()); map.get(routerConnectionTo).add(routerNumber); map.get(routerNumber).add(routerConnectionTo); routerNumber++; } int start=1 ; Queuequeue=new LinkedList<>(); queue.offer(start); Stackstack=new Stack<>(); boolean foundN=false ; while(queue.size()>0){ int current=queue.poll(); for(int next : map.get(current)){ if(visitedToFrom.containsKey(next))continue ; visitedToFrom.put(next,current); queue.offer(next); if(next==n){ foundN=true ; break ; } } if(foundN){ stack.push(n); break ; } } int destination=n ; while(visitedToFrom.containsKey(destination)&& destination!=1){ stack.push(visitedToFrom.get(destination)); destination=stack.peek(); } while(stack.size()>0)System.out.print(stack.pop()+(stack.size()==0 ? "" : " ")); } } ------------------------------------------------------------ OCL File: --------- class BmailComputerNetwork { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : String ; number := scanner.nextLine() ; var n : int ; n := (number)->toInteger() ; var array : Sequence(String) ; array := scanner.nextLine()->split(" ") ; var routerNumber : int ; routerNumber := 2 ; var map : Map(int,Set(int)) ; map := Map{} ; var visitedToFrom : Map(int,int) ; visitedToFrom := Map{} ; for (str : array) do ( ( var routerConnectionTo : int ; routerConnectionTo := (str)->toInteger() ; if map->keys()->includes(routerConnectionTo) then skip else map := map->union(Map{routerConnectionTo |-> Set{}}) ; if map->keys()->includes(routerNumber) then skip else map := map->union(Map{routerNumber |-> Set{}}) ; map->at(routerConnectionTo)->excludes(routerNumber) ; map->at(routerNumber)->excludes(routerConnectionTo) ; routerNumber := routerNumber + 1 ; ) ) ; var start : int ; start := 1 ; var queue : Sequence(int) ; queue := Sequence{} ; queue := queue->including(start) ; var stack : Sequence(int) ; stack := Sequence{} ; var foundN : boolean ; foundN := false ; while (queue->size() > 0) do ( var current : int ; current := queue->min() ; for (next : map->at(current)) do ( ( if (visitedToFrom->keys()->includes(next)) then continue else skip ; visitedToFrom := visitedToFrom->union(Map{next |-> current}) ; queue := queue->including(next) ; if (next = n) then ( foundN := true ; break ) else skip ) ) ; if (foundN) then ( stack := stack->append(n) ; break ) else skip ) ; var destination : int ; destination := n ; while (visitedToFrom->keys()->includes(destination) & destination /= 1) do ( stack := stack->append(visitedToFrom->at(destination)) ; destination := stack->min() ) ; while (stack->size() > 0) do OclFile["System.out"].print(stack->last() + (if stack->size() = 0 then "" else " " endif)) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class bmails { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] parent=new int[n+1]; for(int i=2 ; i<=n ; i++)parent[i]=sc.nextInt(); int q=n ; Stackst=new Stack<>(); while(q!=0){ st.push(q); q=parent[q]; } while(! st.isEmpty())System.out.print(st.pop()+" "); System.out.println(); } } ------------------------------------------------------------ OCL File: --------- class bmails { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var parent : Sequence(int) ; parent := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 2 ; while i <= n do ( parent[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var q : int ; q := n ; var st : Sequence(int) ; st := Sequence{} ; while (q /= 0) do ( st := st->append(q) ; q := parent[q+1] ) ; while (not(st->isEmpty())) do OclFile["System.out"].print(st->last() + " ") ; ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; import java.util.ArrayList ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(in.readLine()); int[] ps=new int[n]; ps[0]=-1 ; String[] sps=in.readLine().split(" "); for(int i=1 ; ians=new ArrayList<>(); while(current!=-1){ ans.add(current); current=ps[current]; } for(int i=ans.size()-1 ; i>=0 ; i--){ if(i!=ans.size()-1){ out.write(" "); } out.write((ans.get(i)+1)+""); } out.write("\n"); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var n : int ; n := (in.readLine())->toInteger() ; var ps : Sequence(int) ; ps := Integer.subrange(1,n)->collect(0) ; ps[0+1] := -1 ; var sps : Sequence(String) ; sps := in.readLine()->split(" ") ; var i : int ; i := 1 ; while i < n do ( ( ps[i+1] := (sps[i - 1+1])->toInteger() - 1 ) ; i := i + 1 ) ; var current : int ; current := n - 1 ; var ans : Sequence(int) ; ans := Sequence{} ; while (current /= -1) do ( ans := ans->including(current) ; current := ps[current+1] ) ; var i : int ; i := ans->size() - 1 ; while i >= 0 do ( ( if (i /= ans->size() - 1) then ( skip ) else skip ; skip ) ; i := i - 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); StringTokenizer str=new StringTokenizer(br.readLine()," "); long[] A=new long[n]; for(int i=0 ; i=0){ c1+=(sum+A[i]+1); sum=-1 ; } else if(i % 2!=0 && sum+A[i]<=0){ c1+=1+(-sum-A[i]); sum=1 ; } else { sum+=A[i]; } } sum=0 ; for(int i=0 ; i=0){ c2+=1+sum+A[i]; sum=-1 ; } else { sum+=A[i]; } } return Math.min(c1,c2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var str : OclIterator ; str := OclIterator.newOclIterator_String_String(br.readLine(), " ") ; var A : Sequence(long) ; A := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := (str.next())->toInteger() ) ; i := i + 1 ) ; var c : long ; c := func(A, n) ; OclFile["System.out"].println(c) ; ) catch (e : IOException) do ( OclFile["System.out"].println("error") ) ); static operation func( A : Sequence(long), n : int) : long pre: true post: true activity: ( var sum : long ; sum := 0 ; var c1 : long ; c1 := 0 ; var c2 : long ; c2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (i mod 2 = 0 & sum + A[i+1] >= 0) then ( c1 := c1+((sum + A[i+1] + 1)) ; sum := -1 ) else if (i mod 2 /= 0 & sum + A[i+1] <= 0) then ( c1 := c1+(1 + (-sum - A[i+1])) ; sum := 1 ) else ( sum := sum+(A[i+1]) ) ; ) ; i := i + 1 ) ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (i mod 2 = 0 & sum + A[i+1] <= 0) then ( c2 := c2+((-sum - A[i+1] + 1)) ; sum := 1 ) else if (i mod 2 /= 0 & sum + A[i+1] >= 0) then ( c2 := c2+(1 + sum + A[i+1]) ; sum := -1 ) else ( sum := sum+(A[i+1]) ) ; ) ; i := i + 1 ) ; return Set{c1, c2}->min() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=26 ; static String countingsort(char[] s){ int[] count=new int[MAX]; for(int i=0 ; iv,String str){ str=countingsort(str.toCharArray()); for(int i=0 ; iv=new Vector(Arrays.asList(arr)); if(isPossible(v,str))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 26; static operation countingsort( s : Sequence(String)) : String pre: true post: true activity: ( var count : Sequence(int) ; count := Integer.subrange(1,MAX)->collect(0) ; var i : int ; i := 0 ; while i < s->size() do ( ( count[s[i+1] - ('a')->char2byte()+1] := count[s[i+1] - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < MAX do ( ( var j : int ; j := 0 ; while (j < count[i+1]) do ( s[index+1] := (i + 'a')->oclAsType(String) ; index := index + 1 ; j := j + 1 ) ) ; i := i + 1 ) ; return ((s) + "") ); static operation isPossible( v : Sequence(String), str : String) : boolean pre: true post: true activity: ( str := countingsort(str->characters()) ; var i : int ; i := 0 ; while i < v->size() - 1 do ( ( var j : int ; j := i + 1 ; while j < v->size() do ( ( var temp : String ; temp := v->at(i+1) + v->at(j+1) ; temp := countingsort(temp->characters()) ; if (temp = str) then ( return true ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "amazon" ; var arr : Sequence(String) ; arr := Sequence{"fds","oxq","zoa","epw","amn"} ; var v : Sequence(String) ; v := Sequence{}->union(arr) ; if (isPossible(v, str)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int h=sc.nextInt(); int v=sc.nextInt(); h=sc.nextInt()-h ; v=sc.nextInt()-v ; String s=sc.next(); if(h==0 && v==0){ System.out.println(0); return ; } int t=-1 ; for(int i=0 ; i0){ v--; } } else if(s.charAt(i)=='E'){ if(h>0){ h--; } } else if(s.charAt(i)=='S'){ if(v<0){ v++; } } else if(s.charAt(i)=='W'){ if(h<0){ h++; } } if(h==0 && v==0){ t=i+1 ; break ; } } System.out.println(t); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; var v : int ; v := sc.getCurrent()->toInteger() ; h := sc.getCurrent()->toInteger() - h ; v := sc.getCurrent()->toInteger() - v ; var s : String ; s := sc.getCurrent() ; if (h = 0 & v = 0) then ( OclFile["System.out"].println(0) ; return ) else skip ; var t : int ; t := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (s->at(i+1) = 'N') then ( if (v > 0) then ( v := v - 1 ) else skip ) else if (s->at(i+1) = 'E') then ( if (h > 0) then ( h := h - 1 ) else skip ) else if (s->at(i+1) = 'S') then ( if (v < 0) then ( v := v + 1 ) else skip ) else if (s->at(i+1) = 'W') then ( if (h < 0) then ( h := h + 1 ) else skip ) else skip ; ; ; ; if (h = 0 & v = 0) then ( t := i + 1 ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(t) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); sc.nextInt(); int sx=sc.nextInt(); int sy=sc.nextInt(); int ex=sc.nextInt(); int ey=sc.nextInt(); String s=sc.next(); System.out.println(solve(s,sx,sy,ex,ey)); sc.close(); } static int solve(String s,int sx,int sy,int ex,int ey){ int distance=computeDistance(sx,sy,ex,ey); int x=sx ; int y=sy ; for(int i=0 ; itoInteger() ; var sy : int ; sy := sc.getCurrent()->toInteger() ; var ex : int ; ex := sc.getCurrent()->toInteger() ; var ey : int ; ey := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; OclFile["System.out"].println(solve(s, sx, sy, ex, ey)) ; skip ; ); static operation solve( s : String, sx : int, sy : int, ex : int, ey : int) : int pre: true post: true activity: ( var distance : int ; distance := computeDistance(sx, sy, ex, ey) ; var x : int ; x := sx ; var y : int ; y := sy ; var i : int ; i := 0 ; while i < s->size() do ( ( var c : String ; c := s->at(i+1) ; var nextX : int ; nextX := x ; var nextY : int ; nextY := y ; if (c = 'E') then ( nextX := nextX + 1 ) else if (c = 'S') then ( nextY := nextY - 1 ) else if (c = 'W') then ( nextX := nextX - 1 ) else ( nextY := nextY + 1 ) ; ; ; var nextDistance : int ; nextDistance := computeDistance(nextX, nextY, ex, ey) ; if (nextDistance < distance) then ( distance := nextDistance ; x := nextX ; y := nextY ; if (distance = 0) then ( return i + 1 ) else skip ) else skip ; ) ; i := i + 1 ) ; return -1 ); static operation computeDistance( x1 : int, y1 : int, x2 : int, y2 : int) : int pre: true post: true activity: ( return if x1 - x2 < 0 then -(x1 - x2) else x1 - x2 endif + if y1 - y2 < 0 then -(y1 - y2) else y1 - y2 endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class D21195 { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int a[]=new int[n+5]; int b[]=new int[n+5]; int c[]=new int[n+5]; for(int i=1 ; i<=n ; i++){ a[i]=scan.nextInt(); } for(int i=1 ; i<=n ; i++){ b[i]=scan.nextInt(); c[b[i] ]=i ; } if(c[1]>=1){ int i=0 ; for(i=2 ; c[i]==c[1]+i-1 ; i++); if(c[i-1]==n){ int j ; for(j=i ; j<=n && c[j]<=(j-i); j++); if(j>n){ System.out.println(n-i+1); return ; } } } int ans=0 ; for(int i=1 ; i<=n ; i++){ ans=Math.max(ans,c[i]-i+1+n); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class D21195 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 5)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n + 5)->collect(0) ; var c : Sequence(int) ; c := Integer.subrange(1,n + 5)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( b[i+1] := scan.getCurrent()->toInteger() ; c[b[i+1]+1] := i ) ; i := i + 1 ) ; if (c[1+1] >= 1) then ( var i : int ; i := 0 ; i := 2 ; while c[i+1] = c[1+1] + i - 1 do ( ; i := i + 1 ) ; if (c[i - 1+1] = n) then ( var j : int ; j := i ; while j <= n & c[j+1] <= (j - i) do ( ; j := j + 1 ) ; if (j > n) then ( OclFile["System.out"].println(n - i + 1) ; return ) else skip ) else skip ) else skip ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( ans := Set{ans, c[i+1] - i + 1 + n}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class NewClass { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(),sx=in.nextInt(),sy=in.nextInt(),ex=in.nextInt(),ey=in.nextInt(); String str=in.next(); int x=ex-sx,y=ey-sy ; int i=0 ; for(; i0)y--; else if(ch=='S' && y<0)y++; else if(ch=='E' && x>0)x--; else if(ch=='W' && x<0)x++; else if(y==0 && x==0)break ; } System.out.println((y==0 && x==0)? i :-1); } } ------------------------------------------------------------ OCL File: --------- class NewClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var sx : int ; sx := in.getCurrent()->toInteger() ; var sy : int ; sy := in.getCurrent()->toInteger() ; var ex : int ; ex := in.getCurrent()->toInteger() ; var ey : int ; ey := in.getCurrent()->toInteger() ; var str : String ; str := in.getCurrent() ; var x : int ; x := ex - sx ; var y : int ; y := ey - sy ; var i : int ; i := 0 ; while i < str->size() do ( ( var ch : String ; ch := str->at(i+1) ; if (ch = 'N' & y > 0) then y := y - 1 ; else if (ch = 'S' & y < 0) then y := y + 1 else if (ch = 'E' & x > 0) then x := x - 1 else if (ch = 'W' & x < 0) then x := x + 1 else if (y = 0 & x = 0) then break else skip ; ; ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(if (y = 0 & x = 0) then i else -1 endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); long sx=in.nextLong(),sy=in.nextLong(),ex=in.nextLong(),ey=in.nextLong(); String s=in.next(); long tim=-1 ; for(int i=0 ; isy){ sy+=1 ; } break ; default : break ; } if(sx==ex && sy==ey){ tim=i+1 ; break ; } } System.out.println(tim); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var sx : long ; sx := in.getCurrent()->toLong() ; var sy : long ; sy := in.getCurrent()->toLong() ; var ex : long ; ex := in.getCurrent()->toLong() ; var ey : long ; ey := in.getCurrent()->toLong() ; var s : String ; s := in.getCurrent() ; var tim : long ; tim := -1 ; var i : int ; i := 0 ; while i < n do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (s->at(i+1)) ; if _switchval = 'S' then if (ey < sy) then ( sy := sy-(1) ) else skip ; break else skip ; if _switchval = 'E' then if (sx < ex) then ( sx := sx+(1) ) else skip ; break else skip ; if _switchval = 'W' then if (ex < sx) then ( sx := sx-(1) ) else skip ; break else skip ; if _switchval = 'N' then if (ey > sy) then ( sy := sy+(1) ) else skip ; break else skip ; if true then break else skip ; ) if (sx = ex & sy = ey) then ( tim := i + 1 ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(tim) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class StringEqualizer { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int q=sc.nextInt(); while(q-->0){ String s=sc.next(); String t=sc.next(); boolean f=false ; for(int i=0 ; itoInteger() ; while (q > 0) do ( q := q - 1 ; skip ; ( var s : String ; s := sc.getCurrent() ; var t : String ; t := sc.getCurrent() ; var f : boolean ; f := false ; var i : int ; i := 0 ; while i < s->size() do ( ( if (t->includes(s.subrange(i+1,i + 1))) then ( f := true ; break ) else skip ) ; i := i + 1 ) ; if (f) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class StringsEqualization { public static void main(String args[]){ Scanner in=new Scanner(System.in); int q=in.nextInt(); in.nextLine(); for(int i=0 ; i0){ yes=true ; break ; } } if(yes)System.out.println("Yes"); else System.out.println("no"); } } } ------------------------------------------------------------ OCL File: --------- class StringsEqualization { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := in.getCurrent()->toInteger() ; skip ; var i : int ; i := 0 ; while i < q do ( ( var s : String ; s := in.nextLine() ; var t : String ; t := in.nextLine() ; var l : int ; l := s->size() ; var ar : Sequence(int) ; ar := Integer.subrange(1,26 + 1)->collect(0) ; var j : int ; j := 0 ; while j < l do ( ( var c : String ; c := s->at(j+1) ; var nu : int ; nu := ((c)->char2byte() - 97) ; ar[nu+1] := ar[nu+1] + 1 ) ; j := j + 1 ) ; var yes : boolean ; yes := false ; l := s->size() ; var j : int ; j := 0 ; while j < l do ( ( var c : String ; c := t->at(j+1) ; var nu : int ; nu := ((c)->char2byte() - 97) ; if (ar[nu+1] > 0) then ( yes := true ; break ) else skip ) ; j := j + 1 ) ; if (yes) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("no") ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.Scanner ; public class FileName { int number ; public FileName(int number){ this.number=number ; } public int getNumber(){ return number ; } public void input(String s){ LinkedListlist=new LinkedList<>(); int count=0 ; for(int i=0 ; i=3){ cResult+=(l-2); } } System.out.println(cResult); } public static void main(String[] a){ Scanner input=new Scanner(System.in); int number=input.nextInt(); FileName instance=new FileName(number); String sName=input.next(); instance.input(sName); } } ------------------------------------------------------------ OCL File: --------- class FileName { attribute number : int; static operation newFileName( number : int) : FileName pre: true post: true activity: ( var self : FileName ; self := createFileName(); self.initialise(number); return self ); operation initialise( number : int) : void pre: true post: true activity: ( self.number := number ); operation getNumber() : int pre: true post: true activity: ( return number ); operation input( s : String) : void pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{} ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < getNumber() do ( ( if (s->at(i+1) = 'x') then ( count := count + 1 ; if (i = getNumber() - 1) then ( list := list->including(count) ) else skip ) else ( list := list->including(count) ; count := 0 ) ) ; i := i + 1 ) ; var cResult : int ; cResult := 0 ; for (l : list) do ( ( if (l >= 3) then ( cResult := cResult+((l - 2)) ) else skip ) ) ; OclFile["System.out"].println(cResult) ; ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := input.getCurrent()->toInteger() ; var instance : FileName ; instance := FileName.newFileName(number) ; var sName : String ; sName := input.getCurrent() ; instance.input(sName) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class B1223 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader in=new FastReader(); int t=1 ; t=in.nextInt(); while(t-->0){ String S1=in.nextLine(); String S2=in.nextLine(); if(S1.length()!=S2.length())System.out.println("NO"); else { HashSethset=new HashSet<>(); for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastReader ; in := FastReader.newFastReader() ; var t : int ; t := 1 ; t := in.nextInt() ; while (t > 0) do ( t := t - 1 ; skip ; ( var S1 : String ; S1 := in.nextLine() ; var S2 : String ; S2 := in.nextLine() ; if (S1->size() /= S2->size()) then OclFile["System.out"].println("NO") ; else ( var hset : Set(int) ; hset := Set{} ; var i : int ; i := 0 ; while i < S1->size() do ( ( hset := hset->including(S1->at(i+1)->oclAsType(int)) ) ; i := i + 1 ) ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < S2->size() do ( ( if ((hset->includes(S2->at(i+1)->oclAsType(int)))) then ( OclFile["System.out"].println("YES") ; flag := 1 ; break ) else skip ) ; i := i + 1 ) ; if (flag = 0) then OclFile["System.out"].println("NO") ; else skip ; ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class StringsEqualization { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); a : while(t-->0){ String a=scan.next(); String b=scan.next(); int n=a.length(); int[] k=new int[26]; for(int i=0 ; i=1){ System.out.println("Yes"); continue a ; } } System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class StringsEqualization { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scan.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : String ; a := scan.getCurrent() ; var b : String ; b := scan.getCurrent() ; var n : int ; n := a->size() ; var k : Sequence(int) ; k := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( k[a->at(i+1) - ('a')->char2byte()+1] := k[a->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (k[b->at(i+1) - ('a')->char2byte()+1] >= 1) then ( OclFile["System.out"].println("Yes") ; continue ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("No") ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStreamReader ; import java.io.IOException ; import java.util.StringTokenizer ; import javax.swing.plaf.synth.SynthMenuItemUI ; import java.io.BufferedReader ; import java.io.PrintWriter ; public class Peter { public static void main(String[] args)throws IOException { PrintWriter pw=new PrintWriter(System.out); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st_1=new StringTokenizer(br.readLine()); int d=Integer.parseInt(st_1.nextToken()); int sumTime=Integer.parseInt(st_1.nextToken()); int low_sum=0,high_sum=0 ; int lo[]=new int[d]; int hi[]=new int[d]; for(int i=0 ; ihigh_sum || sumTimeone_diff){ pw.print(hi[i]); pw.print(" "); diff-=one_diff ; } else if(diff==0){ pw.print(lo[i]); pw.print(" "); } else { pw.print(diff+lo[i]); pw.print(" "); diff=0 ; } } } pw.flush(); } } ------------------------------------------------------------ OCL File: --------- class Peter { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st var stOclIterator : OclFile ; stOclIterator := OclIterator.newOclIterator_String(br.readLine()) : OclIterator ; st var stOclIterator : OclFile ; stOclIterator := OclIterator.newOclIterator_String(br.readLine()) := OclIterator.newOclIterator_String(br.readLine()) ; var d : int ; d := (stst(st(stst(std.next() + "")->toInteger().next().next())->toInteger().next() + "")->toInteger().next().next())->toInteger() ; var sumTime : int ; sumTime := (stst(st(stst(stsumTime.next() + "")->toInteger().next().next())->toInteger().next() + "")->toInteger().next().next())->toInteger() ; var low_sum : int ; low_sum := 0 ; var high_sum : int ; high_sum := 0 ; var lo : Sequence(int) ; lo := Integer.subrange(1,d)->collect(0) ; var hi : Sequence(int) ; hi := Integer.subrange(1,d)->collect(0) ; var i : int ; i := 0 ; while i < d do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var low : int ; low := (st.next())->toInteger() ; low_sum := low_sum+(low) ; lo[i+1] := low ; var high : int ; high := (st.next())->toInteger() ; high_sum := high_sum+(high) ; hi[i+1] := high ; ) ; i := i + 1 ) ; if (sumTime > high_sum or sumTime < low_sum) then ( skip ) else ( skip ; var diff : int ; diff := sumTime - low_sum ; var i : int ; i := 0 ; while i < d do ( ( var one_diff : int ; one_diff := hi[i+1] - lo[i+1] ; if (diff > one_diff) then ( skip ; skip ; diff := diff-(one_diff) ) else if (diff = 0) then ( skip ; skip ) else ( skip ; skip ; diff := 0 ) ; ) ; i := i + 1 ) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int sumtime=sc.nextInt(); int maxtime=0 ; int mintime=0 ; int a[]=new int[n]; int b[]=new int[n]; for(int i=0 ; imaxtime){ System.out.println("NO"); return ; } System.out.println("YES"); for(int i=0 ; itoInteger() ; var sumtime : int ; sumtime := sc.getCurrent()->toInteger() ; var maxtime : int ; maxtime := 0 ; var mintime : int ; mintime := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ; mintime := mintime+(a[i+1]) ; maxtime := maxtime+(b[i+1]) ) ; i := i + 1 ) ; if (sumtime < mintime or sumtime > maxtime) then ( OclFile["System.out"].println("NO") ; return ) else skip ; OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(Set{b[i+1], a[i+1] + sumtime - mintime}->min() + " ") ; sumtime := sumtime-(Set{b[i+1], a[i+1] + sumtime - mintime}->min()) ; mintime := mintime-(a[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Cf4A { BufferedReader br ; StringTokenizer in ; PrintWriter out ; public String nextToken()throws IOException { while(in==null || ! in.hasMoreTokens()){ in=new StringTokenizer(br.readLine()); } return in.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(nextToken()); } public double nextDouble()throws IOException { return Double.parseDouble(nextToken()); } public long nextLong()throws IOException { return Long.parseLong(nextToken()); } public static void main(String[] args)throws IOException { new Cf4A().run(); } public void solve()throws IOException { int d=nextInt(); int st=nextInt(); int[] min=new int[d]; int[] max=new int[d]; int totalMin=0 ; int totalMax=0 ; for(int i=0 ; itotalMax){ out.println("NO"); } else { while(totalMintoInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Cf4A.newCf4A().run() ); operation solve() : void pre: true post: true activity: ( var d : int ; d := nextInt() ; var st : int ; st := nextInt() ; var min : Sequence(int) ; min := Integer.subrange(1,d)->collect(0) ; var max : Sequence(int) ; max := Integer.subrange(1,d)->collect(0) ; var totalMin : int ; totalMin := 0 ; var totalMax : int ; totalMax := 0 ; var i : int ; i := 0 ; while i < d do ( ( min[i+1] := nextInt() ; max[i+1] := nextInt() ; totalMin := totalMin+(min[i+1]) ; totalMax := totalMax+(max[i+1]) ) ; i := i + 1 ) ; if (st < totalMin or st > totalMax) then ( skip ) else ( while (totalMin < st) do ( var i : int ; i := 0 ; while i < d do ( ( if (min[i+1] < max[i+1]) then ( min[i+1] := min[i+1] + 1 ; totalMin := totalMin + 1 ; break ) else skip ) ; i := i + 1 ) ) ; skip ; var i : int ; i := 0 ; while i < d do ( ( skip ) ; i := i + 1 ) ) ; ); operation run() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ) catch (e : IOException) do ( e.printStackTrace() ; OclProcess.exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashSet ; import java.util.List ; import java.util.PriorityQueue ; public class Solution { static int[] nodeColors ; static boolean[] visited ; static List[] neighbors ; static String[][] neighborstring ; static List[] startIndices ; static int[] edgesToPrint ; static int mod=998244353 ; static int[] parents ; static HashSetcycleSet ; static PriorityQueue[] neighborPriority ; public static void main(String[] args)throws IOException { BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); int tests=Integer.parseInt(bufferedReader.readLine()); StringBuilder stringBuilder=new StringBuilder(); for(int test=0 ; test(nodes*(nodes-1))/2){ stringBuilder.append("NO").append("\n"); continue ; } int diameter=0 ; if(edges==(nodes*(nodes-1))/2){ diameter=1 ; } else { diameter=2 ; } if(nodes==1){ diameter=0 ; } if(diametertoInteger() ; var stringBuilder : String ; stringBuilder := StringLib.newString() ; var test : int ; test := 0 ; while test < tests do ( ( var inp : Sequence(String) ; inp := bufferedReader.readLine()->split(" ") ; var nodes : long ; nodes := (inp[0+1])->toLong() ; var edges : long ; edges := (inp[1+1])->toLong() ; var constant : long ; constant := (inp[2+1])->toLong() ; if (edges < nodes - 1 or edges > (nodes * (nodes - 1)) / 2) then ( stringBuilder := stringBuilder + StringLib.newString("NO") + StringLib.newString("\n") ; continue ) else skip ; var diameter : int ; diameter := 0 ; if (edges = (nodes * (nodes - 1)) / 2) then ( diameter := 1 ) else ( diameter := 2 ) ; if (nodes = 1) then ( diameter := 0 ) else skip ; if (diameter < constant - 1) then ( stringBuilder := stringBuilder + StringLib.newString("YES") + StringLib.newString("\n") ) else ( stringBuilder := stringBuilder + StringLib.newString("NO") + StringLib.newString("\n") ) ; ) ; test := test + 1 ) ; OclFile["System.out"].println(stringBuilder) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Math.abs ; import java.util.*; class GFG { static int solution(Vectorarr,int x){ Collections.sort(arr); int closestSum=Integer.MAX_VALUE ; for(int i=0 ; ix){ ptr2--; } else { ptr1++; } } } return closestSum ; } public static void main(String[] args){ Vector arr=new Vector(Arrays.asList(-1,2,1,-4)); int x=1 ; System.out.println(solution(arr,x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solution( arr : Sequence(int), x : int) : int pre: true post: true activity: ( arr := arr->sort() ; var closestSum : int ; closestSum := 2147483647 ; var i : int ; i := 0 ; while i < arr->size() - 2 do ( ( var ptr1 : int ; ptr1 := i + 1 ; var ptr2 : int ; ptr2 := arr->size() - 1 ; while (ptr1 < ptr2) do ( var sum : int ; sum := arr->at(i+1) + arr->at(ptr1+1) + arr->at(ptr2+1) ; if (abs(x - sum) < abs(x - closestSum)) then ( closestSum := sum ) else skip ; if (sum > x) then ( ptr2 := ptr2 - 1 ) else ( ptr1 := ptr1 + 1 ) ) ) ; i := i + 1 ) ; return closestSum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence ; arr := Sequence{}->union(Sequence{-1,2,1,-4}) ; var x : int ; x := 1 ; OclFile["System.out"].println(solution(arr, x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int days=sc.nextInt(); int sumTime=sc.nextInt(); int min[]=new int[days]; int max[]=new int[days]; int maxTime=0 ; int minTime=0 ; for(int i=0 ; imaxTime || sumTimetoInteger() ; var sumTime : int ; sumTime := sc.getCurrent()->toInteger() ; var min : Sequence(int) ; min := Integer.subrange(1,days)->collect(0) ; var max : Sequence(int) ; max := Integer.subrange(1,days)->collect(0) ; var maxTime : int ; maxTime := 0 ; var minTime : int ; minTime := 0 ; var i : int ; i := 0 ; while i < days do ( ( min[i+1] := sc.getCurrent()->toInteger() ; minTime := minTime+(min[i+1]) ; max[i+1] := sc.getCurrent()->toInteger() ; maxTime := maxTime+(max[i+1]) ) ; i := i + 1 ) ; if (sumTime > maxTime or sumTime < minTime) then ( OclFile["System.out"].print("NO") ) else ( OclFile["System.out"].println("YES") ; sumTime := sumTime-(minTime) ; var i : int ; i := 0 ; while i < days do ( ( if (max[i+1] - min[i+1] < sumTime) then ( OclFile["System.out"].print(max[i+1] + " ") ; sumTime := sumTime-(max[i+1] - min[i+1]) ) else ( OclFile["System.out"].print((min[i+1] + sumTime) + " ") ; sumTime := 0 ) ) ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean canBePicked(int digits[],int num){ int copyDigits[]=digits.clone(); while(num>0){ int digit=num % 10 ; if(copyDigits[digit]==0)return false ; else copyDigits[digit]--; num/=10 ; } return true ; } static int countAlphabets(int n){ int i,count=0 ; int digits[]=new int[10]; while(n>0){ int digit=n % 10 ; digits[digit]++; n/=10 ; } for(i='a' ; i<='z' ; i++)if(canBePicked(digits,i))count++; for(i='A' ; i<='Z' ; i++)if(canBePicked(digits,i))count++; return count ; } public static void main(String[] args){ int n=1623455078 ; System.out.println(countAlphabets(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation canBePicked( digits : Sequence(int), num : int) : boolean pre: true post: true activity: ( var copyDigits : Sequence(int) ; copyDigits := digits->copy() ; while (num > 0) do ( var digit : int ; digit := num mod 10 ; if (copyDigits[digit+1] = 0) then return false else copyDigits[digit+1] := copyDigits[digit+1] - 1 ; ; num := num/(10) ) ; return true ); static operation countAlphabets( n : int) : int pre: true post: true activity: ( var i : int ; var count : int ; count := 0 ; var digits : Sequence(int) ; digits := Integer.subrange(1,10)->collect(0) ; while (n > 0) do ( var digit : int ; digit := n mod 10 ; digits[digit+1] := digits[digit+1] + 1 ; n := n/(10) ) ; i := 'a' ; while i <= 'z' do ( if (canBePicked(digits, i)) then count := count + 1 ; else skip ; ; i := i + 1 ) ; i := 'A' ; while i <= 'Z' do ( if (canBePicked(digits, i)) then count := count + 1 ; else skip ; ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 1623455078 ; OclFile["System.out"].println(countAlphabets(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int n=sc.nextInt(); int[] ar=new int[n]; for(int i=0 ; i=0){ minA+=Math.abs(sumA)+1 ; sumA-=Math.abs(sumA)+1 ; } } } long minB=0 ; long sumB=0 ; for(int i=0 ; i=0){ minB+=Math.abs(sumB)+1 ; sumB-=Math.abs(sumB)+1 ; } } } System.out.println(Math.min(minA,minB)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var ar : Sequence(int) ; ar := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ar[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var minA : long ; minA := 0 ; var sumA : long ; sumA := 0 ; var i : int ; i := 0 ; while i < n do ( ( sumA := sumA+(ar[i+1]) ; if (i mod 2 = 0) then ( if (sumA <= 0) then ( minA := minA+(if sumA < 0 then -(sumA) else sumA endif + 1) ; sumA := sumA+(if sumA < 0 then -(sumA) else sumA endif + 1) ) else skip ) else ( if (sumA >= 0) then ( minA := minA+(if sumA < 0 then -(sumA) else sumA endif + 1) ; sumA := sumA-(if sumA < 0 then -(sumA) else sumA endif + 1) ) else skip ) ) ; i := i + 1 ) ; var minB : long ; minB := 0 ; var sumB : long ; sumB := 0 ; var i : int ; i := 0 ; while i < n do ( ( sumB := sumB+(ar[i+1]) ; if (i mod 2 /= 0) then ( if (sumB <= 0) then ( minB := minB+(if sumB < 0 then -(sumB) else sumB endif + 1) ; sumB := sumB+(if sumB < 0 then -(sumB) else sumB endif + 1) ) else skip ) else ( if (sumB >= 0) then ( minB := minB+(if sumB < 0 then -(sumB) else sumB endif + 1) ; sumB := sumB-(if sumB < 0 then -(sumB) else sumB endif + 1) ) else skip ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{minA, minB}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void getNumbers(int a[],int n){ HashMapfreq=new HashMap(); for(int i=0 ; ikeys()->includes(a[i+1])) then ( freq := freq->union(Map{a[i+1] |-> freq->at(a[i+1]) + 1}) ) else ( freq := freq->union(Map{a[i+1] |-> 1}) ) ; ; i := i + 1 ) ; var maxi1 : int ; maxi1 := stream(a).max().getAsInt() ; var i : int ; i := 1 ; while i * i <= maxi1 do ( ( if (maxi1 mod i = 0 & freq->keys()->includes(i) & freq->at(i) /= 0) then ( freq := freq->union(Map{i |-> freq->at(i) - 1}) ; if (i /= (maxi1 / i) & freq->keys()->includes(maxi1 / i) & freq->at(maxi1 / i) /= 0) then freq := freq->union(Map{maxi1 / i |-> freq->at(maxi1 / i) - 1}) ; else skip ) else skip ) ; i := i + 1 ) ; var maxi2 : int ; maxi2 := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (freq->at(a[i+1]) /= 0) then maxi2 := Set{maxi2, a[i+1]}->max() ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(maxi1 + " " + maxi2) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{10,2,8,1,2,4,1,20,4,5} ; var n : int ; n := a->size() ; execute getNumbers(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int N=s.nextInt(); int K=s.nextInt(); int sum=0 ; int xs[]=new int[N]; for(int i=0 ; iMath.abs(K-xs[k])){ sum+=2*Math.abs(K-xs[k]); } else { sum+=2*xs[k]; } } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := s.getCurrent()->toInteger() ; var K : int ; K := s.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var xs : Sequence(int) ; xs := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( xs[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < N do ( ( if (if xs[k+1] < 0 then -(xs[k+1]) else xs[k+1] endif > if K - xs[k+1] < 0 then -(K - xs[k+1]) else K - xs[k+1] endif) then ( sum := sum+(2 * if K - xs[k+1] < 0 then -(K - xs[k+1]) else K - xs[k+1] endif) ) else ( sum := sum+(2 * xs[k+1]) ) ) ; k := k + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ int n=Integer.parseInt(br.readLine()); int k=Integer.parseInt(br.readLine()); String[] tmp=br.readLine().split(" "); int distance=0 ; for(String t : tmp){ int x=Integer.parseInt(t); if(k-xtoInteger() ; var k : int ; k := (br.readLine())->toInteger() ; var tmp : Sequence(String) ; tmp := br.readLine()->split(" ") ; var distance : int ; distance := 0 ; for (t : tmp) do ( ( var x : int ; x := (t)->toInteger() ; if (k - x < x) then ( distance := distance+((k - x) * 2) ) else ( distance := distance+(x * 2) ) ) ) ; OclFile["System.out"].println(distance) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ try { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); int n=Integer.parseInt(br.readLine()); int k=Integer.parseInt(br.readLine()); int sum=0 ; String str[]=br.readLine().split(" "); for(int i=0 ; itoInteger() ; var k : int ; k := (br.readLine())->toInteger() ; var sum : int ; sum := 0 ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := (str[i+1])->toInteger() ; var tmp : int ; tmp := if x - k < 0 then -(x - k) else x - k endif ; if (x < tmp) then ( sum := sum+(x * 2) ) else ( sum := sum+(tmp * 2) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.*; class Main { public static void main(String[] $){ Scanner s=new Scanner(System.in); int n=s.nextInt(),k=s.nextInt(); System.out.println(IntStream.range(0,n).map(o->s.nextInt()).map(o->Math.min(o,k-o)).sum()*2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var k : int ; k := s.getCurrent()->toInteger() ; OclFile["System.out"].println(Integer.subrange(0, n-1)->collect( _x1 | (lambda o : OclAny in s.getCurrent()->toInteger())->apply(_x1) )->collect( _x1 | (lambda o : OclAny in Set{o, k - o}->min())->apply(_x1) )->sum() * 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Main m=new Main(); m.answer(); } private Scanner scan=new Scanner(System.in); private final int N ; private final int K ; private final int[] x ; public Main(){ N=Integer.parseInt(scan.next()); K=Integer.parseInt(scan.next()); x=new int[N]; for(int i=0 ; i2*Integer.min(x,K-x)).sum(); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.answer() ); attribute scan : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute N : int; attribute K : int; attribute x : Sequence(int); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( N := (scan.getCurrent())->toInteger() ; K := (scan.getCurrent())->toInteger() ; x := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( x[i+1] := (scan.getCurrent())->toInteger() ) ; i := i + 1 ) ; skip ; ); operation answer() : void pre: true post: true activity: ( var ans : int ; ans := stream(x)->collect( _x1 | (lambda x : OclAny in 2 * Set{x, K - x}->min())->apply(_x1) )->sum() ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.text.DecimalFormat ; import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import java.util.stream.Stream ; public class Main { static FastScanner fs=new FastScanner(); static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next(){ while(! st.hasMoreElements())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int Int(){ return Integer.parseInt(next()); } long Long(){ return Long.parseLong(next()); } String Str(){ return next(); } } public static void main(String[] args)throws java.lang.Exception { PrintWriter out=new PrintWriter(System.out); int T=1 ; for(int t=0 ; ttoInteger() ); operation Long() : long pre: true post: true activity: ( return (next())->toLong() ); operation Str() : String pre: true post: true activity: ( return next() ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var T : int ; T := 1 ; var t : int ; t := 0 ; while t < T do ( ( var a : String ; a := Str() ; var b : String ; b := Str() ; var sol : Solution ; sol := Solution.newSolution() ; sol.solution(out, a, b) ) ; t := t + 1 ) ; skip ); static operation Int() : int pre: true post: true activity: ( return fs.Int() ); static operation Long() : long pre: true post: true activity: ( return fs.Long() ); static operation Str() : String pre: true post: true activity: ( return fs.Str() ); } class Solution { operation solution( out : OclFile, s : String, t : String) : void pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = '1') then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; if (cnt mod 2 = 1) then ( cnt := cnt + 1 ) else skip ; var i : int ; i := 0 ; while i < t->size() do ( ( if (t->at(i+1) = '1') then cnt := cnt - 1 ; else skip ) ; i := i + 1 ) ; if (cnt < 0) then ( skip ) else ( skip ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class codeforces { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int z=0 ; zc)ans=ans+c ; else ans=ans+arr1[i]; } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class codeforces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; var z : int ; z := 0 ; while z < t do ( ( var n : int ; n := s.getCurrent()->toInteger() ; var c : int ; c := s.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var arr1 : Sequence(int) ; arr1 := Integer.subrange(1,101)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ; arr1[arr[i+1]+1] := arr1[arr[i+1]+1] + 1 ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i < 101 do ( ( if (arr1[i+1] > c) then ans := ans + c ; else ans := ans + arr1[i+1] ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; z := z + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class P297A { private static void solve(){ char[] c1=next().toCharArray(); char[] c2=next().toCharArray(); int cnt1=0 ; for(int i=0 ; icnt1)||(cnt1 % 2!=0 && cnt2>cnt1+1)){ System.out.println("NO"); } else { System.out.println("YES"); } } private static void run(){ br=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); solve(); out.close(); } private static StringTokenizer st ; private static BufferedReader br ; private static PrintWriter out ; private static String next(){ while(st==null || ! st.hasMoreElements()){ String s ; try { s=br.readLine(); } catch(IOException e){ return null ; } st=new StringTokenizer(s); } return st.nextToken(); } private static int nextInt(){ return Integer.parseInt(next()); } private static long nextLong(){ return Long.parseLong(next()); } public static void main(String[] args){ run(); } } ------------------------------------------------------------ OCL File: --------- class P297A { static operation solve() : void pre: true post: true activity: ( var c1 : Sequence(String) ; c1 := next()->characters() ; var c2 : Sequence(String) ; c2 := next()->characters() ; var cnt1 : int ; cnt1 := 0 ; var i : int ; i := 0 ; while i < c1->size() do ( ( if (c1[i+1] = '1') then cnt1 := cnt1 + 1 ; else skip ) ; i := i + 1 ) ; var cnt2 : int ; cnt2 := 0 ; var i : int ; i := 0 ; while i < c2->size() do ( ( if (c2[i+1] = '1') then cnt2 := cnt2 + 1 ; else skip ) ; i := i + 1 ) ; if ((cnt1 mod 2 = 0 & cnt2 > cnt1) or (cnt1 mod 2 /= 0 & cnt2 > cnt1 + 1)) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ) ; ); static operation run() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; out.close() ); static attribute st : OclIterator; static attribute br : OclFile; static attribute out : OclFile; static operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( var s : String ; try ( s := br.readLine() ) catch (e : IOException) do ( return null ) st := OclIterator.newOclIterator_String(s) ) ; return st.next() ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(); long[] a=new long[n]; IntStream.range(0,n).forEach(i->a[i]=scanner.nextLong()); int[] sum1=new int[n],sum2=new int[n]; Arrays.fill(sum1,1); Arrays.fill(sum2,-1); IntStream.range(0,n/2).forEach(i->{ sum1[2*i+1]=-1 ; sum2[2*i+1]=1 ; } ); System.out.println(Math.min(getResult(a,sum1),getResult(a,sum2))); } } private static long getResult(final long[] a,final int[] sum){ int n=a.length ; long now=0,result=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := scanner.getCurrent()->toLong()) ; var sum1 : Sequence(int) ; sum1 := Integer.subrange(1,n)->collect(0) ; var sum2 : Sequence(int) ; sum2 := Integer.subrange(1,n)->collect(0) ; sum1 := sum1->collect(1) ; sum2 := sum2->collect(-1) ; for i : Integer.subrange(0, n / 2-1) do ( skip) ; OclFile["System.out"].println(Set{getResult(a, sum1), getResult(a, sum2)}->min()) ; )) ); static operation getResult( a : Sequence(long), sum : Sequence(int)) : long pre: true post: true activity: ( var n : int ; n := a->size() ; var now : long ; now := 0 ; var result : long ; result := 0 ; var i : int ; i := 0 ; while i < n do ( ( now := now+(a[i+1]) ; if (sum[i+1] * now <= 0) then ( result := result+(if sum[i+1] - now < 0 then -(sum[i+1] - now) else sum[i+1] - now endif) ; now := sum[i+1] ) else skip ) ; i := i + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Odd { public static int oddSum(int n){ return(n*n); } public static void main(String[] args){ int n=20 ; System.out.println(" Sum of first "+n+" Odd Numbers is: "+oddSum(n)); } } ------------------------------------------------------------ OCL File: --------- class Odd { static operation oddSum( n : int) : int pre: true post: true activity: ( return (n * n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 20 ; OclFile["System.out"].println(" Sum of first " + n + " Odd Numbers is: " + oddSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int n=4 ; static int count(int arr[][]){ int diag1=0,diag2=0 ; int row=0,col=0,count=0 ; for(int i=0,j=n-1 ; i0){ n &=(n-1); count++; } return count ; } static int pairs(int arr[],int n,int k){ int count=0 ; int[] f=new int[MAX+1]; for(int i=0 ; i 0) do ( n := MathLib.bitwiseAnd(n, (n - 1)) ; count := count + 1 ) ; return count ); static operation pairs( arr : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var f : Sequence(int) ; f := Integer.subrange(1,MAX + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( f[countSetBits(arr[i+1])+1] := f[countSetBits(arr[i+1])+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= MAX do ( ( var j : int ; j := i ; while j <= MAX 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 ) ; j := j + 1 ) ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5} ; var n : int ; n := arr->size() ; var k : int ; k := 4 ; OclFile["System.out"].println(pairs(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); char[] s=in.next().toCharArray(); Arrays.sort(s); for(char c : s)pw.print(c); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var s : Sequence(String) ; s := in.getCurrent()->characters() ; s := s->sort() ; for (c : s) do ( skip ; ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args)throws IOException,InterruptedException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); Scanner sc=new Scanner(System.in); int n=Integer.parseInt(reader.readLine()); String s=reader.readLine(); char[] array=s.toCharArray(); Arrays.sort(array); System.out.println(new String(array)); sc.close(); writer.flush(); writer.close(); reader.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var writer : OclFile ; writer := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (reader.readLine())->toInteger() ; var s : String ; s := reader.readLine() ; var array : Sequence(String) ; array := s->characters() ; array := array->sort() ; OclFile["System.out"].println(StringLib.newString(array)) ; skip ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class palindrome { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); char[] c=s.toCharArray(); Arrays.sort(c); System.out.println(toString(c)); } public static String toString(char[] a){ String string=new String(a); return string ; } } ------------------------------------------------------------ OCL File: --------- class palindrome { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var c : Sequence(String) ; c := s->characters() ; c := c->sort() ; OclFile["System.out"].println(toString(c)) ; ); static operation toString( a : Sequence(String)) : String pre: true post: true activity: ( var string : String ; string := StringLib.newString(a) ; return string ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.StringTokenizer ; public class CF1064_D2_C { public static void main(String[] args){ FastScanner scanner=new FastScanner(); int n=scanner.nextInt(); char[] arr=scanner.next().toCharArray(); Arrays.sort(arr); System.out.println(String.valueOf(arr)); } static class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } int[] nextArray(int n){ int[] arr=new int[n]; for(int i=0 ; icharacters() ; arr := arr->sort() ; OclFile["System.out"].println((arr)->sum() ) ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextArray( n : int) : Sequence(int) pre: true post: true activity: ( var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := nextInt() ) ; i := i + 1 ) ; return arr ); operation nextArray( n : int, object : boolean) : Sequence(int) pre: true post: true activity: ( var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := nextInt() ) ; i := i + 1 ) ; return arr ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class AvgHeigth { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); Listyo=new ArrayList<>(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var yo : Sequence(int) ; yo := Sequence{} ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; if ((arr[i+1] & 1) = 1) then ( yo := yo->including(arr[i+1]) ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if ((arr[i+1] & 1) = 0) then ( yo := yo->including(arr[i+1]) ) else skip ) ; i := i + 1 ) ; for (x : yo) do ( ( OclFile["System.out"].print(x + " ") ) ) ; OclFile["System.out"].println() ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner cin=new Scanner(System.in); int t=cin.nextInt(),k,i ; for(k=0 ; ktoInteger() ; var k : int ; var i : int ; k := 0 ; while k < t do ( ( var n : int ; n := cin.getCurrent()->toInteger() ; var a : Sequence(void) ; a := Integer.subrange(1,n)->collect(0) ; var j1 : int ; j1 := 0 ; var j2 : int ; j2 := n - 1 ; i := 0 ; while i < n do ( ( var x : int ; x := cin.getCurrent()->toInteger() ; if (x mod 2 = 0) then a[j1+1] := x ; j1 := j1 + 1 ; else a[j2+1] := x ; j2 := j2 - 1 ; ) ; i := i + 1 ) ; i := 0 ; while i < n do ( OclFile["System.out"].print(a[i+1] + " ") ; ; i := i + 1 ) ) ; k := k + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Tttest { public static int fun(int[] arr,int b){ HashMaphm=new LinkedHashMap<>(); for(int i=0 ; i0){ int a=sc.nextInt(); int b=sc.nextInt(); int[] arr=new int[a]; for(int i=0 ; isize() do ( ( if (hm->keys()->includes(arr[i+1])) then ( var of : int ; of := hm->at(arr[i+1]) ; of := of + 1 ; hm := hm->union(Map{arr[i+1] |-> of}) ; continue ) else skip ; hm := hm->union(Map{arr[i+1] |-> 1}) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; for (i : hm->keys()) do ( ( ans := ans+(Set{b, hm->at(i)}->min()) ) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,a)->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(fun(arr, b)) ; t := t - 1 ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long a[]=new long[(int)n]; for(int i=0 ; i0){ if(sum+a[i]>=0){ ans1+=sum+a[i]+1 ; sum=-1 ; } else { sum=sum+a[i]; } } else { if(sum+a[i]<=0){ ans1+=Math.abs(a[i]+sum)+1 ; sum=1 ; } else { sum=sum+a[i]; } } } long ans2=Math.abs(a[0])+1 ; if(a[0]>=0){ sum=-1 ; } else if(a[0]<0){ sum=1 ; } for(int i=1 ; i0){ if(sum+a[i]>=0){ ans2+=sum+a[i]+1 ; sum=-1 ; } else { sum=sum+a[i]; } } else { if(sum+a[i]<=0){ ans2+=Math.abs(a[i]+sum)+1 ; sum=1 ; } else { sum=sum+a[i]; } } } System.out.println(Math.min(ans1,ans2)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var a : Sequence(long) ; a := Integer.subrange(1,n->oclAsType(int))->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var sum : long ; sum := a[0+1] ; var ans1 : long ; ans1 := 0 ; if (sum = 0) then ( sum := 1 ; ans1 := ans1 + 1 ) else skip ; var i : int ; i := 1 ; while i < n do ( ( if (sum > 0) then ( if (sum + a[i+1] >= 0) then ( ans1 := ans1+(sum + a[i+1] + 1) ; sum := -1 ) else ( sum := sum + a[i+1] ) ) else ( if (sum + a[i+1] <= 0) then ( ans1 := ans1+(if a[i+1] + sum < 0 then -(a[i+1] + sum) else a[i+1] + sum endif + 1) ; sum := 1 ) else ( sum := sum + a[i+1] ) ) ) ; i := i + 1 ) ; var ans2 : long ; ans2 := if a[0+1] < 0 then -(a[0+1]) else a[0+1] endif + 1 ; if (a[0+1] >= 0) then ( sum := -1 ) else if (a[0+1] < 0) then ( sum := 1 ) else skip ; ; var i : int ; i := 1 ; while i < n do ( ( if (sum > 0) then ( if (sum + a[i+1] >= 0) then ( ans2 := ans2+(sum + a[i+1] + 1) ; sum := -1 ) else ( sum := sum + a[i+1] ) ) else ( if (sum + a[i+1] <= 0) then ( ans2 := ans2+(if a[i+1] + sum < 0 then -(a[i+1] + sum) else a[i+1] + sum endif + 1) ; sum := 1 ) else ( sum := sum + a[i+1] ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{ans1, ans2}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class A1509 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ int n=scanner.nextInt(); ListoddList=new ArrayList(); ListevenList=new ArrayList(); while(n-->0){ int x=scanner.nextInt(); if(x % 2==0){ evenList.add(x); } else { oddList.add(x); } } for(int i : oddList)System.out.print(i+" "); for(int i : evenList)System.out.print(i+" "); System.out.println(); } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class A1509 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var oddList : Sequence(int) ; oddList := Sequence{} ; var evenList : Sequence(int) ; evenList := Sequence{} ; while (n > 0) do ( n := n - 1 ; skip ; ( var x : int ; x := scanner.getCurrent()->toInteger() ; if (x mod 2 = 0) then ( evenList := evenList->including(x) ) else ( oddList := oddList->including(x) ) ) ; ) ; for (i : oddList) do ( OclFile["System.out"].print(i + " ") ; ) ; for (i : evenList) do ( OclFile["System.out"].print(i + " ") ; ) ; OclFile["System.out"].println() ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test276 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var e : int ; e := 0 ; var o : int ; o := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ; if (a[i+1] mod 2 = 0) then ( b[e+1] := a[i+1] ; e := e + 1 ) else ( c[o+1] := a[i+1] ; o := o + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < e do ( ( OclFile["System.out"].print(b[i+1] + " ") ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < o do ( ( OclFile["System.out"].print(c[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class JavaApplication68 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int num1=sc.nextInt(); int num2=sc.nextInt(); int r1=0 ; int r2=0 ; int r3=0 ; for(int i=1 ; i<7 ; i++){ if(Math.abs(num1-i)>Math.abs(num2-i)){ r1++; } else if(Math.abs(num1-i)toInteger() ; var num2 : int ; num2 := sc.getCurrent()->toInteger() ; var r1 : int ; r1 := 0 ; var r2 : int ; r2 := 0 ; var r3 : int ; r3 := 0 ; var i : int ; i := 1 ; while i < 7 do ( ( if (if num1 - i < 0 then -(num1 - i) else num1 - i endif > if num2 - i < 0 then -(num2 - i) else num2 - i endif) then ( r1 := r1 + 1 ) else if (if num1 - i < 0 then -(num1 - i) else num1 - i endif < if num2 - i < 0 then -(num2 - i) else num2 - i endif) then ( r3 := r3 + 1 ) else ( r2 := r2 + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(r3 + " " + r2 + " " + r1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int win=0 ; int draw=0 ; int lose=0 ; for(int j=1 ; j<=6 ; j++){ if(Math.abs(j-a)==Math.abs(j-b))draw++; else { if(Math.abs(j-a)toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var win : int ; win := 0 ; var draw : int ; draw := 0 ; var lose : int ; lose := 0 ; var j : int ; j := 1 ; while j <= 6 do ( ( if (if j - a < 0 then -(j - a) else j - a endif = if j - b < 0 then -(j - b) else j - b endif) then draw := draw + 1 ; else ( if (if j - a < 0 then -(j - a) else j - a endif < if j - b < 0 then -(j - b) else j - b endif) then win := win + 1 ; else lose := lose + 1 ; ) ) ; j := j + 1 ) ; OclFile["System.out"].println(win) ; OclFile["System.out"].println(draw) ; OclFile["System.out"].println(lose) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String[] args){ new A().solve(); } Scanner in ; private void solve(){ in=new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); int aWins=0 ; int bWins=0 ; int draw=0 ; for(int i=1 ; i<7 ; i++){ int fromA=Math.abs(i-a); int fromB=Math.abs(i-b); if(fromAfromB){ ++bWins ; } else { ++draw ; } } System.out.println(aWins+" "+draw+" "+bWins); } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A.newA().solve() ); attribute in : OclFile; operation solve() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var aWins : int ; aWins := 0 ; var bWins : int ; bWins := 0 ; var draw : int ; draw := 0 ; var i : int ; i := 1 ; while i < 7 do ( ( var fromA : int ; fromA := if i - a < 0 then -(i - a) else i - a endif ; var fromB : int ; fromB := if i - b < 0 then -(i - b) else i - b endif ; if (fromA < fromB) then ( aWins := aWins + 1 ) else if (fromA > fromB) then ( bWins := bWins + 1 ) else ( draw := draw + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(aWins + " " + draw + " " + bWins) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _378A_PlayingWithDice { public static void main(String[] args){ Scanner input=new Scanner(System.in); int a=input.nextInt(); int b=input.nextInt(); int first=0 ; int second=0 ; for(int i=1 ; i<=6 ; i++){ int aDistance=Math.abs(a-i); int bDistance=Math.abs(b-i); if(aDistancebDistance){ second++; } } int draw=6-first-second ; System.out.println(String.format("%d %d %d",first,draw,second)); } } ------------------------------------------------------------ OCL File: --------- class _378A_PlayingWithDice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := input.getCurrent()->toInteger() ; var b : int ; b := input.getCurrent()->toInteger() ; var first : int ; first := 0 ; var second : int ; second := 0 ; var i : int ; i := 1 ; while i <= 6 do ( ( var aDistance : int ; aDistance := if a - i < 0 then -(a - i) else a - i endif ; var bDistance : int ; bDistance := if b - i < 0 then -(b - i) else b - i endif ; if (aDistance < bDistance) then ( first := first + 1 ) else if (aDistance > bDistance) then ( second := second + 1 ) else skip ; ) ; i := i + 1 ) ; var draw : int ; draw := 6 - first - second ; OclFile["System.out"].println(StringLib.format("%d %d %d",Sequence{first,draw,second})) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; class GFG { public static int countOddSquares(int n,int m){ return(int)Math.pow((double)m,0.5)-(int)Math.pow((double)n-1,0.5); } public static void main(String[] args){ int n=5,m=100 ; System.out.print("Count is "+countOddSquares(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countOddSquares( n : int, m : int) : int pre: true post: true activity: ( return m->oclAsType(double)->pow(0.5)->oclAsType(int) - n->oclAsType(double) - 1->pow(0.5)->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var m : int ; m := 100 ; OclFile["System.out"].print("Count is " + countOddSquares(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String year=sc.nextLine(); for(int i=1000 ; i<=9000 ; i++){ year=String.valueOf(Integer.parseInt(year)+1); if(year.charAt(0)!=year.charAt(1)&& year.charAt(0)!=year.charAt(2)&& year.charAt(0)!=year.charAt(3)&& year.charAt(1)!=year.charAt(2)&& year.charAt(1)!=year.charAt(3)&& year.charAt(2)!=year.charAt(3)){ break ; } } System.out.println((year)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var year : String ; year := sc.nextLine() ; var i : int ; i := 1000 ; while i <= 9000 do ( ( year := (((year)->toInteger() + 1) + "") ; if (year->at(0+1) /= year->at(1+1) & year->at(0+1) /= year->at(2+1) & year->at(0+1) /= year->at(3+1) & year->at(1+1) /= year->at(2+1) & year->at(1+1) /= year->at(3+1) & year->at(2+1) /= year->at(3+1)) then ( break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println((year)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class BeautifulYear { public static void main(String[] args)throws IOException { FastIO io=new FastIO(); int y=io.nextInt()+1 ; while(! isUnique(y)){ y++; } io.println(y); io.close(); } private static boolean isUnique(int a){ int[] count=new int[10]; while(a>0){ count[a % 10]++; a/=10 ; } for(int freq : count){ if(freq>1){ return false ; } } return true ; } static class FastIO extends PrintWriter { private BufferedReader br ; private StringTokenizer st ; public FastIO(){ this(System.in,System.out); } public FastIO(InputStream in,OutputStream out){ super(out); br=new BufferedReader(new InputStreamReader(in)); } public FastIO(String problemName)throws IOException { super(new FileWriter(problemName+".out")); br=new BufferedReader(new FileReader(problemName+".in")); } public String next(){ try { while(st==null || ! st.hasMoreTokens()){ st=new StringTokenizer(br.readLine()); } return st.nextToken(); } catch(Exception e){ } return null ; } public String nextLine(){ try { return br.readLine(); } catch(Exception e){ } return null ; } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public float nextFloat(){ return Float.parseFloat(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public boolean nextBoolean(){ return Boolean.parseBoolean(next()); } } } ------------------------------------------------------------ OCL File: --------- class BeautifulYear { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : FastIO ; io := FastIO.newFastIO() ; var y : int ; y := io.nextInt() + 1 ; while (not(isUnique(y))) do ( y := y + 1 ) ; io.println(y) ; io.close() ; ); static operation isUnique( a : int) : boolean pre: true post: true activity: ( var count : Sequence(int) ; count := Integer.subrange(1,10)->collect(0) ; while (a > 0) do ( count[a mod 10+1] := count[a mod 10+1] + 1 ; a := a/(10) ) ; for (freq : count) do ( ( if (freq > 1) then ( return false ) else skip ) ) ; return true ); static class FastIO extends OclFile { attribute br : OclFile; attribute st : OclIterator; static operation newFastIO() : FastIO pre: true post: true activity: ( var self : FastIO ; self := createFastIO(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute this(OclFile["System.in"], OclFile["System.out"]) ); static operation newFastIO( in : OclFile, out : OclFile) : FastIO pre: true post: true activity: ( var self : FastIO ; self := createFastIO(); self.initialise(in, out); return self ); operation initialise( in : OclFile, out : OclFile) : void pre: true post: true activity: ( execute super(out) ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); static operation newFastIO( problemName : String) : FastIO pre: true post: true activity: ( var self : FastIO ; self := createFastIO(); self.initialise(problemName); return self ); operation initialise( problemName : String) : void pre: true post: true activity: ( execute super(OclFile.newOclFile_Write(problemName + ".out")) ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(problemName + ".in")) ); operation next() : String pre: true post: true activity: ( try ( while (st = null or not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ) catch (e : ProgramException) do skip return null ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : ProgramException) do skip return null ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextBoolean() : boolean pre: true post: true activity: ( return parseBoolean(next()) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class nurda { public static void main(String[] args){ Scanner real=new Scanner(System.in); int n=real.nextInt(); for(; ; ){ n++; int b=n/1000 ; int c=(n/100)% 10 ; int d=(n/10)% 10 ; int e=n % 10 ; if(b!=c && b!=d && b!=e && c!=d && c!=e && d!=e){ break ; } } System.out.println(n); } } ------------------------------------------------------------ OCL File: --------- class nurda { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var real : OclFile ; real := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := real.getCurrent()->toInteger() ; while true do ( ( n := n + 1 ; var b : int ; b := n / 1000 ; var c : int ; c := (n / 100) mod 10 ; var d : int ; d := (n / 10) mod 10 ; var e : int ; e := n mod 10 ; if (b /= c & b /= d & b /= e & c /= d & c /= e & d /= e) then ( break ) else skip ; ) ) ; OclFile["System.out"].println(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; class Main { public static void main(String[] argv){ Scanner sc=new Scanner(System.in); int tests=sc.nextInt(); for(int t=1 ; t<=tests ; t++){ int p=sc.nextInt(),q=sc.nextInt(); int[] cells=new int[q]; for(int i=0 ; itoInteger() ; var t : int ; t := 1 ; while t <= tests do ( ( var p : int ; p := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var cells : Sequence(int) ; cells := Integer.subrange(1,q)->collect(0) ; var i : int ; i := 0 ; while i < q do ( ( cells[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var nums : Sequence(int) ; nums := Integer.subrange(1,q + 1)->collect(0) ; nums[0+1] := cells[0+1] - 1 ; var i : int ; i := 1 ; while i < q do ( ( nums[i+1] := cells[i+1] - cells[i - 1+1] - 1 ) ; i := i + 1 ) ; nums[q+1] := p - cells[q - 1+1] ; var fromto : Sequence(Sequence(int)) ; fromto := Integer.subrange(1,q + 1)->collect(Integer.subrange(1,q + 1)->collect(0)) ; var start : int ; start := 0 ; while start <= q do ( skip ; start := start + 1 ) ; var d : int ; d := 1 ; while d <= q do ( ( var start : int ; start := 0 ; while start <= q - d do ( ( var min : int ; min := p * p ; var all : int ; all := 0 ; var i : int ; i := 0 ; while i <= d do ( ( all := all+(nums[start + i+1]) ) ; i := i + 1 ) ; all := all+(d - 1) ; var i : int ; i := 0 ; while i < d do ( ( var sum : int ; sum := all + fromto[start+1][start + i+1] + fromto[start + i + 1+1][start + d+1] ; if (sum < min) then ( min := sum ) else skip ) ; i := i + 1 ) ; fromto[start+1][start + d+1] := min ; ) ; start := start + 1 ) ) ; d := d + 1 ) ; var i : int ; i := 0 ; while i <= q do ( ( var j : int ; j := i ; while j <= q do ( skip ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.err"].println(t) ; OclFile["System.out"].printf("Case #%d: %d\n", t, fromto[0+1][q+1]) ; ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class AAA { static int get_last_two_digit(long N){ if(N<=10){ long ans=0,fac=1 ; for(int i=1 ; i<=N ; i++){ fac=fac*i ; ans+=fac ; } return(int)ans % 100 ; } else return 13 ; } public static void main(String[] args){ long N=1 ; for(N=1 ; N<=10 ; N++)System.out.println("For N="+N+" : "+get_last_two_digit(N)); } } ------------------------------------------------------------ OCL File: --------- class AAA { static operation get_last_two_digit( N : long) : int pre: true post: true activity: ( if (N <= 10) then ( var ans : long ; ans := 0 ; var fac : long ; fac := 1 ; var i : int ; i := 1 ; while i <= N do ( ( fac := fac * i ; ans := ans+(fac) ) ; i := i + 1 ) ; return ans->oclAsType(int) mod 100 ) else return 13 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : long ; N := 1 ; N := 1 ; while N <= 10 do ( OclFile["System.out"].println("For N=" + N + " : " + get_last_two_digit(N)) ; ; N := N + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class _823A { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0 ; i=c)sum+=c ; else sum+=o[j]; } if(sumtoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var c : int ; c := in.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var o : Sequence(int) ; o := Integer.subrange(1,101)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( a[j+1] := in.getCurrent()->toInteger() ; o[a[j+1]+1] := o[a[j+1]+1] + 1 ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < o->size() do ( ( if (o[j+1] >= c) then sum := sum+(c) ; else sum := sum+(o[j+1]) ; ) ; j := j + 1 ) ; if (sum < n) then OclFile["System.out"].println(sum) else OclFile["System.out"].println(n) ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); while(true){ a++; int n1=a/1000,n2=a/100 % 10,n3=a/10 % 10,n4=a % 10 ; if(n1!=n2 && n2!=n3 && n3!=n4 && n1!=n3 && n1!=n4 && n2!=n3 && n2!=n4){ break ; } } System.out.print(a); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; while (true) do ( a := a + 1 ; var n1 : int ; n1 := a / 1000 ; var n2 : int ; n2 := a / 100 mod 10 ; var n3 : int ; n3 := a / 10 mod 10 ; var n4 : int ; n4 := a mod 10 ; if (n1 /= n2 & n2 /= n3 & n3 /= n4 & n1 /= n3 & n1 /= n4 & n2 /= n3 & n2 /= n4) then ( break ) else skip ) ; OclFile["System.out"].print(a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Codesolver { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=0 ; boolean ans=false ; while(! ans){ boolean ar[]=new boolean[10]; int l=0,j=0 ; n++; m=n ; while(m!=0){ int r=m % 10 ; l++; if(! ar[r]){ ar[r]=true ; j++; } else { break ; } m=m/10 ; } if(l==j){ ans=true ; } } System.out.println(n); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Codesolver { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := 0 ; var ans : boolean ; ans := false ; while (not(ans)) do ( var ar : Sequence(boolean) ; ar := Integer.subrange(1,10)->collect(false) ; var l : int ; l := 0 ; var j : int ; j := 0 ; n := n + 1 ; m := n ; while (m /= 0) do ( var r : int ; r := m mod 10 ; l := l + 1 ; if (not(ar[r+1])) then ( ar[r+1] := true ; j := j + 1 ) else ( break ) ; m := m / 10 ) ; if (l = j) then ( ans := true ) else skip ; ) ; OclFile["System.out"].println(n) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static float noOfYears(int t1,int n1,int t2){ float years=((t2-1)*n1/(float)(t1-1)); return years ; } public static void main(String[] args){ int T1=3,N1=5,T2=6 ; System.out.println(noOfYears(T1,N1,T2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation noOfYears( t1 : int, n1 : int, t2 : int) : double pre: true post: true activity: ( var years : double ; years := ((t2 - 1) * n1 / (t1 - 1)->oclAsType(double)) ; return years ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var T1 : int ; T1 := 3 ; var N1 : int ; N1 := 5 ; var T2 : int ; T2 := 6 ; OclFile["System.out"].println(noOfYears(T1, N1, T2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static void printVector(Vectorv){ System.out.println(v.size()); for(int i=0 ; igroup1=new Vector(); Vectorgroup2=new Vector(); for(int i=n ; i>0 ; i--){ if(group1Sum-i>=0){ group1.add(i); group1Sum-=i ; } else { group2.add(i); } } printVector(group1); printVector(group2); } public static void main(String[] args){ int n=5 ; findTwoGroup(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printVector( v : Sequence(int)) : void pre: true post: true activity: ( OclFile["System.out"].println(v->size()) ; var i : int ; i := 0 ; while i < v->size() do ( OclFile["System.out"].print(v->at(i+1) + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ); static operation findTwoGroup( n : int) : void pre: true post: true activity: ( var sum : int ; sum := n * (n + 1) / 2 ; var group1Sum : int ; group1Sum := sum / 2 ; var group1 : Sequence(int) ; group1 := Sequence{} ; var group2 : Sequence(int) ; group2 := Sequence{} ; var i : int ; i := n ; while i > 0 do ( ( if (group1Sum - i >= 0) then ( group1 := group1->including(i) ; group1Sum := group1Sum-(i) ) else ( group2 := group2->including(i) ) ) ; i := i - 1 ) ; execute printVector(group1) ; execute printVector(group2) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; execute findTwoGroup(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class App { static class Sort implements Comparable{ double val ; int ind ; public int compareTo(Sort o){ if(this.val!=o.val){ return(this.valo.ind)?-1 : 1 ; } } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); double k=sc.nextInt()/100.0 ; Sort[] S=new Sort[n+1]; for(int i=1 ; i<=n ; i++){ int a=sc.nextInt(); int b=sc.nextInt(); S[i]=new Sort(); S[i] .val=Math.max(a*t1*(1-k)+b*t2,b*t1*(1-k)+a*t2); S[i] .ind=i ; } Arrays.sort(S,1,n+1); for(int i=n ; i>=1 ; i--){ System.out.print(S[i] .ind+" "); System.out.printf("%.2f\n",S[i] .val); } } } ------------------------------------------------------------ OCL File: --------- class App { static class Sort implements Comparable { attribute val : double; attribute ind : int; operation compareTo( o : Sort) : int pre: true post: true activity: ( if (self.val /= o.val) then ( return if (self.val < o.val) then -1 else 1 endif ) else ( return if (self.ind > o.ind) then -1 else 1 endif ) ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var t1 : int ; t1 := sc.getCurrent()->toInteger() ; var t2 : int ; t2 := sc.getCurrent()->toInteger() ; var k : double ; k := sc.getCurrent()->toInteger() / 100.0 ; var S : Sequence(Sort) ; S := Integer.subrange(1,n + 1)->collect(null) ; var i : int ; i := 1 ; while i <= n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; S[i+1] := Sort.newSort() ; S[i+1].val := Set{a * t1 * (1 - k) + b * t2, b * t1 * (1 - k) + a * t2}->max() ; S[i+1].ind := i ; ) ; i := i + 1 ) ; S := S.subrange(1,1)^(S.subrange(1+1,n + 1)->sort())^S.subrange(n + 1+1,S.size) ; var i : int ; i := n ; while i >= 1 do ( ( OclFile["System.out"].print(S[i+1].ind + " ") ; OclFile["System.out"].printf("%.2f\n", S[i+1].val) ) ; i := i - 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int Distinct_Prime_factors(Vectora){ HashSetm=new HashSet(); for(int i=0 ; i1){ m.add(a.get(i)); } } return m.size(); } public static void main(String args[]){ Vectora=new Vector(); a.add(1); a.add(2); a.add(3); a.add(4); a.add(5); System.out.println(Distinct_Prime_factors(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Distinct_Prime_factors( a : Sequence(int)) : int pre: true post: true activity: ( var m : Set(int) ; m := Set{} ; var i : int ; i := 0 ; while i < a->size() do ( ( var sq : int ; sq := (a->at(i+1))->sqrt()->oclAsType(int) ; var j : int ; j := 2 ; while j <= sq do ( ( if (a->at(i+1) mod j = 0) then ( m := m->including(j) ; while (a->at(i+1) mod j = 0) do ( a := a.setAt(i+1, a->at(i+1) / j) ) ) else skip ) ; j := j + 1 ) ; if (a->at(i+1) > 1) then ( m := m->including(a->at(i+1)) ) else skip ) ; i := i + 1 ) ; return m->size() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{} ; a := a->including(1) ; a := a->including(2) ; a := a->including(3) ; a := a->including(4) ; a := a->including(5) ; OclFile["System.out"].println(Distinct_Prime_factors(a)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class MergeSort { void merge(int arr[],int l,int m,int r){ int n1=m-l+1 ; int n2=r-m ; int L[]=new int[n1]; int R[]=new int[n2]; for(int i=0 ; icollect(0) ; var R : Sequence(int) ; R := Integer.subrange(1,n2)->collect(0) ; var i : int ; i := 0 ; while i < n1 do ( L[i+1] := arr[l + i+1] ; ; i := i + 1 ) ; var j : int ; j := 0 ; while j < n2 do ( R[j+1] := arr[m + 1 + j+1] ; ; j := j + 1 ) ; var i : int ; i := 0 ; var j : int ; j := 0 ; var k : int ; k := l ; while (i < n1 & j < n2) do ( if (L[i+1] <= R[j+1]) then ( arr[k+1] := L[i+1] ; i := i + 1 ) else ( arr[k+1] := R[j+1] ; j := j + 1 ) ; k := k + 1 ) ; while (i < n1) do ( arr[k+1] := L[i+1] ; i := i + 1 ; k := k + 1 ) ; while (j < n2) do ( arr[k+1] := R[j+1] ; j := j + 1 ; k := k + 1 ) ; ); operation sort( arr : Sequence(int), l : int, r : int) : void pre: true post: true activity: ( if (l < r) then ( var m : int ; m := (l + r) / 2 ; execute sort(arr, l, m) ; execute sort(arr, m + 1, r) ; execute merge(arr, l, m, r) ) else skip ); static operation printArray( arr : Sequence(int)) : void pre: true post: true activity: ( var n : int ; n := arr->size() ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{12,11,13,5,6,7} ; OclFile["System.out"].println("Given Array") ; execute printArray(arr) ; var ob : MergeSort ; ob := MergeSort.newMergeSort() ; ob.sort(arr, 0, arr->size() - 1) ; OclFile["System.out"].println("\nSorted array") ; execute printArray(arr) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class newyear { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer s=new StringTokenizer(in.readLine()); long n=Long.parseLong(s.nextToken()); long m=Long.parseLong(s.nextToken()); int ans=0 ; for(int i=1 ; i<=60 ; i++)for(int j=0 ; j<=i-2 ; j++){ long temp=(((1L<=n && temp<=m){ ans++; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class newyear { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var s : OclIterator ; s := OclIterator.newOclIterator_String(in.readLine()) ; var n : long ; n := (s.next())->toLong() ; var m : long ; m := (s.next())->toLong() ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= 60 do ( var j : int ; j := 0 ; while j <= i - 2 do ( ( var temp : long ; temp := ((((1L*(2->pow(i)))->oclAsType(long))) - 1 - (((1L*(2->pow(j)))->oclAsType(long)))) ; if (temp >= n & temp <= m) then ( ans := ans + 1 ) else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static void main(String args[]){ String binaryNumber="1001" ; System.out.println(Integer.parseInt(binaryNumber,2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var binaryNumber : String ; binaryNumber := "1001" ; OclFile["System.out"].println((binaryNumber)->toInteger()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); long a=scan.nextLong(); long b=scan.nextLong(); int counter=0 ; long n=0 ; for(int i=1 ; i<=60 ; i++){ for(int j=0 ; j<=i-2 ; j++){ n=(1L<=a && n<=b){ counter++; } } } System.out.println(counter); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : long ; a := scan.getCurrent()->toLong() ; var b : long ; b := scan.getCurrent()->toLong() ; var counter : int ; counter := 0 ; var n : long ; n := 0 ; var i : int ; i := 1 ; while i <= 60 do ( ( var j : int ; j := 0 ; while j <= i - 2 do ( ( n := ((1L*(2->pow(i)))->oclAsType(long)) - ((1L*(2->pow(j)))->oclAsType(long)) - 1 ; if (n >= a & n <= b) then ( counter := counter + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static int N=105 ; static int[] a=new int[N]; static int[] cnt=new int[N]; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ Arrays.fill(cnt,0); int n=sc.nextInt(),c=sc.nextInt(); for(int i=1 ; i<=n ; i++){ int x=sc.nextInt(); a[i]=x ; cnt[x]++; } int ans=0 ; for(int i=1 ; icollect(0); static attribute cnt : Sequence(int) := Integer.subrange(1,N)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := sc.getCurrent()->toInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( cnt := cnt->collect(0) ; var n : int ; n := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; a[i+1] := x ; cnt[x+1] := cnt[x+1] + 1 ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i < N do ( ( if (cnt[i+1] /= 0) then ( var s : int ; s := cnt[i+1] ; ans := ans+(Set{s, c}->min()) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Arc { static double arcLength(double diameter,double angle){ double pi=22.0/7.0 ; double arc ; if(angle>=360){ System.out.println("Angle cannot"+" be formed"); return 0 ; } else { arc=(pi*diameter)*(angle/360.0); return arc ; } } public static void main(String args[]){ double diameter=25.0 ; double angle=45.0 ; double arc_len=arcLength(diameter,angle); System.out.println(arc_len); } } ------------------------------------------------------------ OCL File: --------- class Arc { static operation arcLength( diameter : double, angle : double) : double pre: true post: true activity: ( var pi : double ; pi := 22.0 / 7.0 ; var arc : double ; if (angle >= 360) then ( OclFile["System.out"].println("Angle cannot" + " be formed") ; return 0 ) else ( arc := (pi * diameter) * (angle / 360.0) ; return arc ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var diameter : double ; diameter := 25.0 ; var angle : double ; angle := 45.0 ; var arc_len : double ; arc_len := arcLength(diameter, angle) ; OclFile["System.out"].println(arc_len) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int find_count(Vectorele){ int count=0 ; for(int i=0 ; ip=new Vector(); int c=0 ; for(int j=ele.size()-1 ; j>=(ele.size()-1-i)&& j>=0 ; j--){ p.add(ele.get(j)); } int j=ele.size()-1,k=0 ; while(j>=0){ if(ele.get(j)!=p.get(k)){ break ; } j--; k++; if(k==p.size()){ c++; k=0 ; } } count=Math.max(count,c); } return count ; } static void solve(int n){ int count=1 ; Vectorele=new Vector(); for(int i=0 ; isize() do ( ( var p : Sequence(int) ; p := Sequence{} ; var c : int ; c := 0 ; var j : int ; j := ele->size() - 1 ; while j >= (ele->size() - 1 - i) & j >= 0 do ( ( p := p->including(ele->at(j+1)) ) ; j := j - 1 ) ; var j : int ; j := ele->size() - 1 ; var k : int ; k := 0 ; while (j >= 0) do ( if (ele->at(j+1) /= p->at(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() ; ) ; i := i + 1 ) ; return count ); static operation solve( n : int) : void pre: true post: true activity: ( var count : int ; count := 1 ; var ele : Sequence(int) ; ele := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(count + ",") ; ele := ele->including(count) ; count := find_count(ele) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; execute solve(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int strScore(String str[],String s,int n){ int score=0,index=0 ; for(int i=0 ; isize() do ( score := score+(s->at(j+1) - ('a')->char2byte() + 1) ; ; j := j + 1 ) ; index := i + 1 ; break ) else skip ) ; i := i + 1 ) ; score := score * index ; return score ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : Sequence(String) ; str := Sequence{"sahil","shashanak","sanjit","abhinav","mohit"} ; var s : String ; s := "abhinav" ; var n : int ; n := str->size() ; var score : int ; score := strScore(str, s, n) ; OclFile["System.out"].println(score) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; public class Main { private void doit(){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int[] data=new int[n]; for(int i=0 ; i=n){ break ; } while(righttoInteger() ; var data : Sequence(int) ; data := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( data[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var count : long ; count := 0 ; var now : int ; now := 0 ; var left : int ; left := 0 ; var right : int ; right := 0 ; while (true) do ( if (left >= n) then ( break ) else skip ; while (right < n) do ( var res : int ; res := MathLib.bitwiseXor(now,data[right+1]) ; var res2 : int ; res2 := MathLib.bitwiseOr(now,data[right+1]) ; if (res /= res2) then ( break ) else skip ; now := MathLib.bitwiseXor(now,data[right+1]) ; right := right + 1 ; ) ; count := count+(right - left) ; now := MathLib.bitwiseXor(now,(MathLib.bitwiseAnd(now,data[left+1]))) ; left := left + 1 ; ) ; OclFile["System.out"].println(count) ; ) ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println("debug=" + (o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ int rep=1 ; if(args.length>0){ rep=Integer.parseInt(args[0]); } (new Main()).__solve(rep); } void __solve(int rep){ try(Scanner cin=new Scanner(System.in); ){ for(int i=0 ; isize() > 0) then ( rep := (args[0+1])->toInteger() ) else skip ; (Main.newMain()).__solve(rep) ); operation __solve( rep : int) : void pre: true post: true activity: ( try ( var cin : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var i : int ; i := 0 ; while i < rep do ( ( execute __solve(cin) ) ; i := i + 1 ) )) ); operation __solve( cin : OclFile) : void pre: true post: true activity: ( var N : int ; N := cin.getCurrent()->toInteger() ; var array : Sequence(int) ; array := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( array[i+1] := cin.getCurrent()->toInteger() ) ; i := i + 1 ) ; var L : int ; L := 0 ; var sum : int ; sum := 0 ; var ret : long ; ret := 0 ; var R : int ; R := 0 ; while R < N do ( ( while ((MathLib.bitwiseAnd(sum,array[R+1])) /= 0) do ( sum := MathLib.bitwiseXor(sum,array[L+1]) ) ; sum := MathLib.bitwiseXor(sum,array[R+1]) ; ret := ret+((R - L + 1)) ) ; R := R + 1 ) ; OclFile["System.out"].println(ret) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { static Scanner scanner=new Scanner(); public static void main(String[] $){ int n=scanner.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var xor : int ; xor := a[0+1] ; var sum : int ; sum := a[0+1] ; var l : int ; l := 0 ; var r : int ; r := 0 ; var ans : long ; ans := 0 ; while (l < n) do ( while (r + 1 < n & (MathLib.bitwiseXor(xor,a[r + 1+1])) = sum + a[r + 1+1]) do ( r := r + 1 ; xor := MathLib.bitwiseXor(xor,a[r+1]) ; sum := sum+(a[r+1]) ) ; ans := ans+(r - l + 1) ; xor := MathLib.bitwiseXor(xor,a[l+1]) ; sum := sum-(a[l+1]) ; l := l + 1 ; ) ; OclFile["System.out"].println(ans) ; ); static class Scanner { attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), (1*(2->pow(15)))->oclAsType(long)); attribute tokenizer : OclIterator; operation next() : String pre: true post: true activity: ( try ( while (tokenizer = null or not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (ignored : IOException) do skip return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int N=sc.nextInt(); int[] vals=new int[N]; for(int i=0 ; itoInteger() ; var vals : Sequence(int) ; vals := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < vals->size() do ( ( vals[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var xor : long ; xor := 0 ; var acum : long ; acum := 0 ; var lastOk : long ; lastOk := 0 ; var i : int ; i := 0 ; while i < N do ( ( xor := MathLib.bitwiseXor(xor,vals[i+1]) ; acum := acum+(vals[i+1]) ; while (xor /= acum) do ( xor := MathLib.bitwiseXor(xor,vals[lastOk->oclAsType(int)+1]) ; acum := acum-(vals[lastOk->oclAsType(int)+1]) ; lastOk := lastOk + 1 ) ; ans := ans+(i - lastOk + 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPossible(float x,float y,float z){ float a=x*x+y*y+z*z ; if(Math.ceil(a)==1 && Math.floor(a)==1)return true ; return false ; } public static void main(String args[]){ float l=0.70710678f,m=0.5f,n=0.5f ; if(isPossible(l,m,n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPossible( x : double, y : double, z : double) : boolean pre: true post: true activity: ( var a : double ; a := x * x + y * y + z * z ; if ((a)->ceil() = 1 & (a)->floor() = 1) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : double ; l := 0.70710678f ; var m : double ; m := 0.5f ; var n : double ; n := 0.5f ; if (isPossible(l, m, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; public final class p076 implements EulerSolution { public static void main(String[] args){ System.out.println(new p076().run()); } public String run(){ return partitions(100,1).subtract(BigInteger.ONE).toString(); } private static BigInteger partitions(int n,int k){ BigInteger[][] table=new BigInteger[n+1][n+1]; for(int i=0 ; i<=n ; i++){ for(int j=n ; j>=0 ; j--){ if(j==i)table[i][j]=BigInteger.ONE ; else if(j>i)table[i][j]=BigInteger.ZERO ; else if(j==0)table[i][j]=table[i][j+1]; else table[i][j]=table[i][j+1] .add(table[i-j][j]); } } return table[n][k]; } } ------------------------------------------------------------ OCL File: --------- class p076 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p076.newp076().run()) ); operation run() : String pre: true post: true activity: ( return partitions(100, 1).subtract(1)+"" ); static operation partitions( n : int, k : int) : long pre: true post: true activity: ( var table : Sequence(Sequence(long)) ; table := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(null)) ; var i : int ; i := 0 ; while i <= n do ( ( var j : int ; j := n ; while j >= 0 do ( ( if (j = i) then table[i+1][j+1] := 1 ; else if (j > i) then table[i+1][j+1] := 0 else if (j = 0) then table[i+1][j+1] := table[i+1][j + 1+1] else table[i+1][j+1] := table[i+1][j + 1+1]->excludes(table[i - j+1][j+1]) ; ; ; ) ; j := j - 1 ) ) ; i := i + 1 ) ; return table[n+1][k+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int largestOddDigit(int n){ int maxOdd=-1 ; while(n>0){ int digit=n % 10 ; if(digit % 2==1 && digit>maxOdd)maxOdd=digit ; n=n/10 ; } return maxOdd ; } static int getProduct(int n){ int maxOdd=largestOddDigit(n); if(maxOdd==-1)return-1 ; return(n*maxOdd); } public static void main(String[] args){ int n=12345 ; System.out.println(getProduct(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation largestOddDigit( n : int) : int pre: true post: true activity: ( var maxOdd : int ; maxOdd := -1 ; while (n > 0) do ( var digit : int ; digit := n mod 10 ; if (digit mod 2 = 1 & digit > maxOdd) then maxOdd := digit ; else skip ; n := n / 10 ) ; return maxOdd ); static operation getProduct( n : int) : int pre: true post: true activity: ( var maxOdd : int ; maxOdd := largestOddDigit(n) ; if (maxOdd = -1) then return -1 else skip ; return (n * maxOdd) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12345 ; OclFile["System.out"].println(getProduct(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String newString(String s,int k){ String X="" ; while(s.length()>0){ char temp=s.charAt(0); for(int i=1 ; isize() > 0) do ( var temp : String ; temp := s->at(0+1) ; var i : int ; i := 1 ; while i < k & i < s->size() do ( ( if (s->at(i+1) < temp) then ( temp := s->at(i+1) ) else skip ) ; i := i + 1 ) ; X := X + temp ; var i : int ; i := 0 ; while i < k do ( ( if (s->at(i+1) = temp) then ( s := s.subrange(0+1,i) + s.subrange(i + 1+1,i + 1) ; break ) else skip ) ; i := i + 1 ) ) ; return X ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "gaurang" ; var k : int ; k := 3 ; OclFile["System.out"].println(newString(s, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void subsetSums(int[] arr,int l,int r,int sum){ if(l>r){ System.out.print(sum+" "); return ; } subsetSums(arr,l+1,r,sum+arr[l]); subsetSums(arr,l+1,r,sum); } public static void main(String[] args){ int[] arr={ 5,4,3 }; int n=arr.length ; subsetSums(arr,0,n-1,0); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation subsetSums( arr : Sequence(int), l : int, r : int, sum : int) : void pre: true post: true activity: ( if (l > r) then ( OclFile["System.out"].print(sum + " ") ; return ) else skip ; execute subsetSums(arr, l + 1, r, sum + arr[l+1]) ; execute subsetSums(arr, l + 1, r, sum) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{5,4,3} ; var n : int ; n := arr->size() ; execute subsetSums(arr, 0, n - 1, 0) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; import java.util.StringTokenizer ; public class B305 { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); long p=Long.parseLong(st.nextToken()); long q=Long.parseLong(st.nextToken()); int n=Integer.parseInt(br.readLine()); Listquotients=new ArrayList<>(); st=new StringTokenizer(br.readLine()); for(int i=0 ; i1 && quotients.get(n-1)==1){ long update=quotients.get(n-2)+1 ; quotients.remove(n-1); quotients.remove(n-2); quotients.add(update); n--; } int start=0 ; while(q!=0){ long quotient=p/q ; long remainder=p % q ; if(start==n || quotients.get(start)!=quotient){ System.out.println("NO"); return ; } p=q ; q=remainder ; start++; } if(start==n){ System.out.println("YES"); } else { System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class B305 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var p : long ; p := (st.next())->toLong() ; var q : long ; q := (st.next())->toLong() ; var n : int ; n := (br.readLine())->toInteger() ; var quotients : Sequence(long) ; quotients := Sequence{} ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( quotients := quotients->including((st.next())->toLong()) ) ; i := i + 1 ) ; if (n > 1 & quotients->at(n - 1+1) = 1) then ( var update : long ; update := quotients->at(n - 2+1) + 1 ; quotients := quotients->excludingFirst(n - 1) ; quotients := quotients->excludingFirst(n - 2) ; quotients := quotients->including(update) ; n := n - 1 ; ) else skip ; var start : int ; start := 0 ; while (q /= 0) do ( var quotient : long ; quotient := p / q ; var remainder : long ; remainder := p mod q ; if (start = n or quotients->at(start+1) /= quotient) then ( OclFile["System.out"].println("NO") ; return ) else skip ; p := q ; q := remainder ; start := start + 1 ; ) ; if (start = n) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; import java.util.Scanner ; public class Main { static long a[]=new long[500]; public static int n ; public static BigDecimal f(int index){ if(index==n)return BigDecimal.valueOf(a[index]).divide(BigDecimal.ONE,45,BigDecimal.ROUND_HALF_DOWN); else return BigDecimal.valueOf(a[index]).add(BigDecimal.ONE.divide(f(index+1),45,BigDecimal.ROUND_HALF_DOWN)); } public static void main(String[] args){ Scanner cin=new Scanner(System.in); BigDecimal p,q ; p=cin.nextBigDecimal(); q=cin.nextBigDecimal(); n=cin.nextInt(); for(int i=1 ; i<=n ; i++){ a[i]=cin.nextLong(); } BigDecimal s1=p.divide(q,45,BigDecimal.ROUND_HALF_DOWN); BigDecimal s2=f(1); if(s1.equals(s2)){ System.out.println("YES"); } else { System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute a : long := Integer.subrange(1,500)->collect(0); static attribute n : int; static operation f( index : int) : double pre: true post: true activity: ( if (index = n) then return (a[index+1] + "")->toReal().divide(1.0, 45, ROUND_HALF_DOWN) else return (a[index+1] + "")->toReal()->excludes(1.0.divide(f(index + 1), 45, ROUND_HALF_DOWN)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var p : double ; var q : double ; p := cin.nextBigDecimal() ; q := cin.nextBigDecimal() ; n := cin.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := cin.getCurrent()->toLong() ) ; i := i + 1 ) ; var s1 : double ; s1 := p.divide(q, 45, ROUND_HALF_DOWN) ; var s2 : double ; s2 := f(1) ; if (s1 = s2) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Solution { public void dfs(int[][] M,int[] visited,int i){ for(int j=0 ; jsize() do ( ( if (M[i+1][j+1] = 1 & visited[j+1] = 0) then ( visited[j+1] := 1 ; execute dfs(M, visited, j) ) else skip ) ; j := j + 1 ) ); operation findCircleNum( M : Sequence(Sequence(int))) : int pre: true post: true activity: ( var visited : Sequence(int) ; visited := Integer.subrange(1,M->size())->collect(0) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < M->size() do ( ( if (visited[i+1] = 0) then ( execute dfs(M, visited, i) ; count := count + 1 ) else skip ) ; i := i + 1 ) ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long factorial(long n){ long res=1 ; for(int i=1 ; i<=n ; i++)res=res*i ; return res ; } static long count(String word){ int freq[]=new int[27]; for(int i=0 ; i<27 ; i++)freq[i]=0 ; long vowel=0,consonant=0 ; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < 27 do ( freq[i+1] := 0 ; ; i := i + 1 ) ; var vowel : long ; vowel := 0 ; var consonant : long ; consonant := 0 ; var i : int ; i := 0 ; while i < word->size() do ( ( freq[word->at(i+1) - ('A')->char2byte()+1] := freq[word->at(i+1) - ('A')->char2byte()+1] + 1 ; if (word->at(i+1) = 'A' or word->at(i+1) = 'E' or word->at(i+1) = 'I' or word->at(i+1) = 'O' or word->at(i+1) = 'U') then ( vowel := vowel + 1 ) else consonant := consonant + 1 ; ) ; i := i + 1 ) ; var vowelArrange : long ; vowelArrange := factorial(vowel) ; vowelArrange := vowelArrange/(factorial(freq[0+1])) ; vowelArrange := vowelArrange/(factorial(freq[4+1])) ; vowelArrange := vowelArrange/(factorial(freq[8+1])) ; vowelArrange := vowelArrange/(factorial(freq[14+1])) ; vowelArrange := vowelArrange/(factorial(freq[20+1])) ; var consonantArrange : long ; consonantArrange := factorial(consonant) ; var i : int ; i := 0 ; while i < 26 do ( ( if (i /= 0 & i /= 4 & i /= 8 & i /= 14 & i /= 20) then consonantArrange := consonantArrange/(factorial(freq[i+1])) ; else skip ) ; i := i + 1 ) ; var total : long ; total := vowelArrange * consonantArrange ; return total ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var word : String ; word := "COMPUTER" ; var ans : long ; ans := count(word) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p037 implements EulerSolution { public static void main(String[] args){ System.out.println(new p037().run()); } public String run(){ long sum=0 ; for(int count=0,n=10 ; count<11 ; n++){ if(isTruncatablePrime(n)){ sum+=n ; count++; } } return Long.toString(sum); } private static boolean isTruncatablePrime(int n){ for(long i=10 ; i<=n ; i*=10){ if(! Library.isPrime(n %(int)i))return false ; } for(; n!=0 ; n/=10){ if(! Library.isPrime(n))return false ; } return true ; } } ------------------------------------------------------------ OCL File: --------- class p037 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p037.newp037().run()) ); operation run() : String pre: true post: true activity: ( var sum : long ; sum := 0 ; var count : int ; count := 0 ; var n : int ; n := 10 ; while count < 11 do ( ( if (isTruncatablePrime(n)) then ( sum := sum+(n) ; count := count + 1 ) else skip ) ; n := n + 1 ) ; return ((sum) + "") ); static operation isTruncatablePrime( n : int) : boolean pre: true post: true activity: ( var i : long ; i := 10 ; while i <= n do ( ( if (not(Library.isPrime(n mod i->oclAsType(int)))) then return false else skip ) ; i := i*(10) ) ; while n /= 0 do ( ( if (not(Library.isPrime(n))) then return false else skip ) ; n := n/(10) ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MahmoudEhabMEX { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),x=in.nextInt(),i,j=0,a[]=new int[101],c=0 ; for(i=0 ; itoInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; var i : int ; var j : int ; j := 0 ; var a : Sequence(void) ; a := Integer.subrange(1,101)->collect(0) ; var c : int ; c := 0 ; i := 0 ; while i < n do ( a[in.getCurrent()->toInteger()+1] := a[in.getCurrent()->toInteger()+1] + 1 ; ; i := i + 1 ) ; skip ; i := 0 ; while i < x do ( c := c+(a[i+1]) ; ; i := i + 1 ) ; OclFile["System.out"].println(if a[x+1] = 1 then x - c + 1 else x - c endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MAX=1000000 ; static int MOD=10000007 ; static int[] result=new int[MAX+1]; static int[] fact=new int[MAX+1]; static void preCompute(){ fact[0]=1 ; result[0]=1 ; for(int i=1 ; i<=MAX ; i++){ fact[i]=((fact[i-1] % MOD)*i)% MOD ; result[i]=((result[i-1] % MOD)*(fact[i] % MOD))% MOD ; } } static void performQueries(int q[],int n){ preCompute(); for(int i=0 ; icollect(0); static attribute fact : Sequence(int) := Integer.subrange(1,MAX + 1)->collect(0); static operation preCompute() : void pre: true post: true activity: ( fact[0+1] := 1 ; result[0+1] := 1 ; var i : int ; i := 1 ; while i <= MAX 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 ) ; i := i + 1 ) ); static operation performQueries( q : Sequence(int), n : int) : void pre: true post: true activity: ( execute preCompute() ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].println(result[q[i+1]+1]) ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var q : Sequence(int) ; q := Sequence{4,5} ; var n : int ; n := q->size() ; execute performQueries(q, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int count(int S[],int m,int n){ if(n==0)return 1 ; if(n<0)return 0 ; if(m<=0 && n>=1)return 0 ; return count(S,m-1,n)+count(S,m,n-S[m-1]); } public static void main(String[] args){ int arr[]={ 1,2,3 }; int m=arr.length ; System.out.println(count(arr,m,4)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count( S : Sequence(int), m : int, n : int) : int 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]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3} ; var m : int ; m := arr->size() ; OclFile["System.out"].println(count(arr, m, 4)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int count(int S[],int m,int n){ if(n==0)return 1 ; if(n<0)return 0 ; if(m<=0 && n>=1)return 0 ; return count(S,m-1,n)+count(S,m,n-S[m-1]); } public static void main(String[] args){ int arr[]={ 1,2,3 }; int m=arr.length ; System.out.println(count(arr,m,4)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count( S : Sequence(int), m : int, n : int) : int 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]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3} ; var m : int ; m := arr->size() ; OclFile["System.out"].println(count(arr, m, 4)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class MainClass { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); String s=st.nextToken(); String[] t=new String[5]; st=new StringTokenizer(br.readLine()); for(int i=0 ; i<5 ; i++){ t[i]=st.nextToken(); } HashMapmap=new HashMap<>(); map.put(s.charAt(0),1); map.put(s.charAt(1),1); boolean flag=false ; for(int i=0 ; i<5 ; i++){ String r=t[i]; char rch=r.charAt(0); char gch=r.charAt(1); if(map.containsKey(rch)|| map.containsKey(gch)){ flag=true ; } } if(flag){ System.out.println("YES"); } else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class MainClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var s : String ; s := st.next() ; var t : Sequence(String) ; t := Integer.subrange(1,5)->collect(null) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < 5 do ( ( t[i+1] := st.next() ) ; i := i + 1 ) ; var map : Map(String,int) ; map := Map{} ; map := map->union(Map{s->at(0+1) |-> 1}) ; map := map->union(Map{s->at(1+1) |-> 1}) ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < 5 do ( ( var r : String ; r := t[i+1] ; var rch : String ; rch := r->at(0+1) ; var gch : String ; gch := r->at(1+1) ; if (map->keys()->includes(rch) or map->keys()->includes(gch)) then ( flag := true ) else skip ) ; i := i + 1 ) ; if (flag) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int N=1000005 ; static int primeFactors[]=new int[N]; static void findPrimeFactors(){ for(int i=2 ; icollect(0); static operation findPrimeFactors() : void pre: true post: true activity: ( var i : int ; i := 2 ; while i < N do ( if (primeFactors[i+1] = 0) then var j : int ; j := i ; while j < N do ( primeFactors[j+1] := primeFactors[j / i+1] + 1 ; ; j := j+(i) ) ; else skip ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < N do ( primeFactors[i+1] := primeFactors[i+1]+(primeFactors[i - 1+1]) ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute findPrimeFactors() ; var a : int ; a := 6 ; var b : int ; b := 3 ; OclFile["System.out"].println(primeFactors[a+1] - primeFactors[b+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class geneddyAndCardGame800 { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); String ontable=sc.next(); String[] hand=new String[5]; boolean canPlay=false ; for(int i=0 ; i<5 ; i++){ hand[i]=sc.next(); if(hand[i] .charAt(0)==ontable.charAt(0)|| hand[i] .charAt(1)==ontable.charAt(1)){ canPlay=true ; } } if(canPlay)System.out.println("YES"); else System.out.println("NO"); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class geneddyAndCardGame800 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ontable : String ; ontable := sc.getCurrent() ; var hand : Sequence(String) ; hand := Integer.subrange(1,5)->collect(null) ; var canPlay : boolean ; canPlay := false ; var i : int ; i := 0 ; while i < 5 do ( ( hand[i+1] := sc.getCurrent() ; if (hand[i+1]->at(0+1) = ontable->at(0+1) or hand[i+1]->at(1+1) = ontable->at(1+1)) then ( canPlay := true ) else skip ) ; i := i + 1 ) ; if (canPlay) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class GennadyCardGame { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String tCard=sc.next(); for(int i=0 ; i<5 ; i++){ String hCard=sc.next(); if(tCard.charAt(1)==hCard.charAt(1)|| tCard.charAt(0)==hCard.charAt(0)||(tCard.charAt(0)=='A' && hCard.charAt(0)=='K')||(tCard.charAt(0)=='A' && hCard.charAt(0)=='A')){ System.out.println("YES"); return ; } } System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class GennadyCardGame { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tCard : String ; tCard := sc.getCurrent() ; var i : int ; i := 0 ; while i < 5 do ( ( var hCard : String ; hCard := sc.getCurrent() ; if (tCard->at(1+1) = hCard->at(1+1) or tCard->at(0+1) = hCard->at(0+1) or (tCard->at(0+1) = 'A' & hCard->at(0+1) = 'K') or (tCard->at(0+1) = 'A' & hCard->at(0+1) = 'A')) then ( OclFile["System.out"].println("YES") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("NO") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.*; public class CP22 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String n1=sc.nextLine(),n2=sc.nextLine(); boolean f=false ; for(int i=0 ; i<2 ; i++){ String s=""+n1.charAt(i); if(n2.contains(s)){ f=true ; } } if(f){ System.out.println("YES"); } else { System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class CP22 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n1 : String ; n1 := sc.nextLine() ; var n2 : String ; n2 := sc.nextLine() ; var f : boolean ; f := false ; var i : int ; i := 0 ; while i < 2 do ( ( var s : String ; s := "" + n1->at(i+1) ; if (n2->includes(s)) then ( f := true ) else skip ) ; i := i + 1 ) ; if (f) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CodeForces { public static void main(String[] args){ Scanner input=new Scanner(System.in); String num=input.nextLine(); System.out.println(num.matches("(1||14||144)+")? "YES" : "NO"); } } ------------------------------------------------------------ OCL File: --------- class CodeForces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : String ; num := input.nextLine() ; OclFile["System.out"].println(if num->isMatch("(1||14||144)+") then "YES" else "NO" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Magic { public void input(String s){ String let="" ; boolean b=true ; for(int i=0 ; isize() do ( ( if (let = "") then ( if (s->at(i+1) = '1') then ( let := let+(s->at(i+1)) ) else ( b := false ; break ) ) else ( if (s->at(i+1) = '4') then ( let := let+(s->at(i+1)) ) else if (s->at(i+1) = '1') then ( let := "" ; let := let+(s->at(i+1)) ) else ( b := false ; break ) ; ; if (let = "144") then ( let := "" ) else skip ) ) ; i := i + 1 ) ; if (b = true) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var instance : Magic ; instance := Magic.newMagic() ; var s : String ; s := input.getCurrent() ; instance.input(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class D { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ int n=sc.nextInt(); int a[]=new int[n]; for(int i=0 ; itoInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var mini : long ; mini := 0 ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i < n do ( ( var diff : long ; diff := a[i+1] - a[i - 1+1] ; mini := mini + (-1) * diff * i ; ans := ans+(mini) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans + a[n - 1+1]) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class A_Magic_Numbers { public static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader reader=new FastReader(); int N=reader.nextInt(); boolean ans=true ; String s=Integer.toString(N); int consecutiveFours=0 ; for(int i=0 ; i2 || i==0){ ans=false ; break ; } } } System.out.println(ans==false ? "NO" : "YES"); } } ------------------------------------------------------------ OCL File: --------- class A_Magic_Numbers { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : FastReader ; reader := FastReader.newFastReader() ; var N : int ; N := reader.nextInt() ; var ans : boolean ; ans := true ; var s : String ; s := ((N) + "") ; var consecutiveFours : int ; consecutiveFours := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( var ch : String ; ch := s->at(i+1) ; if ((ch /= '1' & ch /= '4')) then ( ans := false ; break ) else if (ch = '1') then ( consecutiveFours := 0 ; continue ) else ( consecutiveFours := consecutiveFours + 1 ; if (consecutiveFours > 2 or i = 0) then ( ans := false ; break ) else skip ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(if ans = false then "NO" else "YES" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces { static int MOD=1000000007 ; static int[] arr=new int[100001]; public static void main(String[] args){ Scanner s=new Scanner(System.in); solve(s); } public static void solve(Scanner s){ String str=s.next(); for(char c : str.toCharArray()){ if(c!='1' && c!='4'){ System.out.println("NO"); return ; } } Setcheck=new HashSet<>(); check.add("1"); check.add("14"); check.add("144"); int i=0 ; while(icollect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; execute solve(s) ); static operation solve( s : OclFile) : void pre: true post: true activity: ( var str : String ; str := s.getCurrent() ; for (c : str->characters()) do ( ( if (c /= '1' & c /= '4') then ( OclFile["System.out"].println("NO") ; return ) else skip ) ) ; var check : Set(String) ; check := Set{} ; check := check->including("1") ; check := check->including("14") ; check := check->including("144") ; var i : int ; i := 0 ; while (i < str->size()) do ( if (i < str->size() - 2 & check->includes(str.subrange(i+1,i + 3))) then ( i := i+(3) ) else if (i < str->size() - 1 & check->includes(str.subrange(i+1,i + 2))) then ( i := i+(2) ) else if (check->includes(str.subrange(i+1,i + 1))) then ( i := i+(1) ) else ( OclFile["System.out"].println("NO") ; return ) ; ; ) ; if (i = str->size() - 2) then ( if (not(str.subrange(i+1,i + 2) = "14")) then ( OclFile["System.out"].println("NO") ; return ) else skip ) else skip ; if (i = str->size() - 1) then ( if (not(str.subrange(i+1,i + 1) = "1")) then ( OclFile["System.out"].println("NO") ; return ) else skip ) else skip ; OclFile["System.out"].println("YES") ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; class GFG { static void minCost(int[] arr,int n){ int cost=Integer.MAX_VALUE ; int element=0 ; int XOR=0 ; for(int i=0 ; iMath.abs((XOR ^ arr[i])-arr[i])){ cost=Math.abs((XOR ^ arr[i])-arr[i]); element=arr[i]; } } System.out.println("Element="+element); System.out.println("Operation required="+Math.abs(cost)); } public static void main(String[] args){ int[] arr={ 2,8,4,16 }; int n=arr.length ; minCost(arr,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minCost( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var cost : int ; cost := 2147483647 ; var element : int ; element := 0 ; var XOR : int ; XOR := 0 ; var i : int ; i := 0 ; while i < n do ( XOR := MathLib.bitwiseXor(XOR,arr[i+1]) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (cost > if (MathLib.bitwiseXor(XOR,arr[i+1])) - arr[i+1] < 0 then -((MathLib.bitwiseXor(XOR,arr[i+1])) - arr[i+1]) else (MathLib.bitwiseXor(XOR,arr[i+1])) - arr[i+1] endif) then ( cost := if (MathLib.bitwiseXor(XOR,arr[i+1])) - arr[i+1] < 0 then -((MathLib.bitwiseXor(XOR,arr[i+1])) - arr[i+1]) else (MathLib.bitwiseXor(XOR,arr[i+1])) - arr[i+1] endif ; element := arr[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Element=" + element) ; OclFile["System.out"].println("Operation required=" + if cost < 0 then -(cost) else cost endif) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,8,4,16} ; var n : int ; n := arr->size() ; execute minCost(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int XorAscii(String str,int len){ int ans=(str.charAt(0)); for(int i=1 ; iat(0+1)) ; var i : int ; i := 1 ; while i < len do ( ( ans := (MathLib.bitwiseXor(ans,((str->at(i+1))))) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var len : int ; len := str->size() ; OclFile["System.out"].print(XorAscii(str, len) + "\n") ; str := "GfG" ; len := str->size() ; OclFile["System.out"].print(XorAscii(str, len)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Scanner ; import java.lang.Math ; public class JvForces { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int cs=0 ; csa=new TreeMap(); for(int i=1 ; i<=n ; i++){ int x=sc.nextInt(); a.put(x,i); } TreeMapb=new TreeMap(); for(int i=1 ; i<=n ; i++){ int x=sc.nextInt(); b.put(x,i); } Set>aent=a.entrySet(); Set>bent=b.entrySet(); int ind=1000000007 ; int ans=1000000007 ; Iterator>iterator=aent.iterator(); Map.Entrytemp2=null ; for(Map.Entrytemp : bent){ temp2=iterator.next(); ind=Math.min(temp2.getValue(),ind); int anst=temp.getValue()-1 ; anst+=ind-1 ; ans=Math.min(ans,anst); } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class JvForces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var cs : int ; cs := 0 ; while cs < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Map(int,int) ; a := Map{} ; var i : int ; i := 1 ; while i <= n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; a := a->union(Map{x |-> i}) ) ; i := i + 1 ) ; var b : Map(int,int) ; b := Map{} ; var i : int ; i := 1 ; while i <= n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; b := b->union(Map{x |-> i}) ) ; i := i + 1 ) ; var aent : Set(Map(int,int)) ; aent := a->asSet() ; var bent : Set(Map(int,int)) ; bent := b->asSet() ; var ind : int ; ind := 1000000007 ; var ans : int ; ans := 1000000007 ; var iterator : OclIterator ; iterator := aent->iterator() ; var temp2 : Map(int,int) ; temp2 := null ; for (temp : bent) do ( ( temp2 := iterator.next() ; ind := Set{temp2->values->any(), ind}->min() ; var anst : int ; anst := temp.getValue() - 1 ; anst := anst+(ind - 1) ; ans := Set{ans, anst}->min() ; ) ) ; OclFile["System.out"].println(ans) ; ) ; cs := cs + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static class pair { int first,second ; public pair(int first,int second){ this.first=first ; this.second=second ; } } static void init(int degree[],pair[] edges,int n){ for(int i=0 ; iat("first") := first ; self->at("second") := second ); } static operation init( degree : Sequence(int), edges : Sequence(pair), n : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n do ( ( degree[i+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < edges->size() do ( ( degree[edges[i+1]->at("first")+1] := degree[edges[i+1]->at("first")+1] + 1 ; degree[edges[i+1]->at("second")+1] := degree[edges[i+1]->at("second")+1] + 1 ) ; i := i + 1 ) ); static operation performQueries( edges : Sequence(pair), q : Sequence(int), n : int) : void pre: true post: true activity: ( var degree : Sequence(int) ; degree := Integer.subrange(1,n)->collect(0) ; execute init(degree, edges, n) ; var i : int ; i := 0 ; while i < q->size() do ( ( var node : int ; node := q[i+1] ; if (node = 0) then ( OclFile["System.out"].println("No") ; continue ) else skip ; if (degree[node+1] = 1) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var edges : Sequence(pair) ; edges := Sequence{pair.newpair(0, 1),pair.newpair(0, 2),pair.newpair(1, 3),pair.newpair(1, 4),pair.newpair(4, 5)} ; var q : Sequence(int) ; q := Sequence{0,3,4,5} ; execute performQueries(edges, q, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Solution { static void printArray(int arr[],int n){ Arrays.sort(arr); int l=0,r=n-1,flag=0,i ; int k=2 ; while(l<=r){ if(flag==0){ for(i=l ; ir-k && i>=l ; i--)System.out.print(arr[i]+" "); flag=0 ; r=i ; } k++; } } public static void main(String args[]){ int n=6 ; int arr[]={ 1,2,3,4,5,6 }; printArray(arr,n); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation printArray( arr : Sequence(int), n : int) : void pre: true post: true activity: ( arr := arr->sort() ; var l : int ; l := 0 ; var r : int ; r := n - 1 ; var flag : int ; flag := 0 ; var i : int ; var k : int ; k := 2 ; while (l <= r) do ( if (flag = 0) then ( i := l ; while i < l + k & i <= r do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; flag := 1 ; l := i ) else ( i := r ; while i > r - k & i >= l do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i - 1 ) ; flag := 0 ; r := i ) ; k := k + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5,6} ; execute printArray(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static int MAX=1000 ; static int f[]=new int[MAX]; static int fib(int n){ Arrays.fill(f,0); if(n==0)return 0 ; if(n==1 || n==2)return(f[n]=1); if(f[n]==1)return f[n]; int k ; if((n & 1)==1)k=(n+1)/2 ; else k=n/2 ; if((n & 1)==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]; } static int calculateSum(int n){ return fib(n+2)-1 ; } public static void main(String args[]){ int n=4 ; System.out.println("Sum of Fibonacci numbers is : "+calculateSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 1000; static attribute f : int := Integer.subrange(1,MAX)->collect(0); static operation fib( n : int) : int pre: true post: true activity: ( f := f->collect(0) ; if (n = 0) then return 0 else skip ; if (n = 1 or n = 2) then return (f[n+1]) else skip ; if (f[n+1] = 1) then return f[n+1] else skip ; var k : int ; if ((n & 1) = 1) then k := (n + 1) / 2 else k := n / 2 ; ; if ((n & 1) = 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] ); static operation calculateSum( n : int) : int pre: true post: true activity: ( return fib(n + 2) - 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println("Sum of Fibonacci numbers is : " + calculateSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class c { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int tc=sc.nextInt(); while(tc-->0){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; while (tc > 0) do ( tc := tc - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (n = 1) then OclFile["System.out"].println(0) ; else ( a := a->sort() ; var cnt : Sequence(long) ; cnt := Integer.subrange(1,n - 1)->collect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( cnt[i+1] := a[i + 1+1] - a[i+1] ; ; i := i + 1 ) ; var ans : long ; ans := 0L ; var i : int ; i := 0 ; while i < n - 1 do ( ans := ans-((cnt[i+1] * (i + 1) * (n - i - 1))) ; ; i := i + 1 ) ; for (c : cnt) do ( ans := ans+(c) ; ) ; OclFile["System.out"].println(ans) ; ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args)throws Exception { String str=sc.next(); int wPos=str.indexOf('w'); String pre=str.substring(0,wPos-1); String suf=str.substring(wPos+2); int[][] dp=new int[pre.length()+1][suf.length()+1]; for(int i=1 ; i<=pre.length(); ++i){ for(int j=1 ; j<=suf.length(); ++j){ dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]); if(syn(pre.charAt(i-1),suf.charAt(suf.length()-j))){ dp[i][j]=Math.max(dp[i][j],dp[i-1][j-1]+2); } } } System.out.println(dp[pre.length()][suf.length()]+3); } static boolean syn(char c1,char c2){ if(c1=='(' && c2==')'){ return true ; } if(c1==')' && c2=='('){ return true ; } if(c1=='{' && c2=='}'){ return true ; } if(c1=='}' && c2=='{'){ return true ; } if(c1=='[' && c2==']'){ return true ; } if(c1==']' && c2=='['){ return true ; } return false ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := sc.getCurrent() ; var wPos : int ; wPos := str->indexOf('w')-1 ; var pre : String ; pre := str.subrange(0+1,(wPos)->char2byte() - 1) ; var suf : String ; suf := str.subrange(wPos + 2+1,wPos + 2) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,pre->size() + 1)->collect(Integer.subrange(1,suf->size() + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= pre->size() do ( ( var j : int ; j := 1 ; while j <= suf->size() do ( ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->max() ; if (syn(pre->at(i - 1+1), suf->at(suf->size() - j+1))) then ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i - 1+1][j - 1+1] + 2}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dp[pre->size()+1][suf->size()+1] + 3) ; ); static operation syn( c1 : String, c2 : String) : boolean pre: true post: true activity: ( if (c1 = '(' & c2 = ')') then ( return true ) else skip ; if (c1 = ')' & c2 = '(') then ( return true ) else skip ; if (c1 = '{' & c2 = '}') then ( return true ) else skip ; if (c1 = '}' & c2 = '{') then ( return true ) else skip ; if (c1 = '[' & c2 = ']') then ( return true ) else skip ; if (c1 = ']' & c2 = '[') then ( return true ) else skip ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static char[] arr ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); arr=sc.next().toCharArray(); System.out.println(getLength(0,arr.length-1)); } static int getLength(int left,int right){ if(arr[left]=='i' || arr[right]=='i'){ return 3 ; } if(arr[left]=='('){ if(arr[right]==')'){ return getLength(left+1,right-1)+2 ; } } else if(arr[left]=='{'){ if(arr[right]=='}'){ return getLength(left+1,right-1)+2 ; } } else if(arr[left]=='['){ if(arr[right]==']'){ return getLength(left+1,right-1)+2 ; } } else if(arr[left]==')'){ if(arr[right]=='('){ return getLength(left+1,right-1)+2 ; } } else if(arr[left]=='}'){ if(arr[right]=='{'){ return getLength(left+1,right-1)+2 ; } } else if(arr[left]==']'){ if(arr[right]=='['){ return getLength(left+1,right-1)+2 ; } } return Math.max(getLength(left+1,right),getLength(left,right-1)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute arr : Sequence(String); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; arr := sc.getCurrent()->characters() ; OclFile["System.out"].println(getLength(0, arr->size() - 1)) ); static operation getLength( left : int, right : int) : int pre: true post: true activity: ( if (arr[left+1] = 'i' or arr[right+1] = 'i') then ( return 3 ) else skip ; if (arr[left+1] = '(') then ( if (arr[right+1] = ')') then ( return getLength(left + 1, right - 1) + 2 ) else skip ) else if (arr[left+1] = '{') then ( if (arr[right+1] = '}') then ( return getLength(left + 1, right - 1) + 2 ) else skip ) else if (arr[left+1] = '[') then ( if (arr[right+1] = ']') then ( return getLength(left + 1, right - 1) + 2 ) else skip ) else if (arr[left+1] = ')') then ( if (arr[right+1] = '(') then ( return getLength(left + 1, right - 1) + 2 ) else skip ) else if (arr[left+1] = '}') then ( if (arr[right+1] = '{') then ( return getLength(left + 1, right - 1) + 2 ) else skip ) else if (arr[left+1] = ']') then ( if (arr[right+1] = '[') then ( return getLength(left + 1, right - 1) + 2 ) else skip ) else skip ; ; ; ; ; ; return Set{getLength(left + 1, right), getLength(left, right - 1)}->max() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isDivisibleby17(int n){ if(n==0 || n==17)return true ; if(n<17)return false ; return isDivisibleby17((int)(n>>4)-(int)(n & 15)); } public static void main(String[] args){ int n=35 ; if(isDivisibleby17(n)==true)System.out.printf("%d is divisible by 17",n); else System.out.printf("%d is not divisible by 17",n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isDivisibleby17( n : int) : boolean 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(((n/(2->pow(4)))->oclAsType(long))->oclAsType(int) - (MathLib.bitwiseAnd(n,15))->oclAsType(int)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 35 ; if (isDivisibleby17(n) = true) then OclFile["System.out"].printf("%d is divisible by 17", n) ; else OclFile["System.out"].printf("%d is not divisible by 17", n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long squareSum(long N){ long sum=(long)(N*(N+1)*(2*N+1))/6 ; return sum ; } static long findMaxN(long X){ long low=1,high=100000 ; int N=0 ; while(low<=high){ long mid=(high+low)/2 ; if(squareSum(mid)<=X){ N=(int)mid ; low=mid+1 ; } else high=mid-1 ; } return N ; } public static void main(String[] args){ long X=25 ; System.out.println(findMaxN(X)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation squareSum( N : long) : long pre: true post: true activity: ( var sum : long ; sum := (N * (N + 1) * (2 * N + 1))->oclAsType(long) / 6 ; return sum ); static operation findMaxN( X : long) : long pre: true post: true activity: ( var low : long ; low := 1 ; var high : long ; high := 100000 ; var N : int ; N := 0 ; while (low <= high) do ( var mid : long ; mid := (high + low) / 2 ; if (squareSum(mid) <= X) then ( N := mid->oclAsType(int) ; low := mid + 1 ) else high := mid - 1 ; ) ; return N ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var X : long ; X := 25 ; OclFile["System.out"].println(findMaxN(X)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println("thu:fri:sat:sun:mon:tue:wed".split(":")[sc.nextInt()% 7]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println("thu:fri:sat:sun:mon:tue:wed"->split(":")[sc.getCurrent()->toInteger() mod 7+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ProblemD2 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); int[] result=new int[t]; for(int i=0 ; i0 ; j--){ if(j % 2==1){ result[i]=Math.min(result[i],order[j]+l); } else { l=Math.min(l,order[j]); } } } for(int i=0 ; itoInteger() ; var result : Sequence(int) ; result := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var order : Sequence(int) ; order := Integer.subrange(1,2 * n + 1)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( order[in.getCurrent()->toInteger()+1] := j ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( order[in.getCurrent()->toInteger()+1] := j ) ; j := j + 1 ) ; result[i+1] := 2147483647 ; var l : int ; l := n - 1 ; var j : int ; j := 2 * n ; while j > 0 do ( ( if (j mod 2 = 1) then ( result[i+1] := Set{result[i+1], order[j+1] + l}->min() ) else ( l := Set{l, order[j+1]}->min() ) ) ; j := j - 1 ) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t do ( ( OclFile["System.out"].println(result[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); try { int x=Integer.parseInt(reader.readLine()); if(x==1 || x==8 || x==15 || x==22 || x==29){ System.out.println("fri"); } else if(x==2 || x==9 || x==16 || x==23 || x==30){ System.out.println("sat"); } else if(x==3 || x==10 || x==17 || x==24 || x==31){ System.out.println("sun"); } else if(x==4 || x==11 || x==18 || x==25){ System.out.println("mon"); } else if(x==5 || x==12 || x==19 || x==26){ System.out.println("tue"); } else if(x==6 || x==13 || x==20 || x==27){ System.out.println("wed"); } else if(x==7 || x==14 || x==21 || x==28){ System.out.println("thu"); } reader.close(); } catch(IOException e){ e.printStackTrace(); } } static int gcd(int a,int b){ return b>0 ? gcd(b,a % b): a ; } static int lcm(int a,int b){ return a*b/gcd(a,b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var x : int ; x := (reader.readLine())->toInteger() ; if (x = 1 or x = 8 or x = 15 or x = 22 or x = 29) then ( OclFile["System.out"].println("fri") ) else if (x = 2 or x = 9 or x = 16 or x = 23 or x = 30) then ( OclFile["System.out"].println("sat") ) else if (x = 3 or x = 10 or x = 17 or x = 24 or x = 31) then ( OclFile["System.out"].println("sun") ) else if (x = 4 or x = 11 or x = 18 or x = 25) then ( OclFile["System.out"].println("mon") ) else if (x = 5 or x = 12 or x = 19 or x = 26) then ( OclFile["System.out"].println("tue") ) else if (x = 6 or x = 13 or x = 20 or x = 27) then ( OclFile["System.out"].println("wed") ) else if (x = 7 or x = 14 or x = 21 or x = 28) then ( OclFile["System.out"].println("thu") ) else skip ; ; ; ; ; ; ; skip ) catch (e : IOException) do ( e.printStackTrace() ) ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if b > 0 then gcd(b, a mod b) else a endif ); static operation lcm( a : int, b : int) : int pre: true post: true activity: ( return a * b / gcd(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=(x-9)% 7 ; if(y<0){ y+=7 ; } switch(y){ case 0 : System.out.println("sat"); break ; case 1 : System.out.println("sun"); break ; case 2 : System.out.println("mon"); break ; case 3 : System.out.println("tue"); break ; case 4 : System.out.println("wed"); break ; case 5 : System.out.println("thu"); break ; case 6 : System.out.println("fri"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := (x - 9) mod 7 ; if (y < 0) then ( y := y+(7) ) else skip ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (y) ; if _switchval = 0 then OclFile["System.out"].println("sat") ; break else skip ; if _switchval = 1 then OclFile["System.out"].println("sun") ; break else skip ; if _switchval = 2 then OclFile["System.out"].println("mon") ; break else skip ; if _switchval = 3 then OclFile["System.out"].println("tue") ; break else skip ; if _switchval = 4 then OclFile["System.out"].println("wed") ; break else skip ; if _switchval = 5 then OclFile["System.out"].println("thu") ; break else skip ; if _switchval = 6 then OclFile["System.out"].println("fri") ; else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { static IntStream REPS(int v){ return IntStream.range(0,v); } static IntStream REPS(int l,int r){ return IntStream.rangeClosed(l,r); } static IntStream INS(int n){ return REPS(n).map(i->getInt()); } static Scanner s=new Scanner(System.in); static int getInt(){ return Integer.parseInt(s.next()); } public static void main(String[] $){ String[] d={ "mon","tue","wed","thu","fri","sat","sun" }; System.out.println(d[(getInt()+3)% 7]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation REPS( v : int) : Sequence(int) pre: true post: true activity: ( return Integer.subrange(0, v-1) ); static operation REPS( l : int, r : int) : Sequence(int) pre: true post: true activity: ( return Integer.subrange(l, r) ); static operation INS( n : int) : Sequence(int) pre: true post: true activity: ( return REPS(n)->collect( _x1 | (lambda i : OclAny in getInt())->apply(_x1) ) ); static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation getInt() : int pre: true post: true activity: ( return (s.getCurrent())->toInteger() ); static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var d : Sequence(String) ; d := Sequence{"mon","tue","wed","thu","fri","sat","sun"} ; OclFile["System.out"].println(d[(getInt() + 3) mod 7+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.time.LocalDate ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); LocalDate ld=LocalDate.of(2017,9,sc.nextInt()); switch(ld.getDayOfWeek()){ case FRIDAY : System.out.println("fri"); break ; case MONDAY : System.out.println("mon"); break ; case SATURDAY : System.out.println("sat"); break ; case SUNDAY : System.out.println("sun"); break ; case THURSDAY : System.out.println("thu"); break ; case TUESDAY : System.out.println("tue"); break ; case WEDNESDAY : System.out.println("wed"); break ; default : break ; } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ld : LocalDate ; ld := LocalDate.of(2017, 9, sc.getCurrent()->toInteger()) ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (ld.getDayOfWeek()) ; if _switchval = FRIDAY then OclFile["System.out"].println("fri") ; break else skip ; if _switchval = MONDAY then OclFile["System.out"].println("mon") ; break else skip ; if _switchval = SATURDAY then OclFile["System.out"].println("sat") ; break else skip ; if _switchval = SUNDAY then OclFile["System.out"].println("sun") ; break else skip ; if _switchval = THURSDAY then OclFile["System.out"].println("thu") ; break else skip ; if _switchval = TUESDAY then OclFile["System.out"].println("tue") ; break else skip ; if _switchval = WEDNESDAY then OclFile["System.out"].println("wed") ; break else skip ; if true then break else skip ; ) skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); while(s.hasNext()){ int[] l={ 1,2,3,4,5,6,7,8,9,10 }; int[] a=new int[3]; for(int i=0 ; i<3 ; i++)a[i]=s.nextInt(); for(int i=0 ; i<10 ; i++){ if(a[0]==l[i] || a[1]==l[i] || a[2]==l[i])l[i]=100 ; } int b=0 ; for(int i=0 ; i<10 ; i++){ if(l[i]<=20-a[0]-a[1])b++; } if(b>3)System.out.println("YES"); else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (s.hasNext()) do ( var l : Sequence(int) ; l := Sequence{1,2,3,4,5,6,7,8,9,10} ; var a : Sequence(int) ; a := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < 3 do ( a[i+1] := s.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 10 do ( ( if (a[0+1] = l[i+1] or a[1+1] = l[i+1] or a[2+1] = l[i+1]) then l[i+1] := 100 ; else skip ) ; i := i + 1 ) ; var b : int ; b := 0 ; var i : int ; i := 0 ; while i < 10 do ( ( if (l[i+1] <= 20 - a[0+1] - a[1+1]) then b := b + 1 ; else skip ) ; i := i + 1 ) ; if (b > 3) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class AQW { static int fib[]=new int[43]; static void fibonacci(){ fib[0]=1 ; fib[1]=2 ; for(int i=2 ; i<43 ; i++)fib[i]=fib[i-1]+fib[i-2]; } static int rec(int x,int y,int last){ if(y==0){ if(x==0)return 1 ; return 0 ; } int sum=0 ; for(int i=last ; i>=0 && fib[i]*y>=x ; i--){ if(fib[i]>x)continue ; sum+=rec(x-fib[i],y-1,i); } return sum ; } public static void main(String[] args){ fibonacci(); int n=13,k=3 ; System.out.println("Possible ways are: "+rec(n,k,42)); } } ------------------------------------------------------------ OCL File: --------- class AQW { static attribute fib : int := Integer.subrange(1,43)->collect(0); static operation fibonacci() : void pre: true post: true activity: ( fib[0+1] := 1 ; fib[1+1] := 2 ; var i : int ; i := 2 ; while i < 43 do ( fib[i+1] := fib[i - 1+1] + fib[i - 2+1] ; ; i := i + 1 ) ); static operation rec( x : int, y : int, last : int) : int pre: true post: true activity: ( if (y = 0) then ( if (x = 0) then return 1 else skip ; return 0 ) else skip ; var sum : int ; sum := 0 ; var i : int ; i := last ; while i >= 0 & fib[i+1] * y >= x do ( ( if (fib[i+1] > x) then continue else skip ; sum := sum+(rec(x - fib[i+1], y - 1, i)) ) ; i := i - 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute fibonacci() ; var n : int ; n := 13 ; var k : int ; k := 3 ; OclFile["System.out"].println("Possible ways are: " + rec(n, k, 42)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class B_Summer_sell_off { public static void main(String[] args){ long sum=0 ; Scanner in=new Scanner(System.in); int n=in.nextInt(),f=in.nextInt(); Day[] plan=new Day[n]; while(n-->0){ plan[n]=new Day(); plan[n] .products=in.nextInt(); plan[n] .customers=in.nextInt(); } Arrays.sort(plan); for(Day day : plan){ if(f-->0){ sum+=day.soldProductsInSellOut(); } else sum+=day.soldProducts(); } System.out.println(sum); } } class Day implements Comparable{ int products,customers ; @ Override public int compareTo(Day day){ long temp1=this.soldProductsInSellOut()-this.soldProducts(),temp2=day.soldProductsInSellOut()-day.soldProducts(); if(temp1>temp2)return-1 ; else if(temp1toInteger() ; var f : int ; f := in.getCurrent()->toInteger() ; var plan : Sequence(Day) ; plan := Integer.subrange(1,n)->collect(null) ; while (n > 0) do ( n := n - 1 ; skip ; ( plan[n+1] := Day.newDay() ; plan[n+1].products := in.getCurrent()->toInteger() ; plan[n+1].customers := in.getCurrent()->toInteger() ) ; ) ; plan := plan->sort() ; for (day : plan) do ( ( if (f > 0) then ( sum := sum+(day.soldProductsInSellOut()) ) else sum := sum+(day.soldProducts()) ; ) ) ; OclFile["System.out"].println(sum) ; ); } class Day implements Comparable { attribute products : int; operation compareTo( day : Day) : int pre: true post: true activity: ( var temp1 : long ; temp1 := self.soldProductsInSellOut() - self.soldProducts() ; var temp2 : long ; temp2 := day.soldProductsInSellOut() - day.soldProducts() ; if (temp1 > temp2) then return -1 else if (temp1 < temp2) then return 1 else skip ; ; return 0 ); operation soldProducts() : int pre: true post: true activity: ( return Set{self.products, customers}->min() ); operation soldProductsInSellOut() : int pre: true post: true activity: ( return Set{self.products * 2, customers}->min() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean sameLength(int A,int B){ while((A>0)&&(B>0)){ A=A/10 ; B=B/10 ; } if((A==0)&&(B==0))return true ; return false ; } public static void main(String[] args){ int A=21,B=1 ; if(sameLength(A,B))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sameLength( A : int, B : int) : boolean 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 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 21 ; var B : int ; B := 1 ; if (sameLength(A, B)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int minimumAdjacentDifference(int a[],int n,int k){ int minDiff=Integer.MAX_VALUE ; for(int i=0 ; i<=k ; i++){ int maxDiff=Integer.MIN_VALUE ; for(int j=0 ; jmax() ) ; p := p + 1 ) ) ; j := j + 1 ) ; minDiff := Set{minDiff, maxDiff}->min() ) ; i := i + 1 ) ; return minDiff ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var k : int ; k := 2 ; var a : Sequence(int) ; a := Sequence{3,7,8,10,14} ; OclFile["System.out"].println(minimumAdjacentDifference(a, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=1 ; for(int itr=0 ; itrb)return gcd(a-b,b); return gcd(a,b-a); } } class Pair implements Comparable{ int fi,se ; Pair(int fi,int se){ this.fi=fi ; this.se=se ; } public int compareTo(Pair p){ return this.fi-p.fi ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := 1 ; var itr : int ; itr := 0 ; while itr < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var maxx : long ; maxx := "-9223372036854775808"->toLong() ; var minx : long ; minx := "9223372036854775807"->toLong() ; var maxy : long ; maxy := "-9223372036854775808"->toLong() ; var miny : long ; miny := "9223372036854775807"->toLong() ; var i : int ; i := 0 ; while i < n do ( ( var x : long ; x := in.getCurrent()->toLong() ; var y : long ; y := in.getCurrent()->toLong() ; maxx := Set{x, maxx}->max() ; minx := Set{x, minx}->min() ; maxy := Set{y, maxy}->max() ; miny := Set{y, miny}->min() ; ) ; i := i + 1 ) ; var m : long ; m := Set{1, (Set{maxx - minx, maxy - miny}->max())}->max() ; OclFile["System.out"].println(1l * m * m) ; ) ; itr := itr + 1 ) ); static operation gcd( a : int, b : int) : int 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 > b) then return gcd(a - b, b) else skip ; return gcd(a, b - a) ); } class Pair implements Comparable { attribute fi : int; static operation newPair( fi : int, se : int) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(fi, se); return self ); operation initialise( fi : int, se : int) : void pre: true post: true activity: ( self.fi := fi ; self.se := se ); operation compareTo( p : Map) : int pre: true post: true activity: ( return self.fi - p.fi ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isSubSequence(String str1,String str2){ int m=str1.length(),n=str2.length(); int j=0 ; for(int i=0 ; idict,String str){ String result="" ; int length=0 ; for(String word : dict){ if(lengthsize() ; var n : int ; n := str2->size() ; var j : int ; j := 0 ; var i : int ; i := 0 ; while i < n & j < m do ( ( if (str1->at(j+1) = str2->at(i+1)) then ( j := j + 1 ) else skip ) ; i := i + 1 ) ; return (j = m) ); static operation findLongestString( dict : Sequence(String), str : String) : String pre: true post: true activity: ( var result : String ; result := "" ; var length : int ; length := 0 ; for (word : dict) do ( ( if (length < word->size() & isSubSequence(word, str)) then ( result := word ; length := word->size() ) else skip ) ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"ale","apple","monkey","plea"} ; var dict : Sequence ; dict := Sequence{}->union(arr) ; var str : String ; str := "abpcplea" ; OclFile["System.out"].println(findLongestString(dict, str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static int __gcd(int a,int b){ return b==0 ? a : __gcd(b,a % b); } static void solveProportion(int a,int b1,int b2,int c){ int A=a*b2 ; int B=b1*b2 ; int C=b1*c ; int gcd=__gcd(__gcd(A,B),C); System.out.print(A/gcd+":"+B/gcd+":"+C/gcd); } public static void main(String args[]){ int a,b1,b2,c ; a=3 ; b1=4 ; b2=8 ; c=9 ; solveProportion(a,b1,b2,c); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation __gcd( a : int, b : int) : int pre: true post: true activity: ( return if b = 0 then a else __gcd(b, a mod b) endif ); static operation solveProportion( a : int, b1 : int, b2 : int, c : int) : void pre: true post: true activity: ( var A : int ; A := a * b2 ; var B : int ; B := b1 * b2 ; var C : int ; C := b1 * c ; var gcd : int ; gcd := __gcd(__gcd(A, B), C) ; OclFile["System.out"].print(A / gcd + ":" + B / gcd + ":" + C / gcd) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; var b1 : int ; var b2 : int ; var c : int ; a := 3 ; b1 := 4 ; b2 := 8 ; c := 9 ; execute solveProportion(a, b1, b2, c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { int n,res ; int[] now,ans ; void f(int k,int cnt){ if(res<=cnt)return ; if(k==n){ res=cnt ; return ; } if(now[k]==ans[k])f(k+1,cnt); else { int dif=ans[k]-now[k]; if(dif<0)dif+=10 ; for(int j=k ; jtoInteger() ; if (n = 0) then break else skip ; now := Integer.subrange(1,n)->collect(0) ; ans := Integer.subrange(1,n)->collect(0) ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var i : int ; i := 0 ; while i < n do ( now[i+1] := s[i+1] - ('0')->char2byte() ; ; i := i + 1 ) ; s := sc.getCurrent()->characters() ; var i : int ; i := 0 ; while i < n do ( ans[i+1] := s[i+1] - ('0')->char2byte() ; ; i := i + 1 ) ; res := n ; execute f(0, 0) ; OclFile["System.out"].println(res) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args){ FastScanner input=new FastScanner(); int n=input.nextInt(); String s=input.next()+"a" ; int count=0 ; long ans=0 ; for(int i=0 ; iat(i+1) = 'x') then ( count := count + 1 ) else ( ans := ans+(Set{0, (count)->char2byte() - 2}->max()) ; count := 0 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { int ans,n ; int[] garr ; private void doit(){ Scanner sc=new Scanner(System.in); while(true){ n=sc.nextInt(); if(n==0)break ; char[] s=sc.next().toCharArray(); char[] g=sc.next().toCharArray(); int[] sarr=new int[n]; for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var g : Sequence(String) ; g := sc.getCurrent()->characters() ; var sarr : Sequence(int) ; sarr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( sarr[i+1] := s[i+1] - ('0')->char2byte() ) ; i := i + 1 ) ; garr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( garr[i+1] := g[i+1] - ('0')->char2byte() ) ; i := i + 1 ) ; ans := (1*(2->pow(24)))->oclAsType(long) ; execute dfs(sarr, 0) ; OclFile["System.out"].println(ans) ; ) ); operation dfs( arr : Sequence(int), deep : int) : void pre: true post: true activity: ( if (arr = garr) then ( ans := Set{ans, deep}->min() ; return ) else if (deep = n) then return else skip ; ; if (ans <= deep) then return else skip ; var pos : int ; pos := deep ; while pos < n do ( ( if (garr[pos+1] /= arr[pos+1]) then break else skip ) ; pos := pos + 1 ) ; var diff1 : int ; diff1 := (garr[pos+1] - arr[pos+1] + 10) mod 10 ; var i : int ; i := pos ; while i < n do ( ( var j : int ; j := pos ; while j <= i do ( ( arr[j+1] := (arr[j+1] + diff1) mod 10 ) ; j := j + 1 ) ; execute dfs(arr, deep + 1) ; var j : int ; j := pos ; while j <= i do ( ( arr[j+1] := (arr[j+1] - diff1 + 10) mod 10 ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println("debug=" + (o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static int dfs(final int n,int deep,int[] array,int[] ans){ if(n==deep){ return 0 ; } else if(array[deep]==ans[deep]){ return dfs(n,deep+1,array,ans); } else { final int diff=ans[deep]-array[deep]; int ret=Integer.MAX_VALUE ; for(int k=deep+1 ; k<=n ; k++){ for(int i=deep ; imin() ; var i : int ; i := deep ; while i < k do ( ( array[i+1] := (10 + array[i+1] - diff) mod 10 ) ; i := i + 1 ) ) ; k := k + 1 ) ; return ret + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var array : Sequence(int) ; array := Integer.subrange(1,10)->collect(0) ; var ans : Sequence(int) ; ans := Integer.subrange(1,10)->collect(0) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then ( break ) else skip ; var input1 : Sequence(String) ; input1 := sc.getCurrent()->characters() ; var i : int ; i := 0 ; while i < n do ( ( array[i+1] := input1[i+1] - ('0')->char2byte() ) ; i := i + 1 ) ; var input2 : Sequence(String) ; input2 := sc.getCurrent()->characters() ; var i : int ; i := 0 ; while i < n do ( ( ans[i+1] := input2[i+1] - ('0')->char2byte() ) ; i := i + 1 ) ; OclFile["System.out"].println(dfs(n, 0, array, ans)) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] arg){ while(true){ int K=sc.nextInt(); if(K==0)break ; String s=sc.next(); String t=sc.next(); int[] d=new int[K]; for(int i=0 ; itoInteger() ; if (K = 0) then break else skip ; var s : String ; s := sc.getCurrent() ; var t : String ; t := sc.getCurrent() ; var d : Sequence(int) ; d := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 0 ; while i < K do ( ( d[i+1] := (10 + t->at(i+1) - s->at(i+1)) mod 10 ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(d, 0)) ; ) ); static operation solve( d : Sequence(int), pos : int) : int pre: true post: true activity: ( if (pos = d->size()) then return 0 else skip ; if (d[pos+1] = 0) then return solve(d, pos + 1) else skip ; var prev : int ; prev := d[pos+1] ; var ret : int ; ret := 99 ; var i : int ; i := pos ; while i < d->size() do ( ( d[i+1] := (d[i+1] + 10 - prev) mod 10 ; ret := Set{ret, solve(d, pos + 1) + 1}->min() ) ; i := i + 1 ) ; var i : int ; i := pos ; while i < d->size() do ( ( d[i+1] := (d[i+1] + prev) mod 10 ) ; i := i + 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A_602 { public static void main(String[] args){ FastReader sc=new FastReader(); int n=sc.nextInt(); int bx=sc.nextInt(); long num1=0 ; for(int i=n-1 ; i>=0 ; i--){ int in=sc.nextInt(); num1+=(in)*Math.pow(bx,i); } int n2=sc.nextInt(); int by=sc.nextInt(); long num2=0 ; for(int i=n2-1 ; i>=0 ; i--){ int in=sc.nextInt(); num2+=(in)*Math.pow(by,i); } String ans=num1>num2 ? ">" : num1==num2 ? "=" : "<" ; System.out.println(ans); } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return(str); } } } ------------------------------------------------------------ OCL File: --------- class A_602 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var n : int ; n := sc.nextInt() ; var bx : int ; bx := sc.nextInt() ; var num1 : long ; num1 := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( var in : int ; in := sc.nextInt() ; num1 := num1+((in) * bx->pow(i)) ) ; i := i - 1 ) ; var n2 : int ; n2 := sc.nextInt() ; var by : int ; by := sc.nextInt() ; var num2 : long ; num2 := 0 ; var i : int ; i := n2 - 1 ; while i >= 0 do ( ( var in : int ; in := sc.nextInt() ; num2 := num2+((in) * by->pow(i)) ) ; i := i - 1 ) ; var ans : String ; ans := if num1 > num2 then ">" else if num1 = num2 then "=" else "<" endif endif ; OclFile["System.out"].println(ans) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return (str) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class TwoBases { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); if(scanner.hasNext()){ long x=0,y=0 ; int n=scanner.nextInt(); int p=scanner.nextInt(); for(; n>0 ; x+=Math.pow(p,--n)*scanner.nextInt()); n=scanner.nextInt(); p=scanner.nextInt(); for(; n>0 ; y+=Math.pow(p,--n)*scanner.nextInt()); if(x>y){ System.out.println(">"); } else if(x==y){ System.out.println("="); } else { System.out.println("<"); } } } } ------------------------------------------------------------ OCL File: --------- class TwoBases { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; if (scanner.hasNext()) then ( var x : long ; x := 0 ; var y : long ; y := 0 ; var n : int ; n := scanner.getCurrent()->toInteger() ; var p : int ; p := scanner.getCurrent()->toInteger() ; while n > 0 do ( ; x := x+(p->pow((n - 1)) * scanner.getCurrent()->toInteger()) ) ; n := scanner.getCurrent()->toInteger() ; p := scanner.getCurrent()->toInteger() ; while n > 0 do ( ; y := y+(p->pow((n - 1)) * scanner.getCurrent()->toInteger()) ) ; if (x > y) then ( OclFile["System.out"].println(">") ) else if (x = y) then ( OclFile["System.out"].println("=") ) else ( OclFile["System.out"].println("<") ) ; ; ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] amit)throws Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(); int bx=in.nextInt(); long X=0 ; for(int i=0 ; i"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( amit : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var bx : int ; bx := in.getCurrent()->toInteger() ; var X : long ; X := 0 ; var i : int ; i := 0 ; while i < n do ( ( X := X*(bx) ; X := X+(in.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var m : int ; m := in.getCurrent()->toInteger() ; var by : int ; by := in.getCurrent()->toInteger() ; var Y : long ; Y := 0 ; var i : int ; i := 0 ; while i < m do ( ( Y := Y*(by) ; Y := Y+(in.getCurrent()->toInteger()) ) ; i := i + 1 ) ; if (X = Y) then ( OclFile["System.out"].println("=") ) else if (X < Y) then ( OclFile["System.out"].println("<") ) else ( OclFile["System.out"].println(">") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p078 implements EulerSolution { public static void main(String[] args){ System.out.println(new p078().run()); } private static final int MODULUS=Library.pow(10,6); public String run(){ for(int limit=1 ; ; limit*=2){ int result=search(limit); if(result!=-1)return Integer.toString(result); } } private static int search(int limit){ int[] partitions=new int[limit]; partitions[0]=1 ; for(int i=1 ; icollect(0) ; partitions[0+1] := 1 ; var i : int ; i := 1 ; while i < limit do ( ( var j : int ; j := i ; while j < limit do ( partitions[j+1] := (partitions[j+1] + partitions[j - i+1]) mod MODULUS ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < limit do ( ( if (partitions[i+1] = 0) then return i else skip ) ; i := i + 1 ) ; return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Deque ; import java.util.HashMap ; import java.util.LinkedList ; import java.util.List ; import java.util.Map ; import java.util.stream.Stream ; public class CasimirString { static BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args)throws NumberFormatException,IOException { int cases=Integer.parseInt(reader.readLine()); while(cases-->0){ String[] firstLine=reader.readLine().split(" "); long n=Long.parseLong(firstLine[0]); long m=Long.parseLong(firstLine[1]); long k=Long.parseLong(firstLine[2]); long maxEdges=n*(n-1)/2 ; long diameter=k-2 ; if(diameter<0 || m>maxEdges){ printNo(); } else if(n==1 && m==0){ printYes(); } else if(m==maxEdges && diameter>=1){ printYes(); } else if(diameter>=2){ n-=diameter+1 ; m-=diameter ; m-=n ; if(m>=0)printYes(); else printNo(); } else { printNo(); } } out.flush(); } public static int[] convertToIntArray(String[] str){ return Stream.of(str).mapToInt(Integer :: parseInt).toArray(); } public static void printYes()throws IOException { out.append("YES"+"\n"); } public static void printNo()throws IOException { out.append("NO"+"\n"); } } ------------------------------------------------------------ OCL File: --------- class CasimirString { static attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cases : int ; cases := (reader.readLine())->toInteger() ; while (cases > 0) do ( cases := cases - 1 ; skip ; ( var firstLine : Sequence(String) ; firstLine := reader.readLine()->split(" ") ; var n : long ; n := (firstLine[0+1])->toLong() ; var m : long ; m := (firstLine[1+1])->toLong() ; var k : long ; k := (firstLine[2+1])->toLong() ; var maxEdges : long ; maxEdges := n * (n - 1) / 2 ; var diameter : long ; diameter := k - 2 ; if (diameter < 0 or m > maxEdges) then ( execute printNo() ) else if (n = 1 & m = 0) then ( execute printYes() ) else if (m = maxEdges & diameter >= 1) then ( execute printYes() ) else if (diameter >= 2) then ( n := n-(diameter + 1) ; m := m-(diameter) ; m := m-(n) ; if (m >= 0) then execute printYes() ; else execute printNo() ; ) else ( execute printNo() ) ; ; ; ; ) ; ) ; skip ); static operation convertToIntArray( str : Sequence(String)) : Sequence(int) pre: true post: true activity: ( return Sequence{str}->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ); static operation printYes() : void pre: true post: true activity: ( skip ); static operation printNo() : void pre: true post: true activity: ( skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p010 implements EulerSolution { public static void main(String[] args){ System.out.println(new p010().run()); } private static final int LIMIT=2000000 ; public String run(){ long sum=0 ; for(int p : Library.listPrimes(LIMIT-1))sum+=p ; return Long.toString(sum); } } ------------------------------------------------------------ OCL File: --------- class p010 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p010.newp010().run()) ); static attribute LIMIT : int := 2000000; operation run() : String pre: true post: true activity: ( var sum : long ; sum := 0 ; for (p : Library.listPrimes(LIMIT - 1)) do ( sum := sum+(p) ; ) ; return ((sum) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void generate(Setst,String s){ if(s.length()==0){ return ; } if(! st.contains(s)){ st.add(s); for(int i=0 ; ist=new TreeSet<>(); generate(st,s); for(String str : st){ System.out.println(str); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation generate( st : Set(String), s : String) : void pre: true post: true activity: ( if (s->size() = 0) then ( return ) else skip ; if (not(st->includes(s))) then ( st->excludes(s) ; var i : int ; i := 0 ; while i < s->size() do ( ( var t : String ; t := s ; t := t.subrange(0+1,i) + t.subrange(i + 1+1,i + 1) ; execute generate(st, t) ) ; i := i + 1 ) ) else skip ; return ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "xyz" ; var st : Set(String) ; st := Set{} ; execute generate(st, s) ; for (str : st) do ( ( OclFile["System.out"].println(str) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int divisible(String num){ int n=num.length(); int sum=0 ; for(int i=0 ; isize() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( sum := sum+((num->at(i+1))->oclAsType(int)) ; ; i := i + 1 ) ; if (sum mod 3 = 0) then return 0 else skip ; if (n = 1) then return -1 else skip ; var i : int ; i := 0 ; while i < n do ( if (sum mod 3 = (num->at(i+1) - ('0')->char2byte()) mod 3) then return 1 else skip ; ; i := i + 1 ) ; if (n = 2) then return -1 else skip ; return 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : String ; num := "1234" ; OclFile["System.out"].println(divisible(num)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=100000 ; static int countPairsWithProductK(int arr[],int n,int k){ int count=0 ; int i ; boolean hashmap[]=new boolean[MAX]; for(i=0 ; i=0 &&((index-(int)(index))==0)&& hashmap[k/x])count++; hashmap[x]=false ; } return count ; } public static void main(String[] args){ int arr[]={ 1,5,3,4,2 }; int N=arr.length ; int K=3 ; System.out.print(countPairsWithProductK(arr,N,K)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 100000; static operation countPairsWithProductK( arr : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; var hashmap : Sequence(boolean) ; hashmap := Integer.subrange(1,MAX)->collect(false) ; i := 0 ; while i < n do ( hashmap[arr[i+1]+1] := true ; ; i := i + 1 ) ; i := 0 ; while i < n do ( ( var x : int ; x := arr[i+1] ; var index : double ; index := 1.0 * k / arr[i+1] ; if (index >= 0 & ((index - (index)->oclAsType(int)) = 0) & hashmap[k / x+1]) then count := count + 1 ; else skip ; hashmap[x+1] := false ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,5,3,4,2} ; var N : int ; N := arr->size() ; var K : int ; K := 3 ; OclFile["System.out"].print(countPairsWithProductK(arr, N, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int sum(int a,int b){ int sum=0 ; for(int i=1 ; i<=Math.min(a,b); i++)if(a % i==0 && b % i==0)sum+=i ; return sum ; } public static void main(String[] args){ int A=10,B=15 ; System.out.print("Sum="+sum(A,B)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sum( a : int, b : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= Set{a, b}->min() do ( if (a mod i = 0 & b mod i = 0) then sum := sum+(i) ; else skip ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 10 ; var B : int ; B := 15 ; OclFile["System.out"].print("Sum=" + sum(A, B)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int swapNibbles(int x){ return((x & 0x0F)<<4 |(x & 0xF0)>>4); } public static void main(String arg[]){ int x=100 ; System.out.print(swapNibbles(x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation swapNibbles( x : int) : int pre: true post: true activity: ( return (MathLib.bitwiseOr(((x & 0x0F)*(2->pow(4)))->oclAsType(long),((x & 0xF0)/(2->pow(4)))->oclAsType(long))) ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 100 ; OclFile["System.out"].print(swapNibbles(x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.List ; class Solution { public String[] reorderLogFiles(String[] logs){ Arrays.sort(logs,(log1,log2)->{ String[] split1=log1.split(" ",2); String[] split2=log2.split(" ",2); boolean isDigit1=Character.isDigit(split1[1] .charAt(0)); boolean isDigit2=Character.isDigit(split2[1] .charAt(0)); if(! isDigit1 && ! isDigit2){ int cmp=split1[1] .compareTo(split2[1]); if(cmp!=0)return cmp ; return split1[0] .compareTo(split2[0]); } return isDigit1 ?(isDigit2 ? 0 : 1):-1 ; } ); return logs ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation reorderLogFiles( logs : Sequence(String)) : Sequence(String) pre: true post: true activity: ( logs := OclComparator.sortWith(logs, lambda (log1 , log2) : OclAny in ( var split1 : Sequence(String) ; split1 := log1->split(" ") ; var split2 : Sequence(String) ; split2 := log2->split(" ") ; var isDigit1 : boolean ; isDigit1 := (split1[1+1]->at(0+1) + "")->isMatch("[0-9]") ; var isDigit2 : boolean ; isDigit2 := (split2[1+1]->at(0+1) + "")->isMatch("[0-9]") ; if (not(isDigit1) & not(isDigit2)) then ( var cmp : int ; cmp := split1[1+1]->compareTo(split2[1+1]) ; if (cmp /= 0) then return cmp else skip ; return split1[0+1]->compareTo(split2[0+1]) ) else skip ; return if isDigit1 then (if isDigit2 then 0 else 1 endif) else -1 endif )) ; return logs ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; public class Test { public static void main(String[] args){ Scanner in=new Scanner(System.in); ArrayListarr=new ArrayList<>(); ArrayListans=new ArrayList<>(); int n=in.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( arr := arr->including(in.getCurrent()->toLong()) ) ; i := i + 1 ) ; var swap : int ; swap := 0 ; var m : long ; m := .min(arr) ; var i : int ; i := 0 ; while i < arr->size() do ( ( if (arr->at(i+1) = m) then ( arr := arr.setAt(i+1,"9223372036854775807"->toLong() - 1000) ; m := arr->min() ) else ( swap := swap + 1 ; ans := ans->including(i->oclAsType(long)) ; var temp : long ; temp := arr->at(i+1) ; ans := ans->including(arr->indexOf(m)-1->oclAsType(long)) ; arr := arr.setAt(arr->indexOf(m)-1+1,temp) ; arr := arr.setAt(i+1,"9223372036854775807"->toLong() - 1000) ; m := arr->min() ; ) ) ; i := i + 1 ) ; OclFile["System.out"].println(swap) ; var i : int ; i := 0 ; while i < ans->size() do ( ( OclFile["System.out"].print(ans->at(i+1) + " ") ; if (i mod 2 /= 0 & i /= 0) then OclFile["System.out"].println() ; else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; import java.util.StringTokenizer ; import java.lang.StringBuilder ; import java.lang.Math ; import java.util.HashSet ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); int k=0 ; int[] a=new int[n]; StringTokenizer st=new StringTokenizer(br.readLine()); for(int i=0 ; ia[j]){ min=a[j]; index=j ; } } if(index!=i){ sb.append(i+" "+index); sb.append("\n"); k++; } int t=a[i]; a[i]=a[index]; a[index]=t ; } System.out.println(k); System.out.print(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var k : int ; k := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( var min : int ; min := a[i+1] ; var index : int ; index := i ; var j : int ; j := i ; while j < n do ( ( if (min > a[j+1]) then ( min := a[j+1] ; index := j ) else skip ) ; j := j + 1 ) ; if (index /= i) then ( sb := sb + StringLib.newString(i + " " + index) ; sb := sb + StringLib.newString("\n") ; k := k + 1 ) else skip ; var t : int ; t := a[i+1] ; a[i+1] := a[index+1] ; a[index+1] := t ; ) ; i := i + 1 ) ; OclFile["System.out"].println(k) ; OclFile["System.out"].print(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void swap(int[] arr,int l,int r){ int temp=arr[l]; arr[l]=arr[r]; arr[r]=temp ; } public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := 0 ; c[i+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var temp : int ; temp := a[i+1] ; var mn : int ; mn := 2147483647 ; var j : int ; j := i ; while j < n do ( ( mn := Set{mn, a[j+1]}->min() ) ; j := j + 1 ) ; var j : int ; j := i ; while j < n do ( ( if (mn = a[j+1]) then ( execute swap(a, i, j) ; if (a[i+1] = temp) then ( break ) else skip ; cnt := cnt + 1 ; b[cnt+1] := i ; c[cnt+1] := j ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; var i : int ; i := 1 ; while i <= cnt do ( ( OclFile["System.out"].println(b[i+1] + " " + c[i+1]) ) ; i := i + 1 ) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ValuableResources { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); if(scanner.hasNext()){ int n=scanner.nextInt(); int lx=-1000000000 ; int hx=1000000000 ; int ly=-1000000000 ; int hy=1000000000 ; while(n-->0){ int x=scanner.nextInt(); int y=scanner.nextInt(); lx=Math.max(lx,x); hx=Math.min(hx,x); ly=Math.max(ly,y); hy=Math.min(hy,y); } int p=Math.max((lx-hx),(ly-hy)); System.out.println((long)p*p); } } } ------------------------------------------------------------ OCL File: --------- class ValuableResources { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; if (scanner.hasNext()) then ( var n : int ; n := scanner.getCurrent()->toInteger() ; var lx : int ; lx := -1000000000 ; var hx : int ; hx := 1000000000 ; var ly : int ; ly := -1000000000 ; var hy : int ; hy := 1000000000 ; while (n > 0) do ( n := n - 1 ; skip ; ( var x : int ; x := scanner.getCurrent()->toInteger() ; var y : int ; y := scanner.getCurrent()->toInteger() ; lx := Set{lx, x}->max() ; hx := Set{hx, x}->min() ; ly := Set{ly, y}->max() ; hy := Set{hy, y}->min() ; ) ; ) ; var p : int ; p := Set{(lx - hx), (ly - hy)}->max() ; OclFile["System.out"].println(p->oclAsType(long) * p) ; ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String tes=null ; char c=0 ; ArrayListal=new ArrayList(); ArrayListal2=new ArrayList(); ArrayListal3=new ArrayList(); while(true){ try { tes=br.readLine(); } catch(IOException e){ e.printStackTrace(); } if(tes==null){ break ; } if(tes.equals("")){ break ; } try { String[] fruit=tes.split(" ",0); al.add(Integer.parseInt(fruit[0])); al2.add(Integer.parseInt(fruit[1])); al3.add(Integer.parseInt(fruit[2])); } catch(NumberFormatException e){ break ; } } for(int r=0 ; rsplit(" ") ; al := al->including((fruit[0+1])->toInteger()) ; al2 := al2->including((fruit[1+1])->toInteger()) ; al3 := al3->including((fruit[2+1])->toInteger()) ) catch (e : IncorrectElementException) do ( break ) ) ; var r : int ; r := 0 ; while r < al->size() do ( ( var e : boolean ; e := false ; var pri : int ; pri := 0 ; var i : int ; i := 1 ; while i <= 10 do ( ( if (al->at(r+1) = i or al2->at(r+1) = i or al3->at(r+1) = i) then ( continue ) else skip ; if (al->at(r+1) + al2->at(r+1) + i <= 20) then ( pri := pri + 1 ) else skip ) ; i := i + 1 ) ; if (pri <= 3) then ( e := true ) else skip ; if (e) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ) ; ) ; r := r + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class ch1 { public static void main(String[] args){ int n,k ; Scanner reader=new Scanner(System.in); n=reader.nextInt(); k=reader.nextInt(); char[] b=new char[n]; int i,j,l=0 ; String str=reader.next(); boolean flag2=true ; for(i=0 ; imax1 ? max : max1); } } } ------------------------------------------------------------ OCL File: --------- class ch1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; var k : int ; var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := reader.getCurrent()->toInteger() ; k := reader.getCurrent()->toInteger() ; var b : Sequence(String) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; var j : int ; var l : int ; l := 0 ; var str : String ; str := reader.getCurrent() ; var flag2 : boolean ; flag2 := true ; i := 0 ; while i < n do ( ( var flag : boolean ; flag := true ; j := 0 ; while j < k - 1 do ( ( if (i + 1 = n) then ( flag := false ; i := i + 1 ; break ) else skip ; if (str->at(i+1) /= str->at((i + 1)+1)) then ( flag := false ; break ) else skip ) ; j := j + 1 ) ; if (flag) then ( b[l+1] := str->at(i+1) ; l := l + 1 ; flag2 := false ) else i := i - 1 ; ) ; i := i + 1 ) ; if (flag2) then OclFile["System.out"].println("0") else ( b := b.subrange(1,0)^(b.subrange(0+1,l)->sort())^b.subrange(l+1,b.size) ; var max : int ; max := 1 ; var max1 : int ; max1 := 1 ; i := 0 ; while i < l - 1 do ( ( if (b[i+1] = b[i + 1+1]) then max1 := max1 + 1 ; else ( if (max < max1) then max := max1 ; else skip ; max1 := 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(if max > max1 then max else max1 endif) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class B { static int[] arr ; public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),k=in.nextInt(); char[] s=in.next().toCharArray(); pw.println(solve(n,k,s)); pw.close(); } static int solve(int n,int k,char[] s){ int res=0 ; for(int i=0 ; i<26 ; i++){ char c=(char)('a'+i); int cnt=0 ; int demoRes=0 ; for(int j=0 ; jtoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var s : Sequence(String) ; s := in.getCurrent()->characters() ; skip ; skip ; ); static operation solve( n : int, k : int, s : Sequence(String)) : int pre: true post: true activity: ( var res : int ; res := 0 ; var i : int ; i := 0 ; while i < 26 do ( ( var c : String ; c := ('a' + i)->oclAsType(String) ; var cnt : int ; cnt := 0 ; var demoRes : int ; demoRes := 0 ; var j : int ; j := 0 ; while j < n do ( ( if (s[j+1] = c) then ( cnt := cnt + 1 ) else cnt := 0 ; ; if (cnt = k) then ( demoRes := demoRes + 1 ; cnt := 0 ) else skip ) ; j := j + 1 ) ; res := Set{demoRes, res}->max() ; ) ; i := i + 1 ) ; return res ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { private static boolean isValidString(String str,int n){ int index=str.indexOf("b"); if(index==0)return false ; while(index!=-1){ if(str.charAt(index-1)!='a')return false ; if(index+1indexOf("b")-1 ; if (index = 0) then return false else skip ; while (index /= -1) do ( if (str->at(index - 1+1) /= 'a') then return false else skip ; if (index + 1 < n & str->at(index + 1+1) /= 'b') then return false else skip ; if (index + 2 < n & str->at(index + 2+1) = 'b') then return false else skip ; if (index = n - 1) then return false else skip ; index := str.subrange(index + 2+1)->indexOf("b"+"") + index + 2 - 1 ; ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "abbaaabbabba" ; var n : int ; n := str->size() ; OclFile["System.out"].println(isValidString(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static class TriTree { Node root=new Node(); class Node { ArrayListchild=new ArrayList<>(); char c ; long depth ; public void add(Node node){ child.add(node); } public Node(){ } public Node(char c,long depth){ this.c=c ; this.depth=depth ; } public long xorGrundy(){ long xor=0 ; for(Node node : child)xor ^=node.xorGrundy(); if(child.size()==1)xor ^=grundy(L-depth); return xor ; } } public void addLeaf(String s){ Node cur=root ; for(int i=0 ; iincluding(node) ); static operation newNode() : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: skip; static operation newNode( c : String, depth : long) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(c, depth); return self ); operation initialise( c : String, depth : long) : void pre: true post: true activity: ( self.c := c ; self.depth := depth ); operation xorGrundy() : long pre: true post: true activity: ( var xor : long ; xor := 0 ; for (node : child) do ( xor := MathLib.bitwiseXor(xor,node.xorGrundy()) ; ) ; if (child->size() = 1) then xor := MathLib.bitwiseXor(xor,grundy(L - depth)) ; else skip ; return xor ); } operation addLeaf( s : String) : void pre: true post: true activity: ( var cur : Node ; cur := root ; var i : int ; i := 0 ; while i < s->size() do ( ( var found : boolean ; found := false ; for (child : cur.child) do ( ( if (child.c = s->at(i+1)) then ( cur := child ; found := true ; break ) else skip ) ) ; if (not(found)) then ( var next : Node ; next := Node.newNode(s->at(i+1), i + 1) ; cur->excludes(next) ; cur := next ) else skip ) ; i := i + 1 ) ); operation xorGrundy() : long pre: true post: true activity: ( return root.xorGrundy() ); } static attribute L : long; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; L := sc.getCurrent()->toLong() ; var tree : TriTree ; tree := TriTree.newTriTree() ; var i : int ; i := 0 ; while i < N do ( tree.addLeaf(sc.getCurrent()) ; ; i := i + 1 ) ; OclFile["System.out"].println(if tree.xorGrundy() = 0 then "Bob" else "Alice" endif) ; skip ; ); static operation grundy( n : long) : long pre: true post: true activity: ( var ans : long ; ans := 1 ; while (n mod ans = 0) do ans := ans*(2->pow(1)) ; ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; while((line=br.readLine())!=null && ! line.isEmpty()){ int N,Q ; N=Integer.parseInt(line.substring(0,line.indexOf(' '))); Q=Integer.parseInt(line.substring(line.indexOf(' ')+1)); int[] years=new int[51]; String[] names=new String[N+1]; int yearPrev=1 ; int idxPrev=0 ; names[idxPrev]="kogakubu10gokan" ; for(int i=0 ; iisEmpty())) do ( skip ; ( var N : int ; var Q : int ; N := (line.subrange(0+1,line->indexOf(' ')-1))->toInteger() ; Q := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1))->toInteger() ; var years : Sequence(int) ; years := Integer.subrange(1,51)->collect(0) ; var names : Sequence(String) ; names := Integer.subrange(1,N + 1)->collect(null) ; var yearPrev : int ; yearPrev := 1 ; var idxPrev : int ; idxPrev := 0 ; names[idxPrev+1] := "kogakubu10gokan" ; var i : int ; i := 0 ; while i < N do ( ( line := br.readLine() ; var yearNext : int ; yearNext := (line.subrange(0+1,line->indexOf(' ')-1))->toInteger() ; names[idxPrev + 1+1] := line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) ; var j : int ; j := yearPrev ; while j < yearNext do ( ( years[j+1] := idxPrev ) ; j := j + 1 ) ; yearPrev := yearNext ; idxPrev := idxPrev + 1 ; ) ; i := i + 1 ) ; var j : int ; j := yearPrev ; while j < 51 do ( ( years[j+1] := idxPrev ) ; j := j + 1 ) ; OclFile["System.out"].println(names[years[Q+1]+1]) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,q,i ; int[] y ; String[] name ; n=sc.nextInt(); q=sc.nextInt(); y=new int[n]; name=new String[n]; for(i=0 ; icollect(0) ; name := Integer.subrange(1,n)->collect(null) ; i := 0 ; while i < n do ( ( y[i+1] := sc.nextInt() ; name[i+1] := sc.next() ) ; i := i + 1 ) ; i := 0 ; while i < n do ( if (q < y[i+1]) then ( if (i = 0) then out.println("kogakubu10gokan") else out.println(name[i - 1+1]) ; ; break ) else skip ; ; i := i + 1 ) ; if (i = n) then out.println(name[i - 1+1]) ; else skip ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int q=sc.nextInt(); boolean f=false ; String ans="" ; String pre="kogakubu10gokan" ; for(int i=0 ; iq){ f=true ; ans=pre ; } pre=nex ; } if(ans.equals(""))ans=pre ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var f : boolean ; f := false ; var ans : String ; ans := "" ; var pre : String ; pre := "kogakubu10gokan" ; var i : int ; i := 0 ; while i < n do ( ( var y : int ; y := sc.getCurrent()->toInteger() ; var nex : String ; nex := sc.getCurrent() ; if (not(f) & y > q) then ( f := true ; ans := pre ) else skip ; pre := nex ) ; i := i + 1 ) ; if (ans = "") then ans := pre ; else skip ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Main { static int max ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int q=sc.nextInt(); Data[] list=new Data[n+1]; Calendar cal=Calendar.getInstance(); cal.clear(); cal.set(Calendar.YEAR,1989); list[0]=new Data(cal,"kogakubu10gokan"); int ans=0 ; Calendar check=Calendar.getInstance(); check.clear(); check.set(Calendar.YEAR,q+1988); for(int i=1 ; i<=n ; i++){ cal=Calendar.getInstance(); cal.clear(); cal.set(Calendar.YEAR,1988+sc.nextInt()); if(check.compareTo(cal)>=0)ans=i ; list[i]=new Data(cal,sc.next()); } System.out.println(list[ans] .name); } static class Data { Calendar cal ; String name ; Data(Calendar a,String b){ cal=a ; name=b ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute max : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var list : Sequence(Data) ; list := Integer.subrange(1,n + 1)->collect(null) ; var cal : OclDate ; cal := OclDate.newOclDate() ; cal := cal->intersection(Set{}) ; cal := cal.setAt(YEAR+1, 1989) ; list[0+1] := Data.newData(cal, "kogakubu10gokan") ; var ans : int ; ans := 0 ; var check : OclDate ; check := OclDate.newOclDate() ; check := check->intersection(Set{}) ; check := check.setAt(YEAR+1, q + 1988) ; var i : int ; i := 1 ; while i <= n do ( ( cal := OclDate.newOclDate() ; cal := cal->intersection(Set{}) ; cal := cal.setAt(YEAR+1, 1988 + sc.getCurrent()->toInteger()) ; if (check.compareTo(cal) >= 0) then ans := i ; else skip ; list[i+1] := Data.newData(cal, sc.getCurrent()) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(list[ans+1].name) ; ); static class Data { attribute cal : OclDate; attribute name : String; static operation newData( a : OclDate, b : String) : Data pre: true post: true activity: ( var self : Data ; self := createData(); self.initialise(a, b); return self ); operation initialise( a : OclDate, b : String) : void pre: true post: true activity: ( cal := a ; name := b ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int Q=sc.nextInt(); int[] Y=new int[N+2]; String[] name=new String[N+1]; name[0]="kogakubu10gokan" ; for(int i=0 ; itoInteger() ; var Q : int ; Q := sc.getCurrent()->toInteger() ; var Y : Sequence(int) ; Y := Integer.subrange(1,N + 2)->collect(0) ; var name : Sequence(String) ; name := Integer.subrange(1,N + 1)->collect(null) ; name[0+1] := "kogakubu10gokan" ; var i : int ; i := 0 ; while i < N do ( ( Y[i + 1+1] := sc.getCurrent()->toInteger() ; name[i + 1+1] := sc.getCurrent() ) ; i := i + 1 ) ; Y[N + 1+1] := 100 ; var i : int ; i := 0 ; while i < N + 1 do ( ( if (Y[i+1] <= Q & Q < Y[i + 1+1]) then ( OclFile["System.out"].println(name[i+1]) ; break ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int gcd(int a,int b){ if(a==0)return b ; return gcd(b % a,a); } static void findgcd(int n,int x,int y){ int g=gcd(x,y); for(int i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Q22222 { public static void main(String[] args){ Scanner input=new Scanner(System.in); Dequeq1=new ArrayDeque<>(); Dequeq2=new ArrayDeque<>(); int N=input.nextInt(); int C=input.nextInt(); for(int i=0 ; i1){ if(q1.peek()-C>=1){ q1.addLast(q1.pop()-C); q2.addLast(q2.pop()); } else { q1.removeFirst(); q2.removeFirst(); } if(q1.size()==1)break ; } System.out.println(q2.peek()); } } ------------------------------------------------------------ OCL File: --------- class Q22222 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q1 : Sequence(int) ; q1 := ArrayDeque.newArrayDeque() ; var q2 : Sequence(int) ; q2 := ArrayDeque.newArrayDeque() ; var N : int ; N := input.getCurrent()->toInteger() ; var C : int ; C := input.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < N do ( ( q1 := q1->append(input.getCurrent()->toInteger()) ; q2 := q2->append(i + 1) ) ; i := i + 1 ) ; while (q2->size() > 1) do ( if (q1->min() - C >= 1) then ( q1 := q1->append(q1->last() - C) ; q2 := q2->append(q2->last()) ) else ( q1 := q1->tail() ; q2 := q2->tail() ) ; if (q1->size() = 1) then break else skip ) ; OclFile["System.out"].println(q2->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { final static int number_of_cards=10 ; final static int max_number=20 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int card1=sc.nextInt(); int card2=sc.nextInt(); int card3=sc.nextInt(); int sum=card1+card2 ; boolean used_card[]=new boolean[number_of_cards+1]; used_card[card1]=true ; used_card[card2]=true ; used_card[card3]=true ; int count=0 ; for(int i=1 ; i<=number_of_cards ; ++i){ if(! used_card[i] && sum+i<=max_number){ ++count ; } } System.out.println(judge(count)); } } private static String judge(int count){ return((double)count/(double)(number_of_cards-3)>=0.5)? "YES" : "NO" ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute number_of_cards : int := 10; static attribute max_number : int := 20; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var card1 : int ; card1 := sc.getCurrent()->toInteger() ; var card2 : int ; card2 := sc.getCurrent()->toInteger() ; var card3 : int ; card3 := sc.getCurrent()->toInteger() ; var sum : int ; sum := card1 + card2 ; var used_card : Sequence(boolean) ; used_card := Integer.subrange(1,number_of_cards + 1)->collect(false) ; used_card[card1+1] := true ; used_card[card2+1] := true ; used_card[card3+1] := true ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i <= number_of_cards do ( ( if (not(used_card[i+1]) & sum + i <= max_number) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(judge(count)) ; ) ); static operation judge( count : int) : String pre: true post: true activity: ( return if (count->oclAsType(double) / (number_of_cards - 3)->oclAsType(double) >= 0.5) then "YES" else "NO" endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class codeforces { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[][]=new int[n][2]; int min=Integer.MAX_VALUE ; int max=Integer.MIN_VALUE ; int i ; for(i=0 ; itoInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var min : int ; min := 2147483647 ; var max : int ; max := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1][0+1] := sc.getCurrent()->toInteger() ; a[i+1][1+1] := sc.getCurrent()->toInteger() ; min := Set{min, a[i+1][0+1]}->min() ; max := Set{max, a[i+1][0+1]}->max() ) ; i := i + 1 ) ; var ans : long ; ans := (max - min)->oclAsType(long) * (max - min) ; min := 2147483647 ; max := -2147483648 ; i := 0 ; while i < n do ( ( min := Set{min, a[i+1][1+1]}->min() ; max := Set{max, a[i+1][1+1]}->max() ) ; i := i + 1 ) ; ans := Set{ans, (max - min)->oclAsType(long) * (max - min)}->max() ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static final int MP=200010 ; public static final int MSN=100010 ; public static class p { int bp ; int dp ; } public static void main(String[] args){ int P1=0,P2=0 ; p[] pas=new p[MP]; int[] igo=new int[MSN]; int[] agon=new int[MSN]; int[] agoff=new int[MSN]; Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); for(int i=0 ; icollect(null) ; var igo : Sequence(int) ; igo := Integer.subrange(1,MSN)->collect(0) ; var agon : Sequence(int) ; agon := Integer.subrange(1,MSN)->collect(0) ; var agoff : Sequence(int) ; agoff := Integer.subrange(1,MSN)->collect(0) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( pas[i+1] := p.newp() ; pas[i+1].bp := (sc.getCurrent())->toInteger() ; pas[i+1].dp := (sc.getCurrent())->toInteger() ; igo[pas[i+1].bp+1] := igo[pas[i+1].bp+1] + 1 ; igo[pas[i+1].dp+1] := igo[pas[i+1].dp+1] - 1 ; agon[pas[i+1].bp+1] := agon[pas[i+1].bp+1] + 1 ; agoff[pas[i+1].dp+1] := agoff[pas[i+1].dp+1] + 1 ; ) ; i := i + 1 ) ; var j : int ; j := 1 ; while j < MSN do ( ( igo[j+1] := igo[j+1]+(igo[j - 1+1]) ; agon[j+1] := agon[j+1]+(agon[j - 1+1]) ; agoff[j+1] := agoff[j+1]+(agoff[j - 1+1]) ; if (P2 < igo[j+1]) then ( P2 := igo[j+1] ) else skip ) ; j := j + 1 ) ; var k : int ; k := 0 ; while k < n do ( ( if (P1 < (agon[pas[k+1].dp - 1+1] - agoff[pas[k+1].bp+1])) then ( P1 := agon[pas[k+1].dp - 1+1] - agoff[pas[k+1].bp+1] ) else skip ) ; k := k + 1 ) ; OclFile["System.out"].println(P1 + " " + P2) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); char[] N=sc.next().toCharArray(); int ans=0 ; int acum=0 ; for(int i=0 ; icharacters() ; var ans : int ; ans := 0 ; var acum : int ; acum := 0 ; var i : int ; i := 0 ; while i < N->size() do ( ( acum := acum+(N[i+1] - ('0')->char2byte()) ; ans := Set{ans, acum}->max() ; ans := Set{ans, acum - 1 + (N->size() - i - 1) * 9}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); String str=in.nextLine(); if(str.length()==1){ System.out.println(str); return ; } long num=Long.parseLong(str.substring(1)); int ans=Integer.parseInt(str.substring(0,1))+9*(str.length()-1); if(numsize() = 1) then ( OclFile["System.out"].println(str) ; return ) else skip ; var num : long ; num := (str.subrange(1+1,1))->toLong() ; var ans : int ; ans := (str.subrange(0+1,1))->toInteger() + 9 * (str->size() - 1) ; if (num < 10->pow(str->size() - 1) - 1) then ( ans := ans - 1 ) else skip ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { Reader.init(System.in); String N=Reader.next(); int p=1 ; String tem=""+N.charAt(0); for(int i=0 ; iat(0+1) ; var i : int ; i := 0 ; while i < N->size() - 1 do ( ( tem := tem+("9") ) ; i := i + 1 ) ; if (tem = N) then ( OclFile["System.out"].println((9 * (N->size() - 1) + (N->at(0+1) - ('0')->char2byte()))) ) else ( OclFile["System.out"].println((9 * (N->size() - 1) + (N->at(0+1) - ('1')->char2byte()))) ) ; ); } class Reader { static attribute reader : OclFile; static attribute tokenizer : OclIterator; static operation init( input : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(input)) ; tokenizer := OclIterator.newOclIterator_String("") ); static operation nextToken() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); static operation next() : String pre: true post: true activity: ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ; return tokenizer.next() ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); static operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.out ; import java.awt.image.IndexColorModel ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ long N=sc.nextLong(); ArrayListlist=new ArrayList(); String[] str=String.valueOf(N).split(""); int length=str.length ; int[] array=createInt(str,length); list.add(plusN(array,length)); boolean flag=length==1 ; list.add(squat(length-1,array)); System.out.println(Math.max(list.get(0),list.get(1))); } static int squat(int length,int[] array){ return array[0]+length*9-1 ; } static int[] createInt(String[] str,int length){ int[] array=new int[length]; int i=0 ; for(String s : str){ array[i++]=Integer.parseInt(s); } return array ; } static int plusN(int[] str,int length){ int count=0 ; for(int s : str){ count+=s ; } return count ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : long ; N := sc.getCurrent()->toLong() ; var list : Sequence(int) ; list := Sequence{} ; var str : Sequence(String) ; str := ((N) + "")->split("") ; var length : int ; length := str->size() ; var array : Sequence(int) ; array := createInt(str, length) ; list := list->including(plusN(array, length)) ; var flag : boolean ; flag := length = 1 ; list := list->including(squat(length - 1, array)) ; OclFile["System.out"].println(Set{list->at(0+1), list->at(1+1)}->max()) ; ); static operation squat( length : int, array : Sequence(int)) : int pre: true post: true activity: ( return array[0+1] + length * 9 - 1 ); static operation createInt( str : Sequence(String), length : int) : Sequence(int) pre: true post: true activity: ( var array : Sequence(int) ; array := Integer.subrange(1,length)->collect(0) ; var i : int ; i := 0 ; for (s : str) do ( ( array[i+1] := (s)->toInteger() ; i := i + 1 ) ) ; return array ); static operation plusN( str : Sequence(int), length : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; for (s : str) do ( ( count := count+(s) ) ) ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { private static Scanner sc ; private static Printer pr ; private static void solve(){ long n=sc.nextLong(); int max=cnt(n); for(int i=1 ; true ; i++){ long tmp=n+1 ; for(int j=0 ; j0){ cnt+=tmp % 10 ; tmp/=10 ; } return cnt ; } public static void main(String[] args){ sc=new Scanner(System.in); pr=new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out){ super(out); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile; static attribute pr : Printer; static operation solve() : void pre: true post: true activity: ( var n : long ; n := sc.getCurrent()->toLong() ; var max : int ; max := cnt(n) ; var i : int ; i := 1 ; while true do ( ( var tmp : long ; tmp := n + 1 ; var j : int ; j := 0 ; while j < i do ( ( tmp := tmp/(10) ) ; j := j + 1 ) ; tmp := tmp-(1) ; if (tmp < 0) then ( break ) else skip ; var j : int ; j := 0 ; while j < i do ( ( tmp := tmp*(10) ; tmp := tmp+(9) ) ; j := j + 1 ) ; max := Set{max, cnt(tmp)}->max() ; ) ; i := i + 1 ) ; pr.println(max) ); static operation cnt( n : long) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var tmp : long ; tmp := n ; while (tmp > 0) do ( cnt := cnt+(tmp mod 10) ; tmp := tmp/(10) ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; pr := Printer.newPrinter(OclFile["System.out"]) ; execute solve() ; pr.close() ; skip ; ); static class Printer extends OclFile { static operation newPrinter( out : OclFile) : Printer pre: true post: true activity: ( var self : Printer ; self := createPrinter(); self.initialise(out); return self ); operation initialise( out : OclFile) : void pre: true post: true activity: ( execute super(out) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void PowerOfTwo(int[] x,int n){ Arrays.sort(x); ArrayListres=new ArrayList(); for(int i=0 ; isort() ; var res : Sequence(int) ; res := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 1 ; while j < 31 do ( ( var lx : int ; lx := x[i+1] - ((1*(2->pow(j)))->oclAsType(long)) ; var rx : int ; rx := x[i+1] + ((1*(2->pow(j)))->oclAsType(long)) ; var isl : boolean ; isl := if (x->indexOf(lx) - 1) < 0 then false else true endif ; var isr : boolean ; isr := if (x->indexOf(rx) - 1) < 0 then false else true endif ; if (isl & isr & res->size() < 3) then ( res := res->intersection(Set{}) ; res := res->including(lx) ; res := res->including(x[i+1]) ; res := res->including(rx) ) else skip ; if (isl & res->size() < 2) then ( res := res->intersection(Set{}) ; res := res->including(lx) ; res := res->including(x[i+1]) ) else skip ; if (isr & res->size() < 2) then ( res := res->intersection(Set{}) ; res := res->including(x[i+1]) ; res := res->including(rx) ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (res->size() = 0) then ( OclFile["System.out"].println("-1") ; return ) else skip ; var i : int ; i := 0 ; while i < res->size() do ( OclFile["System.out"].print(res->at(i+1) + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{3,4,5,6,7} ; var n : int ; n := a->size() ; execute PowerOfTwo(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int[] dp=new int[1024]; static int get_binary(int u){ int ans=0 ; while(u>0){ int rem=u % 10 ; ans |=(1<collect(0); static operation get_binary( u : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; while (u > 0) do ( var rem : int ; rem := u mod 10 ; ans := MathLib.bitwiseOr(ans, ((1*(2->pow(rem)))->oclAsType(long))) ; u := u/(10) ) ; return ans ); static operation recur( u : int, array : Sequence(int), n : int) : int 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 i : int ; i := 0 ; while i < n do ( ( var mask : int ; mask := get_binary(array[i+1]) ; if ((MathLib.bitwiseOr(mask,u)) = u) then ( dp[u+1] := Set{Set{0, dp[u xor mask+1]}->max() + array[i+1], dp[u+1]}->max() ) else skip ) ; i := i + 1 ) ; return dp[u+1] ); static operation solve( array : Sequence(int), n : int) : int pre: true post: true activity: ( var i : int ; i := 0 ; while i < ((1*(2->pow(10)))->oclAsType(long)) do ( ( dp[i+1] := -1 ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < ((1*(2->pow(10)))->oclAsType(long)) do ( ( ans := Set{ans, recur(i, array, n)}->max() ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var array : Sequence(int) ; array := Sequence{22,132,4,45,12,223} ; var n : int ; n := array->size() ; OclFile["System.out"].println(solve(array, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int a ; int[] check ; int i,sum ; check=new int[10]; for(; sc.hasNext(); ){ for(i=0 ; i<10 ; i++)check[i]=0 ; sum=0 ; a=sc.nextInt(); sum+=a ; for(i=0 ; i<10 ; i++)if(a==i+1)check[a-1]++; a=sc.nextInt(); sum+=a ; for(i=0 ; i<10 ; i++)if(a==i+1)check[a-1]++; a=sc.nextInt(); for(i=0 ; i<10 ; i++)if(a==i+1)check[a-1]++; a=0 ; for(i=0 ; i<10 ; i++)if(i+1<=20-sum && check[i]==0)a++; if(a>3)out.println("YES"); else out.println("NO"); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var a : int ; var check : Sequence(int) ; var i : int ; var sum : int ; check := Integer.subrange(1,10)->collect(0) ; while sc.hasNext() do ( ( i := 0 ; while i < 10 do ( check[i+1] := 0 ; ; i := i + 1 ) ; sum := 0 ; a := sc.nextInt() ; sum := sum+(a) ; i := 0 ; while i < 10 do ( if (a = i + 1) then check[a - 1+1] := check[a - 1+1] + 1 ; else skip ; ; i := i + 1 ) ; a := sc.nextInt() ; sum := sum+(a) ; i := 0 ; while i < 10 do ( if (a = i + 1) then check[a - 1+1] := check[a - 1+1] + 1 ; else skip ; ; i := i + 1 ) ; a := sc.nextInt() ; i := 0 ; while i < 10 do ( if (a = i + 1) then check[a - 1+1] := check[a - 1+1] + 1 ; else skip ; ; i := i + 1 ) ; a := 0 ; i := 0 ; while i < 10 do ( if (i + 1 <= 20 - sum & check[i+1] = 0) then a := a + 1 ; else skip ; ; i := i + 1 ) ; if (a > 3) then out.println("YES") else out.println("NO") ; ; ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findMaxOddSubarraySum(int arr[],int n){ int min_odd=Integer.MAX_VALUE ; boolean isOdd=false ; int sum=0 ; for(int i=0 ; i0)sum=sum+arr[i]; if(arr[i] % 2!=0){ isOdd=true ; if(min_odd>Math.abs(arr[i]))min_odd=Math.abs(arr[i]); } } if(isOdd==false)return-1 ; if(sum % 2==0)sum=sum-min_odd ; return sum ; } public static void main(String[] args){ int arr[]={ 2,-3,5,-1,4 }; int n=arr.length ; System.out.println(findMaxOddSubarraySum(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findMaxOddSubarraySum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var min_odd : int ; min_odd := 2147483647 ; var isOdd : boolean ; isOdd := false ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n 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 > if arr[i+1] < 0 then -(arr[i+1]) else arr[i+1] endif) then min_odd := if arr[i+1] < 0 then -(arr[i+1]) else arr[i+1] endif ; else skip ) else skip ) ; i := i + 1 ) ; if (isOdd = false) then return -1 else skip ; if (sum mod 2 = 0) then sum := sum - min_odd ; else skip ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,-3,5,-1,4} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findMaxOddSubarraySum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean allBitsSetInTheGivenRange(int n,int l,int r){ int num=((1<pow(r)))->oclAsType(long)) - 1),(((1*(2->pow((l - 1))))->oclAsType(long)) - 1)) ; var new_num : int ; new_num := MathLib.bitwiseAnd(n,num) ; if (new_num = 0) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 17 ; var l : int ; l := 2 ; var r : int ; r := 4 ; if (allBitsSetInTheGivenRange(n, l, r)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int cs=sc.nextInt(); for(int dz=0 ; dzset=new HashSet<>(); for(int dz2=section[dz1][0]; dz2<=section[dz1][1]; dz2++)set.add(dz2); for(int dz2=0 ; dz20){ if((m*p+n*q)%(m*m+n*n)==0 &&(m*q-n*p)%(m*m+n*n)==0){ flag=true ; break J ; } } } } } if(flag)out.println("C"); else out.println("P"); } } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(in); operation isSquare( n : int) : int pre: true post: true activity: ( var i : int ; i := (n)->sqrt()->oclAsType(int) ; while i * i <= n do ( ( if (i * i = n) then return i else skip ) ; i := i + 1 ) ; return -1 ); operation run() : void pre: true post: true activity: ( var a : int ; a := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < a do ( ( var p : int ; p := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var pq2 : int ; pq2 := p * p + q * q ; if (pq2 <= 1) then ( out.println("C") ) else ( var flag : boolean ; flag := false ; var j : int ; j := 2 ; while j * j <= pq2 do ( ( if (pq2 mod j = 0) then ( var m : int ; m := 0 ; while m * m <= j do ( ( var n : int ; if ((n) > 0) then ( if ((m * p + n * q) mod (m * m + n * n) = 0 & (m * q - n * p) mod (m * m + n * n) = 0) then ( flag := true ; break ) else skip ) else skip ) ; m := m + 1 ) ) else skip ) ; j := j + 1 ) ; if (flag) then out.println("C") ; else out.println("P") ; ) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static long getPowMod(long n,long mod){ if(n==0)return 1L % mod ; if(n==1)return 3L % mod ; long res=getPowMod(n/2,mod)% mod ; if(n % 2==0)return(res*res)% mod ; return(res*res*3L)% mod ; } public static void main(String[] arg){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int m=scanner.nextInt(); System.out.println((getPowMod(n,m)+m-1)% m); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation getPowMod( n : long, mod : long) : long pre: true post: true activity: ( if (n = 0) then return 1L mod mod else skip ; if (n = 1) then return 3L mod mod else skip ; var res : long ; res := getPowMod(n / 2, mod) mod mod ; if (n mod 2 = 0) then return (res * res) mod mod else skip ; return (res * res * 3L) mod mod ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println((getPowMod(n, m) + m - 1) mod m) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static long getPowMod(long n,long mod){ if(n==0)return 1L % mod ; if(n==1)return 3L % mod ; long res=getPowMod(n/2,mod)% mod ; if(n % 2==0)return(res*res)% mod ; return(res*res*3L)% mod ; } public static void main(String[] arg){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int m=scanner.nextInt(); if(m==1){ System.out.println(0); return ; } long res=getPowMod(n,m); if(res==0){ System.out.println((m-1)); } else { System.out.println((res-1)% m); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation getPowMod( n : long, mod : long) : long pre: true post: true activity: ( if (n = 0) then return 1L mod mod else skip ; if (n = 1) then return 3L mod mod else skip ; var res : long ; res := getPowMod(n / 2, mod) mod mod ; if (n mod 2 = 0) then return (res * res) mod mod else skip ; return (res * res * 3L) mod mod ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; if (m = 1) then ( OclFile["System.out"].println(0) ; return ) else skip ; var res : long ; res := getPowMod(n, m) ; if (res = 0) then ( OclFile["System.out"].println((m - 1)) ) else ( OclFile["System.out"].println((res - 1) mod m) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class C { private static long binPow(long a,long n,long m){ if(n==0){ return 1 ; } if(n==1){ return a % m ; } if(n % 2==0){ long c=binPow(a,n/2,m)% m ; return(c*c)% m ; } else { return(binPow(a,n-1,m)*a)% m ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(),m=sc.nextLong(); long ans=binPow(3,n,m)-1 ; if(ans<0)ans+=m ; System.out.print(ans); } } ------------------------------------------------------------ OCL File: --------- class C { static operation binPow( a : long, n : long, m : long) : long pre: true post: true activity: ( if (n = 0) then ( return 1 ) else skip ; if (n = 1) then ( return a mod m ) else skip ; if (n mod 2 = 0) then ( var c : long ; c := binPow(a, n / 2, m) mod m ; return (c * c) mod m ) else ( return (binPow(a, n - 1, m) * a) mod m ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var m : long ; m := sc.getCurrent()->toLong() ; var ans : long ; ans := binPow(3, n, m) - 1 ; if (ans < 0) then ans := ans+(m) ; else skip ; OclFile["System.out"].print(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); CF_226A solver=new CF_226A(); solver.solve(1,in,out); out.close(); } static class CF_226A { public void solve(int testNumber,Scanner input,PrintWriter out){ ShortScanner in=new ShortScanner(input); int n=in.i(),m=in.i(); long ans=(((3 % m)*(exp(3,n-1,m)-1)% m)% m+2 % m)% m ; out.println((ans+m)% m); } long exp(long x,int e,int m){ long rs=1 ; while(e>0){ if(e % 2>0){ rs=(rs % m*(x % m))% m ; } x=(x*x)% m ; e>>=1 ; } return(long)(rs % m); } class ShortScanner { Scanner in ; ShortScanner(Scanner in){ this.in=in ; } int i(){ return in.nextInt(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : CF var solver : OclFile ; solver := CF()26A.newCF()26A()26A ; solver := CF()26A.newCF()26A() ; solver.solve(1, in, out) ; skip ; ); static class CF{ operation solve( testNumber : int, input : OclFile, out : OclFile) : void pre: true post: true activity: ( var in : ShortScanner ; in := ShortScanner.newShortScanner(input) ; var n : int ; n := in.i() ; var m : int ; m := in.i() ; var ans : long ; ans := (((3 mod m) * (exp(3, n - 1, m) - 1) mod m) mod m + 2 mod m) mod m ; skip ); operation exp( x : long, e : int, m : int) : long pre: true post: true activity: ( var rs : long ; rs := 1 ; while (e > 0) do ( if (e mod 2 > 0) then ( rs := (rs mod m * (x mod m)) mod m ) else skip ; x := (x * x) mod m ; e := e/(2->pow(1)) ) ; return (rs mod m)->oclAsType(long) ); class ShortScanner { attribute in : OclFile; static operation newShortScanner( in : OclFile) : ShortScanner pre: true post: true activity: ( var self : ShortScanner ; self := createShortScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( self.in := in ); operation i() : int pre: true post: true activity: ( return in.getCurrent()->toInteger() ); } } 26A { operation solve( testNumber : int, input : OclFile, out : OclFile) : void pre: true post: true activity: ( var in : ShortScanner ; in := ShortScanner.newShortScanner(input) ; var n : int ; n := in.i() ; var m : int ; m := in.i() ; var ans : long ; ans := (((3 mod m) * (exp(3, n - 1, m) - 1) mod m) mod m + 2 mod m) mod m ; skip ); operation exp( x : long, e : int, m : int) : long pre: true post: true activity: ( var rs : long ; rs := 1 ; while (e > 0) do ( if (e mod 2 > 0) then ( rs := (rs mod m * (x mod m)) mod m ) else skip ; x := (x * x) mod m ; e := e/(2->pow(1)) ) ; return (rs mod m)->oclAsType(long) ); class ShortScanner { attribute in : OclFile; static operation newShortScanner( in : OclFile) : ShortScanner pre: true post: true activity: ( var self : ShortScanner ; self := createShortScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( self.in := in ); operation i() : int pre: true post: true activity: ( return in.getCurrent()->toInteger() ); } } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class FlyingSaucerSegments { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); long n=in.nextLong(); long mod=in.nextLong(); long ans=fastPow(3,n,mod)-1 ; if(ans==-1)ans+=mod ; out.println(ans); out.close(); } static long fastPow(long a,long b,long mod){ if(b==0)return 1L ; long val=fastPow(a,b/2,mod); if(b % 2==0)return val*val % mod ; else return val*val % mod*a % mod ; } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class FlyingSaucerSegments { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var n : long ; n := in.nextLong() ; var mod : long ; mod := in.nextLong() ; var ans : long ; ans := fastPow(3, n, mod) - 1 ; if (ans = -1) then ans := ans+(mod) ; else skip ; skip ; skip ; ); static operation fastPow( a : long, b : long, mod : long) : long pre: true post: true activity: ( if (b = 0) then return 1L else skip ; var val : long ; val := fastPow(a, b / 2, mod) ; if (b mod 2 = 0) then return val * val mod mod else return val * val mod mod * a mod mod ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileWriter ; import java.io.PrintWriter ; import java.util.Scanner ; public class GCJ_2013_C1 { public static long solve(String s,long n){ long bef_cont=0 ; long bef_noncont=0 ; long endpart=0 ; System.out.println(); for(int i=0 ; i=n){ bef_cont=(i-n+2); } else { bef_cont=bef_cont_prev ; } } else { bef_cont=bef_cont_prev ; endpart=0 ; } } return bef_cont+bef_noncont ; } public static void main(String[] args)throws Exception { String fname="A_large" ; File file=new File(fname+"_in.txt"); Scanner scanner=new Scanner(file); FileWriter outFile=new FileWriter(fname+"_out.txt"); PrintWriter outp=new PrintWriter(outFile); int T=scanner.nextInt(); scanner.nextLine(); for(int i=1 ; i<=T ; i++){ String s=scanner.nextLine(); String sin=s.split(" ")[0]; int n=Integer.parseInt(s.split(" ")[1]); outp.printf("Case #%d: %d\n",i,solve(sin,n)); } outp.close(); } } ------------------------------------------------------------ OCL File: --------- class GCJ{ static operation solve( s : String, n : long) : long pre: true post: true activity: ( var bef_cont : long ; bef_cont := 0 ; var bef_noncont : long ; bef_noncont := 0 ; var endpart : long ; endpart := 0 ; OclFile["System.out"].println() ; var i : int ; i := 0 ; while i < s->size() do ( ( var bef_cont_prev : long ; bef_cont_prev := bef_cont ; var bef_noncont_prev : long ; bef_noncont_prev := bef_noncont ; var c : String ; c := s->at(i+1) ; var cns : boolean ; cns := not(((c = 'a') or (c = 'e') or (c = 'i') or (c = 'o') or (c = 'u'))) ; bef_noncont := bef_noncont_prev + bef_cont_prev ; if (cns) then ( endpart := endpart + 1 ; if (endpart >= n) then ( bef_cont := (i - n + 2) ) else ( bef_cont := bef_cont_prev ) ) else ( bef_cont := bef_cont_prev ; endpart := 0 ) ; ) ; i := i + 1 ) ; return bef_cont + bef_noncont ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fname : String ; fname := "A_large" ; var file : OclFile ; file := OclFile(fname + "_in.txt") ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile.newOclFile(file)) ; var outFile : OclFile ; outFile := OclFile.newOclFile_Write(fname + "_out.txt") ; var outp : OclFile ; outp := OclFile.newOclFile_Write(outFile) ; var T : int ; T := scanner.getCurrent()->toInteger() ; skip ; var i : int ; i := 1 ; while i <= T do ( ( var s : String ; s := scanner.nextLine() ; var sin : String ; sin := s->split(" ")[0+1] ; var n : int ; n := (s->split(" ")[1+1])->toInteger() ; skip ) ; i := i + 1 ) ; skip ; ); } 013_C1 { static operation solve( s : String, n : long) : long pre: true post: true activity: ( var bef_cont : long ; bef_cont := 0 ; var bef_noncont : long ; bef_noncont := 0 ; var endpart : long ; endpart := 0 ; OclFile["System.out"].println() ; var i : int ; i := 0 ; while i < s->size() do ( ( var bef_cont_prev : long ; bef_cont_prev := bef_cont ; var bef_noncont_prev : long ; bef_noncont_prev := bef_noncont ; var c : String ; c := s->at(i+1) ; var cns : boolean ; cns := not(((c = 'a') or (c = 'e') or (c = 'i') or (c = 'o') or (c = 'u'))) ; bef_noncont := bef_noncont_prev + bef_cont_prev ; if (cns) then ( endpart := endpart + 1 ; if (endpart >= n) then ( bef_cont := (i - n + 2) ) else ( bef_cont := bef_cont_prev ) ) else ( bef_cont := bef_cont_prev ; endpart := 0 ) ; ) ; i := i + 1 ) ; return bef_cont + bef_noncont ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fname : String ; fname := "A_large" ; var file : OclFile ; file := OclFile(fname + "_in.txt") ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile.newOclFile(file)) ; var outFile : OclFile ; outFile := OclFile.newOclFile_Write(fname + "_out.txt") ; var outp : OclFile ; outp := OclFile.newOclFile_Write(outFile) ; var T : int ; T := scanner.getCurrent()->toInteger() ; skip ; var i : int ; i := 1 ; while i <= T do ( ( var s : String ; s := scanner.nextLine() ; var sin : String ; sin := s->split(" ")[0+1] ; var n : int ; n := (s->split(" ")[1+1])->toInteger() ; skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int tt=1 ; tt<=t ; tt++){ Integer ara[]=new Integer[3]; Arrays.setAll(ara,i->in.nextInt()); Arrays.sort(ara,Collections.reverseOrder()); int a=ara[0],b=ara[1],c=ara[2]; int count=0 ; if(a!=0){ a--; count++; } if(b!=0){ b--; count++; } if(c!=0){ c--; count++; } if(a!=0 && b!=0){ a--; b--; count++; } if(a!=0 && c!=0){ a--; c--; count++; } if(b!=0 && c!=0){ b--; c--; count++; } if(a!=0 && b!=0 && c!=0){ count++; } System.out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var tt : int ; tt := 1 ; while tt <= t do ( ( var ara : Sequence(int) ; ara := Integer.subrange(1,3)->collect(null) ; setAll(ara, lambda i : OclAny in in.getCurrent()->toInteger()) ; ara := OclComparator.sortWith(ara, reverseOrder()) ; var a : int ; a := ara[0+1] ; var b : int ; b := ara[1+1] ; var c : int ; c := ara[2+1] ; var count : int ; count := 0 ; if (a /= 0) then ( a := a - 1 ; count := count + 1 ) else skip ; if (b /= 0) then ( b := b - 1 ; count := count + 1 ) else skip ; if (c /= 0) then ( c := c - 1 ; count := count + 1 ) else skip ; if (a /= 0 & b /= 0) then ( a := a - 1 ; b := b - 1 ; count := count + 1 ) else skip ; if (a /= 0 & c /= 0) then ( a := a - 1 ; c := c - 1 ; count := count + 1 ) else skip ; if (b /= 0 & c /= 0) then ( b := b - 1 ; c := c - 1 ; count := count + 1 ) else skip ; if (a /= 0 & b /= 0 & c /= 0) then ( count := count + 1 ) else skip ; OclFile["System.out"].println(count) ; ) ; tt := tt + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.LineNumberReader ; public class A { static long result(String name,int n){ int len=name.length(); boolean hasPrev=false ; int curr=0 ; int prevStart=0 ; long res=0 ; int pos=0 ; while(pos=n){ hasPrev=true ; prevStart=pos-n ; res+=1+pos-n ; continue ; } } else { curr=0 ; } if(hasPrev){ res+=1+prevStart ; } } return res ; } static void go(String inputFile)throws Exception { LineNumberReader in=new LineNumberReader(new FileReader(inputFile)); FileWriter out=new FileWriter(inputFile+".out"); int nCases=Integer.parseInt(in.readLine()); for(int c=1 ; c<=nCases ; c++){ String[] tmp=in.readLine().split(" "); long res=result(tmp[0],Integer.parseInt(tmp[1])); String line="Case #"+c+": "+res ; System.out.println(line); out.write(line+"\n"); } out.close(); } public static void main(String[] args)throws Exception { LineNumberReader sysIn=new LineNumberReader(new InputStreamReader(System.in)); String line ; while((line=sysIn.readLine())!=null){ go(line.trim()); } } } ------------------------------------------------------------ OCL File: --------- class A { static operation result( name : String, n : int) : long pre: true post: true activity: ( var len : int ; len := name->size() ; var hasPrev : boolean ; hasPrev := false ; var curr : int ; curr := 0 ; var prevStart : int ; prevStart := 0 ; var res : long ; res := 0 ; var pos : int ; pos := 0 ; while (pos < len) do ( var is : boolean ; is := "aeiou"->indexOf(name->at(pos+1))-1 < 0 ; if (is) then ( curr := curr + 1 ; if (curr >= n) then ( hasPrev := true ; prevStart := pos - n ; res := res+(1 + pos - n) ; continue ) else skip ) else ( curr := 0 ) ; if (hasPrev) then ( res := res+(1 + prevStart) ) else skip ) ; return res ); static operation go( inputFile : String) : void pre: true post: true activity: ( var in : LineNumberReader ; in := LineNumberReader.newLineNumberReader(OclFile.newOclFile_Read(inputFile)) ; var out : OclFile ; out := OclFile.newOclFile_Write(inputFile + ".out") ; var nCases : int ; nCases := (in.readLine())->toInteger() ; var c : int ; c := 1 ; while c <= nCases do ( ( var tmp : Sequence(String) ; tmp := in.readLine()->split(" ") ; var res : long ; res := result(tmp[0+1], (tmp[1+1])->toInteger()) ; var line : String ; line := "Case #" + c + ": " + res ; OclFile["System.out"].println(line) ; skip ; ) ; c := c + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sysIn : LineNumberReader ; sysIn := LineNumberReader.newLineNumberReader(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := sysIn.readLine() ; while ((line) /= null) do ( skip ; ( execute go(line->trim()) ) ; line := sysIn.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Round1C_2013_A { private static void jam(String inFile,String outFile)throws Exception { BufferedReader brIn=new BufferedReader(new FileReader(inFile)); BufferedWriter bwOut=new BufferedWriter(new FileWriter(outFile)); String sLine ; int ca=1 ; brIn.readLine(); int[] starts=new int[1000000]; int[] ends=new int[1000000]; while((sLine=brIn.readLine())!=null){ String[] fields=sLine.split(" "); if(fields.length!=2){ System.out.println("skipping mis-parse: "+sLine); continue ; } String s=fields[0]; int n=Integer.parseInt(fields[1]); int numSets=0 ; int seqNum=0 ; for(int i=0 ; i=n){ starts[numSets]=i+1-n ; ends[numSets]=i+1 ; numSets++; } } else { seqNum=0 ; } } int lastStart=-1 ; long sum=0 ; for(int i=0 ; icollect(0) ; var ends : Sequence(int) ; ends := Integer.subrange(1,1000000)->collect(0) ; sLine := brIn.readLine() ; while ((sLine) /= null) do ( skip ; ( var fields : Sequence(String) ; fields := sLine->split(" ") ; if (fields->size() /= 2) then ( OclFile["System.out"].println("skipping mis-parse: " + sLine) ; continue ) else skip ; var s : String ; s := fields[0+1] ; var n : int ; n := (fields[1+1])->toInteger() ; var numSets : int ; numSets := 0 ; var seqNum : int ; seqNum := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( var c : String ; c := s->at(i+1) ; if (c /= 'a' & c /= 'e' & c /= 'i' & c /= 'o' & c /= 'u') then ( seqNum := seqNum + 1 ; if (seqNum >= n) then ( starts[numSets+1] := i + 1 - (n)->char2byte() ; ends[numSets+1] := i + 1 ; numSets := numSets + 1 ) else skip ) else ( seqNum := 0 ) ) ; i := i + 1 ) ; var lastStart : int ; lastStart := -1 ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < numSets do ( ( var choicesLeft : int ; choicesLeft := starts[i+1] - (lastStart)->char2byte() ; var choicesRight : int ; choicesRight := 1 + s->size() - ends[i+1] ; sum := sum+(choicesLeft->oclAsType(long) * choicesRight->oclAsType(long)) ; lastStart := starts[i+1] ) ; i := i + 1 ) ; var msg : String ; msg := "" + sum ; OclFile["System.out"].println("" + s->size()) ; skip ; ca := ca + 1 ; ) ; sLine := brIn.readLine() ; ) ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute jam(args[0+1], args[1+1]) ); } 013_A { static operation jam( inFile : String, outFile : String) : void pre: true post: true activity: ( var brIn : OclFile ; brIn := OclFile.newOclFile_Read(OclFile.newOclFile_Read(inFile)) ; var bwOut : OclFile ; bwOut := OclFile.newOclFile_Write(OclFile.newOclFile_Write(outFile)) ; var sLine : String ; var ca : int ; ca := 1 ; skip ; var starts : Sequence(int) ; starts := Integer.subrange(1,1000000)->collect(0) ; var ends : Sequence(int) ; ends := Integer.subrange(1,1000000)->collect(0) ; sLine := brIn.readLine() ; while ((sLine) /= null) do ( skip ; ( var fields : Sequence(String) ; fields := sLine->split(" ") ; if (fields->size() /= 2) then ( OclFile["System.out"].println("skipping mis-parse: " + sLine) ; continue ) else skip ; var s : String ; s := fields[0+1] ; var n : int ; n := (fields[1+1])->toInteger() ; var numSets : int ; numSets := 0 ; var seqNum : int ; seqNum := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( var c : String ; c := s->at(i+1) ; if (c /= 'a' & c /= 'e' & c /= 'i' & c /= 'o' & c /= 'u') then ( seqNum := seqNum + 1 ; if (seqNum >= n) then ( starts[numSets+1] := i + 1 - (n)->char2byte() ; ends[numSets+1] := i + 1 ; numSets := numSets + 1 ) else skip ) else ( seqNum := 0 ) ) ; i := i + 1 ) ; var lastStart : int ; lastStart := -1 ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < numSets do ( ( var choicesLeft : int ; choicesLeft := starts[i+1] - (lastStart)->char2byte() ; var choicesRight : int ; choicesRight := 1 + s->size() - ends[i+1] ; sum := sum+(choicesLeft->oclAsType(long) * choicesRight->oclAsType(long)) ; lastStart := starts[i+1] ) ; i := i + 1 ) ; var msg : String ; msg := "" + sum ; OclFile["System.out"].println("" + s->size()) ; skip ; ca := ca + 1 ; ) ; sLine := brIn.readLine() ; ) ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute jam(args[0+1], args[1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; public class A { static BufferedReader br ; static StringTokenizer st ; static PrintWriter pw ; public static void main(String[] args)throws IOException { br=new BufferedReader(new FileReader("a.in")); pw=new PrintWriter(new BufferedWriter(new FileWriter("a.out"))); final int MAX_CASES=readInt(); String vowel="aeiou" ; for(int casenum=1 ; casenum<=MAX_CASES ; casenum++){ pw.printf("Case #%d: ",casenum); String str=nextToken(); int count=readInt(); long ret=0 ; int curr=0 ; int lastStart=-1 ; for(int i=0 ; i=count){ int begin=i-count+1 ; int goAfter=i ; ret+=(begin-lastStart)*1L*(str.length()-goAfter); lastStart=begin ; } } pw.println(ret); } pw.close(); } public static int readInt()throws IOException { return Integer.parseInt(nextToken()); } public static long readLong()throws IOException { return Long.parseLong(nextToken()); } public static double readDouble()throws IOException { return Double.parseDouble(nextToken()); } public static String nextToken()throws IOException { while(st==null || ! st.hasMoreTokens()){ if(! br.ready()){ pw.close(); System.exit(0); } st=new StringTokenizer(br.readLine()); } return st.nextToken(); } public static String readLine()throws IOException { st=null ; return br.readLine(); } } ------------------------------------------------------------ OCL File: --------- class A { static attribute br : OclFile; static attribute st : OclIterator; static attribute pw : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("a.in"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("a.out")))) ; var MAX_CASES : int ; MAX_CASES := readInt() ; var vowel : String ; vowel := "aeiou" ; var casenum : int ; casenum := 1 ; while casenum <= MAX_CASES do ( ( skip ; var str : String ; str := nextToken() ; var count : int ; count := readInt() ; var ret : long ; ret := 0 ; var curr : int ; curr := 0 ; var lastStart : int ; lastStart := -1 ; var i : int ; i := 0 ; while i < str->size() do ( ( if (vowel->indexOf(str->at(i+1) + "")-1 = -1) then ( curr := curr + 1 ) else ( curr := 0 ) ; if (curr >= count) then ( var begin : int ; begin := i - (count)->char2byte() + 1 ; var goAfter : int ; goAfter := i ; ret := ret+((begin - lastStart) * 1L * (str->size() - goAfter)) ; lastStart := begin ) else skip ) ; i := i + 1 ) ; skip ; ) ; casenum := casenum + 1 ) ; skip ; ); static operation readInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); static operation readLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); static operation readDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); static operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( if (not(br.canRead())) then ( skip ; OclProcess.exit(0) ) else skip ; st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ); static operation readLine() : String pre: true post: true activity: ( st := null ; return br.readLine() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class App { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int[] s=new int[n]; for(int i=0 ; i=s[j]){ dp[i]=Math.max(dp[i],dp[j]+1); } } ans=Math.max(ans,dp[i]); } return ans ; } } ------------------------------------------------------------ OCL File: --------- class App { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(A_Curriculum_Vitae(n, s)) ; ); static operation A_Curriculum_Vitae( n : int, s : Sequence(int)) : int pre: true post: true activity: ( var dp : Sequence(int) ; dp := Integer.subrange(1,n)->collect(0) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( dp[i+1] := 1 ; var j : int ; j := 0 ; while j < i do ( ( if (s[i+1] >= s[j+1]) then ( dp[i+1] := Set{dp[i+1], dp[j+1] + 1}->max() ) else skip ) ; j := j + 1 ) ; ans := Set{ans, dp[i+1]}->max() ) ; i := i + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A846 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int ones=0 ; int[] A=new int[N]; for(int n=0 ; ntoInteger() ; var ones : int ; ones := 0 ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var n : int ; n := 0 ; while n < N do ( ( var a : int ; a := in.getCurrent()->toInteger() ; ones := ones+(a) ; A[n+1] := a ) ; n := n + 1 ) ; var zeros : int ; zeros := 0 ; var answer : int ; answer := ones ; var n : int ; n := 0 ; while n < N do ( ( if (A[n+1] = 0) then ( var seenOnes : int ; seenOnes := n - zeros ; var remainingOnes : int ; remainingOnes := ones - seenOnes ; zeros := zeros + 1 ; answer := Set{answer, remainingOnes + zeros}->max() ) else skip ) ; n := n + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxProfit(int profitA[],int profitB[],int n){ int preSum[]=new int[n]; preSum[0]=profitA[0]; for(int i=1 ; i=0 ; i--){ suffSum[i]=suffSum[i+1]+profitB[i]; } int res=preSum[n-1]; for(int i=1 ; icollect(0) ; preSum[0+1] := profitA[0+1] ; var i : int ; i := 1 ; while i < n do ( ( preSum[i+1] := preSum[i - 1+1] + profitA[i+1] ) ; i := i + 1 ) ; var suffSum : Sequence(int) ; suffSum := Integer.subrange(1,n)->collect(0) ; suffSum[n - 1+1] := profitB[n - 1+1] ; var i : int ; i := n - 2 ; while i >= 0 do ( ( suffSum[i+1] := suffSum[i + 1+1] + profitB[i+1] ) ; i := i - 1 ) ; var res : int ; res := preSum[n - 1+1] ; var i : int ; i := 1 ; while i < n - 1 do ( ( res := Set{res, preSum[i+1] + suffSum[i + 1+1]}->max() ) ; i := i + 1 ) ; res := Set{res, suffSum[0+1]}->max() ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var profitA : Sequence(int) ; profitA := Sequence{2,3,2} ; var profitB : Sequence(int) ; profitB := Sequence{10,30,40} ; var n : int ; n := profitA->size() ; OclFile["System.out"].println(maxProfit(profitA, profitB, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ String S=sc.next(); int max=0 ; int count=0 ; for(int i=0 ; isize() do ( ( if (S->at(i+1) = 'R') then ( count := count + 1 ) else ( max := Set{max, count}->max() ; count := 0 ) ) ; i := i + 1 ) ; max := Set{max, count}->max() ; OclFile["System.out"].println(max) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); String input=s.nextLine(); Listcl=new ArrayList<>(); for(int i=0 ; isize() do ( ( cl := cl->including(input->at(i+1)) ) ; i := i + 1 ) ; var flag : boolean ; flag := false ; if (frequency(cl, 'S') = 3) then ( OclFile["System.out"].println("0") ) else if (frequency(cl, 'R') = 3) then ( OclFile["System.out"].println("3") ) else ( var i : int ; i := 0 ; while i < input->size() - 1 do ( ( if (cl->at(i+1) = 'R' & cl->at(i + 1+1) = 'R') then ( flag := true ) else skip ) ; i := i + 1 ) ; if (flag = true) then ( OclFile["System.out"].println("2") ) else ( OclFile["System.out"].println("1") ) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Solution788A { public static int[] arr=new int[100001]; public static int[] dist=new int[100001]; public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); StringTokenizer st=new StringTokenizer(br.readLine()," "); for(int i=1 ; i<=n ; i++){ arr[i]=Integer.parseInt(st.nextToken()); } long finalMax=0 ; for(int start=1 ; start<3 ; start++){ long max=0 ; long sum=0 ; boolean add=true ; for(int i=start ; imax ? sum : max ; add=false ; } else { sum-=dist[i]; add=true ; } if(sum<0){ sum=0 ; add=true ; } } finalMax=max>finalMax ? max : finalMax ; } System.out.println(finalMax); } } ------------------------------------------------------------ OCL File: --------- class Solution788A { static attribute arr : Sequence(int) := Integer.subrange(1,100001)->collect(0); static attribute dist : Sequence(int) := Integer.subrange(1,100001)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var st : OclIterator ; st := OclIterator.newOclIterator_String_String(br.readLine(), " ") ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; var finalMax : long ; finalMax := 0 ; var start : int ; start := 1 ; while start < 3 do ( ( var max : long ; max := 0 ; var sum : long ; sum := 0 ; var add : boolean ; add := true ; var i : int ; i := start ; while i < n do ( ( dist[i+1] := if arr[i+1] - arr[i + 1+1] < 0 then -(arr[i+1] - arr[i + 1+1]) else arr[i+1] - arr[i + 1+1] endif ; if (add) then ( sum := sum+(dist[i+1]) ; max := if sum > max then sum else max endif ; add := false ) else ( sum := sum-(dist[i+1]) ; add := true ) ; if (sum < 0) then ( sum := 0 ; add := true ) else skip ) ; i := i + 1 ) ; finalMax := if max > finalMax then max else finalMax endif ; ) ; start := start + 1 ) ; OclFile["System.out"].println(finalMax) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { Scanner s=new Scanner(System.in); String word=s.next(); int max=0,cnt=0 ; for(int i=0 ; isize() do ( ( if (word->at(i+1) = 'S') then ( max := Set{max, cnt}->max() ; cnt := 0 ) else cnt := cnt + 1 ; ) ; i := i + 1 ) ; max := Set{max, cnt}->max() ; OclFile["System.out"].println(max) ; ); } class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation nextDouble() : double pre: true post: true activity: ( var x : String ; x := next() ; var sb : String ; sb := StringLib.newString("0") ; var res : double ; res := 0 ; var f : double ; f := 1 ; var dec : boolean ; dec := false ; var neg : boolean ; neg := false ; var start : int ; start := 0 ; if (x->at(0+1) = '-') then ( neg := true ; start := start + 1 ) else skip ; var i : int ; i := start ; while i < x->size() do ( if (x->at(i+1) = '.') then ( res := (sb+"")->toLong() ; sb := StringLib.newString("0") ; dec := true ) else ( sb := sb + StringLib.newString(x->at(i+1)) ; if (dec) then f := f*(10) ; else skip ) ; ; i := i + 1 ) ; res := res+((sb+"")->toLong() / f) ; return res * (if neg then -1 else 1 endif) ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public void solve(){ Scanner scan=new Scanner(System.in); String S=scan.next(); if(S.equals("SSS"))System.out.println(0); if(S.equals("SSR"))System.out.println(1); if(S.equals("SRS"))System.out.println(1); if(S.equals("RSS"))System.out.println(1); if(S.equals("RRS"))System.out.println(2); if(S.equals("RSR"))System.out.println(1); if(S.equals("SRR"))System.out.println(2); if(S.equals("RRR"))System.out.println(3); } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : String ; S := scan.getCurrent() ; if (S = "SSS") then OclFile["System.out"].println(0) ; else skip ; if (S = "SSR") then OclFile["System.out"].println(1) ; else skip ; if (S = "SRS") then OclFile["System.out"].println(1) ; else skip ; if (S = "RSS") then OclFile["System.out"].println(1) ; else skip ; if (S = "RRS") then OclFile["System.out"].println(2) ; else skip ; if (S = "RSR") then OclFile["System.out"].println(1) ; else skip ; if (S = "SRR") then OclFile["System.out"].println(2) ; else skip ; if (S = "RRR") then OclFile["System.out"].println(3) ; else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); String x=scan.next(); String a,b,c ; a=x.substring(0,1); b=x.substring(1,2); c=x.substring(2,3); if(a.equals("R")&& b.equals("R")&& c.equals("R")){ System.out.println("3"); } else if(a.equals("R")&& b.equals("R")&& c.equals("S")){ System.out.println("2"); } else if(a.equals("S")&& b.equals("R")&& c.equals("R")){ System.out.println("2"); } else if(a.equals("R")&& b.equals("S")&& c.equals("S")){ System.out.println("1"); } else if(a.equals("S")&& b.equals("R")&& c.equals("S")){ System.out.println("1"); } else if(a.equals("S")&& b.equals("S")&& c.equals("R")){ System.out.println("1"); } else if(a.equals("R")&& b.equals("S")&& c.equals("R")){ System.out.println("1"); } else if(a.equals("S")&& b.equals("S")&& c.equals("S")){ System.out.println("0"); } else { } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : String ; x := scan.getCurrent() ; var a : String ; var b : String ; var c : String ; a := x.subrange(0+1,1) ; b := x.subrange(1+1,2) ; c := x.subrange(2+1,3) ; if (a = "R" & b = "R" & c = "R") then ( OclFile["System.out"].println("3") ) else if (a = "R" & b = "R" & c = "S") then ( OclFile["System.out"].println("2") ) else if (a = "S" & b = "R" & c = "R") then ( OclFile["System.out"].println("2") ) else if (a = "R" & b = "S" & c = "S") then ( OclFile["System.out"].println("1") ) else if (a = "S" & b = "R" & c = "S") then ( OclFile["System.out"].println("1") ) else if (a = "S" & b = "S" & c = "R") then ( OclFile["System.out"].println("1") ) else if (a = "R" & b = "S" & c = "R") then ( OclFile["System.out"].println("1") ) else if (a = "S" & b = "S" & c = "S") then ( OclFile["System.out"].println("0") ) else skip ; ; ; ; ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static Boolean isPentagonal(int N){ double n=(1+Math.sqrt(24*N+1))/6 ; return(n-(int)n)==0 ; } public static void main(String[] args){ int N=19 ; if(isPentagonal(N))System.out.println(N+" is pentagonal "); else System.out.println(N+" is not pentagonal"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPentagonal( N : int) : Boolean pre: true post: true activity: ( var n : double ; n := (1 + (24 * N + 1)->sqrt()) / 6 ; return (n - n->oclAsType(int)) = 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 19 ; if (isPentagonal(N)) then OclFile["System.out"].println(N + " is pentagonal ") ; else OclFile["System.out"].println(N + " is not pentagonal") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { private void doit(){ Scanner sc=new Scanner(System.in); int dataset=sc.nextInt(); while(dataset-->0){ int p=sc.nextInt(); int q=sc.nextInt(); int maxrange=Math.max(p,Math.max(-p,Math.max(q,-q))); int minrange=Math.min(p,Math.min(-p,Math.min(q,-q))); int count=0 ; for(int m=minrange ; m<=maxrange ; m++){ for(int n=minrange ; n<=maxrange ; n++){ if(m==0 && n==0)continue ; int a=m*p+n*q ; int b=m*q-n*p ; int mn=m*m+n*n ; if(a % mn==0 && b % mn==0){ count++; } } } System.out.println(count==8 ? "P" : "C"); } } private void debug(Object...o){ System.out.println("debug="+Arrays.deepToString(o)); } public static void main(String[] args){ new Main().doit(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation doit() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var dataset : int ; dataset := sc.getCurrent()->toInteger() ; while (dataset > 0) do ( dataset := dataset - 1 ; skip ; ( var p : int ; p := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var maxrange : int ; maxrange := Set{p, Set{-p, Set{q, -q}->max()}->max()}->max() ; var minrange : int ; minrange := Set{p, Set{-p, Set{q, -q}->min()}->min()}->min() ; var count : int ; count := 0 ; var m : int ; m := minrange ; while m <= maxrange do ( ( var n : int ; n := minrange ; while n <= maxrange do ( ( if (m = 0 & n = 0) then continue else skip ; var a : int ; a := m * p + n * q ; var b : int ; b := m * q - n * p ; var mn : int ; mn := m * m + n * n ; if (a mod mn = 0 & b mod mn = 0) then ( count := count + 1 ) else skip ; ) ; n := n + 1 ) ) ; m := m + 1 ) ; OclFile["System.out"].println(if count = 8 then "P" else "C" endif) ; ) ; ) ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println("debug=" + (o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long N=sc.nextInt(); long a=1 ; long b=10*10*10*10*10*10*10*10*10+7 ; for(long i=1 ; i<=N ; i++){ a=a*i % b ; if(i==N){ System.out.println(a); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := sc.getCurrent()->toInteger() ; var a : long ; a := 1 ; var b : long ; b := 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7 ; var i : long ; i := 1 ; while i <= N do ( ( a := a * i mod b ; if (i = N) then ( OclFile["System.out"].println(a) ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; public class Main { public static void main(String[] args)throws IOException { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); long N=Long.parseLong(input.readLine()); BigInteger result=new BigInteger("1"); BigInteger divider=new BigInteger("1000000007"); for(int i=1 ; i<=N ; i++){ result=result.multiply(new BigInteger(Integer.toString(i))).mod(divider); } System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var N : long ; N := (input.readLine())->toLong() ; var result : long ; result := long("1") ; var divider : long ; divider := long("1000000007") ; var i : int ; i := 1 ; while i <= N do ( ( result := result.multiply(long(((i) + ""))).mod(divider) ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.LongStream ; public class Main { public static void main(String[] args){ System.out.println(LongStream.rangeClosed(1,Integer.parseInt((new Scanner(System.in)).next())).reduce(1,(x,y)->(x*y)% 1000000007)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(Integer.subrange(1, ((OclFile.newOclFile_Read(OclFile["System.in"])).next())->toInteger())->iterate( _var; _acc : OclAny | 1, lambda (x , y) : OclAny in (x * y) mod 1000000007->apply((_acc,_var)) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.util.Scanner ; public class Main { public static void main(String[] args){ int N=input(System.in); long power=proc(N); System.out.println(power); } static int input(InputStream in){ int result=0 ; try(Scanner sc=new Scanner(in)){ result=sc.nextInt(); } return result ; } static long proc(int N){ long unit=(long)(Math.pow(10,9))+7 ; long power=1 ; for(int i=1 ; i<=N ; i++){ power=power*i % unit ; } return power ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := input(OclFile["System.in"]) ; var power : long ; power := proc(N) ; OclFile["System.out"].println(power) ); static operation input( in : OclFile) : int pre: true post: true activity: ( var result : int ; result := 0 ; try ( var sc : OclFile := OclFile.newOclFile_Read(in) ; ( result := sc.getCurrent()->toInteger() )) return result ); static operation proc( N : int) : long pre: true post: true activity: ( var unit : long ; unit := (10->pow(9))->oclAsType(long) + 7 ; var power : long ; power := 1 ; var i : int ; i := 1 ; while i <= N do ( ( power := power * i mod unit ) ; i := i + 1 ) ; return power ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileInputStream ; import java.util.NoSuchElementException ; import java.util.Scanner ; import java.io.IOException ; import java.io.InputStream ; import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.Deque ; import java.util.HashMap ; import java.util.List ; import java.util.Map.Entry ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long ans=1 ; long MOD=1000000007 ; for(int i=1 ; i<=N ; i++)ans=(ans*i)% MOD ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var ans : long ; ans := 1 ; var MOD : long ; MOD := 1000000007 ; var i : int ; i := 1 ; while i <= N do ( ans := (ans * i) mod MOD ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class FunctionsAgain { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); long[] diff1=new long[N-1]; long[] diff2=new long[N-1]; int first=in.nextInt(); int second ; for(int i=0 ; itoInteger() ; var diff1 : Sequence(long) ; diff1 := Integer.subrange(1,N - 1)->collect(0) ; var diff2 : Sequence(long) ; diff2 := Integer.subrange(1,N - 1)->collect(0) ; var first : int ; first := in.getCurrent()->toInteger() ; var second : int ; var i : int ; i := 0 ; while i < N - 1 do ( ( second := in.getCurrent()->toInteger() ; diff1[i+1] := if second - first < 0 then -(second - first) else second - first endif * (if i mod 2 = 0 then -1 else 1 endif) ; diff2[i+1] := if second - first < 0 then -(second - first) else second - first endif * (if i mod 2 = 0 then 1 else -1 endif) ; first := second ) ; i := i + 1 ) ; var max : long ; max := 0 ; var high : int ; high := 0 ; var counter : long ; counter := 0 ; while (high < N - 1) do ( counter := counter+(diff1[high+1]) ; if (counter <= 0) then ( counter := 0 ) else ( max := Set{max, counter}->max() ) ; high := high + 1 ) ; high := 0 ; counter := 0 ; while (high < N - 1) do ( counter := counter+(diff2[high+1]) ; if (counter <= 0) then ( counter := 0 ) else ( max := Set{max, counter}->max() ) ; high := high + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Eulerian { public static String fibWord(int n){ String Sn_1="0" ; String Sn="01" ; String tmp ; for(int i=2 ; i<=n ; i++){ tmp=Sn ; Sn+=Sn_1 ; Sn_1=tmp ; } return Sn ; } public static void main(String[] args){ int n=6 ; System.out.print(fibWord(n)); } } ------------------------------------------------------------ OCL File: --------- class Eulerian { static operation fibWord( n : int) : String pre: true post: true activity: ( var Sn var SnString : ; SnString := "0" : String ; Sn var SnString : ; SnString := "0" := "0" ; var Sn : String ; Sn := "01" ; var tmp : String ; var i : int ; i := 2 ; while i <= n do ( ( tmp := Sn ; Sn := Sn+(SnSn) ; SnSn SnSn tmp := Sn ; := tmp ; := tmp ) ; i := i + 1 ) ; return Sn ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; OclFile["System.out"].print(fibWord(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int xorPairSum(int ar[],int n){ int sum=0 ; for(int i=0 ; isize() ; OclFile["System.out"].print(xorPairSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int mod=(int)(1e9+7); static int power(int x,int y,int p){ int 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 ; } static int findCount(int N){ int count=power(2,N,mod); return count ; } public static void main(String[] args){ int N=25 ; System.out.println(findCount(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute mod : int := (1e9 + 7)->oclAsType(int); static operation power( x : int, y : int, p : int) : int pre: true post: true activity: ( var res : int ; res := 1 ; x := x mod p ; while (y > 0) do ( if ((y & 1) = 1) then res := (res * x) mod p ; else skip ; y := (y/(2->pow(1)))->oclAsType(long) ; x := (x * x) mod p ) ; return res ); static operation findCount( N : int) : int pre: true post: true activity: ( var count : int ; count := power(2, N, mod) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 25 ; OclFile["System.out"].println(findCount(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class maxima { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t,j,i,n,a,b,p,q ; t=sc.nextInt(); for(j=1 ; j<=t ; j++){ n=sc.nextInt(); a=sc.nextInt(); b=sc.nextInt(); p=1 ; q=n ; if(a==b && a<=(n-2)/2){ System.out.print((p++)+" "); for(i=1 ; i<=a ; i++)System.out.print((q--)+" "+(p++)+" "); for(i=p ; i<=q ; i++)System.out.print(i+" "); } else if((a-b)==1 && a<=(int)Math.ceil((n-2)/2.0)){ for(i=1 ; i<=a ; i++)System.out.print((p++)+" "+(q--)+" "); for(i=q ; i>=p ; i--)System.out.print(i+" "); } else if((b-a)==1 && b<=(int)Math.ceil((n-2)/2.0)){ for(i=1 ; i<=b ; i++)System.out.print((q--)+" "+(p++)+" "); for(i=p ; i<=q ; i++)System.out.print(i+" "); } else System.out.print(-1); System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class maxima { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; var j : int ; var i : int ; var n : int ; var a : int ; var b : int ; var p : int ; var q : int ; t := sc.getCurrent()->toInteger() ; j := 1 ; while j <= t do ( ( n := sc.getCurrent()->toInteger() ; a := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; p := 1 ; q := n ; if (a = b & a <= (n - 2) / 2) then ( OclFile["System.out"].print((p) + " ") ; i := 1 ; while i <= a do ( OclFile["System.out"].print((q) + " " + (p) + " ") ; ; i := i + 1 ) ; i := p ; while i <= q do ( OclFile["System.out"].print(i + " ") ; ; i := i + 1 ) ) else if ((a - b) = 1 & a <= ((n - 2) / 2.0)->ceil()->oclAsType(int)) then ( i := 1 ; while i <= a do ( OclFile["System.out"].print((p) + " " + (q) + " ") ; ; i := i + 1 ) ; i := q ; while i >= p do ( OclFile["System.out"].print(i + " ") ; ; i := i - 1 ) ) else if ((b - a) = 1 & b <= ((n - 2) / 2.0)->ceil()->oclAsType(int)) then ( i := 1 ; while i <= b do ( OclFile["System.out"].print((q) + " " + (p) + " ") ; ; i := i + 1 ) ; i := p ; while i <= q do ( OclFile["System.out"].print(i + " ") ; ; i := i + 1 ) ) else OclFile["System.out"].print(-1) ; ; ; ; OclFile["System.out"].println() ; ) ; j := j + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.*; import java.math.BigInteger ; public class A { public static void main(String[] args)throws Throwable { Scanner in=new Scanner(new File("in.txt")); PrintStream out=new PrintStream(new File("out.txt")); int t=in.nextInt(); in.nextLine(); for(int c=1 ; c<=t ; c++){ out.print("Case #"); out.print(c); out.print(": "); out.println(getSolution(in)); } } private static String getSolution(Scanner in){ long n ; int pd,pg ; n=in.nextLong(); pd=in.nextInt(); pg=in.nextInt(); int factor=gcf(100,pd); if(100/factor>n)return "Broken" ; if((pg==100 && pd!=100)||(pg==0 && pd!=0))return "Broken" ; return "Possible" ; } public static int gcf(int a,int b){ int s ; if(a>b)s=b ; else s=a ; for(int i=s ; i>0 ; i--){ if((a % i==0)&&(b % i==0))return i ; } return-1 ; } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile("in.txt")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile("out.txt")) ; var t : int ; t := in.getCurrent()->toInteger() ; skip ; var c : int ; c := 1 ; while c <= t do ( ( skip ; skip ; skip ; skip ) ; c := c + 1 ) ; ); static operation getSolution( in : OclFile) : String pre: true post: true activity: ( var n : long ; var pd : int ; var pg : int ; n := in.getCurrent()->toLong() ; pd := in.getCurrent()->toInteger() ; pg := in.getCurrent()->toInteger() ; var factor : int ; factor := gcf(100, pd) ; if (100 / factor > n) then return "Broken" else skip ; if ((pg = 100 & pd /= 100) or (pg = 0 & pd /= 0)) then return "Broken" else skip ; return "Possible" ); static operation gcf( a : int, b : int) : int pre: true post: true activity: ( var s : int ; if (a > b) then s := b else s := a ; ; var i : int ; i := s ; while i > 0 do ( ( if ((a mod i = 0) & (b mod i = 0)) then return i else skip ) ; i := i - 1 ) ; return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); while(N-->0){ int m=in.nextInt(); int n=in.nextInt(); Ginko gi=new Ginko(m,n); boolean flg=true ; for(int i=0 ; i<150 ; i++){ for(int j=0 ; j<150 ; j++){ if(i*i+j*j>gi.m*gi.m+gi.n*gi.n || i*i+j*j==0)continue ; if(check(i,j,gi)|| check(i,-j,gi)|| check(-i,j,gi)|| check(-i,-j,gi)){ flg=false ; break ; } } if(! flg)break ; } System.out.println(flg ? "P" : "C"); } } static boolean check(int m,int n,Ginko in){ if(m==1 && n==0 || m==0 && n==1 || m==-1 && n==0 || m==0 && n==-1 || m==in.m && n==in.n || m==-in.n && n==in.m || m==-in.m && n==-in.n || m==in.n && n==-in.m)return false ; int a=m*in.m+n*in.n ; int b=m*in.n-n*in.m ; int mn=m*m+n*n ; if(a % mn==0 && b % mn==0)return true ; else return false ; } } class Ginko { int m ; int n ; Ginko(int m,int n){ this.m=m ; this.n=n ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; while (N > 0) do ( N := N - 1 ; skip ; ( var m : int ; m := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; var gi : Ginko ; gi := Ginko.newGinko(m, n) ; var flg : boolean ; flg := true ; var i : int ; i := 0 ; while i < 150 do ( ( var j : int ; j := 0 ; while j < 150 do ( ( if (i * i + j * j > gi.m * gi.m + gi.n * gi.n or i * i + j * j = 0) then continue else skip ; if (check(i, j, gi) or check(i, -j, gi) or check(-i, j, gi) or check(-i, -j, gi)) then ( flg := false ; break ) else skip ) ; j := j + 1 ) ; if (not(flg)) then break else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(if flg then "P" else "C" endif) ; ) ; ) ); static operation check( m : int, n : int, in : Ginko) : boolean pre: true post: true activity: ( if (m = 1 & n = 0 or m = 0 & n = 1 or m = -1 & n = 0 or m = 0 & n = -1 or m = inm & n = inn or m = -inn & n = inm or m = -inm & n = -inn or m = inn & n = -inm) then return false else skip ; var a : int ; a := m * inm + n * inn ; var b : int ; b := m * inn - n * inm ; var mn : int ; mn := m * m + n * n ; if (a mod mn = 0 & b mod mn = 0) then return true else return false ; ); } class Ginko { attribute m : int; attribute n : int; static operation newGinko( m : int, n : int) : Ginko pre: true post: true activity: ( var self : Ginko ; self := createGinko(); self.initialise(m, n); return self ); operation initialise( m : int, n : int) : void pre: true post: true activity: ( self.m := m ; self.n := n ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package round1a ; import java.io.File ; import java.util.ArrayList ; import java.util.Scanner ; public class A { int caseNo ; double epsilon=0.00000001 ; boolean equals(double a,double b){ return(Math.abs(a-b)=1){ found |=(rateToday % 100==0); } if(maxGamesToday>=2){ found |=(rateToday % 50==0); } if(maxGamesToday>=4){ found |=(rateToday % 25==0); } if(maxGamesToday>=5){ found |=(rateToday % 20==0); } if(maxGamesToday>=10){ found |=(rateToday % 10==0); } if(maxGamesToday>=20){ found |=(rateToday % 5==0); } if(maxGamesToday>=25){ found |=(rateToday % 4==0); } if(maxGamesToday>=50){ found |=(rateToday % 2==0); } possible=found ; } if(possible){ if(rateTotal==0 && rateToday!=0)possible=false ; if(rateTotal==100 && rateToday!=100)possible=false ; } if(possible)System.out.println("Case #"+caseNo+": Possible"); else System.out.println("Case #"+caseNo+": Broken"); } public static void main(String[] args)throws Exception { (new A()).test(); } public void test()throws Exception { Scanner s=new Scanner(new File("A-large.in")); int numTests=s.nextInt(); for(caseNo=1 ; caseNo<=numTests ; caseNo++){ test(s); } } } ------------------------------------------------------------ OCL File: --------- class A { attribute caseNo : int; attribute epsilon : double := 0.00000001; operation equals( a : double, b : double) : boolean pre: true post: true activity: ( return (if a - b < 0 then -(a - b) else a - b endif < epsilon) ); operation test( in : OclFile) : void pre: true post: true activity: ( var maxGamesToday : long ; maxGamesToday := in.nextLong() ; var rateToday : int ; rateToday := in.nextInt() ; var rateTotal : int ; rateTotal := in.nextInt() ; var possible : boolean ; possible := true ; if (maxGamesToday < 100) then ( var found : boolean ; found := false ; if (maxGamesToday >= 1) then ( found := MathLib.bitwiseOr(found, (rateToday mod 100 = 0)) ) else skip ; if (maxGamesToday >= 2) then ( found := MathLib.bitwiseOr(found, (rateToday mod 50 = 0)) ) else skip ; if (maxGamesToday >= 4) then ( found := MathLib.bitwiseOr(found, (rateToday mod 25 = 0)) ) else skip ; if (maxGamesToday >= 5) then ( found := MathLib.bitwiseOr(found, (rateToday mod 20 = 0)) ) else skip ; if (maxGamesToday >= 10) then ( found := MathLib.bitwiseOr(found, (rateToday mod 10 = 0)) ) else skip ; if (maxGamesToday >= 20) then ( found := MathLib.bitwiseOr(found, (rateToday mod 5 = 0)) ) else skip ; if (maxGamesToday >= 25) then ( found := MathLib.bitwiseOr(found, (rateToday mod 4 = 0)) ) else skip ; if (maxGamesToday >= 50) then ( found := MathLib.bitwiseOr(found, (rateToday mod 2 = 0)) ) else skip ; possible := found ; ) else skip ; if (possible) then ( if (rateTotal = 0 & rateToday /= 0) then possible := false ; else skip ; if (rateTotal = 100 & rateToday /= 100) then possible := false ; else skip ) else skip ; if (possible) then OclFile["System.out"].println("Case #" + caseNo + ": Possible") else OclFile["System.out"].println("Case #" + caseNo + ": Broken") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (A.newA()).test() ); operation test() : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile("A-large.in")) ; var numTests : int ; numTests := s.getCurrent()->toInteger() ; caseNo := 1 ; while caseNo <= numTests do ( ( execute test(s) ) ; caseNo := caseNo + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package jam2011 ; import java.io.*; import java.util.*; public class AA { public static void main(String[] args)throws Exception { BufferedReader inputFile=new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); int cases=Integer.parseInt(inputFile.readLine()); PrintStream outFile=new PrintStream(new FileOutputStream(args[1])); for(int i=1 ; i<=cases ; i++){ String lineT[]=tokenize(inputFile.readLine()); long n=Long.parseLong(lineT[0]); long pd=Long.parseLong(lineT[1]); long pg=Long.parseLong(lineT[2]); String out=null ; if(pg==0)out=pd==0 ? "Possible" : "Broken" ; else if(pg==100)out=pd==100 ? "Possible" : "Broken" ; else { if(n>=100)out="Possible" ; else { int nnn=100 ; while(pd % 2==0 && nnn % 2==0 || pd % 5==0 && nnn % 5==0){ if(pd % 2==0 && nnn % 2==0){ nnn/=2 ; pd/=2 ; } if(pd % 5==0 && nnn % 5==0){ nnn/=5 ; pd/=5 ; } } out=nnn<=n ? "Possible" : "Broken" ; } } outFile.println("Case #"+i+": "+out); } outFile.close(); inputFile.close(); } public static String[] tokenize(String input){ StringTokenizer st=new StringTokenizer(input); String[] k=new String[st.countTokens()]; for(int i=0 ; itoInteger() ; var outFile : OclFile ; outFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(args[1+1])) ; var i : int ; i := 1 ; while i <= cases do ( ( var lineT : Sequence(String) ; lineT := tokenize(inputFile.readLine()) ; var n : long ; n := (lineT[0+1])->toLong() ; var pd : long ; pd := (lineT[1+1])->toLong() ; var pg : long ; pg := (lineT[2+1])->toLong() ; var out : String ; out := null ; if (pg = 0) then out := if pd = 0 then "Possible" else "Broken" endif else if (pg = 100) then out := if pd = 100 then "Possible" else "Broken" endif else ( if (n >= 100) then out := "Possible" ; else ( var nnn : int ; nnn := 100 ; while (pd mod 2 = 0 & nnn mod 2 = 0 or pd mod 5 = 0 & nnn mod 5 = 0) do ( if (pd mod 2 = 0 & nnn mod 2 = 0) then ( nnn := nnn/(2) ; pd := pd/(2) ) else skip ; if (pd mod 5 = 0 & nnn mod 5 = 0) then ( nnn := nnn/(5) ; pd := pd/(5) ) else skip ) ; out := if nnn <= n then "Possible" else "Broken" endif ) ) ; ; skip ; ) ; i := i + 1 ) ; skip ; skip ; ); static operation tokenize( input : String) : Sequence(String) pre: true post: true activity: ( var st : OclIterator ; st := OclIterator.newOclIterator_String(input) ; var k : Sequence(String) ; k := Integer.subrange(1,st.elements->size())->collect(null) ; var i : int ; i := 0 ; while i < k->size() do ( k[i+1] := st.next() ; ; i := i + 1 ) ; return k ); static operation tokenize( input : String, sep : String) : Sequence(String) pre: true post: true activity: ( var st : OclIterator ; st := OclIterator.newOclIterator_String_String(input, sep) ; var k : Sequence(String) ; k := Integer.subrange(1,st.elements->size())->collect(null) ; var i : int ; i := 0 ; while i < k->size() do ( k[i+1] := st.next() ; ; i := i + 1 ) ; return k ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package r1a ; import java.util.Scanner ; public class A { static long gcd(long a,long b){ if(b==0)return a ; return gcd(b,a % b); } static boolean solve(long N,long PD,long PG){ long dcoeff=100/gcd(100,PD); long gcoeff=100/gcd(100,PG); long dw=dcoeff*PD/100 ; long gw=gcoeff*PG/100 ; long dl=dcoeff-dw ; long gl=gcoeff-gw ; if(gw==0 && dw!=0)return false ; if(gl==0 && dl!=0)return false ; if(dcoeff>N)return false ; return true ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int cn=1 ; cn<=T ; ++cn){ long N=sc.nextLong(); int PD=sc.nextInt(); int PG=sc.nextInt(); if(solve(N,PD,PG)){ System.out.printf("Case #%d: Possible\n",cn); } else { System.out.printf("Case #%d: Broken\n",cn); } } } } ------------------------------------------------------------ OCL File: --------- class A { static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (b = 0) then return a else skip ; return gcd(b, a mod b) ); static operation solve( N : long, PD : long, PG : long) : boolean pre: true post: true activity: ( var dcoeff : long ; dcoeff := 100 / gcd(100, PD) ; var gcoeff : long ; gcoeff := 100 / gcd(100, PG) ; var dw : long ; dw := dcoeff * PD / 100 ; var gw : long ; gw := gcoeff * PG / 100 ; var dl : long ; dl := dcoeff - dw ; var gl : long ; gl := gcoeff - gw ; if (gw = 0 & dw /= 0) then return false else skip ; if (gl = 0 & dl /= 0) then return false else skip ; if (dcoeff > N) then return false else skip ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := sc.getCurrent()->toInteger() ; var cn : int ; cn := 1 ; while cn <= T do ( ( var N : long ; N := sc.getCurrent()->toLong() ; var PD : int ; PD := sc.getCurrent()->toInteger() ; var PG : int ; PG := sc.getCurrent()->toInteger() ; if (solve(N, PD, PG)) then ( OclFile["System.out"].printf("Case #%d: Possible\n", cn) ) else ( OclFile["System.out"].printf("Case #%d: Broken\n", cn) ) ) ; cn := cn + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class SameParitySummands { private static void print(int n,int k,int base){ if(n0)stringBuilder.append(" "); stringBuilder.append(base); } if(stringBuilder.length()>0)stringBuilder.append(" "); stringBuilder.append(n-(k-1)*base); System.out.println(stringBuilder); } public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); for(int i=0 ; isize() > 0) then stringBuilder := stringBuilder + StringLib.newString(" ") ; else skip ; stringBuilder := stringBuilder + StringLib.newString(base) ) ; j := j + 1 ) ; if (stringBuilder->size() > 0) then stringBuilder := stringBuilder + StringLib.newString(" ") ; else skip ; stringBuilder := stringBuilder + StringLib.newString(n - (k - 1) * base) ; OclFile["System.out"].println(stringBuilder) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; if (k mod 2 = 0) then ( if (n mod 2 = 1) then OclFile["System.out"].println("NO") ; else ( execute print(n, k, 1) ) ) else ( if (n mod 2 = 1) then ( execute print(n, k, 1) ) else ( execute print(n, k, 2) ) ) ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Zmeigorynich { public static void main(String[] args){ Kattio io=new Kattio(); int t=io.nextInt(); for(int i=0 ; imaxdamage){ io.println(-1); } else { if(maxdamage>=heads){ io.println(1); } else if((heads-maxdamage)% maxtotaldamage==0){ io.println((heads-maxdamage)/maxtotaldamage+1); } else { io.println((heads-maxdamage)/maxtotaldamage+2); } } } io.close(); } static class Kattio extends PrintWriter { private BufferedReader r ; private StringTokenizer st ; public Kattio(){ this(System.in,System.out); } public Kattio(InputStream i,OutputStream o){ super(o); r=new BufferedReader(new InputStreamReader(i)); } public Kattio(String problemName)throws IOException { super(problemName+".out"); r=new BufferedReader(new FileReader(problemName+".in")); } public String next(){ try { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(r.readLine()); return st.nextToken(); } catch(Exception e){ } return null ; } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Zmeigorynich { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : Kattio ; io := Kattio.newKattio() ; var t : int ; t := io.nextInt() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := io.nextInt() ; var heads : int ; heads := io.nextInt() ; var maxdamage : int ; maxdamage := 0 ; var maxtotaldamage : int ; maxtotaldamage := 0 ; var j : int ; j := 0 ; while j < n do ( ( var damage : int ; damage := io.nextInt() ; maxdamage := Set{damage, maxdamage}->max() ; var regen : int ; regen := io.nextInt() ; maxtotaldamage := Set{maxtotaldamage, damage - regen}->max() ) ; j := j + 1 ) ; if (maxtotaldamage <= 0 & heads > maxdamage) then ( io.println(-1) ) else ( if (maxdamage >= heads) then ( io.println(1) ) else if ((heads - maxdamage) mod maxtotaldamage = 0) then ( io.println((heads - maxdamage) / maxtotaldamage + 1) ) else ( io.println((heads - maxdamage) / maxtotaldamage + 2) ) ; ) ; ) ; i := i + 1 ) ; io.close() ); static class Kattio extends OclFile { attribute r : OclFile; attribute st : OclIterator; static operation newKattio() : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute this(OclFile["System.in"], OclFile["System.out"]) ); static operation newKattio( i : OclFile, o : OclFile) : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(i, o); return self ); operation initialise( i : OclFile, o : OclFile) : void pre: true post: true activity: ( execute super(o) ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(i)) ); static operation newKattio( problemName : String) : Kattio pre: true post: true activity: ( var self : Kattio ; self := createKattio(); self.initialise(problemName); return self ); operation initialise( problemName : String) : void pre: true post: true activity: ( execute super(problemName + ".out") ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(problemName + ".in")) ); operation next() : String pre: true post: true activity: ( try ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(r.readLine()) ; ; return st.next() ) catch (e : ProgramException) do skip return null ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class zmeigorynich { static int n ; static long x ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int t=Integer.parseInt(st.nextToken()); long[] out=new long[t]; for(int i=0 ; i=x){ out[i]=1 ; continue ; } if(maxdiff<=0){ out[i]=-1 ; continue ; } long lo=1 ; long hi=(long)1e9 ; while(lo!=hi){ long mid=(lo+hi)/2 ; if(x-maxdiff*mid<=maxd){ hi=mid ; } else { lo=mid+1 ; } } out[i]=lo+1 ; } br.close(); for(long v : out){ System.out.println(v); } } } ------------------------------------------------------------ OCL File: --------- class zmeigorynich { static attribute n : int; static attribute x : long; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var t : int ; t := (st.next())->toInteger() ; var out : Sequence(long) ; out := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( st := OclIterator.newOclIterator_String(br.readLine()) ; n := (st.next())->toInteger() ; x := (st.next())->toLong() ; var d : Sequence(long) ; d := Integer.subrange(1,n + 1)->collect(0) ; var h : Sequence(long) ; h := Integer.subrange(1,n + 1)->collect(0) ; var maxd : long ; maxd := "-9223372036854775808"->toLong() ; var maxdiff : long ; maxdiff := "-9223372036854775808"->toLong() ; var j : int ; j := 1 ; while j <= n do ( ( st := OclIterator.newOclIterator_String(br.readLine()) ; d[j+1] := (st.next())->toLong() ; h[j+1] := (st.next())->toLong() ; maxd := Set{maxd, d[j+1]}->max() ; maxdiff := Set{maxdiff, d[j+1] - h[j+1]}->max() ; ) ; j := j + 1 ) ; if (maxd >= x) then ( out[i+1] := 1 ; continue ) else skip ; if (maxdiff <= 0) then ( out[i+1] := -1 ; continue ) else skip ; var lo : long ; lo := 1 ; var hi : long ; hi := 1e9->oclAsType(long) ; while (lo /= hi) do ( var mid : long ; mid := (lo + hi) / 2 ; if (x - maxdiff * mid <= maxd) then ( hi := mid ) else ( lo := mid + 1 ) ) ; out[i+1] := lo + 1 ; ) ; i := i + 1 ) ; skip ; for (v : out) do ( ( OclFile["System.out"].println(v) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class ZmeiGorynich { public static void main(String[] args){ InputReader ir=new InputReader(System.in); StringBuilder sb=new StringBuilder(); int t=ir.nextInt(); while(t-->0){ int n=ir.nextInt(); int x=ir.nextInt(); int maxDiff=0 ; int maxHit=0 ; int i=0 ; while(i=x){ sb.append('1'); } else if(maxDiff>0){ sb.append((int)Math.ceil((double)(x-maxHit)/maxDiff)+1); } else { sb.append("-1"); } sb.append("\n"); } System.out.println(sb); } static class InputReader { BufferedReader reader ; StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream)); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class ZmeiGorynich { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var ir : InputReader ; ir := InputReader.newInputReader(OclFile["System.in"]) ; var sb : String ; sb := StringLib.newString() ; var t : int ; t := ir.nextInt() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := ir.nextInt() ; var x : int ; x := ir.nextInt() ; var maxDiff : int ; maxDiff := 0 ; var maxHit : int ; maxHit := 0 ; var i : int ; i := 0 ; while (i < n) do ( var d : int ; d := ir.nextInt() ; var h : int ; h := ir.nextInt() ; maxHit := Set{maxHit, d}->max() ; maxDiff := Set{maxDiff, d - h}->max() ; i := i + 1 ; ) ; if (maxHit >= x) then ( sb := sb + StringLib.newString('1') ) else if (maxDiff > 0) then ( sb := sb + StringLib.newString(((x - maxHit)->oclAsType(double) / maxDiff)->ceil()->oclAsType(int) + 1) ) else ( sb := sb + StringLib.newString("-1") ) ; ; sb := sb + StringLib.newString("\n") ; ) ; ) ; OclFile["System.out"].println(sb) ; ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); label : for(int x=0 ; x=0 ; i--){ if(s[i]=='0'){ for(int k=0 ; k<61 ; k++){ if((a[i]>>k & 1)==1){ for(int j=0 ; j>k & 1)==1){ a[j] ^=a[i]; } } } } } else { if(a[i]!=0){ System.out.println(1); continue label ; } } } System.out.println(0); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var t : int ; t := (br.readLine())->toInteger() ; var x : int ; x := 0 ; while x < t do ( ( var n : int ; n := (br.readLine())->toInteger() ; var sa : Sequence(String) ; sa := br.readLine()->split(" ") ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (sa[i+1])->toLong() ) ; i := i + 1 ) ; var s : Sequence(String) ; s := br.readLine()->characters() ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (s[i+1] = '0') then ( var k : int ; k := 0 ; while k < 61 do ( ( if ((MathLib.bitwiseAnd((a[i+1]/(2->pow(k)))->oclAsType(long),1)) = 1) then ( var j : int ; j := 0 ; while j < n do ( ( if (i /= j & (MathLib.bitwiseAnd((a[j+1]/(2->pow(k)))->oclAsType(long),1)) = 1) then ( a[j+1] := MathLib.bitwiseXor(a[j+1],a[i+1]) ) else skip ) ; j := j + 1 ) ) else skip ) ; k := k + 1 ) ) else ( if (a[i+1] /= 0) then ( OclFile["System.out"].println(1) ; continue ) else skip ) ) ; i := i - 1 ) ; OclFile["System.out"].println(0) ; ) ; x := x + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int i=0 ; i=0 ; i--){ if(s[i]=='0'){ m[size]=A[i]; size++; } else { long[] work=new long[size+1]; work[0]=A[i]; for(int j=0 ; jtoInteger() ; var i : int ; i := 0 ; while i < T do ( ( var N : int ; N := sc.getCurrent()->toInteger() ; var A : Sequence(long) ; A := Integer.subrange(1,N)->collect(0) ; var j : int ; j := 0 ; while j < N do ( A[j+1] := sc.getCurrent()->toLong() ; ; j := j + 1 ) ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; OclFile["System.out"].println(solve(A, s)) ; ) ; i := i + 1 ) ; skip ); static operation solve( A : Sequence(long), s : Sequence(String)) : int pre: true post: true activity: ( var N : int ; N := A->size() ; var m : Sequence(long) ; m := Integer.subrange(1,N)->collect(0) ; var size : int ; size := 0 ; var i : int ; i := N - 1 ; while i >= 0 do ( ( if (s[i+1] = '0') then ( m[size+1] := A[i+1] ; size := size + 1 ) else ( var work : Sequence(long) ; work := Integer.subrange(1,size + 1)->collect(0) ; work[0+1] := A[i+1] ; var j : int ; j := 0 ; while j < size do ( work[j + 1+1] := m[j+1] ; ; j := j + 1 ) ; if (not(couldBeZero(work))) then ( return 1 ) else skip ) ) ; i := i - 1 ) ; return 0 ); static operation couldBeZero( m : Sequence(long)) : boolean pre: true post: true activity: ( var N : int ; N := m->size() ; var i : int ; i := 0 ; while i < 60 do ( ( var baseIndex : int ; baseIndex := -1 ; var j : int ; j := 1 ; while j < N do ( ( if ((m[j+1] & ((1l*(2->pow(i)))->oclAsType(long))) /= 0) then ( baseIndex := j ; break ) else skip ) ; j := j + 1 ) ; if (baseIndex < 0) then continue else skip ; var base : long ; base := m[baseIndex+1] ; var j : int ; j := 0 ; while j < N do ( ( if ((m[j+1] & ((1l*(2->pow(i)))->oclAsType(long))) /= 0) then ( m[j+1] := MathLib.bitwiseXor(m[j+1],base) ) else skip ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; return m[0+1] = 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean checkPerfectcube(int n){ int d=(int)Math.cbrt(n); if(d*d*d==n)return true ; return false ; } static int smallestPerfectCube(int a[],int n){ int mini=Integer.MAX_VALUE ; for(int i=0 ; icbrt()->oclAsType(int) ; if (d * d * d = n) then return true else skip ; return false ); static operation smallestPerfectCube( a : Sequence(int), n : int) : int pre: true post: true activity: ( var mini : int ; mini := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( if (checkPerfectcube(a[i+1])) then ( mini := Set{a[i+1], mini}->min() ) else skip ) ; i := i + 1 ) ; return mini ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{16,8,25,2,3,10} ; var n : int ; n := a->size() ; OclFile["System.out"].print(smallestPerfectCube(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int sum(int n){ int sum=0 ; while(n>0){ sum=sum+n % 10 ; n=n/10 ; } return sum ; } static void firstN(int n){ int num=19,cnt=1 ; while(cnt!=n){ if(sum(num)==10){ System.out.print(num+" "); cnt++; } num+=9 ; } } public static void main(String[] args){ int n=10 ; firstN(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sum( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; while (n > 0) do ( sum := sum + n mod 10 ; n := n / 10 ) ; return sum ); static operation firstN( n : int) : void pre: true post: true activity: ( var num : int ; num := 19 ; var cnt : int ; cnt := 1 ; while (cnt /= n) do ( if (sum(num) = 10) then ( OclFile["System.out"].print(num + " ") ; cnt := cnt + 1 ) else skip ; num := num+(9) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; execute firstN(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void pairwiseProduct(int[] arr,int n){ int prod=1 ; for(int i=0 ; isize() ; execute pairwiseProduct(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final int FAVOURITE_NUMBER=753 ; public static int process(TestCase testCase){ String S=testCase.S ; int min=Integer.MAX_VALUE ; for(int i=2,length=S.length(); isize() ; while i < length do ( ( var num : int ; num := (S.subrange(i - 2+1,i + 1))->toInteger() ; min := Set{min, diff(num)}->min() ) ; i := i + 1 ) ; return min ); static operation diff( num : int) : int pre: true post: true activity: ( return if FAVOURITE_NUMBER - num < 0 then -(FAVOURITE_NUMBER - num) else FAVOURITE_NUMBER - num endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var testCase : TestCase ; testCase := readFromInput() ; var result : int ; result := process(testCase) ; execute output(result) ); static operation readFromInput() : TestCase pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : String ; S := sc.getCurrent() ; skip ; return TestCase.newTestCase(S) ); static operation output( result : int) : void pre: true post: true activity: ( OclFile["System.out"].println(result) ); static class TestCase { attribute S : String; static operation newTestCase( S : String) : TestCase pre: true post: true activity: ( var self : TestCase ; self := createTestCase(); self.initialise(S); return self ); operation initialise( S : String) : void pre: true post: true activity: ( self.S := S ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); String s=sc.next(); String A ; int num[]=new int[3]; int ans=0 ; int answer=0 ; int result=1000 ; String slist[]=s.split(""); for(int i=2 ; icollect(0) ; var ans : int ; ans := 0 ; var answer : int ; answer := 0 ; var result : int ; result := 1000 ; var slist : Sequence(String) ; slist := s->split("") ; var i : int ; i := 2 ; while i < slist->size() do ( ( A := slist[(i)->char2byte() - 2+1] + slist[(i)->char2byte() - 1+1] + slist[i+1] ; ans := (A)->toInteger() ; answer := if 753 - ans < 0 then -(753 - ans) else 753 - ans endif ; if (answer < result) then ( result := answer ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileNotFoundException ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class B { public static void main(String[] args)throws FileNotFoundException { FastReader fr=new FastReader(); PrintWriter out=new PrintWriter(System.out); StringBuilder st=new StringBuilder(""); int t=fr.nextInt(); while(t-->0){ int n=fr.nextInt(); int nn=n ; int k=fr.nextInt(); nn-=k-1 ; boolean bo=false ; if(nn % 2==1 && nn>=1){ bo=true ; st.append("YES\n"); for(int i=0 ; i=2){ bo=true ; st.append("YES\n"); for(int i=0 ; i 0) do ( t := t - 1 ; skip ; ( var n : int ; n := fr.nextInt() ; var nn : int ; nn := n ; var k : int ; k := fr.nextInt() ; nn := nn-(k - 1) ; var bo : boolean ; bo := false ; if (nn mod 2 = 1 & nn >= 1) then ( bo := true ; st := st + StringLib.newString("YES\n") ; var i : int ; i := 0 ; while i < k - 1 do ( ( st := st + StringLib.newString(1 + " ") ) ; i := i + 1 ) ; st := st + StringLib.newString(nn + "\n") ) else ( n := n-(2 * (k - 1)) ; if (n mod 2 = 0 & n >= 2) then ( bo := true ; st := st + StringLib.newString("YES\n") ; var i : int ; i := 0 ; while i < k - 1 do ( ( st := st + StringLib.newString(2 + " ") ) ; i := i + 1 ) ; st := st + StringLib.newString(n + "\n") ) else skip ) ; if (not(bo)) then ( st := st + StringLib.newString("NO\n") ) else skip ; ) ; ) ; skip ; skip ; ); static class FastReader { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do skip ; return st.next() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static final int number=753 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); String S=sc.nextLine(); int max=Integer.MAX_VALUE ; for(int a=0 ; a<=S.length()-3 ; a++){ int k=Integer.parseInt(S.substring(a,a+3)); max=Math.min(max,Math.abs(k-number)); } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute number : int := 753; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : String ; S := sc.nextLine() ; var max : int ; max := 2147483647 ; var a : int ; a := 0 ; while a <= S->size() - 3 do ( ( var k : int ; k := (S.subrange(a+1,a + 3))->toInteger() ; max := Set{max, if k - number < 0 then -(k - number) else k - number endif}->min() ) ; a := a + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); while(scanner.hasNextLine()){ String s=scanner.nextLine(); int min=1000000 ; for(int i=0 ; i<=s.length()-3 ; i++){ String c=s.substring(i,i+3); int p=Integer.parseInt(c); min=Math.min(Math.abs(p-753),min); } System.out.println(min); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (scanner.hasNextLine()) do ( var s : String ; s := scanner.nextLine() ; var min : int ; min := 1000000 ; var i : int ; i := 0 ; while i <= s->size() - 3 do ( ( var c : String ; c := s.subrange(i+1,i + 3) ; var p : int ; p := (c)->toInteger() ; min := Set{if (p)->char2byte() - 753 < 0 then -((p)->char2byte() - 753) else (p)->char2byte() - 753 endif, min}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static void main(String args[]){ float P=1,R=1,T=1 ; float SI=(P*T*R)/100 ; System.out.println("Simple interest="+SI); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var P : double ; P := 1 ; var R : double ; R := 1 ; var T : double ; T := 1 ; var SI : double ; SI := (P * T * R) / 100 ; OclFile["System.out"].println("Simple interest=" + SI) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { long mod=(long)Math.pow(10,9)+7 ; Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long a=sc.nextLong(); long b=sc.nextLong(); long ans=rep2(2,n,mod)-1 ; long alla=1 ; long allb=1 ; long diva=1 ; long divb=1 ; for(int i=0 ; ipow(9)->oclAsType(long) + 7 ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var ans : long ; ans := rep2(2, n, mod) - 1 ; var alla : long ; alla := 1 ; var allb : long ; allb := 1 ; var diva : long ; diva := 1 ; var divb : long ; divb := 1 ; var i : int ; i := 0 ; while i < a do ( ( alla := alla*((n - i)) ; alla := alla mod mod ; diva := diva*((a - i)) ; diva := diva mod mod ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < b do ( ( allb := allb*((n - i)) ; allb := allb mod mod ; divb := divb*((b - i)) ; divb := divb mod mod ) ; i := i + 1 ) ; alla := alla*(rep2(diva, 10->pow(9)->oclAsType(long) + 5, mod) mod mod) ; alla := alla mod mod ; allb := allb*(rep2(divb, 10->pow(9)->oclAsType(long) + 5, mod) mod mod) ; allb := allb mod mod ; ans := ans-((alla + allb)) ; while (ans < 0) do ( ans := ans+(mod) ) ; OclFile["System.out"].println(ans mod mod) ; ); static operation rep2( b : long, n : long, mod : long) : long pre: true post: true activity: ( if (n = 0) then return 1 else skip ; if (n = 1) then return b else skip ; var bn : long ; bn := rep2(b, n / 2, mod) mod mod ; if (n mod 2 = 0) then ( return (bn mod mod * bn mod mod)->oclAsType(long) mod mod ) else ( return (bn mod mod * bn mod mod)->oclAsType(long) mod mod * b mod mod ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.net.CookieHandler ; import java.util.*; public class Main { static PrintWriter out=new PrintWriter(System.out); static Scanner sc=new Scanner(System.in); static BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); long[] frac ; long mod=1000000000+7 ; public static void main(String[] args)throws IOException { Main main=new Main(); main.solve(); } void solve()throws IOException { int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(); frac=new long[b+1]; frac[0]=1 ; for(int i=1 ; i<=b ; i++)frac[i]=frac[i-1]*i % mod ; long ans=power(2,n)+mod-1 ; ans %=mod ; ans-=helper(n-a+1,n)*inv(a)% mod ; ans-=helper(n-b+1,n)*inv(b)% mod ; ans=(ans+10*mod)% mod ; System.out.println(ans); } long inv(int m){ if(m==0)return 1 ; return power(frac[m],mod-2); } long power(long base,long p){ long ans=1 ; while(p>0){ if(p % 2==1)ans=ans*base % mod ; base=base*base % mod ; p/=2 ; } return ans ; } long helper(long from,long to){ if(from>to){ long mid=to ; to=from ; from=mid ; } long ans=from ; for(long i=from+1 ; i<=to ; i++){ ans=ans*i % mod ; } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute frac : Sequence(long); attribute mod : long := 1000000000 + 7; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.solve() ); operation solve() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; frac := Integer.subrange(1,b + 1)->collect(0) ; frac[0+1] := 1 ; var i : int ; i := 1 ; while i <= b do ( frac[i+1] := frac[i - 1+1] * i mod mod ; ; i := i + 1 ) ; var ans : long ; ans := power(2, n) + mod - 1 ; ans := ans mod mod ; ans := ans-(helper(n - a + 1, n) * inv(a) mod mod) ; ans := ans-(helper(n - b + 1, n) * inv(b) mod mod) ; ans := (ans + 10 * mod) mod mod ; OclFile["System.out"].println(ans) ; ); operation inv( m : int) : long pre: true post: true activity: ( if (m = 0) then return 1 else skip ; return power(frac[m+1], mod - 2) ); operation power( base : long, p : long) : long pre: true post: true activity: ( var ans : long ; ans := 1 ; while (p > 0) do ( if (p mod 2 = 1) then ans := ans * base mod mod ; else skip ; base := base * base mod mod ; p := p/(2) ) ; return ans ); operation helper( from : long, to : long) : long pre: true post: true activity: ( if (from > to) then ( var mid : long ; mid := to ; to := from ; from := mid ) else skip ; var ans : long ; ans := from ; var i : long ; i := from + 1 ; while i <= to do ( ( ans := ans * i mod mod ) ; i := i + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); final int n=scanner.nextInt(); final int a=scanner.nextInt(); final int b=scanner.nextInt(); int result=((modpow(2,n)-1-comb(n,a))% PRIME-comb(n,b))% PRIME ; while(result<0){ result+=PRIME ; } System.out.println(result); } static int modpow(int n,int p){ long res=1 ; long a=n ; for(a %=PRIME ; p>0 ; a=a*a % PRIME,p>>=1)if((p & 1)>0)res=res*a % PRIME ; return(int)res ; } static int tower2(int n){ if(n==1)return 2 ; return(int)((long)tower2(n/2)*tower2(n-n/2)% PRIME); } static int fact(int n){ if(n==1)return 1 ; return(int)((long)n*fact(n-1)% PRIME); } static int comb(int n,int k){ long numer=1,denom=1 ; for(int i=0 ; itoInteger() ; var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; var result : int ; result := ((modpow(2, n) - 1 - comb(n, a)) mod PRIME - comb(n, b)) mod PRIME ; while (result < 0) do ( result := result+(PRIME) ) ; OclFile["System.out"].println(result) ; ); static operation modpow( n : int, p : int) : int pre: true post: true activity: ( var res : long ; res := 1 ; var a : long ; a := n ; a := a mod PRIME ; while p > 0 do ( if ((p & 1) > 0) then res := res * a mod PRIME ; else skip ; ; a := a * a mod PRIME ; p := p/(2->pow(1)) ) ; return res->oclAsType(int) ); static operation tower2( n : int) : int pre: true post: true activity: ( if (n = 1) then return 2 else skip ; return (tower2(n / 2)->oclAsType(long) * tower2(n - n / 2) mod PRIME)->oclAsType(int) ); static operation fact( n : int) : int pre: true post: true activity: ( if (n = 1) then return 1 else skip ; return (n->oclAsType(long) * fact(n - 1) mod PRIME)->oclAsType(int) ); static operation comb( n : int, k : int) : int pre: true post: true activity: ( var numer : long ; numer := 1 ; var denom : long ; denom := 1 ; var i : int ; i := 0 ; while i < k do ( ( numer := numer * (n - i) mod PRIME ; denom := denom * (i + 1) mod PRIME ) ; i := i + 1 ) ; return (numer * inverse(denom->oclAsType(int)) mod PRIME)->oclAsType(int) ); static operation inverse( denom : int) : int pre: true post: true activity: ( if (denom = 0) then return 0 else skip ; var a : int ; a := PRIME ; var b : int ; b := denom ; var x : int ; x := 0 ; var y : int ; y := 1 ; var temp : int ; while (a mod b /= 0) do ( x := x-(a / b * y) ; temp := x ; x := y ; y := temp ; temp := a mod b ; a := b ; b := temp ; ) ; return y ); static attribute PRIME : int := 1000000007; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printPattern(int n){ int t ; for(int i=1 ; i<=n ; i++){ for(int j=i ; j ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static long inv[]; static int mod=1_000_000_007 ; static long pow(long a,int n){ long res=1 ; while(n>0){ if((n-n/2*2)==1){ res=res*a % mod ; } a=a*a % mod ; n>>=1 ; } return res ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); inv=new long[b+1]; inv[1]=1 ; for(int i=2 ; i<=b ; i++){ inv[i]=inv[mod % i]*(mod-mod/i)% mod ; } long comb[]=new long[b+1]; comb[0]=1 ; for(int i=1 ; i<=b ; i++){ comb[i]=comb[i-1]*((n-i+1)% mod); comb[i] %=mod ; comb[i]*=inv[i]; comb[i] %=mod ; } long ans=pow(2,n); ans-=1 ; ans %=mod ; ans-=comb[a]; if(ans<0){ ans+=mod ; } ans %=mod ; ans-=comb[b]; if(ans<0){ ans+=mod ; } ans %=mod ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute inv : Sequence(long); static attribute mod : int := 1_000_000_007; static operation pow( a : long, n : int) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (n > 0) do ( if ((n - n / 2 * 2) = 1) then ( res := res * a mod mod ) else skip ; a := a * a mod mod ; n := n/(2->pow(1)) ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; inv := Integer.subrange(1,b + 1)->collect(0) ; inv[1+1] := 1 ; var i : int ; i := 2 ; while i <= b do ( ( inv[i+1] := inv[mod mod i+1] * (mod - mod / i) mod mod ) ; i := i + 1 ) ; var comb : Sequence(long) ; comb := Integer.subrange(1,b + 1)->collect(0) ; comb[0+1] := 1 ; var i : int ; i := 1 ; while i <= b do ( ( comb[i+1] := comb[i - 1+1] * ((n - i + 1) mod mod) ; comb[i+1] := comb[i+1] mod mod ; comb[i+1] := comb[i+1]*(inv[i+1]) ; comb[i+1] := comb[i+1] mod mod ) ; i := i + 1 ) ; var ans : long ; ans := pow(2, n) ; ans := ans-(1) ; ans := ans mod mod ; ans := ans-(comb[a+1]) ; if (ans < 0) then ( ans := ans+(mod) ) else skip ; ans := ans mod mod ; ans := ans-(comb[b+1]) ; if (ans < 0) then ( ans := ans+(mod) ) else skip ; ans := ans mod mod ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { solve(System.in,System.out); } static final int MOD=(int)Math.pow(10,9)+7 ; static void solve(InputStream is,PrintStream os){ Scanner scan=new Scanner(is); int n=scan.nextInt(); int a=scan.nextInt(); int b=scan.nextInt(); long ret=powMod(2,n)-1-combinationMod(n,a)-combinationMod(n,b); ret %=MOD ; os.println(ret<0 ? ret+MOD : ret); } static long powMod(long seed,long n){ long ret=1 ; while(n>0){ if((n & 1)==1)ret=seed*ret % MOD ; seed=seed*seed % MOD ; n=n>>1 ; } return ret ; } static long combinationMod(long n,long k){ long ret=1 ; for(long i=n ; i>=n-k+1 ; i--){ ret=ret*i % MOD ; BigInteger inv=new BigInteger(String.valueOf(n-i+1)).modInverse(BigInteger.valueOf(MOD)); ret=ret*inv.longValue()% MOD ; } return ret ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve(OclFile["System.in"], OclFile["System.out"]) ); static attribute MOD : int := 10->pow(9)->oclAsType(int) + 7; static operation solve( is : OclFile, os : OclFile) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(is) ; var n : int ; n := scan.getCurrent()->toInteger() ; var a : int ; a := scan.getCurrent()->toInteger() ; var b : int ; b := scan.getCurrent()->toInteger() ; var ret : long ; ret := powMod(2, n) - 1 - combinationMod(n, a) - combinationMod(n, b) ; ret := ret mod MOD ; os.println(if ret < 0 then ret + MOD else ret endif) ; ); static operation powMod( seed : long, n : long) : long pre: true post: true activity: ( var ret : long ; ret := 1 ; while (n > 0) do ( if ((MathLib.bitwiseAnd(n,1)) = 1) then ret := seed * ret mod MOD ; else skip ; seed := seed * seed mod MOD ; n := (n/(2->pow(1)))->oclAsType(long) ) ; return ret ); static operation combinationMod( n : long, k : long) : long pre: true post: true activity: ( var ret : long ; ret := 1 ; var i : long ; i := n ; while i >= n - k + 1 do ( ( ret := ret * i mod MOD ; var inv : long ; inv := long(((n - i + 1) + "")).modInverse((MOD + "")->toLong()) ; ret := ret * inv->oclAsType(long) mod MOD ) ; i := i - 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.lang.Math ; public class cp { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[])throws Exception { FastReader sc=new FastReader(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int k=sc.nextInt(); int sumodd=n-k+1 ; int sumev=n-2*k+2 ; if(sumodd % 2!=0 && sumodd>0){ System.out.println("YES"); for(int i=0 ; i0){ System.out.println("YES"); for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var t : int ; t := sc.nextInt() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.nextInt() ; var k : int ; k := sc.nextInt() ; var sumodd : int ; sumodd := n - k + 1 ; var sumev : int ; sumev := n - 2 * k + 2 ; if (sumodd mod 2 /= 0 & sumodd > 0) then ( OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < k - 1 do ( OclFile["System.out"].print("1 ") ; ; i := i + 1 ) ; OclFile["System.out"].println(sumodd) ) else if (sumev mod 2 = 0 & sumev > 0) then ( OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < k - 1 do ( OclFile["System.out"].print("2 ") ; ; i := i + 1 ) ; OclFile["System.out"].println(sumev) ) else ( OclFile["System.out"].println("NO") ) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.lang.Math ; public class Reconnaissance { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n,d ; int count=0 ; n=sc.nextInt(); d=sc.nextInt(); int[] arr ; arr=new int[1001]; for(int i=0 ; itoInteger() ; d := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,1001)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( var k : int ; k := 0 ; while k < n do ( ( var m : int ; m := if arr[j+1] - arr[k+1] < 0 then -(arr[j+1] - arr[k+1]) else arr[j+1] - arr[k+1] endif ; if (m <= d & j /= k) then ( count := count + 1 ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ; OclFile["System.out"].println(count) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.rmi.server.RemoteServer ; import java.security.cert.CollectionCertStoreParameters ; import java.util.*; import javax.xml.transform.SourceLocator ; public class A_Reconnaissance { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); long k=s.nextLong(); long arr[]=new long[n]; for(int i=0 ; ik)break ; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class A_Reconnaissance { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var k : long ; k := s.getCurrent()->toLong() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toLong() ) ; i := i + 1 ) ; var count : int ; count := 0 ; arr := arr->sort() ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (if arr[i+1] - arr[j+1] < 0 then -(arr[i+1] - arr[j+1]) else arr[i+1] - arr[j+1] endif <= k) then ( count := count+(2) ) else skip ; if (if arr[i+1] - arr[j+1] < 0 then -(arr[i+1] - arr[j+1]) else arr[i+1] - arr[j+1] endif > k) then break else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int d=Integer.parseInt(sc.next()); sc.nextLine(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var d : int ; d := (sc.getCurrent())->toInteger() ; skip ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (if arr[i+1] - arr[j+1] < 0 then -(arr[i+1] - arr[j+1]) else arr[i+1] - arr[j+1] endif <= d) then ( res := res + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(res * 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { static final int INF=0x3f3f3f3f ; static final long LNF=0x3f3f3f3f3f3f3f3fL ; public static void main(String[] args)throws IOException { initReader(); long a=nextInt(),b=nextInt(); long c[]=new long[(int)a]; for(int i=0 ; ioclAsType(int))->collect(0) ; var i : int ; i := 0 ; while i < a do ( ( c[i+1] := nextLong() ) ; i := i + 1 ) ; c := c->sort() ; var num : int ; num := 0 ; var i : int ; i := 0 ; while i < a do ( ( var j : int ; j := i + 1 ; while (j < a) do ( if (c[j+1] - c[i+1] <= b) then ( num := num + 1 ; j := j + 1 ) else break ) ) ; i := i + 1 ) ; pw.println(2 * num) ; pw.close() ; ); static attribute reader : OclFile; static attribute tokenizer : OclIterator; static attribute pw : OclFile; static operation initReader() : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; tokenizer := OclIterator.newOclIterator_String("") ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ); static operation hasNext() : boolean pre: true post: true activity: ( try ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (e : ProgramException) do ( return false ) return true ); static operation next() : String pre: true post: true activity: ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ; return tokenizer.next() ); static operation nextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (e : ProgramException) do ( return null ) ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); static operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); static operation nextChar() : String pre: true post: true activity: ( return next()->at(0+1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean checkDivisibility(String num){ int length=num.length(); if(length==1 && num.charAt(0)=='0')return true ; if(length % 3==1){ num+="00" ; length+=2 ; } else if(length % 3==2){ num+="0" ; length+=1 ; } int sum=0,p=1 ; for(int i=length-1 ; i>=0 ; i--){ int group=0 ; group+=num.charAt(i--)-'0' ; group+=(num.charAt(i--)-'0')*10 ; group+=(num.charAt(i)-'0')*100 ; sum=sum+group*p ; p*=(-1); } sum=Math.abs(sum); return(sum % 13==0); } public static void main(String[] args){ String number="83959092724" ; if(checkDivisibility(number))System.out.println(number+" is divisible by 13."); else System.out.println(number+" is not divisibe by 13."); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkDivisibility( num : String) : boolean pre: true post: true activity: ( var length : int ; length := num->size() ; if (length = 1 & num->at(0+1) = '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 ; sum := 0 ; var p : int ; p := 1 ; var i : int ; i := length - 1 ; while i >= 0 do ( ( var group : int ; group := 0 ; group := group+(num->at(i+1) - ('0')->char2byte()) ; group := group+((num->at(i+1) - ('0')->char2byte()) * 10) ; group := group+((num->at(i+1) - ('0')->char2byte()) * 100) ; sum := sum + group * p ; p := p*((-1)) ; ) ; i := i - 1 ) ; sum := if sum < 0 then -(sum) else sum endif ; return (sum mod 13 = 0) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var number : String ; number := "83959092724" ; if (checkDivisibility(number)) then OclFile["System.out"].println(number + " is divisible by 13.") ; else OclFile["System.out"].println(number + " is not divisibe by 13.") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GfG { static Boolean isOverflow(long a,long b){ if(a==0 || b==0)return false ; long result=a*b ; if(a==result/b)return false ; else return true ; } public static void main(String argc[]){ long a=Long.parseLong("10000000000"); long b=Long.parseLong("-10000000000"); if(isOverflow(a,b))System.out.print("Yes"); else System.out.print("No"); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation isOverflow( a : long, b : long) : Boolean pre: true post: true activity: ( if (a = 0 or b = 0) then return false else skip ; var result : long ; result := a * b ; if (a = result / b) then return false else return true ); static operation main( argc : Sequence(String)) : void pre: true post: true activity: ( var a : long ; a := ("10000000000")->toLong() ; var b : long ; b := ("-10000000000")->toLong() ; if (isOverflow(a, b)) then OclFile["System.out"].print("Yes") ; else OclFile["System.out"].print("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class A { public static void main(String[] args){ FastScanner fs=new FastScanner(); int t=fs.nextInt(); while(t-->0){ long l=fs.nextLong(); long r=fs.nextLong(); if(l*2>r)System.out.println("YES"); else System.out.println("NO"); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next(){ while(! st.hasMoreElements())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fs : FastScanner ; fs := FastScanner.newFastScanner() ; var t : int ; t := fs.nextInt() ; while (t > 0) do ( t := t - 1 ; skip ; ( var l : long ; l := fs.nextLong() ; var r : long ; r := fs.nextLong() ; if (l * 2 > r) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ) ; ) ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF_1437A_MarketingScheme { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int count=scanner.nextInt(); for(int i=0 ; ir){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class CF_1437A_MarketingScheme { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var count : int ; count := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < count do ( ( var l : int ; l := scanner.getCurrent()->toInteger() ; var r : int ; r := scanner.getCurrent()->toInteger() ; if (2 * l > r) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static class Point { int x,y ; } static boolean doOverlap(Point l1,Point r1,Point l2,Point r2){ if(l1.x>=r2.x || l2.x>=r1.x){ return false ; } if(l1.y<=r2.y || l2.y<=r1.y){ return false ; } return true ; } public static void main(String[] args){ Point l1=new Point(),r1=new Point(),l2=new Point(),r2=new Point(); l1.x=0 ; l1.y=10 ; r1.x=10 ; r1.y=0 ; l2.x=5 ; l2.y=5 ; r2.x=15 ; r2.y=0 ; if(doOverlap(l1,r1,l2,r2)){ System.out.println("Rectangles Overlap"); } else { System.out.println("Rectangles Don't Overlap"); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static class Point { attribute x : int; } static operation doOverlap( l1 : Point, r1 : Point, l2 : Point, r2 : Point) : boolean pre: true post: true activity: ( if (l1.x >= r2.x or l2.x >= r1.x) then ( return false ) else skip ; if (l1.y <= r2.y or l2.y <= r1.y) then ( return false ) else skip ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l1 : Point ; l1 := Point.newPoint() ; var r1 : Point ; r1 := Point.newPoint() ; var l2 : Point ; l2 := Point.newPoint() ; var r2 : Point ; r2 := Point.newPoint() ; l1.x := 0 ; l1.y := 10 ; r1.x := 10 ; r1.y := 0 ; l2.x := 5 ; l2.y := 5 ; r2.x := 15 ; r2.y := 0 ; if (doOverlap(l1, r1, l2, r2)) then ( OclFile["System.out"].println("Rectangles Overlap") ) else ( OclFile["System.out"].println("Rectangles Don't Overlap") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static int dp[]; public static int MM=1000001 ; public static void main(String args[]){ Scanner sc=new Scanner(System.in); dp=new int[MM]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < MM do ( ( dp[i+1] := -1 ) ; i := i + 1 ) ; while (true) do ( var N : int ; N := sc.getCurrent()->toInteger() ; if (N = 0) then ( break ) else skip ; OclFile["System.out"].println(recursion(N)) ) ); static operation recursion( in : int) : int pre: true post: true activity: ( if (in = 1) then ( return 0 ) else skip ; if (in < MM) then ( if (dp[in+1] /= -1) then ( return dp[in+1] ) else ( if (in mod 2 = 1) then ( return dp[in+1] ) else ( return dp[in+1] ) ) ) else ( if (in mod 2 = 1) then ( return recursion(in * 3 + 1) + 1 ) else ( return recursion(in / 2) + 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; i=0 && n1 % 2==0){ System.out.println("YES"); for(int j=0 ; j=0 && n2 % 2==0){ System.out.println("YES"); for(int j=0 ; jtoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var n1 : int ; n1 := n - k ; if (n1 >= 0 & n1 mod 2 = 0) then ( OclFile["System.out"].println("YES") ; var j : int ; j := 0 ; while j < k - 1 do ( ( OclFile["System.out"].print("1 ") ) ; j := j + 1 ) ; OclFile["System.out"].println((1 + n1)) ; continue ) else skip ; var n2 : int ; n2 := n - 2 * k ; if (n2 >= 0 & n2 mod 2 = 0) then ( OclFile["System.out"].println("YES") ; var j : int ; j := 0 ; while j < k - 1 do ( ( OclFile["System.out"].print("2 ") ) ; j := j + 1 ) ; OclFile["System.out"].println((2 + n2)) ; continue ) else skip ; OclFile["System.out"].println("NO") ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,count ; for(; ; out.println(count)){ n=sc.nextInt(); if(n==0)break ; for(count=0 ; n!=1 ; count++){ if(n % 2==0)n/=2 ; else n=n*3+1 ; } } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var n : int ; var count : int ; while true do ( ( n := sc.nextInt() ; if (n = 0) then break else skip ; count := 0 ; while n /= 1 do ( ( if (n mod 2 = 0) then n := n/(2) ; else n := n * 3 + 1 ; ) ; count := count + 1 ) ) ; out.println(count) ) ; sc.close() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str="" ; while((str=br.readLine())!=null){ int ans=Integer.parseInt(str); if(ans==0)break ; int cnt=0 ; while(true){ if(ans==1)break ; if(ans % 2==0){ ans/=2 ; } else { ans=ans*3+1 ; } cnt++; } System.out.println(cnt); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : String ; str := "" ; str := br.readLine() ; while ((str) /= null) do ( skip ; ( var ans : int ; ans := (str)->toInteger() ; if (ans = 0) then break else skip ; var cnt : int ; cnt := 0 ; while (true) do ( if (ans = 1) then break else skip ; if (ans mod 2 = 0) then ( ans := ans/(2) ) else ( ans := ans * 3 + 1 ) ; cnt := cnt + 1 ) ; OclFile["System.out"].println(cnt) ; ) ; str := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static int[] dp ; static int f(int n){ if(dp[n]!=-1)return dp[n]; if(n % 2==0)return dp[n]=f(n/2)+1 ; else return dp[n]=f(n*3+1)+1 ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); dp=new int[1000001]; Arrays.fill(dp,-1); dp[1]=0 ; while(true){ int x=sc.nextInt(); if(x==0)break ; System.out.println(f(x)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute dp : Sequence(int); static operation f( n : int) : int pre: true post: true activity: ( if (dp[n+1] /= -1) then return dp[n+1] else skip ; if (n mod 2 = 0) then return dp[n+1] else return dp[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; dp := Integer.subrange(1,1000001)->collect(0) ; dp := dp->collect(-1) ; dp[1+1] := 0 ; while (true) do ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x = 0) then break else skip ; OclFile["System.out"].println(f(x)) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); static int n ; public static void main(String[] args){ while(read()){ slove(); } } static boolean read(){ n=sc.nextInt(); if(n!=0)return true ; return false ; } static void slove(){ int i=0 ; while(n!=1){ if(n % 2==0){ n=n/2 ; } else { n=n*3+1 ; } i++; } System.out.println(i); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute n : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (read()) do ( execute slove() ) ); static operation read() : boolean pre: true post: true activity: ( n := sc.getCurrent()->toInteger() ; if (n /= 0) then return true else skip ; return false ); static operation slove() : void pre: true post: true activity: ( var i : int ; i := 0 ; while (n /= 1) do ( if (n mod 2 = 0) then ( n := n / 2 ) else ( n := n * 3 + 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(i) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A { static FastReader sc=null ; public static void main(String[] args){ sc=new FastReader(); int t=1 ; for(int tt=0 ; tt0 && w+c>=l && l+c>=w)System.out.println("?"); else { if(c==0 && w==l)System.out.println("0"); else if(w>l)System.out.println("+"); else System.out.println("-"); } } } static int[] ruffleSort(int a[]){ ArrayListal=new ArrayList<>(); for(int i : a)al.add(i); Collections.sort(al); for(int i=0 ; i 0 & w + c >= l & l + c >= w) then OclFile["System.out"].println("?") ; else ( if (c = 0 & w = l) then OclFile["System.out"].println("0") ; else if (w > l) then OclFile["System.out"].println("+") else OclFile["System.out"].println("-") ; ; ) ) ; tt := tt + 1 ) ); static operation ruffleSort( a : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var al : Sequence(int) ; al := Sequence{} ; for (i : a) do ( al := al->including(i) ; ) ; al := al->sort() ; var i : int ; i := 0 ; while i < a->size() do ( a[i+1] := al->at(i+1) ; ; i := i + 1 ) ; return a ); static operation print( a : Sequence(int)) : void pre: true post: true activity: ( for (e : a) do ( ( OclFile["System.out"].print(e + " ") ) ) ; OclFile["System.out"].println() ); static class FastReader { attribute st : OclIterator := OclIterator.newOclIterator_String(""); attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.nextInt() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] arg){ Scanner sc=new Scanner(System.in); int up=sc.nextInt(),down=sc.nextInt(),un=sc.nextInt(); if(up-down>0 && untoInteger() ; var down : int ; down := sc.getCurrent()->toInteger() ; var un : int ; un := sc.getCurrent()->toInteger() ; if (up - down > 0 & un < up - down) then OclFile["System.out"].println("+") ; else if (up - down < 0 & un < down - up) then OclFile["System.out"].println("-") else if (up - down = 0 & un = 0) then OclFile["System.out"].println("0") else OclFile["System.out"].println("?") ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] arg){ Scanner sc=new Scanner(System.in); int up=sc.nextInt(),down=sc.nextInt(),un=sc.nextInt(); if(Math.abs(up-down)>0 && un>=Math.abs(up-down)|| Math.abs(up-down)==0 && un>Math.abs(up-down))System.out.println("?"); else if(up-down>0 && untoInteger() ; var down : int ; down := sc.getCurrent()->toInteger() ; var un : int ; un := sc.getCurrent()->toInteger() ; if (if up - down < 0 then -(up - down) else up - down endif > 0 & un >= if up - down < 0 then -(up - down) else up - down endif or if up - down < 0 then -(up - down) else up - down endif = 0 & un > if up - down < 0 then -(up - down) else up - down endif) then OclFile["System.out"].println("?") ; else if (up - down > 0 & un < up - down) then OclFile["System.out"].println("+") else if (up - down < 0 & un < down - up) then OclFile["System.out"].println("-") else if (up - down = 0 & un = 0) then OclFile["System.out"].println("0") ; else skip ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean match_words(String dictionary[],String sentence[],int n,int m){ Mapmp=new HashMap<>(); for(int i=0 ; ikeys()->includes(dictionary[i+1])) then ( mp := mp->union(Map{dictionary[i+1] |-> mp->at(dictionary[i+1]) + 1}) ) else ( mp := mp->union(Map{dictionary[i+1] |-> 1}) ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (mp->keys()->includes(sentence[i+1])) then mp := mp->union(Map{sentence[i+1] |-> mp->at(sentence[i+1]) - 1}) ; else return false ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var dictionary : Sequence(String) ; dictionary := Sequence{"find","a","geeks","all","for","on","geeks","answers","inter"} ; var n : int ; n := dictionary->size() ; var sentence : Sequence(String) ; sentence := Sequence{"find","all","answers","on","geeks","for","geeks"} ; var m : int ; m := sentence->size() ; if (match_words(dictionary, sentence, n, m)) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { private class LargerNumberComparator implements Comparator{ @ Override public int compare(String a,String b){ String order1=a+b ; String order2=b+a ; return order2.compareTo(order1); } } public String largestNumber(int[] nums){ String[] asStrs=new String[nums.length]; for(int i=0 ; i,(,boolean)) { operation compare( a : String, b : String) : int pre: true post: true activity: ( var order1 : String ; order1 := a + b ; var order2 : String ; order2 := b + a ; return order2->compareTo(order1) ); } operation largestNumber( nums : Sequence(int)) : String pre: true post: true activity: ( var asStrs : Sequence(String) ; asStrs := Integer.subrange(1,nums->size())->collect(null) ; var i : int ; i := 0 ; while i < nums->size() do ( ( asStrs[i+1] := ((nums[i+1]) + "") ) ; i := i + 1 ) ; asStrs := OclComparator.sortWith(asStrs, LargerNumberComparator.newLargerNumberComparator()) ; if (asStrs[0+1] = "0") then ( return "0" ) else skip ; var largestNumberStr : String ; largestNumberStr := StringLib.newString() ; for (numAsStr : asStrs) do ( ( largestNumberStr := largestNumberStr+(numAsStr) ) ) ; return largestNumberStr ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int R=3 ; static final int C=3 ; static final int MAX_K=100 ; static int[][][] dp=new int[R][C][MAX_K]; static int pathCountDPRecDP(int[][] mat,int m,int n,int k){ if(m<0 || n<0)return 0 ; if(m==0 && n==0)return(k==mat[m][n] ? 1 : 0); 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]; } static int pathCountDP(int[][] mat,int k){ for(int i=0 ; icollect(Integer.subrange(1,C)->collect(Integer.subrange(1,MAX_K)->collect(0))); static operation pathCountDPRecDP( mat : Sequence(Sequence(int)), m : int, n : int, k : int) : int pre: true post: true activity: ( if (m < 0 or n < 0) then return 0 else skip ; if (m = 0 & n = 0) then return (if k = mat[m+1][n+1] then 1 else 0 endif) 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] ); static operation pathCountDP( mat : Sequence(Sequence(int)), k : int) : int pre: true post: true activity: ( var i : int ; i := 0 ; while i < R do ( var j : int ; j := 0 ; while j < C do ( var l : int ; l := 0 ; while l < MAX_K do ( dp[i+1][j+1][l+1] := -1 ; ; l := l + 1 ) ; ; j := j + 1 ) ; ; i := i + 1 ) ; return pathCountDPRecDP(mat, R - 1, C - 1, k) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 12 ; var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{1,2,3},Sequence{4,6,5},Sequence{3,2,1}} ; OclFile["System.out"].println(pathCountDP(mat, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int N=scan.nextInt(); String previous=scan.next(); String next ; Setused_words=new HashSet(); used_words.add(previous); while(N>1){ next=scan.next(); if(!((previous.charAt(previous.length()-1)==next.charAt(0))&& used_words.add(next))){ System.out.println("No"); scan.close(); return ; } previous=next ; N--; } scan.close(); System.out.println("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scan.getCurrent()->toInteger() ; var previous : String ; previous := scan.getCurrent() ; var next : String ; var used_words : Set(String) ; used_words := Set{} ; used_words := used_words->including(previous) ; while (N > 1) do ( next := scan.getCurrent() ; if (not(((previous->at(previous->size() - 1+1) = next->at(0+1)) & used_words->excludes(next)))) then ( OclFile["System.out"].println("No") ; skip ; return ) else skip ; previous := next ; N := N - 1 ) ; skip ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maximumXor(int arr[],int n){ StacksForward=new Stack(),sBackward=new Stack(); int ans=-1 ; for(int i=0 ; iisEmpty()) & arr[i+1] < arr[sForward->min()+1]) do ( ans := Set{ans, arr[i+1] xor arr[sForward->min()+1]}->max() ; sForward := sForward->front() ) ; sForward := sForward->including(i) ; while (not(sBackward->isEmpty()) & arr[n - i - 1+1] < arr[sBackward->min()+1]) do ( ans := Set{ans, arr[n - i - 1+1] xor arr[sBackward->min()+1]}->max() ; sBackward := sBackward->front() ) ; sBackward->excludes(n - i - 1) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{8,1,2} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(maximumXor(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; class GFG { static double PI=3.14159265 ; public static double area_cicumscribed(double c){ return(c*c*(PI/4)); } public static void main(String[] args){ double c=8.0 ; System.out.println(area_cicumscribed(c)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute PI : double := 3.14159265; static operation area_cicumscribed( c : double) : double pre: true post: true activity: ( return (c * c * (PI / 4)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var c : double ; c := 8.0 ; OclFile["System.out"].println(area_cicumscribed(c)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isValidSeq(int[] a,int n){ int nodes=n+2 ; for(int i=0 ; inodes)return false ; } return true ; } public static void main(String[] args){ int a[]={ 4,1,3,4 }; int n=a.length ; if(isValidSeq(a,n))System.out.println("Valid"); else System.out.print("Invalid"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isValidSeq( a : Sequence(int), n : int) : boolean pre: true post: true activity: ( var nodes : int ; nodes := n + 2 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] < 1 or a[i+1] > nodes) then return false else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{4,1,3,4} ; var n : int ; n := a->size() ; if (isValidSeq(a, n)) then OclFile["System.out"].println("Valid") ; else OclFile["System.out"].print("Invalid") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.*; public class GFG { static double INF=1e9 ; static int MAX=50 ; static void minMaxValues(int[] arr,int n,int m){ int sum=0 ; for(int i=0 ; i<(n+m); i++){ sum+=arr[i]; arr[i]+=50 ; } boolean dp[][]=new boolean[MAX+1][MAX*MAX+1]; dp[0][0]=true ; for(int i=0 ; i<(n+m); i++){ for(int k=Math.min(n,i+1); k>=1 ; k--){ for(int j=0 ; jcollect(Integer.subrange(1,MAX * MAX + 1)->collect(false)) ; dp[0+1][0+1] := true ; var i : int ; i := 0 ; while i < (n + m) do ( ( var k : int ; k := Set{n, i + 1}->min() ; while k >= 1 do ( ( var j : int ; j := 0 ; while j < MAX * MAX + 1 do ( ( if (dp[k - 1+1][j+1]) then dp[k+1][j + arr[i+1]+1] := true ; else skip ) ; j := j + 1 ) ) ; k := k - 1 ) ) ; i := i + 1 ) ; var max_value : double ; max_value := -1 * INF ; var min_value : double ; min_value := INF ; var i : int ; i := 0 ; while i < MAX * MAX + 1 do ( ( if (dp[n+1][i+1]) then ( var temp : int ; temp := i - 50 * n ; max_value := Set{max_value, temp * (sum - temp)}->max() ; min_value := Set{min_value, temp * (sum - temp)}->min() ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print("Maximum Value: " + max_value->oclAsType(int) + "\n" + "Minimum Value: " + min_value->oclAsType(int) + "\n") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; var m : int ; m := 2 ; var arr : Sequence(int) ; arr := Sequence{1,2,3,4} ; execute minMaxValues(arr, n, m) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Stack ; class GFG { static void reverse(String k){ Stacks=new Stack<>(); String[] token=k.split(" "); for(int i=0 ; isplit(" ") ; var i : int ; i := 0 ; while i < token->size() do ( ( s := s->append(token[i+1]) ) ; i := i + 1 ) ; while (not(s->isEmpty())) do ( OclFile["System.out"].print(s->min() + " ") ; s := s->front() ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : String ; k := "geeks for geeks" ; execute reverse(k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int divisorSum(int n){ int sum=0 ; for(int i=1 ; i<=n ; ++i){ for(int j=1 ; j*j<=i ; ++j){ if(i % j==0){ if(i/j==j)sum+=j ; else sum+=j+i/j ; } } } return sum ; } public static void main(String args[]){ int n=4 ; System.out.println(divisorSum(n)); n=5 ; System.out.println(divisorSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation divisorSum( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j * j <= i 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 ) ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(divisorSum(n)) ; n := 5 ; OclFile["System.out"].println(divisorSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static final int MAX=100 ; static boolean allones(String s,int n){ int co=0 ; for(int i=0 ; i=n)return 0 ; if(dp[ind][st]!=-1)return dp[ind][st]; if(st==0)return dp[ind][st]=Math.max(arr[ind]+findlength(arr,s,n,ind+1,1,dp),findlength(arr,s,n,ind+1,0,dp)); else return dp[ind][st]=Math.max(arr[ind]+findlength(arr,s,n,ind+1,1,dp),0); } static int maxLen(String s,int n){ if(allones(s,n))return-1 ; int arr[]=new int[MAX]; for(int i=0 ; isize() do ( if (s->at(i+1) = '1') then co := co+(1) ; else skip ; ; i := i + 1 ) ; return (co = n) ); static operation findlength( arr : Sequence(int), s : String, n : int, ind : int, st : int, dp : Sequence(Sequence(int))) : int pre: true post: true activity: ( if (ind >= n) then return 0 else skip ; if (dp[ind+1][st+1] /= -1) then return dp[ind+1][st+1] else skip ; if (st = 0) then return dp[ind+1][st+1] else return dp[ind+1][st+1] ); static operation maxLen( s : String, n : int) : int pre: true post: true activity: ( if (allones(s, n)) then return -1 else skip ; var arr : Sequence(int) ; arr := Integer.subrange(1,MAX)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := (if s->at(i+1) = '0' then 1 else -1 endif) ; ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,MAX)->collect(Integer.subrange(1,3)->collect(0)) ; for (row : dp) do ( row := row->collect(-1) ; ) ; return findlength(arr, s, n, 0, 0, dp) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "11000010001" ; var n : int ; n := 11 ; OclFile["System.out"].println(maxLen(s, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static class Pair implements Comparable{ int first,second ; Pair(int f,int s){ first=f ; second=s ; } @ Override public int compareTo(Pair o){ if(this.second>o.second)return 1 ; else if(this.second==o.second)return 0 ; return-1 ; } } static int prime[]=new int[100002]; static void SieveOfEratosthenes(){ Arrays.fill(prime,0); prime[0]=0 ; prime[1]=0 ; for(int p=2 ; p*p<=100001 ; p++){ if(prime[p]==0){ prime[p]++; for(int i=p*p ; i<=100001 ; i+=p)prime[i]++; } } } static void sortArr(int arr[],int n){ Pair v[]=new Pair[n]; for(int i=0 ; i { attribute first : int; static operation newPair( f : int, s : int) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(f, s); return self ); operation initialise( f : int, s : int) : void pre: true post: true activity: ( first := f ; second := s ); operation compareTo( o : Map) : int pre: true post: true activity: ( if (self->at("second") > o->at("second")) then return 1 else if (self->at("second") = o->at("second")) then return 0 else skip ; ; return -1 ); } static attribute prime : int := Integer.subrange(1,100002)->collect(0); static operation SieveOfEratosthenes() : void pre: true post: true activity: ( prime := prime->collect(0) ; prime[0+1] := 0 ; prime[1+1] := 0 ; var p : int ; p := 2 ; while p * p <= 100001 do ( ( if (prime[p+1] = 0) then ( prime[p+1] := prime[p+1] + 1 ; var i : int ; i := p * p ; while i <= 100001 do ( prime[i+1] := prime[i+1] + 1 ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ); static operation sortArr( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var v : Sequence(Map) ; v := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( v[i+1] := Map(arr[i+1], prime[arr[i+1]+1]) ) ; i := i + 1 ) ; v := v->sort() ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(v[i+1]->at("first") + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute SieveOfEratosthenes() ; var arr : Sequence(int) ; arr := Sequence{30,2,1024,210,3,6} ; var n : int ; n := arr->size() ; execute sortArr(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findSum(int n){ int ans=0 ; for(int i=1 ; i<=n ; i++)for(int j=1 ; j<=n ; j++)ans+=(i/j); return ans ; } public static void main(String[] args){ int N=2 ; System.out.println(findSum(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findSum( n : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( var j : int ; j := 1 ; while j <= n do ( ans := ans+((i / j)) ; ; j := j + 1 ) ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 2 ; OclFile["System.out"].println(findSum(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int max_element(int arr[]){ int max_e=Integer.MIN_VALUE ; for(int i=0 ; isize() do ( ( max_e := Set{max_e, arr[i+1]}->max() ) ; i := i + 1 ) ; return max_e ); static operation nonPrimeSum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var max_val : int ; max_val := max_element(arr) ; var prime : Sequence(boolean) ; prime := Integer.subrange(1,max_val + 1)->collect(false) ; var i : int ; i := 0 ; while i < prime->size() do ( prime[i+1] := true ; ; i := i + 1 ) ; prime[0+1] := false ; prime[1+1] := false ; var p : int ; p := 2 ; while p * p <= max_val do ( ( if (prime[p+1] = true) then ( var i : int ; i := p * 2 ; while i <= max_val do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( if (not(prime[arr[i+1]+1])) then sum := sum+(arr[i+1]) ; else skip ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,3,7,4,9,8} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(nonPrimeSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Interchange { static void interchangeFirstLast(int m[][]){ int rows=m.length ; for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < m[0+1]->size() do ( ( var t : int ; t := m[0+1][i+1] ; m[0+1][i+1] := m[rows - 1+1][i+1] ; m[rows - 1+1][i+1] := t ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Sequence(Sequence(int)) ; m := Sequence{Sequence{8,9,7,6},Sequence{4,7,6,5},Sequence{3,2,1,8},Sequence{9,9,7,7}} ; execute interchangeFirstLast(m) ; var i : int ; i := 0 ; while i < m->size() do ( ( var j : int ; j := 0 ; while j < m[0+1]->size() do ( OclFile["System.out"].print(m[i+1][j+1] + " ") ; ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); static String input ; public static void main(String[] args){ while(read()){ } } static boolean read(){ if(sc.hasNextInt())return false ; input=sc.next(); solveFirstGame(); for(int i=1 ; i<3 ; i++){ input=sc.next(); solveFirstGame(); } return true ; } static void solveFirstGame(){ int A=0,B=0 ; for(int i=1 ; iB){ A++; } else { B++; } System.out.println(A+" "+B); } static void solve(){ int A=0,B=0 ; System.out.println(A+" "+B); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute input : String; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (read()) do skip ); static operation read() : boolean pre: true post: true activity: ( if (sc.hasNextInt()) then return false else skip ; input := sc.getCurrent() ; execute solveFirstGame() ; var i : int ; i := 1 ; while i < 3 do ( ( input := sc.getCurrent() ; execute solveFirstGame() ) ; i := i + 1 ) ; return true ); static operation solveFirstGame() : void pre: true post: true activity: ( var A : int ; A := 0 ; var B : int ; B := 0 ; var i : int ; i := 1 ; while i < input->size() do ( ( if (input->at(i+1) = 'A') then A := A + 1 ; else skip ; if (input->at(i+1) = 'B') then B := B + 1 ; else skip ) ; i := i + 1 ) ; if (A > B) then ( A := A + 1 ) else ( B := B + 1 ) ; OclFile["System.out"].println(A + " " + B) ); static operation solve() : void pre: true post: true activity: ( var A : int ; A := 0 ; var B : int ; B := 0 ; OclFile["System.out"].println(A + " " + B) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean Move(int a,int x,int b){ if((((b-a)% x==0)||((b-a-1)% x==0)&& a+1!=b)&& b>=a)return true ; return false ; } public static void main(String[] args){ int a=3,x=2,b=7 ; if(Move(a,x,b))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Move( a : int, x : int, b : int) : boolean pre: true post: true activity: ( if ((((b - a) mod x = 0) or ((b - a - 1) mod x = 0) & a + 1 /= b) & b >= a) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 3 ; var x : int ; x := 2 ; var b : int ; b := 7 ; if (Move(a, x, b)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static long startTime=System.currentTimeMillis(); static Scanner sc=new Scanner(System.in); public static void main(String[] args){ long A=sc.nextLong(); long B=sc.nextLong(); for(long i=B+1 ; ; i++){ if((i & 0xFF)==0 && System.currentTimeMillis()-startTime>3500)break ; long ca=i/A+i % A ; long remb=i % B ; long cb=i/B+remb/A+remb % A ; if(catoLong() ; var B : long ; B := sc.getCurrent()->toLong() ; var i : long ; i := B + 1 ; while true do ( ( if ((MathLib.bitwiseAnd(i,0xFF)) = 0 & OclDate.getSystemTime() - startTime > 3500) then break else skip ; var ca : long ; ca := i / A + i mod A ; var remb : long ; remb := i mod B ; var cb : long ; cb := i / B + remb / A + remb mod A ; if (ca < cb) then ( OclFile["System.out"].println(i) ; return ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(-1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public boolean isOneBitCharacter(int[] bits){ int pos=0 ; while(possize() - 1) do ( pos := pos+(bits[pos+1] + 1) ) ; return pos = bits->size() - 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GfG { public static int solve(int low,int high,int T){ while(low<=high){ int mid=(low+high)/2 ; if((mid*(mid+1))==T)return mid ; if(mid>0 &&(mid*(mid+1))>T &&(mid*(mid-1))<=T)return mid-1 ; if((mid*(mid+1))>T)high=mid-1 ; else low=mid+1 ; } return-1 ; } public static void main(String argc[]){ int T=15 ; int ans=solve(1,T,2*T); if(ans!=-1)ans--; System.out.println("Number of stair steps="+ans); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation solve( low : int, high : int, T : int) : int pre: true post: true activity: ( while (low <= high) do ( var mid : int ; mid := (low + high) / 2 ; if ((mid * (mid + 1)) = T) then return mid else skip ; if (mid > 0 & (mid * (mid + 1)) > T & (mid * (mid - 1)) <= T) then return mid - 1 else skip ; if ((mid * (mid + 1)) > T) then high := mid - 1 ; else low := mid + 1 ; ) ; return -1 ); static operation main( argc : Sequence(String)) : void pre: true post: true activity: ( var T : int ; T := 15 ; var ans : int ; ans := solve(1, T, 2 * T) ; if (ans /= -1) then ans := ans - 1 ; else skip ; OclFile["System.out"].println("Number of stair steps=" + ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MaximumHeight(int[] a,int n){ int result=1 ; for(int i=1 ; i<=n ; ++i){ int y=(i*(i+1))/2 ; if(ysize() ; OclFile["System.out"].println(MaximumHeight(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int D=scanner.nextInt(); int A=scanner.nextInt(); Monster[] monsters=new Monster[N]; for(int i=0 ; im.x)); long cum=0 ; int[] delta=new int[N]; int j=0 ; for(int i=0 ; icum)delta[i]=monsters[i] .h-(int)cum ; cum+=delta[i]; } long res=0 ; for(int i=0 ; itoInteger() ; var D : int ; D := scanner.getCurrent()->toInteger() ; var A : int ; A := scanner.getCurrent()->toInteger() ; var monsters : Sequence(Monster) ; monsters := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( var x : int ; x := scanner.getCurrent()->toInteger() ; var h : int ; h := scanner.getCurrent()->toInteger() ; monsters[i+1] := Monster.newMonster(x, (h - 1) / A + 1) ) ; i := i + 1 ) ; monsters := OclComparator.sortWith(monsters, Comparator.comparingLong(lambda m : OclAny in m.x)) ; var cum : long ; cum := 0 ; var delta : Sequence(int) ; delta := Integer.subrange(1,N)->collect(0) ; var j : int ; j := 0 ; var i : int ; i := 0 ; while i < N do ( ( while (j < i & monsters[j+1].x + 2 * D < monsters[i+1].x) do ( cum := cum-(delta[j+1]) ; j := j + 1 ) ; if (monsters[i+1].h > cum) then delta[i+1] := monsters[i+1].h - cum->oclAsType(int) ; else skip ; cum := cum+(delta[i+1]) ) ; i := i + 1 ) ; var res : long ; res := 0 ; var i : int ; i := 0 ; while i < N do ( res := res+(delta[i+1]) ; ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); static class Monster { attribute x : long; attribute h : int; static operation newMonster( x : int, h : int) : Monster pre: true post: true activity: ( var self : Monster ; self := createMonster(); self.initialise(x, h); return self ); operation initialise( x : int, h : int) : void pre: true post: true activity: ( self.x := x ; self.h := h ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.*; import java.io.*; class Monster implements Comparable{ final long x,h ; Monster(long x,long h){ this.x=x ; this.h=h ; } public int compareTo(Monster m){ return Long.compare(this.x,m.x); } } public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] in1=br.readLine().split(" "); long N=Long.parseLong(in1[0]); long D=Long.parseLong(in1[1]); long A=Long.parseLong(in1[2]); Listmonsters=new ArrayList<>(); for(int i=0 ; iposition=new ArrayDeque<>(); long tmp_attack_count=0L ; long total_attack_count=0L ; for(int n=0 ; n { attribute x : long; static operation newMonster( x : long, h : long) : Monster pre: true post: true activity: ( var self : Monster ; self := createMonster(); self.initialise(x, h); return self ); operation initialise( x : long, h : long) : void pre: true post: true activity: ( self.x := x ; self.h := h ); operation compareTo( m : Monster) : int pre: true post: true activity: ( return compare(self.x, m.x) ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var in1 : Sequence(String) ; in1 := br.readLine()->split(" ") ; var N : long ; N := (in1[0+1])->toLong() ; var D : long ; D := (in1[1+1])->toLong() ; var A : long ; A := (in1[2+1])->toLong() ; var monsters : Sequence(Monster) ; monsters := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( in1 := br.readLine()->split(" ") ; var X : long ; X := (in1[0+1])->toLong() ; var H : long ; H := (in1[1+1])->toLong() ; monsters := monsters->including(Monster.newMonster(X, H)) ) ; i := i + 1 ) ; skip ; monsters := monsters->sort() ; var position : Sequence(Sequence(long)) ; position := ArrayDeque.newArrayDeque() ; var tmp_attack_count : long ; tmp_attack_count := 0L ; var total_attack_count : long ; total_attack_count := 0L ; var n : int ; n := 0 ; while n < N do ( ( var now_x : long ; now_x := monsters->at(n+1).x ; var now_h : long ; now_h := monsters->at(n+1).h ; while (not(position->isEmpty()) & position->min()[0+1] + 2 * D < now_x) do ( tmp_attack_count := tmp_attack_count-(position->min()[1+1]) ) ; var attack_count : long ; attack_count := (now_h - tmp_attack_count * A + A - 1L) / A ; if (attack_count <= 0) then continue else skip ; total_attack_count := total_attack_count+(attack_count) ; tmp_attack_count := tmp_attack_count+(attack_count) ; position := position->including(Sequence{now_x,attack_count}) ; ) ; n := n + 1 ) ; OclFile["System.out"].println(total_attack_count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Stack ; import javax.swing.tree.TreeNode ; class Solution { public int sumOfLeftLeaves(TreeNode root){ int res=0 ; Stackstack=new Stack<>(); stack.push(root); while(! stack.isEmpty()){ TreeNode node=stack.pop(); if(node!=null){ if(node.left!=null && node.left.left==null && node.left.right==null)res+=node.left.val ; stack.push(node.right); stack.push(node.left); } } return res ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation sumOfLeftLeaves( root : TreeNode) : int pre: true post: true activity: ( var res : int ; res := 0 ; var stack : Sequence(TreeNode) ; stack := Sequence{} ; stack := stack->append(root) ; while (not(stack->isEmpty())) do ( var node : TreeNode ; node := stack->last() ; if (node /= null) then ( if (node.left /= null & node.left.left = null & node.left.right = null) then res := res+(node.left.val) ; else skip ; stack := stack->append(node.right) ; stack := stack->append(node.left) ) else skip ) ; return res ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class CustomisingTheTrack { public static void main(String[] args){ FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int numTestCases=in.nextInt(); while(numTestCases-->0){ int numSubTrack=in.nextInt(); long sum=0 ; for(int i=0 ; i 0) do ( numTestCases := numTestCases - 1 ; skip ; ( var numSubTrack : int ; numSubTrack := in.nextInt() ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < numSubTrack do ( ( var temp : int ; temp := in.nextInt() ; sum := sum+(temp) ) ; i := i + 1 ) ; sum := sum mod numSubTrack ; var num : long ; num := numSubTrack - sum ; skip ; ) ; ) ; skip ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("sub.in"))) ) catch (ex : FileNotFoundException) do ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (ex : IOException) do skip ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (ex : IOException) do skip return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class main { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); long t=sc.nextLong(); while(t-->0){ int n=sc.nextInt(); Listlist=new ArrayList<>(); for(int i=0 ; itoLong() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var list : Sequence(long) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( list := list->including(sc.getCurrent()->toLong()) ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum + list->at(i+1) ) ; i := i + 1 ) ; var a : long ; a := sum mod n ; if (a = 0) then OclFile["System.out"].println(0) else OclFile["System.out"].println((n - a) * a) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void decToHexa(int n){ char[] hexaDeciNum=new char[100]; int i=0 ; while(n!=0){ int temp=0 ; temp=n % 16 ; if(temp<10){ hexaDeciNum[i]=(char)(temp+48); i++; } else { hexaDeciNum[i]=(char)(temp+55); i++; } n=n/16 ; } for(int j=i-1 ; j>=0 ; j--)System.out.print(hexaDeciNum[j]); } public static void main(String[] args){ int n=2545 ; decToHexa(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation decToHexa( n : int) : void pre: true post: true activity: ( var hexaDeciNum : Sequence(String) ; hexaDeciNum := Integer.subrange(1,100)->collect(0) ; var i : int ; i := 0 ; while (n /= 0) do ( var temp : int ; temp := 0 ; temp := n mod 16 ; if (temp < 10) then ( hexaDeciNum[i+1] := (temp + 48)->oclAsType(String) ; i := i + 1 ) else ( hexaDeciNum[i+1] := (temp + 55)->oclAsType(String) ; i := i + 1 ) ; n := n / 16 ) ; var j : int ; j := i - 1 ; while j >= 0 do ( OclFile["System.out"].print(hexaDeciNum[j+1]) ; ; j := j - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2545 ; execute decToHexa(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public final class Test { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long[] arr=new long[n]; long sum=0 ; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toLong() ; sum := sum+(arr[i+1]) ) ; i := i + 1 ) ; var k : long ; k := sum mod n ; OclFile["System.out"].println(k * (n - k)) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int Race(int B,int C){ int result=0 ; result=((C*100)/B); return 100-result ; } public static void main(String[] args){ int B=10 ; int C=28 ; B=100-B ; C=100-C ; System.out.println(Race(B,C)+" meters"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Race( B : int, C : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; result := ((C * 100) / B) ; return 100 - result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var B : int ; B := 10 ; var C : int ; C := 28 ; B := 100 - B ; C := 100 - C ; OclFile["System.out"].println(Race(B, C) + " meters") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String even_or_odd(String N){ int len=N.length(); if(N.charAt(len-1)=='0' || N.charAt(len-1)=='2' || N.charAt(len-1)=='4' || N.charAt(len-1)=='6' || N.charAt(len-1)=='8' || N.charAt(len-1)=='A' || N.charAt(len-1)=='C' || N.charAt(len-1)=='E')return("Even"); else return("Odd"); } public static void main(String[] args){ String N="AB3454D" ; System.out.print(even_or_odd(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation even_or_odd( N : String) : String pre: true post: true activity: ( var len : int ; len := N->size() ; if (N->at(len - 1+1) = '0' or N->at(len - 1+1) = '2' or N->at(len - 1+1) = '4' or N->at(len - 1+1) = '6' or N->at(len - 1+1) = '8' or N->at(len - 1+1) = 'A' or N->at(len - 1+1) = 'C' or N->at(len - 1+1) = 'E') then return ("Even") else return ("Odd") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : String ; N := "AB3454D" ; OclFile["System.out"].print(even_or_odd(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF1543B { public static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int test=scanner.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < test do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; var sum : long ; sum := 0 ; var j : int ; j := 0 ; while j < n do ( ( sum := sum+(scanner.getCurrent()->toInteger()) ) ; j := j + 1 ) ; var equalParts : long ; equalParts := sum mod n ; var nonEqualParts : long ; nonEqualParts := (n - equalParts) ; OclFile["System.out"].println(equalParts * nonEqualParts) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int N=sc.nextInt(); int[] p=new int[N]; int max=0,sum=0 ; for(int i=0 ; itoInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,N)->collect(0) ; var max : int ; max := 0 ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( p[i+1] := sc.getCurrent()->toInteger() ; sum := sum+(p[i+1]) ; max := Set{max, p[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(sum - max / 2) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ Main main=new Main(); main.solve(args); } public void solve(String[] args){ MyScanner scanner=new MyScanner(); int s=scanner.nextInt(); int max=0 ; int tmp=0 ; int sum=0 ; for(int i=0 ; icollect(null) ; i := 0 ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( try ( if (i < s->size()) then return s[i+1] else skip ; var line : String ; line := br.readLine() ; while (line = "") do ( line := br.readLine() ) ; s := line->split(reg) ; i := 0 ; return s[i+1] ) catch (e : ProgramException) do ( e.printStackTrace() ) return null ); operation nextInt() : int pre: true post: true activity: ( try ( return (next())->toInteger() ) catch (e : ProgramException) do ( e.printStackTrace() ) return -1 ); operation nextDouble() : double pre: true post: true activity: ( try ( return (next())->toReal() ) catch (e : ProgramException) do ( e.printStackTrace() ) return -1 ); operation nextLong() : long pre: true post: true activity: ( try ( return (next())->toLong() ) catch (e : ProgramException) do ( e.printStackTrace() ) return -1 ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int N=sc.nextInt(); static int[] p=new int[N]; static { Arrays.setAll(p,i->sc.nextInt()); } public static void main(String[] args){ Arrays.sort(p); int ans=0 ; for(int i=0 ; itoInteger(); static attribute p : Sequence(int) := Integer.subrange(1,N)->collect(0); static operation initialiseClass() pre: true post: true activity: setAll(p, lambda i : OclAny in sc.getCurrent()->toInteger()) ; ; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( p := p->sort() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < p->size() do ( ( if (i = p->size() - 1) then ( ans := ans+(p[i+1] / 2) ) else ( ans := ans+(p[i+1]) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import java.math.BigInteger ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] p=new int[n]; for(int i=0 ; itoInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var result : int ; result := 0 ; var max : int ; max := 0 ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < n do ( ( max := Set{max, p[i+1]}->max() ; if (max = p[i+1]) then index := i ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (i = index) then ( result := result+(max / 2) ) else ( result := result+(p[i+1]) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); ArrayLista=new ArrayList<>(); for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( a := a->including(scan.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var max : int ; max := a->includes(a->indexOf( a, null->max())-1) / 2 ; var sum : int ; sum := max ; for (x : a) do ( ( sum := sum+(x) ) ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.HashMap ; class OddOccurrence { static int getOddOccurrence(int arr[],int n){ HashMaphmap=new HashMap<>(); for(int i=0 ; ikeys()->includes(arr[i+1])) then ( var val : int ; val := hmap->at(arr[i+1]) ; hmap := hmap->union(Map{arr[i+1] |-> val + 1}) ) else hmap := hmap->union(Map{arr[i+1] |-> 1}) ; ) ; i := i + 1 ) ; for (a : hmap->keys()) do ( ( if (hmap->at(a) mod 2 /= 0) then return a else skip ) ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,3,5,4,5,2,4,3,5,2,4,4,2} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(getOddOccurrence(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static int sumOfDigits(int n){ int sum=0 ; while(n!=0){ sum=sum+n % 10 ; n=n/10 ; } return sum ; } static int countTheNumbers(int l,int r,int y){ int count=0 ; for(int i=l ; i<=r ; i++){ if(sumOfDigits(i)==y)count++; } return count ; } public static void main(String[] args){ int l=0,r=10,y=1 ; System.out.println(countTheNumbers(l,r,y)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation sumOfDigits( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; while (n /= 0) do ( sum := sum + n mod 10 ; n := n / 10 ) ; return sum ); static operation countTheNumbers( l : int, r : int, y : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := l ; while i <= r do ( ( if (sumOfDigits(i) = y) then count := count + 1 ; else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 0 ; var r : int ; r := 10 ; var y : int ; y := 1 ; OclFile["System.out"].println(countTheNumbers(l, r, y)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),s=in.nextInt(); ArrayListls=new ArrayList<>(); for(int i=0 ; itoInteger() ; var s : int ; s := in.getCurrent()->toInteger() ; var ls : Sequence(int) ; ls := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ls := ls->including(in.getCurrent()->toInteger()) ; ; i := i + 1 ) ; ls := ls->sort() ; var otherHalf : int ; otherHalf := (n / 2) ; otherHalf := otherHalf + 1 ; var ans : long ; ans := 0 ; var i : int ; i := otherHalf ; while i < n do ( ( ans := ans+(Set{0, s - ls->at(i+1)}->max()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < (otherHalf - 1) do ( ans := ans+(Set{0, ls->at(i+1) - s}->max()) ; ; i := i + 1 ) ; ans := ans+(if ls->at((otherHalf - 1)+1) - s < 0 then -(ls->at((otherHalf - 1)+1) - s) else ls->at((otherHalf - 1)+1) - s endif) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ReachMedian { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); long s=scan.nextLong(); Long[] nums=new Long[n]; for(int i=0 ; is){ ans+=nums[i]-s ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class ReachMedian { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var s : long ; s := scan.getCurrent()->toLong() ; var nums : Sequence(long) ; nums := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := scan.getCurrent()->toLong() ) ; i := i + 1 ) ; nums := nums->sort() ; var ans : long ; ans := 0 ; var i : int ; i := n / 2 ; while i < n do ( ( if (nums[i+1] < s) then ( ans := ans+(if s - nums[i+1] < 0 then -(s - nums[i+1]) else s - nums[i+1] endif) ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= n / 2 do ( ( if (nums[i+1] > s) then ( ans := ans+(nums[i+1] - s) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int num=scan.nextInt(); for(int i=0 ; i=1){ if(n/data>=2){ str=str+n/data ; } if(data==1000){ str=str+"m" ; } if(data==100){ str=str+"c" ; } if(data==10){ str=str+"x" ; } if(data==1){ str=str+"i" ; } n=n-(n/data)*data ; } if(data==1){ break ; } data=data/10 ; } return str ; } public static int changeChar(String str){ if(str.equals("m")){ return 1000 ; } if(str.equals("c")){ return 100 ; } if(str.equals("x")){ return 10 ; } return 1 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : int ; num := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < num do ( ( var str : Sequence(String) ; str := Integer.subrange(1,2)->collect(null) ; var ans : Sequence(int) ; ans := Integer.subrange(1,2)->collect(0) ; var j : int ; j := 0 ; while j < 2 do ( ( ans[j+1] := 0 ; str[j+1] := scan.getCurrent() ; var k : int ; k := 0 ; while k < str[j+1]->size() do ( ( var hoge : String ; hoge := ((str[j+1]->at(k+1)) + "") ; try ( var huga : String ; huga := ((str[j+1]->at(k + 1+1)) + "") ; ans[j+1] := ans[j+1] + (hoge)->toInteger() * changeChar(huga) ) catch (e : ProgramException) do ( ans[j+1] := ans[j+1] + changeChar(hoge) ; k := k - 1 ) ) ; k := k + 2 ) ) ; j := j + 1 ) ; OclFile["System.out"].println(returnChar(ans[0+1] + ans[1+1])) ) ; i := i + 1 ) ); static operation returnChar( n : int) : String pre: true post: true activity: ( var str : String ; str := "" ; var data : int ; data := 1000 ; while (true) do ( if (n / data >= 1) then ( if (n / data >= 2) then ( str := str + n / data ) else skip ; if (data = 1000) then ( str := str + "m" ) else skip ; if (data = 100) then ( str := str + "c" ) else skip ; if (data = 10) then ( str := str + "x" ) else skip ; if (data = 1) then ( str := str + "i" ) else skip ; n := n - (n / data) * data ; ) else skip ; if (data = 1) then ( break ) else skip ; data := data / 10 ) ; return str ); static operation changeChar( str : String) : int pre: true post: true activity: ( if (str = "m") then ( return 1000 ) else skip ; if (str = "c") then ( return 100 ) else skip ; if (str = "x") then ( return 10 ) else skip ; return 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); long s=scanner.nextLong(); long[] arr=new long[n]; for(int i=0 ; i=0 ; i--){ if(arr[i]<=s){ min=i ; break ; } } long ans=0 ; if(min>=(n-1)/2){ for(int i=(n-1)/2 ; i<=min ; i++){ ans+=s-arr[i]; } } else { for(int i=min+1 ; i<=(n-1)/2 ; i++){ ans+=arr[i]-s ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var s : long ; s := scanner.getCurrent()->toLong() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := scanner.getCurrent()->toLong() ) ; i := i + 1 ) ; arr := arr->sort() ; var min : int ; min := -1 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (arr[i+1] <= s) then ( min := i ; break ) else skip ) ; i := i - 1 ) ; var ans : long ; ans := 0 ; if (min >= (n - 1) / 2) then ( var i : int ; i := (n - 1) / 2 ; while i <= min do ( ( ans := ans+(s - arr[i+1]) ) ; i := i + 1 ) ) else ( var i : int ; i := min + 1 ; while i <= (n - 1) / 2 do ( ( ans := ans+(arr[i+1] - s) ) ; i := i + 1 ) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int s=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; iMath.max(0,a[i]-s)).asLongStream().sum()+IntStream.range(index+1,a.length).map(i->Math.max(0,s-a[i])).asLongStream().sum(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : int ; s := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(a, s)) ; skip ; ); static operation solve( a : Sequence(int), s : int) : long pre: true post: true activity: ( a := a->sort() ; var index : int ; index := a->size() / 2 ; return if a[index+1] - s < 0 then -(a[index+1] - s) else a[index+1] - s endif + Integer.subrange(0, index-1)->collect( _x1 | (lambda i : OclAny in Set{0, a[i+1] - s}->max())->apply(_x1) )->sum() + Integer.subrange(index + 1, a->size()-1)->collect( _x1 | (lambda i : OclAny in Set{0, s - a[i+1]}->max())->apply(_x1) )->sum() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String[] args){ int matrix[][]=new int[5][5],row_index,column_index,x=0,size=5 ; for(row_index=0 ; row_indexcollect(Integer.subrange(1,5)->collect(0)) ; var row_index : int ; var column_index : int ; var x : int ; x := 0 ; var size : int ; size := 5 ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( x := x + 1 ; matrix[row_index+1][column_index+1] := x ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("The matrix is\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( OclFile["System.out"].printf("%d\t", matrix[row_index+1][column_index+1]) ) ; column_index := column_index + 1 ) ; OclFile["System.out"].printf("\n") ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("\nMain diagonal elements are:\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( if (row_index = column_index) then ( OclFile["System.out"].printf("%d,", matrix[row_index+1][column_index+1]) ) else skip ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String args[]){ int matrix[][]=new int[5][5],row_index,column_index,x=0,size=5 ; for(row_index=0 ; row_indexcollect(Integer.subrange(1,5)->collect(0)) ; var row_index : int ; var column_index : int ; var x : int ; x := 0 ; var size : int ; size := 5 ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( x := x + 1 ; matrix[row_index+1][column_index+1] := x ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("The matrix is\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( OclFile["System.out"].printf("%d\t", matrix[row_index+1][column_index+1]) ) ; column_index := column_index + 1 ) ; OclFile["System.out"].printf("\n") ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("\nElements above Main diagonal elements are:\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( if (row_index < column_index) then ( OclFile["System.out"].printf("%d,", matrix[row_index+1][column_index+1]) ) else skip ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String[] args){ int[][] matrix=new int[5][5]; int row_index,column_index,x=0,size=5 ; for(row_index=0 ; row_indexcollect(Integer.subrange(1,5)->collect(0)) ; var row_index : int ; var column_index : int ; var x : int ; x := 0 ; var size : int ; size := 5 ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( x := x + 1 ; matrix[row_index+1][column_index+1] := x ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("The matrix is\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( OclFile["System.out"].printf("%d\t", matrix[row_index+1][column_index+1]) ) ; column_index := column_index + 1 ) ; OclFile["System.out"].printf("\n") ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("\nCorner Elements are:\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( if ((row_index = 0 or row_index = size - 1) & (column_index = 0 or column_index = size - 1)) then OclFile["System.out"].printf("%d,", matrix[row_index+1][column_index+1]) ; else skip ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String[] args){ int[][] matrix=new int[5][5]; int row_index,column_index,x=0,size=5 ; for(row_index=0 ; row_indexsize-1)System.out.printf("%d,",matrix[row_index][column_index]); } } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var matrix : Sequence(Sequence(int)) ; matrix := Integer.subrange(1,5)->collect(Integer.subrange(1,5)->collect(0)) ; var row_index : int ; var column_index : int ; var x : int ; x := 0 ; var size : int ; size := 5 ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( x := x + 1 ; matrix[row_index+1][column_index+1] := x ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("The matrix is\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( OclFile["System.out"].printf("%d\t", matrix[row_index+1][column_index+1]) ) ; column_index := column_index + 1 ) ; OclFile["System.out"].printf("\n") ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("\nElements below Secondary" + " diagonal are:\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( if ((row_index + column_index) > size - 1) then OclFile["System.out"].printf("%d,", matrix[row_index+1][column_index+1]) ; else skip ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.Scanner ; public class Main { InputStream in=System.in ; PrintStream out=System.out ; public void _main(String[] args){ Scanner sc=new Scanner(in); int N=sc.nextInt(); int[] z=new int[100000]; for(int i=0 ; i0)b+=z[X-1]; if(XtoInteger() ; var z : Sequence(int) ; z := Integer.subrange(1,100000)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( z[sc.getCurrent()->toInteger()+1] := z[sc.getCurrent()->toInteger()+1] + 1 ) ; i := i + 1 ) ; skip ; var ans : int ; ans := 0 ; var X : int ; X := 0 ; while X < z->size() do ( ( var b : int ; b := z[X+1] ; if (X > 0) then b := b+(z[X - 1+1]) ; else skip ; if (X < z->size() - 1) then b := b+(z[X + 1+1]) ; else skip ; ans := Set{ans, b}->max() ) ; X := X + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain()._main(args) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String[] args){ int[][] matrix=new int[5][5]; int row_index,column_index,x=0,size=5 ; for(row_index=0 ; row_indexcollect(Integer.subrange(1,5)->collect(0)) ; var row_index : int ; var column_index : int ; var x : int ; x := 0 ; var size : int ; size := 5 ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( x := x + 1 ; matrix[row_index+1][column_index+1] := x ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("The matrix is\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( OclFile["System.out"].printf("%d\t", matrix[row_index+1][column_index+1]) ) ; column_index := column_index + 1 ) ; OclFile["System.out"].printf("\n") ) ; row_index := row_index + 1 ) ; OclFile["System.out"].printf("\nElements above Secondary" + " diagonal are:\n") ; row_index := 0 ; while row_index < size do ( ( column_index := 0 ; while column_index < size do ( ( if ((row_index + column_index) < size - 1) then OclFile["System.out"].printf("%d,", matrix[row_index+1][column_index+1]) ; else skip ) ; column_index := column_index + 1 ) ) ; row_index := row_index + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class helloWorld { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int ar[]=new int[n+1]; boolean[] parent=new boolean[n+1]; String ans="Yes" ; for(int i=2 ; i<=n ; i++){ ar[i]=in.nextInt(); parent[ar[i] ]=true ; } for(int i=1 ; i<=n ; i++){ if(parent[i]){ int a=0 ; for(int j=2 ; j<=n ; j++)if(ar[j]==i && ! parent[j])a++; if(a<3)ans="No" ; } } System.out.println(ans); in.close(); } } ------------------------------------------------------------ OCL File: --------- class helloWorld { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var ar : Sequence(int) ; ar := Integer.subrange(1,n + 1)->collect(0) ; var parent : Sequence(boolean) ; parent := Integer.subrange(1,n + 1)->collect(false) ; var ans : String ; ans := "Yes" ; var i : int ; i := 2 ; while i <= n do ( ( ar[i+1] := in.getCurrent()->toInteger() ; parent[ar[i+1]+1] := true ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( if (parent[i+1]) then ( var a : int ; a := 0 ; var j : int ; j := 2 ; while j <= n do ( if (ar[j+1] = i & not(parent[j+1])) then a := a + 1 ; else skip ; ; j := j + 1 ) ; if (a < 3) then ans := "No" ; else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ChristmasSpruce { static ArrayList[] adj ; static int[] out ; static boolean[] leaf ; static int[] par ; public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); adj=new ArrayList[n+1]; for(int i=0 ; i<=n ; i++)adj[i]=new ArrayList<>(); out=new int[n+1]; par=new int[n+1]; leaf=new boolean[n+1]; for(int i=1 ; i<=n-1 ; i++){ int x=in.nextInt(); adj[x] .add(i+1); par[i+1]=x ; } boolean good=true ; dfs(1); for(int i=1 ; i<=n ; i++){ good &=(leaf[i] ||(out[i]>=3)); } if(good)pw.println("YES"); else pw.println("NO"); pw.close(); } static void dfs(int u){ if(adj[u] .size()==0 && par[u]!=0){ leaf[u]=true ; } for(int v : adj[u]){ dfs(v); if(leaf[v])out[u]++; } } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class ChristmasSpruce { static attribute adj : Sequence(Sequence(int)); static attribute out : Sequence(int); static attribute leaf : Sequence(boolean); static attribute par : Sequence(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; adj := Integer.subrange(1,n + 1)->collect(null) ; var i : int ; i := 0 ; while i <= n do ( adj[i+1] := Sequence{} ; ; i := i + 1 ) ; out := Integer.subrange(1,n + 1)->collect(0) ; par := Integer.subrange(1,n + 1)->collect(0) ; leaf := Integer.subrange(1,n + 1)->collect(false) ; var i : int ; i := 1 ; while i <= n - 1 do ( ( var x : int ; x := in.getCurrent()->toInteger() ; adj[x+1]->excludes(i + 1) ; par[i + 1+1] := x ) ; i := i + 1 ) ; var good : boolean ; good := true ; execute dfs(1) ; var i : int ; i := 1 ; while i <= n do ( ( good := MathLib.bitwiseAnd(good, (leaf[i+1] or (out[i+1] >= 3))) ) ; i := i + 1 ) ; if (good) then skip else skip ; ; skip ; ); static operation dfs( u : int) : void pre: true post: true activity: ( if (adj[u+1]->size() = 0 & par[u+1] /= 0) then ( leaf[u+1] := true ) else skip ; for (v : adj[u+1]) do ( ( execute dfs(v) ; if (leaf[v+1]) then out[u+1] := out[u+1] + 1 ; else skip ) ) ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class DP { static int n ; static Listadj[]; static int mod=(int)1e9+7 ; public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); n=sc.nextInt(); adj=new ArrayList[n]; for(int i=0 ; i(); for(int i=1 ; i=3 ; } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public Scanner(String s)throws FileNotFoundException { br=new BufferedReader(new FileReader(s)); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public String nextLine()throws IOException { return br.readLine(); } public double nextDouble()throws IOException { return Double.parseDouble(next()); } public boolean ready()throws IOException { return br.ready(); } } } ------------------------------------------------------------ OCL File: --------- class DP { static attribute n : int; static attribute adj : Sequence(Sequence(int)); static attribute mod : int := 1e9->oclAsType(int) + 7; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; n := sc.getCurrent()->toInteger() ; adj := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( adj[i+1] := Sequence{} ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( adj[sc.getCurrent()->toInteger() - 1+1]->excludes(i) ) ; i := i + 1 ) ; var check : boolean ; check := dfs(0) ; OclFile["System.out"].println(if check = true then "Yes" else "No" endif) ; skip ; ); static operation dfs( u : int) : boolean pre: true post: true activity: ( var c : int ; c := 0 ; for (v : adj[u+1]) do ( ( if (adj[v+1]->size() = 0) then ( c := c + 1 ) else if (not(dfs(v))) then ( return false ) else skip ; ) ) ; return c >= 3 ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newScanner( s : String) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { static char flag[]=new char[] { 'm','c','x','i' }; static int num[]=new int[] { 1000,100,10,1 }; public static void main(String[] args)throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader reader=new BufferedReader(isr); Main app=new Main(); int n=Integer.valueOf(reader.readLine()); for(int i=0 ; i=num[i]){ n-=num[i]; hoge++; } if(hoge==1){ res+=flag[i]; } else if(hoge!=0){ res+=String.valueOf(hoge)+flag[i]; } hoge=0 ; } return res ; } public int set(char c){ switch(c){ case 'm' : return 1000 ; case 'c' : return 100 ; case 'x' : return 10 ; case 'i' : return 1 ; } return 0 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute flag : String := Sequence{'m','c','x','i'}; static attribute num : int := Sequence{1000,100,10,1}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var reader : OclFile ; reader := OclFile.newOclFile_Read(isr) ; var app : Main ; app := Main.newMain() ; var n : int ; n := (reader.readLine())->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println((app.change(app.sum(reader.readLine())))) ) ; i := i + 1 ) ; skip ; ); operation sum( str : String) : int pre: true post: true activity: ( var s : Sequence(String) ; s := str->split(" ") ; var res : int ; res := 0 ; var hoge : int ; hoge := 1 ; var c : String ; var i : int ; i := 0 ; while i < 2 do ( ( var j : int ; j := 0 ; while j < s[i+1]->size() do ( ( c := s[i+1]->at(j+1) ; if ('2' <= c & c <= '9') then ( hoge := (c)->char2byte() - ('0')->char2byte() ; continue ) else ( res := res+(hoge * set(c)) ) ; hoge := 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; return res ); operation change( n : int) : String pre: true post: true activity: ( var res : String ; res := "" ; var hoge : int ; hoge := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( while (n >= num[i+1]) do ( n := n-(num[i+1]) ; hoge := hoge + 1 ) ; if (hoge = 1) then ( res := res+(flag[i+1]) ) else if (hoge /= 0) then ( res := res+(((hoge) + "") + flag[i+1]) ) else skip ; ; hoge := 0 ) ; i := i + 1 ) ; return res ); operation set( c : String) : int pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (c) ; if _switchval = 'm' then return 1000 else skip ; if _switchval = 'c' then return 100 else skip ; if _switchval = 'x' then return 10 else skip ; if _switchval = 'i' then return 1 else skip ; ) return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class NationalProject { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t!=0){ solve(br,pr); t--; } pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { String[] temp=br.readLine().split(" "); int n=Integer.parseInt(temp[0]); int g=Integer.parseInt(temp[1]); int b=Integer.parseInt(temp[2]); int min=(n+1)/2 ; long left=n ; long right=Long.MAX_VALUE ; while(left<=right){ long mid=left+(right-left)/2 ; if(countGood(mid,g,b)toInteger() ; while (t /= 0) do ( execute solve(br, pr) ; t := t - 1 ) ; skip ; skip ; ); static operation solve( br : OclFile, pr : OclFile) : void pre: true post: true activity: ( var temp : Sequence(String) ; temp := br.readLine()->split(" ") ; var n : int ; n := (temp[0+1])->toInteger() ; var g : int ; g := (temp[1+1])->toInteger() ; var b : int ; b := (temp[2+1])->toInteger() ; var min : int ; min := (n + 1) / 2 ; var left : long ; left := n ; var right : long ; right := "9223372036854775807"->toLong() ; while (left <= right) do ( var mid : long ; mid := left + (right - left) / 2 ; if (countGood(mid, g, b) < min) then ( left := mid + 1 ) else ( right := mid - 1 ) ) ; skip ; ); static operation countGood( day : long, g : int, b : int) : long pre: true post: true activity: ( var totalCycle : long ; totalCycle := day / (g + b) ; var good : long ; good := totalCycle * g ; var extra : long ; extra := day - (g + b) * totalCycle ; good := good+(Set{extra, g}->min()) ; return good ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class asphalt { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t,j,i ; long n,g,b,k,p,d ; t=sc.nextInt(); for(j=1 ; j<=t ; j++){ n=sc.nextLong(); g=sc.nextLong(); b=sc.nextLong(); k=(long)Math.ceil(n/2.0); p=(long)Math.ceil(k/(double)g); d=k+(p-1)*b+(((n-k)-((p-1)*b))>0 ?((n-k)-((p-1)*b)): 0); System.out.println(d); } } } ------------------------------------------------------------ OCL File: --------- class asphalt { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; var j : int ; var i : int ; var n : long ; var g : long ; var b : long ; var k : long ; var p : long ; var d : long ; t := sc.getCurrent()->toInteger() ; j := 1 ; while j <= t do ( ( n := sc.getCurrent()->toLong() ; g := sc.getCurrent()->toLong() ; b := sc.getCurrent()->toLong() ; k := (n / 2.0)->ceil()->oclAsType(long) ; p := (k / g->oclAsType(double))->ceil()->oclAsType(long) ; d := k + (p - 1) * b + (if ((n - k) - ((p - 1) * b)) > 0 then ((n - k) - ((p - 1) * b)) else 0 endif) ; OclFile["System.out"].println(d) ; ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); int max=(int)10e6+1 ; while(t-->0){ String str[]=br.readLine().split(" "); long n=Long.parseLong(str[0]); long g=Long.parseLong(str[1]); long b=Long.parseLong(str[2]); long req=(long)Math.ceil((double)n/2); long rg=(long)Math.ceil((double)req/g); long x=0 ; if((rg-1)*b>=(n-req)){ x=(rg-1)*b ; } else { x=(rg-1)*b+(n-req-(rg-1)*b); } System.out.println(x+req); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var t : int ; t := (br.readLine())->toInteger() ; var max : int ; max := 10e6->oclAsType(int) + 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var str : Sequence(String) ; str := br.readLine()->split(" ") ; var n : long ; n := (str[0+1])->toLong() ; var g : long ; g := (str[1+1])->toLong() ; var b : long ; b := (str[2+1])->toLong() ; var req : long ; req := (n->oclAsType(double) / 2)->ceil()->oclAsType(long) ; var rg : long ; rg := (req->oclAsType(double) / g)->ceil()->oclAsType(long) ; var x : long ; x := 0 ; if ((rg - 1) * b >= ((n)->char2byte() - req)) then ( x := (rg - 1) * b ) else ( x := (rg - 1) * b + ((n)->char2byte() - req - (rg - 1) * b) ) ; OclFile["System.out"].println(x + req) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void findSeries(int num,int first,int sec){ System.out.print(first+" "+sec+" "); int counter=0,sum ; while(counter=n && findDigitsInFactorial(mid-1)log10() + (2 * 3.141592653589793 * n)->log10() / 2.0)) ; return ((x)->floor() + 1)->oclAsType(int) ); static operation findNum( n : int) : int pre: true post: true activity: ( var low : int ; low := 0 ; var hi : int ; hi := 2 * n ; if (n <= 0) then return -1 else skip ; if (findDigitsInFactorial(low) = n) then return low else skip ; while (low <= hi) do ( var mid : int ; mid := (low + hi) / 2 ; if (findDigitsInFactorial(mid) >= n & findDigitsInFactorial(mid - 1) < n) then return mid else if (findDigitsInFactorial(mid) < n) then low := mid + 1 else hi := mid - 1 ; ; ) ; return low ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(findNum(1)) ; OclFile["System.out"].println(findNum(2)) ; OclFile["System.out"].println(findNum(5)) ; OclFile["System.out"].println(findNum(24)) ; OclFile["System.out"].println(findNum(100)) ; OclFile["System.out"].println(findNum(1221)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Main m=new Main(); m.answer(); } private Scanner scan=new Scanner(System.in); private static final int MAX=100000 ; private final int[] count ; public Main(){ count=new int[MAX+1]; int N=Integer.parseInt(scan.next()); for(int i=0 ; i0)result[i]+=count[i-1]; if(icollect(0) ; var N : int ; N := (scan.getCurrent())->toInteger() ; var i : int ; i := 0 ; while i < N do ( ( var a : int ; a := (scan.getCurrent())->toInteger() ; count[a+1] := count[a+1] + 1 ) ; i := i + 1 ) ; skip ); operation answer() : void pre: true post: true activity: ( var result : Sequence(int) ; result := Integer.subrange(1,MAX + 1)->collect(0) ; var i : int ; i := 0 ; while i <= MAX do ( ( result[i+1] := count[i+1] ; if (i > 0) then result[i+1] := result[i+1]+(count[i - 1+1]) ; else skip ; if (i < MAX) then result[i+1] := result[i+1]+(count[i + 1+1]) ; else skip ) ; i := i + 1 ) ; result := result->sort() ; OclFile["System.out"].println(result[MAX+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class GFG { public static void sortSquares(int arr[]){ int n=arr.length ; int k ; for(k=0 ; k=0)break ; } int i=k-1 ; int j=k ; int ind=0 ; int[] temp=new int[n]; while(i>=0 && j=0){ temp[ind++]=arr[i]*arr[i]; i--; } while(jsize() ; var k : int ; k := 0 ; while k < n do ( ( if (arr[k+1] >= 0) then break else skip ) ; k := k + 1 ) ; var i : int ; i := k - 1 ; var j : int ; j := k ; var ind : int ; ind := 0 ; var temp : Sequence(int) ; temp := Integer.subrange(1,n)->collect(0) ; while (i >= 0 & j < n) do ( if (arr[i+1] * arr[i+1] < arr[j+1] * arr[j+1]) 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] ; ind := ind + 1 ; i := i - 1 ) ; while (j < n) do ( temp[ind+1] := arr[j+1] * arr[j+1] ; ind := ind + 1 ; j := j + 1 ) ; var x : int ; x := 0 ; while x < n do ( arr[x+1] := temp[x+1] ; ; x := x + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-6,-3,-1,2,4,5} ; var n : int ; n := arr->size() ; OclFile["System.out"].println("Before sort ") ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; execute sortSquares(arr) ; OclFile["System.out"].println("") ; OclFile["System.out"].println("After Sort ") ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int maxProduct(int arr[],int n){ if(n<3){ return-1 ; } Arrays.sort(arr); return Math.max(arr[0]*arr[1]*arr[n-1],arr[n-1]*arr[n-2]*arr[n-3]); } public static void main(String[] args){ int arr[]={ -10,-3,5,6,-20 }; int n=arr.length ; int max=maxProduct(arr,n); if(max==-1){ System.out.println("No Triplet Exists"); } else { System.out.println("Maximum product is "+max); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxProduct( arr : Sequence(int), n : int) : int pre: true post: true activity: ( if (n < 3) then ( return -1 ) else skip ; arr := arr->sort() ; return Set{arr[0+1] * arr[1+1] * arr[n - 1+1], arr[n - 1+1] * arr[n - 2+1] * arr[n - 3+1]}->max() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-10,-3,5,6,-20} ; var n : int ; n := arr->size() ; var max : int ; max := maxProduct(arr, n) ; if (max = -1) then ( OclFile["System.out"].println("No Triplet Exists") ) else ( OclFile["System.out"].println("Maximum product is " + max) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Deserium { static int countDigits(int n){ int c=0 ; do { c++; n=n/10 ; } while(n!=0); return c ; } static boolean isDeserium(int x){ int temp=x ; int p=countDigits(x); int sum=0 ; while(x!=0){ int digit=x % 10 ; sum+=Math.pow(digit,p); p--; x=x/10 ; } return(sum==temp); } public static void main(String[] args){ int x=135 ; if(isDeserium(x))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class Deserium { static operation countDigits( n : int) : int pre: true post: true activity: ( var c : int ; c := 0 ; while true do (( c := c + 1 ; n := n / 10 ) ; if (n /= 0) then skip else break) ; return c ); static operation isDeserium( x : int) : boolean pre: true post: true activity: ( var temp : int ; temp := x ; var p : int ; p := countDigits(x) ; var sum : int ; sum := 0 ; while (x /= 0) do ( var digit : int ; digit := x mod 10 ; sum := sum+(digit->pow(p)) ; p := p - 1 ; x := x / 10 ) ; return (sum = temp) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 135 ; if (isDeserium(x)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getMinimumSum(int arr[],int n){ int fMin=Integer.MAX_VALUE,sMin=Integer.MAX_VALUE,tMin=Integer.MAX_VALUE ; for(int i=0 ; isize() ; OclFile["System.out"].print(getMinimumSum(arr, n) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static int gen(int n){ if(n==0)return 0 ; else if(n==1)return 1 ; else if(n % 2==0)return 4*gen(n/2); else if(n % 2==1)return 4*gen(n/2)+1 ; return 0 ; } public static void moserDeBruijn(int n){ for(int i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc ; Main(){ sc=new Scanner(System.in); } int ni(){ return sc.nextInt(); } public static void main(String[] args){ new Main().run(); } static int[] LUT ; static { LUT=new int[10001]; LUT['m']=1000 ; LUT['c']=100 ; LUT['x']=10 ; LUT['i']=1 ; LUT[1000]='m' ; LUT[100]='c' ; LUT[10]='x' ; LUT[1]='i' ; } int encode(String str){ int sum=0 ; int stack=1 ; for(char c : str.toCharArray()){ switch(c){ case 'm' : case 'c' : case 'x' : case 'i' : sum+=stack*LUT[c]; stack=1 ; break ; default : stack=c-'0' ; } } return sum ; } String decode(int num){ String str="" ; for(int i=1000 ; 01){ str+=k ; } if(k!=0){ str+=(char)LUT[i]; } num %=i ; } return str ; } void run(){ int n=ni(); for(int i=0 ; itoInteger() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); static attribute LUT : Sequence(int); static operation initialiseClass() pre: true post: true activity: LUT := Integer.subrange(1,10001)->collect(0) ; LUT['m'+1] := 1000 ; LUT['c'+1] := 100 ; LUT['x'+1] := 10 ; LUT['i'+1] := 1 ; LUT[1000+1] := 'm' ; LUT[100+1] := 'c' ; LUT[10+1] := 'x' ; LUT[1+1] := 'i' ; ; operation encode( str : String) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var stack : int ; stack := 1 ; for (c : str->characters()) do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (c) ; if _switchval = 'm' or _switchval = 'c' or _switchval = 'x' or _switchval = 'i' then sum := sum+(stack * LUT[c+1]) ; stack := 1 ; break else skip ; if true then stack := c - ('0')->char2byte() ; else skip ; ) ) ) ; return sum ); operation decode( num : int) : String pre: true post: true activity: ( var str : String ; str := "" ; var i : int ; i := 1000 ; while 0 < i do ( ( var k : int ; k := num / i ; if (k > 1) then ( str := str+(k) ) else skip ; if (k /= 0) then ( str := str+(LUT[i+1]->oclAsType(String)) ) else skip ; num := num mod i ) ; i := i/(10) ) ; return str ); operation run() : void pre: true post: true activity: ( var n : int ; n := ni() ; var i : int ; i := 0 ; while i < n do ( ( var left : String ; left := sc.getCurrent() ; var right : String ; right := sc.getCurrent() ; OclFile["System.out"].println(decode(encode(left) + encode(right))) ) ; i := i + 1 ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); int m=sc.nextInt(); if(n==0 && m==0)break ; int[] map=new int[n]; int[] th=new int[m]; for(int i=0 ; i=n-1)break ; now+=map[now]; if(now<0)now=0 ; } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if (n = 0 & m = 0) then break else skip ; var map : Sequence(int) ; map := Integer.subrange(1,n)->collect(0) ; var th : Sequence(int) ; th := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( map[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( th[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var now : int ; now := 0 ; var idx : int ; idx := 0 ; var ans : int ; ans := 0 ; while (now < n - 1) do ( ans := ans + 1 ; now := now + th[idx+1] ; idx := idx + 1 ; if (now >= n - 1) then break else skip ; now := now+(map[now+1]) ; if (now < 0) then now := 0 ; else skip ; ) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-9 ; int n,m ; int[] b,a ; void run(){ for(; ; ){ n=sc.nextInt(); m=sc.nextInt(); if((n | m)==0){ break ; } b=new int[n]; a=new int[m]; for(int i=0 ; i=n-1){ break ; } p+=b[p]; if(p>=n-1){ break ; } } println(""+(i+1)); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute EPS : double := 1e-9; attribute n : int; attribute b : Sequence(int); operation run() : void pre: true post: true activity: ( while true do ( ( n := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then ( break ) else skip ; b := Integer.subrange(1,n)->collect(0) ; a := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute solve() ; ) ) ); operation solve() : void pre: true post: true activity: ( var p : int ; p := 0 ; var i : int ; i := 0 ; while i < m do ( ( p := p+(a[i+1]) ; if (p >= n - 1) then ( break ) else skip ; p := p+(b[p+1]) ; if (p >= n - 1) then ( break ) else skip ) ; i := i + 1 ) ; execute println("" + (i + 1)) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(; ; ){ String[] readGame=br.readLine().split(" "); int sugorokuNum=Integer.parseInt(readGame[0]); int saikoroCnt=Integer.parseInt(readGame[1]); int[] sugorokuMasu=new int[sugorokuNum]; if(sugorokuNum==0){ break ; } for(int i=0 ; i=sugorokuNum-1 || position+factorCount+sugorokuMasu[position+factorCount]>=sugorokuNum-1){ break ; } else { position+=factorCount+sugorokuMasu[position+factorCount]; } } for(int i=0 ; isplit(" ") ; var sugorokuNum : int ; sugorokuNum := (readGame[0+1])->toInteger() ; var saikoroCnt : int ; saikoroCnt := (readGame[1+1])->toInteger() ; var sugorokuMasu : Sequence(int) ; sugorokuMasu := Integer.subrange(1,sugorokuNum)->collect(0) ; if (sugorokuNum = 0) then ( break ) else skip ; var i : int ; i := 0 ; while i < sugorokuNum do ( ( var factorCount : int ; factorCount := (br.readLine())->toInteger() ; sugorokuMasu[i+1] := factorCount ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var position : int ; position := 0 ; var i : int ; i := 0 ; while i < saikoroCnt do ( ( var factorCount : int ; factorCount := (br.readLine())->toInteger() ; cnt := cnt + 1 ; if (position + factorCount >= sugorokuNum - 1 or position + factorCount + sugorokuMasu[position + factorCount+1] >= sugorokuNum - 1) then ( break ) else ( position := position+(factorCount + sugorokuMasu[position + factorCount+1]) ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < saikoroCnt - cnt do ( ( skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] data=br.readLine().split(" "); int[] num=new int[100000]; for(int i=0 ; imax){ max=temp ; } } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var data : Sequence(String) ; data := br.readLine()->split(" ") ; var num : Sequence(int) ; num := Integer.subrange(1,100000)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( num[(data[i+1])->toInteger()+1] := num[(data[i+1])->toInteger()+1] + 1 ) ; i := i + 1 ) ; var temp : int ; temp := 0 ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i <= 99997 do ( ( temp := num[i+1] + num[i + 1+1] + num[i + 2+1] ; if (temp > max) then ( max := temp ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { int INF=1<<28 ; void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int n=sc.nextInt(); int m=sc.nextInt(); if((n | m)==0)break ; int map[]=new int[n]; int sai[]=new int[m]; for(int i=0 ; i=n-1)break ; p+=sai[cnt]+map[sai[cnt]+p]; if(p>=n-1){ break ; } } if(cnt==m)cnt--; System.out.println(cnt+1); } } public static void main(String[] args){ new Main().run(); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute INF : int := (1*(2->pow(28)))->oclAsType(long); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then break else skip ; var map : Sequence(int) ; map := Integer.subrange(1,n)->collect(0) ; var sai : Sequence(int) ; sai := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( map[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( sai[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var cnt : int ; var p : int ; p := 0 ; cnt := 0 ; while cnt < m do ( ( if (sai[cnt+1] + p >= n - 1) then break else skip ; p := p+(sai[cnt+1] + map[sai[cnt+1] + p+1]) ; if (p >= n - 1) then ( break ) else skip ) ; cnt := cnt + 1 ) ; if (cnt = m) then cnt := cnt - 1 ; else skip ; OclFile["System.out"].println(cnt + 1) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void findMostOccurringChar(Vectorstr){ int[] hash=new int[26]; for(int i=0 ; ihash[max] ? i : max ; } System.out.print((char)(max+97)+"\n"); } public static void main(String[] args){ Vectorstr=new Vector(); str.add("animal"); str.add("zebra"); str.add("lion"); str.add("giraffe"); findMostOccurringChar(str); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findMostOccurringChar( str : Sequence(String)) : void pre: true post: true activity: ( var hash : Sequence(int) ; hash := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < str->size() do ( ( var j : int ; j := 0 ; while j < str->at(i+1)->size() do ( ( hash[str->at(i+1)->at(j+1) - 97+1] := hash[str->at(i+1)->at(j+1) - 97+1] + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < 26 do ( ( max := if hash[i+1] > hash[max+1] then i else max endif ) ; i := i + 1 ) ; OclFile["System.out"].print((max + 97)->oclAsType(String) + "\n") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : Sequence(String) ; str := Sequence{} ; str := str->including("animal") ; str := str->including("zebra") ; str := str->including("lion") ; str := str->including("giraffe") ; execute findMostOccurringChar(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int val(char c){ if(c>='0' && c<='9')return(int)c-'0' ; else return(int)c-'A'+10 ; } static int toDeci(String str,int base){ int len=str.length(); int power=1 ; int num=0 ; int i ; for(i=len-1 ; i>=0 ; i--){ if(val(str.charAt(i))>=base){ System.out.println("Invalid Number"); return-1 ; } num+=val(str.charAt(i))*power ; power=power*base ; } return num ; } public static void main(String[] args){ String str="11A" ; int base=16 ; System.out.println("Decimal equivalent of "+str+" in base "+base+" is "+" "+toDeci(str,base)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation val( c : String) : int pre: true post: true activity: ( if (c >= '0' & c <= '9') then return c->oclAsType(int) - ('0')->char2byte() else return c->oclAsType(int) - ('A')->char2byte() + 10 ); static operation toDeci( str : String, base : int) : int pre: true post: true activity: ( var len : int ; len := str->size() ; var power : int ; power := 1 ; var num : int ; num := 0 ; var i : int ; i := len - 1 ; while i >= 0 do ( ( if (val(str->at(i+1)) >= base) then ( OclFile["System.out"].println("Invalid Number") ; return -1 ) else skip ; num := num+(val(str->at(i+1)) * power) ; power := power * base ) ; i := i - 1 ) ; return num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "11A" ; var base : int ; base := 16 ; OclFile["System.out"].println("Decimal equivalent of " + str + " in base " + base + " is " + " " + toDeci(str, base)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static float pi=3.14159f ; static float volume(float r){ float vol ; vol=((float)4/(float)3)*(pi*r*r*r); return vol ; } static float surface_area(float r){ float sur_ar ; sur_ar=4*pi*r*r ; return sur_ar ; } public static void main(String[] args){ float radius=12 ; float vol,sur_area ; vol=volume(radius); sur_area=surface_area(radius); System.out.println("Volume Of Sphere :"+vol); System.out.println("Surface Area Of Sphere :"+sur_area); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute pi : double := 3.14159f; static operation volume( r : double) : double pre: true post: true activity: ( var vol : double ; vol := (4->oclAsType(double) / 3->oclAsType(double)) * (pi * r * r * r) ; return vol ); static operation surface_area( r : double) : double pre: true post: true activity: ( var sur_ar : double ; sur_ar := 4 * pi * r * r ; return sur_ar ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var radius : double ; radius := 12 ; var vol : double ; var sur_area : double ; vol := volume(radius) ; sur_area := surface_area(radius) ; OclFile["System.out"].println("Volume Of Sphere :" + vol) ; OclFile["System.out"].println("Surface Area Of Sphere :" + sur_area) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static int count(int arr[],int n,int k){ Arrays.sort(arr); int cnt=0 ; int i=0,j=1 ; while(isort() ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; var j : int ; j := 1 ; while (i < n & j < n) do ( j := if (j <= i) then (i + 1) else j endif ; while (j < n & (arr[j+1] - arr[i+1]) < k) do j := j + 1 ; ; cnt := cnt+((n - j)) ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4} ; var n : int ; n := arr->size() ; var k : int ; k := 2 ; OclFile["System.out"].println(count(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.List ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.PrintWriter ; import java.math.BigDecimal ; import java.math.RoundingMode ; import java.text.DecimalFormat ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collection ; import java.util.Scanner ; import java.util.StringTokenizer ; public class main { public static void main(String[] args){ FastScanner in=new FastScanner(); int n=in.nextInt(),p=in.nextInt(); int unit[]=new int[n],stored[]=new int[n]; long sum=0 ; for(int i=0 ; i0){ double mid=(l+r)/2 ; double need=0 ; for(int i=0 ; imid*p){ r=mid ; } else l=mid ; } System.out.println(l); } } class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } ------------------------------------------------------------ OCL File: --------- class main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastScanner ; in := FastScanner.newFastScanner() ; var n : int ; n := in.nextInt() ; var p : int ; p := in.nextInt() ; var unit : Sequence(int) ; unit := Integer.subrange(1,n)->collect(0) ; var stored : Sequence(void) ; stored := Integer.subrange(1,n)->collect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( unit[i+1] := in.nextInt() ; sum := sum+(unit[i+1]) ; stored[i+1] := in.nextInt() ) ; i := i + 1 ) ; if (sum <= p) then ( OclFile["System.out"].println("-1") ; return ) else skip ; var l : double ; l := 0 ; var r : double ; r := 1e10 + 1 ; var total : int ; total := 200 ; while (total > 0) do ( total := total - 1 ; skip ; ( var mid : double ; mid := (l + r) / 2 ; var need : double ; need := 0 ; var i : int ; i := 0 ; while i < n do ( ( need := need+(Set{0, unit[i+1]->oclAsType(double) * mid - stored[i+1]}->max()) ) ; i := i + 1 ) ; if (need > mid * p) then ( r := mid ) else l := mid ; ) ; ) ; OclFile["System.out"].println(l) ; ); } class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new aoj1137().doIt(); } class aoj1137 { char keta[]={ 'i','x','c','m' }; char keta2[]={ '2','3','4','5','6','7','8','9' }; int number(char ctr[]){ int result=0 ; int num2=1 ; int num=1 ; for(int i=0 ; i=0 ; j--){ int ans=sum/m ; if(ans>1){ System.out.print(ans); System.out.print(keta[j]); } else if(ans==1){ System.out.print(keta[j]); } sum=sum % m ; m=m/10 ; } System.out.println(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( aoj1137.newaoj1137().doIt() ); class aoj1137 { attribute keta : String := Sequence{'i','x','c','m'}; attribute keta2 : String := Sequence{'2','3','4','5','6','7','8','9'}; operation number( ctr : Sequence(String)) : int pre: true post: true activity: ( var result : int ; result := 0 ; var num2 : int ; num2 := 1 ; var num : int ; num := 1 ; var i : int ; i := 0 ; while i < ctr->size() do ( ( var j : int ; j := 0 ; while j < 4 do ( ( if (keta[j+1] = ctr[i+1]) then ( result := result + (num * num2) ; num2 := 1 ; break ) else skip ; num := num * 10 ) ; j := j + 1 ) ; num := 1 ; var j : int ; j := 0 ; while j < 8 do ( ( if (keta2[j+1] = ctr[i+1]) then num2 := num2 * (j + 2) ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return result ); operation doIt() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : String ; a := sc.getCurrent() ; var b : String ; b := sc.getCurrent() ; var ctra : Sequence(String) ; ctra := a->characters() ; var ctrb : Sequence(String) ; ctrb := b->characters() ; var sum : int ; sum := number(ctra) + number(ctrb) ; var m : int ; m := 1000 ; var j : int ; j := 3 ; while j >= 0 do ( ( var ans : int ; ans := sum / m ; if (ans > 1) then ( OclFile["System.out"].print(ans) ; OclFile["System.out"].print(keta[j+1]) ) else if (ans = 1) then ( OclFile["System.out"].print(keta[j+1]) ) else skip ; ; sum := sum mod m ; m := m / 10 ) ; j := j - 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class codeTwentySix { public static void main(String[] args){ Scanner input=new Scanner(System.in); int c=input.nextInt(); int l=input.nextInt(); int r=input.nextInt(); int count=0 ; int t=input.nextInt(); int[] array=new int[t]; for(int i=0 ; il){ count++; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class codeTwentySix { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var c : int ; c := input.getCurrent()->toInteger() ; var l : int ; l := input.getCurrent()->toInteger() ; var r : int ; r := input.getCurrent()->toInteger() ; var count : int ; count := 0 ; var t : int ; t := input.getCurrent()->toInteger() ; var array : Sequence(int) ; array := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( array[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t do ( ( if (array[i+1] < r & array[i+1] > l) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int p=s.nextInt(); int l=s.nextInt(); int r=s.nextInt(); int n=s.nextInt(); int counter=0 ; for(int i=0 ; itoInteger() ; var l : int ; l := s.getCurrent()->toInteger() ; var r : int ; r := s.getCurrent()->toInteger() ; var n : int ; n := s.getCurrent()->toInteger() ; var counter : int ; counter := 0 ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := s.getCurrent()->toInteger() ; if (l < a & a < r) then ( counter := counter + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Five { public static void main(String[] args)throws IOException { BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stringTokenizer=new StringTokenizer(bufferedReader.readLine()); int a=Integer.parseInt(stringTokenizer.nextToken()); int b=Integer.parseInt(stringTokenizer.nextToken()); int c=Integer.parseInt(stringTokenizer.nextToken()); int n=Integer.parseInt(bufferedReader.readLine()); stringTokenizer=new StringTokenizer(bufferedReader.readLine()); int j=0 ; int sum=0 ; while(j++b && valtoInteger() ; var b : int ; b := (stringTokenizer.next())->toInteger() ; var c : int ; c := (stringTokenizer.next())->toInteger() ; var n : int ; n := (bufferedReader.readLine())->toInteger() ; stringTokenizer := OclIterator.newOclIterator_String(bufferedReader.readLine()) ; var j : int ; j := 0 ; var sum : int ; sum := 0 ; while (j < n) do ( j := j + 1 ; skip ; ( var val : int ; val := (stringTokenizer.next())->toInteger() ; if (val > b & val < c) then sum := sum + 1 ; else skip ) ; ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[] A=new int[N]; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(N, A)) ; ); static operation solve( N : int, A : Sequence(int)) : int pre: true post: true activity: ( A := A->sort() ; var max : int ; max := -1 ; var prev2 : int ; prev2 := 0 ; var prev1 : int ; prev1 := 0 ; var current : int ; current := 0 ; var current_a : int ; current_a := -1 ; var i : int ; i := 0 ; while i < N do ( ( var a : int ; a := A[i+1] ; if (a /= current_a) then ( max := Set{prev2 + prev1 + current, max}->max() ; if (current_a + 1 = a) then ( prev2 := prev1 ; prev1 := current ) else if (current_a + 2 = a) then ( prev2 := current ; prev1 := 0 ) else ( prev2 := 0 ; prev1 := 0 ) ; ; current_a := a ; current := 1 ) else ( current := current + 1 ) ) ; i := i + 1 ) ; max := Set{prev2 + prev1 + current, max}->max() ; return max ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.util.stream.*; public class App { static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args)throws Exception { if(System.getProperty("ONLINE_JUDGE")==null){ File inputFile=new File("/Users/vipinjain/self/cp/input.txt"); File outputFile=new File("/Users/vipinjain/self/cp/output.txt"); br=new BufferedReader(new FileReader(inputFile)); bw=new BufferedWriter(new FileWriter(outputFile)); } int tests ; tests=1 ; while(tests-->0){ solve(); } bw.flush(); bw.close(); br.close(); } static int getNumberOfDays(int month){ switch(month){ case 1 : case 3 : case 5 : case 7 : case 8 : case 10 : case 12 : return 31 ; case 2 : return 28 ; default : return 30 ; } } static void solve()throws Exception { String[] tmp=br.readLine().split(" "); int a=Integer.parseInt(tmp[0]); int b=Integer.parseInt(tmp[1]); int c=Integer.parseInt(tmp[2]); int n=Integer.parseInt(br.readLine()); int[] arr=Stream.of(br.readLine().split(" ")).mapToInt(Integer :: parseInt).toArray(); int money=0 ; for(int num : arr){ if(num>b && num 0) do ( tests := tests - 1 ; skip ; ( execute solve() ) ; ) ; skip ; skip ; skip ; ); static operation getNumberOfDays( month : int) : int pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (month) ; if _switchval = 1 or _switchval = 3 or _switchval = 5 or _switchval = 7 or _switchval = 8 then if _switchval = 10 then if _switchval = 12 then return 31 else skip ; if _switchval = 2 then return 28 else skip ; if true then return 30 else skip ; ) ); static operation solve() : void pre: true post: true activity: ( var tmp : Sequence(String) ; tmp := br.readLine()->split(" ") ; var a : int ; a := (tmp[0+1])->toInteger() ; var b : int ; b := (tmp[1+1])->toInteger() ; var c : int ; c := (tmp[2+1])->toInteger() ; var n : int ; n := (br.readLine())->toInteger() ; var arr : Sequence(int) ; arr := Sequence{br.readLine()->split(" ")}->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ; var money : int ; money := 0 ; for (num : arr) do ( ( if (num > b & num < c) then ( money := money + 1 ) else skip ) ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String S=sc.next(); System.out.println(solve(S)? "Yes" : "No"); sc.close(); } static boolean solve(String S){ return S.chars().distinct().count()==3 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : String ; S := sc.getCurrent() ; OclFile["System.out"].println(if solve(S) then "Yes" else "No" endif) ; skip ); static operation solve( S : String) : boolean pre: true post: true activity: ( return S.chars()->asOrderedSet()->size() = 3 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws Exception { String line=readLine(); StringTokenizer st=new StringTokenizer(line,""); String s=(String)st.nextToken(); String[] strArray=s.split(""); String a=strArray[0]; String b=strArray[1]; String c=strArray[2]; if((a.equals(b))||(a.equals(c))||(b.equals(c))){ System.out.println("No"); } else { System.out.println("Yes"); } } private static String readLine()throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); return br.readLine(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var line : String ; line := readLine() ; var st : OclIterator ; st := OclIterator.newOclIterator_String_String(line, "") ; var s : String ; s := st.next()->oclAsType(String) ; var strArray : Sequence(String) ; strArray := s->split("") ; var a : String ; a := strArray[0+1] ; var b : String ; b := strArray[1+1] ; var c : String ; c := strArray[2+1] ; if ((a = b) or (a = c) or (b = c)) then ( OclFile["System.out"].println("No") ) else ( OclFile["System.out"].println("Yes") ) ; ); static operation readLine() : String pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; return br.readLine() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static char[][] map ; static int N ; static int M ; static boolean flag ; static int ans ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); String string=sc.next(); char[] cs=string.toCharArray(); boolean[] flag=new boolean[3]; for(int i=0 ; i<3 ; i++){ if(cs[i]=='a'){ flag[0]=true ; } else if(cs[i]=='b'){ flag[1]=true ; } else if(cs[i]=='c'){ flag[2]=true ; } } if(flag[0] && flag[1] && flag[2]){ System.out.println("Yes"); } else { System.out.println("No"); } } } class Pair implements Comparable { String from ; int end ; @ Override public int compareTo(Object other){ Pair otherpair=(Pair)other ; return end-otherpair.end ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute map : Sequence(Sequence(String)); static attribute N : int; static attribute M : int; static attribute flag : boolean; static attribute ans : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var string : String ; string := sc.getCurrent() ; var cs : Sequence(String) ; cs := string->characters() ; var flag : Sequence(boolean) ; flag := Integer.subrange(1,3)->collect(false) ; var i : int ; i := 0 ; while i < 3 do ( ( if (cs[i+1] = 'a') then ( flag[0+1] := true ) else if (cs[i+1] = 'b') then ( flag[1+1] := true ) else if (cs[i+1] = 'c') then ( flag[2+1] := true ) else skip ; ; ) ; i := i + 1 ) ; if (flag[0+1] & flag[1+1] & flag[2+1]) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } class Pair implements OclAny { attribute from : String; attribute end : int; operation compareTo( other : OclAny) : int pre: true post: true activity: ( var otherpair : Map ; otherpair := other->oclAsType(Map) ; return end - otherpair.end ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); String[] ss=s.split(""); Arrays.sort(ss); if(String.join("",ss).equals("abc")){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; var ss : Sequence(String) ; ss := s->split("") ; ss := ss->sort() ; if (join("", ss) = "abc") then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder s=new StringBuilder(); s.append(br.readLine()); System.out.println(new Problem(s).solve()); br.close(); } } class Problem { StringBuilder s ; public Problem(StringBuilder s){ this.s=s ; } public String solve(){ String result="No" ; if(s.toString().contains("a")&& s.toString().contains("b")&& s.toString().contains("c")){ result="Yes" ; } return result ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var s : String ; s := StringLib.newString() ; s := s + StringLib.newString(br.readLine()) ; OclFile["System.out"].println(Problem.newProblem(s).solve()) ; skip ; ); } class Problem { attribute s : String; static operation newProblem( s : String) : Problem pre: true post: true activity: ( var self : Problem ; self := createProblem(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( self.s := s ); operation solve() : String pre: true post: true activity: ( var result : String ; result := "No" ; if (s+""->includes("a") & s+""->includes("b") & s+""->includes("c")) then ( result := "Yes" ) else skip ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class LittleRobberGirlZoo { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n+1]; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); } for(int i=1 ; i<=n ; i++){ for(int j=1 ; jarr[j+1]){ int temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp ; System.out.println(j+" "+(j+1)); } } } } } ------------------------------------------------------------ OCL File: --------- class LittleRobberGirlZoo { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j < n do ( ( if (arr[j+1] > arr[j + 1+1]) then ( var temp : int ; temp := arr[j+1] ; arr[j+1] := arr[j + 1+1] ; arr[j + 1+1] := temp ; OclFile["System.out"].println(j + " " + (j + 1)) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.awt.geom.*; import java.io.*; public class Main { private void doit(){ Scanner sc=new Scanner(System.in); int dataset=sc.nextInt(); while(dataset-->0){ String a=sc.next(); String b=sc.next(); int anum=solve(a); int bnum=solve(b); String c=tostr(anum+bnum); System.out.println(c); } } private int solve(String a){ int mul=1 ; int res=0 ; int[] value=new int[26]; value['m'-'a']=1000 ; value['c'-'a']=100 ; value['x'-'a']=10 ; value['i'-'a']=1 ; for(int i=0 ; itoInteger() ; while (dataset > 0) do ( dataset := dataset - 1 ; skip ; ( var a : String ; a := sc.getCurrent() ; var b : String ; b := sc.getCurrent() ; var anum : int ; anum := solve(a) ; var bnum : int ; bnum := solve(b) ; var c : String ; c := tostr(anum + bnum) ; OclFile["System.out"].println(c) ; ) ; ) ); operation solve( a : String) : int pre: true post: true activity: ( var mul : int ; mul := 1 ; var res : int ; res := 0 ; var value : Sequence(int) ; value := Integer.subrange(1,26)->collect(0) ; value[('m')->char2byte() - ('a')->char2byte()+1] := 1000 ; value[('c')->char2byte() - ('a')->char2byte()+1] := 100 ; value[('x')->char2byte() - ('a')->char2byte()+1] := 10 ; value[('i')->char2byte() - ('a')->char2byte()+1] := 1 ; var i : int ; i := 0 ; while i < a->size() do ( ( if ((a->at(i+1) + "")->isMatch("[0-9]")) then ( mul := a->at(i+1) - ('0')->char2byte() ) else ( res := res+(value[a->at(i+1) - ('a')->char2byte()+1] * mul) ; mul := 1 ) ) ; i := i + 1 ) ; return res ); operation tostr( num : int) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; var c : Sequence(String) ; c := Sequence{"m","c","x","i"} ; var i : int ; i := 1000 ; var count : int ; count := 0 ; while i /= 0 do ( ( if (num / i = 0) then ( continue ) else skip ; var temp : int ; temp := num / i ; if (temp /= 1) then ( sb := sb + StringLib.newString(num / i) ) else skip ; sb := sb + StringLib.newString(c[count+1]) ; num := num mod i ; ) ; i := i / 10 ; count := count + 1 ) ; return sb+"" ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println("debug=" + (o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class div_2_359_b { public static void main(String args[]){ FScanner in=new FScanner(); PrintWriter out=new PrintWriter(System.out); int n=in.nextInt(); int a[]=in.readArray(n); for(int i=n-1 ; i>=0 ; i--){ for(int j=0 ; ja[j+1]){ int temp=a[j]; a[j]=a[j+1]; a[j+1]=temp ; out.println((j+1)+" "+(j+2)); } } } out.close(); } static class FScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb=new StringTokenizer(""); String next(){ while(! sb.hasMoreTokens()){ try { sb=new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try { return br.readLine(); } catch(IOException e){ } return "" ; } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } int[] readArray(int n){ int a[]=new int[n]; for(int i=0 ; i= 0 do ( ( var j : int ; j := 0 ; while j < i do ( ( if (a[j+1] > a[j + 1+1]) then ( var temp : int ; temp := a[j+1] ; a[j+1] := a[j + 1+1] ; a[j + 1+1] := temp ; skip ) else skip ) ; j := j + 1 ) ) ; i := i - 1 ) ; skip ; ); static class FScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute sb : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(sb.hasNext())) do ( try ( sb := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do skip ) ; return sb.next() ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : IOException) do skip return "" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } _359_b { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FScanner ; in := FScanner.newFScanner() ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.nextInt() ; var a : Sequence(int) ; a := in.readArray(n) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( var j : int ; j := 0 ; while j < i do ( ( if (a[j+1] > a[j + 1+1]) then ( var temp : int ; temp := a[j+1] ; a[j+1] := a[j + 1+1] ; a[j + 1+1] := temp ; skip ) else skip ) ; j := j + 1 ) ) ; i := i - 1 ) ; skip ; ); static class FScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute sb : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(sb.hasNext())) do ( try ( sb := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do skip ) ; return sb.next() ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : IOException) do skip return "" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class LittleRobberGirlsZoo { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int temp=0 ; int arr[]=new int[n]; for(int i=0 ; iarr[j]){ temp=arr[j-1]; arr[j-1]=arr[j]; arr[j]=temp ; System.out.println((j)+" "+(j+1)); } } } } } ------------------------------------------------------------ OCL File: --------- class LittleRobberGirlsZoo { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var temp : int ; temp := 0 ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 1 ; while j < (n - i) do ( ( if (arr[j - 1+1] > arr[j+1]) then ( temp := arr[j - 1+1] ; arr[j - 1+1] := arr[j+1] ; arr[j+1] := temp ; OclFile["System.out"].println((j) + " " + (j + 1)) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); while(in.hasNextLine()){ int R=in.nextInt(); int C=in.nextInt(); if(R==0 && C==0)break ; HashMaphm=new HashMap(); for(int i=0 ; itoInteger() ; var C : int ; C := in.getCurrent()->toInteger() ; if (R = 0 & C = 0) then break else skip ; var hm : Map(String,Loc) ; hm := Map{} ; var i : int ; i := 0 ; while i < R do ( ( var str : String ; str := in.getCurrent() ; var j : int ; j := 0 ; while j < C do ( ( var c : String ; c := str->at(j+1) ; if (c = '_') then continue else skip ; hm := hm->union(Map{c |-> Loc.newLoc(i, j)}) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var str : String ; str := in.getCurrent() ; var iPos : int ; iPos := 0 ; var jPos : int ; jPos := 0 ; var count : int ; count := str->size() ; var i : int ; i := 0 ; while i < str->size() do ( ( var loc : Loc ; loc := hm->at(str->at(i+1)) ; count := count+(if (iPos)->char2byte() - loc.i < 0 then -((iPos)->char2byte() - loc.i) else (iPos)->char2byte() - loc.i endif + if jPos - loc.j < 0 then -(jPos - loc.j) else jPos - loc.j endif) ; iPos := loc.i ; jPos := loc.j ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) ); static class Loc { attribute i : int; attribute j : int; static operation newLoc( i : int, j : int) : Loc pre: true post: true activity: ( var self : Loc ; self := createLoc(); self.initialise(i, j); return self ); operation initialise( i : int, j : int) : void pre: true post: true activity: ( self.i := i ; self.j := j ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class amd { public static void main(String args[]){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); int m=s.nextInt(); HashSeths=new HashSet<>(); for(int i=1 ; i<=m ; i++){ int a=s.nextInt(); int b=s.nextInt(); int c=s.nextInt(); hs.add(b); } int node=0 ; for(int i=1 ; i<=n ; i++){ if(! hs.contains(i)){ node=i ; break ; } } for(int i=1 ; i<=n ; i++){ if(i!=node)System.out.println(node+" "+i); } } } } ------------------------------------------------------------ OCL File: --------- class amd { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.getCurrent()->toInteger() ; var m : int ; m := s.getCurrent()->toInteger() ; var hs : Set(int) ; hs := Set{} ; var i : int ; i := 1 ; while i <= m do ( ( var a : int ; a := s.getCurrent()->toInteger() ; var b : int ; b := s.getCurrent()->toInteger() ; var c : int ; c := s.getCurrent()->toInteger() ; hs := hs->including(b) ) ; i := i + 1 ) ; var node : int ; node := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (not(hs->includes(i))) then ( node := i ; break ) else skip ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( if (i /= node) then OclFile["System.out"].println(node + " " + i) ; else skip ) ; i := i + 1 ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B1583 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var M : int ; M := in.getCurrent()->toInteger() ; var used : Sequence(boolean) ; used := Integer.subrange(1,N)->collect(false) ; var m : int ; m := 0 ; while m < M do ( ( skip ; var b : int ; b := in.getCurrent()->toInteger() - 1 ; skip ; used[b+1] := true ) ; m := m + 1 ) ; var center : int ; center := 0 ; while (used[center+1]) do center := center + 1 ; ; var output : String ; output := StringLib.newString() ; var n : int ; n := 0 ; while n < N do ( ( if (n /= center) then ( output := output + StringLib.newString((n + 1) + " " + (center + 1) + "\n") ) else skip ) ; n := n + 1 ) ; OclFile["System.out"].print(output) ; ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class Main { public static final Long mod=Long.valueOf(998244353); public static final int N=200020 ; public static Long[] ch=new Long[N]; public static int[] deg=new int[N]; public static void main(String args[]){ Scanner in ; PrintStream out ; try { in=new Scanner(new FileInputStream("java.in")); out=new PrintStream("java.out"); } catch(FileNotFoundException e){ in=new Scanner(new BufferedInputStream(System.in)); out=System.out ; } ch[0]=Long.valueOf(1); for(int i=1 ; itoLong(); static attribute N : int := 200020; static attribute ch : Sequence(long) := Integer.subrange(1,N)->collect(null); static attribute deg : Sequence(int) := Integer.subrange(1,N)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; var out : OclFile ; try ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("java.in"))) ; out := OclFile.newOclFile_Write(OclFile.newOclFile("java.out")) ) catch (e : FileNotFoundException) do ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile["System.out"] ) ch[0+1] := (1)->toLong() ; var i : int ; i := 1 ; while i < N do ( ( ch[i+1] := (ch[i - 1+1] * i) mod mod ) ; i := i + 1 ) ; var n : int ; n := in.getCurrent()->toInteger() ; var ans : long ; ans := (n)->toLong() ; var i : int ; i := 1 ; var u : int ; var v : int ; while i < n do ( ( u := in.getCurrent()->toInteger() ; v := in.getCurrent()->toInteger() ; deg[u+1] := deg[u+1] + 1 ; deg[v+1] := deg[v+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( ans := ans * ch[deg[i+1]+1] mod mod ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class Main { public static final Long mod=Long.valueOf(998244353); public static final int N=200020 ; public static Long[] ch=new Long[N]; public static int[] deg=new int[N]; public static void main(String args[]){ Scanner in ; PrintStream out ; in=new Scanner(new BufferedInputStream(System.in)); out=System.out ; ch[0]=Long.valueOf(1); for(int i=1 ; itoLong(); static attribute N : int := 200020; static attribute ch : Sequence(long) := Integer.subrange(1,N)->collect(null); static attribute deg : Sequence(int) := Integer.subrange(1,N)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; var out : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile["System.out"] ; ch[0+1] := (1)->toLong() ; var i : int ; i := 1 ; while i < N do ( ( ch[i+1] := (ch[i - 1+1] * i) mod mod ) ; i := i + 1 ) ; var n : int ; n := in.getCurrent()->toInteger() ; var ans : long ; ans := (n)->toLong() ; var i : int ; i := 1 ; var u : int ; var v : int ; while i < n do ( ( u := in.getCurrent()->toInteger() ; v := in.getCurrent()->toInteger() ; deg[u+1] := deg[u+1] + 1 ; deg[v+1] := deg[v+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( ans := ans * ch[deg[i+1]+1] mod mod ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String args[]){ FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=1 ; while(T-->0){ int n=input.nextInt(); long m=998244353 ; int deg[]=new int[n+1]; for(int i=0 ; i 0) do ( T := T - 1 ; skip ; ( var n : int ; n := input.nextInt() ; var m : long ; m := 998244353 ; var deg : Sequence(int) ; deg := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var u : int ; u := input.nextInt() ; var v : int ; v := input.nextInt() ; deg[u+1] := deg[u+1] + 1 ; deg[v+1] := deg[v+1] + 1 ) ; i := i + 1 ) ; var fac : Sequence(long) ; fac := Integer.subrange(1,n + 1)->collect(0) ; fac[0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( ( fac[i+1] := (fac[i - 1+1] * i) mod m ) ; i := i + 1 ) ; var ans : long ; ans := 1 ; var i : int ; i := 1 ; while i <= n do ( ( ans := (ans * fac[deg[i+1]+1]) mod m ) ; i := i + 1 ) ; ans := (ans * n) mod m ; skip ; ) ; ) ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); public static void solve(){ boolean flg=false ; boolean flag=false ; String pass=sc.next(); int n=sc.nextInt(); String arr[]=new String[n]; for(int i=0 ; i0)solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation solve() : void pre: true post: true activity: ( var flg : boolean ; flg := false ; var flag : boolean ; flag := false ; var pass : String ; pass := sc.getCurrent() ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(String) ; arr := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent() ; if (arr[i+1]->compareTo(pass) = 0) then flg := true ; else skip ) ; i := i + 1 ) ; if (flg) then ( OclFile["System.out"].println("YES") ; return ) else skip ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1]->at(1+1) = pass->at(0+1)) then flg := true ; else skip ; if (arr[i+1]->at(0+1) = pass->at(1+1)) then flag := true ; else skip ; if (flg & flag) then break else skip ) ; i := i + 1 ) ; if (flg & flag) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; execute solve() ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _868A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); int t=sc.nextInt(); boolean first=false,second=false ; sc.nextLine(); while(t--!=0){ String v=sc.nextLine(); if(v.equals(s)){ first=true ; second=true ; } if(v.charAt(0)==s.charAt(1)){ second=true ; } if(v.charAt(1)==s.charAt(0)){ first=true ; } if(first && second){ break ; } } if(first && second){ System.out.println("YES"); } else { System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class _868A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.nextLine() ; var t : int ; t := sc.getCurrent()->toInteger() ; var first : boolean ; first := false ; var second : boolean ; second := false ; skip ; while (t /= 0) do ( skip ; ( var v : String ; v := sc.nextLine() ; if (v = s) then ( first := true ; second := true ) else skip ; if (v->at(0+1) = s->at(1+1)) then ( second := true ) else skip ; if (v->at(1+1) = s->at(0+1)) then ( first := true ) else skip ; if (first & second) then ( break ) else skip ; ) ; ) ; if (first & second) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package gcj; import java.util.*; import java.io.*; public class Swinging { final static String PROBLEM_NAME = "swing"; final static String WORK_DIR = "D:\\Gcj\\" + PROBLEM_NAME + "\\"; static void preprocess() {} void solve(Scanner sc, PrintWriter pw) { int N = sc.nextInt(); int[] dist = new int[N]; int[] len = new int[N]; for (int i = 0; i < N; i++) { dist[i] = sc.nextInt(); len[i] = sc.nextInt(); } int D = sc.nextInt(); int[] maxH = new int[N]; Arrays.fill(maxH, -1); maxH[0] = dist[0]; for (int i = 0; i < N; i++) { if (maxH[i] == -1) continue; if (D - dist[i] <= maxH[i]) { pw.println("YES"); return; } for (int j = i + 1; j < N; j++) { if (dist[j] - dist[i] <= maxH[i]) { maxH[j] = Math.max(maxH[j], Math.min(len[j], dist[j] - dist[i])); } } } pw.println("NO"); } public static void main(String[] args) throws Exception { preprocess(); Scanner sc = new Scanner(new FileReader(WORK_DIR + "input.txt")); PrintWriter pw = new PrintWriter(new FileWriter(WORK_DIR + "output.txt")); int caseCnt = sc.nextInt(); for (int caseNum = 0; caseNum < caseCnt; caseNum++) { System.out.println("Processing test case " + (caseNum + 1)); pw.print("Case #" + (caseNum + 1) + ": "); new Swinging().solve(sc, pw); } pw.flush(); pw.close(); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Swinging { static attribute PROBLEM_NAME : String := "swing"; static attribute WORK_DIR : String := "D:\\Gcj\\" + PROBLEM_NAME + "\\"; static operation preprocess() : void pre: true post: true activity: skip; operation solve( sc : OclFile, pw : OclFile) : void pre: true post: true activity: ( var N : int ; N := sc.nextInt() ; var dist : Sequence(int) ; dist := Integer.subrange(1,N)->collect(0) ; var len : Sequence(int) ; len := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( dist[i+1] := sc.nextInt() ; len[i+1] := sc.nextInt() ) ; i := i + 1 ) ; var D : int ; D := sc.nextInt() ; var maxH : Sequence(int) ; maxH := Integer.subrange(1,N)->collect(0) ; maxH := maxH->collect(-1) ; maxH[0+1] := dist[0+1] ; var i : int ; i := 0 ; while i < N do ( ( if (maxH[i+1] = -1) then continue else skip ; if (D - dist[i+1] <= maxH[i+1]) then ( pw.println("YES") ; return ) else skip ; var j : int ; j := i + 1 ; while j < N do ( ( if (dist[j+1] - dist[i+1] <= maxH[i+1]) then ( maxH[j+1] := Set{maxH[j+1], Set{len[j+1], dist[j+1] - dist[i+1]}->min()}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; pw.println("NO") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute preprocess() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(WORK_DIR + "input.txt")) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(WORK_DIR + "output.txt")) ; var caseCnt : int ; caseCnt := sc.getCurrent()->toInteger() ; var caseNum : int ; caseNum := 0 ; while caseNum < caseCnt do ( ( OclFile["System.out"].println("Processing test case " + (caseNum + 1)) ; skip ; Swinging.newSwinging().solve(sc, pw) ) ; caseNum := caseNum + 1 ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class BarkToUnlock { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String one=scan.next(); int n=scan.nextInt(); String bark[]=new String[n]; String rev[]=new String[n]; String all="" ; int count=0 ; int countt=0 ; int counttt=0 ; for(int i=0 ; i=1 && counttt>=1)System.out.println("YES"); else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class BarkToUnlock { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var one : String ; one := scan.getCurrent() ; var n : int ; n := scan.getCurrent()->toInteger() ; var bark : Sequence(String) ; bark := Integer.subrange(1,n)->collect(null) ; var rev : Sequence(String) ; rev := Integer.subrange(1,n)->collect(null) ; var all : String ; all := "" ; var count : int ; count := 0 ; var countt : int ; countt := 0 ; var counttt : int ; counttt := 0 ; var i : int ; i := 0 ; while i < bark->size() do ( ( bark[i+1] := scan.getCurrent() ; rev[i+1] := "" + bark[i+1]->at(1+1) + bark[i+1]->at(0+1) ; if (one->at(0+1) = bark[i+1]->at(1+1)) then ( countt := countt + 1 ) else skip ; if (one->at(1+1) = bark[i+1]->at(0+1)) then ( counttt := counttt + 1 ) else skip ; if (bark[i+1] = one) then ( count := count + 1 ; OclFile["System.out"].println("YES") ; break ) else if (rev[i+1] = one) then ( count := count + 1 ; OclFile["System.out"].println("YES") ; break ) else skip ; ; ) ; i := i + 1 ) ; var i : int ; if (count = 0) then ( if (countt >= 1 & counttt >= 1) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Main m=new Main(); m.run(); } Scanner sc=new Scanner(System.in); void run(){ int n=sc.nextInt(); if(n==1){ System.out.println("Hello World"); } else { int a=sc.nextInt(); int b=sc.nextInt(); System.out.println(a+b); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run() ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 1) then ( OclFile["System.out"].println("Hello World") ) else ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(a + b) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; import java.util.stream.Collectors ; public class A868 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String answer=scanner.nextLine(); int inputCount=Integer.parseInt(scanner.nextLine()); ArrayListinput=new ArrayList<>(); for(int i=0 ; itoInteger() ; var input : Sequence(String) ; input := Sequence{} ; var i : int ; i := 0 ; while i < inputCount do ( ( input := input->including(scanner.nextLine()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < inputCount do ( ( var j : int ; j := 0 ; while j < inputCount do ( ( var tempString : String ; tempString := input->at(i+1) + input->at(j+1) ; if (tempString->includes(answer)) then ( OclFile["System.out"].println("YES") ; return ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; FastReader in=new FastReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskB solver=new TaskB(); solver.solve(1,in,out); out.close(); } static class TaskB { public void solve(int testNumber,FastReader in,PrintWriter out){ int n=in.nextInt(); boolean ans=true ; int c=0 ; int count=0 ; for(int i=0 ; i<=n ; i++){ if(ipow(20)))->oclAsType(long)) ); operation next() : String pre: true post: true activity: ( while (token = null or not(token.hasNext())) do ( try ( token := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return token.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Test { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int i,count=0,temp ; for(i=0 ; itoInteger() ; var i : int ; var count : int ; count := 0 ; var temp : int ; i := 0 ; while i < n do ( ( temp := scan.getCurrent()->toInteger() ; if (temp mod 2 /= 0) then ( if (count = 0) then count := 1 ; else count := 0 ; ) else if (temp = 0) then ( if (count = 1) then break else skip ) else skip ; ) ; i := i + 1 ) ; if (count = 0) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public final class Solution { static int[] arr ; public static void main(String[] args){ Reader input=new Reader(); PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); int n=input.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] < 0) then ( skip ; skip ; return ) else skip ; arr[i+1] := arr[i+1] mod 2 ; if (arr[i+1] = 0) then continue else ( if (i + 1 = n) then ( skip ; skip ; return ) else arr[i + 1+1] := arr[i + 1+1] - 1 ; ) ) ; i := i + 1 ) ; skip ; skip ; ); static class Reader { attribute br : OclFile; attribute st : OclIterator; static operation newReader() : Reader pre: true post: true activity: ( var self : Reader ; self := createReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( try ( if (st = null or not(st.hasNext())) then st := OclIterator.newOclIterator_String(br.readLine()) ; else skip ) catch (ex : IOException) do ( ex.printStackTrace() ; OclProcess.exit(1) ) return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (ex : IOException) do ( ex.printStackTrace() ; OclProcess.exit(1) ) return "" ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String s=scan.nextLine(); int n=scan.nextInt(); minCount(s,n); } public static void minCount(String s,int n){ int len=s.length(); if(n>=len){ StringBuilder sb=new StringBuilder(s); while(lenn){ System.out.println(-1); return ; } int L=1 ; int R=max ; while(L<=R){ int M=(L+R)>>1 ; if(check(map,n,M)){ R=M-1 ; } else { L=M+1 ; } } StringBuilder sb=new StringBuilder(); for(int i=0 ; i<26 ; i++){ char c=(char)('a'+i); int need=(map[i]+L-1)/L ; for(int j=0 ; jtoInteger() ; execute minCount(s, n) ); static operation minCount( s : String, n : int) : void pre: true post: true activity: ( var len : int ; len := s->size() ; if (n >= len) then ( var sb : String ; sb := StringLib.newString(s) ; while (len < n) do ( sb := sb + StringLib.newString("a") ; len := len + 1 ) ; OclFile["System.out"].println(1) ; OclFile["System.out"].println(sb) ; return ) else skip ; var max : int ; max := 0 ; var kind : int ; kind := 0 ; var map : Sequence(int) ; map := Integer.subrange(1,26)->collect(0) ; for (c : s->characters()) do ( ( var idx : int ; idx := c - ('a')->char2byte() ; map[idx+1] := map[idx+1] + 1 ; if (map[idx+1] = 1) then ( kind := kind + 1 ) else skip ; max := Set{max, map[idx+1]}->max() ) ) ; if (kind > n) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var L : int ; L := 1 ; var R : int ; R := max ; while (L <= R) do ( var M : int ; M := ((L + R)/(2->pow(1)))->oclAsType(long) ; if (check(map, n, M)) then ( R := M - 1 ) else ( L := M + 1 ) ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < 26 do ( ( var c : String ; c := ('a' + i)->oclAsType(String) ; var need : int ; need := (map[i+1] + L - 1) / L ; var j : int ; j := 0 ; while j < need do ( ( sb := sb + StringLib.newString(c) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var size : int ; size := sb->size() ; while (size < n) do ( size := size + 1 ; skip ; ( sb := sb + StringLib.newString("a") ) ; ) ; OclFile["System.out"].println(L) ; OclFile["System.out"].println(sb) ; ); static operation check( map : Sequence(int), N : int, limit : int) : boolean pre: true post: true activity: ( var count : int ; count := 0 ; for (num : map) do ( ( count := count+((num + limit - 1) / limit) ) ) ; return count <= N ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Banana { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine(); int n=Integer.parseInt(br.readLine()); int occ[]=new int[26]; int distinctChars=0 ; for(int i=0 ; in){ System.out.println(-1); return ; } int noOfSheets=1 ; while(true){ int nNeeded=0 ; for(int i=0 ; i<26 ; i++){ nNeeded+=Math.ceil(occ[i]*1.0/noOfSheets); } if(nNeeded<=n){ StringBuilder sb=new StringBuilder(); for(int i=0 ; i<26 ; i++){ int occInSticker=(int)Math.ceil(occ[i]*1.0/noOfSheets); char c=(char)('a'+i); for(int j=0 ; jtoInteger() ; var occ : Sequence(int) ; occ := Integer.subrange(1,26)->collect(0) ; var distinctChars : int ; distinctChars := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( var c : int ; c := s->at(i+1) - ('a')->char2byte() ; occ[c+1] := occ[c+1] + 1 ; if (occ[c+1] = 1) then distinctChars := distinctChars + 1 ; else skip ) ; i := i + 1 ) ; if (distinctChars > n) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var noOfSheets : int ; noOfSheets := 1 ; while (true) do ( var nNeeded : int ; nNeeded := 0 ; var i : int ; i := 0 ; while i < 26 do ( ( nNeeded := nNeeded+((occ[i+1] * 1.0 / noOfSheets)->ceil()) ) ; i := i + 1 ) ; if (nNeeded <= n) then ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < 26 do ( ( var occInSticker : int ; occInSticker := (occ[i+1] * 1.0 / noOfSheets)->ceil()->oclAsType(int) ; var c : String ; c := ('a' + i)->oclAsType(String) ; var j : int ; j := 0 ; while j < occInSticker do ( ( sb := sb + StringLib.newString(c) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := sb->size() ; while i < n do ( ( sb := sb + StringLib.newString('a') ) ; i := i + 1 ) ; OclFile["System.out"].println(noOfSheets) ; OclFile["System.out"].println(sb) ; return ) else skip ; noOfSheets := noOfSheets + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A335 { public static void main(String[] args){ Scanner in=new Scanner(System.in); char[] S=in.next().toCharArray(); int N=in.nextInt(); int[] stat=new int[26]; for(char c : S){ stat[c-'a']++; } int letters=0 ; for(int count : stat){ if(count!=0){ letters++; } } if(letters>N){ System.out.println("-1"); return ; } int low=1 ; int high=S.length ; while(lowN){ low=mid+1 ; } else { high=mid ; } } StringBuilder sb=new StringBuilder(); for(int i=0 ; i<26 ; i++){ char c=(char)('a'+i); for(int j=0 ; j<(stat[i]+low-1)/low ; j++){ sb.append(c); } } while(sb.length()characters() ; var N : int ; N := in.getCurrent()->toInteger() ; var stat : Sequence(int) ; stat := Integer.subrange(1,26)->collect(0) ; for (c : S) do ( ( stat[c - ('a')->char2byte()+1] := stat[c - ('a')->char2byte()+1] + 1 ) ) ; var letters : int ; letters := 0 ; for (count : stat) do ( ( if (count /= 0) then ( letters := letters + 1 ) else skip ) ) ; if (letters > N) then ( OclFile["System.out"].println("-1") ; return ) else skip ; var low : int ; low := 1 ; var high : int ; high := S->size() ; while (low < high) do ( var mid : int ; mid := (low + high) / 2 ; var onSheet : int ; onSheet := 0 ; for (count : stat) do ( ( onSheet := onSheet+((count + mid - 1) / mid) ) ) ; if (onSheet > N) then ( low := mid + 1 ) else ( high := mid ) ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < 26 do ( ( var c : String ; c := ('a' + i)->oclAsType(String) ; var j : int ; j := 0 ; while j < (stat[i+1] + low - 1) / low do ( ( sb := sb + StringLib.newString(c) ) ; j := j + 1 ) ) ; i := i + 1 ) ; while (sb->size() < N) do ( sb := sb + StringLib.newString('x') ) ; OclFile["System.out"].println(low) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isOperand(char x){ return(x>='a' && x<='z')||(x>='A' && x<='Z'); } static String getInfix(String exp){ Stacks=new Stack(); for(int i=0 ; i= 'a' & x <= 'z') or (x >= 'A' & x <= 'Z') ); static operation getInfix( exp : String) : String pre: true post: true activity: ( var s : Sequence(String) ; s := Sequence{} ; var i : int ; i := 0 ; while i < exp->size() do ( ( if (isOperand(exp->at(i+1))) then ( s := s->append(exp->at(i+1) + "") ) else ( var op1 : String ; op1 := s->min() ; s := s->front() ; var op2 : String ; op2 := s->min() ; s := s->front() ; s := s->append("(" + op2 + exp->at(i+1) + op1 + ")") ; ) ) ; i := i + 1 ) ; return s->min() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var exp : String ; exp := "ab*c+" ; OclFile["System.out"].println(getInfix(exp)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String a=sc.next(); if(a.equals("SUN")){ System.out.print("7"); } if(a.equals("MON")){ System.out.print("6"); } if(a.equals("TUE")){ System.out.print("5"); } if(a.equals("WED")){ System.out.print("4"); } if(a.equals("THU")){ System.out.print("3"); } if(a.equals("FRI")){ System.out.print("2"); } if(a.equals("SAT")){ System.out.print("1"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : String ; a := sc.getCurrent() ; if (a = "SUN") then ( OclFile["System.out"].print("7") ) else skip ; if (a = "MON") then ( OclFile["System.out"].print("6") ) else skip ; if (a = "TUE") then ( OclFile["System.out"].print("5") ) else skip ; if (a = "WED") then ( OclFile["System.out"].print("4") ) else skip ; if (a = "THU") then ( OclFile["System.out"].print("3") ) else skip ; if (a = "FRI") then ( OclFile["System.out"].print("2") ) else skip ; if (a = "SAT") then ( OclFile["System.out"].print("1") ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.Scanner ; public class A { public static void main(String[] args)throws FileNotFoundException { Scanner in=new Scanner(new File(A.class.getSimpleName()+".in")); PrintWriter out=new PrintWriter(new File(A.class.getSimpleName()+".out")); int T=in.nextInt(); for(int i=0 ; i0 ? "YES" : "NO" ; } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile(OclType["A"].getSimpleName() + ".in")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile(OclType["A"].getSimpleName() + ".out")) ; var T : int ; T := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < T do ( ( var s : String ; s := "Case #" + (i + 1) + ": " + A.newA().solve(in) ; skip ; OclFile["System.out"].println(s) ) ; i := i + 1 ) ; skip ; ); operation solve( in : OclFile) : String pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var d : Sequence(int) ; d := Integer.subrange(1,n + 1)->collect(0) ; var l : Sequence(int) ; l := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( d[i+1] := in.getCurrent()->toInteger() ; l[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; d[n+1] := in.getCurrent()->toInteger() ; var z : Sequence(int) ; z := Integer.subrange(1,n + 1)->collect(0) ; z[0+1] := d[0+1] ; var i : int ; i := 0 ; while i < n do ( ( z[i+1] := Set{z[i+1], l[i+1]}->min() ; var j : int ; j := i + 1 ; while j <= n do ( ( if (d[j+1] <= d[i+1] + z[i+1]) then ( z[j+1] := Set{z[j+1], d[j+1] - d[i+1]}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return if z[n+1] > 0 then "YES" else "NO" endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class MikeAndChildren { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; skip ; skip ; ); static operation solve( a : Sequence(int), n : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var max : int ; max := -2147483648 ; for (i : a) do ( ( max := Set{max, i}->max() ) ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,max * 2 + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var sum : int ; sum := a[i+1] + a[j+1] ; dp[sum+1] := dp[sum+1] + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; for (i : dp) do ( ans := Set{i, ans}->max() ; ) ; return ans ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); HashMapmap=new HashMap<>(); for(int i=0 ; ipast=new HashMap<>(); String next="" ; for(int i=0 ; itoInteger() ; var map : Map(int,String) ; map := Map{} ; var i : int ; i := 0 ; while i < N do ( ( map := map->union(Map{i |-> sc.getCurrent()}) ) ; i := i + 1 ) ; var ans : boolean ; ans := true ; var past : Map(int,String) ; past := Map{} ; var next : String ; next := "" ; var i : int ; i := 0 ; while i < N do ( ( if (past->values()->includes(map->at(i))) then ( ans := false ; break ) else skip ; past := past->union(Map{i |-> map->at(i)}) ; if (i /= 0) then ( if (not(next = map->at(i).subrange(0+1,1))) then ( ans := false ; break ) else skip ) else skip ; next := map->at(i).subrange(map->at(i)->size() - 1+1,map->at(i)->size()) ) ; i := i + 1 ) ; if (ans) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.util.stream.*; public class Main { private static BufferedReader br=null ; public static void main(String[] args){ int n=Integer.parseInt(read(1)[0]); if(n==1){ System.out.println("Hello World"); } else { String[] strs=read(2); System.out.println(Integer.parseInt(strs[0])+Integer.parseInt(strs[1])); } } private static String[] read(int len){ ListstrList=new ArrayList<>(); try { if(br==null){ br=new BufferedReader(new InputStreamReader(System.in)); } for(int i=0 ; itoInteger() ; if (n = 1) then ( OclFile["System.out"].println("Hello World") ) else ( var strs : Sequence(String) ; strs := read(2) ; OclFile["System.out"].println((strs[0+1])->toInteger() + (strs[1+1])->toInteger()) ) ); static operation read( len : int) : Sequence(String) pre: true post: true activity: ( var strList : Sequence(String) ; strList := Sequence{} ; try ( if (br = null) then ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) else skip ; var i : int ; i := 0 ; while i < len do ( ( strList := strList->including(br.readLine()) ) ; i := i + 1 ) ) catch (e : IOException) do skip return strList->asSequence() ); static operation close() : void pre: true post: true activity: ( try ( if (br /= null) then ( skip ) else skip ) catch (e : IOException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ String in=br.readLine(); String[] day={ "SAT","FRI","THU","WED","TUE","MON","SUN" }; for(int i=0 ; isize() do ( ( if (in = day[i+1]) then ( OclFile["System.out"].println(i + 1) ; break ) else skip ) ; i := i + 1 ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Main main=new Main(); main.solve(); } public void solve(){ Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in))); String s=scan.next(); HashMapmap=new HashMap<>(); map.put("SUN",7); map.put("MON",6); map.put("TUE",5); map.put("WED",4); map.put("THU",3); map.put("FRI",2); map.put("SAT",1); System.out.println(map.get(s)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.solve() ); operation solve() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var s : String ; s := scan.getCurrent() ; var map : Map(String,int) ; map := Map{} ; map := map->union(Map{"SUN" |-> 7}) ; map := map->union(Map{"MON" |-> 6}) ; map := map->union(Map{"TUE" |-> 5}) ; map := map->union(Map{"WED" |-> 4}) ; map := map->union(Map{"THU" |-> 3}) ; map := map->union(Map{"FRI" |-> 2}) ; map := map->union(Map{"SAT" |-> 1}) ; OclFile["System.out"].println(map->at(s)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static String[] days={ "SUN","SAT","FRI","THU","WED","TUE","MON" }; public static void main(String[] args){ Scanner sc=new Scanner(System.in); String day=sc.next(); for(int i=0 ; isize() do ( ( if (day = days[i+1]) then ( OclFile["System.out"].println(if i = 0 then 7 else i endif) ) else skip ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); String dow=sc.next(); ArrayListweek=new ArrayList<>(Arrays.asList("SUN","MON","TUE","WED","THU","FRI","SAT")); int result=7-week.indexOf(dow); System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var dow : String ; dow := sc.getCurrent() ; var week : Sequence(String) ; week := Sequence{}->union(Sequence{"SUN","MON","TUE","WED","THU","FRI","SAT"}) ; var result : int ; result := 7 - week->indexOf(dow)-1 ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String prevNum(String str){ int len=str.length(); int index=-1 ; for(int i=len-2 ; i>=0 ; i--){ if(str.charAt(i)>str.charAt(i+1)){ index=i ; break ; } } int smallGreatDgt=-1 ; for(int i=len-1 ; i>index ; i--){ if(str.charAt(i)=str.charAt(smallGreatDgt)){ smallGreatDgt=i ; } } } if(index==-1){ return "-1" ; } if(smallGreatDgt!=-1){ str=swap(str,index,smallGreatDgt); return str ; } return "-1" ; } static String swap(String str,int i,int j){ char ch[]=str.toCharArray(); char temp=ch[i]; ch[i]=ch[j]; ch[j]=temp ; return String.valueOf(ch); } public static void main(String[] args){ String str="34125" ; System.out.println(prevNum(str)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation prevNum( str : String) : String pre: true post: true activity: ( var len : int ; len := str->size() ; var index : int ; index := -1 ; var i : int ; i := len - 2 ; while i >= 0 do ( ( if (str->at(i+1) > str->at(i + 1+1)) then ( index := i ; break ) else skip ) ; i := i - 1 ) ; var smallGreatDgt : int ; smallGreatDgt := -1 ; var i : int ; i := len - 1 ; while i > index do ( ( if (str->at(i+1) < str->at(index+1)) then ( if (smallGreatDgt = -1) then ( smallGreatDgt := i ) else if (str->at(i+1) >= str->at(smallGreatDgt+1)) then ( smallGreatDgt := i ) else skip ; ) else skip ) ; i := i - 1 ) ; if (index = -1) then ( return "-1" ) else skip ; if (smallGreatDgt /= -1) then ( str := swap(str, index, smallGreatDgt) ; return str ) else skip ; return "-1" ); static operation swap( str : String, i : int, j : int) : String pre: true post: true activity: ( var ch : Sequence(String) ; ch := str->characters() ; var temp : String ; temp := ch[i+1] ; ch[i+1] := ch[j+1] ; ch[j+1] := temp ; return ((ch) + "") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "34125" ; OclFile["System.out"].println(prevNum(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isOperand(char c){ return(c>='0' && c<='9'); } static int value(char c){ return(int)(c-'0'); } static int evaluate(String exp){ if(exp.length()==0)return-1 ; int res=value(exp.charAt(0)); for(int i=1 ; i= '0' & c <= '9') ); static operation value( c : String) : int pre: true post: true activity: ( return (c - ('0')->char2byte())->oclAsType(int) ); static operation evaluate( exp : String) : int pre: true post: true activity: ( if (exp->size() = 0) then return -1 else skip ; var res : int ; res := value(exp->at(0+1)) ; var i : int ; i := 1 ; while i < exp->size() do ( ( var opr : String ; opr := exp->at(i+1) ; var opd : String ; opd := exp->at(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)) else if (opr = '*') then res := res*(value(opd)) else if (opr = '/') then res := res/(value(opd)) else return -1 ; ; ; ) ; i := i+(2) ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var expr1 : String ; expr1 := "1+2*5+3" ; var res : int ; res := evaluate(expr1) ; if (res = -1) then OclFile["System.out"].println(expr1 + " is Invalid") else OclFile["System.out"].println("Value of " + expr1 + " is " + res) ; ; var expr2 : String ; expr2 := "1+2*3" ; res := evaluate(expr2) ; if (res = -1) then OclFile["System.out"].println(expr2 + " is Invalid") else OclFile["System.out"].println("Value of " + expr2 + " is " + res) ; ; var expr3 : String ; expr3 := "4-2+6*3" ; res := evaluate(expr3) ; if (res = -1) then OclFile["System.out"].println(expr3 + " is Invalid") else OclFile["System.out"].println("Value of " + expr3 + " is " + res) ; ; var expr4 : String ; expr4 := "1++2" ; res := evaluate(expr4) ; if (res = -1) then OclFile["System.out"].println(expr4 + " is Invalid") else OclFile["System.out"].println("Value of " + expr4 + " is " + res) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class D { public static void main(String[] args)throws Exception { Scanner in=new Scanner(new File("D-large.in")); PrintWriter out=new PrintWriter(new FileWriter(new File("D-large.out"))); int t=in.nextInt(); for(int x=0 ; xtoInteger() ; var x : int ; x := 0 ; while x < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var naomi : Sequence(double) ; naomi := Integer.subrange(1,n)->collect(0.0) ; var y : int ; y := 0 ; while y < n do ( ( naomi[y+1] := in.getCurrent()->toReal() ) ; y := y + 1 ) ; var ken : Sequence(double) ; ken := Integer.subrange(1,n)->collect(0.0) ; var z : int ; z := 0 ; while z < n do ( ( ken[z+1] := in.getCurrent()->toReal() ) ; z := z + 1 ) ; naomi := naomi->sort() ; ken := ken->sort() ; var index : int ; index := 0 ; var win1 : int ; win1 := 0 ; var a : int ; a := 0 ; while a < ken->size() do ( ( while (index < n & naomi[index+1] < ken[a+1]) do ( index := index + 1 ) ; if (index < n) then ( win1 := win1 + 1 ; index := index + 1 ) else skip ) ; a := a + 1 ) ; index := 0 ; var win2 : int ; win2 := 0 ; var b : int ; b := 0 ; while b < naomi->size() do ( ( while (index < n & ken[index+1] < naomi[b+1]) do ( index := index + 1 ; win2 := win2 + 1 ) ; index := index + 1 ) ; b := b + 1 ) ; skip ; ) ; x := x + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedWriter ; import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.util.Scanner ; public class War { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(new FileReader("jam.in")); BufferedWriter bw=new BufferedWriter(new FileWriter("jam.out")); int cases ; cases=sc.nextInt(); for(int z=1 ; z<=cases ; z++){ int n=sc.nextInt(); double[] nami=new double[n]; double[] ken=new double[n]; int i,j ; for(i=0 ; inami[j]){ t=nami[i]; nami[i]=nami[j]; nami[j]=t ; } if(ken[i]>ken[j]){ t=ken[i]; ken[i]=ken[j]; ken[j]=t ; } } int q1=0 ; int q2=n-1 ; int ans1=0 ; for(i=0 ; iken[q1]){ ans1++; q1++; } else { q2--; } int ans2=0 ; q1=0 ; for(i=0 ; itoInteger() ; var z : int ; z := 1 ; while z <= cases do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var nami : Sequence(double) ; nami := Integer.subrange(1,n)->collect(0.0) ; var ken : Sequence(double) ; ken := Integer.subrange(1,n)->collect(0.0) ; var i : int ; var j : int ; i := 0 ; while i < n do ( nami[i+1] := sc.getCurrent()->toReal() ; ; i := i + 1 ) ; i := 0 ; while i < n do ( ken[i+1] := sc.getCurrent()->toReal() ; ; i := i + 1 ) ; i := 0 ; while i < n do ( j := i + 1 ; while j < n do ( ( var t : double ; if (nami[i+1] > nami[j+1]) then ( t := nami[i+1] ; nami[i+1] := nami[j+1] ; nami[j+1] := t ) else skip ; if (ken[i+1] > ken[j+1]) then ( t := ken[i+1] ; ken[i+1] := ken[j+1] ; ken[j+1] := t ) else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; var q1 : int ; q1 := 0 ; var q2 : int ; q2 := n - 1 ; var ans1 : int ; ans1 := 0 ; i := 0 ; while i < n do ( if (nami[i+1] > ken[q1+1]) then ( ans1 := ans1 + 1 ; q1 := q1 + 1 ) else ( q2 := q2 - 1 ) ; ; i := i + 1 ) ; var ans2 : int ; ans2 := 0 ; q1 := 0 ; i := 0 ; while i < n do ( ( while (q1 < n & ken[q1+1] < nami[i+1]) do q1 := q1 + 1 ; ; if (q1 = n) then break else skip ; ans2 := ans2 + 1 ; q1 := q1 + 1 ) ; i := i + 1 ) ; skip ; skip ; ) ; z := z + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedWriter ; import java.io.File ; import java.io.FileWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Exe4 { public static void main(String[] args)throws Exception { Scanner input=new Scanner(new File("input")); BufferedWriter output=new BufferedWriter(new FileWriter(new File("output"))); int T=input.nextInt(); for(int i=0 ; iKen[k]){ k++; } if(ktoInteger() ; var i : int ; i := 0 ; while i < T do ( ( var N : int ; N := input.getCurrent()->toInteger() ; var Noemi : Sequence(double) ; Noemi := Integer.subrange(1,N)->collect(0.0) ; var Ken : Sequence(double) ; Ken := Integer.subrange(1,N)->collect(0.0) ; var j : int ; j := 0 ; while j < N do ( ( Noemi[j+1] := input.getCurrent()->toReal() ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < N do ( ( Ken[j+1] := input.getCurrent()->toReal() ) ; j := j + 1 ) ; Noemi := Noemi->sort() ; Ken := Ken->sort() ; var ans1 : int ; ans1 := 0 ; var ans2 : int ; ans2 := 0 ; var k : int ; var j : int ; k := 0 ; j := 0 ; while (k < N) do ( while (k < N & Noemi[j+1] > Ken[k+1]) do ( k := k + 1 ) ; if (k < N) then ( j := j + 1 ; k := k + 1 ) else skip ) ; ans1 := N - j ; k := 0 ; j := 0 ; while (j < N) do ( while (j < N & Noemi[j+1] < Ken[k+1]) do ( j := j + 1 ) ; if (j < N) then ( j := j + 1 ; k := k + 1 ) else skip ) ; ans2 := k ; skip ; skip ; skip ; ) ; i := i + 1 ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class D { public static void main(String[] args){ Scanner in=new Scanner(System.in); int inputs=in.nextInt(); for(int caseNum=1 ; caseNum<=inputs ; caseNum++){ int blocks=in.nextInt(); double[] naomi=new double[blocks]; double[] ken=new double[blocks]; for(int i=0 ; iken[j]){ i++; j++; cheat++; } else { i++; } } System.out.printf("Case #%d: %d %d\n",caseNum,cheat,normal); } } } ------------------------------------------------------------ OCL File: --------- class D { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var inputs : int ; inputs := in.getCurrent()->toInteger() ; var caseNum : int ; caseNum := 1 ; while caseNum <= inputs do ( ( var blocks : int ; blocks := in.getCurrent()->toInteger() ; var naomi : Sequence(double) ; naomi := Integer.subrange(1,blocks)->collect(0.0) ; var ken : Sequence(double) ; ken := Integer.subrange(1,blocks)->collect(0.0) ; var i : int ; i := 0 ; while i < blocks do ( ( naomi[i+1] := in.getCurrent()->toReal() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < blocks do ( ( ken[i+1] := in.getCurrent()->toReal() ) ; i := i + 1 ) ; ken := ken->sort() ; naomi := naomi->sort() ; var normal : int ; normal := 0 ; var i : int ; i := 0 ; var j : int ; j := 0 ; while (i < blocks & j < blocks) do ( if (naomi[i+1] < ken[j+1]) then ( i := i + 1 ; j := j + 1 ; normal := normal + 1 ) else ( j := j + 1 ) ) ; normal := blocks - normal ; var cheat : int ; cheat := 0 ; i := 0 ; j := 0 ; while (i < blocks & j < blocks) do ( if (naomi[i+1] > ken[j+1]) then ( i := i + 1 ; j := j + 1 ; cheat := cheat + 1 ) else ( i := i + 1 ) ) ; OclFile["System.out"].printf("Case #%d: %d %d\n", caseNum, cheat, normal) ; ) ; caseNum := caseNum + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.util.*; import java.io.*; import java.lang.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); if(a==1)System.out.println("Hello World"); else if(a==2){ int b=sc.nextInt(); int c=sc.nextInt(); System.out.println(b+c); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; if (a = 1) then OclFile["System.out"].println("Hello World") ; else if (a = 2) then ( var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(b + c) ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileInputStream ; import java.io.FileOutputStream ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.Scanner ; public class A { Scanner in ; PrintWriter out ; void doit(int tnum){ int n=in.nextInt(); long[] d=new long[n]; long[] l=new long[n]; for(int i=0 ; itoInteger() ; var d : Sequence(long) ; d := Integer.subrange(1,n)->collect(0) ; var l : Sequence(long) ; l := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( d[i+1] := in.getCurrent()->toLong() ; l[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; var D : long ; D := in.getCurrent()->toLong() ; var ans : Sequence(long) ; ans := Integer.subrange(1,n)->collect(0) ; ans[0+1] := d[0+1] ; var ok : boolean ; ok := false ; var i : int ; i := 1 ; while i < n do ( ans[i+1] := -1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (D - d[i+1] <= ans[i+1]) then ok := true ; else skip ; var j : int ; j := i + 1 ; while j < n do ( ( if ((d[j+1] - d[i+1]) <= ans[i+1]) then ( var attempt : long ; attempt := Set{l[j+1], d[j+1] - d[i+1]}->min() ; if (ans[j+1] = -1) then ans[j+1] := attempt ; else skip ; if (ans[j+1] < attempt) then ans[j+1] := attempt ; else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; OclFile["System.err"].println("Case #" + tnum + ": " + (if ok then "YES" else "NO" endif)) ; ); operation doit() : void pre: true post: true activity: ( out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("A-large.in"))) ; var T : int ; T := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < T do ( ( execute doit(i + 1) ) ; i := i + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A.newA().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class d { public static void main(String[] args){ Scanner input=new Scanner(System.in); int T=input.nextInt(); for(int t=0 ; tsecond=new TreeSet(); for(int i=0 ; ibs[i-elim])count++; } res1=Math.max(res1,count); } System.out.println(res1+" "+res2); } } } ------------------------------------------------------------ OCL File: --------- class d { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := input.getCurrent()->toInteger() ; var t : int ; t := 0 ; while t < T do ( ( OclFile["System.out"].printf("Case #%d: ", t + 1) ; var n : int ; n := input.getCurrent()->toInteger() ; var as : Sequence(double) ; as := Integer.subrange(1,n)->collect(0.0) ; var bs : Sequence(double) ; bs := Integer.subrange(1,n)->collect(0.0) ; var second : Set(double) ; second := Set{} ; var i : int ; i := 0 ; while i < n do ( as[i+1] := input.getCurrent()->toReal() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( bs[i+1] := input.getCurrent()->toReal() ; ; i := i + 1 ) ; for (d : bs) do ( second := second->including(d) ; ) ; as := as->sort() ; bs := bs->sort() ; var res1 : int ; res1 := 0 ; var res2 : int ; res2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( var cur : double ; cur := second.ceiling(as[i+1]) ; if (cur = null) then ( res2 := res2 + 1 ; second := second->excludingFirst(second->first()) ) else second := second->excludingFirst(cur) ; ) ; i := i + 1 ) ; res1 := 0 ; var elim : int ; elim := 0 ; while elim < n do ( ( var count : int ; count := 0 ; var i : int ; i := elim ; while i < n do ( ( if (as[i+1] > bs[i - elim+1]) then count := count + 1 ; else skip ) ; i := i + 1 ) ; res1 := Set{res1, count}->max() ) ; elim := elim + 1 ) ; OclFile["System.out"].println(res1 + " " + res2) ; ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int p=sc.nextInt(); String str=sc.next(); int[] s=new int[n]; for(int i=0 ; i=0 ; i--){ u[i]=(u[i+1]+s[i]*ten)% p ; ten=(ten*10)% p ; } for(int i=0 ; i<=n ; i++){ modCount[u[i] ]++; } long ans=0 ; if(p==2 || p==5){ for(int i=n-1 ; i>=0 ; i--){ if((s[i] % p)==0){ ans+=i+1 ; } } } else { for(int i=0 ; i

toInteger() ; var p : int ; p := sc.getCurrent()->toInteger() ; var str : String ; str := sc.getCurrent() ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := str->at(i+1) - ('0')->char2byte() ) ; i := i + 1 ) ; var u : Sequence(int) ; u := Integer.subrange(1,n + 1)->collect(0) ; var modCount : Sequence(long) ; modCount := Integer.subrange(1,p)->collect(0) ; var ten : int ; ten := 1 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( u[i+1] := (u[i + 1+1] + s[i+1] * ten) mod p ; ten := (ten * 10) mod p ) ; i := i - 1 ) ; var i : int ; i := 0 ; while i <= n do ( ( modCount[u[i+1]+1] := modCount[u[i+1]+1] + 1 ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; if (p = 2 or p = 5) then ( var i : int ; i := n - 1 ; while i >= 0 do ( ( if ((s[i+1] mod p) = 0) then ( ans := ans+(i + 1) ) else skip ) ; i := i - 1 ) ) else ( var i : int ; i := 0 ; while i < p do ( ( ans := ans+(modCount[i+1] * (modCount[i+1] - 1) / 2) ) ; i := i + 1 ) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long p=sc.nextInt(); public static void main(String[] args){ new Main().run(); } void run(){ char[] s=sc.next().toCharArray(); long ans=0 ; long sumMod=0 ; Mapmap=new HashMap<>(); if(p==2 || p==5){ for(int i=n-1 ; 0<=i ; i--){ if((s[i]-'0')% p==0)ans+=i+1 ; } System.out.println(ans); return ; } for(int i=n-1 ; 0<=i ; i--){ long tmp=s[i]-'0' ; tmp*=modPow(10,n-1-i); tmp %=p ; sumMod+=tmp ; sumMod %=p ; if(map.containsKey(sumMod)){ map.put(sumMod,map.get(sumMod)+(long)1); } else { map.put(sumMod,(long)1); } } for(Long t : map.values()){ ans+=t*(t-1)/2 ; } if(map.get((long)0)==null){ System.out.println(ans); } else { System.out.println(ans+map.get((long)0)); } } long modPow(long x,long n){ long sum=1 ; while(n>0){ if((n & 1)==1){ sum*=x ; sum %=p ; } x*=x ; x %=p ; n>>=1 ; } return sum % p ; } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute n : int := sc.getCurrent()->toInteger(); attribute p : long := sc.getCurrent()->toInteger(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var ans : long ; ans := 0 ; var sumMod : long ; sumMod := 0 ; var map : Map(long,long) ; map := Map{} ; if (p = 2 or p = 5) then ( var i : int ; i := n - 1 ; while 0 <= i do ( ( if ((s[i+1] - ('0')->char2byte()) mod p = 0) then ans := ans+(i + 1) ; else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; return ) else skip ; var i : int ; i := n - 1 ; while 0 <= i do ( ( var tmp : long ; tmp := s[i+1] - ('0')->char2byte() ; tmp := tmp*(modPow(10, n - 1 - i)) ; tmp := tmp mod p ; sumMod := sumMod+(tmp) ; sumMod := sumMod mod p ; if (map->keys()->includes(sumMod)) then ( map := map->union(Map{sumMod |-> map->at(sumMod) + 1->oclAsType(long)}) ) else ( map := map->union(Map{sumMod |-> 1->oclAsType(long)}) ) ; ) ; i := i - 1 ) ; for (t : map->values()) do ( ( ans := ans+(t * (t - 1) / 2) ) ) ; if (map->at(0->oclAsType(long)) = null) then ( OclFile["System.out"].println(ans) ) else ( OclFile["System.out"].println(ans + map->at(0->oclAsType(long))) ) ; ); operation modPow( x : long, n : long) : long pre: true post: true activity: ( var sum : long ; sum := 1 ; while (n > 0) do ( if ((MathLib.bitwiseAnd(n,1)) = 1) then ( sum := sum*(x) ; sum := sum mod p ) else skip ; x := x*(x) ; x := x mod p ; n := n/(2->pow(1)) ) ; return sum mod p ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Collections ; import java.util.HashMap ; import java.util.List ; import java.util.Map ; import java.util.Scanner ; import java.util.stream.Collectors ; import java.util.stream.IntStream ; public class Main { public static void main(final String[] args){ final Scanner scanner=new Scanner(System.in); final int n=scanner.nextInt(); final int p=scanner.nextInt(); final String s=scanner.next(); final Listlist=IntStream.range(0,n).mapToObj(i->s.charAt(i)-'0').collect(Collectors.toList()); long count=0 ; if(p==2 || p==5){ for(int i=0 ; icounter=new HashMap<>(); long base=1 ; long current=0 ; Collections.reverse(list); for(final int digit : list){ current=(current+digit*base)% p ; base=base*10 % p ; if(current % p==0){ count++; } if(counter.get(current)!=null){ count+=counter.get(current); } counter.compute(current,(k,v)->v==null ? 1 : v+1); } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var p : int ; p := scanner.getCurrent()->toInteger() ; var s : String ; s := scanner.getCurrent() ; var list : Sequence(int) ; list := Integer.subrange(0, n-1).mapToObj(lambda i : OclAny in s->at(i+1) - ('0')->char2byte()).collect(Collectors.toList()) ; var count : long ; count := 0 ; if (p = 2 or p = 5) then ( var i : int ; i := 0 ; while i < list->size() do ( ( var digit : int ; digit := list->at(i+1) ; if (digit mod p = 0) then ( count := count+(i + 1) ) else skip ) ; i := i + 1 ) ) else ( var counter : Map(long,long) ; counter := Map{} ; var base : long ; base := 1 ; var current : long ; current := 0 ; list := list->reverse() ; for (digit : list) do ( ( current := (current + digit * base) mod p ; base := base * 10 mod p ; if (current mod p = 0) then ( count := count + 1 ) else skip ; if (counter->at(current) /= null) then ( count := count+(counter->at(current)) ) else skip ; counter := counter.compute(current, lambda (k , v) : OclAny in if v = null then 1 else v + 1 endif) ; ) ) ; ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args)throws Exception { int N=sc.nextInt(); int P=sc.nextInt(); String S=sc.next(); int[] A=new int[N]; for(int i=0 ; i=0 ; i--){ if(A[i] % P==0){ c++; } ans+=c ; } } else { int m=0 ; int k=1 ; Mapcount=new HashMap<>(); count.put(0,1); for(int i=N-1 ; i>=0 ; i--){ m=(A[i]*k+m)% P ; Integer c=count.get(m); if(c==null){ c=1 ; } else { ans+=c ; c++; } count.put(m,c); k=(k*10)% P ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; var P : int ; P := sc.getCurrent()->toInteger() ; var S : String ; S := sc.getCurrent() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := S->at(i+1) - ('0')->char2byte() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; if (P = 2 or P = 5) then ( var c : int ; c := 0 ; var i : int ; i := N - 1 ; while i >= 0 do ( ( if (A[i+1] mod P = 0) then ( c := c + 1 ) else skip ; ans := ans+(c) ) ; i := i - 1 ) ) else ( var m : int ; m := 0 ; var k : int ; k := 1 ; var count : Map(int,int) ; count := Map{} ; count := count->union(Map{0 |-> 1}) ; var i : int ; i := N - 1 ; while i >= 0 do ( ( m := (A[i+1] * k + m) mod P ; var c : int ; c := count->at(m) ; if (c = null) then ( c := 1 ) else ( ans := ans+(c) ; c := c + 1 ) ; count := count->union(Map{m |-> c}) ; k := (k * 10) mod P ; ) ; i := i - 1 ) ; ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(),p=scanner.nextInt(); char[] s=scanner.next().toCharArray(); int[] s2=new int[n]; IntStream.range(0,n).forEach(i->s2[i]=s[i]-'0'); int[] m=new int[p]; long answer=0L ; if((2==p)||(5==p)){ answer=IntStream.range(0,n).mapToLong(i->(0==s2[i] % p)? i+1 : 0L).sum(); } else { int now=0 ; int digit=1 ; m[0]=1 ; for(int i=n-1 ; i>=0 ; i--){ now+=s2[i]*digit ; now %=p ; answer+=m[now]; m[now]++; digit*=10 ; digit %=p ; } } System.out.println(answer); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var p : int ; p := scanner.getCurrent()->toInteger() ; var s : Sequence(String) ; s := scanner.getCurrent()->characters() ; var s2 : Sequence(int) ; s2 := Integer.subrange(1,n)->collect(0) ; for i : Integer.subrange(0, n-1) do ( s2[i+1] := s[i+1] - ('0')->char2byte()) ; var m : Sequence(int) ; m := Integer.subrange(1,p)->collect(0) ; var answer : long ; answer := 0L ; if ((2 = p) or (5 = p)) then ( answer := Integer.subrange(0, n-1)->collect( _x1 | (lambda i : OclAny in if (0 = s2[i+1] mod p) then i + 1 else 0L endif)->apply(_x1) )->sum() ) else ( var now : int ; now := 0 ; var digit : int ; digit := 1 ; m[0+1] := 1 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( now := now+(s2[i+1] * digit) ; now := now mod p ; answer := answer+(m[now+1]) ; m[now+1] := m[now+1] + 1 ; digit := digit*(10) ; digit := digit mod p ; ) ; i := i - 1 ) ) ; OclFile["System.out"].println(answer) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static class Node { int data ; Node next ; } static boolean isCircular(Node head){ if(head==null)return true ; Node node=head.next ; while(node!=null && node!=head)node=node.next ; return(node==head); } static Node newNode(int data){ Node temp=new Node(); temp.data=data ; temp.next=null ; return temp ; } public static void main(String args[]){ Node head=newNode(1); head.next=newNode(2); head.next.next=newNode(3); head.next.next.next=newNode(4); System.out.print(isCircular(head)? "Yes\n" : "No\n"); head.next.next.next.next=head ; System.out.print(isCircular(head)? "Yes\n" : "No\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static class Node { attribute data : int; attribute next : Node; } static operation isCircular( head : Node) : boolean pre: true post: true activity: ( if (head = null) then return true else skip ; var node : Node ; node := head.next ; while (node /= null & node /= head) do node := node.next ; ; return (node = head) ); static operation newNode( data : int) : Node pre: true post: true activity: ( var temp : Node ; temp := Node.newNode() ; temp.data := data ; temp.next := null ; return temp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var head : Node ; head := newNode(1) ; head.next := newNode(2) ; head.next.next := newNode(3) ; head.next.next.next := newNode(4) ; OclFile["System.out"].print(if isCircular(head) then "Yes\n" else "No\n" endif) ; head.next.next.next.next := head ; OclFile["System.out"].print(if isCircular(head) then "Yes\n" else "No\n" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countOdd(int[] arr,int n){ int odd=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(countValidPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class PaymentWithChange { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long a=sc.nextLong(); long b=sc.nextLong(); long n=sc.nextLong(); long s=sc.nextLong(); if(s/n<=a && s % n<=b)System.out.println("YES"); else if(s/n>=a &&((((s/n-a)*n)+s % n)<=b))System.out.println("YES"); else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class PaymentWithChange { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var n : long ; n := sc.getCurrent()->toLong() ; var s : long ; s := sc.getCurrent()->toLong() ; if (s / n <= a & s mod n <= b) then OclFile["System.out"].println("YES") else if (s / n >= a & ((((s / n - a) * n) + s mod n) <= b)) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; public class Main { Scanner sc=new Scanner(System.in); void run(){ for(; ; ){ String buffer=sc.next(); if(buffer.equals("0")){ break ; } int p[]=new int[2]; int v=0 ; for(char ch : buffer.substring(1).toCharArray()){ v=ch-'A' ; p[v]++; } if(p[0]>p[1]){ p[0]++; } else { p[1]++; } System.out.println(p[0]+" "+p[1]); buffer=sc.next(); p=new int[2]; for(char ch : buffer.substring(1).toCharArray()){ v=ch-'A' ; p[v]++; } if(p[0]>p[1]){ p[0]++; } else { p[1]++; } System.out.println(p[0]+" "+p[1]); buffer=sc.next(); p=new int[2]; for(char ch : buffer.substring(1).toCharArray()){ v=ch-'A' ; p[v]++; } if(p[0]>p[1]){ p[0]++; } else { p[1]++; } System.out.println(p[0]+" "+p[1]); } } public static void main(String[] args){ Main m=new Main(); m.run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while true do ( ( var buffer : String ; buffer := sc.getCurrent() ; if (buffer = "0") then ( break ) else skip ; var p : Sequence(int) ; p := Integer.subrange(1,2)->collect(0) ; var v : int ; v := 0 ; for (ch : buffer.subrange(1+1,1)->characters()) do ( ( v := ch - ('A')->char2byte() ; p[v+1] := p[v+1] + 1 ) ) ; if (p[0+1] > p[1+1]) then ( p[0+1] := p[0+1] + 1 ) else ( p[1+1] := p[1+1] + 1 ) ; OclFile["System.out"].println(p[0+1] + " " + p[1+1]) ; buffer := sc.getCurrent() ; p := Integer.subrange(1,2)->collect(0) ; for (ch : buffer.subrange(1+1,1)->characters()) do ( ( v := ch - ('A')->char2byte() ; p[v+1] := p[v+1] + 1 ) ) ; if (p[0+1] > p[1+1]) then ( p[0+1] := p[0+1] + 1 ) else ( p[1+1] := p[1+1] + 1 ) ; OclFile["System.out"].println(p[0+1] + " " + p[1+1]) ; buffer := sc.getCurrent() ; p := Integer.subrange(1,2)->collect(0) ; for (ch : buffer.subrange(1+1,1)->characters()) do ( ( v := ch - ('A')->char2byte() ; p[v+1] := p[v+1] + 1 ) ) ; if (p[0+1] > p[1+1]) then ( p[0+1] := p[0+1] + 1 ) else ( p[1+1] := p[1+1] + 1 ) ; OclFile["System.out"].println(p[0+1] + " " + p[1+1]) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class lolwa_gamer { public static void main(String[] args)throws java.lang.Exception { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int w=0 ; w=S/n)S=(S % n); else S=S-a*n ; if(b>=S){ System.out.println("YES"); } else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class lolwa_gamer { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; var w : int ; w := 0 ; while w < t do ( ( var a : int ; a := s.getCurrent()->toInteger() ; var b : int ; b := s.getCurrent()->toInteger() ; var n : int ; n := s.getCurrent()->toInteger() ; var S : long ; S := s.getCurrent()->toLong() ; if (a >= S / n) then S := (S mod n) else S := S - a * n ; ; if (b >= S) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ; ) ; w := w + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A { static int n ; static long[] D ; static long[] L ; static int[] P ; public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int cas=1 ; cas<=T ; cas++){ n=in.nextInt(); D=new long[n+2]; L=new long[n+2]; P=new int[n+2]; D[0]=0 ; L[0]=0 ; for(int i=0 ; itoInteger() ; var cas : int ; cas := 1 ; while cas <= T do ( ( n := in.getCurrent()->toInteger() ; D := Integer.subrange(1,n + 2)->collect(0) ; L := Integer.subrange(1,n + 2)->collect(0) ; P := Integer.subrange(1,n + 2)->collect(0) ; D[0+1] := 0 ; L[0+1] := 0 ; var i : int ; i := 0 ; while i < n do ( ( D[i + 1+1] := in.getCurrent()->toLong() ; L[i + 1+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; D[n + 1+1] := in.getCurrent()->toLong() ; L[n + 1+1] := 0 ; var i : int ; i := 0 ; while i < n + 2 do ( P[i+1] := n + 10 ; ; i := i + 1 ) ; P[1+1] := 0 ; var c : int ; c := 1 ; while c < n + 2 do ( ( if (P[c+1] = n + 10) then continue else skip ; var my_len : long ; my_len := Set{L[c+1], D[c+1] - D[P[c+1]+1]}->min() ; var nxt : int ; nxt := c + 1 ; while nxt < n + 2 & D[nxt+1] - D[c+1] <= my_len do ( ( P[nxt+1] := Set{P[nxt+1], c}->min() ) ; nxt := nxt + 1 ) ) ; c := c + 1 ) ; OclFile["System.out"].printf("Case #%d: %s\n", cas, if P[n + 1+1] = n + 10 then "NO" else "YES" endif) ; ) ; cas := cas + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class PaymentWithoutChange { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ long a=in.nextLong(); long b=in.nextLong(); long n=in.nextLong(); long s=in.nextLong(); long x=s/n ; if(x>=a)x=a ; if((x*n)+b>=s)System.out.println("YES"); else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class PaymentWithoutChange { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : long ; a := in.getCurrent()->toLong() ; var b : long ; b := in.getCurrent()->toLong() ; var n : long ; n := in.getCurrent()->toLong() ; var s : long ; s := in.getCurrent()->toLong() ; var x : long ; x := s / n ; if (x >= a) then x := a ; else skip ; if ((x * n) + b >= s) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class PaymentWithoutChange { public static void main(String[] args)throws FileNotFoundException { FastReader in=new FastReader(); PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); int t=in.nextInt(); while(t-->0){ int a=in.nextInt(); int b=in.nextInt(); int n=in.nextInt(); int s=in.nextInt(); int mod=s % n ; if(mod>b)out.println("NO"); else if((long)a*n+b>=s)out.println("YES"); else out.println("NO"); } out.close(); } private static class FastReader { BufferedReader br ; StringTokenizer st ; FastReader()throws FileNotFoundException { br=new BufferedReader(new InputStreamReader(System.getProperty("ONLINE_JUDGE")==null ? new FileInputStream("input.txt"): System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class PaymentWithoutChange { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastReader ; in := FastReader.newFastReader() ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var t : int ; t := in.nextInt() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : int ; a := in.nextInt() ; var b : int ; b := in.nextInt() ; var n : int ; n := in.nextInt() ; var s : int ; s := in.nextInt() ; var mod : int ; mod := s mod n ; if (mod > b) then skip else if (a->oclAsType(long) * n + b >= s) then skip else skip ; ; ; ) ; ) ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(if OclProcess.getEnvironmentProperty("ONLINE_JUDGE") = null then OclFile.newOclFile_Read(OclFile.newOclFile("input.txt")) else OclFile["System.in"] endif)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var found : boolean ; found := false ; for (i : arr) do ( ( if (((i)->sqrt())->floor()->pow(2) /= i) then ( found := true ; break ) else skip ) ) ; if (found) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ boolean flag=false ; int n=sc.nextInt(); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var flag : boolean ; flag := false ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var sq : int ; sq := (a)->sqrt()->oclAsType(int) ; if (sq * sq /= a) then flag := true ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(if flag then "YES" else "NO" endif) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test309 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var x : boolean ; x := true ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var z : int ; z := (a)->sqrt()->oclAsType(int) ; if (z * z /= a) then ( x := false ) else skip ) ; i := i + 1 ) ; if (x) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ) ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isArmstrong(int x,int n){ int sum1=0 ; int temp=x ; while(temp>0){ int digit=temp % 10 ; sum1+=Math.pow(digit,n); temp/=10 ; } return sum1==x ; } static void CalculateXORandOR(int n){ int CalculateXOR=0 ; int CalculateOR=0 ; int start=(int)Math.pow(10,n-1); int end=(int)(Math.pow(10,n))-1 ; for(int i=start ; itoLowerCase().replace("o", "0").replace("l", "1").replace("i", "1") ; var n : int ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var existingLogin : String ; existingLogin := in.getCurrent()->toLowerCase().replace("o", "0").replace("l", "1").replace("i", "1") ; if (newLogin = existingLogin) then ( OclFile["System.out"].println("No") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class A928 { public static void main(String[] args){ Scanner in=new Scanner(System.in); String S=normalize(in.next()); int N=in.nextInt(); Setset=new HashSet<>(); for(int n=0 ; ntoInteger() ; var set : Set(String) ; set := Set{} ; var n : int ; n := 0 ; while n < N do ( ( set := set->including(normalize(in.getCurrent())) ) ; n := n + 1 ) ; OclFile["System.out"].println(if set->includes(S) then "No" else "Yes" endif) ; ); static operation normalize( s : String) : String pre: true post: true activity: ( s := s->toUpperCase() ; s := s.replace('O', '0') ; s := s.replace('L', '1') ; s := s.replace('I', '1') ; return s ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class LoginVer { static class InputReader { BufferedReader reader ; StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } } static InputReader r=new InputReader(System.in); static PrintWriter pw=new PrintWriter(System.out); public static void main(String[] args){ String s=convert(r.next()); int n=r.nextInt(); String[] arr=new String[n]; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } static attribute r : InputReader := InputReader.newInputReader(OclFile["System.in"]); static attribute pw : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := convert(r.next()) ; var n : int ; n := r.nextInt() ; var arr : Sequence(String) ; arr := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := convert(r.next()) ) ; i := i + 1 ) ; skip ; skip ; ); static operation check( s : String, arr : Sequence(String)) : boolean pre: true post: true activity: ( for (str : arr) do ( ( if (s = str) then ( return false ) else skip ) ) ; return true ); static operation convert( s : String) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < s->size() do ( ( var c : String ; c := s->at(i+1) ; if (c = 'O' or c = 'o') then ( sb := sb + StringLib.newString('0') ) else if (c = 'l' or c = 'L' or c = 'i' or c = 'I') then ( sb := sb + StringLib.newString('1') ) else ( sb := sb + StringLib.newString(c) ) ; ) ; i := i + 1 ) ; return sb+""->toUpperCase() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int minPower(int n,int x){ if(x==1)return n ; int ans=0 ; while(n>0){ ans+=(n % x); n/=x ; } return ans ; } public static void main(String[] args){ int n=5,x=3 ; System.out.println(minPower(n,x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minPower( n : int, x : int) : int pre: true post: true activity: ( if (x = 1) then return n else skip ; var ans : int ; ans := 0 ; while (n > 0) do ( ans := ans+((n mod x)) ; n := n/(x) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var x : int ; x := 3 ; OclFile["System.out"].println(minPower(n, x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A { static Scanner sc=new Scanner(System.in); static class Solver { int N ; int[] ds ; int[] ls ; int D ; boolean solve(){ N=sc.nextInt(); ds=new int[N]; ls=new int[N]; for(int i=0 ; ils[0])return false ; reach[0]=ds[0]; for(int i=0 ; i=D-ds[i])return true ; for(int j=i+1 ; j=0)continue ; if(ds[j]>ds[i]+reach[i])break ; reach[j]=Math.min(ds[j]-ds[i],ls[j]); } } return false ; } } public static void main(String[] args){ int T=sc.nextInt(); for(int i=1 ; i<=T ; ++i){ System.out.print("Case #"+i+": "); Solver solver=new Solver(); System.out.println(solver.solve()? "YES" : "NO"); } } } ------------------------------------------------------------ OCL File: --------- class A { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static class Solver { attribute N : int; attribute ds : Sequence(int); attribute ls : Sequence(int); attribute D : int; operation solve() : boolean pre: true post: true activity: ( N := sc.getCurrent()->toInteger() ; ds := Integer.subrange(1,N)->collect(0) ; ls := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( ds[i+1] := sc.getCurrent()->toInteger() ; ls[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; D := sc.getCurrent()->toInteger() ; var reach : Sequence(int) ; reach := Integer.subrange(1,N)->collect(0) ; reach := reach->collect(-1) ; if (ds[0+1] > ls[0+1]) then return false else skip ; reach[0+1] := ds[0+1] ; var i : int ; i := 0 ; while i < N do ( ( if (reach[i+1] < 0) then continue else skip ; if (reach[i+1] >= D - ds[i+1]) then return true else skip ; var j : int ; j := i + 1 ; while j < N do ( ( if (reach[j+1] >= 0) then continue else skip ; if (ds[j+1] > ds[i+1] + reach[i+1]) then break else skip ; reach[j+1] := Set{ds[j+1] - ds[i+1], ls[j+1]}->min() ) ; j := j + 1 ) ) ; i := i + 1 ) ; return false ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var T : int ; T := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= T do ( ( OclFile["System.out"].print("Case #" + i + ": ") ; var solver : Solver ; solver := Solver.newSolver() ; OclFile["System.out"].println(if solver.solve() then "YES" else "NO" endif) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; class GFG { static boolean isVowel(char x){ if(x=='a' || x=='e' || x=='i' || x=='o' || x=='u')return true ; else return false ; } static String updateSandwichedVowels(String a){ int n=a.length(); String updatedString="" ; for(int i=0 ; isize() ; var updatedString : String ; updatedString := "" ; var i : int ; i := 0 ; while i < n do ( ( if (i = 0 or i = n - 1) then ( updatedString := updatedString+(a->at(i+1)) ; continue ) else skip ; if (isVowel(a->at(i+1)) = true & isVowel(a->at((i)->char2byte() - 1+1)) = false & isVowel(a->at(i + 1+1)) = false) then ( continue ) else skip ; updatedString := updatedString+(a->at(i+1)) ) ; i := i + 1 ) ; return updatedString ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var updatedString : String ; updatedString := updateSandwichedVowels(str) ; OclFile["System.out"].print(updatedString) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int max_element(int[] arr){ int max=arr[0]; for(int ele : arr)if(maxcollect(false) ; prime := prime->collect(true) ; prime[0+1] := false ; prime[1+1] := false ; var p : int ; p := 2 ; while p * p <= max_val do ( ( if (prime[p+1] = true) then ( var i : int ; i := p * 2 ; while i <= max_val do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ; var x1 : int ; x1 := 1 ; var x2 : int ; x2 := 1 ; var i : int ; i := 0 ; while i < n do ( ( if (prime[arr[i+1]+1]) then x1 := MathLib.bitwiseXor(x1,arr[i+1]) ; else if (arr[i+1] /= 1) then x2 := MathLib.bitwiseXor(x2,arr[i+1]) ; else skip ; ) ; i := i + 1 ) ; return if x1 - x2 < 0 then -(x1 - x2) else x1 - x2 endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,3,5,10,15,7} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(calculateDifference(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CircleMetro { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=sc.nextInt(); int x=sc.nextInt(); int b=sc.nextInt(); int y=sc.nextInt(); a--; b--; x--; y--; while(true){ if(a==b){ System.out.println("YES"); return ; } if(a==x || b==y){ break ; } a=(a+1)% n ; b=(b-1+n)% n ; } System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class CircleMetro { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; a := a - 1 ; b := b - 1 ; x := x - 1 ; y := y - 1 ; while (true) do ( if (a = b) then ( OclFile["System.out"].println("YES") ; return ) else skip ; if (a = x or b = y) then ( break ) else skip ; a := (a + 1) mod n ; b := (b - 1 + n) mod n ) ; OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CircleMetro { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=sc.nextInt(); int x=sc.nextInt(); int b=sc.nextInt(); int y=sc.nextInt(); a--; b--; x--; y--; while(true){ if(a==b){ System.out.println("YES"); return ; } if(a==x || b==y){ break ; } a=(a+1)% n ; b=(b-1+n)% n ; } System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class CircleMetro { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; a := a - 1 ; b := b - 1 ; x := x - 1 ; y := y - 1 ; while (true) do ( if (a = b) then ( OclFile["System.out"].println("YES") ; return ) else skip ; if (a = x or b = y) then ( break ) else skip ; a := (a + 1) mod n ; b := (b - 1 + n) mod n ) ; OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPrime(int n){ if(n<=1)return false ; if(n<=3)return true ; if(n % 2==0 || n % 3==0)return false ; for(int i=5 ; i*i<=n ; i=i+6)if(n % i==0 || n %(i+2)==0)return false ; return true ; } static int findSmallest(int N){ if(N==0)return 2 ; if(N==1)return 1 ; int prime=N,counter=0 ; boolean found=false ; while(! found){ if(isPrime(prime))found=true ; else { prime++; counter++; } } return counter ; } public static void main(String[] args){ int N=10 ; System.out.print(findSmallest(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPrime( n : int) : boolean 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 ; i := 5 ; while i * i <= n do ( if (n mod i = 0 or n mod (i + 2) = 0) then return false else skip ; ; i := i + 6 ) ; return true ); static operation findSmallest( N : int) : int pre: true post: true activity: ( if (N = 0) then return 2 else skip ; if (N = 1) then return 1 else skip ; var prime : int ; prime := N ; var counter : int ; counter := 0 ; var found : boolean ; found := false ; while (not(found)) do ( if (isPrime(prime)) then found := true ; else ( prime := prime + 1 ; counter := counter + 1 ) ) ; return counter ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 10 ; OclFile["System.out"].print(findSmallest(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isPowerOfTwo(int n){ return(n>0 &&((n &(n-1))==0))? true : false ; } static int findPosition(int n){ if(! isPowerOfTwo(n))return-1 ; int i=1,pos=1 ; while((i & n)==0){ i=i<<1 ; ++pos ; } return pos ; } public static void main(String[] args){ int n=16 ; int pos=findPosition(n); if(pos==-1)System.out.println("n="+n+",Invalid number"); else System.out.println("n="+n+",Position "+pos); n=12 ; pos=findPosition(n); if(pos==-1)System.out.println("n="+n+",Invalid number"); else System.out.println("n="+n+",Position "+pos); n=128 ; pos=findPosition(n); if(pos==-1)System.out.println("n="+n+",Invalid number"); else System.out.println("n="+n+",Position "+pos); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPowerOfTwo( n : int) : boolean pre: true post: true activity: ( return if (n > 0 & ((n & (n - 1)) = 0)) then true else false endif ); static operation findPosition( n : int) : int pre: true post: true activity: ( if (not(isPowerOfTwo(n))) then return -1 else skip ; var i : int ; i := 1 ; var pos : int ; pos := 1 ; while ((MathLib.bitwiseAnd(i,n)) = 0) do ( i := (i*(2->pow(1)))->oclAsType(long) ; pos := pos + 1 ) ; return pos ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 16 ; var pos : int ; pos := findPosition(n) ; if (pos = -1) then OclFile["System.out"].println("n=" + n + ",Invalid number") else OclFile["System.out"].println("n=" + n + ",Position " + pos) ; ; n := 12 ; pos := findPosition(n) ; if (pos = -1) then OclFile["System.out"].println("n=" + n + ",Invalid number") else OclFile["System.out"].println("n=" + n + ",Position " + pos) ; ; n := 128 ; pos := findPosition(n) ; if (pos = -1) then OclFile["System.out"].println("n=" + n + ",Invalid number") else OclFile["System.out"].println("n=" + n + ",Position " + pos) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==1){ System.out.println("Hello World"); return ; } if(n==2){ int a=sc.nextInt(); int b=sc.nextInt(); System.out.println(a+b); return ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 1) then ( OclFile["System.out"].println("Hello World") ; return ) else skip ; if (n = 2) then ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(a + b) ; return ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean canPlace(int a[],int n,int p,int sep){ int prisoners_placed=1 ; int last_prisoner_placed=a[0]; for(int i=1 ; i=sep){ prisoners_placed++; last_prisoner_placed=current_cell ; if(prisoners_placed==p){ return true ; } } } return false ; } static int maxDistance(int cell[],int n,int p){ Arrays.sort(cell); int start=0 ; int end=cell[n-1]-cell[0]; int ans=0 ; while(start<=end){ int mid=start+((end-start)/2); if(canPlace(cell,n,p,mid)){ ans=mid ; start=mid+1 ; } else { end=mid-1 ; } } return ans ; } public static void main(String[] args){ int cell[]={ 1,2,8,4,9 }; int n=cell.length ; int p=3 ; System.out.println(maxDistance(cell,n,p)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation canPlace( a : Sequence(int), n : int, p : int, sep : int) : boolean pre: true post: true activity: ( var prisoners_placed : int ; prisoners_placed := 1 ; var last_prisoner_placed : int ; last_prisoner_placed := a[0+1] ; var i : int ; i := 1 ; while i < n do ( ( var current_cell : int ; current_cell := a[i+1] ; if (current_cell - last_prisoner_placed >= sep) then ( prisoners_placed := prisoners_placed + 1 ; last_prisoner_placed := current_cell ; if (prisoners_placed = p) then ( return true ) else skip ) else skip ) ; i := i + 1 ) ; return false ); static operation maxDistance( cell : Sequence(int), n : int, p : int) : int pre: true post: true activity: ( cell := cell->sort() ; var start : int ; start := 0 ; var end : int ; end := cell[n - 1+1] - cell[0+1] ; var ans : int ; ans := 0 ; while (start <= end) do ( var mid : int ; mid := start + ((end - start) / 2) ; if (canPlace(cell, n, p, mid)) then ( ans := mid ; start := mid + 1 ) else ( end := mid - 1 ) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cell : Sequence(int) ; cell := Sequence{1,2,8,4,9} ; var n : int ; n := cell->size() ; var p : int ; p := 3 ; OclFile["System.out"].println(maxDistance(cell, n, p)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { static int sum_of_series(int n){ int result=0 ; if(n % 2==0){ result=-(n*(n+1))/2 ; } else { result=(n*(n+1))/2 ; } return result ; } public static void main(String args[]){ int n=3 ; System.out.println(sum_of_series(n)); n=10 ; System.out.println(sum_of_series(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sum_of_series( n : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; if (n mod 2 = 0) then ( result := -(n * (n + 1)) / 2 ) else ( result := (n * (n + 1)) / 2 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(sum_of_series(n)) ; n := 10 ; OclFile["System.out"].println(sum_of_series(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static void find_max(int[] A,int N,int K){ HashMapCount=new HashMap<>(); for(int i=0 ; iMyset=new TreeSet(); for(Map.Entry x : Count.entrySet()){ if(Integer.parseInt(String.valueOf(x.getValue()))==1)Myset.add(Integer.parseInt(String.valueOf(x.getKey()))); } for(int i=K-1 ; ikeys()->includes(A[i+1])) then Count := Count->union(Map{A[i+1] |-> 1 + Count->at(A[i+1])}) else Count := Count->union(Map{A[i+1] |-> 1}) ; ; ; i := i + 1 ) ; var Myset : Set(int) ; Myset := Set{} ; for (x : Count->asSet()) do ( ( if ((((x.getValue()) + ""))->toInteger() = 1) then Myset := Myset->including((((x.getKey()) + ""))->toInteger()) ; else skip ) ) ; var i : int ; i := K - 1 ; while i < N do ( ( if (Count->keys()->includes(A[i+1])) then Count := Count->union(Map{A[i+1] |-> 1 + Count->at(A[i+1])}) else Count := Count->union(Map{A[i+1] |-> 1}) ; ; if ((((Count->at(A[i+1])) + ""))->toInteger() = 1) then Myset := Myset->including(A[i+1]) else Myset := Myset->excludingFirst(A[i+1]) ; ; if (Myset->size() = 0) then OclFile["System.out"].println("Nothing") else OclFile["System.out"].println(Myset->last()) ; ; var x : int ; x := A[i - K + 1+1] ; Count := Count->union(Map{x |-> Count->at(x) - 1}) ; if ((((Count->at(x)) + ""))->toInteger() = 1) then Myset := Myset->including(x) ; else skip ; if ((((Count->at(x)) + ""))->toInteger() = 0) then Myset := Myset->excludingAt(x+1) ; else skip ; ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,2,2,3,3} ; var n : int ; n := a->size() ; var k : int ; k := 3 ; execute find_max(a, n, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int x=sc.nextInt(); int cnt=0 ; for(int i=0 ; i<=a ; i++){ for(int j=0 ; j<=b ; j++){ for(int k=0 ; k<=c ; k++){ if(500*i+100*j+50*k==x){ cnt++; } } } } System.out.println(cnt); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i <= a do ( ( var j : int ; j := 0 ; while j <= b do ( ( var k : int ; k := 0 ; while k <= c do ( ( if (500 * i + 100 * j + 50 * k = x) then ( cnt := cnt + 1 ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static boolean isPalindrome(float num){ String s=String.valueOf(num); int low=0 ; int high=s.length()-1 ; while(lowsize() - 1 ; while (low < high) do ( if (s->at(low+1) /= s->at(high+1)) then return false else skip ; low := low + 1 ; high := high - 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : double ; n := 123.321f ; if (isPalindrome(n)) then OclFile["System.out"].print("Yes") ; else OclFile["System.out"].print("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.io.PrintStream ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); ABC087BCoins solver=new ABC087BCoins(); solver.solve(1,in,out); out.close(); } static class ABC087BCoins { public void solve(int testNumber,Scanner in,PrintWriter out){ int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); int x=in.nextInt(); int ans=0 ; for(int i=0 ; i<=a ; i++){ for(int j=0 ; j<=b ; j++){ for(int k=0 ; k<=c ; k++){ int total=(500*i)+(100*j)+(50*k); if(total==x)ans++; } } } System.out.println(String.valueOf(ans)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : ABC087BCoins ; solver := ABC087BCoins.newABC087BCoins() ; solver.solve(1, in, out) ; skip ; ); static class ABC087BCoins { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var c : int ; c := in.getCurrent()->toInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i <= a do ( ( var j : int ; j := 0 ; while j <= b do ( ( var k : int ; k := 0 ; while k <= c do ( ( var total : int ; total := (500 * i) + (100 * j) + (50 * k) ; if (total = x) then ans := ans + 1 ; else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(((ans) + "")) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { int A=0 ; int B=0 ; int C=0 ; int X=0 ; int count=0 ; void run(){ Scanner sc=new Scanner(System.in); A=sc.nextInt(); B=sc.nextInt(); C=sc.nextInt(); X=sc.nextInt(); for(int i=0 ; i<=A ; i++){ for(int j=0 ; j<=B ; j++){ for(int k=0 ; k<=C ; k++){ if(i*500+j*100+k*50==X){ count++; } } } } System.out.println(count); sc.close(); } void debug(Object...o){ System.out.println(Arrays.deepToString(o)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute A : int := 0; attribute B : int := 0; attribute C : int := 0; attribute X : int := 0; attribute count : int := 0; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; A := sc.getCurrent()->toInteger() ; B := sc.getCurrent()->toInteger() ; C := sc.getCurrent()->toInteger() ; X := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i <= A do ( ( var j : int ; j := 0 ; while j <= B do ( ( var k : int ; k := 0 ; while k <= C do ( ( if (i * 500 + j * 100 + k * 50 = X) then ( count := count + 1 ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; skip ; ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ int A=0 ; int B=0 ; int C=0 ; int X=0 ; int difference=0 ; int judge=0 ; Scanner scanner=new Scanner(System.in); A=scanner.nextInt(); B=scanner.nextInt(); C=scanner.nextInt(); X=scanner.nextInt(); for(int i=0 ; i<=A ; i++){ for(int j=0 ; j<=B ; j++){ difference=(X-(500*i+100*j))/50 ; if(difference>=0 && difference<=C){ judge++; } } } System.out.println(judge); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 0 ; var B : int ; B := 0 ; var C : int ; C := 0 ; var X : int ; X := 0 ; var difference : int ; difference := 0 ; var judge : int ; judge := 0 ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; A := scanner.getCurrent()->toInteger() ; B := scanner.getCurrent()->toInteger() ; C := scanner.getCurrent()->toInteger() ; X := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i <= A do ( ( var j : int ; j := 0 ; while j <= B do ( ( difference := (X - (500 * i + 100 * j)) / 50 ; if (difference >= 0 & difference <= C) then ( judge := judge + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(judge) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int A=Integer.parseInt(sc.next()); int B=Integer.parseInt(sc.next()); int C=Integer.parseInt(sc.next()); int X=Integer.parseInt(sc.next()); int res=0 ; for(int a=0 ; a<=A ; a++){ for(int b=0 ; b<=B ; b++){ int c=(X-a*500-b*100)/50 ; if(c>=0 && c<=C)res++; } } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; A := (sc.getCurrent())->toInteger() ; var B : int ; B := (sc.getCurrent())->toInteger() ; var C : int ; C := (sc.getCurrent())->toInteger() ; var X : int ; X := (sc.getCurrent())->toInteger() ; var res : int ; res := 0 ; var a : int ; a := 0 ; while a <= A do ( ( var b : int ; b := 0 ; while b <= B do ( ( var c : int ; c := (X - a * 500 - b * 100) / 50 ; if (c >= 0 & c <= C) then res := res + 1 ; else skip ) ; b := b + 1 ) ) ; a := a + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class PushZero { static void pushZerosToEnd(int arr[],int n){ int count=0 ; for(int i=0 ; isize() ; execute pushZerosToEnd(arr, n) ; OclFile["System.out"].println("Array after pushing zeros to the back: ") ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int extractMaximum(String str){ int num=0,res=0 ; for(int i=0 ; isize() do ( ( if ((str->at(i+1) + "")->isMatch("[0-9]")) then num := num * 10 + (str->at(i+1) - ('0')->char2byte()) ; else ( res := Set{res, num}->max() ; num := 0 ) ) ; i := i + 1 ) ; return Set{res, num}->max() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "100klh564abc365bg" ; OclFile["System.out"].println(extractMaximum(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; public class Test { static int arr[]=new int[] { 1,2,3,4,5 }; static void rotate(){ int x=arr[arr.length-1],i ; for(i=arr.length-1 ; i>0 ; i--)arr[i]=arr[i-1]; arr[0]=x ; } public static void main(String[] args){ System.out.println("Given Array is"); System.out.println(Arrays.toString(arr)); rotate(); System.out.println("Rotated Array is"); System.out.println(Arrays.toString(arr)); } } ------------------------------------------------------------ OCL File: --------- class Test { static attribute arr : int := Sequence{1,2,3,4,5}; static operation rotate() : void pre: true post: true activity: ( var x : int ; x := arr[arr->size() - 1+1] ; var i : int ; i := arr->size() - 1 ; while i > 0 do ( arr[i+1] := arr[i - 1+1] ; ; i := i - 1 ) ; arr[0+1] := x ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println("Given Array is") ; OclFile["System.out"].println((arr + "")) ; execute rotate() ; OclFile["System.out"].println("Rotated Array is") ; OclFile["System.out"].println((arr + "")) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.System ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNextInt()){ int d=sc.nextInt(); int sum=0 ; for(int i=d ; i<=(600-d); i+=d){ sum+=i*i*d ; } System.out.println(sum); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNextInt()) do ( var d : int ; d := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var i : int ; i := d ; while i <= (600 - d) do ( ( sum := sum+(i * i * d) ) ; i := i+(d) ) ; OclFile["System.out"].println(sum) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class Main { static int Y_MIN=0 ; static int X_MAX=600 ; public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int X_TANI=sc.nextInt(); int MENSEKI=0 ; for(int i=X_TANI ; itoInteger() ; var MENSEKI : int ; MENSEKI := 0 ; var i : int ; i := X_TANI ; while i < X_MAX do ( ( MENSEKI := MENSEKI+(X_TANI * i * i) ) ; i := i+(X_TANI) ) ; OclFile["System.out"].println(MENSEKI) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String input ; int d ; while((input=br.readLine())!=null){ d=Integer.parseInt(input); System.out.println(100*(600-d)*(1200-d)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var input : String ; var d : int ; input := br.readLine() ; while ((input) /= null) do ( skip ; ( d := (input)->toInteger() ; OclFile["System.out"].println(100 * (600 - (d)->char2byte()) * (1200 - (d)->char2byte())) ) ; input := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int d,s ; int i ; for(; sc.hasNext(); ){ d=sc.nextInt(); s=0 ; for(i=d ; i<600 ; i+=d)s+=d*i*i ; System.out.println(s); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var d : int ; var s : int ; var i : int ; while sc.hasNext() do ( ( d := sc.nextInt() ; s := 0 ; i := d ; while i < 600 do ( s := s+(d * i * i) ; ; i := i+(d) ) ; OclFile["System.out"].println(s) ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long squareDigitSum(String s){ long lengthN=s.length(); long result=(lengthN/9)*81+(long)Math.pow((lengthN % 9),2); return result ; } public static void main(String[] args){ String s="1111" ; System.out.println(squareDigitSum(s)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation squareDigitSum( s : String) : long pre: true post: true activity: ( var lengthN : long ; lengthN := s->size() ; var result : long ; result := (lengthN / 9) * 81 + (lengthN mod 9)->pow(2)->oclAsType(long) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "1111" ; OclFile["System.out"].println(squareDigitSum(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { private static int my_pow(int a){ return a*a ; } private static int l_square(int size){ int sum=0,count=1 ; for(int i=size ; i<=600-size ; i=i+size){ sum=sum+my_pow(count*size)*size ; count++; } return sum ; } public static void main(String args[])throws IOException { ArrayListinp=new ArrayList(); ArrayListsq_size=new ArrayList(); ArrayListres=new ArrayList(); Scanner scan=new Scanner(System.in); while(scan.hasNext()){ String str1=scan.next(); inp.add(Integer.valueOf(str1).intValue()); } for(int i=0 ; iincluding((str1)->toInteger()->oclAsType(int)) ) ; var i : int ; i := 0 ; while i < inp->size() do ( ( res := res->including(l_square(inp->at(i+1))) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < res->size() do ( ( OclFile["System.out"].println(res->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isPalindrome(String str,int l,int r){ while(lat(l+1) /= str->at(r+1)) then return false else skip ; l := l + 1 ; r := r - 1 ) ; return true ); static operation CyclicShifts( str : String) : int pre: true post: true activity: ( var n : int ; n := str->size() ; var left : int ; left := 0 ; var right : int ; right := n - 1 ; str := str + str ; var cnt : int ; cnt := 0 ; while (right < 2 * n - 1) do ( if (isPalindrome(str, left, right)) then break else skip ; cnt := cnt + 1 ; left := left + 1 ; right := right + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "bccbbaab" ; OclFile["System.out"].println(CyclicShifts(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findNumbers(int n){ String ans="" ; for(int i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class SpykeTalks { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int numS=scanner.nextInt(); int[] numC=new int[numS]; int[] nArry=new int[numC.length]; for(int i=0 ; iarray[Sbr]){ int valorRojo=array[Srd]; int valorAzul=array[Sbr]; array[Srd]=valorAzul ; array[Sbr]=valorRojo ; } } } } private static int countPairs(int[] arry){ int prj=0 ; for(int i=1 ; i1){ if(arry[i]==arry[i-1] && arry[i]==arry[i+1]){ return-1 ; } } } } return prj ; } } ------------------------------------------------------------ OCL File: --------- class SpykeTalks { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numS : int ; numS := scanner.getCurrent()->toInteger() ; var numC : Sequence(int) ; numC := Integer.subrange(1,numS)->collect(0) ; var nArry : Sequence(int) ; nArry := Integer.subrange(1,numC->size())->collect(0) ; var i : int ; i := 0 ; while i < numC->size() do ( ( var id : int ; id := scanner.getCurrent()->toInteger() ; numC[i+1] := id ) ; i := i + 1 ) ; execute sortIntegerArraySelection(numC) ; var i : int ; i := 0 ; while i < nArry->size() do ( ( nArry[i+1] := numC[i+1] ) ; i := i + 1 ) ; var cnt : int ; cnt := countPairs(nArry) ; OclFile["System.out"].println(cnt) ; ); static operation sortIntegerArraySelection( array : Sequence(int)) : void pre: true post: true activity: ( var Srd : int ; Srd := 0 ; while Srd < array->size() - 1 do ( ( var Sbr : int ; Sbr := Srd + 1 ; while Sbr < array->size() do ( ( if (array[Srd+1] > array[Sbr+1]) then ( var valorRojo : int ; valorRojo := array[Srd+1] ; var valorAzul : int ; valorAzul := array[Sbr+1] ; array[Srd+1] := valorAzul ; array[Sbr+1] := valorRojo ) else skip ) ; Sbr := Sbr + 1 ) ) ; Srd := Srd + 1 ) ); static operation countPairs( arry : Sequence(int)) : int pre: true post: true activity: ( var prj : int ; prj := 0 ; var i : int ; i := 1 ; while i < arry->size() do ( ( if (arry[i+1] = arry[i - 1+1] & arry[i+1] /= 0) then ( prj := prj + 1 ; if (arry->size() - i > 1) then ( if (arry[i+1] = arry[i - 1+1] & arry[i+1] = arry[i + 1+1]) then ( return -1 ) else skip ) else skip ) else skip ) ; i := i + 1 ) ; return prj ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; public class ProblemaB { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] secondLine=br.readLine().split(" "); br.close(); ArrayListmyIds=new ArrayList<>(); for(String s : secondLine){ if(! s.equals("0"))myIds.add(Integer.parseInt(s)); } int par=0 ; int totalSize=myIds.size(); while(myIds.size()>0 && par!=-1){ myIds.removeAll(Arrays.asList(myIds.get(0))); if(totalSize-myIds.size()>2){ par=-1 ; } else if(totalSize-myIds.size()==2){ par++; } totalSize=myIds.size(); } System.out.println(par); } } ------------------------------------------------------------ OCL File: --------- class ProblemaB { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var secondLine : Sequence(String) ; secondLine := br.readLine()->split(" ") ; skip ; var myIds : Sequence(int) ; myIds := Sequence{} ; for (s : secondLine) do ( ( if (not(s = "0")) then myIds := myIds->including((s)->toInteger()) ; else skip ) ) ; var par : int ; par := 0 ; var totalSize : int ; totalSize := myIds->size() ; while (myIds->size() > 0 & par /= -1) do ( myIds := myIds - myIds->at(0+1) ; if (totalSize - myIds->size() > 2) then ( par := -1 ) else if (totalSize - myIds->size() = 2) then ( par := par + 1 ) else skip ; ; totalSize := myIds->size() ) ; OclFile["System.out"].println(par) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class SpikeTalks { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int result=0 ; int nSecretary=sc.nextInt(); int[] arr=new int[nSecretary]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,nSecretary)->collect(0) ; var i : int ; i := 0 ; while i < nSecretary do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (nSecretary = 1) then ( result := 0 ) else ( execute booblesSort(arr) ; var i : int ; i := 1 ; while i < arr->size() do ( ( if (arr[i+1] /= 0 & arr[i+1] = arr[i - 1+1]) then ( result := result + 1 ; if (i + 1 < arr->size() & arr[i+1] = arr[i + 1+1]) then ( result := -1 ; break ) else skip ) else skip ) ; i := i + 1 ) ) ; OclFile["System.out"].println(result) ; ); static operation booblesSort( arr : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < arr->size() do ( ( var j : int ; j := 1 ; while j < arr->size() - i do ( ( if (arr[j+1] < arr[j - 1+1]) then ( var actual : int ; actual := arr[j+1] ; var anterior : int ; anterior := arr[j - 1+1] ; arr[j - 1+1] := actual ; arr[j+1] := anterior ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.*; public class GFG { static int countPairs(int arr[],int n){ int twoCount=0,twoGrCount=0 ; for(int i=0 ; i2)twoGrCount++; } return twoCount*twoGrCount+(twoGrCount*(twoGrCount-1))/2 ; } public static void main(String args[]){ int arr[]={ 3,4,5 }; int n=arr.length ; System.out.println(countPairs(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countPairs( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var twoCount : int ; twoCount := 0 ; var twoGrCount : int ; twoGrCount := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = 2) then twoCount := twoCount + 1 ; else if (arr[i+1] > 2) then twoGrCount := twoGrCount + 1 ; else skip ; ) ; i := i + 1 ) ; return twoCount * twoGrCount + (twoGrCount * (twoGrCount - 1)) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,4,5} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(countPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class cp { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int T=Integer.parseInt(br.readLine()); while(T-->0){ String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); String[] str1=br.readLine().split(" "); long[] arr=new long[n+1]; long zeros=0 ; long sum=0 ; boolean flag=false ; for(int i=0 ; ifindAllFactors(long num){ ArrayListfactors=new ArrayList(); for(long i=1 ; i<=num/i ; ++i){ if(num % i==0){ factors.add(i); factors.add(num/i); } } Collections.sort(factors); return factors ; } public static long gcd(long a,long b){ if(b==0)return a ; return gcd(b,a % b); } } ------------------------------------------------------------ OCL File: --------- class cp { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var T : int ; T := (br.readLine())->toInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( var str : Sequence(String) ; str := br.readLine()->split(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var str1 : Sequence(String) ; str1 := br.readLine()->split(" ") ; var arr : Sequence(long) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var zeros : long ; zeros := 0 ; var sum : long ; sum := 0 ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (str1[i+1])->toLong() ; if (i /= n - 1) then sum := sum+(arr[i+1]) ; else skip ; if (arr[i+1] = 0 & flag) then zeros := zeros + 1 ; else skip ; if (arr[i+1] /= 0) then flag := true ; else skip ) ; i := i + 1 ) ; if (arr[n - 1+1] = 0 & sum /= 0) then skip else skip ; ; ) ; ) ; skip ; ); static operation findAllFactors( num : long) : Sequence(long) pre: true post: true activity: ( var factors : Sequence(long) ; factors := Sequence{} ; var i : long ; i := 1 ; while i <= num / i do ( ( if (num mod i = 0) then ( factors := factors->including(i) ; factors := factors->including(num / i) ) else skip ) ; i := i + 1 ) ; factors := factors->sort() ; return factors ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (b = 0) then return a else skip ; return gcd(b, a mod b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args){ FastScanner input=new FastScanner(); int tc=input.nextInt(); work : while(tc-->0){ int n=input.nextInt(); int a[]=new int[n]; int zero=0 ; long sum=0 ; boolean start=false ; for(int i=0 ; i0 && ! start){ start=true ; } if(start && a[i]==0 && i!=n-1){ zero++; } } System.out.println(zero+sum); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine()throws IOException { return br.readLine(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : FastScanner ; input := FastScanner.newFastScanner() ; var tc : int ; tc := input.nextInt() ; while (tc > 0) do ( tc := tc - 1 ; skip ; ( var n : int ; n := input.nextInt() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var zero : int ; zero := 0 ; var sum : long ; sum := 0 ; var start : boolean ; start := false ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := input.nextInt() ; if (i /= n - 1) then sum := sum+(a[i+1]) ; else skip ; if (a[i+1] > 0 & not(start)) then ( start := true ) else skip ; if (start & a[i+1] = 0 & i /= n - 1) then ( zero := zero + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(zero + sum) ; ) ; ) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static int getFirstSetBitPos(int n){ return(int)((Math.log10(n &-n))/Math.log10(2))+1 ; } public static void main(String[] args){ int n=12 ; System.out.println(getFirstSetBitPos(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getFirstSetBitPos( n : int) : int pre: true post: true activity: ( return (((n & -n)->log10()) / (2)->log10())->oclAsType(int) + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12 ; OclFile["System.out"].println(getFirstSetBitPos(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; class GfG { static int sumFirst(int a[],int n){ HashMapmp=new HashMap<>(); int suf=0 ; for(int i=n-1 ; i>=0 ; i--){ suf+=a[i]; mp.put(suf,i); } int pre=0,maxi=-1 ; for(int i=0 ; ii){ if(pre>maxi){ maxi=pre ; } } } if(maxi==-1)return 0 ; else return maxi ; } public static void main(String[] args){ int a[]={ 1,3,2,1,4 }; int n=a.length ; System.out.println(sumFirst(a,n)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation sumFirst( a : Sequence(int), n : int) : int pre: true post: true activity: ( var mp : Map(int,int) ; mp := Map{} ; var suf : int ; suf := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( suf := suf+(a[i+1]) ; mp := mp->union(Map{suf |-> i}) ) ; i := i - 1 ) ; var pre : int ; pre := 0 ; var maxi : int ; maxi := -1 ; var i : int ; i := 0 ; while i < n do ( ( pre := pre+(a[i+1]) ; if (mp->keys()->includes(pre) & mp->at(pre) > i) then ( if (pre > maxi) then ( maxi := pre ) else skip ) else skip ) ; i := i + 1 ) ; if (maxi = -1) then return 0 else return maxi ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,3,2,1,4} ; var n : int ; n := a->size() ; OclFile["System.out"].println(sumFirst(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class primesquare { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); for(int j=0 ; jtoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < n do ( ( var k : int ; k := 0 ; while k < n do ( ( if (k = j or k = (j + 1) mod n) then OclFile["System.out"].println("1") ; else OclFile["System.out"].println("0") ; ) ; k := k + 1 ) ; OclFile["System.out"].println() ) ; j := j + 1 ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int countX(int n){ String binary=Integer.toBinaryString(n); int count=0 ; for(int i=0 ; isize() do ( ( if (binary->at(i+1) = '1') then count := count + 1 ; else skip ) ; i := i + 1 ) ; var answer : int ; answer := 2->pow(count)->oclAsType(int) ; return answer ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var answer : int ; answer := countX(n) ; OclFile["System.out"].println(answer) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class KyoyaPhotobook { public static void main(String[] args){ Scanner sc=new Scanner(System.in); char[] string=sc.next().toCharArray(); HashSetstringsPossible=new HashSet<>(); for(int insertPosition=0 ; insertPosition<=string.length ; insertPosition++){ for(char c='a' ; c<='z' ; c++){ StringBuilder sb=new StringBuilder(); for(int i=0 ; icharacters() ; var stringsPossible : Set(String) ; stringsPossible := Set{} ; var insertPosition : int ; insertPosition := 0 ; while insertPosition <= string->size() do ( ( var c : String ; c := 'a' ; while c <= 'z' do ( ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < insertPosition do ( ( sb := sb + StringLib.newString(string[i+1]) ) ; i := i + 1 ) ; sb := sb + StringLib.newString(c) ; var i : int ; i := insertPosition ; while i < string->size() do ( ( sb := sb + StringLib.newString(string[i+1]) ) ; i := i + 1 ) ; stringsPossible := stringsPossible->including(sb+"") ; ) ; c := c + 1 ) ) ; insertPosition := insertPosition + 1 ) ; OclFile["System.out"].println(stringsPossible->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static void printElements(int arr[],int n){ for(int i=1 ; iarr[i-1] && arr[i]>arr[i+1])System.out.print(arr[i]+" "); } } public static void main(String[] args){ int arr[]={ 2,3,1,5,4,9,8,7,5 }; int n=arr.length ; printElements(arr,n); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation printElements( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < n - 1 do ( ( if (arr[i+1] > arr[i - 1+1] & arr[i+1] > arr[i + 1+1]) then OclFile["System.out"].print(arr[i+1] + " ") ; else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,3,1,5,4,9,8,7,5} ; var n : int ; n := arr->size() ; execute printElements(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class MissingLetter { public static void main(String[] args){ Scanner in=new Scanner(System.in); String s=in.next(); HashSeths=new HashSet<>(); for(int i=0 ; i<=s.length(); i++){ for(char c='a' ; c<='z' ; c++){ hs.add(s.substring(0,i)+c+s.substring(i)); } } System.out.println(hs.size()); System.exit(0); } } ------------------------------------------------------------ OCL File: --------- class MissingLetter { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := in.getCurrent() ; var hs : Set(String) ; hs := Set{} ; var i : int ; i := 0 ; while i <= s->size() do ( ( var c : String ; c := 'a' ; while c <= 'z' do ( ( hs := hs->including(s.subrange(0+1,i) + c + s.subrange(i+1,i)) ) ; c := c + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(hs->size()) ; OclProcess.exit(0) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Code { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=26 ; String str=input.next(); System.out.println(n+25*str.length()); } } ------------------------------------------------------------ OCL File: --------- class Code { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := 26 ; var str : String ; str := input.getCurrent() ; OclFile["System.out"].println(n + 25 * str->size()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); String s=input.next(); int a=(s.length()+1)*26-s.length(); System.out.println(a); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := input.getCurrent() ; var a : int ; a := (s->size() + 1) * 26 - s->size() ; OclFile["System.out"].println(a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MyClass { public static void main(String args[]){ Scanner in=new Scanner(System.in); String s=in.next(); int n=s.length(); int k=(n+1)*26-n ; System.out.println(k); } } ------------------------------------------------------------ OCL File: --------- class MyClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := in.getCurrent() ; var n : int ; n := s->size() ; var k : int ; k := (n + 1) * 26 - (n)->char2byte() ; OclFile["System.out"].println(k) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int cntWays(int arr[],int n){ if(n==1){ return 0 ; } int tot_sum=0,sum=0,ans=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(cntWays(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { public static int minNumber(int a[],int n,int x){ int l=0,h=0,e=0 ; for(int i=0 ; ix)h++; else if(a[i]h)ans=l-h ; else if(l x) then h := h + 1 else if (a[i+1] < x) then l := l + 1 ; else skip ; ; ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; if (l > h) then ans := l - h else if (l < h) then ans := h - l - 1 ; else skip ; ; return ans + 1 - e ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 10 ; var a : Sequence(int) ; a := Sequence{10,20,30} ; var n : int ; n := a->size() ; OclFile["System.out"].println(minNumber(a, n, x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isSquarePossible(int arr[],int n,int l){ int cnt=0 ; for(int i=0 ; i=l)cnt++; if(cnt>=l)return true ; } return false ; } static int maxArea(int arr[],int n){ int l=0,r=n ; int len=0 ; while(l<=r){ int m=l+((r-l)/2); if(isSquarePossible(arr,n,m)){ len=m ; l=m+1 ; } else r=m-1 ; } return(len*len); } public static void main(String[] args){ int arr[]={ 1,3,4,5,5 }; int n=arr.length ; System.out.println(maxArea(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isSquarePossible( arr : Sequence(int), n : int, l : int) : boolean pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] >= l) then cnt := cnt + 1 ; else skip ; if (cnt >= l) then return true else skip ) ; i := i + 1 ) ; return false ); static operation maxArea( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var l : int ; l := 0 ; var r : int ; r := n ; var len : int ; len := 0 ; while (l <= r) do ( var m : int ; m := l + ((r - l) / 2) ; if (isSquarePossible(arr, n, m)) then ( len := m ; l := m + 1 ) else r := m - 1 ; ) ; return (len * len) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,3,4,5,5} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(maxArea(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static void main(String[] args){ int n=5 ; printPascal(n); } public static void printPascal(int n){ int[][] arr=new int[n][n]; for(int line=0 ; linecollect(Integer.subrange(1,n)->collect(0)) ; var line : int ; line := 0 ; while line < n do ( ( var i : int ; i := 0 ; while i <= line do ( ( if (line = i or i = 0) then arr[line+1][i+1] := 1 else arr[line+1][i+1] := arr[line - 1+1][i - 1+1] + arr[line - 1+1][i+1] ; ; OclFile["System.out"].print(arr[line+1][i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println("") ) ; line := line + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String printLargestString(String s,int l,int r){ int freq[]=new int[26]; l--; r--; for(int i=Math.min(l,r); i<=Math.max(l,r); i++){ freq[s.charAt(i)-'a']++; } String ans="" ; for(int i=25 ; i>=0 ; i--){ while(freq[i]>0){ ans+=(char)('a'+i); freq[i]--; } } return ans ; } public static void main(String[] args){ String s="striver" ; int l=3,r=5 ; System.out.println(printLargestString(s,l,r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printLargestString( s : String, l : int, r : int) : String pre: true post: true activity: ( var freq : Sequence(int) ; freq := Integer.subrange(1,26)->collect(0) ; l := l - 1 ; r := r - 1 ; var i : int ; i := Set{l, r}->min() ; while i <= Set{l, r}->max() do ( ( freq[s->at(i+1) - ('a')->char2byte()+1] := freq[s->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var ans : String ; ans := "" ; var i : int ; i := 25 ; while i >= 0 do ( ( while (freq[i+1] > 0) do ( ans := ans+(('a' + i)->oclAsType(String)) ; freq[i+1] := freq[i+1] - 1 ) ) ; i := i - 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "striver" ; var l : int ; l := 3 ; var r : int ; r := 5 ; OclFile["System.out"].println(printLargestString(s, l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf60A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int lo=1 ; int hi=n ; for(int i=0 ; itoInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var lo : int ; lo := 1 ; var hi : int ; hi := n ; var i : int ; i := 0 ; while i < m do ( ( skip ; skip ; var dir : String ; dir := scan.getCurrent() ; skip ; var num : int ; num := scan.getCurrent()->toInteger() ; if (dir = "left") then ( hi := Set{hi, (num)->char2byte() - 1}->min() ) else ( lo := Set{lo, num + 1}->max() ) ; ) ; i := i + 1 ) ; if (hi - lo < 0) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(hi - lo + 1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int valueofX(int ar[],int n){ int sum=0 ; for(int i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf60A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int left=1 ; int right=n ; for(int i=0 ; iright){ System.out.println(-1); } else { System.out.println(right-left+1); } } } ------------------------------------------------------------ OCL File: --------- class cf60A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var left : int ; left := 1 ; var right : int ; right := n ; var i : int ; i := 0 ; while i < m do ( ( skip ; skip ; var dir : String ; dir := scan.getCurrent() ; skip ; var num : int ; num := scan.getCurrent()->toInteger() ; if (dir = "left") then ( right := Set{right, (num)->char2byte() - 1}->min() ) else ( left := Set{left, num + 1}->max() ) ; ) ; i := i + 1 ) ; if (left > right) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(right - left + 1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class cf60A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int[] intArr=new int[n]; Arrays.fill(intArr,1); for(int i=0 ; itoInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var intArr : Sequence(int) ; intArr := Integer.subrange(1,n)->collect(0) ; intArr := intArr->collect(1) ; var i : int ; i := 0 ; while i < m do ( ( var str : String ; str := scan.getCurrent() ; var str1 : String ; str1 := scan.getCurrent() ; var str2 : String ; str2 := scan.getCurrent() ; var str3 : String ; str3 := scan.getCurrent() ; var a : int ; a := scan.getCurrent()->toInteger() ; if (str2 = "left") then ( var b : int ; b := (a)->char2byte() - 1 ; while b < n do ( ( intArr[b+1] := 0 ) ; b := b + 1 ) ) else if (str2 = "right") then ( var b : int ; b := 0 ; while b < a do ( ( intArr[b+1] := 0 ) ; b := b + 1 ) ) else skip ; ; ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(intArr[i+1]) ) ; i := i + 1 ) ; if (sum = 0) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(sum) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class WhereAreMyFlakes { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int lo=1 ; int hi=scan.nextInt(); int hintCnt=scan.nextInt(); for(int i=0 ; ihi){ System.out.println(-1); } else { System.out.println(hi-lo+1); } } } ------------------------------------------------------------ OCL File: --------- class WhereAreMyFlakes { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var lo : int ; lo := 1 ; var hi : int ; hi := scan.getCurrent()->toInteger() ; var hintCnt : int ; hintCnt := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < hintCnt do ( ( skip ; skip ; var dir : String ; dir := scan.getCurrent() ; skip ; var num : int ; num := scan.getCurrent()->toInteger() ; if (dir = "right") then ( lo := Set{lo, num + 1}->max() ) else ( hi := Set{hi, (num)->char2byte() - 1}->min() ) ; ) ; i := i + 1 ) ; if (lo > hi) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(hi - lo + 1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf60A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int lo=1 ; int hi=n ; for(int i=0 ; itoInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var lo : int ; lo := 1 ; var hi : int ; hi := n ; var i : int ; i := 0 ; while i < m do ( ( skip ; skip ; var dir : String ; dir := scan.getCurrent() ; skip ; var num : int ; num := scan.getCurrent()->toInteger() ; if (dir = "left") then ( hi := Set{hi, (num)->char2byte() - 1}->min() ) else ( lo := Set{lo, num + 1}->max() ) ; ) ; i := i + 1 ) ; if (hi - lo + 1 <= 0) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(hi - lo + 1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B1323 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int M=in.nextInt(); int K=in.nextInt(); int[] A=new int[N+1]; for(int n=0 ; ntoInteger() ; var M : int ; M := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N + 1)->collect(0) ; var n : int ; n := 0 ; while n < N do ( ( A[n+1] := in.getCurrent()->toInteger() ) ; n := n + 1 ) ; var B : Sequence(int) ; B := Integer.subrange(1,M + 1)->collect(0) ; var m : int ; m := 0 ; while m < M do ( ( B[m+1] := in.getCurrent()->toInteger() ) ; m := m + 1 ) ; var aSegments : Sequence(long) ; aSegments := Integer.subrange(1,N + 1)->collect(0) ; var ones : int ; ones := 0 ; for (a : A) do ( ( if (a = 0) then ( var i : int ; i := 1 ; while i <= ones do ( ( aSegments[i+1] := aSegments[i+1]+(ones + 1 - i) ) ; i := i + 1 ) ; ones := 0 ) else ( ones := ones + 1 ) ) ) ; var bSegments : Sequence(long) ; bSegments := Integer.subrange(1,M + 1)->collect(0) ; ones := 0 ; for (b : B) do ( ( if (b = 0) then ( var i : int ; i := 1 ; while i <= ones do ( ( bSegments[i+1] := bSegments[i+1]+(ones + 1 - i) ) ; i := i + 1 ) ; ones := 0 ) else ( ones := ones + 1 ) ) ) ; var answer : long ; answer := 0 ; var d : int ; d := 1 ; while d * d <= K do ( ( if (K mod d = 0) then ( var dd : int ; dd := K / d ; if (d <= N & dd <= M) then ( answer := answer+(aSegments[d+1] * bSegments[dd+1]) ) else skip ; if (d /= dd & d <= M & dd <= N) then ( answer := answer+(aSegments[dd+1] * bSegments[d+1]) ) else skip ) else skip ) ; d := d + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ int n=in.nextInt(); if(n==0)break ; int xmax=0,xmin=0,ymax=0,ymin=0 ; ArrayListx=new ArrayList(); ArrayListy=new ArrayList(); x.add(0); y.add(0); for(int i=1 ; itoInteger() ; if (n = 0) then break else skip ; var xmax : int ; xmax := 0 ; var xmin : int ; xmin := 0 ; var ymax : int ; ymax := 0 ; var ymin : int ; ymin := 0 ; var x : Sequence(int) ; x := Sequence{} ; var y : Sequence(int) ; y := Sequence{} ; x := x->including(0) ; y := y->including(0) ; var i : int ; i := 1 ; while i < n do ( ( var id : int ; id := in.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (in.getCurrent()->toInteger()) ; if _switchval = 0 then x := x->including(x->at(id+1) - 1) ; y := y->including(y->at(id+1)) ; break else skip ; if _switchval = 1 then x := x->including(x->at(id+1)) ; y := y->including(y->at(id+1) - 1) ; break else skip ; if _switchval = 2 then x := x->including(x->at(id+1) + 1) ; y := y->including(y->at(id+1)) ; break else skip ; if _switchval = 3 then x := x->including(x->at(id+1)) ; y := y->including(y->at(id+1) + 1) ; break else skip ; ) xmax := Set{xmax, x->at(i+1)}->max() ; xmin := Set{xmin, x->at(i+1)}->min() ; ymax := Set{ymax, y->at(i+1)}->max() ; ymin := Set{ymin, y->at(i+1)}->min() ; ) ; i := i + 1 ) ; OclFile["System.out"].println((xmax - xmin + 1) + " " + (ymax - ymin + 1)) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { int[] vx={ -1,0,1,0 }; int[] vy={ 0,1,0,-1 }; private void doit(){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0)break ; int[] x=new int[n]; int[] y=new int[n]; for(int i=1 ; itoInteger() ; if (n = 0) then break else skip ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var y : Sequence(int) ; y := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 1 ; while i < n do ( ( var ni : int ; ni := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; x[i+1] := x[ni+1] + vx[d+1] ; y[i+1] := y[ni+1] + vy[d+1] ) ; i := i + 1 ) ; var maxx : int ; maxx := x[0+1] ; var maxy : int ; maxy := y[0+1] ; var minx : int ; minx := x[0+1] ; var miny : int ; miny := y[0+1] ; var i : int ; i := 1 ; while i < n do ( ( maxx := Set{maxx, x[i+1]}->max() ; maxy := Set{maxy, y[i+1]}->max() ; minx := Set{minx, x[i+1]}->min() ; miny := Set{miny, y[i+1]}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println((maxx - minx + 1) + " " + (maxy - miny + 1)) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : Main ; obj := Main.newMain() ; obj.doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean checkTriangularSumRepresentation(int n){ HashSettri=new HashSet<>(); int i=1 ; while(true){ int x=i*(i+1)/2 ; if(x>=n){ break ; } tri.add(x); i++; } for(Integer tm : tri){ if(tri.contains(n-tm)&&(n-tm)!=(int)tri.toArray()[tri.size()-1]){ return true ; } } return false ; } public static void main(String[] args){ int n=24 ; if(checkTriangularSumRepresentation(n)){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkTriangularSumRepresentation( n : int) : boolean pre: true post: true activity: ( var tri : Set(int) ; tri := Set{} ; var i : int ; i := 1 ; while (true) do ( var x : int ; x := i * (i + 1) / 2 ; if (x >= n) then ( break ) else skip ; tri := tri->including(x) ; i := i + 1 ) ; for (tm : tri) do ( ( if (tri->includes(n - tm) & (n - tm) /= tri->asSequence()[tri->size() - 1+1]->oclAsType(int)) then ( return true ) else skip ) ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 24 ; if (checkTriangularSumRepresentation(n)) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static Position[] direction={ new Position(-1,0),new Position(0,-1),new Position(1,0),new Position(0,1)}; public static void main(String args[]){ int N,number,tmp_dire,right,left,top,bottom ; Position[] square_pos ; while((N=sc.nextInt())!=0){ right=0 ; left=0 ; top=0 ; bottom=0 ; square_pos=new Position[N]; square_pos[0]=new Position(0,0); for(int i=1 ; iright)right=square_pos[j] .x ; if(square_pos[j] .ytop)top=square_pos[j] .y ; } System.out.println((right-left+1)+" "+(top-bottom+1)); } } static class Position { int x,y ; Position(int x,int y){ this.x=x ; this.y=y ; } void movePosition(Position tmp){ x+=tmp.x ; y+=tmp.y ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute direction : Sequence(Position) := Sequence{Position.newPosition(-1, 0),Position.newPosition(0, -1),Position.newPosition(1, 0),Position.newPosition(0, 1)}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; var number : int ; var tmp_dire : int ; var right : int ; var left : int ; var top : int ; var bottom : int ; var square_pos : Sequence(Position) ; N := sc.getCurrent()->toInteger() ; while ((N) /= 0) do ( skip ; ( right := 0 ; left := 0 ; top := 0 ; bottom := 0 ; square_pos := Integer.subrange(1,N)->collect(null) ; square_pos[0+1] := Position.newPosition(0, 0) ; var i : int ; i := 1 ; while i < N do ( ( number := sc.getCurrent()->toInteger() ; tmp_dire := sc.getCurrent()->toInteger() ; square_pos[i+1] := Position.newPosition(square_pos[number+1].x, square_pos[number+1].y) ; square_pos[i+1].movePosition(direction[tmp_dire+1]) ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < square_pos->size() do ( ( if (square_pos[j+1].x < left) then left := square_pos[j+1].x else if (square_pos[j+1].x > right) then right := square_pos[j+1].x ; else skip ; ; if (square_pos[j+1].y < bottom) then bottom := square_pos[j+1].y ; else if (square_pos[j+1].y > top) then top := square_pos[j+1].y ; else skip ; ) ; j := j + 1 ) ; OclFile["System.out"].println((right - left + 1) + " " + (top - bottom + 1)) ; ) ; N := sc.getCurrent()->toInteger() ; ) ); static class Position { attribute x : int; static operation newPosition( x : int, y : int) : Position pre: true post: true activity: ( var self : Position ; self := createPosition(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation movePosition( tmp : Position) : void pre: true post: true activity: ( x := x+(tmp.x) ; y := y+(tmp.y) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public final class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; i=arr[j])s+=0 ; else s+=1 ; } System.out.println(Integer.parseInt(s,2)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var l : int ; l := sc.getCurrent()->toInteger() ; var s : String ; s := "" ; var arr : Sequence(int) ; arr := Integer.subrange(1,l)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( var temp : String ; temp := (MathLib.decimal2binary(sc.getCurrent()->toInteger()) + "") ; while (temp->size() < l) do temp := '0' + temp ; ; var k : int ; k := 0 ; while k < l do ( ( if (k < temp->size() & temp->at(k+1) = '1') then arr[k+1] := arr[k+1]+(1) ; else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < l do ( ( if (n - arr[j+1] >= arr[j+1]) then s := s+(0) ; else s := s+(1) ; ) ; j := j + 1 ) ; OclFile["System.out"].println((s)->toInteger()) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.HashMap ; public class Main { public static void main(String[] args){ while(true){ int n=nextInt(); if(n==0){ break ; } HashMaphashMap=new HashMap(); Integer[] zero={ 0,0 }; hashMap.put(0,zero); int x_max=0,x_min=0,y_max=0,y_min=0 ; for(int i=1 ; i'9'))c=System.in.read(); if(c=='-')return-nextInt(); int res=0 ; while(c>='0' && c<='9'){ res=res*10+c-'0' ; c=System.in.read(); } return res ; } catch(IOException e){ e.printStackTrace(); } return-1 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (true) do ( var n : int ; n := nextInt() ; if (n = 0) then ( break ) else skip ; var hashMap : Map(int,Sequence(int)) ; hashMap := Map{} ; var zero : Sequence(int) ; zero := Sequence{0,0} ; hashMap := hashMap->union(Map{0 |-> zero}) ; var x_max : int ; x_max := 0 ; var x_min : int ; x_min := 0 ; var y_max : int ; y_max := 0 ; var y_min : int ; y_min := 0 ; var i : int ; i := 1 ; while i < n do ( ( var base : int ; base := nextInt() ; var x : int ; x := hashMap->at(base)[0+1] ; var y : int ; y := hashMap->at(base)[1+1] ; var direction : int ; direction := nextInt() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (direction) ; if _switchval = 0 then x := x - 1 ; break else skip ; if _switchval = 1 then y := y - 1 ; break else skip ; if _switchval = 2 then x := x + 1 ; break else skip ; if _switchval = 3 then y := y + 1 ; break else skip ; if true then break else skip ; ) var axis : Sequence(int) ; axis := Sequence{x,y} ; hashMap := hashMap->union(Map{i |-> axis}) ; x_max := Set{x_max, x}->max() ; x_min := Set{x_min, x}->min() ; y_max := Set{y_max, y}->max() ; y_min := Set{y_min, y}->min() ; ) ; i := i + 1 ) ; var width : int ; width := x_max - x_min + 1 ; var height : int ; height := y_max - y_min + 1 ; OclFile["System.out"].println(width + " " + height) ; ) ); static operation nextInt() : int pre: true post: true activity: ( var c : int ; try ( c := OclFile["System.in"].read() ; while (c /= '-' & (c < '0' or c > '9')) do c := OclFile["System.in"].read() ; ; if (c = '-') then return -nextInt() else skip ; var res : int ; res := 0 ; while (c >= '0' & c <= '9') do ( res := res * 10 + c - ('0')->char2byte() ; c := OclFile["System.in"].read() ) ; return res ) catch (e : IOException) do ( e.printStackTrace() ) return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { private static boolean solve(Integer[] arr,int n){ if(n==1){ return arr[0]==1 ; } return arr[n-1]-arr[n-2]<=1 ; } public static void main(String[] args){ MyScanner scanner=new MyScanner(); int numOfTests=scanner.nextInt(); for(int i=1 ; i<=numOfTests ; i++){ int n=scanner.nextInt(); Integer[] arr=new Integer[n]; for(int j=0 ; jcollect(null) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := scanner.nextInt() ) ; j := j + 1 ) ; arr := arr->sort() ; var res : boolean ; res := solve(arr, n) ; out.println(if res then "YES" else "NO" endif) ; ) ; i := i + 1 ) ; out.close() ); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import javax.swing.text.html.parser.Entity ; import javax.xml.stream.events.EntityReference ; import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(is); Scanner sc=new Scanner(System.in); long test_case=sc.nextLong(); for(long test=0 ; testtoLong() ; var test : long ; test := 0 ; while test < test_case do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; if (n = 1) then ( if (arr[0+1] = 1) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) else ( arr := arr->sort() ; if (arr[n - 1+1] - arr[n - 2+1] <= 1) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ) ; test := test + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class B { static FastReader sc=null ; public static void main(String[] args){ sc=new FastReader(); int t=sc.nextInt(); for(int tt=0 ; tt1 ? "NO" : "YES"); } } } static int[] ruffleSort(int a[]){ ArrayListal=new ArrayList<>(); for(int i : a)al.add(i); Collections.sort(al); for(int i=0 ; i 1 then "NO" else "YES" endif) ) ) ; tt := tt + 1 ) ); static operation ruffleSort( a : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var al : Sequence(int) ; al := Sequence{} ; for (i : a) do ( al := al->including(i) ; ) ; al := al->sort() ; var i : int ; i := 0 ; while i < a->size() do ( a[i+1] := al->at(i+1) ; ; i := i + 1 ) ; return a ); static operation print( a : Sequence(int)) : void pre: true post: true activity: ( for (e : a) do ( ( OclFile["System.out"].print(e + " ") ) ) ; OclFile["System.out"].println() ); static class FastReader { attribute st : OclIterator := OclIterator.newOclIterator_String(""); attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.nextInt() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n ; n=sc.nextInt(); int arr[]=new int[n]; int fhigh=0 ; int shigh=0 ; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var fhigh : int ; fhigh := 0 ; var shigh : int ; shigh := 0 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; if (shigh <= arr[i+1]) then ( if (fhigh <= arr[i+1]) then ( shigh := fhigh ; fhigh := arr[i+1] ) else ( shigh := arr[i+1] ) ) else skip ) ; i := i + 1 ) ; if (fhigh - shigh < 2) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class test254 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (n = 1) then ( if (a[0+1] <= 1) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) else ( a := a->sort() ; if (a[n - 1+1] - a[n - 2+1] <= 1) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public int[] sortArrayByParityII(int[] A){ int j=1 ; for(int i=0 ; isize() do ( if (A[i+1] mod 2 = 1) then ( while (A[j+1] mod 2 = 1) do j := j+(2) ; ; var tmp : int ; tmp := A[i+1] ; A[i+1] := A[j+1] ; A[j+1] := tmp ) else skip ; ; i := i+(2) ) ; return A ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner cin=new Scanner(System.in); int[] a=new int[2]; while(true){ for(int i=0 ; i<2 ; i++){ a[i]=cin.nextInt(); } if(a[0]==0 && a[1]==0){ break ; } Arrays.sort(a); System.out.printf("%d %d\n",a[0],a[1]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : Sequence(int) ; a := Integer.subrange(1,2)->collect(0) ; while (true) do ( var i : int ; i := 0 ; while i < 2 do ( ( a[i+1] := cin.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (a[0+1] = 0 & a[1+1] = 0) then ( break ) else skip ; a := a->sort() ; OclFile["System.out"].printf("%d %d\n", a[0+1], a[1+1]) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { @ SuppressWarnings("unchecked")public static void main(String[] args){ try(java.util.Scanner sc=new java.util.Scanner(System.in)){ while(sc.hasNextInt()){ for(java.util.Mapmap : new java.util.Map[] { new java.util.HashMap<>()} ){ if(map.put(0,sc.nextInt())==null){ } if(map.put(1,sc.nextInt())==null){ } if(map.get(0)==0 && map.get(1)==0){ } else { if(java.util.Arrays.stream(new String[] { String.valueOf(Math.min(map.get(0),map.get(1)))," ",String.valueOf(Math.max(map.get(0),map.get(1))),"\n" } ).peek(System.out :: print).count()==0){ } } } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : Scanner := Scanner.newScanner(OclFile["System.in"]) ; ( while (sc.hasNextInt()) do ( for (map : Sequence{HashMap.newHashMap()}) do ( ( if (map->at(0, sc.nextInt()) = null) then skip else skip ; if (map->at(1, sc.nextInt()) = null) then skip else skip ; if (map->at(0+1) = 0 & map->at(1+1) = 0) then skip else ( if (java.util.Arrays.stream(Sequence{((Set{map->at(0+1), map->at(1+1)}->min()) + "")," ",((Set{map->at(0+1), map->at(1+1)}->max()) + ""),"\n"}).peek(lambda _pars : OclAny in OclFile["System.out"].print(_pars))->size() = 0) then skip else skip ) ) ) ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Fraction { int num,den ; Fraction(int n,int d){ num=n ; den=d ; } static Fraction maxFraction(Fraction first,Fraction sec){ int a=first.num ; int b=first.den ; int c=sec.num ; int d=sec.den ; int Y=a*d-b*c ; return(Y>0)? first : sec ; } public static void main(String[] args){ Fraction first=new Fraction(3,2); Fraction sec=new Fraction(3,4); Fraction res=maxFraction(first,sec); System.out.println(res.num+"/"+res.den); } } ------------------------------------------------------------ OCL File: --------- class Fraction { attribute num : int; static operation newFraction( n : int, d : int) : Fraction pre: true post: true activity: ( var self : Fraction ; self := createFraction(); self.initialise(n, d); return self ); operation initialise( n : int, d : int) : void pre: true post: true activity: ( num := n ; den := d ); static operation maxFraction( first : Fraction, sec : Fraction) : Fraction pre: true post: true activity: ( var a : int ; a := first.num ; var b : int ; b := first.den ; var c : int ; c := sec.num ; var d : int ; d := sec.den ; var Y : int ; Y := a * d - b * c ; return if (Y > 0) then first else sec endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var first : Fraction ; first := Fraction.newFraction(3, 2) ; var sec : Fraction ; sec := Fraction.newFraction(3, 4) ; var res : Fraction ; res := maxFraction(first, sec) ; OclFile["System.out"].println(res.num + "/" + res.den) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.util.stream.*; public class Main { private static BufferedReader br=null ; public static void main(String[] args){ int n=Integer.parseInt(read(1)[0]); String[] w=read(n); String result="Yes" ; SetwSet=Arrays.stream(w).collect(Collectors.toSet()); if(wSet.size()!=w.length){ result="No" ; } else { for(int i=1 ; istrList=new ArrayList<>(); try { if(br==null){ br=new BufferedReader(new InputStreamReader(System.in)); } for(int i=0 ; itoInteger() ; var w : Sequence(String) ; w := read(n) ; var result : String ; result := "Yes" ; var wSet : Set(String) ; wSet := stream(w).collect(Collectors.toSet()) ; if (wSet->size() /= w->size()) then ( result := "No" ) else ( var i : int ; i := 1 ; while i < w->size() do ( ( if (w[i - 1+1]->at(w[i - 1+1]->size() - 1+1) /= w[i+1]->at(0+1)) then ( result := "No" ) else skip ) ; i := i + 1 ) ) ; OclFile["System.out"].println(result) ; execute close() ; ); static operation read( len : int) : Sequence(String) pre: true post: true activity: ( var strList : Sequence(String) ; strList := Sequence{} ; try ( if (br = null) then ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) else skip ; var i : int ; i := 0 ; while i < len do ( ( strList := strList->including(br.readLine()) ) ; i := i + 1 ) ) catch (e : IOException) do skip return strList->asSequence() ); static operation close() : void pre: true post: true activity: ( try ( if (br /= null) then ( skip ) else skip ) catch (e : IOException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Scanner ; public class practice2 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int l=sc.nextInt(); int c[]=new int[l]; for(int i=0 ; i>j)& 1 ; } int ans=0 ; for(int i=0 ; in-c[i])ans |=1<toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var l : int ; l := sc.getCurrent()->toInteger() ; var c : Sequence(int) ; c := Integer.subrange(1,l)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < l do ( c[j+1] := c[j+1]+(((x/(2->pow(j)))->oclAsType(long)) & 1) ; ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < l do ( if (c[i+1] > n - c[i+1]) then ans := MathLib.bitwiseOr(ans, (1*(2->pow(i)))->oclAsType(long)) ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ try { ArrayListlist=new ArrayList(); BufferedReader d=new BufferedReader(new InputStreamReader(System.in)); while(true){ String s=d.readLine(); if(s!=null && s!="" && ! s.equals("0 0")){ list.add(s); } else { break ; } } for(int i=0 ; ib ? a : b ; System.out.println(tmp+" "+tmp2); } } catch(Throwable e){ e.printStackTrace(); System.out.println("Input Error"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var list : Sequence(String) ; list := Sequence{} ; var d : OclFile ; d := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (true) do ( var s : String ; s := d.readLine() ; if (s /= null & s /= "" & not(s = "0 0")) then ( list := list->including(s) ) else ( break ) ) ; var i : int ; i := 0 ; while i < list->size() do ( ( var s : String ; s := list->at(i+1) ; var sz : OclIterator ; sz := OclIterator.newOclIterator_String(s) ; var a : int ; a := (sz.next())->toInteger() ; var b : int ; b := (sz.next())->toInteger() ; var tmp : int ; var tmp2 : int ; tmp := if a < b then a else b endif ; tmp2 := if a > b then a else b endif ; OclFile["System.out"].println(tmp + " " + tmp2) ; ) ; i := i + 1 ) ) catch (e : OclException) do ( e.printStackTrace() ; OclFile["System.out"].println("Input Error") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc ; static final int INF=1<<28 ; static final double EPS=1e-9 ; void run(){ sc=new Scanner(System.in); for(; ; ){ int x=sc.nextInt(); int y=sc.nextInt(); if(x==0 && y==0)break ; println(min(x,y)+" "+max(x,y)); } sc.close(); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static attribute INF : int := (1*(2->pow(28)))->oclAsType(long); static attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (x = 0 & y = 0) then break else skip ; execute println(Set{x, y}->min() + " " + Set{x, y}->max()) ) ) ; skip ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ int i,j,swap ; Scanner in=new Scanner(System.in); ArrayListarray=new ArrayList(); ArrayListarray2=new ArrayList(); for(i=0 ; in.hasNext(); i++){ array.add(in.nextInt()); if(i % 2==1)if(array.get(i-1)==0 && array.get(i)==0)break ; } for(j=0 ; jincluding(in.getCurrent()->toInteger()) ; if (i mod 2 = 1) then if (array->at(i - 1+1) = 0 & array->at(i+1) = 0) then break else skip ; else skip ) ; i := i + 1 ) ; j := 0 ; while j < i - 1 do ( ( if (array->at(j+1) <= array->at(j + 1+1)) then OclFile["System.out"].println(array->at(j+1) + " " + array->at(j + 1+1)) ; else OclFile["System.out"].println(array->at(j + 1+1) + " " + array->at(j+1)) ; ) ; j := j + 2 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int[] n=new int[9]; char[] list=sc.nextLine().toCharArray(); for(int i : list){ n[i-'1']++; } Listresult=new ArrayList<>(); for(int i=0 ; i<9 ; i++){ for(int j=0 ; j<9 ; j++){ if(n[i]<4 &&(n[j]>=2 || n[i]>=1)){ int[] temp=n.clone(); temp[i]++; temp[j]-=2 ; for(int k=0 ; k<7 ; k++){ if((temp[k]==1 || temp[k]==4)&& temp[k+1]>0 && temp[k+2]>0){ temp[k]--; temp[k+1]--; temp[k+2]--; } if(temp[k]==2 && temp[k+1]>=2 && temp[k+2]>=2){ temp[k]-=2 ; temp[k+1]-=2 ; temp[k+2]-=2 ; } } boolean f=true ; for(int k : temp){ if(k % 3!=0){ f=false ; break ; } } if(f){ result.add(i+1); break ; } } } } if(result.isEmpty()){ System.out.println(0); } else { for(int i=0 ; icollect(0) ; var list : Sequence(String) ; list := sc.nextLine()->characters() ; for (i : list) do ( ( n[i - ('1')->char2byte()+1] := n[i - ('1')->char2byte()+1] + 1 ) ) ; var result : Sequence(int) ; result := Sequence{} ; var i : int ; i := 0 ; while i < 9 do ( ( var j : int ; j := 0 ; while j < 9 do ( ( if (n[i+1] < 4 & (n[j+1] >= 2 or n[i+1] >= 1)) then ( var temp : Sequence(int) ; temp := n->copy() ; temp[i+1] := temp[i+1] + 1 ; temp[j+1] := temp[j+1]-(2) ; var k : int ; k := 0 ; while k < 7 do ( ( if ((temp[k+1] = 1 or temp[k+1] = 4) & temp[k + 1+1] > 0 & temp[k + 2+1] > 0) then ( temp[k+1] := temp[k+1] - 1 ; temp[k + 1+1] := temp[k + 1+1] - 1 ; temp[k + 2+1] := temp[k + 2+1] - 1 ) else skip ; if (temp[k+1] = 2 & temp[k + 1+1] >= 2 & temp[k + 2+1] >= 2) then ( temp[k+1] := temp[k+1]-(2) ; temp[k + 1+1] := temp[k + 1+1]-(2) ; temp[k + 2+1] := temp[k + 2+1]-(2) ) else skip ) ; k := k + 1 ) ; var f : boolean ; f := true ; for (k : temp) do ( ( if (k mod 3 /= 0) then ( f := false ; break ) else skip ) ) ; if (f) then ( result := result->including(i + 1) ; break ) else skip ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (result->isEmpty()) then ( OclFile["System.out"].println(0) ) else ( var i : int ; i := 0 ; while i < result->size() do ( ( OclFile["System.out"].print(if i < result->size() - 1 then result->at(i+1) + " " else result->at(i+1) + "\n" endif) ) ; i := i + 1 ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int[] n=new int[9]; char[] list=sc.nextLine().toCharArray(); for(int i : list){ n[i-'1']++; } Listresult=new ArrayList<>(); for(int i=0 ; i<9 ; i++){ next : for(int j=0 ; j<9 ; j++){ if(n[i]<4 &&(n[j]>=2 || n[i]>=1)){ int[] temp=n.clone(); temp[i]++; temp[j]-=2 ; for(int k=0 ; k<7 ; k++){ process(temp,k,1); process(temp,k,2); if(temp[k] % 3!=0){ continue next ; } } if(temp[7] % 3==0){ result.add(i+1); break ; } } } } if(result.isEmpty()){ System.out.println(0); } else { for(int i=0 ; i=n && a[p+2]>=n){ a[p]-=n ; a[p+1]-=n ; a[p+2]-=n ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var n : Sequence(int) ; n := Integer.subrange(1,9)->collect(0) ; var list : Sequence(String) ; list := sc.nextLine()->characters() ; for (i : list) do ( ( n[i - ('1')->char2byte()+1] := n[i - ('1')->char2byte()+1] + 1 ) ) ; var result : Sequence(int) ; result := Sequence{} ; var i : int ; i := 0 ; while i < 9 do ( ( var j : int ; j := 0 ; while j < 9 do ( ( if (n[i+1] < 4 & (n[j+1] >= 2 or n[i+1] >= 1)) then ( var temp : Sequence(int) ; temp := n->copy() ; temp[i+1] := temp[i+1] + 1 ; temp[j+1] := temp[j+1]-(2) ; var k : int ; k := 0 ; while k < 7 do ( ( execute process(temp, k, 1) ; execute process(temp, k, 2) ; if (temp[k+1] mod 3 /= 0) then ( continue ) else skip ) ; k := k + 1 ) ; if (temp[7+1] mod 3 = 0) then ( result := result->including(i + 1) ; break ) else skip ; ) else skip ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; if (result->isEmpty()) then ( OclFile["System.out"].println(0) ) else ( var i : int ; i := 0 ; while i < result->size() do ( ( OclFile["System.out"].print(result->at(i+1) + (if i < result->size() - 1 then " " else "\n" endif)) ) ; i := i + 1 ) ) ; ) ); static operation process( a : Sequence(int), p : int, n : int) : void pre: true post: true activity: ( if (a[p+1] mod 3 = n & a[p + 1+1] >= n & a[p + 2+1] >= n) then ( a[p+1] := a[p+1]-(n) ; a[p + 1+1] := a[p + 1+1]-(n) ; a[p + 2+1] := a[p + 2+1]-(n) ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; while((line=br.readLine())!=null){ int[] num=new int[10]; boolean flag=false ; String ans="0" ; for(int i=0 ; i<13 ; i++){ num[(int)(line.charAt(i)-'0')]++; } outside : for(int i=1 ; i<=9 ; i++){ if(num[i]==4){ continue ; } for(int j=1 ; j<=9 ; j++){ int[] n=num.clone(); n[i]++; if(n[j]<2){ continue ; } n[j]-=2 ; if(check(n)){ if(! flag){ System.out.print(i); ans="" ; flag=true ; } else { System.out.print(" "+i); } continue outside ; } } } System.out.println(ans); } } private static boolean check(int[] n){ int amari=0 ; for(int i=1 ; i<=7 ; i++){ if(n[i]<0){ return false ; } amari=n[i] % 3 ; n[i]-=amari ; n[i+1]-=amari ; n[i+2]-=amari ; } if((n[8]==3 || n[8]==0)&&(n[9]==3 || n[9]==0)){ return true ; } return false ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := "" ; line := br.readLine() ; while ((line) /= null) do ( skip ; ( var num : Sequence(int) ; num := Integer.subrange(1,10)->collect(0) ; var flag : boolean ; flag := false ; var ans : String ; ans := "0" ; var i : int ; i := 0 ; while i < 13 do ( ( num[(line->at(i+1) - ('0')->char2byte())->oclAsType(int)+1] := num[(line->at(i+1) - ('0')->char2byte())->oclAsType(int)+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= 9 do ( ( if (num[i+1] = 4) then ( continue ) else skip ; var j : int ; j := 1 ; while j <= 9 do ( ( var n : Sequence(int) ; n := num->copy() ; n[i+1] := n[i+1] + 1 ; if (n[j+1] < 2) then ( continue ) else skip ; n[j+1] := n[j+1]-(2) ; if (check(n)) then ( if (not(flag)) then ( OclFile["System.out"].print(i) ; ans := "" ; flag := true ) else ( OclFile["System.out"].print(" " + i) ) ; continue ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; line := br.readLine() ; ) ); static operation check( n : Sequence(int)) : boolean pre: true post: true activity: ( var amari : int ; amari := 0 ; var i : int ; i := 1 ; while i <= 7 do ( ( if (n[i+1] < 0) then ( return false ) else skip ; amari := n[i+1] mod 3 ; n[i+1] := n[i+1]-(amari) ; n[i + 1+1] := n[i + 1+1]-(amari) ; n[i + 2+1] := n[i + 2+1]-(amari) ; ) ; i := i + 1 ) ; if ((n[8+1] = 3 or n[8+1] = 0) & (n[9+1] = 3 or n[9+1] = 0)) then ( return true ) else skip ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { static char[] array=new char[13]; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line=null ; try { while((line=br.readLine())!=null){ line=line.trim(); array=line.toCharArray(); int[] numCount=new int[10]; for(int i=0 ; i=0 && num[9]>=0){ if(ans.equals("0")){ ans=Integer.toString(i); } else { ans+=" "+Integer.toString(i); } break searchHead ; } } } System.out.println(ans); } br.close(); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute array : Sequence(String) := Integer.subrange(1,13)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := null ; try ( line := br.readLine() ; while ((line) /= null) do ( skip ; ( line := line->trim() ; array := line->characters() ; var numCount : Sequence(int) ; numCount := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < array->size() do ( ( numCount[array[i+1] - ('0')->char2byte()+1] := numCount[array[i+1] - ('0')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var ans : String ; ans := "0" ; var i : int ; i := 1 ; while i <= 9 do ( ( if (numCount[i+1] = 4) then continue else skip ; var j : int ; j := 1 ; while j <= 9 do ( ( var num : Sequence(int) ; num := numCount->copy() ; num[i+1] := num[i+1] + 1 ; if (num[j+1] - 2 < 0) then continue else skip ; num[j+1] := num[j+1]-(2) ; var k : int ; k := 1 ; while k <= 7 do ( ( if (num[k+1] < 0) then continue else skip ; var surplus : int ; surplus := num[k+1] mod 3 ; if (surplus /= 0) then ( num[k+1] := num[k+1]-(surplus) ; num[k + 1+1] := num[k + 1+1]-(surplus) ; num[k + 2+1] := num[k + 2+1]-(surplus) ) else skip ) ; k := k + 1 ) ; if (((num[8+1] mod 3) + (num[9+1] mod 3)) = 0 & num[8+1] >= 0 & num[9+1] >= 0) then ( if (ans = "0") then ( ans := ((i) + "") ) else ( ans := ans+(" " + ((i) + "")) ) ; break ) else skip ; ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; line := br.readLine() ; ) ; skip ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.io.IOException ; public class A { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int n=Integer.parseInt(br.readLine()); String s=br.readLine(); int ans=n ; for(int i=0 ; itoInteger() ; var s : String ; s := br.readLine() ; var ans : int ; ans := n ; var i : int ; i := 0 ; while i < n - 1 do ( ( if ((s->at(i+1) = 'U' & s->at(i + 1+1) = 'R') or (s->at(i+1) = 'R' & s->at(i + 1+1) = 'U')) then ( ans := ans - 1 ; i := i + 1 ) else skip ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String S=sc.next(); sc.close(); char[] s=S.toCharArray(); int answer=n ; for(int i=0 ; itoInteger() ; var S : String ; S := sc.getCurrent() ; skip ; var s : Sequence(String) ; s := S->characters() ; var answer : int ; answer := n ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (s[i+1] /= s[i + 1+1]) then ( i := i + 1 ; answer := answer - 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); int sL=s.length(); String sT=s ; for(int i=0 ; isize() ; var sT : String ; sT := s ; var i : int ; i := 0 ; while i < s->size() / 2 do ( ( sL := sL-(2) ; sT := sT.subrange(0+1,sL) ; if (sT.subrange(0+1,sL / 2) = sT.subrange(sL / 2+1,sL / 2)) then ( OclFile["System.out"].println(sL) ; break ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p265 implements EulerSolution { public static void main(String[] args){ System.out.println(new p265().run()); } private static final int N=5 ; private static final int TWO_POW_N=1<>>i)& MASK); return seen==FULL_SET ; } } ------------------------------------------------------------ OCL File: --------- class p265 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p265.newp265().run()) ); static attribute N : int := 5; static attribute TWO_POW_N : int := (1*(2->pow(N)))->oclAsType(long); operation run() : String pre: true post: true activity: ( var sum : long ; sum := 0 ; var start : int ; start := ((1*(2->pow((TWO_POW_N - N - 1))))->oclAsType(long)) + 1 ; var end : int ; end := (1*(2->pow((TWO_POW_N - N))))->oclAsType(long) ; var i : int ; i := start ; while i < end do ( ( if (checkArrangement(i)) then sum := sum+(i) ; else skip ) ; i := i+(2) ) ; return ((sum) + "") ); static attribute MASK : int := TWO_POW_N - 1; static attribute FULL_SET : int := ((1L*(2->pow(TWO_POW_N)))->oclAsType(long))->oclAsType(int) - 1; static operation checkArrangement( digits : int) : boolean pre: true post: true activity: ( var seen : int ; seen := 0 ; var temp : long ; temp := MathLib.bitwiseOr((MathLib.bitwiseAnd(digits,0xFFFFFFFFL)),(((MathLib.bitwiseAnd(digits,0xFFFFFFFFL))*(2->pow(TWO_POW_N)))->oclAsType(long))) ; var i : int ; i := 0 ; while i < TWO_POW_N do ( seen := MathLib.bitwiseOr(seen, (1*(2->pow((MathLib.bitwiseAnd(((temp/(2->pow(i)))->oclAsType(long))->oclAsType(int),MASK)))))->oclAsType(long)) ; ; i := i + 1 ) ; return seen = FULL_SET ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int n=nextInt(); String s=next(); s=s.replaceAll("UR|RU","D"); out.println(s.length()); out.close(); } static BufferedReader br ; static StringTokenizer st=new StringTokenizer(""); static String next()throws IOException { while(! st.hasMoreTokens()){ st=new StringTokenizer(br.readLine()); } return st.nextToken(); } static int nextInt()throws IOException { return Integer.parseInt(next()); } static long nextLong()throws IOException { return Long.parseLong(next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := nextInt() ; var s : String ; s := next() ; s := s.replaceAllMatches("UR|RU", "D" ) ; skip ; skip ; ); static attribute br : OclFile; static attribute st : OclIterator := OclIterator.newOclIterator_String(""); static operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class road { static int row ; static int col ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char ch[]=sc.next().toCharArray(); int sum=0 ; int i=0 ; for(i=0 ; i>arr){ b[i]=true ; for(int j : arr.get(i)){ if(! b[j]){ dfs(b,j,arr); } } } } ------------------------------------------------------------ OCL File: --------- class road { static attribute row : int; static attribute col : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var ch : Sequence(String) ; ch := sc.getCurrent()->characters() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; i := 0 ; while i < n - 1 do ( ( if (ch[i+1] = 'U' & ch[i + 1+1] = 'R') then ( sum := sum + 1 ; i := i + 1 ) else if (ch[i+1] = 'R' & ch[i + 1+1] = 'U') then ( sum := sum + 1 ; i := i + 1 ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(n - (sum)->char2byte()) ; ); static operation dfs( b : Sequence(boolean), i : int, arr : Sequence(Sequence(int))) : void pre: true post: true activity: ( b[i+1] := true ; for (j : arr->at(i+1)) do ( ( if (not(b[j+1])) then ( execute dfs(b, j, arr) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static final int N=100005 ; static int[] phi ; static int[] S ; static void computeTotient(){ for(int i=1 ; icollect(0) ; S := Integer.subrange(1,N)->collect(0) ; execute CoPrimes() ; var q : Sequence(int) ; q := Sequence{3,4} ; var n : int ; n := q->size() ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].println("Number of unordered coprime\n" + "pairs of integers from 1 to " + q[i+1] + " are " + S[q[i+1]+1]) ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Map.Entry ; import java.util.TreeMap ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; while((line=br.readLine())!=null && ! line.isEmpty()){ TreeMapproduct=new TreeMap(); int n=Integer.parseInt(line); int name,quant,delim ; for(int i=0 ; ie : product.entrySet()){ sb.append(itos(e.getKey().intValue())+" "+e.getValue().toString()+"\n"); } System.out.print(sb.toString()); } } static int stoi(String str){ int result=0 ; for(int i=0 ; i=0 ; i--){ c=num>>5*i & 31 ; if(c!=0){ str[len]=(char)(c+'@'); len++; } } return(new String(Arrays.copyOf(str,len))); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := "" ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( var product : Map(int,int) ; product := Map{} ; var n : int ; n := (line)->toInteger() ; var name : int ; var quant : int ; var delim : int ; var i : int ; i := 0 ; while i < n do ( ( line := br.readLine() ; delim := line->indexOf(' ')-1 ; name := stoi(line.subrange(0+1,delim)) ; quant := (line.subrange(delim + 1+1,delim + 1))->toInteger() ; if (product->keys()->includes(name)) then ( product := product->union(Map{name |-> product->at(name) + quant}) ) else ( product := product->union(Map{name |-> quant}) ) ; ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; for (e : product->asSet()) do ( ( sb := sb + StringLib.newString(itos(e.getKey()->oclAsType(int)) + " " + e.getValue()+"" + "\n") ) ) ; OclFile["System.out"].print(sb+"") ; ) ; line := br.readLine() ; ) ); static operation stoi( str : String) : int pre: true post: true activity: ( var result : int ; result := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( result := result*(2->pow(5)) ; result := result+((str->at(i+1) - ('@')->char2byte())) ) ; i := i + 1 ) ; return result ); static operation itos( num : int) : String pre: true post: true activity: ( var str : Sequence(String) ; str := Integer.subrange(1,5)->collect(0) ; var c : int ; var len : int ; len := 0 ; var i : int ; i := 4 ; while i >= 0 do ( ( c := MathLib.bitwiseAnd((num/(2->pow(5 * i)))->oclAsType(long),31) ; if (c /= 0) then ( str[len+1] := (c + '@')->oclAsType(String) ; len := len + 1 ) else skip ) ; i := i - 1 ) ; return (StringLib.newString(str.subrange(1,len))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int n=sc.nextInt(); TreeMapmap=new TreeMap<>(); Listkey=new ArrayList<>(); String s ; int a ; for(int i=0 ; iout.println(e+" "+map.get(e))); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var map : Map(String,int) ; map := Map{} ; var key : Sequence(String) ; key := Sequence{} ; var s : String ; var a : int ; var i : int ; i := 0 ; while i < n do ( ( s := sc.getCurrent() ; a := sc.getCurrent()->toInteger() ; if (not(map->keys()->includes(s))) then ( map := map->union(Map{s |-> a}) ; key := key->including(s) ) else ( map := map->union(Map{s |-> map->at(s) + a}) ) ) ; i := i + 1 ) ; key := key.sort(Comparator.comparingInt(lambda _pars : OclAny in String.newString().length(_pars)).thenComparing(Comparator.naturalOrder())) ; for e : key do ( out.println(e + " " + map->at(e))) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); ArrayListm=new ArrayList(); int s[]=new int[n]; m.add(scan.next()); s[0]=scan.nextInt(); boolean t=false ; for(int i=1 ; imap=new HashMap(); for(int i=0 ; im.get(j+1).length()){ String o=m.get(j); m.set(j,m.get(j+1)); m.set(j+1,o); } } } for(int i=0 ; itoInteger() ; var m : Sequence(String) ; m := Sequence{} ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; m := m->including(scan.getCurrent()) ; s[0+1] := scan.getCurrent()->toInteger() ; var t : boolean ; t := false ; var i : int ; i := 1 ; while i < n do ( ( var mm : String ; mm := scan.getCurrent() ; var j : int ; j := 0 ; while j < m->size() do ( ( if (m->at(j+1) = mm) then ( s[j+1] := s[j+1]+(scan.getCurrent()->toInteger()) ; t := true ; break ) else skip ) ; j := j + 1 ) ; if (t = false) then ( m := m->including(mm) ; s[m->size() - 1+1] := scan.getCurrent()->toInteger() ) else skip ; t := false ) ; i := i + 1 ) ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < m->size() do ( ( map := map->union(Map{m->at(i+1) |-> s[i+1]->oclAsType(int)}) ) ; i := i + 1 ) ; m := m->sort() ; var i : int ; i := 0 ; while i < m->size() do ( ( var j : int ; j := 0 ; while j < m->size() - 1 - i do ( ( if (m->at(j+1)->size() > m->at(j + 1+1)->size()) then ( var o : String ; o := m->at(j+1) ; m := m.setAt(j+1,m->at(j + 1+1)) ; m := m.setAt(j + 1+1,o) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m->size() do ( ( OclFile["System.out"].println(m->at(i+1) + " " + map->at(m->at(i+1))) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Comparator ; import java.util.Map.Entry ; import java.util.Scanner ; import java.util.SortedMap ; import java.util.TreeMap ; public class Main { final static C SINGLE_C=new C(); static class C implements Comparator{ private C(){ }; @ Override public int compare(String o1,String o2){ int result=o1.length()-o2.length(); if(result==0){ result=o1.compareTo(o2); } return result ; } } public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] value=new int[n]; int nextIndex=0 ; SortedMapindexMap=new TreeMap(SINGLE_C); while(n-->0){ String name=in.next(); int index ; if(! indexMap.containsKey(name)){ index=nextIndex ; indexMap.put(name,Integer.valueOf(nextIndex++)); } else { index=indexMap.get(name).intValue(); } value[index]+=in.nextInt(); } for(Entrye : indexMap.entrySet()){ System.out.println(e.getKey()+" "+value[e.getValue().intValue()]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute SINGLE_C : C := C.newC(); static class C implements Function(,(,boolean)) { static operation newC() : C pre: true post: true activity: ( var self : C ; self := createC(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: skip; operation compare( o1 : String, o2 : String) : int pre: true post: true activity: ( var result : int ; result := o1->size() - o2->size() ; if (result = 0) then ( result := o1->compareTo(o2) ) else skip ; return result ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var value : Sequence(int) ; value := Integer.subrange(1,n)->collect(0) ; var nextIndex : int ; nextIndex := 0 ; var indexMap : Map(String,int) ; indexMap := Map{}->union(SINGLE_C) ; while (n > 0) do ( n := n - 1 ; skip ; ( var name : String ; name := in.getCurrent() ; var index : int ; if (not(indexMap->keys()->includes(name))) then ( index := nextIndex ; indexMap := indexMap->union(Map{name |-> (nextIndex)->toInteger()}) ) else ( index := indexMap->at(name)->oclAsType(int) ) ; value[index+1] := value[index+1]+(in.getCurrent()->toInteger()) ) ; ) ; for (e : indexMap->asSet()) do ( ( OclFile["System.out"].println(e.getKey() + " " + value[e.getValue()->oclAsType(int)+1]) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Math.*; public class Main { int INF=1<<28 ; double EPS=1e-10 ; void run(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); HashMapmap=new HashMap(); for(int i=0 ; ientry : map.entrySet()){ vs[i++]=new V(entry.getKey(),entry.getValue()); } sort(vs); for(int j=0 ; j{ String s ; int t ; V(String s,int t){ this.s=s ; this.t=t ; } @ Override public int compareTo(V o){ if(s.length()==o.s.length())return s.compareTo(o.s); return s.length()-o.s.length(); } } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute EPS : double := 1e-10; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var key : String ; key := sc.getCurrent() ; var val : int ; val := sc.getCurrent()->toInteger() ; if (map->keys()->includes(key)) then map := map->union(Map{key |-> map->at(key) + val}) ; else map := map->union(Map{key |-> val}) ; ) ; i := i + 1 ) ; var vs : Sequence(V) ; vs := Integer.subrange(1,map.size())->collect(null) ; var i : int ; i := 0 ; for (entry : map->asSet()) do ( ( vs[i+1] := V.newV(entry.getKey(), entry.getValue()) ; i := i + 1 ) ) ; execute sort(vs) ; var j : int ; j := 0 ; while j < vs->size() do ( ( OclFile["System.out"].println(vs[j+1].s + " " + vs[j+1].t) ) ; j := j + 1 ) ; ); class V implements Comparable { attribute s : String; attribute t : int; static operation newV( s : String, t : int) : V pre: true post: true activity: ( var self : V ; self := createV(); self.initialise(s, t); return self ); operation initialise( s : String, t : int) : void pre: true post: true activity: ( self.s := s ; self.t := t ); operation compareTo( o : V) : int pre: true post: true activity: ( if (s->size() = o.s->size()) then return s->compareTo(o.s) else skip ; return s->size() - o.s->size() ); } operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class a { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=n<<1 ; ArrayListar=new ArrayList(); for(int i=0 ; itoInteger() ; var m : int ; m := (n*(2->pow(1)))->oclAsType(long) ; var ar : Sequence(long) ; ar := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ar := ar->including(in.getCurrent()->toLong()) ; ; i := i + 1 ) ; ar := ar->sort() ; var min1 : long ; min1 := (ar->at(n - 1+1) - ar->at(0+1)) * (ar->at(m - 1+1) - ar->at(n+1)) ; var min2 : long ; min2 := "9223372036854775807"->toLong() ; var extreme : long ; extreme := ar->at(m - 1+1) - ar->at(0+1) ; var i : int ; i := 0 ; while i <= n do ( ( var x : long ; x := ar->at(n + i - 1+1) - ar->at(i+1) ; min2 := Set{min2, x}->min() ) ; i := i + 1 ) ; min2 := extreme * min2 ; OclFile["System.out"].println(Set{min1, min2}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.OutputStream ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); Task solver=new Task(); solver.solve(1,in,out); out.close(); } static class Task { public void solve(int testNumber,InputReader in,PrintWriter out){ String S=in.next(); for(int i=S.length()-2 ; i>=0 ; i-=2){ if(S.substring(0,i/2).equals((S.substring(i/2,i)))){ out.println(i); break ; } } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public char nextChar(){ return next().charAt(0); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : Task ; solver := Task.newTask() ; solver.solve(1, in, out) ; skip ; ); static class Task { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var S : String ; S := in.next() ; var i : int ; i := S->size() - 2 ; while i >= 0 do ( ( if (S.subrange(0+1,i / 2) = (S.subrange(i / 2+1,i))) then ( skip ; break ) else skip ) ; i := i-(2) ) ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextChar() : String pre: true post: true activity: ( return next()->at(0+1) ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class CodeForce1012A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt()*2 ; long[] data=new long[n]; for(int i=0 ; iw*h){ min=w*h ; } } System.out.println(min); } } ------------------------------------------------------------ OCL File: --------- class CodeForce1012A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() * 2 ; var data : Sequence(long) ; data := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( data[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; data := data->sort() ; var half : int ; half := n / 2 ; var min : long ; min := (data[half - 1+1] - data[0+1]) * (data[n - 1+1] - data[half+1]) ; var w : long ; w := data[n - 1+1] - data[0+1] ; var i : int ; i := 1 ; while i < half do ( ( var h : long ; h := data[i + half - 1+1] - data[i+1] ; if (min > w * h) then ( min := w * h ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.List ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); LunlunNumber solver=new LunlunNumber(); solver.solve(1,in,out); out.close(); } static final class LunlunNumber { public void solve(int __,InputReader in,PrintWriter out){ int n=in.nextInt(); Listqueue=new ArrayList<>(n); for(long i=1 ; i<10 ; ++i){ queue.add(i); } for(int head=0 ; queue.size()including(i) ) ; i := i + 1 ) ; var head : int ; head := 0 ; while queue->size() < n do ( ( var current : long ; current := queue->at(head+1) ; if (current mod 10 /= 0) then ( queue := queue->including(current * 10 + (current mod 10 - 1)) ) else skip ; queue := queue->including(current * 10 + (current mod 10)) ; if (current mod 10 /= 9) then ( queue := queue->including(current * 10 + (current mod 10 + 1)) ) else skip ) ; head := head + 1 ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( in : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(readLine()) ) ; return tokenizer.next() ); operation readLine() : String pre: true post: true activity: ( var line : String ; try ( line := reader.readLine() ) catch (e : IOException) do ( error ProgramException(e) ) return line ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A1012 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); Integer[] A=new Integer[2*N]; for(int n=0 ; ntoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,2 * N)->collect(null) ; var n : int ; n := 0 ; while n < A->size() do ( ( A[n+1] := in.getCurrent()->toInteger() ) ; n := n + 1 ) ; A := A->sort() ; var w : long ; w := A[N - 1+1] - A[0+1] ; var h : long ; h := A[2 * N - 1+1] - A[N+1] ; var answer : long ; answer := w * h ; w := A[2 * N - 1+1] - A[0+1] ; var n : int ; n := 1 ; while n < N do ( ( h := A[n + N - 1+1] - A[n+1] ; answer := Set{answer, h * w}->min() ) ; n := n + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { private static final FastReader fr=new FastReader(); public static void main(String[] args)throws IOException { BufferedWriter output=new BufferedWriter(new OutputStreamWriter(System.out)); StringBuilder sb=new StringBuilder(); int testCases=fr.nextInt(); for(int testCase=1 ; testCase<=testCases ; testCase++){ int n=fr.nextInt(); if(solve(n))sb.append("YES\n"); else sb.append("NO\n"); } output.write(sb.toString()); output.flush(); } private static boolean solve(int n){ if(n % 11==0)return true ; for(int i=0 ; i<=10 ; i++){ for(int j=0 ; j<=10 ; j++){ for(int k=0 ; k<=10 ; k++){ if(n-i*111-j*11111-k*1111111<0)break ; if((n-i*111-j*11111-k*1111111)% 11==0)return true ; } } } return false ; } } class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } ------------------------------------------------------------ OCL File: --------- class Solution { static attribute fr : FastReader := FastReader.newFastReader(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var output : OclFile ; output := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var sb : String ; sb := StringLib.newString() ; var testCases : int ; testCases := fr.nextInt() ; var testCase : int ; testCase := 1 ; while testCase <= testCases do ( ( var n : int ; n := fr.nextInt() ; if (solve(n)) then sb := sb + StringLib.newString("YES\n") ; else sb := sb + StringLib.newString("NO\n") ; ) ; testCase := testCase + 1 ) ; skip ; skip ; ); static operation solve( n : int) : boolean pre: true post: true activity: ( if (n mod 11 = 0) then return true else skip ; var i : int ; i := 0 ; while i <= 10 do ( ( var j : int ; j := 0 ; while j <= 10 do ( ( var k : int ; k := 0 ; while k <= 10 do ( ( if (n - i * 111 - j * 11111 - k * 1111111 < 0) then break else skip ; if ((n - i * 111 - j * 11111 - k * 1111111) mod 11 = 0) then return true else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return false ); } class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Z_ccc_6_2 { static int t ; static int x ; static String ans[]; public static void main(String args[])throws IOException { InputStreamReader r=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); t=Integer.parseInt(br.readLine()); ans=new String[t]; for(int i=0 ; itoInteger() ; ans := Integer.subrange(1,t)->collect(null) ; var i : int ; i := 0 ; while i < t do ( ( var boo : boolean ; boo := false ; x := (br.readLine())->toInteger() ; var j : int ; j := 0 ; while j * 111 <= x do ( ( if ((x - 111 * j) mod 11 = 0) then ( boo := true ; break ) else skip ) ; j := j + 1 ) ; if (boo) then ( ans[i+1] := "YES" ) else ( ans[i+1] := "NO" ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t do ( ( OclFile["System.out"].println(ans[i+1]) ) ; i := i + 1 ) ; ); } { static attribute t : int; static attribute x : int; static attribute ans : Sequence(String); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(r) ; t := (br.readLine())->toInteger() ; ans := Integer.subrange(1,t)->collect(null) ; var i : int ; i := 0 ; while i < t do ( ( var boo : boolean ; boo := false ; x := (br.readLine())->toInteger() ; var j : int ; j := 0 ; while j * 111 <= x do ( ( if ((x - 111 * j) mod 11 = 0) then ( boo := true ; break ) else skip ) ; j := j + 1 ) ; if (boo) then ( ans[i+1] := "YES" ) else ( ans[i+1] := "NO" ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t do ( ( OclFile["System.out"].println(ans[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ Scanner in=new Scanner(System.in); String s=in.nextLine(); StringBuilder s1=new StringBuilder(s); for(int i=s.length()-1 ; i>=0 ; i--){ s1.append(s.charAt(i)); } System.out.println(s1); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := in.nextLine() ; var s1 : String ; s1 := StringLib.newString(s) ; var i : int ; i := s->size() - 1 ; while i >= 0 do ( ( s1 := s1 + StringLib.newString(s->at(i+1)) ) ; i := i - 1 ) ; OclFile["System.out"].println(s1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class A { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); String s=sc.next(); out.println(s+new StringBuilder(s).reverse()); out.close(); } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public String nextLine()throws IOException { return br.readLine(); } public boolean ready()throws IOException { return br.ready(); } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var s : String ; s := sc.getCurrent() ; skip ; skip ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile(s))) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Test { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String str=sc.next(); str+=getReverse(str); System.out.println(str); } sc.close(); } private static String getReverse(String str){ String revString="" ; for(int i=str.length()-1 ; i>=0 ; i--)revString+=str.charAt(i)+"" ; return revString ; } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var str : String ; str := sc.getCurrent() ; str := str+(getReverse(str)) ; OclFile["System.out"].println(str) ) ; skip ); static operation getReverse( str : String) : String pre: true post: true activity: ( var revString : String ; revString := "" ; var i : int ; i := str->size() - 1 ; while i >= 0 do ( revString := revString+(str->at(i+1) + "") ; ; i := i - 1 ) ; return revString ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static void main(String[] args){ Scanner s=new Scanner(System.in); String str=s.next(); String rev="" ; for(int i=0 ; isize() do ( ( rev := str->at(i+1) + rev ) ; i := i + 1 ) ; str := str + rev ; OclFile["System.out"].println(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static int fact(int N){ int i,product=1 ; for(i=1 ; i<=N ; i++)product=product*i ; return product ; } public static int nthTerm(int N){ return(N*N)*fact(N); } public static void main(String[] args){ int N=4 ; System.out.println(nthTerm(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fact( N : int) : int pre: true post: true activity: ( var i : int ; var product : int ; product := 1 ; i := 1 ; while i <= N do ( product := product * i ; ; i := i + 1 ) ; return product ); static operation nthTerm( N : int) : int pre: true post: true activity: ( return (N * N) * fact(N) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 4 ; OclFile["System.out"].println(nthTerm(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ThreeSwimmers { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var p : long ; p := sc.getCurrent()->toLong() ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var c : long ; c := sc.getCurrent()->toLong() ; var x : long ; x := a - p mod a ; var y : long ; y := b - p mod b ; var z : long ; z := c - p mod c ; if (p mod a = 0 or p mod b = 0 or p mod c = 0) then ( OclFile["System.out"].println("0") ) else ( var result : long ; result := Set{Set{x, y}->min(), z}->min() ; var res : long ; res := result->oclAsType(long) ; OclFile["System.out"].println(res) ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1492 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ long p=scanner.nextLong(); long a=scanner.nextLong(); long b=scanner.nextLong(); long c=scanner.nextLong(); long a1=(p % a==0)? 0 : a-p % a ; long b1=(p % b==0)? 0 : b-p % b ; long c1=(p % c==0)? 0 : c-p % c ; System.out.println(Math.min(Math.min(a1,b1),c1)); } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class A1492 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var p : long ; p := scanner.getCurrent()->toLong() ; var a : long ; a := scanner.getCurrent()->toLong() ; var b : long ; b := scanner.getCurrent()->toLong() ; var c : long ; c := scanner.getCurrent()->toLong() ; var a1 : long ; a1 := if (p mod a = 0) then 0 else a - p mod a endif ; var b1 : long ; b1 := if (p mod b = 0) then 0 else b - p mod b endif ; var c1 : long ; c1 := if (p mod c = 0) then 0 else c - p mod c endif ; OclFile["System.out"].println(Set{Set{a1, b1}->min(), c1}->min()) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int head=0 ; static void f(int i,char[] r){ if(i==head){ if(r[i]=='9'){ ++head ; f(i+1,r); r[i]=(char)Math.max('0',r[i+1]-1); } else { ++r[i]; } } else if(r[i]=='9' || Math.abs(++r[i]-r[i+1])>1){ f(i+1,r); r[i]=(char)Math.max('0',r[i+1]-1); } } public static void main(String[] args){ Scanner s=new Scanner(System.in); char[] r=new char[11]; Arrays.fill(r,'0'); for(int k=s.nextInt(); k>0 ; --k){ f(0,r); } System.out.println(new StringBuilder(String.valueOf(r)).reverse().toString().replaceFirst("^0+","")); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute head : int := 0; static operation f( i : int, r : Sequence(String)) : void pre: true post: true activity: ( if (i = head) then ( if (r[i+1] = '9') then ( head := head + 1 ; execute f(i + 1, r) ; r[i+1] := Set{'0', r[i + 1+1] - 1}->max()->oclAsType(String) ) else ( r[i+1] := r[i+1] + 1 ) ) else if (r[i+1] = '9' or if r[i+1] - r[i + 1+1] < 0 then -(r[i+1] - r[i + 1+1]) else r[i+1] - r[i + 1+1] endif > 1) then ( execute f(i + 1, r) ; r[i+1] := Set{'0', r[i + 1+1] - 1}->max()->oclAsType(String) ) else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var r : Sequence(String) ; r := Integer.subrange(1,11)->collect(0) ; r := r->collect('0') ; var k : int ; k := s.getCurrent()->toInteger() ; while k > 0 do ( ( execute f(0, r) ) ; k := k - 1 ) ; OclFile["System.out"].println(StringLib.newString((r)->sum() )->reverse()+"".replaceFirstMatch("^0+", "")) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A1492 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long p=sc.nextLong(); long a=sc.nextLong(); long b=sc.nextLong(); long c=sc.nextLong(); System.out.println(Math.min((a-p % a)% a,Math.min((b-p % b)% b,(c-p % c)% c))); } } } ------------------------------------------------------------ OCL File: --------- class A1492 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var p : long ; p := sc.getCurrent()->toLong() ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var c : long ; c := sc.getCurrent()->toLong() ; OclFile["System.out"].println(Set{(a - p mod a) mod a, Set{(b - p mod b) mod b, (c - p mod c) mod c}->min()}->min()) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class A { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ long p=sc.nextLong(); long ans=(long)1e18 ; for(int i=0 ; i<3 ; ++i){ long a=sc.nextLong(); ans=Math.min(ans,((p+a-1)/a)*a-p); } out.println(ans); } out.close(); } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public String nextLine()throws IOException { return br.readLine(); } public boolean ready()throws IOException { return br.ready(); } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var p : long ; p := sc.getCurrent()->toLong() ; var ans : long ; ans := 1e18->oclAsType(long) ; var i : int ; i := 0 ; while i < 3 do ( ( var a : long ; a := sc.getCurrent()->toLong() ; ans := Set{ans, ((p + a - 1) / a) * a - p}->min() ) ; i := i + 1 ) ; skip ) ; ) ; skip ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class A { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int t=in.nextInt(); for(int tt=0 ; tttoInteger() ; var tt : int ; tt := 0 ; while tt < t do ( ( var P : long ; P := in.getCurrent()->toLong() ; var A : long ; A := in.getCurrent()->toLong() ; var B : long ; B := in.getCurrent()->toLong() ; var C : long ; C := in.getCurrent()->toLong() ; var a : long ; a := P mod A ; var b : long ; b := P mod B ; var c : long ; c := P mod C ; a := if (a = 0) then 0 else (A - a) endif ; b := if (b = 0) then 0 else (B - b) endif ; c := if (c = 0) then 0 else (C - c) endif ; var answer : long ; answer := Set{a, Set{b, c}->min()}->min() ; OclFile["System.out"].println(answer) ; ) ; tt := tt + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tc(char)(i % k+'a')).collect(StringBuilder :: new,StringBuilder :: append,StringBuilder :: append).toString(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(solve(n, k)) ) ; tc := tc + 1 ) ; skip ); static operation solve( n : int, k : int) : String pre: true post: true activity: ( return Integer.subrange(0, n-1).mapToObj(lambda i : OclAny in (i mod k + 'a')->oclAsType(String)).collect(lambda _pars : OclAny in String.newString().new(_pars), lambda _pars : OclAny in StringBuilder.newStringBuilder().append(_pars), lambda _pars : OclAny in StringBuilder.newStringBuilder().append(_pars))+"" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class A { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(),k=sc.nextInt(); StringBuilder sb=new StringBuilder(); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( sb := sb + StringLib.newString(('a' + (i mod k))->oclAsType(String)) ; ; i := i + 1 ) ; skip ) ; ) ; skip ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; public class P1092A { public static void main(String[] args)throws IOException { BufferedReader io=new BufferedReader(new InputStreamReader(System.in)); Integer cnt=Integer.valueOf(io.readLine()); Listrs=new ArrayList(); while(cnt>0){ cnt--; String[] input=io.readLine().split(" "); Integer n=Integer.valueOf(input[0]); Integer k=Integer.valueOf(input[1]); StringBuffer tmp=new StringBuffer(); int i=0 ; while(tmp.length()toInteger() ; var rs : Sequence(String) ; rs := Sequence{} ; while (cnt > 0) do ( cnt := cnt - 1 ; var input : Sequence(String) ; input := io.readLine()->split(" ") ; var n : int ; n := (input[0+1])->toInteger() ; var k : int ; k := (input[1+1])->toInteger() ; var tmp : String ; tmp := StringLib.newString() ; var i : int ; i := 0 ; while (tmp->size() < n) do ( tmp := tmp + StringLib.newString((97 + i)->oclAsType(String)) ; i := i + 1 ; if (i mod (k) = 0) then ( i := 0 ) else skip ) ; rs := rs->including(tmp+"") ; ) ; for (string : rs) do ( ( OclFile["System.out"].println(string) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigDecimal ; import java.math.RoundingMode ; import java.util.*; public class ProblemC { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int test=Integer.parseInt(br.readLine()); while(test-->0){ String line[]=br.readLine().split(" "); int n=Integer.parseInt(line[0]); int k=Integer.parseInt(line[1]); String res="" ; char c='a',t=(char)('a'+(k-1)); for(int i=0 ; it)c='a' ; } System.out.println(res); } } } ------------------------------------------------------------ OCL File: --------- class ProblemC { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sb : String ; sb := StringLib.newString() ; var test : int ; test := (br.readLine())->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var line : Sequence(String) ; line := br.readLine()->split(" ") ; var n : int ; n := (line[0+1])->toInteger() ; var k : int ; k := (line[1+1])->toInteger() ; var res : String ; res := "" ; var c : String ; c := 'a' ; var t : String ; t := ('a' + (k - 1))->oclAsType(String) ; var i : int ; i := 0 ; while i < n do ( ( res := res+(c) ; c := c + 1 ; if (c > t) then c := 'a' ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String ln=br.readLine(); String ans=getAnswerString(ln); System.out.println(ans.length()); } private static String getAnswerString(String st){ int st_len=st.length(); st=delOneChar(st); while(! isDoubled(st)){ st=delOneChar(st); } return st ; } private static boolean isDoubled(String st){ int st_len=st.length(); if(st_len==1){ return true ; } if(st_len % 2!=0){ return false ; } int start1=0 ; int start2=st_len/2 ; while(start1size()) ); static operation getAnswerString( st : String) : String pre: true post: true activity: ( var st_len : int ; st_len := st->size() ; st := delOneChar(st) ; while (not(isDoubled(st))) do ( st := delOneChar(st) ) ; return st ); static operation isDoubled( st : String) : boolean pre: true post: true activity: ( var st_len : int ; st_len := st->size() ; if (st_len = 1) then ( return true ) else skip ; if (st_len mod 2 /= 0) then ( return false ) else skip ; var start1 : int ; start1 := 0 ; var start2 : int ; start2 := st_len / 2 ; while (start1 < st_len / 2) do ( var st1 : String ; st1 := st->at(start1+1) ; var st2 : String ; st2 := st->at(start2+1) ; if (st1 /= st2) then ( return false ) else skip ; start1 := start1 + 1 ; start2 := start2 + 1 ; ) ; return true ); static operation delOneChar( st : String) : String pre: true post: true activity: ( return st.subrange(0+1,st->size() - 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { private static int gcd(int reduceNum,int b){ return b==0 ? reduceNum : gcd(b,reduceNum % b); } private static int reduceB(int a,String b){ int result=0 ; for(int i=0 ; isize() do ( ( result := (result * 10 + b->at(i+1) - ('0')->char2byte()) mod a ) ; i := i + 1 ) ; return result ); static operation gcdLarge( a : int, b : String) : int pre: true post: true activity: ( var num : int ; num := reduceB(a, b) ; return gcd(num, a) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 1221 ; var b : String ; b := "19837658191095787329" ; if (a = 0) then OclFile["System.out"].println(b) ; else OclFile["System.out"].println(gcdLarge(a, b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { static long mod=1000000007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int place1=0 ; int place2=0 ; int[] a=new int[n]; Arrays.fill(a,-1); for(int i=0 ; i=0){ c2=(((pow[n+1-c]*mp[n+2-c-i])% mod)*mp[i-1])% mod ; } System.out.println((c1-c2+mod)% mod); } } static long modpow(long left,long right){ long ans=1 ; while(right>0){ if((right & 1)==1){ ans*=left ; } right>>=1 ; left*=left ; ans %=mod ; left %=mod ; } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute mod : long := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var place1 : int ; place1 := 0 ; var place2 : int ; place2 := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; a := a->collect(-1) ; var i : int ; i := 0 ; while i < n + 1 do ( ( var b : int ; b := sc.getCurrent()->toInteger() - 1 ; if (a[b+1] = -1) then ( a[b+1] := i ) else ( place1 := a[b+1] ; place2 := i ) ) ; i := i + 1 ) ; var pow : Sequence(long) ; pow := Integer.subrange(1,n + 2)->collect(0) ; pow[0+1] := 1 ; var i : int ; i := 1 ; while i <= n + 1 do ( ( pow[i+1] := pow[i - 1+1] * i ; pow[i+1] := pow[i+1] mod mod ) ; i := i + 1 ) ; var mp : Sequence(long) ; mp := Integer.subrange(1,n + 2)->collect(0) ; mp[0+1] := 1 ; var i : int ; i := 1 ; while i <= n + 1 do ( ( mp[i+1] := modpow(pow[i+1], mod - 2) ) ; i := i + 1 ) ; var c : int ; c := place2 - place1 + 1 ; var i : int ; i := 1 ; while i <= n + 1 do ( ( var c1 : long ; c1 := (((pow[n + 1+1] * mp[n + 1 - i+1]) mod mod) * mp[i+1]) mod mod ; var c2 : long ; c2 := 0 ; if (n + 2 - c - i >= 0) then ( c2 := (((pow[n + 1 - c+1] * mp[n + 2 - c - i+1]) mod mod) * mp[i - 1+1]) mod mod ) else skip ; OclFile["System.out"].println((c1 - c2 + mod) mod mod) ) ; i := i + 1 ) ; ); static operation modpow( left : long, right : long) : long pre: true post: true activity: ( var ans : long ; ans := 1 ; while (right > 0) do ( if ((right & 1) = 1) then ( ans := ans*(left) ) else skip ; right := right/(2->pow(1)) ; left := left*(left) ; ans := ans mod mod ; left := left mod mod ; ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Problem1444a { static long pi ; static long qi ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ pi=sc.nextLong(); qi=sc.nextLong(); long tmpp=pi ; long tmpq=qi ; long ans=0 ; for(int i=2 ; i<=(long)(Math.sqrt(tmpq)); i++){ tmpp=pi ; while(tmpq % i==0){ if(tmpp % qi!=0){ ans=Math.max(ans,tmpp); } else if(tmpp % i!=0){ } else { tmpp/=i ; continue ; } tmpq/=i ; } } if(tmpq>=2){ long x=pi ; while(true){ if(x % qi!=0){ ans=Math.max(ans,x); break ; } if(x % tmpq!=0){ break ; } else x/=tmpq ; } } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Problem1444a { static attribute pi : long; static attribute qi : long; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( pi := sc.getCurrent()->toLong() ; qi := sc.getCurrent()->toLong() ; var tmpp : long ; tmpp := pi ; var tmpq : long ; tmpq := qi ; var ans : long ; ans := 0 ; var i : int ; i := 2 ; while i <= ((tmpq)->sqrt())->oclAsType(long) do ( ( tmpp := pi ; while (tmpq mod i = 0) do ( if (tmpp mod qi /= 0) then ( ans := Set{ans, tmpp}->max() ) else if (tmpp mod i /= 0) then skip else ( tmpp := tmpp/(i) ; continue ) ; ; tmpq := tmpq/(i) ) ) ; i := i + 1 ) ; if (tmpq >= 2) then ( var x : long ; x := pi ; while (true) do ( if (x mod qi /= 0) then ( ans := Set{ans, x}->max() ; break ) else skip ; if (x mod tmpq /= 0) then ( break ) else x := x/(tmpq) ; ) ) else skip ; OclFile["System.out"].println(ans) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { static int isSumDivides(int N){ int temp=N ; int sum=0 ; while(temp>0){ sum+=temp % 10 ; temp/=10 ; } if(N % sum==0)return 1 ; else return 0 ; } public static void main(String args[]){ int N=12 ; if(isSumDivides(N)==1)System.out.print("YES"); else System.out.print("NO"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isSumDivides( N : int) : int pre: true post: true activity: ( var temp : int ; temp := N ; var sum : int ; sum := 0 ; while (temp > 0) do ( sum := sum+(temp mod 10) ; temp := temp/(10) ) ; if (N mod sum = 0) then return 1 else return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 12 ; if (isSumDivides(N) = 1) then OclFile["System.out"].print("YES") ; else OclFile["System.out"].print("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int checkBitonic(int arr[],int n){ int i,j ; for(i=1 ; iarr[i-1])continue ; if(arr[i]<=arr[i-1])break ; } if(i==n-1)return 1 ; for(j=i+1 ; j=arr[j-1])break ; } i=j ; if(i!=n)return 0 ; return 1 ; } public static void main(String args[]){ int arr[]={ -3,9,7,20,17,5,1 }; int n=arr.length ; System.out.println((checkBitonic(arr,n)==1)? "YES" : "NO"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkBitonic( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var i : int ; var j : int ; i := 1 ; while i < n do ( ( if (arr[i+1] > arr[i - 1+1]) then continue else skip ; if (arr[i+1] <= arr[i - 1+1]) then break else skip ) ; i := i + 1 ) ; if (i = n - 1) then return 1 else skip ; j := i + 1 ; while j < n do ( ( if (arr[j+1] < arr[j - 1+1]) then continue else skip ; if (arr[j+1] >= arr[j - 1+1]) then break else skip ) ; j := j + 1 ) ; i := j ; if (i /= n) then return 0 else skip ; return 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-3,9,7,20,17,5,1} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(if (checkBitonic(arr, n) = 1) then "YES" else "NO" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.Collectors ; public class Main { static List>cnts=new ArrayList<>(); public static void main(String args[]){ Scanner sc=new Scanner(System.in); int K=sc.nextInt(); Listk1=Arrays.asList(1L,2L,3L,4L,5L,6L,7L,8L,9L); cnts.add(k1); gen(10); System.out.println(cnts.stream().flatMap(p->p.stream()).limit(K).collect(Collectors.toList()).get(K-1)); } private static void gen(int keta){ if(cnts.size()ket=cnts.get(keta-1).stream().flatMap(p->{ Listret=new ArrayList<>(); long last=p % 10 ; if(last>0){ ret.add(p*10+last-1); } ret.add(p*10+last); if(last<9){ ret.add(p*10+last+1); } return ret.stream(); } ).collect(Collectors.toList()); cnts.add(ket); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute cnts : Sequence(Sequence(long)) := Sequence{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : int ; K := sc.getCurrent()->toInteger() ; var k1 : Sequence(long) ; k1 := Sequence{1L,2L,3L,4L,5L,6L,7L,8L,9L} ; cnts := cnts->including(k1) ; execute gen(10) ; OclFile["System.out"].println(cnts->concatenateAll( _x1 | (lambda p : OclAny in p)->apply(_x1) ).subrange(1,K).collect(Collectors.toList())->at(K - 1+1)) ; ); static operation gen( keta : int) : void pre: true post: true activity: ( if (cnts->size() < keta) then ( execute gen(keta - 1) ) else skip ; var ket : Sequence(long) ; ket := cnts->at(keta - 1+1)->concatenateAll( _x1 | (lambda p : OclAny in ( var ret : Sequence(long) ; ret := Sequence{} ; var last : long ; last := p mod 10 ; if (last > 0) then ( ret := ret->including(p * 10 + last - 1) ) else skip ; ret := ret->including(p * 10 + last) ; if (last < 9) then ( ret := ret->including(p * 10 + last + 1) ) else skip ; return ret ))->apply(_x1) ).collect(Collectors.toList()) ; cnts := cnts->including(ket) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tctoInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var p : long ; p := sc.getCurrent()->toLong() ; var q : int ; q := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(solve(p, q)) ) ; tc := tc + 1 ) ; skip ); static operation solve( p : long, q : int) : long pre: true post: true activity: ( if (p mod q /= 0) then ( return p ) else skip ; var result : long ; result := 0 ; var i : int ; i := 2 ; while i * i <= q do ( ( if (q mod i = 0) then ( var exponent : int ; exponent := 0 ; while (q mod i = 0) do ( exponent := exponent + 1 ; q := q/(i) ) ; var x : long ; x := p ; while (x mod i = 0) do ( x := x/(i) ) ; var j : int ; j := 0 ; while j < exponent - 1 do ( ( x := x*(i) ) ; j := j + 1 ) ; result := Set{result, x}->max() ; ) else skip ) ; i := i + 1 ) ; if (q /= 1) then ( var x : long ; x := p ; while (x mod q = 0) do ( x := x/(q) ) ; result := Set{result, x}->max() ) else skip ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); static int n=0 ; static Listb=null ; public static void main(String[] args){ n=sc.nextInt(); b=new ArrayList<>(); for(int i=0 ; itrace=findTrace(); if(trace==null){ System.out.println(-1); return ; } for(int i=trace.size()-1 ; i>=0 ; --i){ System.out.println(trace.get(i)); } } static ListfindTrace(){ Listres=new ArrayList<>(); while(b.size()>0){ for(int i=b.size()-1 ; i>=0 ; --i){ if(b.get(i)-1==i){ res.add(b.get(i)); b.remove(i); break ; } if(i==0)return null ; } } return res ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute n : int := 0; static attribute b : Sequence(int) := null; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( n := sc.getCurrent()->toInteger() ; b := Sequence{} ; var i : int ; i := 0 ; while i < n do ( b := b->including(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; var trace : Sequence(int) ; trace := findTrace() ; if (trace = null) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var i : int ; i := trace->size() - 1 ; while i >= 0 do ( ( OclFile["System.out"].println(trace->at(i+1)) ) ; i := i - 1 ) ; ); static operation findTrace() : Sequence(int) pre: true post: true activity: ( var res : Sequence(int) ; res := Sequence{} ; while (b->size() > 0) do ( var i : int ; i := b->size() - 1 ; while i >= 0 do ( ( if (b->at(i+1) - 1 = i) then ( res := res->including(b->at(i+1)) ; b := b->excludingAt(i+1) ; break ) else skip ; if (i = 0) then return null else skip ) ; i := i - 1 ) ) ; return res ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.LinkedList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Listlist=new LinkedList<>(); for(int i=0 ; iansList=new ArrayList<>(); outer : for(int i=0 ; i=0 ; j--){ int num=list.get(j); if(j==num){ list.remove(j); ansList.add(num); continue outer ; } } break ; } if(list.isEmpty()){ Collections.reverse(ansList); for(int num : ansList)System.out.println(num+1); } else { System.out.println(-1); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var list : Sequence(int) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var b : int ; b := sc.getCurrent()->toInteger() ; b := b - 1 ; list := list->including(b) ) ; i := i + 1 ) ; var ansList : Sequence(int) ; ansList := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := list->size() - 1 ; while j >= 0 do ( ( var num : int ; num := list->at(j+1) ; if (j = num) then ( list := list->excludingAt(j+1) ; ansList := ansList->including(num) ; continue ) else skip ) ; j := j - 1 ) ; break ) ; i := i + 1 ) ; if (list->isEmpty()) then ( ansList := ansList->reverse() ; for (num : ansList) do ( OclFile["System.out"].println(num + 1) ; ) ) else ( OclFile["System.out"].println(-1) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Vector ; import java.util.Scanner ; import java.util.Stack ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); ALimitedInsertion solver=new ALimitedInsertion(); solver.solve(1,in,out); out.close(); } static class ALimitedInsertion { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); ArrayListal=new ArrayList<>(); Stackst=new Stack<>(); for(int i=0 ; i=0 ; i--){ if(al.get(i)==i+1){ f=false ; st.add(al.get(i)); al.remove(i); break ; } } if(f){ out.println(-1); return ; } } while(! st.isEmpty()){ out.println(st.pop()); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : ALimitedInsertion ; solver := ALimitedInsertion.newALimitedInsertion() ; solver.solve(1, in, out) ; skip ; ); static class ALimitedInsertion { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var al : Sequence(int) ; al := Sequence{} ; var st : Sequence(int) ; st := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( al := al->including(in.getCurrent()->toInteger()) ) ; i := i + 1 ) ; while (not(al->isEmpty())) do ( var f : boolean ; f := true ; var i : int ; i := al->size() - 1 ; while i >= 0 do ( ( if (al->at(i+1) = i + 1) then ( f := false ; st := st->including(al->at(i+1)) ; al := al->excludingAt(i+1) ; break ) else skip ) ; i := i - 1 ) ; if (f) then ( skip ; return ) else skip ) ; while (not(st->isEmpty())) do ( skip ) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); char[] s=sc.next().toCharArray(); sc.close(); label : for(int i=s.length-1 ; i>0 ; i--){ if(i % 2==0){ int i2=i/2 ; for(int j=0 ; jcharacters() ; skip ; var i : int ; i := s->size() - 1 ; while i > 0 do ( ( if (i mod 2 = 0) then ( var i2 : int ; i2 := i / 2 ; var j : int ; j := 0 ; while j < i2 do ( ( if (s[j+1] /= s[j + i2+1]) then ( continue ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println(i) ; return ) else skip ) ; i := i - 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.Deque ; import java.util.LinkedList ; import java.util.List ; import java.util.Scanner ; import java.util.Stack ; class Task { Listlist ; Dequeprocess ; Task(Listlist,Dequeprocess){ this.list=list ; this.process=process ; } } class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Listb=new LinkedList<>(); for(int i=0 ; ians=null ; Stackstack=new Stack<>(); stack.add(new Task(b,new ArrayDeque())); loop : while(! stack.isEmpty()){ Task task=stack.pop(); Listtmp=task.list ; Dequetmpprocess=task.process ; if(tmp.size()==0){ ans=tmpprocess ; break ; } for(int i=0 ; ilist=new LinkedList<>(); for(int j=0 ; jj+1)continue loop ; list.add(x); } list.remove(i); Dequeprocess=new ArrayDeque<>(); for(int x : tmpprocess){ process.addLast(x); } process.addFirst(i+1); stack.add(new Task(list,process)); } } } if(ans==null){ System.out.println(-1); } else { for(int x : ans){ System.out.println(x); } } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Task { attribute list : Sequence(int); attribute process : Sequence(int); static operation newTask( list : Sequence(int), process : Sequence(int)) : Task pre: true post: true activity: ( var self : Task ; self := createTask(); self.initialise(list, process); return self ); operation initialise( list : Sequence(int), process : Sequence(int)) : void pre: true post: true activity: ( self.list := list ; self.process := process ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var b : Sequence(int) ; b := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( b := b->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var ans : Sequence(int) ; ans := null ; var stack : Sequence(Task) ; stack := Sequence{} ; stack := stack->including(Task.newTask(b, ArrayDeque.newArrayDeque())) ; while (not(stack->isEmpty())) do ( var task : Task ; task := stack->last() ; var tmp : Sequence(int) ; tmp := task.list ; var tmpprocess : Sequence(int) ; tmpprocess := task.process ; if (tmp->size() = 0) then ( ans := tmpprocess ; break ) else skip ; var i : int ; i := 0 ; while i < tmp->size() do ( ( if (tmp->at(i+1) = i + 1) then ( var list : Sequence(int) ; list := Sequence{} ; var j : int ; j := 0 ; while j < tmp->size() do ( ( var x : int ; x := tmp->at(j+1) ; if (x > j + 1) then continue else skip ; list := list->including(x) ) ; j := j + 1 ) ; list := list->excludingAt(i+1) ; var process : Sequence(int) ; process := ArrayDeque.newArrayDeque() ; for (x : tmpprocess) do ( ( process := process->append(x) ) ) ; process := process->prepend(i + 1) ; stack := stack->including(Task.newTask(list, process)) ; ) else skip ) ; i := i + 1 ) ; ) ; if (ans = null) then ( OclFile["System.out"].println(-1) ) else ( for (x : ans) do ( ( OclFile["System.out"].println(x) ) ) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.List ; import java.util.stream.Collectors ; import java.util.stream.IntStream ; public class Main { private static java.util.Scanner scanner=new java.util.Scanner(System.in); public static void main(String[] args){ int n=scanner.nextInt(),ans[]=new int[n]; Listb=IntStream.range(0,n).mapToObj(i->scanner.nextInt()).collect(Collectors.toList()); while(n>0)for(int i=n,d=0 ; i>0 && n>d ; i--)switch(Integer.compare(b.get(i-1),i)){ case 1 : System.out.println(-1); return ; case 0 : ans[--n]=b.get(i-1); b.remove(i-1); continue ; case-1 : d=Math.max(d,n-i+b.get(i-1)); } for(int i : ans)System.out.println(i); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scanner : Scanner := Scanner.newScanner(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := scanner.nextInt() ; var ans : Sequence(void) ; ans := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(0, n-1).mapToObj(lambda i : OclAny in scanner.nextInt()).collect(Collectors.toList()) ; while (n > 0) do var i : int ; i := n ; var d : int ; d := 0 ; while i > 0 & n > d do ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (compare(b->at(i - 1+1), i)) ; if _switchval = 1 then OclFile["System.out"].println(-1) ; return else skip ; if _switchval = 0 then n := n - 1 ; ans[n+1] := b->at(i - 1+1) ; b := b->excludingFirst(i - 1) ; continue else skip ; if _switchval = -1 then d := Set{d, n - i + b->at(i - 1+1)}->max() ; else skip ; ) ; i := i - 1 ) ; ; for (i : ans) do ( OclFile["System.out"].println(i) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Scanner ; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); HashMapmp=new HashMap<>(); for(int i=0 ; i1){ if(res % 2==0){ int b=fun(res/2); ans+=2*b ; } else { int a=(res+1)/2 ; ans+=fun(a)+fun(res-a); } } } System.out.println(ans); } public static int fun(int n){ int ans=n*(n-1); return ans/2 ; } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var mp : Map(String,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := sc.getCurrent() ; mp := mp->union(Map{s->at(0+1) |-> (if mp->keys()->contains(s->at(0+1)) then mp->at(s->at(0+1)) else 0 endif) + 1}) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; for (x : mp->keys()) do ( ( var res : int ; res := mp->at(x) ; if (res > 1) then ( if (res mod 2 = 0) then ( var b : int ; b := fun(res / 2) ; ans := ans+(2 * b) ) else ( var a : int ; a := (res + 1) / 2 ; ans := ans+(fun(a) + fun(res - a)) ) ) else skip ) ) ; OclFile["System.out"].println(ans) ; ); static operation fun( n : int) : int pre: true post: true activity: ( var ans : int ; ans := n * (n - 1) ; return ans / 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class CF1166A { public static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int test=scanner.nextInt(); long[] c1=new long[26]; long[] c2=new long[26]; for(int i=0 ; ic2[ch])c2[ch]++; else c1[ch]++; } long res=0 ; for(int i=0 ; i=2)res+=(c1[i]*(c1[i]-1))/2 ; if(c2[i]>=2)res+=(c2[i]*(c2[i]-1))/2 ; } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class CF1166A { static attribute scanner : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := scanner.getCurrent()->toInteger() ; var c1 : Sequence(long) ; c1 := Integer.subrange(1,26)->collect(0) ; var c2 : Sequence(long) ; c2 := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < test do ( ( var ch : int ; ch := scanner.getCurrent()->at(0+1) - ('a')->char2byte() ; if (c1[ch+1] > c2[ch+1]) then c2[ch+1] := c2[ch+1] + 1 ; else c1[ch+1] := c1[ch+1] + 1 ; ) ; i := i + 1 ) ; var res : long ; res := 0 ; var i : int ; i := 0 ; while i < c1->size() do ( ( if (c1[i+1] >= 2) then res := res+((c1[i+1] * (c1[i+1] - 1)) / 2) ; else skip ; if (c2[i+1] >= 2) then res := res+((c2[i+1] * (c2[i+1] - 1)) / 2) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static int sumOfNum(int n){ int sum=0 ; for(int i=1 ; imap=new HashMap<>(); while(t-->0){ String s=sc.next(); char ch=s.charAt(0); chat[j++]=ch ; map.put(ch,map.getOrDefault(ch,0)+1); } for(char key : map.keySet()){ int n=map.get(key); int chk=n/2 ; int s1=sumOfNum(chk); if(n % 2==0)sum+=s1+s1 ; else sum+=s1+s1+chk ; } System.out.println(sum); } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation sumOfNum( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i < n do ( sum := sum+(i) ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; var sum : int ; sum := 0 ; var chat : Sequence(String) ; chat := Integer.subrange(1,t)->collect(0) ; var map : Map(String,int) ; map := Map{} ; while (t > 0) do ( t := t - 1 ; skip ; ( var s : String ; s := sc.getCurrent() ; var ch : String ; ch := s->at(0+1) ; chat[j+1] := ch ; j := j + 1 ; map := map->union(Map{ch |-> (if map->keys()->contains(ch) then map->at(ch) else 0 endif) + 1}) ) ; ) ; for (key : map->keys()) do ( ( var n : int ; n := map->at(key) ; var chk : int ; chk := n / 2 ; var s1 : int ; s1 := sumOfNum(chk) ; if (n mod 2 = 0) then sum := sum+(s1 + s1) ; else sum := sum+(s1 + s1 + chk) ; ) ) ; OclFile["System.out"].println(sum) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int findLen(int[] arr,int n,int m){ Vectorfilter=new Vector<>(); for(int i=0 ; iincluding(arr[i+1]) ; else skip ; ; i := i + 1 ) ; if (filter->size() = 0) then return 0 else skip ; var c_and : int ; c_and := filter->at(0+1) ; var i : int ; i := 1 ; while i < filter->size() do ( c_and := MathLib.bitwiseAnd(c_and, filter->at(i+1)) ; ; i := i + 1 ) ; if (c_and = m) then return filter->size() else skip ; return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{7,3,3,1,3} ; var n : int ; n := arr->size() ; var m : int ; m := 3 ; OclFile["System.out"].println(findLen(arr, n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.stream.LongStream ; import java.io.IOException ; import java.util.Deque ; import java.util.stream.Collectors ; import java.io.InputStreamReader ; import java.util.stream.Stream ; import java.util.StringTokenizer ; import java.io.BufferedReader ; import java.util.ArrayDeque ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; MyScanner in=new MyScanner(inputStream); PrintWriter out=new PrintWriter(outputStream); D solver=new D(); solver.solve(1,in,out); out.close(); } static class D { public void solve(int testNumber,MyScanner in,PrintWriter out){ int K=in.nextInt(); Dequeque=new ArrayDeque<>(LongStream.rangeClosed(1,9).boxed().collect(Collectors.toSet())); while(--K>0){ long q=que.removeFirst(); long l=q % 10 ; if(l>0)que.add(q*10+l-1); que.add(q*10+l); if(l<9)que.add(q*10+l+1); } out.println(que.removeFirst()); } } static class MyScanner { private BufferedReader in ; private StringTokenizer st ; public MyScanner(InputStream stream){ in=new BufferedReader(new InputStreamReader(stream)); } public String next(){ while(st==null || ! st.hasMoreTokens()){ try { String rl=in.readLine(); if(rl==null){ return null ; } st=new StringTokenizer(rl); } catch(IOException e){ throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : MyScanner ; in := MyScanner.newMyScanner(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : D ; solver := D.newD() ; solver.solve(1, in, out) ; skip ; ); static class D { operation solve( testNumber : int, in : MyScanner, out : OclFile) : void pre: true post: true activity: ( var K : int ; K := in.nextInt() ; var que : Sequence(long) ; que := ArrayDeque.newArrayDeque(Integer.subrange(1, 9).collect(Collectors.toSet())) ; K := K - 1 ; while ((K - 1) > 0) do ( K := K - 1 ; skip ; ( var q : long ; q := que->first() ; var l : long ; l := q mod 10 ; if (l > 0) then que := que->including(q * 10 + l - 1) ; else skip ; que := que->including(q * 10 + l) ; if (l < 9) then que := que->including(q * 10 + l + 1) ; else skip ; ) ; K := K - 1 ; ) ; skip ); } static class MyScanner { attribute in : OclFile; attribute st : OclIterator; static operation newMyScanner( stream : OclFile) : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( var rl : String ; rl := in.readLine() ; if (rl = null) then ( return null ) else skip ; st := OclIterator.newOclIterator_String(rl) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int setBits(int n){ int count=0 ; while(n>0){ n=n &(n-1); count++; } return count ; } static int countPairs(int a[],int n){ int count=0 ; for(int i=0 ; i 0) do ( n := n & (n - 1) ; count := count + 1 ) ; return count ); static operation countPairs( a : Sequence(int), n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( var setbits_x : int ; setbits_x := setBits(a[i+1]) ; var j : int ; j := i + 1 ; while j < n do ( ( var setbits_y : int ; setbits_y := setBits(a[j+1]) ; var setbits_xor_xy : int ; setbits_xor_xy := setBits(a[i+1] xor a[j+1]) ; if (setbits_x + setbits_y = setbits_xor_xy) then count := count + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,3,4,5,6} ; var n : int ; n := a->size() ; OclFile["System.out"].println(countPairs(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long x=sc.nextLong(); long a=0,b=0 ; boolean flag=false ; for(a=0 ; a<200 ; a++){ for(b=0 ; b<200 ; b++){ if(a*a*a*a*a-b*b*b*b*b==x){ flag=true ; break ; } else if(a*a*a*a*a+b*b*b*b*b==x){ b*=-1 ; flag=true ; break ; } else if(-a*a*a*a*a-b*b*b*b*b==x){ a*=-1 ; flag=true ; break ; } else if(-a*a*a*a*a+b*b*b*b*b==x){ a*=-1 ; b*=-1 ; flag=true ; break ; } } if(flag){ break ; } } System.out.println(a+" "+b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : long ; x := sc.getCurrent()->toLong() ; var a : long ; a := 0 ; var b : long ; b := 0 ; var flag : boolean ; flag := false ; a := 0 ; while a < 200 do ( ( b := 0 ; while b < 200 do ( ( if (a * a * a * a * a - b * b * b * b * b = x) then ( flag := true ; break ) else if (a * a * a * a * a + b * b * b * b * b = x) then ( b := b*(-1) ; flag := true ; break ) else if (-a * a * a * a * a - b * b * b * b * b = x) then ( a := a*(-1) ; flag := true ; break ) else if (-a * a * a * a * a + b * b * b * b * b = x) then ( a := a*(-1) ; b := b*(-1) ; flag := true ; break ) else skip ; ; ; ) ; b := b + 1 ) ; if (flag) then ( break ) else skip ) ; a := a + 1 ) ; OclFile["System.out"].println(a + " " + b) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public final class Main { public static void main(String[] args){ final Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); final int x=in.nextInt(); int t=0 ; final Mapmap=new HashMap<>(); while(Math.pow(t,5)<1e18){ map.put((long)Math.pow(t,5),t); map.put((long)Math.pow(-t,5),-t); t++; } twoSum(x,map); } public static void twoSum(int target,Mapmap){ for(long num : map.keySet()){ if(map.containsKey(target+num)){ System.out.println(map.get(target+num)+" "+map.get(num)); return ; } else if(map.containsKey(num-target)){ System.out.println(map.get(num)+" "+map.get(num-target)); return ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var x : int ; x := in.getCurrent()->toInteger() ; var t : int ; t := 0 ; var map : Map(long,int) ; map := Map{} ; while (t->pow(5) < 1e18) do ( map := map->union(Map{t->pow(5)->oclAsType(long) |-> t}) ; map := map->union(Map{-t->pow(5)->oclAsType(long) |-> -t}) ; t := t + 1 ) ; execute twoSum(x, map) ; ); static operation twoSum( target : int, map : Map(long,int)) : void pre: true post: true activity: ( for (num : map->keys()) do ( ( if (map->keys()->includes(target + num)) then ( OclFile["System.out"].println(map->at(target + num) + " " + map->at(num)) ; return ) else if (map->keys()->includes(num - target)) then ( OclFile["System.out"].println(map->at(num) + " " + map->at(num - target)) ; return ) else skip ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ try { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String str=br.readLine(); for(int i=1 ; isize() do ( ( var tmpStr : String ; tmpStr := str.subrange(0+1,str->size() - (i)->char2byte()) ; var tmpLen : int ; tmpLen := tmpStr->size() ; if (tmpLen mod 2 /= 0) then ( continue ) else skip ; var tmp1 : String ; tmp1 := tmpStr.subrange(0+1,tmpLen / 2) ; var tmp2 : String ; tmp2 := tmpStr.subrange(tmpLen / 2+1,tmpLen) ; if (tmp1 = tmp2) then ( OclFile["System.out"].println(tmpLen) ; break ) else skip ; ) ; i := i + 1 ) ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner scan=new Scanner(System.in)){ int X=scan.nextInt(); long A=0 ; long B=0 ; long x=0 ; long y=0 ; ArrayListyakusu=enum_div(X); for(int i=0 ; ienum_div(int n){ ArrayListret=new ArrayList(); for(int i=1 ; i*i<=n ; i++){ if(n % i==0){ ret.add(i); if(i*i!=n){ ret.add(n/i); } } } Collections.sort(ret); return ret ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scan : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var X : int ; X := scan.getCurrent()->toInteger() ; var A : long ; A := 0 ; var B : long ; B := 0 ; var x : long ; x := 0 ; var y : long ; y := 0 ; var yakusu : Sequence(int) ; yakusu := enum_div(X) ; var i : int ; i := 0 ; while i < yakusu->size() do ( ( A := yakusu->at(i+1) ; B := X / A ; x := 0 ; while (true) do ( var z : long ; z := x * x * x * x * x - (x - A) * (x - A) * (x - A) * (x - A) * (x - A) ; if (z = X) then ( OclFile["System.out"].println(x) ; OclFile["System.out"].println(x - A) ; OclProcess.exit(0) ) else skip ; if (x = 10000) then break else skip ; x := x + 1 ) ) ; i := i + 1 ) ; )) ); static operation enum_div( n : int) : Sequence(int) pre: true post: true activity: ( var ret : Sequence(int) ; ret := Sequence{} ; var i : int ; i := 1 ; while i * i <= n do ( ( if (n mod i = 0) then ( ret := ret->including(i) ; if (i * i /= n) then ( ret := ret->including(n / i) ) else skip ) else skip ) ; i := i + 1 ) ; ret := ret->sort() ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final int MOD=1_000_000_007 ; private static final String YES="Yes" ; private static final String NO="No" ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int X=sc.nextInt(); System.out.println(solve(X)); } private static String solve(long X){ for(long i=0 ; i<=1000 ; i++){ for(long j=-2000 ; j<=2000 ; j++){ long tmp=(long)Math.pow(i,5)-(long)Math.pow(j,5); if(tmp==X){ return i+" "+j ; } } } return null ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : int := 1_000_000_007; static attribute YES : String := "Yes"; static attribute NO : String := "No"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : int ; X := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(solve(X)) ); static operation solve( X : long) : String pre: true post: true activity: ( var i : long ; i := 0 ; while i <= 1000 do ( ( var j : long ; j := -2000 ; while j <= 2000 do ( ( var tmp : long ; tmp := i->pow(5)->oclAsType(long) - j->pow(5)->oclAsType(long) ; if (tmp = X) then ( return i + " " + j ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return null ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static long x=sc.nextLong(); static long num[]=new long[123]; public static void main(String[] args){ int i=-1 ; while(++itoLong(); static attribute num : long := Integer.subrange(1,123)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := -1 ; i := i + 1 ; while ((i + 1) < num->size()) do ( i := i + 1 ; length`preSideEffect num.length ; ( if (i = 0) then ( num[0+1] := 0 ; continue ) else skip ; num[i+1] := i->pow(5)->oclAsType(long) ) ; i := i + 1 ; ) ; var j : int ; j := 0 ; while j < num->size() do ( ( var k : int ; k := 0 ; while k < num->size() do ( ( if (num[j+1] - num[k+1] = x) then ( OclFile["System.out"].println(j + " " + k) ; return ) else if (-num[j+1] - num[k+1] = x) then ( OclFile["System.out"].println(-j + " " + k) ; return ) else if (num[j+1] + num[k+1] = x) then ( OclFile["System.out"].println(j + " " + -k) ; return ) else skip ; ; ) ; k := k + 1 ) ) ; j := j + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void findNumbers(int arr[],int n){ int sumN=(n*(n+1))/2 ; int sumSqN=(n*(n+1)*(2*n+1))/6 ; int sum=0,sumSq=0,i ; for(i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := css.getCurrent()->toInteger() ; var k : int ; k := css.getCurrent()->toInteger() ; var str : String ; str := css.getCurrent() ; var stringBuilder : String ; stringBuilder := StringLib.newString(str) ; if (str = stringBuilder->reverse()+"" or k = 0) then ( OclFile["System.out"].println(1) ) else OclFile["System.out"].println(2) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class ReverseAndConcatenate { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine().split(" ")[0]); PrintWriter pr=new PrintWriter(System.out); while(t>0){ t--; String[] ints=br.readLine().split(" "); int n=Integer.parseInt(ints[0]); int k=Integer.parseInt(ints[1]); String s=br.readLine(); boolean isPalindrome=true ; for(int i=0 ; i0)pr.println(2); else pr.println(1); } } pr.close(); } } ------------------------------------------------------------ OCL File: --------- class ReverseAndConcatenate { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var t : int ; t := (br.readLine()->split(" ")[0+1])->toInteger() ; var pr : OclFile ; pr := OclFile.newOclFile_Write(OclFile["System.out"]) ; while (t > 0) do ( t := t - 1 ; var ints : Sequence(String) ; ints := br.readLine()->split(" ") ; var n : int ; n := (ints[0+1])->toInteger() ; var k : int ; k := (ints[1+1])->toInteger() ; var s : String ; s := br.readLine() ; var isPalindrome : boolean ; isPalindrome := true ; var i : int ; i := 0 ; while i < n / 2 do ( ( if (s->at(i+1) /= s->at(n - i - 1+1)) then ( isPalindrome := false ; break ) else skip ) ; i := i + 1 ) ; if (isPalindrome) then ( skip ) else ( if (k > 0) then skip ; else skip ; ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; public final class p113 implements EulerSolution { public static void main(String[] args){ System.out.println(new p113().run()); } private static final int DIGITS=100 ; public String run(){ BigInteger increasing=Library.binomial(DIGITS+9,9).subtract(BigInteger.ONE); BigInteger decreasing=Library.binomial(DIGITS+10,10).subtract(BigInteger.valueOf(DIGITS+1)); BigInteger flat=BigInteger.valueOf(DIGITS*9); return increasing.add(decreasing).subtract(flat).toString(); } } ------------------------------------------------------------ OCL File: --------- class p113 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p113.newp113().run()) ); static attribute DIGITS : int := 100; operation run() : String pre: true post: true activity: ( var increasing : long ; increasing := Library.binomial(DIGITS + 9, 9).subtract(1) ; var decreasing : long ; decreasing := Library.binomial(DIGITS + 10, 10).subtract((DIGITS + 1 + "")->toLong()) ; var flat : long ; flat := (DIGITS * 9 + "")->toLong() ; return increasing->excludes(decreasing).subtract(flat)+"" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long x=sc.nextLong(); Dequeque=new ArrayDeque(); long count=0 ; for(long i=1 ; i<10 ; i++){ que.add(i); } long temp ; while(true){ temp=que.pop(); count++; if(count==x){ System.out.println(temp); return ; } if(temp % 10!=0){ que.add(10*temp+temp % 10-1); } que.add(10*temp+temp % 10); if(temp % 10!=9){ que.add(10*temp+temp % 10+1); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : long ; x := sc.getCurrent()->toLong() ; var que : Sequence(long) ; que := ArrayDeque.newArrayDeque() ; var count : long ; count := 0 ; var i : long ; i := 1 ; while i < 10 do ( ( que := que->including(i) ) ; i := i + 1 ) ; var temp : long ; while (true) do ( temp := que->last() ; que := que->front() ; count := count + 1 ; if (count = x) then ( OclFile["System.out"].println(temp) ; return ) else skip ; if (temp mod 10 /= 0) then ( que := que->including(10 * temp + temp mod 10 - 1) ) else skip ; que := que->including(10 * temp + temp mod 10) ; if (temp mod 10 /= 9) then ( que := que->including(10 * temp + temp mod 10 + 1) ) else skip ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxSum(int arr1[],int arr2[],int n){ int initialParity=0,finalParity=0 ; int sum=0,minPositive=Integer.MAX_VALUE,maxNegative=Integer.MIN_VALUE ; for(int i=0 ; i=0){ finalParity+=1 ; sum+=arr1[i]; minPositive=Math.min(minPositive,arr1[i]); } else { maxNegative=Math.max(maxNegative,arr1[i]); } } if(initialParity % 2==finalParity % 2){ return sum ; } else { if(minPositive+maxNegative>=0){ return sum+maxNegative ; } else { return sum-minPositive ; } } } public static void main(String[] args){ int arr1[]={ 2,-4,5,3 }; int arr2[]={ 0,1,0,1 }; int n=arr1.length ; System.out.println(maxSum(arr1,arr2,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxSum( arr1 : Sequence(int), arr2 : Sequence(int), n : int) : int pre: true post: true activity: ( var initialParity : int ; initialParity := 0 ; var finalParity : int ; finalParity := 0 ; var sum : int ; sum := 0 ; var minPositive : int ; minPositive := 2147483647 ; var maxNegative : int ; maxNegative := -2147483648 ; var i : int ; i := 0 ; while i < n 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() ) ) ; i := i + 1 ) ; if (initialParity mod 2 = finalParity mod 2) then ( return sum ) else ( if (minPositive + maxNegative >= 0) then ( return sum + maxNegative ) else ( return sum - minPositive ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr1 : Sequence(int) ; arr1 := Sequence{2,-4,5,3} ; var arr2 : Sequence(int) ; arr2 := Sequence{0,1,0,1} ; var n : int ; n := arr1->size() ; OclFile["System.out"].println(maxSum(arr1, arr2, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Colorful_Field { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int k=sc.nextInt(); int l=sc.nextInt(); pair[] arr=new pair[k]; for(int i=0 ; i{ int x ; int y ; pair(int a,int b){ x=a ; y=b ; } public int compareTo(pair o){ if(this.x!=o.x)return this.x-o.x ; else return this.y-o.y ; } } } ------------------------------------------------------------ OCL File: --------- class Colorful_Field { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var l : int ; l := sc.getCurrent()->toInteger() ; var arr : Sequence(pair) ; arr := Integer.subrange(1,k)->collect(null) ; var i : int ; i := 0 ; while i < k do ( ( arr[i+1] := pair.newpair(sc.getCurrent()->toInteger() - 1, sc.getCurrent()->toInteger() - 1) ) ; i := i + 1 ) ; arr := arr->sort() ; var i : int ; i := 0 ; while i < l do ( ( var x : int ; x := sc.getCurrent()->toInteger() - 1 ; var y : int ; y := sc.getCurrent()->toInteger() - 1 ; var res : int ; res := x * m + y ; var j : int ; j := 0 ; while j < arr->size() do ( ( if (arr[j+1].x < x or (arr[j+1].x = x & arr[j+1].y < y)) then res := res - 1 ; else if (arr[j+1].x = x & arr[j+1].y = y) then ( OclFile["System.out"].println("Waste") ; continue ) else break ; ) ; j := j + 1 ) ; res := res mod 3 ; OclFile["System.out"].println(if res = 0 then "Carrots" else if res = 1 then "Kiwis" else "Grapes" endif endif) ; ) ; i := i + 1 ) ; ); static class pair implements Comparable { attribute x : int; attribute y : int; static operation newpair( a : int, b : int) : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( x := a ; y := b ); operation compareTo( o : pair) : int pre: true post: true activity: ( if (self.x /= o.x) then return self.x - o.x else return self.y - o.y ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GFG { public static int findNth(int n){ int count=0 ; for(int curr=19 ; ; curr+=9){ int sum=0 ; for(int x=curr ; x>0 ; x=x/10)sum=sum+x % 10 ; if(sum==10)count++; if(count==n)return curr ; } } public static void main(String[] args){ System.out.print(findNth(5)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findNth( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var curr : int ; curr := 19 ; while true do ( ( var sum : int ; sum := 0 ; var x : int ; x := curr ; while x > 0 do ( sum := sum + x mod 10 ; ; x := x / 10 ) ; if (sum = 10) then count := count + 1 ; else skip ; if (count = n) then return curr else skip ) ; curr := curr+(9) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].print(findNth(5)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String p[]={ "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" }; String c=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; String q[]={ "11010","11110","11100","11101","11011","11111","00000","00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001" }; while(sc.hasNext()){ String result="" ; char[] s=sc.nextLine().toCharArray(); for(char t1 : s){ for(int i=0 ; icharacters() ; for (t1 : s) do ( ( var i : int ; i := 0 ; while i < c->size() do ( ( if (t1 = c->at(i+1)) then ( result := result+(p[i+1]) ) else skip ) ; i := i + 1 ) ) ) ; var i : int ; i := 0 ; while i < result->size() mod 5 do ( ( result := result+("0") ) ; i := i + 1 ) ; var result2 : String ; result2 := "" ; var i : int ; i := 0 ; while i < result->size() do ( ( var j : int ; j := 0 ; while j < q->size() do ( ( if (result.subrange(i+1,i + 5) = q[j+1]) then ( result2 := result2+(c->at(j+1)) ) else skip ) ; j := j + 1 ) ) ; i := i+(5) ) ; OclFile["System.out"].println(result2) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF_1447A_AddCandies { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int count=scanner.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < count do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(n - 1) ; var j : int ; j := 2 ; while j <= n do ( ( OclFile["System.out"].print(j) ; if (j < n) then ( OclFile["System.out"].print(" ") ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class DL { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0){ int n=s.nextInt(); System.out.println(n); for(int i=0 ; itoInteger() ; while (t > 0) do ( var n : int ; n := s.getCurrent()->toInteger() ; OclFile["System.out"].println(n) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(i + 1 + " ") ) ; i := i + 1 ) ; t := t - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; class Ward implements Comparable{ public String s ; public int cnt=1 ; Ward(String s){ this.s=s ; } public int compareTo(Ward w){ int ret ; ret=w.cnt-this.cnt ; if(ret==0){ ret=this.s.compareTo(w.s); } return ret ; } public boolean equals(Object obj){ Ward w=(Ward)obj ; return this.s.equals(w.s); } } public class Main { public static void main(String[] args){ final int END=0 ; ArrayListin=new ArrayList(); Ward wrd ; int n,idx,max ; String ward,k ; String[] s ; Scanner sc=new Scanner(System.in); while(true){ n=Integer.parseInt(sc.nextLine()); if(n==END){ break ; } in.clear(); while(n-->0){ s=sc.nextLine().split("\\s"); for(int i=0 ; i0){ System.out.print(" "); } System.out.print(ward); max++; } } if(max==0){ System.out.print("NA"); } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class Ward implements Comparable { attribute s : String; attribute cnt : int := 1; static operation newWard( s : String) : Ward pre: true post: true activity: ( var self : Ward ; self := createWard(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( self.s := s ); operation compareTo( w : Ward) : int pre: true post: true activity: ( var ret : int ; ret := w.cnt - self.cnt ; if (ret = 0) then ( ret := self.s->compareTo(w.s) ) else skip ; return ret ); operation equals( obj : OclAny) : boolean pre: true post: true activity: ( var w : Ward ; w := obj->oclAsType(Ward) ; return self.s = w.s ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var END : int ; END := 0 ; var in : Sequence(Ward) ; in := Sequence{} ; var wrd : Ward ; var n : int ; var idx : int ; var max : int ; var ward : String ; var k : String ; var s : Sequence(String) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( n := (sc.nextLine())->toInteger() ; if (n = END) then ( break ) else skip ; in := in->intersection(Set{}) ; while (n > 0) do ( n := n - 1 ; skip ; ( s := sc.nextLine()->split("\\s") ; var i : int ; i := 0 ; while i < s->size() do ( ( wrd := Ward.newWard(s[i+1]) ; if ((idx) /= -1) then ( in->at(idx+1).cnt := in->at(idx+1).cnt + 1 ) else ( in := in->including(wrd) ) ) ; i := i + 1 ) ) ; ) ; k := sc.nextLine() ; in := in->sort() ; max := 0 ; var i : int ; i := 0 ; while i < in->size() & max < 5 do ( ( ward := in->at(i+1).s ; if (ward->hasPrefix(k)) then ( if (max > 0) then ( OclFile["System.out"].print(" ") ) else skip ; OclFile["System.out"].print(ward) ; max := max + 1 ) else skip ) ; i := i + 1 ) ; if (max = 0) then ( OclFile["System.out"].print("NA") ) else skip ; OclFile["System.out"].println() ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.util.Arrays.deepToString ; import java.util.ArrayList ; import java.util.Collections ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } Scanner sc=new Scanner(System.in); public void run(){ for(; sc.hasNext(); ){ int n=sc.nextInt(); sc.nextLine(); if(n==0)break ; Mapcount=new HashMap(); for(int i=0 ; ips=new ArrayList

(); for(String w : count.keySet()){ if(w.charAt(0)==c){ P p=new P(); p.w=w ; p.count=count.get(w); ps.add(p); } } Collections.sort(ps); if(ps.size()==0){ System.out.println("NA"); } else { System.out.print(ps.get(0).w); for(int i=1 ; i{ int count ; String w ; @ Override public int compareTo(P o){ if(count!=o.count)return-count+o.count ; return w.compareTo(o.w); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while sc.hasNext() do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; skip ; if (n = 0) then break else skip ; var count : Map(String,int) ; count := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var words : Sequence(String) ; words := sc.nextLine()->split(" ") ; for (w : words) do ( ( var k : int ; k := count->at(w) ; if (k = null) then ( k := 0 ) else skip ; k := k + 1 ; count := count->union(Map{w |-> k}) ) ) ) ; i := i + 1 ) ; var c : String ; c := sc.getCurrent()->at(0+1) ; var ps : Sequence(P) ; ps := Sequence{} ; for (w : count->keys()) do ( ( if (w->at(0+1) = c) then ( var p : P ; p := P.newP() ; p.w := w ; p.count := count->at(w) ; ps := ps->including(p) ) else skip ) ) ; ps := ps->sort() ; if (ps->size() = 0) then ( OclFile["System.out"].println("NA") ) else ( OclFile["System.out"].print(ps->at(0+1).w) ; var i : int ; i := 1 ; while i < Set{ps->size(), 5}->min() do ( ( OclFile["System.out"].print(" " + ps->at(i+1).w) ) ; i := i + 1 ) ; OclFile["System.out"].println() ) ; ) ) ); class P implements Comparable

{ attribute count : int; attribute w : String; operation compareTo( o : P) : int pre: true post: true activity: ( if (count /= o.count) then return -count + o.count else skip ; return w->compareTo(o.w) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int a ; while(true){ a=s.nextInt(); if(a==0)System.exit(0); s.nextLine(); String c="" ; HashMapmap=new HashMap(); String wolf[]=new String[100000]; int ind=0 ; int m=1 ; for(int i=0 ; i0 ; i--){ if(count==5)break ; for(int j=0 ; j0)System.out.print(" "); System.out.print(wolf[j]); count++; } } } if(count==0)System.out.println("NA"); else System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; while (true) do ( a := s.getCurrent()->toInteger() ; if (a = 0) then OclProcess.exit(0) ; else skip ; skip ; var c : String ; c := "" ; var map : Map(String,int) ; map := Map{} ; var wolf : Sequence(String) ; wolf := Integer.subrange(1,100000)->collect(null) ; var ind : int ; ind := 0 ; var m : int ; m := 1 ; var i : int ; i := 0 ; while i < a do ( ( var b : String ; b := s.nextLine() ; var d : Sequence(String) ; d := b->split(" ") ; var j : int ; j := 0 ; while j < d->size() do ( ( if (map->keys()->includes(d[j+1])) then ( map := map->union(Map{d[j+1] |-> map->at(d[j+1]) + 1}) ; m := Set{m, map->at(d[j+1])}->max() ) else ( map := map->union(Map{d[j+1] |-> 1}) ; wolf[ind+1] := d[j+1] ; ind := ind + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; wolf := wolf.subrange(1,0)^(wolf.subrange(0+1,ind)->sort())^wolf.subrange(ind+1,wolf.size) ; var p : String ; p := s.getCurrent() ; var count : int ; count := 0 ; var i : int ; i := m ; while i > 0 do ( ( if (count = 5) then break else skip ; var j : int ; j := 0 ; while j < ind do ( ( if (count = 5) then break else skip ; if (p->at(0+1) = wolf[j+1]->at(0+1) & map->at(wolf[j+1]) = i) then ( if (count > 0) then OclFile["System.out"].print(" ") ; else skip ; OclFile["System.out"].print(wolf[j+1]) ; count := count + 1 ) else skip ) ; j := j + 1 ) ) ; i := i - 1 ) ; if (count = 0) then OclFile["System.out"].println("NA") else OclFile["System.out"].println() ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static Boolean divisibleBy20(String num){ int lastTwoDigits=Integer.parseInt(num.substring(num.length()-2,num.length())); return((lastTwoDigits % 5==0)&&(lastTwoDigits % 4==0)); } public static void main(String[] args){ String num="63284689320" ; if(divisibleBy20(num)==true)System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation divisibleBy20( num : String) : Boolean pre: true post: true activity: ( var lastTwoDigits : int ; lastTwoDigits := (num.subrange(num->size() - 2+1,num->size()))->toInteger() ; return ((lastTwoDigits mod 5 = 0) & (lastTwoDigits mod 4 = 0)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : String ; num := "63284689320" ; if (divisibleBy20(num) = true) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int gcd(int a,int b){ if(b==0)return a ; return gcd(b,a % b); } static int countNumbers(int X,int Y,int N){ int divisibleByX=N/X ; int divisibleByY=N/Y ; int LCM=(X*Y)/gcd(X,Y); int divisibleByLCM=N/LCM ; int divisibleByXorY=divisibleByX+divisibleByY-divisibleByLCM ; int divisibleByXnotY=divisibleByXorY-divisibleByY ; return divisibleByXnotY ; } public static void main(String[] args){ int X=2,Y=3,N=10 ; System.out.println(countNumbers(X,Y,N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static 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) ); static operation countNumbers( X : int, Y : int, N : int) : int pre: true post: true activity: ( var divisibleByX : int ; divisibleByX := N / X ; var divisibleByY : int ; divisibleByY := N / Y ; var LCM : int ; LCM := (X * Y) / gcd(X, Y) ; var divisibleByLCM : int ; divisibleByLCM := N / LCM ; var divisibleByXorY : int ; divisibleByXorY := divisibleByX + divisibleByY - divisibleByLCM ; var divisibleByXnotY : int ; divisibleByXnotY := divisibleByXorY - divisibleByY ; return divisibleByXnotY ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var X : int ; X := 2 ; var Y : int ; Y := 3 ; var N : int ; N := 10 ; OclFile["System.out"].println(countNumbers(X, Y, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GFG { public static int findNth(int n){ int count=0 ; for(int curr=1 ; ; curr++){ int sum=0 ; for(int x=curr ; x>0 ; x=x/10)sum=sum+x % 10 ; if(sum==10)count++; if(count==n)return curr ; } } public static void main(String[] args){ System.out.print(findNth(5)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findNth( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var curr : int ; curr := 1 ; while true do ( ( var sum : int ; sum := 0 ; var x : int ; x := curr ; while x > 0 do ( sum := sum + x mod 10 ; ; x := x / 10 ) ; if (sum = 10) then count := count + 1 ; else skip ; if (count = n) then return curr else skip ) ; curr := curr + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].print(findNth(5)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ while(true){ int n=sc.nextInt(),s=sc.nextInt(); if(n==0 && s==0)break ; System.out.println(dfs(0,0,s,n)); } } } public static int dfs(int total,int addv,int target,int n){ if(n==0)return total==target ? 1 : 0 ; else if(addv>9)return 0 ; else return dfs(total+addv,addv+1,target,n-1)+dfs(total,addv+1,target,n); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var s : int ; s := sc.getCurrent()->toInteger() ; if (n = 0 & s = 0) then break else skip ; OclFile["System.out"].println(dfs(0, 0, s, n)) ) )) ); static operation dfs( total : int, addv : int, target : int, n : int) : int pre: true post: true activity: ( if (n = 0) then return if total = target then 1 else 0 endif else if (addv > 9) then return 0 else return dfs(total + addv, addv + 1, target, n - 1) + dfs(total, addv + 1, target, n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; final class Main { private Main(){ } public static void main(final String[] argv)throws IOException { final BufferedReader inputReader=new BufferedReader(new InputStreamReader(System.in)); while(true){ String input=inputReader.readLine(); if(input==null || input.equals("0 0")){ break ; } String[] inputs=input.split(" "); int n=Integer.parseInt(inputs[0]); int s=Integer.parseInt(inputs[1]); System.out.println(solv(n,s)); } } private static int solv(final int n,final int s){ return solv(n,s,0); } private static int solv(final int n,final int s,final int min){ if(n==0){ return s==0 ? 1 : 0 ; } int count=0 ; for(int i=min ; i<10 && i<=s ; i++){ count+=solv(n-1,s-i,i+1); } return count ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: skip; static operation main( argv : Sequence(String)) : void pre: true post: true activity: ( var inputReader : OclFile ; inputReader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (true) do ( var input : String ; input := inputReader.readLine() ; if (input = null or input = "0 0") then ( break ) else skip ; var inputs : Sequence(String) ; inputs := input->split(" ") ; var n : int ; n := (inputs[0+1])->toInteger() ; var s : int ; s := (inputs[1+1])->toInteger() ; OclFile["System.out"].println(solv(n, s)) ; ) ); static operation solv( n : int, s : int) : int pre: true post: true activity: ( return solv(n, s, 0) ); static operation solv( n : int, s : int, min : int) : int pre: true post: true activity: ( if (n = 0) then ( return if s = 0 then 1 else 0 endif ) else skip ; var count : int ; count := 0 ; var i : int ; i := min ; while i < 10 & i <= s do ( ( count := count+(solv(n - 1, s - i, i + 1)) ) ; i := i + 1 ) ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,s ; for(; ; ){ n=sc.nextInt(); s=sc.nextInt(); if(n==0 && s==0)break ; else if(s>45)out.println(0); else out.println(solve(n,s,9)); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } private static int solve(int n,int s,int r){ if(n==0 && s==0)return 1 ; else if(n==0 || s<0 || r==-1)return 0 ; else return solve(n,s,r-1)+solve(n-1,s-r,r-1); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var n : int ; var s : int ; while true do ( ( n := sc.nextInt() ; s := sc.nextInt() ; if (n = 0 & s = 0) then break else if (s > 45) then out.println(0) else out.println(solve(n, s, 9)) ; ; ) ) ; sc.close() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); static operation solve( n : int, s : int, r : int) : int pre: true post: true activity: ( if (n = 0 & s = 0) then return 1 else if (n = 0 or s < 0 or r = -1) then return 0 else return solve(n, s, r - 1) + solve(n - 1, s - r, r - 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; class Main { public static void main(String args[]){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String buf ; try { while("0 0".equals(buf=br.readLine())==false){ StringTokenizer st=new StringTokenizer(buf); int n=Integer.parseInt(st.nextToken()); int s=Integer.parseInt(st.nextToken()); System.out.println(solve(n,s,0)); } } catch(Exception e){ e.printStackTrace(); } } public static int solve(int n,int s,int r){ if(n==0){ if(s==0)return 1 ; else return 0 ; } else { int count=0 ; for(int i=r ; i<=9 ; i++){ count+=solve(n-1,s-i,i+1); } return count ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var buf : String ; try ( while ("0 0" = buf = false) do ( var st : OclIterator ; st := OclIterator.newOclIterator_String(buf) ; var n : int ; n := (st.next())->toInteger() ; var s : int ; s := (st.next())->toInteger() ; OclFile["System.out"].println(solve(n, s, 0)) ) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); static operation solve( n : int, s : int, r : int) : int pre: true post: true activity: ( if (n = 0) then ( if (s = 0) then return 1 else return 0 ) else ( var count : int ; count := 0 ; var i : int ; i := r ; while i <= 9 do ( ( count := count+(solve(n - 1, s - i, i + 1)) ) ; i := i + 1 ) ; return count ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int M[][]; public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=Integer.parseInt(in.next()); M=new int[n][n]; for(int i=0 ; itoInteger() ; M := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( M[i+1][j+1] := (in.getCurrent())->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var INF : int ; INF := 2000000001 ; var d : Sequence(void) ; d := Integer.subrange(1,n)->collect(0) ; var p : Sequence(void) ; p := Integer.subrange(1,n)->collect(0) ; var color : Sequence(String) ; color := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( color[i+1] := 'W' ; d[i+1] := INF ) ; i := i + 1 ) ; d[0+1] := 0 ; p[0+1] := -1 ; while (true) do ( var mincost : int ; mincost := INF ; var u : int ; u := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (color[i+1] /= 'B' & d[i+1] < mincost) then ( mincost := d[i+1] ; u := i ) else skip ) ; i := i + 1 ) ; if (u = -1) then break else skip ; color[u+1] := 'B' ; var v : int ; v := 0 ; while v < n do ( ( if (color[v+1] /= 'B' & M[u+1][v+1] /= -1) then ( if (M[u+1][v+1] < d[v+1]) then ( d[v+1] := M[u+1][v+1] ; color[v+1] := 'G' ) else skip ) else skip ) ; v := v + 1 ) ; ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (d[i+1] /= -1) then sum := sum+(d[i+1]) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.PriorityQueue ; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); ArrayList>edges=new ArrayList<>(); for(int i=0 ; i()); for(int j=0 ; j>edges,int n){ PriorityQueuepq=new PriorityQueue<>(); boolean used[]=new boolean[n]; int sum=0 ; pq.add(new Edge(0,0)); while(! pq.isEmpty()){ Edge e=pq.poll(); if(used[e.to])continue ; used[e.to]=true ; sum+=e.cost ; pq.addAll(edges.get(e.to)); } return sum ; } } class Edge implements Comparable{ int to ; int cost ; public Edge(int to,int cost){ this.to=to ; this.cost=cost ; } @ Override public int compareTo(Edge e){ return this.cost-e.cost ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var edges : Sequence(Sequence(Edge)) ; edges := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var str : Sequence(String) ; str := br.readLine()->split(" ") ; edges := edges->including(Sequence{}) ; var j : int ; j := 0 ; while j < n do ( ( var a : int ; a := (str[j + 1+1])->toInteger() ; if (a = -1) then a := 2147483647 ; else skip ; edges->at(i+1)->excludes(Edge.newEdge(j, a)) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := prime(edges, n) ; OclFile["System.out"].println(ans) ; ); static operation prime( edges : Sequence(Sequence(Edge)), n : int) : int pre: true post: true activity: ( var pq : Sequence(Edge) ; pq := Sequence{} ; var used : Sequence(boolean) ; used := Integer.subrange(1,n)->collect(false) ; var sum : int ; sum := 0 ; pq := pq->including(Edge.newEdge(0, 0)) ; while (not(pq->isEmpty())) do ( var e : Edge ; e := pq->min() ; if (used[e.to+1]) then continue else skip ; used[e.to+1] := true ; sum := sum+(e.cost) ; pq := pq->union(edges->at(e.to+1)) ; ) ; return sum ); } class Edge implements Comparable { attribute to : int; attribute cost : int; static operation newEdge( to : int, cost : int) : Edge pre: true post: true activity: ( var self : Edge ; self := createEdge(); self.initialise(to, cost); return self ); operation initialise( to : int, cost : int) : void pre: true post: true activity: ( self.to := to ; self.cost := cost ); operation compareTo( e : Edge) : int pre: true post: true activity: ( return self.cost - e.cost ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static final int MAX=Integer.MAX_VALUE ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[][] w=new int[n+1][n+1]; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=n ; j++){ int k=sc.nextInt(); w[i][j]=k==-1 ? MAX : k ; } } int sumCost=0 ; boolean[] used=new boolean[n+1]; int[] minCostFromTempMST=new int[n+1]; for(int i=1 ; i<=n ; i++){ minCostFromTempMST[i]=MAX ; } minCostFromTempMST[1]=0 ; while(true){ int next=-1 ; int minCost=MAX ; for(int i=1 ; i<=n ; i++){ if(! used[i] && minCostFromTempMST[i]toInteger() ; var w : Sequence(Sequence(int)) ; w := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= n do ( ( var k : int ; k := sc.getCurrent()->toInteger() ; w[i+1][j+1] := if k = -1 then MAX else k endif ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sumCost : int ; sumCost := 0 ; var used : Sequence(boolean) ; used := Integer.subrange(1,n + 1)->collect(false) ; var minCostFromTempMST : Sequence(int) ; minCostFromTempMST := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( minCostFromTempMST[i+1] := MAX ) ; i := i + 1 ) ; minCostFromTempMST[1+1] := 0 ; while (true) do ( var next : int ; next := -1 ; var minCost : int ; minCost := MAX ; var i : int ; i := 1 ; while i <= n do ( ( if (not(used[i+1]) & minCostFromTempMST[i+1] < minCost) then ( next := i ; minCost := minCostFromTempMST[i+1] ) else skip ) ; i := i + 1 ) ; if (next = -1) then break else skip ; used[next+1] := true ; sumCost := sumCost+(minCostFromTempMST[next+1]) ; var i : int ; i := 1 ; while i <= n do ( ( if (not(used[i+1]) & w[next+1][i+1] /= MAX) then ( minCostFromTempMST[i+1] := Set{minCostFromTempMST[i+1], w[next+1][i+1]}->min() ) else skip ) ; i := i + 1 ) ; ) ; OclFile["System.out"].println(sumCost) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Main main=new Main(); main.test(); } int n ; private void test(){ Scanner input=new Scanner(System.in); n=input.nextInt(); int[][] us=new int[n+1][n+1]; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=n ; j++){ int v=input.nextInt(); us[i][j]=v==-1 ? Integer.MAX_VALUE : v ; } us[i][i]=0 ; } int[] f=new int[n+1]; f[1]=1 ; int t=calc(us,f); System.out.println(t); } int calc(int[][] us,int[] f){ int a=0 ; int v=Integer.MAX_VALUE ; for(int i=1 ; i<=n ; i++){ if(f[i]==1){ for(int j=1 ; j<=n ; j++){ if(i!=j && f[j]!=1 && us[i][j]toInteger() ; var us : Sequence(Sequence(int)) ; us := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= n do ( ( var v : int ; v := input.getCurrent()->toInteger() ; us[i+1][j+1] := if v = -1 then 2147483647 else v endif ) ; j := j + 1 ) ; us[i+1][i+1] := 0 ) ; i := i + 1 ) ; var f : Sequence(int) ; f := Integer.subrange(1,n + 1)->collect(0) ; f[1+1] := 1 ; var t : int ; t := calc(us, f) ; OclFile["System.out"].println(t) ; ); operation calc( us : Sequence(Sequence(int)), f : Sequence(int)) : int pre: true post: true activity: ( var a : int ; a := 0 ; var v : int ; v := 2147483647 ; var i : int ; i := 1 ; while i <= n do ( ( if (f[i+1] = 1) then ( var j : int ; j := 1 ; while j <= n do ( ( if (i /= j & f[j+1] /= 1 & us[i+1][j+1] < v) then ( a := j ; v := us[i+1][j+1] ) else skip ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; f[a+1] := 1 ; if (f[0+1] = 1) then return 0 else skip ; return v + calc(us, f) ); } class Scanner { attribute r : OclFile; attribute st : StreamTokenizer; static operation newScanner( in : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; st := StreamTokenizer.newStreamTokenizer(r) ); operation next() : String pre: true post: true activity: ( execute nextToken() ; return st.sval ); operation nextInt() : int pre: true post: true activity: ( execute nextToken() ; return st.nval->oclAsType(int) ); operation nextToken() : int pre: true post: true activity: ( var token : int ; token := st.TT_EOF ; try ( token := st.next() ) catch (e : IOException) do skip return token ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int t=scanner.nextInt(); int s=scanner.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0 ; i=0 ; j--){ if(j-b[i]>=s || s>=j)dp[j]=Math.max(dp[j],dp[j-b[i] ]+a[i]); ans=Math.max(ans,dp[j]); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var t : int ; t := scanner.getCurrent()->toInteger() ; var s : int ; s := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() ; b[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,t + 1)->collect(0) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := t ; while j - b[i+1] >= 0 do ( ( if (j - b[i+1] >= s or s >= j) then dp[j+1] := Set{dp[j+1], dp[j - b[i+1]+1] + a[i+1]}->max() ; else skip ; ans := Set{ans, dp[j+1]}->max() ) ; j := j - 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countNumber(int N,int S){ int countElements=0 ; int currSum=0 ; while(currSum<=S){ currSum+=N ; N--; countElements++; } return countElements ; } public static void main(String[] args){ int N,S ; N=5 ; S=11 ; int count=countNumber(N,S); System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumber( N : int, S : int) : int pre: true post: true activity: ( var countElements : int ; countElements := 0 ; var currSum : int ; currSum := 0 ; while (currSum <= S) do ( currSum := currSum+(N) ; N := N - 1 ; countElements := countElements + 1 ) ; return countElements ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; var S : int ; N := 5 ; S := 11 ; var count : int ; count := countNumber(N, S) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private final static int WHITE=0 ; private final static int BLACK=1 ; private static int[][] mat ; private static int n ; public static void main(String[] args){ final Scanner sc=new Scanner(System.in); int i,j ; n=sc.nextInt(); mat=new int[n][n]; for(i=0 ; id[i] && color[i]!=BLACK){ u=i ; min=d[i]; } } if(u==-1)break ; color[u]=BLACK ; for(j=0 ; jmat[u][j]){ d[j]=mat[u][j]; p[j]=u ; } } } } for(i=0 ; itoInteger() ; mat := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; i := 0 ; while i < n do ( ( j := 0 ; while j < n do ( ( mat[i+1][j+1] := sc.getCurrent()->toInteger() ; if (mat[i+1][j+1] = -1) then mat[i+1][j+1] := 2147483647 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Prim()) ; ); static operation Prim() : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var u : int ; var min : int ; var i : int ; var j : int ; var d : Sequence(int) ; d := Integer.subrange(1,100)->collect(0) ; var p : Sequence(int) ; p := Integer.subrange(1,100)->collect(0) ; var color : Sequence(int) ; color := Integer.subrange(1,100)->collect(0) ; i := 0 ; while i < n do ( ( d[i+1] := 2147483647 ; p[i+1] := -1 ; color[i+1] := WHITE ) ; i := i + 1 ) ; d[0+1] := 0 ; while (true) do ( min := 2147483647 ; u := -1 ; i := 0 ; while i < n do ( ( if (min > d[i+1] & color[i+1] /= BLACK) then ( u := i ; min := d[i+1] ) else skip ) ; i := i + 1 ) ; if (u = -1) then break else skip ; color[u+1] := BLACK ; j := 0 ; while j < n do ( ( if (color[j+1] /= BLACK & mat[u+1][j+1] /= 2147483647) then ( if (d[j+1] > mat[u+1][j+1]) then ( d[j+1] := mat[u+1][j+1] ; p[j+1] := u ) else skip ) else skip ) ; j := j + 1 ) ; ) ; i := 0 ; while i < n do ( if (p[i+1] /= -1) then sum := sum+(mat[i+1][p[i+1]+1]) ; else skip ; ; i := i + 1 ) ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class Problem3 { public static void main(String[] args)throws IOException { Scanner in=new Scanner(new FileReader("Problem3.in")); PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("Problem3.out"))); int c=in.nextInt(); for(int cn=0 ; cntoInteger() ; var cn : int ; cn := 0 ; while cn < c do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var x : long ; x := in.getCurrent()->toInteger() ; var y : long ; y := in.getCurrent()->toInteger() ; var z : long ; z := in.getCurrent()->toInteger() ; var sub : Sequence(long) ; sub := Integer.subrange(1,n)->collect(0) ; var ans : Sequence(long) ; ans := Integer.subrange(1,n)->collect(null) ; var array : Sequence(long) ; array := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( array[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( sub[i+1] := array[i mod m+1] ; array[i mod m+1] := (x * array[i mod m+1] + y * (i + 1)) mod z ) ; i := i + 1 ) ; ans := ans->collect(1) ; var i : int ; i := 1 ; while i < n do ( var j : int ; j := 0 ; while j < i do ( ( if (sub[j+1] < sub[i+1]) then ans[i+1] := ans[i+1]->excludes(ans[j+1]) ; else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( sum := sum->excludes(ans[i+1]) ; ; i := i + 1 ) ; sum := sum.remainder(long("1000000007")) ; skip ; ) ; cn := cn + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package Andra ; import java.util.*; public class CumulativeTable { public static final long MOD=1000000007 ; private long[] sum ; private int[] degreeTwo ; private int n ; public CumulativeTable(int n){ this.n=n ; this.sum=new long[n+1]; this.degreeTwo=new int[n+1]; calculateDegrees(); } private void calculateDegrees(){ degreeTwo[0]=1 ; degreeTwo[1]=1 ; for(int i=2 ; i<=n ; i++){ if((i & 1)==0)degreeTwo[i]=degreeTwo[i>>1]*2 ; else degreeTwo[i]=1 ; } } public void reset(){ for(int i=0 ; i=0){ toReturn=(toReturn+sum[i])% MOD ; i=i-degreeTwo[i]; } return toReturn ; } public static void main(String[] args){ Random rnd=new Random(); int n=100 ; int[] a=new int[n]; CumulativeTable ct=new CumulativeTable(n); for(int i=0 ; icollect(0) ; self.degreeTwo := Integer.subrange(1,n + 1)->collect(0) ; execute calculateDegrees() ); operation calculateDegrees() : void pre: true post: true activity: ( degreeTwo[0+1] := 1 ; degreeTwo[1+1] := 1 ; var i : int ; i := 2 ; while i <= n do ( ( if ((MathLib.bitwiseAnd(i,1)) = 0) then degreeTwo[i+1] := degreeTwo[(i/(2->pow(1)))->oclAsType(long)+1] * 2 ; else degreeTwo[i+1] := 1 ; ) ; i := i + 1 ) ); operation reset() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n do ( sum[i+1] := 0 ; ; i := i + 1 ) ); operation add( index : int, value : long) : void pre: true post: true activity: ( var i : int ; i := index ; while (i <= n) do ( sum[i+1] := (sum[i+1] + value) mod MOD ; i := i + degreeTwo[i+1] ) ); operation count( index : int) : long pre: true post: true activity: ( var i : int ; i := index ; var toReturn : long ; toReturn := 0 ; while (i >= 0) do ( toReturn := (toReturn + sum[i+1]) mod MOD ; i := i - degreeTwo[i+1] ) ; return toReturn ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var rnd : OclRandom ; rnd := OclRandom.newOclRandom() ; var n : int ; n := 100 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var ct : CumulativeTable ; ct := CumulativeTable.newCumulativeTable(n) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 10 do ( ( var index : int ; index := rnd.nextInt(n) ; var value : int ; value := rnd.nextInt(1000) ; a[index+1] := a[index+1] + value ; ct->excludes(index, value) ; var sum : int ; sum := 0 ; var j : int ; j := 0 ; while j <= index do ( sum := sum+(a[j+1]) ; ; j := j + 1 ) ; OclFile["System.out"].println(sum) ; OclFile["System.out"].println(ct.count(index)) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package codejam2c ; import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { Scanner in=new Scanner(new FileReader("c-small.in")); PrintWriter out=new PrintWriter(new FileWriter("c-small-out.out")); final long M=1000000007 ; int T=in.nextInt(); for(int x=1 ; x<=T ; x++){ int n=in.nextInt(),m=in.nextInt(),X=in.nextInt(),Y=in.nextInt(),Z=in.nextInt(); int i,j ; int[] a=new int[n],A=new int[m]; long[] nr=new long[n]; long S=0 ; for(i=0 ; itoInteger() ; var x : int ; x := 1 ; while x <= T do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var X : int ; X := in.getCurrent()->toInteger() ; var Y : int ; Y := in.getCurrent()->toInteger() ; var Z : int ; Z := in.getCurrent()->toInteger() ; var i : int ; var j : int ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var A : Sequence(int) ; A := Integer.subrange(1,m)->collect(0) ; var nr : Sequence(long) ; nr := Integer.subrange(1,n)->collect(0) ; var S : long ; S := 0 ; i := 0 ; while i < m do ( ( A[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; i := 0 ; while i < n do ( ( a[i+1] := A[i mod m+1] ; A[i mod m+1] := (((X->oclAsType(long) * A[i mod m+1] + Y->oclAsType(long) * (i + 1))->oclAsType(long)) mod Z->oclAsType(long))->oclAsType(int) ) ; i := i + 1 ) ; nr[0+1] := 1 ; S := 1 ; i := 1 ; while i < n do ( ( nr[i+1] := 1 ; j := 0 ; while j < i do ( if (a[j+1] < a[i+1]) then ( nr[i+1] := nr[i+1]+(nr[j+1]) ; nr[i+1] := nr[i+1] mod M ) else skip ; ; j := j + 1 ) ; S := S+(nr[i+1]) ; S := S mod M ) ; i := i + 1 ) ; skip ; ) ; x := x + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ProblemC { public static void main(final String[] args){ final Scanner sc=new Scanner(System.in); final int cases=sc.nextInt(); for(int cc=1 ; cc<=cases ; cc++){ final int n=sc.nextInt(); final int m=sc.nextInt(); final long x=sc.nextLong(),y=sc.nextLong(),z=sc.nextLong(); final int[] h=new int[n]; final int[] a=new int[n]; for(int i=0 ; itoInteger() ; var cc : int ; cc := 1 ; while cc <= cases do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var x : long ; x := sc.getCurrent()->toLong() ; var y : long ; y := sc.getCurrent()->toLong() ; var z : long ; z := sc.getCurrent()->toLong() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < m do ( h[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := h[i mod m+1] ; h[i mod m+1] := ((x * h[i mod m+1] + y * (i + 1)) mod z)->oclAsType(int) ) ; i := i + 1 ) ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := 1 ; var j : int ; j := 0 ; while j < i do ( if (a[j+1] < a[i+1]) then s[i+1] := (s[i+1] + s[j+1]) mod 1000000007 ; else skip ; ; j := j + 1 ) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( count := (count + s[i+1]) mod 1000000007 ; ; i := i + 1 ) ; OclFile["System.out"].printf("Case #%s: %s\n", cc, count) ; ) ; cc := cc + 1 ) ; OclFile["System.out"].flush() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { Scanner in ; PrintWriter out ; String IFILE="c-small-attempt0.in" ; String OFILE="c-small-attempt0.out" ; final long MOD=1000000007 ; public void run()throws IOException { in=new Scanner(new File(IFILE)); out=new PrintWriter(OFILE); int nt=in.nextInt(); for(int it=0 ; ittoInteger() ; var it : int ; it := 0 ; while it < nt do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var x : long ; x := in.getCurrent()->toInteger() ; var y : long ; y := in.getCurrent()->toInteger() ; var z : long ; z := in.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( a[i+1] := in.getCurrent()->toLong() ; ; i := i + 1 ) ; var mas : Sequence(long) ; mas := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( mas[i+1] := a[i mod m+1] ; a[i mod m+1] := (x * a[i mod m+1] + y * (i + 1)) mod z ) ; i := i + 1 ) ; var f : Sequence(long) ; f := Integer.subrange(1,n)->collect(0) ; f := f->collect(1) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < i do ( if (mas[j+1] < mas[i+1]) then f[i+1] := (f[i+1] + f[j+1]) mod MOD ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ans := (ans + f[i+1]) mod MOD ; ; i := i + 1 ) ; skip ; ) ; it := it + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] a)throws Exception { BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(r.readLine()); String[] str=r.readLine().split(" "); int[] arr=new int[n]; for(int i=0 ; i=1 ; i--){ tmp=arr[0]; arr[0]=arr[i]; arr[i]=tmp ; heapify(arr,0,i); } StringBuilder s=new StringBuilder(); for(int i=0 ; i=0 ; i--){ result=heapify(arr,i,arr.length); } return result ; } private static int[] heapify(int[] arr,int index,int maxIndex){ int leftIndex=2*index+1 ; int rightIndex=2*index+2 ; int largestIndex=index ; if(leftIndexarr[index]){ largestIndex=leftIndex ; } if(rightIndexarr[largestIndex]){ largestIndex=rightIndex ; } if(largestIndex!=index){ int tmp=arr[index]; arr[index]=arr[largestIndex]; arr[largestIndex]=tmp ; heapify(arr,largestIndex,maxIndex); } return arr ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (r.readLine())->toInteger() ; var str : Sequence(String) ; str := r.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (str[i+1])->toInteger() ) ; i := i + 1 ) ; arr := buildHeap(arr) ; var tmp : int ; var i : int ; i := n - 1 ; while i >= 1 do ( ( tmp := arr[0+1] ; arr[0+1] := arr[i+1] ; arr[i+1] := tmp ; execute heapify(arr, 0, i) ) ; i := i - 1 ) ; var s : String ; s := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( s := s + StringLib.newString(arr[i+1]) ; if (i /= n - 1) then ( s := s + StringLib.newString(" ") ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; ); static operation buildHeap( arr : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var result : Sequence(int) ; result := Integer.subrange(1,arr->size())->collect(0) ; var i : int ; i := arr->size() / 2 - 1 ; while i >= 0 do ( ( result := heapify(arr, i, arr->size()) ) ; i := i - 1 ) ; return result ); static operation heapify( arr : Sequence(int), index : int, maxIndex : int) : Sequence(int) pre: true post: true activity: ( var leftIndex : int ; leftIndex := 2 * index + 1 ; var rightIndex : int ; rightIndex := 2 * index + 2 ; var largestIndex : int ; largestIndex := index ; if (leftIndex < maxIndex & arr[leftIndex+1] > arr[index+1]) then ( largestIndex := leftIndex ) else skip ; if (rightIndex < maxIndex & arr[rightIndex+1] > arr[largestIndex+1]) then ( largestIndex := rightIndex ) else skip ; if (largestIndex /= index) then ( var tmp : int ; tmp := arr[index+1] ; arr[index+1] := arr[largestIndex+1] ; arr[largestIndex+1] := tmp ; execute heapify(arr, largestIndex, maxIndex) ) else skip ; return arr ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class Main { private static void radixSort(int[] a){ ArrayList>buckets=new ArrayList>(10); for(int i=0 ; i<10 ; i++){ buckets.add(new ArrayDeque()); } for(int b : a){ buckets.get(9).add(b); } int cur=1 ; while(buckets.get(0).size()deque : buckets){ int size=deque.size(); for(int s=0 ; s0){ builder.append(" "); } builder.append(a[i]); } System.out.println(builder.toString()); scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation radixSort( a : Sequence(int)) : void pre: true post: true activity: ( var buckets : Sequence(Sequence(int)) ; buckets := Sequence{} ; var i : int ; i := 0 ; while i < 10 do ( ( buckets := buckets->including(ArrayDeque.newArrayDeque()) ) ; i := i + 1 ) ; for (b : a) do ( ( buckets->at(9+1)->excludes(b) ) ) ; var cur : int ; cur := 1 ; while (buckets->at(0+1)->size() < a->size()) do ( for (deque : buckets) do ( ( var size : int ; size := deque->size() ; var s : int ; s := 0 ; while s < size do ( ( var p : int ; p := deque->min() ; var digit : int ; digit := p / cur ; digit := digit mod 10 ; buckets->at(digit+1)->excludes(p) ) ; s := s + 1 ) ) ) ; cur := cur*(10) ) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := buckets->at(0+1)->min() ; buckets->at(0+1) := buckets->at(0+1)->sort()->tail() ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var builder : String ; builder := StringLib.newString() ; var i : int ; i := 0 ; while i < a->size() do ( ( if (i > 0) then ( builder := builder + StringLib.newString(" ") ) else skip ; builder := builder + StringLib.newString(a[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(builder+"") ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static void QuickSort(int[] arr,int left,int right){ if(left<=right){ int pivot=arr[(left+right)/2],l=left,r=right ; while(l<=r){ while(arr[l]pivot)r--; if(l<=r){ int tmp=arr[l]; arr[l]=arr[r]; arr[r]=tmp ; l++; r--; } } QuickSort(arr,left,r); QuickSort(arr,l,right); } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] data=new int[1000000]; int n=sc.nextInt(); for(int i=0 ; i pivot) do r := r - 1 ; ; if (l <= r) then ( var tmp : int ; tmp := arr[l+1] ; arr[l+1] := arr[r+1] ; arr[r+1] := tmp ; l := l + 1 ; r := r - 1 ; ) else skip ) ; execute QuickSort(arr, left, r) ; execute QuickSort(arr, l, right) ) else skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var data : Sequence(int) ; data := Integer.subrange(1,1000000)->collect(0) ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( data[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; execute QuickSort(data, 0, n - 1) ; var i : int ; i := 0 ; while i < n - 1 do ( OclFile["System.out"].print(data[i+1] + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println(data[n - 1+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String[] W=new String[n]; ArrayListans=new ArrayList<>(); for(int i=0 ; itoInteger() ; var W : Sequence(String) ; W := Integer.subrange(1,n)->collect(null) ; var ans : Sequence(String) ; ans := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( W[i+1] := sc.getCurrent() ; if (not(ans->includes(W[i+1]))) then ( ans := ans->including(W[i+1]) ) else skip ) ; i := i + 1 ) ; var cou : int ; cou := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (W[i+1]->at(W[i+1]->size() - 1+1) /= (W[i + 1+1]->at(0+1))) then ( cou := cou + 1 ) else skip ) ; i := i + 1 ) ; if (ans->size() /= n) then ( OclFile["System.out"].println("No") ) else if (cou /= 0) then ( OclFile["System.out"].println("No") ) else ( OclFile["System.out"].println("Yes") ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; public class GFG { static boolean strmatch(String str,String pattern,int n,int m){ if(m==0)return(n==0); boolean[][] lookup=new boolean[n+1][m+1]; for(int i=0 ; icollect(Integer.subrange(1,m + 1)->collect(false)) ; var i : int ; i := 0 ; while i < n + 1 do ( lookup[i+1] := lookup[i+1]->collect(false) ; ; i := i + 1 ) ; lookup[0+1][0+1] := true ; var j : int ; j := 1 ; while j <= m do ( if (pattern->at(j - 1+1) = '*') then lookup[0+1][j+1] := lookup[0+1][j - 1+1] ; else skip ; ; j := j + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= m do ( ( if (pattern->at(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->at(j - 1+1) = '?' or str->at(i - 1+1) = pattern->at(j - 1+1)) then lookup[i+1][j+1] := lookup[i - 1+1][j - 1+1] else lookup[i+1][j+1] := false ; ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return lookup[n+1][m+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "baaabab" ; var pattern : String ; pattern := "*****ba*****ab" ; if (strmatch(str, pattern, str->size(), pattern->size())) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int t=scanner.nextInt(); int s=scanner.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0 ; i=0 ; j--){ if(j-b[i]>=s || s>=j)dp[j]=Math.max(dp[j],dp[j-b[i] ]+a[i]); } for(int i=0 ; i<=t ; i++)ans=Math.max(ans,dp[i]); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var t : int ; t := scanner.getCurrent()->toInteger() ; var s : int ; s := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() ; b[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,t + 1)->collect(0) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := t ; while j - b[i+1] >= 0 do ( ( if (j - b[i+1] >= s or s >= j) then dp[j+1] := Set{dp[j+1], dp[j - b[i+1]+1] + a[i+1]}->max() ; else skip ) ; j := j - 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= t do ( ans := Set{ans, dp[i+1]}->max() ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); String line_1=buf.readLine(); int n=Integer.parseInt(line_1); int[] scores=new int[n]; String[] line_2=buf.readLine().split(" "); for(int i=0 ; itoInteger())->toInteger() + "")->toInteger())->toInteger() ; var scores : Sequence(int) ; scores := Integer.subrange(1,n)->collect(0) ; var linebuf.readLine()->split(" ") : Sequence(String) ; linebuf.readLine()->split(" ") := buf.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( ( scores[i+1] := (linei[i+1])->toInteger() ) ; i := i + 1 ) ; scores := scores->sort() ; var t : String ; t := StringLib.newString() ; t := t + StringLib.newString(scores[0+1]) ; var j : int ; j := 1 ; while j < n do ( ( t := t + StringLib.newString(" " + scores[j+1]) ) ; j := j + 1 ) ; OclFile["System.out"].println(t) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.Map ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String[] tmp=in.readLine().split(" "); Integer h=Integer.parseInt(tmp[0]); Integer w=Integer.parseInt(tmp[1]); Integer n=Integer.parseInt(tmp[2]); Integer a,b ; Mapcandidates=new HashMap<>(); long[] result=new long[10]; for(int i=0 ; i=0 ; x--){ for(int y=2 ; y>=0 ; y--){ if(a-x>=1 && b-y>=1 &&(a-x+2)<=h &&(b-y+2)<=w){ String key=(a-x)+"+"+(b-y); if(candidates.containsKey(key)){ candidates.put(key,candidates.get(key)+1); } else { candidates.put(key,1); } } } } } result[0]=(long)(h-2)*(w-2)-candidates.size(); for(Map.Entrycandidate : candidates.entrySet()){ result[candidate.getValue()]++; } for(int j=0 ; j<=9 ; j++){ System.out.println(result[j]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var tmp : Sequence(String) ; tmp := in.readLine()->split(" ") ; var h : int ; h := (tmp[0+1])->toInteger() ; var w : int ; w := (tmp[1+1])->toInteger() ; var n : int ; n := (tmp[2+1])->toInteger() ; var a : int ; var b : int ; var candidates : Map(String,int) ; candidates := Map{} ; var result : Sequence(long) ; result := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( tmp := in.readLine()->split(" ") ; a := (tmp[0+1])->toInteger() ; b := (tmp[1+1])->toInteger() ; var x : int ; x := 2 ; while x >= 0 do ( ( var y : int ; y := 2 ; while y >= 0 do ( ( if (a - x >= 1 & b - y >= 1 & (a - x + 2) <= h & (b - y + 2) <= w) then ( var key : String ; key := (a - x) + "+" + (b - y) ; if (candidates->keys()->includes(key)) then ( candidates := candidates->union(Map{key |-> candidates->at(key) + 1}) ) else ( candidates := candidates->union(Map{key |-> 1}) ) ) else skip ) ; y := y - 1 ) ) ; x := x - 1 ) ) ; i := i + 1 ) ; result[0+1] := (h - 2)->oclAsType(long) * (w - 2) - candidates.size() ; for (candidate : candidates->asSet()) do ( ( result[candidate.getValue()+1] := result[candidate.getValue()+1] + 1 ) ) ; var j : int ; j := 0 ; while j <= 9 do ( ( OclFile["System.out"].println(result[j+1]) ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Objects ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int H=scanner.nextInt(); int W=scanner.nextInt(); int N=scanner.nextInt(); HashMapfreq=new HashMap<>(); for(int i=0 ; i1 && sx1 && sytoInteger() ; var W : int ; W := scanner.getCurrent()->toInteger() ; var N : int ; N := scanner.getCurrent()->toInteger() ; var freq : Map(Point,int) ; freq := Map{} ; var i : int ; i := 0 ; while i < N do ( ( var x : int ; x := scanner.getCurrent()->toInteger() ; var y : int ; y := scanner.getCurrent()->toInteger() ; var j : int ; j := -1 ; while j <= 1 do ( ( var k : int ; k := -1 ; while k <= 1 do ( ( var sx : int ; sx := x + j ; var sy : int ; sy := y + k ; if (sx > 1 & sx < H & sy > 1 & sy < W) then ( var p : Point ; p := Point.newPoint(sx, sy) ; freq := freq->union(Map{p |-> (if freq->keys()->contains(p) then freq->at(p) else 0 endif) + 1}) ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var total : Sequence(long) ; total := Integer.subrange(1,10)->collect(0) ; total[0+1] := (H - 2)->oclAsType(long) * (W - 2) - freq.size() ; for (f : freq->values()) do ( total[f+1] := total[f+1] + 1 ; ) ; for (t : total) do ( ( OclFile["System.out"].println(t) ) ) ; ); static class Point { attribute x : int; attribute y : int; static operation newPoint( x : int, y : int) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation equals( o : OclAny) : boolean pre: true post: true activity: ( if (self = o) then return true else skip ; if (o = null or getClass() /= o->oclType()) then return false else skip ; var point : Point ; point := o->oclAsType(Point) ; return x = point.x & y = point.y ); operation hashCode() : int pre: true post: true activity: ( return Objects.hash(x, y) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main extends PrintWriter { Main(){ super(System.out,true); } Scanner sc=new Scanner(System.in); public static void main(String[] $){ Main o=new Main(); o.main(); o.flush(); } static class V { int i,j ; V(int i,int j){ this.i=i ; this.j=j ; } } void main(){ int n=sc.nextInt(); int m=sc.nextInt(); int k=sc.nextInt(); int k_=k*9 ; V[] vv=new V[k_]; k_=0 ; while(k-->0){ int a=sc.nextInt(); int b=sc.nextInt(); for(int i=a-2 ; i<=a ; i++)for(int j=b-2 ; j<=b ; j++)if(i>=1 && j>=1 && i+2<=n && j+2<=m)vv[k_++]=new V(i,j); } Arrays.sort(vv,0,k_,(u,v)->u.i!=v.i ? u.i-v.i : u.j-v.j); int[] kk=new int[10]; for(int u=0,v ; utoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var k_ : int ; k_ := k * 9 ; var vv : Sequence(V) ; vv := Integer.subrange(1,k_)->collect(null) ; k_ := 0 ; while (k > 0) do ( k := k - 1 ; skip ; ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var i : int ; i := a - 2 ; while i <= a do ( var j : int ; j := b - 2 ; while j <= b do ( if (i >= 1 & j >= 1 & i + 2 <= n & j + 2 <= m) then vv[k_+1] := V.newV(i, j) ; k_ := k_ + 1 ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ) ; ) ; vv, 0, k_, lambda (u , v) : OclAny in if u.i /= v.i then u.i - v.i else u.j - v.j endif := vv, 0, k_, lambda (u , v) : OclAny in if u.i /= v.i then u.i - v.i else u.j - v.j endif->sort() ; var kk : Sequence(int) ; kk := Integer.subrange(1,10)->collect(0) ; var u : int ; u := 0 ; var v : int ; while u < k_ do ( ( var i : int ; i := vv[u+1].i ; var j : int ; j := vv[u+1].j ; v := u + 1 ; while (v < k_ & vv[v+1].i = i & vv[v+1].j = j) do v := v + 1 ; ; kk[v - u+1] := kk[v - u+1] + 1 ) ; u := v ) ; var z : long ; z := (n - 2)->oclAsType(long) * (m - 2) ; var h : int ; h := 1 ; while h < 10 do ( z := z-(kk[h+1]) ; ; h := h + 1 ) ; execute println(z) ; var h : int ; h := 1 ; while h < 10 do ( execute println(kk[h+1]) ; ; h := h + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long H=sc.nextLong(); long W=sc.nextLong(); int N=sc.nextInt(); int a[]=new int[N]; int b[]=new int[N]; HashMapmap=new HashMap(); for(int i=0 ; i=H-2)continue out ; in : for(int x=0 ; x<3 ; x++){ if(b[i]-x<0 || b[i]-x>=W-2)continue in ; if(map.containsKey(l-x-y*W)){ map.put(l-x-y*W,map.get(l-x-y*W)+1); } else { map.put(l-x-y*W,1); } } } } long ans[]=new long[10]; int cnt=0 ; for(long key : map.keySet()){ ans[map.get(key)]++; cnt++; } ans[0]=(H-2)*(W-2)-cnt ; for(int i=0 ; i<10 ; i++){ System.out.println(ans[i]); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var H : long ; H := sc.getCurrent()->toLong() ; var W : long ; W := sc.getCurrent()->toLong() ; var N : int ; N := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,N)->collect(0) ; var map : Map(long,int) ; map := Map{} ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := sc.getCurrent()->toInteger() - 1 ; b[i+1] := sc.getCurrent()->toInteger() - 1 ; var l : long ; l := b[i+1] + a[i+1] * W ; var y : int ; y := 0 ; while y < 3 do ( ( if (a[i+1] - y < 0 or a[i+1] - y >= H - 2) then continue else skip ; var x : int ; x := 0 ; while x < 3 do ( ( if (b[i+1] - x < 0 or b[i+1] - x >= W - 2) then continue else skip ; if (map->keys()->includes(l - x - y * W)) then ( map := map->union(Map{l - x - y * W |-> map->at(l - x - y * W) + 1}) ) else ( map := map->union(Map{l - x - y * W |-> 1}) ) ) ; x := x + 1 ) ; ) ; y := y + 1 ) ; ) ; i := i + 1 ) ; var ans : Sequence(long) ; ans := Integer.subrange(1,10)->collect(0) ; var cnt : int ; cnt := 0 ; for (key : map->keys()) do ( ( ans[map->at(key)+1] := ans[map->at(key)+1] + 1 ; cnt := cnt + 1 ) ) ; ans[0+1] := (H - 2) * (W - 2) - cnt ; var i : int ; i := 0 ; while i < 10 do ( ( OclFile["System.out"].println(ans[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int n=sc.nextInt(); int[] arrA=new int[n]; int[] arrB=new int[n]; for(int i=0 ; iresult=new HashMap<>(); for(int i=0 ; iresult,int a,int b,int h,int w){ for(int x=a-2 ; x<=a ; x++){ if(x<1 || x>h-2){ continue ; } for(int y=b-2 ; y<=b ; y++){ if(y<1 || y>w-2){ continue ; } String point=x+" "+y ; if(! result.containsKey(point)){ result.put(point,Integer.valueOf(1)); } else { int count=result.get(point); result.put(point,count+1); } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var arrA : Sequence(int) ; arrA := Integer.subrange(1,n)->collect(0) ; var arrB : Sequence(int) ; arrB := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arrA[i+1] := sc.getCurrent()->toInteger() ; arrB[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; var result : Map(String,int) ; result := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := arrA[i+1] ; var b : int ; b := arrB[i+1] ; execute putBlack(result, a, b, h, w) ) ; i := i + 1 ) ; var count : Sequence(long) ; count := Integer.subrange(1,10)->collect(0) ; count := count->collect(0) ; count[0+1] := (h - 2)->oclAsType(long) * (w - 2)->oclAsType(long) ; for (val : result->values()) do ( ( count[val+1] := count[val+1]+(1) ; count[0+1] := count[0+1]-(1) ) ) ; var i : int ; i := 0 ; while i <= 9 do ( ( OclFile["System.out"].println(count[i+1]) ) ; i := i + 1 ) ; ); static operation putBlack( result : Map(String,int), a : int, b : int, h : int, w : int) : void pre: true post: true activity: ( var x : int ; x := a - 2 ; while x <= a do ( ( if (x < 1 or x > h - 2) then ( continue ) else skip ; var y : int ; y := b - 2 ; while y <= b do ( ( if (y < 1 or y > w - 2) then ( continue ) else skip ; var point : String ; point := x + " " + y ; if (not(result->keys()->includes(point))) then ( result := result->union(Map{point |-> (1)->toInteger()}) ) else ( var count : int ; count := result->at(point) ; result := result->union(Map{point |-> count + 1}) ) ) ; y := y + 1 ) ) ; x := x + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class BCowsAndPokerGame { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int a=0,i=0 ; String s=in.next(); for(char x : s.toCharArray()){ if(x=='A')++a ; else if(x=='I')++i ; } System.out.print(i==1 ? 1 : i==0 ? a : 0); } } ------------------------------------------------------------ OCL File: --------- class BCowsAndPokerGame { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : int ; a := 0 ; var i : int ; i := 0 ; var s : String ; s := in.getCurrent() ; for (x : s->characters()) do ( ( if (x = 'A') then a := a + 1 ; else if (x = 'I') then i := i + 1 ; else skip ; ) ) ; OclFile["System.out"].print(if i = 1 then 1 else if i = 0 then a else 0 endif endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); Integer n=s.nextInt(); String hands=s.next(); Long a=hands.chars().filter(c->c=='A').count(); Long i=hands.chars().filter(c->c=='I').count(); Long f=hands.chars().filter(c->c=='F').count(); Integer result=i>1 ? 0 : i==1 ? 1 : a.intValue(); System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var hands : String ; hands := s.getCurrent() ; var a : long ; a := hands.chars()->select( _x1 | (lambda c : OclAny in c = 'A')->apply(_x1) )->size() ; var i : long ; i := hands.chars()->select( _x1 | (lambda c : OclAny in c = 'I')->apply(_x1) )->size() ; var f : long ; f := hands.chars()->select( _x1 | (lambda c : OclAny in c = 'F')->apply(_x1) )->size() ; var result : int ; result := if i > 1 then 0 else if i = 1 then 1 else a->oclAsType(int) endif endif ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; public class ExtractNumbers { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=br.readLine(); String[] token=str.split("[,;] ",-1); getWords(token); } private static void getWords(String[] stringList){ StringBuilder asb=new StringBuilder(); boolean flaga=false ; boolean flagb=false ; StringBuilder bsb=new StringBuilder(); for(String s : stringList){ if(isInteger(s)){ if(flaga){ asb.append(","+s); } else { flaga=true ; asb.append(s); } } else { if(flagb){ bsb.append(","+s); } else { flagb=true ; bsb.append(s); } } } String a=asb.toString(); String b=bsb.toString(); System.out.println((! flaga)? "-" :("\""+a+"\"")); System.out.println((! flagb)? "-" :("\""+b+"\"")); } private static boolean isInteger(String s){ try { if(s.length()<=9){ int i=Integer.parseInt(s); if(Integer.toString(i).equals(s)){ return true ; } return false ; } else { if(s.startsWith("0")){ return false ; } for(int i=0 ; i9){ return false ; } } return true ; } } catch(Exception ex){ return false ; } } } ------------------------------------------------------------ OCL File: --------- class ExtractNumbers { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : String ; str := br.readLine() ; var token : Sequence(String) ; token := str->split("[,;] ") ; execute getWords(token) ); static operation getWords( stringList : Sequence(String)) : void pre: true post: true activity: ( var asb : String ; asb := StringLib.newString() ; var flaga : boolean ; flaga := false ; var flagb : boolean ; flagb := false ; var bsb : String ; bsb := StringLib.newString() ; for (s : stringList) do ( ( if (isInteger(s)) then ( if (flaga) then ( asb := asb + StringLib.newString("," + s) ) else ( flaga := true ; asb := asb + StringLib.newString(s) ) ) else ( if (flagb) then ( bsb := bsb + StringLib.newString("," + s) ) else ( flagb := true ; bsb := bsb + StringLib.newString(s) ) ) ) ) ; var a : String ; a := asb+"" ; var b : String ; b := bsb+"" ; OclFile["System.out"].println(if (not(flaga)) then "-" else ("\"" + a + "\"") endif) ; OclFile["System.out"].println(if (not(flagb)) then "-" else ("\"" + b + "\"") endif) ; ); static operation isInteger( s : String) : boolean pre: true post: true activity: ( try ( if (s->size() <= 9) then ( var i : int ; i := (s)->toInteger() ; if (((i) + "") = s) then ( return true ) else skip ; return false ) else ( if (s->hasPrefix("0")) then ( return false ) else skip ; var i : int ; i := 0 ; while i < s->size() do ( ( if (((s->at(i+1) - ('0')->char2byte()) < 0) or (s->at(i+1) - ('0')->char2byte()) > 9) then ( return false ) else skip ) ; i := i + 1 ) ; return true ) ) catch (ex : ProgramException) do ( return false ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static void largestInColumn(int cols,int[][] arr){ for(int i=0 ; imaxm)maxm=arr[j][i]; System.out.println(maxm); } } public static void main(String[] args){ int[][] arr=new int[][] { { 3,4,1,8 },{ 1,4,9,11 },{ 76,34,21,1 },{ 2,1,4,5 } }; largestInColumn(4,arr); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation largestInColumn( cols : int, arr : Sequence(Sequence(int))) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < cols do ( ( var maxm : int ; maxm := arr[0+1][i+1] ; var j : int ; j := 1 ; while j < arr[i+1]->size() do ( if (arr[j+1][i+1] > maxm) then maxm := arr[j+1][i+1] ; else skip ; ; j := j + 1 ) ; OclFile["System.out"].println(maxm) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(Sequence(int)) ; arr := Sequence{Sequence{3,4,1,8},Sequence{1,4,9,11},Sequence{76,34,21,1},Sequence{2,1,4,5}} ; execute largestInColumn(4, arr) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static int INF=2<<27 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); int s=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0 ; it)continue ; if(tmp>s && jpow(27)))->oclAsType(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var s : int ; s := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,t + 1)->collect(0)) ; var i : int ; i := 0 ; while i < n + 1 do ( ( dp[i+1][0+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j <= t do ( ( dp[i + 1+1][j+1] := Set{dp[i+1][j+1], dp[i + 1+1][j+1]}->max() ; var tmp : int ; tmp := j + b[i+1] ; if (tmp > t) then continue else skip ; if (tmp > s & j < s) then ( dp[i + 1+1][s+1] := Set{dp[i + 1+1][s+1], dp[i+1][j+1]}->max() ) else ( dp[i + 1+1][tmp+1] := Set{dp[i + 1+1][tmp+1], dp[i+1][j+1] + a[i+1]}->max() ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i <= t do ( ( ans := Set{ans, dp[n+1][i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.util.*; class GFG { static void countDigit(int n){ int temp=n,sum=0,product=1 ; while(temp!=0){ int d=temp % 10 ; temp/=10 ; if(d>0 && n % d==0){ sum+=d ; product*=d ; } } System.out.print("Sum="+sum); System.out.print("\nProduct="+product); } public static void main(String args[]){ int n=1012 ; countDigit(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countDigit( n : int) : void pre: true post: true activity: ( var temp : int ; temp := n ; var sum : int ; sum := 0 ; var product : int ; product := 1 ; while (temp /= 0) do ( var d : int ; d := temp mod 10 ; temp := temp/(10) ; if (d > 0 & n mod d = 0) then ( sum := sum+(d) ; product := product*(d) ) else skip ) ; OclFile["System.out"].print("Sum=" + sum) ; OclFile["System.out"].print("\nProduct=" + product) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 1012 ; execute countDigit(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int minCost(char[] s){ boolean alphabets[]=new boolean[26]; for(int i=0 ; icollect(false) ; var i : int ; i := 0 ; while i < s->size() do ( ( alphabets[s[i+1]->oclAsType(int) - 97+1] := true ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < 26 do ( ( if (alphabets[i+1]) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "geeksforgeeks" ; OclFile["System.out"].println("Total cost to construct " + s + " is " + minCost(s->characters())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int L=sc.nextInt(); int a=sc.nextInt(); int[] t=new int[n]; int[] l=new int[n]; int sum=0 ; for(int i=0 ; itoInteger() ; var L : int ; L := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var l : Sequence(int) ; l := Integer.subrange(1,n)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( t[i+1] := sc.getCurrent()->toInteger() ; l[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var s : int ; s := 0 ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( ans := ans+((t[i+1] - s) / a) ; s := t[i+1] + l[i+1] ) ; i := i + 1 ) ; ans := ans+((L - s) / a) ; OclFile["System.out"].println(ans) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class test { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int L=sc.nextInt(); int a=sc.nextInt(); if(n>0){ long ctr=0,cnt=0 ; for(long i=0 ; i=a){ cnt+=(diff/a); } int nextctr=t+l ; ctr=nextctr ; } if(ctrtoInteger() ; var L : int ; L := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; if (n > 0) then ( var ctr : long ; ctr := 0 ; var cnt : long ; cnt := 0 ; var i : long ; i := 0 ; while i < n do ( ( var t : int ; t := sc.getCurrent()->toInteger() ; var l : int ; l := sc.getCurrent()->toInteger() ; var diff : long ; diff := t - ctr ; if (diff >= a) then ( cnt := cnt+((diff / a)) ) else skip ; var nextctr : int ; nextctr := t + l ; ctr := nextctr ; ) ; i := i + 1 ) ; if (ctr < L) then ( var nn : long ; nn := L - ctr ; cnt := cnt+((nn / a)) ) else skip ; OclFile["System.out"].println(cnt) ) else ( OclFile["System.out"].println(L / a) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner M=new Scanner(System.in); int guke=M.nextInt(); int zongshichang=M.nextInt(); int xiuxi=M.nextInt(); int cishu=0 ; int kaishi=0 ; int last=0 ; int shichang=0 ; for(int i=0 ; itoInteger() ; var zongshichang : int ; zongshichang := M.getCurrent()->toInteger() ; var xiuxi : int ; xiuxi := M.getCurrent()->toInteger() ; var cishu : int ; cishu := 0 ; var kaishi : int ; kaishi := 0 ; var last : int ; last := 0 ; var shichang : int ; shichang := 0 ; var i : int ; i := 0 ; while i < guke do ( ( kaishi := M.getCurrent()->toInteger() ; shichang := M.getCurrent()->toInteger() ; cishu := cishu + (kaishi - last) / xiuxi ; last := kaishi + shichang ) ; i := i + 1 ) ; cishu := cishu + (zongshichang - last) / xiuxi ; OclFile["System.out"].print(cishu) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class main { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ String s=sc.next(); s=s+"A" ; Listalpha=new ArrayList<>(); char c ; String ans="" ; for(c='a' ; c<='z' ; c++){ alpha.add(c); } int[] freq=new int[26]; Arrays.fill(freq,0); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var s : String ; s := sc.getCurrent() ; s := s + "A" ; var alpha : Sequence(String) ; alpha := Sequence{} ; var c : String ; var ans : String ; ans := "" ; c := 'a' ; while c <= 'z' do ( ( alpha := alpha->including(c) ) ; c := c + 1 ) ; var freq : Sequence(int) ; freq := Integer.subrange(1,26)->collect(0) ; freq := freq->collect(0) ; var i : int ; i := 0 ; while i < s->size() - 1 do ( ( var w : String ; w := s->at(i+1) ; if (freq[alpha->indexOf(w)-1+1] = 1) then continue else skip ; if (s->at(i + 1+1) = w) then ( freq[alpha->indexOf(w)-1+1] := 2 ; i := i + 1 ) else freq[alpha->indexOf(w)-1+1] := 1 ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 26 do ( ( if (freq[i+1] = 1) then ans := ans + alpha->at(i+1) ; else skip ) ; i := i + 1 ) ; if (s->size() = 1) then OclFile["System.out"].println(s) else OclFile["System.out"].println(ans) ; ; ) ; ) ); static operation isPrime( n : long) : boolean 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 ; i := 5 ; while i * i <= n do ( if (n mod i = 0 or n mod (i + 2) = 0) then return false else skip ; ; i := i + 6 ) ; return true ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation lcm( a : long, b : long) : long pre: true post: true activity: ( return (a / gcd(a, b)) * b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); boolean[] is_prime=new boolean[1000001]; for(int i=2 ; i<1000001 ; i++){ is_prime[i]=true ; } for(int i=2 ; i<=1000 ; i++){ if(is_prime[i]){ for(int j=2*i ; j<1000001 ; j+=i){ is_prime[j]=false ; } } } while(true){ final int a=sc.nextInt(); final int b=sc.nextInt(); if(a==0 && b==0){ break ; } int a_sum=0 ; int a_max=0 ; for(int i=2 ; i<=a ; i++){ if(! is_prime[i]){ continue ; } else if(a % i!=0){ continue ; } a_sum+=i ; a_max=i ; } int a_key=a_max+a_max-a_sum ; int b_sum=0 ; int b_max=0 ; for(int i=2 ; i<=b ; i++){ if(! is_prime[i]){ continue ; } else if(b % i!=0){ continue ; } b_sum+=i ; b_max=i ; } int b_key=b_max+b_max-b_sum ; if(a_key>b_key){ System.out.println("a"); } else { System.out.println("b"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var is_prime : Sequence(boolean) ; is_prime := Integer.subrange(1,1000001)->collect(false) ; var i : int ; i := 2 ; while i < 1000001 do ( ( is_prime[i+1] := true ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= 1000 do ( ( if (is_prime[i+1]) then ( var j : int ; j := 2 * i ; while j < 1000001 do ( ( is_prime[j+1] := false ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; while (true) do ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (a = 0 & b = 0) then ( break ) else skip ; var a_sum : int ; a_sum := 0 ; var a_max : int ; a_max := 0 ; var i : int ; i := 2 ; while i <= a do ( ( if (not(is_prime[i+1])) then ( continue ) else if (a mod i /= 0) then ( continue ) else skip ; ; a_sum := a_sum+(i) ; a_max := i ) ; i := i + 1 ) ; var a_key : int ; a_key := a_max + a_max - a_sum ; var b_sum : int ; b_sum := 0 ; var b_max : int ; b_max := 0 ; var i : int ; i := 2 ; while i <= b do ( ( if (not(is_prime[i+1])) then ( continue ) else if (b mod i /= 0) then ( continue ) else skip ; ; b_sum := b_sum+(i) ; b_max := i ) ; i := i + 1 ) ; var b_key : int ; b_key := b_max + b_max - b_sum ; if (a_key > b_key) then ( OclFile["System.out"].println("a") ) else ( OclFile["System.out"].println("b") ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Snowball { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int w=sc.nextInt(); int h=sc.nextInt(); int u1=sc.nextInt(); int d1=sc.nextInt(); int u2=sc.nextInt(); int d2=sc.nextInt(); while(h>0){ w+=h ; if(d1==h){ if(u1>w)w=0 ; else w-=u1 ; } else if(d2==h){ if(u2>w)w=0 ; else w-=u2 ; } h--; } System.out.println(w); } } ------------------------------------------------------------ OCL File: --------- class Snowball { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var w : int ; w := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; var u1 : int ; u1 := sc.getCurrent()->toInteger() ; var d1 : int ; d1 := sc.getCurrent()->toInteger() ; var u2 : int ; u2 := sc.getCurrent()->toInteger() ; var d2 : int ; d2 := sc.getCurrent()->toInteger() ; while (h > 0) do ( w := w+(h) ; if (d1 = h) then ( if (u1 > w) then w := 0 ; else w := w-(u1) ; ) else if (d2 = h) then ( if (u2 > w) then w := 0 ; else w := w-(u2) ; ) else skip ; ; h := h - 1 ) ; OclFile["System.out"].println(w) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class P1099A { public static void main(String[] args)throws IOException { BufferedReader io=new BufferedReader(new InputStreamReader(System.in)); String[] wh=io.readLine().split(" "); Integer w=Integer.valueOf(wh[0]); Integer h=Integer.valueOf(wh[1]); String[] s1=io.readLine().split(" "); Integer u1=Integer.valueOf(s1[0]); Integer d1=Integer.valueOf(s1[1]); String[] s2=io.readLine().split(" "); Integer u2=Integer.valueOf(s2[0]); Integer d2=Integer.valueOf(s2[1]); while(h>=0){ w=w+h ; if(d1.equals(h)){ w=w-u1 ; if(w.compareTo(0)<0){ w=0 ; } } if(d2.equals(h)){ w=w-u2 ; if(w.compareTo(0)<0){ w=0 ; } } h--; } System.out.println(w); } } ------------------------------------------------------------ OCL File: --------- class P1099A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : OclFile ; io := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var wh : Sequence(String) ; wh := io.readLine()->split(" ") ; var w : int ; w := (wh[0+1])->toInteger() ; var h : int ; h := (wh[1+1])->toInteger() ; var s1 : Sequence(String) ; s1 := io.readLine()->split(" ") ; var u1 : int ; u1 := (s1[0+1])->toInteger() ; var d1 : int ; d1 := (s1[1+1])->toInteger() ; var s2 : Sequence(String) ; s2 := io.readLine()->split(" ") ; var u2 : int ; u2 := (s2[0+1])->toInteger() ; var d2 : int ; d2 := (s2[1+1])->toInteger() ; while (h >= 0) do ( w := w + h ; if (d1 = h) then ( w := w - u1 ; if (w->compareTo(0) < 0) then ( w := 0 ) else skip ) else skip ; if (d2 = h) then ( w := w - u2 ; if (w->compareTo(0) < 0) then ( w := 0 ) else skip ) else skip ; h := h - 1 ) ; OclFile["System.out"].println(w) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),T=sc.nextInt(),S=sc.nextInt(); int[] a=new int[n],b=new int[n]; for(int i=0 ; itoInteger() ; var T : int ; T := sc.getCurrent()->toInteger() ; var S : int ; S := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,T + 1)->collect(0)) ; var j : int ; j := b[0+1] ; while j <= T do ( ( dp[0+1][j+1] := dp[0+1][j - 1+1] ; if (not((j - b[0+1] < S & S < j))) then dp[0+1][j+1] := a[0+1] ; else skip ) ; j := j + 1 ) ; var i : int ; i := 1 ; while i < n do ( var t : int ; t := 1 ; while t <= T do ( ( dp[i+1][t+1] := Set{dp[i - 1+1][t+1], dp[i+1][t - 1+1]}->max() ; if (b[i+1] <= t & not((t - b[i+1] < S & S < t))) then dp[i+1][t+1] := Set{dp[i+1][t+1], dp[i - 1+1][t - b[i+1]+1] + a[i+1]}->max() ; else skip ) ; t := t + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(dp[n - 1+1][T+1]) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; int[] c=new int[n]; for(int i=0 ; i=c[j]){ j++; } bc[i]=n-j ; } } long ret=0 ; for(int i=n-1 ; i>0 ; i--){ bc[i-1]+=bc[i]; } { int j=0 ; for(int i=0 ; i=b[j]){ j++; } ret+=jtoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( c[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; b := b->sort() ; c := c->sort() ; var bc : Sequence(long) ; bc := Integer.subrange(1,n)->collect(0) ; ( var j : int ; j := 0 ; var i : int ; i := 0 ; while i < n do ( ( while (j < n & b[i+1] >= c[j+1]) do ( j := j + 1 ) ; bc[i+1] := n - j ) ; i := i + 1 ) ) var ret : long ; ret := 0 ; var i : int ; i := n - 1 ; while i > 0 do ( ( bc[i - 1+1] := bc[i - 1+1]+(bc[i+1]) ) ; i := i - 1 ) ; ( var j : int ; j := 0 ; var i : int ; i := 0 ; while i < n do ( ( while (j < n & a[i+1] >= b[j+1]) do ( j := j + 1 ) ; ret := ret+(if j < n then bc[j+1] else 0 endif) ) ; i := i + 1 ) ) OclFile["System.out"].println(ret) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskC solver=new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); int[] a=new int[n]; int[] b=new int[n]; int[] c=new int[n]; for(int i=0 ; i0){ res+=dp1[u-1]; } } out.println(res); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskC ; solver := TaskC.newTaskC() ; solver.solve(1, in, out) ; skip ; ); static class TaskC { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( c[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; a := a->sort() ; b := b->sort() ; c := c->sort() ; var dp1 : Sequence(long) ; dp1 := Integer.subrange(1,n)->collect(0) ; dp1 := dp1->collect(0) ; var u : int ; u := 0 ; var d : int ; d := 0 ; while d < n do ( ( while (u < n & a[u+1] < b[d+1]) do u := u + 1 ; ; if (d = 0) then ( dp1[d+1] := u ) else ( dp1[d+1] := dp1[d - 1+1] + u ) ) ; d := d + 1 ) ; u := 0 ; var res : long ; res := 0 ; var d : int ; d := 0 ; while d < n do ( ( while (u < n & b[u+1] < c[d+1]) do u := u + 1 ; ; if (u > 0) then ( res := res+(dp1[u - 1+1]) ) else skip ) ; d := d + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); int n=sc.nextInt(); Integer[] a=new Integer[n]; Integer[] b=new Integer[n]; Integer[] c=new Integer[n]; for(int i=0 ; ix.compareTo(y)>=0 ? 1 :-1); cc=n-~ Arrays.binarySearch(c,b[i],(x,y)->x.compareTo(y)>0 ? 1 :-1); ans+=aa*cc ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sb : String ; sb := StringLib.newString() ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(null) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(null) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( c[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; c := c->sort() ; var ans : long ; ans := 0 ; var aa : long ; var cc : long ; var i : int ; i := 0 ; while i < n do ( ( aa := -((a->indexOf(lambda (x , y) : OclAny in if x->compareTo(y) >= 0 then 1 else -1 endif) - 1) + 1) ; cc := (n)->char2byte() - -((c->indexOf(lambda (x , y) : OclAny in if x->compareTo(y) > 0 then 1 else -1 endif) - 1) + 1) ; ans := ans+(aa * cc) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (sc.getCurrent())->toInteger() ; ; i := i + 1 ) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := (sc.getCurrent())->toInteger() ; ; i := i + 1 ) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( c[i+1] := (sc.getCurrent())->toInteger() ; ; i := i + 1 ) ; a := a->sort() ; b := b->sort() ; c := c->sort() ; var ret : long ; ret := 0 ; var s : int ; s := 0 ; var t : int ; t := -1 ; var i : int ; i := 0 ; while i < n do ( ( while (s < n & c[s+1] <= b[i+1]) do s := s + 1 ; ; while (t < n - 1 & a[t + 1+1] < b[i+1]) do t := t + 1 ; ; ret := ret+((n - s)->oclAsType(long) * (t + 1)) ) ; i := i + 1 ) ; OclFile["System.out"].println(ret) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static int countDigits(int num){ int cnt=0 ; while(num>0){ cnt++; num/=10 ; } return cnt ; } public static int sumFromStart(int num,int n,int rem){ num/=((int)Math.pow(10,rem)); int sum=0 ; while(num>0){ sum+=(num % 10); num/=10 ; } return sum ; } public static int sumFromEnd(int num,int n){ int sum=0 ; for(int i=0 ; i 0) do ( cnt := cnt + 1 ; num := num/(10) ) ; return cnt ); static operation sumFromStart( num : int, n : int, rem : int) : int pre: true post: true activity: ( num := num/((10->pow(rem)->oclAsType(int))) ; var sum : int ; sum := 0 ; while (num > 0) do ( sum := sum+((num mod 10)) ; num := num/(10) ) ; return sum ); static operation sumFromEnd( num : int, n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+((num mod 10)) ; num := num/(10) ) ; i := i + 1 ) ; return sum ); static operation getAverage( n : int, k : int, l : int) : double pre: true post: true activity: ( var totalDigits : int ; totalDigits := countDigits(n) ; if (totalDigits < (k + l)) then return -1 else skip ; var sum1 : int ; sum1 := sumFromEnd(n, l) ; var sum2 : int ; sum2 := sumFromStart(n, k, totalDigits - k) ; return ((sum1 + sum2)->oclAsType(double) / (k + l)->oclAsType(double)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 123456 ; var k : int ; k := 2 ; var l : int ; l := 3 ; OclFile["System.out"].print(getAverage(n, k, l)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class GFG { static int nthTerm(int n){ int d=2,a1=0 ; int An=a1+(n-1)*d ; return(int)Math.pow(An,3); } public static void main(String[] args){ int n=5 ; System.out.println(nthTerm(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation nthTerm( n : int) : int pre: true post: true activity: ( var d : int ; d := 2 ; var a1 : int ; a1 := 0 ; var An : int ; An := a1 + (n - 1) * d ; return An->pow(3)->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(nthTerm(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { Scanner sc ; Main(){ sc=new Scanner(System.in); } public static void main(String[] args){ new Main().run(); } void debug(Object...o){ System.out.println(Arrays.deepToString(o)); } int a,b ; boolean init(){ a=sc.nextInt(); b=sc.nextInt(); if(a==0 && b==0)return false ; return true ; } ArrayListfactor(int n){ ArrayListret=new ArrayList(); for(int i=2 ; i<=n ; i++){ if(n % i==0){ ret.add(i); while(n % i==0){ n/=i ; } } } return ret ; } int key(int n){ ArrayListfactors=factor(n); int sum=0 ; for(int f : factors){ sum+=f ; } int biggest=factors.get(factors.size()-1); sum-=biggest ; return biggest-sum ; } void run(){ while(init()){ System.out.println(key(a)>key(b)? "a" : "b"); } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((o + "")) ); attribute a : int; operation init() : boolean pre: true post: true activity: ( a := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; if (a = 0 & b = 0) then return false else skip ; return true ); operation factor( n : int) : Sequence(int) pre: true post: true activity: ( var ret : Sequence(int) ; ret := Sequence{} ; var i : int ; i := 2 ; while i <= n do ( ( if (n mod i = 0) then ( ret := ret->including(i) ; while (n mod i = 0) do ( n := n/(i) ) ) else skip ) ; i := i + 1 ) ; return ret ); operation key( n : int) : int pre: true post: true activity: ( var factors : Sequence(int) ; factors := factor(n) ; var sum : int ; sum := 0 ; for (f : factors) do ( ( sum := sum+(f) ) ) ; var biggest : int ; biggest := factors->at(factors->size() - 1+1) ; sum := sum-(biggest) ; return biggest - sum ); operation run() : void pre: true post: true activity: ( while (init()) do ( OclFile["System.out"].println(if key(a) > key(b) then "a" else "b" endif) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Map.Entry ; class Main { static int mod=(int)(Math.pow(10,9)+7); static List>list=new ArrayList>(); public static void main(String[] args){ Scanner sc=new Scanner(System.in); int H=sc.nextInt(); int W=sc.nextInt(); int[][] c=new int[H][W]; for(int i=0 ; ipow(9) + 7)->oclAsType(int); static attribute list : Sequence(Sequence(int)) := Sequence{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var H : int ; H := sc.getCurrent()->toInteger() ; var W : int ; W := sc.getCurrent()->toInteger() ; var c : Sequence(Sequence(int)) ; c := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( c[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : String ; ans := StringLib.newString() ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( if (c[i+1][j+1] mod 2 = 1) then ( if (j = W - 1) then ( if (i /= H - 1) then ( c[i + 1+1][j+1] := c[i + 1+1][j+1] + 1 ; ans := ans + StringLib.newString(i + 1) ; ans := ans + StringLib.newString(" ") ; ans := ans + StringLib.newString(j + 1) ; ans := ans + StringLib.newString(" ") ; ans := ans + StringLib.newString(i + 2) ; ans := ans + StringLib.newString(" ") ; ans := ans + StringLib.newString(j + 1) ; ans := ans + StringLib.newString("\n") ; cnt := cnt + 1 ; ) else skip ) else ( c[i+1][j + 1+1] := c[i+1][j + 1+1] + 1 ; ans := ans + StringLib.newString(i + 1) ; ans := ans + StringLib.newString(" ") ; ans := ans + StringLib.newString(j + 1) ; ans := ans + StringLib.newString(" ") ; ans := ans + StringLib.newString(i + 1) ; ans := ans + StringLib.newString(" ") ; ans := ans + StringLib.newString(j + 2) ; ans := ans + StringLib.newString("\n") ; cnt := cnt + 1 ; ) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; OclFile["System.out"].print(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int height=sc.nextInt(); int width=sc.nextInt(); boolean oddCoin[][]=new boolean[height][width]; for(int i=0 ; ioutput=new ArrayList(); for(int i=0 ; itoInteger() ; var width : int ; width := sc.getCurrent()->toInteger() ; var oddCoin : Sequence(Sequence(boolean)) ; oddCoin := Integer.subrange(1,height)->collect(Integer.subrange(1,width)->collect(false)) ; var i : int ; i := 0 ; while i < height do ( ( var j : int ; j := 0 ; while j < width do ( ( oddCoin[i+1][j+1] := sc.getCurrent()->toInteger() mod 2 = 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var output : Sequence(String) ; output := Sequence{} ; var i : int ; i := 0 ; while i < height - 1 do ( ( var j : int ; j := 0 ; while j < width do ( ( if (oddCoin[i+1][j+1]) then ( count := count + 1 ; oddCoin[i+1][j+1] := not(oddCoin[i+1][j+1]) ; oddCoin[i + 1+1][j+1] := not(oddCoin[i + 1+1][j+1]) ; output := output->including((i + 1) + " " + (j + 1) + " " + (i + 1 + 1) + " " + (j + 1)) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < width - 1 do ( ( if (oddCoin[height - 1+1][j+1]) then ( count := count + 1 ; oddCoin[height - 1+1][j+1] := not(oddCoin[height - 1+1][j+1]) ; oddCoin[height - 1+1][j + 1+1] := not(oddCoin[height - 1+1][j + 1+1]) ; output := output->including(height + " " + (j + 1) + " " + height + " " + (j + 2)) ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println(count) ; var i : int ; i := 0 ; while i < output->size() do ( ( OclFile["System.out"].println(output->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int[][] a=new int[h][w]; for(int i=0 ; ians=new ArrayList(h*w); for(int i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( a[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; var space : String ; space := " " ; var ans : Sequence(String) ; ans := Sequence{}->union(h * w) ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w - 1 do ( ( if (a[i+1][j+1] mod 2 = 1) then ( a[i+1][j+1] := a[i+1][j+1] - 1 ; a[i+1][j + 1+1] := a[i+1][j + 1+1] + 1 ; var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString(i + 1) + StringLib.newString(space) + StringLib.newString(j + 1) + StringLib.newString(space) + StringLib.newString(i + 1) + StringLib.newString(space) + StringLib.newString(j + 2) ; ans := ans->including(sb+"") ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < h - 1 do ( ( if (a[i+1][w - 1+1] mod 2 = 1) then ( a[i+1][w - 1+1] := a[i+1][w - 1+1] - 1 ; a[i + 1+1][w - 1+1] := a[i + 1+1][w - 1+1] + 1 ; var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString(i + 1) + StringLib.newString(space) + StringLib.newString(w) + StringLib.newString(space) + StringLib.newString(i + 2) + StringLib.newString(space) + StringLib.newString(w) ; ans := ans->including(sb+"") ; ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans->size()) ; for (s : ans) do ( ( OclFile["System.out"].println(s) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int T=sc.nextInt(); int S=sc.nextInt(); int[] A=new int[N]; int[] B=new int[N]; for(int i=0 ; itoInteger() ; var T : int ; T := sc.getCurrent()->toInteger() ; var S : int ; S := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var B : Sequence(int) ; B := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ; B[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,T + 1)->collect(Integer.subrange(1,N + 1)->collect(0)) ; var i : int ; i := 0 ; while i < T do ( ( var j : int ; j := 0 ; while j < N do ( ( var n : int ; n := i + B[j+1] ; if ((S <= i or n <= S) & n <= T) then ( dp[n+1][j + 1+1] := Set{dp[n+1][j + 1+1], dp[i+1][j+1] + A[j+1]}->max() ) else skip ; dp[i+1][j + 1+1] := Set{dp[i+1][j + 1+1], dp[i+1][j+1]}->max() ; dp[i + 1+1][j + 1+1] := Set{dp[i + 1+1][j + 1+1], dp[i+1][j + 1+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i <= T do ( ( var j : int ; j := 0 ; while j <= N do ( ( ans := Set{ans, dp[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int[][] map=new int[h][w]; ArrayListlist=new ArrayList<>(); int sum=0 ; for(int i=0 ; i=0 ; j--){ if(jud){ if(j==w-1){ list.add(i+" "+(j+1)+" "+(i+1)+" "+(j+1)); sum++; } else { list.add((i+1)+" "+(j+2)+" "+(i+1)+" "+(j+1)); sum++; } } if(map[i][j] % 2==1){ jud=! jud ; } } } } System.out.println(sum); for(String i : list){ System.out.println(i); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var map : Sequence(Sequence(int)) ; map := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var list : Sequence(String) ; list := Sequence{} ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( map[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var jud : boolean ; jud := false ; var i : int ; i := 0 ; while i < h do ( ( if (i mod 2 = 0) then ( var j : int ; j := 0 ; while j < w do ( ( if (jud) then ( if (j = 0) then ( list := list->including(i + " " + (j + 1) + " " + (i + 1) + " " + (j + 1)) ; sum := sum + 1 ) else ( list := list->including((i + 1) + " " + j + " " + (i + 1) + " " + (j + 1)) ; sum := sum + 1 ) ) else skip ; if (map[i+1][j+1] mod 2 = 1) then ( jud := not(jud) ) else skip ) ; j := j + 1 ) ) else ( var j : int ; j := w - 1 ; while j >= 0 do ( ( if (jud) then ( if (j = w - 1) then ( list := list->including(i + " " + (j + 1) + " " + (i + 1) + " " + (j + 1)) ; sum := sum + 1 ) else ( list := list->including((i + 1) + " " + (j + 2) + " " + (i + 1) + " " + (j + 1)) ; sum := sum + 1 ) ) else skip ; if (map[i+1][j+1] mod 2 = 1) then ( jud := not(jud) ) else skip ) ; j := j - 1 ) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; for (i : list) do ( ( OclFile["System.out"].println(i) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.System.*; import static java.lang.Math.*; public class pre6 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader obj=new FastReader(); int count=0 ; int n=obj.nextInt(); for(int i=1 ; i<=n ; i++){ for(int j=i+1 ; j<=n ; j++){ int k=i ^ j ; if(k>j && k<=n &&(i+j)>k &&(i+k)>j &&(j+k)>i){ count++; } } } out.println(count); } } ------------------------------------------------------------ OCL File: --------- class pre6 { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : FastReader ; obj := FastReader.newFastReader() ; var count : int ; count := 0 ; var n : int ; n := obj.nextInt() ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := i + 1 ; while j <= n do ( ( var k : int ; k := MathLib.bitwiseXor(i,j) ; if (k > j & k <= n & (i + j) > k & (i + k) > j & (j + k) > i) then ( count := count + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; out.println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class forest { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int c=0 ; int counter=0 ; for(int a=1 ; a<=n ; a++){ for(int b=a ; b<=n ; b++){ c=a ^ b ; if(c<=n &&(c<(a+b))&&(a ^ b ^ c)==0 && c>b){ counter++; } } } System.out.println(counter); } } ------------------------------------------------------------ OCL File: --------- class forest { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var c : int ; c := 0 ; var counter : int ; counter := 0 ; var a : int ; a := 1 ; while a <= n do ( ( var b : int ; b := a ; while b <= n do ( ( c := MathLib.bitwiseXor(a,b) ; if (c <= n & (c < (a + b)) & (MathLib.bitwiseXor(MathLib.bitwiseXor(a,b),c)) = 0 & c > b) then ( counter := counter + 1 ) else skip ) ; b := b + 1 ) ) ; a := a + 1 ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Demo2 { public static void main(String[] args){ int n,res=0 ; Scanner scanner=new Scanner(System.in); n=scanner.nextInt(); for(int i=1 ; ij && k<=n)res++; } } System.out.println(res/3); } } ------------------------------------------------------------ OCL File: --------- class Demo2 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; var res : int ; res := 0 ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := scanner.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := i + 1 ; while j <= n do ( ( var k : int ; k := MathLib.bitwiseXor(i,j) ; if (k < i + j & k + i > j & k <= n) then res := res + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(res / 3) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class div_2_572_a { public static void main(String args[]){ FScanner in=new FScanner(); PrintWriter out=new PrintWriter(System.out); int n=in.nextInt(); String s=in.next(); int c=0 ; for(int i=0 ; iat(i+1) ; if (ch = '1') then c := c + 1 ; else c := c - 1 ; ) ; i := i + 1 ) ; if (c /= 0) then ( skip ; skip ) else ( skip ; skip ) ; skip ; ); static class FScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute sb : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(sb.hasNext())) do ( try ( sb := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do skip ) ; return sb.next() ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : IOException) do skip return "" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } _572_a { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FScanner ; in := FScanner.newFScanner() ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.nextInt() ; var s : String ; s := in.next() ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < n do ( ( var ch : String ; ch := s->at(i+1) ; if (ch = '1') then c := c + 1 ; else c := c - 1 ; ) ; i := i + 1 ) ; if (c /= 0) then ( skip ; skip ) else ( skip ; skip ) ; skip ; ); static class FScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute sb : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(sb.hasNext())) do ( try ( sb := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do skip ) ; return sb.next() ); operation nextLine() : String pre: true post: true activity: ( try ( return br.readLine() ) catch (e : IOException) do skip return "" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int longestSubArray(int arr[],int n){ boolean isZeroPresent=false ; for(int i=0 ; isize() ; OclFile["System.out"].print(longestSubArray(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class HelloWorld { public static void solve(int n,int m,int k){ System.out.println((n<=m && n<=k ? "Yes" : "No")); } public static void sol(int n){ int ans=0 ; for(int i=1 ; itoInteger() ; var s : String ; s := sc.getCurrent() ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (s->at(i+1) = '1') then ( cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; if (cnt = n - (cnt)->char2byte()) then ( OclFile["System.out"].println(2) ; var res : String ; res := s.subrange(1+1,1) ; OclFile["System.out"].println(s->at(0+1) + " " + res) ) else ( OclFile["System.out"].println(1) ; OclFile["System.out"].println(s) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printGP(int a,int r,int n){ int curr_term ; for(int i=0 ; ipow(i)->oclAsType(int) ; OclFile["System.out"].print(curr_term + " ") ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 2 ; var r : int ; r := 3 ; var n : int ; n := 5 ; execute printGP(a, r, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void midpoint(int x1,int x2,int y1,int y2){ System.out.print((x1+x2)/2+","+(y1+y2)/2); } public static void main(String[] args){ int x1=-1,y1=2 ; int x2=3,y2=-6 ; midpoint(x1,x2,y1,y2); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation midpoint( x1 : int, x2 : int, y1 : int, y2 : int) : void pre: true post: true activity: ( OclFile["System.out"].print((x1 + x2) / 2 + "," + (y1 + y2) / 2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x1 : int ; x1 := -1 ; var y1 : int ; y1 := 2 ; var x2 : int ; x2 := 3 ; var y2 : int ; y2 := -6 ; execute midpoint(x1, x2, y1, y2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Main { static int ceilSearch(int arr[],int low,int high,int x){ int mid ; if(x<=arr[low])return low ; if(x>arr[high])return-1 ; mid=(low+high)/2 ; if(arr[mid]==x)return mid ; else if(arr[mid]=low && x>arr[mid-1])return mid ; else return ceilSearch(arr,low,mid-1,x); } } public static void main(String[] args){ int arr[]={ 1,2,8,10,10,12,19 }; int n=arr.length ; int x=8 ; int index=ceilSearch(arr,0,n-1,x); if(index==-1)System.out.println("Ceiling of "+x+" doesn't exist in array"); else System.out.println("ceiling of "+x+" is "+arr[index]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation ceilSearch( arr : Sequence(int), low : int, high : int, x : int) : int pre: true post: true activity: ( var mid : int ; if (x <= arr[low+1]) then return low else skip ; if (x > arr[high+1]) then return -1 else skip ; mid := (low + high) / 2 ; if (arr[mid+1] = x) then return mid else if (arr[mid+1] < x) then ( if (mid + 1 <= high & x <= arr[mid + 1+1]) then return mid + 1 else return ceilSearch(arr, mid + 1, high, x) ) else ( if (mid - 1 >= low & x > arr[mid - 1+1]) then return mid else return ceilSearch(arr, low, mid - 1, x) ) ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,8,10,10,12,19} ; var n : int ; n := arr->size() ; var x : int ; x := 8 ; var index : int ; index := ceilSearch(arr, 0, n - 1, x) ; if (index = -1) then OclFile["System.out"].println("Ceiling of " + x + " doesn't exist in array") else OclFile["System.out"].println("ceiling of " + x + " is " + arr[index+1]) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Arrays ; import java.util.HashSet ; import java.util.Iterator ; import java.util.Scanner ; import java.util.Set ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int N=scan.nextInt(); long[] a=new long[(1<=0 ; --j){ j &=K ; if(a[j]>max1){ max2=max1 ; max1=a[j]; } else if(a[j]>max2){ max2=a[j]; } } bef=Math.max(bef,max1+max2); out.println(bef); } out.flush(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scan.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,((1*(2->pow(N)))->oclAsType(long)))->collect(0) ; var i : int ; i := 0 ; while i < ((1*(2->pow(N)))->oclAsType(long)) do ( a[i+1] := scan.getCurrent()->toLong() ; ; i := i + 1 ) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var bef : long ; bef := 0 ; var K : int ; K := 1 ; while K < ((1*(2->pow(N)))->oclAsType(long)) do ( ( var max1 : long ; max1 := -1 ; var max2 : long ; max2 := -1 ; var j : int ; j := K ; while j >= 0 do ( ( j := MathLib.bitwiseAnd(j, K) ; if (a[j+1] > max1) then ( max2 := max1 ; max1 := a[j+1] ) else if (a[j+1] > max2) then ( max2 := a[j+1] ) else skip ; ) ; j := j - 1 ) ; bef := Set{bef, max1 + max2}->max() ; skip ; ) ; K := K + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Set ; public final class p347 implements EulerSolution { public static void main(String[] args){ System.out.println(new p347().run()); } private static final int LIMIT=10000000 ; public String run(){ Setpossible=new HashSet<>(); int[] primes=Library.listPrimes(LIMIT/2); for(int i=0,end=Library.sqrt(LIMIT); iend)break ; for(int j=i+1 ; jLIMIT)break ; int multLimit=LIMIT/lcm ; int multiplier=1 ; while(multiplier*p<=multLimit)multiplier*=p ; int maxMult=multiplier ; while(multiplier % p==0){ multiplier/=p ; while(multiplier*q<=multLimit)multiplier*=q ; maxMult=Math.max(multiplier,maxMult); } possible.add(maxMult*lcm); } } long sum=0 ; for(int x : possible)sum+=x ; return Long.toString(sum); } } ------------------------------------------------------------ OCL File: --------- class p347 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p347.newp347().run()) ); static attribute LIMIT : int := 10000000; operation run() : String pre: true post: true activity: ( var possible : Set(int) ; possible := Set{} ; var primes : Sequence(int) ; primes := Library.listPrimes(LIMIT / 2) ; var i : int ; i := 0 ; var end : int ; end := Library.sqrt(LIMIT) ; while i < primes->size() do ( ( var p : int ; p := primes[i+1] ; if (p > end) then break else skip ; var j : int ; j := i + 1 ; while j < primes->size() do ( ( var q : int ; q := primes[j+1] ; var lcm : int ; lcm := p * q ; if (lcm > LIMIT) then break else skip ; var multLimit : int ; multLimit := LIMIT / lcm ; var multiplier : int ; multiplier := 1 ; while (multiplier * p <= multLimit) do multiplier := multiplier*(p) ; ; var maxMult : int ; maxMult := multiplier ; while (multiplier mod p = 0) do ( multiplier := multiplier/(p) ; while (multiplier * q <= multLimit) do multiplier := multiplier*(q) ; ; maxMult := Set{multiplier, maxMult}->max() ) ; possible := possible->including(maxMult * lcm) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; for (x : possible) do ( sum := sum+(x) ; ) ; return ((sum) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] h=new int[n]; for(int i=0 ; i=k)count++; System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( h[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( if (h[i+1] >= k) then count := count + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int count=0 ; for(int i=0 ; i=k)count++; } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x >= k) then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); System.out.println(IntStream.range(0,N).filter(i->sc.nextInt()>=K).count()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(Integer.subrange(0, N-1)->select( _x1 | (lambda i : OclAny in sc.getCurrent()->toInteger() >= K)->apply(_x1) )->size()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { final int INF=1<<28 ; void run(){ Scanner sc=new Scanner(System.in); final int MAX=1000*1000+1 ; boolean isPrime[]=new boolean[MAX]; Arrays.fill(isPrime,true); int[] primes=new int[MAX]; int idx=0 ; for(int i=2 ; ia || primes[i]==0){ a_key=last-sum ; break ; } if(a % primes[i]==0){ sum+=last ; last=primes[i]; } i++; } sum=0 ; last=0 ; i=0 ; int b_key=0 ; while(true){ if(primes[i]>b || primes[i]==0){ b_key=last-sum ; break ; } if(b % primes[i]==0){ sum+=last ; last=primes[i]; } i++; } System.out.println(a_key>b_key ? "a" : "b"); } } public static void main(String[] args)throws Exception { new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute INF : int := (1*(2->pow(28)))->oclAsType(long); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var MAX : int ; MAX := 1000 * 1000 + 1 ; var isPrime : Sequence(boolean) ; isPrime := Integer.subrange(1,MAX)->collect(false) ; isPrime := isPrime->collect(true) ; var primes : Sequence(int) ; primes := Integer.subrange(1,MAX)->collect(0) ; var idx : int ; idx := 0 ; var i : int ; i := 2 ; while i < MAX do ( ( if (isPrime[i+1]) then ( primes[idx+1] := i ; idx := idx + 1 ; var j : int ; j := i + i ; while j < MAX do ( ( isPrime[j+1] := false ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; while (true) do ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(a,b)) = 0) then break else skip ; var i : int ; i := 0 ; var sum : int ; sum := 0 ; var last : int ; last := 0 ; var a_key : int ; a_key := 0 ; while (true) do ( if (primes[i+1] > a or primes[i+1] = 0) then ( a_key := last - sum ; break ) else skip ; if (a mod primes[i+1] = 0) then ( sum := sum+(last) ; last := primes[i+1] ) else skip ; i := i + 1 ) ; sum := 0 ; last := 0 ; i := 0 ; var b_key : int ; b_key := 0 ; while (true) do ( if (primes[i+1] > b or primes[i+1] = 0) then ( b_key := last - sum ; break ) else skip ; if (b mod primes[i+1] = 0) then ( sum := sum+(last) ; last := primes[i+1] ) else skip ; i := i + 1 ) ; OclFile["System.out"].println(if a_key > b_key then "a" else "b" endif) ; ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Solver { private final int K ; Solver(Scanner in){ int N=in.nextInt(); K=in.nextInt(); int count=0 ; for(int i=0 ; i=K)count++; } System.out.println(count); } void solve(){ } } class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); new Solver(in).solve(); in.close(); } } ------------------------------------------------------------ OCL File: --------- class Solver { attribute K : int; static operation newSolver( in : OclFile) : Solver pre: true post: true activity: ( var self : Solver ; self := createSolver(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( var N : int ; N := in.nextInt() ; K := in.nextInt() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (in.nextInt() >= K) then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); operation solve() : void pre: true post: true activity: skip; } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; Solver.newSolver(in).solve() ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import java.math.BigInteger ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] h=new int[n]; int result=0 ; for(int i=0 ; i=k)result++; } System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < n do ( ( h[i+1] := sc.getCurrent()->toInteger() ; if (h[i+1] >= k) then result := result + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Improve { static boolean isVowel(char c){ String vowel="aeiou" ; for(int i=0 ; icount2)return false ; } return true ; } public static void main(String args[]){ String name="alex",typed="aaalaeex" ; if(printRLE(name,typed))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class Improve { static operation isVowel( c : String) : boolean pre: true post: true activity: ( var vowel : String ; vowel := "aeiou" ; var i : int ; i := 0 ; while i < vowel->size() do ( if (vowel->at(i+1) = c) then return true else skip ; ; i := i + 1 ) ; return false ); static operation printRLE( str : String, typed : String) : boolean pre: true post: true activity: ( var n : int ; n := str->size() ; var m : int ; m := typed->size() ; var j : int ; j := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (str->at(i+1) /= typed->at(j+1)) then return false else skip ; if (isVowel(str->at(i+1)) = false) then ( j := j + 1 ; continue ) else skip ; var count1 : int ; count1 := 1 ; while (i < n - 1 & str->at(i+1) = str->at(i + 1+1)) do ( count1 := count1 + 1 ; i := i + 1 ) ; var count2 : int ; count2 := 1 ; while (j < m - 1 & typed->at(j+1) = str->at(i+1)) do ( count2 := count2 + 1 ; j := j + 1 ) ; if (count1 > count2) then return false else skip ; ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var name : String ; name := "alex" ; var typed : String ; typed := "aaalaeex" ; if (printRLE(name, typed)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int N=2 ; static Boolean isVowel(char ch){ return(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'); } static void performQueries(String str,int len,int queries[][],int q){ int[] pre=new int[len]; if(isVowel(str.charAt(0)))pre[0]=1 ; else pre[0]=0 ; for(int i=1 ; icollect(0) ; if (isVowel(str->at(0+1))) then pre[0+1] := 1 else pre[0+1] := 0 ; ; var i : int ; i := 1 ; while i < len do ( ( if (isVowel(str->at(i+1))) then pre[i+1] := 1 + pre[i - 1+1] ; else pre[i+1] := pre[i - 1+1] ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( if (queries[i+1][0+1] = 0) then ( OclFile["System.out"].println(pre[queries[i+1][1+1]+1]) ) else ( OclFile["System.out"].println((pre[queries[i+1][1+1]+1] - pre[queries[i+1][0+1] - 1+1])) ) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var len : int ; len := str->size() ; var queries : Sequence(Sequence(int)) ; queries := Sequence{Sequence{1,3},Sequence{2,4},Sequence{1,9}} ; var q : int ; q := queries->size() ; execute performQueries(str, len, queries, q) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static final int MAX_CHAR=26 ; static boolean arekAnagrams(String str1,String str2,int k){ int n=str1.length(); if(str2.length()!=n)return false ; int[] count1=new int[MAX_CHAR]; int[] count2=new int[MAX_CHAR]; int count=0 ; for(int i=0 ; icount2[i])count=count+Math.abs(count1[i]-count2[i]); return(count<=k); } public static void main(String args[]){ String str1="anagram" ; String str2="grammar" ; int k=2 ; if(arekAnagrams(str1,str2,k))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX_CHAR : int := 26; static operation arekAnagrams( str1 : String, str2 : String, k : int) : boolean pre: true post: true activity: ( var n : int ; n := str1->size() ; if (str2->size() /= n) then return false else skip ; var count1 : Sequence(int) ; count1 := Integer.subrange(1,MAX_CHAR)->collect(0) ; var count2 : Sequence(int) ; count2 := Integer.subrange(1,MAX_CHAR)->collect(0) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( count1[str1->at(i+1) - ('a')->char2byte()+1] := count1[str1->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( count2[str2->at(i+1) - ('a')->char2byte()+1] := count2[str2->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < MAX_CHAR do ( if (count1[i+1] > count2[i+1]) then count := count + if count1[i+1] - count2[i+1] < 0 then -(count1[i+1] - count2[i+1]) else count1[i+1] - count2[i+1] endif ; else skip ; ; i := i + 1 ) ; return (count <= k) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str1 : String ; str1 := "anagram" ; var str2 : String ; str2 := "grammar" ; var k : int ; k := 2 ; if (arekAnagrams(str1, str2, k)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int[] BitsSetTable256=new int[256]; public static void initialize(){ BitsSetTable256[0]=0 ; for(int i=0 ; i<256 ; i++){ BitsSetTable256[i]=(i & 1)+BitsSetTable256[i/2]; } } public static int countSetBits(int n){ return(BitsSetTable256[n & 0xff]+BitsSetTable256[(n>>8)& 0xff]+BitsSetTable256[(n>>16)& 0xff]+BitsSetTable256[n>>24]); } public static void main(String[] args){ initialize(); int n=9 ; System.out.print(countSetBits(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute BitsSetTable256 : Sequence(int) := Integer.subrange(1,256)->collect(0); static operation initialize() : void pre: true post: true activity: ( BitsSetTable256[0+1] := 0 ; var i : int ; i := 0 ; while i < 256 do ( ( BitsSetTable256[i+1] := (MathLib.bitwiseAnd(i,1)) + BitsSetTable256[i / 2+1] ) ; i := i + 1 ) ); static operation countSetBits( n : int) : int pre: true post: true activity: ( return (BitsSetTable256[n & 0xff+1] + BitsSetTable256[((n/(2->pow(8)))->oclAsType(long)) & 0xff+1] + BitsSetTable256[((n/(2->pow(16)))->oclAsType(long)) & 0xff+1] + BitsSetTable256[(n/(2->pow(24)))->oclAsType(long)+1]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute initialize() ; var n : int ; n := 9 ; OclFile["System.out"].print(countSetBits(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); PriorityQueueqH=new PriorityQueue<>(); PriorityQueueqW=new PriorityQueue<>(); for(int i=0 ; i0 && qW.size()>0){ if(qH.peek()>qW.peek()){ total+=qH.size()*qW.poll(); } else { total+=qW.size()*qH.poll(); } } System.out.println(total); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var qH : Sequence(long) ; qH := Sequence{} ; var qW : Sequence(long) ; qW := Sequence{} ; var i : int ; i := 0 ; while i < h do ( ( qH := qH->including(sc.getCurrent()->toLong()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < h do ( ( qW := qW->including(sc.getCurrent()->toLong()) ) ; i := i + 1 ) ; var total : long ; total := 0 ; while (qH->size() > 0 & qW->size() > 0) do ( if (qH->min() > qW->min()) then ( total := total+(qH->size() * qW->min()) ) else ( total := total+(qW->size() * qH->min()) ) ) ; OclFile["System.out"].println(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countSwap(String str){ int n=str.length(); char s[]=str.toCharArray(); int count=0 ; for(int i=0 ; isize() ; var s : Sequence(String) ; s := str->characters() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n / 2 do ( ( var left : int ; left := i ; var right : int ; right := n - left - 1 ; while (left < right) do ( if (s[left+1] = s[right+1]) then ( break ) else ( right := right - 1 ) ) ; if (left = right) then ( return -1 ) else ( var j : int ; j := right ; while j < n - left - 1 do ( ( var t : String ; t := s[j+1] ; s[j+1] := s[j + 1+1] ; s[j + 1+1] := t ; count := count + 1 ) ; j := j + 1 ) ) ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "geeksfgeeks" ; var count : int ; count := countSwap(s) ; OclFile["System.out"].println(count) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countSC(int N){ int res=(int)Math.sqrt(N)+(int)Math.cbrt(N)-(int)(Math.sqrt(Math.cbrt(N))); return res ; } public static void main(String[] args){ int N=20 ; System.out.println("Number of squares "+"and cubes is "+countSC(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSC( N : int) : int pre: true post: true activity: ( var res : int ; res := (N)->sqrt()->oclAsType(int) + (N)->cbrt()->oclAsType(int) - (((N)->cbrt())->sqrt())->oclAsType(int) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 20 ; OclFile["System.out"].println("Number of squares " + "and cubes is " + countSC(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Collections ; import java.util.HashMap ; import java.util.Vector ; class GFG { static String lucas_sequence(String s,int n){ HashMapm=new HashMap<>(); for(int i=0 ; iv1=new Vector<>(); Vectorv2=new Vector<>(); for(HashMap.Entryentry : m.entrySet())v1.add(entry.getValue()); Collections.sort(v1); if(v1.elementAt(0)==1 && v1.elementAt(1)==2){ v1.set(0,2); v1.set(1,1); } else return "NO" ; int a=2,b=1 ; int c ; v2.add(a); v2.add(b); for(int i=0 ; iunion(Map{s->at(i+1) |-> if m->at(s->at(i+1)) = null then 1 else m->at(s->at(i+1)) + 1 endif}) ; ; i := i + 1 ) ; var v1 : Sequence(int) ; v1 := Sequence{} ; var v2 : Sequence(int) ; v2 := Sequence{} ; for (entry : m->asSet()) do ( v1 := v1->including(entry.getValue()) ; ) ; v1 := v1->sort() ; if (v1->at(0+1) = 1 & v1->at(1+1) = 2) then ( v1 := v1.setAt(0+1,2) ; v1 := v1.setAt(1+1,1) ) else return "NO" ; var a : int ; a := 2 ; var b : int ; b := 1 ; var c : int ; v2 := v2->including(a) ; v2 := v2->including(b) ; var i : int ; i := 0 ; while i < v1->size() - 2 do ( ( v2 := v2->including(a + b) ; c := a + b ; a := b ; b := c ) ; i := i + 1 ) ; var flag : int ; flag := 1 ; var i : int ; i := 0 ; while i < v1->size() do ( ( if (v1->at(i+1) /= v2->at(i+1)) then ( flag := 0 ; break ) else skip ) ; i := i + 1 ) ; if (flag = 1) then return "YES" else return "NO" ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "oooeeeeqkk" ; var n : int ; n := s->size() ; OclFile["System.out"].println(lucas_sequence(s, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int pm=1000000 ; boolean[] prime=new boolean[pm+1000]; for(int i=2 ; i<=pm ; i++)prime[i]=true ; for(int i=2 ; i<=pm+1 ; i++){ for(int j=i+i ; j<=pm ; j+=i){ prime[j]=false ; } } while(true){ int[] in=new int[2]; in[0]=sc.nextInt(); in[1]=sc.nextInt(); if(in[0]==0 && in[1]==0)break ; int[] m=new int[2]; for(int i=0 ; i<2 ; i++){ int max=-1 ; for(int j=in[i]; j>1 ; j--){ if(prime[j] && in[i] % j==0){ if(max==-1)max=j ; else m[i]+=j ; } } m[i]=max-m[i]; } if(m[0]>m[1])System.out.println("a"); else System.out.println("b"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pm : int ; pm := 1000000 ; var prime : Sequence(boolean) ; prime := Integer.subrange(1,pm + 1000)->collect(false) ; var i : int ; i := 2 ; while i <= pm do ( prime[i+1] := true ; ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= pm + 1 do ( ( var j : int ; j := i + i ; while j <= pm do ( ( prime[j+1] := false ) ; j := j+(i) ) ) ; i := i + 1 ) ; while (true) do ( var in : Sequence(int) ; in := Integer.subrange(1,2)->collect(0) ; in[0+1] := sc.getCurrent()->toInteger() ; in[1+1] := sc.getCurrent()->toInteger() ; if (in[0+1] = 0 & in[1+1] = 0) then break else skip ; var m : Sequence(int) ; m := Integer.subrange(1,2)->collect(0) ; var i : int ; i := 0 ; while i < 2 do ( ( var max : int ; max := -1 ; var j : int ; j := in[i+1] ; while j > 1 do ( ( if (prime[j+1] & in[i+1] mod j = 0) then ( if (max = -1) then max := j ; else m[i+1] := m[i+1]+(j) ; ) else skip ) ; j := j - 1 ) ; m[i+1] := max - m[i+1] ) ; i := i + 1 ) ; if (m[0+1] > m[1+1]) then OclFile["System.out"].println("a") else OclFile["System.out"].println("b") ; ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static int findRepeatFirstN2(String s){ int p=-1,i,j ; for(i=0 ; isize() do ( ( j := i + 1 ; while j < s->size() do ( ( if (s->at(i+1) = s->at(j+1)) then ( p := i ; break ) else skip ) ; j := j + 1 ) ; if (p /= -1) then break else skip ) ; i := i + 1 ) ; return p ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var pos : int ; pos := findRepeatFirstN2(str) ; if (pos = -1) then OclFile["System.out"].println("Not found") ; else OclFile["System.out"].println(str->at(pos+1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void relativeComplement(int arr1[],int arr2[],int n,int m){ int i=0,j=0 ; while(iarr2[j]){ j++; } else if(arr1[i]==arr2[j]){ i++; j++; } } while(i arr2[j+1]) then ( j := j + 1 ) else if (arr1[i+1] = arr2[j+1]) then ( i := i + 1 ; j := j + 1 ) else skip ; ; ) ; while (i < n) do OclFile["System.out"].print(arr1[i+1] + " ") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr1 : Sequence(int) ; arr1 := Sequence{3,6,10,12,15} ; var arr2 : Sequence(int) ; arr2 := Sequence{1,3,5,10,16} ; var n : int ; n := arr1->size() ; var m : int ; m := arr2->size() ; execute relativeComplement(arr1, arr2, n, m) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Solution { public int lengthOfLongestSubstring(String s){ int[] charMap=new int[256]; Arrays.fill(charMap,-1); int i=0,maxLen=0 ; for(int j=0 ; j=i){ i=charMap[s.charAt(j)]+1 ; } charMap[s.charAt(j)]=j ; maxLen=Math.max(j-i+1,maxLen); } return maxLen ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation lengthOfLongestSubstring( s : String) : int pre: true post: true activity: ( var charMap : Sequence(int) ; charMap := Integer.subrange(1,256)->collect(0) ; charMap := charMap->collect(-1) ; var i : int ; i := 0 ; var maxLen : int ; maxLen := 0 ; var j : int ; j := 0 ; while j < s->size() do ( ( if (charMap[s->at(j+1)+1] >= i) then ( i := charMap[s->at(j+1)+1] + 1 ) else skip ; charMap[s->at(j+1)+1] := j ; maxLen := Set{j - i + 1, maxLen}->max() ) ; j := j + 1 ) ; return maxLen ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class main { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int m=sc.nextInt(); int arr[]=new int[n]; int arr1[]=new int[m]; for(int i=0 ; i0)ans++; for(int i=1 ; i<=m/2 ; i++){ int temp=Math.abs(arr1[i]-arr1[m-i]); if(temp==0 && arr1[i]!=0)ans++; else ans+=temp ; } System.out.println(ans); } } public static boolean isPowerOfTen(long input){ if(input % 10!=0 || input==0){ return false ; } if(input==10){ return true ; } return isPowerOfTen(input/10); } static boolean isPrime(long n){ if(n<=1)return false ; if(n<=3)return true ; if(n % 2==0 || n % 3==0)return false ; for(int i=5 ; i*i<=n ; i=i+6)if(n % i==0 || n %(i+2)==0)return false ; return true ; } static long gcd(long a,long b){ if(a==0)return b ; return gcd(b % a,a); } static long lcm(long a,long b){ return(a/gcd(a,b))*b ; } } ------------------------------------------------------------ OCL File: --------- class main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var arr1 : Sequence(int) ; arr1 := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr1[sc.getCurrent()->toInteger() mod m+1] := arr1[sc.getCurrent()->toInteger() mod m+1] + 1 ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; if (arr1[0+1] > 0) then ans := ans + 1 ; else skip ; var i : int ; i := 1 ; while i <= m / 2 do ( ( var temp : int ; temp := if arr1[i+1] - arr1[m - i+1] < 0 then -(arr1[i+1] - arr1[m - i+1]) else arr1[i+1] - arr1[m - i+1] endif ; if (temp = 0 & arr1[i+1] /= 0) then ans := ans + 1 ; else ans := ans+(temp) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ) ); static operation isPowerOfTen( input : long) : boolean pre: true post: true activity: ( if (input mod 10 /= 0 or input = 0) then ( return false ) else skip ; if (input = 10) then ( return true ) else skip ; return isPowerOfTen(input / 10) ); static operation isPrime( n : long) : boolean 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 ; i := 5 ; while i * i <= n do ( if (n mod i = 0 or n mod (i + 2) = 0) then return false else skip ; ; i := i + 6 ) ; return true ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation lcm( a : long, b : long) : long pre: true post: true activity: ( return (a / gcd(a, b)) * b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static long mod=(long)(1e9+7); public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),m=in.nextInt(),k=in.nextInt()+1 ; int a[]=new int[n]; ArrayListlist=new ArrayList<>(); for(int i=0 ; ioclAsType(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() + 1 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var list : Sequence(int) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( list := list->including(in.getCurrent()->toInteger()) ) ; i := i + 1 ) ; list := list->sort() ; var max : int ; max := list->at(n - 1+1) ; var min : int ; min := list->at(n - 2+1) ; var div : long ; div := m / k ; var sub : long ; sub := m - div ; sub := sub * max ; div := div*(min) ; var sum : long ; sum := div + sub ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MathsSecondAttempt { public static void main(String[] args){ Emotes(); } public static void Emotes(){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); int k=scan.nextInt(); int largest=Integer.MIN_VALUE ; int larger=Integer.MIN_VALUE ; for(int i=0 ; ilargest){ larger=largest ; largest=x ; } else if(x>larger)larger=x ; } long minusage=m/(k+1); long maxusage=m-minusage ; long out=(maxusage*largest)+(minusage*larger); System.out.println(out); } } ------------------------------------------------------------ OCL File: --------- class MathsSecondAttempt { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute Emotes() ); static operation Emotes() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var largest : int ; largest := -2147483648 ; var larger : int ; larger := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := scan.getCurrent()->toInteger() ; if (x > largest) then ( larger := largest ; largest := x ) else if (x > larger) then larger := x ; else skip ; ) ; i := i + 1 ) ; var minusage : long ; minusage := m / (k + 1) ; var maxusage : long ; maxusage := m - minusage ; var out : long ; out := (maxusage * largest) + (minusage * larger) ; OclFile["System.out"].println(out) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static double floatError(double no){ double sum=0.0 ; for(int i=0 ; i<10 ; i++){ sum=sum+no ; } return sum ; } public static void main(String[] args){ System.out.println(floatError(0.1)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation floatError( no : double) : double pre: true post: true activity: ( var sum : double ; sum := 0.0 ; var i : int ; i := 0 ; while i < 10 do ( ( sum := sum + no ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(floatError(0.1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int H=scan.nextInt(); int W=scan.nextInt(); long A[]=new long[H+1]; long B[]=new long[W+1]; A[0]=0 ; for(int i=1 ; i<=H ; i++){ A[i]=-scan.nextInt(); } B[0]=0 ; for(int i=1 ; i<=W ; i++){ B[i]=-scan.nextInt(); } Arrays.sort(A); Arrays.sort(B); int pos1=0,pos2=0 ; long ans=0 ; for(int loop=0 ; looptoInteger() ; var W : int ; W := scan.getCurrent()->toInteger() ; var A : Sequence(long) ; A := Integer.subrange(1,H + 1)->collect(0) ; var B : Sequence(long) ; B := Integer.subrange(1,W + 1)->collect(0) ; A[0+1] := 0 ; var i : int ; i := 1 ; while i <= H do ( ( A[i+1] := -scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; B[0+1] := 0 ; var i : int ; i := 1 ; while i <= W do ( ( B[i+1] := -scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; A := A->sort() ; B := B->sort() ; var pos1 : int ; pos1 := 0 ; var pos2 : int ; pos2 := 0 ; var ans : long ; ans := 0 ; var loop : int ; loop := 0 ; while loop < H + W do ( ( if (A[pos1+1] < B[pos2+1]) then ( ans := ans+(pos2 * A[pos1+1]) ; pos1 := pos1+(1) ) else ( ans := ans+(pos1 * B[pos2+1]) ; pos2 := pos2+(1) ) ) ; loop := loop + 1 ) ; OclFile["System.out"].println(-ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int oddFib(int n){ n=(3*n+1)/2 ; int a=-1,b=1,c=0,i ; for(i=1 ; i<=n ; i++){ c=a+b ; a=b ; b=c ; } return c ; } public static void main(String[] args){ int n=4 ; System.out.println(oddFib(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation oddFib( n : int) : int pre: true post: true activity: ( n := (3 * n + 1) / 2 ; var a : int ; a := -1 ; var b : int ; b := 1 ; var c : int ; c := 0 ; var i : int ; i := 1 ; while i <= n do ( ( c := a + b ; a := b ; b := c ) ; i := i + 1 ) ; return c ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(oddFib(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); while(N-->0){ String s[]=in.next().split(":"); double S=Double.valueOf(s[0]); double L=Double.valueOf(s[1]); S=360*(60*S+L)/720.0 ; L=360.0*L/60.0 ; double dif=Math.min(Math.abs(S-L),360-Math.abs(S-L)); System.out.println(0<=dif && dif<30 ? "alert" : 90<=dif && dif<=180 ? "safe" : "warning"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; while (N > 0) do ( N := N - 1 ; skip ; ( var s : Sequence(String) ; s := in.getCurrent()->split(":") ; var S : double ; S := (s[0+1])->toReal() ; var L : double ; L := (s[1+1])->toReal() ; S := 360 * (60 * S + L) / 720.0 ; L := 360.0 * L / 60.0 ; var dif : double ; dif := Set{if (S)->char2byte() - L < 0 then -((S)->char2byte() - L) else (S)->char2byte() - L endif, 360 - if (S)->char2byte() - L < 0 then -((S)->char2byte() - L) else (S)->char2byte() - L endif}->min() ; OclFile["System.out"].println(if 0 <= dif & dif < 30 then "alert" else if 90 <= dif & dif <= 180 then "safe" else "warning" endif endif) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int nCr(int n,int r){ int fac[]=new int[100]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( fac[i+1] := 1 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n + 1 do ( ( fac[i+1] := fac[i - 1+1] * i ) ; i := i + 1 ) ; var ans : int ; ans := fac[n+1] / (fac[n - r+1] * fac[r+1]) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; var k : int ; k := 3 ; var ans : int ; ans := nCr(n + k - 1, k) + nCr(k - 1, n - 1) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public void solve()throws IOException { int n=nextInt(); for(int i=0 ; isplit(":") ; var hand : Sequence(int) ; hand := Integer.subrange(1,2)->collect(0) ; hand[0+1] := (s[0+1])->toInteger() ; hand[1+1] := (s[1+1])->toInteger() ; var key : double ; key := if hand[1+1] * 6 - (hand[0+1] * 30 + hand[1+1]->oclAsType(double) / 2) < 0 then -(hand[1+1] * 6 - (hand[0+1] * 30 + hand[1+1]->oclAsType(double) / 2)) else hand[1+1] * 6 - (hand[0+1] * 30 + hand[1+1]->oclAsType(double) / 2) endif ; key := Set{key, 360 - key}->min() ; if (key < 30) then ( writer.println("alert") ) else if (key < 90) then ( writer.println("warning") ) else ( writer.println("safe") ) ; ; writer.flush() ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute reader : OclFile; attribute tokenizer : OclIterator; attribute writer : OclFile; operation run() : void pre: true post: true activity: ( try ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; tokenizer := null ; writer := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ; skip ; ) catch (e : ProgramException) do ( e.printStackTrace() ; OclProcess.exit(1) ) ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nextToken() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ; return tokenizer.next() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { private static BufferedReader br=null ; static { br=new BufferedReader(new InputStreamReader(System.in)); } public static void main(String[] args){ int cnt=parseCnt(); while(cnt-->0){ double diff=parseDiffAngle(); if(diff<30.0 || 330.0tmp2)? tmp1-tmp2 : tmp2-tmp1 ; } return diff*180.0 ; } private static int parseCnt(){ int cnt=0 ; String str=null ; if((str=parseStdin())!=null){ cnt=Integer.parseInt(str); } return cnt ; } private static String parseStdin(){ String stdin=null ; try { String tmp=br.readLine(); if(tmp!=null){ if(! tmp.isEmpty())stdin=tmp ; } } catch(IOException e){ } return stdin ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute br : OclFile := null; static operation initialiseClass() pre: true post: true activity: br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cnt : int ; cnt := parseCnt() ; while (cnt > 0) do ( cnt := cnt - 1 ; skip ; ( var diff : double ; diff := parseDiffAngle() ; if (diff < 30.0 or 330.0 < diff) then ( OclFile["System.out"].println("alert") ) else if (90.0 <= diff & diff <= 270.0) then ( OclFile["System.out"].println("safe") ) else ( OclFile["System.out"].println("warning") ) ; ) ; ) ); static operation parseDiffAngle() : double pre: true post: true activity: ( var diff : double ; diff := 0 ; var tmp1 : double ; tmp1 := 0 ; var tmp2 : double ; tmp2 := 0 ; var time : String ; time := null ; if ((time) /= null) then ( var lines : Sequence(String) ; lines := time->split(":") ; tmp1 := (lines[1+1])->toReal() / 30.0 ; tmp2 := ((lines[0+1])->toReal() * 60.0 + (lines[1+1])->toReal()) / 360.0 ; diff := if (tmp1 > tmp2) then tmp1 - tmp2 else tmp2 - tmp1 endif ) else skip ; return diff * 180.0 ); static operation parseCnt() : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var str : String ; str := null ; if ((str) /= null) then ( cnt := (str)->toInteger() ) else skip ; return cnt ); static operation parseStdin() : String pre: true post: true activity: ( var stdin : String ; stdin := null ; try ( var tmp : String ; tmp := br.readLine() ; if (tmp /= null) then ( if (not(tmp->isEmpty())) then stdin := tmp ; else skip ) else skip ) catch (e : IOException) do skip return stdin ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; public class Main { Scanner sc=new Scanner(System.in); class time { int h ; int m ; int deg ; time(String hm){ String ti[]=hm.split(":"); h=Integer.parseInt(ti[0]); m=Integer.parseInt(ti[1]); deg=Math.abs((h*60+m-m*12)); deg=Math.min(deg,12*60-deg); } @ Override public String toString(){ if(deg<((30)*(12*60)/360)){ return "alert" ; } if(deg>=((90)*(12*60)/360)){ return "safe" ; } return "warning" ; } } void run(){ int n=sc.nextInt(); for(int i=0 ; isplit(":") ; h := (ti[0+1])->toInteger() ; m := (ti[1+1])->toInteger() ; deg := if (h * 60 + m - m * 12) < 0 then -((h * 60 + m - m * 12)) else (h * 60 + m - m * 12) endif ; deg := Set{deg, 12 * 60 - deg}->min() ; ); operation toString() : String pre: true post: true activity: ( if (deg < ((30) * (12 * 60) / 360)) then ( return "alert" ) else skip ; if (deg >= ((90) * (12 * 60) / 360)) then ( return "safe" ) else skip ; return "warning" ); } operation run() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(time.newtime(sc.getCurrent())) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var input : Sequence(String) ; input := br.readLine()->split(":") ; var hour : int ; hour := (input[0+1])->toInteger() ; var min : int ; min := (input[1+1])->toInteger() ; var lhand : double ; lhand := (hour * 60 + min) / 2.0 ; var shand : double ; shand := (min * 6.0) ; var deg : double ; deg := if lhand - shand < 0 then -(lhand - shand) else lhand - shand endif ; if ((0 <= deg & deg < 30) or (330 < deg & deg <= 360)) then ( OclFile["System.out"].println("alert") ) else if ((90 <= deg & deg <= 180) or (180 <= deg & deg <= 270)) then ( OclFile["System.out"].println("safe") ) else ( OclFile["System.out"].println("warning") ) ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isTriangular(int num){ if(num<0)return false ; int sum=0 ; for(int n=1 ; sum<=num ; n++){ sum=sum+n ; if(sum==num)return true ; } return false ; } public static void main(String[] args){ int n=55 ; if(isTriangular(n))System.out.print("The number "+"is a triangular number"); else System.out.print("The number"+" is NOT a triangular number"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isTriangular( num : int) : boolean pre: true post: true activity: ( if (num < 0) then return false else skip ; var sum : int ; sum := 0 ; var n : int ; n := 1 ; while sum <= num do ( ( sum := sum + n ; if (sum = num) then return true else skip ) ; n := n + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 55 ; if (isTriangular(n)) then OclFile["System.out"].print("The number " + "is a triangular number") ; else OclFile["System.out"].print("The number" + " is NOT a triangular number") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int sumOfTheSeries(int n){ int sum_n=(n*(n+1)/2); int sum_sq_n=(n*(n+1)/2)*(2*n+1)/3 ; return(sum_n+sum_sq_n); } public static void main(String[] args){ int n=5 ; System.out.printf("Sum=%d",sumOfTheSeries(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfTheSeries( n : int) : int pre: true post: true activity: ( var sum_n : int ; sum_n := (n * (n + 1) / 2) ; var sum_sq_n : int ; sum_sq_n := (n * (n + 1) / 2) * (2 * n + 1) / 3 ; return (sum_n + sum_sq_n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].printf("Sum=%d", sumOfTheSeries(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void findDistinctOddSum(int n,int k){ if((k*k)<=n &&(n+k)% 2==0){ int val=1 ; int sum=0 ; for(int i=1 ; i0){ int a=in.nextInt(); if(a>2){ for(int i=2 ; i=1 ; i--){ System.out.print(i); System.out.print(" "); } System.out.println(""); } } } } ------------------------------------------------------------ OCL File: --------- class NewClass48 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var a : int ; a := in.getCurrent()->toInteger() ; if (a > 2) then ( var i : int ; i := 2 ; while i < a + 1 do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(1) ) else ( var i : int ; i := a ; while i >= 1 do ( ( OclFile["System.out"].print(i) ; OclFile["System.out"].print(" ") ) ; i := i - 1 ) ; OclFile["System.out"].println("") ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class BearAndForgottenTree3 { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int d=input.nextInt(); int h=input.nextInt(); if(d>2*h ||(d==1 && n!=2)){ System.out.println(-1); return ; } for(int i=1 ; i<=h ; ++i){ System.out.print(i+" "+(i+1)+"\n"); } int x=1 ; for(int i=1 ; i<=(d-h); ++i){ int y=h+1+i ; System.out.print(x+" "+y+"\n"); x=y ; } int v=(d==h)? 2 : 1 ; for(int i=d+2 ; i<=n ; ++i){ System.out.print(i+" "+v+"\n"); } return ; } } ------------------------------------------------------------ OCL File: --------- class BearAndForgottenTree3 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var d : int ; d := input.getCurrent()->toInteger() ; var h : int ; h := input.getCurrent()->toInteger() ; if (d > 2 * h or (d = 1 & n /= 2)) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var i : int ; i := 1 ; while i <= h do ( ( OclFile["System.out"].print(i + " " + (i + 1) + "\n") ) ; i := i + 1 ) ; var x : int ; x := 1 ; var i : int ; i := 1 ; while i <= (d - h) do ( ( var y : int ; y := h + 1 + i ; OclFile["System.out"].print(x + " " + y + "\n") ; x := y ) ; i := i + 1 ) ; var v : int ; v := if (d = h) then 2 else 1 endif ; var i : int ; i := d + 2 ; while i <= n do ( ( OclFile["System.out"].print(i + " " + v + "\n") ) ; i := i + 1 ) ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Ex3 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int oo=0 ; ooarr=new ArrayList<>(); for(int i=0 ; i{ private E value ; private ListNode next ; public ListNode(E newVal,ListNodenewNext){ value=newVal ; next=newNext ; } public E getValue(){ return value ; } public ListNodegetNext(){ return next ; } public void setValue(E newValue){ value=newValue ; } public void setNext(ListNodenewNext){ next=newNext ; } } } ------------------------------------------------------------ OCL File: --------- class Ex3 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var oo : int ; oo := 0 ; while oo < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; if (n = 2) then ( OclFile["System.out"].println("2 1") ) else ( var arr : Sequence(int) ; arr := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( arr := arr->including(i + 1) ) ; i := i + 1 ) ; arr := arr.sort(reverseOrder()) ; var ar : Sequence(int) ; ar := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ar[i+1] := arr->at(i+1) ) ; i := i + 1 ) ; var temp : int ; temp := ar[n / 2+1] ; ar[n / 2+1] := ar[n / 2 + 1+1] ; ar[n / 2 + 1+1] := temp ; var i : int ; i := 0 ; while i < ar->size() do ( ( OclFile["System.out"].print(ar[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ) ; oo := oo + 1 ) ); class ListNode { attribute value : E; attribute next : ListNode; static operation newListNode( newVal : E, newNext : ListNode) : ListNode pre: true post: true activity: ( var self : ListNode ; self := createListNode(); self.initialise(newVal, newNext); return self ); operation initialise( newVal : E, newNext : ListNode) : void pre: true post: true activity: ( value := newVal ; next := newNext ); operation getValue() : E pre: true post: true activity: ( return value ); operation getNext() : ListNode pre: true post: true activity: ( return next ); operation setValue( newValue : E) : void pre: true post: true activity: ( value := newValue ); operation setNext( newNext : ListNode) : void pre: true post: true activity: ( next := newNext ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var min : int ; min := 2147483647 ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( var sa : int ; sa := if a[n - 1+1] - a[i+1] * 2 < 0 then -(a[n - 1+1] - a[i+1] * 2) else a[n - 1+1] - a[i+1] * 2 endif ; if (sa < min) then ( min := sa ; ans := a[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(a[n - 1+1] + " ") ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int test=in.nextInt(); for(int t=1 ; t<=test ; t++){ int n=in.nextInt(); if(n % 2==0){ for(int i=2 ; i<=n ; i+=2){ pw.print(i+" "+(i-1)+" "); } pw.println(); } else { pw.print(n+" "); for(int i=1 ; i<=n-1 ; i++){ pw.print(i+" "); } pw.println(); } } pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var test : int ; test := in.getCurrent()->toInteger() ; var t : int ; t := 1 ; while t <= test do ( ( var n : int ; n := in.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( var i : int ; i := 2 ; while i <= n do ( ( skip ) ; i := i+(2) ) ; skip ) else ( skip ; var i : int ; i := 1 ; while i <= n - 1 do ( ( skip ) ; i := i + 1 ) ; skip ) ) ; t := t + 1 ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF1454A { public static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int test=scanner.nextInt(); while(test-->0){ int n=scanner.nextInt(); for(int i=2 ; i<=n ; i++){ System.out.print(i+" "); } System.out.println(1); } } } ------------------------------------------------------------ OCL File: --------- class CF1454A { static attribute scanner : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := scanner.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var i : int ; i := 2 ; while i <= n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(1) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1454 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); if((n & 1)==0){ for(int i=n ; i>1 ; i--){ System.out.print(i+" "); } System.out.println(1); } else { for(int i=n ; i>(n+1)/2 ; i--){ System.out.print(i+" "); } System.out.print(1+" "); for(int i=(n+1)/2 ; i>2 ; i--){ System.out.print(i+" "); } if(n>2){ System.out.println(2); } } } } } ------------------------------------------------------------ OCL File: --------- class A1454 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; if ((MathLib.bitwiseAnd(n,1)) = 0) then ( var i : int ; i := n ; while i > 1 do ( ( OclFile["System.out"].print(i + " ") ) ; i := i - 1 ) ; OclFile["System.out"].println(1) ) else ( var i : int ; i := n ; while i > (n + 1) / 2 do ( ( OclFile["System.out"].print(i + " ") ) ; i := i - 1 ) ; OclFile["System.out"].print(1 + " ") ; var i : int ; i := (n + 1) / 2 ; while i > 2 do ( ( OclFile["System.out"].print(i + " ") ) ; i := i - 1 ) ; if (n > 2) then ( OclFile["System.out"].println(2) ) else skip ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int check(String s,int K){ for(int ch=0 ; ch<26 ; ch++){ char c=(char)('a'+ch); int last=-1 ; boolean found=true ; for(int i=0 ; i>1 ; if(check(s,mid)==1){ ans=mid ; high=mid-1 ; } else low=mid+1 ; } return ans ; } public static void main(String args[]){ String s="abcde" ; System.out.println(binarySearch(s)); s="aaaa" ; System.out.println(binarySearch(s)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation check( s : String, K : int) : int pre: true post: true activity: ( var ch : int ; ch := 0 ; while ch < 26 do ( ( var c : String ; c := ('a' + ch)->oclAsType(String) ; var last : int ; last := -1 ; var found : boolean ; found := true ; var i : int ; i := 0 ; while i < K do ( if (s->at(i+1) = c) then last := i ; else skip ; ; i := i + 1 ) ; if (last = -1) then continue else skip ; var i : int ; i := K ; while i < s->size() do ( ( if (s->at(i+1) = c) then last := i ; else skip ; if (last <= (i - K)) then ( found := false ; break ) else skip ) ; i := i + 1 ) ; if (found) then return 1 else skip ; ) ; ch := ch + 1 ) ; return 0 ); static operation binarySearch( s : String) : int pre: true post: true activity: ( var low : int ; low := 1 ; var high : int ; high := s->size() ; var ans : int ; ans := 0 ; while (low <= high) do ( var mid : int ; mid := ((high + low)/(2->pow(1)))->oclAsType(long) ; if (check(s, mid) = 1) then ( ans := mid ; high := mid - 1 ) else low := mid + 1 ; ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "abcde" ; OclFile["System.out"].println(binarySearch(s)) ; s := "aaaa" ; OclFile["System.out"].println(binarySearch(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import static java.lang.Math.max ; public class Main { static class Solution { } static public boolean isValid(int total,int remain){ return remain*2-total<=1 ; } static public long solve(int cur,int remain,long[][] dp,long[] arr){ if(! isValid(cur,remain)){ return Long.MIN_VALUE ; } if(remain<=0){ return 0L ; } int state=cur/remain ; if(dp[cur][state]!=Long.MIN_VALUE)return dp[cur][state]; long ans=Long.MIN_VALUE ; if(isValid(cur-1,remain)){ ans=max(ans,solve(cur-1,remain,dp,arr)); } ans=max(ans,solve(cur-2,remain-1,dp,arr)+arr[cur]); dp[cur][state]=ans ; return ans ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] arr=new long[n+1]; long[][] dp=new long[n+1][5]; for(int i=1 ; i<=n ; ++i){ arr[i]=sc.nextLong(); } for(int i=1 ; i<=n ; ++i){ for(int j=0 ; j<5 ; ++j){ dp[i][j]=Long.MIN_VALUE ; } } long ans=solve(n,n/2,dp,arr); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static class Solution { } static operation isValid( total : int, remain : int) : boolean pre: true post: true activity: ( return remain * 2 - total <= 1 ); static operation solve( cur : int, remain : int, dp : Sequence(Sequence(long)), arr : Sequence(long)) : long pre: true post: true activity: ( if (not(isValid(cur, remain))) then ( return "-9223372036854775808"->toLong() ) else skip ; if (remain <= 0) then ( return 0L ) else skip ; var state : int ; state := cur / remain ; if (dp[cur+1][state+1] /= "-9223372036854775808"->toLong()) then return dp[cur+1][state+1] else skip ; var ans : long ; ans := "-9223372036854775808"->toLong() ; if (isValid(cur - 1, remain)) then ( ans := Set{ans, solve(cur - 1, remain, dp, arr)}->max() ) else skip ; ans := Set{ans, solve(cur - 2, remain - 1, dp, arr) + arr[cur+1]}->max() ; dp[cur+1][state+1] := ans ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,5)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 0 ; while j < 5 do ( ( dp[i+1][j+1] := "-9223372036854775808"->toLong() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : long ; ans := solve(n, n / 2, dp, arr) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static long find_max(int i,int N,int[] A,long[] dp){ return i==N-1 ? 0 : Long.max(dp[i+1],A[i]+find_max(i+2,N,A,dp)); } public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int[] A=new int[N]; long[] dp=new long[N+1]; for(int i=0 ; i=0){ dp[i]=dp[i+2]+A[i]; i-=2 ; } i=N-2 ; while(i>=0){ dp[i]=Long.max(dp[i+1],A[i]+dp[i+2]); i-=2 ; } System.out.println(N % 2==0 ? dp[0] : find_max(0,N,A,dp)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation find_max( i : int, N : int, A : Sequence(int), dp : Sequence(long)) : long pre: true post: true activity: ( return if i = N - 1 then 0 else Set{dp[i + 1+1], A[i+1] + find_max(i + 2, N, A, dp)}->max() endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var dp : Sequence(long) ; dp := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; dp[N - 1+1] := A[N - 1+1] ; var i : int ; i := N - 3 ; while (i >= 0) do ( dp[i+1] := dp[i + 2+1] + A[i+1] ; i := i-(2) ) ; i := N - 2 ; while (i >= 0) do ( dp[i+1] := Set{dp[i + 1+1], A[i+1] + dp[i + 2+1]}->max() ; i := i-(2) ) ; OclFile["System.out"].println(if N mod 2 = 0 then dp[0+1] else find_max(0, N, A, dp) endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Mapmp=new HashMap<>(); public static void main(String args[]){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long[] A=new long[N]; for(int i=0 ; itoInteger() ; var A : Sequence(long) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; OclFile["System.out"].println(helper(A, 0, N / 2)) ; ); static operation helper( A : Sequence(long), ofs : int, cnt : int) : long pre: true post: true activity: ( var key : long ; key := ofs * 3_000_00 + cnt ; if (mp->keys()->includes(key)) then ( return mp->at(key) ) else skip ; if (cnt = 0) then ( return 0 ) else skip ; var size : int ; size := (A->size() - ofs) ; if (size = 1 & cnt = 1) then ( return A[ofs+1] ) else skip ; if (size = 2 & cnt = 1) then ( return Set{A[ofs+1], A[ofs + 1+1]}->max() ) else skip ; if (size mod 2 = 1 & size / 2 + 1 = cnt) then ( var ans : long ; ans := A[ofs+1] + helper(A, ofs + 2, cnt - 1) ; mp := mp->union(Map{key |-> ans}) ; return ans ) else skip ; var use : long ; use := A[ofs+1] + helper(A, ofs + 2, cnt - 1) ; var nouse : long ; nouse := helper(A, ofs + 1, cnt) ; var ans : long ; ans := Set{use, nouse}->max() ; mp := mp->union(Map{key |-> ans}) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int D=sc.nextInt(); int X=sc.nextInt(); int[] A=new int[N]; int sum=0 ; for(int i=0 ; itoInteger() ; var D : int ; D := sc.getCurrent()->toInteger() ; var X : int ; X := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < D do ( ( if (j * A[i+1] + 1 <= D) then ( sum := sum+(1) ) else ( break ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum + X) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { static int a1[]={ 0,-1,0,1 }; static int b1[]={ -1,0,1,0 }; private static Scanner sc=new Scanner(System.in); static int K,N ; static int mod=1000000007 ; public static void main(String[] args){ int N=sc.nextInt(); int D=sc.nextInt(); int X=sc.nextInt(); int ans=X ; for(int i=0 ; itoInteger() ; var D : int ; D := sc.getCurrent()->toInteger() ; var X : int ; X := sc.getCurrent()->toInteger() ; var ans : int ; ans := X ; var i : int ; i := 0 ; while i < N do ( ( var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := 1 ; while (B <= D) do ( ans := ans + 1 ; B := B+(A) ) ) ; i := i + 1 ) ; execute p(ans) ; ); static operation p( ans : String) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); static operation p( ans : int) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); static operation p() : void pre: true post: true activity: ( OclFile["System.out"].println() ); static operation p( ans : long) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); static operation p( ans : double) : void pre: true post: true activity: ( OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class codeforce5 { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int d=scan.nextInt(); int h=scan.nextInt(); if(d>2*h ||(d==1 && n!=2)){ System.out.println(-1); return ; } for(int i=1 ; i<=h ; ++i){ System.out.print(i+" "+(i+1)+"\n"); } int x=1 ; for(int i=1 ; i<=(d-h); ++i){ int y=h+1+i ; System.out.print(x+" "+y+"\n"); x=y ; } int v=(d==h)? 2 : 1 ; for(int i=d+2 ; i<=n ; ++i){ System.out.print(i+" "+v+"\n"); } return ; } } ------------------------------------------------------------ OCL File: --------- class codeforce5 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var d : int ; d := scan.getCurrent()->toInteger() ; var h : int ; h := scan.getCurrent()->toInteger() ; if (d > 2 * h or (d = 1 & n /= 2)) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var i : int ; i := 1 ; while i <= h do ( ( OclFile["System.out"].print(i + " " + (i + 1) + "\n") ) ; i := i + 1 ) ; var x : int ; x := 1 ; var i : int ; i := 1 ; while i <= (d - h) do ( ( var y : int ; y := h + 1 + i ; OclFile["System.out"].print(x + " " + y + "\n") ; x := y ) ; i := i + 1 ) ; var v : int ; v := if (d = h) then 2 else 1 endif ; var i : int ; i := d + 2 ; while i <= n do ( ( OclFile["System.out"].print(i + " " + v + "\n") ) ; i := i + 1 ) ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { int n ; Lista=new ArrayList<>(); int max,result ; private Main(Scanner in){ n=Integer.parseInt(in.nextLine()); String[] tokens=in.nextLine().split(" "); for(int i=0 ; i(){ @ Override public int compare(Integer o1,Integer o2){ if(o1o2){ return 1 ; } else { return 0 ; } } } ).get().intValue(); double half=(double)max/2.0 ; result=-1 ; double diff=Double.MAX_VALUE ; for(Integer val : a){ if(val!=max && diff>Math.abs((double)val-half)){ diff=Math.abs((double)val-half); result=val ; } } } private void show(){ System.out.println(max+" "+result); } public static void main(String[] args){ Scanner in=new Scanner(System.in); Main ins=new Main(in); in.close(); ins.calc(); ins.show(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute n : int; attribute a : Sequence(int) := Sequence{}; attribute max : int; static operation newMain( in : OclFile) : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( n := (in.nextLine())->toInteger() ; var tokens : Sequence(String) ; tokens := in.nextLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( ( a := a->including((tokens[i+1])->toInteger()) ) ; i := i + 1 ) ); operation calc() : void pre: true post: true activity: ( max := a->max().get()->oclAsType(int) ; var half : double ; half := max->oclAsType(double) / 2.0 ; result := -1 ; var diff : double ; diff := (2 - 2->pow(-52))*(2->pow(1023)) ; for (val : a) do ( ( if (val /= max & diff > if val->oclAsType(double) - half < 0 then -(val->oclAsType(double) - half) else val->oclAsType(double) - half endif) then ( diff := if val->oclAsType(double) - half < 0 then -(val->oclAsType(double) - half) else val->oclAsType(double) - half endif ; result := val ) else skip ) ) ; ); operation show() : void pre: true post: true activity: ( OclFile["System.out"].println(max + " " + result) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var ins : Main ; ins := Main.newMain(in) ; skip ; ins.calc() ; ins.show() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); final int N=Integer.parseInt(sc.next()); final int D=Integer.parseInt(sc.next()); final int X=Integer.parseInt(sc.next()); int[] a=new int[N]; int chocolate=0 ; for(int i=0 ; itoInteger() ; var D : int ; D := (sc.getCurrent())->toInteger() ; var X : int ; X := (sc.getCurrent())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var chocolate : int ; chocolate := 0 ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var times : int ; times := 0 ; var days : int ; days := 1 ; while (days <= D) do ( chocolate := chocolate + 1 ; times := times + 1 ; days := times * a[i+1] + 1 ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Iterator ; import java.util.List ; import java.util.Map.Entry ; import java.util.PriorityQueue ; import java.util.Scanner ; class Main { static final int MOD=1000000007 ; static final int INF=1<<30 ; Main(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int D=sc.nextInt(); int X=sc.nextInt(); int ans=0 ; for(int i=0 ; ipow(30)))->oclAsType(long); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var D : int ; D := sc.getCurrent()->toInteger() ; var X : int ; X := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < N do ( ( var num : int ; num := sc.getCurrent()->toInteger() ; var k : int ; k := 0 ; while k < 100 do ( if (k * num + 1 <= D) then ans := ans + 1 else break ; ; k := k + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans + X) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); int D=Integer.parseInt(sc.next()); int X=Integer.parseInt(sc.next()); int ans=X+N ; for(int i=0 ; itoInteger() ; var D : int ; D := (sc.getCurrent())->toInteger() ; var X : int ; X := (sc.getCurrent())->toInteger() ; var ans : int ; ans := X + N ; var i : int ; i := 0 ; while i < N do ( ( var n : int ; n := (sc.getCurrent())->toInteger() ; var j : int ; j := n + 1 ; while j <= D do ( ( ans := ans + 1 ) ; j := j+(n) ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; public class GFG { static int maxPrimefactorNum(int N){ int arr[]=new int[N+5]; Arrays.fill(arr,0); for(int i=2 ; i*i<=N ; i++){ if(arr[i]==0){ for(int j=2*i ; j<=N ; j+=i){ arr[j]++; } } arr[i]=1 ; } int maxval=0,maxint=1 ; for(int i=1 ; i<=N ; i++){ if(arr[i]>maxval){ maxval=arr[i]; maxint=i ; } } return maxint ; } public static void main(String[] args){ int N=40 ; System.out.println(maxPrimefactorNum(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxPrimefactorNum( N : int) : int pre: true post: true activity: ( var arr : Sequence(int) ; arr := Integer.subrange(1,N + 5)->collect(0) ; arr := arr->collect(0) ; var i : int ; i := 2 ; while i * i <= N do ( ( if (arr[i+1] = 0) then ( var j : int ; j := 2 * i ; while j <= N do ( ( arr[j+1] := arr[j+1] + 1 ) ; j := j+(i) ) ) else skip ; arr[i+1] := 1 ) ; i := i + 1 ) ; var maxval : int ; maxval := 0 ; var maxint : int ; maxint := 1 ; var i : int ; i := 1 ; while i <= N do ( ( if (arr[i+1] > maxval) then ( maxval := arr[i+1] ; maxint := i ) else skip ) ; i := i + 1 ) ; return maxint ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 40 ; OclFile["System.out"].println(maxPrimefactorNum(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static ListgetPerfectcubes(int n){ Listperfectcubes=new ArrayList(); int current=1 ; int i=1 ; while(current<=n){ perfectcubes.add(current); i+=1 ; current=(int)(Math.pow(i,3)); } return perfectcubes ; } static int maxPairSum(int[] arr){ int n=arr.length ; int max=0 ; int secondMax=0 ; if(arr[0]>arr[1]){ max=arr[0]; secondMax=arr[1]; } else { max=arr[1]; secondMax=arr[0]; } for(int i=2 ; imax){ secondMax=max ; max=arr[i]; } else if(arr[i]>secondMax){ secondMax=arr[i]; } } return(max+secondMax); } static int countPairsWith(int n,Listperfectcubes,Listnums){ int count=0 ; for(int i=0 ; in &&(nums.contains(temp)))count+=1 ; } return count ; } static int countPairs(int[] arr){ int n=arr.length ; int max=maxPairSum(arr); Listperfectcubes=getPerfectcubes(max); Listnums=new ArrayList(); for(int i=0 ; iincluding(current) ; i := i+(1) ; current := (i->pow(3))->oclAsType(int) ) ; return perfectcubes ); static operation maxPairSum( arr : Sequence(int)) : int pre: true post: true activity: ( var n : int ; n := arr->size() ; var max : int ; max := 0 ; var secondMax : int ; secondMax := 0 ; if (arr[0+1] > arr[1+1]) then ( max := arr[0+1] ; secondMax := arr[1+1] ) else ( max := arr[1+1] ; secondMax := arr[0+1] ) ; var i : int ; i := 2 ; while i < n do ( ( if (arr[i+1] > max) then ( secondMax := max ; max := arr[i+1] ) else if (arr[i+1] > secondMax) then ( secondMax := arr[i+1] ) else skip ; ) ; i := i + 1 ) ; return (max + secondMax) ); static operation countPairsWith( n : int, perfectcubes : Sequence(int), nums : Sequence(int)) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < perfectcubes->size() do ( ( var temp : int ; temp := perfectcubes->at(i+1) - n ; if (temp > n & (nums->includes(temp))) then count := count+(1) ; else skip ) ; i := i + 1 ) ; return count ); static operation countPairs( arr : Sequence(int)) : int pre: true post: true activity: ( var n : int ; n := arr->size() ; var max : int ; max := maxPairSum(arr) ; var perfectcubes : Sequence(int) ; perfectcubes := getPerfectcubes(max) ; var nums : Sequence(int) ; nums := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( nums := nums->including(arr[i+1]) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( count := count+(countPairsWith(arr[i+1], perfectcubes, nums)) ) ; i := i + 1 ) ; return count ); static operation main( agrs : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,6,18,9,999,1} ; OclFile["System.out"].print(countPairs(arr)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class codeforces500B { static ArrayList[] adj ; static int[] arr ; static PriorityQueuevals ; static PriorityQueuenodes ; static boolean[] visited ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); arr=new int[n]; adj=new ArrayList[n]; StringTokenizer st=new StringTokenizer(br.readLine()); for(int i=0 ; i(); } for(int a=0 ; a(); nodes=new PriorityQueue<>(); for(int i=0 ; itoInteger() ; arr := Integer.subrange(1,n)->collect(0) ; adj := Integer.subrange(1,n)->collect(null) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (st.next())->toInteger() - 1 ; adj[i+1] := Sequence{} ) ; i := i + 1 ) ; var a : int ; a := 0 ; while a < n do ( ( var str : String ; str := br.readLine() ; var b : int ; b := 0 ; while b < n do ( ( if (str->at(b+1) = '1') then ( adj[a+1]->excludes(b) ) else skip ) ; b := b + 1 ) ) ; a := a + 1 ) ; visited := Integer.subrange(1,n)->collect(false) ; visited := visited->collect(false) ; var answer : Sequence(int) ; answer := Integer.subrange(1,n)->collect(0) ; vals := Sequence{} ; nodes := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( if (not(visited[i+1])) then ( execute dfs(i) ; while (not(vals->isEmpty())) do ( var a : int ; a := vals->min() ; var b : int ; b := nodes->min() ; answer[b+1] := a + 1 ) ) else skip ) ; i := i + 1 ) ; var ans : String ; ans := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( ans := ans + StringLib.newString(answer[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation dfs( node : int) : void pre: true post: true activity: ( visited[node+1] := true ; nodes := nodes->including(node) ; vals := vals->including(arr[node+1]) ; for (next : adj[node+1]) do ( ( if (not(visited[next+1])) then ( execute dfs(next) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class GFG { static double heptdiagonal(double a){ if(a<0)return-1 ; double d=1.802*a ; return d ; } public static void main(String[] args){ int a=6 ; System.out.println(heptdiagonal(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation heptdiagonal( a : double) : double pre: true post: true activity: ( if (a < 0) then return -1 else skip ; var d : double ; d := 1.802 * a ; return d ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 6 ; OclFile["System.out"].println(heptdiagonal(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class GFG { static double decdiagonal(double a){ if(a<0)return-1 ; double d=1.902*a ; return d ; } public static void main(String[] args){ int a=9 ; System.out.println(decdiagonal(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation decdiagonal( a : double) : double pre: true post: true activity: ( if (a < 0) then return -1 else skip ; var d : double ; d := 1.902 * a ; return d ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 9 ; OclFile["System.out"].println(decdiagonal(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.*; import java.util.*; public class Main { static Scanner s=new Scanner(System.in); static int g(){ return Integer.parseInt(s.next()); } public static void main(String[] $){ Point st=new Point(g(),g()),go=new Point(g(),g()); if(st.y>go.y){ Point buf=go ; go=st ; st=buf ; } Comparatorc=Comparator.comparingDouble(Point :: getX); TreeSetp=new TreeSet<>(st.x0 ; --i){ int x=g(),y=g(); if(st.y<=y && y<=go.y)p.add(new Point(x,y)); } int v=lis(p.subSet(st,true,go,true)); System.out.println((Math.abs(st.x-go.x)+Math.abs(st.y-go.y))*100L+v*-20+(v==Math.min(go.y-st.y,Math.abs(go.x-st.x))+1 ? v+1 : v)*5*Math.PI); } static int lis(NavigableSetp){ ArrayListl=new ArrayList<>(); l.add(Integer.MIN_VALUE); while(! p.isEmpty()){ int y=p.pollFirst().y ; if(l.get(l.size()-1)toInteger() ); static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var st : Point ; st := Point.newPoint(g(), g()) ; var go : Point ; go := Point.newPoint(g(), g()) ; if (st.y > go.y) then ( var buf : Point ; buf := go ; go := st ; st := buf ) else skip ; var c : Function(,(,boolean)) ; c := Comparator.comparingDouble(lambda _pars : OclAny in Point.newPoint().getX(_pars)) ; var p : Set(Point) ; p := Set{}->union(if st.x < go.x then c else c.reversed() endif) ; var i : int ; i := g() ; while i > 0 do ( ( var x : int ; x := g() ; var y : int ; y := g() ; if (st.y <= y & y <= go.y) then p := p->including(Point.newPoint(x, y)) ; else skip ) ; i := i - 1 ) ; var v : int ; v := lis(p->select( _x0 | _x0 >= st & _x0 < true )) ; OclFile["System.out"].println((if st.x - go.x < 0 then -(st.x - go.x) else st.x - go.x endif + if st.y - go.y < 0 then -(st.y - go.y) else st.y - go.y endif) * 100L + v * -20 + (if v = Set{go.y - st.y, if go.x - st.x < 0 then -(go.x - st.x) else go.x - st.x endif}->min() + 1 then v + 1 else v endif) * 5 * 3.141592653589793) ; ); static operation lis( p : NavigableSet) : int pre: true post: true activity: ( var l : Sequence(int) ; l := Sequence{} ; l := l->including(-2147483648) ; while (not(p->isEmpty())) do ( var y : int ; y := p->first().y ; if (l->at(l->size() - 1+1) < y) then l := l->including(y) ; else ( var v : int ; v := .binarySearch(l, y) ; if (v < 0) then l := l.setAt(-(v + 1)+1,y) ; else skip ) ) ; return l->size() - 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static void convert(int n,String a,String b){ int[] l=new int[n]; int i ; for(i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( l[i+1] := 0 ; ; i := i + 1 ) ; i := 0 ; while i < n do ( ( if (a->at(i+1) /= b->at(i+1)) then l[i+1] := 1 ; else skip ) ; i := i + 1 ) ; var cc : int ; cc := 0 ; var vl : int ; vl := 0 ; i := 0 ; while i < n do ( ( if (l[i+1] = 0) then ( if (vl /= 0) then cc := cc+(1) ; else skip ; vl := 0 ) else vl := vl+(1) ; ) ; i := i + 1 ) ; if (vl /= 0) then cc := cc+(1) ; else skip ; OclFile["System.out"].println(cc) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : String ; a := "101010" ; var b : String ; b := "110011" ; var n : int ; n := a->size() ; execute convert(n, a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] main){ Scanner sc=new Scanner(System.in); int numOfWord=Integer.parseInt(sc.nextLine()); SetwordSet=new HashSet<>(); boolean followTheRules=true ; String prevEndChar=null ; for(int i=0 ; itoInteger() ; var wordSet : Set(String) ; wordSet := Set{} ; var followTheRules : boolean ; followTheRules := true ; var prevEndChar : String ; prevEndChar := null ; var i : int ; i := 0 ; while i < numOfWord do ( ( var word : String ; word := sc.nextLine() ; if (wordSet->includes(word)) then ( followTheRules := false ; break ) else skip ; if (prevEndChar /= null & not(prevEndChar = ((word->at(0+1)) + ""))) then ( followTheRules := false ; break ) else skip ; prevEndChar := ((word->at(word->size() - 1+1)) + "") ; wordSet := wordSet->including(word) ; ) ; i := i + 1 ) ; var result : String ; result := if followTheRules then "Yes" else "No" endif ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; class Main { public static void main(String[] args){ final Scanner scanner=new Scanner(System.in); final int n=scanner.nextInt(); int[] a=new int[n]; for(int i=0 ; i1){ int mid=(left+right)/2 ; if(a[mid]<=k){ left=mid ; } else { right=mid ; } } return left ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; a := a->sort() ; var r : int ; r := upperBound(a, a[n - 1+1] / 2) ; if (r + 1 < n - 1 & if a[r + 1+1] * 2 - a[n - 1+1] < 0 then -(a[r + 1+1] * 2 - a[n - 1+1]) else a[r + 1+1] * 2 - a[n - 1+1] endif < if a[r+1] * 2 - a[n - 1+1] < 0 then -(a[r+1] * 2 - a[n - 1+1]) else a[r+1] * 2 - a[n - 1+1] endif) then r := a[r + 1+1] else r := a[r+1] ; ; OclFile["System.out"].printf("%d %d\n", a[n - 1+1], r) ; ); static operation upperBound( a : Sequence(int), k : int) : int pre: true post: true activity: ( var left : int ; left := -1 ; var right : int ; right := a->size() ; while (right - left > 1) do ( var mid : int ; mid := (left + right) / 2 ; if (a[mid+1] <= k) then ( left := mid ) else ( right := mid ) ) ; return left ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String SA=sc.next(); String SB=sc.next(); String SC=sc.next(); int ia=0 ; int ib=0 ; int ic=0 ; char next='a' ; String ans="" ; while(true){ if(next=='a'){ if(ia==SA.length()){ ans="A" ; break ; } next=SA.charAt(ia); ia++; } else if(next=='b'){ if(ib==SB.length()){ ans="B" ; break ; } next=SB.charAt(ib); ib++; } else { if(ic==SC.length()){ ans="C" ; break ; } next=SC.charAt(ic); ic++; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var SA : String ; SA := sc.getCurrent() ; var SB : String ; SB := sc.getCurrent() ; var SC : String ; SC := sc.getCurrent() ; var ia : int ; ia := 0 ; var ib : int ; ib := 0 ; var ic : int ; ic := 0 ; var next : String ; next := 'a' ; var ans : String ; ans := "" ; while (true) do ( if (next = 'a') then ( if (ia = SA->size()) then ( ans := "A" ; break ) else skip ; next := SA->at(ia+1) ; ia := ia + 1 ) else if (next = 'b') then ( if (ib = SB->size()) then ( ans := "B" ; break ) else skip ; next := SB->at(ib+1) ; ib := ib + 1 ) else ( if (ic = SC->size()) then ( ans := "C" ; break ) else skip ; next := SC->at(ic+1) ; ic := ic + 1 ) ; ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigDecimal ; import java.nio.charset.StandardCharsets ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } void run(){ Scanner sc=new Scanner(System.in); char[] A=sc.next().toCharArray(); char[] B=sc.next().toCharArray(); char[] C=sc.next().toCharArray(); ListaArray=new ArrayList<>(); ListbArray=new ArrayList<>(); ListcArray=new ArrayList<>(); for(char c : A){ String s=String.valueOf(c); aArray.add(s); } for(char c : B){ String s=String.valueOf(c); bArray.add(s); } for(char c : C){ String s=String.valueOf(c); cArray.add(s); } String next=aArray.get(0); aArray.remove(0); String ans="" ; while(true){ if(next.equals("a")){ if(aArray.size()==0){ ans="A" ; break ; } next=aArray.get(0); aArray.remove(0); } else if(next.equals("b")){ if(bArray.size()==0){ ans="B" ; break ; } next=bArray.get(0); bArray.remove(0); } else { if(cArray.size()==0){ ans="C" ; break ; } next=cArray.get(0); cArray.remove(0); } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : Sequence(String) ; A := sc.getCurrent()->characters() ; var B : Sequence(String) ; B := sc.getCurrent()->characters() ; var C : Sequence(String) ; C := sc.getCurrent()->characters() ; var aArray : Sequence(String) ; aArray := Sequence{} ; var bArray : Sequence(String) ; bArray := Sequence{} ; var cArray : Sequence(String) ; cArray := Sequence{} ; for (c : A) do ( ( var s : String ; s := ((c) + "") ; aArray := aArray->including(s) ) ) ; for (c : B) do ( ( var s : String ; s := ((c) + "") ; bArray := bArray->including(s) ) ) ; for (c : C) do ( ( var s : String ; s := ((c) + "") ; cArray := cArray->including(s) ) ) ; var next : String ; next := aArray->at(0+1) ; aArray := aArray->excludingAt(0+1) ; var ans : String ; ans := "" ; while (true) do ( if (next = "a") then ( if (aArray->size() = 0) then ( ans := "A" ; break ) else skip ; next := aArray->at(0+1) ; aArray := aArray->excludingAt(0+1) ) else if (next = "b") then ( if (bArray->size() = 0) then ( ans := "B" ; break ) else skip ; next := bArray->at(0+1) ; bArray := bArray->excludingAt(0+1) ) else ( if (cArray->size() = 0) then ( ans := "C" ; break ) else skip ; next := cArray->at(0+1) ; cArray := cArray->excludingAt(0+1) ) ; ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { int anum=1 ; int bnum=0 ; int cnum=0 ; void run(){ Scanner sc=new Scanner(System.in); String a=sc.next(); String b=sc.next(); String c=sc.next(); char turn=a.charAt(0); while(true){ if(turn=='a'){ if(anum==a.length()){ System.out.println("A"); break ; } turn=a.charAt(anum); anum++; } else if(turn=='b'){ if(bnum==b.length()){ System.out.println("B"); break ; } turn=b.charAt(bnum); bnum++; } else { if(cnum==c.length()){ System.out.println("C"); break ; } turn=c.charAt(cnum); cnum++; } } sc.close(); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute anum : int := 1; attribute bnum : int := 0; attribute cnum : int := 0; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : String ; a := sc.getCurrent() ; var b : String ; b := sc.getCurrent() ; var c : String ; c := sc.getCurrent() ; var turn : String ; turn := a->at(0+1) ; while (true) do ( if (turn = 'a') then ( if (anum = a->size()) then ( OclFile["System.out"].println("A") ; break ) else skip ; turn := a->at(anum+1) ; anum := anum + 1 ) else if (turn = 'b') then ( if (bnum = b->size()) then ( OclFile["System.out"].println("B") ; break ) else skip ; turn := b->at(bnum+1) ; bnum := bnum + 1 ) else ( if (cnum = c->size()) then ( OclFile["System.out"].println("C") ; break ) else skip ; turn := c->at(cnum+1) ; cnum := cnum + 1 ) ; ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String sa=scanner.next(); String sb=scanner.next(); String sc=scanner.next(); int currentPlayer=0 ; while(true){ char nextPlayer='a' ; switch(currentPlayer){ case 0 : { if(sa.isEmpty()){ System.out.print("A"); return ; } nextPlayer=sa.charAt(0); sa=sa.substring(1); break ; } case 1 : { if(sb.isEmpty()){ System.out.print("B"); return ; } nextPlayer=sb.charAt(0); sb=sb.substring(1); break ; } case 2 : { if(sc.isEmpty()){ System.out.print("C"); return ; } nextPlayer=sc.charAt(0); sc=sc.substring(1); break ; } } if(nextPlayer=='a'){ currentPlayer=0 ; } else if(nextPlayer=='b'){ currentPlayer=1 ; } else if(nextPlayer=='c'){ currentPlayer=2 ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sa : String ; sa := scanner.getCurrent() ; var sb : String ; sb := scanner.getCurrent() ; var sc : String ; sc := scanner.getCurrent() ; var currentPlayer : int ; currentPlayer := 0 ; while (true) do ( var nextPlayer : String ; nextPlayer := 'a' ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (currentPlayer) ; if _switchval = 0 then ( if (sa->isEmpty()) then ( OclFile["System.out"].print("A") ; return ) else skip ; nextPlayer := sa->at(0+1) ; sa := sa.subrange(1+1,1) ; break ) else skip ; if _switchval = 1 then ( if (sb->isEmpty()) then ( OclFile["System.out"].print("B") ; return ) else skip ; nextPlayer := sb->at(0+1) ; sb := sb.subrange(1+1,1) ; break ) else skip ; if _switchval = 2 then ( if (sc->isEmpty()) then ( OclFile["System.out"].print("C") ; return ) else skip ; nextPlayer := sc->at(0+1) ; sc := sc.subrange(1+1,1) ; break ) else skip ; ) if (nextPlayer = 'a') then ( currentPlayer := 0 ) else if (nextPlayer = 'b') then ( currentPlayer := 1 ) else if (nextPlayer = 'c') then ( currentPlayer := 2 ) else skip ; ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main().run(); } void run(){ String a=sc.next(); String b=sc.next(); String c=sc.next(); String[] abc=new String[] { a,b,c }; int t=0 ; for(; ; ){ String e=abc[t]; if(e.length()==0){ break ; } int next=abc[t] .charAt(0)-'a' ; abc[t]=abc[t] .substring(1); t=next ; } System.out.println(new String[] { "A","B","C" } [t]); } int ni(){ return Integer.parseInt(sc.next()); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var a : String ; a := sc.getCurrent() ; var b : String ; b := sc.getCurrent() ; var c : String ; c := sc.getCurrent() ; var abc : Sequence(String) ; abc := Sequence{a,b,c} ; var t : int ; t := 0 ; while true do ( ( var e : String ; e := abc[t+1] ; if (e->size() = 0) then ( break ) else skip ; var next : int ; next := abc[t+1]->at(0+1) - ('a')->char2byte() ; abc[t+1] := abc[t+1].subrange(1+1,1) ; t := next ; ) ) ; OclFile["System.out"].println(Sequence{"A","B","C"}[t+1]) ; ); operation ni() : int pre: true post: true activity: ( return (sc.getCurrent())->toInteger() ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int R=3 ; static int C=4 ; static int gcd(int a,int b){ if(b==0)return a ; return gcd(b,a % b); } static void replacematrix(int[][] mat,int n,int m){ int[] rgcd=new int[R]; int[] cgcd=new int[C]; for(int i=0 ; icollect(0) ; var cgcd : Sequence(int) ; cgcd := Integer.subrange(1,C)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m 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]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < m do ( mat[i+1][j+1] := Set{rgcd[i+1], cgcd[j+1]}->max() ; ; j := j + 1 ) ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Sequence(Sequence(int)) ; m := Sequence{Sequence{1,2,3,3},Sequence{4,5,6,6},Sequence{7,8,9,9},} ; execute replacematrix(m, R, C) ; var i : int ; i := 0 ; while i < R do ( ( var j : int ; j := 0 ; while j < C do ( OclFile["System.out"].print(m[i+1][j+1] + " ") ; ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; import java.util.stream.IntStream ; import javafx.util.Pair ; public class Main { static void sort(int a[]){ Random ran=new Random(); for(int i=0 ; isize() do ( ( var r : int ; r := ran.nextInt(a->size()) ; var temp : int ; temp := a[r+1] ; a[r+1] := a[i+1] ; a[i+1] := temp ) ; i := i + 1 ) ; a := a->sort() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,6)->collect(0) ; a[0+1] := input.getCurrent()->toInteger() ; a[1+1] := input.getCurrent()->toInteger() ; a[2+1] := input.getCurrent()->toInteger() ; a[3+1] := input.getCurrent()->toInteger() ; a[4+1] := input.getCurrent()->toInteger() ; a[5+1] := input.getCurrent()->toInteger() ; var result : Sequence(int) ; result := Integer.subrange(1,3)->collect(0) ; result[0+1] := Set{a[1+1], n - a[2+1] - a[4+1]}->min() ; n := n-(result[0+1]) ; result[1+1] := Set{a[3+1], n - a[4+1]}->min() ; result[2+1] := n - result[1+1] ; OclFile["System.out"].println(result[0+1] + " " + result[1+1] + " " + result[2+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class one { public static void main(String[] args)throws IOException { BufferedReader xx=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(xx.readLine()); String input1[]=xx.readLine().split(" "); int min1=Integer.parseInt(input1[0]); int max1=Integer.parseInt(input1[1]); String input2[]=xx.readLine().split(" "); int min2=Integer.parseInt(input2[0]); int max2=Integer.parseInt(input2[1]); String input3[]=xx.readLine().split(" "); int min3=Integer.parseInt(input3[0]); int max3=Integer.parseInt(input3[1]); int ans1=0,ans2=0,ans3=0 ; n=n-(min1+min2+min3); ans1=min1 ; ans2=min2 ; ans3=min3 ; if(n+min1>=max1){ n=n-max1+min1 ; ans1=max1 ; } else { ans1=ans1+n ; n=0 ; } if(n+min2>=max2){ n=n-max2+min2 ; ans2=max2 ; } else { ans2=ans2+n ; n=0 ; } ans3=ans3+n ; System.out.println(ans1+" "+ans2+" "+ans3); } } ------------------------------------------------------------ OCL File: --------- class one { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var xx : OclFile ; xx := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (xx.readLine())->toInteger() ; var input1 : Sequence(String) ; input1 := xx.readLine()->split(" ") ; var min1 : int ; min1 := (input1[0+1])->toInteger() ; var max1 : int ; max1 := (input1[1+1])->toInteger() ; var input2 : Sequence(String) ; input2 := xx.readLine()->split(" ") ; var min2 : int ; min2 := (input2[0+1])->toInteger() ; var max2 : int ; max2 := (input2[1+1])->toInteger() ; var input3 : Sequence(String) ; input3 := xx.readLine()->split(" ") ; var min3 : int ; min3 := (input3[0+1])->toInteger() ; var max3 : int ; max3 := (input3[1+1])->toInteger() ; var ans1 : int ; ans1 := 0 ; var ans2 : int ; ans2 := 0 ; var ans3 : int ; ans3 := 0 ; n := n - (min1 + min2 + min3) ; ans1 := min1 ; ans2 := min2 ; ans3 := min3 ; if (n + min1 >= max1) then ( n := n - max1 + min1 ; ans1 := max1 ) else ( ans1 := ans1 + n ; n := 0 ) ; if (n + min2 >= max2) then ( n := n - max2 + min2 ; ans2 := max2 ) else ( ans2 := ans2 + n ; n := 0 ) ; ans3 := ans3 + n ; OclFile["System.out"].println(ans1 + " " + ans2 + " " + ans3) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); HashMapmap=new HashMap<>(); int n=in.nextInt(); long sum=0 ; for(int i=0 ; itoInteger() ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var name : int ; name := in.getCurrent()->toInteger() ; var pie : int ; pie := in.getCurrent()->toInteger() ; map := map->union(Map{name |-> pie}) ; sum := sum + pie ) ; i := i + 1 ) ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var name : int ; name := in.getCurrent()->toInteger() ; var pie : int ; pie := in.getCurrent()->toInteger() ; if (map->at(name) = null) then ( sum := sum + pie ) else ( var s : int ; s := map->at(name) ; if (s < pie) then ( sum := sum + pie - s ) else skip ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); BinomialCoefficients solver=new BinomialCoefficients(); solver.solve(1,in,out); out.close(); } static class BinomialCoefficients { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); long[] a=new long[n]; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; a := a->sort() ; var ans : long ; ans := a[n - 1+1] ; if (ans mod 2 = 0) then ( var mid : long ; mid := ans / 2 ; var min : long ; min := "9223372036854775807"->toLong() ; var ans2 : long ; ans2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] = ans) then ( continue ) else skip ; var tmp : long ; tmp := if mid - a[i+1] < 0 then -(mid - a[i+1]) else mid - a[i+1] endif ; if (tmp < min) then ( min := tmp ; ans2 := a[i+1] ) else skip ) ; i := i + 1 ) ; skip ; ) else ( var mid1 : long ; mid1 := ans / 2 ; var mid2 : long ; mid2 := mid1 + 1 ; var min : long ; min := "9223372036854775807"->toLong() ; var ans2 : long ; ans2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] = ans) then ( continue ) else skip ; var tmp : long ; tmp := Set{if mid1 - a[i+1] < 0 then -(mid1 - a[i+1]) else mid1 - a[i+1] endif, if mid2 - a[i+1] < 0 then -(mid2 - a[i+1]) else mid2 - a[i+1] endif}->min() ; if (tmp < min) then ( min := tmp ; ans2 := a[i+1] ) else skip ) ; i := i + 1 ) ; skip ; ) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; class GFG { static int kPrimeFactor(int n,int k){ while(n % 2==0){ k--; n=n/2 ; if(k==0)return 2 ; } for(int i=3 ; i<=Math.sqrt(n); i=i+2){ while(n % i==0){ if(k==1)return i ; k--; n=n/i ; } } if(n>2 && k==1)return n ; return-1 ; } public static void main(String args[]){ int n=12,k=3 ; System.out.println(kPrimeFactor(n,k)); n=14 ; k=3 ; System.out.println(kPrimeFactor(n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation kPrimeFactor( n : int, k : int) : int 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 ; i := 3 ; while i <= (n)->sqrt() 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 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12 ; var k : int ; k := 3 ; OclFile["System.out"].println(kPrimeFactor(n, k)) ; n := 14 ; k := 3 ; OclFile["System.out"].println(kPrimeFactor(n, k)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class homework4 { public static void main(String[] args){ Scanner read=new Scanner(System.in); int n=read.nextInt(),d=read.nextInt(),h=read.nextInt(); if(d>2*h ||(d==1 && n!=2)){ System.out.println(-1); return ; } for(int i=1 ; i<=h ; ++i){ System.out.print(i+" "+(i+1)+"\n"); } int x=1 ; for(int i=1 ; i<=(d-h); ++i){ int y=h+1+i ; System.out.print(x+" "+y+"\n"); x=y ; } int v=(d==h)? 2 : 1 ; for(int i=d+2 ; i<=n ; ++i){ System.out.print(i+" "+v+"\n"); } return ; } } ------------------------------------------------------------ OCL File: --------- class homework4 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var read : OclFile ; read := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := read.getCurrent()->toInteger() ; var d : int ; d := read.getCurrent()->toInteger() ; var h : int ; h := read.getCurrent()->toInteger() ; if (d > 2 * h or (d = 1 & n /= 2)) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var i : int ; i := 1 ; while i <= h do ( ( OclFile["System.out"].print(i + " " + (i + 1) + "\n") ) ; i := i + 1 ) ; var x : int ; x := 1 ; var i : int ; i := 1 ; while i <= (d - h) do ( ( var y : int ; y := h + 1 + i ; OclFile["System.out"].print(x + " " + y + "\n") ; x := y ) ; i := i + 1 ) ; var v : int ; v := if (d = h) then 2 else 1 endif ; var i : int ; i := d + 2 ; while i <= n do ( ( OclFile["System.out"].print(i + " " + v + "\n") ) ; i := i + 1 ) ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.util.*; public class Main { static class Pair { int a ; int b ; int c ; public Pair(int a,int b,int c){ this.a=a ; this.b=b ; this.c=c ; } } static class SortA implements Comparator{ public int compare(Pair s1,Pair s2){ if(s1.bs2.b){ return 1 ; } else if(s1.b==s2.b){ if(s1.cs2.c){ return 1 ; } else { if(s1.as2.a){ return 1 ; } } } return 0 ; } } public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int z=(m+1); PriorityQueuepq=new PriorityQueue<>(new SortA()); for(int i=1 ; i<=m ; i++){ int k=Math.abs((m+1)-2*i); pq.add(new Pair(i,0,k)); } for(int i=0 ; i,(,boolean)) { operation compare( s1 : Map, s2 : Map) : int pre: true post: true activity: ( if (s1.b < s2.b) then ( return -1 ) else if (s1.b > s2.b) then ( return 1 ) else if (s1.b = s2.b) then ( if (s1.c < s2.c) then ( return -1 ) else if (s1.c > s2.c) then ( return 1 ) else ( if (s1.a < s2.a) then ( return -1 ) else if (s1.a > s2.a) then ( return 1 ) else skip ; ) ; ) else skip ; ; ; return 0 ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var z : int ; z := (m + 1) ; var pq : Sequence(Map) ; pq := Sequence{}->union(SortA.newSortA()) ; var i : int ; i := 1 ; while i <= m do ( ( var k : int ; k := if (m + 1) - 2 * i < 0 then -((m + 1) - 2 * i) else (m + 1) - 2 * i endif ; pq := pq->including(Map(i, 0, k)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var z1 : Map ; z1 := pq->min() ; OclFile["System.out"].print(z1.a + " ") ; pq := pq->including(Map(z1.a, z1.b + 1, z1.c)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class B195 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int M=in.nextInt(); Integer[] A=new Integer[M]; for(int m=0 ; m(){ @ Override public int compare(Integer o1,Integer o2){ double d1=Math.abs((M+1)/2.0-o1); double d2=Math.abs((M+1)/2.0-o2); if(d1==d2){ return o1-o2 ; } else { return(int)Math.signum(d1-d2); } } } ); StringBuilder output=new StringBuilder(); for(int n=0 ; ntoInteger() ; var M : int ; M := in.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,M)->collect(null) ; var m : int ; m := 0 ; while m < M do ( ( A[m+1] := m + 1 ) ; m := m + 1 ) ; A := OclComparator.sortWith(A, OclComparator.newOclComparator()) ; var output : String ; output := StringLib.newString() ; var n : int ; n := 0 ; while n < N do ( ( output := output + StringLib.newString(A[n mod M+1]) + StringLib.newString(' ') ) ; n := n + 1 ) ; OclFile["System.out"].print(output) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DifferentIsGood { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); String str=input.next(); System.out.println(str.length()>26 ?-1 : n-str.chars().distinct().count()); } } ------------------------------------------------------------ OCL File: --------- class DifferentIsGood { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var str : String ; str := input.getCurrent() ; OclFile["System.out"].println(if str->size() > 26 then -1 else n - str.chars()->asOrderedSet()->size() endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class DifferentisGood { static public void print(String s){ HashSetset=new HashSet<>(); for(int i=0 ; i(); int count=0 ; boolean flag=false ; for(int i=0 ; i0 && set.contains(s.charAt(i))){ diff--; count++; } else { if(set.contains(s.charAt(i))){ flag=true ; } } set.add(s.charAt(i)); } if(flag){ System.out.println(-1); } else { System.out.println(count); } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); print(s); } } ------------------------------------------------------------ OCL File: --------- class DifferentisGood { static operation print( s : String) : void pre: true post: true activity: ( var set : Set(String) ; set := Set{} ; var i : int ; i := 0 ; while i < s->size() do ( ( set := set->including(s->at(i+1)) ) ; i := i + 1 ) ; var diff : int ; diff := 26 - set->size() ; set := Set{} ; var count : int ; count := 0 ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < s->size() do ( ( if (diff > 0 & set->includes(s->at(i+1))) then ( diff := diff - 1 ; count := count + 1 ) else ( if (set->includes(s->at(i+1))) then ( flag := true ) else skip ) ; set := set->including(s->at(i+1)) ) ; i := i + 1 ) ; if (flag) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(count) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; execute print(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class good { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char s[]=sc.next().toCharArray(); int res=0 ; if(n>26)System.out.println(-1); else { int cnt[]=new int[26]; for(int i=0 ; i1){ res++; cnt[pos]=1 ; } } System.out.println(res); } } } ------------------------------------------------------------ OCL File: --------- class good { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var res : int ; res := 0 ; if (n > 26) then OclFile["System.out"].println(-1) else ( var cnt : Sequence(int) ; cnt := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var pos : int ; pos := s[i+1] - ('a')->char2byte() ; cnt[pos+1] := cnt[pos+1] + 1 ; if (cnt[pos+1] > 1) then ( res := res + 1 ; cnt[pos+1] := 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Mohammad { public static void Mohammad_AboHasan()throws IOException { FastReader fr=new FastReader(); int n=fr.nextInt(); if(n>26){ System.out.println(-1); return ; } String s=fr.next(); Setset=new HashSet<>(); for(int i=0 ; i 26) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var s : String ; s := fr.next() ; var set : Set(String) ; set := Set{} ; var i : int ; i := 0 ; while i < s->size() do ( set := set->including(s->at(i+1)) ; ; i := i + 1 ) ; OclFile["System.out"].println(n - set->size()) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute Mohammad_AboHasan() ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var s : String ; s := br.readLine() ; return s ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class kickStart { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); scanner.nextLine(); char[] chars=scanner.nextLine().toCharArray(); int distinct=0 ; if(chars.length==1)System.out.println(0); else if(chars.length>26)System.out.println(-1); else { Arrays.sort(chars); for(int i=1 ; itoInteger() ; skip ; var chars : Sequence(String) ; chars := scanner.nextLine()->characters() ; var distinct : int ; distinct := 0 ; if (chars->size() = 1) then OclFile["System.out"].println(0) else if (chars->size() > 26) then OclFile["System.out"].println(-1) else ( chars := chars->sort() ; var i : int ; i := 1 ; while i < chars->size() do ( ( if (chars[i+1] /= chars[i - 1+1]) then ( distinct := distinct + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(chars->size() - (distinct + 1)) ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Collections ; import java.util.Map.Entry ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { static Scanner scan=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args){ TreeMap>map=new TreeMap>(); while(scan.hasNext()){ String mozi=scan.next(); int page=si(); if(! map.containsKey(mozi)){ ArrayListlist=new ArrayList(); list.add(page); map.put(mozi,list); } else { ArrayListlist=map.get(mozi); list.add(page); map.put(mozi,list); } } for(Entry>e : map.entrySet()){ out.println(e.getKey()); ArrayListlist=e.getValue(); Collections.sort(list); for(int i=0 ; ikeys()->includes(mozi))) then ( var list : Sequence(int) ; list := Sequence{} ; list := list->including(page) ; map := map->union(Map{mozi |-> list}) ) else ( var list : Sequence(int) ; list := map->at(mozi) ; list := list->including(page) ; map := map->union(Map{mozi |-> list}) ) ) ; for (e : map->asSet()) do ( ( skip ; var list : Sequence(int) ; list := e.getValue() ; list := list->sort() ; var i : int ; i := 0 ; while i < list->size() do ( ( if (i = list->size() - 1) then skip ; else skip ; ) ; i := i + 1 ) ) ) ; skip ); static operation si() : int pre: true post: true activity: ( return (scan.getCurrent())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Iterator ; import java.util.Collections ; import java.util.Comparator ; class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int N ; N=scan.nextInt(); ArrayLista=new ArrayList(); for(int i=0 ; iMath.abs((double)a.get(i)-harfMax)){ r_=Math.abs((double)a.get(i)-harfMax); r=a.get(i); } } System.out.print((int)max+" "+(int)r); } public static void check(ArrayLista){ System.out.print("sorting->"); for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Sequence{} ; var i : int ; i := 0 ; while i < N do ( a := a->including(scan.getCurrent()->toInteger()) ; ; i := i + 1 ) ; a := a->sort() ; var max : double ; max := a->at(N - 1+1)->oclAsType(double) ; var harfMax : double ; harfMax := max / 2 ; var r_ : double ; r_ := max ; var r : double ; r := a->at(0+1) ; var i : int ; i := 0 ; while i < N - 1 do ( ( if (r_ > if a->at(i+1)->oclAsType(double) - harfMax < 0 then -(a->at(i+1)->oclAsType(double) - harfMax) else a->at(i+1)->oclAsType(double) - harfMax endif) then ( r_ := if a->at(i+1)->oclAsType(double) - harfMax < 0 then -(a->at(i+1)->oclAsType(double) - harfMax) else a->at(i+1)->oclAsType(double) - harfMax endif ; r := a->at(i+1) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(max->oclAsType(int) + " " + r->oclAsType(int)) ; ); static operation check( a : Sequence(int)) : void pre: true post: true activity: ( OclFile["System.out"].print("sorting->") ; var i : int ; i := 0 ; while i < a->size() do ( OclFile["System.out"].print(a->at(i+1) + " ") ; ; i := i + 1 ) ; OclFile["System.out"].print(" ") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Word { String name ; int page[],size ; public Word(String n){ name=n ; page=new int[100]; size=0 ; } public void addPage(int p){ page[size++]=p ; } public String getName(){ return name ; } public void printWord(){ int i ; Arrays.sort(page,0,size); System.out.println(name); for(i=0 ; i+10){ Word tmp=w[i]; w[i]=w[j]; w[j]=tmp ; } } } for(int i=0 ; icollect(0) ; size := 0 ); operation addPage( p : int) : void pre: true post: true activity: ( page[size+1] := p ; size := size + 1 ); operation getName() : String pre: true post: true activity: ( return name ); operation printWord() : void pre: true post: true activity: ( var i : int ; page := page.subrange(1,0)^(page.subrange(0+1,size)->sort())^page.subrange(size+1,page.size) ; OclFile["System.out"].println(name) ; i := 0 ; while i + 1 < size do ( ( OclFile["System.out"].print(page[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(page[i+1]) ; ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var w : Sequence(Word) ; w := Integer.subrange(1,100)->collect(null) ; var size : int ; size := 0 ; while (true) do ( var i : int ; var s : Sequence(String) ; if (scan.hasNextLine()) then ( s := scan.nextLine()->split(" ") ) else ( break ) ; i := 0 ; while i < size & not(s[0+1] = w[i+1].getName()) do ( ; i := i + 1 ) ; if (i = size) then ( w[size+1] := Word.newWord(s[0+1]) ; size := size + 1 ) else skip ; w[i+1].addPage((s[1+1])->toInteger()) ; ) ; var i : int ; i := 0 ; while i < size - 1 do ( ( var j : int ; j := i + 1 ; while j < size do ( ( if (w[i+1].getName()->compareTo(w[j+1].getName()) > 0) then ( var tmp : Word ; tmp := w[i+1] ; w[i+1] := w[j+1] ; w[j+1] := tmp ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < size do ( ( w[i+1].printWord() ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; public class Main { Scanner sc=new Scanner(System.in); class index implements Comparable{ String key="" ; LinkedListp=new LinkedList(); @ Override public int compareTo(index o){ return this.key.compareTo(o.key); } @ Override public String toString(){ String ret=key+"\n" ; Integer m[]=null ; m=p.toArray(new Integer[0]); Arrays.sort(m); String r2="" ; for(int a : m){ r2+=" "+a ; } ret+=r2.trim(); return ret ; } @ Override public boolean equals(Object obj){ return this.key.equals(((index)obj).key); } } void run(){ LinkedListmap=new LinkedList(); for(; sc.hasNext(); ){ String w=sc.next(); int p=sc.nextInt(); index o=new index(); o.key=w ; o.p.add(p); int i=map.indexOf(o); if(i==-1){ map.add(o); } else { map.get(i).p.add(p); } } index[] s=map.toArray(new index[0]); Arrays.sort(s); for(int i=0 ; i { attribute key : String := ""; attribute p : Sequence(int) := Sequence{}; operation compareTo( o : index) : int pre: true post: true activity: ( return self.key->compareTo(o.key) ); operation toString() : String pre: true post: true activity: ( var ret : String ; ret := key + "\n" ; var m : Sequence(int) ; m := null ; m := p->asSequence() ; m := m->sort() ; var r2 : String ; r2 := "" ; for (a : m) do ( ( r2 := r2+(" " + a) ) ) ; ret := ret+(r2->trim()) ; return ret ); operation equals( obj : OclAny) : boolean pre: true post: true activity: ( return self.key = (obj->oclAsType(index)).key ); } operation run() : void pre: true post: true activity: ( var map : Sequence(index) ; map := Sequence{} ; while sc.hasNext() do ( ( var w : String ; w := sc.getCurrent() ; var p : int ; p := sc.getCurrent()->toInteger() ; var o : index ; o := index.newindex() ; o.key := w ; o.p->excludes(p) ; var i : int ; i := map->indexOf(o)-1 ; if (i = -1) then ( map := map->including(o) ) else ( map->at(i+1).p->excludes(p) ) ; ) ) ; var s : Sequence(index) ; s := map->asSequence() ; s := s->sort() ; var i : int ; i := 0 ; while i < s->size() do ( ( OclFile["System.out"].println(s[i+1]) ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Task5 { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int d=input.nextInt(); int h=input.nextInt(); if(n>=2 && n<=100000 && h>=1 && d>=h && n-1>=d){ int i ; if(d>2*h){ System.out.println("-1"); } else if(d==h){ if(d==1){ if(n==2){ System.out.println("1 2"); System.exit(0); } else System.out.println("-1"); } else if(d==n-1){ for(i=1 ; in)break ; System.out.println((i-1)+" "+i); i++; } } } } } } ------------------------------------------------------------ OCL File: --------- class Task5 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var d : int ; d := input.getCurrent()->toInteger() ; var h : int ; h := input.getCurrent()->toInteger() ; if (n >= 2 & n <= 100000 & h >= 1 & d >= h & n - 1 >= d) then ( var i : int ; if (d > 2 * h) then ( OclFile["System.out"].println("-1") ) else if (d = h) then ( if (d = 1) then ( if (n = 2) then ( OclFile["System.out"].println("1 2") ; OclProcess.exit(0) ) else OclFile["System.out"].println("-1") ; ) else if (d = n - 1) then ( i := 1 ; while i < n do ( ( OclFile["System.out"].println(i + " " + (i + 1)) ) ; i := i + 1 ) ) else ( i := 1 ; while i <= h do ( ( OclFile["System.out"].println(i + " " + (i + 1)) ) ; i := i + 1 ) ; i := i + 1 ; while (i <= n) do ( OclFile["System.out"].println("2 " + (i)) ) ) ; ) else ( var j : int ; i := 1 ; while i <= h do ( ( OclFile["System.out"].println(i + " " + (i + 1)) ) ; i := i + 1 ) ; i := i + 1 ; while (i <= n) do ( OclFile["System.out"].println("1 " + i) ; i := i + 1 ; j := 1 ; while j < d - h do ( ( if (i > n) then break else skip ; OclFile["System.out"].println((i - 1) + " " + i) ; i := i + 1 ) ; j := j + 1 ) ) ) ; ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.HashMap ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Comparator ; public class Main { Scanner in=new Scanner(System.in); void solve(){ HashMap>map=new HashMap<>(); while(in.hasNextLine()){ String[] s=in.nextLine().split(" "); if(map.containsKey(s[0])){ map.get(s[0]).add(s[1]); } else { map.put(s[0],new ArrayList<>(Arrays.asList(s[1]))); } } String[] p=map.keySet().toArray(new String[map.size()]); Arrays.sort(p); for(String s : p){ System.out.println(s); ArrayListlist=map.get(s); list.sort(new Comparator(){ public int compare(String s1,String s2){ return Integer.parseInt(s1)>Integer.parseInt(s2)? 1 :-1 ; } } ); System.out.println(String.join(" ",map.get(s))); } } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation solve() : void pre: true post: true activity: ( var map : Map(String,Sequence(String)) ; map := Map{} ; while (in.hasNextLine()) do ( var s : Sequence(String) ; s := in.nextLine()->split(" ") ; if (map->keys()->includes(s[0+1])) then ( map->at(s[0+1])->excludes(s[1+1]) ) else ( map := map->union(Map{s[0+1] |-> Sequence{}->union(s[1+1])}) ) ) ; var p : Sequence(String) ; p := map->keys()->asSequence() ; p := p->sort() ; for (s : p) do ( ( OclFile["System.out"].println(s) ; var list : Sequence(String) ; list := map->at(s) ; list := list.sort(OclComparator.newOclComparator()) ; OclFile["System.out"].println(join(" ", map->at(s))) ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Comparator ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ class IndexData { String word ; Listpage=new ArrayList<>(); }; Listlist=new ArrayList<>(); Scanner scanner=new Scanner(System.in); for(; scanner.hasNext(); ){ String word=scanner.next(); int page=scanner.nextInt(); boolean is_equals=false ; for(int i=0 ; i(){ @ Override public int compare(IndexData obj0,IndexData obj1){ return obj0.word.compareTo(obj1.word); } } ); for(int i=0 ; i(){ @ Override public int compare(Integer obj0,Integer obj1){ return(obj0>obj1)? 1 :-1 ; } } ); for(int j=0 ; j0 ? " " : "")+index.page.get(j)); } System.out.println(""); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( class IndexData { attribute word : String; attribute page : Sequence(int) := Sequence{}; } var list : Sequence(IndexData) ; list := Sequence{} ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while scanner.hasNext() do ( ( var word : String ; word := scanner.getCurrent() ; var page : int ; page := scanner.getCurrent()->toInteger() ; var is_equals : boolean ; is_equals := false ; var i : int ; i := 0 ; while i < list->size() do ( ( var index : IndexData ; index := list->at(i+1) ; if (word = index.word) then ( is_equals := true ; index.page->excludes(page) ; list := list.setAt(i+1,index) ; break ) else skip ) ; i := i + 1 ) ; if (not(is_equals)) then ( var index : IndexData ; index := IndexData.newIndexData() ; index.word := word ; index.page->excludes(page) ; list := list->including(index) ) else skip ; ) ) ; list, OclComparator.newOclComparator() := list, OclComparator.newOclComparator()->sort() ; var i : int ; i := 0 ; while i < list->size() do ( ( var index : IndexData ; index := list->at(i+1) ; OclFile["System.out"].println(index.word) ; index.page, OclComparator.newOclComparator() := index.page, OclComparator.newOclComparator()->sort() ; var j : int ; j := 0 ; while j < index.page->size() do ( ( OclFile["System.out"].print((if j > 0 then " " else "" endif) + index.page->at(j+1)) ) ; j := j + 1 ) ; OclFile["System.out"].println("") ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countNumbers(int l,int r){ return((r/6)-(l-1)/6); } public static void main(String[] args){ int l=1000,r=6000 ; System.out.println(countNumbers(l,r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumbers( l : int, r : int) : int pre: true post: true activity: ( return ((r / 6) - (l - 1) / 6) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 1000 ; var r : int ; r := 6000 ; OclFile["System.out"].println(countNumbers(l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int find_greatest_divisor(int l,int r){ if(l==r){ return l ; } return 1 ; } public static void main(String[] args){ int l=2,r=12 ; System.out.println(find_greatest_divisor(l,r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation find_greatest_divisor( l : int, r : int) : int pre: true post: true activity: ( if (l = r) then ( return l ) else skip ; return 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 2 ; var r : int ; r := 12 ; OclFile["System.out"].println(find_greatest_divisor(l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void findSumPairs(int a[],int n){ Mapmpp=new HashMap<>(); for(int i=0 ; ientry : mpp.entrySet()){ if(entry.getValue()>occur){ occur=entry.getValue(); } } for(Map.Entryentry : mpp.entrySet()){ if(entry.getValue()==occur)System.out.println(entry.getKey()); } } public static void main(String args[]){ int a[]={ 1,8,3,11,4,9,2,7 }; int n=a.length ; findSumPairs(a,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findSumPairs( a : Sequence(int), n : int) : void pre: true post: true activity: ( var mpp : Map(int,int) ; mpp := Map{} ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( ( mpp := mpp->union(Map{a[i+1] + a[j+1] |-> if mpp->at(a[i+1] + a[j+1]) = null then 1 else mpp->at(a[i+1] + a[j+1]) + 1 endif}) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var occur : int ; occur := 0 ; for (entry : mpp->asSet()) do ( ( if (entry.getValue() > occur) then ( occur := entry.getValue() ) else skip ) ) ; for (entry : mpp->asSet()) do ( ( if (entry.getValue() = occur) then OclFile["System.out"].println(entry.getKey()) ; else skip ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,8,3,11,4,9,2,7} ; var n : int ; n := a->size() ; execute findSumPairs(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static void twoParts(String str){ int flag=0 ; String a="" ; char[] gfg=str.toCharArray(); for(int i=0 ; icharacters() ; var i : int ; i := 0 ; while i < str->size() do ( ( if (gfg[i+1] = '4') then ( gfg[i+1] := '3' ; a := a+('1') ; flag := 1 ) else if (flag /= 0) then a := a+('0') ; else skip ; ) ; i := i + 1 ) ; str := StringLib.newString(gfg) ; OclFile["System.out"].print(str + " " + a) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "9441" ; execute twoParts(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class AbsentRemainder { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(); int minimum=Integer.MAX_VALUE ; int[] nums=new int[n]; for(int i=0 ; itoInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var minimum : int ; minimum := 2147483647 ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := sc.getCurrent()->toInteger() ; minimum := Set{minimum, nums[i+1]}->min() ) ; i := i + 1 ) ; var i : int ; i := 0 ; var k : int ; k := 0 ; while k < n / 2 do ( ( if (nums[i+1] /= minimum) then ( OclFile["System.out"].println(nums[i+1] + " " + minimum) ; k := k + 1 ) else skip ) ; i := i + 1 ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; class Main { public static void main(String...args){ int N=IN.nextInt(); int ans=0 ; for(int i=0 ; ivoid puts(T arg){ System.out.println(arg); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := IN.nextInt() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < N do ( ( ans := ans+(IN.nextInt()) ) ; i := i + 1 ) ; execute puts(ans - N) ); static attribute IN : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation puts( arg : T) : void pre: true post: true activity: ( OclFile["System.out"].println(arg) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.Closeable ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.HashMap ; import java.util.LinkedList ; import java.util.Map.Entry ; import java.util.PriorityQueue ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { try(final Scanner sc=new Scanner(System.in)){ final int N=sc.nextInt(); long answer=0 ; for(int i=0 ; itoInteger() ; var answer : long ; answer := 0 ; var i : int ; i := 0 ; while i < N do ( ( answer := answer+(sc.getCurrent()->toLong() - 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(answer) )) ); static class Scanner implements Closeable { attribute br : OclFile; attribute tok : OclIterator; static operation newScanner( is : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(is); return self ); operation initialise( is : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(is)) ); operation getLine() : void pre: true post: true activity: ( while (not(hasNext())) do ( tok := OclIterator.newOclIterator_String(br.readLine()) ) ); operation hasNext() : boolean pre: true post: true activity: ( return tok /= null & tok.hasNext() ); operation next() : String pre: true post: true activity: ( execute getLine() ; return tok.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var ret : Sequence(int) ; ret := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ret[i+1] := self.nextInt() ) ; i := i + 1 ) ; return ret ); operation nextLongArray( n : int) : Sequence(long) pre: true post: true activity: ( var ret : Sequence(long) ; ret := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ret[i+1] := self.nextLong() ) ; i := i + 1 ) ; return ret ); operation close() : void pre: true post: true activity: ( skip ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { static int answer=0 ; static String str[]; public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int length=Integer.parseInt(br.readLine()); str=br.readLine().split(" "); for(String num : str){ answer+=Integer.parseInt(num); } answer-=length ; System.out.println(answer); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute answer : int := 0; static attribute str : Sequence(String); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var length : int ; length := (br.readLine())->toInteger() ; str := br.readLine()->split(" ") ; for (num : str) do ( ( answer := answer+((num)->toInteger()) ) ) ; answer := answer-(length) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); StringBuilder ans=new StringBuilder(); ArrayListlines=new ArrayList<>(); String input=sc.nextLine(); int max=input.length(); boolean left=true ; lines.add(input); while(sc.hasNextLine()){ input=sc.nextLine(); lines.add(input); if(input.length()>max){ max=input.length(); } } for(int i=0 ; isize() ; var left : boolean ; left := true ; lines := lines->including(input) ; while (sc.hasNextLine()) do ( input := sc.nextLine() ; lines := lines->including(input) ; if (input->size() > max) then ( max := input->size() ) else skip ) ; var i : int ; i := 0 ; while i < max + 2 do ( ( ans := ans + StringLib.newString('*') ) ; i := i + 1 ) ; ans := ans + StringLib.newString(' ') ; for (line : lines) do ( ( var l : double ; l := ((max)->char2byte() - line->size()) / 2.0 ; var r : double ; r := ((max)->char2byte() - line->size()) / 2.0 ; if (left) then ( r := r+(0.5) ) else ( l := l+(0.5) ) ; if (l->oclAsType(int) /= r->oclAsType(int)) then ( left := not(left) ) else skip ; ans := ans + StringLib.newString('*') ; var i : int ; i := 0 ; while i < l->oclAsType(int) do ( ( ans := ans + StringLib.newString(' ') ) ; i := i + 1 ) ; ans := ans + StringLib.newString(line) ; var i : int ; i := 0 ; while i < r->oclAsType(int) do ( ( ans := ans + StringLib.newString(' ') ) ; i := i + 1 ) ; ans := ans + StringLib.newString("*\n") ; ) ) ; var i : int ; i := 0 ; while i < max + 2 do ( ( ans := ans + StringLib.newString('*') ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; import java.io.*; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br.readLine(); String str[]=br.readLine().split(" "); BigInteger d[]=new BigInteger[str.length]; BigInteger v=BigInteger.ONE ; for(int i=0 ; isplit(" ") ; var d : Sequence(long) ; d := Integer.subrange(1,str->size())->collect(null) ; var v : long ; v := 1 ; var i : int ; i := 0 ; while i < str->size() do ( ( d[i+1] := long(str[i+1]) ; v := v.multiply(d[i+1]) ) ; i := i + 1 ) ; v := v.subtract(1) ; var t : long ; t := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( t := t->excludes(v.remainder(d[i+1])) ) ; i := i + 1 ) ; OclFile["System.out"].println(t) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.LinkedList ; import java.util.List ; import java.util.Map ; import java.util.PriorityQueue ; import java.util.Set ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ FastReader sc=new FastReader(); int n=sc.nextInt(); long res=0 ; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countMoves(int n){ int ct=0 ; for(int i=1 ; i<=n ; i++)ct+=i*(n-i); ct+=n ; return ct ; } public static void main(String[] args){ int n=3 ; System.out.println(countMoves(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countMoves( n : int) : int pre: true post: true activity: ( var ct : int ; ct := 0 ; var i : int ; i := 1 ; while i <= n do ( ct := ct+(i * (n - i)) ; ; i := i + 1 ) ; ct := ct+(n) ; return ct ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(countMoves(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void gouldSequence(int n){ for(int row_num=1 ; row_num<=n ; row_num++){ int count=1 ; int c=1 ; for(int i=1 ; i<=row_num ; i++){ c=c*(row_num-i)/i ; if(c % 2==1)count++; } System.out.print(count+" "); } } public static void main(String[] args){ int n=16 ; gouldSequence(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gouldSequence( n : int) : void pre: true post: true activity: ( var row_num : int ; row_num := 1 ; while row_num <= n do ( ( var count : int ; count := 1 ; var c : int ; c := 1 ; var i : int ; i := 1 ; while i <= row_num do ( ( c := c * (row_num - i) / i ; if (c mod 2 = 1) then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(count + " ") ) ; row_num := row_num + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 16 ; execute gouldSequence(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; itoInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static attribute in : FastScanner := FastScanner.newFastScanner(); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var s : Sequence(String) ; s := in.next()->characters() ; var arr : Sequence(int) ; arr := in.readArray(n) ; var count : int ; count := 0 ; var condi : boolean ; condi := false ; var l : int ; l := 0 ; var r : int ; r := 1 ; var min : int ; min := 2147483647 ; var temp : int ; temp := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (s[i+1] = 'R') then temp := arr[i+1] ; else if (s[i+1] = 'L' & temp /= -1) then ( min := Set{arr[i+1] - temp, min}->min() ) else skip ; ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.reflect.Array ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.IllegalFormatCodePointException ; import java.util.Scanner ; public class Main { static ArrayList md=new ArrayList(); public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); String s=in.next(); int[] x=new int[n]; int d=0 ; int temp=0 ; for(int i=0 ; itoInteger() ; var s : String ; s := in.getCurrent() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var d : int ; d := 0 ; var temp : int ; temp := 0 ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = 'R' & i /= s->size() - 1) then ( if (s->at(i + 1+1) = 'L') then ( d := (x[i + 1+1] - x[i+1]) / 2 ; if (d < temp or temp = 0) then temp := d ; else skip ) else skip ) else skip ) ; i := i + 1 ) ; if (temp = 0) then ( OclFile["System.out"].println("-1") ) else OclFile["System.out"].println(temp) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class _28 { public static void main(String[] args){ Scanner input=new Scanner(System.in); int t=input.nextInt(); while(t-->0){ int n=input.nextInt(); int[] arr=new int[n]; int min=Integer.MAX_VALUE ; for(int i=0 ; i0){ if(arr[i]==min){ i++; } else { System.out.println(arr[i]+" "+min); i++; n--; } } } } } ------------------------------------------------------------ OCL File: --------- class { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := input.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := input.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( var curr : int ; curr := input.getCurrent()->toInteger() ; arr[i+1] := curr ; min := Set{min, curr}->min() ) ; i := i + 1 ) ; n := n / 2 ; var i : int ; i := 0 ; while (i < arr->size() & n > 0) do ( if (arr[i+1] = min) then ( i := i + 1 ) else ( OclFile["System.out"].println(arr[i+1] + " " + min) ; i := i + 1 ; n := n - 1 ) ) ; ) ; ) ); } 8 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := input.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := input.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( var curr : int ; curr := input.getCurrent()->toInteger() ; arr[i+1] := curr ; min := Set{min, curr}->min() ) ; i := i + 1 ) ; n := n / 2 ; var i : int ; i := 0 ; while (i < arr->size() & n > 0) do ( if (arr[i+1] = min) then ( i := i + 1 ) else ( OclFile["System.out"].println(arr[i+1] + " " + min) ; i := i + 1 ; n := n - 1 ) ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import com.sun.security.jgss.GSSUtil ; import java.util.*; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); String str=input.next(); Vectorv=new Vector<>(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var str : String ; str := input.getCurrent() ; var v : Sequence(int) ; v := Sequence{} ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; var counter : int ; counter := 0 ; var i : int ; i := 1 ; while i < str->size() do ( ( if (str->at(i - 1+1) = 'R' & str->at(i+1) = 'L') then ( v := v->including((a[i+1] - a[i - 1+1]) / 2) ) else skip ) ; i := i + 1 ) ; if (not(v->isEmpty())) then ( v := v->sort() ; OclFile["System.out"].println(v->at(0+1)) ) else OclFile["System.out"].println(-1) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DS { public static void main(String[] args){ Scanner s=new Scanner(System.in); int c=s.nextInt()-1 ; String str=s.next(); int y1=s.nextInt(); int p=Integer.MAX_VALUE ; boolean b=true ; for(int i=0 ; itoInteger() - 1 ; var str : String ; str := s.getCurrent() ; var y1 : int ; y1 := s.getCurrent()->toInteger() ; var p : int ; p := 2147483647 ; var b : boolean ; b := true ; var i : int ; i := 0 ; while i < c do ( ( var y2 : int ; y2 := s.getCurrent()->toInteger() ; var pp : int ; pp := 0 ; var f : boolean ; f := false ; if (str->at(i+1) = 'R' & str->at(i + 1+1) = 'L') then ( pp := (y2 - (y1)->char2byte()) / 2 ; f := true ; b := false ) else skip ; y1 := y2 ; if (pp < p & f) then p := pp ; else skip ; ) ; i := i + 1 ) ; if (b) then OclFile["System.out"].println(-1) else OclFile["System.out"].println(p) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF699_D2_A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int num=scanner.nextInt(); int[] colliders=new int[num]; scanner.nextLine(); String directions=scanner.nextLine(); int ans=999999999 ; for(int i=0 ; itoInteger() ; var colliders : Sequence(int) ; colliders := Integer.subrange(1,num)->collect(0) ; skip ; var directions : String ; directions := scanner.nextLine() ; var ans : int ; ans := 999999999 ; var i : int ; i := 0 ; while i < num do ( ( colliders[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < num do ( ( if (directions->at(i+1) = 'L' & directions->at(i - 1+1) = 'R') then ( var time : long ; time := (colliders[i+1] + colliders[i - 1+1]) / 2 ; time := if time - colliders[i - 1+1] < 0 then -(time - colliders[i - 1+1]) else time - colliders[i - 1+1] endif ; if (time < ans) then ans := time->oclAsType(int) ; else skip ) else skip ) ; i := i + 1 ) ; if (ans = 999999999) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(ans) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); int M=Integer.parseInt(sc.next()); int[][] p=new int[M][3]; for(int i=0 ; io1[1]==o2[1] ? o1[2]-o2[2] : o1[1]-o2[1]); Mapmap=new HashMap<>(); int now=0 ; int count=1 ; for(int i=0 ; itoInteger() ; var M : int ; M := (sc.getCurrent())->toInteger() ; var p : Sequence(Sequence(int)) ; p := Integer.subrange(1,M)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < M do ( ( p[i+1][0+1] := i ; p[i+1][1+1] := (sc.getCurrent())->toInteger() ; p[i+1][2+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; skip ; p := OclComparator.sortWith(p, lambda (o1 , o2) : OclAny in if o1[1+1] = o2[1+1] then o1[2+1] - o2[2+1] else o1[1+1] - o2[1+1] endif) ; var map : Map(int,Sequence(int)) ; map := Map{} ; var now : int ; now := 0 ; var count : int ; count := 1 ; var i : int ; i := 0 ; while i < M do ( ( if (now = p[i+1][1+1]) then ( count := count + 1 ) else ( now := p[i+1][1+1] ; count := 1 ) ; var c : Sequence(int) ; c := Sequence{p[i+1][1+1],count} ; map := map->union(Map{p[i+1][0+1] |-> c}) ) ; i := i + 1 ) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var i : int ; i := 0 ; while i < M do ( ( var r : Sequence(int) ; r := map->at(i) ; skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); StringBuilder ans=new StringBuilder(); ArrayListlines=new ArrayList<>(); String input=sc.readLine(); int max=input.length(); boolean left=true ; while(input!=null){ lines.add(input); if(input.length()>max){ max=input.length(); } input=sc.readLine(); } for(int i=0 ; isize() ; var left : boolean ; left := true ; while (input /= null) do ( lines := lines->including(input) ; if (input->size() > max) then ( max := input->size() ) else skip ; input := sc.readLine() ) ; var i : int ; i := 0 ; while i < max + 2 do ( ( ans := ans + StringLib.newString('*') ) ; i := i + 1 ) ; ans := ans + StringLib.newString(' ') ; for (line : lines) do ( ( var l : double ; l := ((max)->char2byte() - line->size()) / 2.0 ; var r : double ; r := ((max)->char2byte() - line->size()) / 2.0 ; if (left) then ( r := r+(0.5) ) else ( l := l+(0.5) ) ; if (l->oclAsType(int) /= r->oclAsType(int)) then ( left := not(left) ) else skip ; ans := ans + StringLib.newString('*') ; var i : int ; i := 0 ; while i < l->oclAsType(int) do ( ( ans := ans + StringLib.newString(' ') ) ; i := i + 1 ) ; ans := ans + StringLib.newString(line) ; var i : int ; i := 0 ; while i < r->oclAsType(int) do ( ( ans := ans + StringLib.newString(' ') ) ; i := i + 1 ) ; ans := ans + StringLib.newString("*\n") ; ) ) ; var i : int ; i := 0 ; while i < max + 2 do ( ( ans := ans + StringLib.newString('*') ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int p[]=new int[m]; long y[]=new long[m]; HashMapmap=new HashMap(); ; long num[]=new long[m]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,m)->collect(0) ; var y : Sequence(long) ; y := Integer.subrange(1,m)->collect(0) ; var map : Map(long,long) ; map := Map{} ; var num : Sequence(long) ; num := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( p[i+1] := sc.getCurrent()->toInteger() ; y[i+1] := sc.getCurrent()->toLong() ; num[i+1] := 10000000000L * p[i+1] + y[i+1] ) ; i := i + 1 ) ; num := num->sort() ; var div : long ; div := 1 ; var counter : long ; counter := 1 ; var i : int ; i := 0 ; while i < m do ( ( if (num[i+1] / 10000000000L = div) then else ( div := num[i+1] / 10000000000L ; counter := 1 ) ; map := map->union(Map{num[i+1] - div * 10000000000L |-> counter}) ; counter := counter + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( var s : String ; s := ((1000000->oclAsType(long) + p[i+1]) + "") ; var s2 : String ; s2 := ((1000000 + map->at(y[i+1])) + "") ; OclFile["System.out"].println(s.subrange(1+1,1) + s2.subrange(1+1,1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { InputStream in=System.in ; PrintStream out=System.out ; void solv(int[][] x){ Arrays.sort(x,new Comparator(){ @ Override public int compare(int[] a,int[] b){ int x=a[1]-b[1]; if(x==0){ return a[2]-b[2]; } return x ; } } ); int prev=-1 ; int num=0 ; for(int i=0 ; ia[0]-b[0]); StringBuilder sb=new StringBuilder(); for(int[] a : x){ sb.append(String.format("%06d%06d\n",a[1],a[3])); } out.print(sb); } public void _main(String[] args){ Scanner sc=new Scanner(in); int n=sc.nextInt(); int m=sc.nextInt(); int[][] x=new int[m][4]; for(int i=0 ; i.newOclComparator()) ; var prev : int ; prev := -1 ; var num : int ; num := 0 ; var i : int ; i := 0 ; while i < x->size() do ( ( if (x[i+1][1+1] /= prev) then ( num := 1 ; prev := x[i+1][1+1] ) else ( num := num + 1 ) ; x[i+1][3+1] := num ) ; i := i + 1 ) ; x := OclComparator.sortWith(x, lambda (a , b) : OclAny in a[0+1] - b[0+1]) ; var sb : String ; sb := StringLib.newString() ; for (a : x) do ( ( sb := sb + StringLib.newString(StringLib.format("%06d%06d\n",Sequence{a[1+1],a[3+1]})) ) ) ; skip ; ); operation _main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var x : Sequence(Sequence(int)) ; x := Integer.subrange(1,m)->collect(Integer.subrange(1,4)->collect(0)) ; var i : int ; i := 0 ; while i < m do ( ( x[i+1] := Sequence{i,sc.getCurrent()->toInteger(),sc.getCurrent()->toInteger(),-1} ) ; i := i + 1 ) ; execute solv(x) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain()._main(args) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.*; public class Main { public static void main(String[] args){ solve(System.in,System.out); } private static class City { int p ; int y ; } static void solve(InputStream is,PrintStream os){ Scanner sc=new Scanner(is); int n=sc.nextInt(); int m=sc.nextInt(); Listcities=new ArrayList<>(m); for(int i=0 ; i>prefToCity=new HashMap<>(); for(City c : cities){ Listlist=prefToCity.getOrDefault(c.p,new ArrayList<>()); list.add(c); prefToCity.put(c.p,list); } MapindexOfPref=new HashMap<>(); for(Listlist : prefToCity.values()){ list.sort(Comparator.comparingInt(c->c.y)); for(int i=0 ; ires=new ArrayList<>(); for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var cities : Sequence(City) ; cities := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( var p : int ; p := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var c : City ; c := City.newCity() ; c.p := p ; c.y := y ; cities := cities->including(c) ; ) ; i := i + 1 ) ; var prefToCity : Map(int,Sequence(City)) ; prefToCity := Map{} ; for (c : cities) do ( ( var list : Sequence(City) ; list := (if prefToCity->keys()->contains(c.p) then prefToCity->at(c.p) else Sequence{} endif) ; list := list->including(c) ; prefToCity := prefToCity->union(Map{c.p |-> list}) ) ) ; var indexOfPref : Map(City,int) ; indexOfPref := Map{} ; for (list : prefToCity->values()) do ( ( list := list.sort(Comparator.comparingInt(lambda c : OclAny in c.y)) ; var i : int ; i := 0 ; while i < list->size() do ( ( indexOfPref := indexOfPref->union(Map{list->at(i+1) |-> i + 1}) ) ; i := i + 1 ) ) ) ; var res : Sequence(String) ; res := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( var c : City ; c := cities->at(i+1) ; res := res->including(StringLib.format("%06d%06d",Sequence{c.p,indexOfPref->at(c)})) ) ; i := i + 1 ) ; os.println(join(lineSeparator(), res)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.text.DecimalFormat ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); int city[][]=new int[m+1][4]; for(int id=1 ; id<=m ; id++){ city[id][0]=id ; city[id][1]=in.nextInt(); city[id][2]=in.nextInt(); } Arrays.sort(city,(c1,c2)->{ if(c1[1]!=c2[1])return c1[1]-c2[1]; else return c1[2]-c2[2]; } ); DecimalFormat df=new DecimalFormat("000000"); String result[]=new String[m]; int pref=-1 ; int num=0 ; for(int i=1 ; i<=m ; i++){ pref=city[i][1]; num=(pref==city[i-1][1] ? num+1 : 1); result[city[i][0]-1]=df.format(pref)+df.format(num); } StringBuilder sb=new StringBuilder(); for(String s : result){ sb.append(s).append("\n"); } System.out.println(sb); in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var city : Sequence(Sequence(int)) ; city := Integer.subrange(1,m + 1)->collect(Integer.subrange(1,4)->collect(0)) ; var id : int ; id := 1 ; while id <= m do ( ( city[id+1][0+1] := id ; city[id+1][1+1] := in.getCurrent()->toInteger() ; city[id+1][2+1] := in.getCurrent()->toInteger() ) ; id := id + 1 ) ; city := OclComparator.sortWith(city, lambda (c1 , c2) : OclAny in ( if (c1[1+1] /= c2[1+1]) then return c1[1+1] - c2[1+1] else return c1[2+1] - c2[2+1] )) ; var df : DecimalFormat ; df := DecimalFormat.newDecimalFormat("000000") ; var result : Sequence(String) ; result := Integer.subrange(1,m)->collect(null) ; var pref : int ; pref := -1 ; var num : int ; num := 0 ; var i : int ; i := 1 ; while i <= m do ( ( pref := city[i+1][1+1] ; num := (if pref = city[i - 1+1][1+1] then num + 1 else 1 endif) ; result[city[i+1][0+1] - 1+1] := df.format(pref) + df.format(num) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; for (s : result) do ( ( sb := sb + StringLib.newString(s) + StringLib.newString("\n") ) ) ; OclFile["System.out"].println(sb) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class KanbanNumbers { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); int places=0 ; String[] once={ "","One","Two","Three","Four","Five","Six","Seven","Eight","Nine" }; String[] str={ "","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Forteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen","Twenty" }; String[] twice={ "","Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety" }; String answer="" ; if(test<=20){ answer=str[test]; } else { while(test>0){ places++; int val=test % 10 ; test=test/10 ; if(places==1){ answer=once[val]+" "+answer ; } else { answer=twice[val]+" "+answer ; } } } answer=answer.toLowerCase(); if(answer.contains("k")|| answer.contains("a")|| answer.contains("n")){ System.out.println("NO"); } else { System.out.println("YES"); } } } ------------------------------------------------------------ OCL File: --------- class KanbanNumbers { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := sc.getCurrent()->toInteger() ; var places : int ; places := 0 ; var once : Sequence(String) ; once := Sequence{"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"} ; var str : Sequence(String) ; str := Sequence{"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Forteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen","Twenty"} ; var twice : Sequence(String) ; twice := Sequence{"","Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"} ; var answer : String ; answer := "" ; if (test <= 20) then ( answer := str[test+1] ) else ( while (test > 0) do ( places := places + 1 ; var val : int ; val := test mod 10 ; test := test / 10 ; if (places = 1) then ( answer := once[val+1] + " " + answer ) else ( answer := twice[val+1] + " " + answer ) ) ) ; answer := answer->toLowerCase() ; if (answer->includes("k") or answer->includes("a") or answer->includes("n")) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void checkIfSortRotated(int arr[],int n){ int minEle=Integer.MAX_VALUE ; int maxEle=Integer.MIN_VALUE ; int minIndex=-1 ; for(int i=0 ; isize() ; execute checkIfSortRotated(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ int n ; Scanner sc=new Scanner(System.in); n=sc.nextInt(); int a=n % 10 ; int b=n/10 ; if(a==1 || a==7 || a==9 || b==1 && a!=2 || b==2 || b==7 || b==9)System.out.print("No"); else System.out.println("Yes"); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; var a : int ; a := n mod 10 ; var b : int ; b := n / 10 ; if (a = 1 or a = 7 or a = 9 or b = 1 & a /= 2 or b = 2 or b = 7 or b = 9) then OclFile["System.out"].print("No") else OclFile["System.out"].println("Yes") ; ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class file { private static final Scanner sc=new Scanner(System.in); private static void foo(){ int n=sc.nextInt(); HashSetset=new HashSet<>(Arrays.asList(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,447,49,51,57,59,61,67,69,71,72,73,74,75,76,77,78,79,81,87,89,90,91,92,93,94,95,96,97,98,99)); if(set.contains(n))System.out.println("NO"); else System.out.println("YES"); } public static void main(String[] args){ foo(); } } ------------------------------------------------------------ OCL File: --------- class file { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation foo() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var set : Set(int) ; set := Set{}->union(Sequence{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,447,49,51,57,59,61,67,69,71,72,73,74,75,76,77,78,79,81,87,89,90,91,92,93,94,95,96,97,98,99}) ; if (set->includes(n)) then OclFile["System.out"].println("NO") ; else OclFile["System.out"].println("YES") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute foo() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; public final class p032 implements EulerSolution { public static void main(String[] args){ System.out.println(new p032().run()); } public String run(){ int sum=0 ; for(int i=1 ; i<10000 ; i++){ if(hasPandigitalProduct(i))sum+=i ; } return Integer.toString(sum); } private static boolean hasPandigitalProduct(int n){ for(int i=1 ; i<=n ; i++){ if(n % i==0 && isPandigital(""+n+i+n/i))return true ; } return false ; } private static boolean isPandigital(String s){ if(s.length()!=9)return false ; char[] temp=s.toCharArray(); Arrays.sort(temp); return new String(temp).equals("123456789"); } } ------------------------------------------------------------ OCL File: --------- class p032 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p032.newp032().run()) ); operation run() : String pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i < 10000 do ( ( if (hasPandigitalProduct(i)) then sum := sum+(i) ; else skip ) ; i := i + 1 ) ; return ((sum) + "") ); static operation hasPandigitalProduct( n : int) : boolean pre: true post: true activity: ( var i : int ; i := 1 ; while i <= n do ( ( if (n mod i = 0 & isPandigital("" + n + i + n / i)) then return true else skip ) ; i := i + 1 ) ; return false ); static operation isPandigital( s : String) : boolean pre: true post: true activity: ( if (s->size() /= 9) then return false else skip ; var temp : Sequence(String) ; temp := s->characters() ; temp := temp->sort() ; return StringLib.newString(temp) = "123456789" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static class Node { int data ; Node left ; Node right ; Node(int value){ data=value ; left=null ; right=null ; } }; static void specific_level_order_traversal(Node root){ Queueq=new LinkedList<>(); Stack>s=new Stack>(); q.add(root); int sz ; while(q.size()>0){ Vectorv=new Vector(); sz=q.size(); for(int i=0 ; i0){ Vectorv=s.peek(); s.pop(); for(int i=0,j=v.size()-1 ; iincluding(root) ; var sz : int ; while (q->size() > 0) do ( var v : Sequence(int) ; v := Sequence{} ; sz := q->size() ; var i : int ; i := 0 ; while i < sz do ( ( var temp : Node ; temp := q->min() ; q := q.remove() ; v := v->including(temp.data) ; if (temp.left /= null) then q := q->including(temp.left) ; else skip ; if (temp.right /= null) then q := q->including(temp.right) ; else skip ; ) ; i := i + 1 ) ; s := s->append(v) ) ; while (s->size() > 0) do ( var v : Sequence(int) ; v := s->min() ; s := s->front() ; var i : int ; i := 0 ; var j : int ; j := v->size() - 1 ; while i < j do ( ( OclFile["System.out"].print(v->at(i+1) + " " + v->at(j+1) + " ") ; j := j - 1 ) ; i := i + 1 ) ) ; OclFile["System.out"].println(root.data) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var root : Node ; root := Node.newNode(1) ; root.left := Node.newNode(2) ; root.right := Node.newNode(3) ; OclFile["System.out"].println("Specific Level Order traversal" + " of binary tree is") ; execute specific_level_order_traversal(root) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; class Main { public static void main(String[] args){ new Main().run(); } long MODULO=1_000_000_000+7 ; void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long[] f=new long[N+1]; long[] cum=new long[N+1]; Arrays.fill(f,-Integer.MAX_VALUE/16); Arrays.fill(cum,-Integer.MAX_VALUE/16); f[1]=N ; cum[1]=N ; for(int i=2 ; i<=N ; ++i){ f[i]=f[i-1]; f[i]=(f[i]+1L*(N-1)*(N-1)% MODULO)% MODULO ; if(i>3){ f[i]=(f[i]+cum[i-3])% MODULO ; } f[i]=(f[i]+Math.min(0,i-3)-(i-N-1)+1)% MODULO ; cum[i]=(cum[i-1]+f[i])% MODULO ; } System.out.println(f[N]); } void tr(Object...objects){ System.out.println(Arrays.deepToString(objects)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute MODULO : long := 1_000_000_000 + 7; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var f : Sequence(long) ; f := Integer.subrange(1,N + 1)->collect(0) ; var cum : Sequence(long) ; cum := Integer.subrange(1,N + 1)->collect(0) ; f := f->collect(-2147483647 / 16) ; cum := cum->collect(-2147483647 / 16) ; f[1+1] := N ; cum[1+1] := N ; var i : int ; i := 2 ; while i <= N do ( ( f[i+1] := f[i - 1+1] ; f[i+1] := (f[i+1] + 1L * (N - 1) * (N - 1) mod MODULO) mod MODULO ; if (i > 3) then ( f[i+1] := (f[i+1] + cum[i - 3+1]) mod MODULO ) else skip ; f[i+1] := (f[i+1] + Set{0, i - 3}->min() - (i - N - 1) + 1) mod MODULO ; cum[i+1] := (cum[i - 1+1] + f[i+1]) mod MODULO ; ) ; i := i + 1 ) ; OclFile["System.out"].println(f[N+1]) ; ); operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.ArrayList ; import java.util.Scanner ; import java.util.Timer ; import java.util.TimerTask ; public class codeForces { static String str="start" ; public static void main(String[] args0)throws IOException { Scanner s=new Scanner(System.in); int max=0 ; boolean LR=true ; ArrayListarr=new ArrayList<>(); try { while(true){ str=s.nextLine(); arr.add(str); if(str.length()>max){ max=str.length(); } } } catch(java.util.NoSuchElementException x){ } finally { for(int i=0 ; iincluding(str) ; if (str->size() > max) then ( max := str->size() ) else skip ) ) catch (x : IncorrectElementException) do skip finally ( var i : int ; i := 0 ; while i < max + 2 do ( ( OclFile["System.out"].print("*") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; var i : int ; i := 0 ; while i < arr->size() do ( ( var size : int ; size := max - arr->at(i+1)->size() ; if ((size) mod 2 = 0) then ( var j : int ; j := 0 ; while j < size / 2 do ( ( arr := arr.setAt(i+1," " + arr->at(i+1) + " ") ) ; j := j + 1 ) ) else ( var j : int ; j := 0 ; while j < size / 2 do ( ( arr := arr.setAt(i+1," " + arr->at(i+1) + " ") ) ; j := j + 1 ) ; if (LR) then arr := arr.setAt(i+1,arr->at(i+1) + " ") else arr := arr.setAt(i+1," " + arr->at(i+1)) ; ; LR := not(LR) ) ; arr := arr.setAt(i+1,"*" + arr->at(i+1) + "*") ; OclFile["System.out"].println(arr->at(i+1)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < max + 2 do ( ( OclFile["System.out"].print("*") ) ; i := i + 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long MOD=1000000007 ; long[] dp=new long[N+1]; dp[0]=1 ; dp[1]=MOD-1 ; long cur=0 ; for(int i=0 ; itoInteger() ; var MOD : long ; MOD := 1000000007 ; var dp : Sequence(long) ; dp := Integer.subrange(1,N + 1)->collect(0) ; dp[0+1] := 1 ; dp[1+1] := MOD - 1 ; var cur : long ; cur := 0 ; var i : int ; i := 0 ; while i < N do ( ( cur := (cur + dp[i+1]) mod MOD ; if (i = N - 1) then ( dp[N+1] := (dp[N+1] + cur * N) mod MOD ) else ( dp[i + 1+1] := (dp[i + 1+1] + cur) mod MOD ; dp[i + 2+1] := (dp[i + 2+1] - cur + MOD) mod MOD ; if (i + 3 <= N) then ( dp[i + 3+1] := (dp[i + 3+1] + cur) mod MOD ; dp[N+1] := (dp[N+1] + cur * (i + 1)) mod MOD ) else ( dp[N+1] := (dp[N+1] + cur * (N - 1)) mod MOD ) ; dp[N+1] := (dp[N+1] + cur * (((N->oclAsType(long) - 1) * (N - 1)) mod MOD)) mod MOD ) ) ; i := i + 1 ) ; OclFile["System.out"].println((cur + dp[N+1]) mod MOD) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int startingPoint(int Length,int Speed1,int Speed2){ int result1=0,result2=0 ; int time1=Length/Speed1 ; int time2=Length/Speed2 ; result1=__gcd(time1,time2); result2=time1*time2/(result1); return result2 ; } static int __gcd(int a,int b){ if(b==0){ return a ; } return __gcd(b,a % b); } static float firstTime(int Length,int Speed1,int Speed2){ float result=0 ; int relativeSpeed=Math.abs(Speed1-Speed2); result=((float)Length/relativeSpeed); return result ; } public static void main(String[] args){ int L=30,S1=5,S2=2 ; float first_Time=firstTime(L,S1,S2); int starting_Point=startingPoint(L,S1,S2); System.out.println("Met first time after "+first_Time+" hrs"); System.out.println("Met at starting point after "+starting_Point+" hrs"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation startingPoint( Length : int, Speed1 : int, Speed2 : int) : int pre: true post: true activity: ( var result1 : int ; result1 := 0 ; var result2 : int ; result2 := 0 ; var time1 : int ; time1 := Length / Speed1 ; var time2 : int ; time2 := Length / Speed2 ; result1 := __gcd(time1, time2) ; result2 := time1 * time2 / (result1) ; return result2 ); static 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) ); static operation firstTime( Length : int, Speed1 : int, Speed2 : int) : double pre: true post: true activity: ( var result : double ; result := 0 ; var relativeSpeed : int ; relativeSpeed := if Speed1 - Speed2 < 0 then -(Speed1 - Speed2) else Speed1 - Speed2 endif ; result := (Length->oclAsType(double) / relativeSpeed) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 30 ; var S1 : int ; S1 := 5 ; var S2 : int ; S2 := 2 ; var first_Time : double ; first_Time := firstTime(L, S1, S2) ; var starting_Point : int ; starting_Point := startingPoint(L, S1, S2) ; OclFile["System.out"].println("Met first time after " + first_Time + " hrs") ; OclFile["System.out"].println("Met at starting point after " + starting_Point + " hrs") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void alphabetPattern(int N){ int left=0,middle=N-1,right=N+1 ; for(int row=0 ; row<2*N-1 ; row++){ if(row ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void segregate0and1(int arr[],int n){ int count=0 ; for(int i=0 ; isize() ; execute segregate0and1(arr, n) ; execute print(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class AA { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var k : long ; k := sc.getCurrent()->toLong() ; var x : int ; x := sc.getCurrent()->toInteger() ; var f : long ; f := k * 9 ; var y : int ; y := x ; while y < 9 do ( ( f := f - 1 ) ; y := y + 1 ) ; OclFile["System.out"].println(f) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getValue(int n){ int i=0,k=1 ; while(i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ new Solver().run(); } } class Point { int x ; int y ; public Point(int x,int y){ this.x=x ; this.y=y ; } public int distanceTo(Point other){ return Math.abs(x-other.x)+Math.abs(y-other.y); } public String toString(){ return String.format("(%d,%d)",x,y); } } class Solver { private boolean reachable(int difft,int d){ int diff=difft-d ; if(diff<0)return false ; if((diff % 2)==0)return true ; return false ; } public void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[] t=new int[N]; Point[] p=new Point[N]; int sum=0 ; for(int i=0 ; itoInteger() ; var t : Sequence(int) ; t := Integer.subrange(1,N)->collect(0) ; var p : Sequence(Point) ; p := Integer.subrange(1,N)->collect(null) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( t[i+1] := sc.getCurrent()->toInteger() ; p[i+1] := Point.newPoint(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var curt : int ; curt := 0 ; var curp : Point ; curp := Point.newPoint(0, 0) ; var i : int ; i := 0 ; while i < N do ( ( var nxtt : int ; nxtt := t[i+1] ; var dst : Point ; dst := p[i+1] ; var d : int ; d := curp.distanceTo(dst) ; if (not(reachable(nxtt - curt, d))) then ( OclFile["System.out"].println("No") ; return ) else skip ; curt := nxtt ; curp := dst ; ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int row=sc.nextInt(); int[][] index=new int[row][3]; for(int i=0 ; iindex[0][0] || d % 2!=index[0][0] % 2){ System.out.println("No"); System.exit(0); } for(int i=1 ; is || distance % 2!=s % 2){ System.out.println("No"); System.exit(0); } } System.out.println("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var row : int ; row := sc.getCurrent()->toInteger() ; var index : Sequence(Sequence(int)) ; index := Integer.subrange(1,row)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < row do ( ( index[i+1][0+1] := sc.getCurrent()->toInteger() ; index[i+1][1+1] := sc.getCurrent()->toInteger() ; index[i+1][2+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var initX : int ; initX := if index[0+1][1+1] < 0 then -(index[0+1][1+1]) else index[0+1][1+1] endif ; var initY : int ; initY := if index[0+1][2+1] < 0 then -(index[0+1][2+1]) else index[0+1][2+1] endif ; var d : int ; d := initX + initY ; if (d > index[0+1][0+1] or d mod 2 /= index[0+1][0+1] mod 2) then ( OclFile["System.out"].println("No") ; OclProcess.exit(0) ) else skip ; var i : int ; i := 1 ; while i < row do ( ( var x : int ; x := if index[i+1][1+1] - index[i - 1+1][1+1] < 0 then -(index[i+1][1+1] - index[i - 1+1][1+1]) else index[i+1][1+1] - index[i - 1+1][1+1] endif ; var y : int ; y := if index[i+1][2+1] - index[i - 1+1][2+1] < 0 then -(index[i+1][2+1] - index[i - 1+1][2+1]) else index[i+1][2+1] - index[i - 1+1][2+1] endif ; var distance : int ; distance := x + y ; var s : int ; s := index[i+1][0+1] - index[i - 1+1][0+1] ; if (distance > s or distance mod 2 /= s mod 2) then ( OclFile["System.out"].println("No") ; OclProcess.exit(0) ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int n=scn.nextInt(); String answer="Yes" ; int t1=0 ; int x1=0 ; int y1=0 ; for(int i=0 ; itoInteger() ; var answer : String ; answer := "Yes" ; var t1 : int ; t1 := 0 ; var x1 : int ; x1 := 0 ; var y1 : int ; y1 := 0 ; var i : int ; i := 0 ; while i < n do ( ( var t2 : int ; t2 := scn.getCurrent()->toInteger() ; var x2 : int ; x2 := scn.getCurrent()->toInteger() ; var y2 : int ; y2 := scn.getCurrent()->toInteger() ; var difT : int ; difT := t2 - (t1)->char2byte() ; var difX : int ; difX := if x1 - x2 < 0 then -(x1 - x2) else x1 - x2 endif ; var difY : int ; difY := if y1 - y2 < 0 then -(y1 - y2) else y1 - y2 endif ; if (difT - (difX + difY) < 0 or (difT - (difX + difY)) mod 2 = 1) then ( answer := "No" ; break ) else ( t1 := t2 ; x1 := x2 ; y1 := y2 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { static final String YES="Yes" ; static final String NO="No" ; public static void main(String[] args)throws Exception { final Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[][] txy=new int[N][3]; for(int i=0 ; iLong.compare(a[0],b[0])); int a=0,b=0 ; for(int i=0 ; itoInteger() ; var txy : Sequence(Sequence(int)) ; txy := Integer.subrange(1,N)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( txy[i+1][0+1] := sc.getCurrent()->toInteger() ; txy[i+1][1+1] := sc.getCurrent()->toInteger() ; txy[i+1][2+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; txy := OclComparator.sortWith(txy, lambda (a , b) : OclAny in compare(a[0+1], b[0+1])) ; var a : int ; a := 0 ; var b : int ; b := 0 ; var i : int ; i := 0 ; while i < N do ( ( var move : int ; move := txy[i+1][0+1] - (if i = 0 then 0 else txy[i - 1+1][0+1] endif) ; var dist : int ; dist := d(txy[i+1][1+1], txy[i+1][2+1], a, b) ; if (move < dist or (move - dist) mod 2 = 1) then ( OclFile["System.out"].println(NO) ; return ) else skip ; a := txy[i+1][1+1] ; b := txy[i+1][2+1] ; ) ; i := i + 1 ) ; OclFile["System.out"].println(YES) ; ); static operation d( x : int, y : int, x2 : int, y2 : int) : int pre: true post: true activity: ( return if x - x2 < 0 then -(x - x2) else x - x2 endif + if y - y2 < 0 then -(y - y2) else y - y2 endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner stdin=new Scanner(System.in); int num=stdin.nextInt(); int prevT=0 ; int prevX=0 ; int prevY=0 ; for(int i=0 ; i0)){ System.out.println("No"); return ; } prevT=t ; prevX=x ; prevY=y ; } System.out.println("Yes"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdin : OclFile ; stdin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : int ; num := stdin.getCurrent()->toInteger() ; var prevT : int ; prevT := 0 ; var prevX : int ; prevX := 0 ; var prevY : int ; prevY := 0 ; var i : int ; i := 0 ; while i < num do ( ( var t : int ; t := stdin.getCurrent()->toInteger() ; var x : int ; x := stdin.getCurrent()->toInteger() ; var y : int ; y := stdin.getCurrent()->toInteger() ; var time : int ; time := t - prevT ; var move : int ; move := if x - prevX < 0 then -(x - prevX) else x - prevX endif + if y - prevY < 0 then -(y - prevY) else y - prevY endif ; if ((time < move) or ((time - move) mod 2 > 0)) then ( OclFile["System.out"].println("No") ; return ) else skip ; prevT := t ; prevX := x ; prevY := y ; ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Solution3 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); Liststrs=new ArrayList<>(); int maxLen=0 ; while(scanner.hasNextLine()){ String str=scanner.nextLine(); if(str.length()>maxLen)maxLen=str.length(); strs.add(str); } for(int i=0 ; isize() > maxLen) then maxLen := str->size() ; else skip ; strs := strs->including(str) ) ; var i : int ; i := 0 ; while i < maxLen + 2 do ( ( OclFile["System.out"].print('*') ) ; i := i + 1 ) ; OclFile["System.out"].println() ; var flag : int ; flag := 0 ; var sb : String ; sb := StringLib.newString() ; for (str : strs) do ( ( var len : int ; len := maxLen - str->size() ; var left : int ; left := (len + flag) / 2 ; var right : int ; right := (len)->char2byte() - left ; if (len mod 2 /= 0) then ( flag := 1 - flag ) else skip ; sb := sb + StringLib.newString('*') ; var i : int ; i := 0 ; while i < left do ( ( sb := sb + StringLib.newString(' ') ) ; i := i + 1 ) ; sb := sb + StringLib.newString(str) ; var i : int ; i := 0 ; while i < right do ( ( sb := sb + StringLib.newString(' ') ) ; i := i + 1 ) ; sb := sb + StringLib.newString("*\n") ; ) ) ; OclFile["System.out"].print(sb+"") ; var i : int ; i := 0 ; while i < maxLen + 2 do ( ( OclFile["System.out"].print('*') ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { final static int MAX=26 ; static int maxSubStr(char[] str1,int len1,char[] str2,int len2){ if(len1>len2)return 0 ; int freq1[]=new int[MAX]; for(int i=0 ; ifreq2[i])return 0 ; minPoss=Math.min(minPoss,freq2[i]/freq1[i]); } return minPoss ; } public static void main(String[] args){ String str1="geeks",str2="gskefrgoekees" ; int len1=str1.length(); int len2=str2.length(); System.out.println(maxSubStr(str1.toCharArray(),len1,str2.toCharArray(),len2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 26; static operation maxSubStr( str1 : Sequence(String), len1 : int, str2 : Sequence(String), len2 : int) : int pre: true post: true activity: ( if (len1 > len2) then return 0 else skip ; var freq1 : Sequence(int) ; freq1 := Integer.subrange(1,MAX)->collect(0) ; var i : int ; i := 0 ; while i < len1 do ( freq1[i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < len1 do ( freq1[str1[i+1] - ('a')->char2byte()+1] := freq1[str1[i+1] - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var freq2 : Sequence(int) ; freq2 := Integer.subrange(1,MAX)->collect(0) ; var i : int ; i := 0 ; while i < len2 do ( freq2[i+1] := 0 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < len2 do ( freq2[str2[i+1] - ('a')->char2byte()+1] := freq2[str2[i+1] - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var minPoss : int ; minPoss := 2147483647 ; var i : int ; i := 0 ; while i < MAX do ( ( if (freq1[i+1] = 0) then continue else skip ; if (freq1[i+1] > freq2[i+1]) then return 0 else skip ; minPoss := Set{minPoss, freq2[i+1] / freq1[i+1]}->min() ) ; i := i + 1 ) ; return minPoss ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str1 : String ; str1 := "geeks" ; var str2 : String ; str2 := "gskefrgoekees" ; var len1 : int ; len1 := str1->size() ; var len2 : int ; len2 := str2->size() ; OclFile["System.out"].println(maxSubStr(str1->characters(), len1, str2->characters(), len2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n,r,p,c ; int[] card=new int[50]; int[] tmp=new int[50]; while(true){ n=sc.nextInt(); r=sc.nextInt(); if(n==0 && r==0)break ; for(int i=0 ; icollect(0) ; var tmp : Sequence(int) ; tmp := Integer.subrange(1,50)->collect(0) ; while (true) do ( n := sc.getCurrent()->toInteger() ; r := sc.getCurrent()->toInteger() ; if (n = 0 & r = 0) then break else skip ; var i : int ; i := 0 ; while i < n do ( ( card[i+1] := n - i ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < r do ( ( p := sc.getCurrent()->toInteger() ; c := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < c do ( ( tmp[j+1] := card[p - 1 + j+1] ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < p - 1 do ( ( card[p - 2 - j + c+1] := card[p - 2 - j+1] ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < c do ( ( card[j+1] := tmp[j+1] ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(card[0+1]) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long gcd(long a,long b){ if(a==0)return b ; return gcd(b % a,a); } static long powGCD(long a,long n,long b){ for(int i=0 ; i=fuda.length-p-c+1)ans[k+p-1]=fuda[k]; else ans[count++]=fuda[k]; } for(int i=0 ; itoInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; while (n /= 0 & r /= 0) do ( var fuda : Sequence(int) ; fuda := Integer.subrange(1,n + 1)->collect(0) ; var ans : Sequence(int) ; ans := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i < n + 1 do ( fuda[i+1] := i ; ; i := i + 1 ) ; var j : int ; j := 0 ; while j < r do ( ( var p : int ; p := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; execute solve(fuda, ans, p, c) ) ; j := j + 1 ) ; OclFile["System.out"].println(ans[n+1]) ; n := sc.getCurrent()->toInteger() ; r := sc.getCurrent()->toInteger() ; ) ); static operation solve( fuda : Sequence(int), ans : Sequence(int), p : int, c : int) : void pre: true post: true activity: ( var count : int ; count := 1 ; var k : int ; k := 1 ; while k < fuda->size() do ( ( if (k <= fuda->size() - p & k >= fuda->size() - p - c + 1) then ans[k + p - 1+1] := fuda[k+1] ; else ans[count+1] := fuda[k+1] ; count := count + 1 ; ) ; k := k + 1 ) ; var i : int ; i := 0 ; while i < ans->size() do ( fuda[i+1] := ans[i+1] ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args){ int i,m,kazu,k,a,count=0,c,d ; String kard ; BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); try { int[] kard1=new int[100]; int[][] temp=new int[1000][100]; while(true){ kard=reader.readLine(); String suuti[]=kard.split(" "); c=Integer.parseInt(suuti[0]); kazu=Integer.parseInt(suuti[1]); if(c==0){ break ; } int e=c ; for(i=0 ; ii){ System.out.println(temp[i][0]); i++; } } catch(IOException e){ System.out.println(e); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var m : int ; var kazu : int ; var k : int ; var a : int ; var count : int ; count := 0 ; var c : int ; var d : int ; var kard : String ; var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var kard1 : Sequence(int) ; kard1 := Integer.subrange(1,100)->collect(0) ; var temp : Sequence(Sequence(int)) ; temp := Integer.subrange(1,1000)->collect(Integer.subrange(1,100)->collect(0)) ; while (true) do ( kard := reader.readLine() ; var suuti : Sequence(String) ; suuti := kard->split(" ") ; c := (suuti[0+1])->toInteger() ; kazu := (suuti[1+1])->toInteger() ; if (c = 0) then ( break ) else skip ; var e : int ; e := c ; i := 0 ; while i < c do ( ( kard1[i+1] := e ; e := e - 1 ) ; i := i + 1 ) ; m := 0 ; while m < kazu do ( ( var al : String ; al := reader.readLine() ; var suuti1 : Sequence(String) ; suuti1 := al->split(" ") ; a := (suuti1[0+1])->toInteger() ; d := (suuti1[1+1])->toInteger() ; k := 0 ; i := a - 1 ; while i < a - 1 + d do ( ( temp[count+1][k+1] := kard1[i+1] ; k := k + 1 ) ; i := i + 1 ) ; i := 0 ; while i < a - 1 do ( ( temp[count+1][k+1] := kard1[i+1] ; k := k + 1 ) ; i := i + 1 ) ; i := a + d - 1 ; while i < c do ( ( temp[count+1][k+1] := kard1[i+1] ; k := k + 1 ) ; i := i + 1 ) ; i := 0 ; while i < c do ( ( kard1[i+1] := temp[count+1][i+1] ) ; i := i + 1 ) ; ) ; m := m + 1 ) ; count := count + 1 ; ) ; i := 0 ; while (count > i) do ( OclFile["System.out"].println(temp[i+1][0+1]) ; i := i + 1 ) ; ) catch (e : IOException) do ( OclFile["System.out"].println(e) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); void work(){ for(; ; ){ int n=sc.nextInt(); int r=sc.nextInt(); if((n | r)==0){ break ; } int[] input=new int[n]; for(int i=0 ; itoInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,r)) = 0) then ( break ) else skip ; var input : Sequence(int) ; input := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( input[i+1] := n - i ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < r do ( ( var p : int ; p := sc.getCurrent()->toInteger() - 1 ; var c : int ; c := sc.getCurrent()->toInteger() ; var deck : Sequence(int) ; deck := input->copy() ; var j : int ; j := 0 ; while j < c do ( ( deck[j+1] := input[j + p+1] ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < p do ( ( deck[j + c+1] := input[j+1] ) ; j := j + 1 ) ; input := deck ; ) ; i := i + 1 ) ; OclFile["System.out"].println(input[0+1]) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var Misson_work : Main ; Misson_work := Main.newMain() ; Misson_work.work() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true){ String[] tmpArray=br.readLine().split(" "); int n=Integer.parseInt(tmpArray[0]); int r=Integer.parseInt(tmpArray[1]); if(n==0 && r==0){ break ; } int[] hanafuda=new int[n]; for(int i=0 ; isplit(" ") ; var n : int ; n := (tmpArray[0+1])->toInteger() ; var r : int ; r := (tmpArray[1+1])->toInteger() ; if (n = 0 & r = 0) then ( break ) else skip ; var hanafuda : Sequence(int) ; hanafuda := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( hanafuda[i+1] := i + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < r do ( ( tmpArray := br.readLine()->split(" ") ; var p : int ; p := (tmpArray[0+1])->toInteger() ; var c : int ; c := (tmpArray[1+1])->toInteger() ; execute shuffleDeck(hanafuda, p, c) ) ; i := i + 1 ) ; OclFile["System.out"].println(hanafuda[hanafuda->size() - 1+1]) ; ) ); static operation shuffleDeck( deck : Sequence(int), p : int, c : int) : void pre: true post: true activity: ( var tmpDeck : Sequence(int) ; tmpDeck := deck.subrange(deck->size() - p - c + 1+1,deck->size() - p + 1) ; var i : int ; i := deck->size() - p - c + 1 ; while i <= deck->size() - c - 1 do ( ( deck[i+1] := deck[i + c+1] ) ; i := i + 1 ) ; var i : int ; i := deck->size() - c ; while i < deck->size() do ( ( deck[i+1] := tmpDeck[i - deck->size() + c+1] ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.lang.*; class GFG { static int log2(int N){ int result=(int)(Math.log(N)/Math.log(2)); return result ; } static int invertBits(int num){ int x=log2(num)+1 ; for(int i=0 ; is1=new HashSet(); HashSets2=new HashSet(); for(int i=0 ; ilog() / (2)->log())->oclAsType(int) ; return result ); static operation invertBits( num : int) : int pre: true post: true activity: ( var x : int ; x := log2(num) + 1 ; var i : int ; i := 0 ; while i < x do ( num := (num xor ((1*(2->pow(i)))->oclAsType(long))) ; ; i := i + 1 ) ; return num ); static operation totalPairs( arr1 : Sequence(int), arr2 : Sequence(int), n : int, m : int) : int pre: true post: true activity: ( var s1 : Set(int) ; s1 := Set{} ; var s2 : Set(int) ; s2 := Set{} ; var i : int ; i := 0 ; while i < m do ( s2 := s2->including(arr2[i+1]) ; ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (not(s1->includes(arr1[i+1]))) then ( if (s2->includes(invertBits(arr1[i+1]))) then ( count := count + 1 ; s1 := s1->including(arr1[i+1]) ) else skip ) else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr1 : Sequence(int) ; arr1 := Sequence{43,7,1,99} ; var arr2 : Sequence(int) ; arr2 := Sequence{5,1,28,20} ; var n : int ; n := arr1->size() ; var m : int ; m := arr2->size() ; OclFile["System.out"].println(totalPairs(arr1, arr2, n, m)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); public Main(){ int t=sc.nextInt(); sc.nextLine(); for(int i=0 ; itoInteger() ; skip ; var i : int ; i := 0 ; while i < t do ( ( var len : int ; len := sc.getCurrent()->toInteger() ; skip ; var s : String ; s := sc.nextLine() ; if (s->hasPrefix("2020") or s->hasSuffix("2020") or (s->at(0+1) = '2' & s.subrange(s->size() - 3+1,s->size() - 3) = "020") or (s.subrange(0+1,3) = "202" & s->at(s->size() - 1+1) = '0') or (s.subrange(0+1,2) = "20" & s.subrange(s->size() - 2+1,s->size() - 2) = "20")) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); String s=sc.next(); boolean f=false ; f |=s.substring(0,4).equals("2020"); f |=s.substring(n-4,n).equals("2020"); f |=(s.charAt(0)+""+s.charAt(1)+""+s.charAt(n-2)+""+s.charAt(n-1)).equals("2020"); f |=(s.charAt(0)+""+s.charAt(n-3)+""+s.charAt(n-2)+""+s.charAt(n-1)).equals("2020"); f |=(s.charAt(0)+""+s.charAt(1)+""+s.charAt(2)+""+s.charAt(n-1)).equals("2020"); System.out.println(f ? "YES" : "NO"); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var f : boolean ; f := false ; f := MathLib.bitwiseOr(f, s.subrange(0+1,4) = "2020") ; f := MathLib.bitwiseOr(f, s.subrange(n - 4+1,n) = "2020") ; f := MathLib.bitwiseOr(f, (s->at(0+1) + "" + s->at(1+1) + "" + s->at(n - 2+1) + "" + s->at(n - 1+1)) = "2020") ; f := MathLib.bitwiseOr(f, (s->at(0+1) + "" + s->at(n - 3+1) + "" + s->at(n - 2+1) + "" + s->at(n - 1+1)) = "2020") ; f := MathLib.bitwiseOr(f, (s->at(0+1) + "" + s->at(1+1) + "" + s->at(2+1) + "" + s->at(n - 1+1)) = "2020") ; OclFile["System.out"].println(if f then "YES" else "NO" endif) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class LastYearSubString { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=Integer.parseInt(input.nextLine()); while(test-->0){ int len=Integer.parseInt(input.nextLine()); String fullString=input.nextLine(); len=fullString.length(); boolean changeable=false ; if(len==4){ changeable=fullString.equals("2020"); } else if(len>4){ for(int i=0 ; i<5 ; i++){ StringBuilder strb=new StringBuilder(fullString); strb.replace(i,len-4+i,""); if(strb.toString().equals("2020")){ changeable=true ; break ; } } } if(changeable){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class LastYearSubString { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := (input.nextLine())->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var len : int ; len := (input.nextLine())->toInteger() ; var fullString : String ; fullString := input.nextLine() ; len := fullString->size() ; var changeable : boolean ; changeable := false ; if (len = 4) then ( changeable := fullString = "2020" ) else if (len > 4) then ( var i : int ; i := 0 ; while i < 5 do ( ( var strb : String ; strb := StringLib.newString(fullString) ; strb.replace(i, len - 4 + i, "") ; if (strb+"" = "2020") then ( changeable := true ; break ) else skip ) ; i := i + 1 ) ) else skip ; ; if (changeable) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String srgs[]){ Scanner sc=new Scanner(System.in); int k_leftA=0 ; int k_leftB=0 ; int k_leftC=0 ; int k_leftD=0 ; int k_rightA=0 ; int k_rightB=0 ; int k_rightC=0 ; int k_rightD=0 ; while(sc.hasNext()){ double left=sc.nextDouble(); double right=sc.nextDouble(); if(1.1<=left){ k_leftA++; } else if(0.6<=left){ k_leftB++; } else if(0.2<=left){ k_leftC++; } else { k_leftD++; } if(1.1<=right){ k_rightA++; } else if(0.6<=right){ k_rightB++; } else if(0.2<=right){ k_rightC++; } else { k_rightD++; } } System.out.println(k_leftA+" "+k_rightA); System.out.println(k_leftB+" "+k_rightB); System.out.println(k_leftC+" "+k_rightC); System.out.println(k_leftD+" "+k_rightD); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( srgs : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k_leftA : int ; k_leftA := 0 ; var k_leftB : int ; k_leftB := 0 ; var k_leftC : int ; k_leftC := 0 ; var k_leftD : int ; k_leftD := 0 ; var k_rightA : int ; k_rightA := 0 ; var k_rightB : int ; k_rightB := 0 ; var k_rightC : int ; k_rightC := 0 ; var k_rightD : int ; k_rightD := 0 ; while (sc.hasNext()) do ( var left : double ; left := sc.getCurrent()->toReal() ; var right : double ; right := sc.getCurrent()->toReal() ; if (1.1 <= left) then ( k_leftA := k_leftA + 1 ) else if (0.6 <= left) then ( k_leftB := k_leftB + 1 ) else if (0.2 <= left) then ( k_leftC := k_leftC + 1 ) else ( k_leftD := k_leftD + 1 ) ; ; ; if (1.1 <= right) then ( k_rightA := k_rightA + 1 ) else if (0.6 <= right) then ( k_rightB := k_rightB + 1 ) else if (0.2 <= right) then ( k_rightC := k_rightC + 1 ) else ( k_rightD := k_rightD + 1 ) ; ; ) ; OclFile["System.out"].println(k_leftA + " " + k_rightA) ; OclFile["System.out"].println(k_leftB + " " + k_rightB) ; OclFile["System.out"].println(k_leftC + " " + k_rightC) ; OclFile["System.out"].println(k_leftD + " " + k_rightD) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; public final class p048 implements EulerSolution { public static void main(String[] args){ System.out.println(new p048().run()); } public String run(){ BigInteger modulus=BigInteger.TEN.pow(10); BigInteger sum=BigInteger.ZERO ; for(int i=1 ; i<=1000 ; i++)sum=sum.add(BigInteger.valueOf(i).modPow(BigInteger.valueOf(i),modulus)); return sum.mod(modulus).toString(); } } ------------------------------------------------------------ OCL File: --------- class p048 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p048.newp048().run()) ); operation run() : String pre: true post: true activity: ( var modulus : long ; modulus := 10.pow(10) ; var sum : long ; sum := 0 ; var i : int ; i := 1 ; while i <= 1000 do ( sum := sum->excludes((i + "")->toLong().modPow((i + "")->toLong(), modulus)) ; ; i := i + 1 ) ; return sum.mod(modulus)+"" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static int n ; public static int A[]; public static int B[]; public static int C[]=new int[10000]; public static StringBuilder sb=new StringBuilder(); public static void main(String[] args)throws NumberFormatException,IOException { Scanner scan=new Scanner(System.in); n=scan.nextInt(); A=new int[n]; B=new int[n]; for(int i=0 ; i=0 ; i--){ B[C[A[i] ]-1]=A[i]; C[A[i] ]--; } for(int i=0 ; icollect(0); static attribute sb : String := StringLib.newString(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := scan.getCurrent()->toInteger() ; A := Integer.subrange(1,n)->collect(0) ; B := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := scan.getCurrent()->toInteger() ; C[A[i+1]+1] := C[A[i+1]+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < 10000 do ( ( C[i+1] := C[i - 1+1] + C[i+1] ) ; i := i + 1 ) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( B[C[A[i+1]+1] - 1+1] := A[i+1] ; C[A[i+1]+1] := C[A[i+1]+1] - 1 ) ; i := i - 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( sb := sb + StringLib.newString(B[i+1]) ; sb := sb + StringLib.newString(" ") ) ; i := i + 1 ) ; OclFile["System.out"].println(sb+"" + B[n - 1+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GfG { static boolean isSlopeGood(double slope,int arr[],int n){ SetsetOfLines=new HashSet(); for(int i=0 ; iincluding(arr[i+1] - slope * (i)) ; ; i := i + 1 ) ; return setOfLines->size() = 2 ); static operation checkForParallel( arr : Sequence(int), n : int) : boolean pre: true post: true activity: ( var slope1 : boolean ; slope1 := isSlopeGood(arr[1+1] - arr[0+1], arr, n) ; var slope2 : boolean ; slope2 := isSlopeGood(arr[2+1] - arr[1+1], arr, n) ; var slope3 : boolean ; slope3 := isSlopeGood((arr[2+1] - arr[0+1]) / 2, arr, n) ; return (slope1 = true or slope2 = true or slope3 = true) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,6,3,8,5} ; var n : int ; n := arr->size() ; if (checkForParallel(arr, n) = true) then OclFile["System.out"].println("1") ; else OclFile["System.out"].println("0") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import com.sun.org.apache.regexp.internal.RE ; import java.util.ArrayList ; import java.util.Comparator ; import java.util.List ; import java.util.Scanner ; public class Main { void solve(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); Listrestaurants=new ArrayList<>(); for(int i=1 ; i<=N ; i++){ restaurants.add(new Restaurant(i,sc.next(),sc.nextInt())); } ComparatorrestaurantComparator=Comparator.comparing(Restaurant :: getCity).thenComparing(Restaurant :: getPoint,Comparator.reverseOrder()); restaurants.sort(restaurantComparator); for(Restaurant restaurant : restaurants){ System.out.println(restaurant.index); } } class Restaurant { int index ; String city ; int point ; String getCity(){ return city ; } int getPoint(){ return point ; } Restaurant(int index,String city,int point){ this.index=index ; this.city=city ; this.point=point ; } } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var restaurants : Sequence(Restaurant) ; restaurants := Sequence{} ; var i : int ; i := 1 ; while i <= N do ( ( restaurants := restaurants->including(Restaurant.newRestaurant(i, sc.getCurrent(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; var restaurantComparator : Function(,(,boolean)) ; restaurantComparator := Comparator.comparing(lambda _pars : OclAny in Restaurant.newRestaurant().getCity(_pars)).thenComparing(lambda _pars : OclAny in Restaurant.newRestaurant().getPoint(_pars), Comparator.reverseOrder()) ; restaurants := restaurants.sort(restaurantComparator) ; for (restaurant : restaurants) do ( ( OclFile["System.out"].println(restaurant.index) ) ) ; ); class Restaurant { attribute index : int; attribute city : String; attribute point : int; operation getCity() : String pre: true post: true activity: ( return city ); operation getPoint() : int pre: true post: true activity: ( return point ); static operation newRestaurant( index : int, city : String, point : int) : Restaurant pre: true post: true activity: ( var self : Restaurant ; self := createRestaurant(); self.initialise(index, city,point); return self ); operation initialise( index : int, city : String, point : int) : void pre: true post: true activity: ( self.index := index ; self.city := city ; self.point := point ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Restaurant implements Comparable{ String direc ; int num ; int i ; public Restaurant(String direc,int num,int i){ this.direc=direc ; this.num=num ; this.i=i ; } public int compareTo(Restaurant other){ int ans=direc.compareTo(other.direc); if(ans!=0)return ans ; return Integer.compare(other.num,num); } } public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); Listlist=new ArrayList(); int n=sc.nextInt(); for(int i=1 ; i<=n ; i++){ String direc=sc.next(); int num=sc.nextInt(); list.add(new Restaurant(direc,num,i)); } Collections.sort(list); for(Restaurant restaulant : list){ System.out.println(restaulant.i); } } } ------------------------------------------------------------ OCL File: --------- class Restaurant implements Comparable { attribute direc : String; attribute num : int; attribute i : int; static operation newRestaurant( direc : String, num : int, i : int) : Restaurant pre: true post: true activity: ( var self : Restaurant ; self := createRestaurant(); self.initialise(direc, num,i); return self ); operation initialise( direc : String, num : int, i : int) : void pre: true post: true activity: ( self.direc := direc ; self.num := num ; self.i := i ); operation compareTo( other : Restaurant) : int pre: true post: true activity: ( var ans : int ; ans := direc->compareTo(other.direc) ; if (ans /= 0) then return ans else skip ; return compare(other.num, num) ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var list : Sequence(Restaurant) ; list := Sequence{} ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( var direc : String ; direc := sc.getCurrent() ; var num : int ; num := sc.getCurrent()->toInteger() ; list := list->including(Restaurant.newRestaurant(direc, num, i)) ) ; i := i + 1 ) ; list := list->sort() ; for (restaulant : list) do ( ( OclFile["System.out"].println(restaulant.i) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import javax.crypto.Cipher ; import java.util.*; public class Main { public static void main(String args[]){ ListcityList=new ArrayList<>(); ListcityList2=new ArrayList<>(); Scanner scanner=new Scanner(System.in); try { int n=scanner.nextInt(); for(int i=0 ; i{ @ Override public int compare(City city1,City city2){ if(city1.name.compareTo(city2.name)==0)return city1.score>city2.score ?-1 : 1 ; return city1.name.compareTo(city2.name); } } class City { String name ; int score ; City(String name,int score){ this.name=name ; this.score=score ; } @ Override public boolean equals(Object o){ if(this==o)return true ; if(o==null || getClass()!=o.getClass())return false ; City city=(City)o ; return score==city.score && Objects.equals(name,city.name); } @ Override public int hashCode(){ return Objects.hash(name,score); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cityList : Sequence(City) ; cityList := Sequence{} ; var cityList2 : Sequence(City) ; cityList2 := Sequence{} ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; try ( var n : int ; n := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var city : String ; city := scanner.getCurrent() ; var score : int ; score := scanner.getCurrent()->toInteger() ; cityList := cityList->including(City.newCity(city, score)) ; cityList2 := cityList2->including(City.newCity(city, score)) ) ; i := i + 1 ) ; cityList := cityList.sort(CityComparater.newCityComparater()) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(cityList2->indexOf(cityList->at(i+1))-1 + 1) ) ; i := i + 1 ) ) catch (e : ProgramException) do ( OclFile["System.out"].println(e.getMessage()) ) finally ( skip ) ); } class CityComparater implements Function(,(,boolean)) { operation compare( city1 : City, city2 : City) : int pre: true post: true activity: ( if (city1.name->compareTo(city2.name) = 0) then return if city1.score > city2.score then -1 else 1 endif else skip ; return city1.name->compareTo(city2.name) ); } class City { attribute name : String; attribute score : int; static operation newCity( name : String, score : int) : City pre: true post: true activity: ( var self : City ; self := createCity(); self.initialise(name, score); return self ); operation initialise( name : String, score : int) : void pre: true post: true activity: ( self.name := name ; self.score := score ); operation equals( o : OclAny) : boolean pre: true post: true activity: ( if (self = o) then return true else skip ; if (o = null or getClass() /= o->oclType()) then return false else skip ; var city : City ; city := o->oclAsType(City) ; return score = city.score & Objects = name, city.name ); operation hashCode() : int pre: true post: true activity: ( return Objects.hash(name, score) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); ArrayListal=new ArrayList<>(); for(int i=1 ; i<=N ; i++){ al.add(new Person(i,sc.next(),sc.nextInt())); } al.sort(Comparator.comparing(Person :: getNum).reversed()); al.sort(Comparator.comparing(Person :: getName)); for(int i=0 ; itoInteger() ; var al : Sequence(Person) ; al := Sequence{} ; var i : int ; i := 1 ; while i <= N do ( ( al := al->including(Person.newPerson(i, sc.getCurrent(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; al := al.sort(Comparator.comparing(lambda _pars : OclAny in Person.newPerson().getNum(_pars)).reversed()) ; al := al.sort(Comparator.comparing(lambda _pars : OclAny in Person.newPerson().getName(_pars))) ; var i : int ; i := 0 ; while i < N do ( ( OclFile["System.out"].println(al->at(i+1).getId()) ) ; i := i + 1 ) ; ); } class Person { attribute id : int; attribute name : String; attribute num : int; static operation newPerson( id : int, name : String, num : int) : Person pre: true post: true activity: ( var self : Person ; self := createPerson(); self.initialise(id, name,num); return self ); operation initialise( id : int, name : String, num : int) : void pre: true post: true activity: ( self.id := id ; self.name := name ; self.num := num ); operation getId() : int pre: true post: true activity: ( return id ); operation getName() : String pre: true post: true activity: ( return name ); operation getNum() : int pre: true post: true activity: ( return num ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Comparator ; import java.util.List ; import java.util.Map ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); Map>map=new TreeMap<>(); Listorder=new ArrayList(); for(int i=0 ; iset=new ArrayList<>(); set.add(p); map.put(s,set); } } Comparatorcomparator=new Comparator(){ @ Override public int compare(Integer o1,Integer o2){ return o2-o1 ; } }; for(Listvalue : map.values()){ value.sort(comparator); for(Integer price : value){ System.out.println(order.indexOf(price)+1); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var map : Map(String,Sequence(int)) ; map := Map{} ; var order : Sequence(int) ; order := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := scanner.getCurrent() ; var p : int ; p := scanner.getCurrent()->toInteger() ; order := order->including(p) ; if (map->keys()->includes(s)) then ( map->at(s)->excludes(p) ) else ( var set : Sequence(int) ; set := Sequence{} ; set := set->including(p) ; map := map->union(Map{s |-> set}) ) ) ; i := i + 1 ) ; var comparator : Function(,(,boolean)) ; comparator := OclComparator.newOclComparator() ; for (value : map->values()) do ( ( value.sort(comparator) ; for (price : value) do ( ( OclFile["System.out"].println(order->indexOf(price)-1 + 1) ) ) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static double maxEdges(double N){ double edges=0 ; edges=Math.floor((N*N)/4); return edges ; } public static void main(String[] args){ double N=5 ; System.out.println(maxEdges(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxEdges( N : double) : double pre: true post: true activity: ( var edges : double ; edges := 0 ; edges := ((N * N) / 4)->floor() ; return edges ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : double ; N := 5 ; OclFile["System.out"].println(maxEdges(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int checkIfStartsWithVowels(char[] str){ if(!(str[0]=='A' || str[0]=='a' || str[0]=='E' || str[0]=='e' || str[0]=='I' || str[0]=='i' || str[0]=='O' || str[0]=='o' || str[0]=='U' || str[0]=='u'))return 1 ; else return 0 ; } static void check(String str){ if(checkIfStartsWithVowels(str.toCharArray())==1)System.out.print("Not Accepted\n"); else System.out.print("Accepted\n"); } public static void main(String[] args){ String str="animal" ; check(str); str="zebra" ; check(str); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkIfStartsWithVowels( str : Sequence(String)) : int pre: true post: true activity: ( if (not((str[0+1] = 'A' or str[0+1] = 'a' or str[0+1] = 'E' or str[0+1] = 'e' or str[0+1] = 'I' or str[0+1] = 'i' or str[0+1] = 'O' or str[0+1] = 'o' or str[0+1] = 'U' or str[0+1] = 'u'))) then return 1 else return 0 ); static operation check( str : String) : void pre: true post: true activity: ( if (checkIfStartsWithVowels(str->characters()) = 1) then OclFile["System.out"].print("Not Accepted\n") ; else OclFile["System.out"].print("Accepted\n") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "animal" ; execute check(str) ; str := "zebra" ; execute check(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static final int MAX=10 ; static int minSum(int arr[],int n){ int freq[]=new int[MAX]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1 ) ; i := i + 1 ) ; var k : int ; k := 0 ; var i : int ; i := 0 ; while i < MAX do ( ( var j : int ; j := 0 ; while j < freq[i+1] do ( ( arr[k+1] := i ; k := k + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var num1 : int ; num1 := 0 ; var num2 : int ; num2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (i mod 2 = 0) then num1 := num1 * MAX + arr[i+1] ; else num2 := num2 * MAX + arr[i+1] ; ) ; i := i + 1 ) ; return num1 + num2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{6,8,4,5,2,3} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(minSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.HashMap ; public class Main { static final int LEFT=0 ; static final int RIGHT=1 ; static final double[] eyeTable={ 1.1,0.6,0.2 }; static int[][] numEye=new int[2][4]; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String buf=null ; while((buf=br.readLine())!=null){ String[] eye=buf.split(" "); String leftEyeClass=judgeEye(Double.parseDouble(eye[LEFT])); String rightEyeClass=judgeEye(Double.parseDouble(eye[RIGHT])); updateData(leftEyeClass,LEFT); updateData(rightEyeClass,RIGHT); } for(int i=0 ; i=eyeTable[i]){ eyeClass=(char)((int)'A'+i); break ; } } return String.valueOf(eyeClass); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute LEFT : int := 0; static attribute RIGHT : int := 1; static attribute eyeTable : Sequence(double) := Sequence{1.1,0.6,0.2}; static attribute numEye : Sequence(Sequence(int)) := Integer.subrange(1,2)->collect(Integer.subrange(1,4)->collect(0)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var buf : String ; buf := null ; buf := br.readLine() ; while ((buf) /= null) do ( skip ; ( var eye : Sequence(String) ; eye := buf->split(" ") ; var leftEyeClass : String ; leftEyeClass := judgeEye((eye[LEFT+1])->toReal()) ; var rightEyeClass : String ; rightEyeClass := judgeEye((eye[RIGHT+1])->toReal()) ; execute updateData(leftEyeClass, LEFT) ; execute updateData(rightEyeClass, RIGHT) ; ) ; buf := br.readLine() ; ) ; var i : int ; i := 0 ; while i < numEye[0+1]->size() do ( ( OclFile["System.out"].println(numEye[LEFT+1][i+1] + " " + numEye[RIGHT+1][i+1]) ) ; i := i + 1 ) ); static operation updateData( eye : String, side : int) : void pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (eye->at(0+1)) ; if _switchval = 'A' then numEye[side+1][0+1] := numEye[side+1][0+1] + 1 ; break else skip ; if _switchval = 'B' then numEye[side+1][1+1] := numEye[side+1][1+1] + 1 ; break else skip ; if _switchval = 'C' then numEye[side+1][2+1] := numEye[side+1][2+1] + 1 ; break else skip ; if _switchval = 'D' then numEye[side+1][3+1] := numEye[side+1][3+1] + 1 ; break else skip ; if true then ) ); static operation judgeEye( eye : double) : String pre: true post: true activity: ( var eyeClass : String ; eyeClass := 'D' ; var i : int ; i := 0 ; while i < eyeTable->size() do ( ( if (eye >= eyeTable[i+1]) then ( eyeClass := (('A')->char2byte() + i)->oclAsType(String) ; break ) else skip ) ; i := i + 1 ) ; return ((eyeClass) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class Main { public static void main(String[] args){ InputStream stream=System.in ; InputReader input=new InputReader(stream); int N=input.nextInt(); int[] A=new int[N+1]; int[] B=new int[N+1]; for(int i=0 ; i=0 ; j--){ B[C[A[j] ] ]=A[j]; C[A[j] ]--; } } } class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stream : OclFile ; stream := OclFile["System.in"] ; var input : InputReader ; input := InputReader.newInputReader(stream) ; var N : int ; N := input.nextInt() ; var A : Sequence(int) ; A := Integer.subrange(1,N + 1)->collect(0) ; var B : Sequence(int) ; B := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i + 1+1] := input.nextInt() ) ; i := i + 1 ) ; execute CountingSort(A, B, 20000) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var i : int ; i := 1 ; while i < N do ( ( skip ) ; i := i + 1 ) ; skip ; skip ; skip ; ); static operation CountingSort( A : Sequence(int), B : Sequence(int), k : int) : void pre: true post: true activity: ( var C : Sequence(int) ; C := Integer.subrange(1,k + 1)->collect(0) ; var j : int ; j := 1 ; while j < A->size() do ( ( C[A[j+1]+1] := C[A[j+1]+1] + 1 ) ; j := j + 1 ) ; var i : int ; i := 1 ; while i <= k do ( ( C[i+1] := C[i+1]+(C[i - 1+1]) ) ; i := i + 1 ) ; var j : int ; j := A->size() - 1 ; while j >= 0 do ( ( B[C[A[j+1]+1]+1] := A[j+1] ; C[A[j+1]+1] := C[A[j+1]+1] - 1 ) ; j := j - 1 ) ); } class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { private void doit(){ Scanner sc=new Scanner(System.in); int da=sc.nextInt(); while(da-->0){ long n=sc.nextLong(); int count=0 ; long max=n ; while(true){ if(max<10){ System.out.println(count); break ; } max=solve(max); if(max>=n){ System.out.println(-1); break ; } count++; } } } private int solve(Long num){ String n=""+num ; int max=0 ; for(int i=1 ; itoInteger() ; while (da > 0) do ( da := da - 1 ; skip ; ( var n : long ; n := sc.getCurrent()->toLong() ; var count : int ; count := 0 ; var max : long ; max := n ; while (true) do ( if (max < 10) then ( OclFile["System.out"].println(count) ; break ) else skip ; max := solve(max) ; if (max >= n) then ( OclFile["System.out"].println(-1) ; break ) else skip ; count := count + 1 ) ) ; ) ); operation solve( num : long) : int pre: true post: true activity: ( var n : String ; n := "" + num ; var max : int ; max := 0 ; var i : int ; i := 1 ; while i < n->size() do ( ( var left : int ; left := (n.subrange(0+1,i))->toInteger() ; var right : int ; right := (n.subrange(i+1,i))->toInteger() ; var res : int ; res := left * right ; max := Set{max, res}->max() ) ; i := i + 1 ) ; return max ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : Main ; obj := Main.newMain() ; obj.doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String args[]){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { int count=Integer.parseInt(br.readLine()); int number[]=new int[count]; int result[]=new int[count]; for(int i=0 ; itoInteger() ; var number : Sequence(int) ; number := Integer.subrange(1,count)->collect(0) ; var result : Sequence(int) ; result := Integer.subrange(1,count)->collect(0) ; var i : int ; i := 0 ; while i < count do ( ( var s : String ; s := br.readLine() ; number[i+1] := (s)->toInteger() ; while (true) do ( if (number[i+1] < 10) then break else skip ; s := ((number[i+1]) + "") ; var two : Sequence(int) ; two := Integer.subrange(1,s->size() - 1)->collect(0) ; var max : int ; max := 0 ; var j : int ; j := 0 ; while j < s->size() - 1 do ( ( var s1 : String ; s1 := s.subrange(0+1,j + 1) ; var s2 : String ; s2 := s.subrange(j + 1+1,s->size()) ; two[j+1] := (s1)->toInteger() * (s2)->toInteger() ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < two->size() do ( ( max := Set{max, two[j+1]}->max() ) ; j := j + 1 ) ; number[i+1] := max ; result[i+1] := result[i+1] + 1 ; ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < count do ( ( OclFile["System.out"].println(result[i+1]) ) ; i := i + 1 ) ; skip ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { static ArrayListmultipliedMaxNums ; static int numOfExe ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int q=sc.nextInt(); for(int i=0 ; i(); numOfExe=0 ; solve(num); System.out.println(numOfExe); } sc.close(); } public static void solve(String num){ if(num.length()==1){ } else { secondExe(num); } } public static void secondExe(String num){ int digitNumber=num.length(); int max=0 ; for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < q do ( ( var num : String ; num := sc.getCurrent() ; multipliedMaxNums := Sequence{} ; numOfExe := 0 ; execute solve(num) ; OclFile["System.out"].println(numOfExe) ; ) ; i := i + 1 ) ; skip ); static operation solve( num : String) : void pre: true post: true activity: ( if (num->size() = 1) then skip else ( execute secondExe(num) ) ); static operation secondExe( num : String) : void pre: true post: true activity: ( var digitNumber : int ; digitNumber := num->size() ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < (digitNumber)->char2byte() - 1 do ( ( var multipledNum : int ; multipledNum := (num.subrange(0+1,(i + 1)))->toInteger() * (num.subrange((i + 1)+1,digitNumber))->toInteger() ; if (max < multipledNum) then ( max := multipledNum ) else skip ) ; i := i + 1 ) ; if (multipliedMaxNums->includes(max)) then ( numOfExe := -1 ) else ( numOfExe := numOfExe + 1 ; multipliedMaxNums := multipliedMaxNums->including(max) ; execute solve(((max) + "")) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,nl,nr,i,j,max,q,count,d ; int[] c ; String s ; for(q=sc.nextInt(); q-->0 ; out.println(count)){ n=sc.nextInt(); max=0 ; for(count=-1 ; max!=-1 ; count++){ d=caldig(n); j=10 ; max=-1 ; for(i=1 ; i 0 do ( ( n := sc.nextInt() ; max := 0 ; count := -1 ; while max /= -1 do ( ( d := caldig(n) ; j := 10 ; max := -1 ; i := 1 ; while i < d do ( ( nr := n mod j ; nl := n / j ; if (max < nr * nl) then max := nr * nl ; else skip ; j := j*(10) ) ; i := i + 1 ) ; n := max ; ) ; count := count + 1 ) ) ; out.println(count) ) ; sc.close() ; ); static operation caldig( n : int) : int pre: true post: true activity: ( var i : int ; i := 1 ; while i < 10 do ( ( if (n / 10 = 0) then return i else skip ; n := n / 10 ) ; i := i + 1 ) ; return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=Integer.parseInt(sc.next()); long m=Integer.parseInt(sc.next()); long ret=0 ; if(n>1 && m>1){ ret=(n-2)*(m-2); } else if(n==1 && m==1){ ret=1 ; } else { ret=Math.max(n,m)-2 ; } System.out.println(ret); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := (sc.getCurrent())->toInteger() ; var m : long ; m := (sc.getCurrent())->toInteger() ; var ret : long ; ret := 0 ; if (n > 1 & m > 1) then ( ret := (n - 2) * (m - 2) ) else if (n = 1 & m = 1) then ( ret := 1 ) else ( ret := Set{n, m}->max() - 2 ) ; ; OclFile["System.out"].println(ret) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long N=sc.nextLong(); long M=sc.nextLong(); long answer=(Math.abs(N-2))*(Math.abs(M-2)); System.out.println(answer); } static int gcd(int a,int b){ return b>0 ? gcd(b,a % b): a ; } static int lcm(int a,int b){ return a*b/gcd(a,b); } static boolean isPrime(int n){ if(n==2)return true ; if(n<2 || n % 2==0)return false ; double d=Math.sqrt(n); for(int i=3 ; i<=d ; i+=2)if(n % i==0){ return false ; } return true ; } static boolean isMultiple(String s,int base,int m){ int temp=0 ; for(int i=0 ; itoLong() ; var M : long ; M := sc.getCurrent()->toLong() ; var answer : long ; answer := (if N - 2 < 0 then -(N - 2) else N - 2 endif) * (if M - 2 < 0 then -(M - 2) else M - 2 endif) ; OclFile["System.out"].println(answer) ; ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if b > 0 then gcd(b, a mod b) else a endif ); static operation lcm( a : int, b : int) : int pre: true post: true activity: ( return a * b / gcd(a, b) ); static operation isPrime( n : int) : boolean pre: true post: true activity: ( if (n = 2) then return true else skip ; if (n < 2 or n mod 2 = 0) then return false else skip ; var d : double ; d := (n)->sqrt() ; var i : int ; i := 3 ; while i <= d do ( if (n mod i = 0) then ( return false ) else skip ; ; i := i+(2) ) ; return true ); static operation isMultiple( s : String, base : int, m : int) : boolean pre: true post: true activity: ( var temp : int ; temp := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( temp := (temp * base + ("" + s->at(i+1))->toInteger()) mod m ) ; i := i + 1 ) ; if (temp = 0) then ( return true ) else skip ; return false ); static operation factorial( i : int) : long pre: true post: true activity: ( if (i = 1) then ( return 1 ) else ( return i * factorial(i - 1) ) ); static operation toNbase( sm : String, m : int, n : int) : String pre: true post: true activity: ( return (((sm)->toLong()) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.BigInteger ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); long n=sc.nextInt(); long m=sc.nextInt(); if(n<2 || m<2){ if(n==1 && m==1){ System.out.println(1); } else { long l=Math.max(n,m); System.out.println(l-2); } } else { BigInteger bign=new BigInteger("0"); BigInteger bigm=new BigInteger("0"); BigInteger ans=new BigInteger("0"); bign=BigInteger.valueOf(n-2); bigm=BigInteger.valueOf(m-2); ans=bign.multiply(bigm); System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toInteger() ; var m : long ; m := sc.getCurrent()->toInteger() ; if (n < 2 or m < 2) then ( if (n = 1 & m = 1) then ( OclFile["System.out"].println(1) ) else ( var l : long ; l := Set{n, m}->max() ; OclFile["System.out"].println(l - 2) ) ) else ( var bign : long ; bign := long("0") ; var bigm : long ; bigm := long("0") ; var ans : long ; ans := long("0") ; bign := (n - 2 + "")->toLong() ; bigm := (m - 2 + "")->toLong() ; ans := bign.multiply(bigm) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner stdin=new Scanner(System.in); long row=stdin.nextLong()-2 ; long column=stdin.nextLong()-2 ; System.out.println(Math.abs(row*column)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdin : OclFile ; stdin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var row : long ; row := stdin.getCurrent()->toLong() - 2 ; var column : long ; column := stdin.getCurrent()->toLong() - 2 ; OclFile["System.out"].println(if row * column < 0 then -(row * column) else row * column endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long N=sc.nextLong(); long M=sc.nextLong(); long ans=0 ; if(N==1){ if(M==1){ ans=1 ; } else if(M==2){ ans=0 ; } else { ans=M-2 ; } } else if(N==2){ if(M==1){ ans=0 ; } else if(M==2){ ans=0 ; } else { ans=0 ; } } else { if(M==1){ ans=N-2 ; } else if(M==2){ ans=0 ; } else { ans=(N-2)*(M-2); } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := sc.getCurrent()->toLong() ; var M : long ; M := sc.getCurrent()->toLong() ; var ans : long ; ans := 0 ; if (N = 1) then ( if (M = 1) then ( ans := 1 ) else if (M = 2) then ( ans := 0 ) else ( ans := M - 2 ) ; ) else if (N = 2) then ( if (M = 1) then ( ans := 0 ) else if (M = 2) then ( ans := 0 ) else ( ans := 0 ) ; ) else ( if (M = 1) then ( ans := N - 2 ) else if (M = 2) then ( ans := 0 ) else ( ans := (N - 2) * (M - 2) ) ; ) ; ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int findNum(int div[],int rem[],int N){ int num=rem[N-1]; for(int i=N-2 ; i>=0 ; i--){ num=num*div[i]+rem[i]; } return num ; } public static void main(String[] args){ int div[]={ 8,3 }; int rem[]={ 2,2 }; int N=div.length ; System.out.println(findNum(div,rem,N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findNum( div : Sequence(int), rem : Sequence(int), N : int) : int pre: true post: true activity: ( var num : int ; num := rem[N - 1+1] ; var i : int ; i := N - 2 ; while i >= 0 do ( ( num := num * div[i+1] + rem[i+1] ) ; i := i - 1 ) ; return num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var div : Sequence(int) ; div := Sequence{8,3} ; var rem : Sequence(int) ; rem := Sequence{2,2} ; var N : int ; N := div->size() ; OclFile["System.out"].println(findNum(div, rem, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.OptionalInt ; import java.util.regex.Pattern ; import java.util.stream.Stream ; public class Main { public static void main(String[] args){ new Main().run(); } public void run(){ try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ int n=Integer.parseInt(br.readLine()); String line=br.readLine(); final Pattern delim=Pattern.compile(" "); int[] arrayS=delim.splitAsStream(line).parallel().mapToInt(Integer :: parseInt).toArray(); OptionalInt max=Arrays.stream(arrayS).max(); dispIntArray(countingSort(arrayS,max.getAsInt())); } catch(IOException e){ System.out.println("IOException!"); } } public int[] countingSort(int[] a,int k){ int aLength=a.length ; int[] result=new int[aLength]; int[] counter=new int[k+1]; for(int var : a){ counter[var]++; } for(int i=1,max=k+1 ; i=0 ; i--){ val=a[i]; result[counter[val]-1]=val ; counter[val]--; } return result ; } public void dispIntArray(int[] target){ StringBuilder s=new StringBuilder(); for(int i : target){ s.append(i).append(" "); } s.setLength(s.length()-1); System.out.println(s); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var n : int ; n := (br.readLine())->toInteger() ; var line : String ; line := br.readLine() ; var delim : OclRegex ; delim := OclRegex.compile(" ") ; var arrayS : Sequence(int) ; arrayS := delim.splitAsStream(line)->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ; var max : OptionalInt ; max := stream(arrayS).max() ; execute dispIntArray(countingSort(arrayS, max.getAsInt())) ; )) catch (e : IOException) do ( OclFile["System.out"].println("IOException!") ) ); operation countingSort( a : Sequence(int), k : int) : Sequence(int) pre: true post: true activity: ( var aLength : int ; aLength := a->size() ; var result : Sequence(int) ; result := Integer.subrange(1,aLength)->collect(0) ; var counter : Sequence(int) ; counter := Integer.subrange(1,k + 1)->collect(0) ; for (var : a) do ( ( counter[var+1] := counter[var+1] + 1 ) ) ; var i : int ; i := 1 ; var max : int ; max := k + 1 ; while i < max do ( ( counter[i+1] := counter[i+1]+(counter[i - 1+1]) ) ; i := i + 1 ) ; var i : int ; i := aLength - 1 ; var val : int ; val := 0 ; while i >= 0 do ( ( val := a[i+1] ; result[counter[val+1] - 1+1] := val ; counter[val+1] := counter[val+1] - 1 ) ; i := i - 1 ) ; return result ); operation dispIntArray( target : Sequence(int)) : void pre: true post: true activity: ( var s : String ; s := StringLib.newString() ; for (i : target) do ( ( s := s + StringLib.newString(i) + StringLib.newString(" ") ) ) ; s := s.subrange(1,s->size() - 1) ; OclFile["System.out"].println(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { static double e=0.0000000001 ; public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); double a,b ; int[] l,r ; int i ; l=new int[4]; r=new int[4]; for(; sc.hasNext(); ){ a=sc.nextDouble(); b=sc.nextDouble(); if(a>=1.1-e)l[0]++; else if(a>=0.6-e)l[1]++; else if(a>=0.2-e)l[2]++; else l[3]++; if(b>=1.1-e)r[0]++; else if(b>=0.6-e)r[1]++; else if(b>=0.2-e)r[2]++; else r[3]++; } for(i=0 ; i<4 ; i++)out.println(l[i]+" "+r[i]); sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute e : double := 0.0000000001; operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var a : double ; var b : double ; var l : Sequence(int) ; var r : Sequence(int) ; var i : int ; l := Integer.subrange(1,4)->collect(0) ; r := Integer.subrange(1,4)->collect(0) ; while sc.hasNext() do ( ( a := sc.nextDouble() ; b := sc.nextDouble() ; if (a >= 1.1 - e) then l[0+1] := l[0+1] + 1 else if (a >= 0.6 - e) then l[1+1] := l[1+1] + 1 else if (a >= 0.2 - e) then l[2+1] := l[2+1] + 1 else l[3+1] := l[3+1] + 1 ; ; ; ; if (b >= 1.1 - e) then r[0+1] := r[0+1] + 1 ; else if (b >= 0.6 - e) then r[1+1] := r[1+1] + 1 else if (b >= 0.2 - e) then r[2+1] := r[2+1] + 1 else r[3+1] := r[3+1] + 1 ; ; ; ) ) ; i := 0 ; while i < 4 do ( out.println(l[i+1] + " " + r[i+1]) ; ; i := i + 1 ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Random ; public class ReservoirSampling { static void selectKItems(int stream[],int n,int k){ int i ; int reservoir[]=new int[k]; for(i=0 ; icollect(0) ; i := 0 ; while i < k do ( reservoir[i+1] := stream[i+1] ; ; i := i + 1 ) ; var r : OclRandom ; r := OclRandom.newOclRandom() ; while i < n do ( ( var j : int ; j := r.nextInt(i + 1) ; if (j < k) then reservoir[j+1] := stream[i+1] ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Following are k randomly selected items") ; OclFile["System.out"].println((reservoir + "")) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stream : Sequence(int) ; stream := Sequence{1,2,3,4,5,6,7,8,9,10,11,12} ; var n : int ; n := stream->size() ; var k : int ; k := 5 ; execute selectKItems(stream, n, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int CenteredDodecahedral_num(int n){ return(2*n+1)*(5*n*n+5*n+1); } public static void main(String[] args){ int n=3 ; System.out.print(n+"th Centered "+"Dodecahedral number : "); System.out.println(CenteredDodecahedral_num(n)); n=10 ; System.out.print(n+"th Centered "+"Dodecahedral number : "); System.out.println(CenteredDodecahedral_num(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation CenteredDodecahedral_num( n : int) : int pre: true post: true activity: ( return (2 * n + 1) * (5 * n * n + 5 * n + 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].print(n + "th Centered " + "Dodecahedral number : ") ; OclFile["System.out"].println(CenteredDodecahedral_num(n)) ; n := 10 ; OclFile["System.out"].print(n + "th Centered " + "Dodecahedral number : ") ; OclFile["System.out"].println(CenteredDodecahedral_num(n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] a=new long[n]; long b=0 ; long b2=0 ; long sum=0 ; long sum2=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var b : long ; b := 0 ; var b2 : long ; b2 := 0 ; var sum : long ; sum := 0 ; var sum2 : long ; sum2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() - (i + 1) ) ; i := i + 1 ) ; a := a->sort() ; if (n mod 2 = 0) then ( b := (a[n / 2+1] + a[n / 2 - 1+1]) / 2 ; b2 := b + 1 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(if a[i+1] - b < 0 then -(a[i+1] - b) else a[i+1] - b endif) ; sum2 := sum2+(if a[i+1] - b2 < 0 then -(a[i+1] - b2) else a[i+1] - b2 endif) ) ; i := i + 1 ) ; sum := Set{sum, sum2}->min() ) else ( b := a[(n + 1) / 2 - 1+1] ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(if a[i+1] - b < 0 then -(a[i+1] - b) else a[i+1] - b endif) ) ; i := i + 1 ) ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { Reader r=new Reader(); int N=r.i(); long[] A=r.ll(); for(int i=0 ; isort() ; var ans : long ; ans := 0 ; var median : long ; median := A[N / 2+1] ; var i : int ; i := 0 ; while i < N do ( ans := ans+(if median - A[i+1] < 0 then -(median - A[i+1]) else median - A[i+1] endif) ; ; i := i + 1 ) ; execute print(ans) ; ); static operation print( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o+"") ); static class Reader extends OclFile { static operation newReader() : Reader pre: true post: true activity: ( var self : Reader ; self := createReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute super(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation s() : String pre: true post: true activity: ( return readLine() ); operation ss() : Sequence(String) pre: true post: true activity: ( return s()->split(" ") ); operation Int( s : String) : int pre: true post: true activity: ( return (s)->toInteger() ); operation i() : int pre: true post: true activity: ( return Int(s()) ); operation ii() : Sequence(int) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var size : int ; size := ss->size() ; var ii : Sequence(int) ; ii := Integer.subrange(1,size)->collect(0) ; var j : int ; j := 0 ; while j < size do ( ii[j+1] := Int(ss[j+1]) ; ; j := j + 1 ) ; return ii ); operation Long( s : String) : long pre: true post: true activity: ( return (s)->toLong() ); operation l() : long pre: true post: true activity: ( return Long(s()) ); operation ll() : Sequence(long) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var size : int ; size := ss->size() ; var ll : Sequence(long) ; ll := Integer.subrange(1,size)->collect(0) ; var j : int ; j := 0 ; while j < size do ( ll[j+1] := Long(ss[j+1]) ; ; j := j + 1 ) ; return ll ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Scanner ; public final class Main { public static void main(String[] args){ final Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); final int n=Integer.parseInt(in.nextLine()); final int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := in.getCurrent()->toInteger() ; arr[i+1] := arr[i+1]-(i + 1) ) ; i := i + 1 ) ; skip ; arr := arr->sort() ; OclFile["System.out"].println(f(arr, arr[n / 2+1])) ; ); static operation f( arr : Sequence(int), median : int) : long pre: true post: true activity: ( var res : long ; res := 0 ; for (value : arr) do ( ( res := res+(if value - median < 0 then -(value - median) else value - median endif) ) ) ; return res ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.Collectors ; import java.io.*; import java.nio.charset.StandardCharsets ; public class Main { public static void main(String[] args)throws IOException { InputStreamReader reader=new InputStreamReader(System.in,StandardCharsets.UTF_8); BufferedReader in=new BufferedReader(reader); Main ins=new Main(in); ins.calc(); ins.showResult(); } int N ; long[] A ; Main(BufferedReader in)throws IOException { N=Integer.parseInt(in.readLine()); A=new long[N]; String[] tokens=in.readLine().split(" "); for(int i=0 ; itoInteger() ; A := Integer.subrange(1,N)->collect(0) ; var tokens : Sequence(String) ; tokens := in.readLine()->split(" ") ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := (tokens[i+1])->toLong() - (i + 1)->oclAsType(long) ) ; i := i + 1 ) ; A := A->sort() ; var med : long ; med := getMedium() ; var result : long ; result := "9223372036854775807"->toLong() / 2 ; var b : long ; b := med - 5 ; while b <= med + 5 do ( ( result := Set{result, sub(b)}->min() ) ; b := b + 1 ) ; OclFile["System.out"].println(result) ; ); operation getMedium() : long pre: true post: true activity: ( if (A->size() = 1) then ( return A[0+1] ) else if (A->size() mod 2 = 1) then ( return A[A->size() / 2+1] ) else ( return (A[A->size() / 2 - 1+1] + A[A->size() / 2+1]) / 2 ) ; ); operation sub( b : long) : long pre: true post: true activity: ( var result : long ; result := 0 ; var i : int ; i := 0 ; while i < N do ( ( result := result+(if A[i+1] - b < 0 then -(A[i+1] - b) else A[i+1] - b endif) ) ; i := i + 1 ) ; return result ); operation calc() : void pre: true post: true activity: skip; operation showResult() : void pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ int N=in.nextInt(); int[] A=new int[N]; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < A->size() do ( ( A[i+1] := in.getCurrent()->toInteger() - (i + 1) ) ; i := i + 1 ) ; A := A->sort() ; var mid : int ; mid := A[A->size() / 2+1] ; if (A->size() mod 2 = 0) then ( mid := (mid + A[A->size() / 2 - 1+1]) / 2 ) else skip ; var minSadVal : long ; minSadVal := 0 ; var i : int ; i := 0 ; while i < A->size() do ( ( minSadVal := minSadVal+(if A[i+1] - mid < 0 then -(A[i+1] - mid) else A[i+1] - mid endif) ) ; i := i + 1 ) ; OclFile["System.out"].println(minSadVal) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int MOD=1000000007 ; int n=sc.nextInt(); int k=sc.nextInt(); for(int i=1 ; i<=k ; i++){ if(n-k+1n-k)return nCkMOD(n,n-k,mod); long res=1 ; for(int i=0 ; i0){ if(n % 2==1)res=(res*a)% mod ; a=(a*a)% mod ; n>>=1 ; } return res % mod ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var MOD : int ; MOD := 1000000007 ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= k do ( ( if (n - k + 1 < i) then ( OclFile["System.out"].println(0) ; continue ) else skip ; OclFile["System.out"].println(nCkMOD(n - k + 1, i, MOD) * nCkMOD(k - 1, i - 1, MOD) mod MOD) ) ; i := i + 1 ) ; ); static operation nCkMOD( n : long, k : long, mod : long) : long pre: true post: true activity: ( if (k > n - k) then return nCkMOD(n, n - k, mod) else skip ; var res : long ; res := 1 ; var i : int ; i := 0 ; while i < k do ( ( res := (res * (n - i)) mod mod ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= k do ( ( res := (res * inverse(i, mod)) mod mod ) ; i := i + 1 ) ; return res mod mod ); static operation inverse( a : long, mod : long) : long pre: true post: true activity: ( return modpow(a, mod - 2, mod) ); static operation modpow( a : long, n : long, mod : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (n > 0) do ( if (n mod 2 = 1) then res := (res * a) mod mod ; else skip ; a := (a * a) mod mod ; n := n/(2->pow(1)) ) ; return res mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws Exception { Scanner sch=new Scanner(System.in); int q=sch.nextInt(); int[] B=countingpaixu(q,sch); StringBuilder af=new StringBuilder(""); af.append(B[0]); for(int i=1 ; ik){ k=A[i]; } } int[] P=new int[A.length]; int i ; int[] C=new int[k+1]; for(i=0 ; i=0 ; i--){ P[C[A[i] ]-1]=A[i]; C[A[i] ]--; } return P ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sch : OclFile ; sch := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := sch.getCurrent()->toInteger() ; var B : Sequence(int) ; B := countingpaixu(q, sch) ; var af : String ; af := StringLib.newString("") ; af := af + StringLib.newString(B[0+1]) ; var i : int ; i := 1 ; while i < B->size() do ( ( af := af + StringLib.newString(" ") + StringLib.newString(B[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(af) ; ); static operation countingpaixu( n : int, aj : OclFile) : Sequence(int) pre: true post: true activity: ( var k : int ; k := 0 ; var A : Sequence(int) ; A := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := aj.nextInt() ; if (A[i+1] > k) then ( k := A[i+1] ) else skip ) ; i := i + 1 ) ; var P : Sequence(int) ; P := Integer.subrange(1,A->size())->collect(0) ; var i : int ; var C : Sequence(int) ; C := Integer.subrange(1,k + 1)->collect(0) ; i := 0 ; while i < A->size() do ( ( C[A[i+1]+1] := C[A[i+1]+1] + 1 ) ; i := i + 1 ) ; i := 1 ; while i <= k do ( ( C[i+1] := C[i+1]+(C[(i)->char2byte() - 1+1]) ) ; i := i + 1 ) ; i := A->size() - 1 ; while i >= 0 do ( ( P[C[A[i+1]+1] - 1+1] := A[i+1] ; C[A[i+1]+1] := C[A[i+1]+1] - 1 ) ; i := i - 1 ) ; return P ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int[][] lenearsum(int numval,int sum){ int sep=(int)Math.pow(10,9)+7 ; int[][] dp=new int[numval+1][sum+1]; for(int i=0 ; ipow(9)->oclAsType(int) + 7 ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,numval + 1)->collect(Integer.subrange(1,sum + 1)->collect(0)) ; var i : int ; i := 0 ; while i < sum + 1 do ( ( dp[1+1][i+1] := 1 ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i < numval + 1 do ( ( var n : int ; n := 0 ; while n < sum + 1 do ( ( if (n = 0) then dp[i+1][n+1] := 1 ; else dp[i+1][n+1] := ((dp[i+1][n - 1+1]) mod sep + (dp[i - 1+1][n+1]) mod sep) mod sep ; ) ; n := n + 1 ) ) ; i := i + 1 ) ; return dp ); static operation calci( K : int, N : int, i : int, dp : Sequence(Sequence(int))) : void pre: true post: true activity: ( var sep : int ; sep := 10->pow(9)->oclAsType(int) + 7 ; if (N - K - (i - 1) < 0) then ( OclFile["System.out"].println(0) ; return ) else skip ; var ret : long ; ret := 1 ; ret := ret*(dp[i+1][K - i+1]) ; ret := ret mod sep ; ret := ret*(dp[i + 1+1][N - K - (i - 1)+1]) ; ret := ret mod sep ; OclFile["System.out"].println(ret) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := lenearsum(k + 1, n + 1) ; var i : int ; i := 1 ; while i <= k do ( ( execute calci(k, n, i, dp) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public void solve()throws IOException { int[][] result=new int[4][2]; while(stdIn.hasNext()){ double[] eye=new double[2]; for(int i=0 ; i<2 ; i++){ eye[i]=stdIn.nextDouble(); if(eye[i]>=1.1){ result[0][i]++; } else if(eye[i]>=0.6){ result[1][i]++; } else if(eye[i]>=0.2){ result[2][i]++; } else { result[3][i]++; } } } for(int[] x : result){ writer.println(x[0]+" "+x[1]); } writer.flush(); } public static void main(String args[])throws IOException { new Main().run(); } Scanner stdIn ; PrintWriter writer ; public void run()throws IOException { stdIn=null ; try { stdIn=new Scanner(new BufferedReader(new InputStreamReader(System.in))); writer=new PrintWriter(System.out); solve(); stdIn.close(); writer.close(); } catch(Exception e){ e.printStackTrace(); System.exit(1); } } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var result : Sequence(Sequence(int)) ; result := Integer.subrange(1,4)->collect(Integer.subrange(1,2)->collect(0)) ; while (stdIn.hasNext()) do ( var eye : Sequence(double) ; eye := Integer.subrange(1,2)->collect(0.0) ; var i : int ; i := 0 ; while i < 2 do ( ( eye[i+1] := stdIn.nextDouble() ; if (eye[i+1] >= 1.1) then ( result[0+1][i+1] := result[0+1][i+1] + 1 ) else if (eye[i+1] >= 0.6) then ( result[1+1][i+1] := result[1+1][i+1] + 1 ) else if (eye[i+1] >= 0.2) then ( result[2+1][i+1] := result[2+1][i+1] + 1 ) else ( result[3+1][i+1] := result[3+1][i+1] + 1 ) ; ; ) ; i := i + 1 ) ) ; for (x : result) do ( ( writer.println(x[0+1] + " " + x[1+1]) ) ) ; writer.flush() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute stdIn : OclFile; attribute writer : OclFile; operation run() : void pre: true post: true activity: ( stdIn := null ; try ( stdIn := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; writer := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ; skip ; ) catch (e : ProgramException) do ( e.printStackTrace() ; OclProcess.exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static int mod=1_000_000_007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); int K=Integer.parseInt(sc.next()); int cnt=N-K+1 ; for(int i=1 ; i<=K ; i++){ if(cnt>0){ System.out.println(nCr(N-K+1,i)*nCr(K-1,i-1)% mod); } else { System.out.println(0); } cnt--; } } public static long factorial(int n){ long tmp=1 ; for(int i=n ; i>0 ; i--){ tmp=(tmp*i)% mod ; } return tmp ; } public static long pow(long a,int n){ long res=1 ; while(n>0){ if((n-n/2*2)==1){ res=(res*a)% mod ; } a=(a*a)% mod ; n>>=1 ; } return res ; } public static long modinv(long n){ return pow(n,mod-2); } public static long nCr(int n,int r){ return factorial(n)*modinv(factorial(n-r))% mod*modinv(factorial(r))% mod ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute mod : int := 1_000_000_007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := (sc.getCurrent())->toInteger() ; var K : int ; K := (sc.getCurrent())->toInteger() ; var cnt : int ; cnt := N - K + 1 ; var i : int ; i := 1 ; while i <= K do ( ( if (cnt > 0) then ( OclFile["System.out"].println(nCr(N - K + 1, i) * nCr(K - 1, i - 1) mod mod) ) else ( OclFile["System.out"].println(0) ) ; cnt := cnt - 1 ) ; i := i + 1 ) ; ); static operation factorial( n : int) : long pre: true post: true activity: ( var tmp : long ; tmp := 1 ; var i : int ; i := n ; while i > 0 do ( ( tmp := (tmp * i) mod mod ) ; i := i - 1 ) ; return tmp ); static operation pow( a : long, n : int) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (n > 0) do ( if ((n - n / 2 * 2) = 1) then ( res := (res * a) mod mod ) else skip ; a := (a * a) mod mod ; n := n/(2->pow(1)) ) ; return res ); static operation modinv( n : long) : long pre: true post: true activity: ( return pow(n, mod - 2) ); static operation nCr( n : int, r : int) : long pre: true post: true activity: ( return factorial(n) * modinv(factorial(n - r)) mod mod * modinv(factorial(r)) mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static long minPerimeter(int n){ int l=(int)Math.sqrt(n); int sq=l*l ; if(sq==n)return l*4 ; else { long row=n/l ; long perimeter=2*(l+row); if(n % l!=0)perimeter+=2 ; return perimeter ; } } public static void main(String[] args){ int n=10 ; System.out.println(minPerimeter(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minPerimeter( n : int) : long pre: true post: true activity: ( var l : int ; l := (n)->sqrt()->oclAsType(int) ; var sq : int ; sq := l * l ; if (sq = n) then return l * 4 else ( var row : long ; row := n / l ; var perimeter : long ; perimeter := 2 * (l + row) ; if (n mod l /= 0) then perimeter := perimeter+(2) ; else skip ; return perimeter ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println(minPerimeter(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Iterator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayList list=new ArrayList(); while(--n>-1){ list.add(sc.nextInt()); } int t=sc.nextInt(); Integer[] arrs=(Integer[])list.toArray(new Integer[list.size()]); Arrays.sort(arrs); int count=0 ; int max=0 ; for(int i=0 ; imax){ max=count ; } } } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var list : Sequence ; list := Sequence{} ; n := n - 1 ; while ((n - 1) > -1) do ( n := n - 1 ; ; ( list := list->including(sc.getCurrent()->toInteger()) ) ; n := n - 1 ; ) ; var t : int ; t := sc.getCurrent()->toInteger() ; var arrs : Sequence(int) ; arrs := list->asSequence()->oclAsType(Sequence(int)) ; arrs := arrs->sort() ; var count : int ; count := 0 ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < list->size() do ( ( count := 0 ; var j : int ; j := i ; while j < list->size() do ( ( if (arrs[j+1] - arrs[i+1] < (t + 1)) then ( count := count + 1 ) else skip ; if (count > max) then ( max := count ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Iterator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayList list=new ArrayList(); while(--n>-1){ list.add(sc.nextInt()); } int t=sc.nextInt(); Integer[] arrs=(Integer[])list.toArray(new Integer[list.size()]); Arrays.sort(arrs); int count=0 ; int max=0 ; for(int i=0 ; imax){ max=count ; } } } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var list : Sequence ; list := Sequence{} ; n := n - 1 ; while ((n - 1) > -1) do ( n := n - 1 ; ; ( list := list->including(sc.getCurrent()->toInteger()) ) ; n := n - 1 ; ) ; var t : int ; t := sc.getCurrent()->toInteger() ; var arrs : Sequence(int) ; arrs := list->asSequence()->oclAsType(Sequence(int)) ; arrs := arrs->sort() ; var count : int ; count := 0 ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < list->size() do ( ( count := 0 ; var j : int ; j := i ; while j < list->size() do ( ( if (arrs[j+1] - arrs[i+1] < (t + 1)) then ( count := count + 1 ) else skip ; if (count > max) then ( max := count ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var t : int ; t := sc.getCurrent()->toInteger() ; arr := arr->sort() ; var result : int ; result := 0 ; var i : int ; i := 0 ; var j : int ; j := 0 ; var num : int ; num := 0 ; while i < arr->size() do ( ( if (arr[i+1] <= arr[j+1] + t) then ( num := num + 1 ; result := Set{result, num}->max() ) else ( num := 0 ; j := j + 1 ; i := j - 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].print(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.Collectors ; public class Problem2 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] ar=new int[n]; for(int i=0 ; itoInteger() ; var ar : Sequence(int) ; ar := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ar[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var T : int ; T := sc.getCurrent()->toInteger() ; ar := ar->sort() ; var i : int ; i := 0 ; var j : int ; j := i ; var max : int ; max := 0 ; while (i < n) do ( while (j < n & (ar[j+1] - ar[i+1]) <= T) do j := j + 1 ; ; max := Set{max, j - i}->max() ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var t : int ; t := in.getCurrent()->toInteger() ; arr := arr->sort() ; var max : int ; max := -1 ; var i : int ; i := 0 ; while i < n do ( ( var ans : int ; ans := 1 ; var j : int ; j := i + 1 ; while j < n do ( ( if (arr[j+1] - arr[i+1] <= t) then ( ans := ans + 1 ) else ( break ) ) ; j := j + 1 ) ; max := Set{ans, max}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int[] pref=new int[100001]; static int checkArmstrong(int x){ int n=String.valueOf(x).length(); int sum1=0 ; int temp=x ; while(temp>0){ int digit=temp % 10 ; sum1+=Math.pow(digit,n); temp/=10 ; } if(sum1==x)return x ; return 0 ; } static void preCompute(){ for(int i=1 ; i<100001 ; i++){ pref[i]=pref[i-1]+checkArmstrong(i); } } static void printSum(int L,int R){ System.out.println(pref[R]-pref[L-1]); } static void printSumarmstrong(int[][] arr,int Q){ preCompute(); for(int i=0 ; icollect(0); static operation checkArmstrong( x : int) : int pre: true post: true activity: ( var n : int ; n := ((x) + "")->size() ; var sum1 : int ; sum1 := 0 ; var temp : int ; temp := x ; while (temp > 0) do ( var digit : int ; digit := temp mod 10 ; sum1 := sum1+(digit->pow(n)) ; temp := temp/(10) ) ; if (sum1 = x) then return x else skip ; return 0 ); static operation preCompute() : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < 100001 do ( ( pref[i+1] := pref[i - 1+1] + checkArmstrong(i) ) ; i := i + 1 ) ); static operation printSum( L : int, R : int) : void pre: true post: true activity: ( OclFile["System.out"].println(pref[R+1] - pref[L - 1+1]) ); static operation printSumarmstrong( arr : Sequence(Sequence(int)), Q : int) : void pre: true post: true activity: ( execute preCompute() ; var i : int ; i := 0 ; while i < Q do ( ( execute printSum(arr[i+1][0+1], arr[i+1][1+1]) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var Q : int ; Q := 2 ; var arr : Sequence(Sequence(int)) ; arr := Sequence{Sequence{1,13},Sequence{121,211}} ; execute printSumarmstrong(arr, Q) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc ; double nd(){ return sc.nextDouble(); } void io(){ sc=new Scanner(System.in); int[][] num=new int[4][2]; for(int[] e : num)Arrays.fill(e,0); int side=0 ; while(sc.hasNext()){ double eye=nd(); if(eye>=1.1)++num[0][side]; else if(eye>=0.6)++num[1][side]; else if(eye>=0.2)++num[2][side]; else++num[3][side]; side ^=1 ; } for(int i=0 ; i<4 ; ++i)System.out.println(num[i][0]+" "+num[i][1]); sc.close(); } public static void main(String[] args){ new Main().io(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; operation nd() : double pre: true post: true activity: ( return sc.getCurrent()->toReal() ); operation io() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : Sequence(Sequence(int)) ; num := Integer.subrange(1,4)->collect(Integer.subrange(1,2)->collect(0)) ; for (e : num) do ( e := e->collect(0) ; ) ; var side : int ; side := 0 ; while (sc.hasNext()) do ( var eye : double ; eye := nd() ; if (eye >= 1.1) then num[0+1][side+1] := num[0+1][side+1] + 1 else if (eye >= 0.6) then num[1+1][side+1] := num[1+1][side+1] + 1 else if (eye >= 0.2) then num[2+1][side+1] := num[2+1][side+1] + 1 else num[3+1][side+1] := num[3+1][side+1] + 1 ; ; ; ; side := MathLib.bitwiseXor(side,1) ) ; var i : int ; i := 0 ; while i < 4 do ( OclFile["System.out"].println(num[i+1][0+1] + " " + num[i+1][1+1]) ; ; i := i + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().io() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int[] ingredient=new int[22]; static int[] b=new int[22]; static double min=10000000 ; static double res=0 ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int v=scanner.nextInt(); for(int i=0 ; icollect(0); static attribute b : Sequence(int) := Integer.subrange(1,22)->collect(0); static attribute min : double := 10000000; static attribute res : double := 0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var v : int ; v := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( ingredient[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( min := Set{min, b[i+1] * 1.0 / ingredient[i+1]}->min() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( res := res+(min * ingredient[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{res, v}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); double v=sc.nextDouble(),k=0,m1=Double.MAX_VALUE ; double[] ing=new double[n]; double[] vol=new double[n]; for(int i=0 ; itoInteger() ; var v : double ; v := sc.getCurrent()->toReal() ; var k : double ; k := 0 ; var m1 : double ; m1 := (2 - 2->pow(-52))*(2->pow(1023)) ; var ing : Sequence(double) ; ing := Integer.subrange(1,n)->collect(0.0) ; var vol : Sequence(double) ; vol := Integer.subrange(1,n)->collect(0.0) ; var i : int ; i := 0 ; while i < n do ( ( ing[i+1] := sc.getCurrent()->toReal() ; k := k+(ing[i+1]) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( vol[i+1] := sc.getCurrent()->toReal() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( m1 := Set{vol[i+1] / ing[i+1], m1}->min() ; ; i := i + 1 ) ; OclFile["System.out"].println(Set{v, k * m1}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Locale ; import java.util.Scanner ; public class A42 { public static void main(String[] args){ Locale.setDefault(Locale.US); Scanner in=new Scanner(System.in); int N=in.nextInt(); int V=in.nextInt(); double[] A=new double[N]; double sum=0 ; for(int n=0 ; ntoInteger() ; var V : int ; V := in.getCurrent()->toInteger() ; var A : Sequence(double) ; A := Integer.subrange(1,N)->collect(0.0) ; var sum : double ; sum := 0 ; var n : int ; n := 0 ; while n < N do ( ( var a : int ; a := in.getCurrent()->toInteger() ; A[n+1] := a ; sum := sum+(a) ) ; n := n + 1 ) ; var max : double ; max := V / sum ; var n : int ; n := 0 ; while n < N do ( ( var b : int ; b := in.getCurrent()->toInteger() ; max := Set{max, b / A[n+1]}->min() ) ; n := n + 1 ) ; OclFile["System.out"].println(max * sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean checkPrime(String number){ if(number.length()==0)return true ; int num=Integer.parseInt(number); for(int i=2 ; i*i<=num ; i++)if((num % i)==0)return false ; return true ; } static int splitIntoPrimes(String number){ int numLen=number.length(); int[] splitDP=new int[numLen+1]; Arrays.fill(splitDP,-1); for(int i=1 ; i<=numLen ; i++){ if(i<=6 && checkPrime(number.substring(0,i)))splitDP[i]=1 ; if(splitDP[i]!=-1){ for(int j=1 ; j<=6 && i+j<=numLen ; j++){ if(checkPrime(number.substring(i,i+j))){ if(splitDP[i+j]==-1)splitDP[i+j]=1+splitDP[i]; else splitDP[i+j]=Math.min(splitDP[i+j],1+splitDP[i]); } } } } return splitDP[numLen]; } public static void main(String[] args){ System.out.print(splitIntoPrimes("13499315")+"\n"); System.out.print(splitIntoPrimes("43")+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkPrime( number : String) : boolean pre: true post: true activity: ( if (number->size() = 0) then return true else skip ; var num : int ; num := (number)->toInteger() ; var i : int ; i := 2 ; while i * i <= num do ( if ((num mod i) = 0) then return false else skip ; ; i := i + 1 ) ; return true ); static operation splitIntoPrimes( number : String) : int pre: true post: true activity: ( var numLen : int ; numLen := number->size() ; var splitDP : Sequence(int) ; splitDP := Integer.subrange(1,numLen + 1)->collect(0) ; splitDP := splitDP->collect(-1) ; var i : int ; i := 1 ; while i <= numLen 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 ; j := 1 ; while j <= 6 & i + j <= numLen 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 ) ; i := i + 1 ) ; return splitDP[numLen+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].print(splitIntoPrimes("13499315") + "\n") ; OclFile["System.out"].print(splitIntoPrimes("43") + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static int squareFree(int n){ int cnt=0 ; for(int i=1 ; ; i++){ boolean isSqFree=true ; for(int j=2 ; j*j<=i ; j++){ if(i %(j*j)==0){ isSqFree=false ; break ; } } if(isSqFree==true){ cnt++; if(cnt==n)return i ; } } } public static void main(String[] args){ int n=10 ; System.out.println(""+squareFree(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation squareFree( n : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := 1 ; while true do ( ( var isSqFree : boolean ; isSqFree := true ; var j : int ; j := 2 ; while j * j <= i 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 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println("" + squareFree(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static boolean validate(long n){ for(int i=0 ; i<10 ; i++){ long temp=n ; int count=0 ; while(temp>0){ if(temp % 10==i)count++; if(count>i)return false ; temp/=10 ; } } return true ; } static public void main(String[] args){ long n=1552793 ; if(validate(n))System.out.println("True"); else System.out.println("False"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation validate( n : long) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < 10 do ( ( var temp : long ; temp := n ; var count : int ; count := 0 ; while (temp > 0) do ( if (temp mod 10 = i) then count := count + 1 ; else skip ; if (count > i) then return false else skip ; temp := temp/(10) ) ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 1552793 ; if (validate(n)) then OclFile["System.out"].println("True") ; else OclFile["System.out"].println("False") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; public class GFG { static boolean sackRace(int p1,int s1,int p2,int s2){ return((s1>s2 &&(p2-p1)%(s1-s2)==0)||(s2>s1 &&(p1-p2)%(s2-s1)==0)); } public static void main(String args[]){ int p1=4,s1=4,p2=8,s2=2 ; if(sackRace(p1,s1,p2,s2))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sackRace( p1 : int, s1 : int, p2 : int, s2 : int) : boolean pre: true post: true activity: ( return ((s1 > s2 & (p2 - p1) mod (s1 - s2) = 0) or (s2 > s1 & (p1 - p2) mod (s2 - s1) = 0)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var p1 : int ; p1 := 4 ; var s1 : int ; s1 := 4 ; var p2 : int ; p2 := 8 ; var s2 : int ; s2 := 2 ; if (sackRace(p1, s1, p2, s2)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public static void main(String[] args){ int x=new java.util.Scanner(System.in).nextInt(); if(x==0){ System.out.println("1"); } else { System.out.println("0"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := Scanner.newScanner(OclFile["System.in"]).nextInt() ; if (x = 0) then ( OclFile["System.out"].println("1") ) else ( OclFile["System.out"].println("0") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int q=sc.nextInt(); PriorityQueuequeue=new PriorityQueue<>(); for(int i=0 ; imap=new TreeMap<>(); for(int i=0 ; i0){ Event e=queue.poll(); Map.Entryx=map.ceilingEntry(e.start-e.point); while(x!=null && x.getKey(){ int start ; int end ; int point ; public Event(int start,int end,int point){ this.start=start ; this.end=end ; this.point=point ; } public int compareTo(Event another){ return point-another.point ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var queue : Sequence(Event) ; queue := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( queue := queue->including(Event.newEvent(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < q do ( ( map := map->union(Map{sc.getCurrent()->toInteger() |-> i}) ) ; i := i + 1 ) ; var ans : Sequence(int) ; ans := Integer.subrange(1,q)->collect(0) ; ans := ans->collect(-1) ; while (queue->size() > 0) do ( var e : Event ; e := queue->min() ; var x : Map(int,int) ; x := map.ceilingEntry(e.start - e.point) ; while (x /= null & x->keys()->any() < e.end - e.point) do ( ans[x->values->any()+1] := e.point ; map := map->antirestrict(Set{x->keys()->any()}) ; x := map.ceilingEntry(e.start - e.point) ) ) ; var sb : String ; sb := StringLib.newString() ; for (x : ans) do ( ( sb := sb + StringLib.newString(x) + StringLib.newString("\n") ) ) ; OclFile["System.out"].print(sb) ; ); static class Event implements Comparable { attribute start : int; attribute end : int; attribute point : int; static operation newEvent( start : int, end : int, point : int) : Event pre: true post: true activity: ( var self : Event ; self := createEvent(); self.initialise(start, end,point); return self ); operation initialise( start : int, end : int, point : int) : void pre: true post: true activity: ( self.start := start ; self.end := end ; self.point := point ); operation compareTo( another : Event) : int pre: true post: true activity: ( return (point)->char2byte() - another.point ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args)throws Exception { try(Scanner sc=new Scanner(System.in)){ int N=sc.nextInt(); int Q=sc.nextInt(); int[][] W=new int[N][3]; for(int i=0 ; iInteger.compare(o1[2],o2[2])); TreeMapD=new TreeMap<>(); for(int i=0 ; i=t-x){ break ; } A[D.get(key)]=x ; D.remove(key); } } StringBuilder ans=new StringBuilder(); for(int a : A){ ans.append(a).append("\n"); } System.out.print(ans.toString()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var N : int ; N := sc.getCurrent()->toInteger() ; var Q : int ; Q := sc.getCurrent()->toInteger() ; var W : Sequence(Sequence(int)) ; W := Integer.subrange(1,N)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( W[i+1][0+1] := sc.getCurrent()->toInteger() ; W[i+1][1+1] := sc.getCurrent()->toInteger() ; W[i+1][2+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; W := OclComparator.sortWith(W, lambda (o1 , o2) : OclAny in compare(o1[2+1], o2[2+1])) ; var D : Map(int,int) ; D := Map{} ; var i : int ; i := 0 ; while i < Q do ( ( D := D->union(Map{sc.getCurrent()->toInteger() |-> i}) ) ; i := i + 1 ) ; var A : Sequence(int) ; A := Integer.subrange(1,Q)->collect(0) ; A := A->collect(-1) ; var i : int ; i := 0 ; while i < N do ( ( var s : int ; s := W[i+1][0+1] ; var t : int ; t := W[i+1][1+1] ; var x : int ; x := W[i+1][2+1] ; while (true) do ( var key : int ; key := D.ceilingKey(s - x) ; if (key = null) then ( break ) else skip ; if (key >= t - x) then ( break ) else skip ; A[D->at(key)+1] := x ; D := D->antirestrict(Set{key}) ; ) ) ; i := i + 1 ) ; var ans : String ; ans := StringLib.newString() ; for (a : A) do ( ( ans := ans + StringLib.newString(a) + StringLib.newString("\n") ) ) ; OclFile["System.out"].print(ans+"") ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int[] seats=new int[] { 1,2,4 }; public static int maxAmount(int M,int N){ PriorityQueueq=new PriorityQueue(Collections.reverseOrder()); for(int i=0 ; i0){ ans=ans+q.peek(); int temp=q.peek(); q.poll(); q.add(temp-1); ticketSold++; } return ans ; } public static void main(String[] args){ int M=seats.length ; int N=3 ; System.out.print(maxAmount(M,N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute seats : Sequence(int) := Sequence{1,2,4}; static operation maxAmount( M : int, N : int) : int pre: true post: true activity: ( var q : Sequence(int) ; q := Sequence{}->union(reverseOrder()) ; var i : int ; i := 0 ; while i < M do ( ( q := q->including(seats[i+1]) ) ; i := i + 1 ) ; var ticketSold : int ; ticketSold := 0 ; var ans : int ; ans := 0 ; while (ticketSold < N & q->min() > 0) do ( ans := ans + q->min() ; var temp : int ; temp := q->min() ; q := q->sort()->tail() ; q := q->including(temp - 1) ; ticketSold := ticketSold + 1 ; ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var M : int ; M := seats->size() ; var N : int ; N := 3 ; OclFile["System.out"].print(maxAmount(M, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maxDifference(int arr[],int N,int k){ int M,S=0,S1=0,max_difference=0 ; for(int i=0 ; imax() ; var i : int ; i := 0 ; while i < M do ( S1 := S1+(arr[i+1]) ; ; i := i + 1 ) ; max_difference := S1 - (S - S1) ; return max_difference ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{8,4,5,2,10} ; var N : int ; N := arr->size() ; var k : int ; k := 2 ; OclFile["System.out"].println(maxDifference(arr, N, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Vector ; import java.util.Arrays ; class GfG { static int checkBit(int pattern,Vectorarr,int n){ int count=0 ; for(int i=0 ; iv=new Vector<>(); for(Integer a : arr)v.add(a); v.add(Integer.MAX_VALUE); n++; int res=0 ; for(int bit=31 ; bit>=0 ; bit--){ int count=checkBit(res |(1<0)diff[i]+=diff[i-1]; if(max_diffcollect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( diff[i+1] := arr[i + 1+1] - arr[i+1] ; ; i := i + 1 ) ; var max_diff : int ; max_diff := diff[0+1] ; var i : int ; i := 1 ; while i < n - 1 do ( ( if (diff[i - 1+1] > 0) then diff[i+1] := diff[i+1]+(diff[i - 1+1]) ; else skip ; if (max_diff < diff[i+1]) then max_diff := diff[i+1] ; else skip ) ; i := i + 1 ) ; return max_diff ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mxdif : MaximumDiffrence ; mxdif := MaximumDiffrence.newMaximumDiffrence() ; var arr : Sequence(int) ; arr := Sequence{80,2,6,3,100} ; var size : int ; size := arr->size() ; OclFile["System.out"].println(mxdif.maxDiff(arr, size)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static float y(float x){ return 1/(1+x*x); } static float trapezoidal(float a,float b,float n){ float h=(b-a)/n ; float s=y(a)+y(b); for(int i=1 ; iround() / 10000.0) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static char[] s ; static int id ; static int len ; static String msg(){ StringBuilder sb=new StringBuilder(); int x=1 ; while(true){ char ch=s[id++]; if(Character.isDigit(ch)){ id--; x=num(); } else if(ch=='('){ String t=msg(); while(sb.length()<=len && x--!=0){ for(int i=0 ; ilen)break ; sb.append(t.charAt(i)); } } x=1 ; } else if(Character.isUpperCase(ch)){ while(sb.length()<=len && x--!=0)sb.append(ch); x=1 ; } else break ; } return sb.toString(); } static int num(){ char ch=s[id++]; int x=ch-'0' ; while(true){ ch=s[id++]; if(! Character.isDigit(ch))break ; x*=10 ; x+=ch-'0' ; } id--; return x ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ String ss=sc.next(); len=sc.nextInt(); if(ss.equals("0")&& len==0)break ; s=(ss+"#").toCharArray(); id=0 ; len++; String genom=msg(); System.out.println(genom.length()>=len ? genom.charAt(len-1): "0"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : Sequence(String); static attribute id : int; static attribute len : int; static operation msg() : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; var x : int ; x := 1 ; while (true) do ( var ch : String ; ch := s[id+1] ; if ((ch + "")->isMatch("[0-9]")) then ( id := id - 1 ; x := num() ) else if (ch = '(') then ( var t : String ; t := msg() ; while (sb->size() <= len & x /= 0) do ( skip ; ( var i : int ; i := 0 ; while i < t->size() do ( ( if (sb->size() > len) then break else skip ; sb := sb + StringLib.newString(t->at(i+1)) ) ; i := i + 1 ) ) ; ) ; x := 1 ) else if ((ch->toUpperCase() = ch)) then ( while (sb->size() <= len & x /= 0) do ( skip ; sb := sb + StringLib.newString(ch) ; ; ) ; x := 1 ) else break ; ; ) ; return sb+"" ); static operation num() : int pre: true post: true activity: ( var ch : String ; ch := s[id+1] ; var x : int ; x := (ch)->char2byte() - ('0')->char2byte() ; while (true) do ( ch := s[id+1] ; id := id + 1 ; if (not((ch + "")->isMatch("[0-9]"))) then break else skip ; x := x*(10) ; x := x+((ch)->char2byte() - ('0')->char2byte()) ) ; id := id - 1 ; return x ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var ss : String ; ss := sc.getCurrent() ; len := sc.getCurrent()->toInteger() ; if (ss = "0" & len = 0) then break else skip ; s := (ss + "#")->characters() ; id := 0 ; len := len + 1 ; var genom : String ; genom := msg() ; OclFile["System.out"].println(if genom->size() >= len then genom->at(len - 1+1) else "0" endif) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static int n ; static int count ; static String str ; static boolean R ; static void solve(int a,int b){ int now=0 ; for(int i=a ; i<=b ; i++){ if('0'<=str.charAt(i)&& str.charAt(i)<='9'){ now*=10 ; now+=(int)(str.charAt(i)-'0'); } else if(str.charAt(i)=='('){ if(now==0)now=1 ; int K=1 ; int j ; for(j=i+1 ; j<=b ; j++){ if(str.charAt(j)=='(')K++; if(str.charAt(j)==')')K--; if(K==0)break ; } for(int k=0 ; kat(i+1) & str->at(i+1) <= '9') then ( now := now*(10) ; now := now+((str->at(i+1) - ('0')->char2byte())->oclAsType(int)) ) else if (str->at(i+1) = '(') then ( if (now = 0) then now := 1 ; else skip ; var K : int ; K := 1 ; var j : int ; j := i + 1 ; while j <= b do ( ( if (str->at(j+1) = '(') then K := K + 1 ; else skip ; if (str->at(j+1) = ')') then K := K - 1 ; else skip ; if (K = 0) then break else skip ) ; j := j + 1 ) ; var k : int ; k := 0 ; while k < now do ( ( execute solve(i + 1, j - 1) ; if (R) then return else skip ) ; k := k + 1 ) ; i := j ; now := 0 ; ) else ( if (now = 0) then now := 1 ; else skip ; var j : int ; j := 0 ; while j < now do ( ( if (count = n) then ( OclFile["System.out"].println(str->at(i+1)) ; R := true ; return ) else skip ; count := count + 1 ) ; j := j + 1 ) ; now := 0 ) ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( str := s.getCurrent() ; var a : int ; a := s.getCurrent()->toInteger() ; n := a ; count := 0 ; R := false ; if (str = "0") then break else skip ; execute solve(0, str->size() - 1) ; if (not(R)) then OclFile["System.out"].println("0") ; else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { FastReader sc=new FastReader(); int x=sc.nextInt(); if(x==1)System.out.println(0); else System.out.println(1); } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var x : int ; x := sc.nextInt() ; if (x = 1) then OclFile["System.out"].println(0) ; else OclFile["System.out"].println(1) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { String s ; char[] a,b ; int n ; int id,pos ; void A(){ while(true){ int start=pos ; int t=id ; int num=1 ; int goal ; while(Character.isDigit(a[id])==true)id++; if(id!=t)num=Integer.valueOf(s.substring(t,id)); B(); goal=pos ; for(int i=0 ; in || j>n){ i=num ; break ; } b[pos]=b[j]; pos++; } } if(id==a.length || a[id]==')')break ; } } void B(){ if(a[id]=='('){ id++; A(); id++; } else { int t=id ; while(idn)break ; b[pos]=a[i]; pos++; } } } } void solve(){ Scanner sc=new Scanner(System.in); while(true){ s=sc.next(); a=s.toCharArray(); n=sc.nextInt(); if(a[0]=='0' && n==0)break ; b=new char[n+1]; Arrays.fill(b,'0'); id=0 ; pos=0 ; A(); System.out.println(b[n]); } } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute s : String; attribute a : Sequence(String); attribute n : int; attribute id : int; operation A() : void pre: true post: true activity: ( while (true) do ( var start : int ; start := pos ; var t : int ; t := id ; var num : int ; num := 1 ; var goal : int ; while ((a[id+1] + "")->isMatch("[0-9]") = true) do id := id + 1 ; ; if (id /= t) then num := (s.subrange(t+1,id))->toInteger() ; else skip ; execute B() ; goal := pos ; var i : int ; i := 0 ; while i < num - 1 do ( ( var j : int ; j := start ; while j < goal do ( ( if (pos > n or j > n) then ( i := num ; break ) else skip ; b[pos+1] := b[j+1] ; pos := pos + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (id = a->size() or a[id+1] = ')') then break else skip ; ) ); operation B() : void pre: true post: true activity: ( if (a[id+1] = '(') then ( id := id + 1 ; execute A() ; id := id + 1 ) else ( var t : int ; t := id ; while (id < s->size() & (a[id+1]->toUpperCase() = a[id+1]) = true) do id := id + 1 ; ; if (id = a->size() or a[id+1] = ')' or (a[id+1] + "")->isMatch("[0-9]") = true) then ( var i : int ; i := t ; while i < id do ( ( if (pos > n) then break else skip ; b[pos+1] := a[i+1] ; pos := pos + 1 ) ; i := i + 1 ) ) else skip ) ); operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( s := sc.getCurrent() ; a := s->characters() ; n := sc.getCurrent()->toInteger() ; if (a[0+1] = '0' & n = 0) then break else skip ; b := Integer.subrange(1,n + 1)->collect(0) ; b := b->collect('0') ; id := 0 ; pos := 0 ; execute A() ; OclFile["System.out"].println(b[n+1]) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static String formula ; static int pos ; static int n ; static StringBuilder sb ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ formula=sc.next(); n=sc.nextInt(); if(formula.equals("0")&& n==0)break ; pos=0 ; sb=new StringBuilder(); parse(); if(n>=sb.length())System.out.println(0); else System.out.println(sb.charAt(n)); } sc.close(); } static void parse(){ while(posn+1){ pos=formula.length(); return ; } if(Character.isUpperCase(formula.charAt(pos))){ if(sb.length()<=n+1)sb.append(formula.charAt(pos)); pos++; return ; } int n=number(); if(formula.charAt(pos)!='('){ for(int i=0 ; itoInteger() ; if (formula = "0" & n = 0) then break else skip ; pos := 0 ; sb := StringLib.newString() ; execute parse() ; if (n >= sb->size()) then OclFile["System.out"].println(0) else OclFile["System.out"].println(sb->at(n+1)) ; ; ) ; skip ); static operation parse() : void pre: true post: true activity: ( while (pos < formula->size() & sb->size() <= n + 1) do execute term() ; ); static operation term() : void pre: true post: true activity: ( if (sb->size() > n + 1) then ( pos := formula->size() ; return ) else skip ; if ((formula->at(pos+1)->toUpperCase() = formula->at(pos+1))) then ( if (sb->size() <= n + 1) then sb := sb + StringLib.newString(formula->at(pos+1)) ; else skip ; pos := pos + 1 ; return ) else skip ; var n : int ; n := number() ; if (formula->at(pos+1) /= '(') then ( var i : int ; i := 0 ; while i < n do ( sb := sb + StringLib.newString(formula->at(pos+1)) ; ; i := i + 1 ) ; pos := pos + 1 ; return ) else skip ; pos := pos + 1 ; var i : int ; i := 0 ; while i < n - 1 do ( ( var t : int ; t := pos ; while (pos < formula->size() & formula->at(pos+1) /= ')') do execute term() ; ; pos := t ) ; i := i + 1 ) ; while (pos < formula->size() & formula->at(pos+1) /= ')') do execute term() ; ; pos := pos + 1 ; return ); static operation number() : int pre: true post: true activity: ( var result : int ; result := 0 ; while ((formula->at(pos+1) + "")->isMatch("[0-9]")) do ( result := result*(10) ; result := result+(formula->at(pos+1) - ('0')->char2byte()) ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void balancedString(String str){ int count=0,i ; int n=str.length(); for(i=0 ; isize() ; i := 0 ; while i < n do ( ( if (str->at(i+1) = '(') then ( OclFile["System.out"].print(str->at(i+1)) ; count := count + 1 ) else if (str->at(i+1) = ')' & count /= 0) then ( OclFile["System.out"].print(str->at(i+1)) ; count := count - 1 ) else if (str->at(i+1) /= ')') then OclFile["System.out"].print(str->at(i+1)) ; else skip ; ; ) ; i := i + 1 ) ; if (count /= 0) then i := 0 ; while i < count do ( OclFile["System.out"].print(")") ; ; i := i + 1 ) ; else skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "gau)ra)v(ku(mar(rajput))" ; execute balancedString(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Count { public static int count4Divisibiles(int arr[],int n){ int freq[]={ 0,0,0,0 }; int i=0 ; int ans ; for(i=0 ; i0 ; j--)C[j]=C[j]+C[j-1]; } } static int summation(int n){ int C[]=new int[MAX]; for(int i=0 ; imin() ; while j > 0 do ( C[j+1] := C[j+1] + C[j - 1+1] ; ; j := j - 1 ) ) ; i := i + 1 ) ); static operation summation( n : int) : int pre: true post: true activity: ( var C : Sequence(int) ; C := Integer.subrange(1,MAX)->collect(0) ; var i : int ; i := 0 ; while i < MAX do ( C[i+1] := 0 ; ; i := i + 1 ) ; execute binomialCoeff(n, C) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i <= n do ( sum := sum+((i * C[i+1])) ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; OclFile["System.out"].println(summation(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MAX=100 ; static void binomialCoeff(int C[],int n){ C[0]=1 ; for(int i=1 ; i<=n ; i++){ for(int j=Math.min(i,n); j>0 ; j--)C[j]=C[j]+C[j-1]; } } static int sumOfproduct(int n){ int sum=0 ; int C[]=new int[MAX]; binomialCoeff(C,n); for(int i=0 ; i<=n ; i++)sum+=C[i]*C[i+1]; return sum ; } public static void main(String[] args){ int n=3 ; System.out.println(sumOfproduct(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 100; static operation binomialCoeff( C : Sequence(int), n : int) : void pre: true post: true activity: ( C[0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := Set{i, n}->min() ; while j > 0 do ( C[j+1] := C[j+1] + C[j - 1+1] ; ; j := j - 1 ) ) ; i := i + 1 ) ); static operation sumOfproduct( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var C : Sequence(int) ; C := Integer.subrange(1,MAX)->collect(0) ; execute binomialCoeff(C, n) ; var i : int ; i := 0 ; while i <= n do ( sum := sum+(C[i+1] * C[i + 1+1]) ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(sumOfproduct(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static int minimumCost(int cost[],int n){ int dp[]=new int[n]; if(n==1)return cost[0]; dp[0]=cost[0]; dp[1]=cost[1]; for(int i=2 ; icollect(0) ; if (n = 1) then return cost[0+1] else skip ; dp[0+1] := cost[0+1] ; dp[1+1] := cost[1+1] ; var i : int ; i := 2 ; while i < n do ( ( dp[i+1] := Set{dp[i - 1+1], dp[i - 2+1]}->min() + cost[i+1] ) ; i := i + 1 ) ; return Set{dp[n - 2+1], dp[n - 1+1]}->min() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{16,19,10,12,18} ; var n : int ; n := a->size() ; OclFile["System.out"].print(minimumCost(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static double cyl(double r,double h){ if(r<0 && h<0)return-1 ; double R=(2*r)/3 ; double H=(2*h)/3 ; double V=3.14*Math.pow(R,2)*H ; return V ; } public static void main(String[] args){ double r=4,h=8 ; System.out.println(cyl(r,h)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cyl( r : double, h : double) : double pre: true post: true activity: ( if (r < 0 & h < 0) then return -1 else skip ; var R : double ; R := (2 * r) / 3 ; var H : double ; H := (2 * h) / 3 ; var V : double ; V := 3.14 * R->pow(2) * H ; return V ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : double ; r := 4 ; var h : double ; h := 8 ; OclFile["System.out"].println(cyl(r, h)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.ArrayList ; public class codforce { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int x=sc.nextInt(); int count=0 ; for(int i=1 ; i<=n ; i++){ if((x % i)==0 && x/i<=n){ count++; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class codforce { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if ((x mod i) = 0 & x / i <= n) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); Main m=new Main(sc); m.show(m.solve()); sc.close(); } Scanner sc ; int x ; Main(Scanner sc){ this.sc=sc ; this.x=sc.nextInt(); } private int solve(){ int answer=0 ; if(x==0){ answer=1 ; } return answer ; } public void show(int answer){ System.out.println(answer); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var m : Main ; m := Main.newMain(sc) ; m.show(m.solve()) ; skip ); attribute sc : OclFile; attribute x : int; static operation newMain( sc : OclFile) : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(sc); return self ); operation initialise( sc : OclFile) : void pre: true post: true activity: ( self.sc := sc ; self.x := sc.getCurrent()->toInteger() ); operation solve() : int pre: true post: true activity: ( var answer : int ; answer := 0 ; if (x = 0) then ( answer := 1 ) else skip ; return answer ); operation show( answer : int) : void pre: true post: true activity: ( OclFile["System.out"].println(answer) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MultiplicationTable { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); int counter=0 ; for(int i=1 ; i<=x ; i++){ if(y % i!=0){ continue ; } if(i*x==y){ counter++; continue ; } for(int j=1 ; j<=x && i*j<=y ; j++){ if((i*j)==y){ counter++; break ; } } } System.out.println(counter); } } ------------------------------------------------------------ OCL File: --------- class MultiplicationTable { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var counter : int ; counter := 0 ; var i : int ; i := 1 ; while i <= x do ( ( if (y mod i /= 0) then ( continue ) else skip ; if (i * x = y) then ( counter := counter + 1 ; continue ) else skip ; var j : int ; j := 1 ; while j <= x & i * j <= y do ( ( if ((i * j) = y) then ( counter := counter + 1 ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long x=sc.nextLong(); int count=0 ; for(int i=1 ; i<=n ; i++){ if(x % i==0 && x/i<=n)count++; } System.out.print(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : long ; x := sc.getCurrent()->toLong() ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (x mod i = 0 & x / i <= n) then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static void main(String args[]){ Scanner Sc=new Scanner(System.in); int n=Sc.nextInt(); int x=Sc.nextInt(); int count=0 ; for(int i=n ; i>=1 ; i--){ int q=x/i ; if(x % i==0 && qtoInteger() ; var x : int ; x := Sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := n ; while i >= 1 do ( ( var q : int ; q := x / i ; if (x mod i = 0 & q < i) then ( count := count+(2) ) else if (x mod i = 0 & q = i) then ( count := count+(1) ) else skip ; ) ; i := i - 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String args[])throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int res=0 ; Setst=new HashSet<>(); for(int i=1 ; i<=n ; i++){ if(m % i==0){ int x=m/i ; if(x<=n)res++; } } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var res : int ; res := 0 ; var st : Set(int) ; st := Set{} ; var i : int ; i := 1 ; while i <= n do ( ( if (m mod i = 0) then ( var x : int ; x := m / i ; if (x <= n) then res := res + 1 ; else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); TreeSetorSet=new TreeSet<>(); ArrayListandList=new ArrayList<>(); for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var orSet : Set(int) ; orSet := Set{} ; var andList : Sequence(int) ; andList := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( orSet := orSet->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (orSet->includes(x)) then ( andList := andList->including(x) ) else ( orSet := orSet->including(x) ) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString(andList->size()) + StringLib.newString(" ") + StringLib.newString(orSet->size()) + StringLib.newString("\n") ; for (x : andList) do ( ( sb := sb + StringLib.newString(x) + StringLib.newString("\n") ) ) ; for (x : orSet) do ( ( sb := sb + StringLib.newString(x) + StringLib.newString("\n") ) ) ; OclFile["System.out"].print(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.HashMap ; import java.util.List ; import java.util.Map ; import java.util.Scanner ; public class Main { static Scanner input=new Scanner(System.in); private static java.io.PrintWriter out=new java.io.PrintWriter(System.out); private static void solve(){ int n=input.nextInt(); int m=input.nextInt(); int[] a=arrayInput(n); int[] b=arrayInput(m); Mapmap=new HashMap<>(); for(int v : a){ map.put(v,1); } for(int v : b){ if(map.containsKey(v)){ map.put(v,2); } else { map.put(v,1); } } Listand=new ArrayList<>(); Listor=new ArrayList<>(map.keySet()); for(Map.Entryentry : map.entrySet()){ if(entry.getValue()==2){ and.add(entry.getKey()); } } Collections.sort(and); Collections.sort(or); out.println(and.size()+" "+or.size()); for(int v : and){ out.println(v); } for(int v : or){ out.println(v); } } public static void main(String[] args){ solve(); out.flush(); } private static int[] arrayInput(int n){ int[] a=new int[n]; for(int i=0 ; itoInteger() ; var m : int ; m := input.getCurrent()->toInteger() ; var a : Sequence(int) ; a := arrayInput(n) ; var b : Sequence(int) ; b := arrayInput(m) ; var map : Map(int,int) ; map := Map{} ; for (v : a) do ( ( map := map->union(Map{v |-> 1}) ) ) ; for (v : b) do ( ( if (map->keys()->includes(v)) then ( map := map->union(Map{v |-> 2}) ) else ( map := map->union(Map{v |-> 1}) ) ) ) ; var and : Sequence(int) ; and := Sequence{} ; var or : Sequence(int) ; or := Sequence{}->union(map->keys()) ; for (entry : map->asSet()) do ( ( if (entry.getValue() = 2) then ( and := and->including(entry.getKey()) ) else skip ) ) ; and := and->sort() ; or := or->sort() ; out.println(and->size() + " " + or->size()) ; for (v : and) do ( ( out.println(v) ) ) ; for (v : or) do ( ( out.println(v) ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ; out.flush() ); static operation arrayInput( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.HashMap ; import java.util.List ; import java.util.Map ; import java.util.Scanner ; public class Main { static Scanner input=new Scanner(System.in); private static java.io.PrintWriter out=new java.io.PrintWriter(System.out); private static void solve(){ int n=input.nextInt(); int m=input.nextInt(); int[] a=arrayInput(n); int[] b=arrayInput(m); Mapmap=new HashMap<>(); for(int v : a){ map.put(v,1); } for(int v : b){ if(map.containsKey(v)){ map.put(v,2); } else { map.put(v,1); } } Listand=new ArrayList<>(); Listor=new ArrayList<>(map.keySet()); for(Map.Entryentry : map.entrySet()){ if(entry.getValue()==2){ and.add(entry.getKey()); } } Collections.sort(and); Collections.sort(or); out.println(and.size()+" "+or.size()); for(int v : and){ out.println(v); } for(int v : or){ out.println(v); } } public static void main(String[] args){ solve(); out.flush(); } private static int[] arrayInput(int n){ int[] a=new int[n]; for(int i=0 ; itoInteger() ; var m : int ; m := input.getCurrent()->toInteger() ; var a : Sequence(int) ; a := arrayInput(n) ; var b : Sequence(int) ; b := arrayInput(m) ; var map : Map(int,int) ; map := Map{} ; for (v : a) do ( ( map := map->union(Map{v |-> 1}) ) ) ; for (v : b) do ( ( if (map->keys()->includes(v)) then ( map := map->union(Map{v |-> 2}) ) else ( map := map->union(Map{v |-> 1}) ) ) ) ; var and : Sequence(int) ; and := Sequence{} ; var or : Sequence(int) ; or := Sequence{}->union(map->keys()) ; for (entry : map->asSet()) do ( ( if (entry.getValue() = 2) then ( and := and->including(entry.getKey()) ) else skip ) ) ; and := and->sort() ; or := or->sort() ; out.println(and->size() + " " + or->size()) ; for (v : and) do ( ( out.println(v) ) ) ; for (v : or) do ( ( out.println(v) ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ; out.flush() ); static operation arrayInput( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); long x ; long y ; while(t-->0){ x=sc.nextLong(); y=sc.nextLong(); System.out.println((x-y)==1 && isPrime(x+y)? "YES" : "NO"); } } static boolean isPrime(long num){ if(num<=1){ return false ; } for(int i=2 ; i<=num/i ; i++){ if((num % i)==0){ return false ; } } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var x : long ; var y : long ; while (t > 0) do ( t := t - 1 ; skip ; ( x := sc.getCurrent()->toLong() ; y := sc.getCurrent()->toLong() ; OclFile["System.out"].println(if (x - y) = 1 & isPrime(x + y) then "YES" else "NO" endif) ) ; ) ; ); static operation isPrime( num : long) : boolean pre: true post: true activity: ( if (num <= 1) then ( return false ) else skip ; var i : int ; i := 2 ; while i <= num / i do ( ( if ((num mod i) = 0) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class codeforces1033B { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int numCases=Integer.parseInt(br.readLine()); while(numCases-->0){ StringTokenizer st=new StringTokenizer(br.readLine()); long a=Long.parseLong(st.nextToken()); long b=Long.parseLong(st.nextToken()); boolean bo=prime(a+b); if(a-b==1 && bo){ System.out.println("YES"); } else { System.out.println("NO"); } } } static boolean prime(long n){ for(long i=2 ; i<=Math.sqrt(n); i++){ if(n % i==0){ return false ; } } return true ; } } ------------------------------------------------------------ OCL File: --------- class codeforces1033B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var numCases : int ; numCases := (br.readLine())->toInteger() ; while (numCases > 0) do ( numCases := numCases - 1 ; skip ; ( var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var a : long ; a := (st.next())->toLong() ; var b : long ; b := (st.next())->toLong() ; var bo : boolean ; bo := prime(a + b) ; if (a - b = 1 & bo) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); static operation prime( n : long) : boolean pre: true post: true activity: ( var i : long ; i := 2 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ FastScanner fs=new FastScanner(); int n=fs.nextInt(); if(n==0){ System.out.println(1); } else if(n==1){ System.out.println(0); } else { } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; itoInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long cnt=1 ; long mod=1000000007 ; char[] c1=sc.next().toCharArray(); char[] c2=sc.next().toCharArray(); int i=0 ; if(c1[0]==c2[0])cnt=3 ; if(c1[0]!=c2[0]){ cnt=6 ; i++; } while(itoInteger() ; var cnt : long ; cnt := 1 ; var mod : long ; mod := 1000000007 ; var c1 : Sequence(String) ; c1 := sc.getCurrent()->characters() ; var c2 : Sequence(String) ; c2 := sc.getCurrent()->characters() ; var i : int ; i := 0 ; if (c1[0+1] = c2[0+1]) then cnt := 3 ; else skip ; if (c1[0+1] /= c2[0+1]) then ( cnt := 6 ; i := i + 1 ) else skip ; while (i < n - 1) do ( if (c1[i+1] /= c2[i+1] & c1[i + 1+1] /= c2[i + 1+1] & c1[i+1] /= c1[i + 1+1]) then cnt := (cnt * 3) mod mod else if (c1[i+1] /= c2[i+1] & c1[i + 1+1] = c2[i + 1+1]) then cnt := cnt mod mod else if (c1[i+1] = c2[i+1] & c1[i + 1+1] /= c2[i + 1+1]) then cnt := (cnt * 2) mod mod else if (c1[i+1] = c2[i+1] & c1[i + 1+1] = c2[i + 1+1]) then cnt := (cnt * 2) mod mod ; else skip ; ; ; ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { private static final int MOD=1_000_000_007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); char[][] d=new char[2][N]; for(int i=0 ; i<2 ; i++){ String s=sc.next(); for(int j=0 ; jtoInteger() ; var d : Sequence(Sequence(String)) ; d := Integer.subrange(1,2)->collect(Integer.subrange(1,N)->collect(0)) ; var i : int ; i := 0 ; while i < 2 do ( ( var s : String ; s := sc.getCurrent() ; var j : int ; j := 0 ; while j < N do ( ( d[i+1][j+1] := s->at(j+1) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var prev : int ; var j : int ; j := if d[0+1][0+1] = d[1+1][0+1] then 1 else 2 endif ; var ans : long ; ans := if d[0+1][0+1] = d[1+1][0+1] then 3 else 6 endif ; while (j < N) do ( if (d[0+1][j+1] = d[1+1][j+1]) then ( ans := ans*(if d[0+1][(j)->char2byte() - 1+1] = d[1+1][(j)->char2byte() - 1+1] then 2 else 1 endif) ; j := j + 1 ) else ( ans := ans*(if d[0+1][(j)->char2byte() - 1+1] = d[1+1][(j)->char2byte() - 1+1] then 2 else 3 endif) ; j := j+(2) ) ; ans := ans mod MOD ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char[] r1=sc.next().toCharArray(); char[] r2=sc.next().toCharArray(); sc.close(); int i ; long count ; boolean prev ; if(r1[0]==r2[0]){ i=1 ; count=3 ; prev=true ; } else { i=2 ; count=6 ; prev=false ; } for(; itoInteger() ; var r1 : Sequence(String) ; r1 := sc.getCurrent()->characters() ; var r2 : Sequence(String) ; r2 := sc.getCurrent()->characters() ; skip ; var i : int ; var count : long ; var prev : boolean ; if (r1[0+1] = r2[0+1]) then ( i := 1 ; count := 3 ; prev := true ) else ( i := 2 ; count := 6 ; prev := false ) ; while i < n do ( ( if (r1[i+1] = r2[i+1]) then ( if (prev) then count := mulmod(count, 2) ; else skip ; prev := true ) else ( if (prev) then count := mulmod(count, 2) else count := mulmod(count, 3) ; ; prev := false ; i := i + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); static operation mulmod( a : long, b : long) : long pre: true post: true activity: ( var MOD : long ; MOD := 1000000007 ; return ((a mod MOD) * (b mod MOD)) mod MOD ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ long MOD=1000000007 ; Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s1=sc.next(); String s2=sc.next(); long ans=1 ; int pos=0 ; int pre=0 ; if(n>1){ if(s1.charAt(0)==s1.charAt(1)){ ans=6 ; pos=2 ; } else { ans=3 ; pos=1 ; pre=1 ; } while(postoInteger() ; var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; var ans : long ; ans := 1 ; var pos : int ; pos := 0 ; var pre : int ; pre := 0 ; if (n > 1) then ( if (s1->at(0+1) = s1->at(1+1)) then ( ans := 6 ; pos := 2 ) else ( ans := 3 ; pos := 1 ; pre := 1 ) ; while (pos < n) do ( if (pre = 0) then ( if (pos = n - 1) then ( pos := pos + 1 ) else ( if (s1->at(pos+1) = s1->at(pos + 1+1)) then ( ans := (ans * 3) mod MOD ; pos := pos+(2) ; pre := 0 ) else ( pos := pos + 1 ; pre := 1 ) ) ) else ( if (pos = n - 1) then ( ans := (ans * 2) mod MOD ; pos := pos + 1 ) else ( if (s1->at(pos+1) = s1->at(pos + 1+1)) then ( ans := (ans * 2) mod MOD ; pos := pos+(2) ; pre := 0 ) else ( ans := (ans * 2) mod MOD ; pos := pos + 1 ; pre := 1 ) ) ) ) ) else ( ans := 3 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { Scanner sc ; int N ; Vec[] v ; static class Vec implements Comparable{ double x,y ; double theta(){ if(x==0d && y==0d)return 0d ; return Math.atan2(y,x); } @ Override public int compareTo(Vec t){ return Double.compare(theta(),t.theta()); } } Main(){ sc=new Scanner(System.in); } void calc(){ N=sc.nextInt(); v=new Vec[N]; for(int i=0 ; imax)max=len ; } } System.out.println(max); } double len(int a,int b){ double x=0d ; double y=0d ; for(int i=a ; i { attribute x : double; operation theta() : double pre: true post: true activity: ( if (x = 0d & y = 0d) then return 0d else skip ; return atan2(y, x) ); operation compareTo( t : Vec) : int pre: true post: true activity: ( return (theta())->compareTo(t.theta()) ); } static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ); operation calc() : void pre: true post: true activity: ( N := sc.getCurrent()->toInteger() ; v := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( v[i+1] := Vec.newVec() ; v[i+1].x := sc.getCurrent()->toInteger() ; v[i+1].y := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; v := v->sort() ; var max : double ; max := -1 ; var a : int ; a := 0 ; while a < N do ( ( var b : int ; b := a + 1 ; while b < a + 1 + N do ( ( var len : double ; len := len(a, b) ; if (len > max) then max := len ; else skip ) ; b := b + 1 ) ) ; a := a + 1 ) ; OclFile["System.out"].println(max) ; ); operation len( a : int, b : int) : double pre: true post: true activity: ( var x : double ; x := 0d ; var y : double ; y := 0d ; var i : int ; i := a ; while i < b do ( ( x := x+(v[i mod N+1].x) ; y := y+(v[i mod N+1].y) ) ; i := i + 1 ) ; return (x * x + y * y)->sqrt() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().calc() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[3]; for(int i=0 ; i0){ int score=0 ; int[] b=Arrays.copyOf(a,3); b[1]--; score++; while(true){ if(b[1]<=0)break ; b[1]--; score++; if(b[2]<=0)break ; b[2]--; score++; } score+=b[0]; if(b[1]>0 || b[2]>0)score++; max=Math.max(max,score); } if(a[2]>0){ int score=0 ; int[] b=Arrays.copyOf(a,3); b[2]--; score++; while(true){ if(b[2]<=0)break ; b[2]--; score++; if(b[1]<=0)break ; b[1]--; score++; } score+=b[0]; if(b[1]>0 || b[2]>0)score++; max=Math.max(max,score); } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[sc.getCurrent()->toInteger() mod 3+1] := a[sc.getCurrent()->toInteger() mod 3+1] + 1 ) ; i := i + 1 ) ; var max : int ; max := 1 ; if (a[1+1] > 0) then ( var score : int ; score := 0 ; var b : Sequence(int) ; b := a.subrange(1,3) ; b[1+1] := b[1+1] - 1 ; score := score + 1 ; while (true) do ( if (b[1+1] <= 0) then break else skip ; b[1+1] := b[1+1] - 1 ; score := score + 1 ; if (b[2+1] <= 0) then break else skip ; b[2+1] := b[2+1] - 1 ; score := score + 1 ; ) ; score := score+(b[0+1]) ; if (b[1+1] > 0 or b[2+1] > 0) then score := score + 1 ; else skip ; max := Set{max, score}->max() ; ) else skip ; if (a[2+1] > 0) then ( var score : int ; score := 0 ; var b : Sequence(int) ; b := a.subrange(1,3) ; b[2+1] := b[2+1] - 1 ; score := score + 1 ; while (true) do ( if (b[2+1] <= 0) then break else skip ; b[2+1] := b[2+1] - 1 ; score := score + 1 ; if (b[1+1] <= 0) then break else skip ; b[1+1] := b[1+1] - 1 ; score := score + 1 ; ) ; score := score+(b[0+1]) ; if (b[1+1] > 0 or b[2+1] > 0) then score := score + 1 ; else skip ; max := Set{max, score}->max() ; ) else skip ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ try(Scanner sc=new Scanner(System.in)){ int n=Integer.parseInt(sc.next()); int[] a=new int[3]; for(int i=0 ; ia[2]){ cnt+=a[2]*2 ; cnt+=Math.min(3,a[1]-a[2]); } else { cnt+=a[1]*2 ; cnt+=Math.min(3,a[2]-a[1]); } } else { cnt=1 ; } System.out.println(cnt); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := (sc.getCurrent())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var p : int ; p := (sc.getCurrent())->toInteger() ; a[p mod 3+1] := a[p mod 3+1] + 1 ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; if (a[1+1] /= 0 or a[2+1] /= 0) then ( cnt := cnt+(a[0+1]) ; if (a[1+1] > a[2+1]) then ( cnt := cnt+(a[2+1] * 2) ; cnt := cnt+(Set{3, a[1+1] - a[2+1]}->min()) ) else ( cnt := cnt+(a[1+1] * 2) ; cnt := cnt+(Set{3, a[2+1] - a[1+1]}->min()) ) ) else ( cnt := 1 ) ; OclFile["System.out"].println(cnt) ; )) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int N=sc.nextInt(); int[] a=new int[3]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( a[sc.getCurrent()->toInteger() mod 3+1] := a[sc.getCurrent()->toInteger() mod 3+1] + 1 ) ; i := i + 1 ) ; if (a[1+1] = 0 & a[2+1] = 0) then ( OclFile["System.out"].println(1) ) else ( var ans : int ; ans := a[0+1] ; ans := ans+(Set{a[1+1], a[2+1]}->min() * 2) ; ans := ans+(Set{3, Set{a[1+1], a[2+1]}->max() - Set{a[1+1], a[2+1]}->min()}->min()) ; OclFile["System.out"].println(ans) ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class MyClass { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s[]=br.readLine().split(" "); int n=Integer.parseInt(s[0]); for(int i=0 ; isplit(" ") ; var n : int ; n := (s[0+1])->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( s := br.readLine()->split(" ") ; var k : long ; k := (s[0+1])->toLong() ; var x : long ; x := (s[1+1])->toLong() ; var ans : long ; ans := x + (k - 1) * 9 ; OclFile["System.out"].println(ans) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] modCounts=new int[3]; for(int i=0 ; itoInteger() ; var modCounts : Sequence(int) ; modCounts := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( modCounts[sc.getCurrent()->toInteger() mod 3+1] := modCounts[sc.getCurrent()->toInteger() mod 3+1] + 1 ) ; i := i + 1 ) ; if (modCounts[1+1] = 0 & modCounts[2+1] = 0) then ( OclFile["System.out"].println(1) ) else if (modCounts[1+1] = modCounts[2+1]) then ( OclFile["System.out"].println(n) ) else if (modCounts[1+1] < modCounts[2+1]) then ( modCounts[2+1] := modCounts[2+1]-(modCounts[1+1]) ; OclFile["System.out"].println(Set{n, n - (modCounts[2+1] - 3)}->min()) ) else ( modCounts[1+1] := modCounts[1+1]-(modCounts[2+1]) ; OclFile["System.out"].println(Set{n, n - (modCounts[1+1] - 3)}->min()) ) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Divisible { public static int gcd(int a,int b){ return b==0 ? a : gcd(b,a % b); } static boolean isDivisible(int x,int y){ if(y==1)return true ; int z=gcd(x,y); if(z==1)return false ; return isDivisible(x,y/z); } public static void main(String[] args){ int x=18,y=12 ; if(isDivisible(x,y))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class Divisible { static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if b = 0 then a else gcd(b, a mod b) endif ); static operation isDivisible( x : int, y : int) : boolean pre: true post: true activity: ( if (y = 1) then return true else skip ; var z : int ; z := gcd(x, y) ; if (z = 1) then return false else skip ; return isDivisible(x, y / z) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 18 ; var y : int ; y := 12 ; if (isDivisible(x, y)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int nthTerm(int N){ int nth=0,first_term=4 ; int pi=1,po=1 ; int n=N ; while(n>1){ pi*=n-1 ; n--; po*=2 ; } nth=(first_term*pi)/po ; return nth ; } public static void main(String[] args){ int N=5 ; System.out.print(nthTerm(N)+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation nthTerm( N : int) : int pre: true post: true activity: ( var nth : int ; nth := 0 ; var first_term : int ; first_term := 4 ; var pi : int ; pi := 1 ; var po : int ; po := 1 ; var n : int ; n := N ; while (n > 1) do ( pi := pi*(n - 1) ; n := n - 1 ; po := po*(2) ) ; nth := (first_term * pi) / po ; return nth ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 5 ; OclFile["System.out"].print(nthTerm(N) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int sum(int N,int X,int Y){ int S1,S2,S3 ; S1=((N/X))*(2*X+(N/X-1)*X)/2 ; S2=((N/Y))*(2*Y+(N/Y-1)*Y)/2 ; S3=((N/(X*Y)))*(2*(X*Y)+(N/(X*Y)-1)*(X*Y))/2 ; return S1+S2-S3 ; } public static void main(String[] args){ int N=14 ; int X=3,Y=5 ; System.out.println(sum(N,X,Y)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sum( N : int, X : int, Y : int) : int pre: true post: true activity: ( var S1 : int ; var S2 : int ; var S3 : int ; S1 := ((N / X)) * (2 * X + (N / X - 1) * X) / 2 ; S2 := ((N / Y)) * (2 * Y + (N / Y - 1) * Y) / 2 ; S3 := ((N / (X * Y))) * (2 * (X * Y) + (N / (X * Y) - 1) * (X * Y)) / 2 ; return S1 + S2 - S3 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 14 ; var X : int ; X := 3 ; var Y : int ; Y := 5 ; OclFile["System.out"].println(sum(N, X, Y)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isUnary(int n){ if(n==1 || n==7)return true ; else if(n/10==0)return false ; int x,sum=0 ; while(n!=0){ x=n % 10 ; sum=sum+x*x ; n=n/10 ; } return isUnary(sum); } static int countUnary(int a,int b){ int count=0 ; for(int i=a ; i<=b ; i++){ if(isUnary(i)==true)count++; } return count ; } public static void main(String[] args){ int a=1000,b=1099 ; System.out.println(countUnary(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isUnary( n : int) : boolean pre: true post: true activity: ( if (n = 1 or n = 7) then return true else if (n / 10 = 0) then return false else skip ; ; var x : int ; var sum : int ; sum := 0 ; while (n /= 0) do ( x := n mod 10 ; sum := sum + x * x ; n := n / 10 ) ; return isUnary(sum) ); static operation countUnary( a : int, b : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := a ; while i <= b do ( ( if (isUnary(i) = true) then count := count + 1 ; else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 1000 ; var b : int ; b := 1099 ; OclFile["System.out"].println(countUnary(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findLength(String str){ int n=str.length(); int maxlen=0 ; for(int i=0 ; isize() ; var maxlen : int ; maxlen := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var length : int ; length := j - i + 1 ; var leftsum : int ; leftsum := 0 ; var rightsum : int ; rightsum := 0 ; var k : int ; k := 0 ; while k < length / 2 do ( ( leftsum := leftsum+((str->at(i + k+1) - ('0')->char2byte())) ; rightsum := rightsum+((str->at(i + k + length / 2+1) - ('0')->char2byte())) ) ; k := k + 1 ) ; if (leftsum = rightsum & maxlen < length) then maxlen := length ; else skip ) ; j := j+(2) ) ) ; i := i + 1 ) ; return maxlen ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "1538023" ; OclFile["System.out"].println("Length of the substring is " + findLength(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static void findFirstAndLast(int arr[],int x){ int n=arr.length ; int first=-1,last=-1 ; for(int i=0 ; isize() ; var first : int ; first := -1 ; var last : int ; last := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (x /= arr[i+1]) then continue else skip ; if (first = -1) then first := i ; else skip ; last := i ) ; i := i + 1 ) ; if (first /= -1) then ( OclFile["System.out"].println("First Occurrence=" + first) ; OclFile["System.out"].println("Last Occurrence=" + last) ) else OclFile["System.out"].println("Not Found") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,2,2,2,3,4,7,8,8} ; var x : int ; x := 8 ; execute findFirstAndLast(arr, x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { private static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); private static String input ; public static void main(String[] args)throws IOException { input=in.readLine(); boolean brackets=input.charAt(0)=='-' ; StringBuilder ans=new StringBuilder("."); int count=0 ; int last_int=-1 ; boolean flag=false ; for(int i=0 ; i=0 && input.charAt(i)!='-' ; i--,j++){ ans.insert(0,input.charAt(i)); if(j % 3==0 && i!=0){ ans.insert(0,','); j=0 ; } } if(ans.charAt(0)==',')ans.delete(0,1); ans.insert(0,'$'); if(brackets){ ans.append(')'); ans.insert(0,'('); } System.out.println(ans.toString()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute input : String; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( input := in.readLine() ; var brackets : boolean ; brackets := input->at(0+1) = '-' ; var ans : String ; ans := StringLib.newString(".") ; var count : int ; count := 0 ; var last_int : int ; last_int := -1 ; var flag : boolean ; flag := false ; var i : int ; i := 0 ; while i < input->size() & count < 2 do ( ( if (input->at(i+1) = '.') then ( flag := true ; last_int := i - 1 ) else skip ; if (flag & input->at(i+1) /= '.') then ( ans := ans + StringLib.newString(input->at(i+1)) ; count := count + 1 ) else skip ) ; i := i + 1 ) ; while (ans->size() < 3) do ans := ans + StringLib.newString('0') ; ; if (last_int = -1) then last_int := input->size() - 1 ; else skip ; var i : int ; i := last_int ; var j : int ; j := 1 ; while i >= 0 & input->at(i+1) /= '-' do ( ( ans := ans.insertAt(0+1, StringLib.newString(input->at(i+1))) ; if (j mod 3 = 0 & i /= 0) then ( ans := ans.insertAt(0+1, StringLib.newString(',')) ; j := 0 ) else skip ) ; i := i - 1 ; j := j + 1 ) ; if (ans->at(0+1) = ',') then ans := ans->antirestrict( Integer.subrange(0+1,1) ) ; else skip ; ans := ans.insertAt(0+1, StringLib.newString('$')) ; if (brackets) then ( ans := ans + StringLib.newString(')') ; ans := ans.insertAt(0+1, StringLib.newString('(')) ) else skip ; OclFile["System.out"].println(ans+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static class Engine { int x,y ; public Engine(int x,int y){ this.x=x ; this.y=y ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); Engine[] engine=new Engine[N]; for(int i=0 ; i(){ public int compare(Engine e1,Engine e2){ if(e1.x==0){ if(e1.y>=0){ return-1 ; } else { return(e2.x==0 && e2.y>=0)|| e2.x<0 ? 1 :-1 ; } } if(e2.x==0){ if(e2.y>=0){ return 1 ; } else { return(e1.x==0 && e1.y>=0)|| e1.x<0 ?-1 : 1 ; } } if(e1.x<0 && e2.x>0){ return-1 ; } if(e1.x>0 && e2.x<0){ return 1 ; } return Long.compare((long)e2.x*e1.y,(long)e1.x*e2.y); } } ); double max=0 ; for(int i=0 ; itoInteger() ; var engine : Sequence(Engine) ; engine := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( engine[i+1] := Engine.newEngine(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; engine := OclComparator.sortWith(engine, OclComparator.newOclComparator()) ; var max : double ; max := 0 ; var i : int ; i := 0 ; while i < N do ( ( var x : long ; x := 0 ; var y : long ; y := 0 ; var j : int ; j := 0 ; while j < N do ( ( x := x+(engine[(i + j) mod N+1].x) ; y := y+(engine[(i + j) mod N+1].y) ; max := Set{max, (x * x + y * y)->sqrt()}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static void main(String args[]){ int n=3 ; int a[]={ 1,2,3 }; int i=0 ; long sum=0 ; for(i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int x=Integer.parseInt(scan.next()); boolean bool=x==1 ? true : false ; int result=! bool ? 1 : 0 ; PrintWriter out=new PrintWriter(System.out); out.println(result); out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := (scan.getCurrent())->toInteger() ; var bool : boolean ; bool := if x = 1 then true else false endif ; var result : int ; result := if not(bool) then 1 else 0 endif ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static float squareArea(float l,float b,float h){ if(l<0 || b<0 || h<0)return-1 ; float a=(l*b)/(l+b); return a*a ; } public static void main(String[] args){ float l=5,b=12,h=13 ; System.out.println(squareArea(l,b,h)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation squareArea( l : double, b : double, h : double) : double pre: true post: true activity: ( if (l < 0 or b < 0 or h < 0) then return -1 else skip ; var a : double ; a := (l * b) / (l + b) ; return a * a ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : double ; l := 5 ; var b : double ; b := 12 ; var h : double ; h := 13 ; OclFile["System.out"].println(squareArea(l, b, h)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { public static long findWays(int m,int n,int x){ long[][] table=new long[n+1][x+1]; for(int j=1 ; j<=m && j<=x ; j++)table[1][j]=1 ; for(int i=2 ; i<=n ; i++){ for(int j=1 ; j<=x ; j++){ for(int k=1 ; kcollect(Integer.subrange(1,x + 1)->collect(0)) ; var j : int ; j := 1 ; while j <= m & j <= x do ( table[1+1][j+1] := 1 ; ; j := j + 1 ) ; var i : int ; i := 2 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= x do ( ( var k : int ; k := 1 ; while k < j & k <= m do ( table[i+1][j+1] := table[i+1][j+1]+(table[i - 1+1][j - k+1]) ; ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return table[n+1][x+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(findWays(4, 2, 1)) ; OclFile["System.out"].println(findWays(2, 2, 3)) ; OclFile["System.out"].println(findWays(6, 3, 8)) ; OclFile["System.out"].println(findWays(4, 2, 5)) ; OclFile["System.out"].println(findWays(4, 3, 5)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.util.InputMismatchException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.TreeSet ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskC solver=new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC { public void solve(int testNumber,InputReader in,PrintWriter out){ String s=in.nextString(); int k=in.nextInt(); TreeSettreeSet=new TreeSet<>(); for(int i=1 ; i<=k ; i++){ for(int j=0 ; j+i<=s.length(); j++){ treeSet.add(s.substring(j,j+i)); } } for(int i=0 ; isize() do ( ( treeSet := treeSet->including(s.subrange(j+1,j + i)) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < (k)->char2byte() - 1 do ( ( treeSet := treeSet->tail() ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute in : OclFile; attribute tok : OclIterator; operation nextString() : String pre: true post: true activity: ( while (not(tok.hasNext())) do ( try ( tok := OclIterator.newOclIterator_String_String(in.readLine(), " ") ) catch (e : IOException) do ( error IncorrectElementException() ) ) ; return tok.next() ); operation nextInt() : int pre: true post: true activity: ( return (nextString())->toInteger() ); static operation newInputReader( inputStream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(inputStream); return self ); operation initialise( inputStream : OclFile) : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(inputStream)) ; tok := OclIterator.newOclIterator_String("") ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.HashSet ; import java.util.List ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String s=sc.next(); int k=sc.nextInt(); Setset=new HashSet<>(); for(int i=0 ; is.length()){ break ; } String sub=s.substring(i,i+j); set.add(sub); } } Listlist=new ArrayList<>(set); Collections.sort(list); System.out.println(list.get(k-1)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var s : String ; s := sc.getCurrent() ; var k : int ; k := sc.getCurrent()->toInteger() ; var set : Set(String) ; set := Set{} ; var i : int ; i := 0 ; while i < s->size() do ( ( var j : int ; j := 1 ; while j <= 5 do ( ( if (i + j > s->size()) then ( break ) else skip ; var sub : String ; sub := s.subrange(i+1,i + j) ; set := set->including(sub) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var list : Sequence(String) ; list := Sequence{}->union(set) ; list := list->sort() ; OclFile["System.out"].println(list->at((k)->char2byte() - 1+1)) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); int k=sc.nextInt(); ArrayListss=new ArrayList<>(); int n=s.length(); for(int i=0 ; ius=ss.stream().sorted().distinct().collect(Collectors.toList()); System.out.println(us.get(k-1)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; var k : int ; k := sc.getCurrent()->toInteger() ; var ss : Sequence(String) ; ss := Sequence{} ; var n : int ; n := s->size() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 1 ; while j <= k do ( ( if (i + j <= n) then ( ss := ss->including(s.subrange(i+1,i + j)) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var us : Sequence(String) ; us := ss->sort()->asOrderedSet().collect(Collectors.toList()) ; OclFile["System.out"].println(us->at((k)->char2byte() - 1+1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.function.*; import java.lang.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String S=sc.next(); int N=S.length(); int K=sc.nextInt(); Setsubstrings=new HashSet<>(); for(int i=0 ; isize() ; var K : int ; K := sc.getCurrent()->toInteger() ; var substrings : Set(String) ; substrings := Set{} ; var i : int ; i := 0 ; while i < N do ( var l : int ; l := 1 ; while l <= Set{(N)->char2byte() - i, K}->min() do ( ( substrings := substrings->including(S.subrange(i+1,i + l)) ) ; l := l + 1 ) ; ; i := i + 1 ) ; var a : Sequence(String) ; a := substrings->asSequence() ; a := a->sort() ; OclFile["System.out"].println(a[K - 1+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Iterator ; import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); String s=sc.next(); int k=sc.nextInt(); TreeSetts=new TreeSet<>(); for(int i=1 ; i<=5 && i<=s.length(); i++){ for(int j=0 ; j<=s.length()-i ; j++){ ts.add(s.substring(j,i+j)); } } Iterator ite=ts.iterator(); for(int i=0 ; itoInteger() ; var ts : Set(String) ; ts := Set{} ; var i : int ; i := 1 ; while i <= 5 & i <= s->size() do ( ( var j : int ; j := 0 ; while j <= s->size() - i do ( ( ts := ts->including(s.subrange(j+1,i + j)) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ite : OclIterator ; ite := ts->iterator() ; var i : int ; i := 0 ; while i < (k)->char2byte() - 1 do ( ( ite.next() ) ; i := i + 1 ) ; OclFile["System.out"].println(ite.next()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int N=3 ; static int M=7 ; static void printOriginalMatrix(int a[],int b[],int[][] mat){ for(int i=0 ; imin() + " ") ; else OclFile["System.out"].print("0" + " ") ; ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,1,3} ; var b : Sequence(int) ; b := Sequence{2,3,0,0,2,0,1} ; var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{1,0,0,0,1,0,0},Sequence{0,0,0,0,0,0,1},Sequence{1,1,0,0,0,0,0}} ; execute printOriginalMatrix(a, b, mat) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printPattern(int n){ int i,j ; for(i=1 ; i<=n ; i++){ for(j=1 ; j<2*n ; j++){ if(j==(n-i+1)|| j==(n+i-1)){ System.out.print("*"); } else if((i>=4 && i<=n-4)&&(j==n-i+4 || j==n+i-4)){ System.out.print("*"); } else if(i==n ||(i==n-4 && j>=n-(n-2*4)&& j<=n+n-2*4)){ System.out.print("*"); } else { System.out.print(" "+" "); } } System.out.print("\n"); } } public static void main(String[] args){ int N=9 ; printPattern(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printPattern( n : int) : void pre: true post: true activity: ( var i : int ; var j : int ; i := 1 ; while i <= n do ( ( j := 1 ; while j < 2 * n do ( ( if (j = (n - i + 1) or j = (n + i - 1)) then ( OclFile["System.out"].print("*") ) else if ((i >= 4 & i <= n - 4) & (j = n - i + 4 or j = n + i - 4)) then ( OclFile["System.out"].print("*") ) else if (i = n or (i = n - 4 & j >= n - (n - 2 * 4) & j <= n + n - 2 * 4)) then ( OclFile["System.out"].print("*") ) else ( OclFile["System.out"].print(" " + " ") ) ; ; ) ; j := j + 1 ) ; OclFile["System.out"].print("\n") ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 9 ; execute printPattern(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } class Node implements Comparable{ double x,y ; public Node(double x,double y){ this.x=x ; this.y=y ; } @ Override public int compareTo(Node o){ return Double.compare(Math.atan2(y,x),Math.atan2(o.y,o.x)); } } void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); double[] X=new double[N]; double[] Y=new double[N]; Node[] nodes=new Node[N]; for(int i=0 ; i { attribute x : double; static operation newNode( x : double, y : double) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(x, y); return self ); operation initialise( x : double, y : double) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation compareTo( o : Node) : int pre: true post: true activity: ( return (atan2(y, x))->compareTo(atan2(o.y, o.x)) ); } operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var X : Sequence(double) ; X := Integer.subrange(1,N)->collect(0.0) ; var Y : Sequence(double) ; Y := Integer.subrange(1,N)->collect(0.0) ; var nodes : Sequence(Node) ; nodes := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( X[i+1] := sc.getCurrent()->toReal() ; Y[i+1] := sc.getCurrent()->toReal() ; nodes[i+1] := Node.newNode(X[i+1], Y[i+1]) ) ; i := i + 1 ) ; nodes := nodes->sort() ; var ans : double ; ans := 0 ; var i : int ; i := 0 ; while i < N do ( ( var curx : double ; curx := 0 ; var cury : double ; cury := 0 ; var j : int ; j := 0 ; while j < N do ( ( curx := curx+(nodes[(i + j) mod N+1].x) ; cury := cury+(nodes[(i + j) mod N+1].y) ; ans := Set{ans, curx * curx + cury * cury}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; ans := (ans)->sqrt() ; OclFile["System.out"].println(ans) ; ); static operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); int count=0 ; for(int i=0 ; itoInteger() ; var s : String ; s := sc.getCurrent() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (s->at(i+1) = '8') then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{count, n / 11}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); while(true){ int n=stdIn.nextInt(); if(n==0){ break ; } long ans=dfs(n); if(ans % 10==0){ ans/=10 ; } else { ans/=10 ; ans+=1 ; } if(ans % 365==0){ System.out.println(ans/365); } else { System.out.println(ans/365+1); } } } public static long dfs(int n){ if(n==0){ return 1 ; } if(n<0){ return 0 ; } long ans=0 ; ans+=dfs(n-1); ans+=dfs(n-2); ans+=dfs(n-3); return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := stdIn.getCurrent()->toInteger() ; if (n = 0) then ( break ) else skip ; var ans : long ; ans := dfs(n) ; if (ans mod 10 = 0) then ( ans := ans/(10) ) else ( ans := ans/(10) ; ans := ans+(1) ) ; if (ans mod 365 = 0) then ( OclFile["System.out"].println(ans / 365) ) else ( OclFile["System.out"].println(ans / 365 + 1) ) ; ) ); static operation dfs( n : int) : long pre: true post: true activity: ( if (n = 0) then ( return 1 ) else skip ; if (n < 0) then ( return 0 ) else skip ; var ans : long ; ans := 0 ; ans := ans+(dfs(n - 1)) ; ans := ans+(dfs(n - 2)) ; ans := ans+(dfs(n - 3)) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { private static int A[]=new int[31]; public static void main(String[] args)throws Exception { A[0]=1 ; A[1]=1 ; A[2]=A[0]+A[1]; for(int i=3 ; icollect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A[0+1] := 1 ; A[1+1] := 1 ; A[2+1] := A[0+1] + A[1+1] ; var i : int ; i := 3 ; while i < A->size() do ( ( var j : int ; j := 0 ; while j < 3 do ( ( A[i+1] := A[i+1]+(A[i + j - 3+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while true do ( ( var N : int ; N := (br.readLine())->toInteger() ; if (N = 0) then break else skip ; OclFile["System.out"].println(year(N)) ) ) ; ); static operation year( n : int) : int pre: true post: true activity: ( var year : double ; year := A[n+1] / 10.0 / 365 ; return (year)->ceil()->oclAsType(int) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.UncheckedIOException ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ SC sc=new SC(System.in); long[] sum=new long[32]; sum[0]=1 ; sum[1]=1 ; sum[2]=2 ; for(int i=3 ; i<=31 ; i++){ sum[i]=sum[i-1]+sum[i-2]+sum[i-3]; } while(true){ int a=sc.nextInt(); if(a==0){ System.exit(0); } else { long yrs=(sum[a]+3649)/3650 ; pl(yrs); } } } public static void pl(Object o){ System.out.println(o); } public static void pl(){ System.out.println(); } public static void p(Object o){ System.out.print(o); } static class SC { private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public SC(InputStream in){ reader=new BufferedReader(new InputStreamReader(in)); } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new UncheckedIOException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public String nextLine(){ try { return reader.readLine(); } catch(IOException e){ throw new UncheckedIOException(e); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : SC ; sc := SC.newSC(OclFile["System.in"]) ; var sum : Sequence(long) ; sum := Integer.subrange(1,32)->collect(0) ; sum[0+1] := 1 ; sum[1+1] := 1 ; sum[2+1] := 2 ; var i : int ; i := 3 ; while i <= 31 do ( ( sum[i+1] := sum[i - 1+1] + sum[i - 2+1] + sum[i - 3+1] ) ; i := i + 1 ) ; while (true) do ( var a : int ; a := sc.nextInt() ; if (a = 0) then ( OclProcess.exit(0) ) else ( var yrs : long ; yrs := (sum[a+1] + 3649) / 3650 ; execute pl(yrs) ) ) ; ); static operation pl( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(o) ); static operation pl() : void pre: true post: true activity: ( OclFile["System.out"].println() ); static operation p( o : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].print(o) ); static class SC { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newSC( in : OclFile) : SC pre: true post: true activity: ( var self : SC ; self := createSC(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ) else skip ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); static int n ; static long[][] dp=new long[31][31]; public static void main(String[] args){ makeDpTable(); while(read()){ solve(); } } static void makeDpTable(){ dp[0][0]=1 ; for(int i=1 ; icollect(Integer.subrange(1,31)->collect(0)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute makeDpTable() ; while (read()) do ( execute solve() ) ); static operation makeDpTable() : void pre: true post: true activity: ( dp[0+1][0+1] := 1 ; var i : int ; i := 1 ; while i < dp->size() do ( ( var j : int ; j := 1 ; while j < dp[0+1]->size() do ( ( var k : int ; k := 1 ; while k <= 3 do ( ( if (j - k < 0) then continue else skip ; dp[i+1][j+1] := dp[i+1][j+1]+(dp[i - 1+1][j - k+1]) ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation read() : boolean pre: true post: true activity: ( n := sc.getCurrent()->toInteger() ; if (n = 0) then return false else skip ; return true ); static operation solve() : void pre: true post: true activity: ( var res : int ; res := 0 ; var i : int ; i := 1 ; while i <= n do ( ( res := res+(dp[i+1][n+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println((res / 10 - 1) / 365 + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public void doIt(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n!=0){ int[] list=new int[30+1]; list[0]=1 ; for(int i=0 ; i<=30 ; i++){ for(int j=1 ; j<=3 ; j++){ if(i-j>=0){ list[i]+=list[i-j]; } } } int result=list[n]; result=result/10 ; result=result/365+1 ; System.out.println(result); n=sc.nextInt(); } } public static void main(String[] args){ Main obj=new Main(); obj.doIt(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation doIt() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; while (n /= 0) do ( var list : Sequence(int) ; list := Integer.subrange(1,30 + 1)->collect(0) ; list[0+1] := 1 ; var i : int ; i := 0 ; while i <= 30 do ( ( var j : int ; j := 1 ; while j <= 3 do ( ( if (i - j >= 0) then ( list[i+1] := list[i+1]+(list[i - j+1]) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var result : int ; result := list[n+1] ; result := result / 10 ; result := result / 365 + 1 ; OclFile["System.out"].println(result) ; n := sc.getCurrent()->toInteger() ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : Main ; obj := Main.newMain() ; obj.doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static void main(String[] args){ int x=10 ; int y=5 ; x=x*y ; y=x/y ; x=x/y ; System.out.println("After swaping:"+" x="+x+",y="+y); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 10 ; var y : int ; y := 5 ; x := x * y ; y := x / y ; x := x / y ; OclFile["System.out"].println("After swaping:" + " x=" + x + ",y=" + y) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { Scanner sc=new Scanner(in); int max(int[] a){ int max=Integer.MIN_VALUE ; for(int i=0 ; isize() do ( ( if (max < a[i+1]) then max := a[i+1] ; else skip ) ; i := i + 1 ) ; return max ); operation run() : void pre: true post: true activity: ( var n : int ; var w : int ; while (true) do ( n := sc.getCurrent()->toInteger() ; w := sc.getCurrent()->toInteger() ; if (n = 0 & w = 0) then break else skip ; var v : Sequence(int) ; v := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( v[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var max : int ; max := max(v) ; var num : int ; num := max / w + 1 ; var x : Sequence(int) ; x := Integer.subrange(1,num)->collect(0) ; for (i : v) do ( x[i / w+1] := x[i / w+1] + 1 ; ) ; var m : int ; m := max(x) ; var ans : double ; ans := 0 ; var i : int ; i := 0 ; while i < num do ( ( ans := ans+((num - i - 1)->oclAsType(double) / (num - 1) * x[i+1] / m) ) ; i := i + 1 ) ; out.println(ans + 0.01) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-9 ; int n ; int w ; int[] h ; void run(){ for(; ; ){ n=sc.nextInt(); w=sc.nextInt(); if((n | w)==0){ break ; } h=new int[20]; int vMax=0 ; int hMax=0 ; for(int i=0 ; ipow(28)))->oclAsType(long); attribute EPS : double := 1e-9; attribute n : int; attribute w : int; attribute h : Sequence(int); operation run() : void pre: true post: true activity: ( while true do ( ( n := sc.getCurrent()->toInteger() ; w := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,w)) = 0) then ( break ) else skip ; h := Integer.subrange(1,20)->collect(0) ; var vMax : int ; vMax := 0 ; var hMax : int ; hMax := 0 ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; h[v / w+1] := h[v / w+1] + 1 ; vMax := Set{vMax, v}->max() ; hMax := Set{hMax, h[v / w+1]}->max() ) ; i := i + 1 ) ; var m : int ; m := vMax / w + 1 ; var ans : double ; ans := 0 ; execute debug("test") ; var i : int ; i := 0 ; while i < m do ( ( var a : double ; a := (m - 1 - i)->oclAsType(double) / (m - 1) ; var b : double ; b := h[i+1]->oclAsType(double) / hMax ; ans := ans+(a * b) ; execute debug("i", i) ; execute debug("a", a) ; execute debug("b", b) ; ) ; i := i + 1 ) ; ans := ans+(0.01) ; execute println("" + ans) ; ) ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: skip; operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try skip catch (e : OclException) do ( e.printStackTrace() ) Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n,w,v,val,h ; double ink ; while(true){ h=0 ; ink=0.01 ; n=sc.nextInt(); w=sc.nextInt(); if(n==0)break ; Listhistogram=new ArrayList<>(); for(int i=0 ; ihistogram.size()-1){ while(v/w>histogram.size()-1)histogram.add(0); } val=histogram.get(v/w)+1 ; if(val>h)h=val ; histogram.set(v/w,val); } double brightness=histogram.size()-1 ; for(int i=0 ; itoInteger() ; w := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var histogram : Sequence(int) ; histogram := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( v := sc.getCurrent()->toInteger() ; if (v / w > histogram->size() - 1) then ( while (v / w > histogram->size() - 1) do histogram := histogram->including(0) ; ) else skip ; val := histogram->at(v / w+1) + 1 ; if (val > h) then h := val ; else skip ; histogram := histogram.setAt(v / w+1,val) ; ) ; i := i + 1 ) ; var brightness : double ; brightness := histogram->size() - 1 ; var i : int ; i := 0 ; while i < histogram->size() do ( ( ink := ink+((histogram->at(i+1) / h->oclAsType(double)) * ((brightness - i) / brightness)) ) ; i := i + 1 ) ; OclFile["System.out"].println(ink) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void segregate0and1(int arr[]){ int type0=0 ; int type1=arr.length-1 ; while(type0size() - 1 ; while (type0 < type1) do ( if (arr[type0+1] = 1) then ( arr[type1+1] := arr[type1+1] + arr[type0+1] ; arr[type0+1] := arr[type1+1] - arr[type0+1] ; arr[type1+1] := arr[type1+1] - arr[type0+1] ; type1 := type1 - 1 ) else ( type0 := type0 + 1 ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var array : Sequence(int) ; array := Sequence{0,1,0,1,1,1} ; execute segregate0and1(array) ; for (a : array) do ( ( OclFile["System.out"].print(a + " ") ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; import java.io.*; public class Hello { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int length=in.nextInt(); String s=in.next(); int c=0 ; for(int i=0 ; itoInteger() ; var s : String ; s := in.getCurrent() ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = '8') then ( c := c + 1 ) else skip ) ; i := i + 1 ) ; var div : int ; div := length / 11 ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.List ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int n=sc.nextInt(); Listl=new LinkedList<>(); for(int i=0 ; itoInteger() ; var l : Sequence(Xy) ; l := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( l := l->including(Xy.newXy(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; l := l.sort(lambda _pars : OclAny in Xy.newXy().hencom(_pars)) ; var max2 : long ; max2 := 0 ; var i : int ; i := 0 ; while i < n do ( ( var rx : long ; rx := 0 ; var ry : long ; ry := 0 ; var j : int ; j := 0 ; while j < n do ( ( rx := rx+(l->at(j+1).x) ; ry := ry+(l->at(j+1).y) ; max2 := Set{rx * rx + ry * ry, max2}->max() ) ; j := j + 1 ) ; var r : Xy ; r := l->at(0+1) ; l := l->including(r) ; ) ; i := i + 1 ) ; OclFile["System.out"].println((max2)->sqrt()) ; ); static class Xy { attribute x : int; attribute y : int; static operation newXy( x : int, y : int) : Xy pre: true post: true activity: ( var self : Xy ; self := createXy(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); static operation hencom( s1 : Xy, s2 : Xy) : int pre: true post: true activity: ( return signum(atan2(s1.y, s1.x) - atan2(s2.y, s2.x))->oclAsType(int) ); operation toString() : String pre: true post: true activity: ( return "[" + x + "," + y + "] " ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in=new Scanner(System.in); static final PrintWriter out=new PrintWriter(System.out,false); static boolean debug=false ; static boolean solve(){ int n=in.nextInt(); int w=in.nextInt(); if(n+w==0)return false ; int[] v=new int[n]; int[] c=new int[120]; for(int i=0 ; i0)idx=i ; max=Math.max(max,c[i]); } double ans=0 ; for(int i=0 ; i<120 ; i++){ ans+=c[i]/max*(1-i/idx); } out.printf("%.6f\n",ans+0.01); return true ; } public static void main(String[] args){ debug=args.length>0 ; long start=System.nanoTime(); while(solve()); out.flush(); long end=System.nanoTime(); dump((end-start)/1000000+" ms"); in.close(); out.close(); } static void dump(Object...o){ if(debug)System.err.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"], false); static attribute debug : boolean := false; static operation solve() : boolean pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var w : int ; w := in.getCurrent()->toInteger() ; if (n + w = 0) then return false else skip ; var v : Sequence(int) ; v := Integer.subrange(1,n)->collect(0) ; var c : Sequence(int) ; c := Integer.subrange(1,120)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( v[i+1] := in.getCurrent()->toInteger() ; c[v[i+1] / w+1] := c[v[i+1] / w+1] + 1 ) ; i := i + 1 ) ; var max : double ; max := 0 ; var idx : double ; idx := 0 ; var i : int ; i := 0 ; while i < 120 do ( ( if (c[i+1] > 0) then idx := i ; else skip ; max := Set{max, c[i+1]}->max() ) ; i := i + 1 ) ; var ans : double ; ans := 0 ; var i : int ; i := 0 ; while i < 120 do ( ( ans := ans+(c[i+1] / max * (1 - i / idx)) ) ; i := i + 1 ) ; skip ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( debug := args->size() > 0 ; var start : long ; start := nanoTime() ; while (solve()) do ; skip ; var end : long ; end := nanoTime() ; execute dump((end - start) / 1000000 + " ms") ; skip ; skip ; ); static operation dump( o : Sequence(OclAny)) : void pre: true post: true activity: ( if (debug) then OclFile["System.err"].println((o + "")) ; else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; class Main { public static Scanner sc=new Scanner(in); public static Random rand=new Random(); public void run(){ while(true){ int n=sc.nextInt(); int w=sc.nextInt(); if(n==0)return ; int[] v=nextIntArray(n); int[] dat=new int[100/w+1]; for(int i=0 ; imax)max=dat[i]; if(dat[i]!=0)l=i ; } double res=0 ; for(int i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; if (n = 0) then return else skip ; var v : Sequence(int) ; v := nextIntArray(n) ; var dat : Sequence(int) ; dat := Integer.subrange(1,100 / w + 1)->collect(0) ; var i : int ; i := 0 ; while i < v->size() do ( ( dat[v[i+1] / w+1] := dat[v[i+1] / w+1] + 1 ) ; i := i + 1 ) ; var max : int ; max := 0 ; var l : int ; l := 0 ; var i : int ; i := 0 ; while i < dat->size() do ( ( if (dat[i+1] > max) then max := dat[i+1] ; else skip ; if (dat[i+1] /= 0) then l := i ; else skip ) ; i := i + 1 ) ; var res : double ; res := 0 ; var i : int ; i := 0 ; while i < l do ( ( res := res+(dat[i+1]->oclAsType(double) / max * (l - i) / (l)) ) ; i := i + 1 ) ; res := res+(0.01) ; execute ln(res) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; return res ); static operation pr( o : OclAny) : void pre: true post: true activity: ( out.print(o) ); static operation ln( o : OclAny) : void pre: true post: true activity: ( out.println(o) ); static operation ln() : void pre: true post: true activity: ( out.println() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=1000000 ; static boolean[] prime=new boolean[MAX]; static void SieveOfEratosthenes(){ for(int i=0 ; iv=new Vector<>(); for(int i=2 ; i0){ sum+=v.get(skip); skip++; k--; } return sum ; } public static void main(String[] args){ int k=3 ; System.out.println(sumPrime(k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 1000000; static attribute prime : Sequence(boolean) := Integer.subrange(1,MAX)->collect(false); static operation SieveOfEratosthenes() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < MAX do ( prime[i+1] := true ; ; i := i + 1 ) ; var p : int ; p := 2 ; while p * p < MAX do ( ( if (prime[p+1]) then ( var i : int ; i := p * p ; while i < MAX do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ); static operation sumPrime( k : int) : int pre: true post: true activity: ( execute SieveOfEratosthenes() ; var v : Sequence(int) ; v := Sequence{} ; var i : int ; i := 2 ; while i < MAX do ( ( if (prime[i+1]) then v := v->including(i) ; else skip ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var skip : int ; skip := (k * (k - 1)) / 2 ; while (k > 0) do ( sum := sum+(v->at(skip+1)) ; skip := skip + 1 ; k := k - 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 3 ; OclFile["System.out"].println(sumPrime(k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.*; import java.io.*; public class a171 { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t>0){ int n=Integer.parseInt(br.readLine()); String[] s=br.readLine().split(" "); int[] arr=new int[n]; long tsum=0 ; for(int i=0 ; i=0){ sum+=arr[i]; ans=Math.max(ans,sum); } else { sum=0 ; } } sum=0 ; for(int i=1 ; i=0){ sum+=arr[i]; ans=Math.max(ans,sum); } else { sum=0 ; } } if(tsum>ans){ System.out.println("YES"); } else { System.out.println("NO"); } t--; } } } ------------------------------------------------------------ OCL File: --------- class a171 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var t : int ; t := (br.readLine())->toInteger() ; while (t > 0) do ( var n : int ; n := (br.readLine())->toInteger() ; var s : Sequence(String) ; s := br.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var tsum : long ; tsum := 0 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (s[i+1])->toInteger() ; tsum := tsum+(arr[i+1]) ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var ans : long ; ans := -1 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (sum + arr[i+1] >= 0) then ( sum := sum+(arr[i+1]) ; ans := Set{ans, sum}->max() ) else ( sum := 0 ) ) ; i := i + 1 ) ; sum := 0 ; var i : int ; i := 1 ; while i < n do ( ( if (sum + arr[i+1] >= 0) then ( sum := sum+(arr[i+1]) ; ans := Set{ans, sum}->max() ) else ( sum := 0 ) ) ; i := i + 1 ) ; if (tsum > ans) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class cupcakes { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t,j,n,i,c,p,k ; long a[],s1,s2 ; t=sc.nextInt(); for(j=1 ; j<=t ; j++){ n=sc.nextInt(); a=new long[n]; s1=0 ; s2=0 ; c=0 ; p=-1 ; for(i=0 ; i=0 && p==-1)p=i ; s1+=a[i]; } if(p==-1){ System.out.println("NO"); continue ; } for(i=p ; i0 && a[i]>0 && a[i-1]<0){ if(s2<=0){ p=i ; s2=0 ; } } s2+=a[i]; if(s2>=s1)break ; } if(i==n ||(p==0 && i==n-1))System.out.println("YES"); else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class cupcakes { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; var j : int ; var n : int ; var i : int ; var c : int ; var p : int ; var k : int ; var a : Sequence(void) ; var s1 : long ; var s2 : long ; t := sc.getCurrent()->toInteger() ; j := 1 ; while j <= t do ( ( n := sc.getCurrent()->toInteger() ; a := Integer.subrange(1,n)->collect(0) ; s1 := 0 ; s2 := 0 ; c := 0 ; p := -1 ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; i := 0 ; while i < n do ( ( if (a[i+1] >= 0 & p = -1) then p := i ; else skip ; s1 := s1+(a[i+1]) ) ; i := i + 1 ) ; if (p = -1) then ( OclFile["System.out"].println("NO") ; continue ) else skip ; i := p ; while i < n do ( ( if (i > 0 & a[i+1] > 0 & a[i - 1+1] < 0) then ( if (s2 <= 0) then ( p := i ; s2 := 0 ) else skip ) else skip ; s2 := s2+(a[i+1]) ; if (s2 >= s1) then break else skip ) ; i := i + 1 ) ; if (i = n or (p = 0 & i = n - 1)) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ int n=sc.nextInt(); int[] table=new int[n]; for(int i=0 ; i=0 ; i--){ sum+=(long)table[i]; if(sum<=0){ flag=true ; } } if(flag){ System.out.println("NO"); continue ; } System.out.println("YES"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := sc.getCurrent()->toInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var table : Sequence(int) ; table := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( table[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var flag : boolean ; flag := false ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(table[i+1]->oclAsType(long)) ; if (sum <= 0) then ( flag := true ) else skip ) ; i := i + 1 ) ; if (flag) then ( OclFile["System.out"].println("NO") ; continue ) else skip ; sum := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( sum := sum+(table[i+1]->oclAsType(long)) ; if (sum <= 0) then ( flag := true ) else skip ) ; i := i - 1 ) ; if (flag) then ( OclFile["System.out"].println("NO") ; continue ) else skip ; OclFile["System.out"].println("YES") ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Solution { static MyScanner str=new MyScanner(); public static void main(String[] args)throws IOException { long T=l(); while(T-->0){ solve(); } } static void solve()throws IOException { int n=i(); int a[]=new int[n]; for(int i=0 ; i=0 ; i--){ sum+=a[i]; if(sum<=0){ System.out.println("NO"); return ; } } System.out.println("YES"); } public static int i()throws IOException { return str.nextInt(); } public static long l()throws IOException { return str.nextLong(); } public static double d()throws IOException { return str.nextDouble(); } public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Solution { static attribute str : MyScanner := MyScanner.newMyScanner(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var T : long ; T := l() ; while (T > 0) do ( T := T - 1 ; skip ; ( execute solve() ) ; ) ); static operation solve() : void pre: true post: true activity: ( var n : int ; n := i() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := i() ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(a[i+1]) ; if (sum <= 0) then ( OclFile["System.out"].println("NO") ; return ) else skip ) ; i := i + 1 ) ; sum := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( sum := sum+(a[i+1]) ; if (sum <= 0) then ( OclFile["System.out"].println("NO") ; return ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println("YES") ; ); static operation i() : int pre: true post: true activity: ( return str.nextInt() ); static operation l() : long pre: true post: true activity: ( return str.nextLong() ); static operation d() : double pre: true post: true activity: ( return str.nextDouble() ); static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX=1000005 ; static Vectorprime=new Vector<>(MAX); static void vecIni(){ for(int i=0 ; iat(i+1)) then ( var j : int ; j := 2 ; while i * j <= N do ( ( prime := prime.insertAt(i * j+1,false) ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ); static operation countLogNeeded( N : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; execute seive(N) ; var i : int ; i := 1 ; while i <= N do ( ( if (prime->at(i+1)) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute vecIni() ; var N : int ; N := 6 ; OclFile["System.out"].println(countLogNeeded(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class New_Year_and_Counting_Cards { public static void main(String[] args){ Scanner input=new Scanner(System.in); String name=input.next(); int count=0 ; for(int i=0 ; isize() do ( ( var ch : String ; ch := name->at(i+1) ; if (ch = 'a' or ch = 'e' or ch = 'i' or ch = 'o' or ch = 'u' or ch = '1' or ch = '3' or ch = '5' or ch = '7' or ch = '9') then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Test { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String str=sc.next(); int eightCount=0 ; for(int i=0 ; i0 && n>=11){ n-=11 ; counter+=1 ; } System.out.println(counter); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var str : String ; str := sc.getCurrent() ; var eightCount : int ; eightCount := 0 ; var i : int ; i := 0 ; while i < n do ( ( var val : int ; val := ("" + str->at(i+1))->toInteger() ; if (val = 8) then eightCount := eightCount+(1) ; else skip ) ; i := i + 1 ) ; var counter : int ; counter := 0 ; while (eightCount > 0 & n >= 11) do ( skip ; ( n := n-(11) ; counter := counter+(1) ) ; ) ; OclFile["System.out"].println(counter) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Partition { public static void main(String[] args){ Scanner input=new Scanner(System.in); String x=input.next(); x=x.replaceAll("[a,e,i,o,u] ","a"); x=x.replaceAll("[1,3,5,7,9] ","1"); int c=0 ; for(int i=0 ; isize() do ( ( if (x->at(i+1) = 'a') then ( c := c + 1 ) else if (x->at(i+1) = '1') then ( c := c + 1 ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public ListtopKFrequent(String[] words,int k){ Mapcount=new HashMap(); for(String word : words){ count.put(word,count.getOrDefault(word,0)+1); } PriorityQueueheap=new PriorityQueue((w1,w2)->count.get(w1).equals(count.get(w2))? w2.compareTo(w1): count.get(w1)-count.get(w2)); for(String word : count.keySet()){ heap.offer(word); if(heap.size()>k)heap.poll(); } Listans=new ArrayList(); while(! heap.isEmpty())ans.add(heap.poll()); Collections.reverse(ans); return ans ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation topKFrequent( words : Sequence(String), k : int) : Sequence(String) pre: true post: true activity: ( var count : Map(String,int) ; count := Map{} ; for (word : words) do ( ( count := count->union(Map{word |-> (if count->keys()->contains(word) then count->at(word) else 0 endif) + 1}) ) ) ; var heap : Sequence(String) ; heap := Sequence{}->union(lambda (w1 , w2) : OclAny in if count->at(w1) = count->at(w2) then w2->compareTo(w1) else count->at(w1) - count->at(w2) endif) ; for (word : count->keys()) do ( ( heap := heap->including(word) ; if (heap->size() > k) then heap := heap->sort()->tail() ; else skip ) ) ; var ans : Sequence(String) ; ans := Sequence{} ; while (not(heap->isEmpty())) do ans := ans->including(heap->min()) ; ; ans := ans->reverse() ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NewYearAndCountingCards { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String s=scan.nextLine(); int c=0 ; for(int i=0 ; isize() do ( ( if (s->at(i+1) = 'a' or s->at(i+1) = 'e' or s->at(i+1) = 'i' or s->at(i+1) = 'o' or s->at(i+1) = 'u' or s->at(i+1) = '1' or s->at(i+1) = '3' or s->at(i+1) = '5' or s->at(i+1) = '7' or s->at(i+1) = '9') then ( c := c + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CountCards { public static void main(String[] args){ Scanner in=new Scanner(System.in); String s=in.next(); in.close(); int c=0,i ; for(i=0 ; isize() do ( ( var v : String ; v := s->at(i+1) ; if (v = 'a' or v = 'e' or v = 'i' or v = 'o' or v = 'u' or ((v + "")->isMatch("[0-9]") & (((v) + ""))->toInteger() mod 2 /= 0)) then ( c := c + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class cf908a { public static void main(String[] args){ Scanner sc=new Scanner(System.in); char[] arr=sc.next().toCharArray(); sc.close(); HashSeths=new HashSet<>(); hs.add('a'); hs.add('e'); hs.add('i'); hs.add('o'); hs.add('u'); hs.add('1'); hs.add('3'); hs.add('5'); hs.add('7'); hs.add('9'); int ans=0 ; for(int i=0 ; icharacters() ; skip ; var hs : Set(String) ; hs := Set{} ; hs := hs->including('a') ; hs := hs->including('e') ; hs := hs->including('i') ; hs := hs->including('o') ; hs := hs->including('u') ; hs := hs->including('1') ; hs := hs->including('3') ; hs := hs->including('5') ; hs := hs->including('7') ; hs := hs->including('9') ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < arr->size() do ( ( ans := ans+(if hs->includes(arr[i+1]) then 1 else 0 endif) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayList>graph=new ArrayList<>(); for(int i=0 ; i()); } for(int i=0 ; iqueue=new PriorityQueue<>(); queue.add(new Path(0,0)); while(queue.size()>0){ Path p=queue.poll(); if(costs[p.idx]<=p.value){ continue ; } costs[p.idx]=p.value ; for(Map.Entryentry : graph.get(p.idx).entrySet()){ queue.add(new Path(entry.getKey(),entry.getValue()+p.value)); } } StringBuilder sb=new StringBuilder(); for(int i=0 ; i{ int idx ; int value ; public Path(int idx,int value){ this.idx=idx ; this.value=value ; } public int compareTo(Path another){ return value-another.value ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var graph : Sequence(Map(int,int)) ; graph := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( graph := graph->including(Map{}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var from : int ; from := sc.getCurrent()->toInteger() ; var count : int ; count := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < count do ( ( graph := graph->at(from+1)->union(Map{sc.getCurrent()->toInteger() |-> sc.getCurrent()->toInteger()}) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var costs : Sequence(int) ; costs := Integer.subrange(1,n)->collect(0) ; costs := costs->collect(2147483647) ; var queue : Sequence(String) ; queue := Sequence{} ; queue := queue->including(String(0, 0)) ; while (queue->size() > 0) do ( var p : String ; p := queue->min() ; if (costs[p.idx+1] <= p.value) then ( continue ) else skip ; costs[p.idx+1] := p.value ; for (entry : graph->at(p.idx+1)->asSet()) do ( ( queue := queue->including(String(entry.getKey(), entry.getValue() + p.value)) ) ) ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( sb := sb + StringLib.newString(i) + StringLib.newString(" ") + StringLib.newString(costs[i+1]) + StringLib.newString("\n") ) ; i := i + 1 ) ; OclFile["System.out"].print(sb) ; ); static class Path implements Comparable { attribute idx : int; attribute value : int; static operation newPath( idx : int, value : int) : Path pre: true post: true activity: ( var self : Path ; self := createPath(); self.initialise(idx, value); return self ); operation initialise( idx : int, value : int) : void pre: true post: true activity: ( self.idx := idx ; self.value := value ); operation compareTo( another : String) : int pre: true post: true activity: ( return value - another.value ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class TextVolume { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.nextLine()),c=0,max=0 ; String[] s=sc.nextLine().split("\\s"); for(int i=0 ; imax){ max=c ; } c=0 ; } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class TextVolume { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.nextLine())->toInteger() ; var c : int ; c := 0 ; var max : int ; max := 0 ; var s : Sequence(String) ; s := sc.nextLine()->split("\\s") ; var i : int ; i := 0 ; while i < s->size() do ( ( var j : int ; j := 0 ; while j < s[i+1]->size() do ( ( if ((s[i+1]->at(j+1)->toUpperCase() = s[i+1]->at(j+1))) then ( c := c + 1 ) else skip ) ; j := j + 1 ) ; if (c > max) then ( max := c ) else skip ; c := 0 ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Ishu { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n,i,ans=0,temp=0 ; String str ; n=scan.nextInt(); scan.nextLine(); str=scan.nextLine(); for(i=0 ; i='A' && str.charAt(i)<='Z')++temp ; else if(str.charAt(i)==' '){ if(ans==0)ans=temp ; else if(anstoInteger() ; skip ; str := scan.nextLine() ; i := 0 ; while i < n do ( ( if (str->at(i+1) >= 'A' & str->at(i+1) <= 'Z') then temp := temp + 1 else if (str->at(i+1) = ' ') then ( if (ans = 0) then ans := temp else if (ans < temp) then ans := temp ; else skip ; ; temp := 0 ) else skip ; ; if (i = n - 1) then ( if (ans = 0) then ans := temp ; else if (ans < temp) then ans := temp ; else skip ; ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Ex3 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int q=in.nextInt(); for(int t=0 ; t{ private E value ; private ListNode next ; public ListNode(E newVal,ListNodenewNext){ value=newVal ; next=newNext ; } public E getValue(){ return value ; } public ListNodegetNext(){ return next ; } public void setValue(E newValue){ value=newValue ; } public void setNext(ListNodenewNext){ next=newNext ; } } } ------------------------------------------------------------ OCL File: --------- class Ex3 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := in.getCurrent()->toInteger() ; var t : int ; t := 0 ; while t < q do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,x)->collect(0) ; var i : int ; i := 0 ; while i < x do ( ( arr[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < x / 2 do ( ( OclFile["System.out"].print(arr[i+1] + " " + arr[(x - 1) - i+1] + " ") ) ; i := i + 1 ) ; if (x mod 2 /= 0) then ( OclFile["System.out"].print(arr[(x / 2)+1] + " ") ) else skip ; OclFile["System.out"].println() ; ) ; t := t + 1 ) ); class ListNode { attribute value : E; attribute next : ListNode; static operation newListNode( newVal : E, newNext : ListNode) : ListNode pre: true post: true activity: ( var self : ListNode ; self := createListNode(); self.initialise(newVal, newNext); return self ); operation initialise( newVal : E, newNext : ListNode) : void pre: true post: true activity: ( value := newVal ; next := newNext ); operation getValue() : E pre: true post: true activity: ( return value ); operation getNext() : ListNode pre: true post: true activity: ( return next ); operation setValue( newValue : E) : void pre: true post: true activity: ( value := newValue ); operation setNext( newNext : ListNode) : void pre: true post: true activity: ( next := newNext ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.lang.Math ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); if(n<11){ System.out.println("0"); return ; } input.nextLine(); String[] digits=input.nextLine().split(""); int total=digits.length ; int eights=0 ; for(String s : digits)if(s.equals("8"))eights++; int result=Math.min(eights,total/11); System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; if (n < 11) then ( OclFile["System.out"].println("0") ; return ) else skip ; skip ; var digits : Sequence(String) ; digits := input.nextLine()->split("") ; var total : int ; total := digits->size() ; var eights : int ; eights := 0 ; for (s : digits) do ( if (s = "8") then eights := eights + 1 ; else skip ; ) ; var result : int ; result := Set{eights, total / 11}->min() ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class SpeedRun { static int T ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); StringTokenizer st=new StringTokenizer(br.readLine()); T=Integer.parseInt(st.nextToken()); for(int t=0 ; tout=new ArrayList<>(); st=new StringTokenizer(br.readLine()); for(int i=0 ; itoInteger() ; var t : int ; t := 0 ; while t < T do ( ( st := OclIterator.newOclIterator_String(br.readLine()) ; var N : int ; N := (st.next())->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; var out : Sequence(int) ; out := Sequence{} ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < N do ( ( arr[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; var r : int ; r := N - 1 ; var l : int ; l := 0 ; while (l <= r) do ( out := out->including(arr[l+1]) ; if (l - 1 = r) then continue else skip ; out := out->including(arr[r+1]) ) ; for (i : out) do ( skip ; ) ; skip ; ) ; t := t + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int tests=scanner.nextInt(); for(int test=0 ; testtoInteger() ; var test : int ; test := 0 ; while test < tests do ( execute solve(scanner) ; ; test := test + 1 ) ); static operation solve( scanner : OclFile) : void pre: true post: true activity: ( var number : int ; number := scanner.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,number)->collect(0) ; var i : int ; i := 0 ; while i < number do ( ( arr[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var lo : int ; lo := 0 ; var hi : int ; hi := number - 1 ; OclFile["System.out"].println() ; while (lo < hi) do ( OclFile["System.out"].print(arr[lo+1] + " ") ; OclFile["System.out"].print(arr[hi+1] + " ") ) ; if (lo = hi) then OclFile["System.out"].print(arr[lo+1]) ; else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static HashMapdic=new HashMap<>(); public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long x=sc.nextLong(); long layer=(long)(4*Math.pow(2,n)-3); dic.put(Long.toString(1),1L); long ans=helper(layer,x); System.out.println(ans); } static public long helper(long layer,long x){ String k=Long.toString(layer)+"*"+Long.toString(x); long ans=0 ; if(dic.containsKey(k))return dic.get(k); if(x<=0 || layer==0)return 0 ; if(layer==1)return 1 ; if(x>layer)x=layer ; if(2*x+1<=layer){ ans+=helper((layer-3)/2,x-1); } else { ans+=helper((layer-3)/2,(layer-3)/2); ans+=1 ; if(x==layer)x--; ans+=helper((layer-3)/2,x-(layer+1)/2); } dic.put(k,ans); return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute dic : Map(String,long) := Map{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : long ; x := sc.getCurrent()->toLong() ; var layer : long ; layer := (4 * 2->pow(n) - 3)->oclAsType(long) ; dic := dic->union(Map{((1) + "") |-> 1L}) ; var ans : long ; ans := helper(layer, x) ; OclFile["System.out"].println(ans) ; ); static operation helper( layer : long, x : long) : long pre: true post: true activity: ( var k : String ; k := ((layer) + "") + "*" + ((x) + "") ; var ans : long ; ans := 0 ; if (dic->keys()->includes(k)) then return dic->at(k) else skip ; if (x <= 0 or layer = 0) then return 0 else skip ; if (layer = 1) then return 1 else skip ; if (x > layer) then x := layer ; else skip ; if (2 * x + 1 <= layer) then ( ans := ans+(helper((layer - 3) / 2, x - 1)) ) else ( ans := ans+(helper((layer - 3) / 2, (layer - 3) / 2)) ; ans := ans+(1) ; if (x = layer) then x := x - 1 ; else skip ; ans := ans+(helper((layer - 3) / 2, x - (layer + 1) / 2)) ) ; dic := dic->union(Map{k |-> ans}) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner stdin=new Scanner(System.in); char[] inS=stdin.next().toCharArray(); ListxList=new ArrayList<>(); ListyList=new ArrayList<>(); boolean moveX=true ; int move=0 ; for(char s : inS){ if(s=='F'){ move++; } else { if(moveX){ xList.add(move); moveX=false ; } else { yList.add(move); moveX=true ; } move=0 ; } } if(move>0){ if(moveX){ xList.add(move); } else { yList.add(move); } } int inX=stdin.nextInt()-xList.remove(0); int inY=stdin.nextInt(); Collections.sort(xList); Collections.reverse(xList); Collections.sort(yList); Collections.reverse(yList); String result="No" ; if(check(inX,xList)&& check(inY,yList)){ result="Yes" ; } System.out.println(result); } private static boolean check(int target,Listlist){ for(int move : list){ if(target>0){ target-=move ; } else { target+=move ; } } return target==0 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdin : OclFile ; stdin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var inS : Sequence(String) ; inS := stdin.getCurrent()->characters() ; var xList : Sequence(int) ; xList := Sequence{} ; var yList : Sequence(int) ; yList := Sequence{} ; var moveX : boolean ; moveX := true ; var move : int ; move := 0 ; for (s : inS) do ( ( if (s = 'F') then ( move := move + 1 ) else ( if (moveX) then ( xList := xList->including(move) ; moveX := false ) else ( yList := yList->including(move) ; moveX := true ) ; move := 0 ) ) ) ; if (move > 0) then ( if (moveX) then ( xList := xList->including(move) ) else ( yList := yList->including(move) ) ) else skip ; var inX : int ; inX := stdin.getCurrent()->toInteger() - xList->at(0+1) ; var inY : int ; inY := stdin.getCurrent()->toInteger() ; xList := xList->sort() ; xList := xList->reverse() ; yList := yList->sort() ; yList := yList->reverse() ; var result : String ; result := "No" ; if (check(inX, xList) & check(inY, yList)) then ( result := "Yes" ) else skip ; OclFile["System.out"].println(result) ; ); static operation check( target : int, list : Sequence(int)) : boolean pre: true post: true activity: ( for (move : list) do ( ( if (target > 0) then ( target := target-(move) ) else ( target := target+(move) ) ) ) ; return target = 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); char s[]=sc.next().toCharArray(); int x=sc.nextInt(),y=sc.nextInt(); int dpx[]=new int[16010]; int dpy[]=new int[16010]; int cnt=0 ; int p=0 ; while(pcharacters() ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var dpx : Sequence(int) ; dpx := Integer.subrange(1,16010)->collect(0) ; var dpy : Sequence(int) ; dpy := Integer.subrange(1,16010)->collect(0) ; var cnt : int ; cnt := 0 ; var p : int ; p := 0 ; while (p < s->size() & s[p+1] = 'F') do ( cnt := cnt + 1 ; p := p + 1 ) ; dpx[cnt + 8000+1] := 1 ; dpy[8000+1] := 1 ; cnt := 0 ; p := p + 1 ; var dir : int ; dir := 1 ; while p < s->size() do ( ( if (s[p+1] = 'F') then cnt := cnt + 1 ; else ( if (dir = 1) then execute update(dpy, cnt) else execute update(dpx, cnt) ; ; cnt := 0 ; dir := 1 - dir ) ) ; p := p + 1 ) ; if (cnt /= 0) then ( if (dir = 1) then execute update(dpy, cnt) ; else execute update(dpx, cnt) ; ) else skip ; if (dpx[x + 8000+1] = 1 & dpy[y + 8000+1] = 1) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); static operation update( dp : Sequence(int), n : int) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Integer.subrange(1,dp->size())->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( ( if (dp[i+1] = 1) then ( arr[i - n+1] := 1 ; arr[i + n+1] := 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < dp->size() do ( ( dp[i+1] := arr[i+1] ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); char[] arr=sc.next().toCharArray(); int x=sc.nextInt(); int y=sc.nextInt(); ArrayListxValues=new ArrayList<>(); ArrayListyValues=new ArrayList<>(); boolean isX=true ; boolean isFirst=true ; int value=0 ; for(char c : arr){ if(c=='T'){ if(isFirst){ x-=value ; isX=false ; isFirst=false ; } else if(isX){ xValues.add(value); isX=false ; } else { yValues.add(value); isX=true ; } value=0 ; } else { value++; } } if(isFirst){ x-=value ; } else if(isX){ xValues.add(value); } else { yValues.add(value); } Collections.sort(xValues); Collections.sort(yValues); for(int i=xValues.size()-1 ; i>=0 ; i--){ if(x>=0){ x-=xValues.get(i); } else { x+=xValues.get(i); } } for(int i=yValues.size()-1 ; i>=0 ; i--){ if(y>=0){ y-=yValues.get(i); } else { y+=yValues.get(i); } } if(x==0 && y==0){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var arr : Sequence(String) ; arr := sc.getCurrent()->characters() ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var xValues : Sequence(int) ; xValues := Sequence{} ; var yValues : Sequence(int) ; yValues := Sequence{} ; var isX : boolean ; isX := true ; var isFirst : boolean ; isFirst := true ; var value : int ; value := 0 ; for (c : arr) do ( ( if (c = 'T') then ( if (isFirst) then ( x := x-(value) ; isX := false ; isFirst := false ) else if (isX) then ( xValues := xValues->including(value) ; isX := false ) else ( yValues := yValues->including(value) ; isX := true ) ; ; value := 0 ) else ( value := value + 1 ) ) ) ; if (isFirst) then ( x := x-(value) ) else if (isX) then ( xValues := xValues->including(value) ) else ( yValues := yValues->including(value) ) ; ; xValues := xValues->sort() ; yValues := yValues->sort() ; var i : int ; i := xValues->size() - 1 ; while i >= 0 do ( ( if (x >= 0) then ( x := x-(xValues->at(i+1)) ) else ( x := x+(xValues->at(i+1)) ) ) ; i := i - 1 ) ; var i : int ; i := yValues->size() - 1 ; while i >= 0 do ( ( if (y >= 0) then ( y := y-(yValues->at(i+1)) ) else ( y := y+(yValues->at(i+1)) ) ) ; i := i - 1 ) ; if (x = 0 & y = 0) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); char[] s=scanner.next().toCharArray(); int x=scanner.nextInt(); int y=scanner.nextInt(); List[] a=new List[2]; for(int i=0 ; i<2 ; i++)a[i]=new ArrayList<>(); int i=0 ; while(ic)a[j] .add(i-c); j=1-j ; } if(solve(a[0],Math.abs(x))&& solve(a[1],Math.abs(y))){ System.out.println("Yes"); } else { System.out.println("No"); } } private static boolean solve(Lista,int x){ final int MAX=16001 ; boolean[][] dp=new boolean[a.size()+1][MAX]; dp[0][0]=true ; for(int i=1 ; i<=a.size(); i++){ for(int j=0 ; j=0)dp[i][j] |=dp[i-1][j-v]; if(j+vcharacters() ; var x : int ; x := scanner.getCurrent()->toInteger() ; var y : int ; y := scanner.getCurrent()->toInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,2)->collect(null) ; var i : int ; i := 0 ; while i < 2 do ( a[i+1] := Sequence{} ; ; i := i + 1 ) ; var i : int ; i := 0 ; while (i < s->size() & s[i+1] = 'F') do ( skip ; x := x - 1 ; ; ) ; var j : int ; j := 1 ; while i < s->size() do ( ( var c : int ; c := i ; while (i < s->size() & s[i+1] = 'F') do i := i + 1 ; ; if (i > c) then a[j+1]->excludes(i - c) ; else skip ; j := 1 - j ) ; i := i + 1 ) ; if (solve(a[0+1], if x < 0 then -(x) else x endif) & solve(a[1+1], if y < 0 then -(y) else y endif)) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); static operation solve( a : Sequence(int), x : int) : boolean pre: true post: true activity: ( var MAX : int ; MAX := 16001 ; var dp : Sequence(Sequence(boolean)) ; dp := Integer.subrange(1,a->size() + 1)->collect(Integer.subrange(1,MAX)->collect(false)) ; dp[0+1][0+1] := true ; var i : int ; i := 1 ; while i <= a->size() do ( ( var j : int ; j := 0 ; while j < MAX do ( ( dp[i+1][j+1] := false ; var v : int ; v := a->at(i - 1+1) ; if (j - v >= 0) then dp[i+1][j+1] := MathLib.bitwiseOr(dp[i+1][j+1], dp[i - 1+1][j - v+1]) ; else skip ; if (j + v < MAX) then dp[i+1][j+1] := MathLib.bitwiseOr(dp[i+1][j+1], dp[i - 1+1][j + v+1]) ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[a->size()+1][x+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { private void doit(){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); int m=sc.nextInt(); if((n | m)==0)break ; String[] name=new String[n]; int[] start=new int[n]; int[] end=new int[n]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then break else skip ; var name : Sequence(String) ; name := Integer.subrange(1,n)->collect(null) ; var start : Sequence(int) ; start := Integer.subrange(1,n)->collect(0) ; var end : Sequence(int) ; end := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( name[i+1] := sc.getCurrent() ; var a : int ; a := sc.getCurrent()->toInteger() ; end[i+1] := sc.getCurrent()->toInteger() ; start[i+1] := end[i+1] - a + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( var yy : int ; yy := sc.getCurrent()->toInteger() ; var flg : boolean ; flg := true ; var j : int ; j := 0 ; while j < n do ( ( if (start[j+1] <= yy & yy <= end[j+1]) then ( flg := false ; var res : int ; res := yy - start[j+1] + 1 ; OclFile["System.out"].println(name[j+1] + " " + res) ; break ) else skip ) ; j := j + 1 ) ; if (flg) then ( OclFile["System.out"].println("Unknown") ) else skip ) ; i := i + 1 ) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } Scanner scanner=new Scanner(System.in); int n ; int q ; private class Data implements Comparable{ String en ; int eby ; int wy ; private Data(String en,int eby,int wy){ this.en=en ; this.eby=eby ; this.wy=wy ; } @ Override public int compareTo(Data o){ return wy-o.wy ; } } Data[] db ; private void run(){ for(; nq(); ){ db=new Data[n]; for(int i=0 ; i0){ System.out.println(db[ip] .en+" "+qry.wy); continue ; } } System.out.println("Unknown"); } } } private boolean nq(){ n=scanner.nextInt(); q=scanner.nextInt(); return(n | q)!=0 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute n : int; attribute q : int; class Data implements Comparable { attribute en : String; attribute eby : int; attribute wy : int; static operation newData( en : String, eby : int, wy : int) : Data pre: true post: true activity: ( var self : Data ; self := createData(); self.initialise(en, eby,wy); return self ); operation initialise( en : String, eby : int, wy : int) : void pre: true post: true activity: ( self.en := en ; self.eby := eby ; self.wy := wy ); operation compareTo( o : Data) : int pre: true post: true activity: ( return wy - o.wy ); } attribute db : Sequence(Data); operation run() : void pre: true post: true activity: ( while nq() do ( ( db := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < db->size() do ( ( db[i+1] := Data.newData(scanner.getCurrent(), scanner.getCurrent()->toInteger(), scanner.getCurrent()->toInteger()) ) ; i := i + 1 ) ; db := db->sort() ; var i : int ; i := 0 ; while i < q do ( ( var qry : Data ; qry := Data.newData("", 0, scanner.getCurrent()->toInteger()) ; var ip : int ; ip := (db->indexOf(qry) - 1) ; if (ip < 0) then ( ip := -ip - 1 ) else skip ; if (ip < db->size()) then ( qry.wy := qry.wy - db[ip+1].wy + db[ip+1].eby ; if (qry.wy > 0) then ( OclFile["System.out"].println(db[ip+1].en + " " + qry.wy) ; continue ) else skip ) else skip ; OclFile["System.out"].println("Unknown") ; ) ; i := i + 1 ) ) ) ); operation nq() : boolean pre: true post: true activity: ( n := scanner.getCurrent()->toInteger() ; q := scanner.getCurrent()->toInteger() ; return (MathLib.bitwiseOr(n,q)) /= 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; while((line=br.readLine())!=null && ! line.isEmpty()){ int N,Q ; N=parseInt(line.substring(0,line.indexOf(' '))); Q=parseInt(line.substring(line.indexOf(' ')+1)); if((N | Q)==0)break ; NavigableMapmins=new TreeMap<>(); Mapmaxs=new HashMap<>(); mins.put(0,"Unknown"); maxs.put("Unknown",0); StringTokenizer st ; for(int i=0 ; iisEmpty())) do ( skip ; ( var N : int ; var Q : int ; N := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; Q := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; if ((MathLib.bitwiseOr(N,Q)) = 0) then break else skip ; var mins : NavigableMap ; mins := Map{} ; var maxs : Map(String,int) ; maxs := Map{} ; mins := mins->union(Map{0 |-> "Unknown"}) ; maxs := maxs->union(Map{"Unknown" |-> 0}) ; var st : OclIterator ; var i : int ; i := 0 ; while i < N do ( ( st := OclIterator.newOclIterator_String(br.readLine()) ; var E : String ; var B : int ; var W : int ; E := st.next() ; B := (st.next() + "")->toInteger() ; W := (st.next() + "")->toInteger() ; mins := mins->union(Map{(W)->char2byte() - (B)->char2byte() + 1 |-> E}) ; maxs := maxs->union(Map{E |-> W}) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < Q do ( ( var q : int ; var w : int ; q := (br.readLine() + "")->toInteger() ; w := q - mins.floorKey(q) + 1 ; var e : String ; e := mins.floorEntry(q).getValue() ; if (q <= maxs->at(e)) then ( OclFile["System.out"].println(e + " " + w) ) else ( OclFile["System.out"].println("Unknown") ) ; ) ; i := i + 1 ) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1060A_PhoneNumber { public static void main(String[] args){ Scanner input=new Scanner(System.in); int len=parseInt(input.nextLine()); String str=input.nextLine(); Listchars=new ArrayList<>(); for(char c : str.toCharArray()){ chars.add(c); } int eights=Collections.frequency(chars,'8'); int possibleNums=len/11 ; if(eights>=possibleNums){ System.out.println(possibleNums); } else { System.out.println(eights); } } } ------------------------------------------------------------ OCL File: --------- class _1060A_PhoneNumber { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var len : int ; len := parseInt(input.nextLine()) ; var str : String ; str := input.nextLine() ; var chars : Sequence(String) ; chars := Sequence{} ; for (c : str->characters()) do ( ( chars := chars->including(c) ) ) ; var eights : int ; eights := .frequency(chars, '8') ; var possibleNums : int ; possibleNums := len / 11 ; if (eights >= possibleNums) then ( OclFile["System.out"].println(possibleNums) ) else ( OclFile["System.out"].println(eights) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.LinkedList ; import java.util.List ; import java.util.PriorityQueue ; import java.util.Scanner ; public class Main { public static void main(String[] args){ final Scanner sc=new Scanner(System.in); while(true){ final int Y=sc.nextInt(); final int Q=sc.nextInt(); if(Y==0 && Q==0){ break ; } String names[]=new String[Y]; int[] dec=new int[Y]; int[] years=new int[Y]; for(int i=0 ; itoInteger() ; var Q : int ; Q := sc.getCurrent()->toInteger() ; if (Y = 0 & Q = 0) then ( break ) else skip ; var names : Sequence(String) ; names := Integer.subrange(1,Y)->collect(null) ; var dec : Sequence(int) ; dec := Integer.subrange(1,Y)->collect(0) ; var years : Sequence(int) ; years := Integer.subrange(1,Y)->collect(0) ; var i : int ; i := 0 ; while i < Y do ( ( names[i+1] := sc.getCurrent() ; dec[i+1] := sc.getCurrent()->toInteger() ; years[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < Q do ( ( var y : int ; y := sc.getCurrent()->toInteger() ; var found : boolean ; found := false ; var pos : int ; pos := -1 ; var j : int ; j := 0 ; while j < Y do ( ( if ((years[j+1] - dec[j+1]) < y & y <= years[j+1]) then ( pos := j ; found := true ; break ) else skip ) ; j := j + 1 ) ; if (not(found)) then ( OclFile["System.out"].println("Unknown") ) else ( OclFile["System.out"].println(names[pos+1] + " " + (y - (years[pos+1] - dec[pos+1]))) ) ; ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner s=new Scanner(System.in); static class calendarSystem implements Comparable{ String EraName ; int EraBasedYear ; int WesternYear ; calendarSystem(String eraName,int eraBasedYear,int westernYear){ EraName=eraName ; EraBasedYear=eraBasedYear ; WesternYear=westernYear ; } public int compareTo(calendarSystem x){ return this.WesternYear-x.WesternYear ; } } public static void main(String[] args){ while(true){ int N=s.nextInt(); int Q=s.nextInt(); if(N==0 && Q==0)break ; calendarSystem[] eraYear=new calendarSystem[N]; for(int i=0 ; i=WesternYear-EraBasedYear+1){ int Year=EraBasedYear-(WesternYear-Query); System.out.println(EraName+" "+Year); return ; } } System.out.println("Unknown"); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static class calendarSystem implements Comparable { attribute EraName : String; attribute EraBasedYear : int; attribute WesternYear : int; static operation newcalendarSystem( eraName : String, eraBasedYear : int, westernYear : int) : calendarSystem pre: true post: true activity: ( var self : calendarSystem ; self := createcalendarSystem(); self.initialise(eraName, eraBasedYear,westernYear); return self ); operation initialise( eraName : String, eraBasedYear : int, westernYear : int) : void pre: true post: true activity: ( EraName := eraName ; EraBasedYear := eraBasedYear ; WesternYear := westernYear ); operation compareTo( x : calendarSystem) : int pre: true post: true activity: ( return self.WesternYear - x.WesternYear ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (true) do ( var N : int ; N := s.getCurrent()->toInteger() ; var Q : int ; Q := s.getCurrent()->toInteger() ; if (N = 0 & Q = 0) then break else skip ; var eraYear : Sequence(calendarSystem) ; eraYear := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( var EraName : String ; EraName := s.getCurrent() ; var EraBasedYear : int ; EraBasedYear := s.getCurrent()->toInteger() ; var WesternYear : int ; WesternYear := s.getCurrent()->toInteger() ; eraYear[i+1] := calendarSystem.newcalendarSystem(EraName, EraBasedYear, WesternYear) ) ; i := i + 1 ) ; eraYear := eraYear->sort() ; var i : int ; i := 0 ; while i < Q do ( ( var Query : int ; Query := s.getCurrent()->toInteger() ; execute convertingYear(Query, eraYear) ) ; i := i + 1 ) ; ) ); static operation convertingYear( Query : int, eraYear : Sequence(calendarSystem)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < eraYear->size() do ( ( var WesternYear : int ; WesternYear := eraYear[i+1].WesternYear ; var EraBasedYear : int ; EraBasedYear := eraYear[i+1].EraBasedYear ; var EraName : String ; EraName := eraYear[i+1].EraName ; if (Query <= WesternYear & Query >= WesternYear - (EraBasedYear)->char2byte() + 1) then ( var Year : int ; Year := (EraBasedYear)->char2byte() - (WesternYear - Query) ; OclFile["System.out"].println(EraName + " " + Year) ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Unknown") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int max_bitwise_or(int L,int R){ Vectorv1=new Vector(),v2=new Vector(),v3=new Vector(); int z=0,i,ans=0,cnt=1 ; while(L>0){ v1.add(L % 2); L=L/2 ; } while(R>0){ v2.add(R % 2); R=R/2 ; } while(v1.size()!=v2.size()){ v1.add(0); } for(i=v2.size()-1 ; i>=0 ; i--){ if(v2.get(i)==1 && v1.get(i)==0 && z==0){ z=1 ; continue ; } if(z==1){ v1.remove(i); v1.add(i,1); } } for(i=0 ; i 0) do ( v1->excludes(L mod 2) ; L := L / 2 ) ; while (R > 0) do ( v2->excludes(R mod 2) ; R := R / 2 ) ; while (v1->size() /= v2->size()) do ( v1->excludes(0) ) ; i := v2->size() - 1 ; while i >= 0 do ( ( if (v2->at(i+1) = 1 & v1->at(i+1) = 0 & z = 0) then ( z := 1 ; continue ) else skip ; if (z = 1) then ( v1 := v1->excludingFirst(i) ; v1->excludes(i, 1) ) else skip ) ; i := i - 1 ) ; i := 0 ; while i < v2->size() do ( ( v3->excludes(v2->at(i+1) or v1->at(i+1)) ) ; i := i + 1 ) ; i := 0 ; while i < v2->size() do ( ( if (v3->at(i+1) = 1) then ( ans := ans+(cnt) ) else skip ; cnt := cnt*(2) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 10 ; var R : int ; R := 20 ; OclFile["System.out"].println(max_bitwise_or(L, R)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String[] nx=sc.nextLine().split(" "); int n=Integer.parseInt(nx[0]); long x=Long.parseLong(nx[1]); Listburger=new ArrayList<>(); Listputty=new ArrayList<>(); burger.add(1L); putty.add(1L); for(int i=0 ; ia,Listp){ if(n==0){ return(x<=0)? 0 : 1 ; } if(x<=a.get(n-1)+1){ return fnx(n-1,x-1,a,p); } if(x==a.get(n-1)+2){ return p.get(n-1)+1 ; } if(a.get(n-1)+2split(" ") ; var n : int ; n := (nx[0+1])->toInteger() ; var x : long ; x := (nx[1+1])->toLong() ; var burger : Sequence(long) ; burger := Sequence{} ; var putty : Sequence(long) ; putty := Sequence{} ; burger := burger->including(1L) ; putty := putty->including(1L) ; var i : int ; i := 0 ; while i < n do ( ( burger := burger->including(2 * burger->at(i+1) + 3) ; putty := putty->including(2 * putty->at(i+1) + 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(fnx(n, x, burger, putty)) ; ); static operation fnx( n : int, x : long, a : Sequence(long), p : Sequence(long)) : long pre: true post: true activity: ( if (n = 0) then ( return if (x <= 0) then 0 else 1 endif ) else skip ; if (x <= a->at(n - 1+1) + 1) then ( return fnx(n - 1, x - 1, a, p) ) else skip ; if (x = a->at(n - 1+1) + 2) then ( return p->at(n - 1+1) + 1 ) else skip ; if (a->at(n - 1+1) + 2 < x & x <= a->at(n+1) + 2) then ( return p->at(n - 1+1) + 1 + fnx(n - 1, x - 2 - a->at(n - 1+1), a, p) ) else skip ; return 2 * p->at(n - 1+1) + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; class GFG { static boolean isDivBy9(int n){ if(n==0 || n==9)return true ; if(n<9)return false ; return isDivBy9((int)(n>>3)-(int)(n & 7)); } public static void main(String arg[]){ for(int i=0 ; i<100 ; i++)if(isDivBy9(i))System.out.print(i+" "); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isDivBy9( n : int) : boolean 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(((n/(2->pow(3)))->oclAsType(long))->oclAsType(int) - (MathLib.bitwiseAnd(n,7))->oclAsType(int)) ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < 100 do ( if (isDivBy9(i)) then OclFile["System.out"].print(i + " ") ; else skip ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GeeksforGeeks { public static void pattern(int n){ for(int i=1 ; i<=n*2 ; i++)System.out.print(" "); System.out.print(0+"\n"); for(int i=1 ; i<=(n*2)-1 ; i++){ if(i0 ; j--)System.out.print(j+" "); System.out.print(0); } else if(i>n){ for(int j=0 ; j<=n-(i-n); j++)System.out.print(j+" "); for(int j=(n-(i-n))-1 ; j>0 ; j--)System.out.print(j+" "); System.out.print(0); } else { for(int j=0 ; j<=n ; j++)System.out.print(j+" "); for(int j=n-1 ; j>0 ; j--)System.out.print(j+" "); System.out.print(0); } System.out.print("\n"); } for(int i=1 ; i<=n*2 ; i++)System.out.print(" "); System.out.print(0); } public static void main(String argc[]){ int n=4 ; pattern(n); } } ------------------------------------------------------------ OCL File: --------- class GeeksforGeeks { static operation pattern( n : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= n * 2 do ( OclFile["System.out"].print(" ") ; ; i := i + 1 ) ; OclFile["System.out"].print(0 + "\n") ; var i : int ; i := 1 ; while i <= (n * 2) - 1 do ( ( if (i < n) then ( var j : int ; j := 1 ; while j <= (n - i) * 2 do ( OclFile["System.out"].print(" ") ; ; j := j + 1 ) ) else ( var j : int ; j := 1 ; while j <= (i mod n) * 2 do ( OclFile["System.out"].print(" ") ; ; j := j + 1 ) ) ; if (i < n) then ( var j : int ; j := 0 ; while j <= i mod n do ( OclFile["System.out"].print(j + " ") ; ; j := j + 1 ) ; var j : int ; j := (i mod n) - 1 ; while j > 0 do ( OclFile["System.out"].print(j + " ") ; ; j := j - 1 ) ; OclFile["System.out"].print(0) ) else if (i > n) then ( var j : int ; j := 0 ; while j <= n - (i - n) do ( OclFile["System.out"].print(j + " ") ; ; j := j + 1 ) ; var j : int ; j := (n - (i - n)) - 1 ; while j > 0 do ( OclFile["System.out"].print(j + " ") ; ; j := j - 1 ) ; OclFile["System.out"].print(0) ) else ( var j : int ; j := 0 ; while j <= n do ( OclFile["System.out"].print(j + " ") ; ; j := j + 1 ) ; var j : int ; j := n - 1 ; while j > 0 do ( OclFile["System.out"].print(j + " ") ; ; j := j - 1 ) ; OclFile["System.out"].print(0) ) ; ; OclFile["System.out"].print("\n") ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n * 2 do ( OclFile["System.out"].print(" ") ; ; i := i + 1 ) ; OclFile["System.out"].print(0) ; ); static operation main( argc : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; execute pattern(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isPowerOfTwo(int n){ if(n==0)return false ; while(n!=1){ if(n % 2!=0)return false ; n=n/2 ; } return true ; } public static void main(String args[]){ if(isPowerOfTwo(31))System.out.println("Yes"); else System.out.println("No"); if(isPowerOfTwo(64))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPowerOfTwo( n : int) : boolean 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 / 2 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( if (isPowerOfTwo(31)) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; if (isPowerOfTwo(64)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.lang.*; public class Solution { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Setset=new HashSet<>(); int n=Integer.parseInt(br.readLine()); String[] str=new String[n]; for(int i=0 ; itoInteger() ; var str : Sequence(String) ; str := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := br.readLine() ; if (set->includes(s)) then ( str[i+1] := "YES" ) else ( set := set->including(s) ; str[i+1] := "NO" ) ) ; i := i + 1 ) ; skip ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(str[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); ArrayListlist=new ArrayList<>(); String str="" ; for(int i=0 ; itoInteger() ; var list : Sequence(String) ; list := Sequence{} ; var str : String ; str := "" ; var i : int ; i := 0 ; while i < n do ( ( str := input.getCurrent() ; OclFile["System.out"].println((if list->includes(str) then "YES" else "NO" endif)) ; list := list->including(str) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Set ; import java.util.HashSet ; public class A_Tom_Riddle_s_Diary { static Scanner in=new Scanner(System.in); public static void main(String[] amit){ int n=in.nextInt(); String s[]=new String[n+1]; int ans=0 ; Setset=new HashSet<>(); for(int i=1 ; i<=n ; i++){ s[i]=in.next(); if(set.contains(s[i])){ System.out.println("YES"); } else { System.out.println("NO"); } set.add(s[i]); } } } ------------------------------------------------------------ OCL File: --------- class A_Tom_Riddle_s_Diary { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( amit : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var s : Sequence(String) ; s := Integer.subrange(1,n + 1)->collect(null) ; var ans : int ; ans := 0 ; var set : Set(String) ; set := Set{} ; var i : int ; i := 1 ; while i <= n do ( ( s[i+1] := in.getCurrent() ; if (set->includes(s[i+1])) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; set := set->including(s[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int sumOfDigit(int n,int b){ int unitDigit,sum=0 ; while(n>0){ unitDigit=n % b ; sum+=unitDigit ; n=n/b ; } return sum ; } public static void main(String[] args){ int n=50 ; int b=2 ; System.out.print(sumOfDigit(n,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfDigit( n : int, b : int) : int pre: true post: true activity: ( var unitDigit : int ; var sum : int ; sum := 0 ; while (n > 0) do ( unitDigit := n mod b ; sum := sum+(unitDigit) ; n := n / b ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 50 ; var b : int ; b := 2 ; OclFile["System.out"].print(sumOfDigit(n, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { static Scanner scan=new Scanner(System.in); public static void main(String args[]){ int n=scan.nextInt(); Listlist=new ArrayList(); for(int i=0 ; itoInteger() ; var list : Sequence(String) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var input : String ; input := scan.getCurrent() ; if (list->includes(input)) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ; list := list->including(input) ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static float surfaceArea(float a,float b,float h){ return 5*a*b+5*b*h ; } static float volume(float b,float h){ return(5*b*h)/2 ; } public static void main(String arr[]){ float a=5 ; float b=3 ; float h=7 ; System.out.println("surface area="+surfaceArea(a,b,h)+","); System.out.println("volume="+volume(b,h)); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation surfaceArea( a : double, b : double, h : double) : double pre: true post: true activity: ( return 5 * a * b + 5 * b * h ); static operation volume( b : double, h : double) : double pre: true post: true activity: ( return (5 * b * h) / 2 ); static operation main( arr : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 5 ; var b : double ; b := 3 ; var h : double ; h := 7 ; OclFile["System.out"].println("surface area=" + surfaceArea(a, b, h) + ",") ; OclFile["System.out"].println("volume=" + volume(b, h)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Run { public static int[] getCount(String s){ int[] count=new int[26]; int len=s.length(); for(int i=0 ; i>list=new ArrayList<>(26); for(int i=0 ; i<26 ; i++)list.add(new ArrayList<>()); for(int i=0 ; icollect(0) ; var len : int ; len := s->size() ; var i : int ; i := 0 ; while i < len do ( count[s->at(i+1) - ('a')->char2byte()+1] := count[s->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; return count ); static operation main( Z : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var op : String ; op := StringLib.newString() ; var n : int ; n := (br.readLine())->toInteger() ; var s : String ; s := br.readLine() ; var m : int ; m := (br.readLine())->toInteger() ; var names : Sequence(String) ; names := Integer.subrange(1,m)->collect(null) ; var i : int ; i := 0 ; while i < m do ( ( names[i+1] := br.readLine() ) ; i := i + 1 ) ; var list : Sequence(Sequence(int)) ; list := Sequence{} ; var i : int ; i := 0 ; while i < 26 do ( list := list->including(Sequence{}) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var c : String ; c := s->at(i+1) ; list->at((c)->char2byte() - ('a')->char2byte()+1)->excludes(i) ) ; i := i + 1 ) ; for (name : names) do ( ( var count : Sequence(int) ; count := getCount(name) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 26 do ( ( var cnt : int ; cnt := count[i+1] ; if (cnt = 0) then continue else skip ; var currAns : int ; currAns := list->at(i+1)->at(cnt - 1+1) + 1 ; ans := Set{currAns, ans}->max() ) ; i := i + 1 ) ; op := op + StringLib.newString(ans) ; op := op + StringLib.newString("\n") ; ) ) ; OclFile["System.out"].println(op) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { class Cache { private long size ; private long pati ; public Cache(long size,long pati){ this.size=size ; this.pati=pati ; } public long size(){ return this.size ; } public long pati(){ return this.pati ; } } public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String[] line=scanner.nextLine().split(" ",2); long n=Long.parseLong(line[0]); long x=Long.parseLong(line[1]); new Main(x,0).main(n); } private long toEat ; private long pati ; private HashMapcacheMap ; public Main(long toEat,long pati){ this.toEat=toEat ; this.pati=pati ; this.cacheMap=new HashMap<>(); } public void main(long level){ this.eat(level); System.out.println(this.pati); } public void eat(long level){ if(toEat==0){ return ; } if(level==0){ this.toEat--; this.pati++; } else { Cache cache=this.cacheMap.get(level-1); long initToEat=this.toEat ; long initPati=this.pati ; this.toEat--; if(cache!=null && this.toEat>=cache.size){ this.toEat-=cache.size ; this.pati+=cache.pati ; } else if(this.toEat>0){ this.eat(level-1); } if(this.toEat>0){ this.toEat--; this.pati++; } if(cache!=null && this.toEat>=cache.size){ this.toEat-=cache.size ; this.pati+=cache.pati ; } else if(this.toEat>0){ this.eat(level-1); } if(this.toEat>0){ this.toEat--; this.cacheMap.put(level,new Cache(initToEat-toEat,pati-initPati)); } } } } ------------------------------------------------------------ OCL File: --------- class Main { class Cache { attribute size : long; attribute pati : long; static operation newCache( size : long, pati : long) : Cache pre: true post: true activity: ( var self : Cache ; self := createCache(); self.initialise(size, pati); return self ); operation initialise( size : long, pati : long) : void pre: true post: true activity: ( self.size := size ; self.pati := pati ); operation size() : long pre: true post: true activity: ( return self.size ); operation pati() : long pre: true post: true activity: ( return self.pati ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var line : Sequence(String) ; line := scanner.nextLine()->split(" ") ; var n : long ; n := (line[0+1])->toLong() ; var x : long ; x := (line[1+1])->toLong() ; Main.newMain(x, 0).main(n) ; ); attribute toEat : long; attribute pati : long; attribute cacheMap : Map(long,Cache); static operation newMain( toEat : long, pati : long) : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(toEat, pati); return self ); operation initialise( toEat : long, pati : long) : void pre: true post: true activity: ( self.toEat := toEat ; self.pati := pati ; self.cacheMap := Map{} ); operation main( level : long) : void pre: true post: true activity: ( self.eat(level) ; OclFile["System.out"].println(self.pati) ); operation eat( level : long) : void pre: true post: true activity: ( if (toEat = 0) then ( return ) else skip ; if (level = 0) then ( self.toEat := self.toEat - 1 ; self.pati := self.pati + 1 ) else ( var cache : Cache ; cache := self.cacheMap->at(level - 1+1) ; var initToEat : long ; initToEat := self.toEat ; var initPati : long ; initPati := self.pati ; self.toEat := self.toEat - 1 ; if (cache /= null & self.toEat >= cache.size) then ( self.toEat := self.toEat-(cache.size) ; self.pati := self.pati+(cache.pati) ) else if (self.toEat > 0) then ( self.eat(level - 1) ) else skip ; ; if (self.toEat > 0) then ( self.toEat := self.toEat - 1 ; self.pati := self.pati + 1 ) else skip ; if (cache /= null & self.toEat >= cache.size) then ( self.toEat := self.toEat-(cache.size) ; self.pati := self.pati+(cache.pati) ) else if (self.toEat > 0) then ( self.eat(level - 1) ) else skip ; ; if (self.toEat > 0) then ( self.toEat := self.toEat - 1 ; self := self.cacheMap->union(Map{level |-> Cache.newCache(initToEat - toEat, pati - initPati)}) ) else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int sum=0 ; for(int i=0 ; i<10 ; i++)sum+=sc.nextInt(); System.out.println(sum); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 10 do ( sum := sum+(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sn=new Scanner(System.in); int sum=0 ; while(sn.hasNext())sum+=sn.nextInt(); System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sn : OclFile ; sn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sum : int ; sum := 0 ; while (sn.hasNext()) do sum := sum+(sn.getCurrent()->toInteger()) ; ; OclFile["System.out"].println(sum) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ Main main=new Main(); main.pointCount(); return ; } private void pointCount(){ BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); try { int point=0 ; for(int i=0 ; i<10 ; i++){ String inputStr=bufferedReader.readLine(); int num=Integer.parseInt(inputStr); point+=num ; } System.out.println(point); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.pointCount() ; return ); operation pointCount() : void pre: true post: true activity: ( var bufferedReader : OclFile ; bufferedReader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var point : int ; point := 0 ; var i : int ; i := 0 ; while i < 10 do ( ( var inputStr : String ; inputStr := bufferedReader.readLine() ; var num : int ; num := (inputStr)->toInteger() ; point := point+(num) ) ; i := i + 1 ) ; OclFile["System.out"].println(point) ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { Scanner sc ; Main(){ sc=new Scanner(System.in); } public static void main(String[] args){ new Main().run(); } void run(){ int sum=0 ; for(int i=0 ; i<10 ; ++i){ sum+=ni(); } System.out.println(sum); } int ni(){ return Integer.parseInt(sc.next()); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 10 do ( ( sum := sum+(ni()) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ); operation ni() : int pre: true post: true activity: ( return (sc.getCurrent())->toInteger() ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); int s ; int[] a=new int[10]; int b ; int d=0 ; public void kei(){ for(b=0 ; bcollect(0); attribute b : int; attribute d : int := 0; operation kei() : void pre: true post: true activity: ( b := 0 ; while b < a->size() do ( ( s := sc.getCurrent()->toInteger() ; d := d + s ) ; b := b + 1 ) ); operation hyouji() : void pre: true post: true activity: ( OclFile["System.out"].println(d) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var go : Main ; go := Main.newMain() ; go.kei() ; go.hyouji() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void printLargestDivisible(int n,int a[]){ int i,c0=0,c5=0 ; for(i=0 ; ifloor()->oclAsType(int) * 9 ; if (c0 = 0) then OclFile["System.out"].print(-1) ; else if (c5 = 0) then OclFile["System.out"].println(0) else ( i := 0 ; while i < c5 do ( OclFile["System.out"].print(5) ; ; i := i + 1 ) ; i := 0 ; while i < c0 do ( OclFile["System.out"].print(0) ; ; i := i + 1 ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{5,5,5,5,5,5,5,5,0,5,5} ; var n : int ; n := a->size() ; execute printLargestDivisible(n, a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.Math ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int mod=998244353 ; int T=in.nextInt(); while(T>0){ int n=in.nextInt(); long res=1 ; if(n % 2!=0){ System.out.println("0"); T--; continue ; } n=n/2 ; for(int i=2 ; i<=n ; i++){ res*=i ; res %=mod ; } res=res*res % mod ; System.out.println(res); T--; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var mod : int ; mod := 998244353 ; var T : int ; T := in.getCurrent()->toInteger() ; while (T > 0) do ( var n : int ; n := in.getCurrent()->toInteger() ; var res : long ; res := 1 ; if (n mod 2 /= 0) then ( OclFile["System.out"].println("0") ; T := T - 1 ; continue ) else skip ; n := n / 2 ; var i : int ; i := 2 ; while i <= n do ( ( res := res*(i) ; res := res mod mod ) ; i := i + 1 ) ; res := res * res mod mod ; OclFile["System.out"].println(res) ; T := T - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine().trim(); } catch(Exception e){ e.printStackTrace(); } return str ; } } static class FastWriter { private final BufferedWriter bw ; public FastWriter(){ this.bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object)throws IOException { bw.append(""+object); } public void println(Object object)throws IOException { print(object); bw.append("\n"); } public void close()throws IOException { bw.close(); } } static int MOD=998244353 ; public static void main(String[] args){ try { FastReader sc=new FastReader(); FastWriter sout=new FastWriter(); int testCases=sc.nextInt(); while(testCases-->0){ int n=sc.nextInt(); if(n % 2!=0){ sout.println(0); } else { long fact=factorial(n/2); fact=(fact*fact)% MOD ; sout.println(fact); } } sout.close(); } catch(Exception e){ return ; } } public static long factorial(int n){ long ans=1 ; while(n>1){ ans=(ans*n)% MOD ; --n ; } return ans % MOD ; } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine()->trim() ) catch (e : ProgramException) do ( e.printStackTrace() ) return str ); } static class FastWriter { attribute bw : OclFile; static operation newFastWriter() : FastWriter pre: true post: true activity: ( var self : FastWriter ; self := createFastWriter(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( self.bw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ); operation print( object : OclAny) : void pre: true post: true activity: ( skip ); operation println( object : OclAny) : void pre: true post: true activity: ( execute print(object) ; skip ); operation close() : void pre: true post: true activity: ( skip ); } static attribute MOD : int := 998244353; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : FastReader ; sc := FastReader.newFastReader() ; var sout : FastWriter ; sout := FastWriter.newFastWriter() ; var testCases : int ; testCases := sc.nextInt() ; while (testCases > 0) do ( testCases := testCases - 1 ; skip ; ( var n : int ; n := sc.nextInt() ; if (n mod 2 /= 0) then ( sout.println(0) ) else ( var fact : long ; fact := factorial(n / 2) ; fact := (fact * fact) mod MOD ; sout.println(fact) ) ) ; ) ; sout.close() ; ) catch (e : ProgramException) do ( return ) ); static operation factorial( n : int) : long pre: true post: true activity: ( var ans : long ; ans := 1 ; while (n > 1) do ( ans := (ans * n) mod MOD ; n := n - 1 ) ; return ans mod MOD ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF1658B { public static Scanner scanner ; public static int MOD=998244353 ; public static void main(String[] args){ scanner=new Scanner(System.in); int test=scanner.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < test do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; if (n mod 2 = 0) then ( var res : long ; res := facto(n / 2) * facto(n / 2) ; OclFile["System.out"].println(res mod MOD) ) else OclFile["System.out"].println(0) ; ) ; i := i + 1 ) ); static operation facto( n : long) : long pre: true post: true activity: ( if (n <= 0) then return 1 else skip ; return (n * facto(n - 1)) mod MOD ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int N=8 ; static int INF=Integer.MAX_VALUE ; public static int shortestDist(int[][] graph){ int[] dist=new int[N]; dist[N-1]=0 ; for(int i=N-2 ; i>=0 ; i--){ dist[i]=INF ; for(int j=i ; jcollect(0) ; dist[N - 1+1] := 0 ; var i : int ; i := N - 2 ; while i >= 0 do ( ( dist[i+1] := INF ; var j : int ; j := i ; while j < N 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() ) ; j := j + 1 ) ) ; i := i - 1 ) ; return dist[0+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var graph : Sequence(Sequence(int)) ; graph := Sequence{Sequence{INF,1,2,5,INF,INF,INF,INF},Sequence{INF,INF,INF,INF,4,11,INF,INF},Sequence{INF,INF,INF,INF,9,5,16,INF},Sequence{INF,INF,INF,INF,INF,INF,2,INF},Sequence{INF,INF,INF,INF,INF,INF,INF,18},Sequence{INF,INF,INF,INF,INF,INF,INF,13},Sequence{INF,INF,INF,INF,INF,INF,INF,2}} ; OclFile["System.out"].println(shortestDist(graph)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] agrs){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int l=in.nextInt(); int[] a=new int[55]; int[] b=new int[55]; int[] aa=new int[55]; int[] bb=new int[55]; for(int i=0 ; itoInteger() ; var l : int ; l := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,55)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,55)->collect(0) ; var aa : Sequence(int) ; aa := Integer.subrange(1,55)->collect(0) ; var bb : Sequence(int) ; bb := Integer.subrange(1,55)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( aa[i+1] := a[i+1] - a[i - 1+1] ) ; i := i + 1 ) ; aa[0+1] := a[0+1] + l - a[n - 1+1] ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( bb[i+1] := b[i+1] - b[i - 1+1] ) ; i := i + 1 ) ; bb[0+1] := b[0+1] + l - b[n - 1+1] ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (aa[j+1] /= bb[(i + j) mod n+1]) then break else skip ) ; j := j + 1 ) ; if (j = n) then ( flag := 1 ; break ) else skip ) ; i := i + 1 ) ; if (flag = 0) then OclFile["System.out"].println("NO") else OclFile["System.out"].println("YES") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.awt.*; import java.awt.geom.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { public static void main(String[] $){ Scanner sc=new Scanner(in); int n=sc.nextInt(); long x=sc.nextLong(); long[] a=new long[51]; a[0]=1 ; long[] p=new long[51]; p[0]=1 ; for(int i=0 ; i<50 ; i++){ a[i+1]=2*a[i]+3 ; p[i+1]=2*p[i]+1 ; } out.println(f(a,p,n,x)); } static long f(long[] a,long[] p,int n,long x){ if(x==1)return n>0 ? 0 : 1 ; if(x==3+2*a[n-1])return p[n-1]*2+1 ; if(x==a[n-1]+2)return p[n-1]+1 ; if(1toInteger() ; var x : long ; x := sc.getCurrent()->toLong() ; var a : Sequence(long) ; a := Integer.subrange(1,51)->collect(0) ; a[0+1] := 1 ; var p : Sequence(long) ; p := Integer.subrange(1,51)->collect(0) ; p[0+1] := 1 ; var i : int ; i := 0 ; while i < 50 do ( ( a[i + 1+1] := 2 * a[i+1] + 3 ; p[i + 1+1] := 2 * p[i+1] + 1 ) ; i := i + 1 ) ; out.println(f(a, p, n, x)) ; ); static operation f( a : Sequence(long), p : Sequence(long), n : int, x : long) : long pre: true post: true activity: ( if (x = 1) then return if n > 0 then 0 else 1 endif else skip ; if (x = 3 + 2 * a[n - 1+1]) then return p[n - 1+1] * 2 + 1 else skip ; if (x = a[n - 1+1] + 2) then return p[n - 1+1] + 1 else skip ; if (1 < x & x <= a[n - 1+1] + 1) then return f(a, p, n - 1, x - 1) else skip ; return p[n - 1+1] + 1 + f(a, p, n - 1, x - a[n - 1+1] - 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Test12 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int l=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; ArrayListlist1=new ArrayList<>(); ArrayListlist2=new ArrayList<>(); for(int i=0 ; itoInteger() ; var l : int ; l := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var list1 : Sequence(int) ; list1 := Sequence{} ; var list2 : Sequence(int) ; list2 := Sequence{} ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var f : boolean ; f := false ; var i : int ; i := 0 ; while i < (n - 1) do ( ( list1 := list1->including(a[i + 1+1] - a[i+1]) ; list2 := list2->including(b[i + 1+1] - b[i+1]) ) ; i := i + 1 ) ; list1 := list1->including(l + a[0+1] - a[n - 1+1]) ; list2 := list2->including(l + b[0+1] - b[n - 1+1]) ; var i : int ; i := 0 ; while i < n do ( ( var flag : boolean ; flag := true ; var j : int ; j := 0 ; while j < n do ( flag := (list1->at(j+1) = list2->at((i + j) mod n+1)) & flag ; ; j := j + 1 ) ; f := (MathLib.bitwiseOr(flag,f)) ) ; i := i + 1 ) ; OclFile["System.out"].println(if f then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maximum(int x,int y){ return((x+y+Math.abs(x-y))/2); } static int minimum(int x,int y){ return((x+y-Math.abs(x-y))/2); } public static void main(String[] args){ int x=99,y=18 ; System.out.println("Maximum: "+maximum(x,y)); System.out.println("Minimum: "+minimum(x,y)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maximum( x : int, y : int) : int pre: true post: true activity: ( return ((x + y + if x - y < 0 then -(x - y) else x - y endif) / 2) ); static operation minimum( x : int, y : int) : int pre: true post: true activity: ( return ((x + y - if x - y < 0 then -(x - y) else x - y endif) / 2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 99 ; var y : int ; y := 18 ; OclFile["System.out"].println("Maximum: " + maximum(x, y)) ; OclFile["System.out"].println("Minimum: " + minimum(x, y)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static double u_cal(double u,int n){ double temp=u ; for(int i=1 ; icollect(Integer.subrange(1,n)->collect(0.0)) ; y[0+1][0+1] := 0.7071 ; y[1+1][0+1] := 0.7660 ; y[2+1][0+1] := 0.8192 ; y[3+1][0+1] := 0.8660 ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := 0 ; while j < n - i do ( y[j+1][i+1] := y[j + 1+1][i - 1+1] - y[j+1][i - 1+1] ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(x[i+1] + "\t") ; var j : int ; j := 0 ; while j < n - i do ( OclFile["System.out"].print(y[i+1][j+1] + "\t") ; ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; var value : double ; value := 52 ; var sum : double ; sum := y[0+1][0+1] ; var u : double ; u := (value - x[0+1]) / (x[1+1] - x[0+1]) ; var i : int ; i := 1 ; while i < n do ( ( sum := sum + (u_cal(u, i) * y[0+1][i+1]) / fact(i) ) ; i := i + 1 ) ; OclFile["System.out"].println("\n Value at " + value + " is " + StringLib.format("%.6g%n",Sequence{sum})) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static void breakLine(){ System.out.print("\n---------------------------------\n"); } static int MAX=10 ; static int arr[]=new int[MAX],no ; static void nQueens(int k,int n){ for(int i=1 ; i<=n ; i++){ if(canPlace(k,i)){ arr[k]=i ; if(k==n){ display(n); } else { nQueens(k+1,n); } } } } static boolean canPlace(int k,int i){ for(int j=1 ; j<=k-1 ; j++){ if(arr[j]==i ||(Math.abs(arr[j]-i)==Math.abs(j-k))){ return false ; } } return true ; } static void display(int n){ breakLine(); System.out.print("Arrangement No."+++no); breakLine(); for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=n ; j++){ if(arr[i]!=j){ System.out.print("\t_"); } else { System.out.print("\tQ"); } } System.out.println(""); } breakLine(); } public static void main(String[] args){ int n=4 ; nQueens(1,n); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation breakLine() : void pre: true post: true activity: ( OclFile["System.out"].print("\n---------------------------------\n") ); static attribute MAX : int := 10; static attribute arr : int := Integer.subrange(1,MAX)->collect(0); static operation nQueens( k : int, n : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= n do ( ( if (canPlace(k, i)) then ( arr[k+1] := i ; if (k = n) then ( execute display(n) ) else ( execute nQueens(k + 1, n) ) ) else skip ) ; i := i + 1 ) ); static operation canPlace( k : int, i : int) : boolean pre: true post: true activity: ( var j : int ; j := 1 ; while j <= k - 1 do ( ( if (arr[j+1] = i or (if arr[j+1] - i < 0 then -(arr[j+1] - i) else arr[j+1] - i endif = if j - k < 0 then -(j - k) else j - k endif)) then ( return false ) else skip ) ; j := j + 1 ) ; return true ); static operation display( n : int) : void pre: true post: true activity: ( execute breakLine() ; OclFile["System.out"].print("Arrangement No." + no) ; execute breakLine() ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= n do ( ( if (arr[i+1] /= j) then ( OclFile["System.out"].print("\t_") ) else ( OclFile["System.out"].print("\tQ") ) ) ; j := j + 1 ) ; OclFile["System.out"].println("") ) ; i := i + 1 ) ; execute breakLine() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; execute nQueens(1, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countWays(int n){ int counter=0 ; for(int i=1 ; i=0)break ; } p=1 ; k=i ; t=s ; if(n % 2==0){ for(i=0 ; itoInteger() ; j := 1 ; while j <= q do ( ( n := sc.getCurrent()->toInteger() ; s := sc.getCurrent() ; str := "" ; i := 0 ; while i < n do ( str := s->at(i+1) + str ; ; i := i + 1 ) ; i := 97 ; while i <= 122 do ( ( if (s->indexOf(i->oclAsType(String))-1 >= 0) then break else skip ) ; i := i + 1 ) ; p := 1 ; k := i ; t := s ; if (n mod 2 = 0) then ( i := 0 ; while i < n do ( ( if (s->at(i+1) = k->oclAsType(String)) then ( w := s.subrange(i+1,i) ; if (i mod 2 = 0) then w := w + s.subrange(0+1,i) else w := w + str.subrange(n - i+1,n - i) ; ; if (w->compareTo(t) < 0) then ( p := (i + 1) ; t := w ) else skip ) else skip ) ; i := i + 1 ) ) else ( i := 0 ; while i < n do ( ( if (s->at(i+1) = k->oclAsType(String)) then ( w := s.subrange(i+1,i) ; if (i mod 2 = 1) then w := w + s.subrange(0+1,i) else w := w + str.subrange(n - i+1,n - i) ; ; if (w->compareTo(t) < 0) then ( p := (i + 1) ; t := w ) else skip ) else skip ) ; i := i + 1 ) ) ; OclFile["System.out"].println(t) ; OclFile["System.out"].println(p) ; ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class StringModification { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t!=0){ solve(br,pr); t--; } pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); String s=br.readLine(); StringBuffer sBuffer=new StringBuffer(s); int k=1 ; String res=s ; sBuffer=new StringBuffer(s); for(int i=0 ; itoInteger() ; while (t /= 0) do ( execute solve(br, pr) ; t := t - 1 ) ; skip ; skip ; ); static operation solve( br : OclFile, pr : OclFile) : void pre: true post: true activity: ( var n : int ; n := (br.readLine())->toInteger() ; var s : String ; s := br.readLine() ; var sBuffer : String ; sBuffer := StringLib.newString(s) ; var k : int ; k := 1 ; var res : String ; res := s ; sBuffer := StringLib.newString(s) ; var i : int ; i := 0 ; while i < n do ( ( var tempK : int ; tempK := i + 1 ; var first : String ; first := s.subrange(tempK - 1+1,n) ; var second : String ; second := StringLib.newString(s.subrange(0+1,tempK - 1)) ; if (tempK mod 2 = n mod 2) then ( second := second->reverse() ; second := second->reverse() ; var sec : String ; sec := second+"" ; var temp : String ; temp := first + sec ; if (temp->compareTo(res) < 0) then ( k := tempK ; res := temp ) else skip ) else ( var sec : String ; sec := second+"" ; var temp : String ; temp := first + sec ; if (temp->compareTo(res) < 0) then ( k := tempK ; res := temp ) else skip ) ) ; i := i + 1 ) ; var total : String ; total := StringLib.newString(s) ; total := total->reverse() ; total := total->reverse() ; if (total+""->compareTo(res) < 0) then ( res := total+"" ; k := n ) else skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); if(k==1){ System.out.println("1"); System.out.println("1"); } else if(k==2){ System.out.println("2"); System.out.println("1 2"); System.out.println("2 1"); } else if(k==3){ System.out.println("2"); System.out.println("1 2"); System.out.println("3 1"); } else if(k==4){ System.out.println("2"); System.out.println("1 2"); System.out.println("3 4"); } else { int cut=4-k % 4 ; int n ; int amari ; if(cut!=4){ n=(k+cut)/2 ; } else { n=k/2 ; cut=0 ; } System.out.println(n); for(int r=0 ; r=1 || amari==n-2 && cut>=2 || amari==n-3 && cut>=3){ System.out.print((c+r)% n+1+" "); } else { System.out.print((c+r)% n+n+1+" "); } } } System.out.println(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; if (k = 1) then ( OclFile["System.out"].println("1") ; OclFile["System.out"].println("1") ) else if (k = 2) then ( OclFile["System.out"].println("2") ; OclFile["System.out"].println("1 2") ; OclFile["System.out"].println("2 1") ) else if (k = 3) then ( OclFile["System.out"].println("2") ; OclFile["System.out"].println("1 2") ; OclFile["System.out"].println("3 1") ) else if (k = 4) then ( OclFile["System.out"].println("2") ; OclFile["System.out"].println("1 2") ; OclFile["System.out"].println("3 4") ) else ( var cut : int ; cut := 4 - k mod 4 ; var n : int ; var amari : int ; if (cut /= 4) then ( n := (k + cut) / 2 ) else ( n := k / 2 ; cut := 0 ) ; OclFile["System.out"].println(n) ; var r : int ; r := 0 ; while r < n do ( ( var c : int ; c := 0 ; while c < n do ( ( if (r mod 2 = 0) then ( OclFile["System.out"].print((c + r) mod n + 1 + " ") ) else ( amari := (c + r) mod n ; if (amari = n - 1 & cut >= 1 or amari = n - 2 & cut >= 2 or amari = n - 3 & cut >= 3) then ( OclFile["System.out"].print((c + r) mod n + 1 + " ") ) else ( OclFile["System.out"].print((c + r) mod n + n + 1 + " ") ) ) ) ; c := c + 1 ) ; OclFile["System.out"].println() ) ; r := r + 1 ) ; ) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); if(k==1){ System.out.println(1); System.out.print(1); return ; } int n=2*((k+3)/4); int curt=n*2-k ; int[][] mat=new int[n][n]; for(int r=0 ; rtoInteger() ; if (k = 1) then ( OclFile["System.out"].println(1) ; OclFile["System.out"].print(1) ; return ) else skip ; var n : int ; n := 2 * ((k + 3) / 4) ; var curt : int ; curt := n * 2 - k ; var mat : Sequence(Sequence(int)) ; mat := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var r : int ; r := 0 ; while r < n do ( ( var c : int ; c := 0 ; while c < n do ( ( if (r mod 2 = 1 & (r + c) mod n < n - curt) then ( mat[r+1][c+1] := n + (r + c) mod n ; mat[r+1][c+1] := mat[r+1][c+1] + 1 ) else ( mat[r+1][c+1] := (r + c) mod n ; mat[r+1][c+1] := mat[r+1][c+1] + 1 ) ) ; c := c + 1 ) ) ; r := r + 1 ) ; OclFile["System.out"].println(n) ; for (row : mat) do ( ( for (x : row) do ( ( OclFile["System.out"].print(x + " ") ) ) ; OclFile["System.out"].println("") ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); if(k==1){ System.out.println(1); System.out.print(1); return ; } int n=2*((k+3)/4); int curt=n*2-k ; int[][] mat=new int[n][n]; for(int r=0 ; rtoInteger() ; if (k = 1) then ( OclFile["System.out"].println(1) ; OclFile["System.out"].print(1) ; return ) else skip ; var n : int ; n := 2 * ((k + 3) / 4) ; var curt : int ; curt := n * 2 - k ; var mat : Sequence(Sequence(int)) ; mat := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var r : int ; r := 0 ; while r < n do ( ( var c : int ; c := 0 ; while c < n do ( ( if (r mod 2 = 1 & (r + c) mod n < n - curt) then ( mat[r+1][c+1] := n + (r + c) mod n ; mat[r+1][c+1] := mat[r+1][c+1] + 1 ) else ( mat[r+1][c+1] := (r + c) mod n ; mat[r+1][c+1] := mat[r+1][c+1] + 1 ) ) ; c := c + 1 ) ) ; r := r + 1 ) ; var rr : int ; rr := 1 ; OclFile["System.out"].println(n) ; for (row : mat) do ( ( var cc : int ; cc := 1 ; for (x : row) do ( ( OclFile["System.out"].print(x) ; if (cc < n) then OclFile["System.out"].print(" ") ; else skip ; cc := cc + 1 ) ) ; if (rr < n) then OclFile["System.out"].println("") ; else skip ; rr := rr + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Integer.parseInt ; import static java.lang.Long.parseLong ; import static java.lang.System.exit ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { static void solve()throws Exception { int k=scanInt(),n ; if(k==1){ n=1 ; } else { n=(k+3)/4*2 ; } out.println(n); for(int i=0 ; itoInteger() ); static operation scanLong() : long pre: true post: true activity: ( return parseLong(scanString()) ); static operation scanString() : String pre: true post: true activity: ( while (tok = null or not(tok.hasNext())) do ( tok := OclIterator.newOclIterator_String(in.readLine()) ) ; return tok.next() ); static attribute in : OclFile; static attribute out : OclFile; static attribute tok : OclIterator; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ; skip ; ) catch (e : OclException) do ( e.printStackTrace() ; execute exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { long patty[]=new long[51]; long size[]=new long[51]; public void main(Scanner sc){ int n=sc.nextInt(); long x=sc.nextLong(); patty[0]=1 ; size[0]=1 ; for(int i=1 ; i<=50 ; i++){ patty[i]=patty[i-1]*2+1 ; size[i]=patty[i]*2-1 ; } System.out.println(calc(n,x)); } private long calc(int level,long x){ if(x==0){ return 0 ; } if(x>=size[level]){ return patty[level]; } if(x*2>size[level]){ return patty[level-1]+1+calc(level-1,x-size[level-1]-2); } else { return calc(level-1,x-1); } } public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ new Main().main(sc); } catch(Exception e){ throw e ; } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute patty : long := Integer.subrange(1,51)->collect(0); attribute size : long := Integer.subrange(1,51)->collect(0); operation main( sc : OclFile) : void pre: true post: true activity: ( var n : int ; n := sc.nextInt() ; var x : long ; x := sc.nextLong() ; patty[0+1] := 1 ; size[0+1] := 1 ; var i : int ; i := 1 ; while i <= 50 do ( ( patty[i+1] := patty[i - 1+1] * 2 + 1 ; size[i+1] := patty[i+1] * 2 - 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(calc(n, x)) ; ); operation calc( level : int, x : long) : long pre: true post: true activity: ( if (x = 0) then ( return 0 ) else skip ; if (x >= size[level+1]) then ( return patty[level+1] ) else skip ; if (x * 2 > size[level+1]) then ( return patty[level - 1+1] + 1 + calc(level - 1, x - size[level - 1+1] - 2) ) else ( return calc(level - 1, x - 1) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( Main.newMain().main(sc) )) catch (e : ProgramException) do ( error e ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int L=2*N-1 ; int[] a=new int[L]; for(int i=0 ; i=mid ; if(satisfy(b))min=mid ; else max=mid ; } System.out.println(min); sc.close(); } static boolean satisfy(boolean[] b){ int L=b.length ; int N=(L+1)/2 ; int l=N-1 ; while(l>0 && b[l]!=b[l-1])l--; int r=N-1 ; while(r0){ if(r=N-1 ? b[l] : b[r]; } else { return b[l]; } } else if(rtoInteger() ; var L : int ; L := 2 * N - 1 ; var a : Sequence(int) ; a := Integer.subrange(1,L)->collect(0) ; var i : int ; i := 0 ; while i < L do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var min : int ; min := 1 ; var max : int ; max := L ; var b : Sequence(boolean) ; b := Integer.subrange(1,L)->collect(false) ; while (min + 1 < max) do ( var mid : int ; mid := (min + max) / 2 ; var i : int ; i := 0 ; while i < L do ( b[i+1] := a[i+1] >= mid ; ; i := i + 1 ) ; if (satisfy(b)) then min := mid ; else max := mid ; ) ; OclFile["System.out"].println(min) ; skip ; ); static operation satisfy( b : Sequence(boolean)) : boolean pre: true post: true activity: ( var L : int ; L := b->size() ; var N : int ; N := (L + 1) / 2 ; var l : int ; l := N - 1 ; while (l > 0 & b[l+1] /= b[l - 1+1]) do l := l - 1 ; ; var r : int ; r := N - 1 ; while (r < L - 1 & b[r+1] /= b[r + 1+1]) do r := r + 1 ; ; if (l > 0) then ( if (r < L - 1) then ( if (b[l+1] = b[r+1]) then return b[l+1] else return if (l + r) / 2 >= N - 1 then b[l+1] else b[r+1] endif ) else ( return b[l+1] ) ) else if (r < L - 1) then ( return b[r+1] ) else ( return b[N - 1+1] xor N mod 2 = 0 ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class LinearSearch { static int countRotations(int arr[],int n){ int min=arr[0],min_index=-1 ; for(int i=0 ; iarr[i]){ min=arr[i]; min_index=i ; } } return min_index ; } public static void main(String[] args){ int arr[]={ 15,18,2,3,6,12 }; int n=arr.length ; System.out.println(countRotations(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class LinearSearch { static operation countRotations( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var min : int ; min := arr[0+1] ; var min_index : int ; min_index := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (min > arr[i+1]) then ( min := arr[i+1] ; min_index := i ) else skip ) ; i := i + 1 ) ; return min_index ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{15,18,2,3,6,12} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(countRotations(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class sum_dig { static int countRec(int n,int sum){ if(n==0)return sum==0 ? 1 : 0 ; if(sum==0)return 1 ; int ans=0 ; for(int i=0 ; i<=9 ; i++)if(sum-i>=0)ans+=countRec(n-1,sum-i); return ans ; } static int finalCount(int n,int sum){ int ans=0 ; for(int i=1 ; i<=9 ; i++)if(sum-i>=0)ans+=countRec(n-1,sum-i); return ans ; } public static void main(String args[]){ int n=2,sum=5 ; System.out.println(finalCount(n,sum)); } } ------------------------------------------------------------ OCL File: --------- class sum_dig { static operation countRec( n : int, sum : int) : int pre: true post: true activity: ( if (n = 0) then return if sum = 0 then 1 else 0 endif else skip ; if (sum = 0) then return 1 else skip ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i <= 9 do ( if (sum - i >= 0) then ans := ans+(countRec(n - 1, sum - i)) ; else skip ; ; i := i + 1 ) ; return ans ); static operation finalCount( n : int, sum : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= 9 do ( if (sum - i >= 0) then ans := ans+(countRec(n - 1, sum - i)) ; else skip ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; var sum : int ; sum := 5 ; OclFile["System.out"].println(finalCount(n, sum)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int numberOfMinutes(int S,int S1){ int Min=0 ; Min=(int)(((S-S1)/Math.floor(S))*60); return Min ; } public static void main(String[] args){ int S=30,S1=10 ; System.out.println(numberOfMinutes(S,S1)+" min"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation numberOfMinutes( S : int, S1 : int) : int pre: true post: true activity: ( var Min : int ; Min := 0 ; Min := (((S - S1) / (S)->floor()) * 60)->oclAsType(int) ; return Min ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : int ; S := 30 ; var S1 : int ; S1 := 10 ; OclFile["System.out"].println(numberOfMinutes(S, S1) + " min") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class sum_dig { static int lookup[][]=new int[101][501]; static int countRec(int n,int sum){ if(n==0)return sum==0 ? 1 : 0 ; if(lookup[n][sum]!=-1)return lookup[n][sum]; int ans=0 ; for(int i=0 ; i<10 ; i++)if(sum-i>=0)ans+=countRec(n-1,sum-i); return lookup[n][sum]=ans ; } static int finalCount(int n,int sum){ for(int i=0 ; i<=100 ; ++i){ for(int j=0 ; j<=500 ; ++j){ lookup[i][j]=-1 ; } } int ans=0 ; for(int i=1 ; i<=9 ; i++)if(sum-i>=0)ans+=countRec(n-1,sum-i); return ans ; } public static void main(String args[]){ int n=3,sum=5 ; System.out.println(finalCount(n,sum)); } } ------------------------------------------------------------ OCL File: --------- class sum_dig { static attribute lookup : int := Integer.subrange(1,101)->collect(Integer.subrange(1,501)->collect(0)); static operation countRec( n : int, sum : int) : int pre: true post: true activity: ( if (n = 0) then return if sum = 0 then 1 else 0 endif else skip ; if (lookup[n+1][sum+1] /= -1) then return lookup[n+1][sum+1] else skip ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 10 do ( if (sum - i >= 0) then ans := ans+(countRec(n - 1, sum - i)) ; else skip ; ; i := i + 1 ) ; return lookup[n+1][sum+1] ); static operation finalCount( n : int, sum : int) : int pre: true post: true activity: ( var i : int ; i := 0 ; while i <= 100 do ( ( var j : int ; j := 0 ; while j <= 500 do ( ( lookup[i+1][j+1] := -1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= 9 do ( if (sum - i >= 0) then ans := ans+(countRec(n - 1, sum - i)) ; else skip ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; var sum : int ; sum := 5 ; OclFile["System.out"].println(finalCount(n, sum)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countIndices(int arr[],int n){ int cnt=0 ; int max=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(countIndices(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int slopeOfNum(String num,int n){ int slope=0 ; for(int i=1 ; inum.charAt(i-1)&& num.charAt(i)>num.charAt(i+1))slope++; else if(num.charAt(i)size() ; OclFile["System.out"].println("Slope=" + slopeOfNum(num, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findNth(int N){ int b=14 ; int i ; for(i=2 ; i<=N ; i++){ if(i % 2==0)b=b*2 ; else b=b-8 ; } return b ; } public static void main(String[] args){ int N=6 ; System.out.print(findNth(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findNth( N : int) : int pre: true post: true activity: ( var b : int ; b := 14 ; var i : int ; i := 2 ; while i <= N do ( ( if (i mod 2 = 0) then b := b * 2 ; else b := b - 8 ; ) ; i := i + 1 ) ; return b ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 6 ; OclFile["System.out"].print(findNth(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int binarySearchCount(int arr[],int n,int key){ int left=0,right=n ; int mid=0 ; while(left>1 ; if(arr[mid]==key){ while(mid+1key)right=mid ; else left=mid+1 ; } while(mid>-1 && arr[mid]>key)mid--; return mid+1 ; } public static void main(String[] args){ int arr[]={ 1,2,4,5,8,10 }; int key=11 ; int n=arr.length ; System.out.print(binarySearchCount(arr,n,key)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation binarySearchCount( arr : Sequence(int), n : int, key : int) : int pre: true post: true activity: ( var left : int ; left := 0 ; var right : int ; right := n ; var mid : int ; mid := 0 ; while (left < right) do ( mid := ((right + left)/(2->pow(1)))->oclAsType(long) ; if (arr[mid+1] = key) then ( while (mid + 1 < n & arr[mid + 1+1] = key) do mid := mid + 1 ; ; break ) else if (arr[mid+1] > key) then right := mid else left := mid + 1 ; ; ) ; while (mid > -1 & arr[mid+1] > key) do mid := mid - 1 ; ; return mid + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,4,5,8,10} ; var key : int ; key := 11 ; var n : int ; n := arr->size() ; OclFile["System.out"].print(binarySearchCount(arr, n, key)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isPowerOfTwo(int x){ return(x>0 &&(!((x &(x-1))>0))); } static void Count_pairs(int a[],int n){ int count=0 ; for(int i=0 ; i 0 & (not(((x & (x - 1)) > 0)))) ); static operation Count_pairs( a : Sequence(int), n : int) : void pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (isPowerOfTwo(a[i+1])) then count := count + 1 ; else skip ) ; i := i + 1 ) ; var ans : int ; ans := (count * (count - 1)) / 2 ; OclFile["System.out"].println(ans) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,5,8,16,128} ; var n : int ; n := a->size() ; execute Count_pairs(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; import static java.lang.Math.max ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(--T>=0){ int n=sc.nextInt(); int cnt=0 ; for(int i=0 ; i<=29 ; ++i){ if((n &(1<toInteger() ; T := T - 1 ; while ((T - 1) >= 0) do ( T := T - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i <= 29 do ( ( if ((MathLib.bitwiseAnd(n,((1*(2->pow(i)))->oclAsType(long)))) /= 0) then ( cnt := cnt+(1) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println((2->pow(cnt))->oclAsType(int)) ) ; T := T - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int cntSubsets(int[] arr,int n){ int max=(int)Math.pow(2,n); int result=0 ; for(int i=0 ; i>1))>0)continue ; result++; } return result ; } static public void main(String[] arg){ int arr[]={ 3,5,7 }; int n=arr.length ; System.out.println(cntSubsets(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cntSubsets( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var max : int ; max := 2->pow(n)->oclAsType(int) ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < max do ( ( var counter : int ; counter := i ; if ((MathLib.bitwiseAnd(counter,((counter/(2->pow(1)))->oclAsType(long)))) > 0) then continue else skip ; result := result + 1 ) ; i := i + 1 ) ; return result ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,5,7} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(cntSubsets(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileInputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; import java.util.StringTokenizer ; public class Eipair { public static void main(String[] args)throws IOException { InputReader sc=new InputReader(System.in); int n=sc.nextInt(); for(int i=0 ; ipow(c)->oclAsType(long)) ) ; i := i + 1 ) ); static class InputReader { attribute tokenizer : OclIterator; attribute reader : OclFile; attribute token : String; attribute temp : String; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( tokenizer := null ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ); static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( tokenizer := null ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ); operation nextLine() : String pre: true post: true activity: ( return reader.readLine() ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( if (temp /= null) then ( tokenizer := OclIterator.newOclIterator_String(temp) ; temp := null ) else ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (e : IOException) do skip ) ; return tokenizer.next() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B { public static void solve(int x){ int c=0 ; for(int i=0 ; i<=31 ; i++){ if((x &(1<pow(i)))->oclAsType(long))) /= 0) then c := c + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].printf("%d\n", (1*(2->pow(c)))->oclAsType(long)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var v : int ; v := sc.getCurrent()->toInteger() ; execute solve(v) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Samyak { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long x=sc.nextLong(); long y=sc.nextLong(); System.out.println(y+(x-1)*9); } } } ------------------------------------------------------------ OCL File: --------- class Samyak { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : long ; x := sc.getCurrent()->toLong() ; var y : long ; y := sc.getCurrent()->toLong() ; OclFile["System.out"].println(y + (x - 1) * 9) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class magic { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); long out[]=new long[t]; for(int i=0 ; itoInteger() ; var out : Sequence(long) ; out := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( var str : String ; str := (MathLib.decimal2binary(sc.getCurrent()->toLong()) + "") ; var k : int ; k := 0 ; var n : int ; n := str->size() ; var j : int ; j := 0 ; while j < n do ( ( if (str->at(j+1) = '1') then k := k + 1 ; else skip ) ; j := j + 1 ) ; out[i+1] := 2->pow(k)->oclAsType(long) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < t do ( ( OclFile["System.out"].println(out[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String args[]){ int a,b,C ; double sin,cos,S,L,h ; Scanner scan=new Scanner(System.in); a=scan.nextInt(); b=scan.nextInt(); C=scan.nextInt(); sin=Math.sin(Math.toRadians(C)); cos=Math.cos(Math.toRadians(C)); S=a*b*sin/2 ; L=a+b+Math.sqrt(a*a+b*b-2*a*b*cos); h=b*sin ; System.out.println(S); System.out.println(L); System.out.println(h); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; var b : int ; var C : int ; var sin : double ; var cos : double ; var S : double ; var L : double ; var h : double ; var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; a := scan.getCurrent()->toInteger() ; b := scan.getCurrent()->toInteger() ; C := scan.getCurrent()->toInteger() ; sin := ((0.017453292519943295*(C)))->sin() ; cos := ((0.017453292519943295*(C)))->cos() ; S := a * b * sin / 2 ; L := a + b + (a * a + b * b - 2 * a * b * cos)->sqrt() ; h := b * sin ; OclFile["System.out"].println(S) ; OclFile["System.out"].println(L) ; OclFile["System.out"].println(h) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=br.readLine(); String[] strArray=str.split(" "); double para[]=new double[3]; double S,L,h ; for(int i=0 ; isplit(" ") ; var para : Sequence(double) ; para := Integer.subrange(1,3)->collect(0.0) ; var S : double ; var L : double ; var h : double ; var i : int ; i := 0 ; while i < strArray->size() do ( ( para[i+1] := (strArray[i+1])->toReal() ) ; i := i + 1 ) ; S := (para[0+1] * para[1+1] * ((0.017453292519943295*(para[2+1])))->sin()) / 2 ; L := para[0+1] + para[1+1] + (para[0+1]->pow(2) + para[1+1]->pow(2) - 2 * para[0+1] * para[1+1] * ((0.017453292519943295*(para[2+1])))->cos())->sqrt() ; h := para[1+1] * ((0.017453292519943295*(para[2+1])))->sin() ; OclFile["System.out"].println(S) ; OclFile["System.out"].println(L) ; OclFile["System.out"].println(h) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); double a=in.nextDouble(),b=in.nextDouble(),C=in.nextDouble(); C=Math.toRadians(C); double c=Math.sqrt(a*a+b*b-2*a*b*Math.cos(C)); double S=0.5*a*b*Math.sin(C); double L=a+b+c ; double h=b*Math.sin(C); System.out.printf("%.8f\n",S); System.out.printf("%.8f\n",L); System.out.printf("%.8f\n",h); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : double ; a := in.getCurrent()->toReal() ; var b : double ; b := in.getCurrent()->toReal() ; var C : double ; C := in.getCurrent()->toReal() ; C := (0.017453292519943295*(C)) ; var c : double ; c := (a * a + b * b - 2 * a * b * (C)->cos())->sqrt() ; var S : double ; S := 0.5 * a * b * (C)->sin() ; var L : double ; L := a + b + c ; var h : double ; h := b * (C)->sin() ; OclFile["System.out"].printf("%.8f\n", S) ; OclFile["System.out"].printf("%.8f\n", L) ; OclFile["System.out"].printf("%.8f\n", h) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int count=0 ; public static void main(String[] args){ @ SuppressWarnings("resource")Scanner sc2=new Scanner(System.in); String[] s=sc2.nextLine().split("[\\s]+"); double a=Double.parseDouble(s[0]); double b=Double.parseDouble(s[1]); double theta=Double.parseDouble(s[2])*(Math.PI/180); double c=Math.sqrt(a*a+b*b-2*a*b*Math.cos(theta)); double s1=0.5*a*b*Math.sin(theta); double h=(2*s1)/a ; System.out.println(s1); System.out.println(a+b+c); System.out.println(h); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute count : int := 0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc2 : OclFile ; sc2 := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : Sequence(String) ; s := sc2.nextLine()->split("[\\s]+") ; var a : double ; a := (s[0+1])->toReal() ; var b : double ; b := (s[1+1])->toReal() ; var theta : double ; theta := (s[2+1])->toReal() * (3.141592653589793 / 180) ; var c : double ; c := (a * a + b * b - 2 * a * b * (theta)->cos())->sqrt() ; var s1 : double ; s1 := 0.5 * a * b * (theta)->sin() ; var h : double ; h := (2 * s1) / a ; OclFile["System.out"].println(s1) ; OclFile["System.out"].println(a + b + c) ; OclFile["System.out"].println(h) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String[] tmp=in.readLine().split(" "); double a=Double.parseDouble(tmp[0]); double b=Double.parseDouble(tmp[1]); double C=Math.PI*Double.parseDouble(tmp[2])/180.0 ; double h=b*Math.sin(C); double S=0.5*a*h ; double c=Math.sqrt(a*a+b*b-2*a*b*Math.cos(C)); double L=a+b+c ; System.out.printf("%.5f\n",S); System.out.printf("%.5f\n",L); System.out.printf("%.5f\n",h); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var tmp : Sequence(String) ; tmp := in.readLine()->split(" ") ; var a : double ; a := (tmp[0+1])->toReal() ; var b : double ; b := (tmp[1+1])->toReal() ; var C : double ; C := 3.141592653589793 * (tmp[2+1])->toReal() / 180.0 ; var h : double ; h := b * (C)->sin() ; var S : double ; S := 0.5 * a * h ; var c : double ; c := (a * a + b * b - 2 * a * b * (C)->cos())->sqrt() ; var L : double ; L := a + b + c ; OclFile["System.out"].printf("%.5f\n", S) ; OclFile["System.out"].printf("%.5f\n", L) ; OclFile["System.out"].printf("%.5f\n", h) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] tmpArray=br.readLine().split(" "); int input[]=new int[n]; int diff=0 ; for(int i=1 ; i<=n ; i++){ input[i-1]=Integer.parseInt(tmpArray[i-1]); if(input[i-1]!=i){ diff++; } } if(diff<=2){ System.out.println("YES"); } else { System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var tmpArray : Sequence(String) ; tmpArray := br.readLine()->split(" ") ; var input : Sequence(int) ; input := Integer.subrange(1,n)->collect(0) ; var diff : int ; diff := 0 ; var i : int ; i := 1 ; while i <= n do ( ( input[i - 1+1] := (tmpArray[i - 1+1])->toInteger() ; if (input[i - 1+1] /= i) then ( diff := diff + 1 ) else skip ) ; i := i + 1 ) ; if (diff <= 2) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[])throws Exception { Scanner s=new Scanner(System.in); int N=s.nextInt(); int i=1 ; String result="YES" ; int count=0 ; while(i<=N){ int p=s.nextInt(); count+=i!=p ? 1 : 0 ; if(count>2){ result="NO" ; break ; } i++; } System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := s.getCurrent()->toInteger() ; var i : int ; i := 1 ; var result : String ; result := "YES" ; var count : int ; count := 0 ; while (i <= N) do ( var p : int ; p := s.getCurrent()->toInteger() ; count := count+(if i /= p then 1 else 0 endif) ; if (count > 2) then ( result := "NO" ; break ) else skip ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static String pref(String str,int ind){ StringBuffer bf=new StringBuffer(); int cnt=0 ; for(int i=ind-1 ; i>=0 && str.charAt(i)!='-' ; i--){ if(cnt % 3==0 && cnt!=0){ bf.append(','); } bf.append(str.charAt(i)); cnt++; } return bf.reverse().toString(); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); StringBuffer bf=new StringBuffer(); int ind=-1 ; for(int i=0 ; i= 0 & str->at(i+1) /= '-' do ( ( if (cnt mod 3 = 0 & cnt /= 0) then ( bf := bf + StringLib.newString(',') ) else skip ; bf := bf + StringLib.newString(str->at(i+1)) ; cnt := cnt + 1 ) ; i := i - 1 ) ; return bf->reverse()+"" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; var bf : String ; bf := StringLib.newString() ; var ind : int ; ind := -1 ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = '.') then ( ind := i ; break ) else skip ) ; i := i + 1 ) ; var prefix : String ; prefix := "" ; var suffix : String ; suffix := "" ; if (ind = -1) then ( prefix := pref(str, str->size()) ; suffix := ".00" ) else ( prefix := pref(str, ind) ; suffix := suffix+(".") ; var i : int ; i := ind + 1 ; while i <= ind + 2 do ( ( if (i < str->size()) then ( suffix := suffix+(str->at(i+1)) ) else ( suffix := suffix+('0') ) ) ; i := i + 1 ) ) ; if (str->at(0+1) = '-') then ( prefix := "($" + prefix ; suffix := suffix+(")") ) else ( prefix := "$" + prefix ) ; OclFile["System.out"].println(prefix + suffix) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); char map[][]=new char[50][50]; int r=sc.nextInt(); int c=sc.nextInt(); sc.nextLine(); for(int y=0 ; ycollect(Integer.subrange(1,50)->collect(0)) ; var r : int ; r := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; skip ; var y : int ; y := 0 ; while y < r do ( ( var s : String ; s := sc.nextLine() ; var x : int ; x := 0 ; while x < c do ( ( map[y+1][x+1] := s->at(x+1) ) ; x := x + 1 ) ) ; y := y + 1 ) ; var minCount : int ; minCount := 2147483647 ; var count : int ; var w_line : int ; w_line := 0 ; while w_line < (r)->char2byte() - 2 do ( ( count := 0 ; var line : int ; line := 0 ; while line <= w_line do ( ( count := count+(difCharLineCount(map[line+1], 'W', c)) ) ; line := line + 1 ) ; var t_cnt : int ; t_cnt := count ; var r_line : int ; r_line := w_line + 2 ; while r_line < r do ( ( var line : int ; line := w_line + 1 ; while line < r_line do ( ( count := count+(difCharLineCount(map[line+1], 'B', c)) ) ; line := line + 1 ) ; var line : int ; line := r_line ; while line < r do ( ( count := count+(difCharLineCount(map[line+1], 'R', c)) ) ; line := line + 1 ) ; if (count < minCount) then ( minCount := count ) else skip ; count := t_cnt ) ; r_line := r_line + 1 ) ) ; w_line := w_line + 1 ) ; OclFile["System.out"].println(minCount) ; ); static operation difCharLineCount( chars : Sequence(String), targetChar : String, limit : int) : int pre: true post: true activity: ( var ret : int ; ret := 0 ; var x : int ; x := 0 ; while x < limit do ( ( if (chars[x+1] /= targetChar) then ( ret := ret + 1 ) else skip ) ; x := x + 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class codechef_submission { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int k=sc.nextInt(); int[] b=new int[n]; if(nd.length-1-(k-1); i--){ sum-=d[i]; } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class codechef_submission { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; if (n < k) then ( OclFile["System.out"].println(n) ; return ) else skip ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var d : Sequence(int) ; d := Integer.subrange(1,n - 1)->collect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( ( d[i+1] := b[i + 1+1] - b[i+1] - 1 ) ; i := i + 1 ) ; d := d->sort() ; var sum : int ; sum := b[b->size() - 1+1] - b[0+1] + 1 ; var i : int ; i := d->size() - 1 ; while i > d->size() - 1 - (k - 1) do ( ( sum := sum-(d[i+1]) ) ; i := i - 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); B0Or1Swap solver=new B0Or1Swap(); solver.solve(1,in,out); out.close(); } static class B0Or1Swap { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(); int a[]=new int[n+1]; int count=0 ; for(int i=1 ; i<=n ; i++)a[i]=in.nextInt(); for(int i=1 ; i<=n ; i++){ if(a[i]==i){ continue ; } if(a[a[i] ]==i){ count++; int temp=a[i]; a[i]=i ; a[temp]=temp ; continue ; } out.println("NO"); return ; } if(count<=1)out.println("YES"); else { out.println("NO"); } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : B0Or1Swap ; solver := B0Or1Swap.newB0Or1Swap() ; solver.solve(1, in, out) ; skip ; ); static class B0Or1Swap { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i <= n do ( a[i+1] := in.nextInt() ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( if (a[i+1] = i) then ( continue ) else skip ; if (a[a[i+1]+1] = i) then ( count := count + 1 ; var temp : int ; temp := a[i+1] ; a[i+1] := i ; a[temp+1] := temp ; continue ) else skip ; skip ; return ) ; i := i + 1 ) ; if (count <= 1) then skip else ( skip ) ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ListinitialList=new ArrayList(); for(int i=0 ; isortedList=initialList.stream().sorted().collect(Collectors.toList()); int count=0 ; String message="YES" ; for(int i=0 ; i2){ message="NO" ; break ; } } } System.out.println(message); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var initialList : Sequence(int) ; initialList := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( initialList := initialList->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var sortedList : Sequence(int) ; sortedList := initialList->sort().collect(Collectors.toList()) ; var count : int ; count := 0 ; var message : String ; message := "YES" ; var i : int ; i := 0 ; while i < n do ( ( if (initialList->at(i+1) /= sortedList->at(i+1)) then ( count := count + 1 ; if (count > 2) then ( message := "NO" ; break ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(message) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int ary[]=new int[n]; for(int i=0 ; iary[i+1]){ if(x==0){ x=ary[i]; } else if(y==0){ y=ary[i+1]; } } } for(int i=0 ; iary[i+1]){ if(k==0){ ary[i]=y ; k+=1 ; } else if(k==1){ ary[i+1]=x ; k+=1 ; } } } for(int i=0 ; iary[i+1]){ return false ; } } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var ary : Sequence(int) ; ary := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < ary->size() do ( ( ary[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; if (isAscendingOrder(ary)) then ( OclFile["System.out"].print("YES") ) else ( OclFile["System.out"].print("NO") ) ; ); static operation isAscendingOrder( ary : Sequence(int)) : boolean pre: true post: true activity: ( var x : int ; x := 0 ; var y : int ; y := 0 ; var k : int ; k := 0 ; var i : int ; i := 0 ; while i < ary->size() - 1 do ( ( if (ary[i+1] > ary[i + 1+1]) then ( if (x = 0) then ( x := ary[i+1] ) else if (y = 0) then ( y := ary[i + 1+1] ) else skip ; ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < ary->size() - 1 do ( ( if (ary[i+1] > ary[i + 1+1]) then ( if (k = 0) then ( ary[i+1] := y ; k := k+(1) ) else if (k = 1) then ( ary[i + 1+1] := x ; k := k+(1) ) else skip ; ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < ary->size() - 1 do ( ( if (ary[i+1] > ary[i + 1+1]) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int N=3 ; static int M=3 ; static int sumMaxOccurring(int arr[][]){ Mapmp=new HashMap<>(); for(int i=0 ; iitr : mp.entrySet()){ if(itr.getValue()>maxFreq){ maxFreq=itr.getValue(); } } for(Map.Entryitr : mp.entrySet()){ if(itr.getValue()==maxFreq){ sum+=(itr.getKey())*(itr.getValue()); } } return sum ; } public static void main(String[] args){ int mat[][]={ { 1,2,3 },{ 1,3,2 },{ 1,5,6 } }; System.out.println(sumMaxOccurring(mat)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute N : int := 3; static attribute M : int := 3; static operation sumMaxOccurring( arr : Sequence(Sequence(int))) : int pre: true post: true activity: ( var mp : Map(int,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( if (mp->keys()->includes(arr[i+1][j+1])) then ( mp := mp->union(Map{arr[i+1][j+1] |-> mp->at(arr[i+1][j+1]) + 1}) ) else ( mp := mp->union(Map{arr[i+1][j+1] |-> 1}) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var maxFreq : int ; maxFreq := -2147483648 ; for (itr : mp->asSet()) do ( ( if (itr.getValue() > maxFreq) then ( maxFreq := itr.getValue() ) else skip ) ) ; for (itr : mp->asSet()) do ( ( if (itr.getValue() = maxFreq) then ( sum := sum+((itr.getKey()) * (itr.getValue())) ) else skip ) ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{1,2,3},Sequence{1,3,2},Sequence{1,5,6}} ; OclFile["System.out"].println(sumMaxOccurring(mat)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int N=3 ; static int M=3 ; static int sumOddOccurring(int arr[][]){ Mapmp=new HashMap<>(); for(int i=0 ; iitr : mp.entrySet()){ if(itr.getValue()% 2!=0){ sum+=(itr.getKey())*(itr.getValue()); } } return sum ; } public static void main(String[] args){ int mat[][]={ { 1,2,3 },{ 1,3,2 },{ 1,5,6 } }; System.out.println(sumOddOccurring(mat)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute N : int := 3; static attribute M : int := 3; static operation sumOddOccurring( arr : Sequence(Sequence(int))) : int pre: true post: true activity: ( var mp : Map(int,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( if (mp->keys()->includes(arr[i+1][j+1])) then ( mp := mp->union(Map{arr[i+1][j+1] |-> mp->at(arr[i+1][j+1]) + 1}) ) else ( mp := mp->union(Map{arr[i+1][j+1] |-> 1}) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; for (itr : mp->asSet()) do ( ( if (itr.getValue() mod 2 /= 0) then ( sum := sum+((itr.getKey()) * (itr.getValue())) ) else skip ) ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{1,2,3},Sequence{1,3,2},Sequence{1,5,6}} ; OclFile["System.out"].println(sumOddOccurring(mat)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int SumOfDigits(String str,int n){ int sum=0 ; for(int i=0 ; iat(i+1) - ('0')->char2byte())->oclAsType(int)) ; ; i := i + 1 ) ; return sum ); static operation Divisible( str : String, n : int) : boolean pre: true post: true activity: ( if (SumOfDigits(str, n) mod 3 = 0 & str->at(n - 1+1) = '0') then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "263730746028908374890" ; var n : int ; n := str->size() ; if (Divisible(str, n)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int total=sc.nextInt(); int[] need=new int[total-1]; for(int i=0 ; itoInteger() ; var need : Sequence(int) ; need := Integer.subrange(1,total - 1)->collect(0) ; var i : int ; i := 0 ; while i < need->size() do ( ( need[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var first : int ; first := sc.getCurrent()->toInteger() ; var end : int ; end := sc.getCurrent()->toInteger() ; var stay : int ; stay := 0 ; var i : int ; i := 0 ; var j : int ; j := first - 1 ; while i < end - first do ( ( stay := stay+(need[j+1]) ) ; i := i + 1 ; j := j + 1 ) ; OclFile["System.out"].println(stay) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ans=0 ; int[] d=new int[n]; for(int i=0 ; i=a-1 && itoInteger() ; var ans : int ; ans := 0 ; var d : Sequence(int) ; d := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( ( d[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (i >= a - 1 & i < b - 1) then ( ans := ans+(d[i+1]) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class subArr { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int arr[]=new int[n]; for(int i=1 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 1 ; while i < n do ( ( arr[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var i : int ; i := a ; while i < b do ( ( sum := sum+(arr[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Sheet4ProblemC { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int[] ranksYears=new int[n-1]; for(int i=0 ; itoInteger() ; var ranksYears : Sequence(int) ; ranksYears := Integer.subrange(1,n - 1)->collect(0) ; var i : int ; i := 0 ; while i < n - 1 do ( ( ranksYears[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ; var a : int ; a := input.getCurrent()->toInteger() ; var b : int ; b := input.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := a - 1 ; while i < b - 1 do ( count := count+(ranksYears[i+1]) ; ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _32_Jzzhu_and_Children { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); Queueq1=new LinkedList<>(); Queueq2=new LinkedList<>(); for(int i=1 ; i<=n ; i++){ q1.add(sc.nextInt()); q2.add(i); } int ans=0 ; while(! q1.isEmpty()){ if(q1.peek()<=m){ q1.poll(); ans=q2.poll(); } else if(q1.peek()>m){ int x=q1.poll(); int val=x-m ; q1.add(val); int val2=q2.poll(); q2.add(val2); } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class _32_Jzzhu_and_Children { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var q1 : Sequence(int) ; q1 := Sequence{} ; var q2 : Sequence(int) ; q2 := Sequence{} ; var i : int ; i := 1 ; while i <= n do ( ( q1 := q1->including(sc.getCurrent()->toInteger()) ; q2 := q2->including(i) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; while (not(q1->isEmpty())) do ( if (q1->min() <= m) then ( q1 := q1->sort()->tail() ; ans := q2->min() ; q2 := q2->sort()->tail() ) else if (q1->min() > m) then ( var x : int ; x := q1->min() ; var val : int ; val := x - m ; q1 := q1->including(val) ; var val2 : int ; val2 := q2->min() ; q2 := q2->including(val2) ; ) else skip ; ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Collections ; import java.util.StringTokenizer ; public class Run { public static void main(String[] Z)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stz ; stz=new StringTokenizer(br.readLine()); int n=Integer.parseInt(stz.nextToken()); int m=Integer.parseInt(stz.nextToken()); int k=Integer.parseInt(stz.nextToken()); stz=new StringTokenizer(br.readLine()); int[] segments=new int[n]; for(int i=0 ; idiffs=new ArrayList<>(n); for(int i=1 ; itoInteger() ; var m : int ; m := (stz.next())->toInteger() ; var k : int ; k := (stz.next())->toInteger() ; stz := OclIterator.newOclIterator_String(br.readLine()) ; var segments : Sequence(int) ; segments := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( segments[i+1] := (stz.next())->toInteger() ) ; i := i + 1 ) ; var diffs : Sequence(int) ; diffs := Sequence{} ; var i : int ; i := 1 ; while i < n do ( ( diffs := diffs->including(segments[i+1] - segments[i - 1+1]) ) ; i := i + 1 ) ; diffs := diffs->sort() ; var ans : int ; ans := n ; var i : int ; i := 0 ; while i < n - k do ( ( ans := ans+(diffs->at(i+1) - 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { static final int W=0 ; static final int B=1 ; static final int R=2 ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; line=br.readLine(); int N,M ; N=parseInt(line.substring(0,line.indexOf(' '))); M=parseInt(line.substring(line.indexOf(' ')+1)); int[][] wbr=new int[N][3]; for(int i=0 ; iindexOf(' ')-1) + "")->toInteger() ; M := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var wbr : Sequence(Sequence(int)) ; wbr := Integer.subrange(1,N)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( line := br.readLine() ; for (c : line->characters()) do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (c) ; if _switchval = 'W' then wbr[i+1][B+1] := wbr[i+1][B+1] + 1 ; wbr[i+1][R+1] := wbr[i+1][R+1] + 1 ; break else skip ; if _switchval = 'B' then wbr[i+1][W+1] := wbr[i+1][W+1] + 1 ; wbr[i+1][R+1] := wbr[i+1][R+1] + 1 ; break else skip ; if _switchval = 'R' then wbr[i+1][W+1] := wbr[i+1][W+1] + 1 ; wbr[i+1][B+1] := wbr[i+1][B+1] + 1 ; break else skip ; ) ) ) ) ; i := i + 1 ) ; var min : int ; min := N * M ; var i : int ; i := 1 ; while i < (N)->char2byte() - 1 do ( ( var j : int ; j := i ; while j < (N)->char2byte() - 1 do ( ( var change : int ; change := 0 ; var k : int ; k := 1 ; while k < (N)->char2byte() - 1 do ( ( if (k < i) then ( change := change+(wbr[k+1][W+1]) ) else if (i <= k & k <= j) then ( change := change+(wbr[k+1][B+1]) ) else ( change := change+(wbr[k+1][R+1]) ) ; ) ; k := k + 1 ) ; min := Set{min, change}->min() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(wbr[0+1][W+1] + min + wbr[(N)->char2byte() - 1+1][R+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int[] arr=new int[x]; int l=arr.length-1 ; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,x)->collect(0) ; var l : int ; l := arr->size() - 1 ; var i : int ; i := 0 ; while i < l do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; while (m /= n) do ( sum := sum+(arr[m - 1+1]) ; m := m + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,i ; int[] a ; n=sc.nextInt(); a=new int[n]; for(i=0 ; i=r){ if(lcollect(0) ; i := 0 ; while i < n do ( a[i+1] := sc.nextInt() ; ; i := i + 1 ) ; out.println(count(a, 0, n)) ; sc.close() ; ); static operation count( c : Sequence(int), l : int, r : int) : long pre: true post: true activity: ( var m : int ; if (l + 1 >= r) then ( if (l < r) then return 0 else skip ; return 1 ) else ( m := (l + r) / 2 ; return (count(c, l, m) + count(c, m, r) + merge(c, l, m, r)) ) ); static operation merge( c : Sequence(int), l : int, m : int, r : int) : long pre: true post: true activity: ( var nl : int ; var nr : int ; var i : int ; var j : int ; var k : int ; var infi : int ; infi := 1980000000 ; var cl : Sequence(int) ; var cr : Sequence(int) ; var count : long ; nl := m - l ; nr := r - m ; cl := Integer.subrange(1,nl + 1)->collect(0) ; cr := Integer.subrange(1,nr + 1)->collect(0) ; i := 0 ; while i < nl do ( cl[i+1] := c[l + i+1] ; ; i := i + 1 ) ; i := 0 ; while i < nr do ( cr[i+1] := c[m + i+1] ; ; i := i + 1 ) ; cl[nl+1] := infi ; cr[nr+1] := infi ; i := 0 ; j := 0 ; count := 0 ; k := l ; while k < r do ( ( if (cl[i+1] < cr[j+1]) then c[k+1] := cl[i+1] ; i := i + 1 ; else ( c[k+1] := cr[j+1] ; j := j + 1 ; count := count+((nl - i)) ) ) ; k := k + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; public class Main { int SENTINEL=1234567890 ; long sum=0 ; void merge(int[] A,int left,int mid,int right){ int n1=mid-left+1 ; int n2=right-mid ; int[] L=new int[n1+1]; int[] R=new int[n2+1]; for(int i=0 ; icollect(0) ; var R : Sequence(int) ; R := Integer.subrange(1,n2 + 1)->collect(0) ; var i : int ; i := 0 ; while i < n1 do ( ( L[i+1] := A[left + i+1] ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n2 do ( ( R[i+1] := A[mid + 1 + i+1] ) ; i := i + 1 ) ; L[n1+1] := SENTINEL ; R[n2+1] := SENTINEL ; var i : int ; i := 0 ; var j : int ; j := 0 ; var k : int ; k := left ; while k <= right do ( ( if (L[i+1] <= R[j+1]) then ( sum := sum+(k - i - left) ; A[k+1] := L[i+1] ; i := i + 1 ) else ( A[k+1] := R[j+1] ; j := j + 1 ) ) ; k := k + 1 ) ; ); operation mergeSort( A : Sequence(int), left : int, right : int) : void pre: true post: true activity: ( if (left < right) then ( var mid : int ; mid := (left + right) / 2 ; execute mergeSort(A, left, mid) ; execute mergeSort(A, mid + 1, right) ; execute merge(A, left, mid, right) ) else skip ); operation run() : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var A : Sequence(int) ; A := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := (str[i+1])->toInteger() ) ; i := i + 1 ) ; execute mergeSort(A, 0, n - 1) ; OclFile["System.out"].println(sum) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static long count=0 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute mergeSort(a, 0, n) ; OclFile["System.out"].println(count) ; ); static operation mergeSort( s : Sequence(int), left : int, right : int) : void pre: true post: true activity: ( if (left + 1 < right) then ( var mid : int ; mid := (left + right) / 2 ; execute mergeSort(s, left, mid) ; execute mergeSort(s, mid, right) ; execute merge(s, left, mid, right) ) else skip ); static operation merge( s : Sequence(int), left : int, mid : int, right : int) : void pre: true post: true activity: ( var L : Sequence(int) ; L := Integer.subrange(1,mid - left + 1)->collect(0) ; var R : Sequence(int) ; R := Integer.subrange(1,right - mid + 1)->collect(0) ; for _x : Integer.subrange(1,L->size() - 1) do L[0 + _x] := s[left + _x] ; for _x : Integer.subrange(1,R->size() - 1) do R[0 + _x] := s[mid + _x] ; L[L->size() - 1+1] := 2147483647 ; R[R->size() - 1+1] := 2147483647 ; var i : int ; i := 0 ; var j : int ; j := 0 ; var k : int ; k := left ; while k < right do ( ( if (L[i+1] <= R[j+1]) then ( s[k+1] := L[i+1] ; i := i + 1 ; count := count+(j) ) else ( s[k+1] := R[j+1] ; j := j + 1 ) ) ; k := k + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class Main { private static long inversions=0 ; public static void main(String[] args)throws java.lang.Exception { Scanner s=new Scanner(System.in); int arraySize=s.nextInt(); int[] A=new int[arraySize]; for(int i=0 ; i=right){ return ; } int mid=(right+left)/2 ; mergeSort(A,left,mid); mergeSort(A,mid,right); merge(A,left,mid,right); } public static void merge(int[] A,int left,int mid,int right){ int n1=mid-left ; int n2=right-mid ; int[] L=new int[n1]; int[] R=new int[n2]; for(int i=0 ; i=n2){ A[k]=L[i]; i=i+1 ; continue ; } if(i>=n1){ A[k]=R[j]; inversions+=L.length-i ; j=j+1 ; continue ; } if(L[i]<=R[j]){ A[k]=L[i]; i=i+1 ; } else { A[k]=R[j]; inversions+=L.length-i ; j=j+1 ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute inversions : long := 0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var arraySize : int ; arraySize := s.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,arraySize)->collect(0) ; var i : int ; i := 0 ; while i < arraySize do ( ( A[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute mergeSort(A, 0, A->size()) ; OclFile["System.out"].println(inversions) ; ); static operation mergeSort( A : Sequence(int), left : int, right : int) : void pre: true post: true activity: ( if (left + 1 >= right) then ( return ) else skip ; var mid : int ; mid := (right + left) / 2 ; execute mergeSort(A, left, mid) ; execute mergeSort(A, mid, right) ; execute merge(A, left, mid, right) ; ); static operation merge( A : Sequence(int), left : int, mid : int, right : int) : void pre: true post: true activity: ( var n1 : int ; n1 := mid - left ; var n2 : int ; n2 := right - mid ; var L : Sequence(int) ; L := Integer.subrange(1,n1)->collect(0) ; var R : Sequence(int) ; R := Integer.subrange(1,n2)->collect(0) ; var i : int ; i := 0 ; while i < n1 do ( ( L[i+1] := A[left + i+1] ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n2 do ( ( R[i+1] := A[mid + i+1] ) ; i := i + 1 ) ; var i : int ; i := 0 ; var j : int ; j := 0 ; var k : int ; k := left ; while k < right do ( ( if (j >= n2) then ( A[k+1] := L[i+1] ; i := i + 1 ; continue ) else skip ; if (i >= n1) then ( A[k+1] := R[j+1] ; inversions := inversions+(L->size() - i) ; j := j + 1 ; continue ) else skip ; if (L[i+1] <= R[j+1]) then ( A[k+1] := L[i+1] ; i := i + 1 ) else ( A[k+1] := R[j+1] ; inversions := inversions+(L->size() - i) ; j := j + 1 ) ) ; k := k + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { static Scanner sc=new Scanner(System.in); static int m,n ; static int[] dx={ -1,0,1,0 },dy={ 0,1,0,-1 }; static int[][] field=new int[92][92]; public static void main(String[] args){ for(int i=0 ; icollect(Integer.subrange(1,92)->collect(0)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < field->size() do ( execute fill(field[i+1], 0) ; ; i := i + 1 ) ; while (read()) do OclFile["System.out"].println(solve()) ; ); static operation read() : boolean pre: true post: true activity: ( m := sc.getCurrent()->toInteger() ; n := sc.getCurrent()->toInteger() ; if (m = 0) then return false else skip ; var i : int ; i := 1 ; while i <= n do ( var j : int ; j := 1 ; while j <= m do ( field[i+1][j+1] := sc.getCurrent()->toInteger() ; ; j := j + 1 ) ; ; i := i + 1 ) ; return true ); static operation solve() : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( var j : int ; j := 1 ; while j <= m do ( if (field[i+1][j+1] = 1) then ans := Set{ans, rec(j, i, 1)}->max() ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; return ans ); static operation rec( x : int, y : int, step : int) : int pre: true post: true activity: ( var ret : int ; ret := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( var nx : int ; nx := x + dx[i+1] ; var ny : int ; ny := y + dy[i+1] ; if (field[ny+1][nx+1] = 1) then ( field[y+1][x+1] := 0 ; ret := Set{ret, rec(nx, ny, step + 1)}->max() ; field[y+1][x+1] := 1 ) else ( ret := Set{ret, step}->max() ) ) ; i := i + 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { static int n,m ; static int[] dx={ 0,0,-1,1 },dy={ -1,1,0,0 }; static boolean[][] map,check ; public static int dfs(int y,int x){ int ret=0 ; for(int i=0 ; i<4 ; i++){ int nextX=x+dx[i]; int nextY=y+dy[i]; if(0<=nextX && nextXmax() ; check[nextY+1][nextX+1] := false ) else skip ) ; i := i + 1 ) ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; while (true) do ( m := (s.readLine())->toInteger() ; n := (s.readLine())->toInteger() ; if (m = 0 & n = 0) then break else skip ; map := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(false)) ; var i : int ; i := 0 ; while i < n do ( ( var data : Sequence(String) ; data := s.readLine()->split(" ") ; var j : int ; j := 0 ; while j < m do ( map[i+1][j+1] := (data[j+1])->toInteger() = 1 ; ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( if (map[i+1][j+1]) then ( check := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(false)) ; max := Set{max, dfs(i, j)}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int M,N ; static boolean[][] f ; static int ans ; static int[] DR={ 1,0,-1,0 }; static int[] DC={ 0,1,0,-1 }; static void dfs(int r,int c,int d){ f[r][c]=false ; for(int i=0 ; i<4 ; ++i){ int nr=r+DR[i]; int nc=c+DC[i]; if(nr<0 || N<=nr || nc<0 || M<=nc || ! f[nr][nc])continue ; dfs(nr,nc,d+1); } f[r][c]=true ; ans=Math.max(ans,d); } public static void main(String[] args){ while(true){ M=sc.nextInt(); N=sc.nextInt(); if(N==0)break ; f=new boolean[N][M]; ans=0 ; for(int i=0 ; imax() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (true) do ( M := sc.getCurrent()->toInteger() ; N := sc.getCurrent()->toInteger() ; if (N = 0) then break else skip ; f := Integer.subrange(1,N)->collect(Integer.subrange(1,M)->collect(false)) ; ans := 0 ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( f[i+1][j+1] := sc.getCurrent() = "1" ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( if (f[i+1][j+1]) then execute dfs(i, j, 1) ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class B { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),m=in.nextInt(),k=in.nextInt(); int[] a=new int[n]; Arrays.setAll(a,i->in.nextInt()); PriorityQueuepq=new PriorityQueue<>(); for(int i=1 ; i0){ int v=pq.remove(); res+=v ; } pw.println(res); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; setAll(a, lambda i : OclAny in in.getCurrent()->toInteger()) ; var pq : Sequence(int) ; pq := Sequence{} ; var i : int ; i := 1 ; while i < n do ( pq := pq->including((a[i+1] - a[i - 1+1]) - 1) ; ; i := i + 1 ) ; var res : long ; res := n ; n := n-(k) ; while (n > 0) do ( n := n - 1 ; skip ; ( var v : int ; v := pq.remove() ; res := res+(v) ) ; ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); while(true){ w=scanner.nextInt(); h=scanner.nextInt(); if((w | h)==0)break ; map=new boolean[h][w]; for(int i=0 ; itoInteger() ; h := scanner.getCurrent()->toInteger() ; if ((w or h) = 0) then break else skip ; map := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(false)) ; var i : int ; i := 0 ; while i < h do ( var j : int ; j := 0 ; while j < w do ( map[i+1][j+1] := scanner.getCurrent()->toInteger() = 0 ; ; j := j + 1 ) ; ; i := i + 1 ) ; ans := 0 ; var i : int ; i := 0 ; while i < h do ( var j : int ; j := 0 ; while j < w do ( ( if (map[i+1][j+1]) then continue else skip ; map[i+1][j+1] := true ; execute dfs(i, j, 1) ; map[i+1][j+1] := false ) ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); operation dfs( y : int, x : int, depth : int) : void pre: true post: true activity: ( ans := Set{ans, depth}->max() ; for (m : move) do ( ( var ny : int ; ny := y + m[0+1] ; var nx : int ; nx := x + m[1+1] ; if (not(isOK(ny, nx))) then continue else skip ; if (map[ny+1][nx+1]) then continue else skip ; map[ny+1][nx+1] := true ; execute dfs(ny, nx, depth + 1) ; map[ny+1][nx+1] := false ; ) ) ); operation isOK( y : int, x : int) : boolean pre: true post: true activity: ( if (0 <= y & y < h & 0 <= x & x < w) then return true else skip ; return false ); attribute h : int; attribute move : Sequence(Sequence(int)) := Sequence{Sequence{-1,0},Sequence{0,-1},Sequence{0,1},Sequence{1,0}}; attribute map : Sequence(Sequence(boolean)); attribute ans : int; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { PrintStream log=new PrintStream(new OutputStream(){ public void write(int b){ } } ); PrintStream result=System.out ; Scanner sc=new Scanner(System.in); void main()throws IOException { int N=sc.nextInt(); int M=sc.nextInt(); sc.nextLine(); String[] s=new String[N]; for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; skip ; var s : Sequence(String) ; s := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( s[i+1] := sc.nextLine() ) ; i := i + 1 ) ; var min : int ; min := 2147483647 ; var WL : int ; WL := 1 ; while WL < N - 1 do ( ( var BL : int ; BL := 1 ; while BL < N - WL do ( ( var cnt : int ; cnt := 0 ; var n : int ; n := 0 ; while n < N do ( ( var c : String ; c := 'R' ; if (n < WL) then c := 'W' else if (n < WL + BL) then c := 'B' ; else skip ; ; var m : int ; m := 0 ; while m < s[n+1]->size() do ( ( if (s[n+1]->at(m+1) /= c) then ( cnt := cnt + 1 ) else skip ) ; m := m + 1 ) ) ; n := n + 1 ) ; skip ; min := Set{cnt, min}->min() ) ; BL := BL + 1 ) ) ; WL := WL + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().main() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); while(true){ int h=sc.nextInt(); int w=sc.nextInt(); if(h==0 && w==0){ break ; } boolean[][] field=new boolean[h][w]; for(int i=0 ; i=field.length || w<0 || w>=field[0] .length || ! field[h][w]){ return 0 ; } int max=0 ; field[h][w]=false ; max=Math.max(max,getCount(h-1,w,field)); max=Math.max(max,getCount(h+1,w,field)); max=Math.max(max,getCount(h,w-1,field)); max=Math.max(max,getCount(h,w+1,field)); field[h][w]=true ; return max+1 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sb : String ; sb := StringLib.newString() ; while (true) do ( var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; if (h = 0 & w = 0) then ( break ) else skip ; var field : Sequence(Sequence(boolean)) ; field := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(false)) ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( field[i+1][j+1] := (sc.getCurrent()->toInteger() = 1) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( if (field[i+1][j+1]) then ( max := Set{max, getCount(i, j, field)}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; sb := sb + StringLib.newString(max) + StringLib.newString("\n") ; ) ; OclFile["System.out"].print(sb) ); static operation getCount( h : int, w : int, field : Sequence(Sequence(boolean))) : int pre: true post: true activity: ( if (h < 0 or h >= field->size() or w < 0 or w >= field[0+1]->size() or not(field[h+1][w+1])) then ( return 0 ) else skip ; var max : int ; max := 0 ; field[h+1][w+1] := false ; max := Set{max, getCount((h)->char2byte() - 1, w, field)}->max() ; max := Set{max, getCount(h + 1, w, field)}->max() ; max := Set{max, getCount(h, w - 1, field)}->max() ; max := Set{max, getCount(h, w + 1, field)}->max() ; field[h+1][w+1] := true ; return max + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Solve s=new Solve(); s.solve(); } } class Solve { Solve(){ } Scanner in=new Scanner(System.in); void solve(){ while(in.hasNext()){ int n=in.nextInt(),k=in.nextInt(); if(n==0 && k==0)return ; int[] a=new int[n]; for(int i=0 ; itoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; if (n = 0 & k = 0) then return else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var t : int ; var i : int ; i := 0 ; while i < k do ( ( ans := ans+(a[i+1]) ) ; i := i + 1 ) ; t := ans ; var s : int ; s := 0 ; var i : int ; i := k ; while i < n do ( ( t := t + a[i+1] - a[s+1] ; s := s + 1 ; ans := Set{ans, t}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.stream.Collectors ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int cnt=-9 ; int range=-9 ; String line ; Listinputs=new ArrayList<>(); while((line=br.readLine().trim())!=null && ! line.isEmpty()&& ! "0 0".equals(line)){ if(cnt<0){ Listlist=Arrays.stream(line.split(" ")).map(Integer :: valueOf).collect(Collectors.toList()); cnt=list.get(0); range=list.get(1); } else { inputs.add(Integer.valueOf(line)); if(--cnt==0){ output(inputs,range); inputs.clear(); cnt=-9 ; } } } } public static void output(Listlist,int range){ int sum=IntStream.range(0,range).map(j->list.get(j)).sum(); int max=sum ; for(int i=range ; itrim() ; while ((line) /= null & not(line->isEmpty()) & not("0 0" = line)) do ( skip ; ( if (cnt < 0) then ( var list : Sequence(int) ; list := stream(line->split(" "))->collect( _x1 | (lambda _pars : OclAny in Integer.newInteger().valueOf(_pars))->apply(_x1) ).collect(Collectors.toList()) ; cnt := list->at(0+1) ; range := list->at(1+1) ) else ( inputs := inputs->including((line)->toInteger()) ; if ((cnt - 1) = 0) then ( execute output(inputs, range) ; inputs := inputs->intersection(Set{}) ; cnt := -9 ) else skip ) ) ; line := br.readLine()->trim() ; ) ; ); static operation output( list : Sequence(int), range : int) : void pre: true post: true activity: ( var sum : int ; sum := Integer.subrange(0, range-1)->collect( _x1 | (lambda j : OclAny in list->at(j+1))->apply(_x1) )->sum() ; var max : int ; max := sum ; var i : int ; i := range ; while i < list->size() do ( ( sum := sum - list->at(i - range+1) + list->at(i+1) ; if (max < sum) then max := sum ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static class BIT { int[] dat ; public BIT(int n){ dat=new int[n+1]; } public void add(int k,int a){ for(int i=k+1 ; i0)return sum(0,t)-sum(0,s); int ret=0 ; for(int i=t ; i>0 ; i-=i &-i){ ret+=dat[i]; } return ret ; } public int get(int k){ int p=Integer.highestOneBit(dat.length-1); for(int q=p ; q>0 ; q>>=1,p |=q){ if(p>=dat.length || kcollect(0) ); operation add( k : int, a : int) : void pre: true post: true activity: ( var i : int ; i := k + 1 ; while i < dat->size() do ( ( dat[i+1] := dat[i+1]+(a) ) ; i := i+(MathLib.bitwiseAnd(i,-i)) ) ); operation sum( s : int, t : int) : int pre: true post: true activity: ( if (s > 0) then return sum(0, t) - sum(0, s) else skip ; var ret : int ; ret := 0 ; var i : int ; i := t ; while i > 0 do ( ( ret := ret+(dat[i+1]) ) ; i := i-(MathLib.bitwiseAnd(i,-i)) ) ; return ret ); operation get( k : int) : int pre: true post: true activity: ( var p : int ; p := highestOneBit(dat->size() - 1) ; var q : int ; q := p ; while q > 0 do ( ( if (p >= dat->size() or k < dat[p+1]) then p := MathLib.bitwiseXor(p,q) ; else k := k-(dat[p+1]) ; ) ; q := q/(2->pow(1)) ; p := MathLib.bitwiseOr(p, q) ) ; return p ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; if (n = 0 & k = 0) then ( break ) else skip ; var bit : BIT ; bit := BIT.newBIT(n) ; var i : int ; i := 0 ; while i < n do ( ( bit->excludes(i, sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var start : int ; start := 0 ; while start < n - k + 1 do ( ( max := Set{max, bit.sum(start, start + k)}->max() ) ; start := start + 1 ) ; OclFile["System.out"].println(max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(); int k=stdIn.nextInt(); int[] ans=new int[1000]; int index=0 ; while(n!=0 || k!=0){ int sum=0 ; int[] num=new int[n]; for(int i=0 ; imax){ max=sum ; } } ans[index]=max ; index++; n=stdIn.nextInt(); k=stdIn.nextInt(); } for(int i=0 ; itoInteger() ; var k : int ; k := stdIn.getCurrent()->toInteger() ; var ans : Sequence(int) ; ans := Integer.subrange(1,1000)->collect(0) ; var index : int ; index := 0 ; while (n /= 0 or k /= 0) do ( var sum : int ; sum := 0 ; var num : Sequence(int) ; num := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < k do ( ( num[i+1] := stdIn.getCurrent()->toInteger() ; sum := sum+(num[i+1]) ) ; i := i + 1 ) ; var i : int ; i := k ; while i < n do ( ( num[i+1] := stdIn.getCurrent()->toInteger() ) ; i := i + 1 ) ; var max : int ; max := sum ; var i : int ; i := 0 ; while i < n - k do ( ( sum := sum - num[i+1] + num[i + k+1] ; if (sum > max) then ( max := sum ) else skip ) ; i := i + 1 ) ; ans[index+1] := max ; index := index + 1 ; n := stdIn.getCurrent()->toInteger() ; k := stdIn.getCurrent()->toInteger() ; ) ; var i : int ; i := 0 ; while i < index do ( ( OclFile["System.out"].println(ans[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader reader=new BufferedReader(isr); String string ; int n,m,max,conflict,array[]; while(!(string=reader.readLine()).equals("0 0")){ n=Integer.valueOf(string.split(" ")[0]); m=Integer.valueOf(string.split(" ")[1]); array=new int[n]; for(int i=0 ; isplit(" ")[0+1])->toInteger() ; m := (string->split(" ")[1+1])->toInteger() ; array := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( array[i+1] := (reader.readLine())->toInteger() ; ; i := i + 1 ) ; max := 0 ; var i : int ; i := 0 ; while i < m do ( max := max+(array[i+1]) ; ; i := i + 1 ) ; conflict := max ; var i : int ; i := 0 ; while i < (n)->char2byte() - (m)->char2byte() - 1 do ( ( conflict := conflict+(array[i + m+1] - array[i+1]) ; if (max < conflict) then max := conflict ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countDivisibleSubseq(String str,int n){ int len=str.length(); int dp[][]=new int[len][n]; dp[0][(str.charAt(0)-'0')% n]++; for(int i=1 ; isize() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,len)->collect(Integer.subrange(1,n)->collect(0)) ; dp[0+1][(str->at(0+1) - ('0')->char2byte()) mod n+1] := dp[0+1][(str->at(0+1) - ('0')->char2byte()) mod n+1] + 1 ; var i : int ; i := 1 ; while i < len do ( ( dp[i+1][(str->at(i+1) - ('0')->char2byte()) mod n+1] := dp[i+1][(str->at(i+1) - ('0')->char2byte()) mod n+1] + 1 ; var j : int ; j := 0 ; while j < n do ( ( dp[i+1][j+1] := dp[i+1][j+1]+(dp[i - 1+1][j+1]) ; dp[i+1][(j * 10 + (str->at(i+1) - ('0')->char2byte())) mod n+1] := dp[i+1][(j * 10 + (str->at(i+1) - ('0')->char2byte())) mod n+1]+(dp[i - 1+1][j+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[len - 1+1][0+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "1234" ; var n : int ; n := 4 ; OclFile["System.out"].print(countDivisibleSubseq(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Generate { static void printWellOrdered(int number,int x,int k){ if(k==0){ System.out.print(number+" "); return ; } for(int i=(x+1); i<10 ; i++)printWellOrdered(number*10+i,i,k-1); } static void generateWellOrdered(int k){ printWellOrdered(0,0,k); } public static void main(String[] args){ int k=3 ; generateWellOrdered(k); } } ------------------------------------------------------------ OCL File: --------- class Generate { static operation printWellOrdered( number : int, x : int, k : int) : void pre: true post: true activity: ( if (k = 0) then ( OclFile["System.out"].print(number + " ") ; return ) else skip ; var i : int ; i := (x + 1) ; while i < 10 do ( execute printWellOrdered(number * 10 + i, i, k - 1) ; ; i := i + 1 ) ); static operation generateWellOrdered( k : int) : void pre: true post: true activity: ( execute printWellOrdered(0, 0, k) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 3 ; execute generateWellOrdered(k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Collections ; import java.util.StringTokenizer ; public class Run { public static void main(String[] Z)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stz ; stz=new StringTokenizer(br.readLine()); int n=Integer.parseInt(stz.nextToken()); int m=Integer.parseInt(stz.nextToken()); int k=Integer.parseInt(stz.nextToken()); stz=new StringTokenizer(br.readLine()); int[] segments=new int[n]; for(int i=0 ; idiffs=new ArrayList<>(n); for(int i=1 ; itoInteger() ; var m : int ; m := (stz.next())->toInteger() ; var k : int ; k := (stz.next())->toInteger() ; stz := OclIterator.newOclIterator_String(br.readLine()) ; var segments : Sequence(int) ; segments := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( segments[i+1] := (stz.next())->toInteger() ) ; i := i + 1 ) ; var diffs : Sequence(int) ; diffs := Sequence{} ; var i : int ; i := 1 ; while i < n do ( ( diffs := diffs->including(segments[i+1] - segments[i - 1+1]) ) ; i := i + 1 ) ; diffs := diffs->sort() ; var ans : int ; ans := n ; var i : int ; i := 0 ; while i < n - k do ( ( ans := ans+(diffs->at(i+1) - 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Hello { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); long n=in.nextLong(),k=in.nextLong(); long sum=1 ; long ans=0 ; long c=1 ; while(true){ sum=(c*(c+1))/2 ; if(sum-k==n-c){ ans=sum-k ; break ; } c++; } pw.println(ans); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Hello { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : long ; n := in.getCurrent()->toLong() ; var k : long ; k := in.getCurrent()->toLong() ; var sum : long ; sum := 1 ; var ans : long ; ans := 0 ; var c : long ; c := 1 ; while (true) do ( sum := (c * (c + 1)) / 2 ; if (sum - k = n - c) then ( ans := sum - k ; break ) else skip ; c := c + 1 ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ESportMafia { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int moves=sc.nextInt()-1 ; int candies=sc.nextInt(); int caja=1,pone=1,poneprev=1,come=0 ; while(moves>0){ if(caja>candies){ come++; caja--; } else { pone++; caja+=pone ; } moves--; } System.out.println(come); } } ------------------------------------------------------------ OCL File: --------- class ESportMafia { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var moves : int ; moves := sc.getCurrent()->toInteger() - 1 ; var candies : int ; candies := sc.getCurrent()->toInteger() ; var caja : int ; caja := 1 ; var pone : int ; pone := 1 ; var poneprev : int ; poneprev := 1 ; var come : int ; come := 0 ; while (moves > 0) do ( if (caja > candies) then ( come := come + 1 ; caja := caja - 1 ) else ( pone := pone + 1 ; caja := caja+(pone) ) ; moves := moves - 1 ) ; OclFile["System.out"].println(come) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Mridul6 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextInt(); long k=sc.nextInt(); if(n==1 && k==1){ System.out.println(0); } else { long i=0 ; int no=0 ; while((i*(i+1))/2k){ if(((i*(i+1))/2)-k==n-i){ no=1 ; } } } if(no==1){ System.out.println(n-i); } } } } ------------------------------------------------------------ OCL File: --------- class Mridul6 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toInteger() ; var k : long ; k := sc.getCurrent()->toInteger() ; if (n = 1 & k = 1) then ( OclFile["System.out"].println(0) ) else ( var i : long ; i := 0 ; var no : int ; no := 0 ; while ((i * (i + 1)) / 2 < k or no = 0) do ( i := i + 1 ; if (((i * (i + 1)) / 2) > k) then ( if (((i * (i + 1)) / 2) - k = n - i) then ( no := 1 ) else skip ) else skip ) ; if (no = 1) then ( OclFile["System.out"].println(n - i) ) else skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); ArrayDequelist=new ArrayDeque(); int count=0 ; int n=sc.nextInt(); for(int i=0 ; i.newArrayDeque() ; var count : int ; count := 0 ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( list := list->append(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var q : int ; q := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( if (list->includes(sc.getCurrent()->toInteger()) = true) then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.out ; import static java.lang.Math.*; class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int ary[]=new int[n]; for(int i=0 ; iq[i])break ; } } out.println(rec); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var ary : Sequence(int) ; ary := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ary[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; ary := ary->sort() ; var m : int ; m := scan.getCurrent()->toInteger() ; var j : int ; j := 0 ; var rec : int ; rec := 0 ; var q : Sequence(int) ; q := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( q[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; q := q->sort() ; var i : int ; i := 0 ; while i < m do ( ( while j < n do ( ( if (ary[j+1] = q[i+1]) then ( j := j + 1 ; rec := rec + 1 ; break ) else if (ary[j+1] > q[i+1]) then break else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; out.println(rec) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { static int count=0 ; public static void main(String[] args){ @ SuppressWarnings("resource")Scanner sc2=new Scanner(System.in); int n=Integer.parseInt(sc2.nextLine()); String[] s=sc2.nextLine().split("[\\s]+"); int[] x=new int[n]; for(int i=0 ; ilist=new ArrayList(); for(int h=0 ; htoInteger() ; var s : Sequence(String) ; s := sc2.nextLine()->split("[\\s]+") ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := (s[i+1])->toInteger() ) ; i := i + 1 ) ; var n2 : int ; n2 := (sc2.nextLine())->toInteger() ; var s2 : Sequence(String) ; s2 := sc2.nextLine()->split("[\\s]+") ; var x2 : Sequence(int) ; x2 := Integer.subrange(1,n2)->collect(0) ; if (s2[0+1] = "") then ( var i : int ; i := 0 ; while i < n2 do ( ( x2[i+1] := (s2[i + 1+1])->toInteger() ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < n2 do ( ( x2[i+1] := (s2[i+1])->toInteger() ) ; i := i + 1 ) ) ; var list : Sequence(int) ; list := Sequence{} ; var h : int ; h := 0 ; while h < n do ( ( var g : int ; g := 0 ; while g < n2 do ( ( if (x[h+1] = x2[g+1]) then ( if (list->includes(x[h+1])) then ( break ) else ( count := count + 1 ; list := list->including(x[h+1]) ) ) else skip ) ; g := g + 1 ) ) ; h := h + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner kbd=new Scanner(System.in); public static void main(String[] args){ int n=kbd.nextInt(); int[] s=new int[n]; int i ; for(i=0 ; is[j])min=j ; } w=s[i]; s[i]=s[min]; s[min]=w ; } } public static boolean search(int[] s,int x){ int low=0 ; int high=s.length-1 ; int middle=(high+low)/2 ; while(low<=high){ if(s[middle]==x)return true ; else if(s[middle]toInteger() ; var s : Sequence(int) ; s := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := kbd.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute sort(s) ; var cnt : int ; cnt := 0 ; var m : int ; m := kbd.getCurrent()->toInteger() ; i := 0 ; while i < m do ( ( var x : int ; x := kbd.getCurrent()->toInteger() ; var a : boolean ; a := search(s, x) ; if (a) then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); static operation sort( s : Sequence(int)) : void pre: true post: true activity: ( var i : int ; var min : int ; var j : int ; var w : int ; i := 0 ; while i < s->size() do ( ( min := i ; j := i ; while j < s->size() do ( ( if (s[min+1] > s[j+1]) then min := j ; else skip ) ; j := j + 1 ) ; w := s[i+1] ; s[i+1] := s[min+1] ; s[min+1] := w ; ) ; i := i + 1 ) ); static operation search( s : Sequence(int), x : int) : boolean pre: true post: true activity: ( var low : int ; low := 0 ; var high : int ; high := s->size() - 1 ; var middle : int ; middle := (high + low) / 2 ; while (low <= high) do ( if (s[middle+1] = x) then return true else if (s[middle+1] < x) then low := middle + 1 else high := middle - 1 ; ; ; middle := (high + low) / 2 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n,q ; int cnt=0 ; ArrayListS=new ArrayList(); ArrayListlist=new ArrayList(); n=Integer.parseInt(br.readLine()); StringTokenizer st=new StringTokenizer(br.readLine()," "); for(int i=0 ; itoInteger() ; var st : OclIterator ; st := OclIterator.newOclIterator_String_String(br.readLine(), " ") ; var i : int ; i := 0 ; while i < n do ( S := S->including((st.next())->toInteger()) ; ; i := i + 1 ) ; q := (br.readLine())->toInteger() ; st := OclIterator.newOclIterator_String_String(br.readLine(), " ") ; var i : int ; i := 0 ; while i < q do ( ( var temp : int ; temp := (st.next())->toInteger() ; if (S->includes(temp) & not(list->includes(temp))) then ( list := list->including(temp) ; cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int m=sc.nextInt(); int cnt=0 ; String arr[]=new String[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var cnt : int ; cnt := 0 ; var arr : Sequence(String) ; arr := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1]->at(m - 1+1) = 'R') then ( cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (arr[n - 1+1]->at(i+1) = 'D') then ( cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.PriorityQueue ; public class Tape { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { String[] temp=br.readLine().split(" "); int n=Integer.parseInt(temp[0]); int m=Integer.parseInt(temp[1]); int k=Integer.parseInt(temp[2]); int[] nums=new int[n]; temp=br.readLine().split(" "); for(int i=0 ; i=n){ pr.println(n); return ; } PriorityQueuegaps=new PriorityQueue<>(); for(int i=0 ; ik){ res+=gaps.poll(); current--; } pr.println(res); } } ------------------------------------------------------------ OCL File: --------- class Tape { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pr : OclFile ; pr := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve(br, pr) ; skip ; skip ; ); static operation solve( br : OclFile, pr : OclFile) : void pre: true post: true activity: ( var temp : Sequence(String) ; temp := br.readLine()->split(" ") ; var n : int ; n := (temp[0+1])->toInteger() ; var m : int ; m := (temp[1+1])->toInteger() ; var k : int ; k := (temp[2+1])->toInteger() ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; temp := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := (temp[i+1])->toInteger() ) ; i := i + 1 ) ; if (k >= n) then ( skip ; return ) else skip ; var gaps : Sequence(int) ; gaps := Sequence{} ; var i : int ; i := 0 ; while i < n - 1 do ( ( gaps := gaps->including(nums[i + 1+1] - nums[i+1] - 1) ) ; i := i + 1 ) ; var res : int ; res := n ; var current : int ; current := n ; while (current > k) do ( res := res + gaps->min() ; gaps := gaps->sort()->tail() ; current := current - 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test288 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var a : Sequence(Sequence(String)) ; a := Integer.subrange(1,n)->collect(Sequence{}) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var b : Sequence(String) ; b := in.getCurrent()->characters() ; a[i+1] := b ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1][m - 1+1] = 'R') then ( sum := sum + 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (a[n - 1+1][i+1] = 'D') then ( sum := sum + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Sol { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int num=sc.nextInt(); for(int p=0 ; ptoInteger() ; var p : int ; p := 0 ; while p < num do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := sc.getCurrent() ; if (i = n - 1) then ( var j : int ; j := 0 ; while j < m do ( ( if (s->at(j+1) = 'D') then count := count + 1 ; else skip ) ; j := j + 1 ) ) else skip ; if (s->at(m - 1+1) = 'R') then count := count + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) ; p := p + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1391B_FixYou { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ int row=input.nextInt(); int col=input.nextInt(); input.nextLine(); ListrightColumn=new ArrayList<>(); ListdownRow=new ArrayList<>(); for(int i=1 ; i<=row ; i++){ String eachRow=input.nextLine(); char c=eachRow.charAt(col-1); rightColumn.add(c); if(i==row){ for(char ch : eachRow.toCharArray()){ downRow.add(ch); } } } int a=Collections.frequency(rightColumn,'R'); int b=Collections.frequency(downRow,'D'); System.out.println(a+b); } } } ------------------------------------------------------------ OCL File: --------- class _1391B_FixYou { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; while (test > 0) do ( test := test - 1 ; skip ; ( var row : int ; row := input.getCurrent()->toInteger() ; var col : int ; col := input.getCurrent()->toInteger() ; skip ; var rightColumn : Sequence(String) ; rightColumn := Sequence{} ; var downRow : Sequence(String) ; downRow := Sequence{} ; var i : int ; i := 1 ; while i <= row do ( ( var eachRow : String ; eachRow := input.nextLine() ; var c : String ; c := eachRow->at(col - 1+1) ; rightColumn := rightColumn->including(c) ; if (i = row) then ( for (ch : eachRow->characters()) do ( ( downRow := downRow->including(ch) ) ) ) else skip ) ; i := i + 1 ) ; var a : int ; a := .frequency(rightColumn, 'R') ; var b : int ; b := .frequency(downRow, 'D') ; OclFile["System.out"].println(a + b) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] w=new int[n]; int[] b=new int[n]; int[] r=new int[n]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var w : Sequence(int) ; w := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var r : Sequence(int) ; r := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var str : String ; str := sc.getCurrent() ; var j : int ; j := 0 ; while j < m do ( ( var c : String ; c := str->at(j+1) ; if (c = 'W') then ( w[i+1] := w[i+1] + 1 ) else if (c = 'B') then ( b[i+1] := b[i+1] + 1 ) else ( r[i+1] := r[i+1] + 1 ) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 100000000 ; var i : int ; i := 1 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var tmp : int ; tmp := 0 ; var k : int ; k := 0 ; while k < i do ( ( tmp := tmp+(m - w[k+1]) ) ; k := k + 1 ) ; var k : int ; k := i ; while k < j do ( ( tmp := tmp+(m - b[k+1]) ) ; k := k + 1 ) ; var k : int ; k := j ; while k < n do ( ( tmp := tmp+(m - r[k+1]) ) ; k := k + 1 ) ; ans := Set{ans, tmp}->min() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class MainClass { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int t=Integer.parseInt(st.nextToken()); while(t-->0){ st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(st.nextToken()); char[][] mat=new char[n][m]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( st := OclIterator.newOclIterator_String(br.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var m : int ; m := (st.next())->toInteger() ; var mat : Sequence(Sequence(String)) ; mat := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( st := OclIterator.newOclIterator_String(br.readLine()) ; var s : String ; s := st.next() ; var j : int ; j := 0 ; while j < m do ( ( mat[i+1][j+1] := s->at(j+1) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (mat[i+1][m - 1+1] = 'R') then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (mat[n - 1+1][i+1] = 'D') then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class ReplaceDigits { static int replace0with5(int number){ return number+=calculateAddedValue(number); } private static int calculateAddedValue(int number){ int result=0 ; int decimalPlace=1 ; if(number==0){ result+=(5*decimalPlace); } while(number>0){ if(number % 10==0)result+=(5*decimalPlace); number/=10 ; decimalPlace*=10 ; } return result ; } public static void main(String[] args){ System.out.print(replace0with5(1020)); } } ------------------------------------------------------------ OCL File: --------- class ReplaceDigits { static operation replace0with5( number : int) : int pre: true post: true activity: ( return number ); static operation calculateAddedValue( number : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; var decimalPlace : int ; decimalPlace := 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/(10) ; decimalPlace := decimalPlace*(10) ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].print(replace0with5(1020)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int power(long x,long y,long p){ long res=1 ; x=x % p ; while(y>0){ if((y & 1)!=0)res=(res*x)% p ; y=y>>1 ; x=(x*x)% p ; } return(int)res ; } static void printLastKDigits(int a,int b,int k){ System.out.print("Last "+k+" digits of "+a+"^"+b+"="); int temp=1 ; for(int i=1 ; i<=k ; i++)temp*=10 ; temp=power(a,b,temp); for(int i=0 ; i 0) do ( if ((y & 1) /= 0) then res := (res * x) mod p ; else skip ; y := (y/(2->pow(1)))->oclAsType(long) ; x := (x * x) mod p ) ; return res->oclAsType(int) ); static operation printLastKDigits( a : int, b : int, k : int) : void pre: true post: true activity: ( OclFile["System.out"].print("Last " + k + " digits of " + a + "^" + b + "=") ; var temp : int ; temp := 1 ; var i : int ; i := 1 ; while i <= k do ( temp := temp*(10) ; ; i := i + 1 ) ; temp := power(a, b, temp) ; var i : int ; i := 0 ; while i < k - ((temp) + "")->size() do ( OclFile["System.out"].print(0) ; ; i := i + 1 ) ; if (temp /= 0) then OclFile["System.out"].print(temp) ; else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 11 ; var b : int ; b := 3 ; var k : int ; k := 2 ; execute printLastKDigits(a, b, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { final static int MAX=26 ; static int minOperation(String str,int len){ int first[]=new int[MAX]; int last[]=new int[MAX]; for(int i=0 ; icollect(0) ; var last : Sequence(int) ; last := Integer.subrange(1,MAX)->collect(0) ; var i : int ; i := 0 ; while i < MAX do ( ( first[i+1] := -1 ; last[i+1] := -1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < len do ( ( var index : int ; index := (str->at(i+1) - ('a')->char2byte()) ; if (first[index+1] = -1) then first[index+1] := i ; else skip ; last[index+1] := i ) ; i := i + 1 ) ; var minOp : int ; minOp := -1 ; var i : int ; i := 0 ; while i < MAX do ( ( if (first[i+1] = -1 or first[i+1] = last[i+1]) then continue else skip ; var cnt : int ; cnt := len - (last[i+1] - first[i+1] + 1) ; if (minOp = -1 or cnt < minOp) then minOp := cnt ; else skip ) ; i := i + 1 ) ; return minOp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "abcda" ; var len : int ; len := str->size() ; OclFile["System.out"].println(minOperation(str, len)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MemoryTrident { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); if(scanner.hasNext()){ String s=scanner.next(); int x=0 ; int y=0 ; if(s.length()==1 || s.length()% 2!=0)System.out.println(-1); else { for(char ch : s.toCharArray()){ if(ch=='U')x++; if(ch=='D')x--; if(ch=='L')y--; if(ch=='R')y++; } System.out.println((Math.abs(x)+Math.abs(y))/2); } } } } ------------------------------------------------------------ OCL File: --------- class MemoryTrident { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; if (scanner.hasNext()) then ( var s : String ; s := scanner.getCurrent() ; var x : int ; x := 0 ; var y : int ; y := 0 ; if (s->size() = 1 or s->size() mod 2 /= 0) then OclFile["System.out"].println(-1) ; else ( for (ch : s->characters()) do ( ( if (ch = 'U') then x := x + 1 ; else skip ; if (ch = 'D') then x := x - 1 ; else skip ; if (ch = 'L') then y := y - 1 ; else skip ; if (ch = 'R') then y := y + 1 ; else skip ) ) ; OclFile["System.out"].println((if x < 0 then -(x) else x endif + if y < 0 then -(y) else y endif) / 2) ) ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p040 implements EulerSolution { public static void main(String[] args){ System.out.println(new p040().run()); } public String run(){ StringBuilder sb=new StringBuilder(); for(int i=1 ; i<1000000 ; i++)sb.append(i); int prod=1 ; for(int i=0 ; i<=6 ; i++)prod*=sb.charAt(Library.pow(10,i)-1)-'0' ; return Integer.toString(prod); } } ------------------------------------------------------------ OCL File: --------- class p040 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p040.newp040().run()) ); operation run() : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; var i : int ; i := 1 ; while i < 1000000 do ( sb := sb + StringLib.newString(i) ; ; i := i + 1 ) ; var prod : int ; prod := 1 ; var i : int ; i := 0 ; while i <= 6 do ( prod := prod*(sb->at(Library.pow(10, i) - 1+1) - ('0')->char2byte()) ; ; i := i + 1 ) ; return ((prod) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int onesComplement(int n){ int number_of_bits=(int)(Math.floor(Math.log(n)/Math.log(2)))+1 ; return((1<log() / (2)->log())->floor())->oclAsType(int) + 1 ; return (((1*(2->pow(number_of_bits)))->oclAsType(long)) - 1) xor n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 22 ; OclFile["System.out"].print(onesComplement(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class IfAtFirstYouDontSucceed { public static void main(String[] args){ Scanner in=new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); int n=in.nextInt(); if(a>=n || b>=n || c>=n ||(a-c+b)>=n || atoInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var c : int ; c := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; if (a >= n or b >= n or c >= n or (a - c + b) >= n or a < c or b < c) then OclFile["System.out"].println(-1) else OclFile["System.out"].println(n - (a - c + b)) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int a=in.nextInt(),b=in.nextInt(),c=in.nextInt(),n=in.nextInt(); System.out.println(getResult(a,b,c,n)); in.close(); } static int getResult(int a,int b,int c,int n){ if(a>n || b>n || c>n)return-1 ; if(atoInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var c : int ; c := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; OclFile["System.out"].println(getResult(a, b, c, n)) ; skip ); static operation getResult( a : int, b : int, c : int, n : int) : int pre: true post: true activity: ( if (a > n or b > n or c > n) then return -1 else skip ; if (a < c or b < c) then return -1 else skip ; var res : int ; res := n - (a + b - c) ; if (res < 1) then return -1 else skip ; return res ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner console=new Scanner(System.in); int bd=console.nextInt(),bk=console.nextInt(),both=console.nextInt(),total=console.nextInt(); int answer=bd+bk-(both); if(answer<0 || answer>=total || bktoInteger() ; var bk : int ; bk := console.getCurrent()->toInteger() ; var both : int ; both := console.getCurrent()->toInteger() ; var total : int ; total := console.getCurrent()->toInteger() ; var answer : int ; answer := bd + bk - (both) ; if (answer < 0 or answer >= total or bk < both or bd < both) then OclFile["System.out"].println(-1) ; else OclFile["System.out"].println(total - answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int n=sc.nextInt(); int lessPass=a-c ; int morePass=b-c ; int totalPassed=lessPass+morePass+c ; int ans=n-totalPassed ; if(ans<=0 || lessPass<0 || morePass<0)System.out.println(-1); else System.out.println(ans); } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var lessPass : int ; lessPass := a - c ; var morePass : int ; morePass := b - c ; var totalPassed : int ; totalPassed := lessPass + morePass + c ; var ans : int ; ans := n - totalPassed ; if (ans <= 0 or lessPass < 0 or morePass < 0) then OclFile["System.out"].println(-1) else OclFile["System.out"].println(ans) ; ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Vector ; class GFG { static void printPermutation(int N,int K){ Vectorres=new Vector<>(); int l=1,r=N,flag=0 ; for(int i=0 ; i=l ; i--){ res.add(i); } } else { for(int i=l ; i<=r ; i++){ res.add(i); } } for(Integer i : res){ System.out.print(i+" "); } } public static void main(String[] args){ int N=10,K=4 ; printPermutation(N,K); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printPermutation( N : int, K : int) : void pre: true post: true activity: ( var res : Sequence(int) ; res := Sequence{} ; var l : int ; l := 1 ; var r : int ; r := N ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < K do ( ( if (flag = 0) then ( res := res->including(l) ; l := l + 1 ) else ( res := res->including(r) ; r := r - 1 ) ; flag := MathLib.bitwiseXor(flag,1) ) ; i := i + 1 ) ; if (flag /= 1) then ( var i : int ; i := r ; while i >= l do ( ( res := res->including(i) ) ; i := i - 1 ) ) else ( var i : int ; i := l ; while i <= r do ( ( res := res->including(i) ) ; i := i + 1 ) ) ; for (i : res) do ( ( OclFile["System.out"].print(i + " ") ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 10 ; var K : int ; K := 4 ; execute printPermutation(N, K) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedOutputStream ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Map ; import java.util.PriorityQueue ; import java.util.Queue ; import java.util.Scanner ; import java.util.StringTokenizer ; import java.util.TreeMap ; public class Practice1 { public static void main(String[] args){ PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); FastReader sc=new FastReader(); int k=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); int v=sc.nextInt(); int min=Math.min(k,b+1); int count=0 ; while(a>0){ int x=Math.min(k,Math.max(b+1,1)); a-=x*v ; b-=x-1 ; count++; } out.println(count); out.close(); } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Practice1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var sc : FastReader ; sc := FastReader.newFastReader() ; var k : int ; k := sc.nextInt() ; var a : int ; a := sc.nextInt() ; var b : int ; b := sc.nextInt() ; var v : int ; v := sc.nextInt() ; var min : int ; min := Set{k, b + 1}->min() ; var count : int ; count := 0 ; while (a > 0) do ( var x : int ; x := Set{k, Set{b + 1, 1}->max()}->min() ; a := a-(x * v) ; b := b-(x - 1) ; count := count + 1 ) ; skip ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int c=in.nextInt(),v0=in.nextInt(),v1=in.nextInt(),a=in.nextInt(),l=in.nextInt(); int count=0 ; int j=0 ; while(c>0){ c-=v0-j ; j=l ; v0=Math.min(v0+a,v1); count++; } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var c : int ; c := in.getCurrent()->toInteger() ; var v0 : int ; v0 := in.getCurrent()->toInteger() ; var v1 : int ; v1 := in.getCurrent()->toInteger() ; var a : int ; a := in.getCurrent()->toInteger() ; var l : int ; l := in.getCurrent()->toInteger() ; var count : int ; count := 0 ; var j : int ; j := 0 ; while (c > 0) do ( c := c-(v0 - j) ; j := l ; v0 := Set{v0 + a, v1}->min() ; count := count + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedOutputStream ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Map ; import java.util.PriorityQueue ; import java.util.Queue ; import java.util.Scanner ; import java.util.StringTokenizer ; import java.util.TreeMap ; public class Practice2 { public static void main(String[] args){ PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); FastReader sc=new FastReader(); int c=sc.nextInt(); int vo=sc.nextInt(); int v1=sc.nextInt(); int a=sc.nextInt(); int l=sc.nextInt(); int count=1 ; int comp=vo ; while(compmin() ; comp := comp+((vo - l)) ) ; skip ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _820A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int c=sc.nextInt(),v0=sc.nextInt(),v1=sc.nextInt(),a=sc.nextInt(),l=sc.nextInt(); if(c==0){ System.out.println(0); return ; } int days=1 ; int pages=v0 ; int capacity=v0 ; while(pagestoInteger() ; var v0 : int ; v0 := sc.getCurrent()->toInteger() ; var v1 : int ; v1 := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var l : int ; l := sc.getCurrent()->toInteger() ; if (c = 0) then ( OclFile["System.out"].println(0) ; return ) else skip ; var days : int ; days := 1 ; var pages : int ; pages := v0 ; var capacity : int ; capacity := v0 ; while (pages < c) do ( capacity := Set{v1, capacity + a}->min() ; pages := pages+(capacity - l) ; days := days + 1 ) ; OclFile["System.out"].println(days) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class IsDivisible { static boolean isDivisibleBy25(String str){ int n=str.length(); if(n==1)return false ; return((str.charAt(n-1)-'0'==0 && str.charAt(n-2)-'0'==0)||((str.charAt(n-2)-'0')*10+(str.charAt(n-1)-'0'))% 25==0); } public static void main(String[] args){ String str="76955" ; if(isDivisibleBy25(str))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class IsDivisible { static operation isDivisibleBy25( str : String) : boolean pre: true post: true activity: ( var n : int ; n := str->size() ; if (n = 1) then return false else skip ; return ((str->at(n - 1+1) - ('0')->char2byte() = 0 & str->at(n - 2+1) - ('0')->char2byte() = 0) or ((str->at(n - 2+1) - ('0')->char2byte()) * 10 + (str->at(n - 1+1) - ('0')->char2byte())) mod 25 = 0) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "76955" ; if (isDivisibleBy25(str)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NewClass27 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int w=in.nextInt(); int h=in.nextInt(); int n=in.nextInt(); int sheet=1 ; while(w % 2==0){ w/=2 ; sheet*=2 ; } while(h % 2==0){ h/=2 ; sheet*=2 ; } if(sheet>=n){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class NewClass27 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var w : int ; w := in.getCurrent()->toInteger() ; var h : int ; h := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; var sheet : int ; sheet := 1 ; while (w mod 2 = 0) do ( w := w/(2) ; sheet := sheet*(2) ) ; while (h mod 2 = 0) do ( h := h/(2) ; sheet := sheet*(2) ) ; if (sheet >= n) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; class GFG { static void printPair(int g,int l){ int n=g*l ; for(int i=1 ; i*i<=n ; i++){ if(n % i==0){ int first=i ; int second=n/i ; int gcd=__gcd(first,second); if(gcd==g && l % first==0 && l % second==0){ System.out.println(first+" "+second); return ; } } } } private static int __gcd(int a,int b){ BigInteger b1=new BigInteger(""+a); BigInteger b2=new BigInteger(""+b); BigInteger gcd=b1.gcd(b2); return gcd.intValue(); } public static void main(String[] args){ int g=3,l=12 ; printPair(g,l); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printPair( g : int, l : int) : void pre: true post: true activity: ( var n : int ; n := g * l ; var i : int ; i := 1 ; while i * i <= n do ( ( if (n mod i = 0) then ( var first : int ; first := i ; var second : int ; second := n / i ; var gcd : int ; gcd := __gcd(first, second) ; if (gcd = g & l mod first = 0 & l mod second = 0) then ( OclFile["System.out"].println(first + " " + second) ; return ) else skip ) else skip ) ; i := i + 1 ) ); static operation __gcd( a : int, b : int) : int pre: true post: true activity: ( var b1 : long ; b1 := long("" + a) ; var b2 : long ; b2 := long("" + b) ; var gcd : long ; gcd := b1.gcd(b2) ; return gcd->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var g : int ; g := 3 ; var l : int ; l := 12 ; execute printPair(g, l) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static VectorprocessQueries(int Q[],int m,int n){ int[] a=new int[m+1]; int[] pos=new int[m+1]; for(int i=1 ; i<=m ; i++){ a[i-1]=i ; pos[i]=i-1 ; } Vectorans=new Vector(); for(int i=0 ; i0 ; j--){ a[j]=a[j]+a[j-1]; a[j-1]=a[j]-a[j-1]; a[j]=a[j]-a[j-1]; pos[a[j] ]=j ; } pos[a[0] ]=0 ; } return ans ; } public static void main(String[] args){ int Q[]={ 3,1,2,1 }; int n=Q.length ; int m=5 ; Vectorans=new Vector(); ans=processQueries(Q,m,n); for(int i=0 ; icollect(0) ; var pos : Sequence(int) ; pos := Integer.subrange(1,m + 1)->collect(0) ; var i : int ; i := 1 ; while i <= m do ( ( a[i - 1+1] := i ; pos[i+1] := i - 1 ) ; i := i + 1 ) ; var ans : Sequence(int) ; ans := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var q : int ; q := Q[i+1] ; var p : int ; p := pos[q+1] ; ans := ans->including(p) ; var j : int ; j := p ; while j > 0 do ( ( a[j+1] := a[j+1] + a[j - 1+1] ; a[j - 1+1] := a[j+1] - a[j - 1+1] ; a[j+1] := a[j+1] - a[j - 1+1] ; pos[a[j+1]+1] := j ) ; j := j - 1 ) ; pos[a[0+1]+1] := 0 ; ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var Q : Sequence(int) ; Q := Sequence{3,1,2,1} ; var n : int ; n := Q->size() ; var m : int ; m := 5 ; var ans : Sequence(int) ; ans := Sequence{} ; ans := processQueries(Q, m, n) ; var i : int ; i := 0 ; while i < ans->size() do ( OclFile["System.out"].print(ans->at(i+1) + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(); int l=stdIn.nextInt(); int[] t=new int[n]; for(int i=0 ; iMath.abs(t[i]))min=Math.abs(t[i]); } int total=0 ; for(int i=0 ; itoInteger() ; var l : int ; l := stdIn.getCurrent()->toInteger() ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( t[i+1] := l + i ) ; i := i + 1 ) ; var min : int ; min := if t[0+1] < 0 then -(t[0+1]) else t[0+1] endif ; var i : int ; i := 1 ; while i < n do ( ( if (min > if t[i+1] < 0 then -(t[i+1]) else t[i+1] endif) then min := if t[i+1] < 0 then -(t[i+1]) else t[i+1] endif ; else skip ) ; i := i + 1 ) ; var total : int ; total := 0 ; var i : int ; i := 0 ; while i < n do ( ( total := total+(t[i+1]) ) ; i := i + 1 ) ; if (t[n - 1+1] < 0) then OclFile["System.out"].println(total + min) else OclFile["System.out"].println(total - min) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; public class Main { double EPS=10.e-08 ; private void doit(){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int a=sc.nextInt(); int[] data=new int[n]; long sum=0 ; for(int i=0 ; iMath.abs(data[i])){ min=Math.abs(data[i]); value=data[i]; } } System.out.println(sum-value); } } private void debug(Object...o){ System.out.println("debug="+Arrays.deepToString(o)); } public static void main(String[] args){ new Main().doit(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute EPS : double := 10.e-08; operation doit() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var data : Sequence(int) ; data := Integer.subrange(1,n)->collect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( data[i+1] := i + a ; sum := sum+(data[i+1]) ) ; i := i + 1 ) ; var min : int ; min := 2147483647 ; var value : int ; value := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (min > if data[i+1] < 0 then -(data[i+1]) else data[i+1] endif) then ( min := if data[i+1] < 0 then -(data[i+1]) else data[i+1] endif ; value := data[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(sum - value) ; ) ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println("debug=" + (o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Comparator ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); final int NUM=scan.nextInt(); Listscores=new ArrayList<>(); int delicious=scan.nextInt(); for(int i=0 ; i(){ @ Override public int compare(Integer a,Integer b){ return Math.abs(a)-Math.abs(b); } } ); scores.remove(0); for(Integer integer : scores){ sum+=integer ; } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var NUM : int ; NUM := scan.getCurrent()->toInteger() ; var scores : Sequence(int) ; scores := Sequence{} ; var delicious : int ; delicious := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < NUM do ( ( scores := scores->including(delicious + i) ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; scores, OclComparator.newOclComparator() := scores, OclComparator.newOclComparator()->sort() ; scores := scores->excludingAt(0+1) ; for (integer : scores) do ( ( sum := sum+(integer) ) ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ int r,b,w,g ; Scanner sc=new Scanner(System.in); r=sc.nextInt(); b=sc.nextInt(); w=sc.nextInt(); g=sc.nextInt(); System.out.println(r+b+w+g); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : int ; var b : int ; var w : int ; var g : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; r := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; w := sc.getCurrent()->toInteger() ; g := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(r + b + w + g) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.InputMismatchException ; class Main { public static void main(String args[]){ int N=0,L=0 ; Scanner scanner=new Scanner(System.in); N=scanner.nextInt(); L=scanner.nextInt(); scanner.close(); int min=1000 ; int flag=0 ; for(int i=0 ; itoInteger() ; L := scanner.getCurrent()->toInteger() ; skip ; var min : int ; min := 1000 ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (if L + i < 0 then -(L + i) else L + i endif < min) then ( min := if L + i < 0 then -(L + i) else L + i endif ; if (L + i < 0) then ( flag := 0 ) else ( flag := 1 ) ) else skip ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( sum := sum + (L + i) ) ; i := i + 1 ) ; if (flag = 0) then ( sum := sum + min ) else ( sum := sum - min ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Main main=new Main(); main.solve(); } public void solve(){ Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int N=scan.nextInt(); int L=scan.nextInt(); int[] apple=new int[N]; int sum=0 ; for(int i=0 ; itoInteger() ; var L : int ; L := scan.getCurrent()->toInteger() ; var apple : Sequence(int) ; apple := Integer.subrange(1,N)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( apple[i+1] := L + i + 1 - 1 ; sum := sum+(apple[i+1]) ) ; i := i + 1 ) ; apple := apple->sort() ; var diff : int ; diff := 2147483647 ; var answer : int ; answer := 2147483647 ; var i : int ; i := 0 ; while i < N do ( ( var taste : int ; taste := sum - apple[i+1] ; if (if sum - taste < 0 then -(sum - taste) else sum - taste endif < diff) then ( answer := taste ; diff := if sum - taste < 0 then -(sum - taste) else sum - taste endif ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int minSum(int arr[],int n){ int sum=arr[0]; for(int i=1 ; isize() ; OclFile["System.out"].println(minSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test144 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; j=n){ System.out.println("YES"); } else { System.out.println("NO"); } } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test144 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < t do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; var sum : int ; sum := 1 ; while (a mod 2 = 0) do ( sum := sum+(sum) ; a := a/(2) ; if (sum = n) then ( break ) else skip ) ; while (b mod 2 = 0) do ( sum := sum+(sum) ; b := b/(2) ; if (sum = n) then ( break ) else skip ) ; if (sum >= n) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void findTriplets(int arr[],int n,int sum){ for(int i=0 ; isize() ; execute findTriplets(arr, n, -2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public final class Codechef { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int numTestcases=scanner.nextInt(); for(int test=1 ; test<=numTestcases ; test++){ int roomWidth=scanner.nextInt(); int roomHeight=scanner.nextInt(); int x1=scanner.nextInt(); int y1=scanner.nextInt(); int x2=scanner.nextInt(); int y2=scanner.nextInt(); int rectWidth=scanner.nextInt(); int rectHeight=scanner.nextInt(); System.out.println(findMin(roomWidth,roomHeight,x1,y1,x2,y2,rectWidth,rectHeight)); } } private static double findMin(int roomWidth,int roomHeight,int x1,int y1,int x2,int y2,int rectWidth,int rectHeight){ int remainingHeightAtTheTop=roomHeight-y2 ; int topMoveDistance=Integer.MAX_VALUE ; int bottomMoveDistance=Integer.MAX_VALUE ; int leftMoveDistance=Integer.MAX_VALUE ; int rightMoveDistance=Integer.MAX_VALUE ; if(rectHeight<=remainingHeightAtTheTop){ return(double)0 ; } else { if(rectHeight+(y2-y1)<=roomHeight)topMoveDistance=rectHeight-remainingHeightAtTheTop ; } int remainingHeightAtTheBottom=y1 ; if(rectHeight<=remainingHeightAtTheBottom){ return(double)0 ; } else { if(rectHeight+(y2-y1)<=roomHeight)bottomMoveDistance=rectHeight-remainingHeightAtTheBottom ; } int remainingWidthInTheLeft=x1 ; if(rectWidth<=remainingWidthInTheLeft){ return(double)0 ; } else { if(rectWidth+(x2-x1)<=roomWidth)leftMoveDistance=rectWidth-remainingWidthInTheLeft ; } int remainingWidthInTheRight=roomWidth-x2 ; if(rectWidth<=remainingWidthInTheRight){ return(double)0 ; } else { if(rectWidth+(x2-x1)<=roomWidth)rightMoveDistance=rectWidth-remainingWidthInTheRight ; } int minValue=Math.min(topMoveDistance,Math.min(bottomMoveDistance,Math.min(leftMoveDistance,rightMoveDistance))); return minValue==Integer.MAX_VALUE ?-1 :(double)minValue ; } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numTestcases : int ; numTestcases := scanner.getCurrent()->toInteger() ; var test : int ; test := 1 ; while test <= numTestcases do ( ( var roomWidth : int ; roomWidth := scanner.getCurrent()->toInteger() ; var roomHeight : int ; roomHeight := scanner.getCurrent()->toInteger() ; var x1 : int ; x1 := scanner.getCurrent()->toInteger() ; var y1 : int ; y1 := scanner.getCurrent()->toInteger() ; var x2 : int ; x2 := scanner.getCurrent()->toInteger() ; var y2 : int ; y2 := scanner.getCurrent()->toInteger() ; var rectWidth : int ; rectWidth := scanner.getCurrent()->toInteger() ; var rectHeight : int ; rectHeight := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(findMin(roomWidth, roomHeight, x1, y1, x2, y2, rectWidth, rectHeight)) ; ) ; test := test + 1 ) ); static operation findMin( roomWidth : int, roomHeight : int, x1 : int, y1 : int, x2 : int, y2 : int, rectWidth : int, rectHeight : int) : double pre: true post: true activity: ( var remainingHeightAtTheTop : int ; remainingHeightAtTheTop := roomHeight - y2 ; var topMoveDistance : int ; topMoveDistance := 2147483647 ; var bottomMoveDistance : int ; bottomMoveDistance := 2147483647 ; var leftMoveDistance : int ; leftMoveDistance := 2147483647 ; var rightMoveDistance : int ; rightMoveDistance := 2147483647 ; if (rectHeight <= remainingHeightAtTheTop) then ( return 0->oclAsType(double) ) else ( if (rectHeight + (y2 - y1) <= roomHeight) then topMoveDistance := rectHeight - remainingHeightAtTheTop ; else skip ) ; var remainingHeightAtTheBottom : int ; remainingHeightAtTheBottom := y1 ; if (rectHeight <= remainingHeightAtTheBottom) then ( return 0->oclAsType(double) ) else ( if (rectHeight + (y2 - y1) <= roomHeight) then bottomMoveDistance := rectHeight - remainingHeightAtTheBottom ; else skip ) ; var remainingWidthInTheLeft : int ; remainingWidthInTheLeft := x1 ; if (rectWidth <= remainingWidthInTheLeft) then ( return 0->oclAsType(double) ) else ( if (rectWidth + (x2 - x1) <= roomWidth) then leftMoveDistance := rectWidth - remainingWidthInTheLeft ; else skip ) ; var remainingWidthInTheRight : int ; remainingWidthInTheRight := roomWidth - x2 ; if (rectWidth <= remainingWidthInTheRight) then ( return 0->oclAsType(double) ) else ( if (rectWidth + (x2 - x1) <= roomWidth) then rightMoveDistance := rectWidth - remainingWidthInTheRight ; else skip ) ; var minValue : int ; minValue := Set{topMoveDistance, Set{bottomMoveDistance, Set{leftMoveDistance, rightMoveDistance}->min()}->min()}->min() ; return if minValue = 2147483647 then -1 else minValue->oclAsType(double) endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Double.min ; import static java.lang.Double.max ; public class ProblemSolving { static Scanner scanner=new Scanner(System.in); public static void main(String[] args){ int t=scanner.nextInt(); while(t-->0){ solve(); } } public static void solve(){ int W=scanner.nextInt(),H=scanner.nextInt(); int x1=scanner.nextInt(),y1=scanner.nextInt(),x2=scanner.nextInt(),y2=scanner.nextInt(); int w=scanner.nextInt(),h=scanner.nextInt(); if(h+y2-y1>H && w+x2-x1>W){ System.out.println(-1); return ; } double ans=1e9 ; if(h+y2-y1<=H){ ans=min(ans,h-(H-y2)); ans=min(ans,h-y1); } if(w+x2-x1<=W){ ans=min(ans,w-(W-x2)); ans=min(ans,w-x1); } ans=max(ans,0.0); System.out.printf("%.9f",ans); System.out.println(); } } ------------------------------------------------------------ OCL File: --------- class ProblemSolving { static attribute scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( execute solve() ) ; ) ); static operation solve() : void pre: true post: true activity: ( var W : int ; W := scanner.getCurrent()->toInteger() ; var H : int ; H := scanner.getCurrent()->toInteger() ; var x1 : int ; x1 := scanner.getCurrent()->toInteger() ; var y1 : int ; y1 := scanner.getCurrent()->toInteger() ; var x2 : int ; x2 := scanner.getCurrent()->toInteger() ; var y2 : int ; y2 := scanner.getCurrent()->toInteger() ; var w : int ; w := scanner.getCurrent()->toInteger() ; var h : int ; h := scanner.getCurrent()->toInteger() ; if (h + y2 - y1 > H & w + x2 - x1 > W) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var ans : double ; ans := 1e9 ; if (h + y2 - y1 <= H) then ( ans := Set{ans, h - (H - y2)}->min() ; ans := Set{ans, h - y1}->min() ) else skip ; if (w + x2 - x1 <= W) then ( ans := Set{ans, w - (W - x2)}->min() ; ans := Set{ans, w - x1}->min() ) else skip ; ans := Set{ans, 0.0}->max() ; OclFile["System.out"].printf("%.9f", ans) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { MyScanner sc=new MyScanner(); void run(){ int H=sc.nextInt(); int W=sc.nextInt(); int[][] dp=new int[H][W]; int max=0 ; for(int i=0 ; icollect(Integer.subrange(1,W)->collect(0)) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( var c : int ; c := sc.nextInt() ; dp[i+1][j+1] := if (c = 0) then 1 else 0 endif ; max := Set{max, dp[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( if (i = 0 or j = 0 or dp[i+1][j+1] = 0) then continue else skip ; dp[i+1][j+1] := Set{dp[i - 1+1][j+1], Set{dp[i+1][j - 1+1], dp[i - 1+1][j - 1+1]}->min()}->min() + 1 ; max := Set{max, dp[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max * max) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); class MyScanner { operation nextInt() : int pre: true post: true activity: ( try ( var c : int ; c := OclFile["System.in"].read() ; while (c /= '-' & (c < '0' or '9' < c)) do c := OclFile["System.in"].read() ; ; if (c = '-') then return -nextInt() else skip ; var res : int ; res := 0 ; while true do (( res := res*(10) ; res := res+(c - ('0')->char2byte()) ; c := OclFile["System.in"].read() ) ; if ('0' <= c & c <= '9') then skip else break) ; return res ) catch (e : ProgramException) do ( return -1 ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int h=scan.nextInt(); int w=scan.nextInt(); scan.nextLine(); int[][] arr=new int[h][w]; for(int i=0 ; itoInteger() ; var w : int ; w := scan.getCurrent()->toInteger() ; skip ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( var line : Sequence(String) ; line := scan.nextLine()->split(" ") ; var j : int ; j := 0 ; while j < w do ( ( arr[i+1][j+1] := (line[j+1])->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ansArr : Sequence(Sequence(int)) ; ansArr := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < h do ( ansArr[i+1][0+1] := if (arr[i+1][0+1] = 0) then 1 else 0 endif ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < w do ( ansArr[0+1][i+1] := if (arr[0+1][i+1] = 0) then 1 else 0 endif ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < h do ( ( var j : int ; j := 1 ; while j < w do ( ( ansArr[i+1][j+1] := if (arr[i+1][j+1] = 0) then Set{Set{ansArr[i - 1+1][j+1], ansArr[i+1][j - 1+1]}->min(), ansArr[i - 1+1][j - 1+1]}->min() + 1 else 0 endif ) ; j := j + 1 ) ) ; i := i + 1 ) ; for (_arr : ansArr) do ( for (num : _arr) do ( ans := Set{ans, num}->max() ; ) ; ) ; OclFile["System.out"].println(ans * ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; line=br.readLine(); int H,W ; H=parseInt(line.substring(0,line.indexOf(' '))); W=parseInt(line.substring(line.indexOf(' ')+1)); int[][] dp=new int[H+1][W+1]; for(int i=1 ; i<=H ; i++){ StringTokenizer st=new StringTokenizer(br.readLine()); for(int j=1 ; j<=W ; j++){ dp[i][j]=parseInt(st.nextToken())==1 ? 0 : 1 ; } } int max=0 ; for(int i=1 ; i<=H ; i++){ for(int j=1 ; j<=W ; j++){ if(dp[i][j]==1){ dp[i][j]=Math.min(dp[i-1][j-1],Math.min(dp[i-1][j],dp[i][j-1]))+1 ; max=Math.max(max,dp[i][j]); } } } System.out.println(max*max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := br.readLine() ; var H : int ; var W : int ; H := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; W := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,H + 1)->collect(Integer.subrange(1,W + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= H do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var j : int ; j := 1 ; while j <= W do ( ( dp[i+1][j+1] := if (st.next() + "")->toInteger() = 1 then 0 else 1 endif ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 1 ; while i <= H do ( ( var j : int ; j := 1 ; while j <= W do ( ( if (dp[i+1][j+1] = 1) then ( dp[i+1][j+1] := Set{dp[i - 1+1][j - 1+1], Set{dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->min()}->min() + 1 ; max := Set{max, dp[i+1][j+1]}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max * max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { boolean main()throws IOException { Scanner sc=new Scanner(systemin); result.printf("%d\n",sc.nextInt()+sc.nextInt()+sc.nextInt()+sc.nextInt()); sc.close(); return false ; } PrintStream log ; PrintStream result=System.out ; BufferedReader systemin ; static Main instance=new Main(); Main(){ systemin=new BufferedReader(new InputStreamReader(System.in)); log=new PrintStream(new OutputStream(){ public void write(int b){ } } ); } public static void main(String[] args)throws IOException { instance.main(); instance.systemin.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation main() : boolean pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(systemin) ; result.printf("%d\n", sc.getCurrent()->toInteger() + sc.getCurrent()->toInteger() + sc.getCurrent()->toInteger() + sc.getCurrent()->toInteger()) ; skip ; return false ); attribute log : OclFile; attribute result : OclFile := OclFile["System.out"]; attribute systemin : OclFile; static attribute instance : Main := Main.newMain(); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( systemin := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; log := OclFile.newOclFile_Write(OclFile()) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( instance.main() ; instance.systemin.close() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int H=in.nextInt(),W=in.nextInt(); int field[][]=new int[H][W]; for(int i=0 ; i=1 && isBS(field,i,j)){ field[i][j]=Math.min(field[i-1][j],Math.min(field[i][j-1],field[i-1][j-1]))+1 ; } max=Math.max(max,field[i][j]); } } System.out.println(max*max); } static boolean isBS(int A[][],int y,int x){ if(y-1<0 || x-1<0)return false ; if(A[y-1][x]>=1 && A[y][x-1]>=1 && A[y-1][x-1]>=1){ return true ; } else return false ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var H : int ; H := in.getCurrent()->toInteger() ; var W : int ; W := in.getCurrent()->toInteger() ; var field : Sequence(Sequence(int)) ; field := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( field[i+1][j+1] := if (in.getCurrent())->toInteger() = 1 then 0 else 1 endif ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( if (field[i+1][j+1] >= 1 & isBS(field, i, j)) then ( field[i+1][j+1] := Set{field[i - 1+1][j+1], Set{field[i+1][j - 1+1], field[i - 1+1][j - 1+1]}->min()}->min() + 1 ) else skip ; max := Set{max, field[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max * max) ; ); static operation isBS( A : Sequence(Sequence(int)), y : int, x : int) : boolean pre: true post: true activity: ( if (y - 1 < 0 or x - 1 < 0) then return false else skip ; if (A[y - 1+1][x+1] >= 1 & A[y+1][x - 1+1] >= 1 & A[y - 1+1][x - 1+1] >= 1) then ( return true ) else return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int[][] dp=new int[h][w]; int[][] map=new int[h][w]; int max=0 ; for(int i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var map : Sequence(Sequence(int)) ; map := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( map[i+1][j+1] := sc.getCurrent()->toInteger() ; if (map[i+1][j+1] = 1) then ( dp[i+1][j+1] := 0 ) else ( dp[i+1][j+1] := 1 ; max := MathLib.bitwiseOr(max, dp[i+1][j+1]) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < h do ( ( var j : int ; j := 1 ; while j < w do ( ( if (map[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], Set{dp[i - 1+1][j - 1+1], dp[i+1][j - 1+1]}->min()}->min() + 1 ; max := Set{max, dp[i+1][j+1]}->max() ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; out.println(max * max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int[] pref=new int[100010]; static int isPerfectSquare(int x){ double sr=Math.sqrt(x); return((sr-Math.floor(sr))==0)? x : 0 ; } static void compute(){ for(int i=1 ; i<=100000 ; ++i){ pref[i]=pref[i-1]+isPerfectSquare(i); } } static void printSum(int L,int R){ int sum=pref[R]-pref[L-1]; System.out.print(sum+" "); } public static void main(String[] args){ compute(); int Q=4 ; int arr[][]={ { 1,10 },{ 1,100 },{ 2,25 },{ 4,50 } }; for(int i=0 ; icollect(0); static operation isPerfectSquare( x : int) : int pre: true post: true activity: ( var sr : double ; sr := (x)->sqrt() ; return if ((sr - (sr)->floor()) = 0) then x else 0 endif ); static operation compute() : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= 100000 do ( ( pref[i+1] := pref[i - 1+1] + isPerfectSquare(i) ) ; i := i + 1 ) ); static operation printSum( L : int, R : int) : void pre: true post: true activity: ( var sum : int ; sum := pref[R+1] - pref[L - 1+1] ; OclFile["System.out"].print(sum + " ") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute compute() ; var Q : int ; Q := 4 ; var arr : Sequence(Sequence(int)) ; arr := Sequence{Sequence{1,10},Sequence{1,100},Sequence{2,25},Sequence{4,50}} ; var i : int ; i := 0 ; while i < Q do ( ( execute printSum(arr[i+1][0+1], arr[i+1][1+1]) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1472A_CardsforFriends { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ int w=input.nextInt(); int h=input.nextInt(); int n=input.nextInt(); int width=1 ; int height=1 ; for(int i=0 ; w % 2==0 ; i++){ w/=2 ; width+=Math.pow(2,i); } for(int i=0 ; h % 2==0 ; i++){ h/=2 ; height+=(int)Math.pow(2,i); } if(width*height>=n){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class _1472A_CardsforFriends { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; while (test > 0) do ( test := test - 1 ; skip ; ( var w : int ; w := input.getCurrent()->toInteger() ; var h : int ; h := input.getCurrent()->toInteger() ; var n : int ; n := input.getCurrent()->toInteger() ; var width : int ; width := 1 ; var height : int ; height := 1 ; var i : int ; i := 0 ; while w mod 2 = 0 do ( ( w := w/(2) ; width := width+(2->pow(i)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while h mod 2 = 0 do ( ( h := h/(2) ; height := height+(2->pow(i)->oclAsType(int)) ) ; i := i + 1 ) ; if (width * height >= n) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); public void run(){ while(sc.hasNext()){ int n=sc.nextInt(); int m=sc.nextInt(); int a=sc.nextInt(); if(n==0 && m==0 && a==0)break ; calc(n,m,a); } } public void calc(int n,int m,int a){ int[][] amida=new int[1001][n+1]; int height=0 ; for(int i=0 ; i0 ; i--){ if(amida[i][a]!=0)a=amida[i][a]; } System.out.println(a); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while (sc.hasNext()) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; if (n = 0 & m = 0 & a = 0) then break else skip ; execute calc(n, m, a) ; ) ); operation calc( n : int, m : int, a : int) : void pre: true post: true activity: ( var amida : Sequence(Sequence(int)) ; amida := Integer.subrange(1,1001)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var height : int ; height := 0 ; var i : int ; i := 0 ; while i < m do ( ( var h : int ; h := sc.getCurrent()->toInteger() ; var p : int ; p := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; amida[h+1][p+1] := q ; amida[h+1][q+1] := p ; if (height < h) then height := h ; else skip ; ) ; i := i + 1 ) ; var i : int ; i := height ; while i > 0 do ( ( if (amida[i+1][a+1] /= 0) then a := amida[i+1][a+1] ; else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(a) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static class pair { int x ; char symbol ; pair(int x,char symbol){ this.x=x ; this.symbol=symbol ; } } @ SuppressWarnings("unchecked")public static void main(String args[]){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(),m=sc.nextInt(),a=sc.nextInt(); ArrayList>al=new ArrayList>(); pair ini=new pair(-1,'+'); ArrayListli_ini=new ArrayList(); li_ini.add(ini); for(int i=0 ; ili_pa=(ArrayList)al.get(p-1).clone(); li_pa.add(pa); pair pa2=new pair(h,'-'); ArrayListli_pa2=(ArrayList)al.get(q-1).clone(); li_pa2.add(pa2); al.set(p-1,li_pa); al.set(q-1,li_pa2); } int height=1001 ; int wh=a ; while(true){ ArrayListcheck=al.get(wh-1); pair target=null ; int max=0 ; for(pair check_pair : check){ int temp=check_pair.x ; if(tempmax){ max=temp ; target=check_pair ; } } height=max ; if(target==null)break ; if(target.symbol=='+'){ wh++; } else { wh--; } } System.out.println(wh); } } } ------------------------------------------------------------ OCL File: --------- class Main { static class pair { attribute x : int; attribute symbol : String; static operation newpair( x : int, symbol : String) : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(x, symbol); return self ); operation initialise( x : int, symbol : String) : void pre: true post: true activity: ( self.x := x ; self.symbol := symbol ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var al : Sequence(Sequence(pair)) ; al := Sequence{} ; var ini : pair ; ini := pair.newpair(-1, '+') ; var li_ini : Sequence(pair) ; li_ini := Sequence{} ; li_ini := li_ini->including(ini) ; var i : int ; i := 0 ; while i < n do ( al := al->including(li_ini) ; ; i := i + 1 ) ; if ((MathLib.bitwiseOr(MathLib.bitwiseOr(n,m),a)) = 0) then break else skip ; var i : int ; i := 0 ; while i < m do ( ( var h : int ; h := sc.getCurrent()->toInteger() ; var p : int ; p := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var pa : pair ; pa := pair.newpair(h, '+') ; var li_pa : Sequence(pair) ; li_pa := al->at(p - 1+1)->copy()->oclAsType(Sequence(pair)) ; li_pa := li_pa->including(pa) ; var pa2 : pair ; pa2 := pair.newpair(h, '-') ; var li_pa2 : Sequence(pair) ; li_pa2 := al->at(q - 1+1)->copy()->oclAsType(Sequence(pair)) ; li_pa2 := li_pa2->including(pa2) ; al := al.setAt(p - 1+1,li_pa) ; al := al.setAt(q - 1+1,li_pa2) ; ) ; i := i + 1 ) ; var height : int ; height := 1001 ; var wh : int ; wh := a ; while (true) do ( var check : Sequence(pair) ; check := al->at(wh - 1+1) ; var target : pair ; target := null ; var max : int ; max := 0 ; for (check_pair : check) do ( ( var temp : int ; temp := check_pair.x ; if (temp < height & temp > max) then ( max := temp ; target := check_pair ) else skip ) ) ; height := max ; if (target = null) then break else skip ; if (target.symbol = '+') then ( wh := wh + 1 ) else ( wh := wh - 1 ) ; ) ; OclFile["System.out"].println(wh) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.security.acl.Group ; import java.util.*; public class Main { static class Bar implements Comparable{ int h ; int p ; int q ; public Bar(int h,int p,int q){ this.h=h ; this.p=p ; this.q=q ; } @ Override public int compareTo(Bar o){ return o.h-h ; } } public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); for(int loop=0 ; ; loop++){ Listlist=new ArrayList(); String s=reader.readLine(); String[] sp=s.split(" "); int N=Integer.parseInt(sp[0]); int M=Integer.parseInt(sp[1]); int A=Integer.parseInt(sp[2]); if(N==0)break ; for(int i=0 ; i { attribute h : int; attribute p : int; attribute q : int; static operation newBar( h : int, p : int, q : int) : Bar pre: true post: true activity: ( var self : Bar ; self := createBar(); self.initialise(h, p,q); return self ); operation initialise( h : int, p : int, q : int) : void pre: true post: true activity: ( self.h := h ; self.p := p ; self.q := q ); operation compareTo( o : Bar) : int pre: true post: true activity: ( return o.h - h ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var loop : int ; loop := 0 ; while true do ( ( var list : Sequence(Bar) ; list := Sequence{} ; var s : String ; s := reader.readLine() ; var sp : Sequence(String) ; sp := s->split(" ") ; var N : int ; N := (sp[0+1])->toInteger() ; var M : int ; M := (sp[1+1])->toInteger() ; var A : int ; A := (sp[2+1])->toInteger() ; if (N = 0) then break else skip ; var i : int ; i := 0 ; while i < M do ( ( s := reader.readLine() ; sp := s->split(" ") ; var h : int ; h := (sp[0+1])->toInteger() ; var p : int ; p := (sp[1+1])->toInteger() ; var q : int ; q := (sp[2+1])->toInteger() ; var bar : Bar ; bar := Bar.newBar(h, p, q) ; list := list->including(bar) ; ) ; i := i + 1 ) ; list := list->sort() ; var pos : int ; pos := A ; var i : int ; i := 0 ; while i < list->size() do ( ( var bar : Bar ; bar := list->at(i+1) ; if (pos = bar.p) then ( pos := bar.q ) else if (pos = bar.q) then ( pos := bar.p ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].printf("%d\n", pos) ; ) ; loop := loop + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static boolean isPrime(int n){ if(n<=1)return false ; if(n<=3)return true ; if(n % 2==0 || n % 3==0)return false ; for(int i=5 ; i*i<=n ; i=i+6)if(n % i==0 || n %(i+2)==0)return false ; return true ; } static int SumOfPrimeDivisors(int n){ int sum=0 ; for(int i=1 ; i<=n ; i++){ if(n % i==0){ if(isPrime(i))sum+=i ; } } return sum ; } public static void main(String args[]){ int n=60 ; System.out.print("Sum of prime divisors of 60 is "+SumOfPrimeDivisors(n)+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPrime( n : int) : boolean 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 ; i := 5 ; while i * i <= n do ( if (n mod i = 0 or n mod (i + 2) = 0) then return false else skip ; ; i := i + 6 ) ; return true ); static operation SumOfPrimeDivisors( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (n mod i = 0) then ( if (isPrime(i)) then sum := sum+(i) ; else skip ) else skip ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 60 ; OclFile["System.out"].print("Sum of prime divisors of 60 is " + SumOfPrimeDivisors(n) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int INT_BITS=32 ; static int leftRotate(int n,int d){ return(n<>(INT_BITS-d)); } static int rightRotate(int n,int d){ return(n>>d)|(n<<(INT_BITS-d)); } public static void main(String arg[]){ int n=16 ; int d=2 ; System.out.print("Left Rotation of "+n+" by "+d+" is "); System.out.print(leftRotate(n,d)); System.out.print("\nRight Rotation of "+n+" by "+d+" is "); System.out.print(rightRotate(n,d)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute INT_BITS : int := 32; static operation leftRotate( n : int, d : int) : int pre: true post: true activity: ( return ((n*(2->pow(d)))->oclAsType(long)) or ((n/(2->pow((INT_BITS - d))))->oclAsType(long)) ); static operation rightRotate( n : int, d : int) : int pre: true post: true activity: ( return ((n/(2->pow(d)))->oclAsType(long)) or ((n*(2->pow((INT_BITS - d))))->oclAsType(long)) ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 16 ; var d : int ; d := 2 ; OclFile["System.out"].print("Left Rotation of " + n + " by " + d + " is ") ; OclFile["System.out"].print(leftRotate(n, d)) ; OclFile["System.out"].print("\nRight Rotation of " + n + " by " + d + " is ") ; OclFile["System.out"].print(rightRotate(n, d)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { FastScanner sc=new FastScanner(System.in); PrintWriter out=new PrintWriter(System.out); int ans=0 ; for(int i=0 ; i<4 ; i++){ int input=sc.nextInt(); ans+=input ; } out.println(ans); out.flush(); } static class FastScanner { private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public FastScanner(InputStream in){ reader=new BufferedReader(new InputStreamReader(in)); tokenizer=null ; } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { return reader.readLine(); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong(){ return Long.parseLong(next()); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastScanner ; sc := FastScanner.newFastScanner(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( var input : int ; input := sc.nextInt() ; ans := ans+(input) ) ; i := i + 1 ) ; skip ; skip ; ); static class FastScanner { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newFastScanner( in : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.next() ); operation nextLine() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( return reader.readLine() ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.nextToken("\n") ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class App { static ArrayListluck=new ArrayList<>(); public static void main(String[] args){ Scanner in=new Scanner(System.in); char[] arr=in.next().toCharArray(); long digitSlot=arr.length ; long ans=0 ; ans=(1<=0 ; i--,count++){ if(arr[(int)i]=='7'){ ans+=(1<characters() ; var digitSlot : long ; digitSlot := arr->size() ; var ans : long ; ans := 0 ; ans := ((1*(2->pow(digitSlot)))->oclAsType(long)) - 2 ; var i : long ; i := digitSlot - 1 ; var count : long ; count := 0 ; while i >= 0 do ( ( if (arr[i->oclAsType(int)+1] = '7') then ( ans := ans+(((1*(2->pow(count)))->oclAsType(long))) ) else skip ) ; i := i - 1 ; count := count + 1 ) ; OclFile["System.out"].println(ans + 1) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.text.DateFormat ; import java.text.ParseException ; import java.text.SimpleDateFormat ; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ String a=in.next(); int n=a.length(); int s=0 ; int qq=1 ; for(int i=1 ; isize() ; var s : int ; s := 0 ; var qq : int ; qq := 1 ; var i : int ; i := 1 ; while i < n do ( ( qq := qq*(2) ; s := s + qq ) ; i := i + 1 ) ; var q : String ; q := "" ; var i : int ; i := 0 ; while i < n do ( ( var c : String ; c := a->at(i+1) ; if (c = '4') then q := q + "0" ; else q := q + "1" ; ) ; i := i + 1 ) ; var w : int ; w := (q)->toInteger() ; OclFile["System.out"].println(s + w + 1) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findPoint(int x1,int y1,int x2,int y2){ System.out.println("("+(int)(2*x2-x1)+","+(int)(2*y2-y1)+")"); } public static void main(String args[]){ int x1=0,y1=0,x2=1,y2=1 ; findPoint(x1,y1,x2,y2); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findPoint( x1 : int, y1 : int, x2 : int, y2 : int) : void pre: true post: true activity: ( OclFile["System.out"].println("(" + (2 * x2 - x1)->oclAsType(int) + "," + (2 * y2 - y1)->oclAsType(int) + ")") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x1 : int ; x1 := 0 ; var y1 : int ; y1 := 0 ; var x2 : int ; x2 := 1 ; var y2 : int ; y2 := 1 ; execute findPoint(x1, y1, x2, y2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF535B { public static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int n=scanner.nextInt(); int res=0 ; int bitIndex=0 ; while(n!=0){ int digit=n % 10 ; if(digit==4)res+=1<toInteger() ; var res : int ; res := 0 ; var bitIndex : int ; bitIndex := 0 ; while (n /= 0) do ( var digit : int ; digit := n mod 10 ; if (digit = 4) then res := res+((1*(2->pow(bitIndex)))->oclAsType(long)) else res := res+(2 * ((1*(2->pow(bitIndex)))->oclAsType(long))) ; ; n := n/(10) ; bitIndex := bitIndex + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void triangle(int n){ int k=2*n-2 ; int ch=1 ; for(int i=0 ; isqrt()->oclAsType(int)) - 1) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 9 ; execute triangle(maxHeight(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Hello { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int test=in.nextInt(); for(int t=1 ; t<=test ; t++){ String s1=in.next(); String s2=in.next(); String str1=s1 ; String str2=s2 ; while(str1.length()!=str2.length()){ if(str1.length()toInteger() ; var t : int ; t := 1 ; while t <= test do ( ( var s1 : String ; s1 := in.getCurrent() ; var s2 : String ; s2 := in.getCurrent() ; var str1 : String ; str1 := s1 ; var str2 : String ; str2 := s2 ; while (str1->size() /= str2->size()) do ( if (str1->size() < str2->size()) then ( str1 := str1+(s1) ) else ( str2 := str2+(s2) ) ) ; if (str1 = str2) then ( skip ) else ( skip ) ; ) ; t := t + 1 ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class main { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ String s1=sc.next(); String s2=sc.next(); int l1=s1.length(); int l2=s2.length(); int l=lcm(l1,l2); String lstr="" ; if(l1>l2){ for(int i=1 ; i<=l/l2 ; i++){ lstr=lstr+s2 ; } int flag=0,j=0,k=0 ; while(ktoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; var l1 : int ; l1 := s1->size() ; var l2 : int ; l2 := s2->size() ; var l : int ; l := lcm(l1, l2) ; var lstr : String ; lstr := "" ; if (l1 > l2) then ( var i : int ; i := 1 ; while i <= l / l2 do ( ( lstr := lstr + s2 ) ; i := i + 1 ) ; var flag : int ; flag := 0 ; var j : int ; j := 0 ; var k : int ; k := 0 ; while (k < lstr->size()) do ( if (j = l1) then j := 0 ; else skip ; if (s1->at(j+1) /= lstr->at(k+1)) then ( flag := 1 ; break ) else ( j := j + 1 ; k := k + 1 ) ) ; if (flag = 0) then OclFile["System.out"].println(lstr) ; else OclFile["System.out"].println(-1) ; ) else ( var i : int ; i := 1 ; while i <= l / l1 do ( ( lstr := lstr + s1 ) ; i := i + 1 ) ; var flag : int ; flag := 0 ; var j : int ; j := 0 ; var k : int ; k := 0 ; while (k < lstr->size()) do ( if (j = l2) then j := 0 ; else skip ; if (s2->at(j+1) /= lstr->at(k+1)) then ( flag := 1 ; break ) else ( j := j + 1 ; k := k + 1 ; continue ) ) ; if (flag = 0) then OclFile["System.out"].println(lstr) ; else OclFile["System.out"].println(-1) ; ) ; ) ; ) ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation lcm( a : int, b : int) : int pre: true post: true activity: ( return (a / gcd(a, b)) * b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practice { static long pow(long a,long b){ if(b==0){ return 1 ; } long ans=0L ; if(b % 2==0){ long val=pow(a,b/2); ans+=val*val ; } else { long val=pow(a,b/2); ans+=val*val*2 ; } return ans ; } static long gcd(int a,int b){ if(b==0){ return a ; } return gcd(b,a % b); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while(t--!=0){ String a=sc.nextLine(); String b=sc.nextLine(); int m=a.length(),n=b.length(); if(mtoInteger() ; skip ; while (t /= 0) do ( skip ; ( var a : String ; a := sc.nextLine() ; var b : String ; b := sc.nextLine() ; var m : int ; m := a->size() ; var n : int ; n := b->size() ; if (m < n) then ( var tmp : String ; tmp := a ; a := b ; b := tmp ; var tt : int ; tt := m ; m := n ; n := tt ; ) else skip ; var ex : String ; ex := a ; var p : int ; p := m ; while (m mod n /= 0) do ( a := a+(ex) ; m := m+(p) ) ; var flag : boolean ; flag := true ; var i : int ; i := 0 ; while i < m do ( ( if (not(b = a.subrange(i+1,i + n))) then ( flag := false ; break ) else skip ) ; i := i + n ) ; if (not(flag)) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(a) ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args)throws IOException,InterruptedException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] p=new int[n]; int min=Integer.MAX_VALUE ; int max=0 ; for(int i=0 ; ik){ System.out.println("NO"); } else { System.out.println("YES"); for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,n)->collect(0) ; var min : int ; min := 2147483647 ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( p[i+1] := sc.getCurrent()->toInteger() ; min := Set{p[i+1], min}->min() ; max := Set{p[i+1], max}->max() ) ; i := i + 1 ) ; if (max - min > k) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < n do ( ( var c : int ; c := 0 ; var j : int ; j := 0 ; while j < p[i+1] do ( ( OclFile["System.out"].print((c mod k) + 1 + " ") ; c := c + 1 ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ) ; skip ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class LC { static class pair { int l,r ; public pair(int l,int r){ this.l=l ; this.r=r ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int max=0,min=Integer.MAX_VALUE ; ArrayLista=new ArrayList<>(); for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var max : int ; max := 0 ; var min : int ; min := 2147483647 ; var a : Sequence(int) ; a := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var temp : int ; temp := sc.getCurrent()->toInteger() ; max := Set{max, temp}->max() ; min := Set{min, temp}->min() ; a := a->including(temp) ) ; i := i + 1 ) ; if (max - min - k <= 0) then ( OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < n do ( ( var count : int ; count := 1 ; var j : int ; j := 0 ; while j < a->at(i+1) do ( ( if (j <= min) then OclFile["System.out"].print(1 + " ") ; else ( count := count + 1 ; OclFile["System.out"].print(count + " ") ) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws Exception { int result=0 ; try(BufferedReader reader=new BufferedReader(new InputStreamReader(System.in))){ String[] numDog=reader.readLine().split(" "); for(int i=0 ; isplit(" ") ; var i : int ; i := 0 ; while i < numDog->size() do ( ( result := result+((numDog[i+1])->toInteger()) ) ; i := i + 1 ) ; OclFile["System.out"].println(result) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeMap ; import java.util.TreeSet ; import javax.management.RuntimeErrorException ; public class CodeforcesQuestions { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int k=s.nextInt(); int arr[]=new int[n]; int temp[]=new int[n]; for(int i=0 ; ik)m=1 ; } System.out.println(); } } } } ------------------------------------------------------------ OCL File: --------- class CodeforcesQuestions { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var k : int ; k := s.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var temp : Sequence(int) ; temp := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := s.getCurrent()->toInteger() ; arr[i+1] := x ; temp[i+1] := x ) ; i := i + 1 ) ; temp := temp->sort() ; var min : int ; min := temp[0+1] ; if (k < temp[n - 1+1] - temp[0+1]) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 1 ; while j <= k & j <= arr[i+1] do ( ( OclFile["System.out"].print(j + " ") ) ; j := j + 1 ) ; j := j - 1 ; if (j = arr[i+1]) then ( OclFile["System.out"].println() ; continue ) else skip ; var m : int ; m := 1 ; while (j /= arr[i+1]) do ( OclFile["System.out"].print(m + " ") ; m := m + 1 ; j := j + 1 ; if (m > k) then m := 1 ; else skip ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void maximumArea(int l,int b,int x,int y){ int left,right,above,below ; left=x*b ; right=(l-x-1)*b ; above=l*y ; below=(b-y-1)*l ; System.out.print(Math.max(Math.max(left,right),Math.max(above,below))); } public static void main(String[] args){ int L=8,B=8 ; int X=0,Y=0 ; maximumArea(L,B,X,Y); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maximumArea( l : int, b : int, x : int, y : int) : void pre: true post: true activity: ( var left : int ; var right : int ; var above : int ; var below : int ; left := x * b ; right := (l - x - 1) * b ; above := l * y ; below := (b - y - 1) * l ; OclFile["System.out"].print(Set{Set{left, right}->max(), Set{above, below}->max()}->max()) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 8 ; var B : int ; B := 8 ; var X : int ; X := 0 ; var Y : int ; Y := 0 ; execute maximumArea(L, B, X, Y) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static void sieve(boolean prime[],int n){ for(int p=2 ; p*p<=n ; p++){ if(prime[p]==false)for(int i=p*2 ; i<=n ; i+=p)prime[i]=true ; } } static int maxDigitInPrimes(int L,int R){ boolean prime[]=new boolean[R+1]; Arrays.fill(prime,false); sieve(prime,R); int freq[]=new int[10]; int val ; for(int i=L ; i<=R ; i++){ if(! prime[i]){ int p=i ; while(p>0){ freq[p % 10]++; p/=10 ; } } } int max=freq[0],ans=0 ; for(int j=1 ; j<10 ; j++){ if(max<=freq[j]){ max=freq[j]; ans=j ; } } return ans ; } public static void main(String[] args){ int L=1,R=20 ; System.out.println(maxDigitInPrimes(L,R)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sieve( prime : Sequence(boolean), n : int) : void pre: true post: true activity: ( var p : int ; p := 2 ; while p * p <= n do ( ( if (prime[p+1] = false) then var i : int ; i := p * 2 ; while i <= n do ( prime[i+1] := true ; ; i := i+(p) ) ; else skip ) ; p := p + 1 ) ); static operation maxDigitInPrimes( L : int, R : int) : int pre: true post: true activity: ( var prime : Sequence(boolean) ; prime := Integer.subrange(1,R + 1)->collect(false) ; prime := prime->collect(false) ; execute sieve(prime, R) ; var freq : Sequence(int) ; freq := Integer.subrange(1,10)->collect(0) ; var val : int ; var i : int ; i := L ; while i <= R do ( ( if (not(prime[i+1])) then ( var p : int ; p := i ; while (p > 0) do ( freq[p mod 10+1] := freq[p mod 10+1] + 1 ; p := p/(10) ) ) else skip ) ; i := i + 1 ) ; var max : int ; max := freq[0+1] ; var ans : int ; ans := 0 ; var j : int ; j := 1 ; while j < 10 do ( ( if (max <= freq[j+1]) then ( max := freq[j+1] ; ans := j ) else skip ) ; j := j + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 1 ; var R : int ; R := 20 ; OclFile["System.out"].println(maxDigitInPrimes(L, R)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int tc=input.nextInt(); work : while(tc-->0){ int n=input.nextInt(); if(n==1){ System.out.println("1"); } else { for(int i=2 ; i<=n ; i++){ System.out.print(i+" "); } System.out.println("1"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tc : int ; tc := input.getCurrent()->toInteger() ; while (tc > 0) do ( tc := tc - 1 ; skip ; ( var n : int ; n := input.getCurrent()->toInteger() ; if (n = 1) then ( OclFile["System.out"].println("1") ) else ( var i : int ; i := 2 ; while i <= n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println("1") ) ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Solution { static MyScanner str=new MyScanner(); public static void main(String[] args)throws IOException { int T=i(); while(T-->0){ solve(); } } static void solve()throws IOException { int n=i(); System.out.print(n+" "); for(int i=1 ; i 0) do ( T := T - 1 ; skip ; ( execute solve() ) ; ) ); static operation solve() : void pre: true post: true activity: ( var n : int ; n := i() ; OclFile["System.out"].print(n + " ") ; var i : int ; i := 1 ; while i < n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ); static operation i() : int pre: true post: true activity: ( return str.nextInt() ); static operation l() : long pre: true post: true activity: ( return str.nextLong() ); static operation d() : double pre: true post: true activity: ( return str.nextDouble() ); static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import java.io.PrintWriter ; public class MyClass { public static void main(String[] args){ InputReader scanner=new InputReader(System.in); PrintWriter output=new PrintWriter(System.out); int T=scanner.nextInt(); while(T-->0){ int n=scanner.nextInt(); output.print(n+" "); for(int i=1 ; i 0) do ( T := T - 1 ; skip ; ( var n : int ; n := scanner.nextInt() ; skip ; var i : int ; i := 1 ; while i < n do ( ( skip ) ; i := i + 1 ) ; skip ) ; ) ; skip ; ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := reader.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.File ; import java.io.FileReader ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Solution { static PrintWriter pw ; static FastScanner s ; public static void main(String[] args)throws Exception { pw=new PrintWriter(System.out); s=new FastScanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); if(n % 2==0){ int i=1 ; while(i<=n){ pw.print((i+1)+" "+(i)+" "); i+=2 ; } } else { pw.print(1+" "); int i=2 ; while(i<=n){ pw.print((i+1)+" "+(i)+" "); i+=2 ; } } pw.println(); } pw.flush(); } } class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public FastScanner(String s)throws Exception { br=new BufferedReader(new FileReader(new File(s))); } public String next()throws Exception { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws Exception { return Integer.parseInt(next()); } public long nextLong()throws Exception { return Long.parseLong(next()); } } ------------------------------------------------------------ OCL File: --------- class Solution { static attribute pw : OclFile; static attribute s : FastScanner; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; s := FastScanner.newFastScanner(OclFile["System.in"]) ; var t : int ; t := s.nextInt() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.nextInt() ; if (n mod 2 = 0) then ( var i : int ; i := 1 ; while (i <= n) do ( skip ; i := i+(2) ) ) else ( skip ; var i : int ; i := 2 ; while (i <= n) do ( skip ; i := i+(2) ) ) ; skip ) ; ) ; skip ; ); } class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner( s : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newFastScanner( s : String) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile(s))) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isequal(String str){ int n=str.length(); int num=0,x=1,i=n-1 ; for(i=n-1 ; i>=0 ; i--){ if('0'<=str.charAt(i)&& str.charAt(i)<='9'){ num=(str.charAt(i)-'0')*x+num ; x=x*10 ; if(num>=n)return false ; } else break ; } return num==i+1 ; } static public void main(String[] args){ String str="geeksforgeeks13" ; if(isequal(str))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isequal( str : String) : boolean pre: true post: true activity: ( var n : int ; n := str->size() ; var num : int ; num := 0 ; var x : int ; x := 1 ; var i : int ; i := n - 1 ; i := n - 1 ; while i >= 0 do ( ( if ('0' <= str->at(i+1) & str->at(i+1) <= '9') then ( num := (str->at(i+1) - ('0')->char2byte()) * x + num ; x := x * 10 ; if (num >= n) then return false else skip ) else break ) ; i := i - 1 ) ; return num = i + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks13" ; if (isequal(str)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static String decToBin(int n){ if(n==0)return "0" ; String bin="" ; while(n>0){ bin=((n & 1)==0 ? '0' : '1')+bin ; n>>=1 ; } return bin ; } public static void main(String[] args){ int n=38 ; System.out.println(decToBin(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation decToBin( n : int) : String pre: true post: true activity: ( if (n = 0) then return "0" else skip ; var bin : String ; bin := "" ; while (n > 0) do ( bin := (if (n & 1) = 0 then '0' else '1' endif) + bin ; n := n/(2->pow(1)) ) ; return bin ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 38 ; OclFile["System.out"].println(decToBin(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void tower(int n,char sourcePole,char destinationPole,char auxiliaryPole){ if(0==n)return ; tower(n-1,sourcePole,auxiliaryPole,destinationPole); System.out.printf("Move the disk %d from %c to %c\n",n,sourcePole,destinationPole); tower(n-1,auxiliaryPole,destinationPole,sourcePole); } public static void main(String[] args){ tower(3,'S','D','A'); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation tower( n : int, sourcePole : String, destinationPole : String, auxiliaryPole : String) : void pre: true post: true activity: ( if (0 = n) then return else skip ; execute tower(n - 1, sourcePole, auxiliaryPole, destinationPole) ; OclFile["System.out"].printf("Move the disk %d from %c to %c\n", n, sourcePole, destinationPole) ; execute tower(n - 1, auxiliaryPole, destinationPole, sourcePole) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute tower(3, 'S', 'D', 'A') ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maxPeople(int p){ int tmp=0,count=0 ; for(int i=1 ; i*i<=p ; i++){ tmp=tmp+(i*i); if(tmp<=p)count++; else break ; } return count ; } public static void main(String args[]){ int p=14 ; System.out.println(maxPeople(p)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxPeople( p : int) : int pre: true post: true activity: ( var tmp : int ; tmp := 0 ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i * i <= p do ( ( tmp := tmp + (i * i) ; if (tmp <= p) then count := count + 1 ; else break ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var p : int ; p := 14 ; OclFile["System.out"].println(maxPeople(p)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { public static String pref(String str,int ind){ StringBuffer bf=new StringBuffer(); int cnt=0 ; for(int i=ind-1 ; i>=0 && str.charAt(i)!='-' ; i--){ if(cnt % 3==0 && cnt!=0){ bf.append(','); } bf.append(str.charAt(i)); cnt++; } return bf.reverse().toString(); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); StringBuffer bf=new StringBuffer(); int ind=-1 ; for(int i=0 ; i= 0 & str->at(i+1) /= '-' do ( ( if (cnt mod 3 = 0 & cnt /= 0) then ( bf := bf + StringLib.newString(',') ) else skip ; bf := bf + StringLib.newString(str->at(i+1)) ; cnt := cnt + 1 ) ; i := i - 1 ) ; return bf->reverse()+"" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; var bf : String ; bf := StringLib.newString() ; var ind : int ; ind := -1 ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = '.') then ( ind := i ; break ) else skip ) ; i := i + 1 ) ; var prefix : String ; prefix := "" ; var suffix : String ; suffix := "" ; if (ind = -1) then ( prefix := pref(str, str->size()) ; suffix := ".00" ) else ( prefix := pref(str, ind) ; suffix := suffix+(".") ; var i : int ; i := ind + 1 ; while i <= ind + 2 do ( ( if (i < str->size()) then ( suffix := suffix+(str->at(i+1)) ) else ( suffix := suffix+('0') ) ) ; i := i + 1 ) ) ; if (str->at(0+1) = '-') then ( prefix := "($" + prefix ; suffix := suffix+(")") ) else ( prefix := "$" + prefix ) ; OclFile["System.out"].println(prefix + suffix) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] d=new int[n]; for(int i=0 ; itoInteger() ; var d : Sequence(int) ; d := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( d[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; d := d->sort() ; var ans : int ; ans := 1 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (d[i+1] /= d[i + 1+1]) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int R=0,B=0,W=0,G=0 ; R=sc.nextInt(); B=sc.nextInt(); W=sc.nextInt(); G=sc.nextInt(); System.out.println((R+B+W+G)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var R : int ; R := 0 ; var B : int ; B := 0 ; var W : int ; W := 0 ; var G : int ; G := 0 ; R := sc.getCurrent()->toInteger() ; B := sc.getCurrent()->toInteger() ; W := sc.getCurrent()->toInteger() ; G := sc.getCurrent()->toInteger() ; OclFile["System.out"].println((R + B + W + G)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int maxLenSub(int arr[],int n){ int mls[]=new int[n],max=0 ; for(int i=0 ; is=new Stack<>(); String a=x.readLine(); char[] c=a.toCharArray(); for(int i=c.length-1 ; i>=0 ; i--){ if(s.isEmpty())s.push(c[i]); else if(s.peek()==c[i]){ s.pop(); } else { s.push(c[i]); } } for(int i=s.size()-1 ; i>=0 ; i--){ out.print(s.pop()); } out.close(); } } ------------------------------------------------------------ OCL File: --------- class Solver { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : OclFile ; x := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var tk : OclIterator ; var s : Sequence(String) ; s := Sequence{} ; var a : String ; a := x.readLine() ; var c : Sequence(String) ; c := a->characters() ; var i : int ; i := c->size() - 1 ; while i >= 0 do ( ( if (s->isEmpty()) then s := s->append(c[i+1]) ; else if (s->min() = c[i+1]) then ( s := s->front() ) else ( s := s->append(c[i+1]) ) ; ) ; i := i - 1 ) ; var i : int ; i := s->size() - 1 ; while i >= 0 do ( ( skip ) ; i := i - 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; import java.util.Stack ; public class JavaApplication1 { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out)); StringBuilder ss=new StringBuilder(in.readLine()); Stacks2=new Stack<>(); for(int i=0 ; isize() do ( ( if (i = 0) then ( s2 := s2->append(ss->at(i+1)) ) else ( if (s2->size() /= 0 & s2->min() = ss->at(i+1)) then ( s2 := s2->front() ) else ( s2 := s2->append(ss->at(i+1)) ) ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s2->size() do ( ( skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Deque ; import java.util.LinkedList ; import java.io.*; public class Plugin { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); String str=br.readLine(); Dequequeue=new LinkedList<>(); for(char c : str.toCharArray()){ if(! queue.isEmpty()){ if(queue.peekLast()==c){ queue.pollLast(); } else { queue.addLast(c); } } else { queue.addLast(c); } } while(! queue.isEmpty()){ pw.print(queue.pollFirst()); } pw.close(); } } ------------------------------------------------------------ OCL File: --------- class Plugin { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ; var str : String ; str := br.readLine() ; var queue : Sequence(String) ; queue := Sequence{} ; for (c : str->characters()) do ( ( if (not(queue->isEmpty())) then ( if (queue.peekLast() = c) then ( queue := queue->front() ) else ( queue := queue->append(c) ) ) else ( queue := queue->append(c) ) ) ) ; while (not(queue->isEmpty())) do ( skip ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String[] args)throws Exception { String g=br.readLine(); StringBuilder sb=new StringBuilder(); Stacks=new Stack<>(); for(int i=0 ; i0 && s.peek()==c)s.pop(); else s.push(c); } char[] arr=new char[s.size()]; int i=s.size()-1 ; while(! s.isEmpty())arr[i--]=s.pop(); for(char c : arr)pw.print(c); pw.println(); pw.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute pw : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var g : String ; g := br.readLine() ; var sb : String ; sb := StringLib.newString() ; var s : Sequence(String) ; s := Sequence{} ; var i : int ; i := 0 ; while i < g->size() do ( ( var c : String ; c := g->at(i+1) ; if (s->size() > 0 & s->min() = c) then s := s->front() ; else s := s->append(c) ; ) ; i := i + 1 ) ; var arr : Sequence(String) ; arr := Integer.subrange(1,s->size())->collect(0) ; var i : int ; i := s->size() - 1 ; while (not(s->isEmpty())) do arr[i+1] := s->last() ; s := s->front() ; ; for (c : arr) do ( skip ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Stack ; import java.util.StringTokenizer ; public class Solve3 { public static void main(String[] args)throws IOException { PrintWriter pw=new PrintWriter(System.out); new Solve3().solve(pw); pw.flush(); pw.close(); } public void solve(PrintWriter pw)throws IOException { FastReader sc=new FastReader(); Stacks=new Stack(); char[] c=sc.next().toCharArray(); for(int i=0 ; icharacters() ; var i : int ; i := 0 ; while i < c->size() do ( ( if (not(s->isEmpty()) & c[i+1] = s->min()) then ( s := s->front() ) else ( s := s->append(c[i+1]) ) ) ; i := i + 1 ) ; var ans : String ; ans := StringLib.newString() ; while (not(s->isEmpty())) do ( ans := ans + StringLib.newString(s->last()) ) ; skip ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( if (st = null or not(st.hasNext())) then ( st := OclIterator.newOclIterator_String(br.readLine()) ) else skip ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; import static java.lang.Math.*; class Main { public static Scanner sc=new Scanner(in); public static Random rand=new Random(); public void run(){ int val=sc.nextInt(); char exp=sc.next().charAt(0); while(exp!='='){ int exp2=sc.nextInt(); switch(exp){ case '+' : val+=exp2 ; break ; case '-' : val-=exp2 ; break ; case '*' : val*=exp2 ; break ; case '/' : val/=exp2 ; break ; } exp=sc.next().charAt(0); } ln(val); } public static void main(String[] args){ new Main().run(); } public int[] nextIntArray(int n){ int[] res=new int[n]; for(int i=0 ; itoInteger() ; var exp : String ; exp := sc.getCurrent()->at(0+1) ; while (exp /= '=') do ( var exp2 : int ; exp2 := sc.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (exp) ; if _switchval = '+' then val := val+(exp2) ; break else skip ; if _switchval = '-' then val := val-(exp2) ; break else skip ; if _switchval = '*' then val := val*(exp2) ; break else skip ; if _switchval = '/' then val := val/(exp2) ; break else skip ; ) exp := sc.getCurrent()->at(0+1) ) ; execute ln(val) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; return res ); static operation pr( o : OclAny) : void pre: true post: true activity: ( out.print(o) ); static operation ln( o : OclAny) : void pre: true post: true activity: ( out.println(o) ); static operation ln() : void pre: true post: true activity: ( out.println() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static long result=Long.parseLong(sc.nextLine()); public static void main(String[] args){ calculator(); } private static void calculator(){ do { String op=sc.nextLine(); if(op.equals("=")){ break ; } int num=Integer.parseInt(sc.nextLine()); switch(op){ case "+" : result+=num ; break ; case "-" : result-=num ; break ; case "*" : result*=num ; break ; case "/" : result/=num ; break ; default : break ; } } while(true); System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute result : long := (sc.nextLine())->toLong(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute calculator() ); static operation calculator() : void pre: true post: true activity: ( while true do (( var op : String ; op := sc.nextLine() ; if (op = "=") then ( break ) else skip ; var num : int ; num := (sc.nextLine())->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (op) ; if _switchval = "+" then result := result+(num) ; break else skip ; if _switchval = "-" then result := result-(num) ; break else skip ; if _switchval = "*" then result := result*(num) ; break else skip ; if _switchval = "/" then result := result/(num) ; break else skip ; if true then break else skip ; ) ) ; if (true) then skip else break) ; OclFile["System.out"].println(result) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int k=s.nextInt(); int[][] peeledTile=new int[k][2]; int center=n/2+1 ; for(int i=0 ; in/2){ peeledTile[i][0]=n-peeledTile[i][0]+1 ; } if(peeledTile[i][1]>n/2){ peeledTile[i][1]=n-peeledTile[i][1]+1 ; } if(n % 2==1 && peeledTile[i][0]==center && peeledTile[i][1]==center){ print(center % 3); } else if(peeledTile[i][0] % 3==peeledTile[i][1] % 3 || peeledTile[i][0]toInteger() ; var k : int ; k := s.getCurrent()->toInteger() ; var peeledTile : Sequence(Sequence(int)) ; peeledTile := Integer.subrange(1,k)->collect(Integer.subrange(1,2)->collect(0)) ; var center : int ; center := n / 2 + 1 ; var i : int ; i := 0 ; while i < k do ( ( peeledTile[i+1][0+1] := s.getCurrent()->toInteger() ; peeledTile[i+1][1+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( ( if (peeledTile[i+1][0+1] > n / 2) then ( peeledTile[i+1][0+1] := n - peeledTile[i+1][0+1] + 1 ) else skip ; if (peeledTile[i+1][1+1] > n / 2) then ( peeledTile[i+1][1+1] := n - peeledTile[i+1][1+1] + 1 ) else skip ; if (n mod 2 = 1 & peeledTile[i+1][0+1] = center & peeledTile[i+1][1+1] = center) then ( execute print(center mod 3) ) else if (peeledTile[i+1][0+1] mod 3 = peeledTile[i+1][1+1] mod 3 or peeledTile[i+1][0+1] < peeledTile[i+1][1+1]) then ( execute print(peeledTile[i+1][0+1] mod 3) ) else ( execute print(peeledTile[i+1][1+1] mod 3) ) ; ) ; i := i + 1 ) ; skip ; ); static operation print( ans : int) : void pre: true post: true activity: ( if (ans = 0) then ans := 3 ; else skip ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayDeque ; import java.util.Deque ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; Dequeops=new ArrayDeque<>(); Dequenums=new ArrayDeque<>(); while((line=br.readLine())!=null && ! line.isEmpty()){ if(line.equals("=")){ System.out.println(nums.pop()); break ; } switch(line.charAt(0)){ case '+' : case '-' : case '*' : case '/' : ops.offer(line.charAt(0)); break ; default : if(ops.size()>0){ char op=ops.pop(); int num1=nums.pop(); int num2=parseInt(line); switch(op){ case '+' : num1+=num2 ; break ; case '-' : num1-=num2 ; break ; case '*' : num1*=num2 ; break ; case '/' : num1/=num2 ; break ; } nums.offer(num1); } else { nums.offer(parseInt(line)); } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var ops : Sequence(String) ; ops := ArrayDeque.newArrayDeque() ; var nums : Sequence(int) ; nums := ArrayDeque.newArrayDeque() ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( if (line = "=") then ( OclFile["System.out"].println(nums->last()) ; break ) else skip ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (line->at(0+1)) ; if _switchval = '+' or _switchval = '-' or _switchval = '*' or _switchval = '/' then ops := ops->including(line->at(0+1)) ; break else skip ; if true then if (ops->size() > 0) then ( var op : String ; op := ops->last() ; var num1 : int ; num1 := nums->last() ; var num2 : int ; num2 := parseInt(line) ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (op) ; if _switchval = '+' then num1 := num1+(num2) ; break else skip ; if _switchval = '-' then num1 := num1-(num2) ; break else skip ; if _switchval = '*' then num1 := num1*(num2) ; break else skip ; if _switchval = '/' then num1 := num1/(num2) ; break else skip ; ) nums := nums->including(num1) ; ) else ( nums := nums->including((line + "")->toInteger()) ) ; else skip ; ) ) ; line := br.readLine() ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class GfG { private static int atMostK(int arr[],int n,int k){ int count=0 ; int left=0 ; int right=0 ; HashMapmap=new HashMap<>(); while(rightk){ map.put(arr[left],map.get(arr[left])-1); if(map.get(arr[left])==0)map.remove(arr[left]); left++; } count+=right-left+1 ; right++; } return count ; } private static int exactlyK(int arr[],int n,int k){ return(atMostK(arr,n,k)-atMostK(arr,n,k-1)); } public static void main(String[] args){ int arr[]={ 2,1,2,1,6 }; int n=arr.length ; int k=2 ; System.out.print(exactlyK(arr,n,k)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation atMostK( arr : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var left : int ; left := 0 ; var right : int ; right := 0 ; var map : Map(int,int) ; map := Map{} ; while (right < n) do ( map := map->union(Map{arr[right+1] |-> (if map->keys()->contains(arr[right+1]) then map->at(arr[right+1]) else 0 endif) + 1}) ; while (map.size() > k) do ( map := map->union(Map{arr[left+1] |-> map->at(arr[left+1]) - 1}) ; if (map->at(arr[left+1]) = 0) then map := map->antirestrict(Set{arr[left+1]}) ; else skip ; left := left + 1 ) ; count := count+(right - left + 1) ; right := right + 1 ) ; return count ); static operation exactlyK( arr : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( return (atMostK(arr, n, k) - atMostK(arr, n, k - 1)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,1,2,1,6} ; var n : int ; n := arr->size() ; var k : int ; k := 2 ; OclFile["System.out"].print(exactlyK(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.LinkedList ; import java.util.Map ; import java.util.Queue ; import java.util.Scanner ; import java.util.Set ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); boolean left_init=false ; int cur=0 ; while(true){ String in=sc.next(); if("=".equals(in)){ System.out.println(cur); break ; } else if("+".equals(in)){ int next=sc.nextInt(); cur+=next ; } else if("-".equals(in)){ int next=sc.nextInt(); cur-=next ; } else if("*".equals(in)){ int next=sc.nextInt(); cur*=next ; } else if("/".equals(in)){ int next=sc.nextInt(); cur/=next ; } else { int input=Integer.parseInt(in); if(! left_init){ cur=input ; left_init=true ; } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var left_init : boolean ; left_init := false ; var cur : int ; cur := 0 ; while (true) do ( var in : String ; in := sc.getCurrent() ; if ("=" = in) then ( OclFile["System.out"].println(cur) ; break ) else if ("+" = in) then ( var next : int ; next := sc.getCurrent()->toInteger() ; cur := cur+(next) ) else if ("-" = in) then ( var next : int ; next := sc.getCurrent()->toInteger() ; cur := cur-(next) ) else if ("*" = in) then ( var next : int ; next := sc.getCurrent()->toInteger() ; cur := cur*(next) ) else if ("/" = in) then ( var next : int ; next := sc.getCurrent()->toInteger() ; cur := cur/(next) ) else ( var input : int ; input := (in)->toInteger() ; if (not(left_init)) then ( cur := input ; left_init := true ) else skip ) ; ; ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { void run(){ Scanner sc=new Scanner(System.in); String exp="("+sc.next()+sc.next()+sc.next()+")" ; while(true){ String op=sc.next(); if(op.equals("=")){ break ; } exp="("+exp+op+sc.next()+")" ; } Parser parser=new Parser(exp); System.out.println(parser.expression()); } public static void main(String[] args){ new Main().run(); } } class Parser { char[] exp ; int begin ; Parser(String str){ this.exp=(str+"#").toCharArray(); } int expression(){ int ret=term(); while(true){ if(exp[begin]=='+'){ begin++; ret+=term(); } else if(exp[begin]=='-'){ begin++; ret-=term(); } else { break ; } } return ret ; } int term(){ int ret=factor(); while(true){ if(exp[begin]=='*'){ begin++; ret*=factor(); } else if(exp[begin]=='/'){ begin++; ret/=factor(); } else { break ; } } return ret ; } int number(){ int ret=0 ; while(Character.isDigit(exp[begin])){ ret*=10 ; ret+=exp[begin]-'0' ; begin++; } return ret ; } int factor(){ if(exp[begin]=='('){ begin++; int ret=expression(); begin++; return ret ; } else { return number(); } } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var exp : String ; exp := "(" + sc.getCurrent() + sc.getCurrent() + sc.getCurrent() + ")" ; while (true) do ( var op : String ; op := sc.getCurrent() ; if (op = "=") then ( break ) else skip ; exp := "(" + exp + op + sc.getCurrent() + ")" ) ; var parser : Parser ; parser := Parser.newParser(exp) ; OclFile["System.out"].println(parser.expression()) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } class Parser { attribute exp : Sequence(String); attribute begin : int; static operation newParser( str : String) : Parser pre: true post: true activity: ( var self : Parser ; self := createParser(); self.initialise(str); return self ); operation initialise( str : String) : void pre: true post: true activity: ( self.exp := (str + "#")->characters() ); operation expression() : int pre: true post: true activity: ( var ret : int ; ret := term() ; while (true) do ( if (exp[begin+1] = '+') then ( begin := begin + 1 ; ret := ret+(term()) ) else if (exp[begin+1] = '-') then ( begin := begin + 1 ; ret := ret-(term()) ) else ( break ) ; ) ; return ret ); operation term() : int pre: true post: true activity: ( var ret : int ; ret := factor() ; while (true) do ( if (exp[begin+1] = '*') then ( begin := begin + 1 ; ret := ret*(factor()) ) else if (exp[begin+1] = '/') then ( begin := begin + 1 ; ret := ret/(factor()) ) else ( break ) ; ) ; return ret ); operation number() : int pre: true post: true activity: ( var ret : int ; ret := 0 ; while ((exp[begin+1] + "")->isMatch("[0-9]")) do ( ret := ret*(10) ; ret := ret+(exp[begin+1] - ('0')->char2byte()) ; begin := begin + 1 ) ; return ret ); operation factor() : int pre: true post: true activity: ( if (exp[begin+1] = '(') then ( begin := begin + 1 ; var ret : int ; ret := expression() ; begin := begin + 1 ; return ret ) else ( return number() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void anglequichord(int z){ System.out.println("The angle is "+z+" degrees"); } public static void main(String[] args){ int z=48 ; anglequichord(z); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation anglequichord( z : int) : void pre: true post: true activity: ( OclFile["System.out"].println("The angle is " + z + " degrees") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var z : int ; z := 48 ; execute anglequichord(z) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args){ MyScanner sc=new MyScanner(); out=new PrintWriter(new BufferedOutputStream(System.out)); int l=sc.nextInt(); int k=sc.nextInt(); long[][] dp=new long[2][l+1]; dp[0][0]=1 ; for(int i=1 ; i<=l ; ++i){ dp[0][i]+=dp[1][i-1]; dp[1][i]+=dp[0][i-1]; if(i>=k)dp[1][i]+=dp[0][i-k]; } long ans=0 ; for(int i=1 ; i<=l ; ++i)ans+=dp[1][i]; out.println(ans); out.close(); } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : MyScanner ; sc := MyScanner.newMyScanner() ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var l : int ; l := sc.nextInt() ; var k : int ; k := sc.nextInt() ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,2)->collect(Integer.subrange(1,l + 1)->collect(0)) ; dp[0+1][0+1] := 1 ; var i : int ; i := 1 ; while i <= l do ( ( dp[0+1][i+1] := dp[0+1][i+1]+(dp[1+1][i - 1+1]) ; dp[1+1][i+1] := dp[1+1][i+1]+(dp[0+1][i - 1+1]) ; if (i >= k) then dp[1+1][i+1] := dp[1+1][i+1]+(dp[0+1][i - k+1]) ; else skip ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i <= l do ( ans := ans+(dp[1+1][i+1]) ; ; i := i + 1 ) ; out.println(ans) ; out.close() ; ); static attribute out : OclFile; static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { int l,k ; long[] dp ; void run(){ Scanner scan=new Scanner(System.in); l=scan.nextInt(); k=scan.nextInt(); dp=new long[l+1]; System.out.println(dfs(l)); } long dfs(int d){ if(l==d)return dfs(d-1)+dfs(d-k); if(d<0)return 0 ; if(d<2)return 1 ; if(dp[d]!=0)return dp[d]; dp[d]=dfs(d-2)+dfs(d-k-1)+1 ; return dp[d]; } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute l : int; attribute dp : Sequence(long); operation run() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; l := scan.getCurrent()->toInteger() ; k := scan.getCurrent()->toInteger() ; dp := Integer.subrange(1,l + 1)->collect(0) ; OclFile["System.out"].println(dfs(l)) ; ); operation dfs( d : int) : long pre: true post: true activity: ( if (l = d) then return dfs(d - 1) + dfs(d - k) else skip ; if (d < 0) then return 0 else skip ; if (d < 2) then return 1 else skip ; if (dp[d+1] /= 0) then return dp[d+1] else skip ; dp[d+1] := dfs(d - 2) + dfs(d - k - 1) + 1 ; return dp[d+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int l=scan.nextInt(); int k=scan.nextInt(); long result=0 ; for(int thick=0 ; thick<=50 ; thick++){ if(thick*k>l){ break ; } for(int thin=0 ; thin<=50 ; thin++){ int height=thick*k+thin+(thick+thin-1); if(height<=0){ continue ; } if(height>l){ break ; } result+=combination(thick+thin,thick); } } System.out.println(result); } static long combination(int n,int m){ BigInteger result=new BigInteger("1"); int j=m ; for(int i=0 ; itoInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var result : long ; result := 0 ; var thick : int ; thick := 0 ; while thick <= 50 do ( ( if (thick * k > l) then ( break ) else skip ; var thin : int ; thin := 0 ; while thin <= 50 do ( ( var height : int ; height := thick * k + thin + (thick + thin - 1) ; if (height <= 0) then ( continue ) else skip ; if (height > l) then ( break ) else skip ; result := result+(combination(thick + thin, thick)) ) ; thin := thin + 1 ) ) ; thick := thick + 1 ) ; OclFile["System.out"].println(result) ; ); static operation combination( n : int, m : int) : long pre: true post: true activity: ( var result : long ; result := long("1") ; var j : int ; j := m ; var i : int ; i := 0 ; while i < m do ( ( result := result.multiply((n - i + "")->toLong()) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= m do ( ( result := result.divide((i + "")->toLong()) ) ; i := i + 1 ) ; return result->oclAsType(long) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-9 ; void run(){ int n=sc.nextInt(); int k=sc.nextInt(); for(int i=0 ; ipow(28)))->oclAsType(long); attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < k do ( ( var x : int ; x := sc.getCurrent()->toInteger() - 1 ; var y : int ; y := sc.getCurrent()->toInteger() - 1 ; var xx : int ; xx := min(x, n - 1 - x) ; var yy : int ; yy := min(y, n - 1 - y) ; execute println((Set{xx, yy}->min() mod 3 + 1) + "") ; ) ; i := i + 1 ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int diff ; int c=2 ; int a=2 ; int sum=0 ; char answer[]=sc.next().toCharArray(); char names[][]=new char[n][]; for(int i=0 ; itoInteger() ; var diff : int ; var c : int ; c := 2 ; var a : int ; a := 2 ; var sum : int ; sum := 0 ; var answer : Sequence(String) ; answer := sc.getCurrent()->characters() ; var names : Sequence(Sequence(String)) ; names := Integer.subrange(1,n)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < n do ( ( names[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( c := 2 ; a := 2 ; var k : int ; k := 0 ; while k < names[i+1]->size() do ( ( if (names[i+1][k+1] = answer[0+1]) then ( var j : int ; j := k + 1 ; while j < names[i+1]->size() do ( ( if (names[i+1][j+1] = answer[1+1]) then ( diff := j - k ; var h : int ; h := j + diff ; while h < names[i+1]->size() do ( ( if (a = answer->size()) then ( sum := sum + 1 ; break ) else if (names[i+1][h+1] = answer[c+1]) then ( c := c + 1 ; a := a + 1 ) else ( c := 2 ; a := 2 ; break ) ; ) ; h := h+(diff) ) ; if (a = answer->size()) then ( sum := sum + 1 ; break ) else skip ) else skip ) ; j := j + 1 ) ) else skip ) ; k := k + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { void solve(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char[] shop=sc.next().toCharArray(); String[] list=new String[n]; boolean[] boo=new boolean[n]; for(int i=0 ; i=c.length)break ; if(c[idx]!=shop[j])break ; if(j==shop.length-1)boo[k]=true ; } if(boo[k])break ; } } } for(int i=0 ; itoInteger() ; var shop : Sequence(String) ; shop := sc.getCurrent()->characters() ; var list : Sequence(String) ; list := Integer.subrange(1,n)->collect(null) ; var boo : Sequence(boolean) ; boo := Integer.subrange(1,n)->collect(false) ; var i : int ; i := 0 ; while i < n do ( list[i+1] := sc.getCurrent() ; ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < 50 do ( ( var k : int ; k := 0 ; while k < n do ( ( if (boo[k+1]) then continue else skip ; var c : Sequence(String) ; c := list[k+1]->characters() ; var l : int ; l := 0 ; while l < c->size() do ( ( var j : int ; j := 0 ; while j < shop->size() do ( ( var idx : int ; idx := i * j + j + l ; if (idx >= c->size()) then break else skip ; if (c[idx+1] /= shop[j+1]) then break else skip ; if (j = shop->size() - 1) then boo[k+1] := true ; else skip ) ; j := j + 1 ) ; if (boo[k+1]) then break else skip ) ; l := l + 1 ) ) ; k := k + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < boo->size() do ( ( if (boo[i+1]) then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static String tidyNum(String str1,int len){ char[] str=str1.toCharArray(); for(int i=len-2 ; i>=0 ; i--){ if(str[i]>str[i+1]){ str[i]--; for(int j=i+1 ; jcharacters() ; var i : int ; i := len - 2 ; while i >= 0 do ( ( if (str[i+1] > str[i + 1+1]) then ( str[i+1] := str[i+1] - 1 ; var j : int ; j := i + 1 ; while j < len do ( str[j+1] := '9' ; ; j := j + 1 ) ) else skip ) ; i := i - 1 ) ; return (str)->sum() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "11333445538" ; var len : int ; len := str->size() ; OclFile["System.out"].println(tidyNum(str, len)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static boolean paddingcheck(String tar,String str,int n,int pad){ boolean f=false ; for(int i=2 ; i=str.length()){ f=false ; break ; } if(tar.charAt(i)==str.charAt(n+i*pad))f=true ; else { f=false ; break ; } } return f ; } static boolean search(String tar,String str){ boolean f=false ; for(int j=0 ; jstr.length())break ; f=paddingcheck(tar,str,j,cnt); if(f==true)return f ; } } } } return f ; } void doIt(){ int n=sc.nextInt(); int ans=0 ; String tar=sc.next(); for(int i=0 ; isize() do ( ( if (n + i * pad >= str->size()) then ( f := false ; break ) else skip ; if (tar->at(i+1) = str->at(n + i * pad+1)) then f := true ; else ( f := false ; break ) ) ; i := i + 1 ) ; return f ); static operation search( tar : String, str : String) : boolean pre: true post: true activity: ( var f : boolean ; f := false ; var j : int ; j := 0 ; while j < str->size() do ( ( if (tar = str) then return true else skip ; if (tar->at(0+1) = str->at(j+1)) then ( var cnt : int ; cnt := 0 ; var i : int ; i := j + 1 ; while i < str->size() do ( ( cnt := cnt + 1 ; if (str->size() < j + cnt) then continue else skip ; if (tar->at(1+1) = str->at(i+1)) then ( if ((j + tar->size() - 1 * cnt) > str->size()) then break else skip ; f := paddingcheck(tar, str, j, cnt) ; if (f = true) then return f else skip ) else skip ) ; i := i + 1 ) ) else skip ) ; j := j + 1 ) ; return f ); operation doIt() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var tar : String ; tar := sc.getCurrent() ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := sc.getCurrent() ; if (search(tar, s)) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int N=parseInt(br.readLine()); String dst=br.readLine(); char top=dst.charAt(0); int count=0 ; for(int i=0 ; i=src.length()){ break outer2 ; } if(dst.charAt(l)!=src.charAt(j+l+(k*l)))break ; if(l==dst.length()-1){ count++; break outer1 ; } } } } } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var N : int ; N := parseInt(br.readLine()) ; var dst : String ; dst := br.readLine() ; var top : String ; top := dst->at(0+1) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N do ( ( var src : String ; src := br.readLine() ; var j : int ; j := 0 ; while j < src->size() do ( ( if (src->at(j+1) = top) then ( var k : int ; k := 0 ; while true do ( ( var l : int ; l := 0 ; while l < dst->size() do ( ( if (j + l + (k * l) >= src->size()) then ( break ) else skip ; if (dst->at(l+1) /= src->at(j + l + (k * l)+1)) then break else skip ; if (l = dst->size() - 1) then ( count := count + 1 ; break ) else skip ) ; l := l + 1 ) ) ; k := k + 1 ) ) else skip ; ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private boolean stringMach(char[] base,String boardStr){ int boardStrlen=boardStr.length()-1 ; int baseIndex=0 ; for(int i=0 ; isize() - 1 ; var baseIndex : int ; baseIndex := 0 ; var i : int ; i := 0 ; while i < boardStrlen do ( ( if (base[baseIndex+1] = boardStr->at(i+1)) then ( baseIndex := baseIndex + 1 ; var j : int ; j := i + 1 ; while j < boardStrlen do ( ( if (base[baseIndex+1] = boardStr->at(j+1)) then ( var margin : int ; margin := j - i ; baseIndex := baseIndex + 1 ; var k : int ; k := j + margin ; while k <= boardStrlen do ( ( if (base[baseIndex+1] = boardStr->at(k+1)) then ( baseIndex := baseIndex + 1 ) else k := boardStrlen ; ; if (baseIndex = base->size()) then ( return true ) else skip ) ; k := k+(margin) ) ) else skip ; baseIndex := 1 ) ; j := j + 1 ) ) else skip ; baseIndex := 0 ) ; i := i + 1 ) ; return false ); operation doIt() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var boardNam : int ; boardNam := sc.getCurrent()->toInteger() ; var board : Sequence(String) ; board := Integer.subrange(1,boardNam)->collect(null) ; var base : Sequence(String) ; base := sc.getCurrent()->characters() ; var trueNum : int ; trueNum := 0 ; var i : int ; i := 0 ; while i < boardNam do ( ( board[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < boardNam do ( ( if (stringMach(base, board[i+1])) then ( trueNum := trueNum + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(trueNum) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doIt() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF218_D2_A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int peaksNum=scanner.nextInt(); int modified=scanner.nextInt(); int[] peaks=new int[peaksNum*2+1]; for(int i=0 ; i=0 ; i--){ if(modified!=0 && i % 2==1){ if((peaks[i-1]peaks[i+1])){ peaks[i]-=1 ; modified--; } } } for(int i=0 ; itoInteger() ; var modified : int ; modified := scanner.getCurrent()->toInteger() ; var peaks : Sequence(int) ; peaks := Integer.subrange(1,peaksNum * 2 + 1)->collect(0) ; var i : int ; i := 0 ; while i < peaksNum * 2 + 1 do ( ( peaks[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := peaksNum * 2 ; while i >= 0 do ( ( if (modified /= 0 & i mod 2 = 1) then ( if ((peaks[i - 1+1] < peaks[i+1] - 1 & peaks[i+1] - 1 > peaks[i + 1+1])) then ( peaks[i+1] := peaks[i+1]-(1) ; modified := modified - 1 ) else skip ) else skip ) ; i := i - 1 ) ; var i : int ; i := 0 ; while i < peaksNum * 2 + 1 do ( ( OclFile["System.out"].print(peaks[i+1] + " ") ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int[] blood=new int[4]; Arrays.fill(blood,0); while(sc.hasNext()){ String[] str=sc.next().split(","); if(str[1] .equals("A")){ blood[0]++; } else if(str[1] .equals("B")){ blood[1]++; } else if(str[1] .equals("AB")){ blood[2]++; } else { blood[3]++; } } for(int $=0 ; $collect(0) ; blood := blood->collect(0) ; while (sc.hasNext()) do ( var str : Sequence(String) ; str := sc.getCurrent()->split(",") ; if (str[1+1] = "A") then ( blood[0+1] := blood[0+1] + 1 ) else if (str[1+1] = "B") then ( blood[1+1] := blood[1+1] + 1 ) else if (str[1+1] = "AB") then ( blood[2+1] := blood[2+1] + 1 ) else ( blood[3+1] := blood[3+1] + 1 ) ; ; ) ; var $ : int ; $ := 0 ; while $ < blood->size() do ( ( OclFile["System.out"].println(blood[$+1]) ) ; $ := $ + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.util.Arrays.*; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { static void tr(Object...os){ System.err.println(deepToString(os)); } void run(){ Scanner sc=new Scanner(System.in); Maptoi=new HashMap(); toi.put("A",0); toi.put("B",1); toi.put("AB",2); toi.put("O",3); int[] ans=new int[4]; for(; sc.hasNext(); ){ String[] s=sc.next().split(","); ++ans[toi.get(s[1])]; } for(int i=0 ; i<4 ; i++){ System.out.println(ans[i]); } } public static void main(String[] args)throws Exception { new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation tr( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var toi : Map(String,int) ; toi := Map{} ; toi := toi->union(Map{"A" |-> 0}) ; toi := toi->union(Map{"B" |-> 1}) ; toi := toi->union(Map{"AB" |-> 2}) ; toi := toi->union(Map{"O" |-> 3}) ; var ans : Sequence(int) ; ans := Integer.subrange(1,4)->collect(0) ; while sc.hasNext() do ( ( var s : Sequence(String) ; s := sc.getCurrent()->split(",") ; ans[toi->at(s[1+1])+1] := ans[toi->at(s[1+1])+1] + 1 ) ) ; var i : int ; i := 0 ; while i < 4 do ( ( OclFile["System.out"].println(ans[i+1]) ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { int i=0,length=0,dam=0 ; boolean first=true ; try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ String line ; while((line=br.readLine())!=null){ if(first){ length=Integer.parseInt(line); first=false ; line=br.readLine(); dam=Integer.parseInt(line); } else { String[] tokens=line.split(" "); int a=Integer.parseInt(tokens[0]); int b=Integer.parseInt(tokens[1]); if(length % 2==0){ a=length/2toInteger() ; first := false ; line := br.readLine() ; dam := (line)->toInteger() ) else ( var tokens : Sequence(String) ; tokens := line->split(" ") ; var a : int ; a := (tokens[0+1])->toInteger() ; var b : int ; b := (tokens[1+1])->toInteger() ; if (length mod 2 = 0) then ( a := if length / 2 < a then length - a + 1 else a endif ; b := if length / 2 < b then length - b + 1 else b endif ) else ( if (length / 2 + 1 /= a) then ( a := if length / 2 < a then length - a + 1 else a endif ) else skip ; if (length / 2 + 1 /= b) then ( b := if length / 2 < b then length - b + 1 else b endif ) else skip ) ; OclFile["System.out"].println(if Set{a, b}->min() mod 3 = 0 then 3 else Set{a, b}->min() mod 3 endif) ; i := i + 1 ; if (i = dam) then ( break ) else skip ; ) ) ; line := br.readLine() ; ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); HashMapmap=new HashMap(); map.put("A",0); map.put("B",0); map.put("O",0); map.put("AB",0); while(true){ String str=br.readLine(); if(str==null){ break ; } String[] tmpArray=str.split(","); String type=tmpArray[1]; map.put(type,map.get(type)+1); } System.out.println(map.get("A")); System.out.println(map.get("B")); System.out.println(map.get("AB")); System.out.println(map.get("O")); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var map : Map(String,int) ; map := Map{} ; map := map->union(Map{"A" |-> 0}) ; map := map->union(Map{"B" |-> 0}) ; map := map->union(Map{"O" |-> 0}) ; map := map->union(Map{"AB" |-> 0}) ; while (true) do ( var str : String ; str := br.readLine() ; if (str = null) then ( break ) else skip ; var tmpArray : Sequence(String) ; tmpArray := str->split(",") ; var type : String ; type := tmpArray[1+1] ; map := map->union(Map{type |-> map->at(type) + 1}) ; ) ; OclFile["System.out"].println(map->at("A")) ; OclFile["System.out"].println(map->at("B")) ; OclFile["System.out"].println(map->at("AB")) ; OclFile["System.out"].println(map->at("O")) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc ; static final int INF=1<<28 ; static final double EPS=1e-9 ; void run(){ sc=new Scanner(System.in); int a=0,b=0,ab=0,o=0 ; for(; sc.hasNext(); ){ String s=sc.nextLine().split(",")[1]; if(s.equals("A"))a++; else if(s.equals("B"))b++; else if(s.equals("AB"))ab++; else o++; } println(a+""); println(b+""); println(ab+""); println(o+""); sc.close(); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static attribute INF : int := (1*(2->pow(28)))->oclAsType(long); static attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := 0 ; var b : int ; b := 0 ; var ab : int ; ab := 0 ; var o : int ; o := 0 ; while sc.hasNext() do ( ( var s : String ; s := sc.nextLine()->split(",")[1+1] ; if (s = "A") then a := a + 1 ; else if (s = "B") then b := b + 1 else if (s = "AB") then ab := ab + 1 else o := o + 1 ; ; ; ) ) ; execute println(a + "") ; execute println(b + "") ; execute println(ab + "") ; execute println(o + "") ; skip ; ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class Main { static final int A=0 ; static final int B=1 ; static final int AB=2 ; static final int O=3 ; public static void main(String[] args){ final Scanner stdin=new Scanner(System.in); int[] sum=new int[4]; while(stdin.hasNextLine()){ final String[] input=stdin.nextLine().split(","); if("A".equals(input[1])){ sum[A]++; } else if("B".equals(input[1])){ sum[B]++; } else if("AB".equals(input[1])){ sum[AB]++; } else { sum[O]++; } } System.out.println(sum[A]); System.out.println(sum[B]); System.out.println(sum[AB]); System.out.println(sum[O]); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute A : int := 0; static attribute B : int := 1; static attribute AB : int := 2; static attribute O : int := 3; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdin : OclFile ; stdin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sum : Sequence(int) ; sum := Integer.subrange(1,4)->collect(0) ; while (stdin.hasNextLine()) do ( var input : Sequence(String) ; input := stdin.nextLine()->split(",") ; if ("A" = input[1+1]) then ( sum[A+1] := sum[A+1] + 1 ) else if ("B" = input[1+1]) then ( sum[B+1] := sum[B+1] + 1 ) else if ("AB" = input[1+1]) then ( sum[AB+1] := sum[AB+1] + 1 ) else ( sum[O+1] := sum[O+1] + 1 ) ; ; ) ; OclFile["System.out"].println(sum[A+1]) ; OclFile["System.out"].println(sum[B+1]) ; OclFile["System.out"].println(sum[AB+1]) ; OclFile["System.out"].println(sum[O+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Solution { public ListNode addTwoNumbers(ListNode l1,ListNode l2){ ListNode dummyHead=new ListNode(0); ListNode p=l1,q=l2,curr=dummyHead ; int carry=0 ; while(p!=null || q!=null){ int x=(p!=null)? p.val : 0 ; int y=(q!=null)? q.val : 0 ; int digit=carry+x+y ; carry=digit/10 ; curr.next=new ListNode(digit % 10); curr=curr.next ; if(p!=null)p=p.next ; if(q!=null)q=q.next ; } if(carry>0){ curr.next=new ListNode(carry); } return dummyHead.next ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation addTwoNumbers( l1 : ListNode, l2 : ListNode) : ListNode pre: true post: true activity: ( var dummyHead : ListNode ; dummyHead := ListNode.newListNode(0) ; var p : ListNode ; p := l1 ; var q : ListNode ; q := l2 ; var curr : ListNode ; curr := dummyHead ; var carry : int ; carry := 0 ; while (p /= null or q /= null) do ( var x : int ; x := if (p /= null) then p.val else 0 endif ; var y : int ; y := if (q /= null) then q.val else 0 endif ; var digit : int ; digit := carry + x + y ; carry := digit / 10 ; curr.next := ListNode.newListNode(digit mod 10) ; curr := curr.next ; if (p /= null) then p := p.next ; else skip ; if (q /= null) then q := q.next ; else skip ; ) ; if (carry > 0) then ( curr.next := ListNode.newListNode(carry) ) else skip ; return dummyHead.next ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static long binomialCoeff(int n,int k){ long res=1 ; if(k>n-k)k=n-k ; for(int i=0 ; i n - k) then k := n - k ; else skip ; var i : int ; i := 0 ; while i < k do ( ( res := res*((n - i)) ; res := res/((i + 1)) ) ; i := i + 1 ) ; return res ); static operation countPaths( x1 : int, y1 : int, x2 : int, y2 : int) : long pre: true post: true activity: ( var m : int ; m := if x1 - x2 < 0 then -(x1 - x2) else x1 - x2 endif ; var n : int ; n := if y1 - y2 < 0 then -(y1 - y2) else y1 - y2 endif ; return (binomialCoeff(m + n, n)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x1 : int ; x1 := 2 ; var y1 : int ; y1 := 3 ; var x2 : int ; x2 := 4 ; var y2 : int ; y2 := 5 ; OclFile["System.out"].println(countPaths(x1, y1, x2, y2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int breakSum(int n){ if(n==0 || n==1)return n ; return Math.max((breakSum(n/2)+breakSum(n/3)+breakSum(n/4)),n); } public static void main(String[] args){ int n=12 ; System.out.println(breakSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation breakSum( n : int) : int pre: true post: true activity: ( if (n = 0 or n = 1) then return n else skip ; return Set{(breakSum(n / 2) + breakSum(n / 3) + breakSum(n / 4)), n}->max() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12 ; OclFile["System.out"].println(breakSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class x809B { static BufferedReader infile ; public static void main(String hi[])throws Exception { infile=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(infile.readLine()); N=Integer.parseInt(st.nextToken()); st.nextToken(); res=new ArrayList(); find(1,N); int first=res.get(0); if(first>1)find(1,first-1); if(firstres ; public static void find(int left,int right)throws Exception { if(left==right){ boolean works=true ; if(left>1 && query(left,left-1)==1)works=false ; if(lefttoInteger() ; st.next() ; res := Sequence{} ; execute find(1, N) ; var first : int ; first := res->at(0+1) ; if (first > 1) then execute find(1, first - 1) ; else skip ; if (first < N) then execute find(first + 1, N) ; else skip ; ); static attribute N : int; static attribute res : Sequence(int); static operation find( left : int, right : int) : void pre: true post: true activity: ( if (left = right) then ( var works : boolean ; works := true ; if (left > 1 & query(left, left - 1) = 1) then works := false ; else skip ; if (left < N & query(left, left + 1) = 1) then works := false ; else skip ; if (works) then ( res := res->including(left) ; if (res->size() = 2) then ( OclFile["System.out"].println("2 " + res->at(0+1) + " " + res->at(1+1)) ; OclProcess.exit(0) ) else skip ) else skip ; return ) else skip ; var mid : int ; mid := (left + right) / 2 ; if (query(mid, mid + 1) = 0) then execute find(left, mid) ; else execute find(mid + 1, right) ; ); static operation query( a : int, b : int) : int pre: true post: true activity: ( OclFile["System.out"].println("1 " + a + " " + b) ; OclFile["System.out"].flush() ; var s : String ; s := infile.readLine() ; if (s->at(0+1) = 'T') then return 0 else skip ; return 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class GladToSeeYou { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int n=sc.nextInt(); int k=sc.nextInt(); int i=search1(0,n); int j=search1(0,i-1); if(j==0 || ! query(j,i))j=search2(i,n); System.out.println("2 "+i+" "+j); } public static boolean query(int x,int y){ System.out.println("1 "+x+" "+y); return sc.next().equals("TAK"); } public static int search1(int x,int y){ int low=x ; int high=y ; while(low+1toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := search1(0, n) ; var j : int ; j := search1(0, i - 1) ; if (j = 0 or not(query(j, i))) then j := search2(i, n) ; else skip ; OclFile["System.out"].println("2 " + i + " " + j) ; ); static operation query( x : int, y : int) : boolean pre: true post: true activity: ( OclFile["System.out"].println("1 " + x + " " + y) ; return sc.getCurrent() = "TAK" ); static operation search1( x : int, y : int) : int pre: true post: true activity: ( var low : int ; low := x ; var high : int ; high := y ; while (low + 1 < high) do ( var i : int ; i := (low + high) / 2 ; if (query(i, i + 1)) then high := i ; else low := i ; ) ; return high ); static operation search2( x : int, y : int) : int pre: true post: true activity: ( var low : int ; low := x ; var high : int ; high := y ; while (low + 1 < high) do ( var i : int ; i := (low + high) / 2 ; if (query(i + 1, i)) then low := i ; else high := i ; ) ; return high ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class CF809B extends PrintWriter { CF809B(){ super(System.out,true); } Scanner sc=new Scanner(System.in); public static void main(String[] $){ CF809B o=new CF809B(); o.main(); o.flush(); } boolean query(int i,int j){ println("1 "+i+" "+j); return sc.next().equals("TAK"); } int search(int lower,int upper){ while(upper-lower>1){ int i=(lower+upper)/2 ; if(query(i,i+1))upper=i ; else lower=i ; } return upper ; } int search_(int lower,int upper){ while(upper-lower>1){ int i=(lower+upper)/2 ; if(query(i+1,i))lower=i ; else upper=i ; } return upper ; } void main(){ int n=sc.nextInt(); int k=sc.nextInt(); int i=search(0,n); int j=search(0,i-1); if(j==0 || ! query(j,i))j=search_(i,n); println("2 "+i+" "+j); } } ------------------------------------------------------------ OCL File: --------- class CF809B extends OclFile { static operation newCF809B() : CF809B pre: true post: true activity: ( var self : CF809B ; self := createCF809B(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute super(OclFile["System.out"], true) ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var o : CF809B ; o := CF809B.newCF809B() ; o.main() ; o.flush() ); operation query( i : int, j : int) : boolean pre: true post: true activity: ( execute println("1 " + i + " " + j) ; return sc.getCurrent() = "TAK" ); operation search( lower : int, upper : int) : int pre: true post: true activity: ( while (upper - lower > 1) do ( var i : int ; i := (lower + upper) / 2 ; if (query(i, i + 1)) then upper := i ; else lower := i ; ) ; return upper ); operation search_( lower : int, upper : int) : int pre: true post: true activity: ( while (upper - lower > 1) do ( var i : int ; i := (lower + upper) / 2 ; if (query(i + 1, i)) then lower := i ; else upper := i ; ) ; return upper ); operation main() : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := search(0, n) ; var j : int ; j := search(0, i - 1) ; if (j = 0 or not(query(j, i))) then j := search_(i, n) ; else skip ; execute println("2 " + i + " " + j) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static int n=3 ; static void preComputeXor(int arr[][],int prefix_xor[][]){ for(int i=0 ; icollect(Integer.subrange(1,n)->collect(0)) ; execute preComputeXor(arr, prefix_xor) ; OclFile["System.out"].println(ansQuerie(prefix_xor, 1, 1, 2, 2)) ; OclFile["System.out"].println(ansQuerie(prefix_xor, 1, 2, 2, 2)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int m=scanner.nextInt(); while(m-->0){ int w=scanner.nextInt(); int h=scanner.nextInt(); int ans=Math.min(w,Math.min(n+1-w,Math.min(h,n+1-h))); ans %=3 ; System.out.println(ans==0 ? 3 : ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; while (m > 0) do ( m := m - 1 ; skip ; ( var w : int ; w := scanner.getCurrent()->toInteger() ; var h : int ; h := scanner.getCurrent()->toInteger() ; var ans : int ; ans := Set{w, Set{n + 1 - w, Set{h, n + 1 - h}->min()}->min()}->min() ; ans := ans mod 3 ; OclFile["System.out"].println(if ans = 0 then 3 else ans endif) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int bellNumber(int n){ int[][] bell=new int[n+1][n+1]; bell[0][0]=1 ; for(int i=1 ; i<=n ; i++){ bell[i][0]=bell[i-1][i-1]; for(int j=1 ; j<=i ; j++)bell[i][j]=bell[i-1][j-1]+bell[i][j-1]; } return bell[n][0]; } public static void main(String[] args){ for(int n=0 ; n<=5 ; n++)System.out.println("Bell Number "+n+" is "+bellNumber(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation bellNumber( n : int) : int pre: true post: true activity: ( var bell : Sequence(Sequence(int)) ; bell := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; bell[0+1][0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( ( bell[i+1][0+1] := bell[i - 1+1][i - 1+1] ; var j : int ; j := 1 ; while j <= i do ( bell[i+1][j+1] := bell[i - 1+1][j - 1+1] + bell[i+1][j - 1+1] ; ; j := j + 1 ) ) ; i := i + 1 ) ; return bell[n+1][0+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 0 ; while n <= 5 do ( OclFile["System.out"].println("Bell Number " + n + " is " + bellNumber(n)) ; ; n := n + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean Survives(int n){ for(int i=2 ; ; i++){ if(i>n)return true ; if(n % i==0)return false ; n-=n/i ; } } public static void main(String[] args){ int n=17 ; if(Survives(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Survives( n : int) : boolean pre: true post: true activity: ( var i : int ; i := 2 ; while true do ( ( if (i > n) then return true else skip ; if (n mod i = 0) then return false else skip ; n := n-(n / i) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 17 ; if (Survives(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isFactorial(int n){ for(int i=1 ; ; i++){ if(n % i==0){ n/=i ; } else { break ; } } if(n==1){ return true ; } else { return false ; } } public static void main(String[] args){ int n=24 ; boolean ans=isFactorial(n); if(ans==true){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isFactorial( n : int) : boolean pre: true post: true activity: ( var i : int ; i := 1 ; while true do ( ( if (n mod i = 0) then ( n := n/(i) ) else ( break ) ) ; i := i + 1 ) ; if (n = 1) then ( return true ) else ( return false ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 24 ; var ans : boolean ; ans := isFactorial(n) ; if (ans = true) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean onlyFirstAndLastAreSet(int n){ if(n==1)return true ; if(n==2)return false ; return(((n-1)&(n-2))==0); } public static void main(String[] args){ int n=9 ; if(onlyFirstAndLastAreSet(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation onlyFirstAndLastAreSet( n : int) : boolean pre: true post: true activity: ( if (n = 1) then return true else skip ; if (n = 2) then return false else skip ; return (((n - 1) & (n - 2)) = 0) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; if (onlyFirstAndLastAreSet(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String target=(scanner.next()).toLowerCase(); int result=0 ; String word="" ; while(true){ word=scanner.next(); if(word.equals("END_OF_TEXT")){ break ; } word=word.toLowerCase(); if(word.equals(target)){ result++; } } System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var target : String ; target := (scanner.getCurrent())->toLowerCase() ; var result : int ; result := 0 ; var word : String ; word := "" ; while (true) do ( word := scanner.getCurrent() ; if (word = "END_OF_TEXT") then ( break ) else skip ; word := word->toLowerCase() ; if (word = target) then ( result := result + 1 ) else skip ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean adjacentSet(int n){ int x=(n &(n>>1)); if(x==1)return true ; else return false ; } public static void main(String args[]){ int n=3 ; if(adjacentSet(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation adjacentSet( n : int) : boolean pre: true post: true activity: ( var x : int ; x := (MathLib.bitwiseAnd(n,((n/(2->pow(1)))->oclAsType(long)))) ; if (x = 1) then return true else return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; if (adjacentSet(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printUncommon(String str1,String str2){ int a1=0,a2=0 ; for(int i=0 ; isize() do ( ( var ch : int ; ch := (str1->at(i+1)) - ('a')->char2byte() ; a1 := MathLib.bitwiseOr(a1,((1*(2->pow(ch)))->oclAsType(long))) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < str2->size() do ( ( var ch : int ; ch := (str2->at(i+1)) - ('a')->char2byte() ; a2 := MathLib.bitwiseOr(a2,((1*(2->pow(ch)))->oclAsType(long))) ) ; i := i + 1 ) ; var ans : int ; ans := MathLib.bitwiseXor(a1,a2) ; var i : int ; i := 0 ; while (i < 26) do ( if (ans mod 2 = 1) then ( OclFile["System.out"].print(('a' + i)->oclAsType(String)) ) else skip ; ans := ans / 2 ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str1 : String ; str1 := "geeksforgeeks" ; var str2 : String ; str2 := "geeksquiz" ; execute printUncommon(str1, str2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class ClassroomWatch { public static void main(String[] args){ Scanner in=new Scanner(System.in); int num=in.nextInt(); int copy=num ; Listresult=new ArrayList<>(); int copyOut=copy ; int math=Math.max(num-100,1); while(copy>=math){ copy-=1 ; int sum=0 ; copyOut=copy ; while(copyOut>0){ sum=sum+(copyOut % 10); copyOut=copyOut/10 ; } if((sum+copy)==num){ result.add(copy); } } System.out.println(result.size()); Collections.sort(result); for(int i=0 ; itoInteger() ; var copy : int ; copy := num ; var result : Sequence(int) ; result := Sequence{} ; var copyOut : int ; copyOut := copy ; var math : int ; math := Set{num - 100, 1}->max() ; while (copy >= math) do ( copy := copy-(1) ; var sum : int ; sum := 0 ; copyOut := copy ; while (copyOut > 0) do ( sum := sum + (copyOut mod 10) ; copyOut := copyOut / 10 ) ; if ((sum + copy) = num) then ( result := result->including(copy) ) else skip ; ) ; OclFile["System.out"].println(result->size()) ; result := result->sort() ; var i : int ; i := 0 ; while i < result->size() do ( ( OclFile["System.out"].println(result->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class ClassroomWatch { public static void main(String[] args){ Scanner in=new Scanner(System.in); int num=in.nextInt(); int copy=num ; Listresult=new ArrayList<>(); int copyOut=copy ; int math=Math.max(num-100,1); while(copy>=math){ copy-=1 ; int sum=0 ; copyOut=copy ; while(copyOut>0){ sum=sum+(copyOut % 10); copyOut=copyOut/10 ; } if((sum+copy)==num){ result.add(copy); } } System.out.println(result.size()); Collections.sort(result); for(int i=0 ; itoInteger() ; var copy : int ; copy := num ; var result : Sequence(int) ; result := Sequence{} ; var copyOut : int ; copyOut := copy ; var math : int ; math := Set{num - 100, 1}->max() ; while (copy >= math) do ( copy := copy-(1) ; var sum : int ; sum := 0 ; copyOut := copy ; while (copyOut > 0) do ( sum := sum + (copyOut mod 10) ; copyOut := copyOut / 10 ) ; if ((sum + copy) = num) then ( result := result->including(copy) ) else skip ; ) ; OclFile["System.out"].println(result->size()) ; result := result->sort() ; var i : int ; i := 0 ; while i < result->size() do ( ( OclFile["System.out"].println(result->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class ClassroomWatch { public static void main(String[] args){ Scanner in=new Scanner(System.in); long n=in.nextLong(); long sum ; ArrayListarrayList=new ArrayList<>(); for(int i=100 ; i>0 ; i--){ long j=n-i ; sum=sum(j); if(sum==i)arrayList.add(n-i); } System.out.println(arrayList.size()); for(int i=0 ; itoLong() ; var sum : long ; var arrayList : Sequence(long) ; arrayList := Sequence{} ; var i : int ; i := 100 ; while i > 0 do ( ( var j : long ; j := n - i ; sum := sum(j) ; if (sum = i) then arrayList := arrayList->including(n - i) ; else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(arrayList->size()) ; var i : int ; i := 0 ; while i < arrayList->size() do ( OclFile["System.out"].println(arrayList->at(i+1)) ; ; i := i + 1 ) ; ); static operation sum( n : long) : long pre: true post: true activity: ( var sum : long ; sum := 0 ; while (n /= 0) do ( var x : long ; x := n mod 10 ; sum := sum+(x) ; n := n/(10) ) ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); int l=scan.nextInt(); int r=scan.nextInt(); int sAll=scan.nextInt(); int sk=scan.nextInt(); int[] ans=getPoints(n,k,l,r,sAll,sk); for(int num : ans){ System.out.print(num+" "); } } public static int[] getPoints(int n,int k,int l,int r,int sAll,int sk){ int[] ans=new int[n]; Arrays.fill(ans,l); sAll-=sk+(n-k)*l ; sk-=k*l ; while(sk>0){ int idx=n-1 ; while(sk>0 && idx>=n-k){ ans[idx--]++; sk--; } } while(sAll>0){ int idx=0 ; while(sAll>0 && idxtoInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var l : int ; l := scan.getCurrent()->toInteger() ; var r : int ; r := scan.getCurrent()->toInteger() ; var sAll : int ; sAll := scan.getCurrent()->toInteger() ; var sk : int ; sk := scan.getCurrent()->toInteger() ; var ans : Sequence(int) ; ans := getPoints(n, k, l, r, sAll, sk) ; for (num : ans) do ( ( OclFile["System.out"].print(num + " ") ) ) ; ); static operation getPoints( n : int, k : int, l : int, r : int, sAll : int, sk : int) : Sequence(int) pre: true post: true activity: ( var ans : Sequence(int) ; ans := Integer.subrange(1,n)->collect(0) ; ans := ans->collect(l) ; sAll := sAll-(sk + (n - k) * l) ; sk := sk-(k * l) ; while (sk > 0) do ( var idx : int ; idx := n - 1 ; while (sk > 0 & idx >= n - k) do ( ans[idx+1] := ans[idx+1] + 1 ; sk := sk - 1 ) ) ; while (sAll > 0) do ( var idx : int ; idx := 0 ; while (sAll > 0 & idx < n - k) do ( ans[idx+1] := ans[idx+1] + 1 ; sAll := sAll - 1 ) ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ClassroomWatch { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); ArrayListans=solve(n); pw.println(ans.size()); for(int i : ans)pw.println(i); pw.close(); } static ArrayListsolve(int n){ ArrayListans=new ArrayList<>(); if(n<100){ for(int i=0 ; i<=n ; i++){ if(posi(i,n))ans.add(i); } } else { for(int i=n-100 ; i<=n ; i++){ if(posi(i,n))ans.add(i); } } return ans ; } static boolean posi(int n,int N){ int temp=n ; int ans=0 ; while(temp!=0){ ans+=(temp % 10); temp/=10 ; } return(ans+n)==N ; } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class ClassroomWatch { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var ans : Sequence(int) ; ans := solve(n) ; skip ; for (i : ans) do ( skip ; ) ; skip ; ); static operation solve( n : int) : Sequence(int) pre: true post: true activity: ( var ans : Sequence(int) ; ans := Sequence{} ; if (n < 100) then ( var i : int ; i := 0 ; while i <= n do ( ( if (posi(i, n)) then ans := ans->including(i) ; else skip ) ; i := i + 1 ) ) else ( var i : int ; i := n - 100 ; while i <= n do ( ( if (posi(i, n)) then ans := ans->including(i) ; else skip ) ; i := i + 1 ) ) ; return ans ); static operation posi( n : int, N : int) : boolean pre: true post: true activity: ( var temp : int ; temp := n ; var ans : int ; ans := 0 ; while (temp /= 0) do ( ans := ans+((temp mod 10)) ; temp := temp/(10) ) ; return (ans + n) = N ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countFactors(int n){ int factors=0 ; for(int i=2 ; i*i<=n ; i++){ while(n % i==0){ n/=i ; factors+=1 ; } } if(n!=1)factors++; return factors ; } static int __gcd(int a,int b){ if(b==0)return a ; return __gcd(b,a % b); } static int minOperations(int A,int B){ int g=__gcd(A,B); A/=g ; B/=g ; return countFactors(A)+countFactors(B); } public static void main(String[] args){ int A=10,B=15 ; System.out.println(minOperations(A,B)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countFactors( n : int) : int pre: true post: true activity: ( var factors : int ; factors := 0 ; var i : int ; i := 2 ; while i * i <= n do ( ( while (n mod i = 0) do ( n := n/(i) ; factors := factors+(1) ) ) ; i := i + 1 ) ; if (n /= 1) then factors := factors + 1 ; else skip ; return factors ); static 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) ); static operation minOperations( A : int, B : int) : int pre: true post: true activity: ( var g : int ; g := __gcd(A, B) ; A := A/(g) ; B := B/(g) ; return countFactors(A) + countFactors(B) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 10 ; var B : int ; B := 15 ; OclFile["System.out"].println(minOperations(A, B)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int flipBit(int a){ if(~ a==0){ return 8*sizeof(); } int currLen=0,prevLen=0,maxLen=0 ; while(a!=0){ if((a & 1)==1){ currLen++; } else if((a & 1)==0){ prevLen=(a & 2)==0 ? 0 : currLen ; currLen=0 ; } maxLen=Math.max(prevLen+currLen,maxLen); a>>=1 ; } return maxLen+1 ; } static byte sizeof(){ byte sizeOfInteger=8 ; return sizeOfInteger ; } public static void main(String[] args){ System.out.println(flipBit(13)); System.out.println(flipBit(1775)); System.out.println(flipBit(15)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation flipBit( a : int) : int pre: true post: true activity: ( if (-(a + 1) = 0) then ( return 8 * sizeof() ) else skip ; var currLen : int ; currLen := 0 ; var prevLen : int ; prevLen := 0 ; var maxLen : int ; maxLen := 0 ; while (a /= 0) do ( if ((a & 1) = 1) then ( currLen := currLen + 1 ) else if ((a & 1) = 0) then ( prevLen := if (a & 2) = 0 then 0 else currLen endif ; currLen := 0 ) else skip ; ; maxLen := Set{prevLen + currLen, maxLen}->max() ; a := a/(2->pow(1)) ) ; return maxLen + 1 ); static operation sizeof() : int pre: true post: true activity: ( var sizeOfInteger : int ; sizeOfInteger := 8 ; return sizeOfInteger ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(flipBit(13)) ; OclFile["System.out"].println(flipBit(1775)) ; OclFile["System.out"].println(flipBit(15)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int printMinimumProduct(int arr[],int n){ int first_min=Math.min(arr[0],arr[1]); int second_min=Math.max(arr[0],arr[1]); for(int i=2 ; imin() ; var second_min : int ; second_min := Set{arr[0+1], arr[1+1]}->max() ; var i : int ; i := 2 ; while i < n do ( ( if (arr[i+1] < first_min) then ( second_min := first_min ; first_min := arr[i+1] ) else if (arr[i+1] < second_min) then second_min := arr[i+1] ; else skip ; ) ; i := i + 1 ) ; return first_min * second_min ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{11,8,5,7,5,100} ; var n : int ; n := a->size() ; OclFile["System.out"].print(printMinimumProduct(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static String checkNumber(int N){ int temp=N ; while(temp>0){ if(temp % 1000==144)temp/=1000 ; else if(temp % 100==14)temp/=100 ; else if(temp % 10==1)temp/=10 ; else { return "NO" ; } } return "YES" ; } public static void main(String[] args){ int N=1414 ; System.out.println(checkNumber(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkNumber( N : int) : String pre: true post: true activity: ( var temp : int ; temp := 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 "NO" ) ; ; ) ; return "YES" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 1414 ; OclFile["System.out"].println(checkNumber(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String W ; String T ; String str ; ArrayListlist=new ArrayList(); int count=0 ; str=br.readLine(); W=str.toLowerCase(); while(true){ T=br.readLine(); if(T.equals("END_OF_TEXT")){ break ; } String strArray[]=T.split(" "); for(int i=0 ; itoLowerCase() ; while (true) do ( T := br.readLine() ; if (T = "END_OF_TEXT") then ( break ) else skip ; var strArray : Sequence(String) ; strArray := T->split(" ") ; var i : int ; i := 0 ; while i < strArray->size() do ( ( list := list->including(strArray[i+1]->toLowerCase()) ) ; i := i + 1 ) ) ; var i : int ; i := 0 ; while i < list->size() do ( ( if (W = list->at(i+1)) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class MyHashMap { final ListNode[] nodes=new ListNode[10000]; public void put(int key,int value){ int i=idx(key); if(nodes[i]==null)nodes[i]=new ListNode(-1,-1); ListNode prev=find(nodes[i],key); if(prev.next==null)prev.next=new ListNode(key,value); else prev.next.val=value ; } public int get(int key){ int i=idx(key); if(nodes[i]==null)return-1 ; ListNode node=find(nodes[i],key); return node.next==null ?-1 : node.next.val ; } public void remove(int key){ int i=idx(key); if(nodes[i]==null)return ; ListNode prev=find(nodes[i],key); if(prev.next==null)return ; prev.next=prev.next.next ; } int idx(int key){ return Integer.hashCode(key)% nodes.length ; } ListNode find(ListNode bucket,int key){ ListNode node=bucket,prev=null ; while(node!=null && node.key!=key){ prev=node ; node=node.next ; } return prev ; } class ListNode { int key,val ; ListNode next ; ListNode(int key,int val){ this.key=key ; this.val=val ; } } } ------------------------------------------------------------ OCL File: --------- class MyHashMap { attribute nodes : Sequence(ListNode) := Integer.subrange(1,10000)->collect(null); operation put( key : int, value : int) : void pre: true post: true activity: ( var i : int ; i := idx(key) ; if (nodes[i+1] = null) then nodes[i+1] := ListNode.newListNode(-1, -1) ; else skip ; var prev : ListNode ; prev := find(nodes[i+1], key) ; if (prev.next = null) then prev.next := ListNode.newListNode(key, value) ; else prev.next.val := value ; ); operation get( key : int) : int pre: true post: true activity: ( var i : int ; i := idx(key) ; if (nodes[i+1] = null) then return -1 else skip ; var node : ListNode ; node := find(nodes[i+1], key) ; return if node.next = null then -1 else node.next.val endif ); operation remove( key : int) : void pre: true post: true activity: ( var i : int ; i := idx(key) ; if (nodes[i+1] = null) then return else skip ; var prev : ListNode ; prev := find(nodes[i+1], key) ; if (prev.next = null) then return else skip ; prev.next := prev.next.next ; ); operation idx( key : int) : int pre: true post: true activity: ( return hashCode(key) mod nodes->size() ); operation find( bucket : ListNode, key : int) : ListNode pre: true post: true activity: ( var node : ListNode ; node := bucket ; var prev : ListNode ; prev := null ; while (node /= null & node.key /= key) do ( prev := node ; node := node.next ) ; return prev ); class ListNode { attribute key : int; attribute next : ListNode; static operation newListNode( key : int, val : int) : ListNode pre: true post: true activity: ( var self : ListNode ; self := createListNode(); self.initialise(key, val); return self ); operation initialise( key : int, val : int) : void pre: true post: true activity: ( self.key := key ; self.val := val ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n+2]; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); arr[i]=Math.min(arr[i],arr[i-1]+1); } for(int i=n ; i>0 ; i--){ arr[i]=Math.min(arr[i],arr[i+1]+1); } System.out.println(Arrays.stream(arr).max().getAsInt()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; arr[i+1] := Set{arr[i+1], arr[i - 1+1] + 1}->min() ) ; i := i + 1 ) ; var i : int ; i := n ; while i > 0 do ( ( arr[i+1] := Set{arr[i+1], arr[i + 1+1] + 1}->min() ) ; i := i - 1 ) ; OclFile["System.out"].println(stream(arr).max().getAsInt()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n+2]; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); } int[] temp=new int[n+2]; Arrays.fill(temp,Integer.MAX_VALUE); temp[0]=0 ; temp[n+1]=0 ; for(int i=1 ; i<=n ; i++){ temp[i]=Math.min(arr[i],temp[i-1]+1); } for(int i=n ; i>=1 ; i--){ temp[i]=Math.min(temp[i],temp[i+1]+1); } int res=0 ; for(int i=1 ; i<=n ; i++){ res=Math.max(res,temp[i]); } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var temp : Sequence(int) ; temp := Integer.subrange(1,n + 2)->collect(0) ; temp := temp->collect(2147483647) ; temp[0+1] := 0 ; temp[n + 1+1] := 0 ; var i : int ; i := 1 ; while i <= n do ( ( temp[i+1] := Set{arr[i+1], temp[i - 1+1] + 1}->min() ) ; i := i + 1 ) ; var i : int ; i := n ; while i >= 1 do ( ( temp[i+1] := Set{temp[i+1], temp[i + 1+1] + 1}->min() ) ; i := i - 1 ) ; var res : int ; res := 0 ; var i : int ; i := 1 ; while i <= n do ( ( res := Set{res, temp[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(),p=in.nextInt(),l=in.nextInt(),r=in.nextInt(),sall=in.nextInt(),sp=in.nextInt(); if(n-p!=0)loop(sall-sp,n-p); if(p!=0)loop(sp,p); } static void loop(int sum,int n){ int k=sum/n ; for(int i=0,j=sum-k*n ; i0 ? 1 : 0)+" "); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var p : int ; p := in.getCurrent()->toInteger() ; var l : int ; l := in.getCurrent()->toInteger() ; var r : int ; r := in.getCurrent()->toInteger() ; var sall : int ; sall := in.getCurrent()->toInteger() ; var sp : int ; sp := in.getCurrent()->toInteger() ; if (n - p /= 0) then execute loop(sall - sp, n - p) ; else skip ; if (p /= 0) then execute loop(sp, p) ; else skip ); static operation loop( sum : int, n : int) : void pre: true post: true activity: ( var k : int ; k := sum / n ; var i : int ; i := 0 ; var j : int ; j := sum - k * n ; while i < n do ( OclFile["System.out"].print(k + (if j > 0 then 1 else 0 endif) + " ") ; ; i := i + 1 ; j := j - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static BufferedReader bf ; static PrintWriter pw ; static int n ; static int a[]; static void solve(int te)throws Exception { int l=0,r=n-1 ; int cnt=1 ; while(l<=r){ a[l]=Math.min(a[l],cnt); a[r]=Math.min(a[r],cnt); l++; r--; cnt++; } for(int i=1 ; i=0 ; i--){ a[i]=Math.min(a[i+1]+1,a[i]); } int ans=0 ; for(int i=0 ; imin() ; a[r+1] := Set{a[r+1], cnt}->min() ; l := l + 1 ; r := r - 1 ; cnt := cnt + 1 ; ) ; var i : int ; i := 1 ; while i < n do ( ( a[i+1] := Set{a[i - 1+1] + 1, a[i+1]}->min() ) ; i := i + 1 ) ; var i : int ; i := n - 2 ; while i >= 0 do ( ( a[i+1] := Set{a[i + 1+1] + 1, a[i+1]}->min() ) ; i := i - 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ans := Set{a[i+1], ans}->max() ; ; i := i + 1 ) ; str := str + StringLib.newString(ans) + StringLib.newString("\n") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var lenv : boolean ; lenv := false ; var te : int ; te := 1 ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; var s : Sequence(String) ; s := bf.readLine()->trim()->split("\\s+") ; n := (s[0+1])->toInteger() ; a := Integer.subrange(1,n)->collect(0) ; s := bf.readLine()->trim()->split("\\s+") ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (s[i+1])->toInteger() ; ; i := i + 1 ) ; execute solve(te) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int remainderWith7(String num){ int series[]={ 1,3,2,-1,-3,-2 }; int series_index=0 ; int result=0 ; for(int i=num.length()-1 ; i>=0 ; i--){ int digit=num.charAt(i)-'0' ; result+=digit*series[series_index]; series_index=(series_index+1)% 6 ; result %=7 ; } if(result<0)result=(result+7)% 7 ; return result ; } public static void main(String[] args){ String str="12345" ; System.out.print("Remainder with 7 is "+remainderWith7(str)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation remainderWith7( num : String) : int pre: true post: true activity: ( var series : Sequence(int) ; series := Sequence{1,3,2,-1,-3,-2} ; var series_index : int ; series_index := 0 ; var result : int ; result := 0 ; var i : int ; i := num->size() - 1 ; while i >= 0 do ( ( var digit : int ; digit := num->at(i+1) - ('0')->char2byte() ; result := result+(digit * series[series_index+1]) ; series_index := (series_index + 1) mod 6 ; result := result mod 7 ) ; i := i - 1 ) ; if (result < 0) then result := (result + 7) mod 7 ; else skip ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "12345" ; OclFile["System.out"].print("Remainder with 7 is " + remainderWith7(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Solution { static void niceIndices(int A[],int n){ int sum=0 ; Mapm=new HashMap(); for(int i=0 ; i>1 ; if(m.containsKey(k)){ if((A[i]==k && m.get(k)>1)||(A[i]!=k))System.out.print((i+1)+" "); } } } } public static void main(String args[]){ int A[]={ 8,3,5,2 }; int n=A.length ; niceIndices(A,n); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation niceIndices( A : Sequence(int), n : int) : void pre: true post: true activity: ( var sum : int ; sum := 0 ; var m : Map(int,int) ; m := Map{} ; var i : int ; i := 0 ; while i < n do ( ( m := m->union(Map{A[i+1] |-> if (m->at(A[i+1]) = null) then 0 else m->at(A[i+1]) + 1 endif}) ; sum := sum+(A[i+1]) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var k : int ; k := sum - A[i+1] ; if (k mod 2 = 0) then ( k := (k/(2->pow(1)))->oclAsType(long) ; if (m->keys()->includes(k)) then ( if ((A[i+1] = k & m->at(k) > 1) or (A[i+1] /= k)) then OclFile["System.out"].print((i + 1) + " ") ; else skip ) else skip ) else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : Sequence(int) ; A := Sequence{8,3,5,2} ; var n : int ; n := A->size() ; execute niceIndices(A, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static String partOdd(String s){ String st="" ; for(int i=0 ; isize() do ( ( if (i mod 2 /= 0) then st := st+(s->at(i+1)) ; else skip ) ; i := i + 1 ) ; return st ); static operation partEven( str : String) : String pre: true post: true activity: ( var s : String ; s := "" ; var i : int ; i := 0 ; while i < str->size() do ( ( if (i mod 2 = 0) then s := s+(str->at(i+1)) ; else skip ) ; i := i + 1 ) ; return s ); static operation canBeMadeEqual( s1 : String, s2 : String) : boolean pre: true post: true activity: ( var even1 : Sequence(String) ; even1 := partEven(s1)->characters() ; var even2 : Sequence(String) ; even2 := partEven(s2)->characters() ; var odd1 : Sequence(String) ; odd1 := partOdd(s1)->characters() ; var odd2 : Sequence(String) ; odd2 := partOdd(s2)->characters() ; even1 := even1->sort() ; even2 := even2->sort() ; odd1 := odd1->sort() ; odd2 := odd2->sort() ; var even_s1 : String ; even_s1 := StringLib.newString(even1) ; var even_s2 : String ; even_s2 := StringLib.newString(even2) ; var odd_s1 : String ; odd_s1 := StringLib.newString(odd1) ; var odd_s2 : String ; odd_s2 := StringLib.newString(odd2) ; if (even_s1 = even_s2 & odd_s1 = odd_s2) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s1 : String ; s1 := "cdab" ; var s2 : String ; s2 := "abcd" ; if (canBeMadeEqual(s1, s2)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int minJumps(int a,int b,int d){ int temp=a ; a=Math.min(a,b); b=Math.max(temp,b); if(d>=b)return(d+b-1)/b ; if(d==0)return 0 ; if(d==a)return 1 ; return 2 ; } public static void main(String[] args){ int a=3,b=4,d=11 ; System.out.println(minJumps(a,b,d)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minJumps( a : int, b : int, d : int) : int pre: true post: true activity: ( var temp : int ; temp := a ; a := Set{a, b}->min() ; b := Set{temp, b}->max() ; if (d >= b) 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 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 3 ; var b : int ; b := 4 ; var d : int ; d := 11 ; OclFile["System.out"].println(minJumps(a, b, d)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; boolean iseven=n % 2==0 ; for(int i=0 ; i=0 ; i--)System.out.print(" "+even[i]); for(int i=0 ; i=0 ; i--)System.out.print(" "+odd[i]); for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var iseven : boolean ; iseven := n mod 2 = 0 ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var odd : Sequence(int) ; var even : Sequence(int) ; if (n mod 2 = 0) then ( odd := Integer.subrange(1,n / 2)->collect(0) ; even := Integer.subrange(1,n / 2)->collect(0) ) else ( odd := Integer.subrange(1,(n + 1) / 2)->collect(0) ; even := Integer.subrange(1,n / 2)->collect(0) ) ; if (iseven) then var i : int ; i := 0 ; while i < (n / 2) do ( ( odd[i+1] := a[2 * i+1] ; even[i+1] := a[2 * i + 1+1] ) ; i := i + 1 ) else ( var i : int ; i := 0 ; while i < (n - 1) / 2 do ( ( odd[i+1] := a[2 * i+1] ; even[i+1] := a[2 * i + 1+1] ) ; i := i + 1 ) ; odd[odd->size() - 1+1] := a[a->size() - 1+1] ) ; if (iseven) then ( OclFile["System.out"].print(even[even->size() - 1+1]) ; var i : int ; i := even->size() - 2 ; while i >= 0 do ( OclFile["System.out"].print(" " + even[i+1]) ; ; i := i - 1 ) ; var i : int ; i := 0 ; while i < odd->size() do ( OclFile["System.out"].print(" " + odd[i+1]) ; ; i := i + 1 ) ) else ( OclFile["System.out"].print(odd[odd->size() - 1+1]) ; var i : int ; i := odd->size() - 2 ; while i >= 0 do ( OclFile["System.out"].print(" " + odd[i+1]) ; ; i := i - 1 ) ; var i : int ; i := 0 ; while i < even->size() do ( OclFile["System.out"].print(" " + even[i+1]) ; ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static char[] 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' }; static char[] b={ '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' }; static char[] c={ '0','1','2','3','4','5','6','7','8','9' }; public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int counter=0 ; String W=stdIn.next(); W=W.toLowerCase(); while(stdIn.hasNext()){ String tmp=stdIn.next(); tmp=tmp.toLowerCase(); if(W.equals(tmp)){ counter++; } } System.out.println(counter); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute a : Sequence(String) := Sequence{'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'}; static attribute b : Sequence(String) := Sequence{'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'}; static attribute c : Sequence(String) := Sequence{'0','1','2','3','4','5','6','7','8','9'}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var counter : int ; counter := 0 ; var W : String ; W := stdIn.getCurrent() ; W := W->toLowerCase() ; while (stdIn.hasNext()) do ( var tmp : String ; tmp := stdIn.getCurrent() ; tmp := tmp->toLowerCase() ; if (W = tmp) then ( counter := counter + 1 ) else skip ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.*; import java.io.InputStreamReader ; import java.util.Scanner ; import java.util.StringTokenizer ; import java.util.*; import java.math.*; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String args[]){ FastReader sc=new FastReader(); PrintWriter pw=new PrintWriter(System.out); int t=1 ; while(t-->0){ int n=sc.nextInt(),f=0,a[]=new int[n]; for(int i=0 ; i=0 ; i-=2){ ans[p++]=a[i]; if(i-1>=0)ans[q--]=a[i-1]; } for(int w : ans)pw.print(w+" "); pw.println(); } pw.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.nextInt() ; var f : int ; f := 0 ; var a : Sequence(void) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.nextInt() ) ; i := i + 1 ) ; var ans : Sequence(void) ; ans := Integer.subrange(1,n)->collect(0) ; var p : int ; p := 0 ; var q : int ; q := n - 1 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( ans[p+1] := a[i+1] ; p := p + 1 ; if (i - 1 >= 0) then ans[q+1] := a[i - 1+1] ; q := q - 1 ; else skip ) ; i := i-(2) ) ; for (w : ans) do ( skip ; ) ; skip ; ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.util.Collection ; import java.io.IOException ; import java.io.BufferedReader ; import java.util.Deque ; import java.util.LinkedList ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskC solver=new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(); boolean end=true ; Dequedq=new LinkedList<>(); for(int i=0 ; iappend(in.nextInt()) ) else dq := dq->prepend(in.nextInt()) ; ; end := not(end) ) ; i := i + 1 ) ; if (end) then while (not(dq->isEmpty())) do skip ; else while (not(dq->isEmpty())) do skip ; ; ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { private static int N ; private static ArrayListarrayList=new ArrayList<>(); public static void input(){ Scanner scan=new Scanner(System.in); N=scan.nextInt(); for(int i=0 ; ib=new ArrayList<>(); if(N % 2==0){ for(int i=N-1 ; i>=0 ; i-=2)b.add(arrayList.get(i)); for(int i=0 ; i=0 ; i-=2)b.add(arrayList.get(i)); for(int i=1 ; itoInteger() ; var i : int ; i := 0 ; while i < N do ( ( arrayList := arrayList->including(scan.getCurrent()->toInteger()) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute input() ; var b : Sequence(int) ; b := Sequence{} ; if (N mod 2 = 0) then ( var i : int ; i := N - 1 ; while i >= 0 do ( b := b->including(arrayList->at(i+1)) ; ; i := i-(2) ) ; var i : int ; i := 0 ; while i < N do ( b := b->including(arrayList->at(i+1)) ; ; i := i+(2) ) ) else ( var i : int ; i := N - 1 ; while i >= 0 do ( b := b->including(arrayList->at(i+1)) ; ; i := i-(2) ) ; var i : int ; i := 1 ; while i < N do ( b := b->including(arrayList->at(i+1)) ; ; i := i+(2) ) ) ; var i : int ; i := 0 ; while i < N do ( ( OclFile["System.out"].print(b->at(i+1) + " ") ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void alter(long x,long y){ while(true){ if(x==0 || y==0)break ; if(x>=2*y)x=x %(2*y); else if(y>=2*x)y=y %(2*x); else break ; } System.out.println("X="+x+","+"Y="+y); } public static void main(String[] args){ long x=12,y=5 ; alter(x,y); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation alter( x : long, y : long) : void pre: true post: true activity: ( while (true) do ( if (x = 0 or y = 0) then break else skip ; if (x >= 2 * y) then x := x mod (2 * y) ; else if (y >= 2 * x) then y := y mod (2 * x) else break ; ) ; OclFile["System.out"].println("X=" + x + "," + "Y=" + y) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : long ; x := 12 ; var y : long ; y := 5 ; execute alter(x, y) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Collections ; import java.util.Iterator ; import java.util.LinkedList ; import java.util.Scanner ; public class Main { static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int N=gi(); int[] A=new int[N]; LinkedListl=new LinkedList(); for(int i=0 ; icollect(0) ; var l : Sequence(int) ; l := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := gi() ; if (i mod 2 = 0) then ( l := l->prepend(A[i+1]) ) else ( l := l->append(A[i+1]) ) ) ; i := i + 1 ) ; if (N mod 2 = 0) then l := l->reverse() ; else skip ; var it : OclIterator ; it := l->iterator() ; var f : boolean ; f := false ; while (it.hasNext()) do ( if (f) then ( OclFile["System.out"].print(" ") ) else ( f := true ) ; OclFile["System.out"].print(it.next()) ) ; ); static operation gs() : String pre: true post: true activity: ( return scanner.getCurrent() ); static operation gi() : int pre: true post: true activity: ( return (scanner.getCurrent())->toInteger() ); static operation gl() : long pre: true post: true activity: ( return (scanner.getCurrent())->toLong() ); static operation gd() : double pre: true post: true activity: ( return (scanner.getCurrent())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st ; int T=Integer.parseInt(br.readLine()); for(int test=0 ; testtoInteger() ; var test : int ; test := 0 ; while test < T do ( ( var n : int ; n := (br.readLine())->toInteger() ; var line : String ; line := br.readLine() ; var answer : int ; answer := 0 ; var i : int ; i := 0 ; while i < line->size() - 1 do ( ( if (line->at(i+1) = line->at(i + 1+1) & line->at(i+1) = '0') then ( answer := answer+(2) ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < line->size() - 2 do ( ( if (line->at(i+1) = '0' & line->at(i + 1+1) = '1' & line->at(i + 2+1) = '0') then ( answer := answer+(1) ) else skip ) ; i := i + 1 ) ; skip ; ) ; test := test + 1 ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MarinProblem { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testCase=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < testCase do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var count : int ; count := 0 ; var ch : Sequence(String) ; ch := sc.getCurrent()->characters() ; var j : int ; j := 0 ; while j < n - 1 do ( ( try ( if (ch[j+1] = '0' & ch[j + 1+1] = '0') then count := count+(2) ; else if (ch[j+1] = '0' & ch[j + 1+1] = '1' & ch[j + 2+1] = '0') then count := count+(1) ; else skip ; ) catch (e : ProgramException) do skip ) ; j := j + 1 ) ; OclFile["System.out"].println(count) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.Math ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); while(T>0){ int n=in.nextInt(); String s=in.next(); char arr[]=s.toCharArray(); int res=0 ; for(int i=0 ; iarr.length-1)len=arr.length-1 ; int j=i+1 ; int t=2 ; while(j<=len){ if(arr[j]=='0'){ res+=t ; break ; } j++; t--; } } } System.out.println(res); T--; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := in.getCurrent()->toInteger() ; while (T > 0) do ( var n : int ; n := in.getCurrent()->toInteger() ; var s : String ; s := in.getCurrent() ; var arr : Sequence(String) ; arr := s->characters() ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < arr->size() do ( ( if (arr[i+1] = '0') then ( var len : int ; len := i + 2 ; if (len > arr->size() - 1) then len := arr->size() - 1 ; else skip ; var j : int ; j := i + 1 ; var t : int ; t := 2 ; while (j <= len) do ( if (arr[j+1] = '0') then ( res := res+(t) ; break ) else skip ; j := j + 1 ; t := t - 1 ) ; ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; T := T - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int gcd(int a,int b){ if(a==0)return b ; return gcd(b % a,a); } static int sumcommDiv(int a,int b){ int n=gcd(a,b); int sum=0 ; for(int i=1 ; i<=Math.sqrt(n); i++){ if(n % i==0){ if(n/i==i)sum+=i ; else sum+=(n/i)+i ; } } return sum ; } public static void main(String[] args){ int a=10,b=15 ; System.out.println("Sum="+sumcommDiv(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation sumcommDiv( a : int, b : int) : int pre: true post: true activity: ( var n : int ; n := gcd(a, b) ; var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then ( if (n / i = i) then sum := sum+(i) ; else sum := sum+((n / i) + i) ; ) else skip ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 10 ; var b : int ; b := 15 ; OclFile["System.out"].println("Sum=" + sumcommDiv(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static int MinimumMoves(int a[],int n,int x){ int ans=0 ; for(int i=1 ; isize() ; OclFile["System.out"].println(MinimumMoves(arr, n, x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int x=sc.nextInt(); String s=sc.next(); boolean ok=true ; Setset=new HashSet<>(); for(char ch='A' ; ch<'A'+x ; ch++){ if(s.indexOf(ch)==-1){ ok=false ; break ; } } if(! ok)System.out.println(0); else { int[] freq=new int[x]; Arrays.fill(freq,0); for(int i=0 ; itoInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var ok : boolean ; ok := true ; var set : Set(String) ; set := Set{} ; var ch : String ; ch := 'A' ; while ch < 'A' + x do ( ( if (s->indexOf(ch)-1 = -1) then ( ok := false ; break ) else skip ) ; ch := ch + 1 ) ; if (not(ok)) then OclFile["System.out"].println(0) else ( var freq : Sequence(int) ; freq := Integer.subrange(1,x)->collect(0) ; freq := freq->collect(0) ; var i : int ; i := 0 ; while i < n do ( freq[s->at(i+1) - ('A')->char2byte()+1] := freq[s->at(i+1) - ('A')->char2byte()+1] + 1 ; ; i := i + 1 ) ; freq := freq->sort() ; OclFile["System.out"].println(freq[0+1] * x) ; ) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Demo { public static void main(String[] args){ int n,k ; Scanner in=new Scanner(System.in); n=in.nextInt(); k=in.nextInt(); String str=in.next(); char[] ch=str.toCharArray(); int[] a=new int[k]; char[] b=new char[k]; char al='A' ; for(int i=0 ; itoInteger() ; k := in.getCurrent()->toInteger() ; var str : String ; str := in.getCurrent() ; var ch : Sequence(String) ; ch := str->characters() ; var a : Sequence(int) ; a := Integer.subrange(1,k)->collect(0) ; var b : Sequence(String) ; b := Integer.subrange(1,k)->collect(0) ; var al : String ; al := 'A' ; var i : int ; i := 0 ; while i < k do ( ( a[i+1] := 0 ; b[i+1] := al ; al := al + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < k do ( ( if (ch[i+1] = b[j+1]) then ( a[j+1] := a[j+1] + 1 ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var min : int ; min := a[0+1] ; var i : int ; i := 0 ; while i < k do ( ( if (a[i+1] <= min) then min := a[i+1] ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min * k) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args){ try(Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out)){ int n=in.nextInt(); int[] v=new int[n]; Setset=new HashSet<>(); for(int i=0 ; itoInteger() ; var v : Sequence(int) ; v := Integer.subrange(1,n)->collect(0) ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( v[i+1] := in.getCurrent()->toInteger() ; set := set->including(v[i+1]) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( execute swap(v, (MathLib.random() * (i - 1))->oclAsType(int), i) ; ; i := i + 1 ) ; v := v->sort() ; var ans : int ; ans := 2 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var d : int ; d := v[j+1] - v[i+1] ; if (set->includes(v[i+1] - d)) then continue else skip ; var cnt : int ; cnt := 2 ; var cur : int ; cur := v[j+1] ; while (set->includes(cur + d)) do ( cur := cur+(d) ; cnt := cnt + 1 ) ; ans := Set{ans, cnt}->max() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; )) ); static operation swap( a : Sequence(int), x : int, y : int) : void pre: true post: true activity: ( var t : int ; t := a[x+1] ; a[x+1] := a[y+1] ; a[y+1] := t ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); int b=scanner.nextInt(); int c=scanner.nextInt(); int size=a*c ; int timestart ; if(size % b==0){ timestart=(size-b*c)/b ; } else { timestart=(size-b*c)/b+1 ; } System.out.print(timestart); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; var size : int ; size := a * c ; var timestart : int ; if (size mod b = 0) then ( timestart := (size - b * c) / b ) else ( timestart := (size - b * c) / b + 1 ) ; OclFile["System.out"].print(timestart) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Problem { public static void main(String[] args){ java.util.Scanner input=new java.util.Scanner(System.in); int a,b,c ; a=input.nextInt(); b=input.nextInt(); c=input.nextInt(); int time=(int)Math.ceil((a*c)/(double)b); System.out.println(time-c); } } ------------------------------------------------------------ OCL File: --------- class Problem { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : Scanner ; input := Scanner.newScanner(OclFile["System.in"]) ; var a : int ; var b : int ; var c : int ; a := input.nextInt() ; b := input.nextInt() ; c := input.nextInt() ; var time : int ; time := ((a * c) / b->oclAsType(double))->ceil()->oclAsType(int) ; OclFile["System.out"].println(time - c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class _195 { public static void main(String[] args){ final Scanner scn=new Scanner(System.in); final int a=scn.nextInt(); final int b=scn.nextInt(); final int c=scn.nextInt(); System.out.println(((a-b)*c+b-1)/b); scn.close(); } } ------------------------------------------------------------ OCL File: --------- class _195 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := scn.getCurrent()->toInteger() ; var b : int ; b := scn.getCurrent()->toInteger() ; var c : int ; c := scn.getCurrent()->toInteger() ; OclFile["System.out"].println(((a - b) * c + b - 1) / b) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Solution { public static int solve(int a,int b,int c){ int t=(a-b)*c ; if(t % b==0)return t/b ; else return t/b+1 ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); System.out.println(solve(a,b,c)); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation solve( a : int, b : int, c : int) : int pre: true post: true activity: ( var t : int ; t := (a - b) * c ; if (t mod b = 0) then return t / b else return t / b + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(solve(a, b, c)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static int mod=1000000007 ; public static void main(String[] args){ Scanner scan=new Scanner(System.in); int N=scan.nextInt(); int K=scan.nextInt(); scan.close(); long[] count=new long[K+1]; for(int j=K ; j>=1 ; j--){ count[j]=power((long)K/j,(long)N); int multi=2 ; while(j*multi<=K){ count[j]-=count[j*multi]; multi++; } } long sum=0 ; for(int j=1 ; j<=K ; j++){ sum+=j*count[j] % mod ; sum=sum % mod ; } System.out.println(sum); } public static long power(long x,long n){ long result=1 ; while(n>0){ if(n % 2==1){ result*=x ; result %=mod ; } x=x*x ; x %=mod ; n>>=1 ; } return result ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute mod : int := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scan.getCurrent()->toInteger() ; var K : int ; K := scan.getCurrent()->toInteger() ; skip ; var count : Sequence(long) ; count := Integer.subrange(1,K + 1)->collect(0) ; var j : int ; j := K ; while j >= 1 do ( ( count[j+1] := power(K->oclAsType(long) / j, N->oclAsType(long)) ; var multi : int ; multi := 2 ; while (j * multi <= K) do ( count[j+1] := count[j+1]-(count[j * multi+1]) ; multi := multi + 1 ) ) ; j := j - 1 ) ; var sum : long ; sum := 0 ; var j : int ; j := 1 ; while j <= K do ( ( sum := sum+(j * count[j+1] mod mod) ; sum := sum mod mod ) ; j := j + 1 ) ; OclFile["System.out"].println(sum) ; ); static operation power( x : long, n : long) : long pre: true post: true activity: ( var result : long ; result := 1 ; while (n > 0) do ( if (n mod 2 = 1) then ( result := result*(x) ; result := result mod mod ) else skip ; x := x * x ; x := x mod mod ; n := n/(2->pow(1)) ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int N=input.nextInt(); int K=input.nextInt(); long mod=(long)(1e9+7); long[] gcdPerNum=new long[K+1]; long answer=0 ; for(int curGCD=K ; curGCD>=1 ; curGCD--){ long base=K/curGCD ; gcdPerNum[curGCD]=FastExp(base,N,mod); for(int OVERCNT=2*curGCD ; OVERCNT<=K ; OVERCNT+=curGCD){ gcdPerNum[curGCD]-=gcdPerNum[OVERCNT]; gcdPerNum[curGCD] %=mod ; if(gcdPerNum[curGCD]<0)gcdPerNum[curGCD]+=mod ; } answer+=gcdPerNum[curGCD]*curGCD ; answer %=mod ; } System.out.println(answer); } public static long FastExp(long base,long exp,long mod){ String Binary=Binary(exp); long[] mods=new long[Binary.length()]; mods[0]=base % mod ; long FinalProduct=1 ; for(int i=1 ; iexp){ length=i ; break ; } } for(int i=length-1 ; i>=0 ; i--){ if(Math.pow(2,i)<=exp){ answer+="1" ; exp-=Math.pow(2,i); } else { answer+="0" ; } } return answer ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := input.getCurrent()->toInteger() ; var K : int ; K := input.getCurrent()->toInteger() ; var mod : long ; mod := (1e9 + 7)->oclAsType(long) ; var gcdPerNum : Sequence(long) ; gcdPerNum := Integer.subrange(1,K + 1)->collect(0) ; var answer : long ; answer := 0 ; var curGCD : int ; curGCD := K ; while curGCD >= 1 do ( ( var base : long ; base := K / curGCD ; gcdPerNum[curGCD+1] := FastExp(base, N, mod) ; var OVERCNT : int ; OVERCNT := 2 * curGCD ; while OVERCNT <= K do ( ( gcdPerNum[curGCD+1] := gcdPerNum[curGCD+1]-(gcdPerNum[OVERCNT+1]) ; gcdPerNum[curGCD+1] := gcdPerNum[curGCD+1] mod mod ; if (gcdPerNum[curGCD+1] < 0) then gcdPerNum[curGCD+1] := gcdPerNum[curGCD+1]+(mod) ; else skip ) ; OVERCNT := OVERCNT+(curGCD) ) ; answer := answer+(gcdPerNum[curGCD+1] * curGCD) ; answer := answer mod mod ; ) ; curGCD := curGCD - 1 ) ; OclFile["System.out"].println(answer) ; ); static operation FastExp( base : long, exp : long, mod : long) : long pre: true post: true activity: ( var Binary : String ; Binary := Binary(exp) ; var mods : Sequence(long) ; mods := Integer.subrange(1,Binary->size())->collect(0) ; mods[0+1] := base mod mod ; var FinalProduct : long ; FinalProduct := 1 ; var i : int ; i := 1 ; while i < mods->size() do ( ( mods[i+1] := ((mods[i - 1+1] mod mod) * (mods[i - 1+1] mod mod)) mod mod ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < Binary->size() do ( ( if (Binary->at(i+1) = '1') then ( FinalProduct := FinalProduct*(mods[Binary->size() - i - 1+1]) ; FinalProduct := FinalProduct mod mod ) else skip ) ; i := i + 1 ) ; return FinalProduct ); static operation Binary( exp : long) : String pre: true post: true activity: ( var answer : String ; answer := "" ; var length : int ; length := 0 ; var i : int ; i := 0 ; while true do ( ( if (2->pow(i) > exp) then ( length := i ; break ) else skip ) ; i := i + 1 ) ; var i : int ; i := (length)->char2byte() - 1 ; while i >= 0 do ( ( if (2->pow(i) <= exp) then ( answer := answer+("1") ; exp := exp-(2->pow(i)) ) else ( answer := answer+("0") ) ) ; i := i - 1 ) ; return answer ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=Integer.parseInt(scan.next()); int k=Integer.parseInt(scan.next()); scan.close(); int mod=1000000000+7 ; long[] d=new long[k+1]; for(int i=1 ; i<=k ; i++){ int count=k/i ; d[i]=modPow(count,n,mod); } for(int i=k ; i>0 ; i--){ int a=2 ; while(i*a<=k){ if(d[i]>=d[i*a]){ d[i]-=d[i*a]; } else { d[i]=d[i]+mod-d[i*a]; } a++; } } long ans=0 ; for(int i=1 ; i<=k ; i++){ ans+=i*d[i]; ans %=mod ; } System.out.println(ans); } private static long modPow(long a,long b,long mod){ if(b==0){ return 1 ; } if(b % 2==0){ return modPow((a*a)% mod,b/2,mod); } else { return modPow((a*a)% mod,b/2,mod)*a % mod ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (scan.getCurrent())->toInteger() ; var k : int ; k := (scan.getCurrent())->toInteger() ; skip ; var mod : int ; mod := 1000000000 + 7 ; var d : Sequence(long) ; d := Integer.subrange(1,k + 1)->collect(0) ; var i : int ; i := 1 ; while i <= k do ( ( var count : int ; count := k / i ; d[i+1] := modPow(count, n, mod) ) ; i := i + 1 ) ; var i : int ; i := k ; while i > 0 do ( ( var a : int ; a := 2 ; while (i * a <= k) do ( if (d[i+1] >= d[i * a+1]) then ( d[i+1] := d[i+1]-(d[i * a+1]) ) else ( d[i+1] := d[i+1] + mod - d[i * a+1] ) ; a := a + 1 ) ) ; i := i - 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i <= k do ( ( ans := ans+(i * d[i+1]) ; ans := ans mod mod ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation modPow( a : long, b : long, mod : long) : long pre: true post: true activity: ( if (b = 0) then ( return 1 ) else skip ; if (b mod 2 = 0) then ( return modPow((a * a) mod mod, b / 2, mod) ) else ( return modPow((a * a) mod mod, b / 2, mod) * a mod mod ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); int c=0 ; String sw="" ; for(int ii=0 ; ; ii++){ String line=br.readLine(); if(ii==0){ sw=line.toLowerCase(); continue ; } if(line.equals("END_OF_TEXT")|| line==null || line.length()==0){ break ; } String[] ss=line.split(" "); for(int jj=0 ; jjtoLowerCase() ; continue ) else skip ; if (line = "END_OF_TEXT" or line = null or line->size() = 0) then ( break ) else skip ; var ss : Sequence(String) ; ss := line->split(" ") ; var jj : int ; jj := 0 ; while jj < ss->size() do ( ( if (sw = ss[jj+1]->toLowerCase()) then ( c := c + 1 ) else skip ) ; jj := jj + 1 ) ; ) ; ii := ii + 1 ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Map.Entry ; class Main { static int mod=(int)(Math.pow(10,9)+7); static List>list=new ArrayList>(); static int a_dist[]; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); long[] mp=new long[K+5]; long ans=0 ; mp[0]=1 ; for(int i=2 ; i<=K ; i++){ mp[i-1]=i ; for(int j=1 ; (double)j<=Math.pow(i,0.5); j++){ if(i % j==0){ mp[i-1]=mp[i-1]-mp[j-1]; if(i/j>j && i/j0){ if((n-n/2*2)==1){ res=(res*a)% mod ; } a=(a*a)% mod ; n>>=1 ; } return res ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute mod : int := (10->pow(9) + 7)->oclAsType(int); static attribute list : Sequence(Sequence(int)) := Sequence{}; static attribute a_dist : Sequence(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var mp : Sequence(long) ; mp := Integer.subrange(1,K + 5)->collect(0) ; var ans : long ; ans := 0 ; mp[0+1] := 1 ; var i : int ; i := 2 ; while i <= K do ( ( mp[i - 1+1] := i ; var j : int ; j := 1 ; while j->oclAsType(double) <= i->pow(0.5) do ( ( if (i mod j = 0) then ( mp[i - 1+1] := mp[i - 1+1] - mp[j - 1+1] ; if (i / j > j & i / j < i) then ( mp[i - 1+1] := mp[i - 1+1] - mp[i / j - 1+1] ) else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= K do ( ( var tmp : long ; tmp := K / i ; ans := (ans + (mp[i - 1+1] * pow(tmp, N) mod mod) mod mod) mod mod ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation pow( a : long, n : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (n > 0) do ( if ((n - n / 2 * 2) = 1) then ( res := (res * a) mod mod ) else skip ; a := (a * a) mod mod ; n := n/(2->pow(1)) ) ; return res ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A1569 { static boolean flag ; static int finals ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int cases=sc.nextInt(); while(cases-->0){ flag=false ; int letters=sc.nextInt(); String ab=sc.next(); for(int i=1 ; itoInteger() ; while (cases > 0) do ( cases := cases - 1 ; skip ; ( flag := false ; var letters : int ; letters := sc.getCurrent()->toInteger() ; var ab : String ; ab := sc.getCurrent() ; var i : int ; i := 1 ; while i < letters do ( ( if (ab->at((i)->char2byte() - 1+1) /= ab->at(i+1)) then ( flag := true ; OclFile["System.out"].println((i) + " " + (i + 1)) ; break ) else skip ) ; i := i + 1 ) ; if (flag = false) then ( OclFile["System.out"].println("-1 " + "-1") ) else skip ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class contest2 { static long fib(long a,long b,long c){ if(c==0)return a ; else if(c==1)return b ; else if(c % 3==0)return a ; else if(c % 3==1)return b ; else return fib(a,b,c-1)^ fib(a,b,c-2); } public static void main(String[] args){ Scanner obj=new Scanner(System.in); int tc=obj.nextInt(); while(tc--!=0){ long a=obj.nextLong(); long b=obj.nextLong(); long c=obj.nextLong(); System.out.println(fib(a,b,c)); } } } ------------------------------------------------------------ OCL File: --------- class contest2 { static operation fib( a : long, b : long, c : long) : long pre: true post: true activity: ( if (c = 0) then return a else if (c = 1) then return b else if (c mod 3 = 0) then return a else if (c mod 3 = 1) then return b else return fib(a, b, c - 1) xor fib(a, b, c - 2) ; ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : OclFile ; obj := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tc : int ; tc := obj.getCurrent()->toInteger() ; while (tc /= 0) do ( skip ; ( var a : long ; a := obj.getCurrent()->toLong() ; var b : long ; b := obj.getCurrent()->toLong() ; var c : long ; c := obj.getCurrent()->toLong() ; OclFile["System.out"].println(fib(a, b, c)) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int divisorSum(int n){ int sum=0 ; for(int i=1 ; i<=n ; ++i)sum+=(n/i)*i ; return sum ; } public static void main(String args[]){ int n=4 ; System.out.println(divisorSum(n)); n=5 ; System.out.println(divisorSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation divisorSum( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( sum := sum+((n / i) * i) ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(divisorSum(n)) ; n := 5 ; OclFile["System.out"].println(divisorSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int[] count=new int[N]; for(int i=0 ; ians[i+1]; j--){ out[j]=i ; } } out[1]=N ; PrintWriter writer=new PrintWriter(System.out); for(int i=0 ; itoInteger() ; var count : Sequence(int) ; count := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( count[sc.getCurrent()->toInteger() - 1+1] := count[sc.getCurrent()->toInteger() - 1+1] + 1 ) ; i := i + 1 ) ; var hist : Sequence(int) ; hist := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( hist[count[i+1]+1] := hist[count[i+1]+1] + 1 ) ; i := i + 1 ) ; var used : Sequence(long) ; used := Integer.subrange(1,N + 1)->collect(0) ; var lack : int ; lack := 0 ; var i : int ; i := 1 ; while i <= N do ( ( lack := lack+(hist[i - 1+1]) ; used[i+1] := used[i - 1+1] + lack ) ; i := i + 1 ) ; var ans : Sequence(int) ; ans := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i <= N do ( ( ans[i+1] := N - ((used[i+1] + i - 1) / i)->oclAsType(int) ) ; i := i + 1 ) ; var out : Sequence(int) ; out := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i < N do ( ( var j : int ; j := ans[i+1] ; while j > ans[i + 1+1] do ( ( out[j+1] := i ) ; j := j - 1 ) ) ; i := i + 1 ) ; out[1+1] := N ; var writer : OclFile ; writer := OclFile.newOclFile_Write(OclFile["System.out"]) ; var i : int ; i := 0 ; while i < N do ( ( skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); Mapfreq=new HashMap<>(); int[] amts=new int[n+1]; for(int j=0 ; j0 ; m--){ while(k<=nTemp/m){ builder.append(m); builder.append('\n'); k++; } nTemp-=amts[m]; } while(k<=n){ builder.append("0\n"); k++; } System.out.print(builder); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var freq : Map(int,int) ; freq := Map{} ; var amts : Sequence(int) ; amts := Integer.subrange(1,n + 1)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( var k : int ; k := in.getCurrent()->toInteger() ; if (not(freq->keys()->includes(k))) then ( freq := freq->union(Map{k |-> 1}) ) else ( freq := freq->union(Map{k |-> freq->at(k) + 1}) ) ; amts[freq->at(k)+1] := amts[freq->at(k)+1] + 1 ) ; j := j + 1 ) ; var builder : String ; builder := StringLib.newString() ; var k : int ; k := 1 ; var nTemp : int ; nTemp := n ; var m : int ; m := n ; while m > 0 do ( ( while (k <= nTemp / m) do ( builder := builder + StringLib.newString(m) ; builder := builder + StringLib.newString(' ') ; k := k + 1 ) ; nTemp := nTemp-(amts[m+1]) ) ; m := m - 1 ) ; while (k <= n) do ( builder := builder + StringLib.newString("0\n") ; k := k + 1 ) ; OclFile["System.out"].print(builder) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main implements Runnable { private static int MOD=1_000_000_007 ; public static void main(String[] args){ Thread thread=new Thread(null,new Main(),"",32*1024*1024); thread.start(); } @ Override public void run(){ final Scanner scanner=new Scanner(System.in); solve(scanner); } static void solve(Scanner scanner){ int N=Integer.parseInt(scanner.next()); int A[]=new int[N]; for(int i=0 ; i1){ int mid=(l+r)>>>1 ; int index=lowerBound(A,0,A.length,mid); int sum=mid*(N-index)+S[index]; if(sum>=mid*k){ l=mid ; } else { r=mid ; } } System.out.println(l); } } static int lowerBound(int[] A,int fromInc,int toExc,int val){ int left=fromInc,right=toExc ; while(right-left>1){ int mid=(left+right)>>>1 ; if(A[mid]toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[(scanner.getCurrent())->toInteger() - 1+1] := A[(scanner.getCurrent())->toInteger() - 1+1] + 1 ) ; i := i + 1 ) ; A := A->sort() ; var S : Sequence(int) ; S := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( S[i + 1+1] := S[i+1] + A[i+1] ) ; i := i + 1 ) ; var k : int ; k := 1 ; while k <= N do ( ( var l : int ; l := 0 ; var r : int ; r := N / k + 1 ; while (r - l > 1) do ( var mid : int ; mid := ((l + r)/(2->pow(1)))->oclAsType(long) ; var index : int ; index := lowerBound(A, 0, A->size(), mid) ; var sum : int ; sum := mid * (N - index) + S[index+1] ; if (sum >= mid * k) then ( l := mid ) else ( r := mid ) ) ; OclFile["System.out"].println(l) ) ; k := k + 1 ) ; ); static operation lowerBound( A : Sequence(int), fromInc : int, toExc : int, val : int) : int pre: true post: true activity: ( var left : int ; left := fromInc ; var right : int ; right := toExc ; while (right - left > 1) do ( var mid : int ; mid := ((left + right)/(2->pow(1)))->oclAsType(long) ; if (A[mid+1] < val) then ( left := mid ) else ( right := mid ) ) ; if (A[left+1] < val) then ( return left + 1 ) else skip ; return left ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A[]=new int[300001]; for(int i=0 ; i=1 ; --i){ if(X[i+1]!=X[i]){ for(int j=X[i+1]+1 ; j<=X[i]; ++j){ res[j]=i ; } } } StringBuilder sb=new StringBuilder(); for(int k=1 ; k<=N ; ++k){ sb.append(res[k]); sb.append('\n'); } System.out.println(sb.toString()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,300001)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( var ai : int ; ai := sc.getCurrent()->toInteger() ; A[ai+1] := A[ai+1] + 1 ) ; i := i + 1 ) ; var freq : Sequence(int) ; freq := Integer.subrange(1,300001)->collect(0) ; for (a : A) do ( ( if (a = 0) then ( continue ) else skip ; freq[a+1] := freq[a+1] + 1 ) ) ; var C : Sequence(long) ; C := Integer.subrange(1,N + 1)->collect(0) ; var D : Sequence(long) ; D := Integer.subrange(1,N + 1)->collect(0) ; var f : int ; f := 1 ; while f <= N do ( ( C[f+1] := C[f - 1+1] + f * freq[f+1] ; D[f+1] := D[f - 1+1] + freq[f+1] ) ; f := f + 1 ) ; var X : Sequence(int) ; X := Integer.subrange(1,N + 1)->collect(0) ; var x : int ; x := 1 ; while x <= N do ( ( var f : long ; f := C[x+1] + x * (D[N+1] - D[x+1]) ; f := f / x ; X[x+1] := f->oclAsType(int) ) ; x := x + 1 ) ; var res : Sequence(int) ; res := Integer.subrange(1,N + 1)->collect(0) ; res[1+1] := N ; var i : int ; i := N - 1 ; while i >= 1 do ( ( if (X[i + 1+1] /= X[i+1]) then ( var j : int ; j := X[i + 1+1] + 1 ; while j <= X[i+1] do ( ( res[j+1] := i ) ; j := j + 1 ) ) else skip ) ; i := i - 1 ) ; var sb : String ; sb := StringLib.newString() ; var k : int ; k := 1 ; while k <= N do ( ( sb := sb + StringLib.newString(res[k+1]) ; sb := sb + StringLib.newString(' ') ) ; k := k + 1 ) ; OclFile["System.out"].println(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { void solve(){ Scanner sc=new Scanner(System.in); boolean[] timeTable=new boolean[24*60]; int h,m ; boolean isFirst ; for(int i=0 ; i<2 ; ++i){ int j ; j=sc.nextInt(); for(; j>0 ; --j){ h=sc.nextInt(); m=sc.nextInt(); timeTable[h*60+m]=true ; } } isFirst=true ; for(h=0 ; h<24 ; ++h){ for(m=0 ; m<60 ; ++m){ if(timeTable[h*60+m]){ if(! isFirst)System.out.print(" "); else isFirst=false ; System.out.format("%d:%02d",h,m); } } } System.out.println(); } public static void main(String[] args){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var timeTable : Sequence(boolean) ; timeTable := Integer.subrange(1,24 * 60)->collect(false) ; var h : int ; var m : int ; var isFirst : boolean ; var i : int ; i := 0 ; while i < 2 do ( ( var j : int ; j := sc.getCurrent()->toInteger() ; while j > 0 do ( ( h := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; timeTable[h * 60 + m+1] := true ) ; j := j - 1 ) ) ; i := i + 1 ) ; isFirst := true ; h := 0 ; while h < 24 do ( ( m := 0 ; while m < 60 do ( ( if (timeTable[h * 60 + m+1]) then ( if (not(isFirst)) then OclFile["System.out"].print(" ") else isFirst := false ; ; OclFile["System.out"].format("%d:%02d", h, m) ) else skip ) ; m := m + 1 ) ) ; h := h + 1 ) ; OclFile["System.out"].println() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); TreeSet

list=new LinkedList

(); for(; sc.hasNext(); ){ String[] s=sc.next().split(","); double x=Double.parseDouble(s[0]); double y=Double.parseDouble(s[1]); list.add(new P(x,y)); } int n=list.size(); P p0=list.getFirst(); double sum=0 ; for(int i=0 ; ipow(28)))->oclAsType(long); static attribute EPS : double := 1e-9; class P { attribute x : double; static operation newP( x : double, y : double) : P pre: true post: true activity: ( var self : P ; self := createP(); self.initialise(x, y); return self ); operation initialise( x : double, y : double) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation length( p : P) : double pre: true post: true activity: ( return sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)) ); } operation run() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var list : Sequence(P) ; list := Sequence{} ; while sc.hasNext() do ( ( var s : Sequence(String) ; s := sc.getCurrent()->split(",") ; var x : double ; x := (s[0+1])->toReal() ; var y : double ; y := (s[1+1])->toReal() ; list := list->including(P.newP(x, y)) ) ) ; var n : int ; n := list->size() ; var p0 : P ; p0 := list->first() ; var sum : double ; sum := 0 ; var i : int ; i := 0 ; while i < n - 2 do ( ( var p1 : P ; p1 := list->at(i + 1+1) ; var p2 : P ; p2 := list->at(i + 2+1) ; var a : double ; a := p0.length(p1) ; var b : double ; b := p1.length(p2) ; var c : double ; c := p2.length(p0) ; var z : double ; z := (a + b + c) / 2 ; var s : double ; s := sqrt(z * (z - a) * (z - b) * (z - c)) ; sum := sum+(s) ; ) ; i := i + 1 ) ; execute println(sum + "") ; skip ; ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int cntWays(String str,int n){ int x=n+1 ; int ways=x*x*(x*x-1)/12 ; return ways ; } public static void main(String[] args){ String str="ab" ; int n=str.length(); System.out.println(cntWays(str,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cntWays( str : String, n : int) : int pre: true post: true activity: ( var x : int ; x := n + 1 ; var ways : int ; ways := x * x * (x * x - 1) / 12 ; return ways ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "ab" ; var n : int ; n := str->size() ; OclFile["System.out"].println(cntWays(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int round(int n){ int a=(n/10)*10 ; int b=a+10 ; return(n-a>b-n)? b : a ; } public static void main(String[] args){ int n=4722 ; System.out.println(round(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation round( n : int) : int pre: true post: true activity: ( var a : int ; a := (n / 10) * 10 ; var b : int ; b := a + 10 ; return if (n - a > b - n) then b else a endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4722 ; OclFile["System.out"].println(round(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ (new Main()).solve(); } void solve(){ Scanner cin=new Scanner(System.in); int T=cin.nextInt(); for(int C=1 ; C<=T ; ++C){ int N=cin.nextInt(); int P=cin.nextInt(); int count[]=new int[P]; for(int i=0 ; i0){ count[1]-=three*2 ; } if(count[3]>0){ count[3]-=three*2 ; } } { if(count[1]>0 || count[2]>0 || count[3]>0){ ++ret ; } } } System.out.println("Case #"+C+": "+ret); } cin.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).solve() ); operation solve() : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := cin.getCurrent()->toInteger() ; var C : int ; C := 1 ; while C <= T do ( ( var N : int ; N := cin.getCurrent()->toInteger() ; var P : int ; P := cin.getCurrent()->toInteger() ; var count : Sequence(int) ; count := Integer.subrange(1,P)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( count[cin.getCurrent()->toInteger() mod P+1] := count[cin.getCurrent()->toInteger() mod P+1] + 1 ) ; i := i + 1 ) ; var ret : int ; ret := count[0+1] ; count[0+1] := 0 ; if (P = 2) then ( ret := ret+((count[1+1] + 1) / 2) ) else if (P = 3) then ( var min : int ; min := Set{count[1+1], count[2+1]}->min() ; ret := ret+(min) ; count[1+1] := count[1+1]-(min) ; count[2+1] := count[2+1]-(min) ; ret := ret+((count[1+1] + 2) / 3) ; ret := ret+((count[2+1] + 2) / 3) ; ) else if (P = 4) then ( ( var two : int ; two := Set{count[1+1], count[3+1]}->min() ; ret := ret+(two) ; count[1+1] := count[1+1]-(two) ; count[3+1] := count[3+1]-(two) ) ( var two : int ; two := count[2+1] / 2 ; ret := ret+(two) ; count[2+1] := count[2+1]-(two * 2) ) ( var three : int ; three := Set{count[2+1], Set{count[1+1] / 2, count[3+1] / 2}->max()}->min() ; ret := ret+(three) ; count[2+1] := count[2+1]-(three) ; if (count[1+1] > 0) then ( count[1+1] := count[1+1]-(three * 2) ) else skip ; if (count[3+1] > 0) then ( count[3+1] := count[3+1]-(three * 2) ) else skip ; ) ( if (count[1+1] > 0 or count[2+1] > 0 or count[3+1] > 0) then ( ret := ret + 1 ) else skip ) ) else skip ; ; ; OclFile["System.out"].println("Case #" + C + ": " + ret) ; ) ; C := C + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class MikeAndFeet_305B { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); StringTokenizer st=new StringTokenizer(br.readLine()); int[] nums=new int[n]; for(int i=0 ; istack=new Stack<>(); stack.push(-1); for(int i=0 ; i=nums[i]){ int j=stack.pop(); int len=i-stack.peek()-1 ; if(arr[len]0 ; i--){ if(arr[i]toInteger() ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( nums[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; execute helper(nums) ; ); static operation helper( nums : Sequence(int)) : void pre: true post: true activity: ( var n : int ; n := nums->size() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var stack : Sequence(int) ; stack := Sequence{} ; stack := stack->append(-1) ; var i : int ; i := 0 ; while i < n do ( ( while (stack->min() /= -1 & nums[stack->min()+1] >= nums[i+1]) do ( var j : int ; j := stack->last() ; var len : int ; len := i - stack->min() - 1 ; if (arr[len+1] < nums[j+1]) then arr[len+1] := nums[j+1] ; else skip ) ; stack := stack->append(i) ) ; i := i + 1 ) ; while (stack->min() /= -1) do ( var j : int ; j := stack->last() ; var len : int ; len := n - stack->min() - 1 ; if (arr[len+1] < nums[j+1]) then arr[len+1] := nums[j+1] ; else skip ) ; var i : int ; i := n - 1 ; while i > 0 do ( ( if (arr[i+1] < arr[i + 1+1]) then arr[i+1] := arr[i + 1+1] ; else skip ) ; i := i - 1 ) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 1 ; while i <= n do ( ( sb := sb + StringLib.newString(arr[i+1]) ; sb := sb + StringLib.newString(' ') ) ; i := i + 1 ) ; OclFile["System.out"].println(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void LeadingZeros(int x,int y){ if((x ^ y)<=(x & y))System.out.print("\nEqual"); else if((x &(~ y))>y)System.out.print(y); else System.out.print(x); } public static void main(String[] args){ int x=10,y=16 ; LeadingZeros(x,y); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation LeadingZeros( x : int, y : int) : void pre: true post: true activity: ( if ((x xor y) <= (x & y)) then OclFile["System.out"].print("\nEqual") ; else if ((x & (-(y + 1))) > y) then OclFile["System.out"].print(y) else OclFile["System.out"].print(x) ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 10 ; var y : int ; y := 16 ; execute LeadingZeros(x, y) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int makeOdd(int n){ if(n % 2!=0)return 1 ; int i ; for(i=2 ; i<=n ; i++)if((n % i==0)&&((n/i)% 2==1))break ; return i ; } public static void main(String[] args){ int n=36 ; int res=makeOdd(n); System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation makeOdd( n : int) : int pre: true post: true activity: ( if (n mod 2 /= 0) then return 1 else skip ; var i : int ; i := 2 ; while i <= n do ( if ((n mod i = 0) & ((n / i) mod 2 = 1)) then break else skip ; ; i := i + 1 ) ; return i ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 36 ; var res : int ; res := makeOdd(n) ; OclFile["System.out"].println(res) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); int[] H=new int[N]; for(int i=0 ; itoInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var H : Sequence(int) ; H := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( H[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; H := H->sort() ; if (H->size() <= K) then ( OclFile["System.out"].println(0) ) else ( var i : int ; i := 0 ; while i < N - K do ( ( ans := ans+(H[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; import java.util.Collections ; public class Main { Scanner scan=new Scanner(System.in); int N ; ArrayListH=new ArrayList<>(); int K ; int min ; Main(){ N=scan.nextInt(); K=scan.nextInt(); for(int i=0 ; iH){ long sumhp=0 ; Collections.sort(H); for(int i=0 ; itoInteger() ; K := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < N do ( ( H := H->including(scan.getCurrent()->toInteger()) ) ; i := i + 1 ) ; OclFile["System.out"].println(minmize(N, K, H)) ); operation minmize( N : int, K : int, H : Sequence(int)) : long pre: true post: true activity: ( var sumhp : long ; sumhp := 0 ; H := H->sort() ; var i : int ; i := 0 ; while i < H->size() - K do ( ( sumhp := sumhp+(H->at(i+1)) ) ; i := i + 1 ) ; return sumhp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n,k,i=0 ; BigInteger s ; s=BigInteger.ZERO ; String[] strs=br.readLine().trim().split("\\s+"); n=Integer.parseInt(strs[0]); k=Integer.parseInt(strs[1]); int a[]=new int[n]; String[] strsa=br.readLine().trim().split("\\s+"); for(i=0 ; i=0)System.out.println("0"); else if((k-n)<0){ Arrays.sort(a); for(i=0 ; itrim()->split("\\s+") ; n := (strs[0+1])->toInteger() ; k := (strs[1+1])->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var strsa : Sequence(String) ; strsa := br.readLine()->trim()->split("\\s+") ; i := 0 ; while i < n do ( ( a[i+1] := (strsa[i+1])->toInteger() ) ; i := i + 1 ) ; if ((k - n) >= 0) then OclFile["System.out"].println("0") else if ((k - n) < 0) then ( a := a->sort() ; i := 0 ; while i < n - k do ( s := s->excludes((a[i+1] + "")->toLong()) ; ; i := i + 1 ) ; OclFile["System.out"].println(s) ) else skip ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long monster_kensu=sc.nextLong(); long kill_kaisu=sc.nextLong(); if(monster_kensu<=kill_kaisu){ System.out.println("0"); } else { Listmonster_list=new ArrayList<>(); for(int i=0 ; itoLong() ; var kill_kaisu : long ; kill_kaisu := sc.getCurrent()->toLong() ; if (monster_kensu <= kill_kaisu) then ( OclFile["System.out"].println("0") ) else ( var monster_list : Sequence(long) ; monster_list := Sequence{} ; var i : int ; i := 0 ; while i < monster_kensu do ( ( monster_list := monster_list->including(sc.getCurrent()->toLong()) ) ; i := i + 1 ) ; monster_list, reverseOrder() := monster_list, reverseOrder()->sort() ; var attack_sum : long ; attack_sum := 0 ; attack_sum := monster_list->collect( _x1 | (lambda _pars : OclAny in Long.newLong().longValue(_pars))->apply(_x1) ).subrange(kill_kaisu+1)->sum() ; OclFile["System.out"].println(attack_sum) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { private static boolean[] calcPrimeTable(int n){ boolean[] table=new boolean[n+1]; for(int i=2 ; i<=Math.sqrt(n); i++){ if(! table[i]){ for(int j=i+i ; j<=n ; j+=i){ table[j]=true ; } } } return table ; } private static void solve(){ boolean[] table=calcPrimeTable(1<<15); Scanner scanner=new Scanner(System.in); while(true){ int n=scanner.nextInt(); int counter=0 ; if(n==0){ break ; } for(int i=2 ; i<=n/2 ; i++){ if(! table[i] && ! table[n-i]){ counter++; } } System.out.println(counter); } } public static void main(String...args){ solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation calcPrimeTable( n : int) : Sequence(boolean) pre: true post: true activity: ( var table : Sequence(boolean) ; table := Integer.subrange(1,n + 1)->collect(false) ; var i : int ; i := 2 ; while i <= (n)->sqrt() do ( ( if (not(table[i+1])) then ( var j : int ; j := i + i ; while j <= n do ( ( table[j+1] := true ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; return table ); static operation solve() : void pre: true post: true activity: ( var table : Sequence(boolean) ; table := calcPrimeTable((1*(2->pow(15)))->oclAsType(long)) ; var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := scanner.getCurrent()->toInteger() ; var counter : int ; counter := 0 ; if (n = 0) then ( break ) else skip ; var i : int ; i := 2 ; while i <= n / 2 do ( ( if (not(table[i+1]) & not(table[n - i+1])) then ( counter := counter + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(counter) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { final static long MOD=1000000007 ; public static void main(String[] args)throws Exception { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String W=in.readLine(); String[] Ws=W.split(" "); int N=Integer.parseInt(Ws[0]); int K=Integer.parseInt(Ws[1]); W=in.readLine(); Ws=W.split(" "); long[] H=new long[Ws.length]; for(int i=0 ; i=0 ; i--){ sum+=H[i]; } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : long := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var W : String ; W := in.readLine() ; var Ws : Sequence(String) ; Ws := W->split(" ") ; var N : int ; N := (Ws[0+1])->toInteger() ; var K : int ; K := (Ws[1+1])->toInteger() ; W := in.readLine() ; Ws := W->split(" ") ; var H : Sequence(long) ; H := Integer.subrange(1,Ws->size())->collect(0) ; var i : int ; i := 0 ; while i < Ws->size() do ( ( H[i+1] := (Ws[i+1])->toLong() ) ; i := i + 1 ) ; H := H->sort() ; var sum : long ; sum := 0 ; var i : int ; i := N - 1 - K ; while i >= 0 do ( ( sum := sum+(H[i+1]) ) ; i := i - 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int minMoves(int n,int a[],int k){ int ct1[]=new int[k]; int ct0[]=new int[k]; int moves=0 ; for(int i=0 ; icollect(0) ; var ct0 : Sequence(int) ; ct0 := Integer.subrange(1,k)->collect(0) ; var moves : int ; moves := 0 ; var i : int ; i := 0 ; while i < n 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 ; ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( moves := moves+(Set{ct1[i+1], ct0[i+1]}->min()) ; ; i := i + 1 ) ; return moves ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 2 ; var a : Sequence(int) ; a := Sequence{1,0,0,0,1,0} ; var n : int ; n := a->size() ; OclFile["System.out"].println(minMoves(n, a, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static long mod=1000000007 ; static long inv2=500000004 ; static long modulo(String num){ long res=0 ; for(int i=0 ; isize() do ( res := (res * 10 + num->at(i+1)->oclAsType(long) - ('0')->char2byte()) mod mod ; ; i := i + 1 ) ; return res ); static operation findSum( L : String, R : String) : long pre: true post: true activity: ( var a : long ; var b : long ; var l : long ; var r : long ; var ret : long ; a := modulo(L) ; b := modulo(R) ; l := ((a * (a - 1)) mod mod * inv2) mod mod ; r := ((b * (b + 1)) mod mod * inv2) mod mod ; ret := (r mod mod - l mod mod) ; if (ret < 0) then ret := ret + mod else ret := ret mod mod ; ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : String ; L := "88949273204" ; var R : String ; R := "98429729474298592" ; OclFile["System.out"].println(findSum(L, R)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Arrays ; public class Main { public static void main(String[] args){ int n=nextInt(); int m=nextInt(); Treasure[] treasure=new Treasure[n]; for(int i=0 ; i=x1){ for(int k=i ; kx2){ i=n ; k=n ; } else if(y1<=treasure[k] .y && treasure[k] .y<=y2){ cnt++; } } break ; } } System.out.println(cnt); } } static int nextInt(){ int c ; try { c=System.in.read(); while(c!='-' &&(c<'0' || c>'9'))c=System.in.read(); if(c=='-')return-nextInt(); int res=0 ; while(c>='0' && c<='9'){ res=res*10+c-'0' ; c=System.in.read(); } return res ; } catch(IOException e){ e.printStackTrace(); } return-1 ; } } class Treasure implements Comparable{ int x=0 ; int y=0 ; public Treasure(int x,int y){ this.x=x ; this.y=y ; } public int compareTo(Treasure t1){ return this.x-t1.x ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := nextInt() ; var m : int ; m := nextInt() ; var treasure : Sequence(Treasure) ; treasure := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( treasure[i+1] := Treasure.newTreasure(nextInt(), nextInt()) ) ; i := i + 1 ) ; treasure := treasure->sort() ; var q : int ; q := 0 ; while q < m do ( ( var cnt : int ; cnt := 0 ; var x1 : int ; x1 := nextInt() ; var y1 : int ; y1 := nextInt() ; var x2 : int ; x2 := nextInt() ; var y2 : int ; y2 := nextInt() ; var i : int ; i := 0 ; while i < n do ( ( if (treasure[i+1].x >= x1) then ( var k : int ; k := i ; while k < n do ( ( if (treasure[k+1].x > x2) then ( i := n ; k := n ) else if (y1 <= treasure[k+1].y & treasure[k+1].y <= y2) then ( cnt := cnt + 1 ) else skip ; ) ; k := k + 1 ) ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ) ; q := q + 1 ) ; ); static operation nextInt() : int pre: true post: true activity: ( var c : int ; try ( c := OclFile["System.in"].read() ; while (c /= '-' & (c < '0' or c > '9')) do c := OclFile["System.in"].read() ; ; if (c = '-') then return -nextInt() else skip ; var res : int ; res := 0 ; while (c >= '0' & c <= '9') do ( res := res * 10 + c - ('0')->char2byte() ; c := OclFile["System.in"].read() ) ; return res ) catch (e : IOException) do ( e.printStackTrace() ) return -1 ); } class Treasure implements Comparable { attribute x : int := 0; attribute y : int := 0; static operation newTreasure( x : int, y : int) : Treasure pre: true post: true activity: ( var self : Treasure ; self := createTreasure(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation compareTo( t1 : Treasure) : int pre: true post: true activity: ( return self.x - t1.x ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int m=sc.nextInt(); int[][] map=new int[n][2]; for(int i=0 ; i(){ public int compare(int[] o1,int[] o2){ return o1[0]-o2[0]; } } ); int cnt,a,b,c,d ; for(int i=0 ; i=a){ for(int k=j ; kc){ j=n ; k=n ; } else if(b<=map[k][1] && map[k][1]<=d){ cnt++; } } break ; } } System.out.println(cnt); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var map : Sequence(Sequence(int)) ; map := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( map[i+1][0+1] := sc.getCurrent()->toInteger() ; map[i+1][1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; map := OclComparator.sortWith(map, OclComparator.newOclComparator()) ; var cnt : int ; var a : int ; var b : int ; var c : int ; var d : int ; var i : int ; i := 0 ; while i < m do ( ( cnt := 0 ; a := sc.getCurrent()->toInteger() ; b := sc.getCurrent()->toInteger() ; c := sc.getCurrent()->toInteger() ; d := sc.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < n do ( ( if (map[j+1][0+1] >= a) then ( var k : int ; k := j ; while k < n do ( ( if (map[k+1][0+1] > c) then ( j := n ; k := n ) else if (b <= map[k+1][1+1] & map[k+1][1+1] <= d) then ( cnt := cnt + 1 ) else skip ; ) ; k := k + 1 ) ; break ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println(cnt) ; ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Arrays ; public class Main { public static void main(String[] args){ int n=nextInt(); int m=nextInt(); Treasure[] treasure=new Treasure[n]; for(int i=0 ; ix2){ break ; } if(treasure[k] .y>=y1 && treasure[k] .y<=y2){ count++; } } break ; } System.out.println(count); } } static int nextInt(){ int c ; try { c=System.in.read(); while(c!='-' &&(c<'0' || c>'9'))c=System.in.read(); if(c=='-')return-nextInt(); int res=0 ; while(c>='0' && c<='9'){ res=res*10+c-'0' ; c=System.in.read(); } return res ; } catch(IOException e){ e.printStackTrace(); } return-1 ; } } class Treasure implements Comparable{ int x=0 ; int y=0 ; public Treasure(int x,int y){ this.x=x ; this.y=y ; } public int compareTo(Treasure t1){ return this.x-t1.x ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := nextInt() ; var m : int ; m := nextInt() ; var treasure : Sequence(Treasure) ; treasure := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( treasure[i+1] := Treasure.newTreasure(nextInt(), nextInt()) ) ; i := i + 1 ) ; treasure := treasure->sort() ; var q : int ; q := 0 ; while q < m do ( ( var count : int ; count := 0 ; var x1 : int ; x1 := nextInt() ; var y1 : int ; y1 := nextInt() ; var x2 : int ; x2 := nextInt() ; var y2 : int ; y2 := nextInt() ; var i : int ; i := 0 ; while i < treasure->size() do ( ( if (treasure[i+1].x < x1) then ( continue ) else skip ; var k : int ; k := i ; while k < treasure->size() do ( ( if (treasure[k+1].x > x2) then ( break ) else skip ; if (treasure[k+1].y >= y1 & treasure[k+1].y <= y2) then ( count := count + 1 ) else skip ) ; k := k + 1 ) ; break ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) ; q := q + 1 ) ; ); static operation nextInt() : int pre: true post: true activity: ( var c : int ; try ( c := OclFile["System.in"].read() ; while (c /= '-' & (c < '0' or c > '9')) do c := OclFile["System.in"].read() ; ; if (c = '-') then return -nextInt() else skip ; var res : int ; res := 0 ; while (c >= '0' & c <= '9') do ( res := res * 10 + c - ('0')->char2byte() ; c := OclFile["System.in"].read() ) ; return res ) catch (e : IOException) do ( e.printStackTrace() ) return -1 ); } class Treasure implements Comparable { attribute x : int := 0; attribute y : int := 0; static operation newTreasure( x : int, y : int) : Treasure pre: true post: true activity: ( var self : Treasure ; self := createTreasure(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation compareTo( t1 : Treasure) : int pre: true post: true activity: ( return self.x - t1.x ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { public void bfs(int x,int num){ Queueq=new LinkedList(); q.add(num); while(! q.isEmpty()){ num=q.peek(); q.poll(); if(num<=x){ System.out.print(num+" "); int last_digit=num % 10 ; if(last_digit==0){ q.add((num*10)+(last_digit+1)); } else if(last_digit==9){ q.add((num*10)+(last_digit-1)); } else { q.add((num*10)+(last_digit-1)); q.add((num*10)+(last_digit+1)); } } } } public void printJumping(int x){ System.out.print("0 "); for(int i=1 ; i<=9 && i<=x ; i++){ this.bfs(x,i); } } public static void main(String[] args)throws IOException { int x=40 ; GFG obj=new GFG(); obj.printJumping(x); } } ------------------------------------------------------------ OCL File: --------- class GFG { operation bfs( x : int, num : int) : void pre: true post: true activity: ( var q : Sequence(int) ; q := Sequence{} ; q := q->including(num) ; while (not(q->isEmpty())) do ( num := q->min() ; q := q->sort()->tail() ; if (num <= x) then ( OclFile["System.out"].print(num + " ") ; var last_digit : int ; last_digit := num mod 10 ; if (last_digit = 0) then ( q := q->including((num * 10) + (last_digit + 1)) ) else if (last_digit = 9) then ( q := q->including((num * 10) + (last_digit - 1)) ) else ( q := q->including((num * 10) + (last_digit - 1)) ; q := q->including((num * 10) + (last_digit + 1)) ) ; ) else skip ) ); operation printJumping( x : int) : void pre: true post: true activity: ( OclFile["System.out"].print("0 ") ; var i : int ; i := 1 ; while i <= 9 & i <= x do ( ( self.bfs(x, i) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 40 ; var obj : GFG ; obj := GFG.newGFG() ; obj.printJumping(x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; boolean ok=true ; Setset=new HashSet<>(); for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var ok : boolean ; ok := true ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; set := set->including(arr[i+1]) ) ; i := i + 1 ) ; var chk : Sequence(int) ; chk := Integer.subrange(1,set->size())->collect(0) ; var i : int ; i := 0 ; for (x : set) do ( chk[i+1] := x ; i := i + 1 ; ) ; chk := chk->sort() ; var len : int ; len := chk->size() ; if (len = 1) then OclFile["System.out"].println(0) else if (len = 2) then ( if ((chk[1+1] - chk[0+1]) mod 2 = 0) then OclFile["System.out"].println((chk[1+1] - chk[0+1]) / 2) ; else OclFile["System.out"].println(chk[1+1] - chk[0+1]) ; ) else if (len = 3) then ( if ((chk[2+1] - chk[1+1]) = (chk[1+1] - chk[0+1])) then OclFile["System.out"].println(chk[2+1] - chk[1+1]) ; else OclFile["System.out"].println(-1) ; ) else OclFile["System.out"].println(-1) ; ; ; ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class dp1 { static int n,dp[]; static int a[]; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int i ; n=sc.nextInt(); a=new int[n]; for(i=0 ; iset=new HashSet<>(); for(i=0 ; i3){ System.out.println(-1); System.exit(0); } if(set.size()==1){ System.out.println(0); System.exit(0); } PriorityQueuepq=new PriorityQueue<>(); for(Integer p : set)pq.add(p); int p,q,r ; p=pq.poll(); q=pq.poll(); if(set.size()==2){ if((q-p)% 2==0)System.out.println((q-p)/2); else System.out.println(q-p); } else { r=pq.poll(); if((r+p)% 2==0 &&(r+p)/2==q)System.out.println(r-q); else System.out.println(-1); } } } ------------------------------------------------------------ OCL File: --------- class dp1 { static attribute n : int; static attribute a : Sequence(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var i : int ; n := sc.getCurrent()->toInteger() ; a := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var set : Set(int) ; set := Set{} ; i := 0 ; while i < n do ( set := set->including(a[i+1]) ; ; i := i + 1 ) ; if (set->size() > 3) then ( OclFile["System.out"].println(-1) ; OclProcess.exit(0) ) else skip ; if (set->size() = 1) then ( OclFile["System.out"].println(0) ; OclProcess.exit(0) ) else skip ; var pq : Sequence(int) ; pq := Sequence{} ; for (p : set) do ( pq := pq->including(p) ; ) ; var p : int ; var q : int ; var r : int ; p := pq->min() ; pq := pq->sort()->tail() ; q := pq->min() ; pq := pq->sort()->tail() ; if (set->size() = 2) then ( if ((q - p) mod 2 = 0) then OclFile["System.out"].println((q - p) / 2) ; else OclFile["System.out"].println(q - p) ; ) else ( r := pq->min() ; pq := pq->sort()->tail() ; if ((r + p) mod 2 = 0 & (r + p) / 2 = q) then OclFile["System.out"].println(r - q) ; else OclFile["System.out"].println(-1) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Run { public static void main(String[] Z)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder op=new StringBuilder(); StringTokenizer stz ; int n=Integer.parseInt(br.readLine()); stz=new StringTokenizer(br.readLine()); ArrayListarr=new ArrayList<>(n); for(int i=0 ; itoInteger() ; stz := OclIterator.newOclIterator_String(br.readLine()) ; var arr : Sequence(int) ; arr := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var num : int ; num := (stz.next())->toInteger() ; arr := arr->including(num) ) ; i := i + 1 ) ; arr := arr->sort() ; var first : int ; first := arr->at(0+1) ; var last : int ; last := arr->at(n - 1+1) ; var ans : int ; ans := -1 ; var val : int ; val := first ; while val <= last do ( ( var d : int ; d := if arr->at(0+1) - val < 0 then -(arr->at(0+1) - val) else arr->at(0+1) - val endif ; var can : boolean ; can := true ; for (curr : arr) do ( ( if (curr = val or curr + d = val or curr - d = val) then skip else ( can := false ; break ) ) ) ; if (can) then ( ans := d ; break ) else skip ) ; val := val + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class MakeThemEqual1154B { private static Scanner s=new Scanner(System.in); public static void main(String[] args){ int n=s.nextInt(); Setset=new TreeSet<>(); for(int i=0 ; ivalues=new ArrayList<>(set); if(values.size()==3 && Math.abs(values.get(0)-values.get(1))==Math.abs(values.get(2)-values.get(1))){ System.out.println(Math.abs(values.get(0)-values.get(1))); } else if(values.size()==2){ int diff=Math.abs(values.get(0)-values.get(1)); System.out.println(diff % 2==0 ? diff/2 : diff); } else if(values.size()==1){ System.out.println(0); } else { System.out.println(-1); } return ; } System.out.println(-1); } } ------------------------------------------------------------ OCL File: --------- class MakeThemEqual1154B { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := s.getCurrent()->toInteger() ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( set := set->including(s.getCurrent()->toInteger()) ) ; i := i + 1 ) ; if (set->size() <= 3) then ( var values : Sequence(int) ; values := Sequence{}->union(set) ; if (values->size() = 3 & if values->at(0+1) - values->at(1+1) < 0 then -(values->at(0+1) - values->at(1+1)) else values->at(0+1) - values->at(1+1) endif = if values->at(2+1) - values->at(1+1) < 0 then -(values->at(2+1) - values->at(1+1)) else values->at(2+1) - values->at(1+1) endif) then ( OclFile["System.out"].println(if values->at(0+1) - values->at(1+1) < 0 then -(values->at(0+1) - values->at(1+1)) else values->at(0+1) - values->at(1+1) endif) ) else if (values->size() = 2) then ( var diff : int ; diff := if values->at(0+1) - values->at(1+1) < 0 then -(values->at(0+1) - values->at(1+1)) else values->at(0+1) - values->at(1+1) endif ; OclFile["System.out"].println(if diff mod 2 = 0 then diff / 2 else diff endif) ) else if (values->size() = 1) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(-1) ) ; ; ; return ) else skip ; OclFile["System.out"].println(-1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ProblemB { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(br.readLine()); String line[]=br.readLine().split(" "); int arr[]=new int[n]; for(int i=0 ; iset=new TreeSet<>(); for(int i=0 ; ilist=new ArrayList<>(); for(int it : arr)list.add(it); Collections.sort(list); for(int i=0 ; itoInteger() ; var line : Sequence(String) ; line := br.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := (line[i+1])->toInteger() ; ; i := i + 1 ) ; var ans : int ; ans := 99999 ; var d : int ; d := 1 ; while d <= 1000 do ( ( var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = d) then continue else skip ; set := set->including(if d - arr[i+1] < 0 then -(d - arr[i+1]) else d - arr[i+1] endif) ) ; i := i + 1 ) ; if (set->size() = 0) then ans := 0 ; else skip ; if (set->size() = 1) then ans := Set{ans, set->first()}->min() ; else skip ) ; d := d + 1 ) ; OclFile["System.out"].println(if ans = 99999 then -1 else ans endif) ; ); static operation sort( arr : Sequence(int)) : void pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{} ; for (it : arr) do ( list := list->including(it) ; ) ; list := list->sort() ; var i : int ; i := 0 ; while i < arr->size() do ( arr[i+1] := list->at(i+1) ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void unsort(int l,int r,int a[],int k){ if(k<1 || l+1==r)return ; k-=2 ; int mid=(l+r)/2 ; int temp=a[mid-1]; a[mid-1]=a[mid]; a[mid]=temp ; unsort(l,mid,a,k); unsort(mid,r,a,k); } static void arrayWithKCalls(int n,int k){ if(k % 2==0){ System.out.print("NO SOLUTION"); return ; } int a[]=new int[n+1]; a[0]=1 ; for(int i=1 ; icollect(0) ; a[0+1] := 1 ; var i : int ; i := 1 ; while i < n do ( a[i+1] := i + 1 ; ; i := i + 1 ) ; k := k - 1 ; execute unsort(0, n, a, k) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(a[i+1] + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; var k : int ; k := 17 ; execute arrayWithKCalls(n, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int a=s.nextInt(),b=s.nextInt(),c=s.nextInt(); for(int i=1 ; i<=b ; i++){ if(a*10/b==c){ System.out.println(i); return ; } a=a*10 % b ; } System.out.println(-1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := s.getCurrent()->toInteger() ; var b : int ; b := s.getCurrent()->toInteger() ; var c : int ; c := s.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= b do ( ( if (a * 10 / b = c) then ( OclFile["System.out"].println(i) ; return ) else skip ; a := a * 10 mod b ) ; i := i + 1 ) ; OclFile["System.out"].println(-1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigDecimal ; import java.math.RoundingMode ; public class Main { public static void main(String[] args)throws IOException { StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); in.nextToken(); BigDecimal a=new BigDecimal(in.nval); in.nextToken(); BigDecimal b=new BigDecimal(in.nval); in.nextToken(); int c=(int)in.nval ; BigDecimal bigNum=a.divide(b,100005,RoundingMode.HALF_UP); String ans=bigNum.toString(); int index=ans.indexOf('.'); int flag=1 ; for(int i=index ; ioclAsType(int) ; var bigNum : double ; bigNum := a.divide(b, 100005, RoundingMode.HALF_UP) ; var ans : String ; ans := bigNum+"" ; var index : int ; index := ans->indexOf('.')-1 ; var flag : int ; flag := 1 ; var i : int ; i := index ; while i < ans->size() - 1 do ( ( var t : String ; t := ans->at(i+1) ; if (t = c + '0') then ( skip ; skip ; flag := 0 ; break ) else skip ) ; i := i + 1 ) ; if (flag = 1) then skip ; else skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner sca=new Scanner(System.in); BigDecimal res=BigDecimal.valueOf(1); BigDecimal a,b ; a=sca.nextBigDecimal(); b=sca.nextBigDecimal(); int n ; n=sca.nextInt(); res=a.divide(b,100005,RoundingMode.HALF_UP); String str ; str=res.toString(); int index=str.indexOf('.'); int flag=1 ; for(int i=index ; itoReal() ; var a : double ; var b : double ; a := sca.nextBigDecimal() ; b := sca.nextBigDecimal() ; var n : int ; n := sca.getCurrent()->toInteger() ; res := a.divide(b, 100005, RoundingMode.HALF_UP) ; var str : String ; str := res+"" ; var index : int ; index := str->indexOf('.')-1 ; var flag : int ; flag := 1 ; var i : int ; i := index ; while i < str->size() - 1 do ( ( var tmp : String ; tmp := str->at(i+1) ; if (tmp = (n + '0')) then ( OclFile["System.out"].println(i - 1) ; flag := 0 ; break ) else skip ) ; i := i + 1 ) ; if (flag = 1) then OclFile["System.out"].println(-1) ; else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int a=s.nextInt(),b=s.nextInt(),c=s.nextInt(); for(int i=1 ; i<=b ; i++){ if(a*10/b==c){ System.out.println(i); return ; } a=a*10 % b ; } System.out.println(-1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := s.getCurrent()->toInteger() ; var b : int ; b := s.getCurrent()->toInteger() ; var c : int ; c := s.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= b do ( ( if (a * 10 / b = c) then ( OclFile["System.out"].println(i) ; return ) else skip ; a := a * 10 mod b ) ; i := i + 1 ) ; OclFile["System.out"].println(-1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int num=sc.nextInt(); int tmp=num ; while(tmp % 2==0){ tmp/=2 ; } if(tmp==1){ System.out.println("No"); return ; } System.out.println("Yes"); int line=(int)(Math.floor((num+1)/4.0)*4)-1 ; StringBuilder ans=new StringBuilder(); for(int i=1 ; itoInteger() ; var tmp : int ; tmp := num ; while (tmp mod 2 = 0) do ( tmp := tmp/(2) ) ; if (tmp = 1) then ( OclFile["System.out"].println("No") ; return ) else skip ; OclFile["System.out"].println("Yes") ; var line : int ; line := (((num + 1) / 4.0)->floor() * 4)->oclAsType(int) - 1 ; var ans : String ; ans := StringLib.newString() ; var i : int ; i := 1 ; while i < line do ( ( ans := ans + StringLib.newString(i + " " + (i + 1) + "\n") ; ans := ans + StringLib.newString((num + i) + " " + (num + i + 1) + "\n") ) ; i := i + 1 ) ; ans := ans + StringLib.newString(line + " " + (num + 1) + "\n") ; var rest : int ; rest := num - line ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (rest) ; if _switchval = 0 then break else skip ; if _switchval = 1 then ans := ans + StringLib.newString((num / tmp + 1) + " " + (line + 1) + "\n") ; ans := ans + StringLib.newString((num - num / tmp) + " " + (num + line + 1) + "\n") ; break else skip ; if _switchval = 2 or _switchval = 3 then ans := ans + StringLib.newString((1) + " " + (line + 1) + "\n") ; ans := ans + StringLib.newString((line + 1) + " " + (line + 2) + "\n") ; ans := ans + StringLib.newString((num + 1) + " " + (num + line + 2) + "\n") ; ans := ans + StringLib.newString((num + line + 2) + " " + (num + line + 1) + "\n") ; if (rest = 3) then ( ans := ans + StringLib.newString((num + line + 2) + " " + (line + 3) + "\n") ; ans := ans + StringLib.newString((num + 2) + " " + (num + line + 3) + "\n") ) else skip ; break else skip ; ) OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; class Main { public static void main(String[] args){ new Main().run(); } void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); { for(long i=1 ; i<1L<<30 ; i*=2){ if(i==N){ System.out.println("No"); return ; } } } System.out.println("Yes"); int M=(N % 2==0 ? N-1 : N); for(int i=2 ; i<=M ; ++i){ System.out.println(1+" "+i); } for(int i=2 ; i<=M ; i+=2){ System.out.println((i+1)+" "+(i+N)); } for(int i=3 ; i<=M ; i+=2){ System.out.println((i-1)+" "+(i+N)); } System.out.println((2+N)+" "+(1+N)); if(M!=N){ for(int i=2 ; i<=M ; ++i){ if(2<=(1 ^ i ^ N)&&(1 ^ i ^ N)<=M &&(1 ^ i ^ N)!=i){ System.out.println(i+" "+N); System.out.println((1 ^ i ^ N)+" "+(N+N)); return ; } } } } void tr(Object...objects){ System.out.println(Arrays.deepToString(objects)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; ( var i : long ; i := 1 ; while i < (1L*(2->pow(30)))->oclAsType(long) do ( ( if (i = N) then ( OclFile["System.out"].println("No") ; return ) else skip ) ; i := i*(2) ) ) OclFile["System.out"].println("Yes") ; var M : int ; M := (if N mod 2 = 0 then N - 1 else N endif) ; var i : int ; i := 2 ; while i <= M do ( ( OclFile["System.out"].println(1 + " " + i) ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= M do ( ( OclFile["System.out"].println((i + 1) + " " + (i + N)) ) ; i := i+(2) ) ; var i : int ; i := 3 ; while i <= M do ( ( OclFile["System.out"].println((i - 1) + " " + (i + N)) ) ; i := i+(2) ) ; OclFile["System.out"].println((2 + N) + " " + (1 + N)) ; if (M /= N) then ( var i : int ; i := 2 ; while i <= M do ( ( if (2 <= (MathLib.bitwiseXor(MathLib.bitwiseXor(1,i),N)) & (MathLib.bitwiseXor(MathLib.bitwiseXor(1,i),N)) <= M & (MathLib.bitwiseXor(MathLib.bitwiseXor(1,i),N)) /= i) then ( OclFile["System.out"].println(i + " " + N) ; OclFile["System.out"].println((MathLib.bitwiseXor(MathLib.bitwiseXor(1,i),N)) + " " + (N + N)) ; return ) else skip ) ; i := i + 1 ) ) else skip ; ); operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); br.close(); int a=0 ; for(int i=0 ; i<19 ; i++){ a=1<3 && b % 2==1){ b+=n ; } System.out.println(n*2+" "+b); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; skip ; var a : int ; a := 0 ; var i : int ; i := 0 ; while i < 19 do ( ( a := (1*(2->pow(i)))->oclAsType(long) ; if (n = a) then ( OclFile["System.out"].println("No") ; return ) else skip ; if (n < a) then ( a := a/(2) ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Yes") ; OclFile["System.out"].println("1 2") ; OclFile["System.out"].println("2 3") ; OclFile["System.out"].println("3 " + (n + 1)) ; OclFile["System.out"].println((n + 1) + " " + (n + 2)) ; OclFile["System.out"].println((n + 2) + " " + (n + 3)) ; var m : int ; m := n ; if (m mod 2 = 0) then ( m := m - 1 ) else skip ; var i : int ; i := 4 ; while i < m do ( ( OclFile["System.out"].println((n + 1) + " " + i) ; OclFile["System.out"].println(i + " " + (i + 1)) ; OclFile["System.out"].println((n + 1) + " " + (n + i + 1)) ; OclFile["System.out"].println((n + i + 1) + " " + (n + i)) ) ; i := i+(2) ) ; if (m /= n) then ( OclFile["System.out"].println(n + " " + a) ; var b : int ; b := n - a + 1 ; if (b > 3 & b mod 2 = 1) then ( b := b+(n) ) else skip ; OclFile["System.out"].println(n * 2 + " " + b) ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Integer.parseInt ; import static java.lang.Long.parseLong ; import static java.lang.System.exit ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { static void solve()throws Exception { int n=scanInt(); if((n &-n)==n){ out.print("No"); return ; } out.println("Yes"); int m=n+(n & 1)-1 ; for(int i=2 ; i<=m ; i++){ out.println("1 "+i); out.println(i+" "+(n+(i ^ 1))); } out.println((n+1)+" "+(n+3)); if(n!=m){ int x=Integer.lowestOneBit(n)+1,y=n-x+1 ; out.println(n+" "+x); out.println((2*n)+" "+y); } } static int scanInt()throws IOException { return parseInt(scanString()); } static long scanLong()throws IOException { return parseLong(scanString()); } static String scanString()throws IOException { while(tok==null || ! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; public static void main(String[] args){ try { in=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); solve(); in.close(); out.close(); } catch(Throwable e){ e.printStackTrace(); exit(1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve() : void pre: true post: true activity: ( var n : int ; n := scanInt() ; if ((MathLib.bitwiseAnd(n,-n)) = n) then ( out.print("No") ; return ) else skip ; out.println("Yes") ; var m : int ; m := n + (MathLib.bitwiseAnd(n,1)) - 1 ; var i : int ; i := 2 ; while i <= m do ( ( out.println("1 " + i) ; out.println(i + " " + (n + (MathLib.bitwiseXor(i,1)))) ) ; i := i + 1 ) ; out.println((n + 1) + " " + (n + 3)) ; if (n /= m) then ( var x : int ; x := lowestOneBit(n) + 1 ; var y : int ; y := n - x + 1 ; out.println(n + " " + x) ; out.println((2 * n) + " " + y) ) else skip ; ); static operation scanInt() : int pre: true post: true activity: ( return (scanString() + "")->toInteger() ); static operation scanLong() : long pre: true post: true activity: ( return parseLong(scanString()) ); static operation scanString() : String pre: true post: true activity: ( while (tok = null or not(tok.hasNext())) do ( tok := OclIterator.newOclIterator_String(in.readLine()) ) ; return tok.next() ); static attribute in : OclFile; static attribute out : OclFile; static attribute tok : OclIterator; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; skip ; skip ; ) catch (e : OclException) do ( e.printStackTrace() ; execute exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isNonHypotenuse(int n){ while(n % 2==0){ n=n/2 ; } for(int i=3 ; i<=Math.sqrt(n); i=i+2){ if(n % i==0){ if((i-1)% 4==0)return false ; while(n % i==0){ n=n/i ; } } } if(n>2 &&(n-1)% 4==0)return false ; else return true ; } public static void test(int n){ System.out.println("Testing for "+n+" : "); if(isNonHypotenuse(n))System.out.println("YES"); else System.out.println("NO"); } public static void main(String args[]){ int n=11 ; test(n); n=10 ; test(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isNonHypotenuse( n : int) : boolean pre: true post: true activity: ( while (n mod 2 = 0) do ( n := n / 2 ) ; var i : int ; i := 3 ; while i <= (n)->sqrt() 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 / i ) ) else skip ) ; i := i + 2 ) ; if (n > 2 & (n - 1) mod 4 = 0) then return false else return true ); static operation test( n : int) : void pre: true post: true activity: ( OclFile["System.out"].println("Testing for " + n + " : ") ; if (isNonHypotenuse(n)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 11 ; execute test(n) ; n := 10 ; execute test(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static Listp=Prime(32768); public static int s=p.size(); public static ListPrime(int n){ Listprimes=new ArrayList(); primes.add(2); for(int i=3 ; i<=n ; i++){ int tmp=(int)(Math.sqrt(i))+1 ; for(int j=2 ; j<=tmp ; j++){ if(i % j==0){ break ; } if(j==tmp){ primes.add(i); } } } return primes ; } public static int check(int n){ int count=0 ; for(int i=0 ; i=i ; j--){ if((p.get(i)+p.get(j))==n){ count++; } } } return count ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int num ; while(true){ num=sc.nextInt(); if(num!=0){ System.out.println(check(num)); } else { break ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute p : Sequence(int) := Prime(32768); static attribute s : int := p->size(); static operation Prime( n : int) : Sequence(int) pre: true post: true activity: ( var primes : Sequence(int) ; primes := Sequence{} ; primes := primes->including(2) ; var i : int ; i := 3 ; while i <= n do ( ( var tmp : int ; tmp := ((i)->sqrt())->oclAsType(int) + 1 ; var j : int ; j := 2 ; while j <= tmp do ( ( if (i mod j = 0) then ( break ) else skip ; if (j = tmp) then ( primes := primes->including(i) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return primes ); static operation check( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 0 ; while i < s do ( ( var j : int ; j := s - 1 ; while j >= i do ( ( if ((p->at(i+1) + p->at(j+1)) = n) then ( count := count + 1 ) else skip ) ; j := j - 1 ) ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : int ; while (true) do ( num := sc.getCurrent()->toInteger() ; if (num /= 0) then ( OclFile["System.out"].println(check(num)) ) else ( break ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); Integer[] d=new Integer[n]; for(int i=0 ; itoInteger() ; var d : Sequence(int) ; d := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( d[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; d := OclComparator.sortWith(d, reverseOrder()) ; var prev : int ; prev := d[0+1] ; var cnt : int ; cnt := 1 ; var i : int ; i := 1 ; while i < n do ( ( if (prev /= d[i+1]) then ( cnt := cnt + 1 ; prev := d[i+1] ) else ( continue ) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static long[] buildValues(int d){ long[] res=new long[d/2]; long high=(long)Math.pow(10,d-1); long low=1L ; for(int i=0 ; i0){ s+=x % 10+"" ; x/=10 ; } return Integer.valueOf(s); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation buildValues( d : int) : Sequence(long) pre: true post: true activity: ( var res : Sequence(long) ; res := Integer.subrange(1,d / 2)->collect(0) ; var high : long ; high := 10->pow(d - 1)->oclAsType(long) ; var low : long ; low := 1L ; var i : int ; i := 0 ; while i < d / 2 do ( ( res[i+1] := high - low ; high := high/(10) ; low := low*(10) ) ; i := i + 1 ) ; return res ); static operation calc( vs : Sequence(long), D : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; var ten : long ; ten := 10 ; var i : int ; i := 0 ; while i < vs->size() do ( ( var now : long ; now := 0 ; while (D mod ten /= 0 & now < 9) do ( D := D-(vs[i+1]) ; now := now + 1 ) ; D := if D < 0 then -(D) else D endif ; ten := ten*(10) ; res := res*(if (i = 0) then (9 - now) else (10 - now) endif) ; ) ; i := i + 1 ) ; return if D = 0 then res else 0 endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var D : int ; D := in.getCurrent()->toInteger() ; var res : long ; res := 0 ; var d : int ; d := 1 ; while d <= 20 do ( ( var vs : Sequence(long) ; vs := buildValues(d) ; var next : long ; next := calc(vs, D) ; if (d mod 2 = 1) then next := next*(10) ; else skip ; res := res+(next) ) ; d := d + 1 ) ; OclFile["System.out"].println(res) ; ); static operation rev( x : int) : int pre: true post: true activity: ( var s : String ; s := "0" ; while (x > 0) do ( s := s+(x mod 10 + "") ; x := x/(10) ) ; return (s)->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); int a=stdIn.nextInt(),b=stdIn.nextInt(); System.out.print((a+b+1)/2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := stdIn.getCurrent()->toInteger() ; var b : int ; b := stdIn.getCurrent()->toInteger() ; OclFile["System.out"].print((a + b + 1) / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int a=Integer.parseInt(sc.next()); int b=Integer.parseInt(sc.next()); double x=((double)a+(double)b)/2 ; int ans=(int)Math.ceil(x); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := (sc.getCurrent())->toInteger() ; var b : int ; b := (sc.getCurrent())->toInteger() ; var x : double ; x := (a->oclAsType(double) + b->oclAsType(double)) / 2 ; var ans : int ; ans := (x)->ceil()->oclAsType(int) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { public static void main(String[] args){ int i,j ; Scanner sc=new Scanner(in); int a=parseInt(sc.next()); int b=parseInt(sc.next()); sc.close(); out.println((int)ceil((double)(a+b)/2)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var j : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var a : int ; a := parseInt(sc.getCurrent()) ; var b : int ; b := parseInt(sc.getCurrent()) ; skip ; out.println(ceil((a + b)->oclAsType(double) / 2)->oclAsType(int)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); double a,b ; a=Double.parseDouble(sc.next()); b=Double.parseDouble(sc.next()); int ans=(int)Math.ceil((a+b)/2); System.out.println(ans); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : double ; var b : double ; a := (sc.getCurrent())->toReal() ; b := (sc.getCurrent())->toReal() ; var ans : int ; ans := ((a + b) / 2)->ceil()->oclAsType(int) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ start(); } public static void start(){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(),b=sc.nextInt(); System.out.println((int)Math.ceil((a+b)/2.0)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute start() ); static operation start() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(((a + b) / 2.0)->ceil()->oclAsType(int)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class codeHundredSixtyTwo { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int[] arrayOne=new int[n]; int egg=0 ; for(int i=0 ; iegg){ return k ; } else { return Typo(k+1,egg,n,arrayOne); } } } ------------------------------------------------------------ OCL File: --------- class codeHundredSixtyTwo { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var arrayOne : Sequence(int) ; arrayOne := Integer.subrange(1,n)->collect(0) ; var egg : int ; egg := 0 ; var i : int ; i := 0 ; while i < n do ( ( arrayOne[i+1] := input.getCurrent()->toInteger() ; egg := egg+(arrayOne[i+1]) ) ; i := i + 1 ) ; arrayOne := arrayOne->sort() ; var k : int ; k := arrayOne[n - 1+1] ; OclFile["System.out"].println(Typo(k, egg, n, arrayOne)) ; ); static operation Typo( k : int, egg : int, n : int, arrayOne : Sequence(int)) : int pre: true post: true activity: ( var sum1 : int ; sum1 := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum1 := sum1+(k - arrayOne[i+1]) ) ; i := i + 1 ) ; if (sum1 > egg) then ( return k ) else ( return Typo(k + 1, egg, n, arrayOne) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static Scanner input=new Scanner(System.in); public static void main(String[] args){ int n=input.nextInt(); int a[]=new int[n]; array(a); Arrays.sort(a); int sum=arraySum(a); int test ; if(sum % n==0)test=sum/n ; else test=(sum+n-1)/n ; int result=test+a[0]; if(result>a[a.length-1]){ while(true){ int sum1=0 ; for(int i=0 ; i=sum)break ; else result++; } } else { result=a[a.length-1]; while(true){ int sum1=0 ; for(int i=0 ; i=sum)break ; else result++; } } System.out.println(result); } public static void array(int a[]){ for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; execute array(a) ; a := a->sort() ; var sum : int ; sum := arraySum(a) ; var test : int ; if (sum mod n = 0) then test := sum / n else test := (sum + n - 1) / n ; ; var result : int ; result := test + a[0+1] ; if (result > a[a->size() - 1+1]) then ( while (true) do ( var sum1 : int ; sum1 := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( sum1 := sum1 + (result - a[i+1]) ) ; i := i + 1 ) ; if (sum1 >= sum) then break else result := result + 1 ; ) ) else ( result := a[a->size() - 1+1] ; while (true) do ( var sum1 : int ; sum1 := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( sum1 := sum1 + (result - a[i+1]) ) ; i := i + 1 ) ; if (sum1 >= sum) then break else result := result + 1 ; ) ) ; OclFile["System.out"].println(result) ; ); static operation array( a : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := input.getCurrent()->toInteger() ) ; i := i + 1 ) ); static operation arraySum( a : Sequence(int)) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < a->size() do ( ( sum := sum + a[i+1] ) ; i := i + 1 ) ; return sum + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { static final int MAX_N=100100 ; static final int mod=1000000007 ; static final int INF=0x3f3f3f3f ; public static void main(String[] args)throws Exception { initReader(System.in); solve(); printWriter.flush(); } public static void solve()throws IOException { int a=nextInt()/1 ; int b=nextInt()/2 ; int c=nextInt()/4 ; printWriter.println(7*Math.min(a,Math.min(b,c))); } static BufferedReader reader ; static StringTokenizer tokenizer ; static PrintWriter printWriter ; static void initReader(InputStream input){ reader=new BufferedReader(new InputStreamReader(input)); tokenizer=new StringTokenizer(""); printWriter=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } static boolean hasNext(){ try { while(! tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } } catch(Exception e){ return false ; } return true ; } static String next()throws IOException { while(! tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static String nextLine(){ try { return reader.readLine(); } catch(Exception e){ return null ; } } static int nextInt()throws IOException { return Integer.parseInt(next()); } static long nextLong()throws IOException { return Long.parseLong(next()); } static double nextDouble()throws IOException { return Double.parseDouble(next()); } static char nextChar()throws IOException { return next().charAt(0); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MAX_N : int := 100100; static attribute mod : int := 1000000007; static attribute INF : int := 0x3f3f3f3f; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute initReader(OclFile["System.in"]) ; execute solve() ; printWriter.flush() ); static operation solve() : void pre: true post: true activity: ( var a : int ; a := nextInt() / 1 ; var b : int ; b := nextInt() / 2 ; var c : int ; c := nextInt() / 4 ; printWriter.println(7 * Set{a, Set{b, c}->min()}->min()) ); static attribute reader : OclFile; static attribute tokenizer : OclIterator; static attribute printWriter : OclFile; static operation initReader( input : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(input)) ; tokenizer := OclIterator.newOclIterator_String("") ; printWriter := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ); static operation hasNext() : boolean pre: true post: true activity: ( try ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (e : ProgramException) do ( return false ) return true ); static operation next() : String pre: true post: true activity: ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ; return tokenizer.next() ); static operation nextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (e : ProgramException) do ( return null ) ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); static operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); static operation nextChar() : String pre: true post: true activity: ( return next()->at(0+1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { static final int MAX_N=100100 ; static final int mod=1000000007 ; static final int INF=0x3f3f3f3f ; public static void main(String[] args)throws Exception { initReader(System.in); solve(); printWriter.flush(); } public static void solve()throws IOException { int a=nextInt(); int b=nextInt(); int c=nextInt(); a/=1 ; b/=2 ; c/=4 ; printWriter.println(Math.min(a,Math.min(b,c))*7); } static BufferedReader reader ; static StringTokenizer tokenizer ; static PrintWriter printWriter ; static void initReader(InputStream input){ reader=new BufferedReader(new InputStreamReader(input)); tokenizer=new StringTokenizer(""); printWriter=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } static boolean hasNext(){ try { while(! tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } } catch(Exception e){ return false ; } return true ; } static String next()throws IOException { while(! tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static String nextLine(){ try { return reader.readLine(); } catch(Exception e){ return null ; } } static int nextInt()throws IOException { return Integer.parseInt(next()); } static long nextLong()throws IOException { return Long.parseLong(next()); } static double nextDouble()throws IOException { return Double.parseDouble(next()); } static char nextChar()throws IOException { return next().charAt(0); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MAX_N : int := 100100; static attribute mod : int := 1000000007; static attribute INF : int := 0x3f3f3f3f; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute initReader(OclFile["System.in"]) ; execute solve() ; printWriter.flush() ); static operation solve() : void pre: true post: true activity: ( var a : int ; a := nextInt() ; var b : int ; b := nextInt() ; var c : int ; c := nextInt() ; a := a/(1) ; b := b/(2) ; c := c/(4) ; printWriter.println(Set{a, Set{b, c}->min()}->min() * 7) ; ); static attribute reader : OclFile; static attribute tokenizer : OclIterator; static attribute printWriter : OclFile; static operation initReader( input : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(input)) ; tokenizer := OclIterator.newOclIterator_String("") ; printWriter := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ); static operation hasNext() : boolean pre: true post: true activity: ( try ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (e : ProgramException) do ( return false ) return true ); static operation next() : String pre: true post: true activity: ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ; return tokenizer.next() ); static operation nextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (e : ProgramException) do ( return null ) ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); static operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); static operation nextChar() : String pre: true post: true activity: ( return next()->at(0+1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _746A_Compote { public static void main(String[] args){ Scanner input=new Scanner(System.in); int lemon=input.nextInt(); int apple=input.nextInt()/2 ; int pears=input.nextInt()/4 ; int result=Math.min(Math.min(lemon,apple),pears); result*=7 ; System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class _746A_Compote { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var lemon : int ; lemon := input.getCurrent()->toInteger() ; var apple : int ; apple := input.getCurrent()->toInteger() / 2 ; var pears : int ; pears := input.getCurrent()->toInteger() / 4 ; var result : int ; result := Set{Set{lemon, apple}->min(), pears}->min() ; result := result*(7) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static double aver(int[] arr){ int sum=0 ; for(int i=0 ; i0){ sum=sum*x ; x=x-1 ; } return sum ; } public static int comb(int x,int y){ int sum=0 ; sum=fac(x); int temp=(fac(y)*fac(x-y)); return sum/temp ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n>0){ sc.nextInt(); sc.nextLine(); String[] f=sc.nextLine().split(""); String[] s=sc.nextLine().split(""); boolean flag=true ; for(int i=0 ; isize() do ( ( sum := sum + arr[i+1] ) ; i := i + 1 ) ; return sum / arr->size() ); static operation fac( x : int) : int pre: true post: true activity: ( var sum : int ; sum := 1 ; while (x > 0) do ( sum := sum * x ; x := x - 1 ) ; return sum ); static operation comb( x : int, y : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; sum := fac(x) ; var temp : int ; temp := (fac(y) * fac(x - y)) ; return sum / temp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; while (n > 0) do ( skip ; skip ; var f : Sequence(String) ; f := sc.nextLine()->split("") ; var s : Sequence(String) ; s := sc.nextLine()->split("") ; var flag : boolean ; flag := true ; var i : int ; i := 0 ; while i < f->size() do ( ( if (f[i+1] = "R") then ( if (s[i+1] = "B" or s[i+1] = "G") then flag := false ; else skip ) else skip ; if (s[i+1] = "R") then ( if (f[i+1] = "B" or f[i+1] = "G") then flag := false ; else skip ) else skip ) ; i := i + 1 ) ; if (flag) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; n := n - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ int total ; int sen=-1,gosen=-1,man=-1 ; boolean judge=false ; Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int Y=sc.nextInt(); for(int i=0 ; i<=N ; i++){ for(int j=0 ; i+j<=N ; j++){ total=i*1000+j*5000+(N-i-j)*10000 ; if(total==Y){ judge=true ; sen=i ; gosen=j ; man=N-i-j ; } if(judge)break ; } if(judge)break ; } System.out.println(man+" "+gosen+" "+sen); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var total : int ; var sen : int ; sen := -1 ; var gosen : int ; gosen := -1 ; var man : int ; man := -1 ; var judge : boolean ; judge := false ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var Y : int ; Y := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i <= N do ( ( var j : int ; j := 0 ; while i + j <= N do ( ( total := i * 1000 + j * 5000 + (N - i - j) * 10000 ; if (total = Y) then ( judge := true ; sen := i ; gosen := j ; man := N - i - j ) else skip ; if (judge) then break else skip ) ; j := j + 1 ) ; if (judge) then break else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(man + " " + gosen + " " + sen) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); Stackstack=new Stack<>(); for(int i=0 ; iset=new HashSet<>(); while(! stack.isEmpty()){ String ans=stack.pop(); if(set.contains(ans))continue ; else { pw.println(ans); } set.add(ans); } pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var stack : Sequence(String) ; stack := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := in.getCurrent() ; stack := stack->append(s) ) ; i := i + 1 ) ; var set : Set(String) ; set := Set{} ; while (not(stack->isEmpty())) do ( var ans : String ; ans := stack->last() ; if (set->includes(ans)) then continue else ( skip ) ; set := set->including(ans) ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ChatOrder { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); Stackstack=new Stack<>(); for(int i=0 ; iset=new HashSet<>(); while(! stack.isEmpty()){ String ans=stack.pop(); if(set.contains(ans))continue ; pw.println(ans); set.add(ans); } pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class ChatOrder { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var stack : Sequence(String) ; stack := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := in.getCurrent() ; stack := stack->append(s) ) ; i := i + 1 ) ; var set : Set(String) ; set := Set{} ; while (not(stack->isEmpty())) do ( var ans : String ; ans := stack->last() ; if (set->includes(ans)) then continue else skip ; skip ; set := set->including(ans) ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class SolutionD { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); String[] a=new String[n]; for(int i=0 ; iset=new HashSet<>(); for(int i=n-1 ; i>=0 ; --i){ if(set.add(a[i])){ System.out.println(a[i]); } } } } ------------------------------------------------------------ OCL File: --------- class SolutionD { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(String) ; a := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent() ) ; i := i + 1 ) ; var set : Set(String) ; set := Set{} ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (set->excludes(a[i+1])) then ( OclFile["System.out"].println(a[i+1]) ) else skip ) ; i := i - 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.System.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(in); int n=sc.nextInt(); String[] arr=new String[n]; Mapmap_arr=new HashMap<>(); for(int i=0 ; ireverseSortedMap=new LinkedHashMap<>(); map_arr.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).forEachOrdered(x->reverseSortedMap.put(x.getKey(),x.getValue())); for(Map.Entryentry : reverseSortedMap.entrySet()){ out.println(entry.getKey()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(String) ; arr := Integer.subrange(1,n)->collect(null) ; var map_arr : Map(String,int) ; map_arr := Map{} ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent() ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( map_arr := map_arr->union(Map{arr[j+1] |-> j}) ) ; j := j + 1 ) ; var reverseSortedMap : Map(String,int) ; reverseSortedMap := Map{} ; map_arr->asSet()->sort().forEachOrdered(lambda x : OclAny in reverseSortedMap->at(x.getKey())) ; for (entry : reverseSortedMap->asSet()) do ( ( out.println(entry.getKey()) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,InputReader in,PrintWriter out){ int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); int res=0 ; while(a % 2==0 && b % 2==0 && c % 2==0){ int a1=(b+c)/2 ; int b1=(a+c)/2 ; int c1=(a+b)/2 ; a=a1 ; b=b1 ; c=c1 ; ++res ; if(res>1000){ out.println(-1); return ; } } out.println(res); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskA ; solver := TaskA.newTaskA() ; solver.solve(1, in, out) ; skip ; ); static class TaskA { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var a : int ; a := in.nextInt() ; var b : int ; b := in.nextInt() ; var c : int ; c := in.nextInt() ; var res : int ; res := 0 ; while (a mod 2 = 0 & b mod 2 = 0 & c mod 2 = 0) do ( var a1 : int ; a1 := (b + c) / 2 ; var b1 : int ; b1 := (a + c) / 2 ; var c1 : int ; c1 := (a + b) / 2 ; a := a1 ; b := b1 ; c := c1 ; res := res + 1 ; if (res > 1000) then ( skip ; return ) else skip ; ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class Main { public static void main(String args[]){ try(Scanner in=new Scanner(System.in)){ int A=in.nextInt(); int B=in.nextInt(); int C=in.nextInt(); HashSetused=new HashSet<>(); used.add(new State(A,B,C)); int count=0 ; for(; ; count++){ if(A % 2==1 || B % 2==1 || C % 2==1){ System.out.println(count); break ; } int nextA=B/2+C/2 ; int nextB=A/2+C/2 ; int nextC=A/2+B/2 ; A=nextA ; B=nextB ; C=nextC ; boolean add=used.add(new State(A,B,C)); if(add==false){ System.out.println(-1); break ; } } } } } class State { int a ; int b ; int c ; public State(int a,int b,int c){ super(); this.a=a ; this.b=b ; this.c=c ; } @ Override public int hashCode(){ final int prime=31 ; int result=1 ; result=prime*result+a ; result=prime*result+b ; result=prime*result+c ; return result ; } @ Override public boolean equals(Object obj){ if(this==obj)return true ; if(obj==null)return false ; if(getClass()!=obj.getClass())return false ; State other=(State)obj ; if(a!=other.a)return false ; if(b!=other.b)return false ; if(c!=other.c)return false ; return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var A : int ; A := in.getCurrent()->toInteger() ; var B : int ; B := in.getCurrent()->toInteger() ; var C : int ; C := in.getCurrent()->toInteger() ; var used : Set(State) ; used := Set{} ; used := used->including(State.newState(A, B, C)) ; var count : int ; count := 0 ; while true do ( ( if (A mod 2 = 1 or B mod 2 = 1 or C mod 2 = 1) then ( OclFile["System.out"].println(count) ; break ) else skip ; var nextA : int ; nextA := B / 2 + C / 2 ; var nextB : int ; nextB := A / 2 + C / 2 ; var nextC : int ; nextC := A / 2 + B / 2 ; A := nextA ; B := nextB ; C := nextC ; var add : boolean ; add := used->excludes(State.newState(A, B, C)) ; if (add = false) then ( OclFile["System.out"].println(-1) ; break ) else skip ; ) ; count := count + 1 ) ; )) ); } class State { attribute a : int; attribute b : int; attribute c : int; static operation newState( a : int, b : int, c : int) : State pre: true post: true activity: ( var self : State ; self := createState(); self.initialise(a, b,c); return self ); operation initialise( a : int, b : int, c : int) : void pre: true post: true activity: ( execute super() ; self.a := a ; self.b := b ; self.c := c ); operation hashCode() : int pre: true post: true activity: ( var prime : int ; prime := 31 ; var result : int ; result := 1 ; result := prime * result + a ; result := prime * result + b ; result := prime * result + c ; return result ); operation equals( obj : OclAny) : boolean pre: true post: true activity: ( if (self = obj) then return true else skip ; if (obj = null) then return false else skip ; if (getClass() /= obj->oclType()) then return false else skip ; var other : State ; other := obj->oclAsType(State) ; if (a /= other.a) then return false else skip ; if (b /= other.b) then return false else skip ; if (c /= other.c) then return false else skip ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.List ; import java.util.ArrayList ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] ss0=br.readLine().trim().split(" ",0); long a=Long.parseLong(ss0[0]); long b=Long.parseLong(ss0[1]); long c=Long.parseLong(ss0[2]); if(isEnd(a,b,c)){ System.out.println(0); return ; } if((a==b)&&(b==c)){ System.out.println(-1); return ; } long x ; long y ; long z ; long count=0L ; do { x=(b+c)/2 ; y=(c+a)/2 ; z=(a+b)/2 ; count+=1 ; a=x ; b=y ; c=z ; } while(isEnd(x,y,z)==false); System.out.println(count); return ; } static void dp(String s){ System.out.println(s); } static void dp(StringBuilder s){ dp(s.toString()); } static void dp(int i){ dp(String.valueOf(i)); } static void dp(long i){ dp(String.valueOf(i)); } static boolean isEnd(long a,long b,long c){ if(a % 2==1){ return true ; } if(b % 2==1){ return true ; } if(c % 2==1){ return true ; } return false ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var ss0 : Sequence(String) ; ss0 := br.readLine()->trim()->split(" ") ; var a : long ; a := (ss0[0+1])->toLong() ; var b : long ; b := (ss0[1+1])->toLong() ; var c : long ; c := (ss0[2+1])->toLong() ; if (isEnd(a, b, c)) then ( OclFile["System.out"].println(0) ; return ) else skip ; if ((a = b) & (b = c)) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var x : long ; var y : long ; var z : long ; var count : long ; count := 0L ; while true do (( x := (b + c) / 2 ; y := (c + a) / 2 ; z := (a + b) / 2 ; count := count+(1) ; a := x ; b := y ; c := z ; ) ; if (isEnd(x, y, z) = false) then skip else break) ; OclFile["System.out"].println(count) ; return ); static operation dp( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation dp( s : String) : void pre: true post: true activity: ( execute dp(s+"") ); static operation dp( i : int) : void pre: true post: true activity: ( execute dp(((i) + "")) ); static operation dp( i : long) : void pre: true post: true activity: ( execute dp(((i) + "")) ); static operation isEnd( a : long, b : long, c : long) : boolean 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 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { private static boolean debug=false ; private static boolean elapsed=false ; private static PrintWriter _out=new PrintWriter(System.out); private static PrintWriter _err=new PrintWriter(System.err); private void solve(Scanner sc){ int A=sc.nextInt(); int B=sc.nextInt(); int C=sc.nextInt(); if(A % 2==1 || B % 2==1 || C % 2==1){ _out.println(0); return ; } if(A==B && B==C){ _out.println(-1); return ; } long cnt=0 ; while(A % 2==0 && B % 2==0 && C % 2==0){ int ta=B/2+C/2 ; int tb=A/2+C/2 ; int tc=A/2+B/2 ; A=ta ; B=tb ; C=tc ; ++cnt ; } _out.println(cnt); } private static BigInteger C(long n,long r){ BigInteger res=BigInteger.ONE ; for(long i=n ; i>n-r ; --i){ res=res.multiply(BigInteger.valueOf(i)); } for(long i=r ; i>1 ; --i){ res=res.divide(BigInteger.valueOf(i)); } return res ; } private static BigInteger P(long n,long r){ BigInteger res=BigInteger.ONE ; for(long i=n ; i>n-r ; --i){ res=res.multiply(BigInteger.valueOf(i)); } return res ; } public static void main(String[] args){ long S=System.currentTimeMillis(); Scanner sc=new Scanner(System.in); new Main().solve(sc); _out.flush(); long G=System.currentTimeMillis(); if(elapsed){ _err.println((G-S)+"ms"); } _err.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute debug : boolean := false; static attribute elapsed : boolean := false; static attribute _out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static attribute _err : OclFile := OclFile.newOclFile_Write(OclFile["System.err"]); operation solve( sc : OclFile) : void pre: true post: true activity: ( var A : int ; A := sc.nextInt() ; var B : int ; B := sc.nextInt() ; var C : int ; C := sc.nextInt() ; if (A mod 2 = 1 or B mod 2 = 1 or C mod 2 = 1) then ( skip ; return ) else skip ; if (A = B & B = C) then ( skip ; return ) else skip ; var cnt : long ; cnt := 0 ; while (A mod 2 = 0 & B mod 2 = 0 & C mod 2 = 0) do ( var ta : int ; ta := B / 2 + C / 2 ; var tb : int ; tb := A / 2 + C / 2 ; var tc : int ; tc := A / 2 + B / 2 ; A := ta ; B := tb ; C := tc ; cnt := cnt + 1 ; ) ; skip ; ); static operation C( n : long, r : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; var i : long ; i := n ; while i > n - r do ( ( res := res.multiply((i + "")->toLong()) ) ; i := i - 1 ) ; var i : long ; i := r ; while i > 1 do ( ( res := res.divide((i + "")->toLong()) ) ; i := i - 1 ) ; return res ); static operation P( n : long, r : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; var i : long ; i := n ; while i > n - r do ( ( res := res.multiply((i + "")->toLong()) ) ; i := i - 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : long ; S := OclDate.getSystemTime() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; Main.newMain().solve(sc) ; skip ; var G : long ; G := OclDate.getSystemTime() ; if (elapsed) then ( skip ) else skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String[] str=in.readLine().split(" "); int a=Integer.parseInt(str[0]); int b=Integer.parseInt(str[1]); int c=Integer.parseInt(str[2]); int count=0 ; boolean flg=false ; for(int i=0 ; i<100000 ; i++){ if(a % 2==0 && b % 2==0 && c % 2==0){ int a_tmp=a ; int b_tmp=b ; int c_tmp=c ; a_tmp=b/2+c/2 ; b_tmp=a/2+c/2 ; c_tmp=a/2+b/2 ; a=a_tmp ; b=b_tmp ; c=c_tmp ; count+=1 ; } else { flg=true ; break ; } } System.out.println(flg==false ?-1 : count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : Sequence(String) ; str := in.readLine()->split(" ") ; var a : int ; a := (str[0+1])->toInteger() ; var b : int ; b := (str[1+1])->toInteger() ; var c : int ; c := (str[2+1])->toInteger() ; var count : int ; count := 0 ; var flg : boolean ; flg := false ; var i : int ; i := 0 ; while i < 100000 do ( ( if (a mod 2 = 0 & b mod 2 = 0 & c mod 2 = 0) then ( var a_tmp : int ; a_tmp := a ; var b_tmp : int ; b_tmp := b ; var c_tmp : int ; c_tmp := c ; a_tmp := b / 2 + c / 2 ; b_tmp := a / 2 + c / 2 ; c_tmp := a / 2 + b / 2 ; a := a_tmp ; b := b_tmp ; c := c_tmp ; count := count+(1) ; ) else ( flg := true ; break ) ) ; i := i + 1 ) ; OclFile["System.out"].println(if flg = false then -1 else count endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int D=sc.nextInt(); System.out.println(solve(D)); sc.close(); } static final int MAXL=17 ; static int N ; static long[] v ; static long solve(int D){ if(D % 9!=0)return 0 ; D/=9 ; long[] B=new long[MAXL]; B[0]=1 ; for(int i=1 ; itoInteger() ; OclFile["System.out"].println(solve(D)) ; skip ); static attribute MAXL : int := 17; static attribute N : int; static attribute v : Sequence(long); static operation solve( D : int) : long pre: true post: true activity: ( if (D mod 9 /= 0) then return 0 else skip ; D := D/(9) ; var B : Sequence(long) ; B := Integer.subrange(1,MAXL)->collect(0) ; B[0+1] := 1 ; var i : int ; i := 1 ; while i < MAXL do ( B[i+1] := B[i - 1+1] * 10 ; ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i <= MAXL do ( ( N := (i + 1) / 2 ; v := Integer.subrange(1,N)->collect(0) ; var j : int ; j := 0 ; while j < N do ( var k : int ; k := j ; while k < i - j do ( v[j+1] := v[j+1]+(B[k+1]) ; ; k := k + 1 ) ; ; j := j + 1 ) ; ans := ans+(count(D, i, 0, Integer.subrange(1,N)->collect(0))) ) ; i := i + 1 ) ; return ans ); static operation count( D : long, l : int, t : int, x : Sequence(int)) : long pre: true post: true activity: ( if (t = N) then ( if (D /= 0) then return 0 else skip ; var ans : long ; ans := 1 ; var i : int ; i := 0 ; while i < N do ( ( ans := ans*((if i = 0 then 9 else 10 endif) - if x[i+1] < 0 then -(x[i+1]) else x[i+1] endif) ) ; i := i + 1 ) ; if (l mod 2 = 0) then ans := ans*(10) ; else skip ; return ans ) else skip ; var ans : long ; ans := 0 ; var m : int ; m := -9 ; while m <= 9 do ( ( if (-v[t+1] < D + v[t+1] * m & D + v[t+1] * m < v[t+1]) then ( x[t+1] := m ; ans := ans+(count(D + v[t+1] * m, l, t + 1, x)) ) else skip ) ; m := m + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class SortExample { static void printOrder(Integer[] arr,int k){ int n=arr.length ; Arrays.sort(arr,0,k); Arrays.sort(arr,k,n,Collections.reverseOrder()); } public static void main(String[] args){ Integer[] arr={ 5,4,6,2,1,3,8,9,-1 }; int k=4 ; printOrder(arr,k); System.out.printf("%s",Arrays.toString(arr)); } } ------------------------------------------------------------ OCL File: --------- class SortExample { static operation printOrder( arr : Sequence(int), k : int) : void pre: true post: true activity: ( var n : int ; n := arr->size() ; arr := arr.subrange(1,0)^(arr.subrange(0+1,k)->sort())^arr.subrange(k+1,arr.size) ; arr, k, n, reverseOrder() := arr, k, n, reverseOrder()->sort() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{5,4,6,2,1,3,8,9,-1} ; var k : int ; k := 4 ; execute printOrder(arr, k) ; OclFile["System.out"].printf("%s", (arr + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A_Vanya_and_Cubes { public static void main(String[] args){ Scanner sn=new Scanner(System.in); int n=sn.nextInt(); int i=0 ; int sum=0 ; while(sum<=n){ for(int j=1 ; j<=i ; j++){ sum+=j ; if(sum>n)break ; } i++; } System.out.println(i-2); } } ------------------------------------------------------------ OCL File: --------- class A_Vanya_and_Cubes { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sn : OclFile ; sn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sn.getCurrent()->toInteger() ; var i : int ; i := 0 ; var sum : int ; sum := 0 ; while (sum <= n) do ( var j : int ; j := 1 ; while j <= i do ( ( sum := sum+(j) ; if (sum > n) then break else skip ) ; j := j + 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(i - 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] tmp=br.readLine().split(" "); int N=Integer.parseInt(tmp[0]); int Y=Integer.parseInt(tmp[1]); int x=-1 ; int y=-1 ; int z=-1 ; if(Y>=100000){ for(int i=0 ; i<=N ; i++){ for(int j=0 ; j<=N-i ; j++){ if(Y==10000*i+5000*j+1000*(N-i-j)){ x=i ; y=j ; z=N-i-j ; } } } } else { for(int i=0 ; i<=N ; i++){ for(int j=0 ; j<=N-i ; j++){ if(Y==1000*i+5000*j+10000*(N-i-j)){ z=i ; y=j ; x=N-i-j ; } } } } System.out.println(x+" "+y+" "+z); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var tmp : Sequence(String) ; tmp := br.readLine()->split(" ") ; var N : int ; N := (tmp[0+1])->toInteger() ; var Y : int ; Y := (tmp[1+1])->toInteger() ; var x : int ; x := -1 ; var y : int ; y := -1 ; var z : int ; z := -1 ; if (Y >= 100000) then ( var i : int ; i := 0 ; while i <= N do ( ( var j : int ; j := 0 ; while j <= N - i do ( ( if (Y = 10000 * i + 5000 * j + 1000 * (N - i - j)) then ( x := i ; y := j ; z := N - i - j ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i <= N do ( ( var j : int ; j := 0 ; while j <= N - i do ( ( if (Y = 1000 * i + 5000 * j + 10000 * (N - i - j)) then ( z := i ; y := j ; x := N - i - j ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; OclFile["System.out"].println(x + " " + y + " " + z) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String[] args){ int i,j,r,N,N1 ; N1=3 ; N=0 ; r=5 ; for(i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ; sum := sum+(arr[i+1]) ) ; i := i + 1 ) ; var score : long ; score := 0 ; arr := arr->sort() ; score := sum ; var i : int ; i := 0 ; while i < n - 1 do ( ( score := score+(arr[i+1]) ; sum := sum - arr[i+1] ; score := score+(sum) ) ; i := i + 1 ) ; OclFile["System.out"].println(score) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class AppleToast { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); long[] a=new long[n]; for(int i=0 ; i=0 ; i--){ sum+=a[i]*(i+2); } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class AppleToast { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var sum : long ; sum := a[n - 1+1] * n ; var i : int ; i := n - 2 ; while i >= 0 do ( ( sum := sum+(a[i+1] * (i + 2)) ) ; i := i - 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float mean(float mid[],int freq[],int n){ float sum=0,freqSum=0 ; for(int i=0 ; icollect(0.0) ; var sum : double ; sum := 0 ; var freqSum : double ; freqSum := 0 ; var sd : double ; var i : int ; i := 0 ; while i < n 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] ) ; i := i + 1 ) ; sd := ((sum - freqSum * mean(mid, freq, n) * mean(mid, freq, n)) / (freqSum - 1))->sqrt()->oclAsType(double) ; return sd ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var lower_limit : Sequence(double) ; lower_limit := Sequence{50,61,71,86,96} ; var upper_limit : Sequence(double) ; upper_limit := Sequence{60,70,85,95,100} ; var freq : Sequence(int) ; freq := Sequence{9,7,9,12,8} ; var n : int ; n := lower_limit->size() ; OclFile["System.out"].println(groupedSD(lower_limit, upper_limit, freq, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Codeforces { public static void main(String args[]){ Scanner k=new Scanner(System.in); long n=k.nextLong(); ArrayListarr=new ArrayList<>(); for(int i=0 ; itoLong() ; var arr : Sequence(long) ; arr := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var a : long ; a := k.getCurrent()->toLong() ; arr := arr->including(a) ) ; i := i + 1 ) ; arr := arr->sort() ; var ans : long ; ans := 0 ; var sum : long ; sum := 0 ; for (a : arr) do ( sum := sum+(a) ; ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( ans := ans+(sum) ; ans := ans+(arr->at(i+1)) ; sum := sum-(arr->at(i+1)) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans + arr->at((n - 1)->oclAsType(int)+1)) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.util.*; class GFG { static boolean func(int a[],int k){ for(int i=0 ; isize() do ( if (a[i+1] mod k = 0) then return true else skip ; ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{14,27,38,76,84} ; var k : int ; k := 19 ; var res : boolean ; res := func(a, k) ; OclFile["System.out"].println(res) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int[] Findpermutation(int n){ int[] a=new int[n+1]; a[1]=n ; for(int i=2 ; i<=n ; i++)a[i]=i-1 ; return a ; } public static void main(String[] args){ int n=8 ; int[] v=Findpermutation(n); for(int i=1 ; i<=n ; i++)System.out.print(v[i]+" "); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Findpermutation( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; a[1+1] := n ; var i : int ; i := 2 ; while i <= n do ( a[i+1] := i - 1 ; ; i := i + 1 ) ; return a ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 8 ; var v : Sequence(int) ; v := Findpermutation(n) ; var i : int ; i := 1 ; while i <= n do ( OclFile["System.out"].print(v[i+1] + " ") ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static Scanner sc=new Scanner(System.in); public static void main(String[] args){ Main instance=new Main(); instance.solve(); } private void solve(){ try { int n=sc.nextInt(); int y=sc.nextInt(); for(int i=0 ; i<=n ; i++){ for(int j=0 ; j<=n ; j++){ int k=n-i-j ; if(k<0){ continue ; } if(i*10000+j*5000+1000*k==y){ System.out.println(i+" "+j+" "+k); return ; } } } System.out.println("-1-1-1"); } catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var instance : Main ; instance := Main.newMain() ; instance.solve() ); operation solve() : void pre: true post: true activity: ( try ( var n : int ; n := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i <= n do ( ( var j : int ; j := 0 ; while j <= n do ( ( var k : int ; k := n - i - j ; if (k < 0) then ( continue ) else skip ; if (i * 10000 + j * 5000 + 1000 * k = y) then ( OclFile["System.out"].println(i + " " + j + " " + k) ; return ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println("-1-1-1") ) catch (e : ProgramException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static int __gcd(int a,int 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); } static void countCoprimePairs(int n){ int count=0 ; System.out.println("The co-prime pairs are: "); for(int i=2 ; i<=Math.sqrt(n); i++){ if(n % i==0){ if(__gcd(i,(n/i))==1){ System.out.print("("+i+","+(n/i)+")\n"); count++; } } } System.out.println("\nNumber of coprime pairs : "+count); } public static void main(String[] args){ int N=120 ; countCoprimePairs(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation __gcd( a : int, b : int) : int 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 > b) then return __gcd(a - b, b) else skip ; return __gcd(a, b - a) ); static operation countCoprimePairs( n : int) : void pre: true post: true activity: ( var count : int ; count := 0 ; OclFile["System.out"].println("The co-prime pairs are: ") ; var i : int ; i := 2 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then ( if (__gcd(i, (n / i)) = 1) then ( OclFile["System.out"].print("(" + i + "," + (n / i) + ")\n") ; count := count + 1 ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("\nNumber of coprime pairs : " + count) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 120 ; execute countCoprimePairs(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class tennis { public static void main(String[] args){ FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder sb=new StringBuilder(); int tt=fs.nextInt(); Long[] a=fs.readArray(tt); sb.append(a[0]).append(" "); long max=Math.max(0L,a[0]); for(int i=1 ; i=0){ int sr=(int)Math.sqrt(x); if((sr*sr)==x)return sr ; else return 0 ; } return 0 ; } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } Long[] readArray(int n){ Long[] a=new Long[n]; for(int i=0 ; imax() ; var i : int ; i := 1 ; while i < tt do ( ( sb := sb + StringLib.newString(max + a[i+1] + " ") ; max := Set{max, a[i+1] + max}->max() ) ; i := i + 1 ) ; skip ; skip ; ); static operation isPerfectSquare( x : int) : int pre: true post: true activity: ( if (x >= 0) then ( var sr : int ; sr := (x)->sqrt()->oclAsType(int) ; if ((sr * sr) = x) then return sr else return 0 ) else skip ; return 0 ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(long) pre: true post: true activity: ( var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextLong() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); StringTokenizer inputString=new StringTokenizer(reader.readLine()); int n=Integer.parseInt(inputString.nextToken()); long[] arr=new long[n]; long[] arr2=new long[n]; long temp=0 ; long[] arrfin=new long[n]; StringTokenizer inputString2=new StringTokenizer(reader.readLine()); for(int i=0 ; i1){ arrfin[i]=arr2[i]; } else { arrfin[i]=arr2[i]+arr[i]; } out.print(arrfin[i]+" "); } reader.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var inputString : OclIterator ; inputString := OclIterator.newOclIterator_String(reader.readLine()) ; var n : int ; n := (inputString.next())->toInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var arr2 : Sequence(long) ; arr2 := Integer.subrange(1,n)->collect(0) ; var temp : long ; temp := 0 ; var arrfin : Sequence(long) ; arrfin := Integer.subrange(1,n)->collect(0) ; var inputString2 : OclIterator ; inputString2 := OclIterator.newOclIterator_String(reader.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( var sum : int ; sum := 0 ; arr[i+1] := (inputString2.next())->toLong() ; if (i = 0) then ( arr2[i+1] := 0 ) else ( if (arr[i - 1+1] < 0) then ( arr2[i+1] := arr2[i - 1+1] ; sum := sum + 1 ) else ( arr2[i+1] := arr2[i - 1+1] + arr[i - 1+1] ) ) ; if (sum > 1) then ( arrfin[i+1] := arr2[i+1] ) else ( arrfin[i+1] := arr2[i+1] + arr[i+1] ) ; skip ; ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); long[] arr=new long[n]; long[] prArr=new long[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var prArr : Sequence(long) ; prArr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := scan.getCurrent()->toLong() ; ; i := i + 1 ) ; var x : long ; x := 0 ; var i : int ; i := 0 ; while i < n do ( ( prArr[i+1] := arr[i+1] + x ; x := Set{x, prArr[i+1]}->max() ; OclFile["System.out"].print(prArr[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class sol { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(),max=0 ; StringBuilder s=new StringBuilder(); for(int i=0 ; itoInteger() ; var max : int ; max := 0 ; var s : String ; s := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() + max ; max := Set{max, a}->max() ; s := s + StringLib.newString(a + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void Count(int[] temp){ int[] query={ 9,3,2 }; int Q=query.length ; for(int i=0 ; id=new HashMap(); for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < Q do ( ( var pos : int ; pos := query[i+1] ; OclFile["System.out"].println(temp[pos - 1+1]) ) ; i := i + 1 ) ); static operation processing( s : String, len : int) : Sequence(int) pre: true post: true activity: ( var temp : Sequence(int) ; temp := Integer.subrange(1,len)->collect(0) ; var d : Map(String,int) ; d := Map{} ; var i : int ; i := 0 ; while i < len do ( ( if (not(d->keys()->includes(s->at(i+1)))) then ( d := d->union(Map{s->at(i+1) |-> i}) ) else ( temp[i+1] := temp[d->at(s->at(i+1))+1] + 1 ; d := d->union(Map{s->at(i+1) |-> i}) ) ) ; i := i + 1 ) ; return temp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "abacsddaa" ; var n : int ; n := s->size() ; var temp : Sequence(int) ; temp := processing(s, n) ; execute Count(temp) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { public static int gcd(int a,int b){ if(a==0)return b ; return gcd(b % a,a); } public static void main(String[] args){ int a=2 ; int b=4 ; System.out.println(gcd(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 2 ; var b : int ; b := 4 ; OclFile["System.out"].println(gcd(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Xor { static int maxXORInRange(int L,int R){ int LXR=L ^ R ; int msbPos=0 ; while(LXR>0){ msbPos++; LXR>>=1 ; } int maxXOR=0 ; int two=1 ; while(msbPos-->0){ maxXOR+=two ; two<<=1 ; } return maxXOR ; } public static void main(String[] args){ int L=8 ; int R=20 ; System.out.println(maxXORInRange(L,R)); } } ------------------------------------------------------------ OCL File: --------- class Xor { static operation maxXORInRange( L : int, R : int) : int pre: true post: true activity: ( var LXR : int ; LXR := MathLib.bitwiseXor(L,R) ; var msbPos : int ; msbPos := 0 ; while (LXR > 0) do ( msbPos := msbPos + 1 ; LXR := LXR/(2->pow(1)) ) ; var maxXOR : int ; maxXOR := 0 ; var two : int ; two := 1 ; while (msbPos > 0) do ( msbPos := msbPos - 1 ; skip ; ( maxXOR := maxXOR+(two) ; two := two*(2->pow(1)) ) ; ) ; return maxXOR ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 8 ; var R : int ; R := 20 ; OclFile["System.out"].println(maxXORInRange(L, R)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void fib(int n){ int a=0,b=1 ; if(n>=0)System.out.print(a+" "); if(n>=1)System.out.print(b+" "); for(int i=2 ; i<=n ; i++){ System.out.print(a+b+" "); b=a+b ; a=b-a ; } } public static void main(String[] args){ fib(9); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fib( n : int) : void pre: true post: true activity: ( var a : int ; a := 0 ; var b : int ; b := 1 ; if (n >= 0) then OclFile["System.out"].print(a + " ") ; else skip ; if (n >= 1) then OclFile["System.out"].print(b + " ") ; else skip ; var i : int ; i := 2 ; while i <= n do ( ( OclFile["System.out"].print(a + b + " ") ; b := a + b ; a := b - a ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute fib(9) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void fib(int n){ int a=0,b=1,c ; if(n>=0)System.out.print(a+" "); if(n>=1)System.out.print(b+" "); for(int i=2 ; i<=n ; i++){ c=a+b ; System.out.print(c+" "); a=b ; b=c ; } } public static void main(String[] args){ fib(9); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fib( n : int) : void pre: true post: true activity: ( var a : int ; a := 0 ; var b : int ; b := 1 ; var c : int ; if (n >= 0) then OclFile["System.out"].print(a + " ") ; else skip ; if (n >= 1) then OclFile["System.out"].print(b + " ") ; else skip ; var i : int ; i := 2 ; while i <= n do ( ( c := a + b ; OclFile["System.out"].print(c + " ") ; a := b ; b := c ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute fib(9) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=256 ; static boolean canMakeStr2(String str1,String str2){ int[] count=new int[MAX]; char[] str3=str1.toCharArray(); for(int i=0 ; icollect(0) ; var str3 : Sequence(String) ; str3 := str1->characters() ; var i : int ; i := 0 ; while i < str3->size() do ( count[str3[i+1]+1] := count[str3[i+1]+1] + 1 ; ; i := i + 1 ) ; var str4 : Sequence(String) ; str4 := str2->characters() ; var i : int ; i := 0 ; while i < str4->size() do ( ( if (count[str4[i+1]+1] = 0) then return false else skip ; count[str4[i+1]+1] := count[str4[i+1]+1] - 1 ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str1 : String ; str1 := "geekforgeeks" ; var str2 : String ; str2 := "for" ; if (canMakeStr2(str1, str2)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(); int y=scanner.nextInt(); System.out.println(Arrays.stream(getResult(n,y)).mapToObj(i->String.valueOf(i)).collect(Collectors.joining(" "))); } } private static int[] getResult(final int n,final int y){ for(int i=0 ; i<=Math.min(y/5000,n); i++){ int count=n-i ; int sum=y-i*5000 ; int diff=sum-count*1000 ; if((diff>=0)&&(0==diff % 9000)&&(diff/9000<=count)){ return new int[] { diff/9000,i,count-diff/9000 }; } } return new int[] { -1,-1,-1 }; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var y : int ; y := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(stream(getResult(n, y)).mapToObj(lambda i : OclAny in ((i) + "")).collect(Collectors.joining(" "))) )) ); static operation getResult( n : int, y : int) : Sequence(int) pre: true post: true activity: ( var i : int ; i := 0 ; while i <= Set{y / 5000, n}->min() do ( ( var count : int ; count := n - i ; var sum : int ; sum := y - i * 5000 ; var diff : int ; diff := sum - count * 1000 ; if ((diff >= 0) & (0 = diff mod 9000) & (diff / 9000 <= count)) then ( return Sequence{diff / 9000,i,count - diff / 9000} ) else skip ) ; i := i + 1 ) ; return Sequence{-1,-1,-1} ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean check(long a,long b){ long c=0 ; while(a!=0){ c=c+a % 10 ; a=a/10 ; } return(c==b); } static long root(long n){ boolean found=false ; long mx=(long)1E18 ; for(long i=0 ; i<=90 ; i++){ long s=i*i+4*n ; long sq=(long)Math.sqrt(s); if(sq*sq==s && check((sq-i)/2,i)){ found=true ; mx=Math.min(mx,(sq-i)/2); } } if(found)return mx ; else return-1 ; } public static void main(String[] args){ long n=110 ; System.out.println(root(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation check( a : long, b : long) : boolean pre: true post: true activity: ( var c : long ; c := 0 ; while (a /= 0) do ( c := c + a mod 10 ; a := a / 10 ) ; return (c = b) ); static operation root( n : long) : long pre: true post: true activity: ( var found : boolean ; found := false ; var mx : long ; mx := 1E18->oclAsType(long) ; var i : long ; i := 0 ; while i <= 90 do ( ( var s : long ; s := i * i + 4 * n ; var sq : long ; sq := (s)->sqrt()->oclAsType(long) ; if (sq * sq = s & check((sq - i) / 2, i)) then ( found := true ; mx := Set{mx, (sq - i) / 2}->min() ) else skip ) ; i := i + 1 ) ; if (found) then return mx else return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 110 ; OclFile["System.out"].println(root(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; public class Main { static int n ; static List>list ; public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] sa=br.readLine().split(" "); n=Integer.parseInt(sa[0]); list=new ArrayList<>(n); for(int i=0 ; i()); } for(int i=0 ; isplit(" ") ; n := (sa[0+1])->toInteger() ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( list := list->including(Sequence{}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( sa := br.readLine()->split(" ") ; var x : int ; x := (sa[0+1])->toInteger() - 1 ; var y : int ; y := (sa[1+1])->toInteger() - 1 ; list->at(x+1)->excludes(y) ; list->at(y+1)->excludes(x) ; ) ; i := i + 1 ) ; skip ; if (dfs(0, -1) = 1) then ( OclFile["System.out"].println("Bob") ) else ( OclFile["System.out"].println("Alice") ) ; ); static operation dfs( x : int, p : int) : int pre: true post: true activity: ( var ret : int ; ret := 0 ; for (next : list->at(x+1)) do ( ( if (next /= p) then ( var c : int ; c := dfs(next, x) ; ret := MathLib.bitwiseXor(ret,c) ) else skip ) ) ; return ret + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { int n ; ArrayListlist[]; private void solve()throws IOException { n=nextInt(); list=new ArrayList[n+1]; for(int i=1 ; i<=n ; i++)list[i]=new ArrayList<>(); for(int i=1 ; icollect(null) ; var i : int ; i := 1 ; while i <= n do ( list[i+1] := Sequence{} ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var u : int ; u := nextInt() ; var v : int ; v := nextInt() ; list[u+1]->excludes(v) ; list[v+1]->excludes(u) ) ; i := i + 1 ) ; out.println(if dfs(1, -1) = 0 then "Bob" else "Alice" endif) ; ); operation dfs( v : int, p : int) : int pre: true post: true activity: ( var ret : int ; ret := 0 ; for (vv : list[v+1]) do ( if (vv /= p) then ret := MathLib.bitwiseXor(ret,dfs(vv, v) + 1) ; else skip ; ) ; return ret ); operation run() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; st := null ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve() ; br.close() ; out.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute br : OclFile; attribute st : OclIterator; attribute out : OclFile; operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; class Main { static int grundy(int v,int pare){ int res=0 ; for(int u : Edge[v])if(u!=pare)res ^=(1+grundy(u,v)); return res ; } static ListEdge[]; public static void main(String[] args){ Scanner scan=new Scanner(System.in); int N=scan.nextInt(); Edge=new ArrayList[N]; for(int i=0 ; i(); for(int i=0 ; itoInteger() ; Edge := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( Edge[i+1] := Sequence{} ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( var x : int ; x := scan.getCurrent()->toInteger() - 1 ; var y : int ; y := scan.getCurrent()->toInteger() - 1 ; Edge[x+1]->excludes(y) ; Edge[y+1]->excludes(x) ) ; i := i + 1 ) ; if (grundy(0, -1) = 0) then ( OclFile["System.out"].println("Bob") ) else ( OclFile["System.out"].println("Alice") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static ArrayList[] edge ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); edge=new ArrayList[N+1]; for(int i=1 ; i(); } for(int i=0 ; ilist=edge[v]; int ret=0 ; for(int i=0 ; itoInteger() ; edge := Integer.subrange(1,N + 1)->collect(null) ; var i : int ; i := 1 ; while i < N + 1 do ( ( edge[i+1] := Sequence{} ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; edge[x+1]->excludes(y) ; edge[y+1]->excludes(x) ) ; i := i + 1 ) ; var ans : String ; ans := "Alice" ; if (dfs(1, 0) = 0) then ans := "Bob" ; else skip ; OclFile["System.out"].println(ans) ; ); static operation dfs( v : int, p : int) : int pre: true post: true activity: ( var list : Sequence(int) ; list := edge[v+1] ; var ret : int ; ret := 0 ; var i : int ; i := 0 ; while i < list->size() do ( ( var u : int ; u := list->at(i+1) ; if (u /= p) then ( ret := (MathLib.bitwiseXor(ret,(dfs(u, v) + 1))) ) else skip ) ; i := i + 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static float rectanglearea(float a,float b){ if(a<0 || b<0)return-1 ; return 2*a*b ; } public static void main(String args[]){ float a=10,b=8 ; System.out.println(rectanglearea(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation rectanglearea( a : double, b : double) : double pre: true post: true activity: ( if (a < 0 or b < 0) then return -1 else skip ; return 2 * a * b ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 10 ; var b : double ; b := 8 ; OclFile["System.out"].println(rectanglearea(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(br.readLine()); Node[] nodes=new Node[n]; for(int i=0 ; iadj ; public Node(int ii){ i=ii ; adj=new ArrayList(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sb : String ; sb := StringLib.newString() ; var n : int ; n := (br.readLine())->toInteger() ; var nodes : Sequence(Node) ; nodes := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( nodes[i+1] := Node.newNode(i) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < (n)->char2byte() - 1 do ( ( var s : Sequence(String) ; s := br.readLine()->split(" ") ; var a : int ; a := (s[0+1])->toInteger() - 1 ; var b : int ; b := (s[1+1])->toInteger() - 1 ; nodes[a+1].adj->excludes(nodes[b+1]) ; nodes[b+1].adj->excludes(nodes[a+1]) ; ) ; i := i + 1 ) ; if (solve(nodes[0+1], -1) /= 0) then ( OclFile["System.out"].println("Alice") ) else ( OclFile["System.out"].println("Bob") ) ; ); static operation solve( a : Node, from : int) : int pre: true post: true activity: ( if (a.adj->size() = 1 & a.i /= 0) then ( return 0 ) else skip ; var ans : int ; ans := 0 ; for (n : a.adj) do ( ( if (n.i /= from) then ( ans := MathLib.bitwiseXor(ans,1 + solve(n, a.i)) ) else skip ) ) ; return ans ); } class Node { attribute i : int; attribute adj : Sequence(Node); static operation newNode( ii : int) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(ii); return self ); operation initialise( ii : int) : void pre: true post: true activity: ( i := ii ; adj := Sequence{} ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; class GFG { public static void maxOverlap(int[] start,int[] end,int n){ int maxa=Arrays.stream(start).max().getAsInt(); int maxb=Arrays.stream(end).max().getAsInt(); int maxc=Math.max(maxa,maxb); int[] x=new int[maxc+2]; Arrays.fill(x,0); int cur=0,idx=0 ; for(int i=0 ; imax() ; var x : Sequence(int) ; x := Integer.subrange(1,maxc + 2)->collect(0) ; x := x->collect(0) ; var cur : int ; cur := 0 ; var idx : int ; idx := 0 ; var i : int ; i := 0 ; while i < n 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 ) ; i := i + 1 ) ; var maxy : int ; maxy := -2147483648 ; var i : int ; i := 0 ; while i <= maxc do ( ( cur := cur+(x[i+1]) ; if (maxy < cur) then ( maxy := cur ; idx := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("Maximum value is:" + maxy + " at position: " + idx + "") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var start : Sequence(int) ; start := Sequence{13,28,29,14,40,17,3} ; var end : Sequence(int) ; end := Sequence{107,95,111,105,70,127,74} ; var n : int ; n := start->size() ; execute maxOverlap(start, end, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); int ans=1900*M+100*(N-M); for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var ans : int ; ans := 1900 * M + 100 * (N - M) ; var i : int ; i := 0 ; while i < M do ( ( ans := ans*(2) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); CHSI solver=new CHSI(); solver.solve(1,in,out); out.close(); } static class CHSI { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=Integer.parseInt(in.next()); int m=Integer.parseInt(in.next()); int ans=(int)((1900*m+100*(n-m))*Math.pow(2,m)); out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : CHSI ; solver := CHSI.newCHSI() ; solver.solve(1, in, out) ; skip ; ); static class CHSI { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := (in.getCurrent())->toInteger() ; var m : int ; m := (in.getCurrent())->toInteger() ; var ans : int ; ans := ((1900 * m + 100 * (n - m)) * 2->pow(m))->oclAsType(int) ; skip ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.*; import static java.lang.Long.*; import static java.lang.Math.*; import static java.lang.System.*; public class Main { public static long LMS=1900 ; public static long SMS=100 ; public static void main(String[] args){ int i=0 ; int j=0 ; int k=0 ; Scanner sc=new Scanner(in); long n=parseLong(sc.next()); long m=parseLong(sc.next()); sc.close(); long t=m*LMS+(n-m)*SMS ; out.println(t*(long)pow(2,m)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute LMS : long := 1900; static attribute SMS : long := 100; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 0 ; var j : int ; j := 0 ; var k : int ; k := 0 ; var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var n : long ; n := parseLong(sc.getCurrent()) ; var m : long ; m := parseLong(sc.getCurrent()) ; skip ; var t : long ; t := m * LMS + (n - m) * SMS ; out.println(t * pow(2, m)->oclAsType(long)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String input=br.readLine(); int notes=Integer.parseInt(input.substring(0,input.indexOf(" "))); input=input.substring(input.indexOf(" ")+1); int money_l=Integer.parseInt(input); int money=money_l/1000 ; String result="-1-1-1" ; if(notes<=money && money<=notes*10){ OUTSIDE : for(int x=0 ; x<=notes ; x++){ if(x*10>money){ break ; } if(money<=x*10+(notes-x)*5){ for(int y=0 ; y<=notes-x ; y++){ if(x*10+y*5>money){ break ; } if(x*10+y*5+(notes-x-y)==money){ result=String.valueOf(x)+" "+String.valueOf(y)+" "+String.valueOf(notes-x-y); break OUTSIDE ; } } } } } System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var input : String ; input := br.readLine() ; var notes : int ; notes := (input.subrange(0+1,input->indexOf(" ")-1))->toInteger() ; input := input.subrange(input->indexOf(" ")-1 + 1+1,input->indexOf(" ")-1 + 1) ; var money_l : int ; money_l := (input)->toInteger() ; var money : int ; money := money_l / 1000 ; var result : String ; result := "-1-1-1" ; if (notes <= money & money <= notes * 10) then ( var x : int ; x := 0 ; while x <= notes do ( ( if (x * 10 > money) then ( break ) else skip ; if (money <= x * 10 + ((notes)->char2byte() - (x)->char2byte()) * 5) then ( var y : int ; y := 0 ; while y <= (notes)->char2byte() - (x)->char2byte() do ( ( if (x * 10 + y * 5 > money) then ( break ) else skip ; if (x * 10 + y * 5 + ((notes)->char2byte() - (x)->char2byte() - y) = money) then ( result := ((x) + "") + " " + ((y) + "") + " " + (((notes)->char2byte() - (x)->char2byte() - y) + "") ; break ) else skip ) ; y := y + 1 ) ) else skip ) ; x := x + 1 ) ; ) else skip ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static int mod=(int)1e9+7 ; static int DX[]={ -1,0,1,0 },DY[]={ 0,-1,0,1 }; public static void main(String[] args){ FastScanner fs=new FastScanner(System.in); int n=fs.nextInt(),m=fs.nextInt(); long ans=(long)Math.pow(2,m)*(1900*m+100*(n-m)); System.out.println(ans); } } class FastScanner { private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public FastScanner(InputStream in){ reader=new BufferedReader(new InputStreamReader(in)); tokenizer=null ; } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { return reader.readLine(); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong(){ return Long.parseLong(next()); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public int[] nextIntArray(int n){ int[] a=new int[n]; for(int i=0 ; ioclAsType(int) + 7; static attribute DX : int := Sequence{-1,0,1,0}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fs : FastScanner ; fs := FastScanner.newFastScanner(OclFile["System.in"]) ; var n : int ; n := fs.nextInt() ; var m : int ; m := fs.nextInt() ; var ans : long ; ans := 2->pow(m)->oclAsType(long) * (1900 * m + 100 * (n - m)) ; OclFile["System.out"].println(ans) ); } class FastScanner { attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newFastScanner( in : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in)) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.next() ); operation nextLine() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( return reader.readLine() ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.nextToken("\n") ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLongArray( n : int) : Sequence(long) pre: true post: true activity: ( var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextLong() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.nio.charset.StandardCharsets ; public class Main { public static void main(String[] args)throws IOException { InputStreamReader reader=new InputStreamReader(System.in,StandardCharsets.UTF_8); BufferedReader in=new BufferedReader(reader); String[] tokens=in.readLine().split(" "); int N=Integer.parseInt(tokens[0]); int M=Integer.parseInt(tokens[1]); long result=1900*M+100*(N-M); long ratio=2 ; for(int i=2 ; i<=M ; ++i){ ratio*=2 ; } result*=ratio ; System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile["System.in"], StandardCharsets.UTF_8) ; var in : OclFile ; in := OclFile.newOclFile_Read(reader) ; var tokens : Sequence(String) ; tokens := in.readLine()->split(" ") ; var N : int ; N := (tokens[0+1])->toInteger() ; var M : int ; M := (tokens[1+1])->toInteger() ; var result : long ; result := 1900 * M + 100 * (N - M) ; var ratio : long ; ratio := 2 ; var i : int ; i := 2 ; while i <= M do ( ( ratio := ratio*(2) ) ; i := i + 1 ) ; result := result*(ratio) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean CheckArray(int arr[],int n){ int prod=1 ; for(int i=0 ; isize() ; if (CheckArray(arr, n)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final int MAX=100000 ; private static int[][] map ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); String string=sc.next(); sc.close(); String mew=string ; while(mew.indexOf("mew")!=-1 && ! mew.equals("mew")){ mew=mew.replaceAll("mew",""); } if(! mew.equals("mew")){ System.out.println("Rabbit"); return ; } System.out.println("Cat"); return ; } static void WarshallFloyd(){ int n=map.length ; for(int i=0 ; iindexOf("mew")-1 /= -1 & not(mew = "mew")) do ( mew := mew.replaceAllMatches("mew", "" ) ) ; if (not(mew = "mew")) then ( OclFile["System.out"].println("Rabbit") ; return ) else skip ; OclFile["System.out"].println("Cat") ; return ); static operation WarshallFloyd() : void pre: true post: true activity: ( var n : int ; n := map->size() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (map[i+1][j+1] = 0) then ( map[i+1][j+1] := MAX ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var k : int ; k := 0 ; while k < n do ( ( var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (i /= j) then ( map[i+1][j+1] := Set{map[i+1][j+1], map[i+1][k+1] + map[k+1][j+1]}->min() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; k := k + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collection ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.HashSet ; import java.util.InputMismatchException ; import java.util.PriorityQueue ; import java.util.Random ; import java.util.Scanner ; import java.util.Stack ; import java.util.TreeMap ; import java.util.TreeSet ; public class CF427_1 { static int N ; static int MOD=(int)(1e9+7); public static void main(String args[]){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=in.nextInt(); while(t-->0){ long n=in.nextInt(); long a=in.nextInt(); long b=in.nextInt(); if(nx*a){ out.println("Yes"); continue ; } long low=1 ; long high=x+1 ; long ans=1 ; while(low<=high){ long mid=(low+high)/2 ; if(mid*a(ans-1)*b && noclAsType(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : long ; n := in.getCurrent()->toInteger() ; var a : long ; a := in.getCurrent()->toInteger() ; var b : long ; b := in.getCurrent()->toInteger() ; if (n < a) then ( skip ; continue ) else skip ; if (a = b) then ( if (n mod a = 0) then ( skip ) else ( skip ) ; continue ) else skip ; var x : long ; x := b / (b - a) ; if (n > x * a) then ( skip ; continue ) else skip ; var low : long ; low := 1 ; var high : long ; high := x + 1 ; var ans : long ; ans := 1 ; while (low <= high) do ( var mid : long ; mid := (low + high) / 2 ; if (mid * a < n) then ( low := mid + 1 ) else ( ans := mid ; high := mid - 1 ) ) ; if (n > (ans - 1) * b & n < ans * a) then ( skip ) else ( skip ) ; ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { boolean flag ; char[] a ; int pos ; void cat(){ if(possize() & a[pos+1] = 'm') then pos := pos + 1 else flag := false ; ; if (flag = false) then return else skip ; if (pos < a->size() & a[pos+1] = 'm') then execute cat() ; else skip ; if (pos < a->size() & a[pos+1] = 'e') then pos := pos + 1 else flag := false ; ; if (flag = false) then return else skip ; if (pos < a->size() & a[pos+1] = 'm') then execute cat() ; else skip ; if (pos < a->size() & a[pos+1] = 'w') then pos := pos + 1 else flag := false ; ; if (flag = false) then return else skip ; ); operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( a := sc.getCurrent()->characters() ; if (a->size() mod 3 /= 0) then ( OclFile["System.out"].println("Rabbit") ) else ( flag := true ; pos := 0 ; execute cat() ; if (flag = true & pos = a->size()) then OclFile["System.out"].println("Cat") ; else OclFile["System.out"].println("Rabbit") ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashSet ; import java.util.Set ; import static java.lang.Integer.parseInt ; public class Main { static Setcat=new HashSet<>(); static Setrabbit=new HashSet<>(); public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; cat.add(""); cat.add("mew"); while((line=br.readLine())!=null && ! line.isEmpty()){ System.out.println(isCat(line)? "Cat" : "Rabbit"); } } static boolean isCat(String S){ if(cat.contains(S))return true ; if(rabbit.contains(S))return false ; if(S.charAt(0)=='m' && S.charAt(S.length()-1)=='w' && S.indexOf('e')>0){ boolean ret=false ; String _S=S.substring(1,S.length()-1); for(int i=0 ; i<_S.length(); i++){ if(_S.charAt(i)=='e'){ ret=isCat(_S.substring(0,i))& isCat(_S.substring(i+1)); if(ret){ cat.add(S); break ; } else { rabbit.add(S); } } } return ret ; } return false ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute cat : Set(String) := Set{}; static attribute rabbit : Set(String) := Set{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; cat := cat->including("") ; cat := cat->including("mew") ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( OclFile["System.out"].println(if isCat(line) then "Cat" else "Rabbit" endif) ) ; line := br.readLine() ; ) ; ); static operation isCat( S : String) : boolean pre: true post: true activity: ( if (cat->includes(S)) then return true else skip ; if (rabbit->includes(S)) then return false else skip ; if (S->at(0+1) = 'm' & S->at(S->size() - 1+1) = 'w' & S->indexOf('e')-1 > 0) then ( var ret : boolean ; ret := false ; var _S : String ; _S := S.subrange(1+1,S->size() - 1) ; var i : int ; i := 0 ; while i < _S->size() do ( ( if (_S->at(i+1) = 'e') then ( ret := isCat(_S.subrange(0+1,i)) & isCat(_S.subrange(i + 1+1,i + 1)) ; if (ret) then ( cat := cat->including(S) ; break ) else ( rabbit := rabbit->including(S) ) ) else skip ) ; i := i + 1 ) ; return ret ) else skip ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { Scanner sc=new Scanner(in); int n,len ; String s ; boolean wa(){ if(s.charAt(n)!='m' || n+2>=len)return false ; n++; if(s.charAt(n)=='m'){ if(! wa())return false ; } if(n>=len || s.charAt(n)!='e')return false ; n++; if(n>=len)return false ; if(s.charAt(n)=='m'){ if(! wa())return false ; } if(n>=len || s.charAt(n)!='w')return false ; n++; return true ; } void run(){ s=sc.next(); len=s.length(); if(len==0){ out.println("Cat"); return ; } n=0 ; if(wa()&& n==len)out.println("Cat"); else out.println("Rabbit"); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(in); attribute n : int; attribute s : String; operation wa() : boolean pre: true post: true activity: ( if (s->at(n+1) /= 'm' or n + 2 >= len) then return false else skip ; n := n + 1 ; if (s->at(n+1) = 'm') then ( if (not(wa())) then return false else skip ) else skip ; if (n >= len or s->at(n+1) /= 'e') then return false else skip ; n := n + 1 ; if (n >= len) then return false else skip ; if (s->at(n+1) = 'm') then ( if (not(wa())) then return false else skip ) else skip ; if (n >= len or s->at(n+1) /= 'w') then return false else skip ; n := n + 1 ; return true ); operation run() : void pre: true post: true activity: ( s := sc.getCurrent() ; len := s->size() ; if (len = 0) then ( out.println("Cat") ; return ) else skip ; n := 0 ; if (wa() & n = len) then out.println("Cat") else out.println("Rabbit") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int N ; static String str ; static int[][] memo ; public static void main(String[] a){ str=sc.next(); N=str.length(); memo=new int[N+1][N+1]; System.out.println(rec(0,N)? "Cat" : "Rabbit"); } static boolean rec(int s,int e){ if(s==e)return true ; if(memo[s][e]!=0)return memo[s][e]==1 ? true : false ; if(str.charAt(s)!='m')return false ; if(str.charAt(e-1)!='w')return false ; boolean ret=false ; for(int i=s+1 ; isize() ; memo := Integer.subrange(1,N + 1)->collect(Integer.subrange(1,N + 1)->collect(0)) ; OclFile["System.out"].println(if rec(0, N) then "Cat" else "Rabbit" endif) ); static operation rec( s : int, e : int) : boolean pre: true post: true activity: ( if (s = e) then return true else skip ; if (memo[s+1][e+1] /= 0) then return if memo[s+1][e+1] = 1 then true else false endif else skip ; if (str->at(s+1) /= 'm') then return false else skip ; if (str->at(e - 1+1) /= 'w') then return false else skip ; var ret : boolean ; ret := false ; var i : int ; i := s + 1 ; while i < e - 1 do ( ( if (str->at(i+1) /= 'e') then continue else skip ; if (rec(s + 1, i) & rec(i + 1, e - 1)) then ( ret := true ; break ) else skip ) ; i := i + 1 ) ; memo[s+1][e+1] := if ret then 1 else -1 endif ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int xor_all_elements(int n){ switch(n & 3){ case 0 : return n ; case 1 : return 1 ; case 2 : return n+1 ; } return 0 ; } static VectorfindArray(int xorr[],int n){ Vectorarr=new Vector(); int xor_all=xor_all_elements(n); int xor_adjacent=0 ; for(int i=0 ; i=0 ; i--){ last_element=xorr[i] ^ last_element ; arr.add(last_element); } return arr ; } public static void main(String[] args){ Vectorarr=new Vector(); int xorr[]={ 7,5,3,7 }; int n=5 ; arr=findArray(xorr,n); for(int i=n-1 ; i>=0 ; i--){ System.out.print(arr.get(i)+" "); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation xor_all_elements( n : int) : int pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (n & 3) ; if _switchval = 0 then return n else skip ; if _switchval = 1 then return 1 else skip ; if _switchval = 2 then return n + 1 else skip ; ) return 0 ); static operation findArray( xorr : Sequence(int), n : int) : Sequence(int) pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{} ; var xor_all : int ; xor_all := xor_all_elements(n) ; var xor_adjacent : int ; xor_adjacent := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( xor_adjacent := MathLib.bitwiseXor(xor_adjacent,xorr[i+1]) ) ; i := i+(2) ) ; var last_element : int ; last_element := MathLib.bitwiseXor(xor_all,xor_adjacent) ; arr := arr->including(last_element) ; var i : int ; i := n - 2 ; while i >= 0 do ( ( last_element := xorr[i+1] xor last_element ; arr := arr->including(last_element) ) ; i := i - 1 ) ; return arr ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{} ; var xorr : Sequence(int) ; xorr := Sequence{7,5,3,7} ; var n : int ; n := 5 ; arr := findArray(xorr, n) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( OclFile["System.out"].print(arr->at(i+1) + " ") ) ; i := i - 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int mod=(int)(1e9+7); static long power(int p){ long res=1 ; for(int i=1 ; i<=p ; ++i){ res*=2 ; res %=mod ; } return res % mod ; } static long subset_square_sum(int A[]){ int n=A.length ; long ans=0 ; for(int i : A){ ans+=(1*i*i)% mod ; ans %=mod ; } return(1*ans*power(n-1))% mod ; } public static void main(String[] args){ int A[]={ 3,7 }; System.out.println(subset_square_sum(A)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute mod : int := (1e9 + 7)->oclAsType(int); static operation power( p : int) : long pre: true post: true activity: ( var res : long ; res := 1 ; var i : int ; i := 1 ; while i <= p do ( ( res := res*(2) ; res := res mod mod ) ; i := i + 1 ) ; return res mod mod ); static operation subset_square_sum( A : Sequence(int)) : long pre: true post: true activity: ( var n : int ; n := A->size() ; var ans : long ; ans := 0 ; for (i : A) do ( ( ans := ans+((1 * i * i) mod mod) ; ans := ans mod mod ) ) ; return (1 * ans * power(n - 1)) mod mod ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : Sequence(int) ; A := Sequence{3,7} ; OclFile["System.out"].println(subset_square_sum(A)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); UnionFindTree uft=new UnionFindTree(n); for(int i=0 ; icities=new HashSet<>(); int count=0 ; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var uft : UnionFindTree ; uft := UnionFindTree.newUnionFindTree(n) ; var i : int ; i := 0 ; while i < m do ( ( uft.unite(sc.getCurrent()->toInteger() - 1, sc.getCurrent()->toInteger() - 1) ) ; i := i + 1 ) ; var cities : Set(int) ; cities := Set{} ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := uft.find(i) ; if (i /= x) then ( cities := cities->including(x) ) else ( count := count + 1 ) ) ; i := i + 1 ) ; var cityCount : int ; cityCount := cities->size() ; var vilCount : int ; vilCount := count - cityCount ; OclFile["System.out"].println(if cityCount - vilCount < 0 then -(cityCount - vilCount) else cityCount - vilCount endif) ; ); static class UnionFindTree { attribute parents : Sequence(int); static operation newUnionFindTree( size : int) : UnionFindTree pre: true post: true activity: ( var self : UnionFindTree ; self := createUnionFindTree(); self.initialise(size); return self ); operation initialise( size : int) : void pre: true post: true activity: ( parents := Integer.subrange(1,size)->collect(0) ; var i : int ; i := 0 ; while i < size do ( ( parents[i+1] := i ) ; i := i + 1 ) ); operation find( x : int) : int pre: true post: true activity: ( if (parents[x+1] = x) then ( return x ) else ( return parents[x+1] ) ); operation unite( x : int, y : int) : void pre: true post: true activity: ( var xx : int ; xx := find(x) ; var yy : int ; yy := find(y) ; if (xx = yy) then ( return ) else skip ; parents[xx+1] := yy ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countDivisibles(int arr[],int n){ int res=0 ; for(int i=0 ; isize() ; OclFile["System.out"].print(countDivisibles(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static final MyScanner in=new MyScanner(); public static void main(String[] args){ long N=in.nextLong(); long M=in.nextLong(); long amari=N % M ; long ura=Math.abs(M-amari); System.out.println(Math.min(amari,ura)); } public static class MyScanner { Scanner sc=new Scanner(System.in); String next(){ return sc.next(); } int nextInt(){ return Integer.valueOf(sc.next()); } long nextLong(){ return Long.valueOf(sc.next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : MyScanner := MyScanner.newMyScanner(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : long ; N := in.nextLong() ; var M : long ; M := in.nextLong() ; var amari : long ; amari := N mod M ; var ura : long ; ura := if M - amari < 0 then -(M - amari) else M - amari endif ; OclFile["System.out"].println(Set{amari, ura}->min()) ; ); static class MyScanner { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation next() : String pre: true post: true activity: ( return sc.getCurrent() ); operation nextInt() : int pre: true post: true activity: ( return (sc.getCurrent())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (sc.getCurrent())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getsum(int x){ return(x*(x+1))/2 ; } static int countJumps(int n){ n=Math.abs(n); int ans=0 ; while(getsum(ans)0)ans++; return ans ; } public static void main(String args[]){ int n=9 ; System.out.println(countJumps(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getsum( x : int) : int pre: true post: true activity: ( return (x * (x + 1)) / 2 ); static operation countJumps( n : int) : int pre: true post: true activity: ( n := if n < 0 then -(n) else n endif ; var ans : int ; ans := 0 ; while (getsum(ans) < n or ((getsum(ans) - n) & 1) > 0) do ans := ans + 1 ; ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].println(countJumps(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ resolve(System.in,System.out); } static void resolve(InputStream is,PrintStream pw){ Scanner sc=new Scanner(is); BigInteger n=new BigInteger(sc.next()); BigInteger k=new BigInteger(sc.next()); BigInteger mod=n.mod(k); pw.println(mod.min(mod.add(k.negate()).abs())); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute resolve(OclFile["System.in"], OclFile["System.out"]) ); static operation resolve( is : OclFile, pw : OclFile) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(is) ; var n : long ; n := long(sc.getCurrent()) ; var k : long ; k := long(sc.getCurrent()) ; var mod : long ; mod := n.mod(k) ; pw.println(mod->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class Main { public static void main(String[] args)throws IOException { FastReader io=new FastReader(); long n=io.nextLong(),k=io.nextLong(); System.out.println(Math.min(n,Math.min(Math.abs(n-(n/k)*k),Math.abs(n-(n/k+1)*k)))); } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var io : FastReader ; io := FastReader.newFastReader() ; var n : long ; n := io.nextLong() ; var k : long ; k := io.nextLong() ; OclFile["System.out"].println(Set{n, Set{if n - (n / k) * k < 0 then -(n - (n / k) * k) else n - (n / k) * k endif, if n - (n / k + 1) * k < 0 then -(n - (n / k + 1) * k) else n - (n / k + 1) * k endif}->min()}->min()) ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.util.Arrays ; import java.util.Scanner ; import java.util.Stack ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(new BufferedInputStream(System.in)); long n=sc.nextLong(); long k=sc.nextLong(); n=n % k ; n=Math.min(n,Math.abs(n-k)); System.out.println(n); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : long ; n := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; n := n mod k ; n := Set{n, if n - k < 0 then -(n - k) else n - k endif}->min() ; OclFile["System.out"].println(n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import static java.lang.Math.min ; public class Main { public static void main(String[] args){ Scanner get=new Scanner(System.in); long n=get.nextLong(),k=get.nextLong(); System.out.println(Math.min((n % k),k-(n % k))); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var get : OclFile ; get := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := get.getCurrent()->toLong() ; var k : long ; k := get.getCurrent()->toLong() ; OclFile["System.out"].println(Set{(n mod k), k - (n mod k)}->min()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; class Item { int value,weight ; public Item(int value,int weight){ this.value=value ; this.weight=weight ; } public int getValue(){ return this.value ; } public int getWeight(){ return this.weight ; } } public class Main { static int N,W ; static int Nmax=105 ; static int Wmax=10005 ; static ArrayListitems=new ArrayList<>(); static int[][] C=new int[Nmax+1][Wmax+1]; public static int knapsack(){ int result=0 ; int maxVal=0 ; for(int i=1 ; i<=N ; i++){ for(int w=1 ; w<=W ; w++){ if(items.get(i).getWeight()<=w){ if(items.get(i).getValue()+C[i-1][w-items.get(i).getWeight()]>C[i-1][w]){ C[i][w]=items.get(i).getValue()+C[i-1][w-items.get(i).getWeight()]; } else { C[i][w]=C[i-1][w]; } } else { C[i][w]=C[i-1][w]; } } maxVal=C[N][W]; } return result=maxVal ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); N=sc.nextInt(); W=sc.nextInt(); Item padding=new Item(0,0); items.add(padding); for(int i=0 ; icollect(Integer.subrange(1,Wmax + 1)->collect(0)); static operation knapsack() : int pre: true post: true activity: ( var result : int ; result := 0 ; var maxVal : int ; maxVal := 0 ; var i : int ; i := 1 ; while i <= N do ( ( var w : int ; w := 1 ; while w <= W do ( ( if (items->at(i+1).getWeight() <= w) then ( if (items->at(i+1).getValue() + C[i - 1+1][w - items->at(i+1).getWeight()+1] > C[i - 1+1][w+1]) then ( C[i+1][w+1] := items->at(i+1).getValue() + C[i - 1+1][w - items->at(i+1).getWeight()+1] ) else ( C[i+1][w+1] := C[i - 1+1][w+1] ) ) else ( C[i+1][w+1] := C[i - 1+1][w+1] ) ) ; w := w + 1 ) ; maxVal := C[N+1][W+1] ) ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := sc.getCurrent()->toInteger() ; W := sc.getCurrent()->toInteger() ; var padding : Item ; padding := Item.newItem(0, 0) ; items := items->including(padding) ; var i : int ; i := 0 ; while i < N do ( ( var item : Item ; item := Item.newItem(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger()) ; items := items->including(item) ) ; i := i + 1 ) ; OclFile["System.out"].println(knapsack()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); AizuKnapsackNoRepetitions solver=new AizuKnapsackNoRepetitions(); solver.solve(1,in,out); out.close(); } static class AizuKnapsackNoRepetitions { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); int w=in.nextInt(); int[] vs=new int[n]; int[] ws=new int[n]; for(int i=0 ; i=ws[j-1]){ dp[i][j]=Math.max(dp[i][j],vs[j-1]+dp[i-ws[j-1] ][j-1]); } } } return dp[w][n]; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : AizuKnapsackNoRepetitions ; solver := AizuKnapsackNoRepetitions.newAizuKnapsackNoRepetitions() ; solver.solve(1, in, out) ; skip ; ); static class AizuKnapsackNoRepetitions { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var w : int ; w := in.getCurrent()->toInteger() ; var vs : Sequence(int) ; vs := Integer.subrange(1,n)->collect(0) ; var ws : Sequence(int) ; ws := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( vs[i+1] := in.getCurrent()->toInteger() ; ws[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; ); operation knapsack( w : int, vs : Sequence(int), ws : Sequence(int), n : int) : int pre: true post: true activity: ( var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,w + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 1 ; while i < w + 1 do ( ( var j : int ; j := 1 ; while j < n + 1 do ( ( dp[i+1][j+1] := dp[i+1][j - 1+1] ; if (i >= ws[j - 1+1]) then ( dp[i+1][j+1] := Set{dp[i+1][j+1], vs[j - 1+1] + dp[i - ws[j - 1+1]+1][j - 1+1]}->max() ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[w+1][n+1] ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new DPB().doIt(); } class DPB { int DP(int v[],int w[],int N,int W,int all[]){ int result=0 ; all[0]=1 ; for(int i=0 ; i=0 ; j--){ if(j+w[i]<=W){ if(all[j]>0){ if(all[0]==1)all[0]=0 ; all[j+w[i] ]=Math.max(all[j+w[i] ],all[j]+v[i]); all[0]=1 ; } if(result= 0 do ( ( if (j + w[i+1] <= W) then ( if (all[j+1] > 0) then ( if (all[0+1] = 1) then all[0+1] := 0 ; else skip ; all[j + w[i+1]+1] := Set{all[j + w[i+1]+1], all[j+1] + v[i+1]}->max() ; all[0+1] := 1 ) else skip ; if (result < all[j + w[i+1]+1]) then result := all[j + w[i+1]+1] ; else skip ) else skip ) ; j := j - 1 ) ) ; i := i + 1 ) ; return result ); operation doIt() : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; var W : int ; W := sc.getCurrent()->toInteger() ; var v : Sequence(int) ; v := Integer.subrange(1,N)->collect(0) ; var w : Sequence(int) ; w := Integer.subrange(1,N)->collect(0) ; var all : Sequence(int) ; all := Integer.subrange(1,W + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( v[i+1] := sc.getCurrent()->toInteger() ; w[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(DP(v, w, N, W, all)) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long modPower(long x,long y,long p){ long 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 ; } static long gcd(long a,long b){ if(b==0)return a ; return gcd(b,a % b); } static long gcdPow(long a,long n,long c){ if(a % c==0)return c ; long modexpo=modPower(a,n,c); return gcd(modexpo,c); } public static void main(String[] args){ long a=10248585,n=1000000,c=12564 ; System.out.println(gcdPow(a,n,c)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation modPower( x : long, y : long, p : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; x := x mod p ; while (y > 0) do ( if ((y & 1) > 0) then res := (res * x) mod p ; else skip ; y := (y/(2->pow(1)))->oclAsType(long) ; x := (x * x) mod p ) ; return res ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( if (b = 0) then return a else skip ; return gcd(b, a mod b) ); static operation gcdPow( a : long, n : long, c : long) : long pre: true post: true activity: ( if (a mod c = 0) then return c else skip ; var modexpo : long ; modexpo := modPower(a, n, c) ; return gcd(modexpo, c) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : long ; a := 10248585 ; var n : long ; n := 1000000 ; var c : long ; c := 12564 ; OclFile["System.out"].println(gcdPow(a, n, c)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader BR=new BufferedReader(new InputStreamReader(System.in)); String str=BR.readLine(); String[] arr=str.split("\\s+"); int an=Integer.parseInt(arr[0]); int mw=Integer.parseInt(arr[1]); int[] values=new int[an]; int[] weights=new int[an]; for(int i=0 ; isplit("\\s+") ; var an : int ; an := (arr[0+1])->toInteger() ; var mw : int ; mw := (arr[1+1])->toInteger() ; var values : Sequence(int) ; values := Integer.subrange(1,an)->collect(0) ; var weights : Sequence(int) ; weights := Integer.subrange(1,an)->collect(0) ; var i : int ; i := 0 ; while i < an do ( ( var temp : String ; temp := BR.readLine() ; var temparr : Sequence(String) ; temparr := temp->split("\\s+") ; var tv : int ; tv := (temparr[0+1])->toInteger() ; var tw : int ; tw := (temparr[1+1])->toInteger() ; values[i+1] := tv ; weights[i+1] := tw ; ) ; i := i + 1 ) ; var Vtable : Sequence(Sequence(int)) ; Vtable := Integer.subrange(1,an + 1)->collect(Integer.subrange(1,mw + 1)->collect(0)) ; var i : int ; i := 1 ; while i < an + 1 do ( ( var j : int ; j := 1 ; while j < mw + 1 do ( ( if (j < weights[i - 1+1]) then ( Vtable[i+1][j+1] := Vtable[i - 1+1][j+1] ) else ( Vtable[i+1][j+1] := Set{Vtable[i - 1+1][j - weights[i - 1+1]+1] + values[i - 1+1], Vtable[i - 1+1][j+1]}->max() ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Vtable[an+1][mw+1]) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int i,j,n,w ; int[] v,vv ; int[][] dp ; n=sc.nextInt(); w=sc.nextInt(); v=new int[n]; vv=new int[n]; dp=new int[n+1][w+1]; for(i=0 ; idp[i+1][j+vv[i] ])dp[i+1][j+vv[i] ]=dp[i][j]+v[i]; } out.println(dp[n][w]); sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var i : int ; var j : int ; var n : int ; var w : int ; var v : Sequence(int) ; var vv : Sequence(int) ; var dp : Sequence(Sequence(int)) ; n := sc.nextInt() ; w := sc.nextInt() ; v := Integer.subrange(1,n)->collect(0) ; vv := Integer.subrange(1,n)->collect(0) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,w + 1)->collect(0)) ; i := 0 ; while i < n do ( ( v[i+1] := sc.nextInt() ; vv[i+1] := sc.nextInt() ) ; i := i + 1 ) ; i := 0 ; while i < n do ( j := 0 ; while j <= w do ( ( if (dp[i + 1+1][j+1] < dp[i+1][j+1]) then dp[i + 1+1][j+1] := dp[i+1][j+1] ; else skip ; if (j + vv[i+1] <= w & dp[i+1][j+1] + v[i+1] > dp[i + 1+1][j + vv[i+1]+1]) then dp[i + 1+1][j + vv[i+1]+1] := dp[i+1][j+1] + v[i+1] ; else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; out.println(dp[n+1][w+1]) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=10 ; static int lcs(int[][][] dp,int[] arr1,int n,int[] arr2,int m,int k){ if(k<0)return-10000000 ; if(n<0 || m<0)return 0 ; int ans=dp[n][m][k]; if(ans!=-1)return ans ; try { ans=Math.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=Math.max(ans,1+lcs(dp,arr1,n-1,arr2,m-1,k)); ans=Math.max(ans,1+lcs(dp,arr1,n-1,arr2,m-1,k-1)); } catch(Exception e){ } return ans ; } public static void main(String[] args){ int k=1 ; int[] arr1={ 1,2,3,4,5 }; int[] arr2={ 5,3,1,4,2 }; int n=arr1.length ; int m=arr2.length ; int[][][] dp=new int[MAX][MAX][MAX]; for(int i=0 ; imax() ; 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, 1 + lcs(dp, arr1, n - 1, arr2, m - 1, k - 1)}->max() ) catch (e : ProgramException) do skip return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 1 ; var arr1 : Sequence(int) ; arr1 := Sequence{1,2,3,4,5} ; var arr2 : Sequence(int) ; arr2 := Sequence{5,3,1,4,2} ; var n : int ; n := arr1->size() ; var m : int ; m := arr2->size() ; var dp : Sequence(Sequence(Sequence(int))) ; dp := Integer.subrange(1,MAX)->collect(Integer.subrange(1,MAX)->collect(Integer.subrange(1,MAX)->collect(0))) ; var i : int ; i := 0 ; while i < MAX do ( var j : int ; j := 0 ; while j < MAX do ( var l : int ; l := 0 ; while l < MAX do ( dp[i+1][j+1][l+1] := -1 ; ; l := l + 1 ) ; ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(lcs(dp, arr1, n, arr2, m, k)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int reverse(int n){ int d=0,s=0 ; while(n>0){ d=n % 10 ; s=s*10+d ; n=n/10 ; } return s ; } static boolean isPalin(int n){ return n==reverse(n); } static int sumOfArray(int[] arr,int n){ int s=0 ; for(int i=0 ; i10)&& isPalin(arr[i])){ s+=arr[i]; } } return s ; } public static void main(String[] args){ int n=6 ; int[] arr={ 12,313,11,44,9,1 }; System.out.println(sumOfArray(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation reverse( n : int) : int pre: true post: true activity: ( var d : int ; d := 0 ; var s : int ; s := 0 ; while (n > 0) do ( d := n mod 10 ; s := s * 10 + d ; n := n / 10 ) ; return s ); static operation isPalin( n : int) : boolean pre: true post: true activity: ( return n = reverse(n) ); static operation sumOfArray( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var s : int ; s := 0 ; var i : int ; i := 0 ; while i < n do ( ( if ((arr[i+1] > 10) & isPalin(arr[i+1])) then ( s := s+(arr[i+1]) ) else skip ) ; i := i + 1 ) ; return s ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var arr : Sequence(int) ; arr := Sequence{12,313,11,44,9,1} ; OclFile["System.out"].println(sumOfArray(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int assignValue(int a,int b,int x){ int arr[]={ a,b }; return(arr[x]); } public static void main(String[] args){ int y=assignValue(3,7,0); System.out.println(y); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation assignValue( a : int, b : int, x : int) : int pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{a,b} ; return (arr[x+1]) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var y : int ; y := assignValue(3, 7, 0) ; OclFile["System.out"].println(y) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Vector ; class Test { static void printDivisors(int n){ Vectorv=new Vector<>(); for(int i=1 ; i<=Math.sqrt(n); i++){ if(n % i==0){ if(n/i==i)System.out.printf("%d ",i); else { System.out.printf("%d ",i); v.add(n/i); } } } for(int i=v.size()-1 ; i>=0 ; i--)System.out.printf("%d ",v.get(i)); } public static void main(String args[]){ System.out.println("The divisors of 100 are: "); printDivisors(100); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation printDivisors( n : int) : void pre: true post: true activity: ( var v : Sequence(int) ; v := Sequence{} ; var i : int ; i := 1 ; while i <= (n)->sqrt() do ( ( if (n mod i = 0) then ( if (n / i = i) then OclFile["System.out"].printf("%d ", i) ; else ( OclFile["System.out"].printf("%d ", i) ; v := v->including(n / i) ) ) else skip ) ; i := i + 1 ) ; var i : int ; i := v->size() - 1 ; while i >= 0 do ( OclFile["System.out"].printf("%d ", v->at(i+1)) ; ; i := i - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println("The divisors of 100 are: ") ; execute printDivisors(100) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static long n,d ; public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int test=in.nextInt(); for(int t=1 ; t<=test ; t++){ n=in.nextInt(); d=in.nextInt(); long min=bs(0,n); pw.println(min<=n ? "YES" : "NO"); } pw.close(); } static long bs(long l,long r){ long mid,res=cal(l); while(l<=r){ mid=(l+r)/2 ; if(cal(mid)toInteger() ; var t : int ; t := 1 ; while t <= test do ( ( n := in.getCurrent()->toInteger() ; d := in.getCurrent()->toInteger() ; var min : long ; min := bs(0, n) ; skip ) ; t := t + 1 ) ; skip ; ); static operation bs( l : long, r : long) : long pre: true post: true activity: ( var mid : long ; var res : long ; res := cal(l) ; while (l <= r) do ( mid := (l + r) / 2 ; if (cal(mid) < res) then ( res := cal(mid) ; l := mid + 1 ) else ( r := mid - 1 ) ) ; return res ); static operation cal( x : long) : long pre: true post: true activity: ( return x + (d / (x + 1)) + (if d mod (x + 1) /= 0 then 1 else 0 endif) ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean divisibleBy3(String number){ int sumOfDigit=0 ; for(int i=0 ; isize() do ( sumOfDigit := sumOfDigit+(number->at(i+1) - ('0')->char2byte()) ; ; i := i + 1 ) ; if (sumOfDigit mod 3 = 0) then return true else skip ; return false ); static operation divisibleBy25( number : String) : boolean pre: true post: true activity: ( if (number->size() < 2) then return false else skip ; var length : int ; length := number->size() ; var lastTwo : int ; lastTwo := (number->at(length - 2+1) - ('0')->char2byte()) * 10 + (number->at(length - 1+1) - ('0')->char2byte()) ; if (lastTwo mod 25 = 0) then return true else skip ; return false ); static operation divisibleBy75( number : String) : boolean pre: true post: true activity: ( if (divisibleBy3(number) & divisibleBy25(number)) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var number : String ; number := "754586672150" ; var divisible : boolean ; divisible := divisibleBy75(number) ; if (divisible) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] num ; int sum ; do { sum=0 ; num=br.readLine().split(""); for(String str : num)sum+=Integer.valueOf(str); if(sum==0)break ; System.out.println(sum); } while(true); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var num : Sequence(String) ; var sum : int ; while true do (( sum := 0 ; num := br.readLine()->split("") ; for (str : num) do ( sum := sum+((str)->toInteger()) ; ) ; if (sum = 0) then break else skip ; OclFile["System.out"].println(sum) ; ) ; if (true) then skip else break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ FastReader f=new FastReader(); while(true){ String line=f.nextLine(); int lineTemp=0 ; if(line.equals("0"))break ; for(char ch : line.toCharArray()){ lineTemp+=Integer.parseInt(String.valueOf(ch)); } System.out.println(lineTemp); } } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var f : FastReader ; f := FastReader.newFastReader() ; while (true) do ( var line : String ; line := f.nextLine() ; var lineTemp : int ; lineTemp := 0 ; if (line = "0") then break else skip ; for (ch : line->characters()) do ( ( lineTemp := lineTemp+((((ch) + ""))->toInteger()) ) ) ; OclFile["System.out"].println(lineTemp) ; ) ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static boolean EqualNumber(int A,int B){ if((A ^ B)!=0)return true ; else return false ; } public static void main(String args[]){ int A=5,B=6 ; if(EqualNumber(A,B)==false)System.out.println(1); else System.out.println(0); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation EqualNumber( A : int, B : int) : boolean pre: true post: true activity: ( if ((A xor B) /= 0) then return true else return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 5 ; var B : int ; B := 6 ; if (EqualNumber(A, B) = false) then OclFile["System.out"].println(1) ; else OclFile["System.out"].println(0) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner scan=new Scanner(System.in); public static void main(String[] args){ for(; scan.hasNext(); ){ int sum=0 ; char[] swap=scan.nextLine().toCharArray(); for(int i=0 ; icharacters() ; var i : int ; i := 0 ; while i < swap->size() do ( ( sum := sum + ("" + swap[i+1])->toInteger() ) ; i := i + 1 ) ; if (sum /= 0) then ( OclFile["System.out"].println(sum) ) else ( break ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.text.DecimalFormat ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); double N=scan.nextDouble(); double d=scan.nextDouble(); double x=scan.nextDouble(); BigDecimal ans=new BigDecimal("0.0"); while(N>0.5){ BigDecimal adnum=BigDecimal.valueOf(d+x*(N-0.5)); ans=ans.add(adnum); d=(N+1.0)*d/N+(5.0*x)/(2.0*N); x=(1.0+(2.0/N))*x ; --N ; } DecimalFormat format=new DecimalFormat("#.#"); format.setMinimumFractionDigits(20); System.out.println(format.format(ans)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : double ; N := scan.getCurrent()->toReal() ; var d : double ; d := scan.getCurrent()->toReal() ; var x : double ; x := scan.getCurrent()->toReal() ; var ans : double ; ans := double("0.0") ; while (N > 0.5) do ( var adnum : double ; adnum := (d + x * (N - 0.5) + "")->toReal() ; ans := ans->excludes(adnum) ; d := (N + 1.0) * d / N + (5.0 * x) / (2.0 * N) ; x := (1.0 + (2.0 / N)) * x ; N := N - 1 ; ) ; var format : DecimalFormat ; format := DecimalFormat.newDecimalFormat("#.#") ; format.setMinimumFractionDigits(20) ; OclFile["System.out"].println(format.format(ans)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class Main { public static final String EOL=System.getProperty("line.separator"); public void exec()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); while(true){ String l=br.readLine(); if(l.equals("0"))break ; int sum=0 ; for(char c : l.toCharArray()){ sum+=c ; } out.println(sum-('0'*l.length())); } out.flush(); } public static void main(String[] args)throws IOException { new Main().exec(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute EOL : String := OclProcess.getEnvironmentProperty("line.separator"); operation exec() : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; while (true) do ( var l : String ; l := br.readLine() ; if (l = "0") then break else skip ; var sum : int ; sum := 0 ; for (c : l->characters()) do ( ( sum := sum+(c) ) ) ; skip ; ) ; skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().exec() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); ArrayListlines=new ArrayList(); int c=0 ; while(true){ String next=sc.nextLine(); if(next.equals("0")){ break ; } lines.add(next); c++; } for(int i=0 ; iincluding(next) ; c := c + 1 ) ; var i : int ; i := 0 ; while i < c do ( ( var s : String ; s := lines->at(i+1) ; var sum : int ; sum := 0 ; var j : int ; j := 0 ; while j < s->size() do ( ( var in : int ; in := (s.subrange(j+1,j + 1))->toInteger() ; sum := sum+(in) ) ; j := j + 1 ) ; OclFile["System.out"].println(sum) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; class GFG { static int Modulo(int a,char b[]){ int mod=0 ; for(int i=0 ; isize() do ( mod := (mod * 10 + b[i+1] - ('0')->char2byte()) mod a ; ; i := i + 1 ) ; return mod ); static operation LastDigit( a : Sequence(String), b : Sequence(String)) : int pre: true post: true activity: ( var len_a : int ; len_a := a->size() ; var len_b : int ; len_b := b->size() ; if (len_a = 1 & len_b = 1 & b[0+1] = '0' & a[0+1] = '0') then return 1 else skip ; if (len_b = 1 & b[0+1] = '0') then return 1 else skip ; if (len_a = 1 & a[0+1] = '0') then return 0 else skip ; var exp : int ; exp := if (Modulo(4, b) = 0) then 4 else Modulo(4, b) endif ; var res : int ; res := (a[len_a - 1+1] - ('0')->char2byte()->pow(exp))->oclAsType(int) ; return res mod 10 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(String) ; a := "117"->characters() ; var b : Sequence(void) ; b := Sequence{'3'} ; OclFile["System.out"].println(LastDigit(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { public static void main(String args[]){ double r=3 ; double R=7 ; float pi=(float)3.14159 ; double Volume=0 ; Volume=2*pi*pi*R*r*r ; System.out.printf("Volume: %f",Volume); double Surface=4*pi*pi*R*r ; System.out.printf("\nSurface: %f",Surface); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : double ; r := 3 ; var R : double ; R := 7 ; var pi : double ; pi := 3.14159->oclAsType(double) ; var Volume : double ; Volume := 0 ; Volume := 2 * pi * pi * R * r * r ; OclFile["System.out"].printf("Volume: %f", Volume) ; var Surface : double ; Surface := 4 * pi * pi * R * r ; OclFile["System.out"].printf("\nSurface: %f", Surface) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int p=sc.nextInt(); int q=sc.nextInt(); double r=sc.nextInt(); int dis=b*p-(b-a)*q ; System.out.println(dis/(q+r)+b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var p : int ; p := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var r : double ; r := sc.getCurrent()->toInteger() ; var dis : int ; dis := b * p - (b - a) * q ; OclFile["System.out"].println(dis / (q + r) + b) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); double a=sc.nextInt(); double b=sc.nextInt(); double p=sc.nextInt(); double q=sc.nextInt(); double r=sc.nextInt(); if(a>b){ System.out.println((b*p+q*(a-b))/(q+r)+b); } else { System.out.println((b*p-q*(b-a))/(q+r)+b); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : double ; a := sc.getCurrent()->toInteger() ; var b : double ; b := sc.getCurrent()->toInteger() ; var p : double ; p := sc.getCurrent()->toInteger() ; var q : double ; q := sc.getCurrent()->toInteger() ; var r : double ; r := sc.getCurrent()->toInteger() ; if (a > b) then ( OclFile["System.out"].println((b * p + q * (a - b)) / (q + r) + b) ) else ( OclFile["System.out"].println((b * p - q * (b - a)) / (q + r) + b) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int N=scan.nextInt(); long[] sum=new long[N]; long[] a=new long[N]; long[] abssum=new long[N+1]; ListminusIndex=new ArrayList<>(); for(int i=0 ; i=0 ; --i)abssum[i]=abssum[i+1]+a[i]; long ans=sum[N-1]; for(int i=0 ; itoInteger() ; var sum : Sequence(long) ; sum := Integer.subrange(1,N)->collect(0) ; var a : Sequence(long) ; a := Integer.subrange(1,N)->collect(0) ; var abssum : Sequence(long) ; abssum := Integer.subrange(1,N + 1)->collect(0) ; var minusIndex : Sequence(int) ; minusIndex := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( if (i = 0) then ( a[i+1] := scan.getCurrent()->toLong() ; sum[i+1] := a[i+1] ) else ( var minus : boolean ; minus := (scan.getCurrent() = "-") ; a[i+1] := scan.getCurrent()->toLong() ; sum[i+1] := sum[i - 1+1] + a[i+1] * (if minus then -1 else 1 endif) ; if (minus) then minusIndex := minusIndex->including(i - 1) ; else skip ) ) ; i := i + 1 ) ; var i : int ; i := N - 1 ; while i >= 0 do ( abssum[i+1] := abssum[i + 1+1] + a[i+1] ; ; i := i - 1 ) ; var ans : long ; ans := sum[N - 1+1] ; var i : int ; i := 0 ; while i < minusIndex->size() - 1 do ( ( ans := Set{ans, sum[minusIndex->at(i+1)+1] - abssum[minusIndex->at(i+1) + 1+1] + 2 * abssum[minusIndex->at(i + 1+1) + 1+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { private void solve()throws IOException { int n=nextInt(); long[] a=new long[n]; char[] c=new char[n]; c[0]='+' ; for(int i=0 ; i0){ c[i]=next().charAt(0); } a[i]=nextInt(); } long s=0 ; long ss=0 ; long ans=0 ; for(int i=n-1 ; i>=0 ; i--){ if(c[i]=='+'){ s+=a[i]; } else { ans=Math.max(-a[i]+s+ans,-a[i]-s+ss); ss+=s+a[i]; s=0 ; } } ans+=s ; out.println(ans); } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st ; PrintWriter out=new PrintWriter(System.out); String next()throws IOException { while(st==null || ! st.hasMoreTokens()){ st=new StringTokenizer(br.readLine()); } return st.nextToken(); } int nextInt()throws IOException { return Integer.parseInt(next()); } public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { solve(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var n : int ; n := nextInt() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var c : Sequence(String) ; c := Integer.subrange(1,n)->collect(0) ; c[0+1] := '+' ; var i : int ; i := 0 ; while i < n do ( ( if (i > 0) then ( c[i+1] := next()->at(0+1) ) else skip ; a[i+1] := nextInt() ) ; i := i + 1 ) ; var s : long ; s := 0 ; var ss : long ; ss := 0 ; var ans : long ; ans := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (c[i+1] = '+') then ( s := s+(a[i+1]) ) else ( ans := Set{-a[i+1] + s + ans, -a[i+1] - s + ss}->max() ; ss := ss+(s + a[i+1]) ; s := 0 ) ) ; i := i - 1 ) ; ans := ans+(s) ; out.println(ans) ; ); attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator; attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( execute solve() ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CF_Round_264B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int s=sc.nextInt(); int[] arr=new int[s]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,s)->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute solve(arr) ; ); static operation solve( arr : Sequence(int)) : void pre: true post: true activity: ( var peak : int ; peak := 0 ; var currentEnergy : int ; currentEnergy := 0 ; var i : int ; i := 1 ; while i < arr->size() do ( ( currentEnergy := currentEnergy+(arr[i - 1+1] - arr[i+1]) ; if (currentEnergy < 0) then ( peak := Set{currentEnergy, peak}->min() ) else skip ) ; i := i + 1 ) ; var res : int ; res := arr[0+1] - peak ; OclFile["System.out"].println(res) ; ); } 64B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : int ; s := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,s)->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute solve(arr) ; ); static operation solve( arr : Sequence(int)) : void pre: true post: true activity: ( var peak : int ; peak := 0 ; var currentEnergy : int ; currentEnergy := 0 ; var i : int ; i := 1 ; while i < arr->size() do ( ( currentEnergy := currentEnergy+(arr[i - 1+1] - arr[i+1]) ; if (currentEnergy < 0) then ( peak := Set{currentEnergy, peak}->min() ) else skip ) ; i := i + 1 ) ; var res : int ; res := arr[0+1] - peak ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Scanner s=new Scanner(System.in); while(true){ String in=s.next(); if(in.equals("#"))System.exit(0); String[] str=in.split("\\|"); boolean ok=false ; for(int i=0 ; isplit("\\|") ; var ok : boolean ; ok := false ; var i : int ; i := 0 ; while i < str->size() do ( ( var now : String ; now := str[i+1].subrange(1+1,str[i+1]->size() - 1) ; var tmp : Sequence(String) ; tmp := now->split("\\&") ; var OK : boolean ; OK := true ; var j : int ; j := 0 ; while j < tmp->size() do ( var k : int ; k := 0 ; while k < tmp->size() do ( ( if (tmp[k+1] = "~" + tmp[j+1]) then OK := false ; else skip ) ; k := k + 1 ) ; ; j := j + 1 ) ; if (OK) then ok := true ; else skip ; ) ; i := i + 1 ) ; if (ok) then OclFile["System.out"].println("yes") else OclFile["System.out"].println("no") ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int N=3 ; static int MaxTraceSub(int mat[][]){ int max_trace=0 ; for(int i=0 ; imax() ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return max_trace ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{10,2,5},Sequence{6,10,4},Sequence{2,7,-10}} ; OclFile["System.out"].println(MaxTraceSub(mat)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.BigInteger ; public class Main { static long[] list=new long[87]; public static void main(String[] args){ Scanner sc=new Scanner(System.in); String nyuA=sc.nextLine(); int N=Integer.parseInt(nyuA); TreeSetlist=new TreeSet<>(); for(int i=0 ; iset=new ArrayList<>(list); System.out.println(set.size()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute list : Sequence(long) := Integer.subrange(1,87)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var nyuA : String ; nyuA := sc.nextLine() ; var N : int ; N := (nyuA)->toInteger() ; var list : Set(int) ; list := Set{} ; var i : int ; i := 0 ; while i < N do ( ( list := list->including((sc.nextLine())->toInteger()) ) ; i := i + 1 ) ; var set : Sequence(int) ; set := Sequence{}->union(list) ; OclFile["System.out"].println(set->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.List ; import java.util.Scanner ; import java.util.concurrent.SynchronousQueue ; public class Main { public static void main(String[] args){ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int d=sc.nextInt(); int x=sc.nextInt(); double[] F=new double[200001]; double[] G=new double[200001]; { Arrays.fill(F,-1); Arrays.fill(G,-1); } F[1]=0.5 ; G[1]=1 ; for(int i=2 ; i<=200000 ; ++i){ F[i]=(1+2./i)*F[i-1]+5./(2*i)*G[i-1]+1./(2*i)*i*(2*i-1); G[i]=(1+1./i)*G[i-1]+1 ; } System.out.println(String.format("%.20f",F[n]*x+d*G[n])); } public static void tr(Object...objects){ System.out.println(Arrays.deepToString(objects)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var F : Sequence(double) ; F := Integer.subrange(1,200001)->collect(0.0) ; var G : Sequence(double) ; G := Integer.subrange(1,200001)->collect(0.0) ; ( F := F->collect(-1) ; G := G->collect(-1) ) F[1+1] := 0.5 ; G[1+1] := 1 ; var i : int ; i := 2 ; while i <= 200000 do ( ( F[i+1] := (1 + 2. / i) * F[i - 1+1] + 5. / (2 * i) * G[i - 1+1] + 1. / (2 * i) * i * (2 * i - 1) ; G[i+1] := (1 + 1. / i) * G[i - 1+1] + 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(StringLib.format("%.20f",Sequence{F[n+1] * x + d * G[n+1]})) ; ); static operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] h=new int[n]; int temp=0 ; for(int i=0 ; itemp){ temp=h[i]; } } System.out.println(temp); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var temp : int ; temp := 0 ; var i : int ; i := 0 ; while i < n do ( ( h[i+1] := in.getCurrent()->toInteger() ; if (h[i+1] > temp) then ( temp := h[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(temp) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; public class A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; i{ public int compare(Pair a,Pair b){ return b.b-a.b ; } } class Pair { int a ; int b ; public Pair(int a,int b){ this.a=a ; this.b=b ; } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : int ; ans := arr[0+1] ; var curr : int ; curr := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( curr := curr+(arr[i+1] - arr[i + 1+1]) ; if (curr < 0) then ( ans := ans+(if curr < 0 then -(curr) else curr endif) ; curr := 0 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } class Sort implements Function(,(,boolean)) { operation compare( a : Map, b : Map) : int pre: true post: true activity: ( return b.b - a.b ); } class Pair { attribute a : int; attribute b : int; static operation newPair( a : int, b : int) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( self.a := a ; self.b := b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; import java.util.Vector ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int[] arr=new int[n]; for(int i=0 ; iarr[i])arr[i]+=arr[i-1]-arr[i]; else continue ; } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; var count : int ; count := arr[0+1] ; var i : int ; i := 1 ; while i < n do ( ( if (arr[i - 1+1] < arr[i+1]) then count := count+(arr[i+1] - arr[i - 1+1]) ; else if (arr[i - 1+1] > arr[i+1]) then arr[i+1] := arr[i+1]+(arr[i - 1+1] - arr[i+1]) else continue ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MyClass { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n+1]; arr[0]=0 ; int ans=0 ; int energy=0 ; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); energy+=arr[i-1]-arr[i]; if(energy<0){ ans-=energy ; energy=0 ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class MyClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; arr[0+1] := 0 ; var ans : int ; ans := 0 ; var energy : int ; energy := 0 ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; energy := energy+(arr[i - 1+1] - arr[i+1]) ; if (energy < 0) then ( ans := ans-(energy) ; energy := 0 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _1047A_LittelCLoves3 { public static void main(String[] args){ Scanner input=new Scanner(System.in); final int num=input.nextInt(); int a=1 ; int b=1 ; int c=num-2 ; if(c % 3==0){ c--; a++; } System.out.println(String.format("%d %d %d",a,b,c)); } } ------------------------------------------------------------ OCL File: --------- class _1047A_LittelCLoves3 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var num : int ; num := input.getCurrent()->toInteger() ; var a : int ; a := 1 ; var b : int ; b := 1 ; var c : int ; c := num - 2 ; if (c mod 3 = 0) then ( c := c - 1 ; a := a + 1 ) else skip ; OclFile["System.out"].println(StringLib.format("%d %d %d",Sequence{a,b,c})) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class HelloWorld { public static void solve(int n,int m,int k){ System.out.println((n<=m && n<=k ? "Yes" : "No")); } public static void sol(int n){ int ans=0 ; for(int i=1 ; itoInteger() ; if ((n - 2) mod 3 = 0) then ( OclFile["System.out"].println("1 2 " + (n - 3)) ) else ( OclFile["System.out"].println("1 1 " + (n - 2)) ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B_Average_Sleep_Time { static Scanner in=new Scanner(System.in); static int n ; static double k ; static double a[]; public static void main(String[] amit){ n=in.nextInt(); k=in.nextDouble(); a=new double[n+1]; for(int i=1 ; i<=n ; i++){ a[i]=in.nextDouble(); } if(n==1){ System.out.printf("%.6f",a[1]); return ; } double prefix[]=new double[n+1]; for(int i=1 ; i<=n ; i++){ prefix[i]=prefix[i-1]+a[i]; } double sum=0.0 ; double pair=0.0 ; for(int i=(int)k ; i<=n ; i++,pair++){ sum+=(prefix[i]-prefix[i-(int)k]); } System.out.printf("%.6f",sum/pair); } } ------------------------------------------------------------ OCL File: --------- class B_Average_Sleep_Time { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute n : int; static attribute k : double; static attribute a : Sequence(double); static operation main( amit : Sequence(String)) : void pre: true post: true activity: ( n := in.getCurrent()->toInteger() ; k := in.getCurrent()->toReal() ; a := Integer.subrange(1,n + 1)->collect(0.0) ; var i : int ; i := 1 ; while i <= n do ( ( a[i+1] := in.getCurrent()->toReal() ) ; i := i + 1 ) ; if (n = 1) then ( OclFile["System.out"].printf("%.6f", a[1+1]) ; return ) else skip ; var prefix : Sequence(double) ; prefix := Integer.subrange(1,n + 1)->collect(0.0) ; var i : int ; i := 1 ; while i <= n do ( ( prefix[i+1] := prefix[i - 1+1] + a[i+1] ) ; i := i + 1 ) ; var sum : double ; sum := 0.0 ; var pair : double ; pair := 0.0 ; var i : int ; i := k->oclAsType(int) ; while i <= n do ( ( sum := sum+((prefix[i+1] - prefix[i - k->oclAsType(int)+1])) ) ; i := i + 1 ; pair := pair + 1 ) ; OclFile["System.out"].printf("%.6f", sum / pair) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Locale ; import java.util.Scanner ; public class B808 { public static void main(String[] args){ Locale.setDefault(Locale.US); Scanner in=new Scanner(System.in); int N=in.nextInt(); int K=in.nextInt(); double sum=0 ; for(int n=1 ; n<=N ; n++){ int a=in.nextInt(); double count=Math.min(Math.min(n,N+1-n),Math.min(K,N-K+1)); sum+=a*count ; } sum/=N-K+1 ; System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class B808 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Locale.setDefault(Locale.US) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var sum : double ; sum := 0 ; var n : int ; n := 1 ; while n <= N do ( ( var a : int ; a := in.getCurrent()->toInteger() ; var count : double ; count := Set{Set{n, N + 1 - n}->min(), Set{K, N - K + 1}->min()}->min() ; sum := sum+(a * count) ) ; n := n + 1 ) ; sum := sum/(N - K + 1) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean oppositeSigns(int x,int y){ return((x ^ y)<0); } static void partitionNegPos(int arr[],int n){ Vectora=new Vector(); Vectorb=new Vector(); a.add(arr[0]); for(int i=1 ; iincluding(arr[0+1]) ; var i : int ; i := 1 ; while i < n do ( ( if (oppositeSigns(a->at(0+1), arr[i+1])) then b := b->including(arr[i+1]) ; else a := a->including(arr[i+1]) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < a->size() do ( OclFile["System.out"].print(a->at(i+1) + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println("") ; var i : int ; i := 0 ; while i < b->size() do ( OclFile["System.out"].print(b->at(i+1) + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,-2,6,-7,8} ; var n : int ; n := arr->size() ; execute partitionNegPos(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.List ; import java.util.Scanner ; import java.util.concurrent.SynchronousQueue ; public class Main { public static void main(String[] args){ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int d=sc.nextInt(); int x=sc.nextInt(); double[] F=new double[200001]; double[] G=new double[200001]; { Arrays.fill(F,-1); Arrays.fill(G,-1); } F[1]=0.5 ; G[1]=1 ; for(int i=2 ; i<=200000 ; ++i){ F[i]=(1+2./i)*F[i-1]+5./(2*i)*G[i-1]+1./(2*i)*i*(2*i-1); G[i]=(1+1d/i)*G[i-1]+1 ; } System.out.println(String.format("%.20f",F[n]*x+d*G[n])); } public static void tr(Object...objects){ System.out.println(Arrays.deepToString(objects)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var x : int ; x := sc.getCurrent()->toInteger() ; var F : Sequence(double) ; F := Integer.subrange(1,200001)->collect(0.0) ; var G : Sequence(double) ; G := Integer.subrange(1,200001)->collect(0.0) ; ( F := F->collect(-1) ; G := G->collect(-1) ) F[1+1] := 0.5 ; G[1+1] := 1 ; var i : int ; i := 2 ; while i <= 200000 do ( ( F[i+1] := (1 + 2. / i) * F[i - 1+1] + 5. / (2 * i) * G[i - 1+1] + 1. / (2 * i) * i * (2 * i - 1) ; G[i+1] := (1 + 1d / i) * G[i - 1+1] + 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(StringLib.format("%.20f",Sequence{F[n+1] * x + d * G[n+1]})) ; ); static operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { private static char[] expr ; private static int ptr ; private static void consume(char c){ assert expr[ptr]==c : "expected "+c+",but got "+expr[ptr]; ptr++; } private static boolean expression(){ do { consume('('); if(clause()){ consume(')'); return true ; } else { consume(')'); } } while(ptrsize() & expr[ptr+1] = '|') then skip else break) ; assert ptr = expr->size() ; return false ); static operation clause() : boolean pre: true post: true activity: ( var assigments : Sequence(int) ; assigments := Integer.subrange(1,'z' + 1)->collect(0) ; var result : boolean ; result := true ; while true do (( if (not(literal(assigments))) then ( result := false ) else skip ) ; if (expr[ptr+1] = '&') then skip ; skip else break) ; ptr := ptr - 1 ; return result ); static operation literal( assigments : Sequence(int)) : boolean pre: true post: true activity: ( var x : int ; if (expr[ptr+1] = '~') then ( ptr := ptr + 1 ; x := 1 ) else ( x := -1 ) ; if (assigments[expr[ptr+1]+1] = x) then ( ptr := ptr + 1 ; return false ) else ( assigments[expr[ptr+1]+1] := -1 * x ; ptr := ptr + 1 ; return true ) ); static operation solve() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var input : String ; input := scanner.getCurrent() ; if (input = "#") then ( break ) else skip ; Main.ptr := 0 ; Main.expr := input->characters() ; OclFile["System.out"].println(if expression() then "yes" else "no" endif) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String args[]){ Solve s=new Solve(); s.solve(); } } class Solve { Scanner in=new Scanner(System.in); void solve(){ while(in.hasNext()){ int n=in.nextInt(); int ans=0,t=1 ; for(int i=0 ; itoInteger() ; var ans : int ; ans := 0 ; var t : int ; t := 1 ; var i : int ; i := 0 ; while i < n / 2 do ( ( ans := ans+(t) ; t := t*(3) ) ; i := i + 1 ) ; ans := ans*(2) ; if (n mod 2 = 1) then ans := ans+(t) ; else skip ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args){ BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); try { String line ; while((line=r.readLine())!=null){ int n=Integer.parseInt(line); if(n==1 || n==2){ System.out.println(n); continue ; } int size=0,weight=4 ; if(n % 2==1){ size=1 ; for(int i=3 ; i<=n ; i+=2){ size+=weight ; weight*=3 ; } } else { size=2 ; weight=6 ; for(int i=4 ; i<=n ; i+=2){ size+=weight ; weight*=3 ; } } System.out.println(size); } } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var line : String ; line := r.readLine() ; while ((line) /= null) do ( skip ; ( var n : int ; n := (line)->toInteger() ; if (n = 1 or n = 2) then ( OclFile["System.out"].println(n) ; continue ) else skip ; var size : int ; size := 0 ; var weight : int ; weight := 4 ; if (n mod 2 = 1) then ( size := 1 ; var i : int ; i := 3 ; while i <= n do ( ( size := size+(weight) ; weight := weight*(3) ) ; i := i+(2) ) ) else ( size := 2 ; weight := 6 ; var i : int ; i := 4 ; while i <= n do ( ( size := size+(weight) ; weight := weight*(3) ) ; i := i+(2) ) ) ; OclFile["System.out"].println(size) ; ) ; line := r.readLine() ; ) ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); int[] dp=new int[31]; dp[1]=1 ; dp[2]=2 ; int sum=0 ; for(int i=3 ; i<=30 ; i+=2){ sum+=Math.pow(3,(i-3)/2); dp[i]=1+4*sum ; } sum=0 ; for(int i=4 ; i<=30 ; i+=2){ sum+=Math.pow(3,(i-4)/2); dp[i]=2+6*sum ; } while(sc.hasNext())System.out.println(dp[sc.nextInt()]); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var dp : Sequence(int) ; dp := Integer.subrange(1,31)->collect(0) ; dp[1+1] := 1 ; dp[2+1] := 2 ; var sum : int ; sum := 0 ; var i : int ; i := 3 ; while i <= 30 do ( ( sum := sum+(3->pow((i - 3) / 2)) ; dp[i+1] := 1 + 4 * sum ) ; i := i+(2) ) ; sum := 0 ; var i : int ; i := 4 ; while i <= 30 do ( ( sum := sum+(3->pow((i - 4) / 2)) ; dp[i+1] := 2 + 6 * sum ) ; i := i+(2) ) ; while (sc.hasNext()) do OclFile["System.out"].println(dp[sc.getCurrent()->toInteger()+1]) ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStream ; import java.io.InputStreamReader ; class Main { public static void main(String args[]){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String str ; while((str=br.readLine())!=null){ int n=Integer.parseInt(str); calc(n); } } catch(Exception e){ } } static void calc(int n){ switch(n){ case 0 : { System.out.println(0); } case 1 : { System.out.println(1); break ; } case 2 : { System.out.println(2); break ; } case 3 : { System.out.println(5); break ; } default : { if(n % 2==0){ int m=n/2-1 ; int result=1 ; int edge=3 ; for(int i=0 ; itoInteger() ; execute calc(n) ) ; str := br.readLine() ; ) ) catch (e : ProgramException) do skip ); static operation calc( n : int) : void pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (n) ; if _switchval = 0 then ( OclFile["System.out"].println(0) ) else skip ; if _switchval = 1 then ( OclFile["System.out"].println(1) ; break ) else skip ; if _switchval = 2 then ( OclFile["System.out"].println(2) ; break ) else skip ; if _switchval = 3 then ( OclFile["System.out"].println(5) ; break ) else skip ; if true then ( if (n mod 2 = 0) then ( var m : int ; m := n / 2 - 1 ; var result : int ; result := 1 ; var edge : int ; edge := 3 ; var i : int ; i := 0 ; while i < m do ( ( result := result+(edge) ; edge := edge*(3) ) ; i := i + 1 ) ; OclFile["System.out"].println(result * 2) ; ) else ( var m : int ; m := ((n)->char2byte() - 1) / 2 ; var result : int ; result := 1 ; var edge : int ; edge := 4 ; var i : int ; i := 0 ; while i < m do ( ( result := result+(edge) ; edge := edge*(3) ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ) ) else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String is ; while((is=in.readLine())!=null){ int n=Integer.parseInt(is); if(n==0){ System.out.println(0); continue ; } else if(n==1){ System.out.println(1); continue ; } else if(n==2){ System.out.println(2); continue ; } int c=2 ; int d=0 ; for(int i=2 ; itoInteger() ; if (n = 0) then ( OclFile["System.out"].println(0) ; continue ) else if (n = 1) then ( OclFile["System.out"].println(1) ; continue ) else if (n = 2) then ( OclFile["System.out"].println(2) ; continue ) else skip ; ; ; var c : int ; c := 2 ; var d : int ; d := 0 ; var i : int ; i := 2 ; while i < n do ( ( if (i mod 2 = 0) then ( d := d * 3 + 1 ) else skip ; c := c+(d * 2 + 1) ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ) ; is := in.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPrime(int n){ if(n==0 || n==1){ return false ; } for(int i=2 ; i*i<=n ; i++){ if(n % i==0){ return false ; } } return true ; } static int sumAscii(String str,int n){ int sum=0 ; for(int i=0 ; iat(i+1))->oclAsType(int)) ) else skip ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var n : int ; n := str->size() ; OclFile["System.out"].println(sumAscii(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cupboard { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int arr[][]=new int[n][2]; for(int i=0 ; in/2){ left=n-count0 ; } else { left=count0 ; } for(int i=0 ; in/2){ right=n-count1 ; } else { right=count1 ; } int sum=left+right ; System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class cupboard { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 2 do ( ( arr[i+1][j+1] := in.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count1 : int ; count1 := 0 ; var count0 : int ; count0 := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1][0+1] = 1) then ( count0 := count0 + 1 ) else skip ) ; i := i + 1 ) ; var left : int ; left := 0 ; var right : int ; right := 0 ; if (count0 > n / 2) then ( left := n - count0 ) else ( left := count0 ) ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1][1+1] = 1) then ( count1 := count1 + 1 ) else skip ) ; i := i + 1 ) ; if (count1 > n / 2) then ( right := n - count1 ) else ( right := count1 ) ; var sum : int ; sum := left + right ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Ideone { public static void main(String[] args)throws java.lang.Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(); int[][] a=new int[n][2]; for(int i=0 ; itoInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < 2 do ( ( a[i+1][j+1] := in.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count1R : int ; count1R := 0 ; var count1L : int ; count1L := 0 ; var time : int ; time := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1][0+1] = 1) then ( count1L := count1L + 1 ) else skip ; if (a[i+1][1+1] = 1) then ( count1R := count1R + 1 ) else skip ) ; i := i + 1 ) ; if (count1R <= n / 2) then ( var i : int ; i := 0 ; while i < n do ( ( if (a[i+1][1+1] = 1) then ( a[i+1][1+1] := 0 ; time := time + 1 ) else skip ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < n do ( ( if (a[i+1][1+1] = 0) then ( a[i+1][1+1] := 1 ; time := time + 1 ) else skip ) ; i := i + 1 ) ) ; if (count1L <= n / 2) then ( var i : int ; i := 0 ; while i < n do ( ( if (a[i+1][0+1] = 1) then ( a[i+1][0+1] := 0 ; time := time + 1 ) else skip ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < n do ( ( if (a[i+1][0+1] = 0) then ( a[i+1][0+1] := 1 ; time := time + 1 ) else skip ) ; i := i + 1 ) ) ; OclFile["System.out"].println(time) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _248A_Cupboards { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); int one1=0 ; int zero1=0 ; int one2=0 ; int zero2=0 ; for(int i=0 ; itoInteger() ; if (num1 = 0) then ( zero1 := zero1 + 1 ) else ( one1 := one1 + 1 ) ; var num2 : int ; num2 := input.getCurrent()->toInteger() ; if (num2 = 0) then ( zero2 := zero2 + 1 ) else ( one2 := one2 + 1 ) ; skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{one1, zero1}->min() + Set{one2, zero2}->min()) ; ); } 48A_Cupboards { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; var one1 : int ; one1 := 0 ; var zero1 : int ; zero1 := 0 ; var one2 : int ; one2 := 0 ; var zero2 : int ; zero2 := 0 ; var i : int ; i := 0 ; while i < test do ( ( var num1 : int ; num1 := input.getCurrent()->toInteger() ; if (num1 = 0) then ( zero1 := zero1 + 1 ) else ( one1 := one1 + 1 ) ; var num2 : int ; num2 := input.getCurrent()->toInteger() ; if (num2 = 0) then ( zero2 := zero2 + 1 ) else ( one2 := one2 + 1 ) ; skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{one1, zero1}->min() + Set{one2, zero2}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeforcesColourblind { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( var col : int ; col := sc.getCurrent()->toInteger() ; var first : String ; first := sc.getCurrent() ; var second : String ; second := sc.getCurrent() ; var flag : int ; flag := 0 ; var j : int ; j := 0 ; while j < col do ( ( var ch1 : String ; ch1 := first->at(j+1) ; var ch2 : String ; ch2 := second->at(j+1) ; if (ch1 = 'R') then ( if (not((ch2 = 'R'))) then ( flag := flag + 1 ; OclFile["System.out"].println("NO") ; break ) else skip ) else ( if (ch2 = 'R') then ( flag := flag + 1 ; OclFile["System.out"].println("NO") ; break ) else skip ) ) ; j := j + 1 ) ; if (flag = 0) then ( OclFile["System.out"].println("yes") ) else skip ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static String strBitwiseAND(String[] arr,int n){ String res="" ; int smallest_size=Integer.MAX_VALUE ; int largest_size=Integer.MIN_VALUE ; for(int i=0 ; ireverse()+"" ; smallest_size := Set{smallest_size, arr[i+1]->size()}->min() ; largest_size := Set{largest_size, arr[i+1]->size()}->max() ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < smallest_size do ( ( var all_ones : boolean ; all_ones := true ; var j : int ; j := 0 ; while j < n do ( ( if (arr[j+1]->at(i+1) = '0') then ( all_ones := false ; break ) else skip ) ; j := j + 1 ) ; res := res+((if all_ones then '1' else '0' endif)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < largest_size - (smallest_size)->char2byte() do ( res := res+('0') ; ; i := i + 1 ) ; var temp : String ; temp := StringLib.newString() ; temp := temp + StringLib.newString(res) ; res := temp->reverse()+"" ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"101","110110","111"} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(strBitwiseAND(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { char[] s ; int id ; boolean assign ; char get(){ return s[id++]; } void exp(){ boolean[][] r=clause(); check(r); while(true){ char ch=get(); if(ch!='|')break ; r=clause(); check(r); } } void check(boolean[][] r){ for(int i=0 ; i<26*2 ; i++){ if(r[0][i] && r[1][i])return ; } assign=true ; } boolean[][] clause(){ get(); boolean[][] r=new boolean[2][26*2]; for(int k=0 ; k<3 ; k++){ int a=0 ; int x=0 ; char ch=get(); if(ch=='~'){ a=1 ; ch=get(); } if(Character.isLowerCase(ch)){ ch=Character.toUpperCase(ch); x=26 ; } r[a][x+ch-'A']=true ; get(); } return r ; } void run(){ Scanner sc=new Scanner(System.in); while(true){ s=(sc.next()+"$").toCharArray(); if(s[0]=='#')break ; id=0 ; assign=false ; exp(); System.out.println(assign ? "yes" : "no"); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute s : Sequence(String); attribute id : int; attribute assign : boolean; operation get() : String pre: true post: true activity: ( return s[id+1] ); operation exp() : void pre: true post: true activity: ( var r : Sequence(Sequence(boolean)) ; r := clause() ; execute check(r) ; while (true) do ( var ch : String ; ch := get() ; if (ch /= '|') then break else skip ; r := clause() ; execute check(r) ) ); operation check( r : Sequence(Sequence(boolean))) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < 26 * 2 do ( ( if (r[0+1][i+1] & r[1+1][i+1]) then return else skip ) ; i := i + 1 ) ; assign := true ); operation clause() : Sequence(Sequence(boolean)) pre: true post: true activity: ( execute get() ; var r : Sequence(Sequence(boolean)) ; r := Integer.subrange(1,2)->collect(Integer.subrange(1,26 * 2)->collect(false)) ; var k : int ; k := 0 ; while k < 3 do ( ( var a : int ; a := 0 ; var x : int ; x := 0 ; var ch : String ; ch := get() ; if (ch = '~') then ( a := 1 ; ch := get() ) else skip ; if ((ch->toLowerCase() = ch)) then ( ch := (ch + "")->toUpperCase() ; x := 26 ) else skip ; r[a+1][x + ch - ('A')->char2byte()+1] := true ; execute get() ; ) ; k := k + 1 ) ; return r ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( s := (sc.getCurrent() + "$")->characters() ; if (s[0+1] = '#') then break else skip ; id := 0 ; assign := false ; execute exp() ; OclFile["System.out"].println(if assign then "yes" else "no" endif) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Problem1 { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); int t=Integer.parseInt(f.readLine()); while(t-->0){ StringTokenizer st=new StringTokenizer(f.readLine()); int n=Integer.parseInt(st.nextToken()); int u=Integer.parseInt(st.nextToken()); int v=Integer.parseInt(st.nextToken()); int[] obstacles=new int[n]; st=new StringTokenizer(f.readLine()); for(int i=0 ; i=2){ free=true ; break ; } } if(free){ out.println(0); continue ; } int cost=-1 ; for(int i=0 ; i0){ out.println(cost); continue ; } out.println(Math.min(u+v,2*v)); } out.close(); } } ------------------------------------------------------------ OCL File: --------- class Problem1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var f : OclFile ; f := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var t : int ; t := (f.readLine())->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var st : OclIterator ; st := OclIterator.newOclIterator_String(f.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var u : int ; u := (st.next())->toInteger() ; var v : int ; v := (st.next())->toInteger() ; var obstacles : Sequence(int) ; obstacles := Integer.subrange(1,n)->collect(0) ; st := OclIterator.newOclIterator_String(f.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( obstacles[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; var free : boolean ; free := false ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (if obstacles[i+1] - obstacles[i + 1+1] < 0 then -(obstacles[i+1] - obstacles[i + 1+1]) else obstacles[i+1] - obstacles[i + 1+1] endif >= 2) then ( free := true ; break ) else skip ) ; i := i + 1 ) ; if (free) then ( skip ; continue ) else skip ; var cost : int ; cost := -1 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (if obstacles[i+1] - obstacles[i + 1+1] < 0 then -(obstacles[i+1] - obstacles[i + 1+1]) else obstacles[i+1] - obstacles[i + 1+1] endif = 1) then ( cost := Set{u, v}->min() ) else skip ) ; i := i + 1 ) ; if (cost > 0) then ( skip ; continue ) else skip ; skip ; ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.Math.*; public class Inheritance { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); int u=s.nextInt(); int v=s.nextInt(); int arr[]=new int[n]; for(int i=0 ; iarr[i+1] || arr[i]arr[i+1] || arr[i]1){ ans=0 ; System.out.println(ans); flag=2 ; break ; } } if(flag==0)System.out.println(v+Math.min(u,v)); else if(flag==1)System.out.println(Math.min(u,v)); } } } ------------------------------------------------------------ OCL File: --------- class Inheritance { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.getCurrent()->toInteger() ; var u : int ; u := s.getCurrent()->toInteger() ; var v : int ; v := s.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if ((arr[i+1] > arr[i + 1+1] or arr[i+1] < arr[i + 1+1]) & if arr[i+1] - arr[i + 1+1] < 0 then -(arr[i+1] - arr[i + 1+1]) else arr[i+1] - arr[i + 1+1] endif = 1) then ( ans := Set{u, v}->min() ; flag := 1 ) else if ((arr[i+1] > arr[i + 1+1] or arr[i+1] < arr[i + 1+1]) & if arr[i+1] - arr[i + 1+1] < 0 then -(arr[i+1] - arr[i + 1+1]) else arr[i+1] - arr[i + 1+1] endif > 1) then ( ans := 0 ; OclFile["System.out"].println(ans) ; flag := 2 ; break ) else skip ; ) ; i := i + 1 ) ; if (flag = 0) then OclFile["System.out"].println(v + Set{u, v}->min()) else if (flag = 1) then OclFile["System.out"].println(Set{u, v}->min()) ; else skip ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getPeriod(int n){ int rem=1 ; for(int i=1 ; i<=n+1 ; i++)rem=(10*rem)% n ; int d=rem ; int count=0 ; do { rem=(10*rem)% n ; count++; } while(rem!=d); return count ; } public static void main(String[] args){ System.out.println(getPeriod(3)); System.out.println(getPeriod(7)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getPeriod( n : int) : int pre: true post: true activity: ( var rem : int ; rem := 1 ; var i : int ; i := 1 ; while i <= n + 1 do ( rem := (10 * rem) mod n ; ; i := i + 1 ) ; var d : int ; d := rem ; var count : int ; count := 0 ; while true do (( rem := (10 * rem) mod n ; count := count + 1 ) ; if (rem /= d) then skip else break) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(getPeriod(3)) ; OclFile["System.out"].println(getPeriod(7)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int countDivisors(int n){ int x=0,ans=1 ; while(n % 2==0){ x++; n=n/2 ; } ans=ans*(x+1); for(int i=3 ; i<=Math.sqrt(n); i=i+2){ x=0 ; while(n % i==0){ x++; n=n/i ; } ans=ans*(x+1); } if(n>2)ans=ans*2 ; return ans ; } static int getTotalCount(int n,int k){ int k_count=countDivisors(k); int count=0 ; for(int i=1 ; isqrt() do ( ( x := 0 ; while (n mod i = 0) do ( x := x + 1 ; n := n / i ) ; ans := ans * (x + 1) ) ; i := i + 2 ) ; if (n > 2) then ans := ans * 2 ; else skip ; return ans ); static operation getTotalCount( n : int, k : int) : int pre: true post: true activity: ( var k_count : int ; k_count := countDivisors(k) ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i < n do ( if (k_count = countDivisors(i)) then count := count + 1 ; else skip ; ; i := i + 1 ) ; if (k < n) then count := count - 1 ; else skip ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 500 ; var k : int ; k := 6 ; OclFile["System.out"].println(getTotalCount(n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class GFG { static int maxDiff(int[] arr,int n){ int result=0 ; Arrays.sort(arr); for(int i=0 ; im ; i--){ if(isValid(i,m)){ System.out.println(i); return ; } } System.out.println("Number Doesn't Exists"); } public static void main(String[] args){ long n=16,m=3 ; findLargestNum(n,m); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isValid( i : long, m : long) : boolean pre: true post: true activity: ( var sq_i : long ; sq_i := (i)->sqrt()->oclAsType(long) ; var sq : long ; sq := Set{m, sq_i}->min() ; var j : long ; j := 2 ; while j <= sq do ( if (i mod j = 0) then return false else skip ; ; j := j + 1 ) ; return true ); static operation findLargestNum( n : long, m : long) : void pre: true post: true activity: ( var i : long ; i := n ; while i > m do ( ( if (isValid(i, m)) then ( OclFile["System.out"].println(i) ; return ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println("Number Doesn't Exists") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 16 ; var m : long ; m := 3 ; execute findLargestNum(n, m) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int uniqueNumbers(int arr[],int n){ Arrays.sort(arr); int freq[]=new int[n+2]; for(int i=0 ; isort() ; var freq : Sequence(int) ; freq := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 0 ; while i < n + 2 do ( freq[i+1] := 0 ; ; i := i + 1 ) ; var x : int ; x := 0 ; while x < n do ( ( if (freq[arr[x+1] - 1+1] = 0) then ( freq[arr[x+1] - 1+1] := freq[arr[x+1] - 1+1] + 1 ) else if (freq[arr[x+1]+1] = 0) then ( freq[arr[x+1]+1] := freq[arr[x+1]+1] + 1 ) else ( freq[arr[x+1] + 1+1] := freq[arr[x+1] + 1+1] + 1 ) ; ) ; x := x + 1 ) ; var unique : int ; unique := 0 ; var x : int ; x := 0 ; while x <= n + 1 do ( ( if (freq[x+1] /= 0) then ( unique := unique + 1 ) else skip ) ; x := x + 1 ) ; return unique ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,3,3,3} ; var n : int ; n := 4 ; var ans : int ; ans := uniqueNumbers(arr, n) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); double d1=sc.nextInt(); double x=sc.nextInt(); double ans=0 ; for(; N>0 ; N--){ ans+=d1+(N-0.5)*x ; d1=((2*N+2)*d1+5*x)/(2*N); x=((double)N+2)/N*x ; } System.out.println(ans); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var d1 : double ; d1 := sc.getCurrent()->toInteger() ; var x : double ; x := sc.getCurrent()->toInteger() ; var ans : double ; ans := 0 ; while N > 0 do ( ( ans := ans+(d1 + (N - 0.5) * x) ; d1 := ((2 * N + 2) * d1 + 5 * x) / (2 * N) ; x := (N->oclAsType(double) + 2) / N * x ) ; N := N - 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean prime(int n){ if(n==1)return false ; for(int i=2 ; i*i<=n ; ++i)if(n % i==0)return false ; return true ; } static int Min_Sum(int n){ if(prime(n))return 1 ; if(n % 2==0)return 2 ; else { if(prime(n-2))return 2 ; else return 3 ; } } public static void main(String[] args){ int n=27 ; System.out.println(Min_Sum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation prime( n : int) : boolean pre: true post: true activity: ( if (n = 1) then return false else skip ; var i : int ; i := 2 ; while i * i <= n do ( if (n mod i = 0) then return false else skip ; ; i := i + 1 ) ; return true ); static operation Min_Sum( n : int) : int 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 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 27 ; OclFile["System.out"].println(Min_Sum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p047 implements EulerSolution { public static void main(String[] args){ System.out.println(new p047().run()); } public String run(){ for(int i=2 ; ; i++){ if(has4PrimeFactors(i+0)&& has4PrimeFactors(i+1)&& has4PrimeFactors(i+2)&& has4PrimeFactors(i+3))return Integer.toString(i); } } private static boolean has4PrimeFactors(int n){ return countDistinctPrimeFactors(n)==4 ; } private static int countDistinctPrimeFactors(int n){ int count=0 ; for(int i=2,end=Library.sqrt(n); i<=end ; i++){ if(n % i==0){ do n/=i ; while(n % i==0); count++; end=Library.sqrt(n); } } if(n>1)count++; return count ; } } ------------------------------------------------------------ OCL File: --------- class p047 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p047.newp047().run()) ); operation run() : String pre: true post: true activity: ( var i : int ; i := 2 ; while true do ( ( if (has4PrimeFactors(i + 0) & has4PrimeFactors(i + 1) & has4PrimeFactors(i + 2) & has4PrimeFactors(i + 3)) then return ((i) + "") else skip ) ; i := i + 1 ) ); static operation has4PrimeFactors( n : int) : boolean pre: true post: true activity: ( return countDistinctPrimeFactors(n) = 4 ); static operation countDistinctPrimeFactors( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 2 ; var end : int ; end := Library.sqrt(n) ; while i <= end do ( ( if (n mod i = 0) then ( while true do ( n := n/(i) ; ; if (n mod i = 0) then skip else break) ; count := count + 1 ; end := Library.sqrt(n) ) else skip ) ; i := i + 1 ) ; if (n > 1) then count := count + 1 ; else skip ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Constructive23 { public static void main(String args[])throws IOException { Scanner sc=new Scanner(System.in); int availableCubes=sc.nextInt(); Object result=getNumberOfPyramids(availableCubes); System.out.println(result); } public static Object getNumberOfPyramids(int availableCubes){ int n=0 ; int level=0 ; while(navailableCubes ? level-1 : level ; } } ------------------------------------------------------------ OCL File: --------- class Constructive23 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var availableCubes : int ; availableCubes := sc.getCurrent()->toInteger() ; var result : OclAny ; result := getNumberOfPyramids(availableCubes) ; OclFile["System.out"].println(result) ); static operation getNumberOfPyramids( availableCubes : int) : OclAny pre: true post: true activity: ( var n : int ; n := 0 ; var level : int ; level := 0 ; while (n < availableCubes) do ( level := level + 1 ; n := n+((level * (level + 1)) / 2) ) ; return if n > availableCubes then level - 1 else level endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static String line ; static int index(char c){ if('a'<=c && c<='z')return c-'a' ; return 26+c-'A' ; } static boolean satisfy(String clause){ String[] vars=clause.split("&"); boolean[][] used=new boolean[2][52]; for(String var : vars){ int pos=var.length()-1 ; int i=index(var.charAt(pos)); if(used[1-pos][i])return false ; used[pos][i]=true ; } return true ; } static boolean solve(){ String[] clause=line.split("\\|"); for(String c : clause){ if(satisfy(c.substring(1,c.length()-1)))return true ; } return false ; } public static void main(String[] args)throws Exception { while(true){ line=sc.next(); if(line.equals("#"))break ; System.out.println(solve()? "yes" : "no"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute line : String; static operation index( c : String) : int pre: true post: true activity: ( if ('a' <= c & c <= 'z') then return c - ('a')->char2byte() else skip ; return 26 + c - ('A')->char2byte() ); static operation satisfy( clause : String) : boolean pre: true post: true activity: ( var vars : Sequence(String) ; vars := clause->split("&") ; var used : Sequence(Sequence(boolean)) ; used := Integer.subrange(1,2)->collect(Integer.subrange(1,52)->collect(false)) ; for (var : vars) do ( ( var pos : int ; pos := var->size() - 1 ; var i : int ; i := index(var->at(pos+1)) ; if (used[1 - pos+1][i+1]) then return false else skip ; used[pos+1][i+1] := true ) ) ; return true ); static operation solve() : boolean pre: true post: true activity: ( var clause : Sequence(String) ; clause := line->split("\\|") ; for (c : clause) do ( ( if (satisfy(c.subrange(1+1,c->size() - 1))) then return true else skip ) ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (true) do ( line := sc.getCurrent() ; if (line = "#") then break else skip ; OclFile["System.out"].println(if solve() then "yes" else "no" endif) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); int length=s.length(); StringBuilder sb=new StringBuilder(); for(int i=0 ; isize() ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < s->size() do ( ( sb := sb + StringLib.newString("x") ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { private static void solve(){ String S=next(); int n=S.length(); for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print("x") ) ; i := i + 1 ) ; OclFile["System.out"].println() ); static attribute br : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var debugDataPath : String ; debugDataPath := OclProcess.getEnvironmentProperty("DD_PATH") ; if (debugDataPath /= null) then ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile(debugDataPath)))) ) catch (e : ProgramException) do ( error ProgramException(e) ) ) else skip ; execute solve() ); static attribute tokenizer : OclIterator := null; static operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : ProgramException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); static operation ni() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nl() : long pre: true post: true activity: ( return (next())->toLong() ); static operation nd() : double pre: true post: true activity: ( return (next())->toReal() ); static operation na( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := ni() ; ; i := i + 1 ) ; return a ); static operation ns() : Sequence(String) pre: true post: true activity: ( return next()->characters() ); static operation nal( n : int) : Sequence(long) pre: true post: true activity: ( var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nl() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import static java.lang.System.out ; public class Main { static MyReader in=new MyReader(); public static void main(String[] args){ String s=in.s(); char[] t=new char[s.length()]; Arrays.fill(t,'x'); out.println(t); } static class MyReader extends BufferedReader { MyReader(){ super(new InputStreamReader(System.in)); } String s(){ try { return readLine(); } catch(IOException e){ return "" ; } } String[] ss(){ return s().split(" "); } int i(){ return Integer.parseInt(s()); } int[] ii(){ String[] ss=ss(); int[] ii=new int[ss.length]; for(int j=0 ; jli(){ String[] ss=ss(); ArrayListli=new ArrayList<>(); for(int j=0 ; jsize())->collect(0) ; t := t->collect('x') ; out.println(t) ); static class MyReader extends OclFile { static operation newMyReader() : MyReader pre: true post: true activity: ( var self : MyReader ; self := createMyReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( execute super(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation s() : String pre: true post: true activity: ( try ( return readLine() ) catch (e : IOException) do ( return "" ) ); operation ss() : Sequence(String) pre: true post: true activity: ( return s()->split(" ") ); operation i() : int pre: true post: true activity: ( return (s())->toInteger() ); operation ii() : Sequence(int) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var ii : Sequence(int) ; ii := Integer.subrange(1,ss->size())->collect(0) ; var j : int ; j := 0 ; while j < ss->size() do ( ii[j+1] := (ss[j+1])->toInteger() ; ; j := j + 1 ) ; return ii ); operation li() : Sequence(int) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var li : Sequence(int) ; li := Sequence{} ; var j : int ; j := 0 ; while j < ss->size() do ( li := li->including((ss[j+1])->toInteger()) ; ; j := j + 1 ) ; return li ); operation l() : long pre: true post: true activity: ( return (s())->toLong() ); operation ll() : Sequence(long) pre: true post: true activity: ( var ss : Sequence(String) ; ss := ss() ; var ll : Sequence(long) ; ll := Integer.subrange(1,ss->size())->collect(0) ; var j : int ; j := 0 ; while j < ss->size() do ( ll[j+1] := (ss[j+1])->toLong() ; ; j := j + 1 ) ; return ll ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.*; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; class Main { public static void main(String[] args){ try { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String b=reader.readLine(); int n=b.length(); String ans="" ; String x="x" ; for(int i=0 ; isize() ; var ans : String ; ans := "" ; var x : String ; x := "x" ; var i : int ; i := 0 ; while i < n do ( ( ans := ans+x ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); String line=sc.nextLine(); int n=line.length(); for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print("x") ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static long mod=(long)(1e9+7); public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int a1=in.nextInt(); int a2=in.nextInt(); int k1=in.nextInt(); int k2=in.nextInt(); int total=in.nextInt(); int c1=a1*(k1-1)+(a2*(k2-1)); int min=0 ; if(c1>=total){ min=0 ; } else { min=total-c1 ; } int val_min=Math.min(k1,k2); int max=0 ; if(k1==val_min){ int value=(a1*k1); if(value>=total){ max=total/k1 ; total=0 ; } else { max=a1 ; total-=(a1*k1); } max+=(total/k2); } else { int value=(a2*k2); if(value>=total){ max=total/k2 ; total=0 ; } else { max=a2 ; total-=(a2*k2); } max+=(total/k1); } pw.println(min+" "+max); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute mod : long := (1e9 + 7)->oclAsType(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var a1 : int ; a1 := in.getCurrent()->toInteger() ; var a2 : int ; a2 := in.getCurrent()->toInteger() ; var k1 : int ; k1 := in.getCurrent()->toInteger() ; var k2 : int ; k2 := in.getCurrent()->toInteger() ; var total : int ; total := in.getCurrent()->toInteger() ; var c1 : int ; c1 := a1 * (k1 - 1) + (a2 * (k2 - 1)) ; var min : int ; min := 0 ; if (c1 >= total) then ( min := 0 ) else ( min := total - c1 ) ; var val_min : int ; val_min := Set{k1, k2}->min() ; var max : int ; max := 0 ; if (k1 = val_min) then ( var value : int ; value := (a1 * k1) ; if (value >= total) then ( max := total / k1 ; total := 0 ) else ( max := a1 ; total := total-((a1 * k1)) ) ; max := max+((total / k2)) ) else ( var value : int ; value := (a2 * k2) ; if (value >= total) then ( max := total / k2 ; total := 0 ) else ( max := a2 ; total := total-((a2 * k2)) ) ; max := max+((total / k1)) ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { public static void main(String[] args){ MathContext mc=new MathContext(25,RoundingMode.HALF_DOWN); Scanner in=new Scanner(System.in); int n=in.nextInt(); int a=in.nextInt(); int x=in.nextInt(); BigDecimal L=new BigDecimal(1); BigDecimal ans=new BigDecimal(2*x); for(int i=2 ; i<=n ; ++i){ BigDecimal t=new BigDecimal(i); L=L.add(BigDecimal.ONE.divide(BigDecimal.valueOf(i),mc)); t=L.add(BigDecimal.valueOf(i)); t=t.multiply(BigDecimal.valueOf(x)); BigDecimal t2=ans.multiply(BigDecimal.valueOf(2)).divide(BigDecimal.valueOf(i),mc); ans=ans.add(t).add(t2); } L=L.add(BigDecimal.ONE.divide(BigDecimal.valueOf(n+1),mc)); L=L.subtract(BigDecimal.ONE); L=L.multiply(BigDecimal.valueOf(n+1)).multiply(BigDecimal.valueOf(2*a-3*x)); L=L.divide(BigDecimal.valueOf(2),mc); ans=ans.add(L); System.out.print(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mc : MathContext ; mc := MathContext.newMathContext(25, RoundingMode.HALF_DOWN) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : int ; a := in.getCurrent()->toInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; var L : double ; L := double(1) ; var ans : double ; ans := double(2 * x) ; var i : int ; i := 2 ; while i <= n do ( ( var t : double ; t := double(i) ; L := L->excludes(1.0.divide((i + "")->toReal(), mc)) ; t := L->excludes((i + "")->toReal()) ; t := t.multiply((x + "")->toReal()) ; var t2 : double ; t2 := ans.multiply((2 + "")->toReal()).divide((i + "")->toReal(), mc) ; ans := ans->excludes(t)->excludes(t2) ; ) ; i := i + 1 ) ; L := L->excludes(1.0.divide((n + 1 + "")->toReal(), mc)) ; L := L.subtract(1.0) ; L := L.multiply((n + 1 + "")->toReal()).multiply((2 * a - 3 * x + "")->toReal()) ; L := L.divide((2 + "")->toReal(), mc) ; ans := ans->excludes(L) ; OclFile["System.out"].print(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Problem { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(f.readLine()); int m=Integer.parseInt(f.readLine()); int k1=Integer.parseInt(f.readLine()); int k2=Integer.parseInt(f.readLine()); int nn=Integer.parseInt(f.readLine()); if(k1<=k2){ int temp=k1 ; k1=k2 ; k2=temp ; temp=n ; n=m ; m=temp ; } if(k1>=k2){ int min=0 ; int nnn=nn ; if(nnn<=(n)*(k1-1)+(m)*(k2-1)){ min=0 ; } else { nnn-=(n)*(k1-1)+(m)*(k2-1); min=nnn ; } int max=Math.min(m,nn/k2); if(max==m){ nn-=(k2*m); max+=(nn/k1); } out.println(min+" "+max); out.close(); } out.close(); } } ------------------------------------------------------------ OCL File: --------- class Problem { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var f : OclFile ; f := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var n : int ; n := (f.readLine())->toInteger() ; var m : int ; m := (f.readLine())->toInteger() ; var k1 : int ; k1 := (f.readLine())->toInteger() ; var k2 : int ; k2 := (f.readLine())->toInteger() ; var nn : int ; nn := (f.readLine())->toInteger() ; if (k1 <= k2) then ( var temp : int ; temp := k1 ; k1 := k2 ; k2 := temp ; temp := n ; n := m ; m := temp ; ) else skip ; if (k1 >= k2) then ( var min : int ; min := 0 ; var nnn : int ; nnn := nn ; if (nnn <= (n) * (k1 - 1) + (m) * (k2 - 1)) then ( min := 0 ) else ( nnn := nnn-((n) * (k1 - 1) + (m) * (k2 - 1)) ; min := nnn ) ; var max : int ; max := Set{m, nn / k2}->min() ; if (max = m) then ( nn := nn-((k2 * m)) ; max := max+((nn / k1)) ) else skip ; skip ; skip ; ) else skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Code { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); boolean t=true ; for(int i=0 ; itoInteger() ; var s : String ; s := sc.getCurrent() ; var t : boolean ; t := true ; var i : int ; i := 0 ; while i < s->size() & t do ( ( if (s->at(i+1) = '*') then ( var j : int ; j := 1 ; while i + 4 * j < s->size() do ( ( if (s->at(i + j+1) = '*' & s->at(i + 2 * j+1) = '*' & s->at(i + 3 * j+1) = '*' & s->at(i + 4 * j+1) = '*') then ( OclFile["System.out"].println("yes") ; t := false ; break ) else skip ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; if (t) then ( OclFile["System.out"].println("no") ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class A { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=sc.nextInt(); char[] c=sc.next().toCharArray(); for(int i=1 ; itoInteger() ; var c : Sequence(String) ; c := sc.getCurrent()->characters() ; var i : int ; i := 1 ; while i < c->size() do ( ( var j : int ; j := 0 ; while j < c->size() do ( ( var j2 : int ; j2 := 0 ; var k : int ; k := j ; while j2 < 5 & k < c->size() do ( ( if (c[k+1] = '.') then break else skip ) ; j2 := j2 + 1 ; k := k+(i) ) ; if (j2 = 5) then ( OclFile["System.out"].println("yes") ; return ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; skip ; skip ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newScanner( fileReader : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(fileReader); return self ); operation initialise( fileReader : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(fileReader) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class zizo { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char[] s=sc.next().toCharArray(); for(int a=0 ; a=n){ continue LOOP ; } if(s[x]=='.'){ continue LOOP ; } } System.out.println("yes"); return ; } } System.out.println("no"); } } ------------------------------------------------------------ OCL File: --------- class zizo { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var a : int ; a := 0 ; while a < n do ( ( var b : int ; b := 1 ; while b < n do ( ( var i : int ; i := 0 ; while i <= 4 do ( ( var x : int ; x := a + b * i ; if (x >= n) then ( continue ) else skip ; if (s[x+1] = '.') then ( continue ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("yes") ; return ) ; b := b + 1 ) ; ) ; a := a + 1 ) ; OclFile["System.out"].println("no") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc=new Scanner(System.in); String line ; void run(){ for(; ; ){ line=sc.nextLine(); if(line.equals("#")){ break ; } boolean satensan=false ; for(String s : line.split("[|] ")){ s=s.substring(1,s.length()-1); String[] ss=s.split("&"); boolean fail=false ; for(int j=0 ; j<3 ; j++){ for(int i=0 ; i<3 ; i++){ fail |=ss[i] .length()==1 && ss[j] .length()==2 && ss[i] .charAt(0)==ss[j] .charAt(1); } } satensan |=! fail ; } println(satensan ? "yes" : "no"); } } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute line : String; operation run() : void pre: true post: true activity: ( while true do ( ( line := sc.nextLine() ; if (line = "#") then ( break ) else skip ; var satensan : boolean ; satensan := false ; for (s : line->split("[|] ")) do ( ( s := s.subrange(1+1,s->size() - 1) ; var ss : Sequence(String) ; ss := s->split("&") ; var fail : boolean ; fail := false ; var j : int ; j := 0 ; while j < 3 do ( ( var i : int ; i := 0 ; while i < 3 do ( ( fail := MathLib.bitwiseOr(fail, ss[i+1]->size() = 1 & ss[j+1]->size() = 2 & ss[i+1]->at(0+1) = ss[j+1]->at(1+1)) ) ; i := i + 1 ) ) ; j := j + 1 ) ; satensan := MathLib.bitwiseOr(satensan, not(fail)) ; ) ) ; execute println(if satensan then "yes" else "no" endif) ; ) ) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Problem_526A { public static boolean sol(int i,int sum,int diff){ if(sum==4)return true ; if(i==n || i==-1)return false ; for(int j=i+1 ; jat(j+1) = '*') then ( if (j - i = diff) then ( if (sol(j, sum + 1, diff)) then return true else skip ) else ( if (sol(j, 1, j - i)) then return true else skip ) ) else skip ) ; j := j + 1 ) ; return false ); static attribute n : int; static attribute s : String; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := (arguments ( )) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; n := sc.getCurrent()->toInteger() ; s := sc.nextLine() ; var i : int ; i := s->indexOf("*")-1 ; if (sol(i, 0, -1)) then OclFile["System.out"].println("yes") else OclFile["System.out"].println("no") ; ; skip ; ); static class Scanner { attribute br : OclFile; attribute st : OclIterator; static operation newScanner() : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation hasnext() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; public class KingOfThieves { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String map=br.readLine(); int maxGap=(int)Math.floor((n-5)/4); for(int i=0 ; i<=maxGap ; i++){ int maxRunSpace=i*4+5 ; for(int j=0 ; j<=n-maxRunSpace ; j++){ if(map.charAt(j)=='.'){ continue ; } else { boolean possible=true ; for(int k=j+i+1 ; ktoInteger() ; var map : String ; map := br.readLine() ; var maxGap : int ; maxGap := ((n - 5) / 4)->floor()->oclAsType(int) ; var i : int ; i := 0 ; while i <= maxGap do ( ( var maxRunSpace : int ; maxRunSpace := i * 4 + 5 ; var j : int ; j := 0 ; while j <= n - maxRunSpace do ( ( if (map->at(j+1) = '.') then ( continue ) else ( var possible : boolean ; possible := true ; var k : int ; k := j + i + 1 ; while k < j + maxRunSpace do ( ( if (map->at(k+1) = '.') then ( possible := false ; break ) else skip ) ; k := k+(i + 1) ) ; if (possible) then ( OclFile["System.out"].println("yes") ; OclProcess.exit(0) ) else skip ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println("no") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int seriesSum(int n){ return(n*(n+1)*(n+2))/6 ; } public static void main(String[] args){ int n=4 ; System.out.println(seriesSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation seriesSum( n : int) : int pre: true post: true activity: ( return (n * (n + 1) * (n + 2)) / 6 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(seriesSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void checksum(int n){ if(n % 3==0)System.out.println(n/3-1+" "+n/3+" "+(n/3+1)); else System.out.println("-1"); } public static void main(String[] args){ int n=6 ; checksum(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checksum( n : int) : void pre: true post: true activity: ( if (n mod 3 = 0) then OclFile["System.out"].println(n / 3 - 1 + " " + n / 3 + " " + (n / 3 + 1)) ; else OclFile["System.out"].println("-1") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; execute checksum(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int angle(int n){ return 2*n ; } public static void main(String[] args){ int n=30 ; System.out.println(angle(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation angle( n : int) : int pre: true post: true activity: ( return 2 * n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 30 ; OclFile["System.out"].println(angle(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static void reverseorder(int n){ boolean prime[]=new boolean[n+1]; for(int i=0 ; i=2 ; i--)if(prime[i]==true)System.out.print(i+" "); } public static void main(String args[]){ int N=25 ; System.out.println("Prime number in reverse order"); if(N==1)System.out.println("No prime no exist in this range"); else reverseorder(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation reverseorder( n : int) : void pre: true post: true activity: ( var prime : Sequence(boolean) ; prime := Integer.subrange(1,n + 1)->collect(false) ; var i : int ; i := 0 ; while i < n do ( prime[i+1] := true ; ; i := i + 1 ) ; var p : int ; p := 2 ; while p * p <= n do ( ( if (prime[p+1] = true) then ( var i : int ; i := p * 2 ; while i <= n do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ; var i : int ; i := n ; while i >= 2 do ( if (prime[i+1] = true) then OclFile["System.out"].print(i + " ") ; else skip ; ; i := i - 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 25 ; OclFile["System.out"].println("Prime number in reverse order") ; if (N = 1) then OclFile["System.out"].println("No prime no exist in this range") ; else execute reverseorder(N) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int centeredTetrahedralNumber(int n){ return(2*n+1)*(n*n+n+3)/3 ; } public static void main(String[] args){ int n=6 ; System.out.println(centeredTetrahedralNumber(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation centeredTetrahedralNumber( n : int) : int pre: true post: true activity: ( return (2 * n + 1) * (n * n + n + 3) / 3 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; OclFile["System.out"].println(centeredTetrahedralNumber(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float avgOfFirstN(int n){ return(float)(1+n)/2 ; } public static void main(String args[]){ int n=20 ; System.out.println(avgOfFirstN(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation avgOfFirstN( n : int) : double pre: true post: true activity: ( return (1 + n)->oclAsType(double) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 20 ; OclFile["System.out"].println(avgOfFirstN(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long evenPowerSum(int n){ return(8*n*(n+1)*(2*n+1)*(3*n*n+3*n-1))/15 ; } public static void main(String[] args){ int n=4 ; System.out.println(evenPowerSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation evenPowerSum( n : int) : long pre: true post: true activity: ( return (8 * n * (n + 1) * (2 * n + 1) * (3 * n * n + 3 * n - 1)) / 15 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(evenPowerSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countStr(int n){ return 1+(n*2)+(n*((n*n)-1)/2); } public static void main(String[] args){ int n=3 ; System.out.println(countStr(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countStr( n : int) : int pre: true post: true activity: ( return 1 + (n * 2) + (n * ((n * n) - 1) / 2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(countStr(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int seriesSum(int n){ return(n*(n+1)*(n+2))/6 ; } public static void main(String[] args){ int n=4 ; System.out.println(seriesSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation seriesSum( n : int) : int pre: true post: true activity: ( return (n * (n + 1) * (n + 2)) / 6 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(seriesSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.BufferedWriter ; import java.io.OutputStreamWriter ; import java.io.IOException ; import java.util.StringTokenizer ; public class Solve { static FastScan jin=new FastScan(); static BufferedWriter jout=new BufferedWriter(new OutputStreamWriter(System.out)); static int T ; public static void main(String[] args)throws Exception { long res=1 ; long cur1=0,cur2=0 ; long score1,score2 ; int N=jin.nextInt(); for(int i=0 ; imin() ; var cur_max : long ; cur_max := Set{cur1, cur2}->max() ; if (cur1 < score_min & cur2 < score_min) then ( res := res+(score_min - cur_max) ; if (cur1 /= cur2) then ( res := res+(1) ) else skip ) else if ((cur1 < score_min & cur2 = score_min) or (cur1 = score_min & cur2 < score_min)) then ( res := res+(1) ) else skip ; ; cur1 := score1 ; cur2 := score2 ; ) ; i := i + 1 ) ; skip ; skip ; ); } class FastScan { attribute br : OclFile; attribute stok : OclIterator; static operation newFastScan() : FastScan pre: true post: true activity: ( var self : FastScan ; self := createFastScan(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (stok = null or not(stok.hasNext())) do ( try ( stok := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return stok.next() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextInt() : int pre: true post: true activity: ( return (self.next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (self.next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (self.next())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int per(int n){ if(n==0)return 3 ; if(n==1)return 0 ; if(n==2)return 2 ; return per(n-2)+per(n-3); } public static void main(String[] args){ int n=9 ; System.out.println(per(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation per( n : int) : int 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) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].println(per(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static int countSetBits(int n){ if(n==0)return 0 ; else return(n & 1)+countSetBits(n>>1); } public static void main(String[] args){ int n=9 ; System.out.println(countSetBits(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSetBits( n : int) : int pre: true post: true activity: ( if (n = 0) then return 0 else return (n & 1) + countSetBits((n/(2->pow(1)))->oclAsType(long)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].println(countSetBits(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int leonardo(int n){ if(n==0 || n==1)return 1 ; return(leonardo(n-1)+leonardo(n-2)+1); } public static void main(String args[]){ System.out.println(leonardo(3)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation leonardo( n : int) : int pre: true post: true activity: ( if (n = 0 or n = 1) then return 1 else skip ; return (leonardo(n - 1) + leonardo(n - 2) + 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(leonardo(3)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static int weightedMean(int n){ return(2*n+1)/3 ; } static public void main(String[] args){ int n=10 ; System.out.println(weightedMean(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation weightedMean( n : int) : int pre: true post: true activity: ( return (2 * n + 1) / 3 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println(weightedMean(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void pattern(int min_stars,int p_height){ int p_space ; p_space=p_height-1 ; int i,j,k,n,x ; x=1 ; for(i=0 ; ii ; j--){ System.out.print(" "); } for(k=0 ; k=x ; n--)System.out.print(" "); for(k=0 ; k i do ( ( OclFile["System.out"].print(" ") ) ; j := j - 1 ) ; k := 0 ; while k < min_stars do ( OclFile["System.out"].print("*") ; ; k := k + 1 ) ; n := (p_height + p_height - 2) ; while n >= x do ( OclFile["System.out"].print(" ") ; ; n := n - 1 ) ; k := 0 ; while k < min_stars do ( OclFile["System.out"].print("*") ; ; k := k + 1 ) ; min_stars := min_stars + 2 ; x := x + 2 ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var min_stars : int ; min_stars := 1 ; var p_height : int ; p_height := 5 ; execute pattern(min_stars, p_height) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int binomialCoeffSum(int n){ return(1<pow(n)))->oclAsType(long)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(binomialCoeffSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countNumberOfTriangles(int n){ return n*(n-1)*(n-2)/6 ; } public static void main(String[] args){ int n=4 ; System.out.println(countNumberOfTriangles(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumberOfTriangles( n : int) : int pre: true post: true activity: ( return n * (n - 1) * (n - 2) / 6 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(countNumberOfTriangles(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findStarNum(int n){ return(6*n*(n-1)+1); } public static void main(String args[]){ int n=3 ; System.out.println(findStarNum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findStarNum( n : int) : int pre: true post: true activity: ( return (6 * n * (n - 1) + 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(findStarNum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int Centered_Trigunal_num(int n){ return(3*n*n+3*n+2)/2 ; } public static void main(String[] args){ int n=3 ; System.out.println(Centered_Trigunal_num(n)); n=12 ; System.out.println(Centered_Trigunal_num(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Centered_Trigunal_num( n : int) : int pre: true post: true activity: ( return (3 * n * n + 3 * n + 2) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(Centered_Trigunal_num(n)) ; n := 12 ; OclFile["System.out"].println(Centered_Trigunal_num(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findValueAtX(int n){ return(n*n*n)+n ; } public static void main(String[] args){ System.out.println(findValueAtX(10)); System.out.println(findValueAtX(2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findValueAtX( n : int) : int pre: true post: true activity: ( return (n * n * n) + n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(findValueAtX(10)) ; OclFile["System.out"].println(findValueAtX(2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void checksum(int n){ if(n % 5==0)System.out.println((n/5-2)+" "+(n/5-1)+" "+(n/5)+" "+(n/5+1)+" "+(n/5+2)); else System.out.println("-1"); } public static void main(String[] args){ int n=15 ; checksum(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checksum( n : int) : void pre: true post: true activity: ( if (n mod 5 = 0) then OclFile["System.out"].println((n / 5 - 2) + " " + (n / 5 - 1) + " " + (n / 5) + " " + (n / 5 + 1) + " " + (n / 5 + 2)) ; else OclFile["System.out"].println("-1") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 15 ; execute checksum(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Scanner ; import java.util.TreeMap ; import java.util.TreeSet ; public class trailzero { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ans=1 ; int a=0,b=0 ; for(int i=0 ; itoInteger() ; var ans : int ; ans := 1 ; var a : int ; a := 0 ; var b : int ; b := 0 ; var i : int ; i := 0 ; while i < n do ( ( var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; ans := ans+(Set{0, Set{c, d}->min() - Set{a, b}->max() + (if (a /= b) then 1 else 0 endif)}->max()) ; a := c ; b := d ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int avg_of_even_num(int n){ return n+1 ; } public static void main(String[] args){ int n=8 ; System.out.println(avg_of_even_num(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation avg_of_even_num( n : int) : int pre: true post: true activity: ( return n + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 8 ; OclFile["System.out"].println(avg_of_even_num(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int heptagonalNumber(int n){ return((5*n*n)-(3*n))/2 ; } public static void main(String[] args){ int n=2 ; System.out.println(heptagonalNumber(n)); n=15 ; System.out.println(heptagonalNumber(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation heptagonalNumber( n : int) : int pre: true post: true activity: ( return ((5 * n * n) - (3 * n)) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; OclFile["System.out"].println(heptagonalNumber(n)) ; n := 15 ; OclFile["System.out"].println(heptagonalNumber(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static float AvgofSquareN(int n){ return(float)((n+1)*(2*n+1))/6 ; } static public void main(String[] args){ int n=2 ; System.out.println(AvgofSquareN(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation AvgofSquareN( n : int) : double pre: true post: true activity: ( return ((n + 1) * (2 * n + 1))->oclAsType(double) / 6 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; OclFile["System.out"].println(AvgofSquareN(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B629 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] FfriendPerDay=new int[367]; int[] MfriendPerDay=new int[367]; int answer=0 ; for(int i=0 ; ianswer)answer=MfriendPerDay[j]; } else { if(FfriendPerDay[j]>answer)answer=FfriendPerDay[j]; } } } System.out.println(answer*2); } } ------------------------------------------------------------ OCL File: --------- class B629 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var FfriendPerDay : Sequence(int) ; FfriendPerDay := Integer.subrange(1,367)->collect(0) ; var MfriendPerDay : Sequence(int) ; MfriendPerDay := Integer.subrange(1,367)->collect(0) ; var answer : int ; answer := 0 ; var i : int ; i := 0 ; while i < n do ( ( var c : String ; c := sc.getCurrent()->at(0+1) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var j : int ; j := a ; while j <= b do ( ( if (c = 'M') then MfriendPerDay[j+1] := MfriendPerDay[j+1] + 1 else FfriendPerDay[j+1] := FfriendPerDay[j+1] + 1 ; ; if (MfriendPerDay[j+1] < FfriendPerDay[j+1]) then ( if (MfriendPerDay[j+1] > answer) then answer := MfriendPerDay[j+1] ; else skip ) else ( if (FfriendPerDay[j+1] > answer) then answer := FfriendPerDay[j+1] ; else skip ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(answer * 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int fnMod(int n){ if(n % 5==1)return 4 ; else return 0 ; } public static void main(String[] args){ int n=10 ; System.out.println(fnMod(n)); n=11 ; System.out.println(fnMod(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fnMod( n : int) : int pre: true post: true activity: ( if (n mod 5 = 1) then return 4 else return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println(fnMod(n)) ; n := 11 ; OclFile["System.out"].println(fnMod(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int getResult(int n){ if((n & 1)>0)return 1 ; return-1 ; } public static void main(String[] args){ int n=3 ; System.out.println(getResult(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getResult( n : int) : int pre: true post: true activity: ( if ((n & 1) > 0) then return 1 else skip ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(getResult(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int fib(int n){ if(n<=1)return n ; return fib(n-1)+fib(n-2); } public static void main(String[] args){ int n=6 ; System.out.println(fib(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fib( n : int) : int pre: true post: true activity: ( if (n <= 1) then return n else skip ; return fib(n - 1) + fib(n - 2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; OclFile["System.out"].println(fib(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int pentagon_pyramidal(int n){ return n*n*(n+1)/2 ; } public static void main(String[] args){ int n=4 ; System.out.println(pentagon_pyramidal(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation pentagon_pyramidal( n : int) : int pre: true post: true activity: ( return n * n * (n + 1) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(pentagon_pyramidal(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findCullen(int n){ return(1<pow(n)))->oclAsType(long)) * n + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; OclFile["System.out"].println(findCullen(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static int countSetBits(int n){ if(n==0)return 0 ; else return 1+countSetBits(n &(n-1)); } public static void main(String[] args){ int n=9 ; System.out.println(countSetBits(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSetBits( n : int) : int pre: true post: true activity: ( if (n = 0) then return 0 else return 1 + countSetBits(n & (n - 1)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].println(countSetBits(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countIntegralSolutions(int n){ return((n+1)*(n+2))/2 ; } public static void main(String[] args){ int n=3 ; System.out.println(countIntegralSolutions(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countIntegralSolutions( n : int) : int pre: true post: true activity: ( return ((n + 1) * (n + 2)) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(countIntegralSolutions(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class div541B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int previousx=0,previousy=0 ; int ans=1 ; for(int i=0 ; itoInteger() ; var previousx : int ; previousx := 0 ; var previousy : int ; previousy := 0 ; var ans : int ; ans := 1 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (previousx = x & previousy = y) then continue else skip ; var max : int ; max := Set{previousx, previousy}->max() ; var min : int ; min := Set{x, y}->min() ; if (previousx = previousy) then ( max := max + 1 ) else skip ; if (max <= min) then ( ans := ans+(min - max + 1) ) else skip ; previousx := x ; previousy := y ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static long centeredTridecagonalNum(long n){ return(13*n*(n-1)+2)/2 ; } public static void main(String[] args){ long n=3 ; System.out.println(centeredTridecagonalNum(n)); n=10 ; System.out.println(centeredTridecagonalNum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation centeredTridecagonalNum( n : long) : long pre: true post: true activity: ( return (13 * n * (n - 1) + 2) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 3 ; OclFile["System.out"].println(centeredTridecagonalNum(n)) ; n := 10 ; OclFile["System.out"].println(centeredTridecagonalNum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int series(int n){ return(8*n*n)+1 ; } public static void main(String args[]){ int n=5 ; System.out.println(series(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation series( n : int) : int pre: true post: true activity: ( return (8 * n * n) + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(series(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; import java.util.*; import static java.util.Arrays.sort ; import javafx.util.Pair ; public class Main { public static void main(String[] args){ FastScanner input=new FastScanner(); int n=input.nextInt(); int male[]=new int[367]; int female[]=new int[367]; for(int i=0 ; icollect(0) ; var female : Sequence(int) ; female := Integer.subrange(1,367)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var ch : String ; ch := input.next()->at(0+1) ; var a : int ; a := input.nextInt() ; var b : int ; b := input.nextInt() ; if (ch = 'M') then ( var j : int ; j := a ; while j <= b do ( ( male[j+1] := male[j+1] + 1 ) ; j := j + 1 ) ) else ( var j : int ; j := a ; while j <= b do ( ( female[j+1] := female[j+1] + 1 ) ; j := j + 1 ) ) ) ; i := i + 1 ) ; var ans : int ; ans := -2147483648 ; var i : int ; i := 1 ; while i < 367 do ( ( ans := Set{ans, Set{male[i+1], female[i+1]}->min()}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans * 2) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static final int MAX=200006 ; static final int CONS=32766 ; static void calc(int a[],int b[],int lr[],int q,int n){ int M,m,i,j,k,l,r,suma,sumb,cc ; cc=0 ; for(i=0 ; i=0){ suma-=a[l]; sumb-=b[l]; } M=Math.max(CONS*suma+CONS*sumb,-CONS*suma-CONS*sumb); M=Math.max(M,Math.max(CONS*suma-CONS*sumb,-CONS*suma+CONS*sumb)); m=Math.min(CONS*suma+CONS*sumb,-CONS*suma-CONS*sumb); m=Math.min(m,Math.min(CONS*suma-CONS*sumb,-CONS*suma+CONS*sumb)); System.out.println((M-m)); q--; } } public static void main(String[] args){ int n=5,q=2 ; int[] a={ 0,7,3,4,5 }; int[] b={ 0,3,1,2,3 }; int[] lr=new int[q*2]; lr[0]=1 ; lr[1]=1 ; lr[2]=1 ; lr[3]=3 ; calc(a,b,lr,q,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 200006; static attribute CONS : int := 32766; static operation calc( a : Sequence(int), b : Sequence(int), lr : Sequence(int), q : int, n : int) : void pre: true post: true activity: ( var M : int ; var m : int ; var i : int ; var j : int ; var k : int ; var l : int ; var r : int ; var suma : int ; var sumb : int ; var cc : int ; cc := 0 ; i := 0 ; while i < n - 1 do ( ( a[i + 1+1] := a[i + 1+1]+(a[i+1]) ; b[i + 1+1] := b[i + 1+1]+(b[i+1]) ) ; i := i + 1 ) ; while (q /= 0) do ( l := lr[cc+1] ; cc := cc + 1 ; r := lr[cc+1] ; cc := cc + 1 ; l := l-(2) ; r := r-(1) ; suma := a[r+1] ; sumb := b[r+1] ; if (l >= 0) then ( suma := suma-(a[l+1]) ; sumb := sumb-(b[l+1]) ) else skip ; M := Set{CONS * suma + CONS * sumb, -CONS * suma - CONS * sumb}->max() ; M := Set{M, Set{CONS * suma - CONS * sumb, -CONS * suma + CONS * sumb}->max()}->max() ; m := Set{CONS * suma + CONS * sumb, -CONS * suma - CONS * sumb}->min() ; m := Set{m, Set{CONS * suma - CONS * sumb, -CONS * suma + CONS * sumb}->min()}->min() ; OclFile["System.out"].println((M - m)) ; q := q - 1 ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var q : int ; q := 2 ; var a : Sequence(int) ; a := Sequence{0,7,3,4,5} ; var b : Sequence(int) ; b := Sequence{0,3,1,2,3} ; var lr : Sequence(int) ; lr := Integer.subrange(1,q * 2)->collect(0) ; lr[0+1] := 1 ; lr[1+1] := 1 ; lr[2+1] := 1 ; lr[3+1] := 3 ; execute calc(a, b, lr, q, n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); int[][] ans=getMatrix(n,k); StringBuilder sb=new StringBuilder(); for(int i=0 ; in*n){ return new int[][] { { -1 } }; } int[][] ans=new int[n][n]; for(int i=0 ; i0 ; i++){ ans[i][i]=1 ; k--; for(int j=i+1 ; j1 ; j++){ ans[i][j]=1 ; ans[j][i]=1 ; k-=2 ; } } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; var ans : Sequence(Sequence(int)) ; ans := getMatrix(n, k) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < ans->size() do ( ( var j : int ; j := 0 ; while j < ans[0+1]->size() do ( ( sb := sb + StringLib.newString(ans[i+1][j+1]) + StringLib.newString(" ") ) ; j := j + 1 ) ; sb := sb + StringLib.newString("\n") ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; ); static operation getMatrix( n : int, k : int) : Sequence(Sequence(int)) pre: true post: true activity: ( if (k > n * n) then ( return Sequence{Sequence{-1}} ) else skip ; var ans : Sequence(Sequence(int)) ; ans := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n & k > 0 do ( ( ans[i+1][i+1] := 1 ; k := k - 1 ; var j : int ; j := i + 1 ; while j < n & k > 1 do ( ( ans[i+1][j+1] := 1 ; ans[j+1][i+1] := 1 ; k := k-(2) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A803 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int K=in.nextInt(); if(N*N0 && A[r][c]==0){ if(r==c){ A[r][c]=1 ; K--; } else if(K>1){ A[r][c]=1 ; A[c][r]=1 ; K-=2 ; } } } } StringBuilder output=new StringBuilder(); for(int r=0 ; rtoInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; if (N * N < K) then ( OclFile["System.out"].println("-1") ) else ( var A : Sequence(Sequence(int)) ; A := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; var r : int ; r := 0 ; while r < N do ( ( var c : int ; c := 0 ; while c < N do ( ( if (K > 0 & A[r+1][c+1] = 0) then ( if (r = c) then ( A[r+1][c+1] := 1 ; K := K - 1 ) else if (K > 1) then ( A[r+1][c+1] := 1 ; A[c+1][r+1] := 1 ; K := K-(2) ) else skip ; ) else skip ) ; c := c + 1 ) ) ; r := r + 1 ) ; var output : String ; output := StringLib.newString() ; var r : int ; r := 0 ; while r < N do ( ( var c : int ; c := 0 ; while c < N do ( ( output := output + StringLib.newString(A[r+1][c+1]) + StringLib.newString(' ') ) ; c := c + 1 ) ; output := output + StringLib.newString(' ') ) ; r := r + 1 ) ; OclFile["System.out"].print(output) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class MaximalBinaryMatrix { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { String[] temp=br.readLine().split(" "); int n=Integer.parseInt(temp[0]); int k=Integer.parseInt(temp[1]); if(k>n*n){ pr.println(-1); return ; } int[][] res=new int[n][n]; for(int i=0 ; isplit(" ") ; var n : int ; n := (temp[0+1])->toInteger() ; var k : int ; k := (temp[1+1])->toInteger() ; if (k > n * n) then ( skip ; return ) else skip ; var res : Sequence(Sequence(int)) ; res := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (k <= 1) then ( break ) else skip ; if (res[i+1][j+1] = 1) then ( continue ) else skip ; res[i+1][j+1] := 1 ; res[j+1][i+1] := 1 ; k := k-(if i = j then 1 else 2 endif) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (k = 1) then ( var i : int ; i := 0 ; while i < n do ( ( if (res[i+1][i+1] = 0) then ( res[i+1][i+1] := 1 ; break ) else skip ) ; i := i + 1 ) ) else skip ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( skip ) ; j := j + 1 ) ; skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int findTrailingZeros(int n){ if((n & 1)==1)return 0 ; else { int ans=0 ; n/=2 ; while(n!=0){ ans+=n/5 ; n/=5 ; } return ans ; } } public static void main(String[] args){ int n=12 ; System.out.println(findTrailingZeros(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findTrailingZeros( n : int) : int pre: true post: true activity: ( if ((n & 1) = 1) then return 0 else ( var ans : int ; ans := 0 ; n := n/(2) ; while (n /= 0) do ( ans := ans+(n / 5) ; n := n/(5) ) ; return ans ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12 ; OclFile["System.out"].println(findTrailingZeros(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Scanner ; import java.util.TreeMap ; import java.util.TreeSet ; public class trailzero { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); TreeSett=new TreeSet(); int ans=0 ; for(int i=0 ; i='a' && c<='z'){ t.add(c); } else { ans=Math.max(ans,t.size()); t=new TreeSet<>(); } } ans=Math.max(ans,t.size()); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class trailzero { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var t : Set(String) ; t := Set{} ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var c : String ; c := s->at(i+1) ; if (c >= 'a' & c <= 'z') then ( t := t->including(c) ) else ( ans := Set{ans, t->size()}->max() ; t := Set{} ) ) ; i := i + 1 ) ; ans := Set{ans, t->size()}->max() ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _864B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); HashSetset=new HashSet<>(); int count=0,max=-1 ; for(char ch : s.toCharArray()){ if(ch>='a' && ch<='z')set.add(ch); else set.clear(); max=Math.max(set.size(),max); } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class _864B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var set : Set(String) ; set := Set{} ; var count : int ; count := 0 ; var max : int ; max := -1 ; for (ch : s->characters()) do ( ( if (ch >= 'a' & ch <= 'z') then set := set->including(ch) else set := set->intersection(Set{}) ; ; max := Set{set->size(), max}->max() ) ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextLine(); String str=sc.nextLine(); int j=1 ; int max=0 ; int count=0 ; Setset=new HashSet<>(); for(int i=0 ; imax)max=count ; } System.out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var str : String ; str := sc.nextLine() ; var j : int ; j := 1 ; var max : int ; max := 0 ; var count : int ; count := 0 ; var set : Set(String) ; set := Set{} ; var i : int ; i := 0 ; while i < str->size() do ( ( if ((str->at(i+1)->toUpperCase() = str->at(i+1))) then ( count := 0 ; set := set->intersection(Set{}) ) else if (set->excludes(str->at(i+1))) then ( set := set->including(str->at(i+1)) ; count := count + 1 ) else skip ; ; if (count > max) then max := count ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import javafx.util.Pair ; import java.io.*; import java.util.*; public class Draw { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); ArrayListp=new ArrayList<>(); p.add(new Pair(0,0)); HashSetset=new HashSet<>(); for(int i=0 ; imin)continue ; ans+=(min-max); if(! set.contains(max))ans++; set.add(max); set.add(min); } pw.println(ans); pw.close(); } static class Pair { long x,y ; Pair(long x,long y){ this.x=x ; this.y=y ; } } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class Draw { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var p : Sequence(Map) ; p := Sequence{} ; p := p->including(Map(0, 0)) ; var set : Set(long) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( p := p->including(Map(in.getCurrent()->toLong(), in.getCurrent()->toLong())) ; ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var max : long ; max := Set{p->at(i - 1+1).x, p->at(i - 1+1).y}->max() ; var min : long ; min := Set{p->at(i+1).x, p->at(i+1).y}->min() ; if (max > min) then continue else skip ; ans := ans+((min - max)) ; if (not(set->includes(max))) then ans := ans + 1 ; else skip ; set := set->including(max) ; set := set->including(min) ; ) ; i := i + 1 ) ; skip ; skip ; ); static class Pair { attribute x : long; static operation newPair( x : long, y : long) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(x, y); return self ); operation initialise( x : long, y : long) : void pre: true post: true activity: ( self.x := x ; self.y := y ); } static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int distancesum(int x[],int y[],int n){ int sum=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(distancesum(x, y, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int T=sc.nextInt(); for(int i=1 ; i<=T ; ++i){ long N=sc.nextLong(); System.out.printf("Case #%d: %d\n",i,solve(N)); } } static long solve(long v){ if(v<=10)return v ; int len=(""+v).length(); long mod=1 ; for(int i=0 ; i0){ rev*=10 ; rev+=tmp % 10 ; tmp/=10 ; } if(rev!=v)return solve(rev)+add+1 ; return solve(v-1)+add+1 ; } } ------------------------------------------------------------ OCL File: --------- class A { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var T : int ; T := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= T do ( ( var N : long ; N := sc.getCurrent()->toLong() ; OclFile["System.out"].printf("Case #%d: %d\n", i, solve(N)) ) ; i := i + 1 ) ); static operation solve( v : long) : long pre: true post: true activity: ( if (v <= 10) then return v else skip ; var len : int ; len := ("" + v)->size() ; var mod : long ; mod := 1 ; var i : int ; i := 0 ; while i < len / 2 do ( ( mod := mod*(10) ) ; i := i + 1 ) ; if (v mod mod = 0) then return solve(v - 1) + 1 else skip ; var add : long ; add := v mod mod - 1 ; v := v-(add) ; var rev : long ; rev := 0 ; var tmp : long ; tmp := v ; while (tmp > 0) do ( rev := rev*(10) ; rev := rev+(tmp mod 10) ; tmp := tmp/(10) ) ; if (rev /= v) then return solve(rev) + add + 1 else skip ; return solve(v - 1) + add + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class A { static long[] POW10=new long[20]; static { POW10[0]=1 ; for(int i=1 ; i1 && Long.parseLong(sb)!=POW10[s.length()/2-1]){ ans+=Long.parseLong("0"+new StringBuilder(s.substring(0,s.length()/2)).reverse().toString()); } ans+=Long.parseLong("0"+s.substring(s.length()/2)); if(zero)ans++; System.out.printf("Case #%d: ",n+1); System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class A { static attribute POW10 : Sequence(long) := Integer.subrange(1,20)->collect(0); static operation initialiseClass() pre: true post: true activity: POW10[0+1] := 1 ; var i : int ; i := 1 ; while i < POW10->size() do ( POW10[i+1] := POW10[i - 1+1] * 10 ; ; i := i + 1 ) ; ; static operation main( orange : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numCases : int ; numCases := input.getCurrent()->toInteger() ; var n : int ; n := 0 ; while n < numCases do ( ( var s : String ; s := input.getCurrent() ; var l : long ; l := (s)->toLong() ; var zero : boolean ; zero := l mod POW10[s->size() / 2+1] = 0 ; if (zero) then ( l := l - 1 ; s := l + "" ) else skip ; var ans : long ; ans := 0 ; var d : int ; d := 1 ; while d < s->size() do ( ans := ans+(POW10[d / 2+1] + POW10[(d + 1) / 2+1] - 1) ; ; d := d + 1 ) ; var sb : String ; sb := "0" + s.subrange(0+1,s->size() / 2) ; if (s->size() > 1 & (sb)->toLong() /= POW10[s->size() / 2 - 1+1]) then ( ans := ans+(("0" + StringLib.newString(s.subrange(0+1,s->size() / 2))->reverse()+"")->toLong()) ) else skip ; ans := ans+(("0" + s.subrange(s->size() / 2+1,s->size() / 2))->toLong()) ; if (zero) then ans := ans + 1 ; else skip ; OclFile["System.out"].printf("Case #%d: ", n + 1) ; OclFile["System.out"].println(ans) ; ) ; n := n + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Slam { static int[] basic=new int[15]; { basic[1]=10 ; for(int i=2 ; i<15 ; i++){ if(i % 2==0){ basic[i]=basic[i-1]+2*(int)(Math.pow(10,i/2))-1 ; } else { basic[i]=basic[i-1]+(int)((Math.pow(10,i/2))+(Math.pow(10,(i+1)/2))-1); } } } static boolean allzero(String t){ for(char ch : t.toCharArray())if(ch!='0')return false ; return true ; } static long f(long v){ if(v<10)return v ; int L=(""+v).length(); String right=(""+v).substring(L/2,L); String left=(""+v).substring(0,L/2); if(allzero(right))return 1+f(v-1); long result=basic[L-1]+Integer.parseInt(right)+Integer.parseInt(new StringBuilder(left).reverse().toString()); result=Math.min(result,basic[L-1]+(v-(long)Math.pow(10,L-1))); return result ; } public static void main(String[] args){ new Slam(); Scanner sc=new Scanner(System.in); int k=sc.nextInt(); for(int kk=1 ; kk<=k ; kk++)System.out.println("Case #"+kk+": "+f(sc.nextLong())); } } ------------------------------------------------------------ OCL File: --------- class Slam { static attribute basic : Sequence(int) := Integer.subrange(1,15)->collect(0); operation initialiseInstance() pre: true post: true activity: basic[1+1] := 10 ; var i : int ; i := 2 ; while i < 15 do ( ( if (i mod 2 = 0) then ( basic[i+1] := basic[i - 1+1] + 2 * (10->pow(i / 2))->oclAsType(int) - 1 ) else ( basic[i+1] := basic[i - 1+1] + ((10->pow(i / 2)) + (10->pow((i + 1) / 2)) - 1)->oclAsType(int) ) ) ; i := i + 1 ) ; ; static operation allzero( t : String) : boolean pre: true post: true activity: ( for (ch : t->characters()) do ( if (ch /= '0') then return false else skip ; ) ; return true ); static operation f( v : long) : long pre: true post: true activity: ( if (v < 10) then return v else skip ; var L : int ; L := ("" + v)->size() ; var right : String ; right := ("" + v).subrange(L / 2+1,L) ; var left : String ; left := ("" + v).subrange(0+1,L / 2) ; if (allzero(right)) then return 1 + f(v - 1) else skip ; var result : long ; result := basic[L - 1+1] + (right)->toInteger() + (StringLib.newString(left)->reverse()+"")->toInteger() ; result := Set{result, basic[L - 1+1] + (v - 10->pow(L - 1)->oclAsType(long))}->min() ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Slam.newSlam() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var kk : int ; kk := 1 ; while kk <= k do ( OclFile["System.out"].println("Case #" + kk + ": " + f(sc.getCurrent()->toLong())) ; ; kk := kk + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ (new Main()).solve(); } void solve(){ Scanner cin=new Scanner(System.in); int T=cin.nextInt(); for(int C=1 ; C<=T ; ++C){ String s=cin.next(); System.out.println("Case #"+C+": "+solve(s)); } } long solve(String s){ if(Long.parseLong(s)==0){ return 0 ; } int N=s.length(); String head=s.substring(0,N/2); String tail=s.substring(N/2); long tmp=Long.parseLong(tail); if(tmp==0){ return 1+solve(""+(Long.parseLong(s)-1)); } String next=""+(Long.parseLong(s)-(tmp-1)); String rev=rev(next); if(Long.parseLong(next)==Long.parseLong(rev)){ return tmp+solve(""+(Long.parseLong(s)-tmp)); } return tmp+solve(rev); } String rev(String s){ return(new StringBuilder(s)).reverse().toString(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).solve() ); operation solve() : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := cin.getCurrent()->toInteger() ; var C : int ; C := 1 ; while C <= T do ( ( var s : String ; s := cin.getCurrent() ; OclFile["System.out"].println("Case #" + C + ": " + solve(s)) ) ; C := C + 1 ) ); operation solve( s : String) : long pre: true post: true activity: ( if ((s)->toLong() = 0) then ( return 0 ) else skip ; var N : int ; N := s->size() ; var head : String ; head := s.subrange(0+1,N / 2) ; var tail : String ; tail := s.subrange(N / 2+1,N / 2) ; var tmp : long ; tmp := (tail)->toLong() ; if (tmp = 0) then ( return 1 + solve("" + ((s)->toLong() - 1)) ) else skip ; var next : String ; next := "" + ((s)->toLong() - ((tmp)->char2byte() - 1)) ; var rev : String ; rev := rev(next) ; if ((next)->toLong() = (rev)->toLong()) then ( return tmp + solve("" + ((s)->toLong() - (tmp)->char2byte())) ) else skip ; return tmp + solve(rev) ); operation rev( s : String) : String pre: true post: true activity: ( return (StringLib.newString(s))->reverse()+"" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A { String solve(Scanner sc){ int N=sc.nextInt(); int[] dp=new int[N+1]; dp[1]=1 ; for(int i=2 ; i<=N ; i++){ dp[i]=Integer.MAX_VALUE ; } for(int i=1 ; i0){ r*=10 ; r+=N % 10 ; N/=10 ; } return r ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int cs=1 ; cs<=T ; cs++){ String res=new A().solve(sc); System.out.println("Case #"+cs+": "+res); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class A { operation solve( sc : OclFile) : String pre: true post: true activity: ( var N : int ; N := sc.nextInt() ; var dp : Sequence(int) ; dp := Integer.subrange(1,N + 1)->collect(0) ; dp[1+1] := 1 ; var i : int ; i := 2 ; while i <= N do ( ( dp[i+1] := 2147483647 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < N do ( ( dp[i + 1+1] := Set{dp[i + 1+1], dp[i+1] + 1}->min() ; var r : int ; r := reverse(i) ; if (r <= N) then ( dp[r+1] := Set{dp[r+1], dp[i+1] + 1}->min() ) else skip ) ; i := i + 1 ) ; return "" + dp[N+1] ); operation reverse( N : int) : int pre: true post: true activity: ( var r : int ; r := 0 ; while (N > 0) do ( r := r*(10) ; r := r+(N mod 10) ; N := N/(10) ) ; return r ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := sc.getCurrent()->toInteger() ; var cs : int ; cs := 1 ; while cs <= T do ( ( var res : String ; res := A.newA().solve(sc) ; OclFile["System.out"].println("Case #" + cs + ": " + res) ) ; cs := cs + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); for(int i=0 ; i1){ break ; } } } if(index<2){ System.out.println(-1); return false ; } else { System.out.println(2); System.out.println(res[0]+" "+res[1]); return true ; } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var len : int ; len := input.getCurrent()->toInteger() ; var nums : Sequence(int) ; nums := Integer.subrange(1,len)->collect(0) ; var j : int ; j := 0 ; while j < len do ( ( nums[j+1] := input.getCurrent()->toInteger() ) ; j := j + 1 ) ; execute func(nums) ) ; i := i + 1 ) ); static operation func( nums : Sequence(int)) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < nums->size() do ( ( if (nums[i+1] mod 2 = 0) then ( OclFile["System.out"].println(1) ; OclFile["System.out"].println(i + 1) ; return true ) else skip ) ; i := i + 1 ) ; var res : Sequence(int) ; res := Integer.subrange(1,2)->collect(0) ; var index : int ; index := 0 ; var i : int ; i := 0 ; while i < nums->size() do ( ( if (nums[i+1] mod 2 /= 0) then ( res[index+1] := i + 1 ; index := index + 1 ; if (index > 1) then ( break ) else skip ) else skip ) ; i := i + 1 ) ; if (index < 2) then ( OclFile["System.out"].println(-1) ; return false ) else ( OclFile["System.out"].println(2) ; OclFile["System.out"].println(res[0+1] + " " + res[1+1]) ; return true ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ new Main().solve(); } private void solve(){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var even : int ; even := -1 ; var odd1 : int ; odd1 := -1 ; var odd2 : int ; odd2 := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] mod 2 /= 0) then ( if (odd1 = -1) then ( odd1 := i ) else if (odd2 = -1) then ( odd2 := i ) else skip ; ) else if (even = -1) then ( even := i ) else skip ; ) ; i := i + 1 ) ; if (even /= -1) then ( OclFile["System.out"].println(1) ; OclFile["System.out"].println((even + 1)) ) else if (odd1 /= -1 & odd2 /= -1) then ( OclFile["System.out"].println(2) ; OclFile["System.out"].println((odd1 + 1) + " " + odd2) ) else ( OclFile["System.out"].println(-1) ) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNextInt()){ int m=in.nextInt(); while(m-->0){ int n=in.nextInt(); int[] num=new int[n]; for(int i=0 ; iindex=new LinkedList<>(); int sum=Arrays.stream(num).sum(); if(sum % 2==1){ if(num.length==1){ System.out.println(-1); return ; } System.out.println(num.length-1); boolean f=true ; for(int i=0 ; itoInteger() ; while (m > 0) do ( m := m - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var num : Sequence(int) ; num := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( num[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute solution(num) ) ; ) ) ); static operation solution( num : Sequence(int)) : void pre: true post: true activity: ( var index : Sequence(int) ; index := Sequence{} ; var sum : int ; sum := stream(num)->sum() ; if (sum mod 2 = 1) then ( if (num->size() = 1) then ( OclFile["System.out"].println(-1) ; return ) else skip ; OclFile["System.out"].println(num->size() - 1) ; var f : boolean ; f := true ; var i : int ; i := 0 ; while i < num->size() do ( ( if (f & num[i+1] mod 2 = 1) then ( f := false ; continue ) else skip ; OclFile["System.out"].print(i + 1) ; OclFile["System.out"].print(" ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) else ( OclFile["System.out"].println(num->size()) ; var i : int ; i := 0 ; while i < num->size() do ( ( OclFile["System.out"].print(i + 1) ; OclFile["System.out"].print(" ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class EvenSubsetSumProblem { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); int n,a,x,j ; boolean found ; while(t-->0){ n=s.nextInt(); a=s.nextInt(); j=0 ; found=false ; if(a % 2==0){ System.out.println("1"); System.out.println(j+1); found=true ; } x=a ; for(int i=1 ; itoInteger() ; var n : int ; var a : int ; var x : int ; var j : int ; var found : boolean ; while (t > 0) do ( t := t - 1 ; skip ; ( n := s.getCurrent()->toInteger() ; a := s.getCurrent()->toInteger() ; j := 0 ; found := false ; if (a mod 2 = 0) then ( OclFile["System.out"].println("1") ; OclFile["System.out"].println(j + 1) ; found := true ) else skip ; x := a ; var i : int ; i := 1 ; while i < n do ( ( a := s.getCurrent()->toInteger() ; if (not(found) & a mod 2 = 0) then ( OclFile["System.out"].println("1") ; OclFile["System.out"].println((i + 1)) ; found := true ) else if (not(found) & x mod 2 /= 0) then ( OclFile["System.out"].println("2") ; OclFile["System.out"].println((j + 1) + " " + (i + 1)) ; found := true ) else skip ; ; x := a ; j := i ) ; i := i + 1 ) ; if (not(found)) then OclFile["System.out"].println("-1") ; else skip ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int minimumSets(int arr[],int n,int key){ int i,j ; Arrays.sort(arr); for(i=0,j=n-1 ; i<=j ; ++i)if(arr[i]+arr[j]<=key)j--; return i ; } public static void main(String[] args){ int[] arr={ 3,5,3,4 }; int n=arr.length ; int key=5 ; System.out.println(minimumSets(arr,n,key)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation minimumSets( arr : Sequence(int), n : int, key : int) : int pre: true post: true activity: ( var i : int ; var j : int ; arr := arr->sort() ; i := 0 ; j := n - 1 ; while i <= j do ( if (arr[i+1] + arr[j+1] <= key) then j := j - 1 ; else skip ; ; i := i + 1 ) ; return i ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,5,3,4} ; var n : int ; n := arr->size() ; var key : int ; key := 5 ; OclFile["System.out"].println(minimumSets(arr, n, key)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; class Main { public static void main(String[] args){ int n=0 ; int[] d=null ; int[] b=new int[101]; try { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String s=reader.readLine(); n=Integer.parseInt(s); d=new int[n]; for(int i=0 ; icollect(0) ; try ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var s : String ; s := reader.readLine() ; n := (s)->toInteger() ; d := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( d[i+1] := (reader.readLine())->toInteger() ) ; i := i + 1 ) ; ) catch (e : IOException) do ( e.printStackTrace() ) var c : int ; c := 0 ; var i : int ; i := 0 ; while i < n do ( ( b[d[i+1]+1] := b[d[i+1]+1] + 1 ; if (b[d[i+1]+1] = 1) then ( c := c + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.Math ; class GFG { static int fib(int n){ double phi=(1+Math.sqrt(5))/2 ; return(int)Math.round(Math.pow(phi,n)/Math.sqrt(5)); } static int calculateSum(int l,int r){ int sum=0 ; for(int i=l ; i<=r ; i++)sum+=fib(i); return sum ; } public static void main(String[] args){ int l=4,r=8 ; System.out.println(calculateSum(l,r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fib( n : int) : int pre: true post: true activity: ( var phi : double ; phi := (1 + (5)->sqrt()) / 2 ; return (phi->pow(n) / (5)->sqrt())->round()->oclAsType(int) ); static operation calculateSum( l : int, r : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := l ; while i <= r do ( sum := sum+(fib(i)) ; ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 4 ; var r : int ; r := 8 ; OclFile["System.out"].println(calculateSum(l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; class GFG { static int commonWords(String[] s){ int m,i,j ; String str ; HashMaphas=new HashMap<>(); String[] ans1=new String[100]; boolean[] ans2=new boolean[100]; int track=0 ; m=s.length ; i=0 ; while(icollect(null) ; var ans2 : Sequence(boolean) ; ans2 := Integer.subrange(1,100)->collect(false) ; var track : int ; track := 0 ; m := s->size() ; i := 0 ; while (i < s[0+1]->size()) do ( str := "" ; while (i < s[0+1]->size() & s[0+1]->at(i+1) /= ' ') do ( str := str+(s[0+1]->at(i+1)) ; i := i + 1 ) ; i := i + 1 ; if (str->compareTo("") /= 0) then ( ans1[track+1] := str ; ans2[track+1] := true ; track := track + 1 ) else skip ) ; j := 1 ; while j < m do ( ( has := has->intersection(Map{}) ; i := 0 ; while (i < s[j+1]->size()) do ( str := "" ; while (i < s[j+1]->size() & s[j+1]->at(i+1) /= ' ') do ( str := str+(s[j+1]->at(i+1)) ; i := i + 1 ) ; i := i + 1 ; if (str->compareTo("") /= 0) then has := has->union(Map{str |-> true}) ; else skip ) ; var k : int ; k := 0 ; while k < track do ( ( if (ans2[k+1] /= false & not(has->keys()->includes(ans1[k+1]))) then ans2[k+1] := false ; else if (ans2[k+1] /= false & has->keys()->includes(ans1[k+1]) & has->at(ans1[k+1]) = true) then has := has->union(Map{ans1[k+1] |-> false}) ; else skip ; ) ; k := k + 1 ) ) ; j := j + 1 ) ; var cnt : int ; cnt := 0 ; var k : int ; k := 0 ; while k < track do ( if (ans2[k+1] = true) then cnt := cnt + 1 ; else skip ; ; k := k + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : Sequence(String) ; s := Sequence{"there is a cow","cow is our mother","cow gives us milk and milk is sweet","there is a boy who loves cow"} ; OclFile["System.out"].println(commonWords(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int dayNum=scan.nextInt(); int chcolotaNum=scan.nextInt(); int[] arr=new int[dayNum]; for(int i=0 ; i=8){ arr[i+1]+=(arr[i]-8); sum+=8 ; res++; if(sum>=chcolotaNum){ System.out.println(res); break ; } } else { sum+=arr[i]; res++; if(sum>=chcolotaNum){ System.out.println(res); break ; } } } else { if(arr[i]>=8){ sum+=8 ; res++; if(sum>=chcolotaNum){ System.out.println(res); } else { System.out.println(-1); } } else { sum+=arr[i]; res++; if(sum>=chcolotaNum){ System.out.println(res); } else { System.out.println(-1); } } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var dayNum : int ; dayNum := scan.getCurrent()->toInteger() ; var chcolotaNum : int ; chcolotaNum := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,dayNum)->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( ( arr[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var res : int ; res := 0 ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < arr->size() do ( ( if (i /= arr->size() - 1) then ( if (arr[i+1] >= 8) then ( arr[i + 1+1] := arr[i + 1+1]+((arr[i+1] - 8)) ; sum := sum+(8) ; res := res + 1 ; if (sum >= chcolotaNum) then ( OclFile["System.out"].println(res) ; break ) else skip ) else ( sum := sum+(arr[i+1]) ; res := res + 1 ; if (sum >= chcolotaNum) then ( OclFile["System.out"].println(res) ; break ) else skip ) ) else ( if (arr[i+1] >= 8) then ( sum := sum+(8) ; res := res + 1 ; if (sum >= chcolotaNum) then ( OclFile["System.out"].println(res) ) else ( OclFile["System.out"].println(-1) ) ) else ( sum := sum+(arr[i+1]) ; res := res + 1 ; if (sum >= chcolotaNum) then ( OclFile["System.out"].println(res) ) else ( OclFile["System.out"].println(-1) ) ) ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CandieCheck { public static void main(String[] args){ Scanner in=new Scanner(System.in); String inputLine1=in.nextLine(); String[] in1=inputLine1.split(" "); String inputLine2=in.nextLine(); String[] in2=inputLine2.split(" "); int days=0,i=0 ; int[] totalCandies=new int[in2.length]; in.close(); int numOfDays=Integer.parseInt(in1[0]); int numOfCandies=Integer.parseInt(in1[1]); for(int j=0 ; j0 && i8){ totalCandies[i]-=8 ; numOfCandies-=8 ; if(isplit(" ") ; var inputLine2 : String ; inputLine2 := in.nextLine() ; var in2 : Sequence(String) ; in2 := inputLine2->split(" ") ; var days : int ; days := 0 ; var i : int ; i := 0 ; var totalCandies : Sequence(int) ; totalCandies := Integer.subrange(1,in2->size())->collect(0) ; skip ; var numOfDays : int ; numOfDays := (in1[0+1])->toInteger() ; var numOfCandies : int ; numOfCandies := (in1[1+1])->toInteger() ; var j : int ; j := 0 ; while j < in2->size() do ( ( totalCandies[j+1] := (in2[j+1])->toInteger() ) ; j := j + 1 ) ; while (days < numOfDays & numOfCandies > 0 & i < totalCandies->size()) do ( if (totalCandies[i+1] > 8) then ( totalCandies[i+1] := totalCandies[i+1]-(8) ; numOfCandies := numOfCandies-(8) ; if (i < totalCandies->size() - 1) then ( totalCandies[i + 1+1] := totalCandies[i + 1+1]+(totalCandies[i+1]) ) else skip ) else ( numOfCandies := numOfCandies-(totalCandies[i+1]) ) ; i := i + 1 ; days := days + 1 ) ; if (numOfCandies <= 0) then ( OclFile["System.out"].println(days) ) else ( OclFile["System.out"].println("-1") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class AryaAndBran { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int sum=0 ; int temp=0 ; int count=0 ; for(int i=0 ; i=k){ count=i+1 ; break ; } } if(count==0){ System.out.println(-1); } else { System.out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class AryaAndBran { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var temp : int ; temp := 0 ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; x := x+(temp) ; var y : int ; y := Set{8, x}->min() ; sum := sum+(y) ; temp := x - y ; if (sum >= k) then ( count := i + 1 ; break ) else skip ; ) ; i := i + 1 ) ; if (count = 0) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(count) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int sumOfTheSeries(int n){ int sum=0 ; for(int i=1 ; i<=n ; i++){ int k=1 ; for(int j=1 ; j<=i ; j++){ sum+=k ; k+=2 ; } } return sum ; } public static void main(String[] args){ int n=5 ; System.out.println("Sum="+sumOfTheSeries(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfTheSeries( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var k : int ; k := 1 ; var j : int ; j := 1 ; while j <= i do ( ( sum := sum+(k) ; k := k+(2) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println("Sum=" + sumOfTheSeries(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isPowerOfTwo(int n){ return n!=0 &&((n &(n-1))==0); } static int previousPowerOfTwo(int n){ while((n & n-1)>1){ n=n & n-1 ; } return n ; } static boolean checkSum(int n){ if(n==0 || n==1)return false ; else if(isPowerOfTwo(n)){ System.out.println(n/2+" "+n/2); } else { int x=previousPowerOfTwo(n); int y=n-x ; if(isPowerOfTwo(y)){ System.out.println(x+" "+y); return true ; } } return false ; } public static void main(String[] argc){ int n1=20 ; if(checkSum(n1)==false)System.out.println("No"); System.out.println(); int n2=11 ; if(checkSum(n2)==false)System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPowerOfTwo( n : int) : boolean pre: true post: true activity: ( return n /= 0 & ((n & (n - 1)) = 0) ); static operation previousPowerOfTwo( n : int) : int pre: true post: true activity: ( while ((n & n - 1) > 1) do ( n := n & n - 1 ) ; return n ); static operation checkSum( n : int) : boolean pre: true post: true activity: ( if (n = 0 or n = 1) then return false else if (isPowerOfTwo(n)) then ( OclFile["System.out"].println(n / 2 + " " + n / 2) ) else ( var x : int ; x := previousPowerOfTwo(n) ; var y : int ; y := n - x ; if (isPowerOfTwo(y)) then ( OclFile["System.out"].println(x + " " + y) ; return true ) else skip ) ; ; return false ); static operation main( argc : Sequence(String)) : void pre: true post: true activity: ( var n1 : int ; n1 := 20 ; if (checkSum(n1) = false) then OclFile["System.out"].println("No") ; else skip ; OclFile["System.out"].println() ; var n2 : int ; n2 := 11 ; if (checkSum(n2) = false) then OclFile["System.out"].println("No") ; else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countSubarray(int arr[],int n,int k){ int start=0,end=0 ; int count=0,sum=arr[0]; while(start=start)count+=end-start ; if(end= start) then count := count+(end - start) ; else skip ; if (end < n) then sum := sum+(arr[end+1]) ; else skip ) else ( sum := sum-(arr[start+1]) ; start := start + 1 ) ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var array : Sequence(int) ; array := Sequence{1,11,2,3,15} ; var k : int ; k := 10 ; var size : int ; size := array->size() ; var count : int ; count := countSubarray(array, size, k) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.*; import java.util.*; public class TpoDoList { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int k=s.nextInt(); int[] a=new int[n]; for(int i=0 ; i>list=new ArrayList<>(); int size=n/k ; for(int i=0 ; itemp=new ArrayList<>(); for(int j=0 ; ji : list){ int sum=0 ; int val=0 ; for(int j=0 ; jtoInteger() ; var k : int ; k := s.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := s.getCurrent()->toInteger() ; ; i := i + 1 ) ; var list : Sequence(Sequence(int)) ; list := Sequence{} ; var size : int ; size := n / k ; var i : int ; i := 0 ; while i < k do ( ( var m : int ; m := i ; var temp : Sequence(int) ; temp := Sequence{} ; var j : int ; j := 0 ; while j < size do ( ( temp := temp->including(m) ; m := (m + k) mod n ) ; j := j + 1 ) ; list := list->including(temp) ) ; i := i + 1 ) ; var max : int ; max := 2147483647 ; var ans : int ; ans := 0 ; for (i : list) do ( ( var sum : int ; sum := 0 ; var val : int ; val := 0 ; var j : int ; j := 0 ; while j < i->size() do ( ( if (j = 0) then val := i->at(j+1) ; else skip ; sum := sum+(a[i->at(j+1)+1]) ) ; j := j + 1 ) ; if (sum < max) then ( max := sum ; ans := val ) else skip ) ) ; OclFile["System.out"].println(ans + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class b366 { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int d=scan.nextInt(); int a[]=new int[n]; long b[]=new long[d]; for(int i=0 ; itoInteger() ; var d : int ; d := scan.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,d)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scan.getCurrent()->toInteger() ; b[i mod d+1] := b[i mod d+1]+(a[i+1]) ) ; i := i + 1 ) ; var in : int ; in := -1 ; var min : long ; min := 10->pow(9)->oclAsType(long) ; var j : int ; j := 0 ; while j < d do ( ( if (b[j+1] < min) then ( min := b[j+1] ; in := j ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println(in + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int fib(int n){ double phi=(1+Math.sqrt(5))/2 ; return(int)Math.round(Math.pow(phi,n)/Math.sqrt(5)); } static int calculateSum(int l,int r){ int sum=fib(r+2)-fib(l+1); return sum ; } static int sumFibonacci(int k){ int l=(k*(k-1))/2 ; int r=l+k ; int sum=calculateSum(l,r-1); return sum ; } public static void main(String args[]){ int k=3 ; System.out.println(sumFibonacci(k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fib( n : int) : int pre: true post: true activity: ( var phi : double ; phi := (1 + (5)->sqrt()) / 2 ; return (phi->pow(n) / (5)->sqrt())->round()->oclAsType(int) ); static operation calculateSum( l : int, r : int) : int pre: true post: true activity: ( var sum : int ; sum := fib(r + 2) - fib(l + 1) ; return sum ); static operation sumFibonacci( k : int) : int pre: true post: true activity: ( var l : int ; l := (k * (k - 1)) / 2 ; var r : int ; r := l + k ; var sum : int ; sum := calculateSum(l, r - 1) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 3 ; OclFile["System.out"].println(sumFibonacci(k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int R=4 ; static int C=3 ; static boolean isSafe(int x,int y){ return(xcollect(Integer.subrange(1,C)->collect(0)); static operation minJump( height : Sequence(Sequence(int)), x : int, y : int) : int 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]) ) else skip ; var diag : int ; diag := 2147483647 ; if (isSafe(x + 1, y + 1)) then ( diag := minJump(height, x + 1, y + 1) + if height[x+1][y+1] - height[x + 1+1][y + 1+1] < 0 then -(height[x+1][y+1] - height[x + 1+1][y + 1+1]) else height[x+1][y+1] - height[x + 1+1][y + 1+1] endif ) else skip ; var down : int ; down := 2147483647 ; if (isSafe(x + 1, y)) then ( down := minJump(height, x + 1, y) + if height[x+1][y+1] - height[x + 1+1][y+1] < 0 then -(height[x+1][y+1] - height[x + 1+1][y+1]) else height[x+1][y+1] - height[x + 1+1][y+1] endif ) else skip ; var right : int ; right := 2147483647 ; if (isSafe(x, y + 1)) then ( right := minJump(height, x, y + 1) + if height[x+1][y+1] - height[x+1][y + 1+1] < 0 then -(height[x+1][y+1] - height[x+1][y + 1+1]) else height[x+1][y+1] - height[x+1][y + 1+1] endif ) else skip ; dp[x+1][y+1] := Set{Set{down, right}->min(), diag}->min() ; return dp[x+1][y+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var height : Sequence(Sequence(int)) ; height := Sequence{Sequence{5,4,2},Sequence{9,2,1},Sequence{2,5,9},Sequence{1,3,11}} ; var i : int ; i := 0 ; while i < R do ( ( var j : int ; j := 0 ; while j < C do ( ( dp[i+1][j+1] := -1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(minJump(height, 0, 0)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DimaAndToDoList { public static void main(String args[]){ int n,k,i,j ; Scanner scan=new Scanner(System.in); n=scan.nextInt(); k=scan.nextInt(); int[] a=new int[n+1]; for(i=1 ; i<=n ; i++)a[i]=scan.nextInt(); int sum,mm=Integer.MAX_VALUE,p=-1 ; for(i=1 ; i<=k ; i++){ sum=0 ; for(j=i ; j<=n ; j+=k){ sum+=a[j]; } if(sumtoInteger() ; k := scan.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; i := 1 ; while i <= n do ( a[i+1] := scan.getCurrent()->toInteger() ; ; i := i + 1 ) ; var sum : int ; var mm : int ; mm := 2147483647 ; var p : int ; p := -1 ; i := 1 ; while i <= k do ( ( sum := 0 ; j := i ; while j <= n do ( ( sum := sum+(a[j+1]) ) ; j := j+(k) ) ; if (sum < mm) then ( mm := sum ; p := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(p) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class temp { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var moves : int ; moves := k ; var min : int ; min := 2147483647 ; var start : int ; start := -1 ; var i : int ; i := 0 ; while i < moves do ( ( var tmp : int ; tmp := 0 ; var j : int ; j := i ; while j < (i + n) do ( ( tmp := tmp+(arr[j+1]) ) ; j := j+(k) ) ; if (tmp < min) then ( min := tmp ; start := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(start + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int KnapSack(int val[],int wt[],int n,int W){ int mat[][]=new int[2][W+1]; int i=0 ; while(icollect(Integer.subrange(1,W + 1)->collect(0)) ; var i : int ; i := 0 ; while (i < n) do ( var j : int ; j := 0 ; if (i mod 2 /= 0) then ( j := j + 1 ; while ((j + 1) <= W) do ( j := j + 1 ; skip ; ( if (wt[i+1] <= j) then ( mat[1+1][j+1] := Set{val[i+1] + mat[0+1][j - wt[i+1]+1], mat[0+1][j+1]}->max() ) else ( mat[1+1][j+1] := mat[0+1][j+1] ) ) ; j := j + 1 ; ) ) else ( j := j + 1 ; while ((j + 1) <= W) do ( j := j + 1 ; skip ; ( if (wt[i+1] <= j) then ( mat[0+1][j+1] := Set{val[i+1] + mat[1+1][j - wt[i+1]+1], mat[1+1][j+1]}->max() ) else ( mat[0+1][j+1] := mat[1+1][j+1] ) ) ; j := j + 1 ; ) ) ; i := i + 1 ) ; return if (n mod 2 /= 0) then mat[0+1][W+1] else mat[1+1][W+1] endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var val : Sequence(void) ; val := Sequence{7,8,4} ; var wt : Sequence(void) ; wt := Sequence{3,8,6} ; var W : int ; W := 10 ; var n : int ; n := 3 ; OclFile["System.out"].println(KnapSack(val, wt, n, W)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNextInt()){ int h1=sc.nextInt(); int h2=sc.nextInt(); int k1=sc.nextInt(); int k2=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); int hiroshi=h1*a+(h1/10)*c+h2*b+(h2/20)*d ; int kenjiro=k1*a+(k1/10)*c+k2*b+(k2/20)*d ; if(hiroshi>kenjiro){ System.out.println("hiroshi"); } else if(hiroshitoInteger() ; var h2 : int ; h2 := sc.getCurrent()->toInteger() ; var k1 : int ; k1 := sc.getCurrent()->toInteger() ; var k2 : int ; k2 := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var hiroshi : int ; hiroshi := h1 * a + (h1 / 10) * c + h2 * b + (h2 / 20) * d ; var kenjiro : int ; kenjiro := k1 * a + (k1 / 10) * c + k2 * b + (k2 / 20) * d ; if (hiroshi > kenjiro) then ( OclFile["System.out"].println("hiroshi") ) else if (hiroshi < kenjiro) then ( OclFile["System.out"].println("kenjiro") ) else ( OclFile["System.out"].println("even") ) ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; class Main { public static void main(String[] args){ BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in)); String str="" ; StringTokenizer stk ; int hirosi_i,hirosi_y ; int kenjir_i,kenjir_y ; int iwana_P,yamame_P,iwana10_B,yamame20_B ; int sc_h,sc_k ; try { str=bfr.readLine(); if(str==""){ System.exit(0); } stk=new StringTokenizer(str," "); hirosi_i=Integer.parseInt(stk.nextToken()); hirosi_y=Integer.parseInt(stk.nextToken()); str=bfr.readLine(); if(str==""){ System.exit(0); } stk=new StringTokenizer(str," "); kenjir_i=Integer.parseInt(stk.nextToken()); kenjir_y=Integer.parseInt(stk.nextToken()); str=bfr.readLine(); if(str==""){ System.exit(0); } stk=new StringTokenizer(str," "); iwana_P=Integer.parseInt(stk.nextToken()); yamame_P=Integer.parseInt(stk.nextToken()); iwana10_B=Integer.parseInt(stk.nextToken()); yamame20_B=Integer.parseInt(stk.nextToken()); sc_h=iwana_P*hirosi_i+(hirosi_i/10)*iwana10_B+yamame_P*hirosi_y+(hirosi_y/20)*yamame20_B ; sc_k=iwana_P*kenjir_i+(kenjir_i/10)*iwana10_B+yamame_P*kenjir_y+(kenjir_y/20)*yamame20_B ; if(sc_k>sc_h){ System.out.println("kenjiro"); } else if(sc_ktoInteger() ; hirosi_y := (stk.next())->toInteger() ; str := bfr.readLine() ; if (str = "") then ( OclProcess.exit(0) ) else skip ; stk := OclIterator.newOclIterator_String_String(str, " ") ; kenjir_i := (stk.next())->toInteger() ; kenjir_y := (stk.next())->toInteger() ; str := bfr.readLine() ; if (str = "") then ( OclProcess.exit(0) ) else skip ; stk := OclIterator.newOclIterator_String_String(str, " ") ; iwana_P := (stk.next())->toInteger() ; yamame_P := (stk.next())->toInteger() ; iwana10_B := (stk.next())->toInteger() ; yamame20_B := (stk.next())->toInteger() ; sc_h := iwana_P * hirosi_i + (hirosi_i / 10) * iwana10_B + yamame_P * hirosi_y + (hirosi_y / 20) * yamame20_B ; sc_k := iwana_P * kenjir_i + (kenjir_i / 10) * iwana10_B + yamame_P * kenjir_y + (kenjir_y / 20) * yamame20_B ; if (sc_k > sc_h) then ( OclFile["System.out"].println("kenjiro") ) else if (sc_k < sc_h) then ( OclFile["System.out"].println("hiroshi") ) else if (sc_k = sc_h) then ( OclFile["System.out"].println("even") ) else skip ; ; ; ) catch (e : IOException) do ( OclProcess.exit(0) ) catch (e : IncorrectElementException) do ( OclProcess.exit(0) ) catch (e : NullAccessException) do ( OclProcess.exit(0) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { void solve(){ Scanner sc=new Scanner(System.in); int h1=sc.nextInt(); int h2=sc.nextInt(); int k1=sc.nextInt(); int k2=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); int hiroshi=h1*a+h2*b+(h1/10)*c+(h2/20)*d ; int kenjiro=k1*a+k2*b+(k1/10)*c+(k2/20)*d ; if(hiroshi>kenjiro)System.out.println("hiroshi"); else if(hiroshitoInteger() ; var h2 : int ; h2 := sc.getCurrent()->toInteger() ; var k1 : int ; k1 := sc.getCurrent()->toInteger() ; var k2 : int ; k2 := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var hiroshi : int ; hiroshi := h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d ; var kenjiro : int ; kenjiro := k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d ; if (hiroshi > kenjiro) then OclFile["System.out"].println("hiroshi") else if (hiroshi < kenjiro) then OclFile["System.out"].println("kenjiro") else OclFile["System.out"].println("even") ; ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int F[][]=new int[2][2]; for(int i=0 ; i<2 ; i++){ for(int j=0 ; j<2 ; j++)F[i][j]=in.nextInt(); } int a=in.nextInt(),b=in.nextInt(),c=in.nextInt(),d=in.nextInt(); int hiro=(a*F[0][0])+(b*F[0][1])+(F[0][0]/10*c)+(F[0][1]/20*d); int ken=(a*F[1][0])+(b*F[1][1])+(F[1][0]/10*c)+(F[1][1]/20*d); String res ; if(hiro>ken)res="hiroshi" ; else if(ken>hiro)res="kenjiro" ; else res="even" ; System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var F : Sequence(Sequence(int)) ; F := Integer.subrange(1,2)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < 2 do ( ( var j : int ; j := 0 ; while j < 2 do ( F[i+1][j+1] := in.getCurrent()->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var c : int ; c := in.getCurrent()->toInteger() ; var d : int ; d := in.getCurrent()->toInteger() ; var hiro : int ; hiro := (a * F[0+1][0+1]) + (b * F[0+1][1+1]) + (F[0+1][0+1] / 10 * c) + (F[0+1][1+1] / 20 * d) ; var ken : int ; ken := (a * F[1+1][0+1]) + (b * F[1+1][1+1]) + (F[1+1][0+1] / 10 * c) + (F[1+1][1+1] / 20 * d) ; var res : String ; if (hiro > ken) then res := "hiroshi" else if (ken > hiro) then res := "kenjiro" else res := "even" ; ; ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int h1,h2,k1,k2,a,b,c,d ; line=br.readLine(); h1=parseInt(line.substring(0,line.indexOf(' '))); h2=parseInt(line.substring(line.indexOf(' ')+1)); line=br.readLine(); k1=parseInt(line.substring(0,line.indexOf(' '))); k2=parseInt(line.substring(line.indexOf(' ')+1)); StringTokenizer st=new StringTokenizer(br.readLine()); a=parseInt(st.nextToken()); b=parseInt(st.nextToken()); c=parseInt(st.nextToken()); d=parseInt(st.nextToken()); int h,k ; h=h1*a+h2*b+(h1/10)*c+(h2/20)*d ; k=k1*a+k2*b+(k1/10)*c+(k2/20)*d ; System.out.println(h==k ? "even" :(h>k ? "hiroshi" : "kenjiro")); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var h1 : int ; var h2 : int ; var k1 : int ; var k2 : int ; var a : int ; var b : int ; var c : int ; var d : int ; line := br.readLine() ; h1 := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; h2 := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; line := br.readLine() ; k1 := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; k2 := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; a := (st.next() + "")->toInteger() ; b := (st.next() + "")->toInteger() ; c := (st.next() + "")->toInteger() ; d := (st.next() + "")->toInteger() ; var h : int ; var k : int ; h := h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d ; k := k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d ; OclFile["System.out"].println(if h = k then "even" else (if h > k then "hiroshi" else "kenjiro" endif) endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long max=n-1L ; long result=0 ; for(long i=1L ; itoLong() ; var max : long ; max := n - 1L ; var result : long ; result := 0 ; var i : long ; i := 1L ; while i < n do ( ( var tempMax : long ; tempMax := max / i ; result := result + tempMax ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int fib(int n){ double phi=(1+Math.sqrt(5))/2 ; return(int)Math.round(Math.pow(phi,n)/Math.sqrt(5)); } static int calculateSum(int l,int r){ int sum=fib(r+2)-fib(l+1); return sum ; } public static void main(String[] args){ int l=4,r=8 ; System.out.println(calculateSum(l,r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation fib( n : int) : int pre: true post: true activity: ( var phi : double ; phi := (1 + (5)->sqrt()) / 2 ; return (phi->pow(n) / (5)->sqrt())->round()->oclAsType(int) ); static operation calculateSum( l : int, r : int) : int pre: true post: true activity: ( var sum : int ; sum := fib(r + 2) - fib(l + 1) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 4 ; var r : int ; r := 8 ; OclFile["System.out"].println(calculateSum(l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ MyScanner sc=new MyScanner(); PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); long res=0 ; for(int i=1 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class B { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int zz=1 ; zz<=T ; zz++){ int N=in.nextInt(); int K=in.nextInt(); long[] sum=new long[N-K+1]; for(int i=0 ; i=K)throw new RuntimeException(); for(long ans=B[K-1]; ; ans++){ long less=0 ; for(long b : B)less+=ans-b ; if(less>=d){ System.out.format("Case #%d: %d\n",zz,ans); break ; } } } } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := in.getCurrent()->toInteger() ; var zz : int ; zz := 1 ; while zz <= T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var sum : Sequence(long) ; sum := Integer.subrange(1,N - K + 1)->collect(0) ; var i : int ; i := 0 ; while i < sum->size() do ( sum[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var diff : Sequence(long) ; diff := Integer.subrange(1,N)->collect(0) ; var A : Sequence(long) ; A := Integer.subrange(1,K)->collect(0) ; var B : Sequence(long) ; B := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 0 ; while i + 1 < sum->size() do ( ( var d : long ; d := sum[i + 1+1] - sum[i+1] ; diff[i + K+1] := diff[i+1] + d ; A[i mod K+1] := Set{A[i mod K+1], diff[i + K+1]}->min() ; B[i mod K+1] := Set{B[i mod K+1], diff[i + K+1]}->max() ) ; i := i + 1 ) ; var total : long ; total := 0 ; var i : int ; i := 0 ; while i < K do ( ( total := total-(A[i+1]) ; B[i+1] := B[i+1]-(A[i+1]) ; A[i+1] := 0 ) ; i := i + 1 ) ; B := B->sort() ; var d : long ; d := sum[0+1] - total ; d := ((d mod K) + K) mod K ; if (d < 0 or d >= K) then error ProgramException() ; else skip ; var ans : long ; ans := B[K - 1+1] ; while true do ( ( var less : long ; less := 0 ; for (b : B) do ( less := less+(ans - b) ; ) ; if (less >= d) then ( OclFile["System.out"].format("Case #%d: %d\n", zz, ans) ; break ) else skip ) ; ans := ans + 1 ) ; ) ; zz := zz + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Arrays ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { void solve(Scanner in,PrintWriter out){ int n=in.nextInt(); int cpt=0 ; for(int c=1 ; csqrt()->oclAsType(int) do ( ( if (n mod i = 0 & i * i /= n) then ( cpt := cpt+(2) ) else if (i * i = n) then ( cpt := cpt + 1 ) else skip ; ) ; i := i + 1 ) ; return cpt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]) ; ( Main.newMain().solve(in, out) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc ; int[] memo ; public static void main(String[] args){ new Main().execute(); } public void execute(){ this.sc=new Scanner(System.in); int n=sc.nextInt(); int cnt=0 ; this.memo=new int[n+1]; for(int i=1 ; itoInteger() ; var cnt : int ; cnt := 0 ; self.memo := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i < n do ( ( cnt := cnt+(countPair(n - i)) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); operation countPair( n : int) : int pre: true post: true activity: ( if (self.memo[n+1] /= 0) then ( return self.memo[n+1] ) else skip ; var cnt : int ; cnt := 0 ; var max : int ; max := ((n)->sqrt())->oclAsType(int) ; var i : int ; i := 1 ; while i <= max do ( ( if (n mod i = 0) then ( cnt := cnt+((if i = n / i then 1 else 2 endif)) ) else skip ) ; i := i + 1 ) ; self.memo[n+1] := cnt ; return cnt ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); double n=sc.nextInt(); long sum=0 ; for(int i=1 ; itoInteger() ; var sum : long ; sum := 0 ; var i : int ; i := 1 ; while i < n do ( ( var one : int ; one := 0 ; if (n mod i = 0) then one := 1 ; else skip ; var tmp : int ; tmp := n->oclAsType(int) / i - one ; sum := sum+(tmp) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static int min1=Integer.MAX_VALUE ; static int count=0 ; public int permutation(String str1,int i,int n,int p){ if(i==n){ int q=Integer.parseInt(str1); if(q-p>0 && qtoInteger() ; if (q - p > 0 & q < min1) then ( min1 := q ; count := 1 ) else skip ) else ( var j : int ; j := i ; while j <= n do ( ( str1 := swap(str1, i, j) ; execute permutation(str1, i + 1, n, p) ; str1 := swap(str1, i, j) ) ; j := j + 1 ) ) ; return min1 ); operation swap( str : String, i : int, j : int) : String pre: true post: true activity: ( var ch : Sequence(String) ; ch := str->characters() ; var temp : String ; temp := ch[i+1] ; ch[i+1] := ch[j+1] ; ch[j+1] := temp ; return ((ch) + "") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 213 ; var B : int ; B := 111 ; var gfg : GFG ; gfg := GFG.newGFG() ; var str1 : String ; str1 := ((A) + "") ; var len : int ; len := str1->size() ; var h : int ; h := gfg.permutation(str1, 0, (len)->char2byte() - 1, B) ; if (count = 1) then OclFile["System.out"].println(h) else OclFile["System.out"].println(-1) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class LC { static class pair { int l,r ; public pair(int l,int r){ this.l=l ; this.r=r ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int p=sc.nextInt(),q=sc.nextInt(),s=sc.nextInt(),e=sc.nextInt(); ArrayListl1=new ArrayList<>(); ArrayListl2=new ArrayList<>(); for(int i=0 ; i

=l2.get(k).l+i && l1.get(j).l<=l2.get(k).r+i)flag=true ; if(l1.get(j).l<=l2.get(k).l+i && l1.get(j).r>=l2.get(k).l+i)flag=true ; } } if(flag)ans++; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class LC { static class pair { attribute l : int; static operation newpair( l : int, r : int) : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(l, r); return self ); operation initialise( l : int, r : int) : void pre: true post: true activity: ( self.l := l ; self.r := r ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var p : int ; p := sc.getCurrent()->toInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var s : int ; s := sc.getCurrent()->toInteger() ; var e : int ; e := sc.getCurrent()->toInteger() ; var l1 : Sequence(pair) ; l1 := Sequence{} ; var l2 : Sequence(pair) ; l2 := Sequence{} ; var i : int ; i := 0 ; while i < p do ( ( l1 := l1->including(pair.newpair(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( l2 := l2->including(pair.newpair(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger())) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := s ; while i <= e do ( ( var flag : boolean ; flag := false ; var j : int ; j := 0 ; while j < l1->size() do ( ( var k : int ; k := 0 ; while k < l2->size() do ( ( if (l1->at(j+1).l >= l2->at(k+1).l + i & l1->at(j+1).l <= l2->at(k+1).r + i) then flag := true ; else skip ; if (l1->at(j+1).l <= l2->at(k+1).l + i & l1->at(j+1).r >= l2->at(k+1).l + i) then flag := true ; else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ; if (flag) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int longestSubsequenceCommonSegment(int k,String s1,String s2){ int n=s1.length(); int m=s2.length(); int lcs[][]=new int[n+1][m+1]; int cnt[][]=new int[n+1][m+1]; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=m ; j++){ lcs[i][j]=Math.max(lcs[i-1][j],lcs[i][j-1]); if(s1.charAt(i-1)==s2.charAt(j-1))cnt[i][j]=cnt[i-1][j-1]+1 ; if(cnt[i][j]>=k){ for(int a=k ; a<=cnt[i][j]; a++)lcs[i][j]=Math.max(lcs[i][j],lcs[i-a][j-a]+a); } } } return lcs[n][m]; } public static void main(String[] args){ int k=4 ; String s1="aggasdfa" ; String s2="aggajasdfa" ; System.out.println(longestSubsequenceCommonSegment(k,s1,s2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation longestSubsequenceCommonSegment( k : int, s1 : String, s2 : String) : int pre: true post: true activity: ( var n : int ; n := s1->size() ; var m : int ; m := s2->size() ; var lcs : Sequence(Sequence(int)) ; lcs := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,m + 1)->collect(0)) ; var cnt : Sequence(Sequence(int)) ; cnt := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,m + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= m do ( ( lcs[i+1][j+1] := Set{lcs[i - 1+1][j+1], lcs[i+1][j - 1+1]}->max() ; if (s1->at(i - 1+1) = s2->at(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] >= k) then ( var a : int ; a := k ; while a <= cnt[i+1][j+1] do ( lcs[i+1][j+1] := Set{lcs[i+1][j+1], lcs[i - a+1][j - a+1] + a}->max() ; ; a := a + 1 ) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return lcs[n+1][m+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 4 ; var s1 : String ; s1 := "aggasdfa" ; var s2 : String ; s2 := "aggajasdfa" ; OclFile["System.out"].println(longestSubsequenceCommonSegment(k, s1, s2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.Arrays ; class GFG { static int numberOfBST(int n){ int dp[]=new int[n+1]; Arrays.fill(dp,0); dp[0]=1 ; dp[1]=1 ; for(int i=2 ; i<=n ; i++){ for(int j=1 ; j<=i ; j++){ dp[i]=dp[i]+(dp[i-j]*dp[j-1]); } } return dp[n]; } public static void main(String[] args){ int n=3 ; System.out.println("Number of structurally "+"Unique BST with "+n+" keys are : "+numberOfBST(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation numberOfBST( n : int) : int pre: true post: true activity: ( var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp := dp->collect(0) ; dp[0+1] := 1 ; dp[1+1] := 1 ; var i : int ; i := 2 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= i do ( ( dp[i+1] := dp[i+1] + (dp[i - j+1] * dp[j - 1+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println("Number of structurally " + "Unique BST with " + n + " keys are : " + numberOfBST(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Faltu1 { public static ListprimeFactors(long n){ long cnt=0 ; Listlist=new ArrayList<>(); while(n % 2==0){ list.add(2l); n/=2 ; } for(long i=3 ; i<=Math.sqrt(n); i+=2){ while(n % i==0){ list.add(i); n/=i ; } } if(n>2)list.add(n); return list ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); Listlist=primeFactors(n); if(list.size()==2){ System.out.println(2); return ; } if(list.size()==1 || n==1l){ System.out.println(1); System.out.println(0); return ; } System.out.println(1); System.out.println(list.get(0)*list.get(1)); } } ------------------------------------------------------------ OCL File: --------- class Faltu1 { static operation primeFactors( n : long) : Sequence(long) pre: true post: true activity: ( var cnt : long ; cnt := 0 ; var list : Sequence(long) ; list := Sequence{} ; while (n mod 2 = 0) do ( list := list->including(2l) ; n := n/(2) ) ; var i : long ; i := 3 ; while i <= (n)->sqrt() do ( ( while (n mod i = 0) do ( list := list->including(i) ; n := n/(i) ) ) ; i := i+(2) ) ; if (n > 2) then list := list->including(n) ; else skip ; return list ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var list : Sequence(long) ; list := primeFactors(n) ; if (list->size() = 2) then ( OclFile["System.out"].println(2) ; return ) else skip ; if (list->size() = 1 or n = 1l) then ( OclFile["System.out"].println(1) ; OclFile["System.out"].println(0) ; return ) else skip ; OclFile["System.out"].println(1) ; OclFile["System.out"].println(list->at(0+1) * list->at(1+1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); public Main(){ int t=sc.nextInt(); sc.nextLine(); for(int i=0 ; itoInteger() ; skip ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; skip ; var s1 : String ; s1 := sc.nextLine() ; var s2 : String ; s2 := sc.nextLine() ; var isSame : boolean ; isSame := true ; var j : int ; j := 0 ; while j < s1->size() do ( ( if ((s1->at(j+1) = 'R' or s2->at(j+1) = 'R') & s1->at(j+1) /= s2->at(j+1)) then ( isSame := false ; break ) else skip ) ; j := j + 1 ) ; if (isSame) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Solution { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s[]=br.readLine().split(" "); String s1[]=br.readLine().split(" "); int b=Integer.parseInt(s[0]); int numOdd=0 ; int numeven=0 ; for(int i=0 ; isplit(" ") ; var s1 : Sequence(String) ; s1 := br.readLine()->split(" ") ; var b : int ; b := (s[0+1])->toInteger() ; var numOdd : int ; numOdd := 0 ; var numeven : int ; numeven := 0 ; var i : int ; i := 0 ; while i < s1->size() do ( ( if ((s1[i+1])->toInteger() mod 2 /= 0 & (s1[i+1])->toInteger() /= 0) then ( numOdd := numOdd + 1 ) else ( numeven := numeven + 1 ) ) ; i := i + 1 ) ; if (b mod 2 = 0) then ( if ((s1[s1->size() - 1+1])->toInteger() mod 2 = 0) then ( OclFile["System.out"].println("even") ) else ( OclFile["System.out"].println("odd") ) ) else ( if (numOdd mod 2 /= 0) then ( OclFile["System.out"].println("odd") ) else ( OclFile["System.out"].println("even") ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.StringTokenizer ; public class A { public static void main(String[] args){ FastScanner fs=new FastScanner(); boolean even=true ; int base=fs.nextInt(),k=fs.nextInt(); for(int i=0 ; i+1toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation readLongArray( n : int) : Sequence(long) pre: true post: true activity: ( var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextLong() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package round3 ; import java.util.Scanner ; public class B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int cases=sc.nextInt(); for(int caze=1 ; caze<=cases ; caze++){ int N=sc.nextInt(); int K=sc.nextInt(); int[] sums=new int[N-K+1]; for(int i=0 ; itoInteger() ; var caze : int ; caze := 1 ; while caze <= cases do ( ( var N : int ; N := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var sums : Sequence(int) ; sums := Integer.subrange(1,N - K + 1)->collect(0) ; var i : int ; i := 0 ; while i < sums->size() do ( ( sums[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var min : Sequence(int) ; min := Integer.subrange(1,K)->collect(0) ; var max : Sequence(int) ; max := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 0 ; while i < K do ( ( var val : int ; val := 0 ; var j : int ; j := i ; while j + 1 < sums->size() do ( ( val := val+(sums[j + 1+1] - sums[j+1]) ; min[i+1] := Set{min[i+1], val}->min() ; max[i+1] := Set{max[i+1], val}->max() ) ; j := j+(K) ) ) ; i := i + 1 ) ; var sumModulo : int ; sumModulo := 0 ; var maxInterval : int ; maxInterval := 0 ; var canUse : int ; canUse := 0 ; var i : int ; i := 0 ; while i < K do ( ( sumModulo := sumModulo-(min[i+1]) ; maxInterval := Set{maxInterval, max[i+1] - min[i+1]}->max() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < K do ( ( canUse := canUse+(maxInterval - (max[i+1] - min[i+1])) ) ; i := i + 1 ) ; var can : boolean ; can := false ; var i : int ; i := 0 ; while i <= canUse do ( ( if ((sumModulo + i - sums[0+1]) mod K = 0) then ( can := true ; break ) else skip ) ; i := i + 1 ) ; if (not(can)) then maxInterval := maxInterval + 1 ; else skip ; OclFile["System.out"].println("Case #" + caze + ": " + maxInterval) ; ) ; caze := caze + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MainClass { public static void main(String[] agrs){ Scanner sc=new Scanner(System.in); int b=sc.nextInt(); int k=sc.nextInt(); int[] lst=new int[k]; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var lst : Sequence(int) ; lst := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < k do ( ( lst[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var od : int ; od := 0 ; if (b mod 2 = 0) then ( if (lst[k - 1+1] mod 2 /= 0) then OclFile["System.out"].println("odd") ; else OclFile["System.out"].println("even") ; ) else ( var i : int ; i := 0 ; while i < k do ( ( if (lst[i+1] mod 2 = 1) then od := od + 1 ; else skip ) ; i := i + 1 ) ; if (od mod 2 = 1) then OclFile["System.out"].println("odd") ; else OclFile["System.out"].println("even") ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Collections ; import java.util.Vector ; class GFG { static void sortMultiples(int arr[],int n,int x){ Vectorv=new Vector(); for(int i=0 ; iincluding(arr[i+1]) ) else skip ) ; i := i + 1 ) ; v := v->sort() ; var j : int ; j := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] mod x = 0) then ( arr[i+1] := v->at(j+1) ) else skip ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{125,3,15,6,100,5} ; var x : int ; x := 5 ; var n : int ; n := arr->size() ; execute sortMultiples(arr, n, x) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(arr[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void sortMultiples(int arr[],int n,int x){ Vectorv=new Vector(); for(int i=0 ; iincluding(arr[i+1]) ) else skip ) ; i := i + 1 ) ; v, reverseOrder() := v, reverseOrder()->sort() ; var j : int ; j := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] mod x = 0) then ( arr[i+1] := v->at(j+1) ) else skip ) ; i := i + 1 ) ; ); static operation printArray( arr : Sequence(int), N : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < N do ( ( OclFile["System.out"].print(arr[i+1] + " ") ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{125,3,15,6,100,5} ; var x : int ; x := 5 ; var n : int ; n := arr->size() ; execute sortMultiples(arr, n, x) ; execute printArray(arr, n) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class Main { public void run(){ Scanner sc=new Scanner(System.in); boolean[] p=new boolean[300000]; boolean[] ms=new boolean[300000]; for(int i=0 ; icollect(false) ; var ms : Sequence(boolean) ; ms := Integer.subrange(1,300000)->collect(false) ; var i : int ; i := 0 ; while i < ms->size() do ( ( ms[i+1] := ((i mod 7 = 1) or (i mod 7 = 6)) ; p[i+1] := ms[i+1] ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i < ms->size() do ( ( if (p[i+1]) then ( var j : int ; j := i + i ; while j < ms->size() do ( ( p[j+1] := false ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 1) then ( break ) else skip ; OclFile["System.out"].print(n + ":") ; var i : int ; i := 2 ; while i <= n do ( ( if (not(p[i+1])) then continue else skip ; if (n mod i = 0) then ( OclFile["System.out"].print(" " + i) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ) ; ); static operation main( Aregs : Sequence(String)) : void pre: true post: true activity: ( var a : Main ; a := Main.newMain() ; a.run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int n,i ; for(; ; ){ n=sc.nextInt(); if(n==1)break ; out.print(n+":"); for(i=6 ; i<=n ; i++){ if(n % i==0 && ismsprime(i))out.print(" "+i); } out.println(); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } private static boolean ismsprime(int p){ int i ; if((p % 7!=1 && p % 7!=6)|| p==1)return false ; for(i=6 ; i*i<=p ; i+=5){ if(p % i==0)return false ; i+=2 ; if(p % i==0)return false ; } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var n : int ; var i : int ; while true do ( ( n := sc.nextInt() ; if (n = 1) then break else skip ; out.print(n + ":") ; i := 6 ; while i <= n do ( ( if (n mod i = 0 & ismsprime(i)) then out.print(" " + i) ; else skip ) ; i := i + 1 ) ; out.println() ; ) ) ; sc.close() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); static operation ismsprime( p : int) : boolean pre: true post: true activity: ( var i : int ; if ((p mod 7 /= 1 & p mod 7 /= 6) or p = 1) then return false else skip ; i := 6 ; while i * i <= p do ( ( if (p mod i = 0) then return false else skip ; i := i+(2) ; if (p mod i = 0) then return false else skip ) ; i := i+(5) ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { Scanner sc=new Scanner(in); int[] eratosthenes(int n){ boolean[] dp=new boolean[n+1]; Listprime=new LinkedList(); for(int i=2 ; i<=n ; i++){ if(i % 7==1 || i % 7==6){ if(dp[i])continue ; prime.add(i); for(int j=i+i ; j<=n ; j+=i)dp[j]=true ; } } int[] ret=new int[prime.size()]; int count=0 ; for(int num : prime)ret[count++]=num ; return ret ; } void run(){ int n ; int[] prime=eratosthenes(400000); while(true){ n=sc.nextInt(); if(n==1)break ; out.printf("%d:",n); int index=0 ; while(prime[index]<=n){ if(n % prime[index]==0 &&((n/prime[index])% 7==1 ||(n/prime[index])% 7==6)){ out.printf(" %d",prime[index]); } index++; } out.println(); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(in); operation eratosthenes( n : int) : Sequence(int) pre: true post: true activity: ( var dp : Sequence(boolean) ; dp := Integer.subrange(1,n + 1)->collect(false) ; var prime : Sequence(int) ; prime := Sequence{} ; var i : int ; i := 2 ; while i <= n do ( ( if (i mod 7 = 1 or i mod 7 = 6) then ( if (dp[i+1]) then continue else skip ; prime := prime->including(i) ; var j : int ; j := i + i ; while j <= n do ( dp[j+1] := true ; ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; var ret : Sequence(int) ; ret := Integer.subrange(1,prime->size())->collect(0) ; var count : int ; count := 0 ; for (num : prime) do ( ret[count+1] := num ; count := count + 1 ; ) ; return ret ); operation run() : void pre: true post: true activity: ( var n : int ; var prime : Sequence(int) ; prime := eratosthenes(400000) ; while (true) do ( n := sc.getCurrent()->toInteger() ; if (n = 1) then break else skip ; out.printf("%d:", n) ; var index : int ; index := 0 ; while (prime[index+1] <= n) do ( if (n mod prime[index+1] = 0 & ((n / prime[index+1]) mod 7 = 1 or (n / prime[index+1]) mod 7 = 6)) then ( out.printf(" %d", prime[index+1]) ) else skip ; index := index + 1 ) ; out.println() ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); MSPrimeGenerator msp=new MSPrimeGenerator(); while(true){ int n=Integer.parseInt(br.readLine()); if(n==1){ break ; } System.out.println(solve(n,msp)); } } static String solve(int n,MSPrimeGenerator msp){ StringBuffer sb=new StringBuffer(); sb.append(n+":"); for(int i=6 ; i<=n ; i++){ if(n % i==0 && msp.isPrime(i)){ sb.append(" "+i); } } return sb.toString(); } } class MSPrimeGenerator { private final int N=300000 ; private boolean[] isPrime=new boolean[N+1]; public MSPrimeGenerator(){ Arrays.fill(isPrime,true); isPrime[0]=false ; isPrime[1]=false ; for(int i=6 ; i<=N ; i++){ if(isPrime[i]==false){ continue ; } if(!(i % 7==1 || i % 7==6)){ isPrime[i]=false ; continue ; } for(int j=i*2 ; j<=N ; j+=i){ isPrime[j]=false ; } } } public boolean isPrime(int index){ return isPrime[index]; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var msp : MSPrimeGenerator ; msp := MSPrimeGenerator.newMSPrimeGenerator() ; while (true) do ( var n : int ; n := (br.readLine())->toInteger() ; if (n = 1) then ( break ) else skip ; OclFile["System.out"].println(solve(n, msp)) ) ); static operation solve( n : int, msp : MSPrimeGenerator) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString(n + ":") ; var i : int ; i := 6 ; while i <= n do ( ( if (n mod i = 0 & msp.isPrime(i)) then ( sb := sb + StringLib.newString(" " + i) ) else skip ) ; i := i + 1 ) ; return sb+"" ); } class MSPrimeGenerator { attribute N : int := 300000; attribute isPrime : Sequence(boolean) := Integer.subrange(1,N + 1)->collect(false); static operation newMSPrimeGenerator() : MSPrimeGenerator pre: true post: true activity: ( var self : MSPrimeGenerator ; self := createMSPrimeGenerator(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( isPrime := isPrime->collect(true) ; isPrime[0+1] := false ; isPrime[1+1] := false ; var i : int ; i := 6 ; while i <= N do ( ( if (isPrime[i+1] = false) then ( continue ) else skip ; if (not((i mod 7 = 1 or i mod 7 = 6))) then ( isPrime[i+1] := false ; continue ) else skip ; var j : int ; j := i * 2 ; while j <= N do ( ( isPrime[j+1] := false ) ; j := j+(i) ) ) ; i := i + 1 ) ); operation isPrime( index : int) : boolean pre: true post: true activity: ( return isPrime[index+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; import java.util.stream.IntStream ; public class Main { public static void main(String[] args)throws IOException { Scanner input=new Scanner(System.in); int n=input.nextInt(); int q=input.nextInt(); String s=input.next(); char str[]=s.toCharArray(); for(int i=0 ; itoInteger() ; var q : int ; q := input.getCurrent()->toInteger() ; var s : String ; s := input.getCurrent() ; var str : Sequence(String) ; str := s->characters() ; var i : int ; i := 0 ; while i < q do ( ( var l : int ; l := input.getCurrent()->toInteger() - 1 ; var r : int ; r := input.getCurrent()->toInteger() - 1 ; var c1 : String ; c1 := input.getCurrent()->at(0+1) ; var c2 : String ; c2 := input.getCurrent()->at(0+1) ; var start : int ; start := l ; var end : int ; end := r ; while (start <= end) do ( if (str[start+1] = c1) then ( str[start+1] := c2 ) else skip ; start := start + 1 ) ; ) ; i := i + 1 ) ; for (c : str) do ( ( OclFile["System.out"].print(c) ) ) ; OclFile["System.out"].println("") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int max=3000001 ; static boolean[] gdosu=new boolean[max]; static boolean[] gdsosu=new boolean[max]; public static void main(String[] args){ for(int i=0 ; icollect(false); static attribute gdsosu : Sequence(boolean) := Integer.subrange(1,max)->collect(false); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < max do ( ( gdosu[i+1] := false ; if (i <= 1) then continue else skip ; if (i mod 7 = 1 or i mod 7 = 6) then ( gdosu[i+1] := true ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < max do ( gdsosu[i+1] := true ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < max do ( ( if (not(gdosu[i+1])) then ( gdsosu[i+1] := false ; continue ) else skip ; var s : int ; s := i + i ; while s < max do ( ( gdsosu[s+1] := false ) ; s := s+(i) ) ) ; i := i + 1 ) ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var input : int ; input := in.getCurrent()->toInteger() ; if (input = 1) then break else skip ; OclFile["System.out"].print(input + ":") ; var i : int ; i := 0 ; while i <= input do ( ( if (not(gdsosu[i+1])) then continue else skip ; if (input mod i = 0) then ( OclFile["System.out"].print(" " + i) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; class GFG { static int divCount(int n){ boolean hash[]=new boolean[n+1]; Arrays.fill(hash,true); for(int p=2 ; p*pcollect(false) ; hash := hash->collect(true) ; var p : int ; p := 2 ; while p * p < n do ( if (hash[p+1] = true) then var i : int ; i := p * 2 ; while i < n do ( hash[i+1] := false ; ; i := i+(p) ) ; else skip ; ; p := p + 1 ) ; var total : int ; total := 1 ; var p : int ; p := 2 ; while p <= n do ( ( if (hash[p+1]) then ( var count : int ; count := 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 ) ; p := p + 1 ) ; return total ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 24 ; OclFile["System.out"].print(divCount(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { new Main().run(); } private void run()throws IOException { Scanner scanner=new Scanner(System.in); while(true){ p=scanner.nextInt(); if(p==0)break ; n=new int[6]; for(int i=0 ; i<6 ; i++)n[i]=scanner.nextInt(); u=new int[6]; System.out.println(slove(p,5)); } } private int slove(int r,int c){ if(c>=0){ int ans=1<<30 ; for(int i=0 ; i<2 ; i++){ u[c]=Math.min(n[c],r/coin[c]+i); ans=Math.min(ans,slove(Math.max(0,r-u[c]*coin[c]),c-1)+u[c]); } return ans ; } else { int ch=-p ; for(int i=0 ; i<6 ; i++)ch+=coin[i]*u[i]; int ans=0 ; for(int i=5 ; i>=0 ; i--){ ans+=ch/coin[i]; ch %=coin[i]; } return ans ; } } int p ; int[] n,u ; int[] coin={ 1,5,10,50,100,500 }; } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( p := scanner.getCurrent()->toInteger() ; if (p = 0) then break else skip ; n := Integer.subrange(1,6)->collect(0) ; var i : int ; i := 0 ; while i < 6 do ( n[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; u := Integer.subrange(1,6)->collect(0) ; OclFile["System.out"].println(slove(p, 5)) ; ) ); operation slove( r : int, c : int) : int pre: true post: true activity: ( if (c >= 0) then ( var ans : int ; ans := (1*(2->pow(30)))->oclAsType(long) ; var i : int ; i := 0 ; while i < 2 do ( ( u[c+1] := Set{n[c+1], r / coin[c+1] + i}->min() ; ans := Set{ans, slove(Set{0, r - u[c+1] * coin[c+1]}->max(), c - 1) + u[c+1]}->min() ) ; i := i + 1 ) ; return ans ) else ( var ch : int ; ch := -p ; var i : int ; i := 0 ; while i < 6 do ( ch := ch+(coin[i+1] * u[i+1]) ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 5 ; while i >= 0 do ( ( ans := ans+(ch / coin[i+1]) ; ch := ch mod coin[i+1] ) ; i := i - 1 ) ; return ans ) ); attribute p : int; attribute n : Sequence(int); attribute coin : Sequence(int) := Sequence{1,5,10,50,100,500}; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Solution { public static void main(String[] args){ FastReader sc=new FastReader(); StringBuilder sb=new StringBuilder(); int testcases=1 ; while(testcases-->0){ int n=sc.nextInt(); int need=1 ; int curr=2 ; int total=0 ; while(n>=need){ total++; n-=need ; need+=curr ; curr++; } sb.append(total); } System.out.println(sb); } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var sb : String ; sb := StringLib.newString() ; var testcases : int ; testcases := 1 ; while (testcases > 0) do ( testcases := testcases - 1 ; skip ; ( var n : int ; n := sc.nextInt() ; var need : int ; need := 1 ; var curr : int ; curr := 2 ; var total : int ; total := 0 ; while (n >= need) do ( total := total + 1 ; n := n-(need) ; need := need+(curr) ; curr := curr + 1 ) ; sb := sb + StringLib.newString(total) ; ) ; ) ; OclFile["System.out"].println(sb) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int numCases=sc.nextInt(); for(int caseNum=1 ; caseNum<=numCases ; caseNum++){ int N=sc.nextInt(); int K=sc.nextInt(); int[] sums=new int[N-K+1]; for(int i=0 ; imid){ possible=false ; break ; } long minValue=-minDiff[i],maxValue=mid-maxDiff[i]; minSum+=minValue ; maxSum+=maxValue ; } long target=((sums[0]-minSum)% K+K)% K+minSum ; if(possible && target<=maxSum){ max=mid ; } else { min=mid+1 ; } } System.out.println("Case #"+caseNum+": "+min); } } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numCases : int ; numCases := sc.getCurrent()->toInteger() ; var caseNum : int ; caseNum := 1 ; while caseNum <= numCases do ( ( var N : int ; N := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var sums : Sequence(int) ; sums := Integer.subrange(1,N - K + 1)->collect(0) ; var i : int ; i := 0 ; while i < N - K + 1 do ( ( sums[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var maxDiff : Sequence(int) ; maxDiff := Integer.subrange(1,K)->collect(0) ; var minDiff : Sequence(int) ; minDiff := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 0 ; while i < K do ( ( var totalDiff : int ; totalDiff := 0 ; var j : int ; j := i ; while j < N - K do ( ( totalDiff := totalDiff+(sums[j + 1+1] - sums[j+1]) ; maxDiff[i+1] := Set{maxDiff[i+1], totalDiff}->max() ; minDiff[i+1] := Set{minDiff[i+1], totalDiff}->min() ) ; j := j+(K) ) ) ; i := i + 1 ) ; var min : long ; min := 0 ; var max : long ; max := 2147483647 ; while (min < max) do ( var mid : long ; mid := (min + max) / 2 ; var possible : boolean ; possible := true ; var minSum : long ; minSum := 0 ; var maxSum : long ; maxSum := 0 ; var i : int ; i := 0 ; while i < K do ( ( if (maxDiff[i+1] - minDiff[i+1] > mid) then ( possible := false ; break ) else skip ; var minValue : long ; minValue := -minDiff[i+1] ; var maxValue : long ; maxValue := mid - maxDiff[i+1] ; minSum := minSum+(minValue) ; maxSum := maxSum+(maxValue) ) ; i := i + 1 ) ; var target : long ; target := ((sums[0+1] - minSum) mod K + K) mod K + minSum ; if (possible & target <= maxSum) then ( max := mid ) else ( min := mid + 1 ) ; ) ; OclFile["System.out"].println("Case #" + caseNum + ": " + min) ; ) ; caseNum := caseNum + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { int INF=1<<28 ; int[] ret ; int[] val={ 500,100,50,10,5,1 }; int plus=500 ; void run(){ Scanner sc=new Scanner(System.in); ret=new int[plus]; fill(ret,INF); ret[0]=0 ; for(int i=0 ; i=0 ; i--)coins[i]=sc.nextInt(); int min=INF ; for(int i=P ; ipow(28)))->oclAsType(long); attribute ret : Sequence(int); attribute val : Sequence(int) := Sequence{500,100,50,10,5,1}; attribute plus : int := 500; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; ret := Integer.subrange(1,plus)->collect(0) ; execute fill(ret, INF) ; ret[0+1] := 0 ; var i : int ; i := 0 ; while i < plus do ( var j : int ; j := 0 ; while j < val->size() do ( ( if (i + val[j+1] < plus) then ret[i + val[j+1]+1] := Set{ret[i + val[j+1]+1], ret[i+1] + 1}->min() ; else skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; while true do ( ( var P : int ; P := sc.getCurrent()->toInteger() ; if (P = 0) then break else skip ; var coins : Sequence(int) ; coins := Integer.subrange(1,val->size())->collect(0) ; var i : int ; i := val->size() - 1 ; while i >= 0 do ( coins[i+1] := sc.getCurrent()->toInteger() ; ; i := i - 1 ) ; var min : int ; min := INF ; var i : int ; i := P ; while i < P + plus do ( ( var pay : int ; pay := i ; var coin : int ; coin := 0 ; var j : int ; j := 0 ; while j < val->size() do ( ( var c : int ; c := min(pay / val[j+1], coins[j+1]) ; pay := pay-(c * val[j+1]) ; coin := coin+(c) ) ; j := j + 1 ) ; if (pay = 0) then min := Set{min, coin + ret[i - P+1]}->min() ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { int[] p={ 1,5,10,50,100,500 }; int[] c ; int pay(int x){ int r=0 ; for(int k=5 ; k>=0 ; k--){ int a=Math.min(x/p[k],c[k]); r+=a ; x-=p[k]*a ; } return r ; } int get(int x){ int r=0 ; for(int k=5 ; k>=0 ; k--){ int c=x/p[k]; r+=c ; x-=p[k]*c ; } return r ; } void run(){ int[] r=new int[666001]; for(int i=0 ; i<666001 ; i++)r[i]=get(i); Scanner sc=new Scanner(System.in); while(true){ int P=sc.nextInt(); if(P==0)break ; c=new int[6]; int sum=0 ; for(int i=0 ; i<6 ; i++){ c[i]=sc.nextInt(); sum+=p[i]*c[i]; } int min=1<<28 ; for(int i=P ; i<=sum ; i++){ min=Math.min(min,pay(i)+r[i-P]); } System.out.println(min); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute p : Sequence(int) := Sequence{1,5,10,50,100,500}; attribute c : Sequence(int); operation pay( x : int) : int pre: true post: true activity: ( var r : int ; r := 0 ; var k : int ; k := 5 ; while k >= 0 do ( ( var a : int ; a := Set{x / p[k+1], c[k+1]}->min() ; r := r+(a) ; x := x-(p[k+1] * a) ) ; k := k - 1 ) ; return r ); operation get( x : int) : int pre: true post: true activity: ( var r : int ; r := 0 ; var k : int ; k := 5 ; while k >= 0 do ( ( var c : int ; c := x / p[k+1] ; r := r+(c) ; x := x-(p[k+1] * c) ) ; k := k - 1 ) ; return r ); operation run() : void pre: true post: true activity: ( var r : Sequence(int) ; r := Integer.subrange(1,666001)->collect(0) ; var i : int ; i := 0 ; while i < 666001 do ( r[i+1] := at(i+1) ; ; i := i + 1 ) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var P : int ; P := sc.getCurrent()->toInteger() ; if (P = 0) then break else skip ; c := Integer.subrange(1,6)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 6 do ( ( c[i+1] := sc.getCurrent()->toInteger() ; sum := sum+(p[i+1] * c[i+1]) ) ; i := i + 1 ) ; var min : int ; min := (1*(2->pow(28)))->oclAsType(long) ; var i : int ; i := P ; while i <= sum do ( ( min := Set{min, pay(i) + r[i - P+1]}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static final int MAX=1000 ; public static final int[] coins=new int[] { 500,100,50,10,5,1 }; public static final int[] maxs=new int[] { Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE }; public static final int ret_coin(int P,int[] coin_nums){ int ret=0 ; for(int i=0 ; isize() do ( ( var p_use : int ; p_use := P / coins[i+1] ; var can_use : int ; can_use := Set{p_use, coin_nums[i+1]}->min() ; ret := ret+(can_use) ; P := P-(coins[i+1] * can_use) ) ; i := i + 1 ) ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var P : int ; P := sc.getCurrent()->toInteger() ; if (P = 0) then ( break ) else skip ; var coin_nums : Sequence(int) ; coin_nums := Integer.subrange(1,6)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 6 do ( ( coin_nums[5 - i+1] := sc.getCurrent()->toInteger() ; sum := sum+(coin_nums[5 - i+1] * coins[5 - i+1]) ) ; i := i + 1 ) ; var max : int ; max := Set{sum, P + 500}->min() ; var min : int ; min := 2147483647 ; var i : int ; i := P ; while i <= max do ( ( min := Set{min, ret_coin(i, coin_nums) + ret_coin(i - P, maxs)}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int[] coin={ 500,100,50,10,5,1 }; public static int[] n=new int[6]; public static void main(String[] args)throws java.io.IOException { Scanner scan=new Scanner(System.in); while(true){ int p=scan.nextInt(); if(p==0)break ; for(int i=5 ; i>=0 ; i--)n[i]=scan.nextInt(); int ans=1000000 ; for(int i=p ; i=coin[i]){ sum+=n/coin[i]; n %=coin[i]; } } return sum ; } public static int buy(int c){ int sum=0 ; for(int i=0 ; i<6 ; i++){ if(c>=coin[i]){ int tmp=Math.min(c/coin[i],n[i]); sum+=tmp ; c-=coin[i]*tmp ; } } if(c!=0)sum=1000000 ; return sum ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute coin : Sequence(int) := Sequence{500,100,50,10,5,1}; static attribute n : Sequence(int) := Integer.subrange(1,6)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var p : int ; p := scan.getCurrent()->toInteger() ; if (p = 0) then break else skip ; var i : int ; i := 5 ; while i >= 0 do ( n[i+1] := scan.getCurrent()->toInteger() ; ; i := i - 1 ) ; var ans : int ; ans := 1000000 ; var i : int ; i := p ; while i < p + 1000 do ( ans := Set{ans, buy(i) + change(i - p)}->min() ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); static operation change( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 6 do ( ( if (n >= coin[i+1]) then ( sum := sum+(n / coin[i+1]) ; n := n mod coin[i+1] ) else skip ) ; i := i + 1 ) ; return sum ); static operation buy( c : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 6 do ( ( if (c >= coin[i+1]) then ( var tmp : int ; tmp := Set{c / coin[i+1], n[i+1]}->min() ; sum := sum+(tmp) ; c := c-(coin[i+1] * tmp) ) else skip ) ; i := i + 1 ) ; if (c /= 0) then sum := 1000000 ; else skip ; return sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static int findMinimumAdjacentSwaps(int arr[],int N){ boolean[] visited=new boolean[N+1]; int minimumSwaps=0 ; Arrays.fill(visited,false); for(int i=0 ; i<2*N ; i++){ if(visited[arr[i] ]==false){ visited[arr[i] ]=true ; int count=0 ; for(int j=i+1 ; j<2*N ; j++){ if(visited[arr[j] ]==false)count++; else if(arr[i]==arr[j])minimumSwaps+=count ; } } } return minimumSwaps ; } public static void main(String args[]){ int arr[]={ 1,2,3,3,1,2 }; int N=arr.length ; N/=2 ; System.out.println(findMinimumAdjacentSwaps(arr,N)); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation findMinimumAdjacentSwaps( arr : Sequence(int), N : int) : int pre: true post: true activity: ( var visited : Sequence(boolean) ; visited := Integer.subrange(1,N + 1)->collect(false) ; var minimumSwaps : int ; minimumSwaps := 0 ; visited := visited->collect(false) ; var i : int ; i := 0 ; while i < 2 * N do ( ( if (visited[arr[i+1]+1] = false) then ( visited[arr[i+1]+1] := true ; var count : int ; count := 0 ; var j : int ; j := i + 1 ; while j < 2 * N 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 ; ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; return minimumSwaps ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,3,1,2} ; var N : int ; N := arr->size() ; N := N/(2) ; OclFile["System.out"].println(findMinimumAdjacentSwaps(arr, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class GFG { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int t=sc.nextInt(); String s=sc.next(); while(t-->0){ int l=sc.nextInt(); int r=sc.nextInt(); String c1=sc.next(); String c2=sc.next(); char ch1=c1.charAt(0); char ch2=c2.charAt(0); String s1=s.substring(l-1,r); s1=s1.replace(ch1,ch2); s=s.substring(0,l-1)+s1+s.substring(r); } System.out.println(s); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; while (t > 0) do ( t := t - 1 ; skip ; ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var c1 : String ; c1 := sc.getCurrent() ; var c2 : String ; c2 := sc.getCurrent() ; var ch1 : String ; ch1 := c1->at(0+1) ; var ch2 : String ; ch2 := c2->at(0+1) ; var s1 : String ; s1 := s.subrange((l)->char2byte() - 1+1,r) ; s1 := s1.replace(ch1, ch2) ; s := s.subrange(0+1,(l)->char2byte() - 1) + s1 + s.subrange(r+1,r) ; ) ; ) ; OclFile["System.out"].println(s) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int X=sc.nextInt(); sc.close(); int total=0 ; int cnt=1 ; while(true){ total+=cnt ; cnt++; if(X<=total){ break ; } } System.out.print(cnt-1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : int ; X := sc.getCurrent()->toInteger() ; skip ; var total : int ; total := 0 ; var cnt : int ; cnt := 1 ; while (true) do ( total := total+(cnt) ; cnt := cnt + 1 ; if (X <= total) then ( break ) else skip ) ; OclFile["System.out"].print(cnt - 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.Closeable ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.HashSet ; import java.util.LinkedList ; import java.util.Scanner ; import java.util.StringTokenizer ; import java.util.TreeMap ; public class Main { public static void main(String[] args)throws IOException { final Scanner sc=new Scanner(System.in); final long X=sc.nextLong(); long pow=0 ; for(int time=0 ; powtoLong() ; var pow : long ; pow := 0 ; var time : int ; time := 0 ; while pow < X do ( ( pow := pow+(time) ; if (X <= pow) then ( OclFile["System.out"].println(time) ; return ) else skip ) ; time := time + 1 ) ); static class Scanner implements Closeable { attribute br : OclFile; attribute tok : OclIterator; static operation newScanner( is : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(is); return self ); operation initialise( is : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(is)) ); operation getLine() : void pre: true post: true activity: ( while (not(hasNext())) do ( tok := OclIterator.newOclIterator_String(br.readLine()) ) ); operation hasNext() : boolean pre: true post: true activity: ( return tok /= null & tok.hasNext() ); operation next() : String pre: true post: true activity: ( execute getLine() ; return tok.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var ret : Sequence(int) ; ret := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ret[i+1] := self.nextInt() ) ; i := i + 1 ) ; return ret ); operation nextLongArray( n : int) : Sequence(long) pre: true post: true activity: ( var ret : Sequence(long) ; ret := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( ret[i+1] := self.nextLong() ) ; i := i + 1 ) ; return ret ); operation close() : void pre: true post: true activity: ( skip ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.NoSuchElementException ; public class Main { int X ; public void solve(){ X=nextInt(); int sum=0 ; int i=0 ; for(; sum='!' && ch<='~')return true ; return false ; } private int nextByte(){ if(! hasNextByte())return-1 ; return buffer[p++]; } public String next(){ if(! hasNext())throw new NoSuchElementException(); StringBuilder sb=new StringBuilder(); int b=-1 ; while(isPrint((b=nextByte()))){ sb.appendCodePoint(b); } return sb.toString(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute X : int; operation solve() : void pre: true post: true activity: ( X := nextInt() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while sum < X do ( ( sum := sum+(i) ) ; i := i + 1 ) ; out.println(i - 1) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( out.flush() ; Main.newMain().solve() ; out.close() ); static attribute in : OclFile := OclFile["System.in"]; static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); attribute buffer : Sequence(int) := Integer.subrange(1,2048)->collect(0); attribute p : int := 0; attribute buflen : int := 0; operation hasNextByte() : boolean pre: true post: true activity: ( if (p < buflen) then return true else skip ; p := 0 ; try ( buflen := in.read(buffer) ) catch (e : IOException) do ( e.printStackTrace() ) if (buflen <= 0) then return false else skip ; return true ); operation hasNext() : boolean pre: true post: true activity: ( while (hasNextByte() & not(isPrint(buffer[p+1]))) do ( p := p + 1 ) ; return hasNextByte() ); operation isPrint( ch : int) : boolean pre: true post: true activity: ( if (ch >= '!' & ch <= '~') then return true else skip ; return false ); operation nextByte() : int pre: true post: true activity: ( if (not(hasNextByte())) then return -1 else skip ; return buffer[p+1] ); operation next() : String pre: true post: true activity: ( if (not(hasNext())) then error IncorrectElementException() ; else skip ; var sb : String ; sb := StringLib.newString() ; var b : int ; b := -1 ; while (isPrint((b))) do ( sb.appendCodePoint(b) ) ; return sb+"" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ Main main=new Main(); main.solveA(sc); } } private void solveD(Scanner sc){ try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out)){ } catch(IOException e){ } } private void solveE(Scanner sc){ try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out)){ } catch(IOException e){ } } private void solveC(Scanner sc){ } void solveB(Scanner sc){ } void solveA(Scanner sc){ runA(sc.nextLong()); } private void runA(long num){ if(num==1){ System.out.println("1"); return ; } long min=1 ; long max=num ; while(min+1num){ max=now ; } else if(x==num){ System.out.println(now); return ; } else { min=now ; } } System.out.println(min+1); } private static int binarySearch(int[] list,int num){ int max=list.length ; int min=0 ; while(min+1num){ max=now ; } else { min=now ; } } return min ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var main : Main ; main := Main.newMain() ; main.solveA(sc) )) ); operation solveD( sc : OclFile) : void pre: true post: true activity: ( try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pw : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip) catch (e : IOException) do skip ); operation solveE( sc : OclFile) : void pre: true post: true activity: ( try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pw : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip) catch (e : IOException) do skip ); operation solveC( sc : OclFile) : void pre: true post: true activity: skip; operation solveB( sc : OclFile) : void pre: true post: true activity: skip; operation solveA( sc : OclFile) : void pre: true post: true activity: ( execute runA(sc.getCurrent()->toLong()) ); operation runA( num : long) : void pre: true post: true activity: ( if (num = 1) then ( OclFile["System.out"].println("1") ; return ) else skip ; var min : long ; min := 1 ; var max : long ; max := num ; while (min + 1 < max) do ( var now : long ; now := (min + max) / 2 ; var x : long ; x := now * (now + 1) / 2 ; if (x > num) then ( max := now ) else if (x = num) then ( OclFile["System.out"].println(now) ; return ) else ( min := now ) ; ) ; OclFile["System.out"].println(min + 1) ; ); static operation binarySearch( list : Sequence(int), num : int) : int pre: true post: true activity: ( var max : int ; max := list->size() ; var min : int ; min := 0 ; while (min + 1 < max) do ( var now : int ; now := (max + min) / 2 ; if (list[now+1] > num) then ( max := now ) else ( min := now ) ) ; return min ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { int ni(){ return cin.nextInt(); } long nl(){ return cin.nextLong(); } String line(){ return cin.nextLine(); } void println(String str){ System.out.println(str); } void print(String str){ System.out.print(str); } static final int MOD=1000000007 ; Scanner cin=new Scanner(System.in); String output ; public static void main(String[] args){ new Main().run(); } public void run(){ input(); int res=solve(); output=res+"" ; println(output); } int X ; void input(){ X=ni(); } int solve(){ int i=1 ; int cnt=0 ; for(; ; i++){ int j=i ; while(j>0){ cnt++; if(cnt==X){ return i ; } j--; } } } } ------------------------------------------------------------ OCL File: --------- class Main { operation ni() : int pre: true post: true activity: ( return cin.nextInt() ); operation nl() : long pre: true post: true activity: ( return cin.nextLong() ); operation line() : String pre: true post: true activity: ( return cin.nextLine() ); operation println( str : String) : void pre: true post: true activity: ( OclFile["System.out"].println(str) ); operation print( str : String) : void pre: true post: true activity: ( OclFile["System.out"].print(str) ); static attribute MOD : int := 1000000007; attribute cin : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute output : String; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( execute input() ; var res : int ; res := solve() ; output := res + "" ; execute println(output) ); attribute X : int; operation input() : void pre: true post: true activity: ( X := ni() ); operation solve() : int pre: true post: true activity: ( var i : int ; i := 1 ; var cnt : int ; cnt := 0 ; while true do ( ( var j : int ; j := i ; while (j > 0) do ( cnt := cnt + 1 ; if (cnt = X) then ( return i ) else skip ; j := j - 1 ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class B { public static void main(String...orange)throws Exception { Scanner input=new Scanner(System.in); int numCases=input.nextInt(); for(int n=0 ; nmaxdiffs[i % K])maxdiffs[i % K]=currdiff[i % K]; if(currdiff[i % K]maxdiffdiff)maxdiffdiff=diffdiffs[i]; int highBound=0 ; for(int i=0 ; itoInteger() ; var n : int ; n := 0 ; while n < numCases do ( ( var N : int ; N := input.getCurrent()->toInteger() ; var K : int ; K := input.getCurrent()->toInteger() ; var sums : Sequence(int) ; sums := Integer.subrange(1,N - K + 1)->collect(0) ; var i : int ; i := 0 ; while i < N - K + 1 do ( sums[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; var maxdiffs : Sequence(int) ; maxdiffs := Integer.subrange(1,K)->collect(0) ; var mindiffs : Sequence(int) ; mindiffs := Integer.subrange(1,K)->collect(0) ; var currdiff : Sequence(int) ; currdiff := Integer.subrange(1,K)->collect(0) ; var i : int ; i := K ; while i < N do ( ( currdiff[i mod K+1] := currdiff[i mod K+1]+(sums[i - K + 1+1] - sums[i - K+1]) ; if (currdiff[i mod K+1] > maxdiffs[i mod K+1]) then maxdiffs[i mod K+1] := currdiff[i mod K+1] ; else skip ; if (currdiff[i mod K+1] < mindiffs[i mod K+1]) then mindiffs[i mod K+1] := currdiff[i mod K+1] ; else skip ) ; i := i + 1 ) ; var diffdiffs : Sequence(int) ; diffdiffs := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 0 ; while i < K do ( diffdiffs[i+1] := maxdiffs[i+1] - mindiffs[i+1] ; ; i := i + 1 ) ; var maxdiffdiff : int ; maxdiffdiff := 0 ; var i : int ; i := 0 ; while i < K do ( if (diffdiffs[i+1] > maxdiffdiff) then maxdiffdiff := diffdiffs[i+1] ; else skip ; ; i := i + 1 ) ; var highBound : int ; highBound := 0 ; var i : int ; i := 0 ; while i < K do ( highBound := highBound+(maxdiffdiff - diffdiffs[i+1]) ; ; i := i + 1 ) ; var target : int ; target := sums[0+1] ; var i : int ; i := 0 ; while i < K do ( target := target+(mindiffs[i+1]) ; ; i := i + 1 ) ; target := (target mod K + K) mod K ; var ans : int ; ans := maxdiffdiff + (if target <= highBound then 0 else 1 endif) ; OclFile["System.out"].printf("Case #%d: ", n + 1) ; OclFile["System.out"].println(ans) ; ) ; n := n + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int minParentheses(String p){ int bal=0 ; int ans=0 ; for(int i=0 ; isize() do ( ( bal := bal+(if p->at(i+1) = '(' then 1 else -1 endif) ; if (bal = -1) then ( ans := ans+(1) ; bal := bal+(1) ) else skip ) ; i := i + 1 ) ; return bal + ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var p : String ; p := "())" ; OclFile["System.out"].println(minParentheses(p)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int a[]=new int[m]; int total=0 ; for(int i=0 ; i=0){ System.out.println(ans); } else { System.out.println(-1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,m)->collect(0) ; var total : int ; total := 0 ; var i : int ; i := 0 ; while i < m do ( ( a[i+1] := sc.getCurrent()->toInteger() ; total := total+(a[i+1]) ) ; i := i + 1 ) ; var ans : int ; ans := n - total ; if (ans >= 0) then ( OclFile["System.out"].println(ans) ) else ( OclFile["System.out"].println(-1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); BHomework solver=new BHomework(); solver.solve(1,in,out); out.close(); } static class BHomework { public void solve(int testNumber,InputReader in,PrintWriter out){ int days=in.nextInt(); int m=in.nextInt(); while(m-->0){ int x=in.nextInt(); days-=x ; } out.println(days<0 ? "-1" : days); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : BHomework ; solver := BHomework.newBHomework() ; solver.solve(1, in, out) ; skip ; ); static class BHomework { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var days : int ; days := in.nextInt() ; var m : int ; m := in.nextInt() ; while (m > 0) do ( m := m - 1 ; skip ; ( var x : int ; x := in.nextInt() ; days := days-(x) ) ; ) ; skip ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ int i ; int k=360 ; int j=1 ; Scanner sc=new Scanner(System.in); if(! sc.hasNextInt()){ System.err.println("aa aa"); } i=Integer.parseInt(sc.nextLine()); if(1<=i && i<=179){ while(!((i*j)% k==0)){ ++j ; } System.out.println(j); } else { System.out.println("aa aa"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var k : int ; k := 360 ; var j : int ; j := 1 ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; if (not(sc.hasNextInt())) then ( OclFile["System.err"].println("aa aa") ) else skip ; i := (sc.nextLine())->toInteger() ; if (1 <= i & i <= 179) then ( while (not(((i * j) mod k = 0))) do ( j := j + 1 ) ; OclFile["System.out"].println(j) ) else ( OclFile["System.out"].println("aa aa") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); long sum=0 ; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < m do ( ( sum := sum+(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var result : long ; result := -1 ; result := Set{n - sum, -1}->max() ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { private static void solve(InputReader in,PrintWriter out){ Integer m=in.nextInt(),n=in.nextInt(); long sum=0 ; for(int i=0 ; i=0)? m-sum :-1); } public static void main(String args[]){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); solve(in,out); out.close(); } private static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public Double nextDouble(){ return Double.parseDouble(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve( in : InputReader, out : OclFile) : void pre: true post: true activity: ( var m : int ; m := in.nextInt() ; var n : int ; n := in.nextInt() ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(in.nextInt()) ) ; i := i + 1 ) ; OclFile["System.out"].print(if (m - sum >= 0) then m - sum else -1 endif) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; execute solve(in, out) ; skip ; ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void swap(int a,int b){ int temp=a ; a=b ; b=temp ; } static int minimumSquare(int a,int b){ int result=0,rem=0 ; if(a0){ result+=a/b ; rem=a % b ; a=b ; b=rem ; } return result ; } public static void main(String[] args){ int n=13,m=29 ; System.out.println(minimumSquare(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation swap( a : int, b : int) : void pre: true post: true activity: ( var temp : int ; temp := a ; a := b ; b := temp ); static operation minimumSquare( a : int, b : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; var rem : int ; rem := 0 ; if (a < b) then execute swap(a, b) ; else skip ; while (b > 0) do ( result := result+(a / b) ; rem := a mod b ; a := b ; b := rem ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 13 ; var m : int ; m := 29 ; OclFile["System.out"].println(minimumSquare(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import static java.lang.Math.max ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int t=input.nextInt(); while(t!=0){ int a=input.nextInt(); int b=input.nextInt(); int c=input.nextInt(); int d=input.nextInt(); int sum=a+b+c+d ; if(sum % 3==0 && sum/3>=max(max(a,b),c))System.out.println("YES"); else System.out.println("NO"); t--; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := input.getCurrent()->toInteger() ; while (t /= 0) do ( var a : int ; a := input.getCurrent()->toInteger() ; var b : int ; b := input.getCurrent()->toInteger() ; var c : int ; c := input.getCurrent()->toInteger() ; var d : int ; d := input.getCurrent()->toInteger() ; var sum : int ; sum := a + b + c + d ; if (sum mod 3 = 0 & sum / 3 >= Set{Set{a, b}->max(), c}->max()) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class coinn { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); int p=0 ; while(t-->0){ int n=in.nextInt(); int n2=in.nextInt(); int n3=in.nextInt(); int n4=in.nextInt(); int max=Math.max(n,Math.max(n2,n3)); int s=n+n2+n3+n4 ; if(s % 3==0 && s/3>=max){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class coinn { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var p : int ; p := 0 ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var n2 : int ; n2 := in.getCurrent()->toInteger() ; var n3 : int ; n3 := in.getCurrent()->toInteger() ; var n4 : int ; n4 := in.getCurrent()->toInteger() ; var max : int ; max := Set{n, Set{n2, n3}->max()}->max() ; var s : int ; s := n + n2 + n3 + n4 ; if (s mod 3 = 0 & s / 3 >= max) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test148 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0 ; imax){ max=a[j]; } } int n=in.nextInt(); for(int j=0 ; j<3 ; j++){ n-=max-a[j]; } if(n>=0 && n % 3==0){ System.out.println("YES"); } else { System.out.println("NO"); } } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test148 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var a : Sequence(int) ; a := Integer.subrange(1,3)->collect(0) ; var max : int ; max := 0 ; var j : int ; j := 0 ; while j < 3 do ( ( a[j+1] := in.getCurrent()->toInteger() ; if (a[j+1] > max) then ( max := a[j+1] ) else skip ) ; j := j + 1 ) ; var n : int ; n := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < 3 do ( ( n := n-(max - a[j+1]) ) ; j := j + 1 ) ; if (n >= 0 & n mod 3 = 0) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; public class B { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int zz=1 ; zz<=T ; zz++){ int N=in.nextInt(); int[] MC=new int[10000]; for(int i=0 ; i0){ boolean legal=true ; if(j+i>10000){ legal=false ; } else { for(int k=0 ; k0){ E[j]--; C[j]--; if(j+1<10000)E[j+1]++; } else { good=false ; break ; } } } } if(good){ ans=i ; } } System.out.format("Case #%d: %d\n",zz,ans); } } } ------------------------------------------------------------ OCL File: --------- class B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := in.getCurrent()->toInteger() ; var zz : int ; zz := 1 ; while zz <= T do ( ( var N : int ; N := in.getCurrent()->toInteger() ; var MC : Sequence(int) ; MC := Integer.subrange(1,10000)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( MC[in.getCurrent()->toInteger() - 1+1] := MC[in.getCurrent()->toInteger() - 1+1] + 1 ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var C : Sequence(int) ; C := Integer.subrange(1,10000)->collect(0) ; var E : Sequence(int) ; E := Integer.subrange(1,10000)->collect(0) ; var i : int ; i := 1 ; while i <= N do ( ( var good : boolean ; good := true ; var j : int ; j := 0 ; while j < 10000 do ( C[j+1] := MC[j+1] ; ; j := j + 1 ) ; E := E->collect(0) ; var j : int ; j := 0 ; while j < 10000 do ( ( while (C[j+1] > 0) do ( var legal : boolean ; legal := true ; if (j + i > 10000) then ( legal := false ) else ( var k : int ; k := 0 ; while k < i do ( if (C[j + k+1] = 0) then legal := false ; else skip ; ; k := k + 1 ) ) ; if (legal) then ( var k : int ; k := 0 ; while k < i do ( C[j + k+1] := C[j + k+1] - 1 ; ; k := k + 1 ) ; if (j + i < 10000) then E[j + i+1] := E[j + i+1] + 1 ; else skip ) else ( if (E[j+1] > 0) then ( E[j+1] := E[j+1] - 1 ; C[j+1] := C[j+1] - 1 ; if (j + 1 < 10000) then E[j + 1+1] := E[j + 1+1] + 1 ; else skip ) else ( good := false ; break ) ) ) ) ; j := j + 1 ) ; if (good) then ( ans := i ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].format("Case #%d: %d\n", zz, ans) ; ) ; zz := zz + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Exersise { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int[][] array=new int[n][4]; for(int i=0 ; imax){ max=array[i]; } } for(int i=0 ; itoInteger() ; var array : Sequence(Sequence(int)) ; array := Integer.subrange(1,n)->collect(Integer.subrange(1,4)->collect(0)) ; var i : int ; i := 0 ; while i < array->size() do ( ( var j : int ; j := 0 ; while j < array[i+1]->size() do ( ( array[i+1][j+1] := input.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < array->size() do ( ( var is : boolean ; is := isTrue(array[i+1]) ; if (is = true) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ; i := i + 1 ) ; ); static operation isTrue( array : Sequence(int)) : boolean pre: true post: true activity: ( var sum : int ; sum := 0 ; var max : int ; max := array[0+1] ; var i : int ; i := 1 ; while i < array->size() - 1 do ( ( if (array[i+1] > max) then ( max := array[i+1] ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < array->size() - 1 do ( ( sum := sum + max - array[i+1] ) ; i := i + 1 ) ; var y : int ; y := array[3+1] - sum ; if (y < 0) then ( return false ) else skip ; if (y mod 3 = 0) then ( return true ) else ( return false ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Collecting { public static void main(String[] args){ Scanner o=new Scanner(System.in); int t=o.nextInt(); while(t-->0){ long a=o.nextInt(),b=o.nextInt(),c=o.nextInt(),n=o.nextInt(); long max=Math.max(a,Math.max(b,c)),minus=3*max-a-b-c ; if(n-minus<0 ||(n-minus)% 3!=0)System.out.println("NO"); else System.out.println("YES"); } } } ------------------------------------------------------------ OCL File: --------- class Collecting { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var o : OclFile ; o := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := o.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : long ; a := o.getCurrent()->toInteger() ; var b : long ; b := o.getCurrent()->toInteger() ; var c : long ; c := o.getCurrent()->toInteger() ; var n : long ; n := o.getCurrent()->toInteger() ; var max : long ; max := Set{a, Set{b, c}->max()}->max() ; var minus : long ; minus := 3 * max - a - b - c ; if (n - minus < 0 or (n - minus) mod 3 /= 0) then OclFile["System.out"].println("NO") ; else OclFile["System.out"].println("YES") ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void findMax(int[] arr,int n){ int maxFirst=Integer.MIN_VALUE ; int mid=n/2 ; for(int i=0 ; imax() ) ; i := i + 1 ) ; if (n mod 2 = 1) then ( maxFirst := Set{maxFirst, arr[mid+1]}->max() ) else skip ; var maxSecond : int ; maxSecond := -2147483648 ; var i : int ; i := mid ; while i < n do ( ( maxSecond := Set{maxSecond, arr[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].print(maxFirst + "," + maxSecond) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,12,14,5} ; var n : int ; n := arr->size() ; execute findMax(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); Task solver=new Task(); solver.solve(in,out); out.close(); } static class Task { public void solve(InputReader in,PrintWriter out){ int x=in.nextInt(); int lcm=(x*360)/gcd(x,360); out.println(lcm/x); } int gcd(int a,int b){ if(a==0){ return b ; } else { return gcd(b % a,a); } } } static class InputReader { BufferedReader br ; StringTokenizer st ; public InputReader(InputStream stream){ br=new BufferedReader(new InputStreamReader(stream)); } public String nextToken(){ while(st==null || ! st.hasMoreTokens()){ String line=null ; try { line=br.readLine(); } catch(IOException e){ throw new RuntimeException(e); } if(line==null){ return null ; } st=new StringTokenizer(line); } return st.nextToken(); } public int nextInt(){ return Integer.parseInt(nextToken()); } public long nextLong(){ return Long.parseLong(nextToken()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : Task ; solver := Task.newTask() ; solver.solve(in, out) ; skip ; ); static class Task { operation solve( in : InputReader, out : OclFile) : void pre: true post: true activity: ( var x : int ; x := in.nextInt() ; var lcm : int ; lcm := (x * 360) / gcd(x, 360) ; skip ); operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then ( return b ) else ( return gcd(b mod a, a) ) ); } static class InputReader { attribute br : OclFile; attribute st : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ); operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( var line : String ; line := null ; try ( line := br.readLine() ) catch (e : IOException) do ( error ProgramException(e) ) if (line = null) then ( return null ) else skip ; st := OclIterator.newOclIterator_String(line) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int sumPairs(int arr[],int n){ int sum=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(sumPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int sumPairs(int arr[],int n){ int sum=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(sumPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int A=in.nextInt(); int B=in.nextInt(); long[] nums=new long[N]; for(int i=0 ; i=N-A ; i--){ sum+=nums[i]; if(i!=N-1 && nums[i]!=nums[i+1]){ isAllSame=false ; } } double avg=((double)sum)/A ; long lowest=nums[N-A]; int numLowestInNums=0 ; int numLowestInAvg=0 ; for(int i=0 ; i=N-A){ numLowestInAvg++; } } } long count=comb(numLowestInNums,numLowestInAvg); if(isAllSame){ for(int i=N-A-1 ; i>=N-B ; i--){ if(nums[i]==lowest){ numLowestInAvg+=1 ; count+=comb(numLowestInNums,numLowestInAvg); } else { break ; } } } System.out.printf("%.6f\n",avg); System.out.println(count); } public static long comb(int n,int r){ long v=1 ; for(int i=0 ; itoInteger() ; var A : int ; A := in.getCurrent()->toInteger() ; var B : int ; B := in.getCurrent()->toInteger() ; var nums : Sequence(long) ; nums := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( nums[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; nums := nums->sort() ; var sum : long ; sum := 0 ; var isAllSame : boolean ; isAllSame := true ; var i : int ; i := N - 1 ; while i >= N - A do ( ( sum := sum+(nums[i+1]) ; if (i /= N - 1 & nums[i+1] /= nums[i + 1+1]) then ( isAllSame := false ) else skip ) ; i := i - 1 ) ; var avg : double ; avg := (sum->oclAsType(double)) / A ; var lowest : long ; lowest := nums[N - A+1] ; var numLowestInNums : int ; numLowestInNums := 0 ; var numLowestInAvg : int ; numLowestInAvg := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (nums[i+1] = lowest) then ( numLowestInNums := numLowestInNums + 1 ; if (i >= N - A) then ( numLowestInAvg := numLowestInAvg + 1 ) else skip ) else skip ) ; i := i + 1 ) ; var count : long ; count := comb(numLowestInNums, numLowestInAvg) ; if (isAllSame) then ( var i : int ; i := N - A - 1 ; while i >= N - B do ( ( if (nums[i+1] = lowest) then ( numLowestInAvg := numLowestInAvg+(1) ; count := count+(comb(numLowestInNums, numLowestInAvg)) ) else ( break ) ) ; i := i - 1 ) ) else skip ; OclFile["System.out"].printf("%.6f\n", avg) ; OclFile["System.out"].println(count) ; ); static operation comb( n : int, r : int) : long pre: true post: true activity: ( var v : long ; v := 1 ; var i : int ; i := 0 ; while i < r do ( ( v := v*(n - i) ; v := v/((i + 1)) ) ; i := i + 1 ) ; return v ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; public class Main { static long[][] comb=new long[51][51]; public static void combTable(){ for(int i=0 ; i<=50 ; ++i){ for(int j=0 ; j<=i ; ++j){ if(j==0 || j==i){ comb[i][j]=1 ; } else { comb[i][j]=comb[i-1][j-1]+comb[i-1][j]; } } } } public static void main(String[] args){ combTable(); Scanner sc=new Scanner(System.in); int N=sc.nextInt(),A=sc.nextInt(),B=sc.nextInt(); Long[] V=new Long[N]; for(int i=0 ; icollect(Integer.subrange(1,51)->collect(0)); static operation combTable() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i <= 50 do ( ( var j : int ; j := 0 ; while j <= i do ( ( if (j = 0 or j = i) then ( comb[i+1][j+1] := 1 ) else ( comb[i+1][j+1] := comb[i - 1+1][j - 1+1] + comb[i - 1+1][j+1] ) ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute combTable() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var V : Sequence(long) ; V := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( ( V[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; V := OclComparator.sortWith(V, reverseOrder()) ; var maxvLastIdx : int ; maxvLastIdx := 0 ; var aValNum : int ; aValNum := 0 ; var aValPos : int ; aValPos := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (V[i+1] = V[A - 1+1]) then ( aValNum := aValNum + 1 ; if (i < A) then ( aValPos := aValPos + 1 ) else skip ) else skip ) ; i := i + 1 ) ; var avg : double ; avg := 0.0 ; var i : int ; i := 0 ; while i < A do ( ( avg := avg+(V[i+1]) ) ; i := i + 1 ) ; avg := avg/(A) ; var cnt : long ; cnt := 0 ; if (aValPos = A) then ( aValPos := A ; while aValPos <= B do ( ( cnt := cnt+(comb[aValNum+1][aValPos+1]) ) ; aValPos := aValPos + 1 ) ) else ( cnt := cnt+(comb[aValNum+1][aValPos+1]) ) ; OclFile["System.out"].printf("%.6f\n", avg) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); long[] v=new long[n]; for(int i=0 ; iva){ big++; } else if(v[i]==va){ eq++; } if(i0){ System.out.println(nCr(eq,a-big)); } else { long ans=0 ; int end=Math.min(eq,b); for(int i=a ; i<=end ; i++){ ans+=nCr(eq,i); } System.out.println(ans); } } static long nCr(int n,int r){ long val=1 ; for(int i=1 ; i<=r ; i++){ val=val*(n-i+1)/i ; } return val ; } static void reverse(long[] a){ for(int i=0 ; itoInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var v : Sequence(long) ; v := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( v[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; skip ; v := v->sort() ; execute reverse(v) ; var va : long ; va := v[a - 1+1] ; var big : int ; big := 0 ; var eq : int ; eq := 0 ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (v[i+1] > va) then ( big := big + 1 ) else if (v[i+1] = va) then ( eq := eq + 1 ) else skip ; ; if (i < a) then ( sum := sum+(v[i+1]) ) else skip ) ; i := i + 1 ) ; var bs : double ; bs := (sum + "")->toReal() ; var ba : double ; ba := (a + "")->toReal() ; OclFile["System.out"].println(bs.divide(ba, 25, ROUND_HALF_UP).toPlainString()) ; if (big > 0) then ( OclFile["System.out"].println(nCr(eq, a - big)) ) else ( var ans : long ; ans := 0 ; var end : int ; end := Set{eq, b}->min() ; var i : int ; i := a ; while i <= end do ( ( ans := ans+(nCr(eq, i)) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ) ; ); static operation nCr( n : int, r : int) : long pre: true post: true activity: ( var val : long ; val := 1 ; var i : int ; i := 1 ; while i <= r do ( ( val := val * (n - i + 1) / i ) ; i := i + 1 ) ; return val ); static operation reverse( a : Sequence(long)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < a->size() / 2 do ( ( var tmp : long ; tmp := a[i+1] ; a[i+1] := a[a->size() - 1 - i+1] ; a[a->size() - 1 - i+1] := tmp ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A=sc.nextInt(); int B=sc.nextInt(); long[] v=new long[N]; for(int i=0 ; ix).toArray(); long[] v_=v ; double avg=IntStream.range(0,A).mapToLong(i->v_[i]).average().getAsDouble(); long last=v[A-1]; int lastCount=(int)Arrays.stream(v).filter(x->x==last).count(); int lastChosen=(int)IntStream.range(0,A).filter(i->v_[i]==last).count(); long wayNum=C(lastCount,lastChosen); if(v[0]==last){ for(int i=A+1 ; i<=B && v[i-1]==last ; ++i){ ++lastChosen ; wayNum+=C(lastCount,lastChosen); } } return String.format("%f\n%d",avg,wayNum); } static long C(int n,int r){ long result=1 ; for(int i=0 ; itoInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var v : Sequence(long) ; v := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < v->size() do ( ( v[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(v, A, B)) ; skip ; ); static operation solve( v : Sequence(long), A : int, B : int) : String pre: true post: true activity: ( v := stream(v)->sort()->collect( _x1 | (lambda x : OclAny in x)->apply(_x1) )->asSequence() ; var v_ : Sequence(long) ; v_ := v ; var avg : double ; avg := Integer.subrange(0, A-1)->collect( _x1 | (lambda i : OclAny in v_[i+1])->apply(_x1) ).average().getAsDouble() ; var last : long ; last := v[A - 1+1] ; var lastCount : int ; lastCount := stream(v)->select( _x1 | (lambda x : OclAny in x = last)->apply(_x1) )->size()->oclAsType(int) ; var lastChosen : int ; lastChosen := Integer.subrange(0, A-1)->select( _x1 | (lambda i : OclAny in v_[i+1] = last)->apply(_x1) )->size()->oclAsType(int) ; var wayNum : long ; wayNum := C(lastCount, lastChosen) ; if (v[0+1] = last) then ( var i : int ; i := A + 1 ; while i <= B & v[i - 1+1] = last do ( ( lastChosen := lastChosen + 1 ; wayNum := wayNum+(C(lastCount, lastChosen)) ) ; i := i + 1 ) ) else skip ; return StringLib.format("%f\n%d",Sequence{avg,wayNum}) ); static operation C( n : int, r : int) : long pre: true post: true activity: ( var result : long ; result := 1 ; var i : int ; i := 0 ; while i < r do ( ( result := result * (n - i) / (i + 1) ) ; i := i + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Main main=new Main(); main.run(); } long C[][]; public void init(int n){ C=new long[n+1][n+1]; C[0][0]=1 ; for(int i=1 ; i<=n ; i++){ C[i][0]=1 ; for(int j=1 ; j<=n ; j++){ C[i][j]=C[i-1][j-1]+C[i-1][j]; } } } private long com(int n,int k){ if(nv=new ArrayList(); for(int i=0 ; icollect(Integer.subrange(1,n + 1)->collect(0)) ; C[0+1][0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( ( C[i+1][0+1] := 1 ; var j : int ; j := 1 ; while j <= n do ( ( C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1] ) ; j := j + 1 ) ) ; i := i + 1 ) ); operation com( n : int, k : int) : long pre: true post: true activity: ( if (n < k) then return 0 else skip ; return C[n+1][k+1] ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var v : Sequence(long) ; v := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( v := v->including(sc.getCurrent()->toLong()) ) ; i := i + 1 ) ; execute init(n) ; v, reverseOrder() := v, reverseOrder()->sort() ; var acnt : int ; acnt := 0 ; var apos : int ; apos := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (v->at(i+1) = v->at(a+1)) then ( acnt := acnt + 1 ; if (i < a) then ( apos := apos + 1 ) else skip ) else skip ) ; i := i + 1 ) ; var total : double ; total := 0.0 ; var i : int ; i := 0 ; while i < a do ( ( total := total+(v->at(i+1)) ) ; i := i + 1 ) ; var ave : double ; ave := total / a->oclAsType(double) ; OclFile["System.out"].println(ave) ; var ans : long ; ans := 0 ; if (apos = a) then ( var i : int ; i := a ; while i <= b do ( ( ans := ans+(com(acnt, i)) ) ; i := i + 1 ) ) else ( ans := com(acnt, apos) ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class B_as { Scanner in ; PrintWriter out ; public void solve()throws IOException { int testNo=in.nextInt(); for(int test=1 ; test<=testNo ; test++){ int n=in.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var test : int ; test := 1 ; while test <= testNo do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var m : int ; m := 0 ; var last : Sequence(int) ; last := Integer.subrange(1,n)->collect(0) ; var len : Sequence(int) ; len := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var blen : int ; blen := 2147483647 ; var best : int ; best := -1 ; var j : int ; j := 0 ; while j < m do ( ( if (last[j+1] = a[i+1] - 1 & len[j+1] < blen) then ( best := j ; blen := len[j+1] ) else skip ) ; j := j + 1 ) ; if (best = -1) then ( last[m+1] := a[i+1] ; len[m+1] := 1 ; m := m + 1 ) else ( last[best+1] := a[i+1] ; len[best+1] := len[best+1] + 1 ) ) ; i := i + 1 ) ; var blen : int ; blen := 2147483647 ; var i : int ; i := 0 ; while i < m do ( ( if (len[i+1] < blen) then ( blen := len[i+1] ) else skip ) ; i := i + 1 ) ; if (blen = 2147483647) then ( blen := 0 ) else skip ; skip ; ) ; test := test + 1 ) ); operation run() : void pre: true post: true activity: ( try ( in := OclFile.newOclFile_Read(OclFile("B-large.in")) ; out := OclFile.newOclFile_Write(OclFile("B-large.out")) ; execute solve() ; skip ; skip ; ) catch (e : IOException) do ( e.printStackTrace() ) ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( Locale.setDefault(Locale.US) ; B_as.newB_as().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static boolean isEmpty(long[] b){ for(int i=0 ; i0){ long A=sc.nextLong(); long B=sc.nextLong(); int n=sc.nextInt(); long[] a=new long[n]; long[] b=new long[n]; boolean ok=true ; long damage=0 ; for(int i=0 ; i0){ ok=false ; break ; } } if(! ok)System.out.println("YES"); else System.out.println("NO"); } } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation isEmpty( b : Sequence(long)) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < b->size() do ( ( if (b[i+1] /= 0) then return false else skip ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : long ; t := sc.getCurrent()->toLong() ; while (t > 0) do ( t := t - 1 ; skip ; ( var A : long ; A := sc.getCurrent()->toLong() ; var B : long ; B := sc.getCurrent()->toLong() ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,n)->collect(0) ; var ok : boolean ; ok := true ; var damage : long ; damage := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( b[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( damage := damage+((b[i+1] + A - 1) / A * a[i+1]) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (B - (damage - a[i+1]) > 0) then ( ok := false ; break ) else skip ) ; i := i + 1 ) ; if (not(ok)) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; ) ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class G1 { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ long n=sc.nextLong(); while(n--!=0){ Slove(); } } private static void Slove(){ long x=sc.nextLong(); long y=sc.nextLong(); int n=sc.nextInt(); long a[]=new long[n]; long b[]=new long[n]; for(int i=0 ; i=1 ? "YES" : "NO"); } } ------------------------------------------------------------ OCL File: --------- class G1 { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := sc.getCurrent()->toLong() ; while (n /= 0) do ( skip ; ( execute Slove() ) ; ) ); static operation Slove() : void pre: true post: true activity: ( var x : long ; x := sc.getCurrent()->toLong() ; var y : long ; y := sc.getCurrent()->toLong() ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var max : long ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( var times : long ; times := (b[i+1] + x - 1) / x ; y := y-(times * a[i+1]) ; max := Set{max, a[i+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(if max + y >= 1 then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { FastReader sc=new FastReader(); PrintWriter pw=new PrintWriter(System.out); int x=sc.nextInt(); int count=0 ; int tmp=x ; x=0 ; while(x!=360){ x=x+tmp ; if(x>360){ x=x-360 ; } count++; } System.out.println(count); } } class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var x : int ; x := sc.nextInt() ; var count : int ; count := 0 ; var tmp : int ; tmp := x ; x := 0 ; while (x /= 360) do ( x := x + tmp ; if (x > 360) then ( x := x - 360 ) else skip ; count := count + 1 ) ; OclFile["System.out"].println(count) ; ); } class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF294A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n+2]; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); } int m=sc.nextInt(); int x,y ; while(m-->0){ x=sc.nextInt(); y=sc.nextInt(); arr[x+1]+=(arr[x]-y); arr[x-1]+=y-1 ; arr[x]=0 ; } for(int i=1 ; i<=n ; i++){ System.out.println(arr[i]); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class CF294A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var x : int ; var y : int ; while (m > 0) do ( m := m - 1 ; skip ; ( x := sc.getCurrent()->toInteger() ; y := sc.getCurrent()->toInteger() ; arr[x + 1+1] := arr[x + 1+1]+((arr[x+1] - y)) ; arr[x - 1+1] := arr[x - 1+1]+(y - 1) ; arr[x+1] := 0 ; ) ; ) ; var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].println(arr[i+1]) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF294A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n+2]; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); } int m=sc.nextInt(); while(m-->0){ int x=sc.nextInt(); int y=sc.nextInt(); arr[x+1]+=(arr[x]-y); arr[x-1]+=y-1 ; arr[x]=0 ; } for(int i=1 ; i<=n ; i++){ System.out.println(arr[i]); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class CF294A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; while (m > 0) do ( m := m - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; arr[x + 1+1] := arr[x + 1+1]+((arr[x+1] - y)) ; arr[x - 1+1] := arr[x - 1+1]+(y - 1) ; arr[x+1] := 0 ; ) ; ) ; var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].println(arr[i+1]) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF294A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n+2]; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); } int m=sc.nextInt(); int x,y ; while(m-->0){ x=sc.nextInt(); y=sc.nextInt(); arr[x+1]+=(arr[x]-y); arr[x-1]+=y-1 ; arr[x]=0 ; } for(int i=1 ; i<=n ; i++){ System.out.println(arr[i]); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class CF294A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var x : int ; var y : int ; while (m > 0) do ( m := m - 1 ; skip ; ( x := sc.getCurrent()->toInteger() ; y := sc.getCurrent()->toInteger() ; arr[x + 1+1] := arr[x + 1+1]+((arr[x+1] - y)) ; arr[x - 1+1] := arr[x - 1+1]+(y - 1) ; arr[x+1] := 0 ; ) ; ) ; var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].println(arr[i+1]) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _294A_ShaassandOskols { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=parseInt(input.nextLine()); int[] lines=new int[n+2]; for(int i=1 ; i<=n ; i++){ lines[i]=input.nextInt(); ; } input.nextLine(); int m=parseInt(input.nextLine()); for(int i=0 ; icollect(0) ; var i : int ; i := 1 ; while i <= n do ( ( lines[i+1] := input.getCurrent()->toInteger() ; ) ; i := i + 1 ) ; skip ; var m : int ; m := parseInt(input.nextLine()) ; var i : int ; i := 0 ; while i < m do ( ( var wire : int ; wire := input.getCurrent()->toInteger() ; var xith : int ; xith := input.getCurrent()->toInteger() ; skip ; var left : int ; left := xith - 1 ; var right : int ; right := lines[wire+1] - xith ; lines[wire + 1+1] := lines[wire + 1+1]+(right) ; lines[wire - 1+1] := lines[wire - 1+1]+(left) ; lines[wire+1] := 0 ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].println(lines[i+1]) ) ; i := i + 1 ) ; ); } 94A_ShaassandOskols { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := parseInt(input.nextLine()) ; var lines : Sequence(int) ; lines := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( lines[i+1] := input.getCurrent()->toInteger() ; ) ; i := i + 1 ) ; skip ; var m : int ; m := parseInt(input.nextLine()) ; var i : int ; i := 0 ; while i < m do ( ( var wire : int ; wire := input.getCurrent()->toInteger() ; var xith : int ; xith := input.getCurrent()->toInteger() ; skip ; var left : int ; left := xith - 1 ; var right : int ; right := lines[wire+1] - xith ; lines[wire + 1+1] := lines[wire + 1+1]+(right) ; lines[wire - 1+1] := lines[wire - 1+1]+(left) ; lines[wire+1] := 0 ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].println(lines[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class BuyAShovel { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n ; n=scan.nextInt(); int arr[]=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var m : int ; var x : int ; var y : int ; m := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( x := scan.getCurrent()->toInteger() ; y := scan.getCurrent()->toInteger() ; if (x = n & x = 1) then ( arr[x - 1+1] := 0 ) else if (x = n) then ( arr[x - 1+1] := (arr[x - 1+1] - (arr[x - 1+1] - y)) - 1 ; arr[x - 2+1] := arr[x - 2+1]+(arr[x - 1+1]) ; arr[x - 1+1] := 0 ) else if (x = 1) then ( arr[x+1] := arr[x+1]+(arr[x - 1+1] - y) ; arr[x - 1+1] := (arr[x - 1+1] - (arr[x - 1+1] - y)) - 1 ; arr[x - 1+1] := 0 ) else ( arr[x+1] := arr[x+1]+(arr[x - 1+1] - y) ; arr[x - 1+1] := (arr[x - 1+1] - (arr[x - 1+1] - y)) - 1 ; arr[x - 2+1] := arr[x - 2+1]+(arr[x - 1+1]) ; arr[x - 1+1] := 0 ) ; ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(arr[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Pattern { void display(){ int n=5 ; int space=n/2,num=1 ; for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=space ; j++)System.out.print(" "); int count=num/2+1 ; for(int k=1 ; k<=num ; k++){ System.out.print(count); if(k<=num/2)count--; else count++; } System.out.println(); if(i<=n/2){ space=space-1 ; num=num+2 ; } else { space=space+1 ; num=num-2 ; } } } public static void main(String[] args){ Pattern p=new Pattern(); p.display(); } } ------------------------------------------------------------ OCL File: --------- class Pattern { operation display() : void pre: true post: true activity: ( var n : int ; n := 5 ; var space : int ; space := n / 2 ; var num : int ; num := 1 ; var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := 1 ; while j <= space do ( OclFile["System.out"].print(" ") ; ; j := j + 1 ) ; var count : int ; count := num / 2 + 1 ; var k : int ; k := 1 ; while k <= num do ( ( OclFile["System.out"].print(count) ; if (k <= num / 2) then count := count - 1 ; else count := count + 1 ; ) ; k := k + 1 ) ; OclFile["System.out"].println() ; if (i <= n / 2) then ( space := space - 1 ; num := num + 2 ) else ( space := space + 1 ; num := num - 2 ) ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var p : OclRegex ; p := OclRegex() ; p.display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int N=3 ; static int countPairs(int a[][]){ int sumr[]=new int[N]; int sumc[]=new int[N]; for(int i=0 ; isumr[j])count++; return count ; } public static void main(String[] args){ int a[][]={ { 1,2,3 },{ 4,5,6 },{ 7,8,9 } }; System.out.println(countPairs(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute N : int := 3; static operation countPairs( a : Sequence(Sequence(int))) : int pre: true post: true activity: ( var sumr : Sequence(int) ; sumr := Integer.subrange(1,N)->collect(0) ; var sumc : Sequence(int) ; sumc := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( var j : int ; j := 0 ; while j < N do ( ( sumr[i+1] := sumr[i+1]+(a[i+1][j+1]) ; sumc[j+1] := sumc[j+1]+(a[i+1][j+1]) ) ; j := j + 1 ) ; ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N do ( var j : int ; j := 0 ; while j < N do ( if (sumc[i+1] > sumr[j+1]) then count := count + 1 ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(Sequence(int)) ; a := Sequence{Sequence{1,2,3},Sequence{4,5,6},Sequence{7,8,9}} ; OclFile["System.out"].println(countPairs(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; class GFG { public static int nobleInteger(int arr[]){ int size=arr.length ; for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < size do ( ( var count : int ; count := 0 ; var j : int ; j := 0 ; while j < size do ( if (arr[i+1] < arr[j+1]) then count := count + 1 ; else skip ; ; j := j + 1 ) ; if (count = arr[i+1]) then return arr[i+1] else skip ) ; i := i + 1 ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,3,20,40,2} ; var res : int ; res := nobleInteger(arr) ; if (res /= -1) then OclFile["System.out"].println("The noble " + "integer is " + res) ; else OclFile["System.out"].println("No Noble " + "Integer Found") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package round3 ; import java.io.File ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class B { static class Niz { int zadnji,duzina ; Niz(int element){ duzina=1 ; zadnji=element ; } } public static void main(String[] args)throws IOException { Scanner in=new Scanner(new File("B.in")); PrintWriter out=new PrintWriter(new File("B.out")); int tt=in.nextInt(); for(int ttt=1 ; ttt<=tt ; ttt++){ int n=in.nextInt(); int[] t=new int[n]; for(int i=0 ; i0){ Arrays.sort(t); ArrayListnizovi=new ArrayList(); for(int i=0 ; iniz.duzina))a=niz ; if(a==null)nizovi.add(new Niz(t[i])); else { a.duzina++; a.zadnji=t[i]; } } res=n ; for(Niz niz : nizovi)if(niz.duzinatoInteger() ; var ttt : int ; ttt := 1 ; while ttt <= tt do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var t : Sequence(int) ; t := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( t[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var res : int ; res := 0 ; if (n > 0) then ( t := t->sort() ; var nizovi : Sequence(Niz) ; nizovi := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var a : Niz ; a := null ; for (niz : nizovi) do ( if (niz.zadnji = t[i+1] - 1 & (a = null or a.duzina > niz.duzina)) then a := niz ; else skip ; ) ; if (a = null) then nizovi := nizovi->including(Niz.newNiz(t[i+1])) ; else ( a.duzina := a.duzina + 1 ; a.zadnji := t[i+1] ) ) ; i := i + 1 ) ; res := n ; for (niz : nizovi) do ( if (niz.duzina < res) then res := niz.duzina ; else skip ; ) ; ) else skip ; skip ; skip ; ) ; ttt := ttt + 1 ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayLista=new ArrayList<>(); ArrayListb=new ArrayList<>(); ArrayListc=new ArrayList<>(); for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Sequence{} ; var b : Sequence(int) ; b := Sequence{} ; var c : Sequence(int) ; c := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x = 1) then a := a->including(i + 1) ; else skip ; if (x = 2) then b := b->including(i + 1) ; else skip ; if (x = 3) then c := c->including(i + 1) ; else skip ) ; i := i + 1 ) ; var count : int ; count := Set{a->size(), Set{b->size(), c->size()}->min()}->min() ; OclFile["System.out"].println(count) ; var i : int ; i := 0 ; while i < count do ( ( OclFile["System.out"].println(a->at(i+1) + " " + b->at(i+1) + " " + c->at(i+1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class Main { BufferedReader br ; StringTokenizer st ; int max=-1 ; void solve()throws IOException { long x=ni(); long temp=360 ; long i=2 ; while(temp % x!=0){ temp=360*i ; i++; } pl(temp/x); } int hcf(int a,int b){ if(a==0)return b ; return hcf(b % a,a); } Main(){ try { br=new BufferedReader(new InputStreamReader(System.in)); try { st=new StringTokenizer(br.readLine()); } catch(Exception e){ System.out.println(e); } } catch(Exception e){ System.out.println(e); } } Main(String s){ try { br=new BufferedReader(new FileReader(s)); st=new StringTokenizer(br.readLine()); } catch(Exception e){ System.out.println(e); } } public static void main(String[] args)throws IOException { new Main().solve(); } String ns(){ if(! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(Exception e){ System.out.println(e); } } return st.nextToken(); } int ni(){ return Integer.parseInt(ns()); } long nl(){ return Long.parseLong(ns()); } double nd(){ return Double.parseDouble(ns()); } void pl(String s){ System.out.println(s); } void pl(long s){ System.out.println(s); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute br : OclFile; attribute st : OclIterator; attribute max : int := -1; operation solve() : void pre: true post: true activity: ( var x : long ; x := ni() ; var temp : long ; temp := 360 ; var i : long ; i := 2 ; while (temp mod x /= 0) do ( temp := 360 * i ; i := i + 1 ) ; execute pl(temp / x) ; ); operation hcf( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then return b else skip ; return hcf(b mod a, a) ); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : ProgramException) do ( OclFile["System.out"].println(e) ) ) catch (e : ProgramException) do ( OclFile["System.out"].println(e) ) ); static operation newMain( s : String) : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ; st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : ProgramException) do ( OclFile["System.out"].println(e) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); operation ns() : String pre: true post: true activity: ( if (not(st.hasNext())) then ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : ProgramException) do ( OclFile["System.out"].println(e) ) ) else skip ; return st.next() ); operation ni() : int pre: true post: true activity: ( return (ns())->toInteger() ); operation nl() : long pre: true post: true activity: ( return (ns())->toLong() ); operation nd() : double pre: true post: true activity: ( return (ns())->toReal() ); operation pl( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); operation pl( s : long) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] ones=new int[n]; int[] twos=new int[n]; int[] thirds=new int[n]; int c_one=0,c_sec=0,c_third=0 ; for(int i=0 ; itoInteger() ; var ones : Sequence(int) ; ones := Integer.subrange(1,n)->collect(0) ; var twos : Sequence(int) ; twos := Integer.subrange(1,n)->collect(0) ; var thirds : Sequence(int) ; thirds := Integer.subrange(1,n)->collect(0) ; var c_one : int ; c_one := 0 ; var c_sec : int ; c_sec := 0 ; var c_third : int ; c_third := 0 ; var i : int ; i := 0 ; while i < n do ( ( var num : int ; num := sc.getCurrent()->toInteger() ; if (num = 1) then ( ones[c_one+1] := i + 1 ; c_one := c_one + 1 ) else if (num = 2) then ( twos[c_sec+1] := i + 1 ; c_sec := c_sec + 1 ) else if (num = 3) then ( thirds[c_third+1] := i + 1 ; c_third := c_third + 1 ) else skip ; ; ) ; i := i + 1 ) ; var min : int ; min := Set{c_one, Set{c_third, c_sec}->min()}->min() ; OclFile["System.out"].println(min) ; var i : int ; i := 0 ; while i < min do ( ( if (min = 0) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(ones[i+1] + " " + twos[i+1] + " " + thirds[i+1]) ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class NewClass33 { @ SuppressWarnings("empty-statement")public static void main(String[] args){ java.util.Scanner in=new java.util.Scanner(System.in); int n=in.nextInt(); int arr[][]=new int[4][5001]; int count[]=new int[4]; for(int i=1 ; i<=n ; i++){ int g=in.nextInt(); count[g]++; arr[g][count[g] ]=i ; } int s=Math.min(Math.min(count[1],count[2]),count[3]); System.out.println(s); for(int i=1 ; i<=s ; i++){ System.out.print(arr[1][i]+" "+arr[2][i]+" "+arr[3][i]); System.out.println(""); } } } ------------------------------------------------------------ OCL File: --------- class NewClass33 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : Scanner ; in := Scanner.newScanner(OclFile["System.in"]) ; var n : int ; n := in.nextInt() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,4)->collect(Integer.subrange(1,5001)->collect(0)) ; var count : Sequence(int) ; count := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( var g : int ; g := in.nextInt() ; count[g+1] := count[g+1] + 1 ; arr[g+1][count[g+1]+1] := i ) ; i := i + 1 ) ; var s : int ; s := Set{Set{count[1+1], count[2+1]}->min(), count[3+1]}->min() ; OclFile["System.out"].println(s) ; var i : int ; i := 1 ; while i <= s do ( ( OclFile["System.out"].print(arr[1+1][i+1] + " " + arr[2+1][i+1] + " " + arr[3+1][i+1]) ; OclFile["System.out"].println("") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class TeamOlympiad { public static void main(String[] args){ Scanner in=new Scanner(System.in); int number=in.nextInt(); int[][] arr=new int[4][number+1]; for(int i=1 ; i<=number ; i++){ int a=in.nextInt(); arr[a][++arr[a][0] ]=i ; } int w=Math.min(Math.min(arr[1][0],arr[2][0]),arr[3][0]); System.out.println(w); for(int i=1 ; i<=w ; i++){ System.out.println(arr[1][i]+" "+arr[2][i]+" "+arr[3][i]); } } } ------------------------------------------------------------ OCL File: --------- class TeamOlympiad { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var number : int ; number := in.getCurrent()->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,4)->collect(Integer.subrange(1,number + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= number do ( ( var a : int ; a := in.getCurrent()->toInteger() ; arr[a+1][0+1] := arr[a+1][0+1] + 1 ; arr[a+1][arr[a+1][0+1]+1] := i ) ; i := i + 1 ) ; var w : int ; w := Set{Set{arr[1+1][0+1], arr[2+1][0+1]}->min(), arr[3+1][0+1]}->min() ; OclFile["System.out"].println(w) ; var i : int ; i := 1 ; while i <= w do ( ( OclFile["System.out"].println(arr[1+1][i+1] + " " + arr[2+1][i+1] + " " + arr[3+1][i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GFG { public static int findRepeatFirst(String s){ int p=-1,i,k ; int MAX_CHAR=256 ; int hash[]=new int[MAX_CHAR]; int pos[]=new int[MAX_CHAR]; for(i=0 ; ipos[i])p=pos[i]; } } return p ; } public static void main(String[] args){ String str="geeksforgeeks" ; int pos=findRepeatFirst(str); if(pos==-1)System.out.println("Not found"); else System.out.println(str.charAt(pos)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findRepeatFirst( s : String) : int pre: true post: true activity: ( var p : int ; p := -1 ; var i : int ; var k : int ; var MAX_CHAR : int ; MAX_CHAR := 256 ; var hash : Sequence(int) ; hash := Integer.subrange(1,MAX_CHAR)->collect(0) ; var pos : Sequence(int) ; pos := Integer.subrange(1,MAX_CHAR)->collect(0) ; i := 0 ; while i < s->size() do ( ( k := s->at(i+1)->oclAsType(int) ; 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 ; ) ; i := i + 1 ) ; i := 0 ; while i < MAX_CHAR do ( ( if (hash[i+1] = 2) then ( if (p = -1) then p := pos[i+1] ; else if (p > pos[i+1]) then p := pos[i+1] ; else skip ; ) else skip ) ; i := i + 1 ) ; return p ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var pos : int ; pos := findRepeatFirst(str) ; if (pos = -1) then OclFile["System.out"].println("Not found") ; else OclFile["System.out"].println(str->at(pos+1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long N=sc.nextLong(); long f=(long)Math.ceil(Math.sqrt(N)); long min=N-1 ; for(long i=1 ; i<=f ; i++){ if(N % i!=0){ continue ; } if(N/i+i-2<=min){ min=N/i+i-2 ; } } System.out.println(min); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := sc.getCurrent()->toLong() ; var f : long ; f := ((N)->sqrt())->ceil()->oclAsType(long) ; var min : long ; min := N - 1 ; var i : long ; i := 1 ; while i <= f do ( ( if (N mod i /= 0) then ( continue ) else skip ; if (N / i + i - 2 <= min) then ( min := N / i + i - 2 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.math.*; import java.util.ArrayList ; import java.util.*; import java.io.*; public class Main { static Scanner scn=new Scanner(System.in); public static void main(String[] args){ long n=scn.nextLong(); int s=(int)Math.sqrt(n); boolean flag=true ; long n1=-1 ; long n2=-1 ; while(flag){ if(n % s==0){ flag=false ; n1=s ; n2=n/s ; } else { s--; } } long ans=n1+n2-2 ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scn : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := scn.getCurrent()->toLong() ; var s : int ; s := (n)->sqrt()->oclAsType(int) ; var flag : boolean ; flag := true ; var n1 : long ; n1 := -1 ; var n2 : long ; n2 := -1 ; while (flag) do ( if (n mod s = 0) then ( flag := false ; n1 := s ; n2 := n / s ) else ( s := s - 1 ) ) ; var ans : long ; ans := n1 + n2 - 2 ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); CWalkOnMultiplicationTable solver=new CWalkOnMultiplicationTable(); solver.solve(1,in,out); out.close(); } static class CWalkOnMultiplicationTable { public void solve(int testNumber,InputReader in,PrintWriter out){ long n=in.nextLong(); long answer=Long.MAX_VALUE ; for(long i=1 ; i*i<=n ; i++){ if(n % i==0){ long j=n/i ; answer=Math.min(answer,i+j-2); } } out.println(answer); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : CWalkOnMultiplicationTable ; solver := CWalkOnMultiplicationTable.newCWalkOnMultiplicationTable() ; solver.solve(1, in, out) ; skip ; ); static class CWalkOnMultiplicationTable { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : long ; n := in.nextLong() ; var answer : long ; answer := "9223372036854775807"->toLong() ; var i : long ; i := 1 ; while i * i <= n do ( ( if (n mod i = 0) then ( var j : long ; j := n / i ; answer := Set{answer, i + j - 2}->min() ) else skip ) ; i := i + 1 ) ; skip ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner scan=new Scanner(System.in)){ long N=scan.nextLong(); ArrayListzenyaku_a=enum_div(N); ArrayListzenyaku_b=enum_div2(zenyaku_a,N); long min=zenyaku_a.get(0)+zenyaku_b.get(0); for(int i=1 ; izenyaku_a.get(i)+zenyaku_b.get(i)){ min=zenyaku_a.get(i)+zenyaku_b.get(i); } } System.out.println(min-2); ; } } private static ArrayListenum_div(long n){ ArrayListret=new ArrayList(); for(long i=1 ; i*i<=n ; i++){ if(n % i==0){ ret.add(i); if(i!=1 && i*i!=n){ ret.add(n/i); } } } ret.add(n); Collections.sort(ret); return ret ; } private static ArrayListenum_div2(ArrayLista,long n){ ArrayListret=new ArrayList(); for(int i=0 ; itoLong() ; var zenyaku_a : Sequence(long) ; zenyaku_a := enum_div(N) ; var zenyaku_b : Sequence(long) ; zenyaku_b := enum_div2(zenyaku_a, N) ; var min : long ; min := zenyaku_a->at(0+1) + zenyaku_b->at(0+1) ; var i : int ; i := 1 ; while i < zenyaku_a->size() do ( ( if (min > zenyaku_a->at(i+1) + zenyaku_b->at(i+1)) then ( min := zenyaku_a->at(i+1) + zenyaku_b->at(i+1) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min - 2) ; )) ); static operation enum_div( n : long) : Sequence(long) pre: true post: true activity: ( var ret : Sequence(long) ; ret := Sequence{} ; var i : long ; i := 1 ; while i * i <= n do ( ( if (n mod i = 0) then ( ret := ret->including(i) ; if (i /= 1 & i * i /= n) then ( ret := ret->including(n / i) ) else skip ) else skip ) ; i := i + 1 ) ; ret := ret->including(n) ; ret := ret->sort() ; return ret ); static operation enum_div2( a : Sequence(long), n : long) : Sequence(long) pre: true post: true activity: ( var ret : Sequence(long) ; ret := Sequence{} ; var i : int ; i := 0 ; while i < a->size() do ( ( ret := ret->including(n / a->at(i+1)) ) ; i := i + 1 ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintWriter ; import java.lang.reflect.Array ; import java.math.BigDecimal ; import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Comparator ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Iterator ; import java.util.List ; import java.util.Map ; import java.util.Map.Entry ; import java.util.PriorityQueue ; import java.util.Queue ; import java.util.Scanner ; import java.util.Set ; import java.util.Stack ; import java.util.TreeMap ; import java.util.TreeSet ; import static java.util.Comparator.*; public class Main { public static void main(String[] args){ PrintWriter out=new PrintWriter(System.out); Solver solver=new Solver(System.in,out); solver.solve(); out.close(); } } class Solver { Scanner sc ; PrintWriter out ; public Solver(InputStream in,PrintWriter out){ sc=new Scanner(in); this.out=out ; } long INF=999999999999L ; public void solve(){ long N=Long.parseLong(sc.next()); long ans=INF ; for(long i=2 ; i*i<=N ; i++){ if(N % i==0){ ans=Math.min(ans,(i-1)+(N/i-1)); } } if(ans==INF)ans=N-1 ; out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var solver : Solver ; solver := Solver.newSolver(OclFile["System.in"], out) ; solver.solve() ; skip ); } class Solver { attribute sc : OclFile; attribute out : OclFile; static operation newSolver( in : OclFile, out : OclFile) : Solver pre: true post: true activity: ( var self : Solver ; self := createSolver(); self.initialise(in, out); return self ); operation initialise( in : OclFile, out : OclFile) : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(in) ; self.out := out ); attribute INF : long := 999999999999L; operation solve() : void pre: true post: true activity: ( var N : long ; N := (sc.getCurrent())->toLong() ; var ans : long ; ans := INF ; var i : long ; i := 2 ; while i * i <= N do ( ( if (N mod i = 0) then ( ans := Set{ans, (i - 1) + (N / i - 1)}->min() ) else skip ) ; i := i + 1 ) ; if (ans = INF) then ans := N - 1 ; else skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class Main { static StreamTokenizer in ; static int next()throws Exception { in.nextToken(); return(int)in.nval ; }; static PrintWriter out ; static String NAME="b" ; public static void main(String[] args)throws Exception { in=new StreamTokenizer(new BufferedReader(new FileReader(new File(NAME+".in")))); out=new PrintWriter(new File(NAME+".out")); int tests=next(); for(int test=1 ; test<=tests ; test++){ int n=next(); if(n==0){ out.println("Case #"+test+": 0"); continue ; } int m=10005 ; int[] k=new int[m]; for(int i=0 ; is=new ArrayList(); ArrayListe=new ArrayList(); for(int i=start ; i<=end ; i++){ if(k[i]>k[i-1])for(int j=0 ; joclAsType(int) ); static attribute out : OclFile; static attribute NAME : String := "b"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( in := StreamTokenizer.newStreamTokenizer(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile(NAME + ".in")))) ; out := OclFile.newOclFile_Write(OclFile(NAME + ".out")) ; var tests : int ; tests := next() ; var test : int ; test := 1 ; while test <= tests do ( ( var n : int ; n := next() ; if (n = 0) then ( skip ; continue ) else skip ; var m : int ; m := 10005 ; var k : Sequence(int) ; k := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( k[next()+1] := k[next()+1] + 1 ; ; i := i + 1 ) ; var answ : int ; answ := 100000 ; var start : int ; start := 0 ; var end : int ; end := 0 ; while (true) do ( while (start < m & k[start+1] = 0) do start := start + 1 ; ; if (start = m) then break else skip ; end := start ; while (k[end+1] /= 0) do end := end + 1 ; ; var s : Sequence(int) ; s := Sequence{} ; var e : Sequence(int) ; e := Sequence{} ; var i : int ; i := start ; while i <= end do ( ( if (k[i+1] > k[i - 1+1]) then var j : int ; j := 0 ; while j < k[i+1] - k[i - 1+1] do ( s := s->including(i) ; ; j := j + 1 ) ; else skip ; if (k[i+1] < k[i - 1+1]) then var j : int ; j := 0 ; while j < k[i - 1+1] - k[i+1] do ( e := e->including(i) ; ; j := j + 1 ) ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s->size() do ( answ := Set{answ, e->at(i+1) - s->at(i+1)}->min() ; ; i := i + 1 ) ; start := end ; ) ; skip ; ) ; test := test + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ShortestKingPath { public static void main(String[] args){ Scanner in=new Scanner(System.in); String s=in.next(); String s1=in.next(); char c[]=s.toCharArray(); char c1[]=s1.toCharArray(); int diff=c1[0]-c[0]; int dif=c1[1]-c[1]; int n=Math.abs(diff); int m=Math.abs(dif); String ans="" ; while(diff!=0 || dif!=0){ if(diff>0){ ans+="R" ; diff--; } if(diff<0){ ans+="L" ; diff++; } if(dif>0){ ans+="U" ; dif--; } if(dif<0){ ans+="D" ; dif++; } ans+="\n" ; } System.out.println(Math.max(n,m)); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class ShortestKingPath { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := in.getCurrent() ; var s1 : String ; s1 := in.getCurrent() ; var c : Sequence(String) ; c := s->characters() ; var c1 : Sequence(String) ; c1 := s1->characters() ; var diff : int ; diff := c1[0+1] - c[0+1] ; var dif : int ; dif := c1[1+1] - c[1+1] ; var n : int ; n := if diff < 0 then -(diff) else diff endif ; var m : int ; m := if dif < 0 then -(dif) else dif endif ; var ans : String ; ans := "" ; while (diff /= 0 or dif /= 0) do ( if (diff > 0) then ( ans := ans+("R") ; diff := diff - 1 ) else skip ; if (diff < 0) then ( ans := ans+("L") ; diff := diff + 1 ) else skip ; if (dif > 0) then ( ans := ans+("U") ; dif := dif - 1 ) else skip ; if (dif < 0) then ( ans := ans+("D") ; dif := dif + 1 ) else skip ; ans := ans+("\n") ; ) ; OclFile["System.out"].println(Set{n, m}->max()) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); BigInteger x=new BigInteger(sc.next()); BigInteger n=new BigInteger("360"); BigInteger gcd=x.gcd(n); System.out.println(n.divide(gcd)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : long ; x := long(sc.getCurrent()) ; var n : long ; n := long("360") ; var gcd : long ; gcd := x.gcd(n) ; OclFile["System.out"].println(n.divide(gcd)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int[] seg={ 6,2,5,5,4,5,6,3,7,6 }; static int computeSegment(int x){ if(x==0)return seg[0]; int count=0 ; while(x>0){ count+=seg[x % 10]; x/=10 ; } return count ; } static int elementMinSegment(int[] arr,int n){ int minseg=computeSegment(arr[0]); int minindex=0 ; for(int i=1 ; i 0) do ( count := count+(seg[x mod 10+1]) ; x := x/(10) ) ; return count ); static operation elementMinSegment( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var minseg : int ; minseg := computeSegment(arr[0+1]) ; var minindex : int ; minindex := 0 ; var i : int ; i := 1 ; while i < n do ( ( var temp : int ; temp := computeSegment(arr[i+1]) ; if (temp < minseg) then ( minseg := temp ; minindex := i ) else skip ) ; i := i + 1 ) ; return arr[minindex+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{489,206,745,123,756} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(elementMinSegment(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { static int factorial(int n){ int fact=1,i ; if(n==0)return 1 ; for(i=1 ; i<=n ; i++)fact*=i ; return fact ; } static void findmiddle(int A,int X,int n){ int i,j,aPow,xPow ; float middleTerm1,middleTerm2 ; if(n % 2==0){ i=n/2 ; aPow=(int)Math.pow(A,n-i); xPow=(int)Math.pow(X,i); middleTerm1=((float)factorial(n)/(factorial(n-i)*factorial(i)))*aPow*xPow ; System.out.println("MiddleTerm="+middleTerm1); } else { i=(n-1)/2 ; j=(n+1)/2 ; aPow=(int)Math.pow(A,n-i); xPow=(int)Math.pow(X,i); middleTerm1=((float)factorial(n)/(factorial(n-i)*factorial(i)))*aPow*xPow ; aPow=(int)Math.pow(A,n-j); xPow=(int)Math.pow(X,j); middleTerm2=((float)factorial(n)/(factorial(n-j)*factorial(j)))*aPow*xPow ; System.out.println("MiddleTerm1="+middleTerm1); System.out.println("MiddleTerm2="+middleTerm2); } } public static void main(String[] args){ int n=6,A=2,X=4 ; findmiddle(A,X,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation factorial( n : int) : int pre: true post: true activity: ( var fact : int ; fact := 1 ; var i : int ; if (n = 0) then return 1 else skip ; i := 1 ; while i <= n do ( fact := fact*(i) ; ; i := i + 1 ) ; return fact ); static operation findmiddle( A : int, X : int, n : int) : void pre: true post: true activity: ( var i : int ; var j : int ; var aPow : int ; var xPow : int ; var middleTerm1 : double ; var middleTerm2 : double ; if (n mod 2 = 0) then ( i := n / 2 ; aPow := A->pow(n - i)->oclAsType(int) ; xPow := X->pow(i)->oclAsType(int) ; middleTerm1 := (factorial(n)->oclAsType(double) / (factorial(n - i) * factorial(i))) * aPow * xPow ; OclFile["System.out"].println("MiddleTerm=" + middleTerm1) ; ) else ( i := (n - 1) / 2 ; j := (n + 1) / 2 ; aPow := A->pow(n - i)->oclAsType(int) ; xPow := X->pow(i)->oclAsType(int) ; middleTerm1 := (factorial(n)->oclAsType(double) / (factorial(n - i) * factorial(i))) * aPow * xPow ; aPow := A->pow(n - j)->oclAsType(int) ; xPow := X->pow(j)->oclAsType(int) ; middleTerm2 := (factorial(n)->oclAsType(double) / (factorial(n - j) * factorial(j))) * aPow * xPow ; OclFile["System.out"].println("MiddleTerm1=" + middleTerm1) ; OclFile["System.out"].println("MiddleTerm2=" + middleTerm2) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var A : int ; A := 2 ; var X : int ; X := 4 ; execute findmiddle(A, X, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public class a { public static long time ; public static void main(String[] args)throws Exception { time=System.currentTimeMillis(); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); go(br); br.close(); System.exit(0); } public static void go(BufferedReader br)throws Exception { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); System.out.println(a*(b-1)+b*(c-1)+c*(a-1)+1); sc.close(); } public static void checkTime(){ System.out.println(System.currentTimeMillis()-time); time=System.currentTimeMillis(); } } ------------------------------------------------------------ OCL File: --------- class a { static attribute time : long; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( time := OclDate.getSystemTime() ; var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; execute go(br) ; skip ; OclProcess.exit(0) ; ); static operation go( br : OclFile) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(a * (b - 1) + b * (c - 1) + c * (a - 1) + 1) ; skip ; ); static operation checkTime() : void pre: true post: true activity: ( OclFile["System.out"].println(OclDate.getSystemTime() - time) ; time := OclDate.getSystemTime() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { FastScanner input=new FastScanner(); long a=input.nextLong(); long b=input.nextLong(); long c=input.nextLong(); long ans=0 ; ans=(a*b*c)-((a-1)*(b-1)*(c-1)); System.out.println(ans); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; itoInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.PrintWriter ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); double[] a=new double[n]; double[] tmp=new double[n]; long ans=0 ; for(int i=0 ; i=0){ ans++; } } Arrays.sort(tmp); for(int i=0 ; i0 ; i-=i &(-i))res+=data[i]; return res ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var a : Sequence(double) ; a := Integer.subrange(1,n)->collect(0.0) ; var tmp : Sequence(double) ; tmp := Integer.subrange(1,n)->collect(0.0) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() - k ; if (i /= 0) then ( a[i+1] := a[i+1]+(a[i - 1+1]) ) else skip ; tmp[i+1] := a[i+1] ; if (tmp[i+1] >= 0) then ( ans := ans + 1 ) else skip ) ; i := i + 1 ) ; tmp := tmp->sort() ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := -(tmp->indexOf(a[i+1] + 0.1) - 1) ) ; i := i + 1 ) ; var b : BIT ; b := BIT.newBIT(n + 1) ; var i : int ; i := 0 ; while i < n do ( ( ans := ans+(b->at(a[i+1]->oclAsType(int)+1)) ; b->excludes(a[i+1]->oclAsType(int)) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static class BIT { attribute n : int; attribute data : Sequence(int); static operation newBIT( n : int) : BIT pre: true post: true activity: ( var self : BIT ; self := createBIT(); self.initialise(n); return self ); operation initialise( n : int) : void pre: true post: true activity: ( self.n := n ; data := Integer.subrange(1,n + 1)->collect(0) ); operation add( i : int) : void pre: true post: true activity: ( while i <= n do ( data[i+1] := data[i+1] + 1 ; ; i := i+(MathLib.bitwiseAnd(i,(-i))) ) ); operation get( i : int) : int pre: true post: true activity: ( var res : int ; res := 0 ; while i > 0 do ( res := res+(data[i+1]) ; ; i := i-(MathLib.bitwiseAnd(i,(-i))) ) ; return res ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static long[] bit ; static int len ; static void add(int x,long y){ while(x<=len){ bit[x]+=y ; x+=x &(-x); } } static long sum(int x){ long tmp=0L ; while(x>0){ tmp+=bit[x]; x-=x &(-x); } return tmp ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); int[] a=new int[N]; for(int i=0 ; iset=new TreeSet(); set.add(0L); for(int i=0 ; ilist=new ArrayList(set); int[] ruiseki_new=new int[N+1]; for(int i=0 ; i 0) do ( tmp := tmp+(bit[x+1]) ; x := x-(x & (-x)) ) ; return tmp ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( a[i+1] := sc.getCurrent()->toInteger() ; a[i+1] := a[i+1]-(K) ) ; i := i + 1 ) ; var ruiseki : Sequence(long) ; ruiseki := Integer.subrange(1,N + 1)->collect(0) ; var set : Set(long) ; set := Set{} ; set := set->including(0L) ; var i : int ; i := 0 ; while i < N do ( ( ruiseki[i + 1+1] := ruiseki[i+1] + a[i+1] ; set := set->including(ruiseki[i + 1+1]) ) ; i := i + 1 ) ; var list : Sequence(long) ; list := Sequence{}->union(set) ; var ruiseki_new : Sequence(int) ; ruiseki_new := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N + 1 do ( ( ruiseki_new[i+1] := (list->indexOf(ruiseki[i+1]) - 1) + 1 ) ; i := i + 1 ) ; len := list->size() ; bit := Integer.subrange(1,len + 1)->collect(0) ; var i : int ; i := 0 ; while i < N + 1 do ( ( execute add(ruiseki_new[i+1], 1) ) ; i := i + 1 ) ; var ans : long ; ans := 0L ; var i : int ; i := 0 ; while i < N + 1 do ( ( execute add(ruiseki_new[i+1], -1) ; ans := ans+((N - i - sum(ruiseki_new[i+1] - 1))) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static long[] sum ; static int n ; static long tot=0 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); n=sc.nextInt(); int K=sc.nextInt(); sum=new long[n+1]; for(int i=1 ; i<=n ; i++){ sum[i]=sum[i-1]+sc.nextInt()-K ; } merge(0,n); System.out.println(tot); } static void merge(int left,int right){ if(left>=right)return ; int mid=(left+right)/2 ; merge(left,mid); merge(mid+1,right); int i=left,j=mid+1,k=0 ; long[] temp=new long[right-left+1]; while(i<=mid && j<=right){ if(sum[i]<=sum[j]){ tot+=mid-i+1 ; temp[k++]=sum[j++]; } else temp[k++]=sum[i++]; } while(i<=mid)temp[k++]=sum[i++]; while(j<=right)temp[k++]=sum[j++]; for(int m=0 ; mtoInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; sum := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( sum[i+1] := sum[i - 1+1] + sc.getCurrent()->toInteger() - K ) ; i := i + 1 ) ; execute merge(0, n) ; OclFile["System.out"].println(tot) ; ); static operation merge( left : int, right : int) : void pre: true post: true activity: ( if (left >= right) then return else skip ; var mid : int ; mid := (left + right) / 2 ; execute merge(left, mid) ; execute merge(mid + 1, right) ; var i : int ; i := left ; var j : int ; j := mid + 1 ; var k : int ; k := 0 ; var temp : Sequence(long) ; temp := Integer.subrange(1,right - left + 1)->collect(0) ; while (i <= mid & j <= right) do ( if (sum[i+1] <= sum[j+1]) then ( tot := tot+(mid - i + 1) ; temp[k+1] := sum[j+1] ; k := k + 1 ; j := j + 1 ) else temp[k+1] := sum[i+1] ; k := k + 1 ; i := i + 1 ; ) ; while (i <= mid) do temp[k+1] := sum[i+1] ; k := k + 1 ; i := i + 1 ; ; while (j <= right) do temp[k+1] := sum[j+1] ; k := k + 1 ; j := j + 1 ; ; var m : int ; m := 0 ; while m < temp->size() do ( sum[left + m+1] := temp[m+1] ; ; m := m + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class kString1000 { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); String str=sc.next(); HashMaphmap=new HashMap<>(); for(int i=0 ; i0){ sb.append(ch); numberOfTimes--; } } } if(isPossible==false)System.out.println("-1"); else { String res=sb.toString(); while(k>1){ sb.append(res); k--; } System.out.println(sb.toString()); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class kString1000 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var str : String ; str := sc.getCurrent() ; var hmap : Map(String,int) ; hmap := Map{} ; var i : int ; i := 0 ; while i < str->size() do ( ( var ch : String ; ch := str->at(i+1) ; hmap := hmap->union(Map{ch |-> (if hmap->keys()->contains(ch) then hmap->at(ch) else 0 endif) + 1}) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var isPossible : boolean ; isPossible := true ; for (ch : hmap->keys()) do ( ( var freq : int ; freq := hmap->at(ch) ; if (freq mod k /= 0) then ( isPossible := false ; break ) else ( var numberOfTimes : int ; numberOfTimes := freq / k ; while (numberOfTimes > 0) do ( sb := sb + StringLib.newString(ch) ; numberOfTimes := numberOfTimes - 1 ) ) ) ) ; if (isPossible = false) then OclFile["System.out"].println("-1") else ( var res : String ; res := sb+"" ; while (k > 1) do ( sb := sb + StringLib.newString(res) ; k := k - 1 ) ; OclFile["System.out"].println(sb+"") ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class qus { public static void main(String[] args){ Scanner in=new Scanner(System.in); int k=in.nextInt(); String str=in.next(); HashMapmap=new HashMap(); for(int i=0 ; i0){ ans+=c ; count--; } } } String s=ans ; k=k-1 ; while(k>0){ ans+=s ; k--; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class qus { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := in.getCurrent()->toInteger() ; var str : String ; str := in.getCurrent() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < str->size() do ( ( map := map->union(Map{str->at(i+1) |-> (if map->keys()->contains(str->at(i+1)) then map->at(str->at(i+1)) else 0 endif) + 1}) ) ; i := i + 1 ) ; var ans : String ; ans := "" ; var count : int ; count := 0 ; for (c : map->keys()) do ( ( if (map->at(c) mod k /= 0) then ( OclFile["System.out"].println("-1") ; return ) else ( count := map->at(c) / k ; while (count > 0) do ( ans := ans+(c) ; count := count - 1 ) ) ) ) ; var s : String ; s := ans ; k := k - 1 ; while (k > 0) do ( ans := ans+(s) ; k := k - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Code { public static void main(String args[]){ Scanner r=new Scanner(System.in); String ans="" ; int n=r.nextInt(); String s=r.next(); int a[]=new int[26]; for(int i=0 ; itoInteger() ; var s : String ; s := r.getCurrent() ; var a : Sequence(int) ; a := Integer.subrange(1,26)->collect(0) ; var i : int ; i := 0 ; while i < s->size() do ( ( a[s->at(i+1) - ('a')->char2byte()+1] := a[s->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 26 do ( ( if (a[i+1] mod n /= 0) then ( OclFile["System.out"].println("-1") ; return ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 26 do ( ( var j : int ; j := 0 ; while j < a[i+1] / n do ( ans := ans + (i + 97)->oclAsType(String) ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(ans) ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int compareStrings(String str1,String str2){ int i=0 ; while(istr2.charAt(i))return-1 ; if(str1.charAt(i)last)return-1 ; int mid=(last+first)/2 ; if(arr[mid] .isEmpty()){ int left=mid-1 ; int right=mid+1 ; while(true){ if(leftlast)return-1 ; if(right<=last && ! arr[right] .isEmpty()){ mid=right ; break ; } if(left>=right && ! arr[left] .isEmpty()){ mid=left ; break ; } right++; left--; } } if(compareStrings(str,arr[mid])==0)return mid ; if(compareStrings(str,arr[mid])<0)return searchStr(arr,str,mid+1,last); return searchStr(arr,str,first,mid-1); } public static void main(String[] args){ String[] arr={ "for","","","","geeks","ide","","practice","","","quiz","","" }; String str="quiz" ; int n=arr.length ; System.out.println(searchStr(arr,str,0,n-1)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation compareStrings( str1 : String, str2 : String) : int pre: true post: true activity: ( var i : int ; i := 0 ; while (i < str1->size() - 1 & str1->at(i+1) = str2->at(i+1)) do i := i + 1 ; ; if (str1->at(i+1) > str2->at(i+1)) then return -1 else skip ; if (str1->at(i+1) < str2->at(i+1)) then return 1 else return 0 ); static operation searchStr( arr : Sequence(String), str : String, first : int, last : int) : int pre: true post: true activity: ( if (first > last) then return -1 else skip ; var mid : int ; mid := (last + first) / 2 ; if (arr[mid+1]->isEmpty()) then ( var left : int ; left := mid - 1 ; var right : int ; right := mid + 1 ; while (true) do ( if (left < right & right > last) then return -1 else skip ; if (right <= last & not(arr[right+1]->isEmpty())) then ( mid := right ; break ) else skip ; if (left >= right & not(arr[left+1]->isEmpty())) then ( mid := left ; break ) else skip ; right := right + 1 ; left := left - 1 ; ) ) else skip ; if (compareStrings(str, arr[mid+1]) = 0) then return mid else skip ; if (compareStrings(str, arr[mid+1]) < 0) then return searchStr(arr, str, mid + 1, last) else skip ; return searchStr(arr, str, first, mid - 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(String) ; arr := Sequence{"for","","","","geeks","ide","","practice","","","quiz","",""} ; var str : String ; str := "quiz" ; var n : int ; n := arr->size() ; OclFile["System.out"].println(searchStr(arr, str, 0, (n)->char2byte() - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import sun.java2d.pipe.OutlineTextRenderer ; import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.Scanner ; public class B { private static final int MAX=20000 ; private String solve(Scanner in){ int n=in.nextInt(); if(n==0){ return "0" ; } int[] a=new int[MAX]; for(int i=0 ; il+1){ int m=(l+r)/2 ; int[] aa=a.clone(); int[] b=new int[MAX+1]; for(int i=0 ; i0){ if(i>0 && b[i-1]>0){ b[i-1]--; b[i]++; aa[i]--; } else { boolean ok=true ; for(int j=i ; jcollect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[in.nextInt() - 1+1] := a[in.nextInt() - 1+1] + 1 ) ; i := i + 1 ) ; var l : int ; l := 1 ; var r : int ; r := n + 1 ; while (r > l + 1) do ( var m : int ; m := (l + r) / 2 ; var aa : Sequence(int) ; aa := a->copy() ; var b : Sequence(int) ; b := Integer.subrange(1,MAX + 1)->collect(0) ; var i : int ; i := 0 ; while i < MAX do ( ( while (aa[i+1] > 0) do ( if (i > 0 & b[i - 1+1] > 0) then ( b[i - 1+1] := b[i - 1+1] - 1 ; b[i+1] := b[i+1] + 1 ; aa[i+1] := aa[i+1] - 1 ) else ( var ok : boolean ; ok := true ; var j : int ; j := i ; while j < i + m do ( ( if (aa[j+1] = 0) then ok := false ; else skip ; aa[j+1] := aa[j+1] - 1 ) ; j := j + 1 ) ; if (not(ok)) then ( r := m ; continue ) else skip ; b[i + m - 1+1] := b[i + m - 1+1] + 1 ) ) ) ; i := i + 1 ) ; l := m ; ) ; return "" + l ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile("input.txt")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var T : int ; T := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < T do ( ( var s : String ; s := "Case #" + (i + 1) + ": " + B.newB().solve(in) ; skip ; OclFile["System.out"].println(s) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printPattern(int radius){ double dist ; for(int i=0 ; i<=2*radius ; i++){ for(int j=0 ; j<=2*radius ; j++){ dist=Math.sqrt((i-radius)*(i-radius)+(j-radius)*(j-radius)); if(dist>radius-0.5 && distsqrt() ; if (dist > radius - 0.5 & dist < radius + 0.5) then OclFile["System.out"].print("*") ; else OclFile["System.out"].print(" ") ; ) ; j := j + 1 ) ; OclFile["System.out"].print("\n") ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var radius : int ; radius := 6 ; execute printPattern(radius) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int N=sc.nextInt(); int[] p=new int[N]; for(int i=0 ; itoInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( p[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < N - 2 do ( ( if (p[i+1] < p[i + 1+1] & p[i + 1+1] < p[i + 2+1] or p[i + 2+1] < p[i + 1+1] & p[i + 1+1] < p[i+1]) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ FastReader sc=new FastReader(); int N=sc.nextInt(); int[] arr=new int[N]; for(int i=0 ; ib && b>c)return true ; if(c>b && b>a)return true ; return false ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var N : int ; N := sc.nextInt() ; var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( arr[i+1] := sc.nextInt() ) ; i := i + 1 ) ; var counter : int ; counter := 0 ; var i : int ; i := 1 ; while i < N - 1 do ( ( if (check(arr[i - 1+1], arr[i+1], arr[i + 1+1])) then counter := counter + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(counter) ; ); static operation check( a : int, b : int, c : int) : boolean pre: true post: true activity: ( if (a > b & b > c) then return true else skip ; if (c > b & b > a) then return true else skip ; return false ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { public Main(){ } public static void main(String[] args){ MapmapP=new HashMap(); Scanner sc=new Scanner(System.in); int n,p,p1,p0,p2,result ; int index ; n=sc.nextInt(); for(index=0 ; indextoInteger() ; index := 0 ; while index < n do ( ( p := sc.getCurrent()->toInteger() ; mapP := mapP->union(Map{index |-> p}) ) ; index := index + 1 ) ; skip ; result := 0 ; index := 1 ; while index < n - 1 do ( ( p0 := mapP->at(index - 1) ; p1 := mapP->at(index) ; p2 := mapP->at(index + 1) ; if ((p0 - p1) * (p2 - p1) < 0) then ( result := result + 1 ) else skip ) ; index := index + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int total=Integer.parseInt(sc.next()); Listlist=new ArrayList<>(); for(int x=1 ; x<=total ; x++){ list.add(Integer.parseInt(sc.next())); } int res=0 ; for(int x=1 ; x<=total-2 ; x++){ int first=list.get(x-1); int second=list.get(x); int third=list.get(x+1); if(firsttoInteger() ; var list : Sequence(int) ; list := Sequence{} ; var x : int ; x := 1 ; while x <= total do ( ( list := list->including((sc.getCurrent())->toInteger()) ) ; x := x + 1 ) ; var res : int ; res := 0 ; var x : int ; x := 1 ; while x <= total - 2 do ( ( var first : int ; first := list->at(x - 1+1) ; var second : int ; second := list->at(x+1) ; var third : int ; third := list->at(x + 1+1) ; if (first < second & second < third) then ( res := res + 1 ) else skip ; if (second < first & third < second) then ( res := res + 1 ) else skip ; ) ; x := x + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.util.Arrays ; import java.util.HashMap ; import java.util.Map ; import java.util.Objects ; import java.util.Scanner ; import java.util.StringJoiner ; import java.util.stream.Stream ; public class Main { public static void main(final String[] args)throws Exception { Scanner sc=new Scanner(System.in); long u=sc.nextLong(); long[] p=new long[(int)u]; for(int i=0 ; itoLong() ; var p : Sequence(long) ; p := Integer.subrange(1,u->oclAsType(int))->collect(0) ; var i : int ; i := 0 ; while i < p->size() do ( ( p[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var i : int ; i := 1 ; while i < p->size() - 1 do ( ( var tmp : Sequence(long) ; tmp := p.subrange(i - 1+1,i + 2) ; tmp := tmp->sort() ; if (tmp[1+1] = p[i+1]) then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Ehabandsubtraction { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int length=sc.nextInt(); int op=sc.nextInt(); int arr[]=new int[length+1]; arr[0]=sc.nextInt(); for(int i=1 ; i0){ System.out.println("0"); op--; } } } ------------------------------------------------------------ OCL File: --------- class Ehabandsubtraction { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var length : int ; length := sc.getCurrent()->toInteger() ; var op : int ; op := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,length + 1)->collect(0) ; arr[0+1] := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i < length do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr[length+1] := 0 ; arr := arr->sort() ; var i : int ; i := 1 ; while i <= length do ( ( if (op = 0) then ( break ) else skip ; if (arr[i+1] - arr[i - 1+1] /= 0) then ( op := op - 1 ; OclFile["System.out"].println(arr[i+1] - arr[i - 1+1]) ) else skip ) ; i := i + 1 ) ; while (op > 0) do ( OclFile["System.out"].println("0") ; op := op - 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; public class GFG { static Listfactors=new ArrayList<>(10); static void findFactors(int n){ for(int i=1 ; i*i<=n ; i++){ if(n % i==0){ if((n/i)==i){ factors.add(factors.size(),i); } else { factors.add(factors.size(),n/i); factors.add(factors.size(),i); } } } } static int findProduct(int n){ int product=-1 ; int si=factors.size(); for(int i=0 ; iproduct){ product=p ; } } } } } } return product ; } public static void main(String[] args){ int n=10 ; findFactors(n); System.out.println(findProduct(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute factors : Sequence(int) := Sequence{}; static operation findFactors( n : int) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i * i <= n do ( ( if (n mod i = 0) then ( if ((n / i) = i) then ( factors := factors.insertAt(factors->size()+1,i) ) else ( factors := factors.insertAt(factors->size()+1,n / i) ; factors := factors.insertAt(factors->size()+1,i) ) ) else skip ) ; i := i + 1 ) ); static operation findProduct( n : int) : int pre: true post: true activity: ( var product : int ; product := -1 ; var si : int ; si := factors->size() ; var i : int ; i := 0 ; while i < si do ( ( var j : int ; j := 0 ; while j < si do ( ( var k : int ; k := 0 ; while k < si do ( ( var l : int ; l := 0 ; while l < si do ( ( var s : int ; s := factors->at(i+1) + factors->at(j+1) + factors->at(k+1) + factors->at(l+1) ; if (s = n) then ( var p : int ; p := factors->at(i+1) * factors->at(j+1) * factors->at(k+1) * factors->at(l+1) ; if (p > product) then ( product := p ) else skip ) else skip ) ; l := l + 1 ) ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return product ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; execute findFactors(n) ; OclFile["System.out"].println(findProduct(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int sum=0 ; for(int i=0 ; i<5 ; i++)sum+=sc.nextInt(); if(sum % 5==0 && sum!=0)sum/=5 ; else sum=-1 ; System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Codeforces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 5 do ( sum := sum+(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; if (sum mod 5 = 0 & sum /= 0) then sum := sum/(5) else sum := -1 ; ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int a=scan.nextInt(); int b=scan.nextInt(); int ans=getNum(a,b); System.out.println(ans); } public static int getNum(int a,int b){ int reverseB=0 ; while(b>0){ reverseB=reverseB*10+b % 10 ; b/=10 ; } return a+reverseB ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := scan.getCurrent()->toInteger() ; var b : int ; b := scan.getCurrent()->toInteger() ; var ans : int ; ans := getNum(a, b) ; OclFile["System.out"].println(ans) ; ); static operation getNum( a : int, b : int) : int pre: true post: true activity: ( var reverseB : int ; reverseB := 0 ; while (b > 0) do ( reverseB := reverseB * 10 + b mod 10 ; b := b/(10) ) ; return a + reverseB ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Initialbet { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int sum=0 ; for(int i=0 ; i<5 ; i++)sum+=sc.nextInt(); System.out.println(sum % 5==0 && sum!=0 ? sum/5 :-1); } } ------------------------------------------------------------ OCL File: --------- class Initialbet { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 5 do ( sum := sum+(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; OclFile["System.out"].println(if sum mod 5 = 0 & sum /= 0 then sum / 5 else -1 endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class GreatSequence { private static Scanner s=new Scanner(System.in); private static void solve(){ int n=s.nextInt(); long x=s.nextLong(); MapcountMap=new HashMap<>(); long[] arr=new long[n]; for(int i=0 ; i0){ long temp=arr[i]*x ; if(countMap.containsKey(temp)&& countMap.get(temp)>0){ countMap.put(arr[i],countMap.get(arr[i])-1); countMap.put(temp,countMap.get(temp)-1); } } } int ans=0 ; for(Long key : countMap.keySet()){ ans+=countMap.get(key); } System.out.println(ans); } public static void main(String[] args){ int t=s.nextInt(); while(t-->0){ solve(); } } } ------------------------------------------------------------ OCL File: --------- class GreatSequence { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation solve() : void pre: true post: true activity: ( var n : int ; n := s.getCurrent()->toInteger() ; var x : long ; x := s.getCurrent()->toLong() ; var countMap : Map(long,int) ; countMap := Map{} ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toLong() ; if (countMap->keys()->includes(arr[i+1])) then ( countMap := countMap->union(Map{arr[i+1] |-> countMap->at(arr[i+1]) + 1}) ) else ( countMap := countMap->union(Map{arr[i+1] |-> 1}) ) ) ; i := i + 1 ) ; arr := arr->sort() ; var i : int ; i := 0 ; while i < n do ( ( if (countMap->keys()->includes(arr[i+1]) & countMap->at(arr[i+1]) > 0) then ( var temp : long ; temp := arr[i+1] * x ; if (countMap->keys()->includes(temp) & countMap->at(temp) > 0) then ( countMap := countMap->union(Map{arr[i+1] |-> countMap->at(arr[i+1]) - 1}) ; countMap := countMap->union(Map{temp |-> countMap->at(temp) - 1}) ) else skip ) else skip ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; for (key : countMap->keys()) do ( ( ans := ans+(countMap->at(key)) ) ) ; OclFile["System.out"].println(ans) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( execute solve() ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class InitialBet { public static void main(String[] args){ Scanner s=new Scanner(System.in); byte c1=s.nextByte(); byte c2=s.nextByte(); byte c3=s.nextByte(); byte c4=s.nextByte(); byte c5=s.nextByte(); int total=c1+c2+c3+c4+c5 ; if(total==0)System.out.println("-1"); else { double b1=total/5.0 ; int b2=total/5 ; if(b1==b2)System.out.println(b2); else System.out.println("-1"); } } } ------------------------------------------------------------ OCL File: --------- class InitialBet { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var c1 : int ; c1 := s.nextByte() ; var c2 : int ; c2 := s.nextByte() ; var c3 : int ; c3 := s.nextByte() ; var c4 : int ; c4 := s.nextByte() ; var c5 : int ; c5 := s.nextByte() ; var total : int ; total := c1 + c2 + c3 + c4 + c5 ; if (total = 0) then OclFile["System.out"].println("-1") else ( var b1 : double ; b1 := total / 5.0 ; var b2 : int ; b2 := total / 5 ; if (b1 = b2) then OclFile["System.out"].println(b2) ; else OclFile["System.out"].println("-1") ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class JavaApplication83 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int counter=0 ; for(int i=0 ; i<5 ; i++){ counter+=sc.nextInt(); } if(counter % 5==0 && counter>=5){ System.out.println(counter/5); } else { System.out.println(-1); } } } ------------------------------------------------------------ OCL File: --------- class JavaApplication83 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var counter : int ; counter := 0 ; var i : int ; i := 0 ; while i < 5 do ( ( counter := counter+(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; if (counter mod 5 = 0 & counter >= 5) then ( OclFile["System.out"].println(counter / 5) ) else ( OclFile["System.out"].println(-1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static float Area(float a){ if(a<0)return-1 ; float x=0.464f*a ; float A=0.70477f*(float)Math.pow(x,2); return A ; } public static void main(String[] args){ float a=5 ; System.out.println(String.format("%.5f",Area(a))); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Area( a : double) : double pre: true post: true activity: ( if (a < 0) then return -1 else skip ; var x : double ; x := 0.464f * a ; var A : double ; A := 0.70477f * x->pow(2)->oclAsType(double) ; return A ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 5 ; OclFile["System.out"].println(StringLib.format("%.5f",Sequence{Area(a)})) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.LinkedList ; import java.util.Queue ; import java.util.Scanner ; import java.util.Vector ; public class Domnio { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); if(isPalindrome(s)&& isReflectable(s)){ System.out.println("YES"); } else { System.out.println("NO"); } } public static boolean isPalindrome(String s){ for(int i=0 ; isize() / 2 do ( ( if (s->at(i+1) /= s->at(s->size() - 1 - (i)->char2byte()+1)) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); static operation isReflectable( s : String) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < s->size() do ( ( if ("AHIMOTUVWXY"->indexOf(s->at(i+1))-1 = -1) then ( return false ) else skip ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class StartUp { public static void main(String[] args){ Scanner x=new Scanner(System.in); String a=x.nextLine(); int m=0 ; int n=a.length()-1 ; int y=0 ; int r=0 ; int u=0 ; int j=0 ; for(int i=1 ; i<=a.length(); i++){ if(a.charAt(r)=='A' || a.charAt(r)=='H' || a.charAt(r)=='I' || a.charAt(r)=='M' || a.charAt(r)=='O' || a.charAt(r)=='T' || a.charAt(r)=='U' || a.charAt(r)=='V' || a.charAt(r)=='W' || a.charAt(r)=='X' || a.charAt(r)=='Y'){ m++; } else { break ; } r++; } if(m==a.length()){ while(y<=n){ if(a.charAt(y)==a.charAt(n))u=1 ; else { u=0 ; break ; } y++; n--; } } if(u==1)System.out.println("YES"); else if(u==0)System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class StartUp { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : OclFile ; x := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : String ; a := x.nextLine() ; var m : int ; m := 0 ; var n : int ; n := a->size() - 1 ; var y : int ; y := 0 ; var r : int ; r := 0 ; var u : int ; u := 0 ; var j : int ; j := 0 ; var i : int ; i := 1 ; while i <= a->size() do ( ( if (a->at(r+1) = 'A' or a->at(r+1) = 'H' or a->at(r+1) = 'I' or a->at(r+1) = 'M' or a->at(r+1) = 'O' or a->at(r+1) = 'T' or a->at(r+1) = 'U' or a->at(r+1) = 'V' or a->at(r+1) = 'W' or a->at(r+1) = 'X' or a->at(r+1) = 'Y') then ( m := m + 1 ) else ( break ) ; r := r + 1 ) ; i := i + 1 ) ; if (m = a->size()) then ( while (y <= n) do ( if (a->at(y+1) = a->at(n+1)) then u := 1 else ( u := 0 ; break ) ; y := y + 1 ; n := n - 1 ) ) else skip ; if (u = 1) then OclFile["System.out"].println("YES") else if (u = 0) then OclFile["System.out"].println("NO") ; else skip ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class TaskA { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String name=sc.nextLine(); int toCheck=name.length()% 2==0 ? name.length()/2 : name.length()/2+1 ; for(int i=0 ; isize() mod 2 = 0 then name->size() / 2 else name->size() / 2 + 1 endif ; var i : int ; i := 0 ; while i < toCheck do ( ( var c : String ; c := name->at(i+1) ; var m : String ; m := name->at(name->size() - 1 - i+1) ; if (c /= m or not(sym(c)) or not(sym(m))) then ( OclFile["System.out"].println("NO") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ; return ); static operation sym( c : String) : boolean pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (c) ; if _switchval = 'A' then return true else skip ; if _switchval = 'H' then return true else skip ; if _switchval = 'I' then return true else skip ; if _switchval = 'M' then return true else skip ; if _switchval = 'O' then return true else skip ; if _switchval = 'T' then return true else skip ; if _switchval = 'U' then return true else skip ; if _switchval = 'V' then return true else skip ; if _switchval = 'W' then return true else skip ; if _switchval = 'X' then return true else skip ; if _switchval = 'Y' then return true else skip ; if true then return false else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int M=scanner.nextInt(); Bottle[] bottles=new Bottle[N]; for(int i=0 ; ibottle.price)); long left=-1 ; long right=100_000_000_000_000L ; while(right-left>1){ long mid=(left+right)/2 ; long k=mid ; int n=0 ; for(int i=0 ; i=M){ right=mid ; } else { left=mid ; } } System.out.println(right); } private static class Bottle { private final int price ; private final int cap ; private Bottle(int price,int cap){ this.price=price ; this.cap=cap ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; var M : int ; M := scanner.getCurrent()->toInteger() ; var bottles : Sequence(Bottle) ; bottles := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( bottles[i+1] := Bottle.newBottle(scanner.getCurrent()->toInteger(), scanner.getCurrent()->toInteger()) ; ; i := i + 1 ) ; bottles := OclComparator.sortWith(bottles, Comparator.comparingInt(lambda bottle : OclAny in bottle.price)) ; var left : long ; left := -1 ; var right : long ; right := 100_000_000_000_000L ; while (right - left > 1) do ( var mid : long ; mid := (left + right) / 2 ; var k : long ; k := mid ; var n : int ; n := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (bottles[i+1].price->oclAsType(long) * bottles[i+1].cap < k) then ( n := n+(bottles[i+1].cap) ; k := k-(bottles[i+1].price->oclAsType(long) * bottles[i+1].cap) ) else ( n := n+(k / bottles[i+1].price) ; break ) ) ; i := i + 1 ) ; if (n >= M) then ( right := mid ) else ( left := mid ) ; ) ; OclFile["System.out"].println(right) ; ); static class Bottle { attribute price : int; attribute cap : int; static operation newBottle( price : int, cap : int) : Bottle pre: true post: true activity: ( var self : Bottle ; self := createBottle(); self.initialise(price, cap); return self ); operation initialise( price : int, cap : int) : void pre: true post: true activity: ( self.price := price ; self.cap := cap ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Map.Entry ; import java.util.Scanner ; import java.util.TreeMap ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long m=sc.nextInt(); TreeMapmap=new TreeMap<>(); for(int i=0 ; ientry : map.entrySet()){ long key=entry.getKey(); int val=entry.getValue(); if(m>=val){ ans+=key*val ; m=m-val ; } else if(mtoInteger() ; var m : long ; m := sc.getCurrent()->toInteger() ; var map : Map(long,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var key : long ; key := sc.getCurrent()->toLong() ; var val : int ; val := sc.getCurrent()->toInteger() ; if (map->keys()->includes(key)) then ( map := map->union(Map{key |-> map->at(key) + val}) ) else ( map := map->union(Map{key |-> val}) ) ) ; i := i + 1 ) ; var ans : long ; ans := 0l ; for (entry : map->asSet()) do ( ( var key : long ; key := entry.getKey() ; var val : int ; val := entry.getValue() ; if (m >= val) then ( ans := ans+(key * val) ; m := m - val ) else if (m < val) then ( ans := ans+(m * key) ; break ) else skip ; ) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Solution171A { public static void main(String[] args){ InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); Solver171A solver=new Solver171A(); solver.solve(0,in,out); out.close(); } static class Solver171A { public void solve(int testNumber,InputReader in,PrintWriter out){ long a1=in.nextInt(),a2=in.nextInt(); long res=0 ; while(a2>0){ res*=10 ; res+=(a2 % 10); a2/=10 ; } res+=a1 ; out.println(res); } public boolean check(int r,int g,int b,int w){ int odd=0 ; if(r % 2==1){ odd++; } if(g % 2==1){ odd++; } if(b % 2==1){ odd++; } if(w % 2==1){ odd++; } if(odd<=1){ return true ; } return false ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Solution171A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : InputReader ; in := InputReader.newInputReader(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var solver : Solver171A ; solver := Solver171A.newSolver171A() ; solver.solve(0, in, out) ; skip ; ); static class Solver171A { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var a1 : long ; a1 := in.nextInt() ; var a2 : long ; a2 := in.nextInt() ; var res : long ; res := 0 ; while (a2 > 0) do ( res := res*(10) ; res := res+((a2 mod 10)) ; a2 := a2/(10) ) ; res := res+(a1) ; skip ; ); operation check( r : int, g : int, b : int, w : int) : boolean pre: true post: true activity: ( var odd : int ; odd := 0 ; if (r mod 2 = 1) then ( odd := odd + 1 ) else skip ; if (g mod 2 = 1) then ( odd := odd + 1 ) else skip ; if (b mod 2 = 1) then ( odd := odd + 1 ) else skip ; if (w mod 2 = 1) then ( odd := odd + 1 ) else skip ; if (odd <= 1) then ( return true ) else skip ; return false ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long m=sc.nextLong(); long ans=0 ; long[][] ab=new long[n][2]; for(int c=0 ; cLong.compare(a[0],b[0])); long count=0 ; int c=0 ; while(count0){ ans+=ab[c][0]; ab[c][1]--; } else { ans+=ab[c+1][0]; ab[c+1][1]--; c++; } count++; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : long ; m := sc.getCurrent()->toLong() ; var ans : long ; ans := 0 ; var ab : Sequence(Sequence(long)) ; ab := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var c : int ; c := 0 ; while c < n do ( ( ab[c+1][0+1] := sc.getCurrent()->toLong() ; ab[c+1][1+1] := sc.getCurrent()->toLong() ) ; c := c + 1 ) ; ab := OclComparator.sortWith(ab, lambda (a , b) : OclAny in compare(a[0+1], b[0+1])) ; var count : long ; count := 0 ; var c : int ; c := 0 ; while (count < m) do ( if (ab[c+1][1+1] > 0) then ( ans := ans+(ab[c+1][0+1]) ; ab[c+1][1+1] := ab[c+1][1+1] - 1 ) else ( ans := ans+(ab[c + 1+1][0+1]) ; ab[c + 1+1][1+1] := ab[c + 1+1][1+1] - 1 ; c := c + 1 ) ; count := count + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); ArrayListlist=new ArrayList<>(); for(int i=0 ; i{ @ Override public int compare(KeySort sort1,KeySort sort2){ if(sort1.sort==sort2.sort){ return 0 ; } else if(sort1.sort>sort2.sort){ return 1 ; } else { return-1 ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var list : Sequence(KeySort) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var a : long ; a := sc.getCurrent()->toLong() ; var b : int ; b := sc.getCurrent()->toInteger() ; list := list->including(KeySort.newKeySort(b, a)) ) ; i := i + 1 ) ; list, KeySortComparator.newKeySortComparator() := list, KeySortComparator.newKeySortComparator()->sort() ; var money : long ; money := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (list->at(i+1).key <= m) then ( money := money+(list->at(i+1).key * list->at(i+1).sort) ; m := m-(list->at(i+1).key) ) else ( money := money+(m * list->at(i+1).sort) ; break ) ) ; i := i + 1 ) ; OclFile["System.out"].println(money) ; ); } class KeySort { attribute key : int; attribute sort : long; static operation newKeySort( key : int, sort : long) : KeySort pre: true post: true activity: ( var self : KeySort ; self := createKeySort(); self.initialise(key, sort); return self ); operation initialise( key : int, sort : long) : void pre: true post: true activity: ( self.key := key ; self.sort := sort ); } class KeySortComparator implements Function(,(,boolean)) { operation compare( sort1 : KeySort, sort2 : KeySort) : int pre: true post: true activity: ( if (sort1.sort = sort2.sort) then ( return 0 ) else if (sort1.sort > sort2.sort) then ( return 1 ) else ( return -1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Arrays ; public class Main { public static void main(String[] args){ Scanner m=new Scanner(System.in); int t ; t=m.nextInt(); while(t-->0){ int n ; int x ; n=m.nextInt(); x=m.nextInt(); long[] arr=new long[n]; for(int i=0 ; ihm=new HashMap<>(); int cnt=0 ; for(int i=n-1 ; i>-1 ; i--){ if(hm.containsKey(x*arr[i]*1l)==true){ if(hm.get(arr[i]*x*1l)==1)hm.remove(x*arr[i]*1l); else hm.put(arr[i]*x*1l,hm.get(arr[i]*x*1l)-1); cnt+=2 ; } else { if(hm.containsKey(arr[i]*1l))hm.put(arr[i]*1l,hm.get(arr[i]*1l)+1); else hm.put(arr[i]*1l,1); } } System.out.println(n-cnt); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : OclFile ; m := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := m.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; var x : int ; n := m.getCurrent()->toInteger() ; x := m.getCurrent()->toInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := m.getCurrent()->toLong() ; ; i := i + 1 ) ; arr := arr->sort() ; var hm : Map(long,int) ; hm := Map{} ; var cnt : int ; cnt := 0 ; var i : int ; i := n - 1 ; while i > -1 do ( ( if (hm->keys()->includes(x * arr[i+1] * 1l) = true) then ( if (hm->at(arr[i+1] * x * 1l) = 1) then hm := hm->antirestrict(Set{x * arr[i+1] * 1l}) else hm := hm->union(Map{arr[i+1] * x * 1l |-> hm->at(arr[i+1] * x * 1l) - 1}) ; ; cnt := cnt+(2) ) else ( if (hm->keys()->includes(arr[i+1] * 1l)) then hm := hm->union(Map{arr[i+1] * 1l |-> hm->at(arr[i+1] * 1l) + 1}) ; else hm := hm->union(Map{arr[i+1] * 1l |-> 1}) ; ) ) ; i := i - 1 ) ; OclFile["System.out"].println(n - cnt) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int m=Integer.parseInt(sc.next()); int[][] ab=new int[n][2]; for(int i=0 ; i(){ @ Override public int compare(int[] o1,int[] o2){ return o1[0]-o2[0]; } } ); int remain=m ; long res=0 ; int count=0 ; for(int i=0 ; itoInteger() ; var m : int ; m := (sc.getCurrent())->toInteger() ; var ab : Sequence(Sequence(int)) ; ab := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( ab[i+1][0+1] := (sc.getCurrent())->toInteger() ; ab[i+1][1+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; ab := OclComparator.sortWith(ab, OclComparator.newOclComparator()) ; var remain : int ; remain := m ; var res : long ; res := 0 ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (remain = 0) then break else skip ; count := Set{remain, ab[i+1][1+1]}->min() ; res := res+(count->oclAsType(long) * ab[i+1][0+1]) ; remain := remain-(count) ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class BinaryTree { Node root ; static class Node { int val ; Node left,right ; Node(int v){ val=v ; left=null ; right=null ; } } BinaryTree(Node r){ root=r ; } BinaryTree(){ } public boolean isSymmetric(Node root){ Queueq=new LinkedList(); q.add(root.left); q.add(root.right); while(! q.isEmpty()){ Node tempLeft=q.remove(); Node tempRight=q.remove(); if(tempLeft==null && tempRight==null)continue ; if((tempLeft==null && tempRight!=null)||(tempLeft!=null && tempRight==null))return false ; if(tempLeft.val!=tempRight.val)return 0 ; q.add(tempLeft.left); q.add(tempRight.right); q.add(tempLeft.right); q.add(tempRight.left); } return true ; } public static void main(String[] args){ Node n=new Node(1); BinaryTree bt=new BinaryTree(n); bt.root.left=new Node(2); bt.root.right=new Node(2); bt.root.left.left=new Node(3); bt.root.left.right=new Node(4); bt.root.right.left=new Node(4); bt.root.right.right=new Node(3); if(bt.isSymmetric(bt.root))System.out.println("The given tree is Symmetric"); else System.out.println("The given tree is not Symmetric"); } } ------------------------------------------------------------ OCL File: --------- class BinaryTree { attribute root : Node; static class Node { attribute val : int; attribute left : Node; static operation newNode( v : int) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(v); return self ); operation initialise( v : int) : void pre: true post: true activity: ( val := v ; left := null ; right := null ); } static operation newBinaryTree( r : Node) : BinaryTree pre: true post: true activity: ( var self : BinaryTree ; self := createBinaryTree(); self.initialise(r); return self ); operation initialise( r : Node) : void pre: true post: true activity: ( root := r ); static operation newBinaryTree() : BinaryTree pre: true post: true activity: ( var self : BinaryTree ; self := createBinaryTree(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: skip; operation isSymmetric( root : Node) : boolean pre: true post: true activity: ( var q : Sequence(Node) ; q := Sequence{} ; q := q->including(root.left) ; q := q->including(root.right) ; while (not(q->isEmpty())) do ( var tempLeft : Node ; tempLeft := q.remove() ; var tempRight : Node ; tempRight := q.remove() ; if (tempLeft = null & tempRight = null) then continue else skip ; if ((tempLeft = null & tempRight /= null) or (tempLeft /= null & tempRight = null)) then return false else skip ; if (tempLeft.val /= tempRight.val) then return 0 else skip ; q := q->including(tempLeft.left) ; q := q->including(tempRight.right) ; q := q->including(tempLeft.right) ; q := q->including(tempRight.left) ; ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : Node ; n := Node.newNode(1) ; var bt : BinaryTree ; bt := BinaryTree.newBinaryTree(n) ; bt.root.left := Node.newNode(2) ; bt.root.right := Node.newNode(2) ; bt.root.left.left := Node.newNode(3) ; bt.root.left.right := Node.newNode(4) ; bt.root.right.left := Node.newNode(4) ; bt.root.right.right := Node.newNode(3) ; if (bt.isSymmetric(bt.root)) then OclFile["System.out"].println("The given tree is Symmetric") else OclFile["System.out"].println("The given tree is not Symmetric") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Similar_strings { static int countManipulations(String s1,String s2){ int count=0 ; int char_count[]=new int[26]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < s1->size() do ( char_count[s1->at(i+1) - ('a')->char2byte()+1] := char_count[s1->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s2->size() do ( if (char_count[s2->at(i+1) - ('a')->char2byte()+1] <= 0) then count := count + 1 ; else skip ; ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s1 : String ; s1 := "ddcf" ; var s2 : String ; s2 := "cedk" ; OclFile["System.out"].println(countManipulations(s1, s2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var x : int ; x := scanner.getCurrent()->toInteger() ; var y : int ; y := scanner.getCurrent()->toInteger() ; if (x = 0 & y = 0) then ( OclFile["System.out"].println(0) ) else if (x = 0 or y = 0) then ( OclFile["System.out"].println(1) ) else ( var temp : int ; temp := (x * x + y * y)->sqrt()->oclAsType(int) ; if (temp * temp = x * x + y * y) then ( OclFile["System.out"].println(1) ) else ( OclFile["System.out"].println(2) ) ) ; ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ double x=sc.nextDouble(); double y=sc.nextDouble(); if((int)x==0 &&(int)y==0){ System.out.println(0); continue ; } double sqrt=Math.sqrt(Math.pow(x,2)+Math.pow(y,2)); if(sqrt==(int)sqrt)System.out.println(1); else System.out.println(2); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : double ; x := sc.getCurrent()->toReal() ; var y : double ; y := sc.getCurrent()->toReal() ; if (x->oclAsType(int) = 0 & y->oclAsType(int) = 0) then ( OclFile["System.out"].println(0) ; continue ) else skip ; var sqrt : double ; sqrt := (x->pow(2) + y->pow(2))->sqrt() ; if (sqrt = sqrt->oclAsType(int)) then OclFile["System.out"].println(1) else OclFile["System.out"].println(2) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ double x=sc.nextDouble(); double y=sc.nextDouble(); if((int)x==0 &&(int)y==0){ System.out.println(0); continue ; } double sqrt=Math.sqrt(Math.pow(x,2)+Math.pow(y,2)); if(sqrt==(int)sqrt)System.out.println(1); else System.out.println(2); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : double ; x := sc.getCurrent()->toReal() ; var y : double ; y := sc.getCurrent()->toReal() ; if (x->oclAsType(int) = 0 & y->oclAsType(int) = 0) then ( OclFile["System.out"].println(0) ; continue ) else skip ; var sqrt : double ; sqrt := (x->pow(2) + y->pow(2))->sqrt() ; if (sqrt = sqrt->oclAsType(int)) then OclFile["System.out"].println(1) else OclFile["System.out"].println(2) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; import static java.lang.Double.parseDouble ; import static java.lang.Integer.parseInt ; import static java.lang.Long.parseLong ; public class Main { static BufferedWriter of=null ; static { try { of=new BufferedWriter(new FileWriter(new File("filee.txt"))); } catch(IOException e){ e.printStackTrace(); } } private static BufferedWriter ifile=null ; static { try { ifile=new BufferedWriter(new FileWriter(String.valueOf(System.in))); } catch(IOException e){ e.printStackTrace(); } } private static final BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out)); private static final Fast in=new Fast(); public static void main(String[] args)throws IOException { int n=in.nextInt(); while(n>0){ int m1=in.nextInt(); int m2=in.nextInt(); if(m1==0 && m2==0)System.out.println("0"); else if(Math.sqrt((m1*m1)+(m2*m2))-(int)Math.sqrt((m1*m1)+(m2*m2))==0)System.out.println("1"); else System.out.println("2"); n--; } } public static class Fast { BufferedReader br ; StringTokenizer st ; public Fast(){ br=new BufferedReader(new InputStreamReader(System.in)); } public Fast(FileReader f){ br=new BufferedReader(f); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws IOException { return parseInt(next()); } public long nextLong()throws IOException { return parseLong(next()); } public double nextDouble()throws IOException { return parseDouble(next()); } public float nextFloat()throws IOException { return Float.parseFloat(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute of : OclFile := null; static operation initialiseClass() pre: true post: true activity: try ( of := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile("filee.txt"))) ) catch (e : IOException) do ( e.printStackTrace() ) ; static attribute ifile : OclFile := null; static operation initialiseClass() pre: true post: true activity: try ( ifile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(((OclFile["System.in"]) + ""))) ) catch (e : IOException) do ( e.printStackTrace() ) ; static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static attribute in : Fast := Fast.newFast(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; while (n > 0) do ( var m1 : int ; m1 := in.nextInt() ; var m2 : int ; m2 := in.nextInt() ; if (m1 = 0 & m2 = 0) then OclFile["System.out"].println("0") else if (((m1 * m1) + (m2 * m2))->sqrt() - ((m1 * m1) + (m2 * m2))->sqrt()->oclAsType(int) = 0) then OclFile["System.out"].println("1") else OclFile["System.out"].println("2") ; ; ; n := n - 1 ) ); static class Fast { attribute br : OclFile; attribute st : OclIterator; static operation newFast() : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); static operation newFast( f : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(f); return self ); operation initialise( f : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(f) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next() + "")->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return parseLong(next()) ); operation nextDouble() : double pre: true post: true activity: ( return parseDouble(next()) ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findNumberOfEvenCells(int n,int q[][],int size){ int row[]=new int[n]; int col[]=new int[n]; for(int i=0 ; icollect(0) ; var col : Sequence(int) ; col := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < size do ( ( var x : int ; x := q[i+1][0+1] ; var y : int ; y := q[i+1][1+1] ; row[x - 1+1] := row[x - 1+1] + 1 ; col[y - 1+1] := col[y - 1+1] + 1 ) ; i := i + 1 ) ; var r1 : int ; r1 := 0 ; var r2 : int ; r2 := 0 ; var c1 : int ; c1 := 0 ; var c2 : int ; c2 := 0 ; var i : int ; i := 0 ; while i < n 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 ) ; i := i + 1 ) ; var count : int ; count := r1 * c1 + r2 * c2 ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; var q : Sequence(Sequence(int)) ; q := Sequence{Sequence{1,1},Sequence{1,2},Sequence{2,1}} ; var size : int ; size := q->size() ; OclFile["System.out"].println(findNumberOfEvenCells(n, q, size)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findLength(int[] arr,int n){ int x=0 ; for(int i=0 ; i=n)break ; } ans=Math.max(ans,j-i); } return ans ; } public static void main(String[] args){ int arr[]={ 1,2,2 }; int n=arr.length ; System.out.println(findLength(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findLength( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var x : int ; x := 0 ; var i : int ; i := 0 ; while i < n do ( x := Set{x, arr[i+1]}->max() ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] /= x) then continue else skip ; var j : int ; j := i ; while (arr[j+1] = x) do ( j := j + 1 ; if (j >= n) then break else skip ) ; ans := Set{ans, j - i}->max() ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,2} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findLength(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { static int arr[]=new int[] { 1,2,2,4 }; static int countIncreasing(int n){ int cnt=0 ; for(int i=0 ; iarr[j-1])cnt++; else break ; } } return cnt ; } public static void main(String[] args){ System.out.println("Count of strictly increasing subarrays is "+countIncreasing(arr.length)); } } ------------------------------------------------------------ OCL File: --------- class Test { static attribute arr : int := Sequence{1,2,2,4}; static operation countIncreasing( n : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (arr[j+1] > arr[j - 1+1]) then cnt := cnt + 1 ; else break ) ; j := j + 1 ) ) ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println("Count of strictly increasing subarrays is " + countIncreasing(arr->size())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static class Node { int data ; Node next ; }; static Node head ; static void push(Node head_ref,int new_data){ Node new_node=new Node(); new_node.data=new_data ; new_node.next=head_ref ; head_ref=new_node ; head=head_ref ; } static void uniqueElements(Node head){ HashMaphash=new HashMap(); for(Node temp=head ; temp!=null ; temp=temp.next){ if(hash.containsKey(temp.data)){ hash.put(temp.data,hash.get(temp.data)+1); } else { hash.put(temp.data,1); } } int count=0 ; for(Node temp=head ; temp!=null ; temp=temp.next){ if(hash.get(temp.data)==1){ System.out.print(temp.data+" "); count++; } } if(count==0)System.out.print(" No Unique Elements "); } public static void main(String[] args){ head=null ; push(head,5); push(head,4); push(head,3); push(head,5); push(head,3); push(head,2); push(head,4); push(head,4); push(head,1); uniqueElements(head); } } ------------------------------------------------------------ OCL File: --------- class GFG { static class Node { attribute data : int; attribute next : Node; } static attribute head : Node; static operation push( head_ref : Node, new_data : int) : void pre: true post: true activity: ( var new_node : Node ; new_node := Node.newNode() ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; head := head_ref ; ); static operation uniqueElements( head : Node) : void pre: true post: true activity: ( var hash : Map(int,int) ; hash := Map{} ; var temp : Node ; temp := head ; while temp /= null do ( ( if (hash->keys()->includes(temp.data)) then ( hash := hash->union(Map{temp.data |-> hash->at(temp.data) + 1}) ) else ( hash := hash->union(Map{temp.data |-> 1}) ) ) ; temp := temp.next ) ; var count : int ; count := 0 ; var temp : Node ; temp := head ; while temp /= null do ( ( if (hash->at(temp.data) = 1) then ( OclFile["System.out"].print(temp.data + " ") ; count := count + 1 ) else skip ) ; temp := temp.next ) ; if (count = 0) then OclFile["System.out"].print(" No Unique Elements ") ; else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( head := null ; execute push(head, 5) ; execute push(head, 4) ; execute push(head, 3) ; execute push(head, 5) ; execute push(head, 3) ; execute push(head, 2) ; execute push(head, 4) ; execute push(head, 4) ; execute push(head, 1) ; execute uniqueElements(head) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static int min=0 ; public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; iarr=new ArrayList(); HashMapfreq=new HashMap(); for(int j=0 ; jtoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : long ; n := sc.getCurrent()->toLong() ; var x : long ; x := sc.getCurrent()->toLong() ; var arr : Sequence(long) ; arr := Sequence{} ; var freq : Map(long,long) ; freq := Map{} ; var j : int ; j := 0 ; while j < n do ( ( var s : long ; s := sc.getCurrent()->toLong() ; arr := arr->including(s) ; if (freq->keys()->includes(s)) then ( freq := freq->union(Map{s |-> freq->at(s) + 1}) ) else ( freq := freq->union(Map{s |-> 1L}) ) ) ; j := j + 1 ) ; arr := arr->sort() ; var k : int ; k := 0 ; while k < arr->size() do ( ( if (freq->at(arr->at(k+1)) = 0) then ( continue ) else skip ; var multi : long ; multi := arr->at(k+1) * x ; if (freq->keys()->includes(multi)) then ( if (freq->at(multi) = 0) then ( freq := freq->union(Map{arr->at(k+1) |-> freq->at(arr->at(k+1)) - 1}) ; min := min + 1 ; continue ) else ( freq := freq->union(Map{arr->at(k+1) |-> freq->at(arr->at(k+1)) - 1}) ; freq := freq->union(Map{multi |-> freq->at(multi) - 1}) ) ) else ( freq := freq->union(Map{arr->at(k+1) |-> freq->at(arr->at(k+1)) - 1}) ; min := min + 1 ; continue ) ) ; k := k + 1 ) ; OclFile["System.out"].println(min) ; min := 0 ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String n=sc.next(); if(n.contains("9")){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : String ; n := sc.getCurrent() ; if (n->includes("9")) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.InputMismatchException ; import java.io.IOException ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; FastScanner in=new FastScanner(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,FastScanner in,PrintWriter out){ int n=in.nextInt(); out.println(n>=90 || n % 10==9 ? "Yes" : "No"); } } static class FastScanner { private InputStream in ; private byte[] buffer=new byte[1024]; private int bufPointer ; private int bufLength ; public FastScanner(InputStream in){ this.in=in ; } private int readByte(){ if(bufPointer>=bufLength){ if(bufLength==-1)throw new InputMismatchException(); bufPointer=0 ; try { bufLength=in.read(buffer); } catch(IOException e){ throw new InputMismatchException(); } if(bufLength<=0)return-1 ; } return buffer[bufPointer++]; } private static boolean isSpaceChar(int c){ return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1 ; } public long nextLong(){ long n=0 ; int b=readByte(); while(isSpaceChar(b))b=readByte(); boolean minus=(b=='-'); if(minus)b=readByte(); while(b>='0' && b<='9'){ n*=10 ; n+=b-'0' ; b=readByte(); } if(! isSpaceChar(b))throw new NumberFormatException(); return minus ?-n : n ; } public int nextInt(){ long n=nextLong(); if(nInteger.MAX_VALUE)throw new NumberFormatException(); return(int)n ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : FastScanner ; in := FastScanner.newFastScanner(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskA ; solver := TaskA.newTaskA() ; solver.solve(1, in, out) ; skip ; ); static class TaskA { operation solve( testNumber : int, in : FastScanner, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; skip ); } static class FastScanner { attribute in : OclFile; attribute buffer : Sequence(int) := Integer.subrange(1,1024)->collect(0); attribute bufPointer : int; attribute bufLength : int; static operation newFastScanner( in : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( self.in := in ); operation readByte() : int pre: true post: true activity: ( if (bufPointer >= bufLength) then ( if (bufLength = -1) then error IncorrectElementException() ; else skip ; bufPointer := 0 ; try ( bufLength := in.read(buffer) ) catch (e : IOException) do ( error IncorrectElementException() ) if (bufLength <= 0) then return -1 else skip ) else skip ; return buffer[bufPointer+1] ); static operation isSpaceChar( c : int) : boolean pre: true post: true activity: ( return c = ' ' or c = ' ' or c = '\r' or c = '\t' or c = -1 ); operation nextLong() : long pre: true post: true activity: ( var n : long ; n := 0 ; var b : int ; b := readByte() ; while (isSpaceChar(b)) do b := readByte() ; ; var minus : boolean ; minus := (b = '-') ; if (minus) then b := readByte() ; else skip ; while (b >= '0' & b <= '9') do ( n := n*(10) ; n := n+(b - ('0')->char2byte()) ; b := readByte() ) ; if (not(isSpaceChar(b))) then error IncorrectElementException() ; else skip ; return if minus then -n else n endif ); operation nextInt() : int pre: true post: true activity: ( var n : long ; n := nextLong() ; if (n < -2147483648 or n > 2147483647) then error IncorrectElementException() ; else skip ; return n->oclAsType(int) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.IOException ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); System.out.println((N % 10==9 || N/10==9)? "Yes" : "No"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(if (N mod 10 = 9 or N / 10 = 9) then "Yes" else "No" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { InputReader in=new InputReader(); PrintWriter out=new PrintWriter(System.out); int test_cases=1 ; Solver s=new Solver(); for(int i=1 ; i<=test_cases ; i++){ s.solve(i,in,out); } out.close(); } } class Solver { void solve(int test_number,InputReader in,PrintWriter out)throws IOException { int n=in.nextInt(); out.println((n/10==9 || n % 10==9)? "Yes" : "No"); } } class InputReader { BufferedReader br ; StringTokenizer st ; public InputReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : InputReader ; in := InputReader.newInputReader() ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var test_cases : int ; test_cases := 1 ; var s : Solver ; s := Solver.newSolver() ; var i : int ; i := 1 ; while i <= test_cases do ( ( s.solve(i, in, out) ) ; i := i + 1 ) ; skip ; ); } class Solver { operation solve( test_number : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; skip ); } class InputReader { attribute br : OclFile; attribute st : OclIterator; static operation newInputReader() : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ String in=br.readLine(); String chr[]=in.split(""); System.out.println(chr[0] .equals("9")|| chr[1] .equals("9")? "Yes" : "No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var in : String ; in := br.readLine() ; var chr : Sequence(String) ; chr := in->split("") ; OclFile["System.out"].println(if chr[0+1] = "9" or chr[1+1] = "9" then "Yes" else "No" endif) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String longDivision(String number,int divisor){ String ans="" ; int idx=0 ; char[] num=number.toCharArray(); int temp=num[idx]-'0' ; while(tempidx){ ans+=(temp/divisor); temp=(temp % divisor)*10+num[idx++]-'0' ; } if(ans.length()==0)return "0" ; return ans ; } public static void main(String[] args){ String number="1248163264128256512" ; int divisor=125 ; System.out.println(longDivision(number,divisor)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation longDivision( number : String, divisor : int) : String pre: true post: true activity: ( var ans : String ; ans := "" ; var idx : int ; idx := 0 ; var num : Sequence(String) ; num := number->characters() ; var temp : int ; temp := num[idx+1] - ('0')->char2byte() ; while (temp < divisor) do idx := idx + 1 ; temp := temp * 10 + (num[idx+1] - ('0')->char2byte()) ; ; idx := idx+(1) ; while (num->size() > idx) do ( ans := ans+((temp / divisor)) ; temp := (temp mod divisor) * 10 + num[idx+1] - ('0')->char2byte() ; idx := idx + 1 ) ; if (ans->size() = 0) then return "0" else skip ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var number : String ; number := "1248163264128256512" ; var divisor : int ; divisor := 125 ; OclFile["System.out"].println(longDivision(number, divisor)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader sc=new FastReader(); int n=sc.nextInt(); int m=sc.nextInt(); int t=reverse(m); System.out.println(t+n); } public static int reverse(int n){ if(n<10)return n*10 ; int t=n,r=0 ; while(t>0){ r=(r*10)+t % 10 ; t=t/10 ; } return r ; } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var n : int ; n := sc.nextInt() ; var m : int ; m := sc.nextInt() ; var t : int ; t := reverse(m) ; OclFile["System.out"].println(t + n) ; ); static operation reverse( n : int) : int pre: true post: true activity: ( if (n < 10) then return n * 10 else skip ; var t : int ; t := n ; var r : int ; r := 0 ; while (t > 0) do ( r := (r * 10) + t mod 10 ; t := t / 10 ) ; return r ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float rhombusarea(float l,float b){ if(l<0 || b<0)return-1 ; return(l*b)/2 ; } public static void main(String[] args){ float l=16,b=6 ; System.out.println(rhombusarea(l,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation rhombusarea( l : double, b : double) : double pre: true post: true activity: ( if (l < 0 or b < 0) then return -1 else skip ; return (l * b) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : double ; l := 16 ; var b : double ; b := 6 ; OclFile["System.out"].println(rhombusarea(l, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class Array_Stabilization { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Listl=new ArrayList<>(); for(int i=0 ; itoInteger() ; var l : Sequence(int) ; l := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( l := l->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; l := l->sort() ; var min : int ; min := .min(l) ; OclFile["System.out"].println(Set{l->at(n - 2+1) - min, l->at(n - 1+1) - l->at(1+1)}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B1095 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); long n=scanner.nextLong(); Setset=new HashSet<>(); ArrayListlist=new ArrayList<>(); while(n-->0){ long a=scanner.nextLong(); list.add(a); } Collections.sort(list); System.out.println(Math.min((list.get(list.size()-1)-list.get(1)),(list.get(list.size()-2)-list.get(0)))); } } ------------------------------------------------------------ OCL File: --------- class B1095 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := scanner.getCurrent()->toLong() ; var set : Set(long) ; set := Set{} ; var list : Sequence(long) ; list := Sequence{} ; while (n > 0) do ( n := n - 1 ; skip ; ( var a : long ; a := scanner.getCurrent()->toLong() ; list := list->including(a) ) ; ) ; list := list->sort() ; OclFile["System.out"].println(Set{(list->at(list->size() - 1+1) - list->at(1+1)), (list->at(list->size() - 2+1) - list->at(0+1))}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public final class Solution { public static void main(String[] args)throws IOException { BufferedReader bi=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(bi.readLine()); String s[]=bi.readLine().split(" "); Integer a[]=new Integer[n]; for(int i=0 ; itoInteger() ; var s : Sequence(String) ; s := bi.readLine()->split(" ") ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (s[i+1])->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; OclFile["System.out"].println(Set{a[n - 1+1] - a[1+1], a[n - 2+1] - a[0+1]}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countZeros(int x){ int y ; int 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 ; } public static void main(String[] args){ int x=101 ; System.out.println(countZeros(x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countZeros( x : int) : int pre: true post: true activity: ( var y : int ; var n : int ; n := 32 ; y := (x/(2->pow(16)))->oclAsType(long) ; if (y /= 0) then ( n := n - 16 ; x := y ) else skip ; y := (x/(2->pow(8)))->oclAsType(long) ; if (y /= 0) then ( n := n - 8 ; x := y ) else skip ; y := (x/(2->pow(4)))->oclAsType(long) ; if (y /= 0) then ( n := n - 4 ; x := y ) else skip ; y := (x/(2->pow(2)))->oclAsType(long) ; if (y /= 0) then ( n := n - 2 ; x := y ) else skip ; y := (x/(2->pow(1)))->oclAsType(long) ; if (y /= 0) then return n - 2 else skip ; return n - x ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 101 ; OclFile["System.out"].println(countZeros(x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class vanyaAdCubes23 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int sum=0 ; int ht=0 ; int i=1 ; while(n!=0){ sum+=i ; n-=sum ; if(n<0){ break ; } i++; ht++; } System.out.println(ht); } } ------------------------------------------------------------ OCL File: --------- class vanyaAdCubes23 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var ht : int ; ht := 0 ; var i : int ; i := 1 ; while (n /= 0) do ( sum := sum+(i) ; n := n-(sum) ; if (n < 0) then ( break ) else skip ; i := i + 1 ; ht := ht + 1 ; ) ; OclFile["System.out"].println(ht) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { public static boolean possible(int n){ if(n>3){ int sum=(n*(n+1))/2 ; if(sum % 3==0){ return true ; } } return false ; } public static void main(String[] args){ int n=5 ; if(possible(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation possible( n : int) : boolean pre: true post: true activity: ( if (n > 3) then ( var sum : int ; sum := (n * (n + 1)) / 2 ; if (sum mod 3 = 0) then ( return true ) else skip ) else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; if (possible(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class lll { public static void main(String[] args){ FastScanner fastScanner=new FastScanner(); int n=fastScanner.nextInt(); ArrayListar=new ArrayList<>(); while(n-->0){ ar.add(fastScanner.nextInt()); } if(n==2)System.out.println(0); else { ar.sort(Collections.reverseOrder()); if(ar.get(1)-ar.get(ar.size()-1)>ar.get(0)-ar.get(ar.size()-2))System.out.println(ar.get(0)-ar.get(ar.size()-2)); else System.out.println(ar.get(1)-ar.get(ar.size()-1)); } } } class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner(String s){ try { br=new BufferedReader(new FileReader(s)); } catch(FileNotFoundException e){ e.printStackTrace(); } } public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String nextToken(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } int nextInt(){ return Integer.parseInt(nextToken()); } long nextLong(){ return Long.parseLong(nextToken()); } double nextDouble(){ return Double.parseDouble(nextToken()); } } ------------------------------------------------------------ OCL File: --------- class lll { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fastScanner : FastScanner ; fastScanner := FastScanner.newFastScanner() ; var n : int ; n := fastScanner.nextInt() ; var ar : Sequence(int) ; ar := Sequence{} ; while (n > 0) do ( n := n - 1 ; skip ; ( ar := ar->including(fastScanner.nextInt()) ) ; ) ; if (n = 2) then OclFile["System.out"].println(0) else ( ar := ar.sort(reverseOrder()) ; if (ar->at(1+1) - ar->at(ar->size() - 1+1) > ar->at(0+1) - ar->at(ar->size() - 2+1)) then OclFile["System.out"].println(ar->at(0+1) - ar->at(ar->size() - 2+1)) ; else OclFile["System.out"].println(ar->at(1+1) - ar->at(ar->size() - 1+1)) ; ) ; ); } class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner( s : String) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(s); return self ); operation initialise( s : String) : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ) catch (e : FileNotFoundException) do ( e.printStackTrace() ) ); static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); int C=sc.nextInt(); int[] B=new int[M]; int[][] A=new int[N][M]; for(int i=0 ; i0){ count++; } } System.out.print(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var C : int ; C := sc.getCurrent()->toInteger() ; var B : Sequence(int) ; B := Integer.subrange(1,M)->collect(0) ; var A : Sequence(Sequence(int)) ; A := Integer.subrange(1,N)->collect(Integer.subrange(1,M)->collect(0)) ; var i : int ; i := 0 ; while i < M do ( ( B[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( A[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N do ( ( var wa : int ; wa := C ; var j : int ; j := 0 ; while j < M do ( ( wa := wa+(B[j+1] * A[i+1][j+1]) ) ; j := j + 1 ) ; if (wa > 0) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { private static void solve(){ int n=ni(); int m=ni(); int c=ni(); int b[]=na(m); int result=0 ; for(int i=0 ; i0 ? 1 : 0 ; } System.out.println(result); } private static Scanner scanner=new Scanner(System.in); public static void main(String[] args){ String debugDataPath=System.getenv("DD_PATH"); if(debugDataPath!=null){ try { scanner=new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))))); } catch(Exception e){ throw new RuntimeException(e); } } solve(); } private static StringTokenizer tokenizer=null ; public static String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(scanner.nextLine()); } catch(Exception e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } private static int ni(){ return Integer.parseInt(next()); } private static long nl(){ return Long.parseLong(next()); } private static double nd(){ return Double.parseDouble(next()); } private static int[] na(int n){ int[] a=new int[n]; for(int i=0 ; i 0 then 1 else 0 endif) ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); static attribute scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var debugDataPath : String ; debugDataPath := OclProcess.getEnvironmentProperty("DD_PATH") ; if (debugDataPath /= null) then ( try ( scanner := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile(debugDataPath))))) ) catch (e : ProgramException) do ( error ProgramException(e) ) ) else skip ; execute solve() ); static attribute tokenizer : OclIterator := null; static operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(scanner.nextLine()) ) catch (e : ProgramException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); static operation ni() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nl() : long pre: true post: true activity: ( return (next())->toLong() ); static operation nd() : double pre: true post: true activity: ( return (next())->toReal() ); static operation na( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := ni() ; ; i := i + 1 ) ; return a ); static operation ns() : Sequence(String) pre: true post: true activity: ( return next()->characters() ); static operation nal( n : int) : Sequence(long) pre: true post: true activity: ( var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nl() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Double.parseDouble ; import static java.lang.Integer.parseInt ; import static java.lang.Long.parseLong ; import static java.lang.System.exit ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class A { static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; static void solve()throws Exception { long a=nextLong(); long b=parseLong(new StringBuilder(next()).reverse().toString()); out.println(a+b); } static int nextInt()throws IOException { return parseInt(next()); } static long nextLong()throws IOException { return parseLong(next()); } static double nextDouble()throws IOException { return parseDouble(next()); } static String next()throws IOException { while(tok==null || ! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } public static void main(String[] args){ try { in=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(new OutputStreamWriter(System.out)); solve(); in.close(); out.close(); } catch(Throwable e){ e.printStackTrace(); exit(1); } } } ------------------------------------------------------------ OCL File: --------- class A { static attribute in : OclFile; static attribute out : OclFile; static attribute tok : OclIterator; static operation solve() : void pre: true post: true activity: ( var a : long ; a := nextLong() ; var b : long ; b := parseLong(StringLib.newString(next())->reverse()+"") ; skip ); static operation nextInt() : int pre: true post: true activity: ( return (next() + "")->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return parseLong(next()) ); static operation nextDouble() : double pre: true post: true activity: ( return parseDouble(next()) ); static operation next() : String pre: true post: true activity: ( while (tok = null or not(tok.hasNext())) do ( tok := OclIterator.newOclIterator_String(in.readLine()) ) ; return tok.next() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; execute solve() ; skip ; skip ; ) catch (e : OclException) do ( e.printStackTrace() ; execute exit(1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { void solve(){ int N=in.nextInt(),M=in.nextInt(),C=in.nextInt(); int[] B=new int[M]; for(int i=0 ; i0)ans++; } out.println(ans); } public static void main(String[] args){ in=new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out=new PrintWriter(System.out); new Main().solve(); out.close(); } static FastScanner in ; static PrintWriter out ; static class FastScanner { BufferedReader in ; StringTokenizer st ; public FastScanner(BufferedReader in){ this.in=in ; } public String nextToken(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(in.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public int nextInt(){ return Integer.parseInt(nextToken()); } public long nextLong(){ return Long.parseLong(nextToken()); } public double nextDouble(){ return Double.parseDouble(nextToken()); } } } ------------------------------------------------------------ OCL File: --------- class Main { operation solve() : void pre: true post: true activity: ( var N : int ; N := in.nextInt() ; var M : int ; M := in.nextInt() ; var C : int ; C := in.nextInt() ; var B : Sequence(int) ; B := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( B[i+1] := in.nextInt() ; ; i := i + 1 ) ; var A : Sequence(Sequence(int)) ; A := Integer.subrange(1,N)->collect(Integer.subrange(1,M)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( A[i+1][j+1] := in.nextInt() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < N do ( ( var sum : int ; sum := C ; var j : int ; j := 0 ; while j < M do ( ( sum := sum+(A[i+1][j+1] * B[j+1]) ) ; j := j + 1 ) ; if (sum > 0) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; out.println(ans) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( in := FastScanner.newFastScanner(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; Main.newMain().solve() ; out.close() ); static attribute in : FastScanner; static attribute out : OclFile; static class FastScanner { attribute in : OclFile; attribute st : OclIterator; static operation newFastScanner( in : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( self.in := in ); operation nextToken() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(in.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (nextToken())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (nextToken())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (nextToken())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedOutputStream ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static PrintWriter out ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); out=new PrintWriter(new BufferedOutputStream(System.out)); int n=Integer.parseInt(sc.next()); int m=Integer.parseInt(sc.next()); int c=Integer.parseInt(sc.next()); ArrayListb_list=new ArrayList<>(); for(int i=0 ; i0){ ans++; } } out.println(ans); sc.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute out : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var m : int ; m := (sc.getCurrent())->toInteger() ; var c : int ; c := (sc.getCurrent())->toInteger() ; var b_list : Sequence(int) ; b_list := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( b_list := b_list->including((sc.getCurrent())->toInteger()) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var sum : int ; sum := 0 ; var j : int ; j := 0 ; var a : int ; a := 0 ; while j < m do ( ( a := (sc.getCurrent())->toInteger() ; sum := sum+(a * b_list->at(j+1)) ) ; j := j + 1 ) ; sum := sum+(c) ; if (sum > 0) then ( ans := ans + 1 ) else skip ) ; i := i + 1 ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.PriorityQueue ; import java.util.Queue ; public class Main { private static int LINE_NUMBER=0 ; private static int CODE_NUMBER=0 ; private static int BIAS=0 ; private static int solver(int[] coe,int[] src){ int sum=BIAS ; for(int i=0 ; i0){ return 1 ; } else { return 0 ; } } public static void main(String[] args){ InputStreamReader is=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(is); try { String[] inputArray=br.readLine().split(" "); LINE_NUMBER=Integer.parseInt(inputArray[0]); CODE_NUMBER=Integer.parseInt(inputArray[1]); BIAS=Integer.parseInt(inputArray[2]); } catch(Exception e){ e.printStackTrace(); } int[] coe=new int[CODE_NUMBER]; int[] src=new int[CODE_NUMBER]; int answer=0 ; try { String[] inputArray=br.readLine().split(" "); for(int j=0 ; j 0) then ( return 1 ) else ( return 0 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var is : OclFile ; is := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(is) ; try ( var inputArray : Sequence(String) ; inputArray := br.readLine()->split(" ") ; LINE_NUMBER := (inputArray[0+1])->toInteger() ; CODE_NUMBER := (inputArray[1+1])->toInteger() ; BIAS := (inputArray[2+1])->toInteger() ) catch (e : ProgramException) do ( e.printStackTrace() ) var coe : Sequence(int) ; coe := Integer.subrange(1,CODE_NUMBER)->collect(0) ; var src : Sequence(int) ; src := Integer.subrange(1,CODE_NUMBER)->collect(0) ; var answer : int ; answer := 0 ; try ( var inputArray : Sequence(String) ; inputArray := br.readLine()->split(" ") ; var j : int ; j := 0 ; while j < CODE_NUMBER do ( ( coe[j+1] := (inputArray[j+1])->toInteger() ) ; j := j + 1 ) ; var line : int ; line := 0 ; while line < LINE_NUMBER do ( ( var srcArray : Sequence(String) ; srcArray := br.readLine()->split(" ") ; var idx : int ; idx := 0 ; while idx < CODE_NUMBER do ( ( src[idx+1] := (srcArray[idx+1])->toInteger() ) ; idx := idx + 1 ) ; answer := answer+(solver(coe, src)) ) ; line := line + 1 ) ) catch (e : ProgramException) do ( e.printStackTrace() ) OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isVowel(char ch){ ch=Character.toUpperCase(ch); return(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U'); } static String duplicateVowels(String str){ int t=str.length(); String res="" ; for(int i=0 ; itoUpperCase() ; return (ch = 'A' or ch = 'E' or ch = 'I' or ch = 'O' or ch = 'U') ); static operation duplicateVowels( str : String) : String pre: true post: true activity: ( var t : int ; t := str->size() ; var res : String ; res := "" ; var i : int ; i := 0 ; while i < t do ( ( if (isVowel(str->at(i+1))) then res := res+(str->at(i+1)) ; else skip ; res := res+(str->at(i+1)) ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "helloworld" ; OclFile["System.out"].println("Original String: " + str) ; var res : String ; res := duplicateVowels(str) ; OclFile["System.out"].println("String with Vowels duplicated: " + res) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int mod=1000000007 ; static int[][] dp=new int[55][55]; static int NoofWays(int face,int throwsVal,int sum){ if(sum==0 && throwsVal==0){ return 1 ; } if(sum<0 || throwsVal==0){ return 0 ; } if(dp[throwsVal][sum]!=-1){ return dp[throwsVal][sum]; } int ans=0 ; for(int i=1 ; i<=face ; i++){ ans+=NoofWays(face,throwsVal-1,sum-i); } return dp[throwsVal][sum]=ans ; } public static void main(String[] args){ int faces=6,throwsVal=3,sum=12 ; for(int i=0 ; i<55 ; i++){ for(int j=0 ; j<55 ; j++){ dp[i][j]=-1 ; } } System.out.println(NoofWays(faces,throwsVal,sum)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute mod : int := 1000000007; static attribute dp : Sequence(Sequence(int)) := Integer.subrange(1,55)->collect(Integer.subrange(1,55)->collect(0)); static operation NoofWays( face : int, throwsVal : int, sum : int) : int pre: true post: true activity: ( if (sum = 0 & throwsVal = 0) then ( return 1 ) else skip ; if (sum < 0 or throwsVal = 0) then ( return 0 ) else skip ; if (dp[throwsVal+1][sum+1] /= -1) then ( return dp[throwsVal+1][sum+1] ) else skip ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= face do ( ( ans := ans+(NoofWays(face, throwsVal - 1, sum - i)) ) ; i := i + 1 ) ; return dp[throwsVal+1][sum+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var faces : int ; faces := 6 ; var throwsVal : int ; throwsVal := 3 ; var sum : int ; sum := 12 ; var i : int ; i := 0 ; while i < 55 do ( ( var j : int ; j := 0 ; while j < 55 do ( ( dp[i+1][j+1] := -1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(NoofWays(faces, throwsVal, sum)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countPairsWithProdK(int arr[],int n,int k){ int count=0 ; for(int i=0 ; isize() ; var K : int ; K := 3 ; OclFile["System.out"].println(countPairsWithProdK(arr, N, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int CountZeroBit(int n){ int count=0 ; while(n>0){ if((n & 1)!=0)count++; n>>=1 ; } return count ; } static int CountORandSumEqual(int N){ int count=CountZeroBit(N); return(1< 0) do ( if ((n & 1) /= 0) then count := count + 1 ; else skip ; n := n/(2->pow(1)) ) ; return count ); static operation CountORandSumEqual( N : int) : int pre: true post: true activity: ( var count : int ; count := CountZeroBit(N) ; return ((1*(2->pow(count)))->oclAsType(long)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 10 ; OclFile["System.out"].print(CountORandSumEqual(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static void profitLoss(int N,int M){ if(N==M)System.out.print("No Profit nor Loss"); else { float result=0 ; result=(float)(Math.abs(N-M))/M ; if(N-M<0)System.out.print("Loss=-"+result*100+"%"); else System.out.print("Profit="+result*100+"%"); } } public static void main(String[] args){ int N=8,M=9 ; profitLoss(N,M); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation profitLoss( N : int, M : int) : void pre: true post: true activity: ( if (N = M) then OclFile["System.out"].print("No Profit nor Loss") ; else ( var result : double ; result := 0 ; result := (if N - M < 0 then -(N - M) else N - M endif)->oclAsType(double) / M ; if (N - M < 0) then OclFile["System.out"].print("Loss=-" + result * 100 + "%") ; else OclFile["System.out"].print("Profit=" + result * 100 + "%") ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 8 ; var M : int ; M := 9 ; execute profitLoss(N, M) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static int cubesum(int n){ return(n)*(n)*(2*n*n-1); } public static void main(String args[]){ int a=4 ; System.out.println(cubesum(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cubesum( n : int) : int pre: true post: true activity: ( return (n) * (n) * (2 * n * n - 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 4 ; OclFile["System.out"].println(cubesum(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { public static int cubesum(int n){ return 2*n*n*(n+1)*(n+1); } public static void main(String args[]){ int a=8 ; System.out.println(cubesum(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cubesum( n : int) : int pre: true post: true activity: ( return 2 * n * n * (n + 1) * (n + 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 8 ; OclFile["System.out"].println(cubesum(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class A1133 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); int x3=sc.nextInt(); int y3=sc.nextInt(); System.out.println("3"); System.out.println((x1+x2-x3)+" "+(y1+y2-y3)); System.out.println((x3+x2-x1)+" "+(y3+y2-y1)); System.out.println((x1+x3-x2)+" "+(y1+y3-y2)); } } ------------------------------------------------------------ OCL File: --------- class A1133 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x1 : int ; x1 := sc.getCurrent()->toInteger() ; var y1 : int ; y1 := sc.getCurrent()->toInteger() ; var x2 : int ; x2 := sc.getCurrent()->toInteger() ; var y2 : int ; y2 := sc.getCurrent()->toInteger() ; var x3 : int ; x3 := sc.getCurrent()->toInteger() ; var y3 : int ; y3 := sc.getCurrent()->toInteger() ; OclFile["System.out"].println("3") ; OclFile["System.out"].println((x1 + x2 - x3) + " " + (y1 + y2 - y3)) ; OclFile["System.out"].println((x3 + x2 - x1) + " " + (y3 + y2 - y1)) ; OclFile["System.out"].println((x1 + x3 - x2) + " " + (y1 + y3 - y2)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] arg){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int M=scanner.nextInt(); int L=scanner.nextInt(); int[][] E=new int[N][N]; for(int u=0 ; utoInteger() ; var M : int ; M := scanner.getCurrent()->toInteger() ; var L : int ; L := scanner.getCurrent()->toInteger() ; var E : Sequence(Sequence(int)) ; E := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; var u : int ; u := 0 ; while u < N do ( ( var v : int ; v := 0 ; while v < N do ( ( E[u+1][v+1] := (if u = v then 0 else L + 1 endif) ) ; v := v + 1 ) ) ; u := u + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; E[a - 1+1][b - 1+1] := c ; E[b - 1+1][a - 1+1] := c ; ) ; i := i + 1 ) ; execute allpairsShortestPaths(E) ; var u : int ; u := 0 ; while u < N do ( ( var v : int ; v := 0 ; while v < N do ( ( E[u+1][v+1] := (if E[u+1][v+1] <= L then 1 else N + 1 endif) ) ; v := v + 1 ) ) ; u := u + 1 ) ; execute allpairsShortestPaths(E) ; var Q : int ; Q := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < Q do ( ( var s : int ; s := scanner.getCurrent()->toInteger() ; var t : int ; t := scanner.getCurrent()->toInteger() ; var d : int ; d := E[s - 1+1][t - 1+1] ; OclFile["System.out"].println(if d < N then d - 1 else -1 endif) ) ; i := i + 1 ) ; ); static operation allpairsShortestPaths( D : Sequence(Sequence(int))) : void pre: true post: true activity: ( var N : int ; N := D->size() ; var v : int ; v := 0 ; while v < N do ( ( var a : int ; a := 0 ; while a < N do ( ( var b : int ; b := 0 ; while b < N do ( ( D[a+1][b+1] := Set{D[a+1][b+1], D[a+1][v+1] + D[v+1][b+1]}->min() ) ; b := b + 1 ) ) ; a := a + 1 ) ) ; v := v + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxPartition(String s){ int n=s.length(),P=0 ; String current="",previous="" ; for(int i=0 ; isize() ; var P : int ; P := 0 ; var current : String ; current := "" ; var previous : String ; previous := "" ; var i : int ; i := 0 ; while i < n do ( ( current := current+(s->at(i+1)) ; if (not(current = previous)) then ( previous := current ; current := "" ; P := P + 1 ) else skip ) ; i := i + 1 ) ; return P ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "geeksforgeeks" ; var ans : int ; ans := maxPartition(s) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class TripForMeal { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int min=Math.min(a,Math.min(b,c)); if(min==a || min==b || n==1)System.out.println(min*(n-1)); else System.out.println(Math.min(a,b)+c*(n-2)); } } ------------------------------------------------------------ OCL File: --------- class TripForMeal { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var min : int ; min := Set{a, Set{b, c}->min()}->min() ; if (min = a or min = b or n = 1) then OclFile["System.out"].println(min * (n - 1)) else OclFile["System.out"].println(Set{a, b}->min() + c * (n - 2)) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Problem876A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int cost=0 ; int[] a=new int[3]; for(int i=0 ; i<3 ; ++i){ a[i]=sc.nextInt(); } if(n>1){ cost=Math.min(a[0],a[1]); } if(n>2){ cost+=Math.min(cost,a[2])*(n-2); } System.out.println(cost); } } ------------------------------------------------------------ OCL File: --------- class Problem876A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var cost : int ; cost := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,3)->collect(0) ; var i : int ; i := 0 ; while i < 3 do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (n > 1) then ( cost := Set{a[0+1], a[1+1]}->min() ) else skip ; if (n > 2) then ( cost := cost+(Set{cost, a[2+1]}->min() * (n - 2)) ) else skip ; OclFile["System.out"].println(cost) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int sumOfFactors(int n){ int sum=0 ; for(int f=1 ; f<=n/2 ; f++){ if(n % f==0){ sum+=f ; } } return sum ; } static int getSum(int[] arr,int n){ int sum=0 ; for(int i=0 ; i0 && arr[i]==sumOfFactors(arr[i])){ sum+=arr[i]; } } return sum ; } public static void main(String[] args){ int[] arr={ 17,6,10,6,4 }; int n=arr.length ; System.out.print(getSum(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfFactors( n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var f : int ; f := 1 ; while f <= n / 2 do ( ( if (n mod f = 0) then ( sum := sum+(f) ) else skip ) ; f := f + 1 ) ; return sum ); static operation getSum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] > 0 & arr[i+1] = sumOfFactors(arr[i+1])) then ( sum := sum+(arr[i+1]) ) else skip ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{17,6,10,6,4} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(getSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class fibonacci { static int fib(int n){ int a=0,b=1,c ; if(n==0)return a ; for(int i=2 ; i<=n ; i++){ c=a+b ; a=b ; b=c ; } return b ; } public static void main(String args[]){ int n=9 ; System.out.println(fib(n)); } } ------------------------------------------------------------ OCL File: --------- class fibonacci { static operation fib( n : int) : int pre: true post: true activity: ( var a : int ; a := 0 ; var b : int ; b := 1 ; var c : int ; if (n = 0) then return a else skip ; var i : int ; i := 2 ; while i <= n do ( ( c := a + b ; a := b ; b := c ) ; i := i + 1 ) ; return b ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].println(fib(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Codesolver { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayListar=new ArrayList<>(); for(int i=0 ; itoInteger() ; var ar : Sequence(int) ; ar := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( ar := ar->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var j : int ; j := 1 ; while j <= n do ( ( OclFile["System.out"].print(ar->indexOf(j)-1 + 1 + " ") ) ; j := j + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class Dastan { static FastReader scan=new FastReader(); static PrintWriter sout=new PrintWriter(System.out); public static void main(String[] something){ Codeforces(); sout.close(); } static void Codeforces(){ int x=scan.nextInt(); Integer[] arr=new Integer[x]; int[] arr1=new int[x]; for(int i=0 ; icollect(null) ; var arr1 : Sequence(int) ; arr1 := Integer.subrange(1,x)->collect(0) ; var i : int ; i := 0 ; while i < x do ( ( var p : int ; p := scan.nextInt() ; arr[i+1] := p ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < x do ( ( var c : int ; c := arr->indexOf(i + 1)-1 + 1 ; arr1[i+1] := c ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < arr1->size() do ( OclFile["System.out"].print(arr1[i+1] + " ") ; ; i := i + 1 ) ; ); static operation isPalindrome( str : String) : boolean pre: true post: true activity: ( var sb : String ; sb := StringLib.newString(str) ; return str = sb->reverse()+"" ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float area(float r){ if(r<0)return-1 ; float area=(float)(3.14*Math.pow(r/(2*Math.sqrt(2)),2)); return area ; } public static void main(String[] args){ float a=5 ; System.out.println(area(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation area( r : double) : double pre: true post: true activity: ( if (r < 0) then return -1 else skip ; var area : double ; area := (3.14 * r / (2 * (2)->sqrt())->pow(2))->oclAsType(double) ; return area ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 5 ; OclFile["System.out"].println(area(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int num=in.nextInt(); int[] friends=new int[num]; for(int i=1 ; icollect(0) ; var i : int ; i := 1 ; while i < num + 1 do ( ( friends[in.nextInt() - 1+1] := i ) ; i := i + 1 ) ; for (friend : friends) do ( ( skip ) ) ; skip ; ); static class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( try ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("sub.in"))) ) catch (ex : FileNotFoundException) do ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (ex : IOException) do skip ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (ex : IOException) do skip return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class _749B { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); int x3=sc.nextInt(); int y3=sc.nextInt(); System.out.println(3); System.out.println(x1+x2-x3+" "+(y1+y2-y3)); System.out.println(x2+x3-x1+" "+(y2+y3-y1)); System.out.println(x1+x3-x2+" "+(y1+y3-y2)); } } ------------------------------------------------------------ OCL File: --------- class _749B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x1 : int ; x1 := sc.getCurrent()->toInteger() ; var y1 : int ; y1 := sc.getCurrent()->toInteger() ; var x2 : int ; x2 := sc.getCurrent()->toInteger() ; var y2 : int ; y2 := sc.getCurrent()->toInteger() ; var x3 : int ; x3 := sc.getCurrent()->toInteger() ; var y3 : int ; y3 := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(3) ; OclFile["System.out"].println(x1 + x2 - x3 + " " + (y1 + y2 - y3)) ; OclFile["System.out"].println(x2 + x3 - x1 + " " + (y2 + y3 - y1)) ; OclFile["System.out"].println(x1 + x3 - x2 + " " + (y1 + y3 - y2)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n+1]; int[] ans=new int[n+1]; for(int i=1 ; i<=n ; i++){ arr[i]=sc.nextInt(); ans[arr[i] ]=i ; } for(int i=1 ; i<=n ; i++){ System.out.print(ans[i]+" "); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var ans : Sequence(int) ; ans := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; ans[arr[i+1]+1] := i ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].print(ans[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner Data=new Scanner(System.in); String str_Number=Data.nextLine(); int NUMBER=Integer.parseInt(str_Number); String str_Frinds_Get=Data.nextLine(); String Friends_Get_List[]=str_Frinds_Get.split(" "); int Friends_Get[]=new int[NUMBER]; int Frinds_Gift[]=new int[NUMBER]; for(int i=0 ; itoInteger() ; var str_Frinds_Get : String ; str_Frinds_Get := Data.nextLine() ; var Friends_Get_List : Sequence(String) ; Friends_Get_List := str_Frinds_Get->split(" ") ; var Friends_Get : Sequence(int) ; Friends_Get := Integer.subrange(1,NUMBER)->collect(0) ; var Frinds_Gift : Sequence(int) ; Frinds_Gift := Integer.subrange(1,NUMBER)->collect(0) ; var i : int ; i := 0 ; while i < Friends_Get_List->size() do ( ( Friends_Get[i+1] := (Friends_Get_List[i+1])->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < Friends_Get->size() do ( ( Frinds_Gift[Friends_Get[i+1] - 1+1] := i + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < Frinds_Gift->size() do ( ( if (i = Frinds_Gift->size() - 1) then ( OclFile["System.out"].print(Frinds_Gift[i+1]) ) else ( OclFile["System.out"].print(Frinds_Gift[i+1] + " ") ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int distinctCount(int arr[],int n){ Sets=new HashSet(); for(int i=0 ; iincluding(if arr[i+1] < 0 then -(arr[i+1]) else arr[i+1] endif) ; ; i := i + 1 ) ; return s->size() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-2,-1,0,1,1} ; var n : int ; n := arr->size() ; OclFile["System.out"].println("Count of absolute distinct values : " + distinctCount(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); HashMaph=new HashMap<>(); for(int i=0 ; i<1<0){ red+=s.charAt(j); } else { blue+=s.charAt(j); } } String key=red+":"+blue ; long tmp=h.getOrDefault(key,0L); h.put(key,tmp+1); } long ans=0 ; for(int i=0 ; i<1<0){ red+=s.charAt(2*n-1-j); } else { blue+=s.charAt(2*n-1-j); } } String key=red+":"+blue ; long tmp=h.getOrDefault(key,0L); ans+=tmp ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var h : Map(String,long) ; h := Map{} ; var i : int ; i := 0 ; while i < (1*(2->pow(n)))->oclAsType(long) do ( ( var red : String ; red := "" ; var blue : String ; blue := "" ; var j : int ; j := 0 ; while j < n do ( ( if ((MathLib.bitwiseAnd(i,((1*(2->pow(j)))->oclAsType(long)))) > 0) then ( red := red+(s->at(j+1)) ) else ( blue := blue+(s->at(j+1)) ) ) ; j := j + 1 ) ; var key : String ; key := red + ":" + blue ; var tmp : long ; tmp := (if h->keys()->contains(key) then h->at(key) else 0L endif) ; h := h->union(Map{key |-> tmp + 1}) ; ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < (1*(2->pow(n)))->oclAsType(long) do ( ( var red : String ; red := "" ; var blue : String ; blue := "" ; var j : int ; j := 0 ; while j < n do ( ( if ((MathLib.bitwiseAnd(i,((1*(2->pow(j)))->oclAsType(long)))) > 0) then ( red := red+(s->at(2 * n - 1 - (j)->char2byte()+1)) ) else ( blue := blue+(s->at(2 * n - 1 - (j)->char2byte()+1)) ) ) ; j := j + 1 ) ; var key : String ; key := red + ":" + blue ; var tmp : long ; tmp := (if h->keys()->contains(key) then h->at(key) else 0L endif) ; ans := ans+(tmp) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); String s=in.next(); char[] l=new char[n]; char[] r=new char[n]; for(int i=0 ; i>j)& 1 ; buf[k][p[k]++]=l[j]; } long[][] dp=new long[p[0]+1][p[1]+1]; dp[0][0]=1 ; for(int x=0 ; x<=p[0]; x++){ for(int y=0 ; y<=p[1]; y++){ if(xtoInteger() ; var s : String ; s := in.getCurrent() ; var l : Sequence(String) ; l := Integer.subrange(1,n)->collect(0) ; var r : Sequence(String) ; r := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( l[i+1] := s->at(i+1) ; r[i+1] := s->at(2 * n - 1 - i+1) ) ; i := i + 1 ) ; var buf : Sequence(Sequence(String)) ; buf := Integer.subrange(1,2)->collect(Integer.subrange(1,n)->collect(0)) ; var count : long ; count := 0 ; var i : int ; i := 0 ; while i < ((1*(2->pow(n)))->oclAsType(long)) do ( ( var p : Sequence(int) ; p := Integer.subrange(1,2)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( var k : int ; k := MathLib.bitwiseAnd(((i/(2->pow(j)))->oclAsType(long)),1) ; buf[k+1][p[k+1]+1] := l[j+1] ; p[k+1] := p[k+1] + 1 ) ; j := j + 1 ) ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,p[0+1] + 1)->collect(Integer.subrange(1,p[1+1] + 1)->collect(0)) ; dp[0+1][0+1] := 1 ; var x : int ; x := 0 ; while x <= p[0+1] do ( ( var y : int ; y := 0 ; while y <= p[1+1] do ( ( if (x < p[0+1] & r[x + y+1] = buf[0+1][x+1]) then ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1]+(dp[x+1][y+1]) ) else skip ; if (y < p[1+1] & r[x + y+1] = buf[1+1][y+1]) then ( dp[x+1][y + 1+1] := dp[x+1][y + 1+1]+(dp[x+1][y+1]) ) else skip ) ; y := y + 1 ) ) ; x := x + 1 ) ; count := count+(dp[p[0+1]+1][p[1+1]+1]) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); String S=sc.next(); HashMapmap=new HashMap(); for(int i=0 ; i<(1<=0 ; j--){ arr[j]=tmp % 2 ; tmp/=2 ; if(arr[j]==1)red+=S.charAt(N+j); else blue+=S.charAt(N+j); } String key=red+" "+blue ; if(map.containsKey(key)){ ans+=map.get(key); } else { } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var S : String ; S := sc.getCurrent() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < ((1*(2->pow(N)))->oclAsType(long)) do ( ( var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; var tmp : int ; tmp := i ; var red : String ; red := "" ; var blue : String ; blue := "" ; var j : int ; j := 0 ; while j < N do ( ( arr[j+1] := tmp mod 2 ; tmp := tmp/(2) ; if (arr[j+1] = 1) then red := red+(S->at(j+1)) ; else blue := blue+(S->at(j+1)) ; ) ; j := j + 1 ) ; var key : String ; key := red + " " + blue ; if (map->keys()->includes(key)) then ( map := map->union(Map{key |-> map->at(key) + 1}) ) else ( map := map->union(Map{key |-> 1}) ) ; ) ; i := i + 1 ) ; var ans : long ; ans := 0L ; var i : int ; i := 0 ; while i < ((1*(2->pow(N)))->oclAsType(long)) do ( ( var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; var tmp : int ; tmp := i ; var red : String ; red := "" ; var blue : String ; blue := "" ; var j : int ; j := N - 1 ; while j >= 0 do ( ( arr[j+1] := tmp mod 2 ; tmp := tmp/(2) ; if (arr[j+1] = 1) then red := red+(S->at(N + j+1)) ; else blue := blue+(S->at(N + j+1)) ; ) ; j := j - 1 ) ; var key : String ; key := red + " " + blue ; if (map->keys()->includes(key)) then ( ans := ans+(map->at(key)) ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long x=sc.nextLong(); long year=0 ; double kingaku=100 ; do { kingaku=kingaku*1.01 ; kingaku=Math.floor(kingaku); year++; } while(kingakutoLong() ; var year : long ; year := 0 ; var kingaku : double ; kingaku := 100 ; while true do (( kingaku := kingaku * 1.01 ; kingaku := (kingaku)->floor() ; year := year + 1 ) ; if (kingaku < x) then skip else break) ; OclFile["System.out"].println(year) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class Main { private static PrintWriter out ; public static void main(String[] args){ Main main=new Main(); Runtime.getRuntime().addShutdownHook(new Thread(()->out.close())); try { main.run(args); } catch(Exception e){ e.printStackTrace(); } } private void run(String[] arguments)throws Exception { MyScanner sc=new MyScanner(); out=new PrintWriter(new BufferedOutputStream(System.out)); long target=sc.nextLong(); long originalValue=100 ; int ans=0 ; while(true){ ans++; originalValue=(long)Math.floor(originalValue*1.01); if(originalValue>=target){ break ; } } out.println(ans); out.close(); } private class MyScanner { BufferedReader br ; StringTokenizer st ; MyScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute out : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; Runtime.getRuntime().addShutdownHook(OclProcess.newOclProcess((lambdaParameters ( )) out.closeFile())) ; try ( main.run(args) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); operation run( arguments : Sequence(String)) : void pre: true post: true activity: ( var sc : MyScanner ; sc := MyScanner.newMyScanner() ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var target : long ; target := sc.nextLong() ; var originalValue : long ; originalValue := 100 ; var ans : int ; ans := 0 ; while (true) do ( ans := ans + 1 ; originalValue := (originalValue * 1.01)->floor()->oclAsType(long) ; if (originalValue >= target) then ( break ) else skip ) ; skip ; skip ; ); class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); long X=sc.nextLong(); long money=100 ; long ans=0 ; for(int i=1 ; ; i++){ money*=1.01 ; if(money>=X){ ans=i ; break ; } } System.out.println(ans); } static private int binarySearch(long num,long[] orderedArray){ int lowerBorder=-1 ; int upperBorder=orderedArray.length ; int mid ; while(upperBorder-lowerBorder>1){ mid=(upperBorder+lowerBorder)/2 ; if(orderedArray[mid]<=num){ lowerBorder=mid ; } else { upperBorder=mid ; } } return lowerBorder ; } static private int binarySearch(long num,ArrayListorderedList){ int lowerBorder=-1 ; int upperBorder=orderedList.size(); int mid ; while(upperBorder-lowerBorder>1){ mid=(upperBorder+lowerBorder)/2 ; if(orderedList.get(mid)<=num){ lowerBorder=mid ; } else { upperBorder=mid ; } } return lowerBorder ; } public static int gcd(int a,int b){ return b==0 ? a : gcd(b,a % b); } public static long gcd(long a,long b){ return b==0 ? a : gcd(b,a % b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : long ; X := sc.getCurrent()->toLong() ; var money : long ; money := 100 ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while true do ( ( money := money*(1.01) ; if (money >= X) then ( ans := i ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation binarySearch( num : long, orderedArray : Sequence(long)) : int pre: true post: true activity: ( var lowerBorder : int ; lowerBorder := -1 ; var upperBorder : int ; upperBorder := orderedArray->size() ; var mid : int ; while (upperBorder - lowerBorder > 1) do ( mid := (upperBorder + lowerBorder) / 2 ; if (orderedArray[mid+1] <= num) then ( lowerBorder := mid ) else ( upperBorder := mid ) ) ; return lowerBorder ); static operation binarySearch( num : long, orderedList : Sequence(long)) : int pre: true post: true activity: ( var lowerBorder : int ; lowerBorder := -1 ; var upperBorder : int ; upperBorder := orderedList->size() ; var mid : int ; while (upperBorder - lowerBorder > 1) do ( mid := (upperBorder + lowerBorder) / 2 ; if (orderedList->at(mid+1) <= num) then ( lowerBorder := mid ) else ( upperBorder := mid ) ) ; return lowerBorder ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if b = 0 then a else gcd(b, a mod b) endif ); static operation gcd( a : long, b : long) : long pre: true post: true activity: ( return if b = 0 then a else gcd(b, a mod b) endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float area(float a){ if(a<0)return-1 ; float area=(float)Math.sqrt(a)/6 ; return area ; } public static void main(String[] args){ float a=10 ; System.out.println(area(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation area( a : double) : double pre: true post: true activity: ( if (a < 0) then return -1 else skip ; var area : double ; area := (a)->sqrt()->oclAsType(double) / 6 ; return area ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 10 ; OclFile["System.out"].println(area(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Parallelogram_is_Back { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int x=scanner.nextInt(); int y=scanner.nextInt(); int a=scanner.nextInt(); int b=scanner.nextInt(); int c=scanner.nextInt(); int d=scanner.nextInt(); System.out.println("3"); System.out.println((x+a-c)+" "+(y+b-d)); System.out.println((x+c-a)+" "+(y+d-b)); System.out.println((c+a-x)+" "+(d+b-y)); scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class Parallelogram_is_Back { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := scanner.getCurrent()->toInteger() ; var y : int ; y := scanner.getCurrent()->toInteger() ; var a : int ; a := scanner.getCurrent()->toInteger() ; var b : int ; b := scanner.getCurrent()->toInteger() ; var c : int ; c := scanner.getCurrent()->toInteger() ; var d : int ; d := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println("3") ; OclFile["System.out"].println((x + a - c) + " " + (y + b - d)) ; OclFile["System.out"].println((x + c - a) + " " + (y + d - b)) ; OclFile["System.out"].println((c + a - x) + " " + (d + b - y)) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.math.RoundingMode ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long X=Long.parseLong(sc.next()); sc.close(); BigDecimal bd1=new BigDecimal("100"); BigDecimal bd2=new BigDecimal("1.01"); BigDecimal bd3=new BigDecimal(String.valueOf(X)); int year=0 ; while(bd1.compareTo(bd3)==-1){ bd1=bd1.multiply(bd2); bd1=bd1.setScale(0,RoundingMode.DOWN); year++; } System.out.println(year); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : long ; X := (sc.getCurrent())->toLong() ; skip ; var bd1 : double ; bd1 := double("100") ; var bd2 : double ; bd2 := double("1.01") ; var bd3 : double ; bd3 := double(((X) + "")) ; var year : int ; year := 0 ; while (bd1->compareTo(bd3) = -1) do ( bd1 := bd1.multiply(bd2) ; bd1 := bd1.setScale(0, RoundingMode.DOWN) ; year := year + 1 ) ; OclFile["System.out"].println(year) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static class pair implements Comparable{ int id ; int ans ; pair(int x,int y){ id=x ; ans=y ; } public pair(){ } public int compareTo(pair o){ return this.id-o.id ; } } static ArrayListgr[]; static int[] ar ; static Scanner sc=new Scanner(System.in); static int pri[]=new int[(int)1e6+5]; static StringBuilder out=new StringBuilder(); public static void main(String[] args)throws IOException { int t=1 ; while(t-->0){ long ru=sc.nextLong(); long val=100 ; long n=0 ; while(val { attribute id : int; attribute ans : int; static operation newpair( x : int, y : int) : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( id := x ; ans := y ); static operation newpair() : pair pre: true post: true activity: ( var self : pair ; self := createpair(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: skip; operation compareTo( o : pair) : int pre: true post: true activity: ( return self.id - o.id ); } static attribute gr : Sequence(Sequence(int)); static attribute ar : Sequence(int); static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute pri : int := Integer.subrange(1,1e6->oclAsType(int) + 5)->collect(0); static attribute out : String := StringLib.newString(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var ru : long ; ru := sc.getCurrent()->toLong() ; var val : long ; val := 100 ; var n : long ; n := 0 ; while (val < ru) do ( val := val+(val / 100) ; n := n + 1 ) ; OclFile["System.out"].println(n) ; ) ; ) ; OclFile["System.out"].println(out) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean digitDividesK(int num,int k){ while(num!=0){ int d=num % 10 ; if(d!=0 && k % d==0)return true ; num=num/10 ; } return false ; } static int findCount(int l,int r,int k){ int count=0 ; for(int i=l ; i<=r ; i++){ if(digitDividesK(i,k))count++; } return count ; } public static void main(String[] args){ int l=20,r=35 ; int k=45 ; System.out.println(findCount(l,r,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation digitDividesK( num : int, k : int) : boolean pre: true post: true activity: ( while (num /= 0) do ( var d : int ; d := num mod 10 ; if (d /= 0 & k mod d = 0) then return true else skip ; num := num / 10 ) ; return false ); static operation findCount( l : int, r : int, k : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := l ; while i <= r do ( ( if (digitDividesK(i, k)) then count := count + 1 ; else skip ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 20 ; var r : int ; r := 35 ; var k : int ; k := 45 ; OclFile["System.out"].println(findCount(l, r, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class cp { public static void findAllFactor(int[][] div,int n){ int divCnt[]=new int[n+1]; int ptr[]=new int[n+1]; for(int i=n ; i>=1 ; --i){ for(int j=i ; j<=n ; j+=i)divCnt[j]++; } for(int i=1 ; i<=n ; ++i)div[i]=new int[divCnt[i] ]; for(int i=n ; i>=1 ; --i){ for(int j=i ; j<=n ; j+=i)div[j][ptr[j]++]=i ; } } public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int[] l=new int[4]; for(int i=0 ; i<4 ; i++){ String str=br.readLine(); String ss=str.substring(2); l[i]=ss.length(); } int cnt=0 ; ArrayListlist=new ArrayList<>(); for(int i=0 ; i<4 ; i++){ int id=0,id1=0 ; for(int j=0 ; j<4 ; j++){ if(j!=i){ if(l[i]<=l[j]/2)id++; } if(j!=i){ if(l[i]>=2*l[j])id1++; } } if(id==3 || id1==3){ list.add(i); } } if(list.size()==1){ System.out.println((char)('A'+list.get(0))); } else { System.out.println("C"); } } } ------------------------------------------------------------ OCL File: --------- class cp { static operation findAllFactor( div : Sequence(Sequence(int)), n : int) : void pre: true post: true activity: ( var divCnt : Sequence(int) ; divCnt := Integer.subrange(1,n + 1)->collect(0) ; var ptr : Sequence(int) ; ptr := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := n ; while i >= 1 do ( ( var j : int ; j := i ; while j <= n do ( divCnt[j+1] := divCnt[j+1] + 1 ; ; j := j+(i) ) ) ; i := i - 1 ) ; var i : int ; i := 1 ; while i <= n do ( div[i+1] := Integer.subrange(1,divCnt[i+1])->collect(0) ; ; i := i + 1 ) ; var i : int ; i := n ; while i >= 1 do ( ( var j : int ; j := i ; while j <= n do ( div[j+1][ptr[j+1]+1] := i ; ptr[j+1] := ptr[j+1] + 1 ; ; j := j+(i) ) ) ; i := i - 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var l : Sequence(int) ; l := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( ( var str : String ; str := br.readLine() ; var ss : String ; ss := str.subrange(2+1,2) ; l[i+1] := ss->size() ) ; i := i + 1 ) ; var cnt : int ; cnt := 0 ; var list : Sequence(int) ; list := Sequence{} ; var i : int ; i := 0 ; while i < 4 do ( ( var id : int ; id := 0 ; var id1 : int ; id1 := 0 ; var j : int ; j := 0 ; while j < 4 do ( ( if (j /= i) then ( if (l[i+1] <= l[j+1] / 2) then id := id + 1 ; else skip ) else skip ; if (j /= i) then ( if (l[i+1] >= 2 * l[j+1]) then id1 := id1 + 1 ; else skip ) else skip ) ; j := j + 1 ) ; if (id = 3 or id1 = 3) then ( list := list->including(i) ) else skip ) ; i := i + 1 ) ; if (list->size() = 1) then ( OclFile["System.out"].println(('A' + list->at(0+1))->oclAsType(String)) ) else ( OclFile["System.out"].println("C") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class question { public static void main(String[] args)throws NumberFormatException,IOException { Scanner sc=new Scanner(System.in); int arr[]=new int[4]; for(int i=0 ; i<4 ; i++)arr[i]=sc.next().length()-2 ; char alpha[]={ '#','A','B','C','D' }; char ans=alpha[0]; int shorter=0,longer=0,flag=0 ; for(int i=0 ; i<4 ; i++){ shorter=0 ; longer=0 ; for(int j=0 ; j<4 ; j++){ if(i!=j){ if(2*arr[i]<=arr[j])shorter++; else if(arr[i]>=2*arr[j])longer++; } } if((shorter==3 && longer==0)||(shorter==0 && longer==3)){ ans=alpha[i+1]; flag++; } } if(flag==1){ System.out.println(ans); } else System.out.println("C"); } } ------------------------------------------------------------ OCL File: --------- class question { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var arr : Sequence(int) ; arr := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( arr[i+1] := sc.getCurrent()->size() - 2 ; ; i := i + 1 ) ; var alpha : Sequence(String) ; alpha := Sequence{'#','A','B','C','D'} ; var ans : String ; ans := alpha[0+1] ; var shorter : int ; shorter := 0 ; var longer : int ; longer := 0 ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( shorter := 0 ; longer := 0 ; var j : int ; j := 0 ; while j < 4 do ( ( if (i /= j) then ( if (2 * arr[i+1] <= arr[j+1]) then shorter := shorter + 1 ; else if (arr[i+1] >= 2 * arr[j+1]) then longer := longer + 1 ; else skip ; ) else skip ) ; j := j + 1 ) ; if ((shorter = 3 & longer = 0) or (shorter = 0 & longer = 3)) then ( ans := alpha[i + 1+1] ; flag := flag + 1 ) else skip ) ; i := i + 1 ) ; if (flag = 1) then ( OclFile["System.out"].println(ans) ) else OclFile["System.out"].println("C") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CodeForces { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a[]=new int[5]; for(int i=1 ; i<=4 ; i++){ a[i]=sc.nextInt(); } String s=sc.next(); int wastedCalories=0 ; for(int i=0 ; icollect(0) ; var i : int ; i := 1 ; while i <= 4 do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var s : String ; s := sc.getCurrent() ; var wastedCalories : int ; wastedCalories := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = '1') then wastedCalories := wastedCalories+(a[1+1]) ; else skip ; if (s->at(i+1) = '2') then wastedCalories := wastedCalories+(a[2+1]) ; else skip ; if (s->at(i+1) = '3') then wastedCalories := wastedCalories+(a[3+1]) ; else skip ; if (s->at(i+1) = '4') then wastedCalories := wastedCalories+(a[4+1]) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(wastedCalories) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CodeForces { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a[]=new int[5]; for(int i=1 ; i<=4 ; i++){ a[i]=sc.nextInt(); } String s=sc.next(); int wastedCalories=0 ; for(int i=0 ; icollect(0) ; var i : int ; i := 1 ; while i <= 4 do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var s : String ; s := sc.getCurrent() ; var wastedCalories : int ; wastedCalories := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = '1') then wastedCalories := wastedCalories+(a[1+1]) ; else skip ; if (s->at(i+1) = '2') then wastedCalories := wastedCalories+(a[2+1]) ; else skip ; if (s->at(i+1) = '3') then wastedCalories := wastedCalories+(a[3+1]) ; else skip ; if (s->at(i+1) = '4') then wastedCalories := wastedCalories+(a[4+1]) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(wastedCalories) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MyClass { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=sc.nextInt(); int ans=0 ; String str=sc.next(); for(int i=0 ; itoInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var str : String ; str := sc.getCurrent() ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str->at(i+1) = '1') then ( ans := ans+(a) ) else if (str->at(i+1) = '2') then ( ans := ans+(b) ) else if (str->at(i+1) = '3') then ( ans := ans+(c) ) else ( ans := ans+(d) ) ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class A431 { static Scanner sc=new Scanner(); public static void main(String[] args){ solve(); } public static void solve(){ int[] a=sc.readArray(4); String str=sc.next(); int sum=0 ; for(int i=0 ; isize() do ( ( sum := sum+(a[("" + str->at(i+1))->toInteger() - 1+1]) ) ; i := i + 1 ) ; OclFile["System.out"].print(sum) ; ); static class Scanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int cntSubSeq(int arr[],int n){ int pos_count=0 ; int neg_count=0 ; int result ; for(int i=0 ; i0)pos_count++; if(arr[i]<0)neg_count++; } result=(int)Math.pow(2,pos_count); if(neg_count>0)result*=Math.pow(2,neg_count-1); else result=0 ; return result ; } public static void main(String[] args){ int arr[]={ 3,-4,-1,6 }; int n=arr.length ; System.out.print(cntSubSeq(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cntSubSeq( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var pos_count : int ; pos_count := 0 ; var neg_count : int ; neg_count := 0 ; var result : int ; var i : int ; i := 0 ; while i < n 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 ) ; i := i + 1 ) ; result := 2->pow(pos_count)->oclAsType(int) ; if (neg_count > 0) then result := result*(2->pow(neg_count - 1)) else result := 0 ; ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,-4,-1,6} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(cntSubSeq(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); void union(int a,int b,int[] par,int[] size){ a=getPar(a,par); b=getPar(b,par); par[a]=b ; size[b]+=size[a]; } int getPar(int a,int[] par){ if(par[a]==a)return a ; return par[a]=getPar(par[a],par); } void solution(){ String s1=sc.next(); String s2=sc.next(); int x=s1.charAt(0)-s2.charAt(0); int y=s1.charAt(1)-s2.charAt(1); int ans=Math.max(Math.abs(x),Math.abs(y)); StringBuilder sb=new StringBuilder(); for(int i=0 ; i0){ sb.append("L"); x--; } if(y<0){ sb.append("U"); y++; } else if(y>0){ sb.append("D"); y--; } sb.append("\n"); } System.out.println(ans+"\n"+sb); } public static void main(String[] args){ new Main().solution(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation union( a : int, b : int, par : Sequence(int), size : Sequence(int)) : void pre: true post: true activity: ( a := getPar(a, par) ; b := getPar(b, par) ; par[a+1] := b ; size[b+1] := size[b+1]+(size[a+1]) ); operation getPar( a : int, par : Sequence(int)) : int pre: true post: true activity: ( if (par[a+1] = a) then return a else skip ; return par[a+1] ); operation solution() : void pre: true post: true activity: ( var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; var x : int ; x := s1->at(0+1) - s2->at(0+1) ; var y : int ; y := s1->at(1+1) - s2->at(1+1) ; var ans : int ; ans := Set{if x < 0 then -(x) else x endif, if y < 0 then -(y) else y endif}->max() ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < ans do ( ( if (x < 0) then ( sb := sb + StringLib.newString("R") ; x := x + 1 ) else if (x > 0) then ( sb := sb + StringLib.newString("L") ; x := x - 1 ) else skip ; ; if (y < 0) then ( sb := sb + StringLib.newString("U") ; y := y + 1 ) else if (y > 0) then ( sb := sb + StringLib.newString("D") ; y := y - 1 ) else skip ; ; sb := sb + StringLib.newString("\n") ) ; i := i + 1 ) ; OclFile["System.out"].println(ans + "\n" + sb) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solution() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B_388 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int x1=in.nextInt(); int y1=in.nextInt(); int x2=in.nextInt(); int y2=in.nextInt(); int x3=in.nextInt(); int y3=in.nextInt(); System.out.println(3); System.out.println((x1+x2-x3)+" "+(y1+y2-y3)); System.out.println((x2+x3-x1)+" "+(y2+y3-y1)); System.out.println((x3+x1-x2)+" "+(y3+y1-y2)); } } ------------------------------------------------------------ OCL File: --------- class B_388 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x1 : int ; x1 := in.getCurrent()->toInteger() ; var y1 : int ; y1 := in.getCurrent()->toInteger() ; var x2 : int ; x2 := in.getCurrent()->toInteger() ; var y2 : int ; y2 := in.getCurrent()->toInteger() ; var x3 : int ; x3 := in.getCurrent()->toInteger() ; var y3 : int ; y3 := in.getCurrent()->toInteger() ; OclFile["System.out"].println(3) ; OclFile["System.out"].println((x1 + x2 - x3) + " " + (y1 + y2 - y3)) ; OclFile["System.out"].println((x2 + x3 - x1) + " " + (y2 + y3 - y1)) ; OclFile["System.out"].println((x3 + x1 - x2) + " " + (y3 + y1 - y2)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static float trianglearea(float a,float b){ if(a<0 || b<0)return-1 ; float area=(float)(3*Math.sqrt(3)*Math.pow(a,2))/(4*b); return area ; } public static void main(String[] args){ float a=4,b=2 ; System.out.println(trianglearea(a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation trianglearea( a : double, b : double) : double pre: true post: true activity: ( if (a < 0 or b < 0) then return -1 else skip ; var area : double ; area := (3 * (3)->sqrt() * a->pow(2))->oclAsType(double) / (4 * b) ; return area ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 4 ; var b : double ; b := 2 ; OclFile["System.out"].println(trianglearea(a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int cntSubSeq(int arr[],int n){ int pos_count=0 ; int neg_count=0 ; int result ; for(int i=0 ; i0)pos_count++; if(arr[i]<0)neg_count++; } result=(int)Math.pow(2,pos_count); if(neg_count>0)result*=Math.pow(2,neg_count-1); result-=1 ; return result ; } public static void main(String[] args){ int arr[]={ 2,-3,-1,4 }; int n=arr.length ; System.out.print(cntSubSeq(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cntSubSeq( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var pos_count : int ; pos_count := 0 ; var neg_count : int ; neg_count := 0 ; var result : int ; var i : int ; i := 0 ; while i < n 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 ) ; i := i + 1 ) ; result := 2->pow(pos_count)->oclAsType(int) ; if (neg_count > 0) then result := result*(2->pow(neg_count - 1)) ; else skip ; result := result-(1) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,-3,-1,4} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(cntSubSeq(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; class GFG { static int sum(int ar[],int n){ HashMapmp=new HashMap<>(); for(int i=0 ; iunion(Map{ar[i+1] |-> 0}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( mp := mp->union(Map{ar[i+1] |-> mp->at(ar[i+1]) + 1}) ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; for (p : mp->asSet()) do ( ( n := n-(p.getValue()->oclAsType(int)) ; sum := sum+(n) ) ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var ar : Sequence(int) ; ar := Sequence{5,4,4,2,2,8} ; var ans : int ; ans := sum(ar, n) ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean permutation(int[] arr,int n){ Sethash=new HashSet(); int maxEle=0 ; for(int i=0 ; iincluding(arr[i+1]) ; maxEle := Set{maxEle, arr[i+1]}->max() ) ; i := i + 1 ) ; if (maxEle /= n) then return false else skip ; if (hash->size() = n) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,5,3,2} ; var n : int ; n := arr->size() ; if (permutation(arr, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getPassingCars(int[] A,int n){ int result=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(getPassingCars(A, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int w=sc.nextInt(); int h=sc.nextInt(); if(w==0 && h==0)break ; BigInteger[][] bi=new BigInteger[h+1][w+1]; for(int i=0 ; i<=h ; i++){ for(int j=0 ; j<=w ; j++){ bi[i][j]=BigInteger.ZERO ; } } BigInteger zero=BigInteger.ZERO ; BigInteger max=BigInteger.ZERO ; String s,t ; for(int i=1 ; i<=h ; i++){ s=sc.next(); for(int j=1 ; j<=w ; j++){ t=s.substring(j-1,j); if(t.codePointAt(0)<58){ if(bi[i][j-1] .compareTo(zero)==0 && bi[i-1][j] .compareTo(zero)==0 && t.compareTo("0")==0)continue ; BigInteger x=bi[i][j-1] .multiply(BigInteger.TEN).add(new BigInteger(t)); BigInteger y=bi[i-1][j] .multiply(BigInteger.TEN).add(new BigInteger(t)); if(x.compareTo(y)>0)bi[i][j]=x ; else bi[i][j]=y ; if(max.compareTo(bi[i][j])<0)max=bi[i][j]; } } } System.out.println(max); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var w : int ; w := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; if (w = 0 & h = 0) then break else skip ; var bi : Sequence(Sequence(long)) ; bi := Integer.subrange(1,h + 1)->collect(Integer.subrange(1,w + 1)->collect(null)) ; var i : int ; i := 0 ; while i <= h do ( ( var j : int ; j := 0 ; while j <= w do ( ( bi[i+1][j+1] := 0 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var zero : long ; zero := 0 ; var max : long ; max := 0 ; var s : String ; var t : String ; var i : int ; i := 1 ; while i <= h do ( ( s := sc.getCurrent() ; var j : int ; j := 1 ; while j <= w do ( ( t := s.subrange(j - 1+1,j) ; if (t.codePointAt(0) < 58) then ( if (bi[i+1][j - 1+1]->compareTo(zero) = 0 & bi[(i)->char2byte() - 1+1][j+1]->compareTo(zero) = 0 & t->compareTo("0") = 0) then continue else skip ; var x : long ; x := bi[i+1][j - 1+1].multiply(10)->excludes(long(t)) ; var y : long ; y := bi[(i)->char2byte() - 1+1][j+1].multiply(10)->excludes(long(t)) ; if (x->compareTo(y) > 0) then bi[i+1][j+1] := x else bi[i+1][j+1] := y ; ; if (max->compareTo(bi[i+1][j+1]) < 0) then max := bi[i+1][j+1] ; else skip ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int w=sc.nextInt(); int h=sc.nextInt(); if((w | h)==0)break ; char[][] m=new char[h][w]; for(int i=0 ; i=0 ; i--)for(int j=w-1 ; j>=0 ; j--){ if(Character.isUpperCase(m[i][j]))continue ; String l=m[i][j]+"" ; String d=m[i][j]+"" ; if(i+1d.length()? l : d ; } else { BigInteger bl=new BigInteger(l); BigInteger bd=new BigInteger(d); if(bl.compareTo(bd)>0)dp[i][j]=l ; else dp[i][j]=d ; } BigInteger b=new BigInteger(dp[i][j]); if(b.compareTo(new BigInteger(res))>0){ res=dp[i][j]; } } System.out.println(new BigInteger(res).toString()); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var w : int ; w := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(w,h)) = 0) then break else skip ; var m : Sequence(Sequence(String)) ; m := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( m[i+1] := sc.getCurrent()->characters() ; ; i := i + 1 ) ; var dp : Sequence(Sequence(String)) ; dp := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(null)) ; var res : String ; res := "0" ; var i : int ; i := h - 1 ; while i >= 0 do ( var j : int ; j := w - 1 ; while j >= 0 do ( ( if ((m[i+1][j+1]->toUpperCase() = m[i+1][j+1])) then continue else skip ; var l : String ; l := m[i+1][j+1] + "" ; var d : String ; d := m[i+1][j+1] + "" ; if (i + 1 < h & not((m[i + 1+1][j+1]->toUpperCase() = m[i + 1+1][j+1]))) then d := d+(dp[i + 1+1][j+1]) ; else skip ; if (j + 1 < w & not((m[i+1][j + 1+1]->toUpperCase() = m[i+1][j + 1+1]))) then l := l+(dp[i+1][j + 1+1]) ; else skip ; if (l->size() /= d->size()) then ( dp[i+1][j+1] := if l->size() > d->size() then l else d endif ) else ( var bl : long ; bl := long(l) ; var bd : long ; bd := long(d) ; if (bl->compareTo(bd) > 0) then dp[i+1][j+1] := l ; else dp[i+1][j+1] := d ; ) ; var b : long ; b := long(dp[i+1][j+1]) ; if (b->compareTo(long(res)) > 0) then ( res := dp[i+1][j+1] ) else skip ; ) ; j := j - 1 ) ; ; i := i - 1 ) ; OclFile["System.out"].println(long(res)+"") ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; import static java.lang.System.*; public class Main { Scanner sc=new Scanner(in); void run(){ while(true){ int w=sc.nextInt(),h=sc.nextInt(); if(w==0 && h==0)break ; String[] rows=new String[h]; for(int i=0 ; i0)? dp[i-1][j] : dp[i][j-1]).multiply(BigInteger.TEN)).add(new BigInteger(""+rows[i-1] .charAt(j-1))); res=(dp[i][j] .compareTo(res)>0)? dp[i][j] : res ; } } } out.println(res); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(in); operation run() : void pre: true post: true activity: ( while (true) do ( var w : int ; w := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; if (w = 0 & h = 0) then break else skip ; var rows : Sequence(String) ; rows := Integer.subrange(1,h)->collect(null) ; var i : int ; i := 0 ; while i < h do ( rows[i+1] := sc.getCurrent() ; ; i := i + 1 ) ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,h + 1)->collect(Integer.subrange(1,w + 1)->collect(null)) ; var i : int ; i := 0 ; while i <= h do ( var j : int ; j := 0 ; while j <= w do ( dp[i+1][j+1] := 0 ; ; j := j + 1 ) ; ; i := i + 1 ) ; var res : long ; res := 0 ; var i : int ; i := 1 ; while i <= h do ( ( var j : int ; j := 1 ; while j <= w do ( ( if ((rows[i - 1+1]->at(j - 1+1) + "")->isMatch("[0-9]")) then ( dp[i+1][j+1] := ((if (dp[i - 1+1][j+1]->compareTo(dp[i+1][j - 1+1]) > 0) then dp[i - 1+1][j+1] else dp[i+1][j - 1+1] endif).multiply(10))->excludes(long("" + rows[i - 1+1]->at(j - 1+1))) ; res := if (dp[i+1][j+1]->compareTo(res) > 0) then dp[i+1][j+1] else res endif ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; out.println(res) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int w=sc.nextInt(); int h=sc.nextInt(); if(w==0 && h==0){ break ; } char[][] m=new char[h][]; for(int i=0 ; i0){ dp[i][j]=dp[i][j] .max(dp[i-1][j] .multiply(BigInteger.TEN).add(d)); } if(j>0){ dp[i][j]=dp[i][j] .max(dp[i][j-1] .multiply(BigInteger.TEN).add(d)); } ans=ans.max(dp[i][j]); } } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var w : int ; w := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; if (w = 0 & h = 0) then ( break ) else skip ; var m : Sequence(Sequence(String)) ; m := Integer.subrange(1,h)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < h do ( ( m[i+1] := sc.getCurrent()->characters() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(null)) ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( dp[i+1][j+1] := 0 ; if (not((m[i+1][j+1] + "")->isMatch("[0-9]"))) then ( continue ) else skip ; var d : long ; d := (m[i+1][j+1] - ('0')->char2byte() + "")->toLong() ; dp[i+1][j+1] := d ; if (i > 0) then ( dp[i+1][j+1] := dp[i+1][j+1]->max() ) else skip ; if (j > 0) then ( dp[i+1][j+1] := dp[i+1][j+1]->max() ) else skip ; ans := ans->max() ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.StringTokenizer ; public class A { public static void main(String args[]){ FS in=new FS(); PrintWriter out=new PrintWriter(System.out); int N=in.nextInt(); int ar[]=new int[N]; int cols=0 ; for(int i=0 ; icollect(0) ; var cols : int ; cols := 0 ; var i : int ; i := 0 ; while i < N do ( ar[i+1] := in.nextInt() ; ; i := i + 1 ) ; var done : Sequence(boolean) ; done := Integer.subrange(1,N)->collect(false) ; ar := ar->sort() ; var i : int ; i := 0 ; while i < N do ( ( if (done[i+1]) then continue else skip ; cols := cols + 1 ; var j : int ; j := i ; while j < N do ( if (ar[j+1] mod ar[i+1] = 0) then done[j+1] := true ; else skip ; ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; skip ; ); static class FS { attribute br : OclFile; attribute st : OclIterator; static operation newFS() : FS pre: true post: true activity: ( var self : FS ; self := createFS(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : ProgramException) do skip ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); String s=sc.next(); StringBuilder tmp=new StringBuilder(); int[] freq=new int[26]; Arrays.fill(freq,0); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; s := sc.getCurrent() ; var tmp : String ; tmp := StringLib.newString() ; var freq : Sequence(int) ; freq := Integer.subrange(1,26)->collect(0) ; freq := freq->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( freq[s->at(i+1) - ('a')->char2byte()+1] := freq[s->at(i+1) - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 26 do ( ( var j : int ; j := 0 ; while j < freq[i+1] do ( ( tmp := tmp + StringLib.newString(('a' + i)->oclAsType(String) + "") ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (s->at(i+1) /= tmp->at(i+1)) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; skip ; ) ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; a := a->sort() ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] < 0) then continue else skip ; cnt := cnt + 1 ; var j : int ; j := i + 1 ; while j < n do ( ( if (a[j+1] mod a[i+1] = 0) then a[j+1] := -1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float area(float a){ if(a<0)return-1 ; float area=(float)Math.pow((a*Math.sqrt(3))/(Math.sqrt(2)),2); return area ; } public static void main(String[] args){ float a=5 ; System.out.println(area(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation area( a : double) : double pre: true post: true activity: ( if (a < 0) then return -1 else skip ; var area : double ; area := (a * (3)->sqrt()) / ((2)->sqrt())->pow(2)->oclAsType(double) ; return area ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 5 ; OclFile["System.out"].println(area(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A_Paint_the_Numbers { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] A=new int[n]; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( A[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; A := A->sort() ; var B : Sequence(boolean) ; B := Integer.subrange(1,n)->collect(false) ; var i : int ; i := 0 ; while i < n - 1 do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (A[j+1] mod A[i+1] = 0) then ( B[j+1] := true ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (B[i+1] = false) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class A1209 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int a[]=new int[n]; Setset=new HashSet<>(); for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (a[j+1] mod a[i+1] = 0) then ( a[j+1] := a[i+1] ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( set := set->including(a[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(set->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.rmi.server.RemoteServer ; import java.security.cert.CollectionCertStoreParameters ; import java.util.*; public class A_Paint_the_Numbers { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); long arr[]=new long[n]; int count[]=new int[101]; HashSetset=new HashSet<>(); int i=0 ; Vectorv=new Vector<>(); for(i=0 ; itoInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var count : Sequence(int) ; count := Integer.subrange(1,101)->collect(0) ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; var v : Sequence(long) ; v := Sequence{} ; i := 0 ; while i < n do ( ( v := v->including(s.getCurrent()->toLong()) ; if (arr[i+1] = 1) then ( break ) else skip ) ; i := i + 1 ) ; v := v->sort() ; var c : int ; c := 0 ; var max : int ; max := 0 ; if (i /= n) then ( OclFile["System.out"].println(1) ) else ( var k : int ; k := 1 ; var num : int ; num := 2 ; while (not(v->isEmpty())) do ( var a : long ; a := v->at(0+1) ; var j : int ; j := 1 ; if (v->includes(a)) then ( while (not(v->isEmpty()) & a * j <= v->at(v->size() - 1+1)) do ( while (not(v->isEmpty()) & v->includes(a * j)) do v := v->excludingFirst(a * j) ; ; j := j + 1 ) ; c := c + 1 ) else skip ) ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class template { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); String s=sc.next(); boolean letter[]=new boolean[26]; String ans="" ; int count=0 ; for(char ch : s.toCharArray()){ if(! letter[ch-'a']){ count++; letter[ch-'a']=true ; if(count<=k){ ans+="\n" ; } } ans+=ch ; } if(counttoInteger() ; var s : String ; s := sc.getCurrent() ; var letter : Sequence(boolean) ; letter := Integer.subrange(1,26)->collect(false) ; var ans : String ; ans := "" ; var count : int ; count := 0 ; for (ch : s->characters()) do ( ( if (not(letter[ch - ('a')->char2byte()+1])) then ( count := count + 1 ; letter[ch - ('a')->char2byte()+1] := true ; if (count <= k) then ( ans := ans+("\n") ) else skip ) else skip ; ans := ans+(ch) ) ) ; if (count < k) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES" + ans) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxSum(int[] a,int n){ int ans=0 ; int[] arr=new int[n+1]; for(int i=1 ; i<=n ; i++)arr[i]=a[i-1]; int[][] dp=new int[n+1][3]; for(int i=1 ; i<=n ; ++i){ dp[i][0]=Math.max(arr[i],dp[i-1][0]+arr[i]); dp[i][1]=Math.max(0,dp[i-1][0])-arr[i]; if(i>=2)dp[i][1]=Math.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]=Math.max(dp[i][2],dp[i-1][2]+arr[i]); ans=Math.max(ans,dp[i][0]); ans=Math.max(ans,dp[i][1]); ans=Math.max(ans,dp[i][2]); } return ans ; } public static void main(String[] args){ int arr[]={ -5,3,2,7,-8,3,7,-9,10,12,-6 }; int n=arr.length ; System.out.println(maxSum(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxSum( a : Sequence(int), n : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( arr[i+1] := a[i - 1+1] ; ; i := i + 1 ) ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,3)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( ( dp[i+1][0+1] := Set{arr[i+1], dp[i - 1+1][0+1] + arr[i+1]}->max() ; dp[i+1][1+1] := Set{0, dp[i - 1+1][0+1]}->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][0+1]}->max() ; ans := Set{ans, dp[i+1][1+1]}->max() ; ans := Set{ans, dp[i+1][2+1]}->max() ; ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-5,3,2,7,-8,3,7,-9,10,12,-6} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(maxSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static int gcd(int a,int b){ if(a==0)return b ; return gcd(b % a,a); } static int lcm(int n,int m){ return(n*m)/gcd(n,m); } public static void main(String[] args){ int n=2,m=3,k=5 ; System.out.print(k/lcm(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation lcm( n : int, m : int) : int pre: true post: true activity: ( return (n * m) / gcd(n, m) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 2 ; var m : int ; m := 3 ; var k : int ; k := 5 ; OclFile["System.out"].print(k / lcm(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.dnd.Autoscroll ; import java.io.BufferedReader ; import java.io.DataInputStream ; import java.io.FileInputStream ; import java.io.IOException ; import java.util.*; import java.io.InputStreamReader ; import java.util.Scanner ; public class cp { public static void main(String[] args)throws IOException,NullPointerException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] a=new long[n]; for(int i=0 ; ihs=new HashSet<>(); hs.add(4L); for(int i=3 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var p : Sequence(boolean) ; p := Integer.subrange(1,1000001)->collect(false) ; p[0+1] := false ; p[1+1] := false ; p[2+1] := true ; var i : int ; i := 3 ; while i < p->size() do ( p[i+1] := true ; ; i := i+(2) ) ; var i : int ; i := 3 ; while i < p->size() do ( ( if (p[i+1]) then ( var j : int ; j := 3 * i ; while j < p->size() do ( p[j+1] := false ; ; j := j+(2 * i) ) ) else skip ) ; i := i+(2) ) ; var hs : Set(long) ; hs := Set{} ; hs := hs->including(4L) ; var i : int ; i := 3 ; while i < p->size() do ( ( if (p[i+1]) then hs := hs->including(i->oclAsType(long) * i) ; else skip ) ; i := i+(2) ) ; var i : int ; i := 0 ; while i < n do ( ( if (hs->includes(a[i+1])) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.Arrays ; import java.util.Scanner ; import java.util.StringTokenizer ; public class Main { static class Reader { static BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tokenizer=new StringTokenizer(""); static String next()throws IOException { while(! tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static int nextInt()throws IOException { return Integer.parseInt(next()); } static double nextDouble()throws IOException { return Double.parseDouble(next()); } static long nextLong()throws IOException { return Long.parseLong(next()); } } static boolean[] isPrime=new boolean[1000005]; static int[] prime=new int[1000005]; public static void aiPrime(int n){ Arrays.fill(isPrime,true); isPrime[1]=false ; int cnt=0 ; for(int i=2 ; i<=n ; i++){ if(isPrime[i])prime[++cnt]=i ; for(int j=1 ; j<=cnt && i*prime[j]<=n ; j++){ isPrime[i*prime[j] ]=false ; if(i % prime[j]==0)break ; } } } static Reader scanner=new Reader(); static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args)throws IOException { aiPrime(1000000); int n ; n=scanner.nextInt(); for(int i=1 ; i<=n ; i++){ long x=scanner.nextLong(); int sq=(int)Math.sqrt((double)x); if((x % sq==0)&&(x/sq==sq)&&(isPrime[sq])){ out.println("YES"); out.flush(); } else { out.println("NO"); out.flush(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static class Reader { static attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute tokenizer : OclIterator := OclIterator.newOclIterator_String(""); static operation next() : String pre: true post: true activity: ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ; return tokenizer.next() ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static attribute isPrime : Sequence(boolean) := Integer.subrange(1,1000005)->collect(false); static attribute prime : Sequence(int) := Integer.subrange(1,1000005)->collect(0); static operation aiPrime( n : int) : void pre: true post: true activity: ( isPrime := isPrime->collect(true) ; isPrime[1+1] := false ; var cnt : int ; cnt := 0 ; var i : int ; i := 2 ; while i <= n do ( ( if (isPrime[i+1]) then cnt := cnt + 1 ; prime[cnt+1] := i ; else skip ; var j : int ; j := 1 ; while j <= cnt & i * prime[j+1] <= n do ( ( isPrime[i * prime[j+1]+1] := false ; if (i mod prime[j+1] = 0) then break else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ); static attribute scanner : OclFile := OclFile(); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute aiPrime(1000000) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( var x : long ; x := scanner.getCurrent()->toLong() ; var sq : int ; sq := (x->oclAsType(double))->sqrt()->oclAsType(int) ; if ((x mod sq = 0) & (x / sq = sq) & (isPrime[sq+1])) then ( skip ; skip ) else ( skip ; skip ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class SubsequencePermutation { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int testCase=scanner.nextInt()*2 ; String[] temp=new String[testCase]; for(int i=0 ; itoInteger() * 2 ; var temp : Sequence(String) ; temp := Integer.subrange(1,testCase)->collect(null) ; var i : int ; i := 0 ; while i < testCase do ( ( temp[i+1] := scanner.getCurrent() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < temp->size() do ( ( OclFile["System.out"].println(solve(temp[i+1])) ) ; i := i + 2 ) ; ); static operation solve( val : String) : int pre: true post: true activity: ( var tempChar : Sequence(String) ; tempChar := val->characters() ; tempChar := tempChar->sort() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < val->size() do ( ( if (val->at(i+1) /= tempChar[i+1]) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.Arrays ; import java.util.Scanner ; import java.util.StringTokenizer ; public class Main { static class Reader { static BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tokenizer=new StringTokenizer(""); static String next()throws IOException { while(! tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static int nextInt()throws IOException { return Integer.parseInt(next()); } static double nextDouble()throws IOException { return Double.parseDouble(next()); } static long nextLong()throws IOException { return Long.parseLong(next()); } } static boolean[] isPrime=new boolean[1000005]; public static void aiPrime(int n){ Arrays.fill(isPrime,true); isPrime[1]=false ; for(int i=2 ; i<=n ; i++){ if(isPrime[i]){ for(int j=2 ; j*i<=n ; j++){ isPrime[i*j]=false ; } } } } static Reader scanner=new Reader(); static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args)throws IOException { aiPrime(1000000); int n ; n=scanner.nextInt(); for(int i=1 ; i<=n ; i++){ long x=scanner.nextLong(); int sq=(int)Math.sqrt((double)x); if((x % sq==0)&&(x/sq==sq)&&(isPrime[sq])){ out.println("YES"); out.flush(); } else { out.println("NO"); out.flush(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static class Reader { static attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute tokenizer : OclIterator := OclIterator.newOclIterator_String(""); static operation next() : String pre: true post: true activity: ( while (not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ; return tokenizer.next() ); static operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); static operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static attribute isPrime : Sequence(boolean) := Integer.subrange(1,1000005)->collect(false); static operation aiPrime( n : int) : void pre: true post: true activity: ( isPrime := isPrime->collect(true) ; isPrime[1+1] := false ; var i : int ; i := 2 ; while i <= n do ( ( if (isPrime[i+1]) then ( var j : int ; j := 2 ; while j * i <= n do ( ( isPrime[i * j+1] := false ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ); static attribute scanner : OclFile := OclFile(); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute aiPrime(1000000) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( ( var x : long ; x := scanner.getCurrent()->toLong() ; var sq : int ; sq := (x->oclAsType(double))->sqrt()->oclAsType(int) ; if ((x mod sq = 0) & (x / sq = sq) & (isPrime[sq+1])) then ( skip ; skip ) else ( skip ; skip ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); boolean[] ara=new boolean[1000001]; for(int i=2 ; i<=1000 ; i++){ if(! ara[i]){ for(int j=2*i ; jtoInteger() ; var ara : Sequence(boolean) ; ara := Integer.subrange(1,1000001)->collect(false) ; var i : int ; i := 2 ; while i <= 1000 do ( ( if (not(ara[i+1])) then ( var j : int ; j := 2 * i ; while j < ara->size() do ( ( ara[j+1] := true ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; ara[1+1] := true ; var i : int ; i := 0 ; while i < n do ( ( var num : long ; num := in.getCurrent()->toLong() ; if ((num)->sqrt() mod 1 = 0 & not(ara[(num)->sqrt()->oclAsType(int)+1])) then ( skip ) else ( skip ) ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static double trianglearea(double a){ if(a<0)return-1 ; double area=(3*Math.sqrt(3)*Math.pow(a,2))/4 ; return area ; } public static void main(String[] args){ double a=6 ; System.out.println(trianglearea(a)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation trianglearea( a : double) : double pre: true post: true activity: ( if (a < 0) then return -1 else skip ; var area : double ; area := (3 * (3)->sqrt() * a->pow(2)) / 4 ; return area ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : double ; a := 6 ; OclFile["System.out"].println(trianglearea(a)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; class GFG { public static int segments(int n,int[] p,int m){ HashMapc=new HashMap<>(); c.put(0,1); boolean has=false ; int sum=0 ; int ans=0 ; for(int r=0 ; rm)sum++; if(p[r]==m)has=true ; if(has)ans+=(c.get(sum)==null ? 0 : c.get(sum))+(c.get(sum-1)==null ? 0 : c.get(sum-1)); else c.put(sum,c.get(sum)==null ? 1 : c.get(sum)+1); } return ans ; } public static void main(String[] args){ int[] a={ 2,4,5,3,1 }; int n=a.length ; int m=4 ; System.out.println(segments(n,a,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation segments( n : int, p : Sequence(int), m : int) : int pre: true post: true activity: ( var c : Map(int,int) ; c := Map{} ; c := c->union(Map{0 |-> 1}) ; var has : boolean ; has := false ; var sum : int ; sum := 0 ; var ans : int ; ans := 0 ; var r : int ; r := 0 ; while r < n do ( ( if (p[r+1] < m) then sum := sum - 1 else if (p[r+1] > m) then sum := sum + 1 ; else skip ; ; if (p[r+1] = m) then has := true ; else skip ; if (has) then ans := ans+((if c->at(sum) = null then 0 else c->at(sum) endif) + (if c->at(sum - 1) = null then 0 else c->at(sum - 1) endif)) ; else c := c->union(Map{sum |-> if c->at(sum) = null then 1 else c->at(sum) + 1 endif}) ; ) ; r := r + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,4,5,3,1} ; var n : int ; n := a->size() ; var m : int ; m := 4 ; OclFile["System.out"].println(segments(n, a, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ProblemD { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); String line[]=br.readLine().split(" "); int n=Integer.parseInt(line[0]); int k=Integer.parseInt(line[1]); line=br.readLine().split(" "); int arr[]=new int[n]; HashMapmap=new HashMap<>(); for(int i=0 ; i1){ count+=2 ; map.put(parity,map.get(parity)-2); } } else if(map.containsKey(k-parity)){ if(parity!=k-parity){ if(map.get(parity)>0 && map.get(k-parity)>0){ count+=2 ; map.put(parity,map.get(parity)-1); map.put(k-parity,map.get(k-parity)-1); } } } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class ProblemD { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sb : String ; sb := StringLib.newString() ; var line : Sequence(String) ; line := br.readLine()->split(" ") ; var n : int ; n := (line[0+1])->toInteger() ; var k : int ; k := (line[1+1])->toInteger() ; line := br.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (line[i+1])->toInteger() ; map := map->union(Map{arr[i+1] mod k |-> (if map->keys()->contains(arr[i+1] mod k) then map->at(arr[i+1] mod k) else 0 endif) + 1}) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( var parity : int ; parity := arr[i+1] mod k ; if ((parity = 0 or parity = k - parity) & map->keys()->includes(parity)) then ( if (map->at(parity) > 1) then ( count := count+(2) ; map := map->union(Map{parity |-> map->at(parity) - 2}) ) else skip ) else if (map->keys()->includes(k - parity)) then ( if (parity /= k - parity) then ( if (map->at(parity) > 0 & map->at(k - parity) > 0) then ( count := count+(2) ; map := map->union(Map{parity |-> map->at(parity) - 1}) ; map := map->union(Map{k - parity |-> map->at(k - parity) - 1}) ) else skip ) else skip ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class practice { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int k=s.nextInt(); int arr[]=new int[n]; for(int i=0 ; itoInteger() ; var k : int ; k := s.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; var res : Sequence(int) ; res := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( ( var a : int ; a := arr[i+1] mod k ; res[a+1] := res[a+1] + 1 ) ; i := i + 1 ) ; var ans : int ; ans := if res[0+1] mod 2 = 0 then res[0+1] else res[0+1] - 1 endif ; var l : int ; l := 1 ; var h : int ; h := k - 1 ; while (l < h) do ( ans := ans+(2 * (Set{res[l+1], res[h+1]}->min())) ; l := l + 1 ; h := h - 1 ) ; if (k mod 2 = 0) then ( var p : int ; p := k / 2 ; ans := ans+(if res[p+1] mod 2 = 0 then res[p+1] else res[p+1] - 1 endif) ) else skip ; OclFile["System.out"].print(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static String check(int[] arr,int n){ int count=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(check(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int s=sc.nextInt(); int n=sc.nextInt(); int[] arr1=new int[n]; int[] arr2=new int[n]; for(int i=0 ; iarr1[i]){ s+=arr2[i]; arr1[i]=arr1[n-1]; arr2[i]=arr2[n-1]; n--; i=-1 ; } } System.out.print(n==0 ? "YES" : "NO"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : int ; s := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr1 : Sequence(int) ; arr1 := Integer.subrange(1,n)->collect(0) ; var arr2 : Sequence(int) ; arr2 := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr1[i+1] := sc.getCurrent()->toInteger() ; arr2[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (s > arr1[i+1]) then ( s := s+(arr2[i+1]) ; arr1[i+1] := arr1[n - 1+1] ; arr2[i+1] := arr2[n - 1+1] ; n := n - 1 ; i := -1 ; ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(if n = 0 then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Code { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int s=sc.nextInt(); int n=sc.nextInt(); int[][] dragons=new int[n][2]; for(int i=0 ; idragons[i][0]){ s+=dragons[i][1]; dragons[i]=dragons[n-1]; n-=1 ; i=-1 ; } } if(n==0){ System.out.print("YES"); } else { System.out.print("NO"); }; } } ------------------------------------------------------------ OCL File: --------- class Code { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : int ; s := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var dragons : Sequence(Sequence(int)) ; dragons := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( dragons[i+1][0+1] := sc.getCurrent()->toInteger() ; dragons[i+1][1+1] := sc.getCurrent()->toInteger() ) ; i := i+(1) ) ; var i : int ; i := 0 ; while i < n do ( ( if (s > dragons[i+1][0+1]) then ( s := s+(dragons[i+1][1+1]) ; dragons[i+1] := dragons[n - 1+1] ; n := n-(1) ; i := -1 ) else skip ) ; i := i+(1) ) ; if (n = 0) then ( OclFile["System.out"].print("YES") ) else ( OclFile["System.out"].print("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ System.out.println(askAndCheck(new Scanner(System.in))? "YES" : "NO"); } public static boolean askAndCheck(Scanner scanner){ String[] firstLine=scanner.nextLine().split(" "); int s=Integer.parseInt(firstLine[0]); int n=Integer.parseInt(firstLine[1]); int[][] numbers=stringToIntMatrix(scanner,n); return isPossibleWin(s,numbers); } private static boolean isPossibleWin(int s,int[][] numbers){ Arrays.sort(numbers,Comparator.comparingInt(o->o[0])); for(int[] xY : numbers){ if(xY[0]>=s){ return false ; } s+=xY[1]; } return true ; } public static int[][] stringToIntMatrix(Scanner scanner,int n){ int[][] array=new int[n][]; for(int i=0 ; isplit(" ") ; var s : int ; s := (firstLine[0+1])->toInteger() ; var n : int ; n := (firstLine[1+1])->toInteger() ; var numbers : Sequence(Sequence(int)) ; numbers := stringToIntMatrix(scanner, n) ; return isPossibleWin(s, numbers) ); static operation isPossibleWin( s : int, numbers : Sequence(Sequence(int))) : boolean pre: true post: true activity: ( numbers := OclComparator.sortWith(numbers, Comparator.comparingInt(lambda o : OclAny in o[0+1])) ; for (xY : numbers) do ( ( if (xY[0+1] >= s) then ( return false ) else skip ; s := s+(xY[1+1]) ) ) ; return true ); static operation stringToIntMatrix( scanner : OclFile, n : int) : Sequence(Sequence(int)) pre: true post: true activity: ( var array : Sequence(Sequence(int)) ; array := Integer.subrange(1,n)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < n do ( ( var numbers : Sequence(String) ; numbers := scanner.nextLine()->split(" ") ; array[i+1] := Sequence{(numbers[0+1])->toInteger(),(numbers[1+1])->toInteger()} ) ; i := i + 1 ) ; return array ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long sumAP(long n,long d){ n/=d ; return(n)*(1+n)*d/2 ; } static long sumMultiples(long n){ n--; return sumAP(n,2)+sumAP(n,5)-sumAP(n,10); } public static void main(String[] args){ long n=20 ; System.out.println(sumMultiples(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumAP( n : long, d : long) : long pre: true post: true activity: ( n := n/(d) ; return (n) * (1 + n) * d / 2 ); static operation sumMultiples( n : long) : long pre: true post: true activity: ( n := n - 1 ; return sumAP(n, 2) + sumAP(n, 5) - sumAP(n, 10) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 20 ; OclFile["System.out"].println(sumMultiples(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class S { public static void main(String[] args){ java.util.Scanner scanner=new java.util.Scanner(System.in); int s=scanner.nextInt(); int n=scanner.nextInt(); Dragon[] dragons=new Dragon[n]; for(int i=0 ; idragons[j+1] .force){ Dragon tmp=dragons[j]; dragons[j]=dragons[j+1]; dragons[j+1]=tmp ; } } } } static class Dragon { public int force ; public int prize ; public Dragon(int force,int prize){ this.force=force ; this.prize=prize ; } } } ------------------------------------------------------------ OCL File: --------- class S { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : Scanner ; scanner := Scanner.newScanner(OclFile["System.in"]) ; var s : int ; s := scanner.nextInt() ; var n : int ; n := scanner.nextInt() ; var dragons : Sequence(Dragon) ; dragons := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < dragons->size() do ( ( var x : int ; x := scanner.nextInt() ; var y : int ; y := scanner.nextInt() ; dragons[i+1] := Dragon.newDragon(x, y) ) ; i := i + 1 ) ; execute sort(dragons) ; for (dragon : dragons) do ( ( if (s <= dragon.force) then ( OclFile["System.out"].println("NO") ; return ) else skip ; s := s+(dragon.prize) ) ) ; OclFile["System.out"].println("YES") ; ); static operation sort( dragons : Sequence(Dragon)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < dragons->size() - 1 do ( ( var j : int ; j := 0 ; while j < dragons->size() - 1 do ( ( if (dragons[j+1].force > dragons[j + 1+1].force) then ( var tmp : Dragon ; tmp := dragons[j+1] ; dragons[j+1] := dragons[j + 1+1] ; dragons[j + 1+1] := tmp ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ); static class Dragon { attribute force : int; attribute prize : int; static operation newDragon( force : int, prize : int) : Dragon pre: true post: true activity: ( var self : Dragon ; self := createDragon(); self.initialise(force, prize); return self ); operation initialise( force : int, prize : int) : void pre: true post: true activity: ( self.force := force ; self.prize := prize ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; class GFG { public static int countOrderedPairs(int[] A,int n){ int orderedPairs=0 ; HashMapm=new HashMap<>(); for(int i=0 ; i=X)orderedPairs++; } } return orderedPairs ; } public static void main(String[] args){ int[] A={ 1,1,2,2,3 }; int n=A.length ; System.out.print(countOrderedPairs(A,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countOrderedPairs( A : Sequence(int), n : int) : int pre: true post: true activity: ( var orderedPairs : int ; orderedPairs := 0 ; var m : Map(int,int) ; m := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (m->at(A[i+1]) = null) then m := m->union(Map{A[i+1] |-> 1}) ; else ( var a : int ; a := m->at(A[i+1]) ; m := m->union(Map{A[i+1] |-> (a + 1)}) ) ) ; i := i + 1 ) ; for (entry : m->keys()) do ( ( var X : int ; X := entry ; var Y : int ; Y := m->at(entry) ; var j : int ; j := 1 ; while j <= Y do ( ( if (m->at(j) >= X) then orderedPairs := orderedPairs + 1 ; else skip ) ; j := j + 1 ) ) ) ; return orderedPairs ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : Sequence(int) ; A := Sequence{1,1,2,2,3} ; var n : int ; n := A->size() ; OclFile["System.out"].print(countOrderedPairs(A, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int minimumflip(int mat[][],int n){ int flip=0 ; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < str->size() do ( if (str->at(i+1) /= ' ') then count[str->at(i+1)->oclAsType(int)+1] := count[str->at(i+1)->oclAsType(int)+1] + 1 ; else skip ; ; i := i + 1 ) ; var n : int ; n := i ; i := 0 ; while i < n do ( if (count[str->at(i+1)->oclAsType(int)+1] = 1) then OclFile["System.out"].print(str->at(i+1)) ; else skip ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "GeeksforGeeks" ; execute printDistinct(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { static final int MAX_X=2000 ; static final int MAX_Y=2000 ; int[][] s=new int[MAX_X][MAX_Y]; void solve(){ for(int i=0 ; icollect(Integer.subrange(1,MAX_Y)->collect(0)); operation solve() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < MAX_X do ( var j : int ; j := 0 ; while j < MAX_Y do ( s[i+1][j+1] := 0 ; ; j := j + 1 ) ; ; i := i + 1 ) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := 0 ; while k < 2 do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; var i : int ; i := x ; while i < x + w do ( var j : int ; j := y ; while j < y + h do ( s[i+1][j+1] := s[i+1][j+1] + 1 ; ; j := j + 1 ) ; ; i := i + 1 ) ; ) ; k := k + 1 ) ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < MAX_X do ( var j : int ; j := 0 ; while j < MAX_Y do ( if (s[i+1][j+1] = 1) then c := c + 1 ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.*; public class Main { static Scanner scan=new Scanner(System.in); public static void main(String[] args){ ListMN=numbers(); Listmn=numbers(); print((MN.get(0)-mn.get(0))*(MN.get(1)-mn.get(1))); } public static Listnumbers(){ Listintegers=new ArrayList<>(); for(String item : getLine().split(" ")){ integers.add(toInt(item)); } return integers ; } public static void add(int[][] a,int[] n,int[] m){ for(int i=0 ; iat(0+1) - mn->at(0+1)) * (MN->at(1+1) - mn->at(1+1))) ); static operation numbers() : Sequence(int) pre: true post: true activity: ( var integers : Sequence(int) ; integers := Sequence{} ; for (item : getLine()->split(" ")) do ( ( integers := integers->including(toInt(item)) ) ) ; return integers ); static operation add( a : Sequence(Sequence(int)), n : Sequence(int), m : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < n->size() do ( skip ; i := i + 1 ) ); static operation sum( a : Sequence(Sequence(int)), n : Sequence(int), m : Sequence(int)) : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n->size() do ( ( var j : int ; j := 0 ; while j < m->size() do ( ( if (n[i+1] = 1 & m[j+1] = 1) then ( sum := sum+(a[i+1][j+1]) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return sum ); static operation getInt() : int pre: true post: true activity: ( return scan.getCurrent()->toInteger() ); static operation getLine() : String pre: true post: true activity: ( return scan.nextLine() ); static operation toInt( str : String) : int pre: true post: true activity: ( return (str)->toInteger() ); static operation toLong( str : String) : long pre: true post: true activity: ( return (str)->toLong() ); static operation print( str : String) : void pre: true post: true activity: ( OclFile["System.out"].println(str) ); static operation print( num : int) : void pre: true post: true activity: ( execute print("" + num) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); AWhiteCells solver=new AWhiteCells(); solver.solve(1,in,out); out.close(); } static class AWhiteCells { public void solve(int testNumber,InputReader in,PrintWriter out){ int W=in.nextInt(); int H=in.nextInt(); int w=in.nextInt(); int h=in.nextInt(); out.print((W-w)*(H-h)); } } static class InputReader implements AutoCloseable { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public void close(){ } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : AWhiteCells ; solver := AWhiteCells.newAWhiteCells() ; solver.solve(1, in, out) ; skip ; ); static class AWhiteCells { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var W : int ; W := in.nextInt() ; var H : int ; H := in.nextInt() ; var w : int ; w := in.nextInt() ; var h : int ; h := in.nextInt() ; skip ; ); } static class InputReader implements AutoCloseable { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation close() : void pre: true post: true activity: skip; } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int height,width,black_height,black_width,area ; height=Integer.parseInt(sc.next()); width=Integer.parseInt(sc.next()); black_height=Integer.parseInt(sc.next()); black_width=Integer.parseInt(sc.next()); area=(height-black_height)*(width-black_width); System.out.println(area); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var height : int ; var width : int ; var black_height : int ; var black_width : int ; var area : int ; height := (sc.getCurrent())->toInteger() ; width := (sc.getCurrent())->toInteger() ; black_height := (sc.getCurrent())->toInteger() ; black_width := (sc.getCurrent())->toInteger() ; area := (height - black_height) * (width - black_width) ; OclFile["System.out"].println(area) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(in); int n=sc.nextInt(); int m=sc.nextInt(); int h=sc.nextInt(); int w=sc.nextInt(); out.println(n*m-h*m-w*n+h*w); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; out.println(n * m - h * m - w * n + h * w) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int row=sc.nextInt(); int column=sc.nextInt(); int blackRow=sc.nextInt(); int blackColumn=sc.nextInt(); int blackCount=(row*blackColumn+column*blackRow)-(blackRow*blackColumn); int allWhite=row*column ; System.out.println(allWhite-blackCount); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var row : int ; row := sc.getCurrent()->toInteger() ; var column : int ; column := sc.getCurrent()->toInteger() ; var blackRow : int ; blackRow := sc.getCurrent()->toInteger() ; var blackColumn : int ; blackColumn := sc.getCurrent()->toInteger() ; var blackCount : int ; blackCount := (row * blackColumn + column * blackRow) - (blackRow * blackColumn) ; var allWhite : int ; allWhite := row * column ; OclFile["System.out"].println(allWhite - blackCount) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); while(t>0){ int n=scan.nextInt(); int s ; int f ; int sum=0 ; for(int i=0 ; itoInteger() ; while (t > 0) do ( var n : int ; n := scan.getCurrent()->toInteger() ; var s : int ; var f : int ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( s := scan.getCurrent()->toInteger() ; f := scan.getCurrent()->toInteger() ; sum := sum+(f - s) ) ; i := i + 1 ) ; if (t <= sum) then ( OclFile["System.out"].println("OK") ) else ( OclFile["System.out"].println(t - sum) ) ; t := scan.getCurrent()->toInteger() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static void divide(int n,int m){ System.out.println("Remainder="+((n)&(m-1))); System.out.println("Quotient="+(n>>(int)(Math.log(m)/Math.log(2)))); } static public void main(String[] args){ int n=43,m=8 ; divide(n,m); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation divide( n : int, m : int) : void pre: true post: true activity: ( OclFile["System.out"].println("Remainder=" + ((n) & (m - 1))) ; OclFile["System.out"].println("Quotient=" + ((n/(2->pow(((m)->log() / (2)->log())->oclAsType(int))))->oclAsType(long))) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 43 ; var m : int ; m := 8 ; execute divide(n, m) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Comparator ; import java.util.Scanner ; public class Solution { public static void main(String[] args){ double threshold=1e-6 ; Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[][] f=new int[n][2]; for(int i=0 ; icomparator=Comparator.comparingInt(o->o[0]); double lo=0 ; double hi=1e9 ; double prev=-1 ; while(lo<=hi){ double mid=lo+(hi-lo)/2 ; boolean can=true ; double min=1e-9 ; double max=1e9 ; for(int i=0 ; i=min || localMax>=min && localMax<=max || localMax>=max && localMin<=min){ max=Math.min(max,localMax); min=Math.max(min,localMin); } else { can=false ; break ; } } if(can){ hi=mid ; if(Math.abs(mid-prev)<=threshold){ break ; } else { prev=mid ; } } else { lo=mid ; } } System.out.println(lo); } } ------------------------------------------------------------ OCL File: --------- class Solution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var threshold : double ; threshold := 1e-6 ; var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var f : Sequence(Sequence(int)) ; f := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( f[i+1][0+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( f[i+1][1+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var comparator : Function(,(,boolean)) ; comparator := Comparator.comparingInt(lambda o : OclAny in o[0+1]) ; var lo : double ; lo := 0 ; var hi : double ; hi := 1e9 ; var prev : double ; prev := -1 ; while (lo <= hi) do ( var mid : double ; mid := lo + (hi - lo) / 2 ; var can : boolean ; can := true ; var min : double ; min := 1e-9 ; var max : double ; max := 1e9 ; var i : int ; i := 0 ; while i < f->size() do ( ( var c : int ; c := f[i+1][0+1] ; var s : int ; s := f[i+1][1+1] ; var localMin : double ; localMin := c - s * mid ; var localMax : double ; localMax := c + s * mid ; if (localMin <= max & localMin >= min or localMax >= min & localMax <= max or localMax >= max & localMin <= min) then ( max := Set{max, localMax}->min() ; min := Set{min, localMin}->max() ) else ( can := false ; break ) ; ) ; i := i + 1 ) ; if (can) then ( hi := mid ; if (if mid - prev < 0 then -(mid - prev) else mid - prev endif <= threshold) then ( break ) else ( prev := mid ) ) else ( lo := mid ) ; ) ; OclFile["System.out"].println(lo) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class MeetingPlace { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); int[] xs=new int[n]; int[] vs=new int[n]; int minx=Integer.MAX_VALUE ; int maxx=0 ; StringTokenizer st=new StringTokenizer(br.readLine()); for(int i=0 ; imaxx)maxx=xs[i]; if(xs[i]maxt)maxt=Math.abs(xs[i]-pos)/vs[i]; return maxt ; } } ------------------------------------------------------------ OCL File: --------- class MeetingPlace { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var xs : Sequence(int) ; xs := Integer.subrange(1,n)->collect(0) ; var vs : Sequence(int) ; vs := Integer.subrange(1,n)->collect(0) ; var minx : int ; minx := 2147483647 ; var maxx : int ; maxx := 0 ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( xs[i+1] := (st.next())->toInteger() ; if (xs[i+1] > maxx) then maxx := xs[i+1] ; else skip ; if (xs[i+1] < minx) then minx := xs[i+1] ; else skip ) ; i := i + 1 ) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( vs[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; var left : double ; left := minx ; var right : double ; right := maxx ; var mid : double ; mid := (left + right) / 2 ; var lt : double ; var rt : double ; var mt : double ; while (true) do ( mt := calcTime(xs, vs, mid) ; lt := calcTime(xs, vs, (left + mid) / 2) ; rt := calcTime(xs, vs, (right + mid) / 2) ; if ((mid - left) / 2 < 1.0e-6) then ( OclFile["System.out"].println(mt) ; break ) else skip ; if (calcTime(xs, vs, mid - 1e-6) < calcTime(xs, vs, mid + 1e-6)) then ( right := mid ; mid := (left + right) / 2 ) else ( left := mid ; mid := (left + right) / 2 ) ; ) ; ); static operation calcTime( xs : Sequence(int), vs : Sequence(int), pos : double) : double pre: true post: true activity: ( var maxt : double ; maxt := 0 ; var i : int ; i := 0 ; while i < xs->size() do ( if (if xs[i+1] - pos < 0 then -(xs[i+1] - pos) else xs[i+1] - pos endif / vs[i+1] > maxt) then maxt := if xs[i+1] - pos < 0 then -(xs[i+1] - pos) else xs[i+1] - pos endif / vs[i+1] ; else skip ; ; i := i + 1 ) ; return maxt ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int distinct(int[] arr,int n){ int count=0 ; if(n==1)return 1 ; for(int i=0 ; isize() ; OclFile["System.out"].println(distinct(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int maxSubArraySumRepeated(int a[],int n,int k){ int max_so_far=0 ; int INT_MIN,max_ending_here=0 ; for(int i=0 ; isize() ; var k : int ; k := 3 ; OclFile["System.out"].println("Maximum contiguous sum is " + maxSubArraySumRepeated(a, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { long gcd(long a,long b){ return b==0 ? a : gcd(b,a % b); } void run(){ Scanner sc=new Scanner(System.in); while(true){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); if((a | b | c)==0)break ; double D=b*b-4*a*c ; if(D<0)System.out.println("Impossible"); else if(D==0){ int A=2*a ; int B=-b ; long g=gcd(Math.abs(A),Math.abs(B)); A/=g ; B/=g ; System.out.println(A+" "+(-B)+" "+A+" "+(-B)); } else { int k=1 ; while(k*k<=D){ if(k*k==D)break ; k++; } if(k*k>D){ System.out.println("Impossible"); continue ; } int P=2*a ; int Q=-b+k ; int R=2*a ; int S=-b-k ; long g=gcd(Math.abs(P),Math.abs(Q)); P/=g ; Q/=g ; g=gcd(Math.abs(R),Math.abs(S)); R/=g ; S/=g ; Q=-Q ; S=-S ; if(P>R ||(P==R && Q>S))System.out.println(P+" "+Q+" "+R+" "+S); else System.out.println(R+" "+S+" "+P+" "+Q); } } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation gcd( a : long, b : long) : long pre: true post: true activity: ( return if b = 0 then a else gcd(b, a mod b) endif ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(MathLib.bitwiseOr(a,b),c)) = 0) then break else skip ; var D : double ; D := b * b - 4 * a * c ; if (D < 0) then OclFile["System.out"].println("Impossible") else if (D = 0) then ( var A : int ; A := 2 * a ; var B : int ; B := -b ; var g : long ; g := gcd(if A < 0 then -(A) else A endif, if B < 0 then -(B) else B endif) ; A := A/(g) ; B := B/(g) ; OclFile["System.out"].println(A + " " + (-B) + " " + A + " " + (-B)) ; ) else ( var k : int ; k := 1 ; while (k * k <= D) do ( if (k * k = D) then break else skip ; k := k + 1 ) ; if (k * k > D) then ( OclFile["System.out"].println("Impossible") ; continue ) else skip ; var P : int ; P := 2 * a ; var Q : int ; Q := -b + k ; var R : int ; R := 2 * a ; var S : int ; S := -b - k ; var g : long ; g := gcd(if P < 0 then -(P) else P endif, if Q < 0 then -(Q) else Q endif) ; P := P/(g) ; Q := Q/(g) ; g := gcd(if R < 0 then -(R) else R endif, if S < 0 then -(S) else S endif) ; R := R/(g) ; S := S/(g) ; Q := -Q ; S := -S ; if (P > R or (P = R & Q > S)) then OclFile["System.out"].println(P + " " + Q + " " + R + " " + S) else OclFile["System.out"].println(R + " " + S + " " + P + " " + Q) ; ; ) ; ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.geom.*; import java.io.*; import java.util.*; public class Main { double EPS=1.0e-08 ; private void doit(){ Scanner sc=new Scanner(System.in); while(true){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); if((a | b | c)==0)break ; int d=b*b-4*a*c ; int e=(int)Math.sqrt(d+EPS); if(e*e!=d){ System.out.println("Impossible"); continue ; } int res1=-b+e ; int res2=-b-e ; int aa=2*a ; int div=gcd(res1,aa); int p=aa/div ; int q=res1/div ; if(p*q<0){ p=Math.abs(p); q=Math.abs(q); } else { p=Math.abs(p); q=Math.abs(q)*-1 ; } int div2=gcd(res2,aa); int r=aa/div2 ; int s=res2/div2 ; if(r*s<0){ r=Math.abs(r); s=Math.abs(s); } else { r=Math.abs(r); s=Math.abs(s)*-1 ; } if(p>r ||(p==r && q>=s)){ System.out.printf("%d %d %d %d\n",p,q,r,s); } else { System.out.printf("%d %d %d %d\n",r,s,p,q); } } } private int gcd(int a,int b){ if(b==0)return a ; else return gcd(b,a % b); } private void debug(Object...o){ System.out.println("debug="+Arrays.deepToString(o)); } public static void main(String[] args){ new Main().doit(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute EPS : double := 1.0e-08; operation doit() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(MathLib.bitwiseOr(a,b),c)) = 0) then break else skip ; var d : int ; d := b * b - 4 * a * c ; var e : int ; e := (d + EPS)->sqrt()->oclAsType(int) ; if (e * e /= d) then ( OclFile["System.out"].println("Impossible") ; continue ) else skip ; var res1 : int ; res1 := -b + e ; var res2 : int ; res2 := -b - e ; var aa : int ; aa := 2 * a ; var div : int ; div := gcd(res1, aa) ; var p : int ; p := aa / div ; var q : int ; q := res1 / div ; if (p * q < 0) then ( p := if p < 0 then -(p) else p endif ; q := if q < 0 then -(q) else q endif ) else ( p := if p < 0 then -(p) else p endif ; q := if q < 0 then -(q) else q endif * -1 ) ; var div2 : int ; div2 := gcd(res2, aa) ; var r : int ; r := aa / div2 ; var s : int ; s := res2 / div2 ; if (r * s < 0) then ( r := if r < 0 then -(r) else r endif ; s := if s < 0 then -(s) else s endif ) else ( r := if r < 0 then -(r) else r endif ; s := if s < 0 then -(s) else s endif * -1 ) ; if (p > r or (p = r & q >= s)) then ( OclFile["System.out"].printf("%d %d %d %d\n", p, q, r, s) ) else ( OclFile["System.out"].printf("%d %d %d %d\n", r, s, p, q) ) ; ) ); operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (b = 0) then return a else return gcd(b, a mod b) ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println("debug=" + (o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static long SubArraySum(int arr[],int n){ long result=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println("Sum of SubArray " + SubArraySum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static long SubArraySum(int arr[],int n){ long result=0,temp=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println("Sum of SubArray : " + SubArraySum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; class GFG { public static void checkType(int arr[],int n){ if(arr[0]<=arr[1] && arr[n-2]<=arr[n-1])System.out.println("Increasing"); else if(arr[0]>=arr[1] && arr[n-2]>=arr[n-1])System.out.println("Decreasing"); else if(arr[0]<=arr[1] && arr[n-2]>=arr[n-1])System.out.println("Increasing then decreasing"); else System.out.println("Decreasing then increasing"); } public static void main(String[] args){ int[] arr=new int[] { 1,2,3,4 }; int n=arr.length ; checkType(arr,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkType( arr : Sequence(int), n : int) : void pre: true post: true activity: ( if (arr[0+1] <= arr[1+1] & arr[n - 2+1] <= arr[n - 1+1]) then OclFile["System.out"].println("Increasing") ; else if (arr[0+1] >= arr[1+1] & arr[n - 2+1] >= arr[n - 1+1]) then OclFile["System.out"].println("Decreasing") else if (arr[0+1] <= arr[1+1] & arr[n - 2+1] >= arr[n - 1+1]) then OclFile["System.out"].println("Increasing then decreasing") else OclFile["System.out"].println("Decreasing then increasing") ; ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4} ; var n : int ; n := arr->size() ; execute checkType(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int maxOnesIndex(boolean arr[],int n){ int start=0 ; int end=0 ; int maxIndex=-1 ; int lastInd=-1 ; int maxCnt=0 ; while(endsize() ; OclFile["System.out"].println("Index of 0 to be replaced is " + maxOnesIndex(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.Map ; public class TokitsukazeAndAllZeroSequence { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t>0){ int n=Integer.parseInt(br.readLine()); int[] a=new int[n]; String[] str=br.readLine().split(" "); for(int i=0 ; imp=new HashMap<>(); for(int i=0 ; i0 || nonZeroUnique+zeroCounttoInteger() ; while (t > 0) do ( var n : int ; n := (br.readLine())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (str[i+1])->toInteger() ; ; i := i + 1 ) ; var mp : Map(int,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (mp->keys()->includes(a[i+1])) then mp := mp->union(Map{a[i+1] |-> mp->at(a[i+1]) + 1}) ; else mp := mp->union(Map{a[i+1] |-> 1}) ; ) ; i := i + 1 ) ; var operations : int ; operations := 0 ; var nonZeroUnique : int ; nonZeroUnique := 0 ; for (key : mp->keys()) do ( ( if (key /= 0) then ( var cnt : int ; cnt := mp->at(key) ; if (cnt = 1) then ( nonZeroUnique := nonZeroUnique+(1) ) else ( operations := operations+(cnt) ) ) else skip ) ) ; var zeroCount : int ; zeroCount := (if mp->keys()->contains(0) then mp->at(0) else 0 endif) ; if (zeroCount > 0 or nonZeroUnique + zeroCount < n) then ( operations := operations+(nonZeroUnique) ) else ( operations := operations+(nonZeroUnique + 1) ) ; OclFile["System.out"].println(operations) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.Map ; public class TokitsukazeAndAllZeroSequence { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t>0){ int n=Integer.parseInt(br.readLine()); int[] a=new int[n]; String[] str=br.readLine().split(" "); for(int i=0 ; imp=new HashMap<>(); for(int i=0 ; i0 || nonZeroUnique+zeroCounttoInteger() ; while (t > 0) do ( var n : int ; n := (br.readLine())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (str[i+1])->toInteger() ; ; i := i + 1 ) ; var mp : Map(int,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (mp->keys()->includes(a[i+1])) then mp := mp->union(Map{a[i+1] |-> mp->at(a[i+1]) + 1}) ; else mp := mp->union(Map{a[i+1] |-> 1}) ; ) ; i := i + 1 ) ; var operations : int ; operations := 0 ; var nonZeroUnique : int ; nonZeroUnique := 0 ; for (key : mp->keys()) do ( ( if (key /= 0) then ( var cnt : int ; cnt := mp->at(key) ; if (cnt = 1) then ( nonZeroUnique := nonZeroUnique+(1) ) else ( operations := operations+(cnt) ) ) else skip ) ) ; var zeroCount : int ; zeroCount := if mp->keys()->includes(0) then mp->at(0) else 0 endif ; if (zeroCount > 0 or nonZeroUnique + zeroCount < n) then ( operations := operations+(nonZeroUnique) ) else ( operations := operations+(nonZeroUnique + 1) ) ; OclFile["System.out"].println(operations) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class ProblemA { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; imp=new HashMap<>(); boolean flag=false ; for(Integer val : a){ if(mp.containsKey(val)){ mp.put(val,mp.get(val)+1); flag=true ; } else { mp.put(val,1); } } Integer ans=n+1 ; if(mp.containsKey(0)){ ans=ans-mp.get(0)-1 ; } else if(flag){ ans=n ; } System.out.println(ans); t--; } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class ProblemA { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var mp : Map(int,int) ; mp := Map{} ; var flag : boolean ; flag := false ; for (val : a) do ( ( if (mp->keys()->includes(val)) then ( mp := mp->union(Map{val |-> mp->at(val) + 1}) ; flag := true ) else ( mp := mp->union(Map{val |-> 1}) ) ) ) ; var ans : int ; ans := n + 1 ; if (mp->keys()->includes(0)) then ( ans := ans - mp->at(0) - 1 ) else if (flag) then ( ans := n ) else skip ; ; OclFile["System.out"].println(ans) ; t := t - 1 ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Test { static int x=32 ; static String toggleCase(char[] a){ for(int i=0 ; isize() do ( ( a[i+1] := MathLib.bitwiseXor(a[i+1],32) ) ; i := i + 1 ) ; return StringLib.newString(a) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "CheRrY" ; OclFile["System.out"].print("Toggle case: ") ; str := toggleCase(str->characters()) ; OclFile["System.out"].println(str) ; OclFile["System.out"].print("Original string: ") ; str := toggleCase(str->characters()) ; OclFile["System.out"].println(str) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static boolean[][] domino=new boolean[7][7]; static int[] count=new int[7]; static int N ; public static void main(String[] args)throws Exception { while(sc.hasNext()){ N=sc.nextInt(); for(boolean[] a : domino){ Arrays.fill(a,false); } Arrays.fill(count,0); for(int i=0 ; icollect(Integer.subrange(1,7)->collect(false)); static attribute count : Sequence(int) := Integer.subrange(1,7)->collect(0); static attribute N : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (sc.hasNext()) do ( N := sc.getCurrent()->toInteger() ; for (a : domino) do ( ( a := a->collect(false) ) ) ; count := count->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( var v : String ; v := sc.getCurrent() ; var f : int ; f := v->at(0+1) - ('0')->char2byte() ; var s : int ; s := v->at(1+1) - ('0')->char2byte() ; domino[f+1][s+1] := true ; count[f+1] := count[f+1] + 1 ; count[s+1] := count[s+1] + 1 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(if solve() then "Yes" else "No" endif) ; ) ); static operation solve() : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < 7 do ( ( if (solve(i, 0)) then ( return true ) else skip ) ; i := i + 1 ) ; return false ); static operation solve( first : int, depth : int) : boolean pre: true post: true activity: ( if (depth = N) then return true else skip ; if (count[first+1] = 0) then return false else skip ; var odd : int ; odd := 0 ; var i : int ; i := 0 ; while i < 7 do ( ( if (count[i+1] mod 2 /= 0) then odd := odd + 1 ; else skip ) ; i := i + 1 ) ; if (not((odd = 0 or (odd = 2 & count[first+1] mod 2 /= 0)))) then return false else skip ; var i : int ; i := 0 ; while i < 7 do ( ( var r : int ; r := Set{i, first}->min() ; var c : int ; c := Set{i, first}->max() ; if (domino[r+1][c+1]) then ( domino[r+1][c+1] := false ; count[r+1] := count[r+1] - 1 ; count[c+1] := count[c+1] - 1 ; if (solve(i, depth + 1)) then return true else skip ; count[c+1] := count[c+1] + 1 ; count[r+1] := count[r+1] + 1 ; domino[r+1][c+1] := true ; ) else skip ) ; i := i + 1 ) ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printArray(int arr[],int n){ for(int i=0 ; i=0 ; i--)suffixMax[i]=Math.max(arr[i],suffixMax[i+1]); int minSoFar=arr[0]; arr[0]=suffixMax[1]; for(int i=1 ; icollect(0) ; suffixMax[n - 1+1] := arr[n - 1+1] ; var i : int ; i := n - 2 ; while i >= 0 do ( suffixMax[i+1] := Set{arr[i+1], suffixMax[i + 1+1]}->max() ; ; i := i - 1 ) ; var minSoFar : int ; minSoFar := arr[0+1] ; arr[0+1] := suffixMax[1+1] ; var i : int ; i := 1 ; while i < n - 1 do ( ( var temp : int ; temp := arr[i+1] ; arr[i+1] := if suffixMax[i + 1+1] - minSoFar < 0 then -(suffixMax[i + 1+1] - minSoFar) else suffixMax[i + 1+1] - minSoFar endif ; minSoFar := Set{minSoFar, temp}->min() ) ; i := i + 1 ) ; arr[n - 1+1] := minSoFar ; execute printArray(arr, n) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,5,2,4,3} ; var n : int ; n := arr->size() ; execute generateArr(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Char_frequency { static final int SIZE=26 ; static void printCharWithFreq(String str){ int n=str.length(); int[] freq=new int[SIZE]; for(int i=0 ; isize() ; var freq : Sequence(int) ; freq := Integer.subrange(1,SIZE)->collect(0) ; var i : int ; i := 0 ; while i < n do ( freq[str->at(i+1) - ('a')->char2byte()+1] := freq[str->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (freq[str->at(i+1) - ('a')->char2byte()+1] /= 0) then ( OclFile["System.out"].print(str->at(i+1)) ; OclFile["System.out"].print(freq[str->at(i+1) - ('a')->char2byte()+1] + " ") ; freq[str->at(i+1) - ('a')->char2byte()+1] := 0 ) else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; execute printCharWithFreq(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.nio.Buffer ; import java.util.*; public class Main2 { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int testCases=sc.nextInt(); while(testCases-->0){ int length=sc.nextInt(); int[] array=new int[length]; for(int i=0 ; i1){ found=true ; System.out.println("yes"); System.out.println((i+1)+" "+(i+2)); break ; } } if(! found){ System.out.println("no"); } } } } ------------------------------------------------------------ OCL File: --------- class Main2 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var testCases : int ; testCases := sc.getCurrent()->toInteger() ; while (testCases > 0) do ( testCases := testCases - 1 ; skip ; ( var length : int ; length := sc.getCurrent()->toInteger() ; var array : Sequence(int) ; array := Integer.subrange(1,length)->collect(0) ; var i : int ; i := 0 ; while i < length do ( ( array[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var found : boolean ; found := false ; var i : int ; i := 0 ; while i < length - 1 do ( ( var diff : int ; diff := if array[i+1] - array[i + 1+1] < 0 then -(array[i+1] - array[i + 1+1]) else array[i+1] - array[i + 1+1] endif ; if (diff > 1) then ( found := true ; OclFile["System.out"].println("yes") ; OclFile["System.out"].println((i + 1) + " " + (i + 2)) ; break ) else skip ) ; i := i + 1 ) ; if (not(found)) then ( OclFile["System.out"].println("no") ) else skip ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Interesting { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; i1){ flag=true ; l=j ; } } if(l==0){ System.out.println("NO"); } else { System.out.println("YES"); System.out.println(l+" "+(l+1)); } } } } ------------------------------------------------------------ OCL File: --------- class Interesting { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var flag : boolean ; flag := false ; var l : int ; l := 0 ; a[0+1] := sc.getCurrent()->toInteger() ; var j : int ; j := 1 ; while j < n do ( ( a[j+1] := sc.getCurrent()->toInteger() ; if (if a[j+1] - a[j - 1+1] < 0 then -(a[j+1] - a[j - 1+1]) else a[j+1] - a[j - 1+1] endif > 1) then ( flag := true ; l := j ) else skip ) ; j := j + 1 ) ; if (l = 0) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ; OclFile["System.out"].println(l + " " + (l + 1)) ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; while(!(line=br.readLine().trim()).equals("0")&& ! line.isEmpty()){ int goal=Integer.parseInt(line); int times=Integer.parseInt(br.readLine().trim()); int sum=0 ; for(int i=0 ; i=goal ? "OK" : goal-sum); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := "" ; while (not((line) = "0") & not(line->isEmpty())) do ( var goal : int ; goal := (line)->toInteger() ; var times : int ; times := (br.readLine()->trim())->toInteger() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < times do ( ( line := br.readLine()->trim() ; var s : int ; s := (line.subrange(0+1,line->indexOf(' ')-1))->toInteger() ; var f : int ; f := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1))->toInteger() ; sum := sum+(f - s) ) ; i := i + 1 ) ; OclFile["System.out"].println(if sum >= goal then "OK" else (goal)->char2byte() - sum endif) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; i=2){ System.out.println("YES"); System.out.println(i+" "+(i+1)); flag=true ; break ; } } if(! flag){ System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := sc.getCurrent()->toInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var flag : boolean ; flag := false ; var i : int ; i := 1 ; while i < n do ( ( if (if arr[i+1] - arr[i - 1+1] < 0 then -(arr[i+1] - arr[i - 1+1]) else arr[i+1] - arr[i - 1+1] endif >= 2) then ( OclFile["System.out"].println("YES") ; OclFile["System.out"].println(i + " " + (i + 1)) ; flag := true ; break ) else skip ) ; i := i + 1 ) ; if (not(flag)) then ( OclFile["System.out"].println("NO") ) else skip ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p160 implements EulerSolution { public static void main(String[] args){ System.out.println(new p160().run()); } public String run(){ return Long.toString(factorialSuffix(1000000000000L)); } private static long factorialSuffix(long n){ long twos=countFactors(n,2)-countFactors(n,5); if(twos>=2505)twos=(twos-5)% 2500+5 ; return factorialish(n)*Library.powMod(2,(int)twos,100000)% 100000 ; } private static long factorialish(long n){ return evenFactorialish(n)*oddFactorialish(n)% 100000 ; } private static long evenFactorialish(long n){ if(n==0)return 1 ; else return factorialish(n/2); } private static long oddFactorialish(long n){ if(n==0)return 1 ; else return oddFactorialish(n/5)*factorialCoprime(n)% 100000 ; } private static long factorialCoprime(long n){ n %=100000 ; long product=1 ; for(int i=1 ; i<=n ; i++){ if(i % 2!=0 && i % 5!=0)product=i*product % 100000 ; } return product ; } private static long countFactors(long end,long n){ if(end==0)return 0 ; else return end/n+countFactors(end/n,n); } } ------------------------------------------------------------ OCL File: --------- class p160 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p160.newp160().run()) ); operation run() : String pre: true post: true activity: ( return ((factorialSuffix(1000000000000L)) + "") ); static operation factorialSuffix( n : long) : long pre: true post: true activity: ( var twos : long ; twos := countFactors(n, 2) - countFactors(n, 5) ; if (twos >= 2505) then twos := (twos - 5) mod 2500 + 5 ; else skip ; return factorialish(n) * Library.powMod(2, twos->oclAsType(int), 100000) mod 100000 ); static operation factorialish( n : long) : long pre: true post: true activity: ( return evenFactorialish(n) * oddFactorialish(n) mod 100000 ); static operation evenFactorialish( n : long) : long pre: true post: true activity: ( if (n = 0) then return 1 else return factorialish(n / 2) ); static operation oddFactorialish( n : long) : long pre: true post: true activity: ( if (n = 0) then return 1 else return oddFactorialish(n / 5) * factorialCoprime(n) mod 100000 ); static operation factorialCoprime( n : long) : long pre: true post: true activity: ( n := n mod 100000 ; var product : long ; product := 1 ; var i : int ; i := 1 ; while i <= n do ( ( if (i mod 2 /= 0 & i mod 5 /= 0) then product := i * product mod 100000 ; else skip ) ; i := i + 1 ) ; return product ); static operation countFactors( end : long, n : long) : long pre: true post: true activity: ( if (end = 0) then return 0 else return end / n + countFactors(end / n, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; public class Word_Correction { public static void main(String[] args)throws Exception { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(reader.readLine()); String v="aeiouy" ; char[] str=(reader.readLine()).toCharArray(); String res="" ; boolean lastChResIsV=false ; for(int i=0 ; itoInteger() ; var v : String ; v := "aeiouy" ; var str : Sequence(String) ; str := (reader.readLine())->characters() ; var res : String ; res := "" ; var lastChResIsV : boolean ; lastChResIsV := false ; var i : int ; i := 0 ; while i < n do ( ( res := res+(if (not(v->includes(str[i+1] + "")) or not(lastChResIsV)) then str[i+1] else "" endif) ; lastChResIsV := if v->includes(str[i+1] + "") then true else false endif ) ; i := i + 1 ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class WordCorrection { public static void main(String[] args){ try { BufferedReader pf=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(pf.readLine()); String y=pf.readLine(); char v ; int count=0 ; int count2=0 ; String word="" ; for(int i=0 ; i=2){ count2=0 ; } else { word=word+y.charAt(i); } } else { word=word+y.charAt(i); count=0 ; count2=0 ; } } System.out.println(word); } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class WordCorrection { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var pf : OclFile ; pf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (pf.readLine())->toInteger() ; var y : String ; y := pf.readLine() ; var v : String ; var count : int ; count := 0 ; var count2 : int ; count2 := 0 ; var word : String ; word := "" ; var i : int ; i := 0 ; while i < n do ( ( v := y->at(i+1) ; if (v = 'a' or v = 'e' or v = 'y' or v = 'i' or v = 'o' or v = 'u') then ( count := count + 1 ; count2 := count2 + 1 ; if (count = 2) then ( count := 0 ) else if (count2 >= 2) then ( count2 := 0 ) else ( word := word + y->at(i+1) ) ; ) else ( word := word + y->at(i+1) ; count := 0 ; count2 := 0 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(word) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; public class P3_word_correction { public static boolean vowels(char c){ return((c=='a')||(c=='e')||(c=='u')||(c=='i')||(c=='y')||(c=='o')); } public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(reader.readLine()); String word=reader.readLine(); int count=0 ; for(int i=0 ; itoInteger() ; var word : String ; word := reader.readLine() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < word->size() do ( ( if (vowels(word->at(i+1))) then ( count := count + 1 ; if (count <= 1) then ( skip ) else skip ) else ( count := 0 ; skip ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; public class P3_word_correction { public static boolean vowels(char c){ return((c=='a')||(c=='e')||(c=='u')||(c=='i')||(c=='y')||(c=='o')); } public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(reader.readLine()); String word=reader.readLine(); int count=0 ; for(int i=0 ; itoInteger() ; var word : String ; word := reader.readLine() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < word->size() do ( ( if (vowels(word->at(i+1))) then ( count := count + 1 ; if (count <= 1) then ( skip ) else skip ) else ( count := 0 ; skip ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.*; public class CP23 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n1=sc.nextInt(); int k=0,i=1 ; while(n1>k){ k=k+i ; n1=n1-k ; if(n1>=0)i++; } System.out.println(i-1); } } ------------------------------------------------------------ OCL File: --------- class CP23 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n1 : int ; n1 := sc.getCurrent()->toInteger() ; var k : int ; k := 0 ; var i : int ; i := 1 ; while (n1 > k) do ( k := k + i ; n1 := n1 - k ; if (n1 >= 0) then i := i + 1 ; else skip ) ; OclFile["System.out"].println(i - 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static int N ; public static int[] arr ; public static void main(String[] args)throws Exception { Scanner in=new Scanner(System.in); while(in.hasNextInt()){ N=in.nextInt(); arr=new int[N]; boolean[] visited=new boolean[N]; for(int i=0 ; itoInteger() ; arr := Integer.subrange(1,N)->collect(0) ; var visited : Sequence(boolean) ; visited := Integer.subrange(1,N)->collect(false) ; var i : int ; i := 0 ; while i < N do ( ( arr[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var found : boolean ; found := false ; var i : int ; i := 0 ; while i < N & not(found) do ( ( visited[i+1] := true ; found := found or recursive(0, arr[i+1] mod 10, visited, 1) or recursive(0, arr[i+1] / 10, visited, 1) ; visited[i+1] := false ) ; i := i + 1 ) ; if (found) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ) ); static operation recursive( pos : int, n : int, visited : Sequence(boolean), len : int) : boolean pre: true post: true activity: ( if (len = N) then return true else skip ; if (pos = N) then return false else skip ; var ret : boolean ; ret := false ; var a : int ; a := arr[pos+1] mod 10 ; var b : int ; b := arr[pos+1] / 10 ; var newNum : int ; newNum := if a = n then b else a endif ; if (visited[pos+1]) then return recursive(pos + 1, n, visited, len) else skip ; if (a /= n & b /= n) then return recursive(pos + 1, n, visited, len) else skip ; visited[pos+1] := true ; ret := ret or recursive(0, newNum, visited, len + 1) ; visited[pos+1] := false ; ret := ret or recursive(pos + 1, n, visited, len) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.InputStreamReader ; import java.io.OutputStreamWriter ; public class AWordCorrection { @ SuppressWarnings("empty-statement")public static void main(String[] args)throws Exception { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); String vowels="aeiouy" ; int n=Integer.parseInt(reader.readLine()); String word=reader.readLine(); int count=0 ; for(int i=0 ; itoInteger() ; var word : String ; word := reader.readLine() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (vowels->includes("" + word->at(i+1))) then ( count := count + 1 ; if (count <= 1) then skip ; else skip ) else ( count := 0 ; skip ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args)throws Exception { nint(); int q=nint(); TreeMapmap=new TreeMap<>(); map.put(-1,Integer.MAX_VALUE); while(q-->0){ int command=nint(); if(command==0){ int s=nint(); int t=nint(); int x=nint(); int rightValue=map.floorEntry(t+1).getValue(); map.subMap(s,t+1).clear(); map.put(s,x); map.put(t+1,rightValue); } else { int i=nint(); System.out.println(map.floorEntry(i).getValue()); } } } static int nint(){ return Integer.parseInt(sc.next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute nint() ; var q : int ; q := nint() ; var map : Map(int,int) ; map := Map{} ; map := map->union(Map{-1 |-> 2147483647}) ; while (q > 0) do ( q := q - 1 ; skip ; ( var command : int ; command := nint() ; if (command = 0) then ( var s : int ; s := nint() ; var t : int ; t := nint() ; var x : int ; x := nint() ; var rightValue : int ; rightValue := map.floorEntry(t + 1).getValue() ; map := map->restrict( _key | _key < t + 1 & _key >= s )->intersection(Set{}) ; map := map->union(Map{s |-> x}) ; map := map->union(Map{t + 1 |-> rightValue}) ; ) else ( var i : int ; i := nint() ; OclFile["System.out"].println(map.floorEntry(i).getValue()) ) ) ; ) ; ); static operation nint() : int pre: true post: true activity: ( return (sc.getCurrent())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner kbd=new Scanner(System.in); public static void main(String[] args){ while(kbd.hasNext()){ int t=kbd.nextInt(); if(t!=0){ solve(t); } } } static void solve(int t){ int dotime=0 ; int n=kbd.nextInt(); while(n>0){ int a=kbd.nextInt(); int b=kbd.nextInt(); dotime+=(b-a); n--; } if(dotime>=t)System.out.println("OK"); else System.out.println(t-dotime); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute kbd : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (kbd.hasNext()) do ( var t : int ; t := kbd.getCurrent()->toInteger() ; if (t /= 0) then ( execute solve(t) ) else skip ) ); static operation solve( t : int) : void pre: true post: true activity: ( var dotime : int ; dotime := 0 ; var n : int ; n := kbd.getCurrent()->toInteger() ; while (n > 0) do ( var a : int ; a := kbd.getCurrent()->toInteger() ; var b : int ; b := kbd.getCurrent()->toInteger() ; dotime := dotime+((b - a)) ; n := n - 1 ) ; if (dotime >= t) then OclFile["System.out"].println("OK") ; else OclFile["System.out"].println(t - dotime) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.TreeMap ; public class Main { Scanner sc=new Scanner(System.in); public static void main(String[] args)throws Exception { new Main().run(); } void run(){ nint(); int q=nint(); TreeMapmap=new TreeMap<>(); map.put(-1,Integer.MAX_VALUE); while(q-->0){ int cmd=nint(); if(cmd==0){ int s=nint(); int t=nint(); int x=nint(); Integer rightValue=map.floorEntry(t+1).getValue(); map.subMap(s,t+1).clear(); map.put(s,x); map.put(t+1,rightValue); } else { int i=nint(); System.out.println(map.floorEntry(i).getValue()); } } } int nint(){ return Integer.parseInt(sc.next()); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( execute nint() ; var q : int ; q := nint() ; var map : Map(int,int) ; map := Map{} ; map := map->union(Map{-1 |-> 2147483647}) ; while (q > 0) do ( q := q - 1 ; skip ; ( var cmd : int ; cmd := nint() ; if (cmd = 0) then ( var s : int ; s := nint() ; var t : int ; t := nint() ; var x : int ; x := nint() ; var rightValue : int ; rightValue := map.floorEntry(t + 1).getValue() ; map := map->restrict( _key | _key < t + 1 & _key >= s )->intersection(Set{}) ; map := map->union(Map{s |-> x}) ; map := map->union(Map{t + 1 |-> rightValue}) ; ) else ( var i : int ; i := nint() ; OclFile["System.out"].println(map.floorEntry(i).getValue()) ) ) ; ) ; ); operation nint() : int pre: true post: true activity: ( return (sc.getCurrent())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean checkSame(int n){ int set=0 ; int unset=0 ; while(n>0){ if((n & 1)==1)set++; else unset++; n=n>>1 ; } if(set==unset)return true ; else return false ; } public static void main(String[] args){ int n=12 ; if(checkSame(n))System.out.println("YES"); else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkSame( n : int) : boolean pre: true post: true activity: ( var set : int ; set := 0 ; var unset : int ; unset := 0 ; while (n > 0) do ( if ((n & 1) = 1) then set := set + 1 else unset := unset + 1 ; ; n := (n/(2->pow(1)))->oclAsType(long) ) ; if (set = unset) then return true else return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12 ; if (checkSame(n)) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class solution { static void CountPair(int L,int R){ int x=(R-L+1); System.out.println(x/2+"\n"); } public static void main(String args[]){ int L,R ; L=1 ; R=8 ; CountPair(L,R); } } ------------------------------------------------------------ OCL File: --------- class solution { static operation CountPair( L : int, R : int) : void pre: true post: true activity: ( var x : int ; x := (R - L + 1) ; OclFile["System.out"].println(x / 2 + "\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; var R : int ; L := 1 ; R := 8 ; execute CountPair(L, R) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int MOD=1000000007 ; static int number_of_ways(int arr[],int n,int k){ if(k==1)return 1 ; int dp[]=new int[k+1]; int i ; for(i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < k + 1 do ( dp[i+1] := -1 ; ; i := i + 1 ) ; i := 0 ; while i < n do ( dp[arr[i+1]+1] := 0 ; ; i := i + 1 ) ; dp[0+1] := 1 ; dp[1+1] := if (dp[1+1] = -1) then 1 else dp[1+1] endif ; i := 2 ; while i <= k 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 ) ; i := i + 1 ) ; return dp[k+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3} ; var n : int ; n := arr->size() ; var k : int ; k := 6 ; OclFile["System.out"].println(number_of_ways(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); for(int x=0 ; xlist=new ArrayList(); for(int i=0 ; i'9'))c=System.in.read(); if(c=='-')return-nextInt(); int res=0 ; while(c>='0' && c<='9'){ res=res*10+c-'0' ; c=System.in.read(); } return res ; } catch(IOException e){ e.printStackTrace(); } return-1 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var x : int ; x := 0 ; while x < n do ( ( var query : String ; query := scanner.getCurrent() ; var list : Sequence(String) ; list := Sequence{} ; var i : int ; i := 0 ; while i < query->size() - 1 do ( ( var top : String ; top := StringLib.newString(query.subrange(0+1,i + 1)) ; var bottom : String ; bottom := StringLib.newString(query.subrange(i + 1+1,query->size())) ; var tops : Sequence(String) ; tops := Integer.subrange(1,2)->collect(null) ; tops[0+1] := top+"" ; tops[1+1] := top->reverse()+"" ; var bottoms : Sequence(String) ; bottoms := Integer.subrange(1,2)->collect(null) ; bottoms[0+1] := bottom+"" ; bottoms[1+1] := bottom->reverse()+"" ; var j : int ; j := 0 ; while j < tops->size() do ( ( var j2 : int ; j2 := 0 ; while j2 < bottoms->size() do ( ( var sequence0 : String ; sequence0 := tops[j+1] + bottoms[j2+1] ; var sequence1 : String ; sequence1 := bottoms[j2+1] + tops[j+1] ; if (not(list->includes(sequence0))) then ( list := list->including(sequence0) ) else skip ; if (not(list->includes(sequence1))) then ( list := list->including(sequence1) ) else skip ) ; j2 := j2 + 1 ) ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(list->size()) ) ; x := x + 1 ) ); static operation nextInt() : int pre: true post: true activity: ( var c : int ; try ( c := OclFile["System.in"].read() ; while (c /= '-' & (c < '0' or c > '9')) do c := OclFile["System.in"].read() ; ; if (c = '-') then return -nextInt() else skip ; var res : int ; res := 0 ; while (c >= '0' & c <= '9') do ( res := res * 10 + c - ('0')->char2byte() ; c := OclFile["System.in"].read() ) ; return res ) catch (e : IOException) do ( e.printStackTrace() ) return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int a=Integer.parseInt(br.readLine()); String[] b=new String[1000]; for(int i=0 ; iset=new HashSet(); for(int k=0 ; k<(str.length()-1)*8 ; k++){ set.add(b[k]); } Iterator it=set.iterator(); System.out.println(set.size()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var a : int ; a := (br.readLine())->toInteger() ; var b : Sequence(String) ; b := Integer.subrange(1,1000)->collect(null) ; var i : int ; i := 0 ; while i < a do ( ( var str : String ; str := br.readLine() ; var j : int ; j := 0 ; var Len : int ; Len := 1 ; while Len < str->size() do ( ( var str2 : String ; str2 := str.subrange(0+1,Len) ; var str3 : String ; str3 := str.subrange(Len+1,str->size()) ; var str4 : String ; str4 := StringLib.newString(str2) ; str4 := str4->reverse() ; var rev : String ; rev := StringLib.newString(str4) ; var str5 : String ; str5 := StringLib.newString(str3) ; str5 := str5->reverse() ; var rev2 : String ; rev2 := StringLib.newString(str5) ; b[j+1] := str2 + str3 ; b[j + 1+1] := str2 + rev2 ; b[j + 2+1] := rev + str3 ; b[j + 3+1] := rev + rev2 ; var rev3 : String ; rev3 := StringLib.newString(b[j+1]) ; rev3 := rev3->reverse() ; b[j + 4+1] := StringLib.newString(rev3) ; var rev4 : String ; rev4 := StringLib.newString(b[j + 1+1]) ; rev4 := rev4->reverse() ; b[j + 5+1] := StringLib.newString(rev4) ; var rev5 : String ; rev5 := StringLib.newString(b[j + 2+1]) ; rev5 := rev5->reverse() ; b[j + 6+1] := StringLib.newString(rev5) ; var rev6 : String ; rev6 := StringLib.newString(b[j + 3+1]) ; rev6 := rev6->reverse() ; b[j + 7+1] := StringLib.newString(rev6) ; j := j + 8 ; ) ; Len := Len + 1 ) ; var set : Set(String) ; set := Set{} ; var k : int ; k := 0 ; while k < (str->size() - 1) * 8 do ( ( set := set->including(b[k+1]) ) ; k := k + 1 ) ; var it : OclIterator ; it := set->iterator() ; OclFile["System.out"].println(set->size()) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); PrintWriter pr=new PrintWriter(System.out); int m=sc.nextInt(); while(m-->0){ String t=sc.next(); if(t.length()==1)pr.println(1); Settrain=new HashSet(); train.add(t); for(int k=0 ; ktoInteger() ; while (m > 0) do ( m := m - 1 ; skip ; ( var t : String ; t := sc.getCurrent() ; if (t->size() = 1) then skip ; else skip ; var train : Set(String) ; train := Set{} ; train := train->including(t) ; var k : int ; k := 0 ; while k < t->size() do ( ( var d1 : String ; d1 := t.subrange(0+1,k) ; var d2 : String ; d2 := t.subrange(k+1,t->size()) ; var sb1 : String ; sb1 := StringLib.newString(d1) ; var sb2 : String ; sb2 := StringLib.newString(d2) ; var rd1 : String ; rd1 := sb1->reverse()+"" ; var rd2 : String ; rd2 := sb2->reverse()+"" ; train := train->including(d2 + d1) ; train := train->including(d1 + rd2) ; train := train->including(rd2 + d1) ; train := train->including(rd1 + d2) ; train := train->including(d2 + rd1) ; train := train->including(rd1 + rd2) ; train := train->including(rd2 + rd1) ; ) ; k := k + 1 ) ; skip ; ) ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.HashSet ; import java.util.List ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null && ! line.isEmpty()){ int n=Integer.parseInt(line); for(int i=0 ; itrains=new HashSet(); line=br.readLine(); for(String train : organize(line)){ if(! trains.contains(train))trains.add(train); } System.out.println(trains.size()); } } } static Listorganize(String line){ Listos=new ArrayList(); for(int j=1 ; jisEmpty())) do ( skip ; ( var n : int ; n := (line)->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var trains : Set(String) ; trains := Set{} ; line := br.readLine() ; for (train : organize(line)) do ( ( if (not(trains->includes(train))) then trains := trains->including(train) ; else skip ) ) ; OclFile["System.out"].println(trains->size()) ) ; i := i + 1 ) ) ; line := br.readLine() ; ) ); static operation organize( line : String) : Sequence(String) pre: true post: true activity: ( var os : Sequence(String) ; os := Sequence{} ; var j : int ; j := 1 ; while j < line->size() do ( ( var t1 : String ; t1 := line.subrange(0+1,j) ; var t2 : String ; t2 := line.subrange(j+1,j) ; os := os->including(t1 + t2) ; os := os->including(t1 + StringLib.newString(t2)->reverse()+"") ; os := os->including(StringLib.newString(t1)->reverse()+"" + t2) ; os := os->including(StringLib.newString(t1)->reverse()+"" + StringLib.newString(t2)->reverse()+"") ; os := os->including(t2 + t1) ; os := os->including(t2 + StringLib.newString(t1)->reverse()+"") ; os := os->including(StringLib.newString(t2)->reverse()+"" + t1) ; os := os->including(StringLib.newString(t2)->reverse()+"" + StringLib.newString(t1)->reverse()+"") ; ) ; j := j + 1 ) ; return os ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.PrintWriter ; public class A_1391 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); for(int i=1 ; i<=n ; i++)out.print(i+" "); out.println(); } out.flush(); } } ------------------------------------------------------------ OCL File: --------- class A_1391 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n do ( skip ; ; i := i + 1 ) ; skip ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; class Main { public static Scanner sc=new Scanner(in); public static Random rand=new Random(); public void run(){ int n=sc.nextInt(); while(n--!=0){ int c=1 ; String str=sc.next(); Setst=new HashSet(); for(int i=1 ; i<=str.length(); i++){ String s1=str.substring(0,i); String s2=str.substring(i,str.length()); String r1=(new StringBuffer(s1)).reverse().toString(); String r2=(new StringBuffer(s2)).reverse().toString(); st.add(s1+s2); st.add(s2+s1); st.add(s1+r2); st.add(r2+s1); st.add(s2+r1); st.add(r1+s2); st.add(r1+r2); st.add(r2+r1); } ln(st.size()); } } public static void main(String[] args){ new Main().run(); } public int[] nextIntArray(int n){ int[] res=new int[n]; for(int i=0 ; itoInteger() ; while (n /= 0) do ( skip ; ( var c : int ; c := 1 ; var str : String ; str := sc.getCurrent() ; var st : Set(String) ; st := Set{} ; var i : int ; i := 1 ; while i <= str->size() do ( ( var s1 : String ; s1 := str.subrange(0+1,i) ; var s2 : String ; s2 := str.subrange(i+1,str->size()) ; var r1 : String ; r1 := (StringLib.newString(s1))->reverse()+"" ; var r2 : String ; r2 := (StringLib.newString(s2))->reverse()+"" ; st := st->including(s1 + s2) ; st := st->including(s2 + s1) ; st := st->including(s1 + r2) ; st := st->including(r2 + s1) ; st := st->including(s2 + r1) ; st := st->including(r1 + s2) ; st := st->including(r1 + r2) ; st := st->including(r2 + r1) ; ) ; i := i + 1 ) ; execute ln(st->size()) ; ) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; return res ); static operation pr( o : OclAny) : void pre: true post: true activity: ( out.print(o) ); static operation ln( o : OclAny) : void pre: true post: true activity: ( out.println(o) ); static operation ln() : void pre: true post: true activity: ( out.println() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ int target,times,start,end ; String ret ; Scanner sc=new Scanner(System.in); while(true){ ret="" ; target=sc.nextInt(); if(target==0){ break ; } times=sc.nextInt(); while(times-->0){ start=sc.nextInt(); end=sc.nextInt(); target-=(end-start); } if(target<=0){ ret="OK" ; } else { ret=String.valueOf(target); } System.out.println(ret); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var target : int ; var times : int ; var start : int ; var end : int ; var ret : String ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( ret := "" ; target := sc.getCurrent()->toInteger() ; if (target = 0) then ( break ) else skip ; times := sc.getCurrent()->toInteger() ; while (times > 0) do ( times := times - 1 ; skip ; ( start := sc.getCurrent()->toInteger() ; end := sc.getCurrent()->toInteger() ; target := target-((end - start)) ) ; ) ; if (target <= 0) then ( ret := "OK" ) else ( ret := ((target) + "") ) ; OclFile["System.out"].println(ret) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Sequences { static int getTotalNumberOfSequences(int m,int n){ if(m ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printKMax(int a[],int n,int k){ if(k==1){ for(int i=0 ; imax)max=a[p]; p+=1 ; if(q==p && p!=n){ System.out.print(max+" "); q++; p=++t ; if(q max) then max := a[p+1] ; else skip ; p := p+(1) ; if (q = p & p /= n) then ( OclFile["System.out"].print(max + " ") ; q := q + 1 ; t := t + 1 ; p := t ; if (q < n) then max := a[q+1] ; else skip ) else skip ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,2,3,4,5,6,7,8,9,10} ; var n : int ; n := a->size() ; var K : int ; K := 3 ; execute printKMax(a, n, K) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t>0){ int a=scn.nextInt(); int b=scn.nextInt(); int c=scn.nextInt(); if((b-a)==(c-b)){ System.out.println("YES"); } else if((a+c)%(2*b)==0){ System.out.println("YES"); } else if((2*b-c)>0 &&((2*b-c)% a==0)){ System.out.println("YES"); } else if((2*b-a)>0 &&((2*b-a)% c==0)){ System.out.println("YES"); } else { System.out.println("NO"); } t--; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scn.getCurrent()->toInteger() ; while (t > 0) do ( var a : int ; a := scn.getCurrent()->toInteger() ; var b : int ; b := scn.getCurrent()->toInteger() ; var c : int ; c := scn.getCurrent()->toInteger() ; if ((b - a) = (c - b)) then ( OclFile["System.out"].println("YES") ) else if ((a + c) mod (2 * b) = 0) then ( OclFile["System.out"].println("YES") ) else if ((2 * b - c) > 0 & ((2 * b - c) mod a = 0)) then ( OclFile["System.out"].println("YES") ) else if ((2 * b - a) > 0 & ((2 * b - a) mod c = 0)) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ; ; ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class MakeUp { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ double a=sc.nextInt(); double b=sc.nextInt(); double c=sc.nextInt(); if(2*b-c>0 &&(2*b-c)% a==0){ System.out.println("YES"); } else if(a+c>0 &&(a+c)%(2*b)==0){ System.out.println("YES"); } else if(2*b-a>0 &&(2*b-a)% c==0){ System.out.println("YES"); } else { System.out.println("NO"); } } } } ------------------------------------------------------------ OCL File: --------- class MakeUp { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : double ; a := sc.getCurrent()->toInteger() ; var b : double ; b := sc.getCurrent()->toInteger() ; var c : double ; c := sc.getCurrent()->toInteger() ; if (2 * b - c > 0 & (2 * b - c) mod a = 0) then ( OclFile["System.out"].println("YES") ) else if (a + c > 0 & (a + c) mod (2 * b) = 0) then ( OclFile["System.out"].println("YES") ) else if (2 * b - a > 0 & (2 * b - a) mod c = 0) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class B1624 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int new_a=b-(c-b); int new_b=a+(c-a)/2 ; int new_c=a+2*(b-a); solve(a,b,c,new_a,new_b,new_c); } } public static void solve(int a,int b,int c,int new_a,int new_b,int new_c){ if(new_a>=a && new_a!=0 && new_a % a==0){ System.out.println("YES"); return ; } if(new_b>=b && new_b!=0 && new_b % b==0 &&(c-a)% 2==0){ System.out.println("YES"); return ; } if(new_c>=c && new_c!=0 && new_c % c==0){ System.out.println("YES"); return ; } System.out.println("NO"); return ; } } ------------------------------------------------------------ OCL File: --------- class B1624 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var new_a : int ; new_a := b - (c - b) ; var new_b : int ; new_b := a + (c - a) / 2 ; var new_c : int ; new_c := a + 2 * (b - a) ; execute solve(a, b, c, new_a, new_b, new_c) ; ) ; ) ); static operation solve( a : int, b : int, c : int, new_a : int, new_b : int, new_c : int) : void pre: true post: true activity: ( if (new_a >= a & new_a /= 0 & new_a mod a = 0) then ( OclFile["System.out"].println("YES") ; return ) else skip ; if (new_b >= b & new_b /= 0 & new_b mod b = 0 & (c - a) mod 2 = 0) then ( OclFile["System.out"].println("YES") ; return ) else skip ; if (new_c >= c & new_c /= 0 & new_c mod c = 0) then ( OclFile["System.out"].println("YES") ; return ) else skip ; OclFile["System.out"].println("NO") ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String findLongestPalindrome(String str){ int count[]=new int[256]; for(int i=0 ; i=0 ; i--){ ans+=try1[i]; } return ans ; } public static void main(String[] args){ String str="abbaccd" ; System.out.println(findLongestPalindrome(str)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findLongestPalindrome( str : String) : String pre: true post: true activity: ( var count : Sequence(int) ; count := Integer.subrange(1,256)->collect(0) ; var i : int ; i := 0 ; while i < str->size() do ( ( count[str->at(i+1)+1] := count[str->at(i+1)+1] + 1 ) ; i := i + 1 ) ; var beg : String ; beg := "" ; var mid : String ; mid := "" ; var end : String ; end := "" ; var ch : String ; ch := 'a' ; while ch <= 'z' do ( ( if (count[ch+1] mod 2 = 1) then ( mid := ((ch) + "") ; count[ch+1] := count[ch+1] - 1 ) else ( var i : int ; i := 0 ; while i < count[ch+1] / 2 do ( ( beg := beg+(ch) ) ; i := i + 1 ) ) ) ; ch := ch + 1 ) ; end := beg ; end := reverse(end) ; return beg + mid + end ); static operation reverse( str : String) : String pre: true post: true activity: ( var ans : String ; ans := "" ; var try1 : Sequence(String) ; try1 := str->characters() ; var i : int ; i := try1->size() - 1 ; while i >= 0 do ( ( ans := ans+(try1[i+1]) ) ; i := i - 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "abbaccd" ; OclFile["System.out"].println(findLongestPalindrome(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void reverse(long a[],int b,int e){ long A[]=new long[e-b]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < e - b do ( A[i+1] := a[e - 1 - i+1] ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < e - b do ( a[b + i+1] := A[i+1] ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var q : int ; q := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var b : int ; b := sc.getCurrent()->toInteger() ; var e : int ; e := sc.getCurrent()->toInteger() ; execute reverse(a, b, e) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( OclFile["System.out"].print(a[i+1] + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println(a[n - 1+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); int[] a=new int[n]; str=br.readLine().split(" "); for(int i=0 ; isplit(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; str := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (str[i+1])->toInteger() ; ; i := i + 1 ) ; str := br.readLine()->split(" ") ; var q : int ; q := (str[0+1])->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( str := br.readLine()->split(" ") ; var b : int ; b := (str[0+1])->toInteger() ; var e : int ; e := (str[1+1])->toInteger() ; e := e-(1) ; var j : int ; j := b ; while j < b + (e - b + 1) / 2 do ( ( var k : int ; k := e - (j - b) ; var bf : int ; bf := a[j+1] ; a[j+1] := a[k+1] ; a[k+1] := bf ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(a[i+1]) ; if (i /= n - 1) then OclFile["System.out"].print(" ") ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].print("\n") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { static Scanner scInputData=new Scanner(System.in); static ArrayListarrA=new ArrayList(); public static void main(String[] args){ getArr(arrA); reverseArr(); putResult(); } private static void putResult(){ for(int arrNum=0 ; arrNumarr){ int iArrNum=0 ; iArrNum=scInputData.nextInt(); while(arr.size()size() - 1 do ( ( OclFile["System.out"].print(arrA->at(arrNum+1) + " ") ) ; arrNum := arrNum + 1 ) ; OclFile["System.out"].println(arrA->at(arrA->size() - 1+1)) ); static operation reverseArr() : void pre: true post: true activity: ( var revNum : int ; revNum := scInputData.getCurrent()->toInteger() ; var start : int ; start := 0 ; var end : int ; end := 0 ; var indexToRev : int ; indexToRev := 0 ; while indexToRev < revNum do ( ( start := scInputData.getCurrent()->toInteger() ; end := scInputData.getCurrent()->toInteger() ; execute reverseNum(start, end) ) ; indexToRev := indexToRev + 1 ) ); static operation reverseNum( start : int, end : int) : void pre: true post: true activity: ( var changeNum : int ; changeNum := (end - start)->oclAsType(int) / 2 ; var val_small : int ; val_small := 0 ; var indexToChange : int ; indexToChange := 0 ; while indexToChange < changeNum do ( ( val_small := arrA->at(start + indexToChange+1) ; arrA := arrA.setAt(start + indexToChange+1,arrA->at(end - indexToChange - 1+1)) ; arrA := arrA.setAt(end - indexToChange - 1+1,val_small) ) ; indexToChange := indexToChange + 1 ) ); static operation getArr( arr : Sequence(int)) : void pre: true post: true activity: ( var iArrNum : int ; iArrNum := 0 ; iArrNum := scInputData.getCurrent()->toInteger() ; while (arr->size() < iArrNum) do ( arr->excludes(scInputData.getCurrent()->toInteger()) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Round663A { public static PrintWriter pw=new PrintWriter(System.out); public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); long t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); for(int i=n ; i>0 ; i--){ pw.print(i+" "); } pw.println(); } pw.close(); } } ------------------------------------------------------------ OCL File: --------- class Round663A { static attribute pw : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : long ; t := (br.readLine())->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := (br.readLine())->toInteger() ; var i : int ; i := n ; while i > 0 do ( ( skip ) ; i := i - 1 ) ; skip ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int t=sc.nextInt(); if(t==0)break ; int n=sc.nextInt(),sum=0 ; for(int i=0 ; itoInteger() ; if (t = 0) then break else skip ; var n : int ; n := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var s : int ; s := sc.getCurrent()->toInteger() ; var f : int ; f := sc.getCurrent()->toInteger() ; sum := sum+(f - s) ) ; i := i + 1 ) ; OclFile["System.out"].println(if t <= sum then "OK" else t - sum endif) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int size=in.nextInt(),arr[]=new int[size]; for(int i=0 ; itoInteger() ; var arr : Sequence(void) ; arr := Integer.subrange(1,size)->collect(0) ; var i : int ; i := 0 ; while i < size do ( ( arr[i+1] := (in.getCurrent())->toInteger() ) ; i := i + 1 ) ; var loop : int ; loop := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < loop do ( ( var begin : int ; begin := (in.getCurrent())->toInteger() ; var end : int ; end := (in.getCurrent())->toInteger() ; var j : int ; j := 0 ; while j < (end - begin) / 2 do ( ( var temp : int ; temp := arr[begin + j+1] ; arr[begin + j+1] := arr[end - 1 - j+1] ; arr[end - 1 - j+1] := temp ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < size do ( ( skip ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); int num=sc.nextInt(); ArrayListarray=new ArrayList<>(); for(int i=0 ; isub=array.subList(l,r); Collections.reverse(sub); for(int j=l ; jtoInteger() ; var array : Sequence(int) ; array := Sequence{} ; var i : int ; i := 0 ; while i < num do ( ( var tmp : int ; tmp := sc.getCurrent()->toInteger() ; array := array->including(tmp) ) ; i := i + 1 ) ; var num_query : int ; num_query := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < num_query do ( ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var sub : Sequence(int) ; sub := array.subrange(l+1,r) ; sub := sub->reverse() ; var j : int ; j := l ; while j < r do ( ( array := array.setAt(j+1,sub->at(j - l+1)) ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < array->size() do ( ( sb := sb + StringLib.newString(array->at(i+1)) ; if (i /= array->size() - 1) then sb := sb + StringLib.newString(' ') ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Tttest { public static int fun(String s1,String s2){ Sets=new HashSet<>(); for(int i=0 ; i0){ String s1=sc.next(); String s2=sc.next(); System.out.println(fun(s1,s2)); t--; } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Tttest { static operation fun( s1 : String, s2 : String) : int pre: true post: true activity: ( var s : Set(String) ; s := Set{} ; var i : int ; i := 0 ; while i < s1->size() do ( ( s := s->including(s1->at(i+1)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s2->size() do ( ( s := s->including(s2->at(i+1)) ) ; i := i + 1 ) ; return s->size() - 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( var s1 : String ; s1 := sc.getCurrent() ; var s2 : String ; s2 := sc.getCurrent() ; OclFile["System.out"].println(fun(s1, s2)) ; t := t - 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { Fast f=new Fast(System.in); int t=f.nextInt(); while(t--!=0){ String s1=f.next(); String s2=f.next(); String s=s1+s2 ; int[] freq=new int[26]; int ans=0 ; for(int i=0 ; icollect(0) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < s->size() do ( freq[s->at(i+1) - ('a')->char2byte()+1] := freq[s->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; for (i : freq) do ( ans := ans+(if i /= 0 then 1 else 0 endif) ; ) ; OclFile["System.out"].println(ans - 1) ; ) ; ) ; OclFile["System.out"].flush() ; OclFile["System.out"].close() ; ); } class Fast { attribute st : OclIterator; attribute br : OclFile; static operation newFast( s : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile(s))) ); static operation newFast( file : String) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(file); return self ); operation initialise( file : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(file)) ); static operation newFast( r : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(r); return self ); operation initialise( r : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(r) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation readAllLines( reader : OclFile) : String pre: true post: true activity: ( var content : String ; content := StringLib.newString() ; var line : String ; line := reader.readLine() ; while ((line) /= null) do ( skip ; ( content := content + StringLib.newString(line) ; content := content + StringLib.newString(lineSeparator()) ) ; line := reader.readLine() ; ) ; return content+"" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A1721 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); for(int t=0 ; ttoInteger() ; var t : int ; t := 0 ; while t < T do ( ( var data : Sequence(String) ; data := (in.getCurrent() + in.getCurrent())->characters() ; var stat : Sequence(int) ; stat := Integer.subrange(1,26)->collect(0) ; for (c : data) do ( ( stat[c - ('a')->char2byte()+1] := stat[c - ('a')->char2byte()+1] + 1 ) ) ; stat := stat->sort() ; var answer : int ; if (stat[25+1] = 4) then ( answer := 0 ) else if (stat[25+1] = 3) then ( answer := 1 ) else if (stat[25+1] = 2) then ( answer := if (stat[24+1] = 2) then 1 else 2 endif ) else ( answer := 3 ) ; ; ; OclFile["System.out"].println(answer) ; ) ; t := t + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); while(n-->0){ String s1=scanner.next(); String s2=scanner.next(); int[] arr=new int[26]; int count=0 ; for(int i=0 ; itoInteger() ; while (n > 0) do ( n := n - 1 ; skip ; ( var s1 : String ; s1 := scanner.getCurrent() ; var s2 : String ; s2 := scanner.getCurrent() ; var arr : Sequence(int) ; arr := Integer.subrange(1,26)->collect(0) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < s1->size() do ( ( arr[(s1->at(i+1) - ('a')->char2byte())+1] := arr[(s1->at(i+1) - ('a')->char2byte())+1] + 1 ; arr[(s2->at(i+1) - ('a')->char2byte())+1] := arr[(s2->at(i+1) - ('a')->char2byte())+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 26 do ( ( if (arr[i+1] /= 0) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count - 1) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.HashSet ; import java.util.StringTokenizer ; import java.util.TreeMap ; public class A { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ HashSeths=new HashSet(); for(int i=0 ; i<2 ; i++){ String x=sc.next(); for(int j=0 ; j<2 ; j++)hs.add(x.charAt(j)); } out.println(hs.size()==1 ? 0 : hs.size()==2 ? 1 : hs.size()==3 ? 2 : 3); } out.close(); } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public boolean hasNext(){ return st.hasMoreTokens(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public String nextLine()throws IOException { return br.readLine(); } public boolean ready()throws IOException { return br.ready(); } } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var hs : Set(String) ; hs := Set{} ; var i : int ; i := 0 ; while i < 2 do ( ( var x : String ; x := sc.getCurrent() ; var j : int ; j := 0 ; while j < 2 do ( hs := hs->including(x->at(j+1)) ; ; j := j + 1 ) ) ; i := i + 1 ) ; skip ) ; ) ; skip ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation hasNext() : boolean pre: true post: true activity: ( return st.hasNext() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int findMissingPositive(int arr[],int n){ int m=1 ; HashSetx=new HashSet(); for(int i=0 ; iincluding(arr[i+1]) ) else if (m = arr[i+1]) then ( m := m + 1 ; while (x->includes(m)) do ( x := x->excludingAt(m+1) ; m := m + 1 ) ) else skip ; ) ; i := i + 1 ) ; return m ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,3,-7,6,8,1,-10,15} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findMissingPositive(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); final int max=100000+5 ; PriorityQueuepq=new PriorityQueue<>(10,Collections.reverseOrder()); int N=sc.nextInt(); int[] A=new int[N]; for(int i=0 ; i0)pq.add(rec[i]); } if(pq.size()==1){ System.out.println(1); System.exit(0); } while(pq.size()>1 && pq.peek()>1){ int cur=pq.poll(); if(cur>=3 && cur % 2==1){ pq.add(1); continue ; } if(cur % 2==0){ int next=pq.poll(); if(next==1)pq.add(1); else { pq.add(1); pq.add(next-1); } } } System.out.println(pq.size()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var max : int ; max := 100000 + 5 ; var pq : Sequence(int) ; pq := Sequence{} ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( A[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var rec : Sequence(int) ; rec := Integer.subrange(1,max + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( rec[A[i+1]+1] := rec[A[i+1]+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= max do ( ( if (rec[i+1] > 0) then pq := pq->including(rec[i+1]) ; else skip ) ; i := i + 1 ) ; if (pq->size() = 1) then ( OclFile["System.out"].println(1) ; OclProcess.exit(0) ) else skip ; while (pq->size() > 1 & pq->min() > 1) do ( var cur : int ; cur := pq->min() ; if (cur >= 3 & cur mod 2 = 1) then ( pq := pq->including(1) ; continue ) else skip ; if (cur mod 2 = 0) then ( var next : int ; next := pq->min() ; if (next = 1) then pq := pq->including(1) ; else ( pq := pq->including(1) ; pq := pq->including(next - 1) ) ) else skip ) ; OclFile["System.out"].println(pq->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[] A=new int[N]; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; A := A->sort() ; var ba : int ; ba := -1 ; var cnt : int ; cnt := 0 ; for (a : A) do ( ( if (ba = a) then ( cnt := cnt + 1 ) else ( ba := a ) ) ) ; cnt := (cnt / 2.0)->ceil()->oclAsType(int) * 2 ; out.println(N - cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); long total=0 ; for(long i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var total : long ; total := 0 ; var i : long ; i := 0 ; while i < h do ( ( var j : long ; j := 0 ; while j < w do ( ( var x : long ; x := sc.getCurrent()->toInteger() ; total := total+(x * (i + 1) * (h - i) * (j + 1) * (w - j)) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(total) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int fact(int num){ int fact=1 ; while(num>1){ fact*=num ; num-=1 ; } return fact ; } static int catalan(int n){ return fact(2*n)/(fact(n)*fact(n+1)); } public static void main(String[] args){ int n=5 ; int arr[]={ 1,2,3,4,5 }; int i,k ; for(k=0 ; k 1) do ( fact := fact*(num) ; num := num-(1) ) ; return fact ); static operation catalan( n : int) : int pre: true post: true activity: ( return fact(2 * n) / (fact(n) * fact(n + 1)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5} ; var i : int ; var k : int ; k := 0 ; while k < n do ( ( var s : int ; s := 0 ; i := 0 ; while i < n do ( ( if (arr[i+1] < arr[k+1]) then s := s+(1) ; else skip ) ; i := i + 1 ) ; var catalan_leftBST : int ; catalan_leftBST := catalan(s) ; var catalan_rightBST : int ; catalan_rightBST := catalan(n - s - 1) ; var totalBST : int ; totalBST := catalan_rightBST * catalan_leftBST ; OclFile["System.out"].print(totalBST + " ") ; ) ; k := k + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test283 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; j0 ; i--){ System.out.print(i+" "); } System.out.println(); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test283 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < t do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var i : int ; i := x ; while i > 0 do ( ( OclFile["System.out"].print(i + " ") ) ; i := i - 1 ) ; OclFile["System.out"].println() ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static PrintWriter out ; public static FastScanner in ; private void solve(){ int[] cnt=new int[100002]; Arrays.fill(cnt,0); int n=in.nextInt(); for(int i=0 ; i1){ ans-=(cnt[i]-1); } } if(ans % 2==0)ans--; out.print(ans); } private void runIO(){ in=new FastScanner(); out=new PrintWriter(new BufferedOutputStream(System.out)); solve(); out.close(); } private static class FastScanner { BufferedReader bufferedReader ; StringTokenizer stringTokenizer ; private FastScanner(){ bufferedReader=new BufferedReader(new InputStreamReader(System.in)); } private String next(){ if(stringTokenizer==null || ! stringTokenizer.hasMoreElements()){ try { stringTokenizer=new StringTokenizer(bufferedReader.readLine()); } catch(IOException e){ e.printStackTrace(); } } return stringTokenizer.nextToken(); } private int nextInt(){ return Integer.parseInt(next()); } private long nextLong(){ return Long.parseLong(next()); } private String nextLine(){ String ret="" ; try { ret=bufferedReader.readLine(); } catch(IOException e){ e.printStackTrace(); } return ret ; } } public static void main(String[] args){ new Main().runIO(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute out : OclFile; static attribute in : FastScanner; operation solve() : void pre: true post: true activity: ( var cnt : Sequence(int) ; cnt := Integer.subrange(1,100002)->collect(0) ; cnt := cnt->collect(0) ; var n : int ; n := in.nextInt() ; var i : int ; i := 0 ; while i < n do ( ( cnt[in.nextInt()+1] := cnt[in.nextInt()+1] + 1 ) ; i := i + 1 ) ; var ans : int ; ans := n ; var i : int ; i := 0 ; while i < 100001 do ( ( if (cnt[i+1] > 1) then ( ans := ans-((cnt[i+1] - 1)) ) else skip ) ; i := i + 1 ) ; if (ans mod 2 = 0) then ans := ans - 1 ; else skip ; skip ; ); operation runIO() : void pre: true post: true activity: ( in := FastScanner.newFastScanner() ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; execute solve() ; skip ); static class FastScanner { attribute bufferedReader : OclFile; attribute stringTokenizer : OclIterator; static operation newFastScanner() : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( bufferedReader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( if (stringTokenizer = null or not(stringTokenizer.hasNext())) then ( try ( stringTokenizer := OclIterator.newOclIterator_String(bufferedReader.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) else skip ; return stringTokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( var ret : String ; ret := "" ; try ( ret := bufferedReader.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return ret ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().runIO() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; import java.util.stream.IntStream ; public class Main { public static void main(String[] args){ try(Scanner scanner=new Scanner(System.in)){ int n=scanner.nextInt(); int[] a=new int[n]; Mapmap=new HashMap<>(); IntStream.range(0,n).forEach(i->{ a[i]=scanner.nextInt(); map.put(a[i],map.getOrDefault(a[i],0)+1); } ); int sum=map.entrySet().stream().mapToInt(entry->entry.getValue()-1).sum(); System.out.println(n-sum-(sum & 1)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var map : Map(int,int) ; map := Map{} ; for i : Integer.subrange(0, n-1) do ( skip) ; var sum : int ; sum := map->asSet()->collect( _x1 | (lambda entry : OclAny in entry.getValue() - 1)->apply(_x1) )->sum() ; OclFile["System.out"].println(n - sum - (MathLib.bitwiseAnd(sum,1))) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int numOfCards=s.nextInt(); int numOverlap=0 ; Setcards=new HashSet(); for(int i=0 ; itoInteger() ; var numOverlap : int ; numOverlap := 0 ; var cards : Set(int) ; cards := Set{} ; var i : int ; i := 0 ; while i < numOfCards do ( ( var tmp : int ; tmp := s.getCurrent()->toInteger() ; if (not(cards->includes(tmp))) then ( cards := cards->including(tmp) ) else ( numOverlap := numOverlap + 1 ) ) ; i := i + 1 ) ; if (numOverlap mod 2 = 0) then ( OclFile["System.out"].println(numOfCards - numOverlap) ) else ( OclFile["System.out"].println(numOfCards - numOverlap - 1) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int k=in.nextInt(); int n=-1,m=-1 ; for(int i=5 ; i*i<=k ; i++){ if(k % i==0){ n=i ; m=k/n ; } } if(n==-1){ System.out.println(-1); return ; } char[] c={ 'a','e','i','o','u' }; for(int i=0 ; itoInteger() ; var n : int ; n := -1 ; var m : int ; m := -1 ; var i : int ; i := 5 ; while i * i <= k do ( ( if (k mod i = 0) then ( n := i ; m := k / n ) else skip ) ; i := i + 1 ) ; if (n = -1) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var c : Sequence(String) ; c := Sequence{'a','e','i','o','u'} ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < m do ( ( skip ) ; j := j + 1 ) ; ; i := i + 1 ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.System.out ; public class pre127 { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } static int isPrime(int n){ if(n==2)return-1 ; int ans=-1 ; for(int i=2 ; i*i<=n ; i++)if(n % i==0)ans=i ; return ans ; } public static void main(String args[]){ FastReader obj=new FastReader(); int k=obj.nextInt(),p=isPrime(k); if(p<5 || k<25){ out.println(-1); return ; } char v[]={ 'a','e','i','o','u' }; int t,n=p,m=k/n ; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation isPrime( n : int) : int pre: true post: true activity: ( if (n = 2) then return -1 else skip ; var ans : int ; ans := -1 ; var i : int ; i := 2 ; while i * i <= n do ( if (n mod i = 0) then ans := i ; else skip ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : FastReader ; obj := FastReader.newFastReader() ; var k : int ; k := obj.nextInt() ; var p : int ; p := isPrime(k) ; if (p < 5 or k < 25) then ( out.println(-1) ; return ) else skip ; var v : Sequence(String) ; v := Sequence{'a','e','i','o','u'} ; var t : int ; var n : int ; n := p ; var m : int ; m := k / n ; var i : int ; i := 0 ; while i < n do ( ( t := i mod 5 ; var j : int ; j := 0 ; while j < m do ( ( out.print(v[t mod 5+1]) ; t := t + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.Collectors ; public class Main { static final char[] VOWELS={ 'a','e','i','o','u' }; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); System.out.println(solve(k)); sc.close(); } static String solve(int k){ for(int row=VOWELS.length ; row*row<=k ; row++){ if(k % row==0){ int col=k/row ; char[][] grid=new char[row][col]; for(int r=0 ; rtoInteger() ; OclFile["System.out"].println(solve(k)) ; skip ); static operation solve( k : int) : String pre: true post: true activity: ( var row : int ; row := VOWELS->size() ; while row * row <= k do ( ( if (k mod row = 0) then ( var col : int ; col := k / row ; var grid : Sequence(Sequence(String)) ; grid := Integer.subrange(1,row)->collect(Integer.subrange(1,col)->collect(0)) ; var r : int ; r := 0 ; while r < row do ( ( var c : int ; c := 0 ; while c < col do ( ( grid[r+1][c+1] := VOWELS[(r + c) mod VOWELS->size()+1] ) ; c := c + 1 ) ) ; r := r + 1 ) ; return stream(grid)->collect( _x1 | (lambda _pars : OclAny in String.newString().new(_pars))->apply(_x1) ).collect(Collectors.joining()) ) else skip ) ; row := row + 1 ) ; return "-1" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class codeforces { public static void main(String args[])throws IOException { File file=new File("input.txt"); Scanner sc=new Scanner(file); FileWriter fw=new FileWriter("output.txt"); int n=sc.nextInt(); int k=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; i>hm=new HashMap<>(); for(int i=0 ; i<=100 ; i++){ ArrayLista=new ArrayList<>(); for(int j=0 ; jx=new ArrayList<>(); for(int i=100 ; i>=0 ; i--){ if(hm.containsKey(i)){ for(int j : hm.get(i)){ if(k>0){ x.add(j); t=i ; k--; } else { f=1 ; break ; } } if(f==1)break ; } } fw.write(String.valueOf(t)); fw.write("\n"); for(int i : x){ String s=String.valueOf(i); s=s+" " ; fw.write(s); } fw.close(); } } ------------------------------------------------------------ OCL File: --------- class codeforces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var file : OclFile ; file := OclFile("input.txt") ; var sc : OclFile ; sc := OclFile.newOclFile_Read(file) ; var fw : OclFile ; fw := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var hm : Map(int,Sequence(int)) ; hm := Map{} ; var i : int ; i := 0 ; while i <= 100 do ( ( var a : Sequence(int) ; a := Sequence{} ; var j : int ; j := 0 ; while j < n do ( ( if (arr[j+1] = i) then ( a := a->including(j + 1) ) else skip ) ; j := j + 1 ) ; if (a->size() /= 0) then hm := hm->union(Map{i |-> a}) ; else skip ) ; i := i + 1 ) ; var f : int ; f := 0 ; var t : int ; t := 0 ; var x : Sequence(int) ; x := Sequence{} ; var i : int ; i := 100 ; while i >= 0 do ( ( if (hm->keys()->includes(i)) then ( for (j : hm->at(i)) do ( ( if (k > 0) then ( x := x->including(j) ; t := i ; k := k - 1 ) else ( f := 1 ; break ) ) ) ; if (f = 1) then break else skip ) else skip ) ; i := i - 1 ) ; skip ; skip ; for (i : x) do ( ( var s : String ; s := ((i) + "") ; s := s + " " ; skip ) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Reading { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner((new FileReader("input.txt"))); FileWriter out=new FileWriter("output.txt"); int n=sc.nextInt(),k=sc.nextInt(); Lista=new ArrayList<>(); for(int i=0 ; ib=new ArrayList<>(a); Collections.sort(b); out.write(b.get(n-k)+"\n"); int h=b.get(n-k); for(int i=0 ; i=h && k>0){ out.write(i+1+" "); --k ; } } sc.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Reading { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read((OclFile.newOclFile_Read(OclFile.newOclFile("input.txt")))) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Sequence{} ; var i : int ; i := 0 ; while i < n do ( a := a->including(sc.getCurrent()->toInteger()) ; ; i := i + 1 ) ; var b : Sequence(int) ; b := Sequence{}->union(a) ; b := b->sort() ; skip ; var h : int ; h := b->at(n - k+1) ; var i : int ; i := 0 ; while i < n do ( ( if (a->at(i+1) >= h & k > 0) then ( skip ; k := k - 1 ) else skip ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class reading { public static void main(String[] args)throws IOException { Scanner bf=new Scanner(new File("Input.txt")); PrintWriter pw=new PrintWriter("output.txt"); String[] ars=bf.nextLine().split(" "); int n=Integer.parseInt(ars[0]); int k=Integer.parseInt(ars[1]); int[] arr=new int[n]; ars=bf.nextLine().split(" "); for(int i=0 ; isplit(" ") ; var n : int ; n := (ars[0+1])->toInteger() ; var k : int ; k := (ars[1+1])->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; ars := bf.nextLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := (ars[i+1])->toInteger() ) ; i := i + 1 ) ; var copy : Sequence(int) ; copy := arr->copy() ; arr := arr->sort() ; skip ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := n - k ; while i < n do ( ( sb := sb + StringLib.newString(at(copy, arr[i+1]+1) + " ") ) ; i := i + 1 ) ; skip ; skip ; ); static operation get( arr : Sequence(int), x : int) : int pre: true post: true activity: ( var y : int ; y := 0 ; var i : int ; i := 0 ; while i < arr->size() do ( ( if (arr[i+1] = x) then ( y := i ; arr[i+1] := -1 ; break ) else skip ) ; i := i + 1 ) ; return y + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import javax.naming.NamingEnumeration ; import javax.swing.plaf.IconUIResource ; import javax.swing.plaf.synth.SynthOptionPaneUI ; import java.awt.font.FontRenderContext ; import java.awt.image.ImageProducer ; import java.beans.beancontext.BeanContextServiceRevokedEvent ; import java.lang.reflect.Array ; import java.util.*; import java.math.BigInteger ; import java.util.spi.LocaleNameProvider ; public class ques { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int j=0 ; jtoInteger() ; var j : int ; j := 0 ; while j < n do ( ( var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; if (if a - b < 0 then -(a - b) else a - b endif = 1) then OclFile["System.out"].println("NO") ; else OclFile["System.out"].println("YES") ; ) ; j := j + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String args[])throws Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(); if(n % 2==0){ System.out.println(-1); } else { for(int i=0 ; itoInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(-1) ) else ( var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(((2 * i) mod n) + " ") ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findevenPair(int[] A,int N){ int i,j ; int evenPair=0 ; for(i=0 ; isize() ; OclFile["System.out"].println(findevenPair(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String args[])throws Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(); if(n % 2==0){ System.out.println(-1); } else { for(int i=0 ; itoInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(-1) ) else ( var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(i + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(((2 * i) mod n) + " ") ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int n=Integer.parseInt(in.readLine()); if(n % 2==0){ System.out.println(-1); return ; } int[] a=new int[n],b=new int[n]; for(int i=0 ; itoInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := i ; ; i := i + 1 ) ; var p : int ; p := n - 1 ; var i : int ; i := 0 ; while i < n do ( b[i+1] := p ; p := p - 1 ; ; i := i+(2) ) ; var i : int ; i := 1 ; while i < n do ( b[i+1] := p ; p := p - 1 ; ; i := i+(2) ) ; var i : int ; i := 0 ; while i < n do ( skip ; ; i := i + 1 ) ; skip ; var i : int ; i := 0 ; while i < n do ( skip ; ; i := i + 1 ) ; skip ; var i : int ; i := 0 ; while i < n do ( skip ; ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int n=Integer.parseInt(in.readLine()); if(n % 2==0){ System.out.println(-1); return ; } int[] a=new int[n],b=new int[n]; for(int i=0 ; itoInteger() ; if (n mod 2 = 0) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := i ; ; i := i + 1 ) ; var p : int ; p := n - 1 ; var i : int ; i := 0 ; while i < n do ( b[i+1] := p ; p := p - 1 ; ; i := i+(2) ) ; var i : int ; i := 1 ; while i < n do ( b[i+1] := p ; p := p - 1 ; ; i := i+(2) ) ; var arrStr : Sequence(String) ; arrStr := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( arrStr[i+1] := ((a[i+1]) + "") ; ; i := i + 1 ) ; skip ; var i : int ; i := 0 ; while i < n do ( arrStr[i+1] := ((b[i+1]) + "") ; ; i := i + 1 ) ; skip ; var i : int ; i := 0 ; while i < n do ( arrStr[i+1] := (((a[i+1] + b[i+1]) mod n) + "") ; ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class LuckyPermutationTriple { public static void main(String[] args)throws IOException { Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); int n=in.nextInt(); ArrayListf=new ArrayList<>(),sec=new ArrayList<>(),th=new ArrayList<>(); if(n==1){ pw.println(0); pw.println(0); pw.println(0); pw.close(); return ; } if(n % 2==0){ pw.println("-1"); } else { int j=1 ; for(int i=n-1 ; i>=0 ; i--){ f.add(i); sec.add(j); int z=(i+j)% n ; j+=2 ; if(j>=n)j=0 ; th.add(z); } } for(int i : f)pw.print(i+" "); pw.println(); for(int i : sec)pw.print(i+" "); pw.println(); for(int i : th)pw.print(i+" "); pw.println(); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class LuckyPermutationTriple { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var n : int ; n := in.getCurrent()->toInteger() ; var f : Sequence(int) ; f := Sequence{} ; var sec : Sequence(int) ; sec := Sequence{} ; var th : Sequence(int) ; th := Sequence{} ; if (n = 1) then ( skip ; skip ; skip ; skip ; return ) else skip ; if (n mod 2 = 0) then ( skip ) else ( var j : int ; j := 1 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( f->excludes(i) ; sec->excludes(j) ; var z : int ; z := (i + j) mod n ; j := j+(2) ; if (j >= n) then j := 0 ; else skip ; th->excludes(z) ; ) ; i := i - 1 ) ) ; for (i : f) do ( skip ; ) ; skip ; for (i : sec) do ( skip ; ) ; skip ; for (i : th) do ( skip ; ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countWays(int arr[],int n){ int pos[]=new int[n]; int p=0,i ; for(i=0 ; icollect(0) ; var p : int ; p := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = 1) then ( pos[p+1] := i + 1 ; p := p + 1 ) else skip ) ; i := i + 1 ) ; if (p = 0) then return 0 else skip ; var ways : int ; ways := 1 ; i := 0 ; while i < p - 1 do ( ( ways := ways*(pos[i + 1+1] - pos[i+1]) ) ; i := i + 1 ) ; return ways ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,0,1,0,1} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(countWays(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static boolean solve(String n,int l){ if(l<3){ if(Integer.parseInt(n)% 8==0)return true ; n=new String((new StringBuilder()).append(n).reverse()); if(Integer.parseInt(n)% 8==0)return true ; return false ; } int[] hash=new int[10]; for(int i=0 ; ihash[dup % 10])continue ; dup=dup/10 ; if(freq[dup % 10]>hash[dup % 10])continue ; dup=dup/10 ; if(freq[dup % 10]>hash[dup % 10])continue ; return true ; } return false ; } public static void main(String[] args){ String number="31462708" ; int l=number.length(); if(solve(number,l))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solve( n : String, l : int) : boolean pre: true post: true activity: ( if (l < 3) then ( if ((n)->toInteger() mod 8 = 0) then return true else skip ; n := StringLib.newString((StringLib.newString()) + StringLib.newString(n)->reverse()) ; if ((n)->toInteger() mod 8 = 0) then return true else skip ; return false ) else skip ; var hash : Sequence(int) ; hash := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < l do ( hash[n->at(i+1) - ('0')->char2byte()+1] := hash[n->at(i+1) - ('0')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var i : int ; i := 104 ; while i < 1000 do ( ( var dup : int ; dup := i ; var freq : Sequence(int) ; freq := Integer.subrange(1,10)->collect(0) ; freq[dup mod 10+1] := freq[dup mod 10+1] + 1 ; dup := dup / 10 ; freq[dup mod 10+1] := freq[dup mod 10+1] + 1 ; dup := dup / 10 ; freq[dup mod 10+1] := freq[dup mod 10+1] + 1 ; dup := i ; if (freq[dup mod 10+1] > hash[dup mod 10+1]) then continue else skip ; dup := dup / 10 ; if (freq[dup mod 10+1] > hash[dup mod 10+1]) then continue else skip ; dup := dup / 10 ; if (freq[dup mod 10+1] > hash[dup mod 10+1]) then continue else skip ; return true ) ; i := i+(8) ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var number : String ; number := "31462708" ; var l : int ; l := number->size() ; if (solve(number, l)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static int MOD=998244353 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int A=sc.nextInt(); int B=sc.nextInt(); long K=sc.nextLong(); long ans=0 ; long[] comb=new long[n+1]; comb[0]=1 ; for(int i=1 ; in)continue ; if(y<0)break ; ans=(ans+comb[x]*comb[(int)y] % MOD)% MOD ; } } System.out.println(ans); } static long calc(int n,long a){ long MulSumN=1 ; long MulSumA=1 ; for(int i=1 ; i<=a ; i++){ MulSumN*=n-i+1 ; MulSumN %=MOD ; MulSumA*=i ; MulSumA %=MOD ; } return MulSumN*pow(MulSumA,MOD-2)% MOD ; } public static long pow(long a,int b){ if(b==1)return a ; if(b % 2==0){ long d=pow(a,b/2); return d*d % MOD ; } return a*pow(a,b-1)% MOD ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : int := 998244353; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var K : long ; K := sc.getCurrent()->toLong() ; var ans : long ; ans := 0 ; var comb : Sequence(long) ; comb := Integer.subrange(1,n + 1)->collect(0) ; comb[0+1] := 1 ; var i : int ; i := 1 ; while i < n + 1 do ( ( comb[i+1] := comb[i - 1+1] * (n - i + 1) mod MOD * pow(i, MOD - 2) mod MOD ) ; i := i + 1 ) ; var q : long ; q := K + A ; var x : int ; x := 0 ; while x <= n do ( ( q := q-(A) ; if (q mod B = 0) then ( var y : long ; y := q / B ; if (y > n) then continue else skip ; if (y < 0) then break else skip ; ans := (ans + comb[x+1] * comb[y->oclAsType(int)+1] mod MOD) mod MOD ) else skip ) ; x := x + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation calc( n : int, a : long) : long pre: true post: true activity: ( var MulSumN : long ; MulSumN := 1 ; var MulSumA : long ; MulSumA := 1 ; var i : int ; i := 1 ; while i <= a do ( ( MulSumN := MulSumN*(n - i + 1) ; MulSumN := MulSumN mod MOD ; MulSumA := MulSumA*(i) ; MulSumA := MulSumA mod MOD ) ; i := i + 1 ) ; return MulSumN * pow(MulSumA, MOD - 2) mod MOD ); static operation pow( a : long, b : int) : long pre: true post: true activity: ( if (b = 1) then return a else skip ; if (b mod 2 = 0) then ( var d : long ; d := pow(a, b / 2) ; return d * d mod MOD ) else skip ; return a * pow(a, b - 1) mod MOD ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static long MOD=998244353 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long a=sc.nextLong(); long b=sc.nextLong(); long k=sc.nextLong(); long[] comb=new long[n+1]; comb[0]=1 ; for(int i=1 ; i<=n ; i++){ comb[i]=div(((comb[i-1]*(n-i+1))% MOD),i,MOD); } long ans=0 ; for(int i=0 ; i<=n ; i++){ if((k-a*i)% b==0 && 0<=(k-a*i)/b &&(k-a*i)/b<=n){ ans+=comb[i]*comb[(int)((k-a*i)/b)]; ans %=MOD ; } } System.out.println(ans); } public static long pow(long a,long b,long mod){ if(b==0){ return 1 ; } else { long c=pow(a,b/2,mod); return((c*c % mod)*(b % 2==1 ? a : 1))% mod ; } } public static long div(long a,long b,long mod){ return(a*pow(b,mod-2,mod)% mod); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : long := 998244353; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; var comb : Sequence(long) ; comb := Integer.subrange(1,n + 1)->collect(0) ; comb[0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( ( comb[i+1] := div(((comb[i - 1+1] * (n - i + 1)) mod MOD), i, MOD) ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i <= n do ( ( if ((k - a * i) mod b = 0 & 0 <= (k - a * i) / b & (k - a * i) / b <= n) then ( ans := ans+(comb[i+1] * comb[((k - a * i) / b)->oclAsType(int)+1]) ; ans := ans mod MOD ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation pow( a : long, b : long, mod : long) : long pre: true post: true activity: ( if (b = 0) then ( return 1 ) else ( var c : long ; c := pow(a, b / 2, mod) ; return ((c * c mod mod) * (if b mod 2 = 1 then a else 1 endif)) mod mod ) ); static operation div( a : long, b : long, mod : long) : long pre: true post: true activity: ( return (a * pow(b, mod - 2, mod) mod mod) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long a=sc.nextLong(); long b=sc.nextLong(); long d=a-b ; boolean ok=false ; if(d==1)System.out.println("NO"); else System.out.println("YES"); } } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var d : long ; d := a - b ; var ok : boolean ; ok := false ; if (d = 1) then OclFile["System.out"].println("NO") else OclFile["System.out"].println("YES") ; ; ) ; ) ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); long a=Integer.parseInt(sc.next()); long b=Integer.parseInt(sc.next()); long k=Long.parseLong(sc.next()); int mod=998244353 ; int max=300_003 ; Mod_nCr mn=new Mod_nCr(mod,max); long ans=0 ; for(int red=0 ; red<=n ; red++){ int blue=(int)((k-red*a)/b); if(red*a+blue*b==k && 0<=blue){ ans+=mn.nCr(n,red)*mn.nCr(n,blue); ans %=mod ; } } System.out.println(ans); } } class Mod_nCr { int mod ; long[] fact ; long[] rfact ; public Mod_nCr(int mod,int max){ this.mod=mod ; fact=new long[max]; rfact=new long[max]; fact[0]=1 ; rfact[0]=1 ; for(int i=1 ; i0){ if(p % 2==1){ a=a*x % m ; } x=x*x % m ; p/=2 ; } return a ; } private long mod_inverse(long a,long m){ return mod_pow(a,m-2,m); } public long nCr(int n,int r){ if(ntoInteger() ; var a : long ; a := (sc.getCurrent())->toInteger() ; var b : long ; b := (sc.getCurrent())->toInteger() ; var k : long ; k := (sc.getCurrent())->toLong() ; var mod : int ; mod := 998244353 ; var max : int ; max := 300_003 ; var mn : Mod_nCr ; mn := Mod_nCr.newMod_nCr(mod, max) ; var ans : long ; ans := 0 ; var red : int ; red := 0 ; while red <= n do ( ( var blue : int ; blue := ((k - red * a) / b)->oclAsType(int) ; if (red * a + blue * b = k & 0 <= blue) then ( ans := ans+(mn.nCr(n, red) * mn.nCr(n, blue)) ; ans := ans mod mod ) else skip ) ; red := red + 1 ) ; OclFile["System.out"].println(ans) ; ); } class Mod_nCr { attribute mod : int; attribute fact : Sequence(long); attribute rfact : Sequence(long); static operation newMod_nCr( mod : int, max : int) : Mod_nCr pre: true post: true activity: ( var self : Mod_nCr ; self := createMod_nCr(); self.initialise(mod, max); return self ); operation initialise( mod : int, max : int) : void pre: true post: true activity: ( self.mod := mod ; fact := Integer.subrange(1,max)->collect(0) ; rfact := Integer.subrange(1,max)->collect(0) ; fact[0+1] := 1 ; rfact[0+1] := 1 ; var i : int ; i := 1 ; while i < max do ( ( fact[i+1] := (fact[i - 1+1] * i) mod mod ; rfact[i+1] := mod_inverse(fact[i+1], mod) ) ; i := i + 1 ) ; ); operation mod_pow( x : long, p : long, m : long) : long pre: true post: true activity: ( var a : long ; a := 1 ; while (p > 0) do ( if (p mod 2 = 1) then ( a := a * x mod m ) else skip ; x := x * x mod m ; p := p/(2) ) ; return a ); operation mod_inverse( a : long, m : long) : long pre: true post: true activity: ( return mod_pow(a, m - 2, m) ); operation nCr( n : int, r : int) : long pre: true post: true activity: ( if (n < r) then return 0 else skip ; return fact[n+1] * rfact[r+1] mod mod * rfact[n - r+1] mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.BigInteger ; class Main { public static long comb(long a,long b,long mod,long[] pw,long[] ipw){ return(((pw[(int)a]*ipw[(int)a-(int)b])% mod)*ipw[(int)b])% mod ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int max=400000 ; int mod=998244353 ; long[] pw=new long[max]; pw[0]=1 ; long[] ipw=new long[max]; BigInteger modb=new BigInteger(String.valueOf(mod)); for(int i=1 ; in || B<0)continue ; ans+=(comb(n,A,mod,pw,ipw)*comb(n,B,mod,pw,ipw))% mod ; ans %=mod ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation comb( a : long, b : long, mod : long, pw : Sequence(long), ipw : Sequence(long)) : long pre: true post: true activity: ( return (((pw[a->oclAsType(int)+1] * ipw[a->oclAsType(int) - b->oclAsType(int)+1]) mod mod) * ipw[b->oclAsType(int)+1]) mod mod ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var max : int ; max := 400000 ; var mod : int ; mod := 998244353 ; var pw : Sequence(long) ; pw := Integer.subrange(1,max)->collect(0) ; pw[0+1] := 1 ; var ipw : Sequence(long) ; ipw := Integer.subrange(1,max)->collect(0) ; var modb : long ; modb := long(((mod) + "")) ; var i : int ; i := 1 ; while i < max do ( ( pw[i+1] := (i * pw[i - 1+1]) mod mod ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < max do ( ( ipw[i+1] := long(((pw[i+1]) + "")).modInverse(modb)->oclAsType(long) ) ; i := i + 1 ) ; var n : long ; n := sc.getCurrent()->toLong() ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; var ans : long ; ans := 0 ; var A : int ; A := 0 ; while A <= n do ( ( if ((k - A * a) mod b /= 0) then continue else skip ; var B : long ; B := (k - A * a) / b ; if (B > n or B < 0) then continue else skip ; ans := ans+((comb(n, A, mod, pw, ipw) * comb(n, B, mod, pw, ipw)) mod mod) ; ans := ans mod mod ; ) ; A := A + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findEvenPair(int A[],int N){ int evenPair=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(findEvenPair(A, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final long MOD=998244353 ; private static long FACT[]; private static long IFACT[]; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long A=sc.nextInt(); long B=sc.nextInt(); long K=sc.nextLong(); solve(N,A,B,K); } private static void solve(int N,long A,long B,long K){ FACT=new long[N+1]; IFACT=new long[N+1]; FACT[0]=1 ; IFACT[0]=1 ; for(int i=1 ; i<=N ; i++){ FACT[i]=FACT[i-1]*i % MOD ; IFACT[i]=inv(FACT[i]); } long ans=0 ; for(int numA=0 ; numA<=N ; numA++){ long rem=K-A*numA ; if(rem<0){ break ; } int numB=(int)(rem/B); if(A*numA+B*numB==K && numB<=N){ ans=(ans+comb(N,numA)*comb(N,numB))% MOD ; } } System.out.println(ans); } private static long comb(int n,int r){ if(n<0 || r<0 || nn/2){ r=n-r ; } return FACT[n]*IFACT[n-r] % MOD*IFACT[r] % MOD ; } private static long inv(long a){ long b=MOD ; long p=1,q=0 ; while(b>0){ long c=a/b ; long d ; d=a ; a=b ; b=d % b ; d=p ; p=q ; q=d-c*q ; } return p<0 ? p+MOD : p ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : long := 998244353; static attribute FACT : Sequence(long); static attribute IFACT : Sequence(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : long ; A := sc.getCurrent()->toInteger() ; var B : long ; B := sc.getCurrent()->toInteger() ; var K : long ; K := sc.getCurrent()->toLong() ; execute solve(N, A, B, K) ; ); static operation solve( N : int, A : long, B : long, K : long) : void pre: true post: true activity: ( FACT := Integer.subrange(1,N + 1)->collect(0) ; IFACT := Integer.subrange(1,N + 1)->collect(0) ; FACT[0+1] := 1 ; IFACT[0+1] := 1 ; var i : int ; i := 1 ; while i <= N do ( ( FACT[i+1] := FACT[i - 1+1] * i mod MOD ; IFACT[i+1] := inv(FACT[i+1]) ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var numA : int ; numA := 0 ; while numA <= N do ( ( var rem : long ; rem := K - A * numA ; if (rem < 0) then ( break ) else skip ; var numB : int ; numB := (rem / B)->oclAsType(int) ; if (A * numA + B * numB = K & numB <= N) then ( ans := (ans + comb(N, numA) * comb(N, numB)) mod MOD ) else skip ) ; numA := numA + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation comb( n : int, r : int) : long pre: true post: true activity: ( if (n < 0 or r < 0 or n < r) then ( return 0 ) else skip ; if (r > n / 2) then ( r := n - r ) else skip ; return FACT[n+1] * IFACT[n - r+1] mod MOD * IFACT[r+1] mod MOD ); static operation inv( a : long) : long pre: true post: true activity: ( var b : long ; b := MOD ; var p : long ; p := 1 ; var q : long ; q := 0 ; while (b > 0) do ( var c : long ; c := a / b ; var d : long ; d := a ; a := b ; b := d mod b ; d := p ; p := q ; q := d - c * q ; ) ; return if p < 0 then p + MOD else p endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int min_elimination(int n,int arr[]){ int countOdd=0 ; for(int i=0 ; imin() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,7,9} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(min_elimination(n, arr)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedWriter ; import java.io.File ; import java.io.FileWriter ; import java.io.PrintWriter ; import java.util.Scanner ; public class b { public static void main(String[] Args)throws Exception { Scanner sc=new Scanner(new File("B-large.in")); PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(new File("b.out")))); int cc=0 ; int t=sc.nextInt(); while(t-->0){ String x=sc.next(); for(int i=0 ; ix.charAt(j+1)){ String nx=x.substring(0,j); nx=nx+(char)(x.charAt(j)-1); while(nx.length()1 && x.charAt(0)=='0')x=x.substring(1); out.printf("Case #%d: %s%n",++cc,x); } out.close(); } } ------------------------------------------------------------ OCL File: --------- class b { static operation main( Args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile("B-large.in")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile("b.out")))) ; var cc : int ; cc := 0 ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : String ; x := sc.getCurrent() ; var i : int ; i := 0 ; while i < x->size() do ( var j : int ; j := 0 ; while j + 1 < x->size() do ( if (x->at(j+1) > x->at(j + 1+1)) then ( var nx : String ; nx := x.subrange(0+1,j) ; nx := nx + (x->at(j+1) - 1)->oclAsType(String) ; while (nx->size() < x->size()) do nx := nx + "9" ; ; x := nx ) else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; while (x->size() > 1 & x->at(0+1) = '0') do x := x.subrange(1+1,1) ; ; skip ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class B { private String solveTest()throws IOException { String s=next(); int i=0 ; while(i=s.charAt(i)){ i++; } if(i==s.length()-1)return s ; while(i>0 && s.charAt(i-1)==s.charAt(i))i--; String res="" ; for(int j=0 ; jsize() - 1 & s->at(i + 1+1) >= s->at(i+1)) do ( i := i + 1 ) ; if (i = s->size() - 1) then return s else skip ; while (i > 0 & s->at((i)->char2byte() - 1+1) = s->at(i+1)) do i := i - 1 ; ; var res : String ; res := "" ; var j : int ; j := 0 ; while j < s->size() do ( ( res := res+(if j < i then s->at(j+1) else if j = i then (s->at(j+1) - 1)->oclAsType(String) else '9' endif endif) ) ; j := j + 1 ) ; if (res->at(0+1) = '0') then res := res.subrange(1+1,1) ; else skip ; return res ); operation solve() : void pre: true post: true activity: ( var n : int ; n := nextInt() ; var i : int ; i := 0 ; while i < n do ( ( var res : String ; res := solveTest() ; OclFile["System.out"].println("Case #" + (i + 1) + ": " + res) ; out.println("Case #" + (i + 1) + ": " + res) ) ; i := i + 1 ) ); attribute br : OclFile; attribute st : OclIterator; attribute out : OclFile; operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(br.readLine()) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( B.newB().run() ); operation run() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(self->oclType().getSimpleName().subrange(0+1,1) + ".in")) ; out := OclFile.newOclFile_Write(self->oclType().getSimpleName().subrange(0+1,1) + ".out") ; try ( execute solve() ) catch (e : IOException) do ( e.printStackTrace() ) skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package qualification ; import java.io.*; import java.util.*; public class B_TidyNumbers { private static final String FILENAME="B-large" ; private static final boolean STANDARD_OUTPUT=false ; public static void main(String[] args)throws Throwable { try(BufferedReader in=new BufferedReader(new FileReader(FILENAME+".in"))){ try(PrintStream out=! STANDARD_OUTPUT ? new PrintStream(FILENAME+".out"): System.out){ for(int t=1,T=Integer.parseInt(in.readLine()); t<=T ; t++){ char[] N=in.readLine().toCharArray(); int i=1,k=0 ; for(i=1 ; i=N[i-1]; i++){ } if(i=0 && N[k]==N[i-1]; k--){ } N[++k]--; Arrays.fill(N,k+1,N.length,'9'); k=k==0 && N[0]=='0' ? 1 : 0 ; } out.println("Case #"+t+": "+new String(N,k,N.length-k)); } } } } } ------------------------------------------------------------ OCL File: --------- class B_TidyNumbers { static attribute FILENAME : String := "B-large"; static attribute STANDARD_OUTPUT : boolean := false; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(FILENAME + ".in")) ; ( try ( var out : OclFile := if not(STANDARD_OUTPUT) then OclFile.newOclFile_Write(FILENAME + ".out") else OclFile["System.out"] endif ; ( var t : int ; t := 1 ; var T : int ; T := (in.readLine())->toInteger() ; while t <= T do ( ( var N : Sequence(String) ; N := in.readLine()->characters() ; var i : int ; i := 1 ; var k : int ; k := 0 ; i := 1 ; while i < N->size() & N[i+1] >= N[i - 1+1] do ( skip ; i := i + 1 ) ; if (i < N->size()) then ( k := i - 1 ; while k >= 0 & N[k+1] = N[i - 1+1] do ( skip ; k := k - 1 ) ; N[k+1] := N[k+1] - 1 ; N := N->collect('9') ; k := if k = 0 & N[0+1] = '0' then 1 else 0 endif ) else skip ; skip ; ) ; t := t + 1 ) )) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package com.company ; import java.io.FileInputStream ; import java.io.FileNotFoundException ; import java.io.FileOutputStream ; import java.io.PrintStream ; import java.util.Arrays ; import java.util.Scanner ; public class ProbB { private Scanner scanner=new Scanner(System.in); public void main(){ reDirect(); int T=scanner.nextInt(); for(int cas=1 ; cas<=T ; cas++){ long ans=run(); System.out.println("Case #"+cas+": "+ans); } } private long run(){ long input=scanner.nextLong(); char[] arr=Long.valueOf(input).toString().toCharArray(); int x=arr.length ; for(int i=0 ; iarr[i+1]){ x=i+1 ; break ; } } if(x==arr.length){ return input ; } int y=x-1 ; while(y>0 && arr[y]==arr[y-1])y--; arr[y]--; for(int i=y+1 ; itoInteger() ; var cas : int ; cas := 1 ; while cas <= T do ( ( var ans : long ; ans := run() ; OclFile["System.out"].println("Case #" + cas + ": " + ans) ) ; cas := cas + 1 ) ); operation run() : long pre: true post: true activity: ( var input : long ; input := scanner.getCurrent()->toLong() ; var arr : Sequence(String) ; arr := (input)->toLong()+""->characters() ; var x : int ; x := arr->size() ; var i : int ; i := 0 ; while i < arr->size() - 1 do ( ( if (arr[i+1] > arr[i + 1+1]) then ( x := i + 1 ; break ) else skip ) ; i := i + 1 ) ; if (x = arr->size()) then ( return input ) else skip ; var y : int ; y := x - 1 ; while (y > 0 & arr[y+1] = arr[y - 1+1]) do y := y - 1 ; ; arr[y+1] := arr[y+1] - 1 ; var i : int ; i := y + 1 ; while i < arr->size() do ( ( arr[i+1] := '9' ) ; i := i + 1 ) ; return (StringLib.newString(arr))->toLong() ); operation reDirect() : void pre: true post: true activity: ( try ( var fileInputStream : OclFile ; fileInputStream := OclFile.newOclFile_Read(OclFile.newOclFile("B-large.in")) ; scanner := OclFile.newOclFile_Read(fileInputStream) ; var ps : OclFile ; ps := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("bout-large.txt"))) ; setOut(ps) ) catch (e : FileNotFoundException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package qualifier ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public class BTidyNumbers { public static void main(String[] args){ try(Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)))){ int tests=sc.nextInt(); for(int t=1 ; t<=tests ; t++){ int[] digits=sc.next().chars().map(i->i-'0').toArray(); for(int x=0 ; xdigits[x+1]){ digits[x]--; for(int y=x+1 ; y0 && digits[x]toInteger() ; var t : int ; t := 1 ; while t <= tests do ( ( var digits : Sequence(int) ; digits := sc.getCurrent().chars()->collect( _x1 | (lambda i : OclAny in i - ('0')->char2byte())->apply(_x1) )->asSequence() ; var x : int ; x := 0 ; while x < digits->size() - 1 do ( ( if (digits[x+1] > digits[x + 1+1]) then ( digits[x+1] := digits[x+1] - 1 ; var y : int ; y := x + 1 ; while y < digits->size() do ( digits[y+1] := 9 ; ; y := y + 1 ) ; while (digits[x+1] < 0 or (x > 0 & digits[x+1] < digits[x - 1+1])) do ( digits[x+1] := 9 ; digits[x - 1+1] := digits[x - 1+1] - 1 ; x := x - 1 ) ; break ) else skip ) ; x := x + 1 ) ; var start : int ; start := 0 ; while (digits[start+1] = 0) do start := start + 1 ; ; var sb : String ; sb := StringLib.newString() ; var x : int ; x := start ; while x < digits->size() do ( sb := sb + StringLib.newString((digits[x+1] + '0')->oclAsType(String)) ; ; x := x + 1 ) ; OclFile["System.out"].printf("Case #%d: %s%n", t, sb+"") ; ) ; t := t + 1 ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class PrimeSubtraction { public static void main(String[] args){ Scanner iScanner=new Scanner(System.in); int test=iScanner.nextInt(); while(test>0){ test--; long a=iScanner.nextLong(); long b=iScanner.nextLong(); if(a-b!=1){ System.out.println("YES"); } else System.out.println("NO"); } } } ------------------------------------------------------------ OCL File: --------- class PrimeSubtraction { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var iScanner : OclFile ; iScanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := iScanner.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; var a : long ; a := iScanner.getCurrent()->toLong() ; var b : long ; b := iScanner.getCurrent()->toLong() ; if (a - b /= 1) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static class Node { int data ; Node next ; } static Node first,last ; static int length=0 ; static void printList(Node node){ while(node!=null){ System.out.printf("%d ",node.data); node=node.next ; } } static void moveToFront(Node head,Node p,int m){ if(head==null)return ; p=head ; head=head.next ; m++; if(length==m){ p.next=null ; last.next=first ; first=head ; } else moveToFront(head,p,m); } static Node push(Node head_ref,int new_data){ Node new_node=new 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++; return head_ref ; } public static void main(String[] args){ Node start=null ; start=push(start,5); start=push(start,4); start=push(start,3); start=push(start,2); start=push(start,1); start=push(start,0); System.out.printf("\n Initial Linked list\n"); printList(start); int m=4 ; Node temp=new Node(); moveToFront(start,temp,m); System.out.printf("\n Final Linked list\n"); start=first ; printList(start); } } ------------------------------------------------------------ OCL File: --------- class GFG { static class Node { attribute data : int; attribute next : Node; } static attribute first : Node; static attribute length : int := 0; static operation printList( node : Node) : void pre: true post: true activity: ( while (node /= null) do ( OclFile["System.out"].printf("%d ", node.data) ; node := node.next ) ); static operation moveToFront( head : Node, p : Node, m : int) : void pre: true post: true activity: ( if (head = null) then return else skip ; p := head ; head := head.next ; m := m + 1 ; if (length = m) then ( p.next := null ; last.next := first ; first := head ) else execute moveToFront(head, p, m) ; ; ); static operation push( head_ref : Node, new_data : int) : Node pre: true post: true activity: ( var new_node : Node ; new_node := Node.newNode() ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; if (length = 0) then last := head_ref else first := head_ref ; ; length := length + 1 ; return head_ref ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var start : Node ; start := null ; start := push(start, 5) ; start := push(start, 4) ; start := push(start, 3) ; start := push(start, 2) ; start := push(start, 1) ; start := push(start, 0) ; OclFile["System.out"].printf("\n Initial Linked list\n") ; execute printList(start) ; var m : int ; m := 4 ; var temp : Node ; temp := Node.newNode() ; execute moveToFront(start, temp, m) ; OclFile["System.out"].printf("\n Final Linked list\n") ; start := first ; execute printList(start) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int count9s(String number){ int count=0 ; int n=number.length(); for(int i=0 ; isize() ; var i : int ; i := 0 ; while i < n do ( ( var sum : int ; sum := number->at(i+1) - ('0')->char2byte() ; if (number->at(i+1) = '9') then count := count + 1 ; else skip ; var j : int ; j := i + 1 ; while j < n do ( ( sum := (sum + number->at(j+1) - ('0')->char2byte()) mod 9 ; if (sum = 0) then count := count + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(count9s("4189")) ; OclFile["System.out"].println(count9s("1809")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findExtra(int arr1[],int arr2[],int n){ int index=n ; int left=0,right=n-1 ; while(left<=right){ int mid=(left+right)/2 ; if(arr2[mid]==arr1[mid])left=mid+1 ; else { index=mid ; right=mid-1 ; } } return index ; } public static void main(String[] args){ int arr1[]={ 2,4,6,8,10,12,13 }; int arr2[]={ 2,4,6,8,10,12 }; int n=arr2.length ; System.out.println(findExtra(arr1,arr2,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findExtra( arr1 : Sequence(int), arr2 : Sequence(int), n : int) : int pre: true post: true activity: ( var index : int ; index := n ; var left : int ; left := 0 ; var right : int ; right := n - 1 ; while (left <= right) do ( var mid : int ; mid := (left + right) / 2 ; if (arr2[mid+1] = arr1[mid+1]) then left := mid + 1 ; else ( index := mid ; right := mid - 1 ) ) ; return index ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr1 : Sequence(int) ; arr1 := Sequence{2,4,6,8,10,12,13} ; var arr2 : Sequence(int) ; arr2 := Sequence{2,4,6,8,10,12} ; var n : int ; n := arr2->size() ; OclFile["System.out"].println(findExtra(arr1, arr2, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findevenPair(int[] A,int N){ int i,j ; int evenPair=0 ; for(i=0 ; isize() ; OclFile["System.out"].println(findevenPair(A, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static void parallel(int a[][]){ boolean x=true,y=true ; for(int i=0 ; isize() - 1 do ( ( var j : int ; j := 0 ; while j < 2 do ( ( if (a[i+1][0+1] /= a[i + 1+1][0+1]) then x := false ; else skip ; if (a[i+1][1+1] /= a[i + 1+1][1+1]) then y := false ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (x) then OclFile["System.out"].println("Parallel to X Axis") ; else if (y) then OclFile["System.out"].println("Parallel to Y Axis") else OclFile["System.out"].println("Not parallel to X" + " and Y axis") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(Sequence(int)) ; a := Sequence{Sequence{1,2},Sequence{1,4},Sequence{1,6},Sequence{1,0}} ; execute parallel(a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.*; import java.util.*; public class b { static BufferedReader f ; static StringTokenizer st ; static StringBuilder ans=new StringBuilder(); public static void tc()throws IOException { st=new StringTokenizer(f.readLine()); int n=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(st.nextToken()); int[] arr=new int[n*m]; int[][] grid=new int[n][m]; for(int i=0 ; itoInteger() ; var m : int ; m := (st.next())->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n * m)->collect(0) ; var grid : Sequence(Sequence(int)) ; grid := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( st := OclIterator.newOclIterator_String(f.readLine()) ; var x : int ; x := 0 ; while x < m do ( ( var curr : int ; curr := (st.next())->toInteger() - 1 ; arr[curr+1] := i ; grid[i+1][x+1] := curr ) ; x := x + 1 ) ) ; i := i + 1 ) ; var op : Sequence(int) ; op := Integer.subrange(1,n)->collect(0) ; st := OclIterator.newOclIterator_String(f.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( var curr : int ; curr := (st.next())->toInteger() - 1 ; op[i+1] := arr[curr+1] ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m - 1 do ( ( st := OclIterator.newOclIterator_String(f.readLine()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := 0 ; while x < m do ( ( ans := ans + StringLib.newString(grid[op[i+1]+1][x+1] + 1 + " ") ) ; x := x + 1 ) ; ans := ans + StringLib.newString("\n") ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( f := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; st := OclIterator.newOclIterator_String(f.readLine()) ; var t : int ; t := (st.next())->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( execute tc() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B1413 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); StringBuilder output=new StringBuilder(); for(int t=0 ; ttoInteger() ; var output : String ; output := StringLib.newString() ; var t : int ; t := 0 ; while t < T do ( ( var R : int ; R := in.getCurrent()->toInteger() ; var C : int ; C := in.getCurrent()->toInteger() ; var rows : Sequence(Sequence(int)) ; rows := Integer.subrange(1,R)->collect(Sequence{}) ; var rowIndex : Sequence(int) ; rowIndex := Integer.subrange(1,R * C + 1)->collect(0) ; var r : int ; r := 0 ; while r < R do ( ( var row : Sequence(int) ; row := Integer.subrange(1,C)->collect(0) ; var c : int ; c := 0 ; while c < C do ( ( var a : int ; a := in.getCurrent()->toInteger() ; row[c+1] := a ; rowIndex[a+1] := r ) ; c := c + 1 ) ; rows[r+1] := row ) ; r := r + 1 ) ; var c : int ; c := 0 ; while c < C do ( ( var r : int ; r := 0 ; while r < R do ( ( var a : int ; a := in.getCurrent()->toInteger() ; if (c = 0) then ( for (elem : rows[rowIndex[a+1]+1]) do ( ( output := output + StringLib.newString(elem) + StringLib.newString(' ') ) ) ; output := output + StringLib.newString(' ') ) else skip ) ; r := r + 1 ) ) ; c := c + 1 ) ; ) ; t := t + 1 ) ; OclFile["System.out"].print(output) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countTriangles(int a[],int n){ int cnt=0 ; int pairs=0 ; for(int i=n-1 ; i>=0 ; i--){ pairs+=a[i]/2 ; if(a[i] % 2==1 && pairs>0){ cnt+=1 ; pairs-=1 ; } } cnt+=(2*pairs)/3 ; return cnt ; } public static void main(String[] args){ int a[]={ 1,2,2,2,2 }; int n=a.length ; System.out.println(countTriangles(a,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countTriangles( a : Sequence(int), n : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var pairs : int ; pairs := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( pairs := pairs+(a[i+1] / 2) ; if (a[i+1] mod 2 = 1 & pairs > 0) then ( cnt := cnt+(1) ; pairs := pairs-(1) ) else skip ) ; i := i - 1 ) ; cnt := cnt+((2 * pairs) / 3) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,2,2,2,2} ; var n : int ; n := a->size() ; OclFile["System.out"].println(countTriangles(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int findMaxXOR(Vectorarr,int n){ Vectorstack=new Vector(); int res=0,l=0,i ; for(i=0 ; i1){ res=Math.max(res,stack.get(l-1)^ stack.get(l-2)); } } return res ; } public static void main(String[] args){ Integer[] temp={ 9,8,3,5,7 }; Vectorarr=new Vector<>(Arrays.asList(temp)); int result1=findMaxXOR(arr,5); Collections.reverse(arr); int result2=findMaxXOR(arr,5); System.out.print(Math.max(result1,result2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findMaxXOR( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var stack : Sequence(int) ; stack := Sequence{} ; var res : int ; res := 0 ; var l : int ; l := 0 ; var i : int ; i := 0 ; while i < n do ( ( while (not(stack->isEmpty()) & stack->at(stack->size() - 1+1) < arr->at(i+1)) do ( stack := stack->excludingFirst(stack->size() - 1) ; l := l - 1 ) ; stack := stack->including(arr->at(i+1)) ; l := l + 1 ; if (l > 1) then ( res := Set{res, stack->at(l - 1+1) xor stack->at(l - 2+1)}->max() ) else skip ) ; i := i + 1 ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var temp : Sequence(int) ; temp := Sequence{9,8,3,5,7} ; var arr : Sequence(int) ; arr := Sequence{}->union(temp) ; var result1 : int ; result1 := findMaxXOR(arr, 5) ; arr := arr->reverse() ; var result2 : int ; result2 := findMaxXOR(arr, 5) ; OclFile["System.out"].print(Set{result1, result2}->max()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean asPowerSum(int w,int m){ while(m>0){ if((m-1)% w==0)m=(m-1)/w ; else if((m+1)% w==0)m=(m+1)/w ; else if(m % w==0)m=m/w ; else break ; } return(m==0); } public static void main(String[] args){ int w=3,m=7 ; if(asPowerSum(w,m))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation asPowerSum( w : int, m : int) : boolean 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) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var w : int ; w := 3 ; var m : int ; m := 7 ; if (asPowerSum(w, m)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class A_Prime_Subtraction { public static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader reader=new FastReader(); int T=reader.nextInt(); while(T!=0){ T--; long x=reader.nextLong(); long y=reader.nextLong(); if(x-y==1L){ System.out.println("NO"); } else { System.out.println("YES"); } } } } ------------------------------------------------------------ OCL File: --------- class A_Prime_Subtraction { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : FastReader ; reader := FastReader.newFastReader() ; var T : int ; T := reader.nextInt() ; while (T /= 0) do ( T := T - 1 ; var x : long ; x := reader.nextLong() ; var y : long ; y := reader.nextLong() ; if (x - y = 1L) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Graph { int V ; Vector[] adj ; Graph(int V){ this.V=V ; this.adj=new Vector[V]; for(int i=0 ; i(); } void addEdge(int u,int v){ adj[u] .add(v); adj[v] .add(u); } int countEdges(){ int sum=0 ; for(int i=0 ; icollect(null) ; var i : int ; i := 0 ; while i < V do ( adj[i+1] := Sequence{} ; ; i := i + 1 ) ); operation addEdge( u : int, v : int) : void pre: true post: true activity: ( adj[u+1]->excludes(v) ; adj[v+1]->excludes(u) ); operation countEdges() : int pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < V do ( sum := sum+(adj[i+1]->size()) ; ; i := i + 1 ) ; return sum / 2 ); } class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var V : int ; V := 9 ; var g : Graph ; g := Graph.newGraph(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) ; OclFile["System.out"].println(g.countEdges()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GfG { public static int findremainder(int arr[],int len,int n){ int mul=1 ; for(int i=0 ; i0){ bit=N % 2 ; if(bit==0)count++; N=N/2 ; } return(int)Math.pow(2,count); } public static void main(String args[]){ int N=7 ; System.out.println(xorEqualsOrCount(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation xorEqualsOrCount( N : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var bit : int ; while (N > 0) do ( bit := N mod 2 ; if (bit = 0) then count := count + 1 ; else skip ; N := N / 2 ) ; return 2->pow(count)->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 7 ; OclFile["System.out"].println(xorEqualsOrCount(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.regex.Matcher ; import java.util.regex.Pattern ; public class Main { public static void main(String[] args){ @ SuppressWarnings("resource")Scanner sc=new Scanner(System.in); String s=sc.nextLine(); String ptn=sc.nextLine(); ptn=ptn.replaceAll("_","."); Matcher m=Pattern.compile(ptn).matcher(s); if(m.find()){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.nextLine() ; var ptn : String ; ptn := sc.nextLine() ; ptn := ptn.replaceAllMatches("_", "." ) ; var m : OclRegex ; m := OclRegex.compile(ptn).matcher(s) ; if (m.nextMatch()) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int rangeGCD(int n,int m){ return(n==m)? n : 1 ; } public static void main(String[] args){ int n=475 ; int m=475 ; System.out.println(rangeGCD(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation rangeGCD( n : int, m : int) : int pre: true post: true activity: ( return if (n = m) then n else 1 endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 475 ; var m : int ; m := 475 ; OclFile["System.out"].println(rangeGCD(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.regex.*; class Main { public static void main(String[] z){ Scanner cin=new Scanner(System.in); String s=cin.next(); String t=cin.next().replaceAll("_","."); Matcher m=Pattern.compile(t).matcher(s); System.out.println(m.find()? "Yes" : "No"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( z : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := cin.getCurrent() ; var t : String ; t := cin.getCurrent().replaceAllMatches("_", "." ) ; var m : OclRegex ; m := OclRegex.compile(t).matcher(s) ; OclFile["System.out"].println(if m.nextMatch() then "Yes" else "No" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.lang.Math ; import java.io.*; class GFG { static double getValue(double n){ double result=(Math.floor(Math.log(n+1)/Math.log(2))); return Math.pow(2,result); } public static void main(String[] args){ double n=9 ; System.out.println(getValue(n)); n=1025 ; System.out.println(getValue(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getValue( n : double) : double pre: true post: true activity: ( var result : double ; result := (((n + 1)->log() / (2)->log())->floor()) ; return 2->pow(result) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : double ; n := 9 ; OclFile["System.out"].println(getValue(n)) ; n := 1025 ; OclFile["System.out"].println(getValue(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int[][] q=new int[8][8]; static int[][] ok=new int[8][8]; static int cnt=0 ; static void mark(int a,int b,int x){ for(int i=0 ; i<8 ; i++){ for(int j=0 ; j<8 ; j++){ if(i==a || j==b || Math.abs(i-a)==Math.abs(j-b)){ ok[i][j]+=x ; } } } } static void dfs(int a){ if(cnt==8)return ; if(a==64)return ; int i=a/8 ; int j=a % 8 ; if(ok[i][j]==0){ mark(i,j,1); q[i][j]=1 ; cnt++; dfs(a+1); if(cnt==8)return ; mark(i,j,-1); q[i][j]=0 ; cnt--; dfs(a+1); if(cnt==8)return ; } else { dfs(a+1); if(cnt==8)return ; } } public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); for(int i=0 ; icollect(Integer.subrange(1,8)->collect(0)); static attribute ok : Sequence(Sequence(int)) := Integer.subrange(1,8)->collect(Integer.subrange(1,8)->collect(0)); static attribute cnt : int := 0; static operation mark( a : int, b : int, x : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < 8 do ( ( var j : int ; j := 0 ; while j < 8 do ( ( if (i = a or j = b or if i - a < 0 then -(i - a) else i - a endif = if j - b < 0 then -(j - b) else j - b endif) then ( ok[i+1][j+1] := ok[i+1][j+1]+(x) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ); static operation dfs( a : int) : void pre: true post: true activity: ( if (cnt = 8) then return else skip ; if (a = 64) then return else skip ; var i : int ; i := a / 8 ; var j : int ; j := a mod 8 ; if (ok[i+1][j+1] = 0) then ( execute mark(i, j, 1) ; q[i+1][j+1] := 1 ; cnt := cnt + 1 ; execute dfs(a + 1) ; if (cnt = 8) then return else skip ; execute mark(i, j, -1) ; q[i+1][j+1] := 0 ; cnt := cnt - 1 ; execute dfs(a + 1) ; if (cnt = 8) then return else skip ; ) else ( execute dfs(a + 1) ; if (cnt = 8) then return else skip ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < k do ( ( var r : int ; r := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; execute mark(r, c, 1) ; q[r+1][c+1] := 1 ) ; i := i + 1 ) ; cnt := k ; execute dfs(0) ; var i : int ; i := 0 ; while i < 8 do ( ( var j : int ; j := 0 ; while j < 8 do ( ( if (q[i+1][j+1] = 1) then ( OclFile["System.out"].print("Q") ) else ( OclFile["System.out"].print(".") ) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Board { int[] Q ; boolean[] filled ; Board(){ Q=new int[8]; filled=new boolean[8]; Arrays.fill(Q,-1); Scanner sc=new Scanner(System.in); int k=sc.nextInt(); for(int i=0 ; i=8){ return true ; } if(filled[row]){ return solve(row+1); } for(int c=0 ; c<8 ; ++c){ if(can_place(row,c)){ Q[row]=c ; if(solve(row+1)){ return true ; } Q[row]=-1 ; } } return false ; } boolean can_place(int row,int col){ for(int r=0 ; r<8 ; ++r){ if(Q[r]==col)return false ; int row_difference=Math.abs(r-row); if(Q[r]>=0 &&(Q[r]==col+row_difference || Q[r]==col-row_difference))return false ; } return true ; } void print(){ for(int r=0 ; r<8 ; ++r){ for(int c=0 ; ccollect(0) ; filled := Integer.subrange(1,8)->collect(false) ; Q := Q->collect(-1) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < k do ( ( var r : int ; r := sc.getCurrent()->toInteger() ; filled[r+1] := true ; var c : int ; c := sc.getCurrent()->toInteger() ; Q[r+1] := c ) ; i := i + 1 ) ; ); operation solve( row : int) : boolean pre: true post: true activity: ( if (row >= 8) then ( return true ) else skip ; if (filled[row+1]) then ( return solve(row + 1) ) else skip ; var c : int ; c := 0 ; while c < 8 do ( ( if (can_place(row, c)) then ( Q[row+1] := c ; if (solve(row + 1)) then ( return true ) else skip ; Q[row+1] := -1 ) else skip ) ; c := c + 1 ) ; return false ); operation can_place( row : int, col : int) : boolean pre: true post: true activity: ( var r : int ; r := 0 ; while r < 8 do ( ( if (Q[r+1] = col) then return false else skip ; var row_difference : int ; row_difference := if r - row < 0 then -(r - row) else r - row endif ; if (Q[r+1] >= 0 & (Q[r+1] = col + row_difference or Q[r+1] = col - row_difference)) then return false else skip ) ; r := r + 1 ) ; return true ); operation print() : void pre: true post: true activity: ( var r : int ; r := 0 ; while r < 8 do ( ( var c : int ; c := 0 ; while c < Q[r+1] do ( ( OclFile["System.out"].print(".") ) ; c := c + 1 ) ; OclFile["System.out"].print("Q") ; var c : int ; c := Q[r+1] + 1 ; while c < 8 do ( ( OclFile["System.out"].print(".") ) ; c := c + 1 ) ; OclFile["System.out"].println() ) ; r := r + 1 ) ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var b : Board ; b := Board.newBoard() ; b.solve(0) ; b.print() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); r=new int[8]; Arrays.fill(r,-1); int k=sc.nextInt(); for(int i=0 ; i=j-i && perm[j]==perm[i]-(j-i)){ flag=false ; break ; } } } if(flag){ res=perm.clone(); } } return ; } for(int i=0 ; icollect(0) ; r := r->collect(-1) ; var k : int ; k := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < k do ( ( r[sc.getCurrent()->toInteger()+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; used := Integer.subrange(1,8)->collect(false) ; perm := Integer.subrange(1,8)->collect(0) ; execute permutation(0, 8) ; var q : Sequence(String) ; q := Sequence{"Q.......",".Q......","..Q.....","...Q....","....Q...",".....Q..","......Q.",".......Q"} ; var i : int ; i := 0 ; while i < 8 do ( ( OclFile["System.out"].println(q[res[i+1]+1]) ) ; i := i + 1 ) ; skip ; ); static attribute r : Sequence(int); static attribute res : Sequence(int); static attribute used : Sequence(boolean); static attribute perm : Sequence(int); static operation permutation( pos : int, n : int) : void pre: true post: true activity: ( if (pos = n) then ( var i : int ; i := 0 ; while i < n do ( ( if (r[i+1] /= -1 & r[i+1] /= perm[i+1]) then ( return ) else skip ) ; i := i + 1 ) ; if (res = null) then ( var flag : boolean ; flag := true ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( if (perm[i+1] < n - (j - i) & perm[j+1] = perm[i+1] + j - i) then ( flag := false ; break ) else skip ; if (perm[i+1] >= j - i & perm[j+1] = perm[i+1] - (j - i)) then ( flag := false ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (flag) then ( res := perm->copy() ) else skip ) else skip ; return ) else skip ; var i : int ; i := 0 ; while i < n do ( ( if (not(used[i+1])) then ( perm[pos+1] := i ; used[i+1] := true ; execute permutation(pos + 1, n) ; used[i+1] := false ) else skip ) ; i := i + 1 ) ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long a=sc.nextLong(); long b=sc.nextLong(); if(atoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; if (a < b) then OclFile["System.out"].println(b - a) ; else ( if (a mod 2 /= b mod 2) then OclFile["System.out"].println(1) ; else OclFile["System.out"].println(0) ; ) ) ; ) ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static final int[] queens=new int[8]; static final boolean[] threatend=new boolean[8]; public static void main(String[] Args)throws IOException { final BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); final int n=Integer.parseInt(br.readLine()); for(int i=0 ; i=8)return true ; if(threatend[r])return available(r,queens[r])&& check(r+1); for(int i=0 ; i<8 ; i++){ queens[r]=i ; if(available(r,i)&& check(r+1))return true ; } return false ; } private static boolean available(int r,int c){ for(int i=0 ; i<8 ; i++){ if(ir && threatend[i])){ if(c==queens[i])return false ; if(Math.abs(c-queens[i])==Math.abs(r-i))return false ; } } return true ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute queens : Sequence(int) := Integer.subrange(1,8)->collect(0); static attribute threatend : Sequence(boolean) := Integer.subrange(1,8)->collect(false); static operation main( Args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String_String(br.readLine(), " ") ; var r : int ; r := (st.next())->toInteger() ; var c : int ; c := (st.next())->toInteger() ; queens[r+1] := c ; threatend[r+1] := true ; ) ; i := i + 1 ) ; execute check(0) ; var output : Sequence(String) ; output := Integer.subrange(1,72)->collect(0) ; output := output->collect('.') ; var i : int ; i := 8 ; while i < 72 do ( ( output[i+1] := ' ' ) ; i := i+(9) ) ; var i : int ; i := 0 ; while i < 8 do ( ( output[i * 9 + queens[i+1]+1] := 'Q' ) ; i := i + 1 ) ; OclFile["System.out"].print(output) ; ); static operation check( r : int) : boolean pre: true post: true activity: ( if (r >= 8) then return true else skip ; if (threatend[r+1]) then return available(r, queens[r+1]) & check(r + 1) else skip ; var i : int ; i := 0 ; while i < 8 do ( ( queens[r+1] := i ; if (available(r, i) & check(r + 1)) then return true else skip ) ; i := i + 1 ) ; return false ); static operation available( r : int, c : int) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < 8 do ( ( if (i < r or (i > r & threatend[i+1])) then ( if (c = queens[i+1]) then return false else skip ; if (if c - queens[i+1] < 0 then -(c - queens[i+1]) else c - queens[i+1] endif = if r - i < 0 then -(r - i) else r - i endif) then return false else skip ) else skip ) ; i := i + 1 ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isCyclic(long N){ long num=N ; int count=0 ; int digit=(int)(num % 10); boolean allSame=true ; while(num>0){ count++; if(num % 10!=digit)allSame=false ; num=num/10 ; } if(allSame==true)return false ; if(count % 2==0){ long halfPower=(long)Math.pow(10,count/2); long firstHalf=N % halfPower ; long secondHalf=N/halfPower ; if(firstHalf==firstHalf && isCyclic(firstHalf))return false ; } num=N ; while(true){ long rem=num % 10 ; long div=num/10 ; num=(long)(Math.pow(10,count-1))*rem+div ; if(num==N)break ; if(num % N!=0)return false ; } return true ; } public static void main(String[] args){ long N=142857 ; if(isCyclic(N))System.out.print("Yes"); else System.out.print("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isCyclic( N : long) : boolean pre: true post: true activity: ( var num : long ; num := N ; var count : int ; count := 0 ; var digit : int ; digit := (num mod 10)->oclAsType(int) ; var allSame : boolean ; allSame := true ; while (num > 0) do ( count := count + 1 ; if (num mod 10 /= digit) then allSame := false ; else skip ; num := num / 10 ) ; if (allSame = true) then return false else skip ; if (count mod 2 = 0) then ( var halfPower : long ; halfPower := 10->pow(count / 2)->oclAsType(long) ; var firstHalf : long ; firstHalf := N mod halfPower ; var secondHalf : long ; secondHalf := N / halfPower ; if (firstHalf = firstHalf & isCyclic(firstHalf)) then return false else skip ) else skip ; num := N ; while (true) do ( var rem : long ; rem := num mod 10 ; var div : long ; div := num / 10 ; num := (10->pow(count - 1))->oclAsType(long) * rem + div ; if (num = N) then break else skip ; if (num mod N /= 0) then return false else skip ; ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : long ; N := 142857 ; if (isCyclic(N)) then OclFile["System.out"].print("Yes") ; else OclFile["System.out"].print("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean subarrayPossible(int arr[],int n){ int sum=0 ; for(int i=0 ; i=0 ; i--){ sum+=arr[i]; if(sum<=0)return true ; } return false ; } public static void main(String args[]){ int arr[]={ 10,5,-12,7,-10,20,30,-10,50,60 }; int size=arr.length ; if(subarrayPossible(arr,size))System.out.print("Yes"+"\n"); else System.out.print("No"+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation subarrayPossible( arr : Sequence(int), n : int) : boolean pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(arr[i+1]) ; if (sum <= 0) then return true else skip ) ; i := i + 1 ) ; sum := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( sum := sum+(arr[i+1]) ; if (sum <= 0) then return true else skip ) ; i := i - 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,5,-12,7,-10,20,30,-10,50,60} ; var size : int ; size := arr->size() ; if (subarrayPossible(arr, size)) then OclFile["System.out"].print("Yes" + "\n") ; else OclFile["System.out"].print("No" + "\n") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static String largestSubStr(String s){ while(s.length()!=0 && s.charAt(s.length()-1)=='1')s=s.substring(0,s.length()-1); if(s.length()==0)return "-1" ; else return s ; } public static void main(String[] args){ String s="11001" ; System.out.println(largestSubStr(s)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation largestSubStr( s : String) : String pre: true post: true activity: ( while (s->size() /= 0 & s->at(s->size() - 1+1) = '1') do s := s.subrange(0+1,s->size() - 1) ; ; if (s->size() = 0) then return "-1" else return s ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "11001" ; OclFile["System.out"].println(largestSubStr(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static int[][] multi ; static int[] line ; static int[] col ; static int rec(int m,int n){ if(m==n)return 0 ; if(multi[m][n]==0){ int min=Integer.MAX_VALUE ; for(int i=m ; itoInteger() ; multi := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; line := Integer.subrange(1,n)->collect(0) ; col := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( line[i+1] := scan.getCurrent()->toInteger() ; col[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; OclFile["System.out"].println(rec(0, n - 1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static final int MAX=100 ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] in ; int[] a=new int[MAX+1]; for(int i=0 ; itoInteger() ; var in : Sequence(String) ; var a : Sequence(int) ; a := Integer.subrange(1,MAX + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( in := br.readLine()->split(" ") ; a[i+1] := (in[0+1])->toInteger() ; if (i = n - 1) then ( a[i + 1+1] := (in[1+1])->toInteger() ) else skip ) ; i := i + 1 ) ; var cost : Sequence(Sequence(long)) ; cost := Integer.subrange(1,MAX)->collect(Integer.subrange(1,MAX)->collect(0)) ; execute calcCost(a, cost) ; OclFile["System.out"].println(cost[0+1][n - 1+1]) ; ); static operation calcCost( a : Sequence(int), cost : Sequence(Sequence(long))) : void pre: true post: true activity: ( var n : int ; n := cost->size() ; var k : int ; k := 0 ; while k < n do ( ( var i : int ; i := 0 ; while i + k < n do ( ( if (k = 0) then ( cost[i+1][k+1] := 0 ; continue ) else skip ; cost[i+1][k+1] := "9223372036854775807"->toLong() ; var j : int ; j := 0 ; while j < k do ( ( var c : long ; c := cost[i+1][j+1] + cost[i + j + 1+1][k - j - 1+1] + a[i+1] * a[i + j + 1+1] * a[i + k + 1+1] ; if (c < cost[i+1][k+1]) then ( cost[i+1][k+1] := c ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ) ; k := k + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { static int[][] dp ; static int[] p ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.nextLine()); dp=new int[n+1][n+1]; p=new int[n+1]; for(int i=0 ; itoInteger() ; dp := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; p := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var input : Sequence(int) ; input := stream(sc.nextLine()->split(" "))->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ; p[i+1] := input[0+1] ; p[i + 1+1] := input[1+1] ) ; i := i + 1 ) ; out.println(count(1, n)) ; ); static operation count( i : int, j : int) : int pre: true post: true activity: ( if (dp[i+1][j+1] /= 0 or i = j) then return dp[i+1][j+1] else skip ; if (i - j = 1) then return dp[i+1][j+1] else skip ; var min : int ; min := 2147483647 ; var k : int ; k := i ; while k < j do ( ( min := Set{min, count(i, k) + count(k + 1, j) + p[i - 1+1] * p[k+1] * p[j+1]}->min() ) ; k := k + 1 ) ; return dp[i+1][j+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class IS { public static void main(String[] args){ new IS().runapp(); } void runapp(){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int d=scan.nextInt(); int[] sequence=new int[n]; int step=0 ; int store ; for(int x=0 ; xtoInteger() ; var d : int ; d := scan.getCurrent()->toInteger() ; var sequence : Sequence(int) ; sequence := Integer.subrange(1,n)->collect(0) ; var step : int ; step := 0 ; var store : int ; var x : int ; x := 0 ; while x < n do ( ( sequence[x+1] := scan.getCurrent()->toInteger() ) ; x := x + 1 ) ; var y : int ; y := 0 ; while y < n - 1 do ( ( while (sequence[y + 1+1] <= sequence[y+1]) do ( var diff : int ; diff := sequence[y + 1+1] - sequence[y+1] ; if (sequence[y + 1+1] = sequence[y+1]) then ( sequence[y + 1+1] := sequence[y + 1+1] + d ; step := step + 1 ) else ( diff := -diff ; store := (diff / d) + 1 ; step := step + store ; sequence[y + 1+1] := sequence[y + 1+1] + (d * store) ) ) ) ; y := y + 1 ) ; OclFile["System.out"].printf("%d", step) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public int findCost(int arr[]){ int temp[][]=new int[arr.length][arr.length]; int q=0 ; for(int l=2 ; lsize())->collect(Integer.subrange(1,arr->size())->collect(0)) ; var q : int ; q := 0 ; var l : int ; l := 2 ; while l < arr->size() do ( ( var i : int ; i := 0 ; while i < arr->size() - l do ( ( var j : int ; j := i + l ; temp[i+1][j+1] := 1000000 ; var k : int ; k := i + 1 ; while k < j do ( ( q := temp[i+1][k+1] + temp[k+1][j+1] + arr[i+1] * arr[k+1] * arr[j+1] ; if (q < temp[i+1][j+1]) then ( temp[i+1][j+1] := q ) else skip ) ; k := k + 1 ) ) ; i := i + 1 ) ) ; l := l + 1 ) ; return temp[0+1][arr->size() - 1+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mmc : Main ; mmc := Main.newMain() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 1 ; while i < N + 1 do ( ( arr[i - 1+1] := sc.getCurrent()->toInteger() ; arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var cost : int ; cost := mmc.findCost(arr) ; OclFile["System.out"].println(cost) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; public class P1301A { public static void main(String[] args)throws IOException { BufferedReader io=new BufferedReader(new InputStreamReader(System.in)); Integer cnt=Integer.valueOf(io.readLine()); Listrs=new ArrayList(); while(cnt>0){ cnt--; String a=io.readLine(); String b=io.readLine(); String c=io.readLine(); Boolean flag=true ; for(int i=0 ; itoInteger() ; var rs : Sequence(String) ; rs := Sequence{} ; while (cnt > 0) do ( cnt := cnt - 1 ; var a : String ; a := io.readLine() ; var b : String ; b := io.readLine() ; var c : String ; c := io.readLine() ; var flag : Boolean ; flag := true ; var i : int ; i := 0 ; while i < c->size() do ( ( if (c->at(i+1) /= a->at(i+1) & c->at(i+1) /= b->at(i+1)) then ( flag := false ; break ) else skip ) ; i := i + 1 ) ; if (flag) then ( rs := rs->including("YES") ) else ( rs := rs->including("NO") ) ; ) ; for (string : rs) do ( ( OclFile["System.out"].println(string) ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String a ; String b ; String c ; boolean flag=true ; int n=scan.nextInt(); for(int i=1 ; i<=n ; i++){ flag=true ; a=scan.next(); b=scan.next(); c=scan.next(); for(int j=0 ; jtoInteger() ; var i : int ; i := 1 ; while i <= n do ( ( flag := true ; a := scan.getCurrent() ; b := scan.getCurrent() ; c := scan.getCurrent() ; var j : int ; j := 0 ; while j < a->size() do ( ( if (a->at(j+1) = b->at(j+1)) then ( if (c->at(j+1) /= a->at(j+1)) then ( flag := false ) else skip ) else if (a->at(j+1) /= b->at(j+1)) then ( if (c->at(j+1) = a->at(j+1) or c->at(j+1) = b->at(j+1)) then continue else ( flag := false ) ) else skip ; ) ; j := j + 1 ) ; if (flag) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ String a=null,b=null,c=null ; Scanner sc=new Scanner(System.in); int n=sc.nextInt(),length,i,flag ; sc.nextLine(); while(n--!=0){ flag=1 ; a=sc.nextLine(); b=sc.nextLine(); c=sc.nextLine(); length=a.length(); for(i=0 ; itoInteger() ; var length : int ; var i : int ; var flag : int ; skip ; while (n /= 0) do ( skip ; ( flag := 1 ; a := sc.nextLine() ; b := sc.nextLine() ; c := sc.nextLine() ; length := a->size() ; i := 0 ; while i < length do ( ( if (not(c.subrange(i+1,i + 1) = a.subrange(i+1,i + 1)) & not(c.subrange(i+1,i + 1) = b.subrange(i+1,i + 1))) then ( flag := 0 ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(if flag = 1 then "YES" else "NO" endif) ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.stream.IntStream ; public class A_Three_Strings { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tcc.charAt(i)==a.charAt(i)|| c.charAt(i)==b.charAt(i)); } } ------------------------------------------------------------ OCL File: --------- class A_Three_Strings { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var a : String ; a := sc.getCurrent() ; var b : String ; b := sc.getCurrent() ; var c : String ; c := sc.getCurrent() ; OclFile["System.out"].println(if solve(a, b, c) then "YES" else "NO" endif) ) ; tc := tc + 1 ) ; skip ); static operation solve( a : String, b : String, c : String) : boolean pre: true post: true activity: ( return Integer.subrange(0, c->size()-1)->forAll( _x2 | (lambda i : OclAny in c->at(i+1) = a->at(i+1) or c->at(i+1) = b->at(i+1))->apply(_x2) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner in=new Scanner(System.in); static int n,m ; static long a[],b[]; static void solve(){ int even1=0,odd1=0 ; for(int i=0 ; imin() + Set{even2, odd1}->min() ; OclFile["System.out"].println(odd) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( n := in.getCurrent()->toInteger() ; m := in.getCurrent()->toInteger() ; a := Integer.subrange(1,n)->collect(0) ; b := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( b[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; execute solve() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int N=1000005 ; static void sumOddDigit(int digitSum[]){ for(int i=1 ; icollect(0) ; var factorDigitSum : Sequence(int) ; factorDigitSum := Integer.subrange(1,N)->collect(0) ; execute sumOddDigit(digitSum) ; execute sumFactor(digitSum, factorDigitSum) ; var i : int ; i := 0 ; while i < q do ( OclFile["System.out"].print(factorDigitSum[n[i+1]+1] + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var q : int ; q := 2 ; var n : Sequence(int) ; n := Sequence{10,36} ; execute wrapper(q, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static double squareRoot(double n){ return Math.pow(2,0.5*(Math.log(n)/Math.log(2))); } public static void main(String[] args){ double n=12 ; System.out.println(squareRoot(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation squareRoot( n : double) : double pre: true post: true activity: ( return 2->pow(0.5 * ((n)->log() / (2)->log())) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : double ; n := 12 ; OclFile["System.out"].println(squareRoot(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int a=scan.nextInt(); String op=scan.next(); int b=scan.nextInt(); while(true){ if(op.equals("+")){ System.out.println(a+b); a=scan.nextInt(); op=scan.next(); b=scan.nextInt(); } else if(op.equals("-")){ System.out.println(a-b); a=scan.nextInt(); op=scan.next(); b=scan.nextInt(); } else if(op.equals("*")){ System.out.println(a*b); a=scan.nextInt(); op=scan.next(); b=scan.nextInt(); } else if(op.equals("/")){ System.out.println(a/b); a=scan.nextInt(); op=scan.next(); b=scan.nextInt(); } else if(op.equals("?")){ break ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := scan.getCurrent()->toInteger() ; var op : String ; op := scan.getCurrent() ; var b : int ; b := scan.getCurrent()->toInteger() ; while (true) do ( if (op = "+") then ( OclFile["System.out"].println(a + b) ; a := scan.getCurrent()->toInteger() ; op := scan.getCurrent() ; b := scan.getCurrent()->toInteger() ) else if (op = "-") then ( OclFile["System.out"].println(a - (b)->char2byte()) ; a := scan.getCurrent()->toInteger() ; op := scan.getCurrent() ; b := scan.getCurrent()->toInteger() ) else if (op = "*") then ( OclFile["System.out"].println(a * b) ; a := scan.getCurrent()->toInteger() ; op := scan.getCurrent() ; b := scan.getCurrent()->toInteger() ) else if (op = "/") then ( OclFile["System.out"].println(a / b) ; a := scan.getCurrent()->toInteger() ; op := scan.getCurrent() ; b := scan.getCurrent()->toInteger() ) else if (op = "?") then ( break ) else skip ; ; ; ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int highestPowerof2(int n){ int p=(int)(Math.log(n)/Math.log(2)); return(int)Math.pow(2,p); } public static void main(String[] args){ int n=10 ; System.out.println(highestPowerof2(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation highestPowerof2( n : int) : int pre: true post: true activity: ( var p : int ; p := ((n)->log() / (2)->log())->oclAsType(int) ; return 2->pow(p)->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; OclFile["System.out"].println(highestPowerof2(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countPaths(int m,int n){ int[][] dp=new int[m+1][n+1]; for(int i=1 ; i<=m ; i++){ for(int j=1 ; j<=n ; j++){ if(i==1 || j==1)dp[i][j]=1 ; else dp[i][j]=dp[i-1][j]+dp[i][j-1]; } } return dp[m][n]; } public static void main(String[] args){ int n=5 ; int m=5 ; System.out.println(countPaths(n,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countPaths( m : int, n : int) : int pre: true post: true activity: ( var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,m + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= m do ( ( var j : int ; j := 1 ; while j <= n 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] ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[m+1][n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var m : int ; m := 5 ; OclFile["System.out"].println(countPaths(n, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int arrSize=51 ; static int maxSum=201 ; static int MAX=100 ; static int inf=999999 ; static int dp[][]=new int[arrSize][maxSum]; static int visit[][]=new int[arrSize][maxSum]; static int RetClose(int a,int b,int s){ if(Math.abs(a-s)0)return dp[i][sum+MAX]; visit[i][sum+MAX]=1 ; dp[i][sum+MAX]=RetClose(arr[i]+MinDiff(i+1,sum+arr[i],arr,n),MinDiff(i+1,sum,arr,n),-1*sum); return dp[i][sum+MAX]; } static void FindClose(int arr[],int n){ int ans=inf ; for(int i=1 ; i<=n ; i++)ans=RetClose(arr[i-1]+MinDiff(i,arr[i-1],arr,n),ans,0); System.out.println(ans); } public static void main(String[] args){ int arr[]={ 25,-9,-10,-4,-7,-33 }; int n=arr.length ; FindClose(arr,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute arrSize : int := 51; static attribute maxSum : int := 201; static attribute MAX : int := 100; static attribute inf : int := 999999; static attribute dp : int := Integer.subrange(1,arrSize)->collect(Integer.subrange(1,maxSum)->collect(0)); static attribute visit : int := Integer.subrange(1,arrSize)->collect(Integer.subrange(1,maxSum)->collect(0)); static operation RetClose( a : int, b : int, s : int) : int pre: true post: true activity: ( if (if a - s < 0 then -(a - s) else a - s endif < if b - s < 0 then -(b - s) else b - s endif) then return a else return b ); static operation MinDiff( i : int, sum : int, arr : Sequence(int), n : int) : int pre: true post: true activity: ( if (i = n) then return 0 else skip ; if (visit[i+1][sum + MAX+1] > 0) 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] ); static operation FindClose( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var ans : int ; ans := inf ; var i : int ; i := 1 ; while i <= n do ( ans := RetClose(arr[i - 1+1] + MinDiff(i, arr[i - 1+1], arr, n), ans, 0) ; ; i := i + 1 ) ; OclFile["System.out"].println(ans) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{25,-9,-10,-4,-7,-33} ; var n : int ; n := arr->size() ; execute FindClose(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean hasCrest(int arr[],int n,int L,int R){ int[] present=new int[n]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( ( present[i+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n - 2 do ( ( if ((arr[i+1] <= arr[i + 1+1]) & (arr[i+1] <= arr[i - 1+1])) then ( present[i+1] := 1 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( present[i+1] := present[i+1]+(present[i - 1+1]) ) ; i := i + 1 ) ; if (present[L+1] = present[R - 1+1]) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,1,3,5,12,11,7,9} ; var N : int ; N := arr->size() ; var L : int ; L := 2 ; var R : int ; R := 6 ; if (hasCrest(arr, N, L, R)) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countSquares(int m,int n){ if(nString.valueOf(computeSum(r[i])-computeSum(l[i]-1))).collect(Collectors.joining("\n")); } static int computeSum(int limit){ return((limit % 2==0)? 1 :-1)*(limit+1)/2 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := sc.getCurrent()->toInteger() ; var l : Sequence(int) ; l := Integer.subrange(1,q)->collect(0) ; var r : Sequence(int) ; r := Integer.subrange(1,q)->collect(0) ; var i : int ; i := 0 ; while i < q do ( ( l[i+1] := sc.getCurrent()->toInteger() ; r[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].print(solve(l, r)) ; skip ; ); static operation solve( l : Sequence(int), r : Sequence(int)) : String pre: true post: true activity: ( return Integer.subrange(0, l->size()-1).mapToObj(lambda i : OclAny in ((computeSum(r[i+1]) - computeSum(l[i+1] - 1)) + "")).collect(Collectors.joining("\n")) ); static operation computeSum( limit : int) : int pre: true post: true activity: ( return (if (limit mod 2 = 0) then 1 else -1 endif) * (limit + 1) / 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class B1080 { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var sum : int ; sum := 0 ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var l : int ; l := (st.next())->toInteger() ; var r : int ; r := (st.next())->toInteger() ; var length : int ; length := r - l + 1 ; if (length mod 2 = 0) then ( if (r mod 2 = 0) then ( sum := length / 2 ) else if (r mod 2 = 1) then ( sum := -length / 2 ) else skip ; ) else if (length mod 2 = 1) then ( if (r mod 2 = 0 & l mod 2 = 0) then ( sum := r - (length / 2) ) else if (r mod 2 = 1 & l mod 2 = 1) then ( sum := -r + (length / 2) ) else skip ; ) else skip ; ; OclFile["System.out"].println(sum) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; iset=new HashSet<>(6); String res="YES" ; while(n--!=0){ set.clear(); int s1=in.nextInt(),s2=in.nextInt(); set.add(s1); set.add(s2); set.add(x); set.add(arr[s1]); set.add(arr[s2]); set.add(arr[x]); if(set.size()!=6)res="NO" ; } out.println(res); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static attribute in : FastScanner := FastScanner.newFastScanner(); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation s( t : int) : void pre: true post: true activity: ( t := 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var arr : Sequence(int) ; arr := Sequence{0,6,5,4,3,2,1} ; var x : int ; x := in.nextInt() ; var set : Set(int) ; set := Set{} ; var res : String ; res := "YES" ; while (n /= 0) do ( skip ; ( set := set->intersection(Set{}) ; var s1 : int ; s1 := in.nextInt() ; var s2 : int ; s2 := in.nextInt() ; set := set->including(s1) ; set := set->including(s2) ; set := set->including(x) ; set := set->including(arr[s1+1]) ; set := set->including(arr[s2+1]) ; set := set->including(arr[x+1]) ; if (set->size() /= 6) then res := "NO" ; else skip ; ) ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),m=in.nextInt(); ArrayListnodd=new ArrayList<>(); ArrayListneven=new ArrayList<>(); for(int i=0 ; imodd=new ArrayList<>(); ArrayListmeven=new ArrayList<>(); for(int i=0 ; itoInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var nodd : Sequence(int) ; nodd := Sequence{} ; var neven : Sequence(int) ; neven := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := in.getCurrent()->toInteger() ; if (v mod 2 = 0) then ( neven := neven->including(v) ) else ( nodd := nodd->including(v) ) ) ; i := i + 1 ) ; var modd : Sequence(int) ; modd := Sequence{} ; var meven : Sequence(int) ; meven := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( var v : int ; v := in.getCurrent()->toInteger() ; if (v mod 2 = 0) then ( meven := meven->including(v) ) else ( modd := modd->including(v) ) ) ; i := i + 1 ) ; var ans : int ; ans := Set{neven->size(), modd->size()}->min() + Set{nodd->size(), meven->size()}->min() ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { static int ans(int x){ if(x % 2==0)return x/2 ; else return-x+ans(x-1); } public static void main(String[] args)throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int l=sc.nextInt(); int r=sc.nextInt(); int sum=ans(r)-ans(l-1); System.out.println(sum); } } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation ans( x : int) : int pre: true post: true activity: ( if (x mod 2 = 0) then return x / 2 else return -x + ans(x - 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; var sum : int ; sum := ans(r) - ans(l - 1) ; OclFile["System.out"].println(sum) ) ; ) ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class p1401A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(),k=sc.nextInt(); System.out.println(k>n ? k-n :(n-k)% 2); } } } ------------------------------------------------------------ OCL File: --------- class p1401A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(if k > n then k - n else (n - k) mod 2 endif) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import javax.swing.*; import java.io.IOException ; import java.io.OutputStream ; import java.math.BigInteger ; import java.nio.CharBuffer ; import java.util.*; public class Main { static Scanner scan=new Scanner(System.in); public static void main(String[] args){ int t=1 ; while(t-->0){ System.out.println(solve()); } } public static String solve(){ int n=scan.nextInt(); String answer=(n-1)% 9+1+"" ; return answer ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scan : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( OclFile["System.out"].println(solve()) ) ; ) ); static operation solve() : String pre: true post: true activity: ( var n : int ; n := scan.getCurrent()->toInteger() ; var answer : String ; answer := (n - 1) mod 9 + 1 + "" ; return answer ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static int next ; static void solve(){ while(next>=10){ int sum=0 ; for(char c :(next+"").toCharArray()){ sum+=c-'0' ; } next=sum ; } str.append(next).append("\n"); } public static void main(String[] args)throws java.lang.Exception { BufferedReader bf ; PrintWriter pw ; boolean lenv=false ; if(lenv){ bf=new BufferedReader(new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); } else { bf=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out)); } String s[]=bf.readLine().trim().split("\\s+"); next=Integer.parseInt(s[0]); solve(); pw.println(str); pw.flush(); } } ------------------------------------------------------------ OCL File: --------- class Coder { static attribute str : String := StringLib.newString(); static attribute next : int; static operation solve() : void pre: true post: true activity: ( while (next >= 10) do ( var sum : int ; sum := 0 ; for (c : (next + "")->characters()) do ( ( sum := sum+(c - ('0')->char2byte()) ) ) ; next := sum ) ; str := str + StringLib.newString(next) + StringLib.newString("\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; var pw : OclFile ; var lenv : boolean ; lenv := false ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; var s : Sequence(String) ; s := bf.readLine()->trim()->split("\\s+") ; next := (s[0+1])->toInteger() ; execute solve() ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class root { public static void main(String args[]){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); System.out.println((n-1)% 9+1); } } ------------------------------------------------------------ OCL File: --------- class root { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; OclFile["System.out"].println((n - 1) mod 9 + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ long a=in.nextLong(); if(a==0)System.out.println(0); else if(a % 2==1)System.out.println((a+1)/2); else if(a % 2==0)System.out.println(a+1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (in.hasNext()) do ( var a : long ; a := in.getCurrent()->toLong() ; if (a = 0) then OclFile["System.out"].println(0) ; else if (a mod 2 = 1) then OclFile["System.out"].println((a + 1) / 2) else if (a mod 2 = 0) then OclFile["System.out"].println(a + 1) ; else skip ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import org.w3c.dom.ls.LSInput ; import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.*; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; import java.util.jar.Attributes ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,InputReader in,PrintWriter out){ long n=in.nextLong(); long c=n+1 ; if(n==0){ out.println("0"); } else if(c % 2==0){ out.println(c/2); } else { out.println(c); } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskA ; solver := TaskA.newTaskA() ; solver.solve(1, in, out) ; skip ; ); static class TaskA { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : long ; n := in.nextLong() ; var c : long ; c := n + 1 ; if (n = 0) then ( skip ) else if (c mod 2 = 0) then ( skip ) else ( skip ) ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import org.w3c.dom.ls.LSInput ; import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.*; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; import java.util.jar.Attributes ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,InputReader in,PrintWriter out){ long n=in.nextLong(); long sum=n+1 ; if(n==0){ out.println(0); } else if(sum % 2==0){ out.println(sum/2); } else { out.println(sum); } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskA ; solver := TaskA.newTaskA() ; solver.solve(1, in, out) ; skip ; ); static class TaskA { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : long ; n := in.nextLong() ; var sum : long ; sum := n + 1 ; if (n = 0) then ( skip ) else if (sum mod 2 = 0) then ( skip ) else ( skip ) ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ long a=in.nextLong(); if(a % 2==1)System.out.println((a+1)/2); else if(a % 2==0 && a>0)System.out.println((a+1)); else if(a==0)System.out.println("0"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (in.hasNext()) do ( var a : long ; a := in.getCurrent()->toLong() ; if (a mod 2 = 1) then OclFile["System.out"].println((a + 1) / 2) ; else if (a mod 2 = 0 & a > 0) then OclFile["System.out"].println((a + 1)) else if (a = 0) then OclFile["System.out"].println("0") ; else skip ; ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Problem979A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong()+1 ; System.out.println((n & 1)==0 ? n/2 : n==1 ? 0 : n); } } ------------------------------------------------------------ OCL File: --------- class Problem979A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() + 1 ; OclFile["System.out"].println(if (MathLib.bitwiseAnd(n,1)) = 0 then n / 2 else if n = 1 then 0 else n endif endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),m=in.nextInt(); ArrayListnodd=new ArrayList<>(); ArrayListneven=new ArrayList<>(); for(int i=0 ; imodd=new ArrayList<>(); ArrayListmeven=new ArrayList<>(); for(int i=0 ; itoInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var nodd : Sequence(int) ; nodd := Sequence{} ; var neven : Sequence(int) ; neven := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var v : int ; v := in.getCurrent()->toInteger() ; if (v mod 2 = 0) then ( neven := neven->including(v) ) else ( nodd := nodd->including(v) ) ) ; i := i + 1 ) ; var modd : Sequence(int) ; modd := Sequence{} ; var meven : Sequence(int) ; meven := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( var v : int ; v := in.getCurrent()->toInteger() ; if (v mod 2 = 0) then ( meven := meven->including(v) ) else ( modd := modd->including(v) ) ) ; i := i + 1 ) ; var ans : int ; ans := Set{neven->size(), modd->size()}->min() + Set{nodd->size(), meven->size()}->min() ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countWays(int n,int arr[],int len){ int count[]=new int[n+1]; count[0]=1 ; if(n==0)return 1 ; for(int i=1 ; i<=n ; i++){ int no_ways=0 ; for(int j=0 ; j=0){ no_ways+=count[i-arr[j] ]; } count[i]=no_ways ; } } return count[n]; } public static void main(String args[]){ int arr[]={ 1,3,5 }; int len=arr.length ; int n=5 ; System.out.print(countWays(n,arr,len)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countWays( n : int, arr : Sequence(int), len : int) : int pre: true post: true activity: ( var count : Sequence(int) ; count := Integer.subrange(1,n + 1)->collect(0) ; count[0+1] := 1 ; if (n = 0) then return 1 else skip ; var i : int ; i := 1 ; while i <= n do ( ( var no_ways : int ; no_ways := 0 ; var j : int ; j := 0 ; while j < len do ( ( if (i - arr[j+1] >= 0) then ( no_ways := no_ways+(count[i - arr[j+1]+1]) ) else skip ; count[i+1] := no_ways ) ; j := j + 1 ) ) ; i := i + 1 ) ; return count[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,3,5} ; var len : int ; len := arr->size() ; var n : int ; n := 5 ; OclFile["System.out"].print(countWays(n, arr, len)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int N=4 ; static int maxDecimalValue(int mat[][],int i,int j,int p){ if(i>=N || j>=N){ return 0 ; } int result=Math.max(maxDecimalValue(mat,i,j+1,p+1),maxDecimalValue(mat,i+1,j,p+1)); if(mat[i][j]==1){ return(int)(Math.pow(2,p)+result); } else { return result ; } } public static void main(String[] args){ int mat[][]={ { 1,1,0,1 },{ 0,1,1,0 },{ 1,0,0,1 },{ 1,0,1,1 },}; System.out.println(maxDecimalValue(mat,0,0,0)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute N : int := 4; static operation maxDecimalValue( mat : Sequence(Sequence(int)), i : int, j : int, p : int) : int pre: true post: true activity: ( if (i >= N or j >= N) then ( return 0 ) else skip ; var result : int ; result := 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)->oclAsType(int) ) else ( return result ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var mat : Sequence(Sequence(int)) ; mat := Sequence{Sequence{1,1,0,1},Sequence{0,1,1,0},Sequence{1,0,0,1},Sequence{1,0,1,1},} ; OclFile["System.out"].println(maxDecimalValue(mat, 0, 0, 0)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static double dist(double m,double b1,double b2){ double d=Math.abs(b2-b1)/((m*m)-1); return d ; } public static void main(String[] args){ double m=2,b1=4,b2=3 ; System.out.println(dist(m,b1,b2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation dist( m : double, b1 : double, b2 : double) : double pre: true post: true activity: ( var d : double ; d := if b2 - b1 < 0 then -(b2 - b1) else b2 - b1 endif / ((m * m) - 1) ; return d ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : double ; m := 2 ; var b1 : double ; b1 := 4 ; var b2 : double ; b2 := 3 ; OclFile["System.out"].println(dist(m, b1, b2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { Scanner s=new Scanner(System.in); int n=s.nextInt(); int ps=0 ; int ns=0 ; for(int i=0 ; itoInteger() ; var ps : int ; ps := 0 ; var ns : int ; ns := 0 ; var i : int ; i := 0 ; while i < n do ( ( var no : int ; no := s.getCurrent()->toInteger() ; if (no < 0) then ns := ns - (no) ; else ps := ps + no ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ps + ns) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF946A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[] arr1=new int[n]; int b=0 ; int c=0 ; for(int i=0 ; i0){ b=arr1[i]+b ; } else if(arr1[i]<0){ c=arr1[i]+c ; } } System.out.println(b-c); } } ------------------------------------------------------------ OCL File: --------- class CF946A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var arr1 : Sequence(int) ; arr1 := Integer.subrange(1,n)->collect(0) ; var b : int ; b := 0 ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < n do ( ( arr1[i+1] := scan.getCurrent()->toInteger() ; if (arr1[i+1] > 0) then ( b := arr1[i+1] + b ) else if (arr1[i+1] < 0) then ( c := arr1[i+1] + c ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(b - c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf946A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int ans=0 ; for(int i=0 ; itoInteger() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( ans := ans+(if scan.getCurrent()->toInteger() < 0 then -(scan.getCurrent()->toInteger()) else scan.getCurrent()->toInteger() endif) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class cf946A { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[] num=new int[n]; int seqPos=0 ; int seqNeg=0 ; for(int i=0 ; i=0){ seqPos+=num[i]; } else if(num[i]<0){ seqNeg+=num[i]; } } System.out.println(seqPos-seqNeg); } } ------------------------------------------------------------ OCL File: --------- class cf946A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var num : Sequence(int) ; num := Integer.subrange(1,n)->collect(0) ; var seqPos : int ; seqPos := 0 ; var seqNeg : int ; seqNeg := 0 ; var i : int ; i := 0 ; while i < n do ( ( num[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (num[i+1] >= 0) then ( seqPos := seqPos+(num[i+1]) ) else if (num[i+1] < 0) then ( seqNeg := seqNeg+(num[i+1]) ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(seqPos - seqNeg) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int array[]=new int[105]; int n,sum=0 ; n=scan.nextInt(); for(int i=0 ; icollect(0) ; var n : int ; var sum : int ; sum := 0 ; n := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( array[i+1] := scan.getCurrent()->toInteger() ; if (array[i+1] < 0) then array[i+1] := if array[i+1] < 0 then -(array[i+1]) else array[i+1] endif ; else skip ; sum := sum+(array[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countSubstrs(String s1,String s2){ int ans=0 ; for(int i=0 ; isize() do ( ( var s3 : String ; s3 := "" ; var s4 : Sequence(String) ; s4 := s1->characters() ; var j : int ; j := i ; while j < s1->size() do ( ( s3 := s3+(s4[j+1]) ; if (s2->indexOf(s3)-1 /= -1) then ans := ans + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s1 : String ; s1 := "aab" ; var s2 : String ; s2 := "aaaab" ; OclFile["System.out"].println(countSubstrs(s1, s2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=100005 ; static boolean[] prime=new boolean[MAX]; static void SieveOfEratosthenes(){ for(int i=0 ; icollect(false); static operation SieveOfEratosthenes() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < MAX do ( prime[i+1] := true ; ; i := i + 1 ) ; prime[0+1] := false ; prime[1+1] := false ; var p : int ; p := 2 ; while p * p < MAX do ( ( if (prime[p+1]) then ( var i : int ; i := p * 2 ; while i < MAX do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ); static operation countPrimes( n : int) : int pre: true post: true activity: ( execute SieveOfEratosthenes() ; var cnt : int ; cnt := 0 ; var i : int ; i := 2 ; while i < n do ( ( if (prime[i+1] & prime[i - 2+1]) then cnt := cnt + 1 ; else skip ) ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 11 ; OclFile["System.out"].print(countPrimes(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public final class Template { private static int hashofIds[]=new int[100001]; public static void main(String[] args){ FastScanner sc=new FastScanner(System.in); int n=sc.nextInt(); for(int i=0 ; icollect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastScanner ; sc := FastScanner.newFastScanner(OclFile["System.in"]) ; var n : int ; n := sc.nextInt() ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.nextInt() ; var id : int ; id := sc.nextInt() ; if (hashofIds[id+1] < x) then ( OclFile["System.out"].println("NO") ; return ) else if (hashofIds[id+1] = x) then hashofIds[id+1] := hashofIds[id+1] + 1 ; else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ); } class FastScanner { attribute br : OclFile; attribute st : OclIterator; static operation newFastScanner( stream : OclFile) : FastScanner pre: true post: true activity: ( var self : FastScanner ; self := createFastScanner(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class okabeandfuturegadgetlaboratory { public static void main(String[] args)throws IOException { BufferedReader fin=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(fin.readLine()); int[][] lab=new int[n][n]; for(int i=0 ; itoInteger() ; var lab : Sequence(Sequence(int)) ; lab := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var st : OclIterator ; st := OclIterator.newOclIterator_String(fin.readLine()) ; var j : int ; j := 0 ; while j < n do ( ( lab[i+1][j+1] := (st.next())->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : boolean ; ans := true ; var x : int ; x := 0 ; while x < n do ( ( var y : int ; y := 0 ; while y < n do ( ( if (lab[x+1][y+1] /= 1) then ( var cur : int ; cur := lab[x+1][y+1] ; var isValid : boolean ; isValid := false ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (lab[x+1][i+1] + lab[j+1][y+1] = cur) then ( isValid := true ; break ) else skip ) ; j := j + 1 ) ; if (isValid) then ( break ) else skip ) ; i := i + 1 ) ; if (not(isValid)) then ( ans := false ; break ) else skip ) else skip ) ; y := y + 1 ) ; if (not(ans)) then ( break ) else skip ) ; x := x + 1 ) ; OclFile["System.out"].println(if ans then "Yes" else "No" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.geom.Line2D ; import java.awt.geom.Point2D ; import java.util.*; public class Main { Scanner sc=new Scanner(System.in); private void doit(){ while(true){ int n=sc.nextInt(); if(n==0)break ; int[] data=new int[12]; for(int i=0 ; i<12 ; i++){ data[i]=sc.nextInt()-sc.nextInt(); } int sum=0 ; boolean flg=false ; int ans=-1 ; for(int i=0 ; i<12 ; i++){ sum+=data[i]; if(sum>=n){ ans=i+1 ; flg=true ; break ; } } if(flg){ System.out.println(ans); } else { System.out.println("NA"); } } } private void debug(Object...o){ System.out.println("debug="+Arrays.deepToString(o)); } public static void main(String[] args){ new Main().doit(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation doit() : void pre: true post: true activity: ( while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var data : Sequence(int) ; data := Integer.subrange(1,12)->collect(0) ; var i : int ; i := 0 ; while i < 12 do ( ( data[i+1] := sc.getCurrent()->toInteger() - sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var flg : boolean ; flg := false ; var ans : int ; ans := -1 ; var i : int ; i := 0 ; while i < 12 do ( ( sum := sum+(data[i+1]) ; if (sum >= n) then ( ans := i + 1 ; flg := true ; break ) else skip ) ; i := i + 1 ) ; if (flg) then ( OclFile["System.out"].println(ans) ) else ( OclFile["System.out"].println("NA") ) ; ) ); operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println("debug=" + (o + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().doit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class HelloWorld { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testcases=1 ; for(int t=0 ; ttoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,m)->collect(0) ; var be : int ; be := 0 ; var bo : int ; bo := 0 ; var ae : int ; ae := 0 ; var ao : int ; ao := 0 ; var i : int ; i := 1 ; while i < n + 1 do ( ( a[i - 1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < m + 1 do ( ( b[i - 1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] mod 2 = 0) then ( ae := ae + 1 ) else ( ao := ao + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (b[i+1] mod 2 = 0) then ( be := be + 1 ) else ( bo := bo + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{ae, bo}->min() + Set{ao, be}->min()) ; ) ; t := t + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class CF417B { public static void main(String[] args){ int n=fs.nextInt(); int[] participantToSubmissionId=new int[(int)(10e5+1)]; for(int i=0 ; iparticipantToSubmissionId[participantId]){ System.out.println("NO"); return ; } } System.out.println("YES"); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next(){ while(! st.hasMoreTokens())try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a=new int[n]; for(int i=0 ; ioclAsType(int))->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := fs.nextInt() ; var participantId : int ; participantId := fs.nextInt() ; if (participantToSubmissionId[participantId+1] = x) then participantToSubmissionId[participantId+1] := participantToSubmissionId[participantId+1] + 1 ; else if (participantToSubmissionId[participantId+1] = x + 1) then continue else if (x > participantToSubmissionId[participantId+1]) then ( OclFile["System.out"].println("NO") ; return ) else skip ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static attribute fs : FastScanner := FastScanner.newFastScanner(); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Program { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),m[]=new int[100001]; for(int i=0 ; itoInteger() ; var m : Sequence(void) ; m := Integer.subrange(1,100001)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; if (m[k+1] < x) then ( OclFile["System.out"].println("NO") ; return ) else if (m[k+1] = x) then m[k+1] := m[k+1] + 1 ; else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B417 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int[] stat=new int[100001]; boolean ok=true ; for(int n=0 ; ntoInteger() ; var stat : Sequence(int) ; stat := Integer.subrange(1,100001)->collect(0) ; var ok : boolean ; ok := true ; var n : int ; n := 0 ; while n < N do ( ( var x : int ; x := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var seen : int ; seen := stat[k+1] ; if (seen < x) then ( ok := false ) else if (seen = x) then ( stat[k+1] := stat[k+1] + 1 ) else skip ; ) ; n := n + 1 ) ; OclFile["System.out"].println(if ok then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long powermod(long x,long y,long p){ long res=1 ; x=x % p ; while(y>0){ if((y & 1L)>0)res=(res*x)% p ; y=y>>1L ; x=(x*x)% p ; } return res ; } static long modInverse(long a,long m){ long m0=m,t,q ; long 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+=m0 ; return x1 ; } static long evaluteExpression(long n){ long firstsum=0,mod=10 ; for(long i=2,j=0 ; (1L< 0) do ( if ((y & 1L) > 0) then res := (res * x) mod p ; else skip ; y := (y/(2->pow(1L)))->oclAsType(long) ; x := (x * x) mod p ) ; return res ); static operation modInverse( a : long, m : long) : long pre: true post: true activity: ( var m0 : long ; m0 := m ; var t : long ; var q : long ; var x0 : long ; x0 := 0 ; var x1 : long ; x1 := 1 ; if (m = 1) then return 0 else skip ; while (a > 1) do ( q := a / m ; t := 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 ); static operation evaluteExpression( n : long) : long pre: true post: true activity: ( var firstsum : long ; firstsum := 0 ; var mod : long ; mod := 10 ; var i : long ; i := 2 ; var j : long ; j := 0 ; while ((1L*(2->pow(j)))->oclAsType(long)) <= n do ( firstsum := (firstsum + i) mod mod ; ; i := i*(i) ; j := j + 1 ) ; var secondsum : long ; secondsum := (powermod(4L, n + 1, mod) - 1) * modInverse(3L, mod) ; return (firstsum * secondsum) mod mod ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := 3 ; OclFile["System.out"].println(evaluteExpression(n)) ; n := 10 ; OclFile["System.out"].println(evaluteExpression(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static HashMaphm=new HashMap(); static void countFreq(int a[],int n){ for(int i=0 ; ikeys()->includes(a[i+1])) then hm := hm->union(Map{a[i+1] |-> hm->at(a[i+1]) + 1}) else hm := hm->union(Map{a[i+1] |-> 1}) ; ; ; i := i + 1 ) ); static operation query( x : int) : int pre: true post: true activity: ( if (hm->keys()->includes(x)) then return hm->at(x) else skip ; return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,3,2,4,2,1} ; var n : int ; n := a->size() ; execute countFreq(a, n) ; OclFile["System.out"].println(query(2)) ; OclFile["System.out"].println(query(3)) ; OclFile["System.out"].println(query(5)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxN=10 ; static int[] fact=new int[maxN]; static int ncr(int n,int r){ return(fact[n]/fact[r])/fact[n-r]; } static int findSum(int[] arr,int n){ fact[0]=1 ; for(int i=1 ; icollect(0); static operation ncr( n : int, r : int) : int pre: true post: true activity: ( return (fact[n+1] / fact[r+1]) / fact[n - r+1] ); static operation findSum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( fact[0+1] := 1 ; var i : int ; i := 1 ; while i < n do ( fact[i+1] := i * fact[i - 1+1] ; ; i := i + 1 ) ; var mul : int ; mul := 0 ; var i : int ; i := 0 ; while i <= n - 1 do ( mul := mul+(2->pow(i)->oclAsType(int) * ncr(n - 1, i)) ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ans := ans+(mul * arr[i+1]) ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,1} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int sumDigits(int n){ int sum=0 ; while(n>0){ int digit=n % 10 ; sum+=digit ; n/=10 ; } return sum ; } static boolean isDivBySix(String str,int n){ int sum=0 ; for(int i=0 ; i 0) do ( var digit : int ; digit := n mod 10 ; sum := sum+(digit) ; n := n/(10) ) ; return sum ); static operation isDivBySix( str : String, n : int) : boolean pre: true post: true activity: ( var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+((str->at(i+1) - ('a')->char2byte() + 1)->oclAsType(int)) ) ; i := i + 1 ) ; if (sum mod 3 /= 0) then return false else skip ; var lastDigit : int ; lastDigit := ((str->at(n - 1+1) - ('a')->char2byte() + 1)->oclAsType(int)) mod 10 ; if (lastDigit mod 2 /= 0) then return false else skip ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "ab" ; var n : int ; n := str->size() ; if (isDivBySix(str, n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long product(int[][] mat,int n){ long d1=0,d2=0 ; for(int i=0 ; isize() ; OclFile["System.out"].print(product(mat, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class gfg { int find(String s){ int max=0,i,j=0,countk=0,countr=0 ; int table[][]=new int[s.length()][2]; for(i=0 ; i=0 ; i--){ if(s.charAt(i)=='K'){ countk++; table[j--][1]=countk ; } if(Math.min(table[j+1][0],table[j+1][1])>max)max=Math.min(table[j+1][0],table[j+1][1]); } return max ; } public static void main(String srgs[]){ String s="RKRRRKKRRKKKKRR" ; gfg ob=new gfg(); int n=ob.find(s); System.out.println(n); } } ------------------------------------------------------------ OCL File: --------- class gfg { operation find( s : String) : int pre: true post: true activity: ( var max : int ; max := 0 ; var i : int ; var j : int ; j := 0 ; var countk : int ; countk := 0 ; var countr : int ; countr := 0 ; var table : Sequence(Sequence(int)) ; table := Integer.subrange(1,s->size())->collect(Integer.subrange(1,2)->collect(0)) ; i := 0 ; while i < s->size() do ( ( if (s->at(i+1) = 'R') then countr := countr + 1 ; else table[j+1][0+1] := countr ; j := j + 1 ; ) ; i := i + 1 ) ; j := j - 1 ; i := s->size() - 1 ; while i >= 0 do ( ( if (s->at(i+1) = 'K') then ( countk := countk + 1 ; table[j+1][1+1] := countk ; j := j - 1 ) else skip ; if (Set{table[j + 1+1][0+1], table[j + 1+1][1+1]}->min() > max) then max := Set{table[j + 1+1][0+1], table[j + 1+1][1+1]}->min() ; else skip ) ; i := i - 1 ) ; return max ); static operation main( srgs : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "RKRRRKKRRKKKKRR" ; var ob : gfg ; ob := gfg.newgfg() ; var n : int ; n := ob.find(s) ; OclFile["System.out"].println(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.System.*; import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ while(true){ int n=sc.nextInt(); if(n==0)break ; boolean F=false ; int saving=0 ; int[] a=new int[12],b=new int[12]; for(int i=0 ; i<12 ; i++){ a[i]=sc.nextInt(); b[i]=sc.nextInt(); } for(int i=0 ; i<12 ; i++){ saving+=a[i]-b[i]; if(saving>=n){ out.println(i+1); F=true ; break ; } } if(! F)out.println("NA"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var F : boolean ; F := false ; var saving : int ; saving := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,12)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,12)->collect(0) ; var i : int ; i := 0 ; while i < 12 do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 12 do ( ( saving := saving+(a[i+1] - b[i+1]) ; if (saving >= n) then ( out.println(i + 1) ; F := true ; break ) else skip ) ; i := i + 1 ) ; if (not(F)) then out.println("NA") ; else skip ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; public class GFG { static int cost(int[] a,int n){ int min=a[0]; for(int i=1 ; isize() do ( ( if (a[i+1] < min) then min := a[i+1] ; else skip ) ; i := i + 1 ) ; return (n - 1) * min ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{4,3,2} ; var n : int ; n := a->size() ; OclFile["System.out"].println(cost(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[][] red=new int[n][2]; int[][] blue=new int[n][2]; for(int i=0 ; iInteger.compare(a[0],b[0])); Arrays.sort(blue,(a,b)->Integer.compare(a[0],b[0])); NavigableSetset=new TreeSet<>((a,b)->Integer.compare(a[1],b[1])); int ri=0 ; int answer=0 ; for(int bi=0 ; bitoInteger() ; var red : Sequence(Sequence(int)) ; red := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var blue : Sequence(Sequence(int)) ; blue := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( red[i+1][0+1] := sc.getCurrent()->toInteger() ; red[i+1][1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( blue[i+1][0+1] := sc.getCurrent()->toInteger() ; blue[i+1][1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; red := OclComparator.sortWith(red, lambda (a , b) : OclAny in compare(a[0+1], b[0+1])) ; blue := OclComparator.sortWith(blue, lambda (a , b) : OclAny in compare(a[0+1], b[0+1])) ; var set : NavigableSet ; set := Set{}->union(lambda (a , b) : OclAny in compare(a[1+1], b[1+1])) ; var ri : int ; ri := 0 ; var answer : int ; answer := 0 ; var bi : int ; bi := 0 ; while bi < n do ( ( while (ri < n & red[ri+1][0+1] < blue[bi+1][0+1]) do ( set->excludes(red[ri+1]) ) ; if (set->isEmpty()) then continue else skip ; var x : Sequence(int) ; x := set.lower(blue[bi+1]) ; if (x = null) then continue else skip ; set := set->excludingFirst(x) ; answer := answer + 1 ; ) ; bi := bi + 1 ) ; OclFile["System.out"].println(answer) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int N=4 ; static int areSame(int A[][],int B[][]){ int i,j ; for(i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void ReplaceElements(int arr[],int n){ int X=0 ; for(int i=0 ; isize() ; execute ReplaceElements(arr, n) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(arr[i+1] + " ") ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static class pair { int first,second ; public pair(int first,int second){ this.first=first ; this.second=second ; } } static pair getMaxandMinProduct(int arr[],int n){ int curMaxProduct=arr[0]; int curMinProduct=arr[0]; int prevMaxProduct=arr[0]; int prevMinProduct=arr[0]; int maxProduct=arr[0]; int minProduct=arr[0]; for(int i=1 ; iat("first") := first ; self->at("second") := second ); } static operation getMaxandMinProduct( arr : Sequence(int), n : int) : pair pre: true post: true activity: ( var curMaxProduct : int ; curMaxProduct := arr[0+1] ; var curMinProduct : int ; curMinProduct := arr[0+1] ; var prevMaxProduct : int ; prevMaxProduct := arr[0+1] ; var prevMinProduct : int ; prevMinProduct := arr[0+1] ; var maxProduct : int ; maxProduct := arr[0+1] ; var minProduct : int ; minProduct := arr[0+1] ; var i : int ; i := 1 ; while i < n 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 ; ) ; i := i + 1 ) ; return pair.newpair(minProduct, maxProduct) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-4,-2,3,7,5,0,1} ; var n : int ; n := arr->size() ; var product : pair ; product := getMaxandMinProduct(arr, n) ; OclFile["System.out"].printf("Minimum product is %d and " + "Maximum product is %d", product->at("first"), product->at("second")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.*; import java.util.*; class GFG { public static boolean isPrime(int n){ if(n<=1)return false ; if(n<=3)return true ; if(n % 2==0 || n % 3==0)return false ; for(int i=5 ; i*i<=n ; i=i+6)if(n % i==0 || n %(i+2)==0)return false ; return true ; } public static int primorial(int n){ int p=2 ; n--; for(int i=3 ; n!=0 ; i++){ if(isPrime(i)==true){ p=p*i ; n--; } i++; } return p ; } public static int findNextPrime(int n){ int nextPrime=n+2 ; while(true){ if(isPrime(nextPrime)==true)break ; nextPrime++; } return nextPrime ; } public static int fortunateNumber(int n){ int p=primorial(n); return findNextPrime(p)-p ; } public static void main(String[] args){ int n=5 ; System.out.println(fortunateNumber(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPrime( n : int) : boolean 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 ; i := 5 ; while i * i <= n do ( if (n mod i = 0 or n mod (i + 2) = 0) then return false else skip ; ; i := i + 6 ) ; return true ); static operation primorial( n : int) : int pre: true post: true activity: ( var p : int ; p := 2 ; n := n - 1 ; var i : int ; i := 3 ; while n /= 0 do ( ( if (isPrime(i) = true) then ( p := p * i ; n := n - 1 ) else skip ; i := i + 1 ) ; i := i + 1 ) ; return p ); static operation findNextPrime( n : int) : int pre: true post: true activity: ( var nextPrime : int ; nextPrime := n + 2 ; while (true) do ( if (isPrime(nextPrime) = true) then break else skip ; nextPrime := nextPrime + 1 ) ; return nextPrime ); static operation fortunateNumber( n : int) : int pre: true post: true activity: ( var p : int ; p := primorial(n) ; return findNextPrime(p) - p ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; OclFile["System.out"].println(fortunateNumber(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Code { static long idx ; static long cnt ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long l=sc.nextLong(); long r=sc.nextLong(); System.out.println(util(n,r)-util(n,l-1)); } public static long util(long n,long x){ if(x==0 || n==0){ return 0 ; } if(n==1){ return 1 ; } if(x<=(long)Math.pow(2,len(n/2))-1){ return util(n/2,x); } if(x==(long)Math.pow(2,len(n/2))-1+1){ return(n/2)+(n % 2); } return(n/2)+(n % 2)+util(n/2,x-((long)Math.pow(2,len(n/2))-1)-1); } public static int len(long n){ int l=0 ; while(n>0){ n/=2 ; l++; } return l ; } } ------------------------------------------------------------ OCL File: --------- class Code { static attribute idx : long; static attribute cnt : long; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var l : long ; l := sc.getCurrent()->toLong() ; var r : long ; r := sc.getCurrent()->toLong() ; OclFile["System.out"].println(util(n, r) - util(n, l - 1)) ; ); static operation util( n : long, x : long) : long pre: true post: true activity: ( if (x = 0 or n = 0) then ( return 0 ) else skip ; if (n = 1) then ( return 1 ) else skip ; if (x <= 2->pow(len(n / 2))->oclAsType(long) - 1) then ( return util(n / 2, x) ) else skip ; if (x = 2->pow(len(n / 2))->oclAsType(long) - 1 + 1) then ( return (n / 2) + (n mod 2) ) else skip ; return (n / 2) + (n mod 2) + util(n / 2, x - (2->pow(len(n / 2))->oclAsType(long) - 1) - 1) ); static operation len( n : long) : int pre: true post: true activity: ( var l : int ; l := 0 ; while (n > 0) do ( n := n/(2) ; l := l + 1 ) ; return l ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.io.BufferedOutputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Sample { private static final Scanner sc=new Scanner(new BufferedInputStream(System.in)); private static final PrintWriter pw=new PrintWriter(new BufferedOutputStream(System.out),true); private static StringBuffer ans=new StringBuffer(); public static void main(String[] args)throws Exception { long n=sc.nextLong(),cnt=0L,l=sc.nextLong(),r=sc.nextLong(); char[] a=Long.toBinaryString(n).toCharArray(); for(long i=l ; i<=r ; i++){ for(int j=0 ; j<32 ; j++){ if((i &(1<toLong() ; var cnt : long ; cnt := 0L ; var l : long ; l := sc.getCurrent()->toLong() ; var r : long ; r := sc.getCurrent()->toLong() ; var a : Sequence(String) ; a := (MathLib.decimal2binary(n) + "")->characters() ; var i : long ; i := l ; while i <= r do ( ( var j : int ; j := 0 ; while j < 32 do ( ( if ((MathLib.bitwiseAnd(i,((1*(2->pow(j)))->oclAsType(long)))) /= 0) then ( if (a[j+1] = '1') then cnt := cnt + 1 ; else skip ; break ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; ans := ans + StringLib.newString(cnt) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Ideone { private static long getTotalLength(long n){ if(n==1)return 1 ; return getTotalLength(n/2)*2+1 ; } private static long getTotalOnes(long n){ if(n==1)return 1 ; return getTotalOnes(n/2)*2+n % 2 ; } private static long getOnes(long n,long l,long r){ if(r=l)ans+=getOnes(n/2,l,Math.min(left,r)); ans+=(r>=left+1 && l<=left+1 ? n % 2 : 0); if(r-left-1>=Math.max(1,l-left-1))ans+=getOnes(n/2,Math.max(1,l-left-1),r-left-1); return ans ; } public static void main(String[] args)throws java.lang.Exception { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); String arr[]=reader.readLine().split(" "); long n=Long.parseLong(arr[0]); long l=Long.parseLong(arr[1]); long r=Long.parseLong(arr[2]); if(n<2){ System.out.println(n); } else { System.out.println(getOnes(n,l,r)); } } } ------------------------------------------------------------ OCL File: --------- class Ideone { static operation getTotalLength( n : long) : long pre: true post: true activity: ( if (n = 1) then return 1 else skip ; return getTotalLength(n / 2) * 2 + 1 ); static operation getTotalOnes( n : long) : long pre: true post: true activity: ( if (n = 1) then return 1 else skip ; return getTotalOnes(n / 2) * 2 + n mod 2 ); static operation getOnes( n : long, l : long, r : long) : long pre: true post: true activity: ( if (r < l) then return 0 else skip ; if (n = 1) then return 1 else skip ; var left : long ; left := getTotalLength(n / 2) ; if (l = 1 & (r = left or r = left + 1)) then ( var ans : long ; ans := getTotalOnes(n / 2) + (if r = left + 1 then n mod 2 else 0 endif) ; return ans ) else skip ; var ans : long ; ans := 0 ; if (Set{left, r}->min() >= l) then ans := ans+(getOnes(n / 2, l, Set{left, r}->min())) ; else skip ; ans := ans+((if r >= left + 1 & l <= left + 1 then n mod 2 else 0 endif)) ; if (r - left - 1 >= Set{1, l - left - 1}->max()) then ans := ans+(getOnes(n / 2, Set{1, l - left - 1}->max(), r - left - 1)) ; else skip ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var arr : Sequence(String) ; arr := reader.readLine()->split(" ") ; var n : long ; n := (arr[0+1])->toLong() ; var l : long ; l := (arr[1+1])->toLong() ; var r : long ; r := (arr[2+1])->toLong() ; if (n < 2) then ( OclFile["System.out"].println(n) ) else ( OclFile["System.out"].println(getOnes(n, l, r)) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForOne { public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long l=sc.nextLong(); long r=sc.nextLong(); System.out.println(util(n,r)-util(n,l-1)); } public static long util(long n,long x){ if(x==0 || n==0){ return 0 ; } if(n==1){ return 1 ; } if(x<=len(n/2)){ return util(n/2,x); } if(x==len(n/2)+1){ return(n/2)+(n % 2); } return(n/2)+(n % 2)+util(n/2,x-len(n/2)-1); } public static long len(long n){ long bits=numberOfBits(n); return(long)Math.pow(2,bits)-(long)1 ; } public static long numberOfBits(long n){ long l=0 ; while(n>0){ n/=2 ; l++; } return l ; } } ------------------------------------------------------------ OCL File: --------- class CodeForOne { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var l : long ; l := sc.getCurrent()->toLong() ; var r : long ; r := sc.getCurrent()->toLong() ; OclFile["System.out"].println(util(n, r) - util(n, l - 1)) ; ); static operation util( n : long, x : long) : long pre: true post: true activity: ( if (x = 0 or n = 0) then ( return 0 ) else skip ; if (n = 1) then ( return 1 ) else skip ; if (x <= len(n / 2)) then ( return util(n / 2, x) ) else skip ; if (x = len(n / 2) + 1) then ( return (n / 2) + (n mod 2) ) else skip ; return (n / 2) + (n mod 2) + util(n / 2, x - len(n / 2) - 1) ); static operation len( n : long) : long pre: true post: true activity: ( var bits : long ; bits := numberOfBits(n) ; return 2->pow(bits)->oclAsType(long) - 1->oclAsType(long) ); static operation numberOfBits( n : long) : long pre: true post: true activity: ( var l : long ; l := 0 ; while (n > 0) do ( n := n/(2) ; l := l + 1 ) ; return l ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class Main { public static void main(String[] args){ try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder stringBuilder=new StringBuilder(); final int term=12 ; String line ; while((line=br.readLine())!=null){ if(line.equals("0")){ break ; } int goal=Integer.parseInt(line); int totalAmount=0 ; String progressMonth="" ; for(int i=0 ; itotalAmount){ totalAmount=calculate(dataSet,totalAmount); progressMonth=check(i,goal,totalAmount); } } stringBuilder.append(progressMonth+"\n"); } System.out.print(stringBuilder); } catch(Exception e){ e.printStackTrace(); } } private static int calculate(String[] dataSet,int totalAmount){ int income=Integer.parseInt(dataSet[0]); int outcome=Integer.parseInt(dataSet[1]); totalAmount+=(income-outcome); return totalAmount ; } private static String check(int progressMonth,int goal,int totalAmount){ if(goal<=totalAmount){ return String.valueOf(progressMonth+1); } return "NA" ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var stringBuilder : String ; stringBuilder := StringLib.newString() ; var term : int ; term := 12 ; var line : String ; line := br.readLine() ; while ((line) /= null) do ( skip ; ( if (line = "0") then ( break ) else skip ; var goal : int ; goal := (line)->toInteger() ; var totalAmount : int ; totalAmount := 0 ; var progressMonth : String ; progressMonth := "" ; var i : int ; i := 0 ; while i < term do ( ( var dataSet : Sequence(String) ; dataSet := br.readLine()->split(" ") ; if (goal > totalAmount) then ( totalAmount := calculate(dataSet, totalAmount) ; progressMonth := check(i, goal, totalAmount) ) else skip ) ; i := i + 1 ) ; stringBuilder := stringBuilder + StringLib.newString(progressMonth + "\n") ; ) ; line := br.readLine() ; ) ; OclFile["System.out"].print(stringBuilder) ; ) catch (e : ProgramException) do ( e.printStackTrace() ) ); static operation calculate( dataSet : Sequence(String), totalAmount : int) : int pre: true post: true activity: ( var income : int ; income := (dataSet[0+1])->toInteger() ; var outcome : int ; outcome := (dataSet[1+1])->toInteger() ; totalAmount := totalAmount+((income - outcome)) ; return totalAmount ); static operation check( progressMonth : int, goal : int, totalAmount : int) : String pre: true post: true activity: ( if (goal <= totalAmount) then ( return ((progressMonth + 1) + "") ) else skip ; return "NA" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void findMaxFrequency(String s){ int arr[]=new int[26]; for(int i=0 ; ihash=new HashMap(); for(int i=0 ; i<26 ; i++)if(arr[i]!=0){ if(hash.containsKey(arr[i])){ hash.put(arr[i],hash.get(arr[i])+1); } else { hash.put(arr[i],1); } } int max_count=0,res=-1 ; for(Map.Entryi : hash.entrySet()){ if(max_countcollect(0) ; var i : int ; i := 0 ; while i < s->size() do ( arr[s->at(i+1) - ('a')->char2byte()+1] := arr[s->at(i+1) - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var hash : Map(int,int) ; hash := Map{} ; var i : int ; i := 0 ; while i < 26 do ( if (arr[i+1] /= 0) then ( if (hash->keys()->includes(arr[i+1])) then ( hash := hash->union(Map{arr[i+1] |-> hash->at(arr[i+1]) + 1}) ) else ( hash := hash->union(Map{arr[i+1] |-> 1}) ) ) else skip ; ; i := i + 1 ) ; var max_count : int ; max_count := 0 ; var res : int ; res := -1 ; for (i : hash->asSet()) do ( ( if (max_count < i.getValue()) then ( res := i.getKey() ; max_count := i.getValue() ) else skip ) ) ; OclFile["System.out"].println("Frequency " + res + " is repeated " + max_count + " times") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "geeksgeeks" ; execute findMaxFrequency(s) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countSub(int arr[],int n){ int count[]=new int[10]; for(int i=0 ; i=0 ; j--)count[arr[i] ]+=count[j]; count[arr[i] ]++; } int result=0 ; for(int i=0 ; i<10 ; i++)result+=count[i]; return result ; } public static void main(String[] args){ int arr[]={ 3,2,4,5,4 }; int n=arr.length ; System.out.println(countSub(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countSub( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var count : Sequence(int) ; count := Integer.subrange(1,10)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := arr[i+1] - 1 ; while j >= 0 do ( count[arr[i+1]+1] := count[arr[i+1]+1]+(count[j+1]) ; ; j := j - 1 ) ; count[arr[i+1]+1] := count[arr[i+1]+1] + 1 ) ; i := i + 1 ) ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < 10 do ( result := result+(count[i+1]) ; ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,2,4,5,4} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(countSub(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Listred=new ArrayList<>(); for(int i=0 ; iblue=new ArrayList<>(); for(int i=0 ; ia.a-b.a); blue.sort((a,b)->a.a-b.a); for(Point bp : blue){ Listpossible=new ArrayList<>(); for(Point rp : red){ if(bp.arp.b){ possible.add(rp); } } possible.sort((a,b)->b.b-a.b); for(Point point : possible){ if(point.paired){ continue ; } else { point.paired=true ; break ; } } } long count=red.stream().filter(p->p.paired).count(); System.out.println(count); sc.close(); } } class Point { @ Override public String toString(){ return "Point[a="+a+",b="+b+",paired="+paired+"] " ; } int a ; int b ; Boolean paired=false ; public Point(int a,int b){ this.a=a ; this.b=b ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var red : Sequence(Point) ; red := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var p : Point ; p := Point.newPoint(a, b) ; red := red->including(p) ) ; i := i + 1 ) ; var blue : Sequence(Point) ; blue := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var p : Point ; p := Point.newPoint(a, b) ; blue := blue->including(p) ) ; i := i + 1 ) ; red := red.sort(lambda (a , b) : OclAny in a.a - b.a) ; blue := blue.sort(lambda (a , b) : OclAny in a.a - b.a) ; for (bp : blue) do ( ( var possible : Sequence(Point) ; possible := Sequence{} ; for (rp : red) do ( ( if (bp.a < rp.a) then break else skip ; if (bp.b > rp.b) then ( possible := possible->including(rp) ) else skip ) ) ; possible := possible.sort(lambda (a , b) : OclAny in b.b - a.b) ; for (point : possible) do ( ( if (point.paired) then ( continue ) else ( point.paired := true ; break ) ) ) ) ) ; var count : long ; count := red->select( _x1 | (lambda p : OclAny in p.paired)->apply(_x1) )->size() ; OclFile["System.out"].println(count) ; skip ; ); } class Point { operation toString() : String pre: true post: true activity: ( return "Point[a=" + a + ",b=" + b + ",paired=" + paired + "] " ); attribute a : int; attribute b : int; attribute paired : Boolean := false; static operation newPoint( a : int, b : int) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( self.a := a ; self.b := b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static ArrayListfindingValues(int m,int n,int mth,int nth){ int d=(Math.abs(mth-nth))/Math.abs((m-1)-(n-1)); int a=mth-((m-1)*d); ArrayListres=new ArrayList(); res.add(a); res.add(d); return res ; } static int findSum(int m,int n,int mth,int nth,int p){ ArrayListad=findingValues(m,n,mth,nth); int a=ad.get(0); int d=ad.get(1); int sum=(p*(2*a+(p-1)*d))/2 ; return sum ; } public static void main(String[] args){ int m=6,n=10,mTerm=12,nTerm=20,p=5 ; System.out.println(findSum(m,n,mTerm,nTerm,p)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findingValues( m : int, n : int, mth : int, nth : int) : Sequence(int) pre: true post: true activity: ( var d : int ; d := (if mth - nth < 0 then -(mth - nth) else mth - nth endif) / if (m - 1) - (n - 1) < 0 then -((m - 1) - (n - 1)) else (m - 1) - (n - 1) endif ; var a : int ; a := mth - ((m - 1) * d) ; var res : Sequence(int) ; res := Sequence{} ; res := res->including(a) ; res := res->including(d) ; return res ); static operation findSum( m : int, n : int, mth : int, nth : int, p : int) : int pre: true post: true activity: ( var ad : Sequence(int) ; ad := findingValues(m, n, mth, nth) ; var a : int ; a := ad->at(0+1) ; var d : int ; d := ad->at(1+1) ; var sum : int ; sum := (p * (2 * a + (p - 1) * d)) / 2 ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : int ; m := 6 ; var n : int ; n := 10 ; var mTerm : int ; mTerm := 12 ; var nTerm : int ; nTerm := 20 ; var p : int ; p := 5 ; OclFile["System.out"].println(findSum(m, n, mTerm, nTerm, p)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void count_unique(HashSets,int n){ if(s.contains(n))return ; s.add(n); n+=1 ; while(n % 10==0){ n=n/10 ; } count_unique(s,n); } public static void main(String[] args){ int n=10 ; HashSets=new HashSet<>(); count_unique(s,n); System.out.println(s.size()); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count_unique( s : Set(int), n : int) : void pre: true post: true activity: ( if (s->includes(n)) then return else skip ; s->excludes(n) ; n := n+(1) ; while (n mod 10 = 0) do ( n := n / 10 ) ; execute count_unique(s, n) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; var s : Set(int) ; s := Set{} ; execute count_unique(s, n) ; OclFile["System.out"].println(s->size()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int mod=1000000007 ; static int noOfBinaryStrings(int N,int k){ int dp[]=new int[100002]; for(int i=1 ; i<=k-1 ; i++){ dp[i]=1 ; } dp[k]=2 ; for(int i=k+1 ; i<=N ; i++){ dp[i]=(dp[i-1]+dp[i-k])% mod ; } return dp[N]; } public static void main(String[] args){ int N=4 ; int K=2 ; System.out.println(noOfBinaryStrings(N,K)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute mod : int := 1000000007; static operation noOfBinaryStrings( N : int, k : int) : int pre: true post: true activity: ( var dp : Sequence(int) ; dp := Integer.subrange(1,100002)->collect(0) ; var i : int ; i := 1 ; while i <= k - 1 do ( ( dp[i+1] := 1 ) ; i := i + 1 ) ; dp[k+1] := 2 ; var i : int ; i := k + 1 ; while i <= N do ( ( dp[i+1] := (dp[i - 1+1] + dp[i - k+1]) mod mod ) ; i := i + 1 ) ; return dp[N+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 4 ; var K : int ; K := 2 ; OclFile["System.out"].println(noOfBinaryStrings(N, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B918 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),m=in.nextInt(); MapH=new HashMap<>(); while(n-->0){ String s=in.next(),ip=in.next(); H.put(ip,s); } while(m-->0){ String c=in.next(),ip=in.next().replace(";",""); System.out.println(c+" "+ip+"; #"+H.get(ip)); } } } ------------------------------------------------------------ OCL File: --------- class B918 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var H : Map(String,String) ; H := Map{} ; while (n > 0) do ( n := n - 1 ; skip ; ( var s : String ; s := in.getCurrent() ; var ip : String ; ip := in.getCurrent() ; H := H->union(Map{ip |-> s}) ) ; ) ; while (m > 0) do ( m := m - 1 ; skip ; ( var c : String ; c := in.getCurrent() ; var ip : String ; ip := in.getCurrent().replace(";", "") ; OclFile["System.out"].println(c + " " + ip + "; #" + H->at(ip)) ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class IpAddress { public static void main(String[] args){ Scanner s=new Scanner(System.in); StringTokenizer st=new StringTokenizer(s.nextLine()); int N=Integer.parseInt(st.nextToken()); int M=Integer.parseInt(st.nextToken()); HashMapmap=new HashMap<>(); for(int i=0 ; itoInteger() ; var M : int ; M := (st.next())->toInteger() ; var map : Map(String,String) ; map := Map{} ; var i : int ; i := 0 ; while i < N do ( ( st := OclIterator.newOclIterator_String(s.nextLine()) ; var name : String ; name := st.next() ; var ip : String ; ip := st.next() ; map := map->union(Map{ip |-> name}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < M do ( ( var line : String ; line := s.nextLine() ; st := OclIterator.newOclIterator_String(line) ; var command : String ; command := st.next() ; var ip : String ; ip := st.next() ; ip := ip.subrange(0+1,ip->size() - 1) ; var name : String ; name := map->at(ip) ; OclFile["System.out"].println(line + " #" + name) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import java.util.Scanner ; public class completeSearch { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); String[][] a=new String[n][2]; for(int j=0 ; jtoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(Sequence(String)) ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(null)) ; var j : int ; j := 0 ; while j < a->size() do ( ( a[j+1][0+1] := sc.getCurrent() ; a[j+1][1+1] := sc.getCurrent() + ';' ) ; j := j + 1 ) ; var b : Sequence(Sequence(String)) ; b := Integer.subrange(1,m)->collect(Integer.subrange(1,2)->collect(null)) ; var j : int ; j := 0 ; while j < b->size() do ( ( b[j+1][0+1] := sc.getCurrent() ; b[j+1][1+1] := sc.getCurrent() ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < b->size() do ( ( var k : int ; k := 0 ; while k < a->size() do ( ( if (b[j+1][1+1] = a[k+1][1+1]) then ( OclFile["System.out"].println(b[j+1][0+1] + " " + b[j+1][1+1] + " #" + a[k+1][0+1]) ; break ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.HashMap ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args)throws IOException { FastReader fr=new FastReader(); HashMapmp=new HashMap<>(); int n=fr.nextInt(); int m=fr.nextInt(); String s,s2 ; while(n-->0){ s=fr.next(); s2=fr.next(); mp.put(s2,s); } while(m-->0){ s=fr.next(); s2=fr.next(); System.out.println(s+" "+s2+" #"+mp.get(s2.substring(0,s2.length()-1))); } } } class FastReader { BufferedReader bf ; StringTokenizer st ; public FastReader(){ bf=new BufferedReader(new InputStreamReader(System.in)); } public String nextLine(){ String st="" ; try { st=bf.readLine(); } catch(IOException e){ e.printStackTrace(); } return st ; } public String next(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(bf.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var fr : FastReader ; fr := FastReader.newFastReader() ; var mp : Map(String,String) ; mp := Map{} ; var n : int ; n := fr.nextInt() ; var m : int ; m := fr.nextInt() ; var s : String ; var s2 : String ; while (n > 0) do ( n := n - 1 ; skip ; ( s := fr.next() ; s2 := fr.next() ; mp := mp->union(Map{s2 |-> s}) ) ; ) ; while (m > 0) do ( m := m - 1 ; skip ; ( s := fr.next() ; s2 := fr.next() ; OclFile["System.out"].println(s + " " + s2 + " #" + mp->at(s2.subrange(0+1,s2->size() - 1))) ) ; ) ; ); } class FastReader { attribute bf : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation nextLine() : String pre: true post: true activity: ( var st : String ; st := "" ; try ( st := bf.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return st ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(bf.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int val ; while((val=getInt(br))!=0){ int month=0 ; for(int i=1 ; i<=12 ; i++){ String s=br.readLine(); if(month==0){ val-=Integer.parseInt(s.substring(0,s.indexOf(" "))); val+=Integer.parseInt(s.substring(s.indexOf(" ")+1)); if(val<=0){ month=i ; } } } System.out.println(month>0 ?(month): "NA"); } } private static int getInt(BufferedReader br)throws IOException { return Integer.parseInt(br.readLine()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var val : int ; val := getInt(br) ; while ((val) /= 0) do ( skip ; ( var month : int ; month := 0 ; var i : int ; i := 1 ; while i <= 12 do ( ( var s : String ; s := br.readLine() ; if (month = 0) then ( val := val-((s.subrange(0+1,s->indexOf(" ")-1))->toInteger()) ; val := val+((s.subrange(s->indexOf(" ")-1 + 1+1,s->indexOf(" ")-1 + 1))->toInteger()) ; if (val <= 0) then ( month := i ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(if month > 0 then (month) else "NA" endif) ) ; val := getInt(br) ; ) ); static operation getInt( br : OclFile) : int pre: true post: true activity: ( return (br.readLine())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { private static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args)throws IOException { String s=in.readLine(); String[] split=s.split(" "); int n=Integer.parseInt(split[0]); int l=Integer.parseInt(split[1]); String s2=in.readLine(); String[] split2=s2.split(" "); int[] arr=new int[n]; for(int i=0 ; isplit(" ") ; var n : int ; n := (split[0+1])->toInteger() ; var l : int ; l := (split[1+1])->toInteger() ; var s2 : String ; s2 := in.readLine() ; var split2 : Sequence(String) ; split2 := s2->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < split2->size() do ( ( arr[i+1] := (split2[i+1])->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; var max : int ; max := Set{arr[0+1] * 2, (l - arr[n - 1+1]) * 2}->max() ; var i : int ; i := 1 ; while i < arr->size() do ( ( var d : int ; d := arr[i+1] - arr[i - 1+1] ; max := Set{d, max}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max->oclAsType(double) / 2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; public class Lanterns { public static void main(String[] args){ Scanner o=new Scanner(System.in); int n=o.nextInt(),l=o.nextInt(); long[] arr=new long[n]; for(int i=0 ; imax)max=arr[i+1]-arr[i]; } max/=2 ; if(arr[0]!=0 && maxtoInteger() ; var l : int ; l := o.getCurrent()->toInteger() ; var arr : Sequence(long) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := o.getCurrent()->toLong() ) ; i := i + 1 ) ; arr := arr->sort() ; var max : double ; max := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (arr[i + 1+1] - arr[i+1] > max) then max := arr[i + 1+1] - arr[i+1] ; else skip ) ; i := i + 1 ) ; max := max/(2) ; if (arr[0+1] /= 0 & max < arr[0+1]) then max := arr[0+1] ; else skip ; if (arr[n - 1+1] /= l & max < l - arr[n - 1+1]) then max := l - arr[n - 1+1] ; else skip ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(),l=s.nextInt(); double arr[]=new double[n]; for(int i=0 ; itoInteger() ; var l : int ; l := s.getCurrent()->toInteger() ; var arr : Sequence(double) ; arr := Integer.subrange(1,n)->collect(0.0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := s.getCurrent()->toInteger() ; ; i := i + 1 ) ; arr := arr->sort() ; var ans : double ; ans := Set{arr[0+1], l - arr[n - 1+1]}->max() ; var i : int ; i := 1 ; while i < n do ( ( ans := Set{ans, (arr[i+1] - arr[i - 1+1]) / 2}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; import java.util.Collections ; import java.util.Comparator ; import java.util.LinkedList ; import java.util.List ; import java.util.PriorityQueue ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); Comparatorcomp=(p1,p2)->p1.x-p2.x ; Listred=new LinkedList<>(); for(int i=0 ; iblue=new PriorityQueue<>(comp); for(int i=0 ; itoInteger() ; var comp : Function(,(,boolean)) ; comp := lambda (p1 , p2) : OclAny in p1.x - p2.x ; var red : Sequence(Point) ; red := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var in : Sequence(String) ; in := br.readLine()->split(" ") ; red := red->including(Point.newPoint((in[0+1])->toInteger(), (in[1+1])->toInteger())) ) ; i := i + 1 ) ; red, comp := red, comp->sort() ; var blue : Sequence(Point) ; blue := Sequence{}->union(comp) ; var i : int ; i := 0 ; while i < n do ( ( var in : Sequence(String) ; in := br.readLine()->split(" ") ; blue := blue->including(Point.newPoint((in[0+1])->toInteger(), (in[1+1])->toInteger())) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; while (not(blue->isEmpty())) do ( var b : Point ; b := blue->min() ; var index : int ; index := -1 ; var maxy : int ; maxy := -1 ; var i : int ; i := 0 ; var tmp : Point ; tmp := red->at(i+1) ; while (i < red->size() & (tmp).x < b.x) do ( skip ; ( if (tmp.y < b.y & maxy < tmp.y) then ( index := i ; maxy := tmp.y ) else skip ; i := i + 1 ) ; tmp := red->at(i+1) ; ) ; if (index /= -1) then ( red := red->excludingAt(index+1) ; ans := ans + 1 ) else skip ; ) ; OclFile["System.out"].println(ans) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int l=in.nextInt(); ArrayListarr=new ArrayList<>(); for(int i=0 ; id)d=temp ; } int first=arr.get(0); int last=l-arr.get(n-1); if(last>d)d=last ; if(first>d)d=first ; System.out.println(d); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var l : int ; l := in.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( arr := arr->including(in.getCurrent()->toInteger()) ) ; i := i + 1 ) ; arr := arr->sort() ; var d : double ; d := 0 ; var temp : double ; var i : int ; i := 0 ; while i < n - 1 do ( ( temp := (arr->at(i + 1+1) - arr->at(i+1)) / 2.0 ; if (temp > d) then d := temp ; else skip ) ; i := i + 1 ) ; var first : int ; first := arr->at(0+1) ; var last : int ; last := l - arr->at(n - 1+1) ; if (last > d) then d := last ; else skip ; if (first > d) then d := first ; else skip ; OclFile["System.out"].println(d) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void minAdjDifference(int arr[],int n){ if(n<2)return ; int res=Math.abs(arr[1]-arr[0]); for(int i=2 ; i 2) then maximum_split := maximum_split + 1 ; else skip ; if (maximum_split < K) then ( OclFile["System.out"].println("No") ; return ) else skip ; OclFile["System.out"].println("Yes") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 12 ; var K : int ; K := 3 ; execute KPrimeDivisors(N, K) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p077 implements EulerSolution { public static void main(String[] args){ System.out.println(new p077().run()); } private static final int TARGET=5000 ; public String run(){ for(int limit=1 ; ; limit*=2){ int result=search(limit,TARGET); if(result!=-1)return Integer.toString(result); } } private static int search(int limit,int target){ int[] partitions=new int[limit]; partitions[0]=1 ; for(int i=0 ; itarget)return i ; } return-1 ; } } ------------------------------------------------------------ OCL File: --------- class p077 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p077.newp077().run()) ); static attribute TARGET : int := 5000; operation run() : String pre: true post: true activity: ( var limit : int ; limit := 1 ; while true do ( ( var result : int ; result := search(limit, TARGET) ; if (result /= -1) then return ((result) + "") else skip ) ; limit := limit*(2) ) ); static operation search( limit : int, target : int) : int pre: true post: true activity: ( var partitions : Sequence(int) ; partitions := Integer.subrange(1,limit)->collect(0) ; partitions[0+1] := 1 ; var i : int ; i := 0 ; while i < partitions->size() do ( ( if (not(Library.isPrime(i))) then continue else skip ; var j : int ; j := i ; while j < partitions->size() do ( partitions[j+1] := partitions[j+1]+(partitions[j - i+1]) ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < limit do ( ( if (partitions[i+1] > target) then return i else skip ) ; i := i + 1 ) ; return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.Queue ; class GFG { static int minimumMulitplications(int start,int end,int a[],int n){ int ans[]=new int[100001]; Arrays.fill(ans,-1); int mod=100000 ; Queueq=new LinkedList<>(); q.add(start % mod); ans[start]=0 ; while(! q.isEmpty()){ int top=q.peek(); q.remove(); if(top==end){ return ans[end]; } for(int i=0 ; icollect(0) ; ans := ans->collect(-1) ; var mod : int ; mod := 100000 ; var q : Sequence(int) ; q := Sequence{} ; q := q->including(start mod mod) ; ans[start+1] := 0 ; while (not(q->isEmpty())) do ( var top : int ; top := q->min() ; q := q.remove() ; if (top = end) then ( return ans[end+1] ) else skip ; var i : int ; i := 0 ; while i < n do ( ( var pushed : int ; pushed := top * a[i+1] ; pushed := pushed mod mod ; if (ans[pushed+1] = -1) then ( ans[pushed+1] := ans[top+1] + 1 ; q := q->including(pushed) ) else skip ) ; i := i + 1 ) ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var start : int ; start := 7 ; var end : int ; end := 66175 ; var a : Sequence(int) ; a := Sequence{3,4,65} ; var n : int ; n := a->size() ; OclFile["System.out"].println(minimumMulitplications(start, end, a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Seasons { public static void findSeason(int M){ switch(M){ case 12 : case 1 : case 2 : System.out.println("WINTER"); break ; case 3 : case 4 : case 5 : System.out.println("SPRING"); break ; case 6 : case 7 : case 8 : System.out.println("SUMMER"); break ; case 9 : case 10 : case 11 : System.out.println("AUTUMN"); break ; default : System.out.println("Invalid Month number"); break ; } } public static void main(String abc[]){ int M=5 ; System.out.println("For Month number: "+M); findSeason(M); M=10 ; System.out.println("For Month number: "+M); findSeason(M); } } ------------------------------------------------------------ OCL File: --------- class Seasons { static operation findSeason( M : int) : void pre: true post: true activity: ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (M) ; if _switchval = 12 or _switchval = 1 or _switchval = 2 then OclFile["System.out"].println("WINTER") ; break else skip ; if _switchval = 3 or _switchval = 4 or _switchval = 5 then OclFile["System.out"].println("SPRING") ; break else skip ; if _switchval = 6 or _switchval = 7 or _switchval = 8 then OclFile["System.out"].println("SUMMER") ; break else skip ; if _switchval = 9 or _switchval = 10 or _switchval = 11 then OclFile["System.out"].println("AUTUMN") ; break else skip ; if true then OclFile["System.out"].println("Invalid Month number") ; break else skip ; ) ); static operation main( abc : Sequence(String)) : void pre: true post: true activity: ( var M : int ; M := 5 ; OclFile["System.out"].println("For Month number: " + M) ; execute findSeason(M) ; M := 10 ; OclFile["System.out"].println("For Month number: " + M) ; execute findSeason(M) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); ArrayListarr=new ArrayList<>(); while(true){ boolean flag=false ; int border=Integer.parseInt(scan.next()); if(border==0){ break ; } String ret="NA" ; int sum=0 ; for(int i=0 ; i<12 ; i++){ int m=Integer.parseInt(scan.next()); int n=Integer.parseInt(scan.next()); int sub=m-n ; sum+=sub ; if(sum>=border && flag==false){ ret=String.valueOf(i+1); flag=true ; } } arr.add(ret); } arr.stream().forEach(System.out :: println); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var arr : Sequence(String) ; arr := Sequence{} ; while (true) do ( var flag : boolean ; flag := false ; var border : int ; border := (scan.getCurrent())->toInteger() ; if (border = 0) then ( break ) else skip ; var ret : String ; ret := "NA" ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < 12 do ( ( var m : int ; m := (scan.getCurrent())->toInteger() ; var n : int ; n := (scan.getCurrent())->toInteger() ; var sub : int ; sub := m - n ; sum := sum+(sub) ; if (sum >= border & flag = false) then ( ret := ((i + 1) + "") ; flag := true ) else skip ; ) ; i := i + 1 ) ; arr := arr->including(ret) ; ) ; for _forEach : arr do ( skip ;) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.HashMap ; import java.util.Scanner ; public class DreamoonLikesPermutations { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0){ int n=s.nextInt(); int arr[]=new int[n]; for(int i=0 ; imap=new HashMap<>(); for(int i=n-1 ; i>=0 ; i--){ map.put(arr[i],true); dis[i]=map.size(); max=Math.max(max,arr[i]); maxi[i]=max ; } ArrayListans=new ArrayList(); HashMapstr=new HashMap<>(); max=Integer.MIN_VALUE ; for(int i=0 ; itoInteger() ; while (t > 0) do ( var n : int ; n := s.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dis : Sequence(int) ; dis := Integer.subrange(1,n)->collect(0) ; var max : int ; max := -2147483648 ; var maxi : Sequence(int) ; maxi := Integer.subrange(1,n)->collect(0) ; var map : Map(int,Boolean) ; map := Map{} ; var i : int ; i := n - 1 ; while i >= 0 do ( ( map := map->union(Map{arr[i+1] |-> true}) ; dis[i+1] := map.size() ; max := Set{max, arr[i+1]}->max() ; maxi[i+1] := max ) ; i := i - 1 ) ; var ans : Sequence(int) ; ans := Sequence{} ; var str : Map(int,Boolean) ; str := Map{} ; max := -2147483648 ; var i : int ; i := 0 ; while i < n - 1 do ( ( str := str->union(Map{arr[i+1] |-> true}) ; max := Set{max, arr[i+1]}->max() ; if (i + 1 = max & str.size() = i + 1 & dis[i + 1+1] = n - i - 1 & maxi[i + 1+1] = n - i - 1) then ( ans := ans->including(i + 1) ; ans := ans->including(n - i - 1) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans->size() / 2) ; var i : int ; i := 0 ; while i < ans->size() do ( ( OclFile["System.out"].println(ans->at(i+1) + " " + ans->at(i + 1+1)) ) ; i := i + 2 ) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class DreamoonLikesPermutations { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t!=0){ solve(br,pr); t--; } pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); String[] temp=br.readLine().split(" "); int[] nums=new int[n]; for(int i=0 ; iset=new TreeSet<>(); Setres=new HashSet<>(); for(int i=1 ; i<=n ; i++){ set.add(i); } for(int i=0 ; i(); for(int i=1 ; i<=n ; i++){ set.add(i); } for(int i=n-1 ; i>=0 ; i--){ set.remove(nums[i]); if(set.first()!=n-i+1){ res.remove(i); } } pr.println(res.size()); for(int i : res){ pr.println(i+" "+(n-i)); } } } ------------------------------------------------------------ OCL File: --------- class DreamoonLikesPermutations { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pr : OclFile ; pr := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := (br.readLine())->toInteger() ; while (t /= 0) do ( execute solve(br, pr) ; t := t - 1 ) ; skip ; skip ; ); static operation solve( br : OclFile, pr : OclFile) : void pre: true post: true activity: ( var n : int ; n := (br.readLine())->toInteger() ; var temp : Sequence(String) ; temp := br.readLine()->split(" ") ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := (temp[i+1])->toInteger() ) ; i := i + 1 ) ; var set : Set(int) ; set := Set{} ; var res : Set(int) ; res := Set{} ; var i : int ; i := 1 ; while i <= n do ( ( set := set->including(i) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( set := set->excludingFirst(nums[i+1]) ; if (set->first() = i + 2) then ( res := res->including(i + 1) ) else skip ) ; i := i + 1 ) ; set := Set{} ; var i : int ; i := 1 ; while i <= n do ( ( set := set->including(i) ) ; i := i + 1 ) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( set := set->excludingFirst(nums[i+1]) ; if (set->first() /= n - i + 1) then ( res := res->excludingAt(i+1) ) else skip ) ; i := i - 1 ) ; skip ; for (i : res) do ( ( skip ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int p=s.nextInt(); int q=s.nextInt(); String str=s.next(); for(int i=0 ; i<=n/p ; i++){ int find=n-p*i ; if(find % q==0){ int start=0 ; System.out.println(i+find/q); while(i>0){ System.out.println(str.substring(start,start+p)); start+=p ; i--; } int j=find/q ; while(j>0){ System.out.println(str.substring(start,start+q)); start+=q ; j--; } return ; } } System.out.println(-1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var p : int ; p := s.getCurrent()->toInteger() ; var q : int ; q := s.getCurrent()->toInteger() ; var str : String ; str := s.getCurrent() ; var i : int ; i := 0 ; while i <= n / p do ( ( var find : int ; find := n - p * i ; if (find mod q = 0) then ( var start : int ; start := 0 ; OclFile["System.out"].println(i + find / q) ; while (i > 0) do ( OclFile["System.out"].println(str.subrange(start+1,start + p)) ; start := start+(p) ; i := i - 1 ) ; var j : int ; j := find / q ; while (j > 0) do ( OclFile["System.out"].println(str.subrange(start+1,start + q)) ; start := start+(q) ; j := j - 1 ) ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(-1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int p=scan.nextInt(); int q=scan.nextInt(); String str=scan.next(); int x=0,y=0 ; for(int i=0 ; in)){ System.out.println("-1"); } else { System.out.println(x+y); for(int i=0 ; itoInteger() ; var p : int ; p := scan.getCurrent()->toInteger() ; var q : int ; q := scan.getCurrent()->toInteger() ; var str : String ; str := scan.getCurrent() ; var x : int ; x := 0 ; var y : int ; y := 0 ; var i : int ; i := 0 ; while i < n do ( ( if ((n - q * i) mod p = 0) then ( y := i ; break ) else skip ) ; i := i + 1 ) ; if ((n - q * y) mod p = 0) then ( x := (n - q * y) / p ; if (x < 0) then ( x := x * (-1) ) else skip ) else skip ; if ((x = 0 & y = 0) or (x * p + y * q > n)) then ( OclFile["System.out"].println("-1") ) else ( OclFile["System.out"].println(x + y) ; var i : int ; i := 0 ; while i < x do ( ( OclFile["System.out"].println(str.subrange(i * p+1,i * p + p)) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < y do ( ( OclFile["System.out"].println(str.subrange(i * q + p * x+1,i * q + p * x + q)) ) ; i := i + 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[][] red=new int[n][2]; int[][] blue=new int[n][2]; for(int i=0 ; iarray1[1]-array2[1]); Arrays.sort(blue,(array1,array2)->array1[0]-array2[0]); SetusedSet=new HashSet<>(); for(int[] b : blue){ int max=-1 ; for(int i=0 ; i=b[0])continue ; if(red[i][1]>=b[1])break ; if(max==-1 || red[max][1]toInteger() ; var red : Sequence(Sequence(int)) ; red := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var blue : Sequence(Sequence(int)) ; blue := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < 2 do ( red[i+1][j+1] := sc.getCurrent()->toInteger() ; ; j := j + 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < 2 do ( blue[i+1][j+1] := sc.getCurrent()->toInteger() ; ; j := j + 1 ) ; ; i := i + 1 ) ; red := OclComparator.sortWith(red, lambda (array1 , array2) : OclAny in array1[1+1] - array2[1+1]) ; blue := OclComparator.sortWith(blue, lambda (array1 , array2) : OclAny in array1[0+1] - array2[0+1]) ; var usedSet : Set(int) ; usedSet := Set{} ; for (b : blue) do ( ( var max : int ; max := -1 ; var i : int ; i := 0 ; while i < red->size() do ( ( if (usedSet->includes(i) or red[i+1][0+1] >= b[0+1]) then continue else skip ; if (red[i+1][1+1] >= b[1+1]) then break else skip ; if (max = -1 or red[max+1][1+1] < red[i+1][1+1]) then max := i ; else skip ) ; i := i + 1 ) ; if (max /= -1) then usedSet := usedSet->including(max) ; else skip ) ) ; OclFile["System.out"].println(usedSet->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int countp=0 ; static int countq=0 ; public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int a[]=new int[2]; a[0]=input.nextInt(); a[1]=input.nextInt(); String s=input.next(); if(s.length()% a[0]==0){ countp=s.length()/a[0]; } else if(s.length()% a[1]==0){ countq=s.length()/a[1]; } else { for(int i=0 ; i<=100 ; i++){ if((s.length()-(a[0]*i))% a[1]==0 &&((s.length()-(a[0]*i))/a[1])>=0){ countp=i ; countq=(s.length()-(a[0]*i))/a[1]; break ; } } } int start=0 ; if(countp==0 && countq==0){ System.out.println("-1"); } else { System.out.println(countp+countq); while(countp-->0){ System.out.println(s.substring(start,start+a[0])); start=start+a[0]; } while(countq-->0){ System.out.println(s.substring(start,start+a[1])); start+=a[1]; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute countp : int := 0; static attribute countq : int := 0; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := input.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,2)->collect(0) ; a[0+1] := input.getCurrent()->toInteger() ; a[1+1] := input.getCurrent()->toInteger() ; var s : String ; s := input.getCurrent() ; if (s->size() mod a[0+1] = 0) then ( countp := s->size() / a[0+1] ) else if (s->size() mod a[1+1] = 0) then ( countq := s->size() / a[1+1] ) else ( var i : int ; i := 0 ; while i <= 100 do ( ( if ((s->size() - (a[0+1] * i)) mod a[1+1] = 0 & ((s->size() - (a[0+1] * i)) / a[1+1]) >= 0) then ( countp := i ; countq := (s->size() - (a[0+1] * i)) / a[1+1] ; break ) else skip ) ; i := i + 1 ) ) ; ; var start : int ; start := 0 ; if (countp = 0 & countq = 0) then ( OclFile["System.out"].println("-1") ) else ( OclFile["System.out"].println(countp + countq) ; while (countp > 0) do ( countp := countp - 1 ; skip ; ( OclFile["System.out"].println(s.subrange(start+1,start + a[0+1])) ; start := start + a[0+1] ) ; ) ; while (countq > 0) do ( countq := countq - 1 ; skip ; ( OclFile["System.out"].println(s.subrange(start+1,start + a[1+1])) ; start := start+(a[1+1]) ) ; ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class TheTextSplitting { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); int p=Integer.parseInt(str[1]); int q=Integer.parseInt(str[2]); String string=br.readLine(); int pa=-1 ; int qb=-1 ; for(int i=0 ; (p*i<=n); i++){ if((n-i*p)% q==0){ pa=i ; qb=(n-pa*p)/q ; } if(pa!=-1){ break ; } } if(pa==-1){ System.out.print("-1"); return ; } StringBuilder sb=new StringBuilder(); int start=0 ; for(int i=0 ; isplit(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var p : int ; p := (str[1+1])->toInteger() ; var q : int ; q := (str[2+1])->toInteger() ; var string : String ; string := br.readLine() ; var pa : int ; pa := -1 ; var qb : int ; qb := -1 ; var i : int ; i := 0 ; while (p * i <= n) do ( ( if ((n - i * p) mod q = 0) then ( pa := i ; qb := (n - pa * p) / q ) else skip ; if (pa /= -1) then ( break ) else skip ) ; i := i + 1 ) ; if (pa = -1) then ( OclFile["System.out"].print("-1") ; return ) else skip ; var sb : String ; sb := StringLib.newString() ; var start : int ; start := 0 ; var i : int ; i := 0 ; while i < pa do ( ( var j : int ; j := 0 ; while j < p do ( ( sb := sb + StringLib.newString(string->at(start+1)) ; if (j = p - 1) then ( sb := sb + StringLib.newString("\n") ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < qb do ( ( var j : int ; j := 0 ; while j < q do ( ( sb := sb + StringLib.newString(string->at(start+1)) ; if (j = q - 1) then ( sb := sb + StringLib.newString("\n") ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(pa + qb) ; OclFile["System.out"].print(sb+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isDigit(char ch){ if(ch>='0' && ch<='9')return true ; return false ; } static int nextNonDigit(String str,int i){ while(i=str.length())return-1 ; return i ; } static void appendRepeated(StringBuilder sb,String str,int times){ for(int i=0 ; i= '0' & ch <= '9') then return true else skip ; return false ); static operation nextNonDigit( str : String, i : int) : int pre: true post: true activity: ( while (i < str->size() & isDigit(str->at(i+1))) do ( i := i + 1 ) ; if (i >= str->size()) then return -1 else skip ; return i ); static operation appendRepeated( sb : String, str : String, times : int) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < times do ( sb := sb + StringLib.newString(str) ; ; i := i + 1 ) ); static operation findString( str : String, n : int) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString("") ; var startStr : int ; startStr := nextNonDigit(str, 0) ; while (startStr /= -1) do ( var endStr : int ; endStr := startStr ; while ((endStr + 1) < n & not(isDigit(str->at(endStr + 1+1)))) do ( endStr := endStr + 1 ) ; var startNum : int ; startNum := endStr + 1 ; if (startNum = -1) then break else skip ; var endNum : int ; endNum := startNum ; while ((endNum + 1) < n & isDigit(str->at(endNum + 1+1))) do ( endNum := endNum + 1 ) ; var num : int ; num := (str.subrange(startNum+1,endNum + 1))->toInteger() ; execute appendRepeated(sb, str.subrange(startStr+1,endStr + 1), num) ; startStr := nextNonDigit(str, endStr + 1) ; ) ; return sb+"" ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "g1ee1ks1for1g1e2ks1" ; var n : int ; n := str->size() ; OclFile["System.out"].println(findString(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.HashSet ; import java.util.Set ; public class Main { private static final String VOWEL="aeiou" ; public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true){ int n=Integer.parseInt(br.readLine()); if(n==0)break ; int max=0 ; ArrayListlist=new ArrayList<>(); for(int i=0 ; iset ; while(++ans<=max){ set=new HashSet<>(); for(String str : list){ set.add(trim(str,ans)); } if(set.size()==n){ break ; } } System.out.println(ans>max ?-1 : ans); } } static String trim(String str,int len){ StringBuilder sb=new StringBuilder(); boolean flg=true ; for(char elm : str.toCharArray()){ if(flg){ sb.append(elm); flg=false ; } if(VOWEL.indexOf(elm)>=0){ flg=true ; } } return sb.toString().substring(0,Math.min(len,sb.length())); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute VOWEL : String := "aeiou"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (true) do ( var n : int ; n := (br.readLine())->toInteger() ; if (n = 0) then break else skip ; var max : int ; max := 0 ; var list : Sequence(String) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var str : String ; str := br.readLine() ; max := Set{str->size(), max}->max() ; list := list->including(str) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var set : Set(String) ; ans := ans + 1 ; while ((ans + 1) <= max) do ( ans := ans + 1 ; skip ; ( set := Set{} ; for (str : list) do ( ( set := set->including(trim(str, ans)) ) ) ; if (set->size() = n) then ( break ) else skip ) ; ans := ans + 1 ; ) ; OclFile["System.out"].println(if ans > max then -1 else ans endif) ; ) ); static operation trim( str : String, len : int) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; var flg : boolean ; flg := true ; for (elm : str->characters()) do ( ( if (flg) then ( sb := sb + StringLib.newString(elm) ; flg := false ) else skip ; if (VOWEL->indexOf(elm)-1 >= 0) then ( flg := true ) else skip ) ) ; return sb+"".subrange(0+1,Set{len, sb->size()}->min()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static Setlist ; public static void main(String[] args){ Scanner scan=new Scanner(System.in); list=new HashSet<>(); list.add('a'); list.add('i'); list.add('u'); list.add('e'); list.add('o'); int n ; loop : while(scan.hasNext()){ n=scan.nextInt(); if(n==0)return ; String[] arr=new String[n]; for(int i=0 ; iincluding('a') ; list := list->including('i') ; list := list->including('u') ; list := list->including('e') ; list := list->including('o') ; var n : int ; while (scan.hasNext()) do ( n := scan.getCurrent()->toInteger() ; if (n = 0) then return else skip ; var arr : Sequence(String) ; arr := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := getShortName(scan.getCurrent()->characters()) ; ; i := i + 1 ) ; arr := arr->sort() ; var result : int ; result := 0 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (arr[i+1] = arr[i + 1+1]) then ( OclFile["System.out"].println(-1) ; continue ) else ( var same : int ; same := 0 ; var j : int ; j := 0 ; while j < Set{arr[i+1]->size(), arr[i + 1+1]->size()}->min() do ( ( if (arr[i+1]->at(j+1) = arr[i + 1+1]->at(j+1)) then ( same := same + 1 ) else skip ) ; j := j + 1 ) ; result := Set{same, result}->max() ) ) ; i := i + 1 ) ; OclFile["System.out"].println(result + 1) ; ) ; ); static operation getShortName( input : Sequence(String)) : String pre: true post: true activity: ( var result : String ; result := "" + input[0+1] ; var i : int ; i := 1 ; while i < input->size() do ( ( if (list->includes(input[(i)->char2byte() - 1+1])) then ( result := result+(input[i+1]) ) else skip ) ; i := i + 1 ) ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practice { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); if(a==b && c==b){ System.out.println(0); } else { int sum=Math.abs(a-b)+Math.abs(b-c)+Math.abs(c-a); sum-=4 ; System.out.println(Math.max(sum,0)); } } } } ------------------------------------------------------------ OCL File: --------- class Practice { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if (a = b & c = b) then ( OclFile["System.out"].println(0) ) else ( var sum : int ; sum := if a - b < 0 then -(a - b) else a - b endif + if b - c < 0 then -(b - c) else b - c endif + if c - a < 0 then -(c - a) else c - a endif ; sum := sum-(4) ; OclFile["System.out"].println(Set{sum, 0}->max()) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { private static final String covconv(String s){ final char[] a=s.toCharArray(); int sp=0 ; for(int p=0 ; pcharacters() ; var sp : int ; sp := 0 ; var p : int ; p := 0 ; while p < a->size() do ( ( a[sp+1] := a[p+1] ; sp := sp + 1 ; while (p < a->size() & "aiueo"->indexOf(a[p+1])-1 = -1) do p := p + 1 ; ) ; p := p + 1 ) ; return StringLib.newString(a, 0, sp) ); static operation kenkov( s : Sequence(String)) : int pre: true post: true activity: ( var rvalue : int ; rvalue := 0 ; var i : int ; i := 0 ; while i < s->size() do ( rvalue := Set{rvalue, s[i+1]->size()}->max() ; ; i := i + 1 ) ; return rvalue ); static operation check_disjoint( s : Sequence(String), k : int) : boolean pre: true post: true activity: ( var i : int ; i := 0 ; while i < s->size() do ( ( var s1 : String ; s1 := s[i+1].subrange(0+1,Set{s[i+1]->size(), k}->min()) ; var j : int ; j := i + 1 ; while j < s->size() do ( ( var s2 : String ; s2 := s[j+1].subrange(0+1,Set{s[j+1]->size(), k}->min()) ; if (s1 = s2) then return false else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : Scanner := Scanner.newScanner(OclFile["System.in"]) ; ( while true do ( ( var n : int ; n := sc.nextInt() ; if (n = 0) then break else skip ; var s : Sequence(String) ; s := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := covconv(sc.next()) ) ; i := i + 1 ) ; var max_length : int ; max_length := kenkov(s) ; var k : int ; k := 1 ; while k <= max_length do ( ( if (check_disjoint(s, k)) then ( OclFile["System.out"].println(k) ; continue ) else skip ) ; k := k + 1 ) ; OclFile["System.out"].println("-1") ; ) ) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.HashSet ; import java.util.List ; import java.util.Scanner ; import java.util.Set ; public class Main { public static String getAbbrName(String name,int k){ StringBuilder sb=new StringBuilder(); sb.append(name.charAt(0)); String vowels="aiueo" ; for(int i=0 ; inames,int k){ SetabbrSet=new HashSet<>(); for(String name : names){ String abbr=getAbbrName(name,k); if(abbrSet.contains(abbr))return false ; abbrSet.add(abbr); } return true ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); sc.nextLine(); if(n==0)break ; Listnames=new ArrayList<>(); while(n>0){ String name=sc.nextLine(); names.add(name); n--; } int minK=-1 ; for(int k=1 ; k<=50 ; k++){ if(canGiveUniqueName(names,k)){ minK=k ; break ; } } System.out.println(minK); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation getAbbrName( name : String, k : int) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString(name->at(0+1)) ; var vowels : String ; vowels := "aiueo" ; var i : int ; i := 0 ; while i < name->size() - 1 do ( ( var c : String ; c := name->at(i+1) ; if (sb->size() = k) then break else skip ; if (vowels->indexOf(c)-1 /= -1) then ( var nc : String ; nc := name->at(i + 1+1) ; sb := sb + StringLib.newString(nc) ) else skip ) ; i := i + 1 ) ; return sb+"" ); static operation canGiveUniqueName( names : Sequence(String), k : int) : boolean pre: true post: true activity: ( var abbrSet : Set(String) ; abbrSet := Set{} ; for (name : names) do ( ( var abbr : String ; abbr := getAbbrName(name, k) ; if (abbrSet->includes(abbr)) then return false else skip ; abbrSet := abbrSet->including(abbr) ) ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; skip ; if (n = 0) then break else skip ; var names : Sequence(String) ; names := Sequence{} ; while (n > 0) do ( var name : String ; name := sc.nextLine() ; names := names->including(name) ; n := n - 1 ) ; var minK : int ; minK := -1 ; var k : int ; k := 1 ; while k <= 50 do ( ( if (canGiveUniqueName(names, k)) then ( minK := k ; break ) else skip ) ; k := k + 1 ) ; OclFile["System.out"].println(minK) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ while(sc.hasNext()){ int n=sc.nextInt(); if(n==0)break ; String[] code=new String[n+1]; for(int i=0 ; i0){ System.out.println(-1); } else { System.out.println(ans); } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while (sc.hasNext()) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var code : Sequence(String) ; code := Integer.subrange(1,n + 1)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( var str : String ; str := sc.getCurrent() ; var s : String ; s := "" ; s := s+(((str->at(0+1)) + "")) ; var j : int ; j := 0 ; while j < str->size() - 1 do ( ( if (str->at(j+1) = 'a' or str->at(j+1) = 'i' or str->at(j+1) = 'u' or str->at(j+1) = 'e' or str->at(j+1) = 'o') then ( s := s+(((str->at(j + 1+1)) + "")) ) else skip ) ; j := j + 1 ) ; code[i+1] := s ; ) ; i := i + 1 ) ; var c : int ; c := 0 ; var ans : int ; ans := 0 ; var k : int ; k := 0 ; while k < 50 do ( ( c := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var str1 : String ; str1 := code[i+1].subrange(0+1,Set{k + 1, code[i+1]->size()}->min()) ; var str2 : String ; str2 := code[j+1].subrange(0+1,Set{k + 1, code[j+1]->size()}->min()) ; if (str1 = str2) then ( c := 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (c = 0) then ( ans := k + 1 ; break ) else skip ) ; k := k + 1 ) ; if (c > 0) then ( OclFile["System.out"].println(-1) ) else ( OclFile["System.out"].println(ans) ) ; ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.math.*; import java.util.*; public class D { char[] cs ; int n ; public static void main(String[] args){ new D().run(); } void run(){ Scanner sc=new Scanner(System.in); int on=sc.nextInt(); for(int o=1 ; o<=on ; o++){ System.out.printf("Case #%d: ",o); n=sc.nextInt(); cs=sc.next().toCharArray(); System.out.println(permRec(new int[n],new boolean[n],0)); } } int permRec(int[] a,boolean[] used,int p){ if(p==a.length){ char last=0 ; int res=0 ; for(int i=0 ; itoInteger() ; var o : int ; o := 1 ; while o <= on do ( ( OclFile["System.out"].printf("Case #%d: ", o) ; n := sc.getCurrent()->toInteger() ; cs := sc.getCurrent()->characters() ; OclFile["System.out"].println(permRec(Integer.subrange(1,n)->collect(0), Integer.subrange(1,n)->collect(false), 0)) ) ; o := o + 1 ) ); operation permRec( a : Sequence(int), used : Sequence(boolean), p : int) : int pre: true post: true activity: ( if (p = a->size()) then ( var last : String ; last := 0 ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < cs->size() do ( ( var j : int ; j := 0 ; while j < n do ( ( var c : String ; c := cs[i + a[j+1]+1] ; if (c /= last) then ( res := res + 1 ; last := c ) else skip ) ; j := j + 1 ) ) ; i := i+(n) ) ; return res ) else ( var res : int ; res := 2147483647 ; a[p+1] := 0 ; while a[p+1] < used->size() do ( if (not(used[a[p+1]+1])) then ( used[a[p+1]+1] := true ; res := Set{res, permRec(a, used, p + 1)}->min() ; used[a[p+1]+1] := false ) else skip ; ; a[p+1] := a[p+1] + 1 ) ; return res ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.io.File ; import java.io.FileNotFoundException ; import java.util.Scanner ; public class D { static Scanner in ; static PrintWriter out ; public static void main(String[] args)throws FileNotFoundException { in=new Scanner(new File("input.txt")); out=new PrintWriter("output.txt"); int n=in.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < n do ( ( skip ) ; i := i + 1 ) ; skip ; ); attribute k : int; attribute s : String; attribute p : Sequence(int); attribute z : Sequence(boolean); attribute res : int; operation solve() : OclAny pre: true post: true activity: ( k := in.getCurrent()->toInteger() ; s := in.getCurrent() ; p := Integer.subrange(1,k)->collect(0) ; z := Integer.subrange(1,k)->collect(false) ; res := s->size() + 1 ; execute bt(0) ; return "" + res ); operation bt( i : int) : void pre: true post: true activity: ( if (i = k) then ( var pc : String ; pc := '.' ; var r : int ; r := 0 ; var j : int ; j := 0 ; while j < s->size() / k do ( ( var t : int ; t := 0 ; while t < k do ( ( var c : String ; c := s->at(j * k + p[t+1]+1) ; if (c /= pc) then ( pc := c ; r := r + 1 ) else skip ) ; t := t + 1 ) ) ; j := j + 1 ) ; res := Set{res, r}->min() ) else ( p[i+1] := 0 ; while p[i+1] < k do ( if (not(z[p[i+1]+1])) then ( z[p[i+1]+1] := true ; execute bt(i + 1) ; z[p[i+1]+1] := false ) else skip ; ; p[i+1] := p[i+1] + 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; class Main { public static final int INF=Integer.MAX_VALUE/4 ; public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); int[] red=new int[2*N]; int[] blue=new int[2*N]; Arrays.fill(red,INF); Arrays.fill(blue,INF); for(int i=0 ; i=0){ ans++; red[maxIdx]=INF ; } } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute INF : int := 2147483647 / 4; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; var red : Sequence(int) ; red := Integer.subrange(1,2 * N)->collect(0) ; var blue : Sequence(int) ; blue := Integer.subrange(1,2 * N)->collect(0) ; red := red->collect(INF) ; blue := blue->collect(INF) ; var i : int ; i := 0 ; while i < N do ( ( red[scanner.getCurrent()->toInteger()+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( blue[scanner.getCurrent()->toInteger()+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 2 * N do ( ( if (blue[i+1] /= INF) then ( var maxY : int ; maxY := -1 ; var maxIdx : int ; maxIdx := -1 ; var j : int ; j := 0 ; while j < i do ( ( if (red[j+1] /= INF & red[j+1] < blue[i+1] & maxY < red[j+1]) then ( maxY := red[j+1] ; maxIdx := j ) else skip ) ; j := j + 1 ) ; if (maxIdx >= 0) then ( ans := ans + 1 ; red[maxIdx+1] := INF ) else skip ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.HashSet ; import java.util.Scanner ; import java.util.Stack ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); while(true){ int n=Integer.parseInt(scan.next()); int m=Integer.parseInt(scan.next()); if(n==0)break ; V[] ver=new V[n]; for(int i=0 ; istk=new Stack(); stk.push(new int[] { 0,0 } ); used[0]=true ; int ans=0 ; while(! stk.isEmpty()){ int[] p=stk.pop(); int num=p[0],deep=p[1]; ans++; if(deep!=2)for(Integer i : ver[num] .to){ if(! used[i]){ used[i]=true ; stk.push(new int[] { i,deep+1 } ); } } } out.println(ans-1); } out.flush(); } } class V { HashSetto=new HashSet(); } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; while (true) do ( var n : int ; n := (scan.getCurrent())->toInteger() ; var m : int ; m := (scan.getCurrent())->toInteger() ; if (n = 0) then break else skip ; var ver : Sequence(V) ; ver := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ver[i+1] := V.newV() ; ; i := i + 1 ) ; var used : Sequence(boolean) ; used := Integer.subrange(1,n)->collect(false) ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := (scan.getCurrent())->toInteger() - 1 ; var b : int ; b := (scan.getCurrent())->toInteger() - 1 ; ver[a+1].to->excludes(b) ; ver[b+1].to->excludes(a) ) ; i := i + 1 ) ; var stk : Sequence(Sequence(int)) ; stk := Sequence{} ; stk := stk->append(Sequence{0,0}) ; used[0+1] := true ; var ans : int ; ans := 0 ; while (not(stk->isEmpty())) do ( var p : Sequence(int) ; p := stk->last() ; var num : int ; num := p[0+1] ; var deep : int ; deep := p[1+1] ; ans := ans + 1 ; if (deep /= 2) then for (i : ver[num+1].to) do ( ( if (not(used[i+1])) then ( used[i+1] := true ; stk := stk->append(Sequence{i,deep + 1}) ) else skip ) ) ; else skip ) ; skip ; ) ; skip ); } class V { attribute to : Set(int) := Set{}; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n,m ; int a[]; int friendA[]; int friendB[]; int count ; n=sc.nextInt(); m=sc.nextInt(); while(n+m!=0){ a=new int[n]; a[0]=1 ; for(int i=1 ; itoInteger() ; m := sc.getCurrent()->toInteger() ; while (n + m /= 0) do ( a := Integer.subrange(1,n)->collect(0) ; a[0+1] := 1 ; var i : int ; i := 1 ; while i < n do ( ( a[i+1] := 0 ) ; i := i + 1 ) ; friendA := Integer.subrange(1,m)->collect(0) ; friendB := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( friendA[i+1] := sc.getCurrent()->toInteger() ; friendB[i+1] := sc.getCurrent()->toInteger() ; if (friendA[i+1] = 1) then ( a[friendB[i+1] - 1+1] := 2 ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (a[friendA[i+1] - 1+1] = 2 & a[friendB[i+1] - 1+1] = 0) then ( a[friendB[i+1] - 1+1] := 3 ) else if (a[friendB[i+1] - 1+1] = 2 & a[friendA[i+1] - 1+1] = 0) then ( a[friendA[i+1] - 1+1] := 3 ) else skip ; ) ; i := i + 1 ) ; count := -1 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] /= 0) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; n := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class ThreeFriends { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ long a=sc.nextLong(); long b=sc.nextLong(); long c=sc.nextLong(); long absValue=Math.abs(a-b)+Math.abs(a-c)+Math.abs(b-c); long result=Math.max(absValue-4,0); System.out.println(result); } } } ------------------------------------------------------------ OCL File: --------- class ThreeFriends { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := sc.getCurrent()->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var c : long ; c := sc.getCurrent()->toLong() ; var absValue : long ; absValue := if a - b < 0 then -(a - b) else a - b endif + if a - c < 0 then -(a - c) else a - c endif + if b - c < 0 then -(b - c) else b - c endif ; var result : long ; result := Set{absValue - 4, 0}->max() ; OclFile["System.out"].println(result) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Set ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ int n,m,count=0,i ; int a[]=new int[10000]; int b[]=new int[10000]; Sets=new TreeSet(); Settest=new TreeSet(); Scanner sc=new Scanner(System.in); n=sc.nextInt(); m=sc.nextInt(); while(true){ if(n==0 && m==0)break ; for(i=0 ; icollect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,10000)->collect(0) ; var s : Set(int) ; s := Set{} ; var test : Set(int) ; test := Set{} ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; while (true) do ( if (n = 0 & m = 0) then break else skip ; i := 0 ; while i < m do ( ( a[i+1] := sc.getCurrent()->toInteger() ; b[i+1] := sc.getCurrent()->toInteger() ; if (a[i+1] = 1) then ( count := count + 1 ; s := s->including(b[i+1]) ; test := test->including(b[i+1]) ) else skip ) ; i := i + 1 ) ; i := 0 ; while i < m do ( ( if (s->includes(a[i+1]) & not(test->includes(b[i+1])) & a[i+1] /= 1 & b[i+1] /= 1) then ( count := count + 1 ; test := test->including(b[i+1]) ) else if (not(test->includes(a[i+1])) & s->includes(b[i+1]) & a[i+1] /= 1 & b[i+1] /= 1) then ( count := count + 1 ; test := test->including(a[i+1]) ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; n := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; s := s->intersection(Set{}) ; test := test->intersection(Set{}) ; count := 0 ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { int INF=1<<28 ; int n,m ; LinkedList[] friends ; @ SuppressWarnings("unchecked")void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ n=sc.nextInt(); m=sc.nextInt(); if((n | m)==0)break ; friends=new LinkedList[n]; for(int i=0 ; i(); for(int i=0 ; iset=new HashSet(); for(int a : friends[0]){ set.add(a); for(int b : friends[a])set.add(b); } System.out.println((set.size()==0 ? 0 : set.size()-1)); } } public static void main(String[] args){ new Main().run(); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute n : int; attribute friends : Sequence(Sequence(int)); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( n := sc.getCurrent()->toInteger() ; m := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then break else skip ; friends := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( friends[i+1] := Sequence{} ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( var a : int ; a := sc.getCurrent()->toInteger() - 1 ; var b : int ; b := sc.getCurrent()->toInteger() - 1 ; friends[a+1]->excludes(b) ; friends[b+1]->excludes(a) ) ; i := i + 1 ) ; var set : Set(int) ; set := Set{} ; for (a : friends[0+1]) do ( ( set := set->including(a) ; for (b : friends[a+1]) do ( set := set->including(b) ; ) ) ) ; OclFile["System.out"].println((if set->size() = 0 then 0 else set->size() - 1 endif)) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.nio.charset.MalformedInputException ; import java.util.StringTokenizer ; import java.util.Arrays ; public class Cv { public static void main(String[] args){ FastScanner in=new FastScanner(); Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ String s=sc.next(); out.println(s.length()); } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next(){ while(! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } byte nextByte(){ return Byte.parseByte(next()); } short nextShort(){ return Short.parseShort(next()); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return java.lang.Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } } } ------------------------------------------------------------ OCL File: --------- class Cv { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : FastScanner ; in := FastScanner.newFastScanner() ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var s : String ; s := sc.getCurrent() ; skip ) ; ) ; skip ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); operation nextByte() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextShort() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return java.lang.Long.parseLong(next()) ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication49 { public static void main(String[] args){ Scanner read=new Scanner(System.in); long n=read.nextLong(); while(n--!=0){ String s=read.next(); System.out.println(s.length()); } } } ------------------------------------------------------------ OCL File: --------- class JavaApplication49 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var read : OclFile ; read := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := read.getCurrent()->toLong() ; while (n /= 0) do ( skip ; ( var s : String ; s := read.getCurrent() ; OclFile["System.out"].println(s->size()) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test267 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var a : Sequence(String) ; a := in.getCurrent()->characters() ; OclFile["System.out"].println(a->size()) ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public ListtopKFrequent(int[] nums,int k){ HashMapcount=new HashMap(); for(int n : nums){ count.put(n,count.getOrDefault(n,0)+1); } PriorityQueueheap=new PriorityQueue((n1,n2)->count.get(n1)-count.get(n2)); for(int n : count.keySet()){ heap.add(n); if(heap.size()>k)heap.poll(); } Listtop_k=new LinkedList(); while(! heap.isEmpty())top_k.add(heap.poll()); Collections.reverse(top_k); return top_k ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation topKFrequent( nums : Sequence(int), k : int) : Sequence(int) pre: true post: true activity: ( var count : Map(int,int) ; count := Map{} ; for (n : nums) do ( ( count := count->union(Map{n |-> (if count->keys()->contains(n) then count->at(n) else 0 endif) + 1}) ) ) ; var heap : Sequence(int) ; heap := Sequence{}->union(lambda (n1 , n2) : OclAny in count->at(n1) - count->at(n2)) ; for (n : count->keys()) do ( ( heap := heap->including(n) ; if (heap->size() > k) then heap := heap->sort()->tail() ; else skip ) ) ; var top_k : Sequence(int) ; top_k := Sequence{} ; while (not(heap->isEmpty())) do top_k := top_k->including(heap->min()) ; ; top_k := top_k->reverse() ; return top_k ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class test222 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0 ; ja[i]){ b[i]=a[i]; a[i]=x ; } else { b[i]=x ; } if(b[i]>max){ max=b[i]; } } Arrays.sort(a); System.out.println(max*a[n-1]); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class test222 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() ; if (x > a[i+1]) then ( b[i+1] := a[i+1] ; a[i+1] := x ) else ( b[i+1] := x ) ; if (b[i+1] > max) then ( max := b[i+1] ) else skip ) ; i := i + 1 ) ; a := a->sort() ; OclFile["System.out"].println(max * a[n - 1+1]) ; ) ; j := j + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.HashMap ; import java.util.Map ; class GFG { static String Hex(int num){ HashMapm=new HashMap(); char digit='0' ; char c='a' ; for(int i=0 ; i<=15 ; i++){ if(i<10){ m.put(i,digit); digit++; } else { m.put(i,c); c++; } } String res="" ; if(num==0){ return "0" ; } if(num>0){ while(num!=0){ res=m.get(num % 16)+res ; num/=16 ; } } else { int n=num ; while(n!=0){ res=m.get(n % 16)+res ; n/=16 ; } } return res ; } public static void main(String[] args){ int x=134,y=-1,z=-234 ; System.out.println("Hexa representation for"); System.out.println(x+" is "+Hex(x)); System.out.println(y+" is "+Hex(y)); System.out.println(z+" is "+Hex(z)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Hex( num : int) : String pre: true post: true activity: ( var m : Map(int,String) ; m := Map{} ; var digit : String ; digit := '0' ; var c : String ; c := 'a' ; var i : int ; i := 0 ; while i <= 15 do ( ( if (i < 10) then ( m := m->union(Map{i |-> digit}) ; digit := digit + 1 ) else ( m := m->union(Map{i |-> c}) ; c := c + 1 ) ) ; i := i + 1 ) ; var res : String ; res := "" ; if (num = 0) then ( return "0" ) else skip ; if (num > 0) then ( while (num /= 0) do ( res := m->at(num mod 16) + res ; num := num/(16) ) ) else ( var n : int ; n := num ; while (n /= 0) do ( res := m->at(n mod 16) + res ; n := n/(16) ) ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var x : int ; x := 134 ; var y : int ; y := -1 ; var z : int ; z := -234 ; OclFile["System.out"].println("Hexa representation for") ; OclFile["System.out"].println(x + " is " + Hex(x)) ; OclFile["System.out"].println(y + " is " + Hex(y)) ; OclFile["System.out"].println(z + " is " + Hex(z)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.PriorityQueue ; import java.util.Queue ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); int m=sc.nextInt(); if((n | m)==0)break ; boolean infect[]=new boolean[n+1]; infect[1]=true ; Queueq=new PriorityQueue(); for(int i=0 ; i{ public int s ; public int d ; public int t ; Data(int t,int s,int d){ this.t=t ; this.s=s ; this.d=d ; } public int compareTo(Data a){ return t-a.t ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,m)) = 0) then break else skip ; var infect : Sequence(boolean) ; infect := Integer.subrange(1,n + 1)->collect(false) ; infect[1+1] := true ; var q : Sequence(Data) ; q := Sequence{} ; var i : int ; i := 0 ; while i < m do ( ( var t : int ; t := sc.getCurrent()->toInteger() ; var s : int ; s := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; q := q->including(Data.newData(t, s, d)) ) ; i := i + 1 ) ; while (not(q->isEmpty())) do ( var data : Data ; data := q->min() ; var s : int ; s := data.s ; var d : int ; d := data.d ; if (infect[s+1]) then ( infect[d+1] := true ) else skip ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (infect[i+1]) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } class Data implements Comparable { attribute s : int; attribute d : int; attribute t : int; static operation newData( t : int, s : int, d : int) : Data pre: true post: true activity: ( var self : Data ; self := createData(); self.initialise(t, s,d); return self ); operation initialise( t : int, s : int, d : int) : void pre: true post: true activity: ( self.t := t ; self.s := s ; self.d := d ); operation compareTo( a : Data) : int pre: true post: true activity: ( return t - a.t ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Comparator ; import java.util.PriorityQueue ; import java.util.Queue ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null && ! line.isEmpty()){ int n=parseInt(line.substring(0,line.indexOf(' '))); int m=parseInt(line.substring(line.indexOf(' ')+1)); if((n | m)==0)break ; boolean[] ps=new boolean[n+1]; Queuets=new PriorityQueue(11,new Comparator(){ @ Override public int compare(int[] o1,int[] o2){ return o1[0]-o2[0]; } } ); StringTokenizer st ; for(int i=0 ; iisEmpty())) do ( skip ; ( var n : int ; n := parseInt(line.subrange(0+1,line->indexOf(' ')-1)) ; var m : int ; m := parseInt(line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1)) ; if ((MathLib.bitwiseOr(n,m)) = 0) then break else skip ; var ps : Sequence(boolean) ; ps := Integer.subrange(1,n + 1)->collect(false) ; var ts : Sequence(Sequence(int)) ; ts := Sequence{} ; var st : OclIterator ; var i : int ; i := 0 ; while i < m do ( ( st := OclIterator.newOclIterator_String(br.readLine()) ; var t : int ; var s : int ; var d : int ; t := (st.next() + "")->toInteger() ; s := (st.next() + "")->toInteger() ; d := (st.next() + "")->toInteger() ; ts := ts->including(Sequence{t,s,d}) ; ) ; i := i + 1 ) ; ps[1+1] := true ; var count : int ; count := 1 ; while (not(ts->isEmpty())) do ( var t : Sequence(int) ; t := ts->min() ; if (ps[t[1+1]+1] & not(ps[t[2+1]+1])) then ( ps[t[2+1]+1] := true ; count := count + 1 ) else skip ) ; OclFile["System.out"].println(count) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF709A { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int b=sc.nextInt(); int d=sc.nextInt(); int a,sum=0,count=0 ; while(n-->0){ a=sc.nextInt(); if(a<=b){ sum+=a ; } if(sum>d){ sum=0 ; count++; } } System.out.println(count); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class CF709A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var a : int ; var sum : int ; sum := 0 ; var count : int ; count := 0 ; while (n > 0) do ( n := n - 1 ; skip ; ( a := sc.getCurrent()->toInteger() ; if (a <= b) then ( sum := sum+(a) ) else skip ; if (sum > d) then ( sum := 0 ; count := count + 1 ) else skip ) ; ) ; OclFile["System.out"].println(count) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; class Main { public static Scanner sc=new Scanner(in); public static Random rand=new Random(); class Packet { int t ; int from ; int to ; Packet(int t,int from,int to){ this.t=t ; this.from=from ; this.to=to ; } } public void run(){ while(true){ int N=sc.nextInt(),M=sc.nextInt(); if(N==0)return ; Packet[] ps=new Packet[M]; for(int i=0 ; i(){ @ Override public int compare(Packet o1,Packet o2){ return o1.t-o2.t ; } } ); boolean[] infected=new boolean[N]; infected[0]=true ; for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; if (N = 0) then return else skip ; var ps : Sequence(Packet) ; ps := Integer.subrange(1,M)->collect(null) ; var i : int ; i := 0 ; while i < M do ( ( ps[i+1] := Packet.newPacket(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger() - 1, sc.getCurrent()->toInteger() - 1) ) ; i := i + 1 ) ; ps := OclComparator.sortWith(ps, OclComparator.newOclComparator()) ; var infected : Sequence(boolean) ; infected := Integer.subrange(1,N)->collect(false) ; infected[0+1] := true ; var i : int ; i := 0 ; while i < M do ( ( if (infected[ps[i+1].from+1]) then infected[ps[i+1].to+1] := true ; else skip ) ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (infected[i+1]) then res := res + 1 ; else skip ) ; i := i + 1 ) ; execute ln(res) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( res[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; return res ); static operation pr( o : OclAny) : void pre: true post: true activity: ( out.print(o) ); static operation ln( o : OclAny) : void pre: true post: true activity: ( out.println(o) ); static operation ln() : void pre: true post: true activity: ( out.println() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.TreeSet ; public class Main { Scanner sc ; Main(){ sc=new Scanner(System.in); } class com implements Comparable{ int t ; int s ; int d ; public int compareTo(com tar){ return t-tar.t ; } com(int t,int s,int d){ this.t=t ; this.s=s ; this.d=d ; } } public void run(){ for(; ; ){ int n=sc.nextInt(); int m=sc.nextInt(); if(n==0){ break ; } TreeSethl=new TreeSet(); com[] arr=new com[m]; for(int i=0 ; i { attribute t : int; attribute s : int; attribute d : int; operation compareTo( tar : com) : int pre: true post: true activity: ( return t - tar.t ); static operation newcom( t : int, s : int, d : int) : com pre: true post: true activity: ( var self : com ; self := createcom(); self.initialise(t, s,d); return self ); operation initialise( t : int, s : int, d : int) : void pre: true post: true activity: ( self.t := t ; self.s := s ; self.d := d ); } operation run() : void pre: true post: true activity: ( while true do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; if (n = 0) then ( break ) else skip ; var hl : Set(int) ; hl := Set{} ; var arr : Sequence(com) ; arr := Integer.subrange(1,m)->collect(null) ; var i : int ; i := 0 ; while i < m do ( ( var a : com ; a := com.newcom(sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger(), sc.getCurrent()->toInteger()) ; arr[i+1] := a ) ; i := i + 1 ) ; arr := arr->sort() ; hl := hl->including(1) ; for (c : arr) do ( ( var s : int ; s := c.s ; var d : int ; d := c.d ; if (hl->includes(s)) then ( hl := hl->including(d) ) else skip ) ) ; OclFile["System.out"].println(hl->size()) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : Main ; m := Main.newMain() ; m.run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void sort(String a[],int n){ for(int i=0 ; i0){ String s=a[i]; a[i]=a[j]; a[j]=s ; } } } } static String lexsmallest(String a[],int n){ sort(a,n); String answer="" ; for(int i=0 ; icollect(null) ; var i : int ; i := 1 ; while i < 28 do ( S[i+1] := sc.getCurrent() ; ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() mod 3 ; var n : int ; n := sc.getCurrent()->toInteger() mod 3 ; m := if m = 0 then 3 else m endif ; n := if n = 0 then 3 else n endif ; m := (m - 1) * 9 + n ; if (S[m+1]->includes(".") or S[m + 3+1]->includes(".") or S[m + 6+1]->includes(".")) then ( S[m+1] := S[m+1].replace(".", "!") ; S[m + 3+1] := S[m + 3+1].replace(".", "!") ; S[m + 6+1] := S[m + 6+1].replace(".", "!") ) else ( var i : int ; i := 1 ; while i < 28 do ( S[i+1] := S[i+1].replace(".", "!") ; ; i := i + 1 ) ) ; execute out(S) ; ); static operation out( S : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < 28 do ( ( OclFile["System.out"].print(S[i+1] + " ") ; if ((i + 1) mod 3 = 1) then OclFile["System.out"].println("") ; else skip ; if ((i + 1) mod 9 = 1) then OclFile["System.out"].println("") ; else skip ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class first { public static void main(String Args[]){ Scanner sc=new Scanner(System.in); int n ; n=sc.nextInt(); int arr[]=new int[n]; for(int i=0 ; i=0 ; j--){ if(arr[j]==0){ System.out.print(j+1); System.exit(0); } } } else { for(int j=n-2 ; j>=0 ; j--){ if(arr[j]==1){ System.out.print(j+1); System.exit(0); } } } } } ------------------------------------------------------------ OCL File: --------- class first { static operation main( Args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (arr[n - 1+1] = 1) then ( var j : int ; j := n - 2 ; while j >= 0 do ( ( if (arr[j+1] = 0) then ( OclFile["System.out"].print(j + 1) ; OclProcess.exit(0) ) else skip ) ; j := j - 1 ) ) else ( var j : int ; j := n - 2 ; while j >= 0 do ( ( if (arr[j+1] = 1) then ( OclFile["System.out"].print(j + 1) ; OclProcess.exit(0) ) else skip ) ; j := j - 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.Integer.parseInt ; public class _1631A_MinMaxSwap { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=parseInt(input.nextLine()); while(test-->0){ int len=parseInt(input.nextLine()); ListfirstArray=new ArrayList<>(); ListsecondArray=new ArrayList<>(); for(int i=0 ; ibiggerArray=getMaxArray(firstArray,secondArray); ListsmallerArray=firstArray==biggerArray ? secondArray : firstArray ; int maxValue=Collections.max(biggerArray); int maxIndex=biggerArray.indexOf(maxValue); for(int i=0 ; ifirstElement){ smallerArray.set(i,firstElement); } } int result=maxValue*Collections.max(smallerArray); System.out.println(result); } } private static ListgetMaxArray(ListfirstArray,ListsecondArray){ int first=Collections.max(firstArray); int second=Collections.max(secondArray); if(first>second){ return firstArray ; } return secondArray ; } } ------------------------------------------------------------ OCL File: --------- class _1631A_MinMaxSwap { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := parseInt(input.nextLine()) ; while (test > 0) do ( test := test - 1 ; skip ; ( var len : int ; len := parseInt(input.nextLine()) ; var firstArray : Sequence(int) ; firstArray := Sequence{} ; var secondArray : Sequence(int) ; secondArray := Sequence{} ; var i : int ; i := 0 ; while i < len do ( ( firstArray := firstArray->including(input.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < len do ( ( secondArray := secondArray->including(input.getCurrent()->toInteger()) ) ; i := i + 1 ) ; skip ; var biggerArray : Sequence(int) ; biggerArray := getMaxArray(firstArray, secondArray) ; var smallerArray : Sequence(int) ; smallerArray := if firstArray = biggerArray then secondArray else firstArray endif ; var maxValue : int ; maxValue := .max(biggerArray) ; var maxIndex : int ; maxIndex := biggerArray->indexOf(maxValue)-1 ; var i : int ; i := 0 ; while i < len do ( ( var firstElement : int ; firstElement := biggerArray->at(i+1) ; var secondElement : int ; secondElement := smallerArray->at(i+1) ; if (i /= maxIndex & secondElement > firstElement) then ( smallerArray := smallerArray.setAt(i+1,firstElement) ) else skip ) ; i := i + 1 ) ; var result : int ; result := maxValue * .max(smallerArray) ; OclFile["System.out"].println(result) ; ) ; ) ); static operation getMaxArray( firstArray : Sequence(int), secondArray : Sequence(int)) : Sequence(int) pre: true post: true activity: ( var first : int ; first := .max(firstArray) ; var second : int ; second := .max(secondArray) ; if (first > second) then ( return firstArray ) else skip ; return secondArray ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import java.util.*; public class Main { public static int ans(int arr[],int z,int o,int n){ for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,t)->collect(0) ; var z : int ; z := 0 ; var o : int ; o := 0 ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < t do ( ( arr[i+1] := (st.next())->toInteger() ; if (arr[i+1] = 1) then o := o + 1 ; else z := z + 1 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans(arr, z, o, t)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Integer.min ; import java.util.Scanner ; public class Main { public static void main(String[] args){ int n,a[]=new int[200000],s=0,m=0 ; Scanner in=new Scanner(System.in); n=in.nextInt(); for(int i=0 ; i=0 ; i--){ if(a[i]==0){ s=i+1 ; break ; } } for(int i=n-1 ; i>=0 ; i--){ if(a[i]==1){ m=i+1 ; break ; } } System.out.println(min(s,m)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; var a : Sequence(void) ; a := Integer.subrange(1,200000)->collect(0) ; var s : int ; s := 0 ; var m : int ; m := 0 ; var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (a[i+1] = 0) then ( s := i + 1 ; break ) else skip ) ; i := i - 1 ) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( if (a[i+1] = 1) then ( m := i + 1 ; break ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(Set{s, m}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(int i=0 ; ; i++){ String[] s=br.readLine().split(" "); int a=Integer.parseInt(s[0]); char[] op=s[1] .toCharArray(); int b=Integer.parseInt(s[2]); if(op[0]=='?'){ break ; } else if(op[0]=='+'){ System.out.println(a+b); } else if(op[0]=='-'){ System.out.println(a-b); } else if(op[0]=='*'){ System.out.println(a*b); } else if(op[0]=='/'){ System.out.println(a/b); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var i : int ; i := 0 ; while true do ( ( var s : Sequence(String) ; s := br.readLine()->split(" ") ; var a : int ; a := (s[0+1])->toInteger() ; var op : Sequence(String) ; op := s[1+1]->characters() ; var b : int ; b := (s[2+1])->toInteger() ; if (op[0+1] = '?') then ( break ) else if (op[0+1] = '+') then ( OclFile["System.out"].println(a + b) ) else if (op[0+1] = '-') then ( OclFile["System.out"].println(a - b) ) else if (op[0+1] = '*') then ( OclFile["System.out"].println(a * b) ) else if (op[0+1] = '/') then ( OclFile["System.out"].println(a / b) ) else skip ; ; ; ; ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Doors { public static void main(String[] args){ Scanner in=new Scanner(System.in); int amount=in.nextInt(); int last1=1 ; int last0=1 ; for(int i=0 ; itoInteger() ; var last1 : int ; last1 := 1 ; var last0 : int ; last0 := 1 ; var i : int ; i := 0 ; while i < amount do ( ( var num : int ; num := in.getCurrent()->toInteger() ; if (num = 0) then ( last0 := i + 1 ) else ( last1 := i + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(Set{last0, last1}->min()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Sleep { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int H=sc.nextInt(); int M=sc.nextInt(); int min=H*60+M ; int ans=Integer.MAX_VALUE ; int ans1=Integer.MAX_VALUE ; int ans2=Integer.MAX_VALUE ; for(int i=0 ; i=0){ ans1=Integer.min(temp-min,ans1); } else { ans2=Integer.min(temp-min,ans2); } } if(ans1!=Integer.MAX_VALUE){ System.out.println(ans1/60+" "+ans1 % 60); } else { ans2=1440+ans2 ; System.out.println(ans2/60+" "+ans2 % 60); } } } } ------------------------------------------------------------ OCL File: --------- class Sleep { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var H : int ; H := sc.getCurrent()->toInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var min : int ; min := H * 60 + M ; var ans : int ; ans := 2147483647 ; var ans1 : int ; ans1 := 2147483647 ; var ans2 : int ; ans2 := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( var h : int ; h := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var temp : int ; temp := h * 60 + m ; ans := temp - min ; if (ans >= 0) then ( ans1 := Set{temp - min, ans1}->min() ) else ( ans2 := Set{temp - min, ans2}->min() ) ; ) ; i := i + 1 ) ; if (ans1 /= 2147483647) then ( OclFile["System.out"].println(ans1 / 60 + " " + ans1 mod 60) ) else ( ans2 := 1440 + ans2 ; OclFile["System.out"].println(ans2 / 60 + " " + ans2 mod 60) ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class class11 { public static void main(String arg[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int h=sc.nextInt(); int m=sc.nextInt(); int i,min=1000000,tot=h*60+m ; for(i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var i : int ; var min : int ; min := 1000000 ; var tot : int ; tot := h * 60 + m ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var t2 : int ; t2 := x * 60 + y ; var diff : int ; diff := t2 - tot ; if (diff < 0) then diff := diff+(1440) ; else skip ; min := Set{diff, min}->min() ; ) ; i := i + 1 ) ; var ans1 : int ; ans1 := min / 60 ; var ans2 : int ; ans2 := min - ans1 * 60 ; OclFile["System.out"].println(ans1 + " " + ans2) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class EveryoneLikeSleeping { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int numberOfSets=scan.nextInt(); for(int i=0 ; isleepingArrayMinutes=new LinkedList<>(); for(int x=0 ; xtoInteger() ; var i : int ; i := 0 ; while i < numberOfSets do ( ( var sleepingHours : int ; sleepingHours := 1000 ; var sleepingMinutes : int ; sleepingMinutes := 1000 ; var numberOfAlarms : int ; numberOfAlarms := scan.getCurrent()->toInteger() ; var sleepHours : int ; sleepHours := scan.getCurrent()->toInteger() ; var sleepMinutes : int ; sleepMinutes := scan.getCurrent()->toInteger() ; sleepMinutes := sleepMinutes+(sleepHours * 60) ; var sleepingArrayMinutes : Sequence(int) ; sleepingArrayMinutes := Sequence{} ; var x : int ; x := 0 ; while x < numberOfAlarms do ( ( var h : int ; h := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; m := m+(h * 60) ; if (sleepMinutes <= m) then ( sleepingMinutes := m - sleepMinutes ) else ( sleepingMinutes := 1440 - sleepMinutes + m ) ; sleepingArrayMinutes := sleepingArrayMinutes->including(sleepingMinutes) ; ) ; x := x + 1 ) ; var min : int ; min := .min(sleepingArrayMinutes) ; OclFile["System.out"].println(min / 60 + " " + min mod 60) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class EveryoneLikeSleeping { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int numberOfSets=scan.nextInt(); for(int i=0 ; isleepingArrayMinutes=new ArrayList<>(); for(int x=0 ; xtoInteger() ; var i : int ; i := 0 ; while i < numberOfSets do ( ( var sleepingHours : int ; sleepingHours := 1000 ; var sleepingMinutes : int ; sleepingMinutes := 1000 ; var numberOfAlarms : int ; numberOfAlarms := scan.getCurrent()->toInteger() ; var sleepHours : int ; sleepHours := scan.getCurrent()->toInteger() ; var sleepMinutes : int ; sleepMinutes := scan.getCurrent()->toInteger() ; sleepMinutes := sleepMinutes+(sleepHours * 60) ; var sleepingArrayMinutes : Sequence(int) ; sleepingArrayMinutes := Sequence{} ; var x : int ; x := 0 ; while x < numberOfAlarms do ( ( var h : int ; h := scan.getCurrent()->toInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; m := m+(h * 60) ; if (sleepMinutes <= m) then ( sleepingMinutes := m - sleepMinutes ) else ( sleepingMinutes := 1440 - sleepMinutes + m ) ; sleepingArrayMinutes := sleepingArrayMinutes->including(sleepingMinutes) ; ) ; x := x + 1 ) ; var min : int ; min := .min(sleepingArrayMinutes) ; OclFile["System.out"].println(min / 60 + " " + min mod 60) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Map ; import java.util.Scanner ; import java.util.Vector ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); Integer numberOfTests=scanner.nextInt(); while(numberOfTests-->0){ Integer numberOfAlarms=scanner.nextInt(); Integer vladHourSleep=scanner.nextInt(); Integer vladMinSleep=scanner.nextInt(); Integer totalVladMinutes=vladHourSleep*60+vladMinSleep ; Integer minDifference=Integer.MAX_VALUE ; while(numberOfAlarms-->0){ Integer alarmHour=scanner.nextInt(); Integer alarmMin=scanner.nextInt(); Integer totalAlarmMinutes=alarmHour*60+alarmMin ; Integer difference=totalAlarmMinutes-totalVladMinutes ; if(difference<0)difference+=1440 ; minDifference=Math.min(minDifference,difference); } Integer ans1=minDifference/60 ; int ans2=minDifference-ans1*60 ; System.out.println(ans1+" "+ans2); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numberOfTests : int ; numberOfTests := scanner.getCurrent()->toInteger() ; while (numberOfTests > 0) do ( numberOfTests := numberOfTests - 1 ; skip ; ( var numberOfAlarms : int ; numberOfAlarms := scanner.getCurrent()->toInteger() ; var vladHourSleep : int ; vladHourSleep := scanner.getCurrent()->toInteger() ; var vladMinSleep : int ; vladMinSleep := scanner.getCurrent()->toInteger() ; var totalVladMinutes : int ; totalVladMinutes := vladHourSleep * 60 + vladMinSleep ; var minDifference : int ; minDifference := 2147483647 ; while (numberOfAlarms > 0) do ( numberOfAlarms := numberOfAlarms - 1 ; skip ; ( var alarmHour : int ; alarmHour := scanner.getCurrent()->toInteger() ; var alarmMin : int ; alarmMin := scanner.getCurrent()->toInteger() ; var totalAlarmMinutes : int ; totalAlarmMinutes := alarmHour * 60 + alarmMin ; var difference : int ; difference := totalAlarmMinutes - totalVladMinutes ; if (difference < 0) then difference := difference+(1440) ; else skip ; minDifference := Set{minDifference, difference}->min() ; ) ; ) ; var ans1 : int ; ans1 := minDifference / 60 ; var ans2 : int ; ans2 := minDifference - ans1 * 60 ; OclFile["System.out"].println(ans1 + " " + ans2) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ while(sc.hasNext()){ int e=sc.nextInt(); if(e==0)break ; int min=Integer.MAX_VALUE ; for(int z=0 ; z<1000000 ; z++){ if(z>e)break ; for(int y=0 ; y<=1000000 ; y++){ if(z*z*z+y*y>e || min<=z+y)break ; int x=e-y*y-z*z*z ; min=Math.min(x+y+z,min); } } System.out.println(min); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while (sc.hasNext()) do ( var e : int ; e := sc.getCurrent()->toInteger() ; if (e = 0) then break else skip ; var min : int ; min := 2147483647 ; var z : int ; z := 0 ; while z < 1000000 do ( ( if (z > e) then break else skip ; var y : int ; y := 0 ; while y <= 1000000 do ( ( if (z * z * z + y * y > e or min <= z + y) then break else skip ; var x : int ; x := e - y * y - z * z * z ; min := Set{x + y + z, min}->min() ) ; y := y + 1 ) ) ; z := z + 1 ) ; OclFile["System.out"].println(min) ; ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int x,e,i,j,m ; for(; ; ){ e=sc.nextInt(); if(e==0)break ; m=e ; for(i=0 ; i*i*i<=e ; i++)for(j=0 ; j*j<=e ; j++)if(i*i*i+j*j<=e){ x=e-(i*i*i+j*j); if(m>x+j+i)m=x+j+i ; } out.println(m); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var x : int ; var e : int ; var i : int ; var j : int ; var m : int ; while true do ( ( e := sc.nextInt() ; if (e = 0) then break else skip ; m := e ; i := 0 ; while i * i * i <= e do ( j := 0 ; while j * j <= e do ( if (i * i * i + j * j <= e) then ( x := e - (i * i * i + j * j) ; if (m > x + j + i) then m := x + j + i ; else skip ) else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; out.println(m) ; ) ) ; sc.close() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Tower { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int top=sc.nextInt(); int k=7-top ; boolean check=true ; for(int i=1 ; i<=n ; i++){ int l=sc.nextInt(); int r=sc.nextInt(); if(l==k || l==top || r==k || r==top){ check=false ; break ; } } System.out.println(check ? "YES" : "NO"); } } ------------------------------------------------------------ OCL File: --------- class Tower { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var top : int ; top := sc.getCurrent()->toInteger() ; var k : int ; k := 7 - top ; var check : boolean ; check := true ; var i : int ; i := 1 ; while i <= n do ( ( var l : int ; l := sc.getCurrent()->toInteger() ; var r : int ; r := sc.getCurrent()->toInteger() ; if (l = k or l = top or r = k or r = top) then ( check := false ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(if check then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class codeforce { public static void main(String[] args){ Scanner css=new Scanner(System.in); int t=css.nextInt(); while(t-->0){ int n=css.nextInt(); int[] arr1=new int[n]; int[] arr2=new int[n]; for(int i=0 ; iarr2[i]){ int temp=arr1[i]; arr1[i]=arr2[i]; arr2[i]=temp ; } } int max1=arr1[0]; int max2=arr2[0]; for(int i=1 ; imax1){ max1=arr1[i]; } if(arr2[i]>max2){ max2=arr2[i]; } } System.out.println(max1*max2); } } } ------------------------------------------------------------ OCL File: --------- class codeforce { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var css : OclFile ; css := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := css.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := css.getCurrent()->toInteger() ; var arr1 : Sequence(int) ; arr1 := Integer.subrange(1,n)->collect(0) ; var arr2 : Sequence(int) ; arr2 := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr1[i+1] := css.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( arr2[i+1] := css.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (arr1[i+1] > arr2[i+1]) then ( var temp : int ; temp := arr1[i+1] ; arr1[i+1] := arr2[i+1] ; arr2[i+1] := temp ) else skip ) ; i := i + 1 ) ; var max1 : int ; max1 := arr1[0+1] ; var max2 : int ; max2 := arr2[0+1] ; var i : int ; i := 1 ; while i < n do ( ( if (arr1[i+1] > max1) then ( max1 := arr1[i+1] ) else skip ; if (arr2[i+1] > max2) then ( max2 := arr2[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max1 * max2) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Juicer { static Scanner sc=new Scanner(System.in); public static void main(String args[])throws IOException { int n=sc.nextInt(); int b=sc.nextInt(); int d=sc.nextInt(); int sum=0 ; int counter=0 ; while(n-->0){ int orange=sc.nextInt(); if(orange>b)continue ; sum+=orange ; if(sum>d){ counter++; sum=0 ; } } System.out.println(counter); } } ------------------------------------------------------------ OCL File: --------- class Juicer { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var sum : int ; sum := 0 ; var counter : int ; counter := 0 ; while (n > 0) do ( n := n - 1 ; skip ; ( var orange : int ; orange := sc.getCurrent()->toInteger() ; if (orange > b) then continue else skip ; sum := sum+(orange) ; if (sum > d) then ( counter := counter + 1 ; sum := 0 ) else skip ) ; ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { int x=0 ; int y=0 ; int z=0 ; int[] m=new int[10000]; int temp_m ; int count ; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(count=0 ; count>=0 ; count++){ String str=br.readLine(); int e=Integer.parseInt(str); if(e==0){ break ; } m[count]=e ; for(int tempz=0 ; tempz*tempz*tempz<=e ; tempz++){ z=tempz ; } for(int i=0 ; z>=0 ; i++){ for(int tempy=0 ; tempy*tempy<=e-z*z*z ; tempy++){ y=tempy ; } x=e-z*z*z-y*y ; temp_m=x+y+z ; if(temp_mcollect(0) ; var temp_m : int ; var count : int ; var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; count := 0 ; while count >= 0 do ( ( var str : String ; str := br.readLine() ; var e : int ; e := (str)->toInteger() ; if (e = 0) then ( break ) else skip ; m[count+1] := e ; var tempz : int ; tempz := 0 ; while tempz * tempz * tempz <= e do ( ( z := tempz ) ; tempz := tempz + 1 ) ; var i : int ; i := 0 ; while z >= 0 do ( ( var tempy : int ; tempy := 0 ; while tempy * tempy <= (e)->char2byte() - z * z * z do ( ( y := tempy ) ; tempy := tempy + 1 ) ; x := (e)->char2byte() - z * z * z - y * y ; temp_m := x + y + z ; if (temp_m < m[count+1]) then ( m[count+1] := temp_m ) else skip ; z := z - 1 ; ) ; i := i + 1 ) ; ) ; count := count + 1 ) ; var i : int ; i := 0 ; while i < count do ( ( OclFile["System.out"].println(m[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { void run(){ Scanner sc=new Scanner(System.in); boolean[] Z=new boolean[1000001]; int[] z=new int[1000001]; for(int i=0 ; i<=100 ; i++){ Z[i*i*i]=true ; z[i*i*i]=i ; } for(; ; ){ int e=sc.nextInt(); if(e==0)break ; int res=1<<29 ; for(int x=0 ; x<=1000000 ; x++){ if(res<=x)break ; for(int y=0 ; y<=1000000 ; y++){ if(res<=x+y || ecollect(false) ; var z : Sequence(int) ; z := Integer.subrange(1,1000001)->collect(0) ; var i : int ; i := 0 ; while i <= 100 do ( ( Z[i * i * i+1] := true ; z[i * i * i+1] := i ) ; i := i + 1 ) ; while true do ( ( var e : int ; e := sc.getCurrent()->toInteger() ; if (e = 0) then break else skip ; var res : int ; res := (1*(2->pow(29)))->oclAsType(long) ; var x : int ; x := 0 ; while x <= 1000000 do ( ( if (res <= x) then break else skip ; var y : int ; y := 0 ; while y <= 1000000 do ( ( if (res <= x + y or e < x + y * y) then break else skip ; if (not(Z[e - x - y * y+1])) then continue else skip ; res := Set{res, x + y + z[e - x - y * y+1]}->min() ) ; y := y + 1 ) ) ; x := x + 1 ) ; OclFile["System.out"].println(res) ; ) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Math.*; public class Main { int INF=1<<28 ; double EPS=1e-10 ; void run(){ Scanner sc=new Scanner(System.in); for(; ; ){ int e=sc.nextInt(); if(e==0)break ; int c=(int)cbrt(e),min=e ; for(int z=0 ; z<=c ; z++){ int s=(int)sqrt(e-z*z*z); for(int y=0 ; y<=s ; y++){ int x=e-y*y-z*z*z ; min=min(min,x+y+z); } } System.out.println(min); } } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute EPS : double := 1e-10; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var e : int ; e := sc.getCurrent()->toInteger() ; if (e = 0) then break else skip ; var c : int ; c := cbrt(e)->oclAsType(int) ; var min : int ; min := e ; var z : int ; z := 0 ; while z <= c do ( ( var s : int ; s := sqrt(e - z * z * z)->oclAsType(int) ; var y : int ; y := 0 ; while y <= s do ( ( var x : int ; x := e - y * y - z * z * z ; min := Set{min, x + y + z}->min() ) ; y := y + 1 ) ) ; z := z + 1 ) ; OclFile["System.out"].println(min) ; ) ) ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.*; class Main { Scanner sc ; int N,M ; String S ; Dequed ; private void calc(){ sc=new Scanner(System.in); N=sc.nextInt(); M=sc.nextInt(); S=sc.next(); d=new ArrayDeque<>(); int p=N ; while(p>0){ int dice=Math.min(M,p); while(true){ if(dice==0 || p-dice<0){ dice=-1 ; break ; } if(S.charAt(p-dice)=='0')break ; dice--; } if(dice==-1)break ; p-=dice ; d.addFirst(dice); } if(p>0)System.out.println(-1); else { System.out.println(d.stream().map(n->String.valueOf(n)).collect(Collectors.joining(" "))); } } public static void main(String[] args){ new Main().calc(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; attribute N : int; attribute S : String; attribute d : Sequence(int); operation calc() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := sc.getCurrent()->toInteger() ; M := sc.getCurrent()->toInteger() ; S := sc.getCurrent() ; d := ArrayDeque.newArrayDeque() ; var p : int ; p := N ; while (p > 0) do ( var dice : int ; dice := Set{M, p}->min() ; while (true) do ( if (dice = 0 or p - dice < 0) then ( dice := -1 ; break ) else skip ; if (S->at(p - dice+1) = '0') then break else skip ; dice := dice - 1 ) ; if (dice = -1) then break else skip ; p := p-(dice) ; d := d->prepend(dice) ; ) ; if (p > 0) then OclFile["System.out"].println(-1) else ( OclFile["System.out"].println(d->collect( _x1 | (lambda n : OclAny in ((n) + ""))->apply(_x1) ).collect(Collectors.joining(" "))) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().calc() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); char[] arr=sc.next().toCharArray(); int max=0 ; int count=0 ; for(char c : arr){ if(c=='1'){ count++; max=Math.max(max,count); } else { count=0 ; } } if(max>=m){ System.out.println(-1); return ; } ArrayDequestack=new ArrayDeque<>(); int idx=n ; while(idx>0){ int next=Math.max(idx-m,0); while(arr[next]=='1'){ next++; } stack.push(idx-next); idx=next ; } boolean isFirst=true ; StringBuilder sb=new StringBuilder(); while(stack.size()>0){ if(! isFirst){ sb.append(" "); } sb.append(stack.pop()); isFirst=false ; } System.out.println(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var arr : Sequence(String) ; arr := sc.getCurrent()->characters() ; var max : int ; max := 0 ; var count : int ; count := 0 ; for (c : arr) do ( ( if (c = '1') then ( count := count + 1 ; max := Set{max, count}->max() ) else ( count := 0 ) ) ) ; if (max >= m) then ( OclFile["System.out"].println(-1) ; return ) else skip ; var stack : Sequence(int) ; stack := ArrayDeque.newArrayDeque() ; var idx : int ; idx := n ; while (idx > 0) do ( var next : int ; next := Set{idx - m, 0}->max() ; while (arr[next+1] = '1') do ( next := next + 1 ) ; stack := stack->append(idx - next) ; idx := next ) ; var isFirst : boolean ; isFirst := true ; var sb : String ; sb := StringLib.newString() ; while (stack->size() > 0) do ( if (not(isFirst)) then ( sb := sb + StringLib.newString(" ") ) else skip ; sb := sb + StringLib.newString(stack->last()) ; isFirst := false ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Main { PrintWriter out=new PrintWriter(System.out); BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok=new StringTokenizer(""); String next()throws IOException { if(! tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } int ni()throws IOException { return Integer.parseInt(next()); } long nl()throws IOException { return Long.parseLong(next()); } void solve()throws IOException { int n=ni(),m=ni(); String s=next(); int[] A=new int[n+1]; for(int x=0 ; x<=n ; x++){ if(s.charAt(x)=='1')A[x]=1 ; } int c=0 ; int[] B=new int[n+10]; int p=n ; boolean f=false ; outer : while(true){ int newp=p-m ; if(newp<=0){ B[c]=p ; break ; } while(A[newp]==1){ newp++; if(newp==p){ f=true ; break outer ; } } B[c]=p-newp ; c++; p=newp ; } if(f)out.println("-1"); else { for(int x=c ; x>=0 ; x--)out.print(B[x]+" "); out.println(); } out.flush(); } public static void main(String[] args)throws IOException { new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); attribute in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute tok : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( if (not(tok.hasNext())) then ( tok := OclIterator.newOclIterator_String(in.readLine()) ) else skip ; return tok.next() ); operation ni() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nl() : long pre: true post: true activity: ( return (next())->toLong() ); operation solve() : void pre: true post: true activity: ( var n : int ; n := ni() ; var m : int ; m := ni() ; var s : String ; s := next() ; var A : Sequence(int) ; A := Integer.subrange(1,n + 1)->collect(0) ; var x : int ; x := 0 ; while x <= n do ( ( if (s->at(x+1) = '1') then A[x+1] := 1 ; else skip ) ; x := x + 1 ) ; var c : int ; c := 0 ; var B : Sequence(int) ; B := Integer.subrange(1,n + 10)->collect(0) ; var p : int ; p := n ; var f : boolean ; f := false ; while (true) do ( var newp : int ; newp := p - m ; if (newp <= 0) then ( B[c+1] := p ; break ) else skip ; while (A[newp+1] = 1) do ( newp := newp + 1 ; if (newp = p) then ( f := true ; break ) else skip ) ; B[c+1] := p - newp ; c := c + 1 ; p := newp ; ) ; if (f) then skip else ( var x : int ; x := c ; while x >= 0 do ( skip ; ; x := x - 1 ) ; skip ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); sc.nextLine(); String s=sc.nextLine(); int[] dp=new int[n+1]; Arrays.fill(dp,Integer.MAX_VALUE); dp[n]=0 ; Queueq=new LinkedList<>(); q.offer(0); for(int i=n-1 ; i>=0 ; i--){ while(true){ if(q.size()==0){ System.out.println(-1); return ; } if(q.peek()!=Integer.MAX_VALUE && q.size()<=m)break ; q.poll(); } if(s.charAt(i)=='0')dp[i]=q.peek()+1 ; q.offer(dp[i]); } Listansweer=new ArrayList<>(); int x=0 ; int rest=dp[0]; while(xtoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; skip ; var s : String ; s := sc.nextLine() ; var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp := dp->collect(2147483647) ; dp[n+1] := 0 ; var q : Sequence(int) ; q := Sequence{} ; q := q->including(0) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( while (true) do ( if (q->size() = 0) then ( OclFile["System.out"].println(-1) ; return ) else skip ; if (q->min() /= 2147483647 & q->size() <= m) then break else skip ; q := q->sort()->tail() ) ; if (s->at(i+1) = '0') then dp[i+1] := q->min() + 1 ; else skip ; q := q->including(dp[i+1]) ) ; i := i - 1 ) ; var answeer : Sequence(int) ; answeer := Sequence{} ; var x : int ; x := 0 ; var rest : int ; rest := dp[0+1] ; while (x < n) do ( rest := rest - 1 ; var i : int ; i := 1 ; while (dp[x + i+1] /= rest) do i := i + 1 ; ; answeer := answeer->including(i) ; x := x+(i) ; ) ; var i : int ; i := 0 ; while i < answeer->size() do ( ( OclFile["System.out"].print(answeer->at(i+1)) ; OclFile["System.out"].print(" ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); int M=Integer.parseInt(sc.next()); String S=sc.next(); char[] c=S.toCharArray(); ArrayListans=new ArrayList(); int i=N ; int flag=0 ; loop : while(i>=0){ for(int j=M ; j>=1 ; j--){ if(i-j<0)continue ; if(c[i-j]=='0'){ i-=j ; ans.add(j); break ; } if(j==1){ flag=1 ; break loop ; } } if(i==0)break ; } if(flag==1){ System.out.println(-1); } else { for(int j=ans.size()-1 ; j>=0 ; j--){ System.out.println(ans.get(j)); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := (sc.getCurrent())->toInteger() ; var M : int ; M := (sc.getCurrent())->toInteger() ; var S : String ; S := sc.getCurrent() ; var c : Sequence(String) ; c := S->characters() ; var ans : Sequence(int) ; ans := Sequence{} ; var i : int ; i := N ; var flag : int ; flag := 0 ; while (i >= 0) do ( var j : int ; j := M ; while j >= 1 do ( ( if (i - j < 0) then continue else skip ; if (c[i - j+1] = '0') then ( i := i-(j) ; ans := ans->including(j) ; break ) else skip ; if (j = 1) then ( flag := 1 ; break ) else skip ) ; j := j - 1 ) ; if (i = 0) then break else skip ) ; if (flag = 1) then ( OclFile["System.out"].println(-1) ) else ( var j : int ; j := ans->size() - 1 ; while j >= 0 do ( ( OclFile["System.out"].println(ans->at(j+1)) ) ; j := j - 1 ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static long p=1_000_000_007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); if((2*y-x)% 3!=0 ||(2*x-y)% 3!=0 || Math.max(x,y)>Math.min(x,y)*2){ System.out.println(0); return ; } int s=(2*y-x)/3 ; int t=(2*x-y)/3 ; long z=(long)s+t ; long A=1 ; long B=1 ; for(int i=0 ; itoInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if ((2 * y - x) mod 3 /= 0 or (2 * x - y) mod 3 /= 0 or Set{x, y}->max() > Set{x, y}->min() * 2) then ( OclFile["System.out"].println(0) ; return ) else skip ; var s : int ; s := (2 * y - x) / 3 ; var t : int ; t := (2 * x - y) / 3 ; var z : long ; z := s->oclAsType(long) + t ; var A : long ; A := 1 ; var B : long ; B := 1 ; var i : int ; i := 0 ; while i < s do ( ( A := A*((z - i)) ; A := A mod p ; B := B*((s - i)) ; B := B mod p ) ; i := i + 1 ) ; OclFile["System.out"].println(A * inv(B, p - 2) mod p) ; ); static operation inv( n : long, k : long) : long pre: true post: true activity: ( if (k = 0) then ( return 1 ) else skip ; if (k mod 2 = 0) then ( var l : long ; l := inv(n, k / 2) ; return l * l mod p ) else ( return n * inv(n, k - 1) mod p ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final int MOD=1000000007 ; public static void main(String[] args){ var sc=new Scanner(System.in); var x=sc.nextInt(); var y=sc.nextInt(); sc.close(); var a=(x+y)/3 ; var b=Math.min(x,y)-a ; if((x+y)% 3==0 && b>=0){ var modCalc=new Main().new ModCalc(MOD); var result=modCalc.combine(a,b); System.out.println(result); } else { System.out.println(0); } } public class ModCalc { int mod ; public ModCalc(int mod){ this.mod=mod ; } public int add(int a,int b){ return(int)(((long)a+b)% mod); } public int subtract(int a,int b){ return(int)(((long)a-b+mod)% mod); } public int multiply(int a,int b){ return(int)(((long)a*b)% mod); } public int divide(int a,int b){ return multiply(a,pow(b,mod-2)); } public int pow(int n,int k){ if(k==0){ return 1 ; } else if(k % 2==0){ int p=pow(n,k/2); return multiply(p,p); } else { int p=pow(n,(k-1)/2); return multiply(multiply(p,p),n); } } public int combine(int n,int k){ int sum1=1 ; int sum2=1 ; for(int i=0 ; imin() - a ; if ((x + y) mod 3 = 0 & b >= 0) then ( var modCalc : var ; modCalc := (Main.newMain()).newModCalc(MOD) ; var result : var ; result := modCalc.combine(a, b) ; OclFile["System.out"].println(result) ) else ( OclFile["System.out"].println(0) ) ; ); class ModCalc { attribute mod : int; static operation newModCalc( mod : int) : ModCalc pre: true post: true activity: ( var self : ModCalc ; self := createModCalc(); self.initialise(mod); return self ); operation initialise( mod : int) : void pre: true post: true activity: ( self.mod := mod ); operation add( a : int, b : int) : int pre: true post: true activity: ( return ((a->oclAsType(long) + b) mod mod)->oclAsType(int) ); operation subtract( a : int, b : int) : int pre: true post: true activity: ( return ((a->oclAsType(long) - b + mod) mod mod)->oclAsType(int) ); operation multiply( a : int, b : int) : int pre: true post: true activity: ( return ((a->oclAsType(long) * b) mod mod)->oclAsType(int) ); operation divide( a : int, b : int) : int pre: true post: true activity: ( return multiply(a, pow(b, mod - 2)) ); operation pow( n : int, k : int) : int pre: true post: true activity: ( if (k = 0) then ( return 1 ) else if (k mod 2 = 0) then ( var p : int ; p := pow(n, k / 2) ; return multiply(p, p) ) else ( var p : int ; p := pow(n, (k - 1) / 2) ; return multiply(multiply(p, p), n) ) ; ); operation combine( n : int, k : int) : int pre: true post: true activity: ( var sum1 : int ; sum1 := 1 ; var sum2 : int ; sum2 := 1 ; var i : int ; i := 0 ; while i < k do ( ( sum1 := multiply(sum1, n - i) ; sum2 := multiply(sum2, i + 1) ) ; i := i + 1 ) ; return divide(sum1, sum2) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class P3 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[][]=new int[n][n]; for(int i=0 ; itoInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( a[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (n = 1) then ( if (a[0+1][0+1] = 1) then ( OclFile["System.out"].println("YES") ; return ) else ( OclFile["System.out"].println("NO") ; return ) ) else skip ; var mast : boolean ; mast := false ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (a[i+1][j+1] /= 1) then ( cnt := 0 ; var k : int ; k := 0 ; while k < n do ( ( var l : int ; l := 0 ; while l < n do ( ( if (a[i+1][j+1] = a[i+1][k+1] + a[l+1][j+1]) then ( cnt := 1 ; break ) else skip ) ; l := l + 1 ) ; if (cnt = 1) then break else skip ) ; k := k + 1 ) ; if (cnt = 0) then ( OclFile["System.out"].println("NO") ; return ) else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (cnt = 1) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class BuyAShovel { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n,b,d ; n=scan.nextInt(); b=scan.nextInt(); d=scan.nextInt(); int a ; int sum=0 ; int counter=0 ; for(int i=0 ; id){ counter++; sum=0 ; } } System.out.print(counter); } } ------------------------------------------------------------ OCL File: --------- class BuyAShovel { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var b : int ; var d : int ; n := scan.getCurrent()->toInteger() ; b := scan.getCurrent()->toInteger() ; d := scan.getCurrent()->toInteger() ; var a : int ; var sum : int ; sum := 0 ; var counter : int ; counter := 0 ; var i : int ; i := 0 ; while i < n do ( ( a := scan.getCurrent()->toInteger() ; if (a <= b) then ( sum := sum+(a) ) else skip ; if (sum > d) then ( counter := counter + 1 ; sum := 0 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForces1461B { public static void main(String[] args){ Scanner input=new Scanner(System.in); int t=input.nextInt(); for(int q=0 ; q0 ; i--){ for(int j=1 ; j<=k ; j++){ if(a[i][j]==0){ continue ; } else { a[i][j]=Math.min(Math.min(a[i+1][j-1],a[i+1][j]),a[i+1][j+1])+1 ; count+=a[i][j]; } } } System.out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class CodeForces1461B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := input.getCurrent()->toInteger() ; var q : int ; q := 0 ; while q < t do ( ( var n : int ; n := input.getCurrent()->toInteger() ; var k : int ; k := input.getCurrent()->toInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,n + 2)->collect(Integer.subrange(1,k + 2)->collect(0)) ; var count : int ; count := 0 ; var i : int ; i := 1 ; while i <= n do ( ( var s : String ; s := input.getCurrent() ; var j : int ; j := 1 ; while j <= s->size() do ( ( if (s->at((j)->char2byte() - 1+1) = '*') then ( a[i+1][j+1] := 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := n ; while i > 0 do ( ( var j : int ; j := 1 ; while j <= k do ( ( if (a[i+1][j+1] = 0) then ( continue ) else ( a[i+1][j+1] := Set{Set{a[i + 1+1][(j)->char2byte() - 1+1], a[i + 1+1][j+1]}->min(), a[i + 1+1][j + 1+1]}->min() + 1 ; count := count+(a[i+1][j+1]) ) ) ; j := j + 1 ) ) ; i := i - 1 ) ; OclFile["System.out"].println(count) ; ) ; q := q + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int mod=1000000007 ; public static long frac(int n){ long ans=1 ; for(int i=2 ; i<=n ; i++){ ans*=i ; ans %=mod ; } return ans ; } public static long modpow(long a,long n,long mod){ long res=1 ; while(n>0){ if(n % 2==1){ res=res*a % mod ; } a=a*a % mod ; n>>=1 ; } return res ; } static long modinv(long a,long mod){ return modpow(a,mod-2,mod); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); double a=(2*(double)x-(double)y)/3 ; double b=(2*(double)y-(double)x)/3 ; if(((2*x-y)% 3==0 &&(2*y-x)% 3==0)&&(2*x-y>=0 && 2*y-x>=0)){ int aa=(int)a ; int bb=(int)b ; int cc=aa+bb ; long ans1=frac(aa+bb); long ans2=modinv(frac(aa),mod); long ans3=modinv(frac(bb),mod); long ans4=((ans1*ans2)% mod*ans3)% mod ; System.out.println(ans4); } else { System.out.println("0"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute mod : int := 1000000007; static operation frac( n : int) : long pre: true post: true activity: ( var ans : long ; ans := 1 ; var i : int ; i := 2 ; while i <= n do ( ( ans := ans*(i) ; ans := ans mod mod ) ; i := i + 1 ) ; return ans ); static operation modpow( a : long, n : long, mod : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (n > 0) do ( if (n mod 2 = 1) then ( res := res * a mod mod ) else skip ; a := a * a mod mod ; n := n/(2->pow(1)) ) ; return res ); static operation modinv( a : long, mod : long) : long pre: true post: true activity: ( return modpow(a, mod - 2, mod) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; var a : double ; a := (2 * x->oclAsType(double) - y->oclAsType(double)) / 3 ; var b : double ; b := (2 * y->oclAsType(double) - x->oclAsType(double)) / 3 ; if (((2 * x - y) mod 3 = 0 & (2 * y - x) mod 3 = 0) & (2 * x - y >= 0 & 2 * y - x >= 0)) then ( var aa : int ; aa := a->oclAsType(int) ; var bb : int ; bb := b->oclAsType(int) ; var cc : int ; cc := aa + bb ; var ans1 : long ; ans1 := frac(aa + bb) ; var ans2 : long ; ans2 := modinv(frac(aa), mod) ; var ans3 : long ; ans3 := modinv(frac(bb), mod) ; var ans4 : long ; ans4 := ((ans1 * ans2) mod mod * ans3) mod mod ; OclFile["System.out"].println(ans4) ; ) else ( OclFile["System.out"].println("0") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { static int MOD=1000000007 ; static long[] fac=new long[1000000]; static long[] finv=new long[1000000]; static long[] inv=new long[1000000]; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str[]=br.readLine().split(" "); int x=Integer.parseInt(str[0]); int y=Integer.parseInt(str[1]); int a=(2*x-y)/3 ; int b=(2*y-x)/3 ; if(((-x+2*y)% 3!=0)||((2*x-y)% 3!=0)){ System.out.println(0); } else { COMinit(); System.out.println(COM(a+b,a)); } } public static void COMinit(){ fac[0]=1L ; fac[1]=1L ; finv[0]=1L ; finv[1]=1L ; inv[1]=1L ; for(int i=2 ; i<1000000 ; i++){ fac[i]=fac[i-1]*i % MOD ; inv[i]=MOD-inv[MOD % i]*(MOD/i)% MOD ; finv[i]=finv[i-1]*inv[i] % MOD ; } } public static long COM(int n,int k){ if(ncollect(0); static attribute finv : Sequence(long) := Integer.subrange(1,1000000)->collect(0); static attribute inv : Sequence(long) := Integer.subrange(1,1000000)->collect(0); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : Sequence(String) ; str := br.readLine()->split(" ") ; var x : int ; x := (str[0+1])->toInteger() ; var y : int ; y := (str[1+1])->toInteger() ; var a : int ; a := (2 * x - y) / 3 ; var b : int ; b := (2 * y - (x)->char2byte()) / 3 ; if (((-x + 2 * y) mod 3 /= 0) or ((2 * x - y) mod 3 /= 0)) then ( OclFile["System.out"].println(0) ) else ( execute COMinit() ; OclFile["System.out"].println(COM(a + b, a)) ) ; ); static operation COMinit() : void pre: true post: true activity: ( fac[0+1] := 1L ; fac[1+1] := 1L ; finv[0+1] := 1L ; finv[1+1] := 1L ; inv[1+1] := 1L ; var i : int ; i := 2 ; while i < 1000000 do ( ( fac[i+1] := fac[i - 1+1] * i mod MOD ; inv[i+1] := MOD - inv[MOD mod i+1] * (MOD / i) mod MOD ; finv[i+1] := finv[i - 1+1] * inv[i+1] mod MOD ) ; i := i + 1 ) ; ); static operation COM( n : int, k : int) : long pre: true post: true activity: ( if (n < k) then ( return 0L ) else skip ; if (n < 0 or k < 0) then ( return 0L ) else skip ; return fac[n+1] * (finv[k+1] * finv[n - k+1] mod MOD) mod MOD ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { private static final int MOD=1_000_000_007 ; private static final int MAX=1000000 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int X=sc.nextInt(); int Y=sc.nextInt(); int A=-1,B=-1 ; for(int a=0 ; a<=X ; a++){ int b=X-2*a ; if(b>=0 && a+2*b==Y){ A=a ; B=b ; break ; } } if(A==-1){ System.out.println(0); } else { System.out.println(combMod(A+B,A)); } } private static long combMod(int n,int k){ long[] fac=new long[n+1]; fac[0]=1 ; for(int i=1 ; i<=n ; i++){ fac[i]=fac[i-1]*i % MOD ; } return((fac[n]*power(fac[k],MOD-2))% MOD)*power(fac[n-k],MOD-2)% MOD ; } private static long power(long a,int n){ if(n==0){ return 1 ; } if(n % 2==1){ return power(a,n-1)*a % MOD ; } long half=power(a,n/2); return half*half % MOD ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : int := 1_000_000_007; static attribute MAX : int := 1000000; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : int ; X := sc.getCurrent()->toInteger() ; var Y : int ; Y := sc.getCurrent()->toInteger() ; var A : int ; A := -1 ; var B : int ; B := -1 ; var a : int ; a := 0 ; while a <= X do ( ( var b : int ; b := X - 2 * a ; if (b >= 0 & a + 2 * b = Y) then ( A := a ; B := b ; break ) else skip ) ; a := a + 1 ) ; if (A = -1) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(combMod(A + B, A)) ) ; ); static operation combMod( n : int, k : int) : long pre: true post: true activity: ( var fac : Sequence(long) ; fac := Integer.subrange(1,n + 1)->collect(0) ; fac[0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( ( fac[i+1] := fac[i - 1+1] * i mod MOD ) ; i := i + 1 ) ; return ((fac[n+1] * power(fac[k+1], MOD - 2)) mod MOD) * power(fac[n - k+1], MOD - 2) mod MOD ); static operation power( a : long, n : int) : long pre: true post: true activity: ( if (n = 0) then ( return 1 ) else skip ; if (n mod 2 = 1) then ( return power(a, n - 1) * a mod MOD ) else skip ; var half : long ; half := power(a, n / 2) ; return half * half mod MOD ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int setBit(int xorValue){ int count=0 ; while(xorValue>=1){ if(xorValue % 2==1)count++; xorValue/=2 ; } return count ; } static int minFlip(int n,int k){ int size=(int)(Math.log(n)/Math.log(2))+1 ; int max=(int)Math.pow(2,k)-1 ; max=max<<(size-k); int xorValue=(n ^ max); return(setBit(xorValue)); } public static void main(String[] args){ int n=27,k=3 ; System.out.println("Min Flips="+minFlip(n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation setBit( xorValue : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; while (xorValue >= 1) do ( if (xorValue mod 2 = 1) then count := count + 1 ; else skip ; xorValue := xorValue/(2) ) ; return count ); static operation minFlip( n : int, k : int) : int pre: true post: true activity: ( var size : int ; size := ((n)->log() / (2)->log())->oclAsType(int) + 1 ; var max : int ; max := 2->pow(k)->oclAsType(int) - 1 ; max := (max*(2->pow((size - k))))->oclAsType(long) ; var xorValue : int ; xorValue := (MathLib.bitwiseXor(n,max)) ; return (setBit(xorValue)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 27 ; var k : int ; k := 3 ; OclFile["System.out"].println("Min Flips=" + minFlip(n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] a=new long[n]; long sum=0 ; for(int i=0 ; i0){ long t=sum ; ans+=sum ; sum=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ; sum := sum+((a[i+1] / n->oclAsType(long))) ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; while (sum > 0) do ( var t : long ; t := sum ; ans := ans+(sum) ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var s : long ; s := a[i+1] / n->oclAsType(long) ; a[i+1] := a[i+1]-((s * n->oclAsType(long))) ; a[i+1] := a[i+1]+((t - s)) ; sum := sum+((a[i+1] / n->oclAsType(long))) ) ; i := i + 1 ) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.StringTokenizer ; public class Main { public static void main(String args[]){ ConsoleScanner cin=new ConsoleScanner(); PrintWriter cout=new PrintWriter(System.out); solve(cin,cout); cout.flush(); } private static void solve(ConsoleScanner cin,PrintWriter cout){ int n=cin.nextInt(); long[] a=new long[n]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < a->size() do ( a[i+1] := cin.nextLong() ; ; i := i + 1 ) ; var millis : long ; millis := OclDate.getSystemTime() ; var ans : long ; ans := solve(n, a) ; skip ; assert null /= cout.format("%d elapsed", OclDate.getSystemTime() - millis) ; ); static operation solve( n : int, a : Sequence(long)) : long pre: true post: true activity: ( var ans : long ; ans := 0 ; var opes : Sequence(long) ; opes := Integer.subrange(1,n)->collect(0) ; while (true) do ( var any : boolean ; any := false ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( opes[i+1] := a[i+1] / n ; sum := sum+(opes[i+1]) ; any := MathLib.bitwiseOr(any, opes[i+1] /= 0) ; a[i+1] := a[i+1] mod n ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := a[i+1]+(sum - opes[i+1]) ; ; i := i + 1 ) ; ans := ans+(sum) ; if (not(any)) then break else skip ; ) ; return ans ); static class ConsoleScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( try ( while (not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ) catch (e : IOException) do ( error AssertionException(e) ) ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main extends PrintWriter { Main(){ super(System.out,true); } Scanner sc=new Scanner(System.in); public static void main(String[] $){ Main o=new Main(); o.main(); o.flush(); } void main(){ int n=sc.nextInt(); long[] aa=new long[n]; for(int i=0 ; itoInteger() ; var aa : Sequence(long) ; aa := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( aa[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var ans : long ; ans := 0 ; while (true) do ( var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var cnt : long ; cnt := aa[i+1] / n ; sum := sum+(cnt) ) ; i := i + 1 ) ; if (sum = 0) then break else skip ; ans := ans+(sum) ; var i : int ; i := 0 ; while i < n do ( ( var cnt : long ; cnt := aa[i+1] / n ; aa[i+1] := aa[i+1] mod n + sum - cnt ) ; i := i + 1 ) ; ) ; execute println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } final long MODULO=1_000_000_000+7 ; public void run(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] a=new long[n]; for(int i=0 ; i1){ long m=(l+u)/2 ; if(f(a,m)<0){ l=m ; } else { u=m ; } } for(long i=Math.max(0,u-1000); i<=u+1000 ; ++i){ if(f(a,i)==0){ System.out.println(i); return ; } } } long f(long[] a,long k){ int n=a.length ; long s=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; a := a->sort() ; var l : long ; l := 0 ; var u : long ; u := "9223372036854775807"->toLong() / 10 ; while (u - l > 1) do ( var m : long ; m := (l + u) / 2 ; if (f(a, m) < 0) then ( l := m ) else ( u := m ) ) ; var i : long ; i := Set{0, u - 1000}->max() ; while i <= u + 1000 do ( ( if (f(a, i) = 0) then ( OclFile["System.out"].println(i) ; return ) else skip ) ; i := i + 1 ) ; ); operation f( a : Sequence(long), k : long) : long pre: true post: true activity: ( var n : int ; n := a->size() ; var s : long ; s := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] + k <= n - 1) then ( continue ) else ( var res : long ; res := a[i+1] + k - (n - 1) ; s := s+((res + n) / (n + 1)) ) ) ; i := i + 1 ) ; return k - s ); static operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static final long INF=1000000000000000000L ; public static void main(String[] args){ Scanner in=new Scanner(System.in); final int N=in.nextInt(); long[] as=new long[N]; for(int i=0 ; i0){ isFinished=false ; K+=k ; for(int j=0 ; jtoInteger() ; var as : Sequence(long) ; as := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( as[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; var K : long ; K := 0 ; while (true) do ( var isFinished : boolean ; isFinished := true ; var i : int ; i := 0 ; while i < N do ( ( var k : long ; k := as[i+1] / N ; if (k > 0) then ( isFinished := false ; K := K+(k) ; var j : int ; j := 0 ; while j < N do ( ( if (j = i) then ( as[j+1] := as[j+1] mod N ) else ( as[j+1] := as[j+1]+(k) ) ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ; if (isFinished) then ( break ) else skip ) ; OclFile["System.out"].printf("%d\n", K) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0 ; iset=new HashSet<>(); int count=0 ; Random random=new Random(); while(counttoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := scan.getCurrent()->toInteger() ) ; j := j + 1 ) ; execute printArrayB(n, arr) ) ; i := i + 1 ) ); static operation printArrayB( n : int, arr : Sequence(int)) : void pre: true post: true activity: ( if (n = 1) then ( OclFile["System.out"].println("YES") ; OclFile["System.out"].println(1) ; return ) else skip ; var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString("YES\n") ; var set : Set(int) ; set := Set{} ; var count : int ; count := 0 ; var random : OclRandom ; random := OclRandom.newOclRandom() ; while (count < n) do ( var cur : int ; cur := random.nextInt(1000 * 1000) + 1 ; var valid : boolean ; valid := true ; for (num : arr) do ( ( if (set->includes(num + cur)) then ( valid := false ; break ) else skip ) ) ; if (valid) then ( sb := sb + StringLib.newString(cur) + StringLib.newString(" ") ; count := count + 1 ; for (num : arr) do ( ( set := set->including(num + cur) ) ) ) else skip ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class A1239 { private static final int LIMIT=100_000 ; private static final long MOD=1_000_000_007 ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int m=Integer.parseInt(st.nextToken()); int n=Integer.parseInt(st.nextToken()); long[] fibonacci=new long[LIMIT+1]; fibonacci[0]=1 ; fibonacci[1]=1 ; for(int i=2 ; i<=LIMIT ; i++){ fibonacci[i]=(fibonacci[i-1]+fibonacci[i-2])% MOD ; } System.out.println(((fibonacci[m]+fibonacci[n]-1)*2)% MOD); } } ------------------------------------------------------------ OCL File: --------- class A1239 { static attribute LIMIT : int := 100_000; static attribute MOD : long := 1_000_000_007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var m : int ; m := (st.next())->toInteger() ; var n : int ; n := (st.next())->toInteger() ; var fibonacci : Sequence(long) ; fibonacci := Integer.subrange(1,LIMIT + 1)->collect(0) ; fibonacci[0+1] := 1 ; fibonacci[1+1] := 1 ; var i : int ; i := 2 ; while i <= LIMIT do ( ( fibonacci[i+1] := (fibonacci[i - 1+1] + fibonacci[i - 2+1]) mod MOD ) ; i := i + 1 ) ; OclFile["System.out"].println(((fibonacci[m+1] + fibonacci[n+1] - 1) * 2) mod MOD) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findSubSeq(int arr[],int n,int sum){ for(int i=n-1 ; i>=0 ; i--){ if(sum= 0 do ( ( if (sum < arr[i+1]) then arr[i+1] := -1 ; else sum := sum-(arr[i+1]) ; ) ; i := i - 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] /= -1) then OclFile["System.out"].print(arr[i+1] + " ") ; else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{17,25,46,94,201,400} ; var n : int ; n := arr->size() ; var sum : int ; sum := 272 ; execute findSubSeq(arr, n, sum) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { static int countWays(int num){ int[] dp=new int[num+1]; int MOD=(int)1E9+7 ; dp[1]=2 ; for(int i=2 ; i<=num ; ++i){ dp[i]=0 ; for(int j=1 ; j<=3 ; ++j){ if(i-j==0)dp[i]+=1 ; else if(j==1)dp[i]+=dp[i-j]*2 ; else if(i-j>0)dp[i]+=dp[i-j]; if(dp[i]>=MOD)dp[i] %=MOD ; } } return dp[num]; } static public void main(String[] args){ int n=3 ; System.out.println(countWays(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countWays( num : int) : int pre: true post: true activity: ( var dp : Sequence(int) ; dp := Integer.subrange(1,num + 1)->collect(0) ; var MOD : int ; MOD := 1E9->oclAsType(int) + 7 ; dp[1+1] := 2 ; var i : int ; i := 2 ; while i <= num do ( ( dp[i+1] := 0 ; var j : int ; j := 1 ; while j <= 3 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] >= MOD) then dp[i+1] := dp[i+1] mod MOD ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[num+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(countWays(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ double p=Math.sqrt(sc.nextDouble()); int n=sc.nextInt(); if(p==0 && n==0)break ; double max=1/(double)n ; double min=(double)n ; int max_p=1 ; int max_q=n ; int min_p=n ; int min_q=1 ; for(int i=1 ; i<=n ; i++){ int j1=(int)Math.floor(i*p); int j2=(int)Math.ceil(i*p); if(j1<=n &&(double)j1/i>max){ max=(double)j1/i ; max_p=j1 ; max_q=i ; } if(j2<=n &&(double)j2/itoReal())->sqrt() ; var n : int ; n := sc.getCurrent()->toInteger() ; if (p = 0 & n = 0) then break else skip ; var max : double ; max := 1 / n->oclAsType(double) ; var min : double ; min := n->oclAsType(double) ; var max_p : int ; max_p := 1 ; var max_q : int ; max_q := n ; var min_p : int ; min_p := n ; var min_q : int ; min_q := 1 ; var i : int ; i := 1 ; while i <= n do ( ( var j1 : int ; j1 := (i * p)->floor()->oclAsType(int) ; var j2 : int ; j2 := (i * p)->ceil()->oclAsType(int) ; if (j1 <= n & j1->oclAsType(double) / i > max) then ( max := j1->oclAsType(double) / i ; max_p := j1 ; max_q := i ) else skip ; if (j2 <= n & j2->oclAsType(double) / i < min) then ( min := j2->oclAsType(double) / i ; min_p := j2 ; min_q := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].printf("%d/%d %d/%d\n", min_p, min_q, max_p, max_q) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { final int INF=1<<28 ; void run(){ Scanner sc=new Scanner(System.in); while(true){ int p=sc.nextInt(); int n=sc.nextInt(); if((p | n)==0)break ; double max=0 ; double min=Double.POSITIVE_INFINITY ; double rp=Math.sqrt(p); int a=1 ; int b=1 ; int u=0 ; int v=0 ; int x=0 ; int y=0 ; while(true){ if(1.0*a/b>rp){ if(min>1.0*a/b){ min=1.0*a/b ; x=a ; y=b ; } b++; if(b>n)break ; } else { if(max<1.0*a/b){ max=1.0*a/b ; u=a ; v=b ; } a++; if(a>n)break ; } } int g1=gcd(x,y); int g2=gcd(u,v); x/=g1 ; y/=g1 ; u/=g2 ; v/=g2 ; System.out.println(x+"/"+y+" "+u+"/"+v); } } int gcd(int a,int b){ if(apow(28)))->oclAsType(long); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var p : int ; p := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(p,n)) = 0) then break else skip ; var max : double ; max := 0 ; var min : double ; min := Math_PINFINITY ; var rp : double ; rp := (p)->sqrt() ; var a : int ; a := 1 ; var b : int ; b := 1 ; var u : int ; u := 0 ; var v : int ; v := 0 ; var x : int ; x := 0 ; var y : int ; y := 0 ; while (true) do ( if (1.0 * a / b > rp) then ( if (min > 1.0 * a / b) then ( min := 1.0 * a / b ; x := a ; y := b ) else skip ; b := b + 1 ; if (b > n) then break else skip ) else ( if (max < 1.0 * a / b) then ( max := 1.0 * a / b ; u := a ; v := b ) else skip ; a := a + 1 ; if (a > n) then break else skip ) ) ; var g1 : int ; g1 := gcd(x, y) ; var g2 : int ; g2 := gcd(u, v) ; x := x/(g1) ; y := y/(g1) ; u := u/(g2) ; v := v/(g2) ; OclFile["System.out"].println(x + "/" + y + " " + u + "/" + v) ; ) ); operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a < b) then ( a := MathLib.bitwiseXor(a,b) ; b := MathLib.bitwiseXor(a,b) ; a := MathLib.bitwiseXor(a,b) ) else skip ; if (b = 0) then return a else skip ; return gcd(b, a mod b) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ long n=s.nextInt(); int nums=0 ; long temp=n ; while(temp>0){ nums++; temp/=10 ; } int min=Integer.MAX_VALUE ; int[] arr=new int[nums]; int i=nums-1 ; temp=n ; while(temp>0){ arr[i--]=(int)temp % 10 ; min=Math.min(min,(int)temp % 10); temp/=10 ; } if(nums==2)System.out.println(arr[1]); else System.out.println(min); } } } ------------------------------------------------------------ OCL File: --------- class Codeforces { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : long ; n := s.getCurrent()->toInteger() ; var nums : int ; nums := 0 ; var temp : long ; temp := n ; while (temp > 0) do ( nums := nums + 1 ; temp := temp/(10) ) ; var min : int ; min := 2147483647 ; var arr : Sequence(int) ; arr := Integer.subrange(1,nums)->collect(0) ; var i : int ; i := nums - 1 ; temp := n ; while (temp > 0) do ( arr[i+1] := temp->oclAsType(int) mod 10 ; i := i - 1 ; min := Set{min, temp->oclAsType(int) mod 10}->min() ; temp := temp/(10) ) ; if (nums = 2) then OclFile["System.out"].println(arr[1+1]) else OclFile["System.out"].println(min) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0 ; iset=new HashSet<>(); ArrayListans=new ArrayList<>(); Random random=new Random(); while(true){ int cur=random.nextInt(1000*1000)+1 ; boolean used=true ; for(int num : arr){ if(set.contains(num+cur)){ used=false ; break ; } } if(used){ sb.append(cur).append(" "); ans.add(cur); if(ans.size()==n){ break ; } for(int num : arr){ set.add(num+cur); } } } System.out.println(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := scan.getCurrent()->toInteger() ) ; j := j + 1 ) ; execute printArrayB(n, arr) ) ; i := i + 1 ) ); static operation printArrayB( n : int, arr : Sequence(int)) : void pre: true post: true activity: ( if (n = 1) then ( OclFile["System.out"].println("YES") ; OclFile["System.out"].println(1) ; return ) else skip ; var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString("YES\n") ; var set : Set(int) ; set := Set{} ; var ans : Sequence(int) ; ans := Sequence{} ; var random : OclRandom ; random := OclRandom.newOclRandom() ; while (true) do ( var cur : int ; cur := random.nextInt(1000 * 1000) + 1 ; var used : boolean ; used := true ; for (num : arr) do ( ( if (set->includes(num + cur)) then ( used := false ; break ) else skip ) ) ; if (used) then ( sb := sb + StringLib.newString(cur) + StringLib.newString(" ") ; ans := ans->including(cur) ; if (ans->size() = n) then ( break ) else skip ; for (num : arr) do ( ( set := set->including(num + cur) ) ) ) else skip ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Collections ; import java.util.LinkedList ; import java.util.List ; import java.util.Scanner ; public class A1684 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t-->0){ String n=scanner.next(); Listlist=new LinkedList<>(); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : String ; n := scanner.getCurrent() ; var list : Sequence(String) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n->size() do ( ( list := list->including(n->at(i+1)) ) ; i := i + 1 ) ; list := list->sort() ; if (list->size() = 2) then ( OclFile["System.out"].println(if (n->at(0+1) = list->at(0+1)) then list->at(1+1) else list->at(0+1) endif) ) else ( OclFile["System.out"].println(list->at(0+1)) ) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t--!=0){ int n=scanner.nextInt(); System.out.println(testcase(n)); } } public static int testcase(int n){ if(n<100){ return n % 10 ; } int ans=Integer.MAX_VALUE ; while(n!=0){ ans=Math.min(ans,n % 10); n/=10 ; } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(testcase(n)) ) ; ) ); static operation testcase( n : int) : int pre: true post: true activity: ( if (n < 100) then ( return n mod 10 ) else skip ; var ans : int ; ans := 2147483647 ; while (n /= 0) do ( ans := Set{ans, n mod 10}->min() ; n := n/(10) ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import static java.lang.Math.*; public class B { public static void main(String[] args)throws IOException { int n=readInt(),k=readInt(); Lista=new ArrayList(); int sol=n+1 ; for(int start=0 ; starttemp=new ArrayList(); boolean[] fill=new boolean[n]; for(int j=start ; jcollect(false) ; var j : int ; j := start ; while j < n do ( ( temp := temp->including(j) ; var tj : int ; tj := max(0, j - k) ; while tj <= Set{n - 1, j + k}->min() do ( fill[tj+1] := true ; ; tj := tj + 1 ) ) ; j := j+(2 * k + 1) ) ; var work : boolean ; work := true ; for (b : fill) do ( work := MathLib.bitwiseAnd(work, b) ; ) ; if (work & temp->size() < sol) then ( sol := temp->size() ; a := temp ) else skip ; ) ; start := start + 1 ) ; out.println(a->size()) ; for (x : a) do ( out.print(x + 1 + " ") ; ) ; out.println() ; out.close() ; ); static attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static attribute st : OclIterator := OclIterator.newOclIterator_String(""); static operation read() : String pre: true post: true activity: ( return if st.hasNext() then st.next() else (st).next() endif ); static operation readInt() : int pre: true post: true activity: ( return (read())->toInteger() ); static operation readLong() : long pre: true post: true activity: ( return (read())->toLong() ); static operation readDouble() : double pre: true post: true activity: ( return (read())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { int count(int num){ int c=0 ; while(num!=0){ c++; num=num/10 ; } return c ; } public static void main(String args[]){ Scanner Sc=new Scanner(System.in); int a=Sc.nextInt(); int i ; Main obj=new Main(); int num[]=new int[a]; for(i=0 ; i2){ int min=9 ; while(n!=0){ d=n % 10 ; if(min>d)min=d ; n=n/10 ; } System.out.println(min); } } } } ------------------------------------------------------------ OCL File: --------- class Main { operation count( num : int) : int pre: true post: true activity: ( var c : int ; c := 0 ; while (num /= 0) do ( c := c + 1 ; num := num / 10 ) ; return c ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var Sc : OclFile ; Sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := Sc.getCurrent()->toInteger() ; var i : int ; var obj : Main ; obj := Main.newMain() ; var num : Sequence(int) ; num := Integer.subrange(1,a)->collect(0) ; i := 0 ; while i < a do ( ( num[i+1] := Sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; i := 0 ; while i < a do ( ( var n : int ; n := num[i+1] ; var c : int ; c := obj.count(n) ; var d : int ; if (c = 2) then OclFile["System.out"].println(n mod 10) ; else if (c > 2) then ( var min : int ; min := 9 ; while (n /= 0) do ( d := n mod 10 ; if (min > d) then min := d ; else skip ; n := n / 10 ) ; OclFile["System.out"].println(min) ) else skip ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; class GFG { static int sumofoddFactors(int n){ int res=1 ; while(n % 2==0)n=n/2 ; for(int i=3 ; i<=Math.sqrt(n); i++){ int count=0,curr_sum=1 ; int curr_term=1 ; while(n % i==0){ count++; n=n/i ; curr_term*=i ; curr_sum+=curr_term ; } res*=curr_sum ; } if(n>=2)res*=(1+n); return res ; } public static void main(String args[])throws IOException { int n=30 ; System.out.println(sumofoddFactors(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumofoddFactors( n : int) : int pre: true post: true activity: ( var res : int ; res := 1 ; while (n mod 2 = 0) do n := n / 2 ; ; var i : int ; i := 3 ; while i <= (n)->sqrt() do ( ( var count : int ; count := 0 ; var curr_sum : int ; curr_sum := 1 ; var curr_term : int ; curr_term := 1 ; while (n mod i = 0) do ( count := count + 1 ; n := n / i ; curr_term := curr_term*(i) ; curr_sum := curr_sum+(curr_term) ) ; res := res*(curr_sum) ) ; i := i + 1 ) ; if (n >= 2) then res := res*((1 + n)) ; else skip ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 30 ; OclFile["System.out"].println(sumofoddFactors(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; public class GFG { static int sumofFactors(int n){ int res=1 ; for(int i=2 ; i<=Math.sqrt(n); i++){ int curr_sum=1 ; int curr_term=1 ; while(n % i==0){ n=n/i ; curr_term*=i ; curr_sum+=curr_term ; } res*=curr_sum ; } if(n>2)res*=(1+n); return res ; } public static void main(String args[]){ int n=30 ; System.out.println(sumofFactors(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumofFactors( n : int) : int pre: true post: true activity: ( var res : int ; res := 1 ; var i : int ; i := 2 ; while i <= (n)->sqrt() do ( ( var curr_sum : int ; curr_sum := 1 ; var curr_term : int ; curr_term := 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) ) ; i := i + 1 ) ; if (n > 2) then res := res*((1 + n)) ; else skip ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 30 ; OclFile["System.out"].println(sumofFactors(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.awt.geom.Point2D ; public class Main { static int n ; static Point2D d ; static HashMapc ; static boolean dfs(Point2D p,double sum,int time){ if(time==n)return true ; for(Point2D pp : c.keySet()){ if(c.get(pp))continue ; if(sum+p.distance(pp)>=d.distance(pp))return false ; } c.put(p,true); for(Point2D pp : c.keySet()){ if(c.get(pp))continue ; if(dfs(pp,sum+p.distance(pp),time+1))return true ; } c.put(p,false); return false ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ n=sc.nextInt(); Point2D h=new Point2D.Double(sc.nextDouble(),sc.nextDouble()); d=new Point2D.Double(sc.nextDouble(),sc.nextDouble()); if(n==0)break ; c=new HashMap(); c.put(h,false); for(int i=0 ; ikeys()) do ( ( if (c->at(pp)) then continue else skip ; if (sum + p.distance(pp) >= d.distance(pp)) then return false else skip ) ) ; c := c->union(Map{p |-> true}) ; for (pp : c->keys()) do ( ( if (c->at(pp)) then continue else skip ; if (dfs(pp, sum + p.distance(pp), time + 1)) then return true else skip ) ) ; c := c->union(Map{p |-> false}) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( n := sc.getCurrent()->toInteger() ; var h : Point2D ; h := Double.newDouble(sc.getCurrent()->toReal(), sc.getCurrent()->toReal()) ; d := Double.newDouble(sc.getCurrent()->toReal(), sc.getCurrent()->toReal()) ; if (n = 0) then break else skip ; c := Map{} ; c := c->union(Map{h |-> false}) ; var i : int ; i := 0 ; while i < n do ( ( c := c->union(Map{Double.newDouble(sc.getCurrent()->toReal(), sc.getCurrent()->toReal()) |-> false}) ) ; i := i + 1 ) ; OclFile["System.out"].println(if dfs(h, 0, 0) then "YES" else "NO" endif) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class CF38B { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); char[] rr=br.readLine().toCharArray(); char[] kk=br.readLine().toCharArray(); int xr=rr[0]-'a' ; int yr=rr[1]-'1' ; int xk=kk[0]-'a' ; int yk=kk[1]-'1' ; int cnt=0 ; for(int x=0 ; x<8 ; x++){ for(int y=0 ; y<8 ; y++){ if(x==xr || y==yr)continue ; if(x==xk && y==yk)continue ; int dx,dy ; dx=Math.abs(x-xr); dy=Math.abs(y-yr); if((dx==1 && dy==2)||(dx==2 && dy==1))continue ; dx=Math.abs(x-xk); dy=Math.abs(y-yk); if((dx==1 && dy==2)||(dx==2 && dy==1))continue ; cnt++; } } System.out.println(cnt); } } ------------------------------------------------------------ OCL File: --------- class CF38B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var rr : Sequence(String) ; rr := br.readLine()->characters() ; var kk : Sequence(String) ; kk := br.readLine()->characters() ; var xr : int ; xr := rr[0+1] - ('a')->char2byte() ; var yr : int ; yr := rr[1+1] - ('1')->char2byte() ; var xk : int ; xk := kk[0+1] - ('a')->char2byte() ; var yk : int ; yk := kk[1+1] - ('1')->char2byte() ; var cnt : int ; cnt := 0 ; var x : int ; x := 0 ; while x < 8 do ( ( var y : int ; y := 0 ; while y < 8 do ( ( if (x = xr or y = yr) then continue else skip ; if (x = xk & y = yk) then continue else skip ; var dx : int ; var dy : int ; dx := if x - xr < 0 then -(x - xr) else x - xr endif ; dy := if y - yr < 0 then -(y - yr) else y - yr endif ; if ((dx = 1 & dy = 2) or (dx = 2 & dy = 1)) then continue else skip ; dx := if x - xk < 0 then -(x - xk) else x - xk endif ; dy := if y - yk < 0 then -(y - yk) else y - yk endif ; if ((dx = 1 & dy = 2) or (dx = 2 & dy = 1)) then continue else skip ; cnt := cnt + 1 ; ) ; y := y + 1 ) ) ; x := x + 1 ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0 ; iset=new HashSet<>(); Arrays.sort(arr); int[] diffs=new int[n*(n-1)/2]; int idx=0 ; for(int i=0 ; i=1)used[next]=true ; } cur++; } System.out.println(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := scan.getCurrent()->toInteger() ) ; j := j + 1 ) ; execute printArrayB(n, arr) ) ; i := i + 1 ) ); static operation printArrayB( n : int, arr : Sequence(int)) : void pre: true post: true activity: ( if (n = 1) then ( OclFile["System.out"].println("YES") ; OclFile["System.out"].println(1) ; return ) else skip ; var sb : String ; sb := StringLib.newString() ; var set : Set(int) ; set := Set{} ; arr := arr->sort() ; var diffs : Sequence(int) ; diffs := Integer.subrange(1,n * (n - 1) / 2)->collect(0) ; var idx : int ; idx := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( diffs[idx+1] := arr[j+1] - arr[i+1] ; idx := idx + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; sb := sb + StringLib.newString("YES\n") ; var count : int ; count := 0 ; var used : Sequence(boolean) ; used := Integer.subrange(1,1000001)->collect(false) ; var cur : int ; cur := 1 ; while (count < n) do ( while (used[cur+1]) do ( cur := cur + 1 ) ; count := count + 1 ; sb := sb + StringLib.newString(cur) + StringLib.newString(" ") ; for (diff : diffs) do ( ( var next : int ; next := cur + diff ; if (next <= 1000000 & next >= 1) then used[next+1] := true ; else skip ) ) ; cur := cur + 1 ; ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isPrime(int n){ if(n<=1)return false ; if(n<=3)return true ; if(n % 2==0 || n % 3==0)return false ; for(int i=5 ; i*i<=n ; i+=6){ if(n % i==0 || n %(i+2)==0){ return false ; } } return true ; } static boolean twinPrime(int n1,int n2){ return(isPrime(n1)&& isPrime(n2)&& Math.abs(n1-n2)==2); } static int countTwinPairs(int arr[],int n){ int count=0 ; for(int i=0 ; isize() ; OclFile["System.out"].print(countTwinPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),m=in.nextInt(); int a[]=new int[n]; for(int i=0 ; imap=new HashMap<>(); ArrayListlist=new ArrayList<>(); for(int j=0 ; jl=new ArrayList<>(); for(int i=0 ; itoInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( var map : Map(int,int) ; map := Map{} ; var list : Sequence(int) ; list := Sequence{} ; var j : int ; j := 0 ; while j < n do ( ( list := list->including(in.getCurrent()->toInteger()) ) ; j := j + 1 ) ; var max : int ; max := .max(list) ; var ind : int ; ind := list->indexOf(max)-1 ; a[ind+1] := a[ind+1] + 1 ; ) ; i := i + 1 ) ; var l : Sequence(int) ; l := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( l := l->including(a[i+1]) ) ; i := i + 1 ) ; var max_ans : int ; max_ans := .max(l) ; var ans : int ; ans := l->indexOf(max_ans)-1 ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class B { static TreeSetset ; public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(),m=in.nextInt(); int[][] votes=new int[m][n]; for(int i=0 ; imap=new HashMap(); for(int i=0 ; itoInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var votes : Sequence(Sequence(int)) ; votes := Integer.subrange(1,m)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < m do ( ( var j : int ; j := 0 ; while j < n do ( ( votes[i+1][j+1] := in.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < m do ( ( var max : int ; max := votes[i+1][0+1] ; var winner : int ; winner := 1 ; var j : int ; j := 0 ; while j < n do ( ( if (max < votes[i+1][j+1]) then ( max := votes[i+1][j+1] ; winner := j + 1 ) else skip ) ; j := j + 1 ) ; map := map->union(Map{winner |-> (if map->keys()->contains(winner) then map->at(winner) else 0 endif) + 1}) ) ; i := i + 1 ) ; var ans : int ; ans := 1 ; var max : int ; max := 0 ; var i : int ; i := 1 ; while i <= n do ( ( if (max < (if map->keys()->contains(i) then map->at(i) else 0 endif)) then ( ans := i ; max := map->at(i) ) else skip ) ; i := i + 1 ) ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int[] a=new int[n]; for(int i=0 ; is=new TreeSet(); for(int i=n-1 ; i>=0 ; i--){ int x=idx[i]; s.add(x); int l1=-1,l2=-1 ; int r1=n,r2=n ; Integer tmp ; if((tmp=s.lower(x))!=null){ l2=tmp ; if((tmp=s.lower(tmp))!=null){ l1=tmp ; } } if((tmp=s.higher(x))!=null){ r1=tmp ; if((tmp=s.higher(tmp))!=null){ r2=tmp ; } } long w1=(l2-l1)*(r1-x); long w2=(x-l2)*(r2-r1); ans+=(w1+w2)*(i+1); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var idx : Sequence(int) ; idx := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( idx[a[i+1] - 1+1] := i ) ; i := i + 1 ) ; var s : Set(int) ; s := Set{} ; var i : int ; i := n - 1 ; while i >= 0 do ( ( var x : int ; x := idx[i+1] ; s := s->including(x) ; var l1 : int ; l1 := -1 ; var l2 : int ; l2 := -1 ; var r1 : int ; r1 := n ; var r2 : int ; r2 := n ; var tmp : int ; if ((tmp) /= null) then ( l2 := tmp ; if ((tmp) /= null) then ( l1 := tmp ) else skip ) else skip ; if ((tmp) /= null) then ( r1 := tmp ; if ((tmp) /= null) then ( r2 := tmp ) else skip ) else skip ; var w1 : long ; w1 := (l2 - l1) * (r1 - x) ; var w2 : long ; w2 := (x - l2) * (r2 - r1) ; ans := ans+((w1 + w2) * (i + 1)) ; ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class A_570 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] res=new int[n]; Arrays.fill(res,0); for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var res : Sequence(int) ; res := Integer.subrange(1,n)->collect(0) ; res := res->collect(0) ; var i : int ; i := 0 ; while i < m do ( ( var max : int ; max := 0 ; var ind : int ; ind := 0 ; var j : int ; j := 0 ; while j < n do ( ( var in : int ; in := sc.getCurrent()->toInteger() ; if (max < in) then ( max := in ; ind := j ) else skip ) ; j := j + 1 ) ; res[ind+1] := res[ind+1]+(1) ) ; i := i + 1 ) ; var ind : int ; ind := 0 ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (max < res[i+1]) then ( max := res[i+1] ; ind := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ind + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int m=input.nextInt(); HashMapvote=new HashMap<>(); int resultIndex=-1 ; int resultValue=-1 ; for(int i=0 ; itempMaxValue){ tempMaxIndex=j ; tempMaxValue=temp ; } } if(vote.containsKey(tempMaxIndex))vote.put(tempMaxIndex,vote.get(tempMaxIndex)+1); else vote.put(tempMaxIndex,1); tempMaxValue=vote.get(tempMaxIndex); if(tempMaxValue>resultValue ||(resultValue==tempMaxValue && tempMaxIndextoInteger() ; var m : int ; m := input.getCurrent()->toInteger() ; var vote : Map(int,int) ; vote := Map{} ; var resultIndex : int ; resultIndex := -1 ; var resultValue : int ; resultValue := -1 ; var i : int ; i := 0 ; while i < m do ( ( var tempMaxIndex : int ; tempMaxIndex := -1 ; var tempMaxValue : int ; tempMaxValue := -1 ; var j : int ; j := 1 ; while j <= n do ( ( var temp : int ; temp := input.getCurrent()->toInteger() ; if (temp > tempMaxValue) then ( tempMaxIndex := j ; tempMaxValue := temp ) else skip ) ; j := j + 1 ) ; if (vote->keys()->includes(tempMaxIndex)) then vote := vote->union(Map{tempMaxIndex |-> vote->at(tempMaxIndex) + 1}) else vote := vote->union(Map{tempMaxIndex |-> 1}) ; ; tempMaxValue := vote->at(tempMaxIndex) ; if (tempMaxValue > resultValue or (resultValue = tempMaxValue & tempMaxIndex < resultIndex)) then ( resultIndex := tempMaxIndex ; resultValue := tempMaxValue ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(resultIndex) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int EqualNumbers(int a[],int n){ int sum=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(EqualNumbers(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; public class GfG { public static int find(int n,int k){ if(n+1>=k)return(k-1); else return(2*n+1-k); } public static void main(String argc[]){ int n=4,k=7 ; int freq=find(n,k); if(freq<0)System.out.print(" element"+" not exist \n "); else System.out.print(" Frequency"+" of "+k+" is "+freq+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation find( n : int, k : int) : int pre: true post: true activity: ( if (n + 1 >= k) then return (k - 1) else return (2 * n + 1 - k) ); static operation main( argc : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; var k : int ; k := 7 ; var freq : int ; freq := find(n, k) ; if (freq < 0) then OclFile["System.out"].print(" element" + " not exist \n ") ; else OclFile["System.out"].print(" Frequency" + " of " + k + " is " + freq + "\n") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CaseOfFakeNos { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); if(scanner.hasNext()){ int n=scanner.nextInt(); int arr[]=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := scanner.getCurrent()->toInteger() ; ; i := i + 1 ) ; while (arr[0+1] /= 0) do ( arr[0+1] := (arr[0+1] + 1) mod n ; var i : int ; i := 1 ; while i < n do ( ( if (i mod 2 = 1) then ( arr[i+1] := (arr[i+1] + n - 1) mod n ) else ( arr[i+1] := (arr[i+1] + 1) mod n ) ) ; i := i + 1 ) ) ; if (check(arr)) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; ) else skip ); static operation check( arr : Sequence(int)) : boolean pre: true post: true activity: ( var count : int ; count := 0 ; for (i : arr) do ( if (i /= count) then return false else skip ; ) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class Solution { public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(reader.readLine()); int[] arr=new int[1000001]; StringTokenizer sToken=new StringTokenizer(reader.readLine()); for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,1000001)->collect(0) ; var sToken : OclIterator ; sToken := OclIterator.newOclIterator_String(reader.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( arr[(sToken.next())->toInteger()+1] := arr[(sToken.next())->toInteger()+1] + 1 ) ; i := i + 1 ) ; var rest : int ; rest := 0 ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i <= 1000000 do ( ( res := res+(((rest + arr[i+1]) mod 2)) ; rest := (rest + arr[i+1]) / 2 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 40 do ( ( res := res+((rest mod 2)) ; rest := rest / 2 ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class CodeForces_C3 { static int m=1000001 ; public static void main(String[] args){ Scanner input=new Scanner(System.in); int t=input.nextInt(); for(int tt=0 ; tt=1 && bitoInteger() ; var tt : int ; tt := 0 ; while tt < t do ( ( var n : int ; n := input.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( a[j+1] := input.getCurrent()->toInteger() ) ; j := j + 1 ) ; var bool : Sequence(boolean) ; bool := Integer.subrange(1,m)->collect(false) ; var idx : int ; idx := 0 ; var i : int ; i := 1 ; while i < m & idx < n do ( ( if (not(bool[i+1])) then ( b[idx+1] := i ; idx := idx + 1 ; for (x : a) do ( ( for (y : a) do ( ( var bi : int ; bi := i + x - y ; if (bi >= 1 & bi < m) then ( bool[bi+1] := true ) else skip ) ) ) ) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(b[i+1] + " ") ) ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ; tt := tt + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int count=0 ; String S=sc.next(); for(int i=0 ; isize() do ( ( if ('+' = S->at(i+1)) then ( count := count + 1 ) else count := count - 1 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.IOException ; public class Main { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String[] str=in.readLine().split(""); int ans=0 ; for(int i=0 ; i<4 ; i++){ if(str[i] .equals("+"))ans++; else ans--; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : Sequence(String) ; str := in.readLine()->split("") ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( if (str[i+1] = "+") then ans := ans + 1 ; else ans := ans - 1 ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner scanner=new Scanner(System.in); public static void main(String[] $){ String s=scanner.next(); System.out.println(s.replace("-","").length()-s.replace("+","").length()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scanner : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := scanner.getCurrent() ; OclFile["System.out"].println(s.replace("-", "")->size() - s.replace("+", "")->size()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String S=sc.next(); String S1=S.substring(0,1); String S2=S.substring(1,2); String S3=S.substring(2,3); String S4=S.substring(3,4); int count=0 ; if(S1.equals("+")){ count++; } else { count--; } if(S2.equals("+")){ count++; } else { count--; } if(S3.equals("+")){ count++; } else { count--; } if(S4.equals("+")){ count++; } else { count--; } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : String ; S := sc.getCurrent() ; var S1 : String ; S1 := S.subrange(0+1,1) ; var S2 : String ; S2 := S.subrange(1+1,2) ; var S3 : String ; S3 := S.subrange(2+1,3) ; var S4 : String ; S4 := S.subrange(3+1,4) ; var count : int ; count := 0 ; if (S1 = "+") then ( count := count + 1 ) else ( count := count - 1 ) ; if (S2 = "+") then ( count := count + 1 ) else ( count := count - 1 ) ; if (S3 = "+") then ( count := count + 1 ) else ( count := count - 1 ) ; if (S4 = "+") then ( count := count + 1 ) else ( count := count - 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc ; int N ; int[][] P ; public Main(){ sc=new Scanner(System.in); } private void calc(){ N=sc.nextInt(); P=new int[N][2]; for(int i=0 ; i-Integer.compare(a[1],b[1])); TreeSett=new TreeSet<>(); long s=0 ; for(int i=0 ; itail=t.tailSet(ind,false).iterator(); int c=tail.hasNext()? tail.next(): N ; int d=tail.hasNext()? tail.next(): N ; Iteratorhead=t.headSet(ind,false).descendingIterator(); int b=head.hasNext()? head.next():-1 ; int a=head.hasNext()? head.next():-1 ; s+=((long)P[i][1])*((c-ind)*(b-a)+(d-c)*(ind-b)); } System.out.println(s); } public static void main(String[] args){ new Main().calc(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; attribute N : int; attribute P : Sequence(Sequence(int)); static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ); operation calc() : void pre: true post: true activity: ( N := sc.getCurrent()->toInteger() ; P := Integer.subrange(1,N)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1][0+1] := i ; P[i+1][1+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; P := OclComparator.sortWith(P, lambda (a , b) : OclAny in -compare(a[1+1], b[1+1])) ; var t : Set(int) ; t := Set{} ; var s : long ; s := 0 ; var i : int ; i := 0 ; while i < N do ( ( var ind : int ; ind := P[i+1][0+1] ; t := t->including(ind) ; var tail : OclIterator ; tail := t->select( _x0 | _x0 >= ind, false )->iterator() ; var c : int ; c := if tail.hasNext() then tail.next() else N endif ; var d : int ; d := if tail.hasNext() then tail.next() else N endif ; var head : OclIterator ; head := t->select( _x0 | _x0 < ind, false ).descendingIterator() ; var b : int ; b := if head.hasNext() then head.next() else -1 endif ; var a : int ; a := if head.hasNext() then head.next() else -1 endif ; s := s+((P[i+1][1+1]->oclAsType(long)) * ((c - ind) * (b - a) + (d - c) * (ind - b))) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(s) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().calc() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ partA101(); } public static void partA101(){ Scanner scA=new Scanner(System.in); String S=scA.next(); int count=0 ; for(int i=0 ; i<4 ; i++){ if(S.charAt(i)=='+'){ count++; } else if(S.charAt(i)=='-'){ count--; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute partA101() ); static operation partA101() : void pre: true post: true activity: ( var scA : OclFile ; scA := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : String ; S := scA.getCurrent() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( if (S->at(i+1) = '+') then ( count := count + 1 ) else if (S->at(i+1) = '-') then ( count := count - 1 ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class SlimeCombining { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); ArrayListA=new ArrayList(); for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( A := A->including(1) ) ; i := i + 1 ) ; var x : int ; x := 0 ; while x < 100000 do ( ( var i : int ; i := 0 ; while (i < A->size() - 1) do ( if (A->at(i+1) = A->at(i + 1+1)) then ( A := A.setAt(i+1,A->at(i+1) + 1) ; A := A.setAt(i + 1+1,0) ) else skip ; i := i + 1 ) ; var itr : OclIterator ; itr := A->iterator() ; while (itr.hasNext()) do ( if (itr.next()->oclAsType(int) = 0) then ( itr := itr.remove() ) else skip ) ) ; x := x + 1 ) ; var i : int ; i := 0 ; while i < A->size() do ( ( OclFile["System.out"].print(A->at(i+1) + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class questionCF { static ArrayListgame(ArrayListlist,int n){ if(n==1){ list.add(1); return list ; } if(n==2){ list.add(2); return list ; } int count=0 ; for(int i=1 ; true ; i=i*2){ count++; if(i==n){ list.add(count); return list ; } else if(i>n){ list.add(count-1); game(list,n-(i/2)); return list ; } } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayListl=new ArrayList<>(); ArrayListlist=game(l,n); for(int i=0 ; iexcludes(1) ; return list ) else skip ; if (n = 2) then ( list->excludes(2) ; return list ) else skip ; var count : int ; count := 0 ; var i : int ; i := 1 ; while true do ( ( count := count + 1 ; if (i = n) then ( list->excludes(count) ; return list ) else if (i > n) then ( list->excludes(count - 1) ; execute game(list, n - (i / 2)) ; return list ) else skip ; ) ; i := i * 2 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var l : Sequence(int) ; l := Sequence{} ; var list : Sequence(int) ; list := game(l, n) ; var i : int ; i := 0 ; while i < list->size() do ( OclFile["System.out"].print(list->at(i+1) + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class questionCF { static ArrayListgame(ArrayListlist,int n){ if(n==1){ list.add(1); return list ; } if(n==2){ list.add(2); return list ; } int count=0 ; for(int i=1 ; true ; i=i*2){ count++; if(i==n){ list.add(count); return list ; } else if(i>n){ list.add(count-1); game(list,n-(i/2)); return list ; } } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayListl=new ArrayList<>(); ArrayListlist=game(l,n); for(int i=0 ; iexcludes(1) ; return list ) else skip ; if (n = 2) then ( list->excludes(2) ; return list ) else skip ; var count : int ; count := 0 ; var i : int ; i := 1 ; while true do ( ( count := count + 1 ; if (i = n) then ( list->excludes(count) ; return list ) else if (i > n) then ( list->excludes(count - 1) ; execute game(list, n - (i / 2)) ; return list ) else skip ; ) ; i := i * 2 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var l : Sequence(int) ; l := Sequence{} ; var list : Sequence(int) ; list := game(l, n) ; var i : int ; i := 0 ; while i < list->size() do ( OclFile["System.out"].print(list->at(i+1) + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class SlimeCombining { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); ArrayListA=new ArrayList(); for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( A := A->including(1) ) ; i := i + 1 ) ; var x : int ; x := 0 ; while x < n do ( ( var i : int ; i := 0 ; while (i < A->size() - 1) do ( if (A->at(i+1) = A->at(i + 1+1)) then ( A := A.setAt(i+1,A->at(i+1) + 1) ; A := A.setAt(i + 1+1,0) ) else skip ; i := i + 1 ) ; var itr : OclIterator ; itr := A->iterator() ; while (itr.hasNext()) do ( if (itr.next()->oclAsType(int) = 0) then ( itr := itr.remove() ) else skip ) ) ; x := x + 1 ) ; var i : int ; i := 0 ; while i < A->size() do ( ( OclFile["System.out"].print(A->at(i+1) + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0 ; iset=new HashSet<>(); Arrays.sort(arr); int[] diffs=new int[n*(n-1)/2]; int idx=0 ; for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scan.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( arr[j+1] := scan.getCurrent()->toInteger() ) ; j := j + 1 ) ; execute printArrayB(n, arr) ) ; i := i + 1 ) ); static operation printArrayB( n : int, arr : Sequence(int)) : void pre: true post: true activity: ( if (n = 1) then ( OclFile["System.out"].println("YES") ; OclFile["System.out"].println(1) ; return ) else skip ; var sb : String ; sb := StringLib.newString() ; var set : Set(int) ; set := Set{} ; arr := arr->sort() ; var diffs : Sequence(int) ; diffs := Integer.subrange(1,n * (n - 1) / 2)->collect(0) ; var idx : int ; idx := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( diffs[idx+1] := arr[j+1] - arr[i+1] ; idx := idx + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; sb := sb + StringLib.newString("YES\n") ; var count : int ; count := 0 ; var cur : int ; cur := 1 ; var random : OclRandom ; random := OclRandom.newOclRandom() ; while (count < n) do ( cur := random.nextInt(1000 * 1000) + 1 ; var valid : boolean ; valid := true ; for (num : arr) do ( ( if (set->includes(num + cur)) then ( valid := false ; break ) else skip ) ) ; if (valid) then ( count := count + 1 ; sb := sb + StringLib.newString(cur) + StringLib.newString(" ") ; if (valid) then ( for (hum : arr) do ( ( set := set->including(hum + cur) ) ) ) else skip ) else skip ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.Math ; import java.io.*; class GFG { static int nextPowerOfFour(int n){ int x=(int)Math.floor(Math.sqrt(Math.sqrt(n))); if(Math.pow(x,4)==n)return n ; else { x=x+1 ; return(int)Math.pow(x,4); } } public static void main(String[] args)throws java.lang.Exception { int n=122 ; System.out.println(nextPowerOfFour(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation nextPowerOfFour( n : int) : int pre: true post: true activity: ( var x : int ; x := (((n)->sqrt())->sqrt())->floor()->oclAsType(int) ; if (x->pow(4) = n) then return n else ( x := x + 1 ; return x->pow(4)->oclAsType(int) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 122 ; OclFile["System.out"].println(nextPowerOfFour(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int division(int num1,int num2){ if(num1==0)return 0 ; if(num2==0)return Integer.MAX_VALUE ; boolean negResult=false ; if(num1<0){ num1=-num1 ; if(num2<0)num2=-num2 ; else negResult=true ; } else if(num2<0){ num2=-num2 ; negResult=true ; } int quotient=0 ; while(num1>=num2){ num1=num1-num2 ; quotient++; } if(negResult)quotient=-quotient ; return quotient ; } public static void main(String[] args){ int num1=13,num2=2 ; System.out.println(division(num1,num2)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation division( num1 : int, num2 : int) : int pre: true post: true activity: ( if (num1 = 0) then return 0 else skip ; if (num2 = 0) then return 2147483647 else skip ; var negResult : boolean ; negResult := false ; 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 ; quotient := 0 ; while (num1 >= num2) do ( num1 := num1 - num2 ; quotient := quotient + 1 ) ; if (negResult) then quotient := -quotient ; else skip ; return quotient ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num1 : int ; num1 := 13 ; var num2 : int ; num2 := 2 ; OclFile["System.out"].println(division(num1, num2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] a=new long[n]; long max=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var max : long ; max := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ; max := Set{max, a[i+1]}->max() ) ; i := i + 1 ) ; var half : long ; half := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (if max / 2 - a[i+1] < 0 then -(max / 2 - a[i+1]) else max / 2 - a[i+1] endif < if max / 2 - half < 0 then -(max / 2 - half) else max / 2 - half endif) then ( half := a[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(max + " " + half) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); DBinomialCoefficients solver=new DBinomialCoefficients(); solver.solve(1,in,out); out.close(); } static class DBinomialCoefficients { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); int[] a=new int[n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var col : int ; col := a[n - 1+1] ; var min : int ; min := col / 2 ; var max : int ; max := min + (if col mod 2 = 0 then 0 else 1 endif) ; skip ; skip ; var d : int ; d := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( var cd : int ; cd := Set{if max - a[i+1] < 0 then -(max - a[i+1]) else max - a[i+1] endif, if min - a[i+1] < 0 then -(min - a[i+1]) else min - a[i+1] endif}->min() ; if (cd < d) then ( d := cd ) else ( skip ; return ) ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ final Scanner sc=new Scanner(System.in); int n=sc.nextInt(); TreeSetset=new TreeSet<>(); for(int i=0 ; itoInteger() ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( set := set->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var ans1 : int ; ans1 := set->last() ; var ans2 : int ; ans2 := 0 ; var diff : int ; diff := 2147483647 ; var h : int ; h := set.ceiling(ans1 / 2) ; var l : int ; l := set.lower(ans1 / 2) ; if (h = ans1) then ( h := l ) else skip ; if (ans1 mod 2 = 0) then ( var base : int ; base := ans1 / 2 ; if (h /= null) then ( var d : int ; d := if base - h < 0 then -(base - h) else base - h endif ; if (d < diff) then ( diff := d ; ans2 := h ) else skip ) else skip ; if (l /= null) then ( var d : int ; d := if base - l < 0 then -(base - l) else base - l endif ; if (d < diff) then ( diff := d ; ans2 := l ) else skip ) else skip ) else ( var base : int ; base := ans1 / 2 ; var base2 : int ; base2 := ans1 / 2 + 1 ; if (h /= null) then ( var d : int ; d := if base2 - h < 0 then -(base2 - h) else base2 - h endif ; if (d < diff) then ( diff := d ; ans2 := h ) else skip ) else skip ; if (l /= null) then ( var d : int ; d := if base - l < 0 then -(base - l) else base - l endif ; if (d < diff) then ( diff := d ; ans2 := l ) else skip ) else skip ) ; OclFile["System.out"].println(ans1 + " " + ans2) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; int[] pos=new int[n+1]; for(int i=0 ; iset=new TreeSet<>(); L[n]=pos[n]+1 ; R[n]=n-pos[n]; set.add(pos[n]); long res=0 ; for(int k=n-1 ; k>=1 ; k--){ Integer left=set.lower(pos[k]); Integer right=set.higher(pos[k]); if(left==null){ L[k]=pos[k]+1 ; } else { L[k]=pos[k]-left ; R[arr[left] ]=L[k]; } if(right==null){ R[k]=n-pos[k]; } else { R[k]=right-pos[k]; L[arr[right] ]=R[k]; } if(left!=null){ res+=((long)k)*((long)L[arr[left] ])*((long)R[k]); } if(right!=null){ res+=((long)k)*((long)L[k])*((long)R[arr[right] ]); } set.add(pos[k]); } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var pos : Sequence(int) ; pos := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ; pos[arr[i+1]+1] := i ) ; i := i + 1 ) ; var L : Sequence(int) ; L := Integer.subrange(1,n + 1)->collect(0) ; var R : Sequence(int) ; R := Integer.subrange(1,n + 1)->collect(0) ; var set : Set(int) ; set := Set{} ; L[n+1] := pos[n+1] + 1 ; R[n+1] := n - pos[n+1] ; set := set->including(pos[n+1]) ; var res : long ; res := 0 ; var k : int ; k := n - 1 ; while k >= 1 do ( ( var left : int ; left := set.lower(pos[k+1]) ; var right : int ; right := set.higher(pos[k+1]) ; if (left = null) then ( L[k+1] := pos[k+1] + 1 ) else ( L[k+1] := pos[k+1] - left ; R[arr[left+1]+1] := L[k+1] ) ; if (right = null) then ( R[k+1] := n - pos[k+1] ) else ( R[k+1] := right - pos[k+1] ; L[arr[right+1]+1] := R[k+1] ) ; if (left /= null) then ( res := res+((k->oclAsType(long)) * (L[arr[left+1]+1]->oclAsType(long)) * (R[k+1]->oclAsType(long))) ) else skip ; if (right /= null) then ( res := res+((k->oclAsType(long)) * (L[k+1]->oclAsType(long)) * (R[arr[right+1]+1]->oclAsType(long))) ) else skip ; set := set->including(pos[k+1]) ; ) ; k := k - 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Comparator ; import java.util.PriorityQueue ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); int[] input=new int[n]; String[] tmpArray=br.readLine().split(" "); for(int i=0 ; i=Math.abs(input[i]-med)){ a=i ; } } System.out.println(input[b]+" "+input[a]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var n : int ; n := (br.readLine())->toInteger() ; var input : Sequence(int) ; input := Integer.subrange(1,n)->collect(0) ; var tmpArray : Sequence(String) ; tmpArray := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( ( input[i+1] := (tmpArray[i+1])->toInteger() ) ; i := i + 1 ) ; input := input->sort() ; var a : int ; a := 0 ; var b : int ; b := n - 1 ; var med : int ; med := input[n - 1+1] / 2 ; var i : int ; i := 1 ; while i < n - 2 do ( ( if (if input[a+1] - med < 0 then -(input[a+1] - med) else input[a+1] - med endif >= if input[i+1] - med < 0 then -(input[i+1] - med) else input[i+1] - med endif) then ( a := i ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(input[b+1] + " " + input[a+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; for(int i=0 ; i=0 ; i--){ if(Math.abs(target-a[i])=0 ; i--){ int old=Math.min(Math.abs(ans-t1),Math.abs(ans-t2)); int cur=Math.min(Math.abs(a[i]-t1),Math.abs(a[i]-t2)); if(curtoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; a := a->sort() ; OclFile["System.out"].print(((a[n - 1+1]) + "") + " ") ; var ans : int ; ans := a[n - 2+1] ; if (a[n - 1+1] mod 2 = 0) then ( var target : int ; target := a[n - 1+1] / 2 ; var i : int ; i := n - 3 ; while i >= 0 do ( ( if (if target - a[i+1] < 0 then -(target - a[i+1]) else target - a[i+1] endif < if target - ans < 0 then -(target - ans) else target - ans endif) then ans := a[i+1] ; else skip ) ; i := i - 1 ) ) else ( var t1 : int ; t1 := a[n - 1+1] / 2 ; var t2 : int ; t2 := a[n - 1+1] / 2 + 1 ; var i : int ; i := n - 3 ; while i >= 0 do ( ( var old : int ; old := Set{if ans - t1 < 0 then -(ans - t1) else ans - t1 endif, if ans - t2 < 0 then -(ans - t2) else ans - t2 endif}->min() ; var cur : int ; cur := Set{if a[i+1] - t1 < 0 then -(a[i+1] - t1) else a[i+1] - t1 endif, if a[i+1] - t2 < 0 then -(a[i+1] - t2) else a[i+1] - t2 endif}->min() ; if (cur < old) then ans := a[i+1] ; else skip ) ; i := i - 1 ) ) ; OclFile["System.out"].print(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p020 implements EulerSolution { public static void main(String[] args){ System.out.println(new p020().run()); } public String run(){ String temp=Library.factorial(100).toString(); int sum=0 ; for(int i=0 ; isize() do ( sum := sum+(temp->at(i+1) - ('0')->char2byte()) ; ; i := i + 1 ) ; return ((sum) + "") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.Math ; class GFG { static int NthArmstrong(int n){ int count=0 ; for(int i=1 ; i<=Integer.MAX_VALUE ; i++){ int num=i,rem,digit=0,sum=0 ; num=i ; digit=(int)Math.log10(num)+1 ; while(num>0){ rem=num % 10 ; sum=sum+(int)Math.pow(rem,digit); num=num/10 ; } if(i==sum)count++; if(count==n)return i ; } return n ; } public static void main(String[] args){ int n=12 ; System.out.println(NthArmstrong(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation NthArmstrong( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 1 ; while i <= 2147483647 do ( ( var num : int ; num := i ; var rem : int ; var digit : int ; digit := 0 ; var sum : int ; sum := 0 ; num := i ; digit := (num)->log10()->oclAsType(int) + 1 ; while (num > 0) do ( rem := num mod 10 ; sum := sum + rem->pow(digit)->oclAsType(int) ; num := num / 10 ) ; if (i = sum) then count := count + 1 ; else skip ; if (count = n) then return i else skip ; ) ; i := i + 1 ) ; return n ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 12 ; OclFile["System.out"].println(NthArmstrong(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Main { static int binarySearch(int arr[],int low,int high,int key){ if(higharr[mid])return binarySearch(arr,(mid+1),high,key); return binarySearch(arr,low,(mid-1),key); } public static void main(String[] args){ int arr[]={ 5,6,7,8,9,10 }; int n,key ; n=arr.length ; key=10 ; System.out.println("Index: "+binarySearch(arr,0,n,key)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation binarySearch( arr : Sequence(int), low : int, high : int, key : int) : int pre: true post: true activity: ( if (high < low) then return -1 else skip ; var mid : int ; mid := (low + high) / 2 ; if (key = arr[mid+1]) then return mid else skip ; if (key > arr[mid+1]) then return binarySearch(arr, (mid + 1), high, key) else skip ; return binarySearch(arr, low, (mid - 1), key) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{5,6,7,8,9,10} ; var n : int ; var key : int ; n := arr->size() ; key := 10 ; OclFile["System.out"].println("Index: " + binarySearch(arr, 0, n, key)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Codeforces3 { public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); System.out.println((n-3)+" "+1+" "+1+" "+1); } } } ------------------------------------------------------------ OCL File: --------- class Codeforces3 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := s.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := s.getCurrent()->toInteger() ; OclFile["System.out"].println((n - 3) + " " + 1 + " " + 1 + " " + 1) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t--!=0){ int n=scanner.nextInt(); System.out.println(n-3+" "+1+" "+1+" "+1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; OclFile["System.out"].println(n - 3 + " " + 1 + " " + 1 + " " + 1) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; import static java.lang.Double.parseDouble ; import static java.lang.Integer.bitCount ; import static java.lang.Integer.parseInt ; import static java.lang.Long.parseLong ; public class Test3 { private static final BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out)); private static final Fast in=new Fast(); public static void main(String[] args)throws IOException { int num=in.nextInt(); for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return parseLong(next()) ); operation nextDouble() : double pre: true post: true activity: ( return parseDouble(next()) ); operation nextFloat() : double pre: true post: true activity: ( return parseFloat(next()) ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.BigInteger ; import java.util.*; public class TaskC { static final int SIZE=(int)2e5+5 ; static ArrayListli=new ArrayList<>(); public static void solve(InputReader in,PrintWriter out){ int n=in.nextInt(); int t=n-2 ; out.println(1+" "+(t-1)+" 1 "+"1"); } public static void init(){ } public static void clear(int n){ } public static void main(String[] args){ init(); InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int T=1 ; T=in.nextInt(); for(int i=1 ; i<=T ; ++i){ solve(in,out); } out.close(); } private static class InputReader { private BufferedReader reader ; private StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public String nextLine(){ String str="" ; try { str=reader.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class TaskC { static attribute SIZE : int := 2e5->oclAsType(int) + 5; static attribute li : Sequence(long) := Sequence{}; static operation solve( in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var t : int ; t := n - 2 ; out.println(1 + " " + (t - 1) + " 1 " + "1") ); static operation init() : void pre: true post: true activity: skip; static operation clear( n : int) : void pre: true post: true activity: skip; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute init() ; var in : InputReader ; in := InputReader.newInputReader(OclFile["System.in"]) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var T : int ; T := 1 ; T := in.nextInt() ; var i : int ; i := 1 ; while i <= T do ( ( execute solve(in, out) ) ; i := i + 1 ) ; skip ; ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := reader.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.math.*; public class Main { public static void main(String[] args){ Scanner sin=new Scanner(System.in); int n=sin.nextInt(); BigInteger plus ; System.out.println(2); for(int i=2 ; itoInteger() ; var plus : long ; OclFile["System.out"].println(2) ; var i : int ; i := 2 ; while i < n + 1 do ( ( plus := (i + 1 + "")->toLong() ; plus := plus.multiply(plus) ; plus := plus.multiply((i + "")->toLong()) ; plus := plus.subtract((i - 1 + "")->toLong()) ; OclFile["System.out"].println(plus) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf3 { private static Scanner is=new Scanner(System.in); public static long isSquare(long n){ double sq=Math.sqrt(n); if((long)sq*(long)sq==n)return(long)sq ; else return-1 ; } public static void main(String[] args){ int n=is.nextInt(); long[] pluses=new long[n]; long onScreen=2 ; int k=2 ; pluses[0]=2 ; long nextsq=6 ; while(ksqrt() ; if (sq->oclAsType(long) * sq->oclAsType(long) = n) then return sq->oclAsType(long) else return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := is.getCurrent()->toInteger() ; var pluses : Sequence(long) ; pluses := Integer.subrange(1,n)->collect(0) ; var onScreen : long ; onScreen := 2 ; var k : int ; k := 2 ; pluses[0+1] := 2 ; var nextsq : long ; nextsq := 6 ; while (k < n + 1) do ( pluses[k - 1+1] := nextsq * ((k + 1)->oclAsType(long)) - (k - 1)->oclAsType(long) ; k := k + 1 ; onScreen := nextsq ; var sq : long ; sq := isSquare(k) ; nextsq := k * (k + 1) ; ) ; OclFile["System.out"].println(2) ; var i : long ; i := 2 ; while i <= n do ( ( OclFile["System.out"].println(i * (i + 1) * (i + 1) - (i - 1)) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); int[] P=new int[N]; int[] A=new int[N+1]; for(int i=0 ; iset=new TreeSet<>(); set.add(0); set.add(N+1); set.add(A[N]); long sum=0 ; for(int i=N-1 ; i>=1 ; --i){ int Xi=A[i]; long y=set.higher(Xi); long z=ytoInteger() ; var P : Sequence(int) ; P := Integer.subrange(1,N)->collect(0) ; var A : Sequence(int) ; A := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( P[i+1] := (sc.getCurrent())->toInteger() ; A[P[i+1]+1] := i + 1 ) ; i := i + 1 ) ; skip ; var set : Set(int) ; set := Set{} ; set := set->including(0) ; set := set->including(N + 1) ; set := set->including(A[N+1]) ; var sum : long ; sum := 0 ; var i : int ; i := N - 1 ; while i >= 1 do ( ( var Xi : int ; Xi := A[i+1] ; var y : long ; y := set.higher(Xi) ; var z : long ; z := if y < N + 1 then set.higher(y->oclAsType(int)) else N + 1 endif ; var x : long ; x := set.lower(Xi) ; var w : long ; w := if x /= 0 then set.lower(x->oclAsType(int)) else 0 endif ; var C : long ; C := (x - w) * (y - Xi) + (Xi - x) * (z - y) ; sum := sum+(C * i) ; set := set->including(Xi) ; ) ; i := i - 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf3 { private static Scanner is=new Scanner(System.in); public static long isSquare(long n){ double sq=Math.sqrt(n); if((long)sq*(long)sq==n)return(long)sq ; else return-1 ; } public static void main(String[] args){ int n=is.nextInt(); long[] pluses=new long[n]; long onScreen=2 ; int k=2 ; pluses[0]=2 ; long nextsq=2 ; while(ksqrt() ; if (sq->oclAsType(long) * sq->oclAsType(long) = n) then return sq->oclAsType(long) else return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := is.getCurrent()->toInteger() ; var pluses : Sequence(long) ; pluses := Integer.subrange(1,n)->collect(0) ; var onScreen : long ; onScreen := 2 ; var k : int ; k := 2 ; pluses[0+1] := 2 ; var nextsq : long ; nextsq := 2 ; while (k < n + 1) do ( pluses[k - 1+1] := ((k + 1)->oclAsType(long)) * (k + 1) * k - (k - 1) ; k := k + 1 ; onScreen := nextsq ; var sq : long ; sq := isSquare(k) ; nextsq := k * (k + 1) ; ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(if pluses[i+1] < 0 then -(pluses[i+1]) else pluses[i+1] endif) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean digitWell(int n,int m,int k){ int cnt=0 ; while(n>0){ if(n % 10==m)++cnt ; n/=10 ; } return cnt==k ; } static int findInt(int n,int m,int k){ int i=n+1 ; while(true){ if(digitWell(i,m,k))return i ; i++; } } public static void main(String[] args){ int n=111,m=2,k=2 ; System.out.println(findInt(n,m,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation digitWell( n : int, m : int, k : int) : boolean pre: true post: true activity: ( var cnt : int ; cnt := 0 ; while (n > 0) do ( if (n mod 10 = m) then cnt := cnt + 1 ; else skip ; n := n/(10) ) ; return cnt = k ); static operation findInt( n : int, m : int, k : int) : int pre: true post: true activity: ( var i : int ; i := n + 1 ; while (true) do ( if (digitWell(i, m, k)) then return i else skip ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 111 ; var m : int ; m := 2 ; var k : int ; k := 2 ; OclFile["System.out"].println(findInt(n, m, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; class GFG { static int findCount(int d){ return 9*(int)((Math.pow(10,d-1)-Math.pow(9,d-1))); } static int findCountUpto(int d){ int totalCount=0 ; for(int i=1 ; i<=d ; i++)totalCount+=findCount(i); return totalCount ; } public static void main(String args[]){ int d=1 ; System.out.println(findCountUpto(d)); d=2 ; System.out.println(findCountUpto(d)); d=4 ; System.out.println(findCountUpto(d)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findCount( d : int) : int pre: true post: true activity: ( return 9 * ((10->pow(d - 1) - 9->pow(d - 1)))->oclAsType(int) ); static operation findCountUpto( d : int) : int pre: true post: true activity: ( var totalCount : int ; totalCount := 0 ; var i : int ; i := 1 ; while i <= d do ( totalCount := totalCount+(findCount(i)) ; ; i := i + 1 ) ; return totalCount ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var d : int ; d := 1 ; OclFile["System.out"].println(findCountUpto(d)) ; d := 2 ; OclFile["System.out"].println(findCountUpto(d)) ; d := 4 ; OclFile["System.out"].println(findCountUpto(d)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void equal_xor_sum(int arr[],int n){ int Sum=0 ; int Xor=0 ; for(int i=0 ; isize() ; execute equal_xor_sum(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(); int[] arr=new int[n+1]; for(int i=1 ; i<=n ; i++){ arr[n-i+1]=i ; } if(an/2 || a==n/2+1 && b==n/2){ for(int i=1 ; i<=n ; i++)System.out.print(arr[i]+" "); System.out.println(); } else System.out.println("-1"); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( arr[n - i + 1+1] := i ) ; i := i + 1 ) ; if (a < b) then ( arr[n - a + 1+1] := b ; arr[n - b + 1+1] := a ) else skip ; if (a <= n / 2 & b > n / 2 or a = n / 2 + 1 & b = n / 2) then ( var i : int ; i := 1 ; while i <= n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ) else OclFile["System.out"].println("-1") ; ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Main { static int getMissingNo(int a[],int n){ int i,total ; total=(n+1)*(n+2)/2 ; for(i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); Integer[] A=new Integer[N]; int all=0 ; for(int i=0 ; itoInteger() ; var M : int ; M := sc.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(null) ; var all : int ; all := 0 ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := sc.getCurrent()->toInteger() ; all := all+(A[i+1]) ) ; i := i + 1 ) ; skip ; A := OclComparator.sortWith(A, reverseOrder()) ; if (A[M - 1+1] < (all / (4.0 * M))->ceil()) then ( OclFile["System.out"].println("No") ; return ) else skip ; OclFile["System.out"].println("Yes") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args)throws IOException { int n=sc.nextInt(); int m=sc.nextInt(); int[] a=new int[n]; int sum=0 ; for(int i=0 ; i=val){ count++; } } if(count>=m)out.println("Yes"); else out.println("No"); out.flush(); out.close(); } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader fileReader){ br=new BufferedReader(fileReader); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public String nextLine()throws IOException { return br.readLine(); } public boolean ready()throws IOException { return br.ready(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; sum := sum+(a[i+1]) ) ; i := i + 1 ) ; a := a->sort() ; var val : int ; val := (sum + (4 * m - 1)) / (4 * m) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] >= val) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; if (count >= m) then skip else skip ; ; skip ; skip ; ); static class Scanner { attribute st : OclIterator; attribute br : OclFile; static operation newScanner( s : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newScanner( fileReader : OclFile) : Scanner pre: true post: true activity: ( var self : Scanner ; self := createScanner(); self.initialise(fileReader); return self ); operation initialise( fileReader : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(fileReader) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ ArrayListnumeros=new ArrayList(); Scanner scan=new Scanner(System.in); int N=scan.nextInt(); double M=scan.nextFloat(); int contador=0 ; int sumaTotal=0 ; double valor=0 ; double porcentaje=(1/(4*M)); while(contador=valor){ contador++; } } if(contador>=M){ System.out.println("Yes"); } else { System.out.println("No"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var numeros : Sequence(int) ; numeros := Sequence{} ; var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scan.getCurrent()->toInteger() ; var M : double ; M := scan.nextFloat() ; var contador : int ; contador := 0 ; var sumaTotal : int ; sumaTotal := 0 ; var valor : double ; valor := 0 ; var porcentaje : double ; porcentaje := (1 / (4 * M)) ; while (contador < N) do ( var numerito : int ; numerito := scan.getCurrent()->toInteger() ; numeros := numeros->including(numerito) ; sumaTotal := sumaTotal+(numerito) ; contador := contador + 1 ) ; valor := sumaTotal * porcentaje ; contador := 0 ; for (a : numeros) do ( ( if (a >= valor) then ( contador := contador + 1 ) else skip ) ) ; if (contador >= M) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int total=scanner.nextInt(); long popular=scanner.nextInt(); int[] target=new int[total]; int tokuhyo ; String result="Yes" ; for(int i=0 ; itoInteger() ; var popular : long ; popular := scanner.getCurrent()->toInteger() ; var target : Sequence(int) ; target := Integer.subrange(1,total)->collect(0) ; var tokuhyo : int ; var result : String ; result := "Yes" ; var i : int ; i := 0 ; while i < total do ( ( target[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; tokuhyo := java.util.Arrays.stream(target)->sum() ; target := stream(target)->sort()->collect( _x1 | (lambda _pars : OclAny in Integer.newInteger().intValue(_pars))->apply(_x1) )->asSequence() ; var t : long ; t := 4 * popular ; var l : double ; l := 1->oclAsType(double) / t ; var s : double ; s := tokuhyo * l ; var i : int ; i := 0 ; while i < popular do ( ( if (target[i+1] < s) then ( result := "No" ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int N ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); N=sc.nextInt(); int P[]=new int[N]; for(int i=0 ; its=new TreeSet<>(); long ans=0 ; for(int i=N-1 ; i>=0 ; i--){ int now=idx[i]; int hi1=myHigher(ts,now); int hi2=myHigher(ts,hi1); int low1=myLower(ts,now); int low2=myLower(ts,low1); long cnt=(long)(hi2-hi1)*(now-low1)+(long)(hi1-now)*(low1-low2); ans+=cnt*(i+1); ts.add(now); } System.out.println(ans); } static int myHigher(TreeSetts,int now){ if(ts.higher(now)!=null)return ts.higher(now); else return N ; } static int myLower(TreeSetts,int now){ if(ts.lower(now)!=null)return ts.lower(now); else return-1 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute N : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := sc.getCurrent()->toInteger() ; var P : Sequence(int) ; P := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( P[i+1] := sc.getCurrent()->toInteger() - 1 ; ; i := i + 1 ) ; skip ; var idx : Sequence(int) ; idx := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( idx[P[i+1]+1] := i ; ; i := i + 1 ) ; var ts : Set(int) ; ts := Set{} ; var ans : long ; ans := 0 ; var i : int ; i := N - 1 ; while i >= 0 do ( ( var now : int ; now := idx[i+1] ; var hi1 : int ; hi1 := myHigher(ts, now) ; var hi2 : int ; hi2 := myHigher(ts, hi1) ; var low1 : int ; low1 := myLower(ts, now) ; var low2 : int ; low2 := myLower(ts, low1) ; var cnt : long ; cnt := (hi2 - hi1)->oclAsType(long) * (now - low1) + (hi1 - now)->oclAsType(long) * (low1 - low2) ; ans := ans+(cnt * (i + 1)) ; ts := ts->including(now) ; ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); static operation myHigher( ts : Set(int), now : int) : int pre: true post: true activity: ( if (ts.higher(now) /= null) then return ts.higher(now) else return N ); static operation myLower( ts : Set(int), now : int) : int pre: true post: true activity: ( if (ts.lower(now) /= null) then return ts.lower(now) else return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int[] fact=new int[14]; static int size=1 ; static void preCompute(int N){ fact[0]=1 ; for(int i=1 ; fact[i-1]<=N ; i++){ fact[i]=(fact[i-1]*i); size++; } } static void findMin(int N){ preCompute(N); int originalN=N ; Vectorans=new Vector(); for(int i=size-1 ; i>=0 ; i--){ while(N>=fact[i]){ N-=fact[i]; ans.add(fact[i]); } } System.out.print(ans.size()+"\n"); for(int i=0 ; icollect(0); static attribute size : int := 1; static operation preCompute( N : int) : void pre: true post: true activity: ( fact[0+1] := 1 ; var i : int ; i := 1 ; while fact[i - 1+1] <= N do ( ( fact[i+1] := (fact[i - 1+1] * i) ; size := size + 1 ) ; i := i + 1 ) ); static operation findMin( N : int) : void pre: true post: true activity: ( execute preCompute(N) ; var originalN : int ; originalN := N ; var ans : Sequence(int) ; ans := Sequence{} ; var i : int ; i := size - 1 ; while i >= 0 do ( ( while (N >= fact[i+1]) do ( N := N-(fact[i+1]) ; ans := ans->including(fact[i+1]) ) ) ; i := i - 1 ) ; OclFile["System.out"].print(ans->size() + "\n") ; var i : int ; i := 0 ; while i < ans->size() do ( OclFile["System.out"].print(ans->at(i+1) + " ") ; ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 27 ; execute findMin(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { static boolean[] x=new boolean[10000001]; public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringBuilder out=new StringBuilder(); StringTokenizer tk=new StringTokenizer(in.readLine()); int n=Int(tk.nextToken()),m=Int(tk.nextToken()),k=Int(tk.nextToken()); tk=new StringTokenizer(in.readLine()); for(int i=0 ; i0){ if(x[pos]){ System.out.println(pos); return ; } tk=new StringTokenizer(in.readLine()); int a=Int(tk.nextToken()),b=Int(tk.nextToken()); pos=(pos==a)? b : pos==b ? a : pos ; } System.out.println(pos); } static int Int(String s){ return Integer.parseInt(s); } static long Lon(String s){ return Long.parseLong(s); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute x : Sequence(boolean) := Integer.subrange(1,10000001)->collect(false); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : String ; out := StringLib.newString() ; var tk : OclIterator ; tk := OclIterator.newOclIterator_String(in.readLine()) ; var n : int ; n := Int(tk.next()) ; var m : int ; m := Int(tk.next()) ; var k : int ; k := Int(tk.next()) ; tk := OclIterator.newOclIterator_String(in.readLine()) ; var i : int ; i := 0 ; while i < m do ( ( x[Int(tk.next())+1] := true ) ; i := i + 1 ) ; var pos : int ; pos := 1 ; while (k > 0) do ( k := k - 1 ; skip ; ( if (x[pos+1]) then ( OclFile["System.out"].println(pos) ; return ) else skip ; tk := OclIterator.newOclIterator_String(in.readLine()) ; var a : int ; a := Int(tk.next()) ; var b : int ; b := Int(tk.next()) ; pos := if (pos = a) then b else if pos = b then a else pos endif endif ) ; ) ; OclFile["System.out"].println(pos) ; ); static operation Int( s : String) : int pre: true post: true activity: ( return (s)->toInteger() ); static operation Lon( s : String) : long pre: true post: true activity: ( return (s)->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Odd { public static int oddSum(int n){ int sum=0,curr=1 ; for(int i=0 ; isize() do ( var j : int ; j := 0 ; while j < s2->size() do ( if (s1->at(i+1) = s2->at(j+1)) then return true else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; return false ); static operation countPairs( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var numberOfPairs : int ; numberOfPairs := 0 ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := i + 1 ; while j < n do ( if (checkValidPair(arr[i+1], arr[j+1])) then numberOfPairs := numberOfPairs + 1 ; else skip ; ; j := j + 1 ) ; ; i := i + 1 ) ; return numberOfPairs ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,12,24} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(countPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; class GFG { static ArrayList values_of_r_and_a(double m,double n,double mth,double nth){ if(mpow(1.0 / (m - n)) ; var a : double ; a := mth / r->pow((m - 1)) ; var arr : Sequence ; arr := Sequence{} ; arr := arr->including(a) ; arr := arr->including(r) ; return arr ); static operation FindSum( m : double, n : double, mth : double, nth : double, p : double) : double pre: true post: true activity: ( var ar : Sequence ; ar := values_of_r_and_a(m, n, mth, nth) ; var a : double ; a := ar->at(0+1)->oclAsType(double) ; var r : double ; r := ar->at(1+1)->oclAsType(double) ; var pth : double ; pth := a * r->pow((p - 1.0)) ; return pth ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var m : double ; m := 10 ; var n : double ; n := 5 ; var p : double ; p := 15 ; var mth : double ; mth := 2560 ; var nth : double ; nth := 80 ; OclFile["System.out"].println(FindSum(m, n, mth, nth, p)->oclAsType(int)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class CoinChange { static long countWays(int S[],int m,int n){ long[] table=new long[n+1]; Arrays.fill(table,0); table[0]=1 ; for(int i=0 ; icollect(0) ; table := table->collect(0) ; table[0+1] := 1 ; var i : int ; i := 0 ; while i < m do ( var j : int ; j := S[i+1] ; while j <= n do ( table[j+1] := table[j+1]+(table[j - S[i+1]+1]) ; ; j := j + 1 ) ; ; i := i + 1 ) ; return table[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3} ; var m : int ; m := arr->size() ; var n : int ; n := 4 ; OclFile["System.out"].println(countWays(arr, m, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class CoinChange { static long countWays(int S[],int m,int n){ long[] table=new long[n+1]; Arrays.fill(table,0); table[0]=1 ; for(int i=0 ; icollect(0) ; table := table->collect(0) ; table[0+1] := 1 ; var i : int ; i := 0 ; while i < m do ( var j : int ; j := S[i+1] ; while j <= n do ( table[j+1] := table[j+1]+(table[j - S[i+1]+1]) ; ; j := j + 1 ) ; ; i := i + 1 ) ; return table[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3} ; var m : int ; m := arr->size() ; var n : int ; n := 4 ; OclFile["System.out"].println(countWays(arr, m, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static void incrementVector(Vectora){ int n=a.size(); a.set(n-1,a.get(n-1)+1); int carry=a.get(n-1)/10 ; a.set(n-1,a.get(n-1)% 10); for(int i=n-2 ; i>=0 ; i--){ if(carry==1){ a.set(i,a.get(i)+1); carry=a.get(i)/10 ; a.set(i,a.get(i)% 10); } } if(carry==1)a.add(0,1); } public static void main(String[] args){ Vectorvect=new Vector(); vect.add(1); vect.add(7); vect.add(8); vect.add(9); incrementVector(vect); for(int i=0 ; isize() ; a := a.setAt(n - 1+1, a->at(n - 1+1) + 1) ; var carry : int ; carry := a->at(n - 1+1) / 10 ; a := a.setAt(n - 1+1, a->at(n - 1+1) mod 10) ; var i : int ; i := n - 2 ; while i >= 0 do ( ( if (carry = 1) then ( a := a.setAt(i+1, a->at(i+1) + 1) ; carry := a->at(i+1) / 10 ; a := a.setAt(i+1, a->at(i+1) mod 10) ) else skip ) ; i := i - 1 ) ; if (carry = 1) then a->excludes(0, 1) ; else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var vect : Sequence(int) ; vect := Sequence{} ; vect := vect->including(1) ; vect := vect->including(7) ; vect := vect->including(8) ; vect := vect->including(9) ; execute incrementVector(vect) ; var i : int ; i := 0 ; while i < vect->size() do ( OclFile["System.out"].print(vect->at(i+1) + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; class GFG { static boolean pronic_check(int n){ int x=(int)(Math.sqrt(n)); if(x*(x+1)==n)return true ; else return false ; } public static void main(String[] args){ int n=56 ; if(pronic_check(n)==true)System.out.println("YES"); else System.out.println("NO"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation pronic_check( n : int) : boolean pre: true post: true activity: ( var x : int ; x := ((n)->sqrt())->oclAsType(int) ; if (x * (x + 1) = n) then return true else return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 56 ; if (pronic_check(n) = true) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int d=sc.nextInt(); int ta=sc.nextInt(); int tb=sc.nextInt(); double da=sc.nextInt(); double db=sc.nextInt(); double min=Double.MAX_VALUE ; for(int i=0 ; i*da<=d ; i++){ for(int j=0 ; i*da+j*db<=d ; j++){ if(i==0 && j==0){ continue ; } min=Math.min(min,Math.abs((ta*i*da+tb*j*db)/(i*da+j*db)-t)); } } System.out.println(min); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; var ta : int ; ta := sc.getCurrent()->toInteger() ; var tb : int ; tb := sc.getCurrent()->toInteger() ; var da : double ; da := sc.getCurrent()->toInteger() ; var db : double ; db := sc.getCurrent()->toInteger() ; var min : double ; min := (2 - 2->pow(-52))*(2->pow(1023)) ; var i : int ; i := 0 ; while i * da <= d do ( ( var j : int ; j := 0 ; while i * da + j * db <= d do ( ( if (i = 0 & j = 0) then ( continue ) else skip ; min := Set{min, if (ta * i * da + tb * j * db) / (i * da + j * db) - t < 0 then -((ta * i * da + tb * j * db) / (i * da + j * db) - t) else (ta * i * da + tb * j * db) / (i * da + j * db) - t endif}->min() ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxXOR(int arr[],int n){ int xorArr=0 ; for(int i=0 ; imax() ; ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,1,3} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(maxXOR(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean CheckIfstartsWithOne(int n,int b){ int m=(int)(Math.log10(n)/Math.log10(2)); for(int i=1 ; i<=m ; i++){ if(n>=(int)Math.pow(b,i)&& n<=2*(int)Math.pow(b,i)-1)return true ; } return false ; } public static void main(String args[]){ System.out.println(CheckIfstartsWithOne(6,4)? "Yes" : "No"); System.out.println(CheckIfstartsWithOne(24,2)? "Yes" : "No"); System.out.println(CheckIfstartsWithOne(24,7)? "Yes" : "No"); System.out.println(CheckIfstartsWithOne(24,15)? "Yes" : "No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation CheckIfstartsWithOne( n : int, b : int) : boolean pre: true post: true activity: ( var m : int ; m := ((n)->log10() / (2)->log10())->oclAsType(int) ; var i : int ; i := 1 ; while i <= m do ( ( if (n >= b->pow(i)->oclAsType(int) & n <= 2 * b->pow(i)->oclAsType(int) - 1) then return true else skip ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(if CheckIfstartsWithOne(6, 4) then "Yes" else "No" endif) ; OclFile["System.out"].println(if CheckIfstartsWithOne(24, 2) then "Yes" else "No" endif) ; OclFile["System.out"].println(if CheckIfstartsWithOne(24, 7) then "Yes" else "No" endif) ; OclFile["System.out"].println(if CheckIfstartsWithOne(24, 15) then "Yes" else "No" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ try { ArrayListlist=new ArrayList(); BufferedReader ds=new BufferedReader(new InputStreamReader(System.in)); while(true){ String s=ds.readLine(); if(s!=null && s!=""){ StringTokenizer sz=new StringTokenizer(s); sz.nextToken(); String perser=sz.nextToken(); if(perser.equals("?")){ break ; } list.add(s); } else { break ; } } for(int i=0 ; iincluding(s) ; ) else ( break ) ) ; var i : int ; i := 0 ; while i < list->size() do ( ( var s : String ; s := list->at(i+1) ; var sz : OclIterator ; sz := OclIterator.newOclIterator_String(s) ; var a : int ; a := (sz.next())->toInteger() ; var per : String ; per := sz.next() ; var b : int ; b := (sz.next())->toInteger() ; execute printline(a, b, per) ; ) ; i := i + 1 ) ) catch (e : OclException) do ( e.printStackTrace() ; OclFile["System.out"].println("Input Error") ) ); static operation printline( a : int, b : int, per : String) : void pre: true post: true activity: ( var res : int ; res := 0 ; if (per = "+") then res := a + b else if (per = "-") then res := a - (b)->char2byte() else if (per = "*") then res := a * b else if (per = "/") then res := a / b ; else skip ; ; ; ; OclFile["System.out"].println(res) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { static Scanner scanner=new Scanner(System.in); public static void main(String[] args){ double a=scanner.nextInt(); double b=scanner.nextInt(); for(int x=1 ; xtoInteger() ; var b : double ; b := scanner.getCurrent()->toInteger() ; var x : int ; x := 1 ; while x < a do ( ( var y : int ; y := 1 ; while y < b do ( ( var d : double ; d := (x / a) * (x / a) + (y / b) * (y / b) ; if (if d - 1 < 0 then -(d - 1) else d - 1 endif < 0.00000001) then ( var xxx : int ; xxx := x ; var yyy : int ; yyy := (((a * a - x * x)->sqrt() + 0.5)->oclAsType(int)) ; var xx : int ; xx := y ; var yy : int ; yy := ((b * b - y * y)->sqrt() + 0.5)->oclAsType(int) ; OclFile["System.out"].println("YES") ; OclFile["System.out"].println("0 0") ; if (yy = yyy) then OclFile["System.out"].println(xxx + " " + (-yyy)) else OclFile["System.out"].println(-xxx + " " + yyy) ; ; OclFile["System.out"].println(xx + " " + yy) ; return ) else skip ) ; y := y + 1 ) ) ; x := x + 1 ) ; OclFile["System.out"].println("NO") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static Scanner sc ; public static void main(String[] args){ sc=new Scanner(System.in); final int INF=1_000_000_000 ; int n=sc.nextInt(); long c=sc.nextLong(); long[] x=new long[n]; long[] v=new long[n]; for(int i=0 ; itoInteger() ; var c : long ; c := sc.getCurrent()->toLong() ; var x : Sequence(long) ; x := Integer.subrange(1,n)->collect(0) ; var v : Sequence(long) ; v := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := sc.getCurrent()->toLong() ; v[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var sum1 : long ; sum1 := 0 ; var sum2 : long ; sum2 := 0 ; var dp1 : Sequence(long) ; dp1 := Integer.subrange(1,n + 1)->collect(0) ; var dp2 : Sequence(long) ; dp2 := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( sum1 := sum1+(v[i+1]) ; dp1[i + 1+1] := sum1 - x[i+1] ; dp1[i + 1+1] := Set{dp1[i+1], dp1[i + 1+1]}->max() ; sum2 := sum2+(v[n - i - 1+1]) ; dp2[i + 1+1] := sum2 - (c - x[n - i - 1+1]) ; dp2[i + 1+1] := Set{dp2[i+1], dp2[i + 1+1]}->max() ; ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var a1 : long ; a1 := Set{dp1[i + 1+1], dp1[i + 1+1] - x[i+1] + dp2[n - i - 1+1]}->max() ; var a2 : long ; a2 := Set{dp2[i + 1+1], dp2[i + 1+1] - (c - x[n - i - 1+1]) + dp1[n - i - 1+1]}->max() ; var aa : long ; aa := Set{a1, a2}->max() ; ans := Set{ans, aa}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static class Sushi { long x ; long v ; public Sushi(long x,long v){ this.x=x ; this.v=v ; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long C=sc.nextLong(); Sushi[] s=new Sushi[N]; for(int i=0 ; i(){ public int compare(Sushi s1,Sushi s2){ return-Long.compare(s1.x,s2.x); } } ); for(int i=0 ; i=0 ; i--){ sum+=s[i] .v ; max=Math.max(max,sum-(C-s[i] .x)*2+cwmax[i]); } return max ; } } ------------------------------------------------------------ OCL File: --------- class Main { static class Sushi { attribute x : long; attribute v : long; static operation newSushi( x : long, v : long) : Sushi pre: true post: true activity: ( var self : Sushi ; self := createSushi(); self.initialise(x, v); return self ); operation initialise( x : long, v : long) : void pre: true post: true activity: ( self.x := x ; self.v := v ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var C : long ; C := sc.getCurrent()->toLong() ; var s : Sequence(Sushi) ; s := Integer.subrange(1,N)->collect(null) ; var i : int ; i := 0 ; while i < N do ( s[i+1] := Sushi.newSushi(sc.getCurrent()->toLong(), sc.getCurrent()->toLong()) ; ; i := i + 1 ) ; var ans : long ; ans := solve(s, C) ; s := OclComparator.sortWith(s, OclComparator.newOclComparator()) ; var i : int ; i := 0 ; while i < N do ( s[i+1].x := C - s[i+1].x ; ; i := i + 1 ) ; ans := Set{ans, solve(s, C)}->max() ; OclFile["System.out"].println(ans) ; skip ; ); static operation solve( s : Sequence(Sushi), C : long) : long pre: true post: true activity: ( var N : int ; N := s->size() ; var cwmax : Sequence(long) ; cwmax := Integer.subrange(1,N + 1)->collect(0) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < N do ( ( sum := sum+(s[i+1].v) ; cwmax[i + 1+1] := Set{cwmax[i+1], sum - s[i+1].x}->max() ) ; i := i + 1 ) ; var max : long ; max := cwmax[N+1] ; sum := 0 ; var i : int ; i := N - 1 ; while i >= 0 do ( ( sum := sum+(s[i+1].v) ; max := Set{max, sum - (C - s[i+1].x) * 2 + cwmax[i+1]}->max() ) ; i := i - 1 ) ; return max ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; class Main { static Scanner sc=new Scanner(System.in); static long[] x=new long[100005]; static long[] v=new long[100005]; static long[] s=new long[100005]; static long n,c ; static long ans=0 ; static long sum ; public static void main(String[] args){ Arrays.fill(x,0); Arrays.fill(v,0); Arrays.fill(s,0); n=sc.nextLong(); c=sc.nextLong(); for(int i=1 ; i<=n ; i++){ x[i]=sc.nextLong(); v[i]=sc.nextLong(); } x[(int)n+1]=c ; Arrays.fill(s,Long.MIN_VALUE); sum=0 ; s[0]=0 ; for(int i=1 ; i<=n ; i++){ sum+=v[i]; s[i]=Math.max(sum-x[i]*2,s[i-1]); } sum=0 ; for(int i=(int)n+1 ; i>0 ; i--){ sum+=v[i]; ans=Math.max(ans,s[i-1]+sum-(c-x[i])); } Arrays.fill(s,Long.MIN_VALUE); sum=0 ; s[0]=0 ; for(int i=1 ; i<=n ; i++){ sum+=v[i]; s[i]=Math.max(sum-x[i],s[i-1]); } sum=0 ; for(int i=(int)n+1 ; i>0 ; i--){ sum+=v[i]; ans=Math.max(ans,s[i-1]+sum-(2*c-2*x[i])); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute x : Sequence(long) := Integer.subrange(1,100005)->collect(0); static attribute v : Sequence(long) := Integer.subrange(1,100005)->collect(0); static attribute s : Sequence(long) := Integer.subrange(1,100005)->collect(0); static attribute n : long; static attribute ans : long := 0; static attribute sum : long; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( x := x->collect(0) ; v := v->collect(0) ; s := s->collect(0) ; n := sc.getCurrent()->toLong() ; c := sc.getCurrent()->toLong() ; var i : int ; i := 1 ; while i <= n do ( ( x[i+1] := sc.getCurrent()->toLong() ; v[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; x[n->oclAsType(int) + 1+1] := c ; s := s->collect("-9223372036854775808"->toLong()) ; sum := 0 ; s[0+1] := 0 ; var i : int ; i := 1 ; while i <= n do ( ( sum := sum+(v[i+1]) ; s[i+1] := Set{sum - x[i+1] * 2, s[i - 1+1]}->max() ) ; i := i + 1 ) ; sum := 0 ; var i : int ; i := n->oclAsType(int) + 1 ; while i > 0 do ( ( sum := sum+(v[i+1]) ; ans := Set{ans, s[i - 1+1] + sum - (c - x[i+1])}->max() ) ; i := i - 1 ) ; s := s->collect("-9223372036854775808"->toLong()) ; sum := 0 ; s[0+1] := 0 ; var i : int ; i := 1 ; while i <= n do ( ( sum := sum+(v[i+1]) ; s[i+1] := Set{sum - x[i+1], s[i - 1+1]}->max() ) ; i := i + 1 ) ; sum := 0 ; var i : int ; i := n->oclAsType(int) + 1 ; while i > 0 do ( ( sum := sum+(v[i+1]) ; ans := Set{ans, s[i - 1+1] + sum - (2 * c - 2 * x[i+1])}->max() ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long C=sc.nextLong(); long[] x=new long[N]; long[] v=new long[N]; long ans=0 ; for(int i=0 ; itoInteger() ; var C : long ; C := sc.getCurrent()->toLong() ; var x : Sequence(long) ; x := Integer.subrange(1,N)->collect(0) ; var v : Sequence(long) ; v := Integer.subrange(1,N)->collect(0) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < N do ( ( x[i+1] := sc.getCurrent()->toLong() ; v[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var sum1 : long ; sum1 := 0 ; var sum2 : long ; sum2 := 0 ; var a : Sequence(long) ; a := Integer.subrange(1,N + 1)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,N + 1)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( sum1 := sum1+(v[i+1]) ; a[i + 1+1] := sum1 - x[i+1] ; a[i + 1+1] := Set{a[i+1], a[i + 1+1]}->max() ; sum2 := sum2+(v[N - i - 1+1]) ; b[i + 1+1] := sum2 - (C - x[N - i - 1+1]) ; b[i + 1+1] := Set{b[i+1], b[i + 1+1]}->max() ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var t1 : long ; t1 := Set{a[i + 1+1], a[i + 1+1] - x[i+1] + b[N - i - 1+1]}->max() ; var t2 : long ; t2 := Set{b[i + 1+1], b[i + 1+1] - (C - x[N - i - 1+1]) + a[N - i - 1+1]}->max() ; var t3 : long ; t3 := Set{t1, t2}->max() ; ans := Set{ans, t3}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean IsLarger(int[] X,int[] Y,int n){ for(int i=0 ; isize() ; OclFile["System.out"].println(solve(X, Y, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static double average(int arr[],int n,int k){ double total=0 ; if(2*k>=n)return 0 ; Arrays.sort(arr); int start=k,end=n-k-1 ; for(int i=start ; i<=end ; i++)total+=arr[i]; return(total/(n-2*k)); } public static void main(String[] args){ int arr[]={ 1,2,4,4,5,6 }; int n=arr.length ; int k=2 ; System.out.println(average(arr,n,k)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation average( arr : Sequence(int), n : int, k : int) : double pre: true post: true activity: ( var total : double ; total := 0 ; if (2 * k >= n) then return 0 else skip ; arr := arr->sort() ; var start : int ; start := k ; var end : int ; end := n - k - 1 ; var i : int ; i := start ; while i <= end do ( total := total+(arr[i+1]) ; ; i := i + 1 ) ; return (total / (n - 2 * k)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,4,4,5,6} ; var n : int ; n := arr->size() ; var k : int ; k := 2 ; OclFile["System.out"].println(average(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int gcd(int a,int b){ if(a==0)return b ; return gcd(b % a,a); } static void commDiv(int a,int b){ int n=gcd(a,b); a=a/n ; b=b/n ; System.out.println("A="+a+",B="+b); } public static void main(String[] args){ int a=10,b=15 ; commDiv(a,b); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation gcd( a : int, b : int) : int pre: true post: true activity: ( if (a = 0) then return b else skip ; return gcd(b mod a, a) ); static operation commDiv( a : int, b : int) : void pre: true post: true activity: ( var n : int ; n := gcd(a, b) ; a := a / n ; b := b / n ; OclFile["System.out"].println("A=" + a + ",B=" + b) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 10 ; var b : int ; b := 15 ; execute commDiv(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printValueOfPi(int N){ double pi=2*Math.acos(0.0); System.out.println(pi); } public static void main(String[] args){ int N=4 ; printValueOfPi(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation printValueOfPi( N : int) : void pre: true post: true activity: ( var pi : double ; pi := 2 * (0.0)->acos() ; OclFile["System.out"].println(pi) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 4 ; execute printValueOfPi(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class JavaApplication439 { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int x=input.nextInt(); boolean chesck=true ; int y=7-x ; for(int i=0 ; itoInteger() ; var x : int ; x := input.getCurrent()->toInteger() ; var chesck : boolean ; chesck := true ; var y : int ; y := 7 - x ; var i : int ; i := 0 ; while i < n do ( ( var q : int ; q := input.getCurrent()->toInteger() ; var w : int ; w := input.getCurrent()->toInteger() ; if (q = x or q = y or w = x or w = y) then ( chesck := false ; break ) else skip ) ; i := i + 1 ) ; if (chesck) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import javax.lang.model.util.ElementScanner6 ; public class ques1 { public static void main(String[] args){ Scanner scn=new Scanner(System.in); int n=scn.nextInt(); int m=scn.nextInt(); double max1=-0.0 ; double max2=-0.0 ; HashMapmap=new HashMap<>(); int idx1=n ; int idx2=-1 ; for(int i=0 ; i=max1){ max1=Math.ceil((double)a/m); idx1=i+1 ; } } System.out.println(idx1); } public static boolean isPrime(int n){ boolean ans=true ; for(int i=2 ; i*i<=n ; i++){ if(n % i==0){ ans=false ; break ; } } if(ans==true)return true ; else return false ; } } ------------------------------------------------------------ OCL File: --------- class ques1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scn.getCurrent()->toInteger() ; var m : int ; m := scn.getCurrent()->toInteger() ; var max1 : double ; max1 := -0.0 ; var max2 : double ; max2 := -0.0 ; var map : Map(int,int) ; map := Map{} ; var idx1 : int ; idx1 := n ; var idx2 : int ; idx2 := -1 ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := scn.getCurrent()->toInteger() ; if ((a->oclAsType(double) / m)->ceil() >= max1) then ( max1 := (a->oclAsType(double) / m)->ceil() ; idx1 := i + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(idx1) ; ); static operation isPrime( n : int) : boolean pre: true post: true activity: ( var ans : boolean ; ans := true ; var i : int ; i := 2 ; while i * i <= n do ( ( if (n mod i = 0) then ( ans := false ; break ) else skip ) ; i := i + 1 ) ; if (ans = true) then return true else return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.HashSet ; import java.util.Set ; import java.util.StringTokenizer ; public class Main { public static PrintWriter out ; public static void main(String[] args){ MyScanner sc=new MyScanner(); out=new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); int m=sc.nextInt(); int k=sc.nextInt(); Setholes=new HashSet<>(); for(int i=0 ; iincluding(sc.nextInt()) ) ; i := i + 1 ) ; var cup : int ; cup := 1 ; if (not(holes->includes(cup))) then ( var i : int ; i := 0 ; while i < k do ( ( cup := swap(sc.nextInt(), sc.nextInt(), cup) ; if (holes->includes(cup)) then ( break ) else skip ) ; i := i + 1 ) ) else skip ; skip ; skip ; ); static operation swap( pos1 : int, pos2 : int, cup : int) : int pre: true post: true activity: ( if (cup = pos1) then return pos2 else if (cup = pos2) then return pos1 else return cup ; ); static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class geeks { public static int minimumOperations(int[] a,int n){ HashMapmp=new HashMap<>(); for(int i=0 ; ientry : mp.entrySet()){ if(entry.getValue()>1){ count+=(entry.getValue()-1); } } return count ; } public static void main(String[] args){ int[] a={ 2,1,2,3,3,4,3 }; int n=a.length ; System.out.println(minimumOperations(a,n)); } } ------------------------------------------------------------ OCL File: --------- class geeks { static operation minimumOperations( a : Sequence(int), n : int) : int pre: true post: true activity: ( var mp : Map(int,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (mp->at(a[i+1]) /= null) then ( var x : int ; x := mp->at(a[i+1]) ; mp := mp->union(Map{a[i+1] |-> (x + 1)}) ) else mp := mp->union(Map{a[i+1] |-> 1}) ; ) ; i := i + 1 ) ; var count : int ; count := 0 ; for (entry : mp->asSet()) do ( ( if (entry.getValue() > 1) then ( count := count+((entry.getValue() - 1)) ) else skip ) ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,1,2,3,3,4,3} ; var n : int ; n := a->size() ; OclFile["System.out"].println(minimumOperations(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static boolean isA(char[] s){ if(s.length<6)return false ; if(!(s[0]=='>' && s[1]=='\''))return false ; int con=0 ; while(2+con' && s[1]=='^'))return false ; int i=2 ; int c=0 ; while(i+1=s.length || c==0)return false ; return i+1==s.length-1 && s[i]=='~' && s[i+1]=='~' ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ char[] s=sc.next().toCharArray(); System.out.println(isA(s)? "A" : isB(s)? "B" : "NA"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation isA( s : Sequence(String)) : boolean pre: true post: true activity: ( if (s->size() < 6) then return false else skip ; if (not((s[0+1] = '>' & s[1+1] = '\''))) then return false else skip ; var con : int ; con := 0 ; while (2 + con < s->size() & s[2 + con+1] = '=') do con := con + 1 ; ; if (con = 0) then return false else skip ; if (2 + con = s->size() or s[2 + con+1] /= '#') then return false else skip ; var b : int ; b := 3 + con ; var sec : int ; sec := 0 ; while (b + sec < s->size() & s[b + sec+1] = '=') do sec := sec + 1 ; ; if (sec /= con or b + sec = s->size()) then return false else skip ; return s[b + sec+1] = '~' & b + sec = s->size() - 1 ); static operation isB( s : Sequence(String)) : boolean pre: true post: true activity: ( if (s->size() < 6) then return false else skip ; if (not((s[0+1] = '>' & s[1+1] = '^'))) then return false else skip ; var i : int ; i := 2 ; var c : int ; c := 0 ; while (i + 1 < s->size() & s[i+1] = 'Q' & s[i + 1+1] = '=') do ( i := i+(2) ; c := c + 1 ) ; if (i + 1 >= s->size() or c = 0) then return false else skip ; return i + 1 = s->size() - 1 & s[i+1] = '~' & s[i + 1+1] = '~' ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var s : Sequence(String) ; s := sc.getCurrent()->characters() ; OclFile["System.out"].println(if isA(s) then "A" else if isB(s) then "B" else "NA" endif endif) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { boolean main()throws IOException { String s=reader.readLine(); String type="NA" ; String regA=">'(=+)#(=+)\\~" ; if(s.matches(regA)){ if(s.replaceAll(regA,"$1").equals(s.replaceAll(regA,"$2")))type="A" ; } else if(s.matches(">\\^(Q=)+\\~\\~")){ type="B" ; } System.out.printf("%s\n",type); return true ; } private final static boolean DEBUG=false ; public static void main(String[] args)throws IOException { if(DEBUG){ log=System.out ; String inputStr="1:>'======#======~:" ; inputStr=inputStr.replace(":","\n"); reader=new BufferedReader(new StringReader(inputStr)); } else { log=new PrintStream(new OutputStream(){ public void write(int b){ } } ); reader=new BufferedReader(new InputStreamReader(System.in)); } int N=readIntArray()[0]; for(int i=0 ; iisMatch(regA)) then ( if (s.replaceAllMatches(regA, "$1" ) = s.replaceAllMatches(regA, "$2" )) then type := "A" ; else skip ) else if (s->isMatch(">\\^(Q=)+\\~\\~")) then ( type := "B" ) else skip ; ; OclFile["System.out"].printf("%s\n", type) ; return true ); static attribute DEBUG : boolean := false; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( if (DEBUG) then ( log := OclFile["System.out"] ; var inputStr : String ; inputStr := "1:>'======#======~:" ; inputStr := inputStr.replace(":", "\n") ; reader := OclFile.newOclFile_Read(StringReader.newStringReader(inputStr)) ) else ( log := OclFile.newOclFile_Write(OclFile()) ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ) ; var N : int ; N := readIntArray()[0+1] ; var i : int ; i := 0 ; while i < N do ( ( var b : boolean ; b := Main.newMain().main() ; if (not(b)) then break else skip ) ; i := i + 1 ) ; reader.close() ); static attribute log : OclFile; static attribute reader : OclFile; static operation readIntArray() : Sequence(int) pre: true post: true activity: ( var s : String ; s := null ; while true do ( ( s := reader.readLine() ; if (s = null) then return null else skip ; s := s->trim() ; if (s->size() /= 0) then break else skip ) ) ; var sp : Sequence(String) ; sp := s->split("[,] ") ; var a : Sequence(int) ; a := Integer.subrange(1,sp->size())->collect(0) ; var i : int ; i := 0 ; while i < sp->size() do ( ( a[i+1] := (sp[i+1])->toInteger() ) ; i := i + 1 ) ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.regex.Matcher ; import java.util.regex.Pattern ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static final long HUGE_NUM=99999999999999999L ; public static final double EPS=0.000000001 ; @ SuppressWarnings("unchecked")public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); StringBuilder ans=new StringBuilder(); for(int loop=0 ; loop'(=+)#\\1~\\z")){ ans.append("A\n"); } else if(input_str.matches("\\A>\\^(Q=)+~~\\z")){ ans.append("B\n"); } else { ans.append("NA\n"); } } System.out.printf(ans.toString()); } } class UTIL { public static long gcd(long x,long y){ x=Math.abs(x); y=Math.abs(y); if(xtoInteger() ; var ans : String ; ans := StringLib.newString() ; var loop : int ; loop := 0 ; while loop < N do ( ( var input_str : String ; input_str := scanner.getCurrent() ; if (input_str->isMatch("\\A>'(=+)#\\1~\\z")) then ( ans := ans + StringLib.newString("A\n") ) else if (input_str->isMatch("\\A>\\^(Q=)+~~\\z")) then ( ans := ans + StringLib.newString("B\n") ) else ( ans := ans + StringLib.newString("NA\n") ) ; ) ; loop := loop + 1 ) ; OclFile["System.out"].printf(ans+"") ; ); } class UTIL { static operation gcd( x : long, y : long) : long pre: true post: true activity: ( x := if x < 0 then -(x) else x endif ; y := if y < 0 then -(y) else y endif ; if (x < y) then ( var tmp : long ; tmp := y ; y := x ; x := tmp ) else skip ; if (y = 0) then ( return x ) else ( return gcd(y, x mod y) ) ); static operation lcm( x : long, y : long) : long pre: true post: true activity: ( return (x * y) / gcd(x, y) ); static operation getNUM( tmp_str : String) : int pre: true post: true activity: ( return (tmp_str)->toInteger() ); static operation isNumber( tmp_str : String) : boolean pre: true post: true activity: ( if (tmp_str = null or tmp_str->size() = 0) then ( return false ) else skip ; var pattern : OclRegex ; pattern := OclRegex.compile("\\A[0-9]+\\z") ; var matcher : OclRegex ; matcher := pattern.matcher(tmp_str) ; return matcher.isMatch() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.lang.Integer ; import java.lang.System ; import java.lang.Exception ; import java.util.regex.Matcher ; import java.util.regex.Pattern ; public class Main { public static void main(String[] args)throws Exception { BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); Pattern a=Pattern.compile(">'(=+)#\\1~"); Pattern b=Pattern.compile(">\\^(Q=)+~~"); int n=Integer.parseInt(r.readLine()); for(int i=0 ; i'(=+)#\\1~") ; var b : OclRegex ; b := OclRegex.compile(">\\^(Q=)+~~") ; var n : int ; n := (r.readLine())->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := r.readLine() ; var ma : OclRegex ; ma := a.matcher(s) ; var mb : OclRegex ; mb := b.matcher(s) ; if (ma.isMatch()) then ( OclFile["System.out"].println("A") ) else if (mb.isMatch()) then ( OclFile["System.out"].println("B") ) else ( OclFile["System.out"].println("NA") ) ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void specialNumber(int n){ if(n<10 || n>99)System.out.println("Invalid Input! "+"Number should have "+"2 digits only"); else { int first=n/10 ; int last=n % 10 ; int sum=first+last ; int pro=first*last ; if((sum+pro)==n){ System.out.println(n+" is a Special"+" Two-Digit Number"); } else { System.out.println(n+" is Not a Special"+" Two-Digit Number"); } } } public static void main(String args[]){ int n=59 ; specialNumber(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation specialNumber( n : int) : void pre: true post: true activity: ( if (n < 10 or n > 99) then OclFile["System.out"].println("Invalid Input! " + "Number should have " + "2 digits only") ; else ( var first : int ; first := n / 10 ; var last : int ; last := n mod 10 ; var sum : int ; sum := first + last ; var pro : int ; pro := first * last ; if ((sum + pro) = n) then ( OclFile["System.out"].println(n + " is a Special" + " Two-Digit Number") ) else ( OclFile["System.out"].println(n + " is Not a Special" + " Two-Digit Number") ) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 59 ; execute specialNumber(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxProdSum(int arr[],int n){ int leftArraySum=0,maxProduct=0 ; for(int i=0 ; imaxProduct){ maxProduct=k ; } } return maxProduct ; } public static void main(String[] args){ int arr[]={ 4,10,1,7,2,9 }; int n=arr.length ; System.out.print(maxProdSum(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxProdSum( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var leftArraySum : int ; leftArraySum := 0 ; var maxProduct : int ; maxProduct := 0 ; var i : int ; i := 0 ; while i < n do ( ( leftArraySum := leftArraySum+(arr[i+1]) ; var rightArraySum : int ; rightArraySum := 0 ; var j : int ; j := i + 1 ; while j < n do ( ( rightArraySum := rightArraySum+(arr[j+1]) ) ; j := j + 1 ) ; var k : int ; k := leftArraySum * rightArraySum ; if (k > maxProduct) then ( maxProduct := k ) else skip ; ) ; i := i + 1 ) ; return maxProduct ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{4,10,1,7,2,9} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(maxProdSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long oddNumSum(int n){ return(n*(2*n+1)*(24*n*n*n-12*n*n-14*n+7))/15 ; } public static void main(String[] args){ int n=4 ; System.out.println(oddNumSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation oddNumSum( n : int) : long pre: true post: true activity: ( return (n * (2 * n + 1) * (24 * n * n * n - 12 * n * n - 14 * n + 7)) / 15 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(oddNumSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int odd_digits(int n){ if(n<10)return n ; else if(n/10<10)return 9 ; else if(n/100<10)return 9+n-99 ; else if(n/1000<10)return 9+900 ; else if(n/10000<10)return 909+n-9999 ; else return 90909 ; } public static void main(String[] args){ int n=893 ; System.out.println(odd_digits(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation odd_digits( n : int) : int 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 ; ; ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 893 ; OclFile["System.out"].println(odd_digits(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findPairs(int arr[],int n){ int cntEven=0,cntOdd=0 ; for(int i=0 ; iat(0+1)) ; var i : int ; i := 1 ; while i < str->size() do ( if ((not(is_vow(str->at(i - 1+1)))) or (not(is_vow(str->at(i+1))))) then OclFile["System.out"].print(str->at(i+1)) ; else skip ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeks for geeks" ; execute removeVowels(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] a)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()," "); int nums[]=new int[3]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < nums->size() do ( nums[i+1] := (st.next())->toInteger() ; ; i := i + 1 ) ; nums := nums->sort() ; OclFile["System.out"].println(nums[0+1] + " " + nums[1+1] + " " + nums[2+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int atMostSum(int arr[],int n,int k){ int sum=0 ; int cnt=0,maxcnt=0 ; for(int i=0 ; imax() ) ; i := i + 1 ) ; return maxcnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,1,0,1,1,0} ; var n : int ; n := arr->size() ; var k : int ; k := 4 ; OclFile["System.out"].print(atMostSum(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isPower(int n){ for(int x=2 ; x<=(int)Math.sqrt(n); x++){ float f=(float)Math.log(n)/(float)Math.log(x); if((f-(int)f)==0.0)return true ; } return false ; } public static void main(String args[]){ for(int i=2 ; i<100 ; i++)if(isPower(i))System.out.print(i+" "); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isPower( n : int) : boolean pre: true post: true activity: ( var x : int ; x := 2 ; while x <= (n)->sqrt()->oclAsType(int) do ( ( var f : double ; f := (n)->log()->oclAsType(double) / (x)->log()->oclAsType(double) ; if ((f - f->oclAsType(int)) = 0.0) then return true else skip ) ; x := x + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; i := 2 ; while i < 100 do ( if (isPower(i)) then OclFile["System.out"].print(i + " ") ; else skip ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int countDistinct(int arr[],int n){ HashSeths=new HashSet(); for(int i=0 ; iincluding(arr[i+1]) ) ; i := i + 1 ) ; return hs->size() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{6,10,5,4,9,120,4,6,10} ; OclFile["System.out"].println(countDistinct(arr, arr->size())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B_Array_Sharpening { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int tc=0 ; tc=index){ ++index ; } if(index==a.length){ return true ; } if(a.length-index-1>=a[index-1]){ return false ; } while(index=a.length-index-1){ ++index ; } return index==a.length ; } } ------------------------------------------------------------ OCL File: --------- class B_Array_Sharpening { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var tc : int ; tc := 0 ; while tc < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(if solve(a) then "Yes" else "No" endif) ) ; tc := tc + 1 ) ; skip ); static operation solve( a : Sequence(int)) : boolean pre: true post: true activity: ( var index : int ; index := 0 ; while (index < a->size() & a[index+1] >= index) do ( index := index + 1 ) ; if (index = a->size()) then ( return true ) else skip ; if (a->size() - index - 1 >= a[index - 1+1]) then ( return false ) else skip ; while (index < a->size() & a[index+1] >= a->size() - index - 1) do ( index := index + 1 ) ; return index = a->size() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner scanner=new Scanner(System.in); while(true){ int q1=scanner.nextInt(); if(q1==0)break ; int b=scanner.nextInt(); int c1=scanner.nextInt(); int c2=scanner.nextInt(); int q2=scanner.nextInt(); int count=-1 ; for(int i=q2 ; i>=1 ; i--){ int aa=i*c1 ; int bb=Math.max((q1-i),0)*c2 ; if(aa+bb<=b){ count=i ; break ; } } if(count==-1){ System.out.println("NA"); } else { int ans=(b-count*c1)/c2 ; System.out.println(count+" "+ans); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var q1 : int ; q1 := scanner.getCurrent()->toInteger() ; if (q1 = 0) then break else skip ; var b : int ; b := scanner.getCurrent()->toInteger() ; var c1 : int ; c1 := scanner.getCurrent()->toInteger() ; var c2 : int ; c2 := scanner.getCurrent()->toInteger() ; var q2 : int ; q2 := scanner.getCurrent()->toInteger() ; var count : int ; count := -1 ; var i : int ; i := q2 ; while i >= 1 do ( ( var aa : int ; aa := i * c1 ; var bb : int ; bb := Set{(q1 - i), 0}->max() * c2 ; if (aa + bb <= b) then ( count := i ; break ) else skip ) ; i := i - 1 ) ; if (count = -1) then ( OclFile["System.out"].println("NA") ) else ( var ans : int ; ans := (b - count * c1) / c2 ; OclFile["System.out"].println(count + " " + ans) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.util.Arrays.deepToString ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } void tr(Object...os){ System.err.println(deepToString(os)); } Scanner sc=new Scanner(System.in); public void run(){ for(; sc.hasNext(); ){ int q1=sc.nextInt(); if(q1==0)break ; int b=sc.nextInt(); int c1=sc.nextInt(); int c2=sc.nextInt(); int q2=sc.nextInt(); int BUY1U=Math.min(b/c1,q2); int ansBuy1=-1 ; for(int buy1=1 ; buy1<=BUY1U ; buy1++){ int buy2=(b-c1*buy1)/c2 ; if(buy1>0 && buy1+buy2>=q1){ ansBuy1=buy1 ; } } if(ansBuy1==-1)System.out.println("NA"); else { int buy2=(b-c1*ansBuy1)/c2 ; System.out.println(ansBuy1+" "+buy2); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation tr( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while sc.hasNext() do ( ( var q1 : int ; q1 := sc.getCurrent()->toInteger() ; if (q1 = 0) then break else skip ; var b : int ; b := sc.getCurrent()->toInteger() ; var c1 : int ; c1 := sc.getCurrent()->toInteger() ; var c2 : int ; c2 := sc.getCurrent()->toInteger() ; var q2 : int ; q2 := sc.getCurrent()->toInteger() ; var BUY1U : int ; BUY1U := Set{b / c1, q2}->min() ; var ansBuy1 : int ; ansBuy1 := -1 ; var buy1 : int ; buy1 := 1 ; while buy1 <= BUY1U do ( ( var buy2 : int ; buy2 := (b - c1 * buy1) / c2 ; if (buy1 > 0 & buy1 + buy2 >= q1) then ( ansBuy1 := buy1 ) else skip ) ; buy1 := buy1 + 1 ) ; if (ansBuy1 = -1) then OclFile["System.out"].println("NA") else ( var buy2 : int ; buy2 := (b - c1 * ansBuy1) / c2 ; OclFile["System.out"].println(ansBuy1 + " " + buy2) ) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; while((line=br.readLine())!=null && ! line.isEmpty()){ if(line.equals("0"))break ; words=line.split(" "); int q1,b,c1,c2,q2 ; q1=parseInt(words[0]); b=parseInt(words[1]); c1=parseInt(words[2]); c2=parseInt(words[3]); q2=parseInt(words[4]); int a1=0,a2=0 ; if(b/c1>=q2){ a1=q2 ; a2=(b-c1*q2)/c2 ; } else { a1=b/c1 ; a2=(b-c1*a1)/c2 ; } if(a1+a2c2){ while(a1+a20 && a2>=0 && a1+a2>=q1 && a1<=q2){ System.out.println(a1+" "+a2); } else { System.out.println("NA"); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; line := br.readLine() ; while ((line) /= null & not(line->isEmpty())) do ( skip ; ( if (line = "0") then break else skip ; words := line->split(" ") ; var q1 : int ; var b : int ; var c1 : int ; var c2 : int ; var q2 : int ; q1 := (words[0+1] + "")->toInteger() ; b := (words[1+1] + "")->toInteger() ; c1 := (words[2+1] + "")->toInteger() ; c2 := (words[3+1] + "")->toInteger() ; q2 := (words[4+1] + "")->toInteger() ; var a1 : int ; a1 := 0 ; var a2 : int ; a2 := 0 ; if (b / c1 >= q2) then ( a1 := q2 ; a2 := (b - c1 * q2) / c2 ) else ( a1 := b / c1 ; a2 := (b - c1 * a1) / c2 ) ; if (a1 + a2 < q1) then ( if (c1 > c2) then ( while (a1 + a2 < q1) do ( a1 := a1 - 1 ; a2 := (b - c1 * a1) / c2 ) ) else if (c1 < c2) then ( while (a1 + a2 < q1) do ( a2 := a2 - 1 ; a1 := (b - c2 * a2) / c1 ) ) else skip ; ) else skip ; if (a1 > 0 & a2 >= 0 & a1 + a2 >= q1 & a1 <= q2) then ( OclFile["System.out"].println(a1 + " " + a2) ) else ( OclFile["System.out"].println("NA") ) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { private static int minBroadcastRange(int[] houses,int[] towers){ int n=houses.length ; int m=towers.length ; int leftTower=Integer.MIN_VALUE ; int rightTower=towers[0]; int j=0,k=0 ; int min_range=0 ; while(jmin_range)min_range=local_max ; j++; } else { leftTower=towers[k]; if(ksize() ; var m : int ; m := towers->size() ; var leftTower : int ; leftTower := -2147483648 ; var rightTower : int ; rightTower := towers[0+1] ; var j : int ; j := 0 ; var k : int ; k := 0 ; var min_range : int ; min_range := 0 ; while (j < n) do ( if (houses[j+1] < rightTower) then ( var left : int ; left := houses[j+1] - leftTower ; var right : int ; right := rightTower - houses[j+1] ; var local_max : int ; local_max := if left < right then left else right endif ; if (local_max > min_range) then min_range := local_max ; else skip ; j := j + 1 ; ) else ( leftTower := towers[k+1] ; if (k < m - 1) then ( k := k + 1 ; rightTower := towers[k+1] ) else rightTower := 2147483647 ; ) ) ; return min_range ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{12,13,11,80} ; var b : Sequence(int) ; b := Sequence{4,6,15,60} ; var max : int ; max := minBroadcastRange(a, b) ; OclFile["System.out"].println(max) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); void run(){ for(; ; ){ int q1=sc.nextInt(); if(q1==0)return ; int b=sc.nextInt(); int c1=sc.nextInt(); int c2=sc.nextInt(); int q2=sc.nextInt(); int aizCnt=0 ; int norCnt=0 ; aizCnt=Math.min(b/c1,q2); b-=aizCnt*c1 ; norCnt+=b/c2 ; b-=norCnt*c2 ; while(aizCnt+norCnttoInteger() ; if (q1 = 0) then return else skip ; var b : int ; b := sc.getCurrent()->toInteger() ; var c1 : int ; c1 := sc.getCurrent()->toInteger() ; var c2 : int ; c2 := sc.getCurrent()->toInteger() ; var q2 : int ; q2 := sc.getCurrent()->toInteger() ; var aizCnt : int ; aizCnt := 0 ; var norCnt : int ; norCnt := 0 ; aizCnt := Set{b / c1, q2}->min() ; b := b-(aizCnt * c1) ; norCnt := norCnt+(b / c2) ; b := b-(norCnt * c2) ; while (aizCnt + norCnt < q1 & 1 < aizCnt) do ( skip ; ( b := b+(c1) ; norCnt := norCnt+(b / c2) ; b := b-((b / c2) * c2) ) ; ) ; OclFile["System.out"].println(if (aizCnt = 0 or aizCnt + norCnt < q1) then "NA" else (aizCnt + " " + norCnt) endif) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int maxval(int a[],int n){ if(n<2){ return-99999 ; } int max=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(maxval(arr, len)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); if((a<=b)&&(a<=c)&&(b<=c)){ System.out.printf("%d %d %d\n",a,b,c); } else if((a<=b)&&(a<=c)&&(c<=b)){ System.out.printf("%d %d %d\n",a,c,b); } else if((b<=a)&&(b<=c)&&(a<=c)){ System.out.printf("%d %d %d\n",b,a,c); } else if((b<=a)&&(b<=c)&&(c<=a)){ System.out.printf("%d %d %d\n",b,c,a); } else if((c<=a)&&(c<=b)&&(a<=b)){ System.out.printf("%d %d %d\n",c,a,b); } else if((c<=a)&&(c<=b)&&(b<=a)){ System.out.printf("%d %d %d\n",c,b,a); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; if ((a <= b) & (a <= c) & (b <= c)) then ( OclFile["System.out"].printf("%d %d %d\n", a, b, c) ) else if ((a <= b) & (a <= c) & (c <= b)) then ( OclFile["System.out"].printf("%d %d %d\n", a, c, b) ) else if ((b <= a) & (b <= c) & (a <= c)) then ( OclFile["System.out"].printf("%d %d %d\n", b, a, c) ) else if ((b <= a) & (b <= c) & (c <= a)) then ( OclFile["System.out"].printf("%d %d %d\n", b, c, a) ) else if ((c <= a) & (c <= b) & (a <= b)) then ( OclFile["System.out"].printf("%d %d %d\n", c, a, b) ) else if ((c <= a) & (c <= b) & (b <= a)) then ( OclFile["System.out"].printf("%d %d %d\n", c, b, a) ) else skip ; ; ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findDigitalRoot(int num){ int sum=Integer.MAX_VALUE,tempNum=num ; while(sum>=10){ sum=0 ; while(tempNum>0){ sum+=tempNum % 10 ; tempNum/=10 ; } tempNum=sum ; } return sum ; } static void findAnswer(int X,int N){ int counter=0 ; for(int i=1 ; counter= 10) do ( sum := 0 ; while (tempNum > 0) do ( sum := sum+(tempNum mod 10) ; tempNum := tempNum/(10) ) ; tempNum := sum ) ; return sum ); static operation findAnswer( X : int, N : int) : void pre: true post: true activity: ( var counter : int ; counter := 0 ; var i : int ; i := 1 ; while counter < N do ( ( var digitalRoot : int ; digitalRoot := findDigitalRoot(i) ; if (digitalRoot = X) then ( counter := counter + 1 ) else skip ; if (counter = N) then ( OclFile["System.out"].print(i) ; break ) else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var X : int ; X := 1 ; var N : int ; N := 3 ; execute findAnswer(X, N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int reversDigits(int num){ int rev_num=0 ; while(num>0){ rev_num=rev_num*10+num % 10 ; num=num/10 ; } return rev_num ; } public static void main(String[] args){ int num=4562 ; System.out.println("Reverse of no.is "+reversDigits(num)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation reversDigits( num : int) : int pre: true post: true activity: ( var rev_num : int ; rev_num := 0 ; while (num > 0) do ( rev_num := rev_num * 10 + num mod 10 ; num := num / 10 ) ; return rev_num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 4562 ; OclFile["System.out"].println("Reverse of no.is " + reversDigits(num)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int reversDigits(int num){ int rev_num=0 ; while(num>0){ rev_num=rev_num*10+num % 10 ; num=num/10 ; } return rev_num ; } public static void main(String[] args){ int num=4562 ; System.out.println("Reverse of no.is "+reversDigits(num)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation reversDigits( num : int) : int pre: true post: true activity: ( var rev_num : int ; rev_num := 0 ; while (num > 0) do ( rev_num := rev_num * 10 + num mod 10 ; num := num / 10 ) ; return rev_num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 4562 ; OclFile["System.out"].println("Reverse of no.is " + reversDigits(num)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int reversDigits(int num){ int rev_num=0 ; while(num>0){ rev_num=rev_num*10+num % 10 ; num=num/10 ; } return rev_num ; } public static void main(String[] args){ int num=4562 ; System.out.println("Reverse of no.is "+reversDigits(num)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation reversDigits( num : int) : int pre: true post: true activity: ( var rev_num : int ; rev_num := 0 ; while (num > 0) do ( rev_num := rev_num * 10 + num mod 10 ; num := num / 10 ) ; return rev_num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 4562 ; OclFile["System.out"].println("Reverse of no.is " + reversDigits(num)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int rev_num=0 ; static int base_pos=1 ; static int reversDigits(int num){ if(num>0){ reversDigits(num/10); rev_num+=(num % 10)*base_pos ; base_pos*=10 ; } return rev_num ; } public static void main(String[] args){ int num=4562 ; System.out.println(reversDigits(num)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute rev_num : int := 0; static attribute base_pos : int := 1; static operation reversDigits( num : int) : int pre: true post: true activity: ( if (num > 0) then ( execute reversDigits(num / 10) ; rev_num := rev_num+((num mod 10) * base_pos) ; base_pos := base_pos*(10) ) else skip ; return rev_num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 4562 ; OclFile["System.out"].println(reversDigits(num)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int rev_num=0 ; static int base_pos=1 ; static int reversDigits(int num){ if(num>0){ reversDigits(num/10); rev_num+=(num % 10)*base_pos ; base_pos*=10 ; } return rev_num ; } public static void main(String[] args){ int num=4562 ; System.out.println(reversDigits(num)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute rev_num : int := 0; static attribute base_pos : int := 1; static operation reversDigits( num : int) : int pre: true post: true activity: ( if (num > 0) then ( execute reversDigits(num / 10) ; rev_num := rev_num+((num mod 10) * base_pos) ; base_pos := base_pos*(10) ) else skip ; return rev_num ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : int ; num := 4562 ; OclFile["System.out"].println(reversDigits(num)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class PrimeNumber { static void primeOccurences(int[] arr,int k){ Mapmap=new HashMap<>(); for(int i=0 ; ientry : map.entrySet()){ int value=entry.getValue(); if(isPrime(value)&& value>=k)System.out.println(entry.getKey()); } } private static boolean isPrime(int n){ if((n>2 && n % 2==0)|| n==1)return false ; for(int i=3 ; i<=(int)Math.sqrt(n); i+=2){ if(n % i==0)return false ; } return true ; } public static void main(String[] args){ int[] arr={ 11,11,11,23,11,37,37,51,51,51,51,51 }; int k=2 ; primeOccurences(arr,k); } } ------------------------------------------------------------ OCL File: --------- class PrimeNumber { static operation primeOccurences( arr : Sequence(int), k : int) : void pre: true post: true activity: ( var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < arr->size() do ( ( var val : int ; val := arr[i+1] ; var freq : int ; if (map->keys()->includes(val)) then ( freq := map->at(val) ; freq := freq + 1 ) else freq := 1 ; ; map := map->union(Map{val |-> freq}) ) ; i := i + 1 ) ; for (entry : map->asSet()) do ( ( var value : int ; value := entry.getValue() ; if (isPrime(value) & value >= k) then OclFile["System.out"].println(entry.getKey()) ; else skip ) ) ); static operation isPrime( n : int) : boolean pre: true post: true activity: ( if ((n > 2 & n mod 2 = 0) or n = 1) then return false else skip ; var i : int ; i := 3 ; while i <= (n)->sqrt()->oclAsType(int) do ( ( if (n mod i = 0) then return false else skip ) ; i := i+(2) ) ; return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{11,11,11,23,11,37,37,51,51,51,51,51} ; var k : int ; k := 2 ; execute primeOccurences(arr, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class SillyMistake { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { int n=Integer.parseInt(br.readLine()); String[] temp=br.readLine().split(" "); int[] events=new int[n]; for(int i=0 ; ires=new ArrayList<>(); Setentered=new HashSet<>(); MapcountEnter=new HashMap(); int left=0 ; for(int right=0 ; right(); } } else if(event>0){ if(countEnter.containsKey(event)){ pr.println(-1); return ; } countEnter.put(event,1); entered.add(event); } } if(entered.size()!=0){ pr.println(-1); return ; } pr.println(res.size()); for(int i : res){ pr.print(i+" "); } } } ------------------------------------------------------------ OCL File: --------- class SillyMistake { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pr : OclFile ; pr := OclFile.newOclFile_Write(OclFile["System.out"]) ; execute solve(br, pr) ; skip ; skip ; ); static operation solve( br : OclFile, pr : OclFile) : void pre: true post: true activity: ( var n : int ; n := (br.readLine())->toInteger() ; var temp : Sequence(String) ; temp := br.readLine()->split(" ") ; var events : Sequence(int) ; events := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( events[i+1] := (temp[i+1])->toInteger() ) ; i := i + 1 ) ; var res : Sequence(int) ; res := Sequence{} ; var entered : Set(int) ; entered := Set{} ; var countEnter : Map(int,int) ; countEnter := Map{} ; var left : int ; left := 0 ; var right : int ; right := 0 ; while right < n do ( ( var event : int ; event := events[right+1] ; if (event < 0) then ( if (entered->includes(-event) = false) then ( skip ; return ) else skip ; entered := entered->excludingFirst(-event) ; if (entered->size() = 0) then ( res := res->including(right - left + 1) ; left := right + 1 ; countEnter := Map{} ) else skip ) else if (event > 0) then ( if (countEnter->keys()->includes(event)) then ( skip ; return ) else skip ; countEnter := countEnter->union(Map{event |-> 1}) ; entered := entered->including(event) ) else skip ; ) ; right := right + 1 ) ; if (entered->size() /= 0) then ( skip ; return ) else skip ; skip ; for (i : res) do ( ( skip ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static float trianglearea(float l,float b){ if(l<0 || b<0)return-1 ; float area=(l*b)/2 ; return area ; } public static void main(String args[]){ float l=5,b=4 ; System.out.println(trianglearea(l,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation trianglearea( l : double, b : double) : double pre: true post: true activity: ( if (l < 0 or b < 0) then return -1 else skip ; var area : double ; area := (l * b) / 2 ; return area ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : double ; l := 5 ; var b : double ; b := 4 ; OclFile["System.out"].println(trianglearea(l, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxSubArraySum(int a[],int size){ int max_so_far=Integer.MIN_VALUE,max_ending_here=0,start=0,end=0,s=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(maxSubArraySum(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class test300 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int a[]=new int[100]; int min=1 ; for(int i=0 ; imin){ min=a[x-1]; } } System.out.println(min); in.close(); } } ------------------------------------------------------------ OCL File: --------- class test300 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,100)->collect(0) ; var min : int ; min := 1 ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() ; a[x - 1+1] := a[x - 1+1] + 1 ; if (a[x - 1+1] > min) then ( min := a[x - 1+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner in=new Scanner(System.in); ArrayListlist=new ArrayList(); list.add(in.nextShort()); list.add(in.nextShort()); list.add(in.nextShort()); Collections.sort(list); byte c=0 ; String s ; for(Short i : list){ if(cincluding(in.nextShort()) ; list := list->including(in.nextShort()) ; list := list->including(in.nextShort()) ; list := list->sort() ; var c : int ; c := 0 ; var s : String ; for (i : list) do ( ( if (c < list->size() - 1) then s := " " else s := "" ; ; OclFile["System.out"].printf("%d%s", i, s) ; c := c+(1) ) ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class PolycarpsPockets { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[] A=new int[101]; scan.nextLine(); for(int i=0 ; ires){ res=A[i]; } } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class PolycarpsPockets { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,101)->collect(0) ; skip ; var i : int ; i := 0 ; while i < n do ( ( A[scan.getCurrent()->toInteger()+1] := A[scan.getCurrent()->toInteger()+1] + 1 ) ; i := i + 1 ) ; var res : int ; res := 0 ; var i : int ; i := 0 ; while i < 101 do ( ( if (A[i+1] > res) then ( res := A[i+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Arrays ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[101]; int MAX=0 ; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,101)->collect(0) ; var MAX : int ; MAX := 0 ; var i : int ; i := 0 ; while i < n do ( ( var b : int ; b := sc.getCurrent()->toInteger() ; a[b+1] := a[b+1] + 1 ; MAX := Set{a[b+1], MAX}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(MAX) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main(String[] args)throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(br.readLine().trim()); int arr[]=new int[n]; String a[]=br.readLine().trim().split(" "); for(int i=0 ; il=new HashMap<>(); for(int i=0 ; ix : l.entrySet()){ max=Math.max(max,x.getValue()); } bw.write(max+"\n"); br.close(); bw.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var bw : OclFile ; bw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var n : int ; n := (br.readLine()->trim())->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var a : Sequence(String) ; a := br.readLine()->trim()->split(" ") ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := (a[i+1])->toInteger() ; ; i := i + 1 ) ; var max : int ; max := -2147483648 ; var l : Map(int,int) ; l := Map{} ; var i : int ; i := 0 ; while i < n do ( ( l := l->union(Map{arr[i+1] |-> 1 + (if l->keys()->contains(arr[i+1]) then l->at(arr[i+1]) else 0 endif)}) ) ; i := i + 1 ) ; for (x : l->asSet()) do ( ( max := Set{max, x.getValue()}->max() ) ) ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args){ FastScanner input=new FastScanner(); int n=input.nextInt(); int count[]=new int[1000]; int max=Integer.MIN_VALUE ; for(int i=0 ; icollect(0) ; var max : int ; max := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( var value : int ; value := input.nextInt() ; count[value+1] := count[value+1] + 1 ; max := Set{max, count[value+1]}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); static class FastScanner { attribute br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); attribute st : OclIterator := OclIterator.newOclIterator_String(""); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( return br.readLine() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); ArrayListans=new ArrayList<>(); int cnt=0 ; for(int i=0 ; i<20 ; i++){ int pow=-1 ; for(int j=0 ; (1<toInteger() ; var ans : Sequence(int) ; ans := Sequence{} ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < 20 do ( ( var pow : int ; pow := -1 ; var j : int ; j := 0 ; while ((1*(2->pow(j)))->oclAsType(long)) <= n do ( ( if ((((1*(2->pow(j)))->oclAsType(long)) & n) = 0) then ( pow := j ) else skip ) ; j := j + 1 ) ; if (pow = -1) then break else skip ; pow := pow + 1 ; cnt := cnt + 1 ; n := MathLib.bitwiseXor(n,(((1*(2->pow(pow)))->oclAsType(long)) - 1)) ; var allok : boolean ; allok := true ; var k : int ; k := 0 ; while ((1*(2->pow(k)))->oclAsType(long)) <= n do ( ( if ((((1*(2->pow(k)))->oclAsType(long)) & n) = 0) then ( allok := false ; break ) else skip ) ; k := k + 1 ) ; if (allok) then ( ans := ans->including(pow) ; break ) else skip ; cnt := cnt + 1 ; n := n+(1) ; ans := ans->including(pow) ; ) ; i := i + 1 ) ; if (cnt = 0) then skip else ( skip ; for (a : ans) do ( skip ; ) ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.HashSet ; import java.util.Scanner ; public class Main { public static long N ; public static HashSetset ; public static void main(String[] args){ Scanner s=new Scanner(System.in); N=s.nextLong(); set=new HashSet(); long curr=1 ; for(int i=0 ; i<60 ; i++){ curr*=2 ; set.add(curr-1); } int count=0 ; ArrayListlist=new ArrayList(); while(! set.contains(N)){ int k=highest(N); long xor=(1L<<(k+1))-1 ; list.add(k+1); N ^=xor ; count++; if(set.contains(N)){ break ; } N++; count++; } System.out.println(count); for(long i : list){ System.out.print(i+" "); } } public static int highest(long i){ for(int k=40 ; k>=0 ; k--){ if(((i>>k)& 1)==1){ return k ; } } return-1 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute N : long; static attribute set : Set(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := s.getCurrent()->toLong() ; set := Set{} ; var curr : long ; curr := 1 ; var i : int ; i := 0 ; while i < 60 do ( ( curr := curr*(2) ; set := set->including(curr - 1) ) ; i := i + 1 ) ; var count : int ; count := 0 ; var list : Sequence(int) ; list := Sequence{} ; while (not(set->includes(N))) do ( var k : int ; k := highest(N) ; var xor : long ; xor := ((1L*(2->pow((k + 1))))->oclAsType(long)) - 1 ; list := list->including(k + 1) ; N := MathLib.bitwiseXor(N,xor) ; count := count + 1 ; if (set->includes(N)) then ( break ) else skip ; N := N + 1 ; count := count + 1 ; ) ; OclFile["System.out"].println(count) ; for (i : list) do ( ( OclFile["System.out"].print(i + " ") ) ) ; ); static operation highest( i : long) : int pre: true post: true activity: ( var k : int ; k := 40 ; while k >= 0 do ( ( if ((((i/(2->pow(k)))->oclAsType(long)) & 1) = 1) then ( return k ) else skip ) ; k := k - 1 ) ; return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int[] arr=new int[n]; for(int i=0 ; ihs=new HashSet<>(); ArrayListlengths=new ArrayList<>(); HashMaph=new HashMap<>(); for(int i=0 ; i0){ if(hs.contains(arr[i])){ System.out.println(-1); return ; } else { hs.add(arr[i]); h.put(arr[i],1); iszero++; if(hs.size()==1){ count=i ; } } } else { if(hs.contains(arr[i])){ System.out.println(-1); return ; } else { int x=Math.abs(arr[i]); if(! hs.contains(x)){ System.out.println(-1); return ; } else { hs.add(arr[i]); h.put(x,0); iszero--; if(iszero==0){ lengths.add(i-count+1); hs.clear(); h.clear(); } } } } if(i==n-1 && hs.size()>0){ System.out.println(-1); return ; } } System.out.println(lengths.size()); for(int e : lengths)System.out.print(e+" "); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := s.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; execute fun(arr, n) ; ); static operation fun( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var iszero : int ; iszero := 0 ; var count : int ; count := 0 ; var ans1 : int ; ans1 := 0 ; var hs : Set(int) ; hs := Set{} ; var lengths : Sequence(int) ; lengths := Sequence{} ; var h : Map(int,int) ; h := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] > 0) then ( if (hs->includes(arr[i+1])) then ( OclFile["System.out"].println(-1) ; return ) else ( hs := hs->including(arr[i+1]) ; h := h->union(Map{arr[i+1] |-> 1}) ; iszero := iszero + 1 ; if (hs->size() = 1) then ( count := i ) else skip ) ) else ( if (hs->includes(arr[i+1])) then ( OclFile["System.out"].println(-1) ; return ) else ( var x : int ; x := if arr[i+1] < 0 then -(arr[i+1]) else arr[i+1] endif ; if (not(hs->includes(x))) then ( OclFile["System.out"].println(-1) ; return ) else ( hs := hs->including(arr[i+1]) ; h := h->union(Map{x |-> 0}) ; iszero := iszero - 1 ; if (iszero = 0) then ( lengths := lengths->including(i - count + 1) ; hs := hs->intersection(Set{}) ; h := h->intersection(Map{}) ) else skip ) ) ) ; if (i = n - 1 & hs->size() > 0) then ( OclFile["System.out"].println(-1) ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(lengths->size()) ; for (e : lengths) do ( OclFile["System.out"].print(e + " ") ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.lang.*; public class Main { public static int inf=(int)1e9+7 ; public static void main(String[] args)throws IOException,InterruptedException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out)); Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int len=0 ; for(int i=31 ; i>=0 ; i--){ if(((x>>i)& 1)==1){ len=i+1 ; break ; } } int opt=1 ; if(x==(1<<(len+1))-1){ System.out.println(0); } else { Listlist=new ArrayList<>(); while(x!=(1<<(len))-1){ if(opt % 2==0){ opt++; x++; } else { for(int i=len-1 ; i>=0 ; i--){ if(((x>>i)& 1)==0){ x ^=(1<<(i+1))-1 ; list.add(i+1); opt++; break ; } } } } System.out.println(opt-1); for(int y : list){ System.out.print(y+" "); } } sc.close(); writer.flush(); writer.close(); reader.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute inf : int := 1e9->oclAsType(int) + 7; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var writer : OclFile ; writer := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var len : int ; len := 0 ; var i : int ; i := 31 ; while i >= 0 do ( ( if ((((x/(2->pow(i)))->oclAsType(long)) & 1) = 1) then ( len := i + 1 ; break ) else skip ) ; i := i - 1 ) ; var opt : int ; opt := 1 ; if (x = ((1*(2->pow((len + 1))))->oclAsType(long)) - 1) then ( OclFile["System.out"].println(0) ) else ( var list : Sequence(int) ; list := Sequence{} ; while (x /= ((1*(2->pow((len))))->oclAsType(long)) - 1) do ( if (opt mod 2 = 0) then ( opt := opt + 1 ; x := x + 1 ) else ( var i : int ; i := len - 1 ; while i >= 0 do ( ( if ((((x/(2->pow(i)))->oclAsType(long)) & 1) = 0) then ( x := MathLib.bitwiseXor(x,((1*(2->pow((i + 1))))->oclAsType(long)) - 1) ; list := list->including(i + 1) ; opt := opt + 1 ; break ) else skip ) ; i := i - 1 ) ) ) ; OclFile["System.out"].println(opt - 1) ; for (y : list) do ( ( OclFile["System.out"].print(y + " ") ) ) ) ; skip ; skip ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Map ; class GfG { static int sumKRepeating(int arr[],int n,int k){ int sum=0 ; HashMapmp=new HashMap<>(); for(int i=0 ; ikeys()->includes(arr[i+1]))) then mp := mp->union(Map{arr[i+1] |-> 0}) ; else skip ; mp := mp->union(Map{arr[i+1] |-> mp->at(arr[i+1]) + 1}) ) ; i := i + 1 ) ; for (x : mp->keys()) do ( if (mp->at(x) = k) then sum := sum+(x) ; else skip ; ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{9,9,10,11,8,8,9,8} ; var n : int ; n := arr->size() ; var k : int ; k := 3 ; OclFile["System.out"].println(sumKRepeating(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashSet ; import java.util.List ; import java.util.Scanner ; import java.util.Set ; import java.util.stream.Collectors ; import java.util.stream.Stream ; public class Temp { static BufferedReader br=null ; static Scanner sc=null ; public static void main(String[] args){ br=new BufferedReader(new InputStreamReader(System.in)); sc=new Scanner(System.in); try { int n=sc.nextInt(); int m=sc.nextInt(); int[][] marks=new int[n][m]; int[] subjects=new int[m]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var marks : Sequence(Sequence(int)) ; marks := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var subjects : Sequence(int) ; subjects := Integer.subrange(1,m)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var line : Sequence(String) ; line := sc.getCurrent()->characters() ; var j : int ; j := 0 ; while j < m do ( ( marks[i+1][j+1] := line[j+1] - ('0')->char2byte() ; subjects[j+1] := Set{subjects[j+1], marks[i+1][j+1]}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sucessfull : int ; sucessfull := 0 ; for (student : marks) do ( ( var i : int ; i := 0 ; while i < m do ( ( if (student[i+1] = subjects[i+1]) then ( sucessfull := sucessfull + 1 ; break ) else skip ) ; i := i + 1 ) ) ) ; OclFile["System.out"].println(sucessfull) ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.OutputStream ; import java.io.PrintStream ; import java.util.*; public class P152A { public static void main(String[] args)throws Exception { new P152A().run(); } void run()throws Exception { Scanner scanner=new Scanner(getInputStream()); int n=scanner.nextInt(); int m=scanner.nextInt(); String[] grades=new String[n]; for(int i=0 ; imax){ max=grades[i] .charAt(s); } } for(int i=0 ; itoInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; var grades : Sequence(String) ; grades := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( grades[i+1] := scanner.getCurrent() ) ; i := i + 1 ) ; var best : Sequence(boolean) ; best := Integer.subrange(1,n)->collect(false) ; var s : int ; s := 0 ; while s < m do ( ( var max : String ; max := '0' ; var i : int ; i := 0 ; while i < n do ( ( if (grades[i+1]->at(s+1) > max) then ( max := grades[i+1]->at(s+1) ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (grades[i+1]->at(s+1) = max) then ( best[i+1] := true ) else skip ) ; i := i + 1 ) ) ; s := s + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (best[i+1]) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; getOutputStream().println(count) ; ); operation getInputStream() : OclFile pre: true post: true activity: ( return OclFile["System.in"] ); operation getOutputStream() : OclFile pre: true post: true activity: ( return OclFile["System.out"] ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner imput=new Scanner(System.in); int a=imput.nextInt(); int b=imput.nextInt(); int c=imput.nextInt(); int max,mid,min ; if(a>b){ if(a>c){ max=a ; if(b>c){ mid=b ; min=c ; } else { mid=c ; min=b ; } } else { max=c ; mid=a ; min=b ; } } else if(a>c){ max=b ; mid=a ; min=c ; } else { min=a ; if(b>c){ max=b ; mid=c ; } else { max=c ; mid=b ; } } System.out.println(min+" "+mid+" "+max); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var imput : OclFile ; imput := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := imput.getCurrent()->toInteger() ; var b : int ; b := imput.getCurrent()->toInteger() ; var c : int ; c := imput.getCurrent()->toInteger() ; var max : int ; var mid : int ; var min : int ; if (a > b) then ( if (a > c) then ( max := a ; if (b > c) then ( mid := b ; min := c ) else ( mid := c ; min := b ) ) else ( max := c ; mid := a ; min := b ) ) else if (a > c) then ( max := b ; mid := a ; min := c ) else ( min := a ; if (b > c) then ( max := b ; mid := c ) else ( max := c ; mid := b ) ) ; ; OclFile["System.out"].println(min + " " + mid + " " + max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); long matrix[][]=new long[n][m]; boolean arr[]=new boolean[n]; for(int i=0 ; i=0 ; j--){ long r=Long.parseLong(Character.toString(num.charAt(len-1))); matrix[i][j]=r ; len--; } } long max=0 ; for(int j=0 ; jlist=new ArrayList<>(); for(int i=0 ; imax){ list.clear(); list.add(i); max=matrix[i][j]; } } for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var matrix : Sequence(Sequence(long)) ; matrix := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var arr : Sequence(boolean) ; arr := Integer.subrange(1,n)->collect(false) ; var i : int ; i := 0 ; while i < n do ( ( var num : String ; num := sc.getCurrent() ; var len : int ; len := num->size() ; var j : int ; j := m - 1 ; while j >= 0 do ( ( var r : long ; r := ((num->at((len)->char2byte() - 1+1) + ""))->toLong() ; matrix[i+1][j+1] := r ; len := len - 1 ) ; j := j - 1 ) ) ; i := i + 1 ) ; var max : long ; max := 0 ; var j : int ; j := 0 ; while j < m do ( ( max := matrix[0+1][j+1] ; var list : Sequence(int) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( if (matrix[i+1][j+1] = max) then ( list := list->including(i) ) else if (matrix[i+1][j+1] > max) then ( list := list->intersection(Set{}) ; list := list->including(i) ; max := matrix[i+1][j+1] ) else skip ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < list->size() do ( ( arr[list->at(i+1)+1] := true ) ; i := i + 1 ) ; list := list->intersection(Set{}) ; ) ; j := j + 1 ) ; var count : long ; count := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] = true) then ( count := count + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int noofstudent=sc.nextInt(); int noofsubjects=sc.nextInt(); int arr[][]=new int[noofstudent][noofsubjects]; for(int i=0 ; iset=new HashSet<>(); for(int i=0 ; iminmarks){ minmarks=arr[j][i]; } } for(int j=0 ; jtoInteger() ; var noofsubjects : int ; noofsubjects := sc.getCurrent()->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,noofstudent)->collect(Integer.subrange(1,noofsubjects)->collect(0)) ; var i : int ; i := 0 ; while i < noofstudent do ( ( var s : String ; s := sc.getCurrent() ; var j : int ; j := 0 ; while j < noofsubjects do ( ( arr[i+1][j+1] := s->at(j+1) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < noofsubjects do ( ( var minmarks : int ; minmarks := -2147483648 ; var j : int ; j := 0 ; while j < noofstudent do ( ( if (arr[j+1][i+1] > minmarks) then ( minmarks := arr[j+1][i+1] ) else skip ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < noofstudent do ( ( if (arr[j+1][i+1] = minmarks) then ( set := set->including(j) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(set->size()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findLength(String str,int n){ int sum[]=new int[n+1]; sum[0]=0 ; for(int i=1 ; i<=n ; i++)sum[i]=(sum[i-1]+str.charAt(i-1)-'0'); int ans=0 ; for(int len=2 ; len<=n ; len+=2){ for(int i=0 ; i<=n-len ; i++){ int j=i+len-1 ; if(sum[i+len/2]-sum[i]==sum[i+len]-sum[i+len/2])ans=Math.max(ans,len); } } return ans ; } public static void main(String[] args){ String str="123123" ; System.out.println("Length of the substring is "+findLength(str,str.length())); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findLength( str : String, n : int) : int pre: true post: true activity: ( var sum : Sequence(int) ; sum := Integer.subrange(1,n + 1)->collect(0) ; sum[0+1] := 0 ; var i : int ; i := 1 ; while i <= n do ( sum[i+1] := (sum[i - 1+1] + str->at(i - 1+1) - ('0')->char2byte()) ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var len : int ; len := 2 ; while len <= n do ( ( var i : int ; i := 0 ; while i <= n - len do ( ( var j : int ; j := i + len - 1 ; if (sum[i + len / 2+1] - sum[i+1] = sum[i + len+1] - sum[i + len / 2+1]) then ans := Set{ans, len}->max() ; else skip ) ; i := i + 1 ) ) ; len := len+(2) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "123123" ; OclFile["System.out"].println("Length of the substring is " + findLength(str, str->size())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ double x=sc.nextDouble(); System.out.println(x<=48.00 ? "light fly" : x<=51.00 ? "fly" : x<=54.00 ? "bantam" : x<=57.00 ? "feather" : x<=60.00 ? "light" : x<=64.00 ? "light welter" : x<=69.00 ? "welter" : x<=75.00 ? "light middle" : x<=81.00 ? "middle" : x<=91.00 ? "light heavy" : "heavy"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var x : double ; x := sc.getCurrent()->toReal() ; OclFile["System.out"].println(if x <= 48.00 then "light fly" else if x <= 51.00 then "fly" else if x <= 54.00 then "bantam" else if x <= 57.00 then "feather" else if x <= 60.00 then "light" else if x <= 64.00 then "light welter" else if x <= 69.00 then "welter" else if x <= 75.00 then "light middle" else if x <= 81.00 then "middle" else if x <= 91.00 then "light heavy" else "heavy" endif endif endif endif endif endif endif endif endif endif) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static String judge(double w){ if(w<=48.0){ return "light fly" ; } else if(w>=48.0 && w<=51.0){ return "fly" ; } else if(w>=51.0 && w<=54.0){ return "bantam" ; } else if(w>=54.0 && w<=57.0){ return "feather" ; } else if(w>=57.0 && w<=60.0){ return "light" ; } else if(w>=60.0 && w<=64.0){ return "light welter" ; } else if(w>=64.0 && w<=69.0){ return "welter" ; } else if(w>=69.0 && w<=75.0){ return "light middle" ; } else if(w>=75.0 && w<=81.0){ return "middle" ; } else if(w>=81.0 && w<=91.0){ return "light heavy" ; } else { return "heavy" ; } } public static void main(String[] args)throws IOException { Scanner stdIn=null ; Listresult=new ArrayList(); try { stdIn=new Scanner(new BufferedReader(new InputStreamReader(System.in))); while(stdIn.hasNext()){ double w=stdIn.nextDouble(); result.add(judge(w)); } for(String str : result){ System.out.println(str); } } finally { if(stdIn!=null){ stdIn.close(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation judge( w : double) : String pre: true post: true activity: ( if (w <= 48.0) then ( return "light fly" ) else if (w >= 48.0 & w <= 51.0) then ( return "fly" ) else if (w >= 51.0 & w <= 54.0) then ( return "bantam" ) else if (w >= 54.0 & w <= 57.0) then ( return "feather" ) else if (w >= 57.0 & w <= 60.0) then ( return "light" ) else if (w >= 60.0 & w <= 64.0) then ( return "light welter" ) else if (w >= 64.0 & w <= 69.0) then ( return "welter" ) else if (w >= 69.0 & w <= 75.0) then ( return "light middle" ) else if (w >= 75.0 & w <= 81.0) then ( return "middle" ) else if (w >= 81.0 & w <= 91.0) then ( return "light heavy" ) else ( return "heavy" ) ; ; ; ; ; ; ; ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := null ; var result : Sequence(String) ; result := Sequence{} ; try ( stdIn := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; while (stdIn.hasNext()) do ( var w : double ; w := stdIn.getCurrent()->toReal() ; result := result->including(judge(w)) ) ; for (str : result) do ( ( OclFile["System.out"].println(str) ) ) ) finally ( if (stdIn /= null) then ( skip ) else skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int getRemainder(int num,int divisor){ return(num-divisor*(num/divisor)); } public static void main(String[] args){ System.out.println(getRemainder(100,7)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getRemainder( num : int, divisor : int) : int pre: true post: true activity: ( return (num - divisor * (num / divisor)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(getRemainder(100, 7)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static void solve(double w){ String res="" ; if(w<=48.0)res="light fly" ; else if(w<=51.0)res="fly" ; else if(w<=54.0)res="bantam" ; else if(w<=57.0)res="feather" ; else if(w<=60.0)res="light" ; else if(w<=64.0)res="light welter" ; else if(w<=69.0)res="welter" ; else if(w<=75.0)res="light middle" ; else if(w<=81.0)res="middle" ; else if(w<=91.0)res="light heavy" ; else res="heavy" ; System.out.println(res); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ double weight=sc.nextDouble(); solve(weight); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation solve( w : double) : void pre: true post: true activity: ( var res : String ; res := "" ; if (w <= 48.0) then res := "light fly" else if (w <= 51.0) then res := "fly" else if (w <= 54.0) then res := "bantam" else if (w <= 57.0) then res := "feather" else if (w <= 60.0) then res := "light" else if (w <= 64.0) then res := "light welter" else if (w <= 69.0) then res := "welter" else if (w <= 75.0) then res := "light middle" else if (w <= 81.0) then res := "middle" else if (w <= 91.0) then res := "light heavy" else res := "heavy" ; ; ; ; ; ; ; ; ; ; ; OclFile["System.out"].println(res) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var weight : double ; weight := sc.getCurrent()->toReal() ; execute solve(weight) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); StringBuilder builder=new StringBuilder(); String line ; String now="A" ; while((line=reader.readLine())!=null){ if(line.isEmpty())break ; double a=Double.parseDouble(line); if(a>91.00)builder.append("heavy").append('\n'); else if(a>81.00)builder.append("light heavy").append('\n'); else if(a>75.00)builder.append("middle").append('\n'); else if(a>69.00)builder.append("light middle").append('\n'); else if(a>64.00)builder.append("welter").append('\n'); else if(a>60.00)builder.append("light welter").append('\n'); else if(a>57.00)builder.append("light").append('\n'); else if(a>54.00)builder.append("feather").append('\n'); else if(a>51.00)builder.append("bantam").append('\n'); else if(a>48.00)builder.append("fly").append('\n'); else builder.append("light fly").append('\n'); } System.out.print(builder); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var builder : String ; builder := StringLib.newString() ; var line : String ; var now : String ; now := "A" ; line := reader.readLine() ; while ((line) /= null) do ( skip ; ( if (line->isEmpty()) then break else skip ; var a : double ; a := (line)->toReal() ; if (a > 91.00) then builder := builder + StringLib.newString("heavy") + StringLib.newString(' ') ; else if (a > 81.00) then builder := builder + StringLib.newString("light heavy") + StringLib.newString(' ') else if (a > 75.00) then builder := builder + StringLib.newString("middle") + StringLib.newString(' ') else if (a > 69.00) then builder := builder + StringLib.newString("light middle") + StringLib.newString(' ') else if (a > 64.00) then builder := builder + StringLib.newString("welter") + StringLib.newString(' ') else if (a > 60.00) then builder := builder + StringLib.newString("light welter") + StringLib.newString(' ') else if (a > 57.00) then builder := builder + StringLib.newString("light") + StringLib.newString(' ') else if (a > 54.00) then builder := builder + StringLib.newString("feather") + StringLib.newString(' ') else if (a > 51.00) then builder := builder + StringLib.newString("bantam") + StringLib.newString(' ') else if (a > 48.00) then builder := builder + StringLib.newString("fly") + StringLib.newString(' ') else builder := builder + StringLib.newString("light fly") + StringLib.newString(' ') ; ; ; ; ; ; ; ; ; ; ) ; line := reader.readLine() ; ) ; OclFile["System.out"].print(builder) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static final String LIGHT="light" ; public static final String FLY="fly" ; public static final String BANTAM="bantam" ; public static final String FETHER="feather" ; public static final String WELTER="welter" ; public static final String MIDDLE="middle" ; public static final String HEAVY="heavy" ; public static void main(String[] args){ Scanner scanner=null ; try { scanner=new Scanner(System.in); while(scanner.hasNextDouble()){ double weight=scanner.nextDouble(); System.out.println(getClassName(weight)); } } finally { scanner.close(); } } public static String getClassName(double num){ StringBuilder sb=new StringBuilder(); if(num<=48.00 ||(57.00toReal() ; OclFile["System.out"].println(getClassName(weight)) ) ) finally ( skip ) ); static operation getClassName( num : double) : String pre: true post: true activity: ( var sb : String ; sb := StringLib.newString() ; if (num <= 48.00 or (57.00 < num & num <= 64.00) or (69.00 < num & num <= 75.00) or (81.00 < num & num <= 91.00)) then ( sb := sb + StringLib.newString(LIGHT) ; sb := sb + StringLib.newString(" ") ) else skip ; if (num <= 51.00) then ( sb := sb + StringLib.newString(FLY) ) else if (num <= 54.00) then ( sb := sb + StringLib.newString(BANTAM) ) else if (num <= 57.00) then ( sb := sb + StringLib.newString(FETHER) ) else if (num <= 60.00) then skip else if (num <= 69.00) then ( sb := sb + StringLib.newString(WELTER) ) else if (num <= 81.00) then ( sb := sb + StringLib.newString(MIDDLE) ) else ( sb := sb + StringLib.newString(HEAVY) ) ; ; ; ; ; ; return sb+""->trim() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class A_545 { public static void main(String[] args){ FastReader sc=new FastReader(); int n=sc.nextInt(); ArrayListlt=new ArrayList(); for(int i=0 ; iincluding(i + 1) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(lt->size()) ; var i : int ; i := 0 ; while i < lt->size() do ( OclFile["System.out"].print(lt->at(i+1) + " ") ; ; i := i + 1 ) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return (str) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class a { private static Scanner sc=new Scanner(System.in); private static int n ; private static VectormVector=new Vector<>(); private static void solve()throws Exception { VectoransVector=new Vector<>(); int index=0 ; for(int i=0 ; iat(index+1) = 3 or mVector->at(index+1) = 1) then ( flag := false ; break ) else skip ) ; j := j + 1 ; index := index + 1 ) ; if (flag) then ( ansVector := ansVector->including(i + 1) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ansVector->size()) ; if (ansVector->size() /= 0) then ( for (integer : ansVector) do ( ( OclFile["System.out"].print(integer + " ") ) ) ) else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n * n do ( ( mVector := mVector->including(sc.getCurrent()->toInteger()) ) ; i := i + 1 ) ; execute solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int[] num={ 0,0,0 }; for(int i=0 ; ii ; j--){ if(a[j]size() do ( ( num[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; bubbleSort.sort(num) ; OclFile["System.out"].print(num[0+1]) ; var i : int ; i := 1 ; while i < num->size() do ( ( OclFile["System.out"].print(" " + num[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println("") ; skip ; ); } class bubbleSort { static operation sort( a : Sequence(int)) : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < a->size() - 1 do ( ( var j : int ; j := a->size() - 1 ; while j > i do ( ( if (a[j+1] < a[j - 1+1]) then ( var t : int ; t := a[j+1] ; a[j+1] := a[j - 1+1] ; a[j - 1+1] := t ) else skip ) ; j := j - 1 ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; import java.math.*; public class J_545 { public static void main(String[] args){ Scanner cin=new Scanner(System.in); int n,ans=0 ; n=cin.nextInt(); int[][] arr=new int[102][102]; int[] collision=new int[102]; for(int i=1 ; i<=n ; i++){ for(int k=1 ; k<=n ; k++){ arr[i][k]=cin.nextInt(); if(arr[i][k]==1)collision[i]=1 ; else if(arr[i][k]==2)collision[k]=1 ; else if(arr[i][k]==3){ collision[i]=1 ; collision[k]=1 ; } } } boolean isStart=true ; for(int i=1 ; i<=n ; i++){ if(collision[i]==0)ans++; } System.out.println(ans); if(ans>0){ for(int i=1 ; i<=n ; i++){ if(collision[i]==0){ ans++; if(isStart==false)System.out.print(" "); isStart=false ; System.out.print(i); } } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class J_545 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var ans : int ; ans := 0 ; n := cin.getCurrent()->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,102)->collect(Integer.subrange(1,102)->collect(0)) ; var collision : Sequence(int) ; collision := Integer.subrange(1,102)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( var k : int ; k := 1 ; while k <= n do ( ( arr[i+1][k+1] := cin.getCurrent()->toInteger() ; if (arr[i+1][k+1] = 1) then collision[i+1] := 1 ; else if (arr[i+1][k+1] = 2) then collision[k+1] := 1 else if (arr[i+1][k+1] = 3) then ( collision[i+1] := 1 ; collision[k+1] := 1 ) else skip ; ; ) ; k := k + 1 ) ) ; i := i + 1 ) ; var isStart : boolean ; isStart := true ; var i : int ; i := 1 ; while i <= n do ( ( if (collision[i+1] = 0) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; if (ans > 0) then ( var i : int ; i := 1 ; while i <= n do ( ( if (collision[i+1] = 0) then ( ans := ans + 1 ; if (isStart = false) then OclFile["System.out"].print(" ") ; else skip ; isStart := false ; OclFile["System.out"].print(i) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println() ) else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void rearrange(int a[],int size){ int positive=0,negative=1,temp ; while(true){ while(positive=0)positive+=2 ; while(negative= 0) do positive := positive+(2) ; ; while (negative < size & a[negative+1] <= 0) do negative := negative+(2) ; ; if (positive < size & negative < size) then ( temp := a[positive+1] ; a[positive+1] := a[negative+1] ; a[negative+1] := temp ) else break ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,-3,5,6,-3,6,7,-4,9,10} ; var n : int ; n := arr->size() ; execute rearrange(arr, n) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.PriorityQueue ; import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int K=scan.nextInt(); int[] dp=new int[K]; Arrays.fill(dp,Integer.MAX_VALUE); class Node { int to,cost ; Node(int to,int cost){ this.to=to ; this.cost=cost ; } } PriorityQueueque=new PriorityQueue<>((a,b)->a.cost-b.cost); for(int i=1 ; idp[v])continue ; for(int i=0 ; i<10 ; ++i){ int nextv=(v*10+i)% K ; int nextc=c+i ; if(dp[nextv]>nextc){ dp[nextv]=nextc ; que.add(new Node(nextv,nextc)); } } } System.out.println(dp[0]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var K : int ; K := scan.getCurrent()->toInteger() ; var dp : Sequence(int) ; dp := Integer.subrange(1,K)->collect(0) ; dp := dp->collect(2147483647) ; class Node { attribute to : int; static operation newNode( to : int, cost : int) : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(to, cost); return self ); operation initialise( to : int, cost : int) : void pre: true post: true activity: ( self.to := to ; self.cost := cost ); } var que : Sequence(Node) ; que := Sequence{}->union(lambda (a , b) : OclAny in a.cost - b.cost) ; var i : int ; i := 1 ; while i < Set{10, K}->min() do ( ( dp[i+1] := i ; que := que->including(Node.newNode(i, i)) ) ; i := i + 1 ) ; while (not(que->isEmpty())) do ( var node : Node ; node := que->min() ; var v : int ; v := node.to ; var c : int ; c := node.cost ; if (c > dp[v+1]) then continue else skip ; var i : int ; i := 0 ; while i < 10 do ( ( var nextv : int ; nextv := (v * 10 + i) mod K ; var nextc : int ; nextc := c + i ; if (dp[nextv+1] > nextc) then ( dp[nextv+1] := nextc ; que := que->including(Node.newNode(nextv, nextc)) ) else skip ) ; i := i + 1 ) ; ) ; OclFile["System.out"].println(dp[0+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); int[] dist=new int[k]; for(int i=0 ; ideque=new ArrayDeque<>(); deque.addFirst(1); int[] visit=new int[k]; visit[1]=1 ; while(deque.size()>0){ int u=deque.pollFirst(); int v1=(10*u)% k ; int v2=(u+1)% k ; if(visit[v1]==0){ dist[v1]=Math.min(dist[v1],dist[u]); deque.addFirst(v1); visit[v1]=1 ; } else { if(dist[v1]>dist[u]){ dist[v1]=dist[u]; deque.remove(v1); deque.addFirst(v1); } } if(visit[v2]==0){ dist[v2]=Math.min(dist[v2],dist[u]+1); deque.addLast(v2); visit[v2]=1 ; } } System.out.println(dist[0]+1); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var dist : Sequence(int) ; dist := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < k do ( ( dist[i+1] := 2147483647 ) ; i := i + 1 ) ; dist[1+1] := 0 ; var deque : Sequence(int) ; deque := ArrayDeque.newArrayDeque() ; deque := deque->prepend(1) ; var visit : Sequence(int) ; visit := Integer.subrange(1,k)->collect(0) ; visit[1+1] := 1 ; while (deque->size() > 0) do ( var u : int ; u := deque->first() ; var v1 : int ; v1 := (10 * u) mod k ; var v2 : int ; v2 := (u + 1) mod k ; if (visit[v1+1] = 0) then ( dist[v1+1] := Set{dist[v1+1], dist[u+1]}->min() ; deque := deque->prepend(v1) ; visit[v1+1] := 1 ) else ( if (dist[v1+1] > dist[u+1]) then ( dist[v1+1] := dist[u+1] ; deque := deque->excludingAt(v1+1) ; deque := deque->prepend(v1) ) else skip ) ; if (visit[v2+1] = 0) then ( dist[v2+1] := Set{dist[v2+1], dist[u+1] + 1}->min() ; deque := deque->append(v2) ; visit[v2+1] := 1 ) else skip ; ) ; OclFile["System.out"].println(dist[0+1] + 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class tennis { public static void main(String[] args){ Scanner in=new Scanner(System.in); StringBuilder sb=new StringBuilder(); int res=0,cnt1=0,cnt2=0 ; int n=in.nextInt(),m=in.nextInt(),z=in.nextInt(); for(int i=m ; i<=z ; i+=m){ for(int j=n ; j<=z ; j+=n){ if(i==j)res++; } } System.out.println(res); } } ------------------------------------------------------------ OCL File: --------- class tennis { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var sb : String ; sb := StringLib.newString() ; var res : int ; res := 0 ; var cnt1 : int ; cnt1 := 0 ; var cnt2 : int ; cnt2 := 0 ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var z : int ; z := in.getCurrent()->toInteger() ; var i : int ; i := m ; while i <= z do ( ( var j : int ; j := n ; while j <= z do ( ( if (i = j) then res := res + 1 ; else skip ) ; j := j+(n) ) ) ; i := i+(m) ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args){ solve(); } public static void solve(){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); Dequedq=new ArrayDeque(); boolean[] judge=new boolean[k]; Arrays.fill(judge,true); Point now=new Point(1,1); dq.add(now); while(! dq.isEmpty()){ Point z=dq.removeFirst(); if(! judge[(z.x)]){ continue ; } judge[(z.x)]=false ; if(z.x==0){ System.out.println(z.y); break ; } if(judge[(z.x*10)% k]){ dq.addFirst(new Point((z.x*10)% k,z.y)); } if(judge[(z.x+1)% k]){ dq.addLast(new Point((z.x+1)% k,z.y+1)); } } } } class Point { int x ; int y ; Point(int x,int y){ this.x=x ; this.y=y ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); static operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var k : int ; k := sc.getCurrent()->toInteger() ; var dq : Sequence(Point) ; dq := ArrayDeque.newArrayDeque() ; var judge : Sequence(boolean) ; judge := Integer.subrange(1,k)->collect(false) ; judge := judge->collect(true) ; var now : Point ; now := Point.newPoint(1, 1) ; dq := dq->including(now) ; while (not(dq->isEmpty())) do ( var z : Point ; z := dq->first() ; if (not(judge[(z.x)+1])) then ( continue ) else skip ; judge[(z.x)+1] := false ; if (z.x = 0) then ( OclFile["System.out"].println(z.y) ; break ) else skip ; if (judge[(z.x * 10) mod k+1]) then ( dq := dq->prepend(Point.newPoint((z.x * 10) mod k, z.y)) ) else skip ; if (judge[(z.x + 1) mod k+1]) then ( dq := dq->append(Point.newPoint((z.x + 1) mod k, z.y + 1)) ) else skip ; ) ; ); } class Point { attribute x : int; attribute y : int; static operation newPoint( x : int, y : int) : Point pre: true post: true activity: ( var self : Point ; self := createPoint(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Deque ; import java.util.List ; import java.util.PriorityQueue ; import java.util.Queue ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().compute(); } void compute(){ Scanner sc=new Scanner(System.in); int K=sc.nextInt(); int[] one=new int[K]; int[] zero=new int[K]; for(int i=1 ; ique=new ArrayDeque<>(); int[] min=new int[K]; for(int i=0 ; itoInteger() ; var one : Sequence(int) ; one := Integer.subrange(1,K)->collect(0) ; var zero : Sequence(int) ; zero := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 1 ; while i < K do ( ( one[i+1] := (i + 1) mod K ; zero[i+1] := (i * 10) mod K ) ; i := i + 1 ) ; var que : Sequence(int) ; que := ArrayDeque.newArrayDeque() ; var min : Sequence(int) ; min := Integer.subrange(1,K)->collect(0) ; var i : int ; i := 0 ; while i < K do ( ( min[i+1] := 2147483647 ) ; i := i + 1 ) ; que := que->append(1) ; min[1+1] := 1 ; while (not(que->isEmpty())) do ( var cur : int ; cur := que->first() ; if (min[cur+1] + 1 < min[one[cur+1]+1]) then ( que := que->append(one[cur+1]) ; min[one[cur+1]+1] := min[cur+1] + 1 ) else skip ; if (min[cur+1] < min[zero[cur+1]+1]) then ( que := que->prepend(zero[cur+1]) ; min[zero[cur+1]+1] := min[cur+1] ) else skip ) ; OclFile["System.out"].println(min[0+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class Main { public static void main(String[] args){ final Scanner stdin=new Scanner(System.in); while(stdin.hasNextDouble()){ final double minV=stdin.nextDouble(); final double t=minV/9.8 ; final double y=4.9*t*t ; for(int i=0 ; i<100000 ; i++){ if(y<=5*i-5){ System.out.println(i); break ; } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdin : OclFile ; stdin := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (stdin.hasNextDouble()) do ( var minV : double ; minV := stdin.getCurrent()->toReal() ; var t : double ; t := minV / 9.8 ; var y : double ; y := 4.9 * t * t ; var i : int ; i := 0 ; while i < 100000 do ( ( if (y <= 5 * i - 5) then ( OclFile["System.out"].println(i) ; break ) else skip ) ; i := i + 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); double y,t,v ; for(; sc.hasNext(); ){ v=sc.nextDouble(); t=v/9.8 ; y=4.9*t*t ; out.println((int)y/5+2); } sc.close(); } public static void main(String[] args){ (new Main()).run(System.in,System.out); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run( in : InputStream, out : PrintStream) : void pre: true post: true activity: ( var sc : Scanner ; sc := Scanner.newScanner(in) ; var y : double ; var t : double ; var v : double ; while sc.hasNext() do ( ( v := sc.nextDouble() ; t := v / 9.8 ; y := 4.9 * t * t ; out.println(y->oclAsType(int) / 5 + 2) ) ) ; sc.close() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.io.InputStreamReader ; import java.io.BufferedReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null){ double v=Double.parseDouble(line); int f=0 ; while(true){ f++; double height=5*f-5 ; double t=Math.sqrt(height/4.9); double vReal=9.8*t ; if(vReal>=v)break ; } System.out.println(f); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; line := br.readLine() ; while ((line) /= null) do ( skip ; ( var v : double ; v := (line)->toReal() ; var f : int ; f := 0 ; while (true) do ( f := f + 1 ; var height : double ; height := 5 * f - 5 ; var t : double ; t := (height / 4.9)->sqrt() ; var vReal : double ; vReal := 9.8 * t ; if (vReal >= v) then break else skip ; ) ; OclFile["System.out"].println(f) ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in=new Scanner(System.in); static final PrintWriter out=new PrintWriter(System.out,false); static void solve(){ double v=in.nextDouble(); double t=v/9.8 ; double y=4.9*t*t ; for(int i=1 ; ; i++){ if(y<=5*i-5){ out.println(i); return ; } } } public static void main(String[] args){ long start=System.currentTimeMillis(); while(in.hasNext())solve(); out.flush(); long end=System.currentTimeMillis(); in.close(); out.close(); } static void trace(Object...o){ System.out.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"], false); static operation solve() : void pre: true post: true activity: ( var v : double ; v := in.getCurrent()->toReal() ; var t : double ; t := v / 9.8 ; var y : double ; y := 4.9 * t * t ; var i : int ; i := 1 ; while true do ( ( if (y <= 5 * i - 5) then ( skip ; return ) else skip ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var start : long ; start := OclDate.getSystemTime() ; while (in.hasNext()) do execute solve() ; ; skip ; var end : long ; end := OclDate.getSystemTime() ; skip ; skip ; ); static operation trace( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((o + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class anotherforA18 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int arr[]=new int[6]; for(int i=0 ; i<6 ; i++)arr[i]=in.nextInt(); if(isRight(arr)){ System.out.println("RIGHT"); return ; } for(int i=0 ; i<6 ; i++){ arr[i]++; if(isRight(arr)){ System.out.println("ALMOST"); return ; } arr[i]-=2 ; if(isRight(arr)){ System.out.println("ALMOST"); return ; } arr[i]++; } System.out.println("NEITHER"); } public static boolean isRight(int[] arr){ if(cal(arr))return false ; int v[]=new int[6]; for(int i=0 ; i<6 ; i++)v[i]=arr[(i+2)% 6]-arr[i]; if(v[0]*v[2]+v[1]*v[3]==0)return true ; if(v[2]*v[4]+v[3]*v[5]==0)return true ; if(v[0]*v[4]+v[1]*v[5]==0)return true ; return false ; } public static boolean cal(int[] arr){ int a=arr[2]-arr[0]; int b=arr[3]-arr[1]; int c=arr[4]-arr[0]; int d=arr[5]-arr[1]; if(b*c-a*d==0)return true ; return false ; } } ------------------------------------------------------------ OCL File: --------- class anotherforA18 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var arr : Sequence(int) ; arr := Integer.subrange(1,6)->collect(0) ; var i : int ; i := 0 ; while i < 6 do ( arr[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; if (isRight(arr)) then ( OclFile["System.out"].println("RIGHT") ; return ) else skip ; var i : int ; i := 0 ; while i < 6 do ( ( arr[i+1] := arr[i+1] + 1 ; if (isRight(arr)) then ( OclFile["System.out"].println("ALMOST") ; return ) else skip ; arr[i+1] := arr[i+1]-(2) ; if (isRight(arr)) then ( OclFile["System.out"].println("ALMOST") ; return ) else skip ; arr[i+1] := arr[i+1] + 1 ; ) ; i := i + 1 ) ; OclFile["System.out"].println("NEITHER") ; ); static operation isRight( arr : Sequence(int)) : boolean pre: true post: true activity: ( if (cal(arr)) then return false else skip ; var v : Sequence(int) ; v := Integer.subrange(1,6)->collect(0) ; var i : int ; i := 0 ; while i < 6 do ( v[i+1] := arr[(i + 2) mod 6+1] - arr[i+1] ; ; i := i + 1 ) ; if (v[0+1] * v[2+1] + v[1+1] * v[3+1] = 0) then return true else skip ; if (v[2+1] * v[4+1] + v[3+1] * v[5+1] = 0) then return true else skip ; if (v[0+1] * v[4+1] + v[1+1] * v[5+1] = 0) then return true else skip ; return false ); static operation cal( arr : Sequence(int)) : boolean pre: true post: true activity: ( var a : int ; a := arr[2+1] - arr[0+1] ; var b : int ; b := arr[3+1] - arr[1+1] ; var c : int ; c := arr[4+1] - arr[0+1] ; var d : int ; d := arr[5+1] - arr[1+1] ; if (b * c - a * d = 0) then return true else skip ; return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; class Main { private static final double G=9.8 ; public static void main(String args[]){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String buf ; try { while((buf=br.readLine())!=null){ double v=Double.parseDouble(buf); double t=v/G ; double y=(G/2)*t*t ; double N=(y+5)/5 ; System.out.println((int)Math.ceil(N)); } } catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute G : double := 9.8; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var buf : String ; try ( buf := br.readLine() ; while ((buf) /= null) do ( skip ; ( var v : double ; v := (buf)->toReal() ; var t : double ; t := v / G ; var y : double ; y := (G / 2) * t * t ; var N : double ; N := (y + 5) / 5 ; OclFile["System.out"].println((N)->ceil()->oclAsType(int)) ; ) ; buf := br.readLine() ; ) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws NumberFormatException,IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); StringBuilder builder=new StringBuilder(); String line ; while((line=reader.readLine())!=null){ if(line.isEmpty())break ; double a=Double.parseDouble(line); double sum=a ; for(int i=0 ; i<9 ; i++){ if(i % 2==0){ a=a*2 ; } else { a=a/3 ; } sum+=a ; } System.out.println(sum); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var builder : String ; builder := StringLib.newString() ; var line : String ; line := reader.readLine() ; while ((line) /= null) do ( skip ; ( if (line->isEmpty()) then break else skip ; var a : double ; a := (line)->toReal() ; var sum : double ; sum := a ; var i : int ; i := 0 ; while i < 9 do ( ( if (i mod 2 = 0) then ( a := a * 2 ) else ( a := a / 3 ) ; sum := sum+(a) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ; line := reader.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] a){ Scanner sc=new Scanner(System.in); for(; sc.hasNextDouble(); )System.out.println(7.8148148*sc.nextDouble()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( a : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while sc.hasNextDouble() do ( OclFile["System.out"].println(7.8148148 * sc.getCurrent()->toReal()) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Practise { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int same=0 ; Setset=new HashSet<>(); int min=Math.min(a,b); for(int i=1 ; i<=c/min ; i++){ if(a<=b){ set.add(i*b); if(set.contains(i*a))same++; } else { set.add(i*a); if(set.contains(i*b))same++; } } System.out.println(same); } } ------------------------------------------------------------ OCL File: --------- class Practise { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var same : int ; same := 0 ; var set : Set(int) ; set := Set{} ; var min : int ; min := Set{a, b}->min() ; var i : int ; i := 1 ; while i <= c / min do ( ( if (a <= b) then ( set := set->including(i * b) ; if (set->includes(i * a)) then same := same + 1 ; else skip ) else ( set := set->including(i * a) ; if (set->includes(i * b)) then same := same + 1 ; else skip ) ) ; i := i + 1 ) ; OclFile["System.out"].println(same) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; import java.math.BigDecimal ; class Main { public static void main(String args[]){ InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String buf ; try { while((buf=br.readLine())!=null){ BigDecimal a=new BigDecimal(buf); BigDecimal two=new BigDecimal("2.0"); BigDecimal three=new BigDecimal("3.0"); BigDecimal sum=new BigDecimal(buf); for(int i=2 ; i<=10 ; i++){ if(i % 2==0)a=two.multiply(a); else a=a.divide(three,10,BigDecimal.ROUND_FLOOR); sum=sum.add(a); } System.out.println(sum.toString()); } } catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(isr) ; var buf : String ; try ( buf := br.readLine() ; while ((buf) /= null) do ( skip ; ( var a : double ; a := double(buf) ; var two : double ; two := double("2.0") ; var three : double ; three := double("3.0") ; var sum : double ; sum := double(buf) ; var i : int ; i := 2 ; while i <= 10 do ( ( if (i mod 2 = 0) then a := two.multiply(a) else a := a.divide(three, 10, ROUND_FLOOR) ; ; sum := sum->excludes(a) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum+"") ; ) ; buf := br.readLine() ; ) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in=new Scanner(System.in); static final PrintWriter out=new PrintWriter(System.out,false); static void solve(){ double a=in.nextDouble(); double ans=0 ; for(int i=0 ; i<10 ; i++){ ans+=a ; if(i % 2==0)a*=2 ; else a/=3 ; } out.printf("%.8f\n",ans); } public static void main(String[] args){ long start=System.currentTimeMillis(); while(in.hasNext())solve(); out.flush(); long end=System.currentTimeMillis(); in.close(); out.close(); } static void trace(Object...o){ System.out.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"], false); static operation solve() : void pre: true post: true activity: ( var a : double ; a := in.getCurrent()->toReal() ; var ans : double ; ans := 0 ; var i : int ; i := 0 ; while i < 10 do ( ( ans := ans+(a) ; if (i mod 2 = 0) then a := a*(2) ; else a := a/(3) ; ) ; i := i + 1 ) ; skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var start : long ; start := OclDate.getSystemTime() ; while (in.hasNext()) do execute solve() ; ; skip ; var end : long ; end := OclDate.getSystemTime() ; skip ; skip ; ); static operation trace( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((o + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.text.NumberFormat ; import java.util.Scanner ; public class Main { public static void main(String arg[]){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ double n=sc.nextDouble(); double ans=0 ; double a[]=new double[11]; a[1]=n ; for(int i=2 ; i<=10 ; i++){ if(i % 2==0)a[i]=a[i-1]*2 ; else a[i]=a[i-1]/3 ; } for(int i=1 ; i<=10 ; i++)ans+=a[i]; NumberFormat d=NumberFormat.getInstance(); d.setMaximumFractionDigits(8); System.out.println(d.format(ans)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var n : double ; n := sc.getCurrent()->toReal() ; var ans : double ; ans := 0 ; var a : Sequence(double) ; a := Integer.subrange(1,11)->collect(0.0) ; a[1+1] := n ; var i : int ; i := 2 ; while i <= 10 do ( ( if (i mod 2 = 0) then a[i+1] := a[i - 1+1] * 2 ; else a[i+1] := a[i - 1+1] / 3 ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= 10 do ( ans := ans+(a[i+1]) ; ; i := i + 1 ) ; var d : NumberFormat ; d := NumberFormat.getInstance() ; d.setMaximumFractionDigits(8) ; OclFile["System.out"].println(d.format(ans)) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void IfExists(int arr[],int n){ int sum[]=new int[n]; Arrays.sort(arr); sum[0]=arr[0]; for(int i=1 ; ii){ lindex=m ; r=m-1 ; } else l=m+1 ; } if(sum[findex]==sum[n-1]-sum[lindex-1]){ flag=true ; break ; } } if(flag)System.out.println("Yes"); else System.out.println("No"); } public static void main(String args[]){ int arr[]={ 1,2,2,5 }; int n=arr.length ; IfExists(arr,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation IfExists( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var sum : Sequence(int) ; sum := Integer.subrange(1,n)->collect(0) ; arr := arr->sort() ; sum[0+1] := arr[0+1] ; var i : int ; i := 1 ; while i < n do ( sum[i+1] := sum[i - 1+1] + arr[i+1] ; ; i := i + 1 ) ; var max : int ; max := arr[n - 1+1] ; var flag : boolean ; flag := false ; var i : int ; i := 1 ; while i <= max do ( ( var findex : int ; findex := 0 ; var lindex : int ; lindex := 0 ; var l : int ; l := 0 ; var r : int ; r := n - 1 ; while (l <= r) do ( var m : int ; m := (l + r) / 2 ; if (arr[m+1] < i) then ( findex := m ; l := m + 1 ) else r := m - 1 ; ) ; l := 1 ; r := n ; flag := false ; while (l <= r) do ( var m : int ; m := (r + l) / 2 ; if (arr[m+1] > i) then ( lindex := m ; r := m - 1 ) else l := m + 1 ; ) ; if (sum[findex+1] = sum[n - 1+1] - sum[lindex - 1+1]) then ( flag := true ; break ) else skip ; ) ; i := i + 1 ) ; if (flag) then OclFile["System.out"].println("Yes") else OclFile["System.out"].println("No") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,2,5} ; var n : int ; n := arr->size() ; execute IfExists(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.*; import java.io.*; public class a171 { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine(); int x=Integer.parseInt(s.split(" ")[0]); int y=Integer.parseInt(s.split(" ")[1]); int curx=0 ; int cury=0 ; int ctr=0 ; int turns=0 ; int valx=1 ; int valy=1 ; int tc=0 ; while(true){ if(curx==x && cury==y){ break ; } tc++; if(tc % 2==0){ tc=1 ; turns++; } if(ctr % 2==0){ int prevx=curx ; if((ctr/2)% 2==0){ curx+=valx ; if(cury==y && x>prevx && xcurx && xprevy && ycury && ysplit(" ")[0+1])->toInteger() ; var y : int ; y := (s->split(" ")[1+1])->toInteger() ; var curx : int ; curx := 0 ; var cury : int ; cury := 0 ; var ctr : int ; ctr := 0 ; var turns : int ; turns := 0 ; var valx : int ; valx := 1 ; var valy : int ; valy := 1 ; var tc : int ; tc := 0 ; while (true) do ( if (curx = x & cury = y) then ( break ) else skip ; tc := tc + 1 ; if (tc mod 2 = 0) then ( tc := 1 ; turns := turns + 1 ) else skip ; if (ctr mod 2 = 0) then ( var prevx : int ; prevx := curx ; if ((ctr / 2) mod 2 = 0) then ( curx := curx+(valx) ; if (cury = y & x > prevx & x < curx) then ( break ) else skip ) else ( curx := curx-(valx) ; if (cury = y & x > curx & x < prevx) then ( break ) else skip ) ; valx := valx+(1) ) else ( var prevy : int ; prevy := cury ; if ((ctr / 2) mod 2 = 0) then ( cury := cury+(valy) ; if (curx = x & y > prevy & y < cury) then ( break ) else skip ) else ( cury := cury-(valy) ; if (curx = x & y > cury & y < prevy) then ( break ) else skip ) ; valy := valy+(1) ) ; ctr := ctr + 1 ; ) ; OclFile["System.out"].println(turns) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Map ; import java.util.HashMap ; public class A_Point_on_Spiral { static Scanner in=new Scanner(System.in); static int x,y ; static Mapmap=new HashMap<>(); public static void main(String[] amit){ x=in.nextInt(); y=in.nextInt(); if(x==0 && y==0){ System.out.println(0); } else if(-x+1=y){ System.out.println((1+(x-1)*4)); } else if(-y<=x && xtoInteger() ; y := in.getCurrent()->toInteger() ; if (x = 0 & y = 0) then ( OclFile["System.out"].println(0) ) else if (-x + 1 < y & x >= y) then ( OclFile["System.out"].println((1 + (x - 1) * 4)) ) else if (-y <= x & x < y) then ( OclFile["System.out"].println((2 + (y - 1) * 4)) ) else if (x <= y & y < -x) then ( OclFile["System.out"].println((3 + (-x - 1) * 4)) ) else ( OclFile["System.out"].println((4 + (-y - 1) * 4)) ) ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A279 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int X=in.nextInt(); int Y=in.nextInt(); int[][] diff=new int[][] { { 1,0 },{ 0,1 },{ -1,0 },{ 0,-1 } }; int x=0 ; int y=0 ; int length=1 ; int turns=0 ; while(true){ int direction=turns % 4 ; int nextx=x+length*diff[direction][0]; int nexty=y+length*diff[direction][1]; if(Math.min(x,nextx)<=X && X<=Math.max(x,nextx)&& Math.min(y,nexty)<=Y && Y<=Math.max(y,nexty)){ break ; } turns++; if(turns % 2==0){ length++; } x=nextx ; y=nexty ; } System.out.println(turns); } } ------------------------------------------------------------ OCL File: --------- class A279 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : int ; X := in.getCurrent()->toInteger() ; var Y : int ; Y := in.getCurrent()->toInteger() ; var diff : Sequence(Sequence(int)) ; diff := Sequence{Sequence{1,0},Sequence{0,1},Sequence{-1,0},Sequence{0,-1}} ; var x : int ; x := 0 ; var y : int ; y := 0 ; var length : int ; length := 1 ; var turns : int ; turns := 0 ; while (true) do ( var direction : int ; direction := turns mod 4 ; var nextx : int ; nextx := x + length * diff[direction+1][0+1] ; var nexty : int ; nexty := y + length * diff[direction+1][1+1] ; if (Set{x, nextx}->min() <= X & X <= Set{x, nextx}->max() & Set{y, nexty}->min() <= Y & Y <= Set{y, nexty}->max()) then ( break ) else skip ; turns := turns + 1 ; if (turns mod 2 = 0) then ( length := length + 1 ) else skip ; x := nextx ; y := nexty ; ) ; OclFile["System.out"].println(turns) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class A18 { static boolean right(int arr[]){ double x[]=new double[3]; x[0]=Math.pow(arr[0]-arr[2],2)+Math.pow(arr[1]-arr[3],2); x[1]=Math.pow(arr[0]-arr[4],2)+Math.pow(arr[1]-arr[5],2); x[2]=Math.pow(arr[4]-arr[2],2)+Math.pow(arr[5]-arr[3],2); Arrays.sort(x); if(x[0]+x[1]==x[2] && x[1]!=0 && x[0]!=0 && x[2]!=0)return true ; return false ; } public static void main(String args[])throws IOException { Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintWriter pw=new PrintWriter(System.out); int arr[]=new int[6]; for(int i=0 ; i<6 ; i++){ arr[i]=sc.nextInt(); } if(right(arr))pw.println("RIGHT"); else { for(int i=0 ; i<6 ; i++){ arr[i]++; if(right(arr)){ pw.println("ALMOST"); break ; } arr[i]-=2 ; if(right(arr)){ pw.println("ALMOST"); break ; } arr[i]++; if(i==5)pw.println("NEITHER"); } } pw.close(); } } ------------------------------------------------------------ OCL File: --------- class A18 { static operation right( arr : Sequence(int)) : boolean pre: true post: true activity: ( var x : Sequence(double) ; x := Integer.subrange(1,3)->collect(0.0) ; x[0+1] := arr[0+1] - arr[2+1]->pow(2) + arr[1+1] - arr[3+1]->pow(2) ; x[1+1] := arr[0+1] - arr[4+1]->pow(2) + arr[1+1] - arr[5+1]->pow(2) ; x[2+1] := arr[4+1] - arr[2+1]->pow(2) + arr[5+1] - arr[3+1]->pow(2) ; x := x->sort() ; if (x[0+1] + x[1+1] = x[2+1] & x[1+1] /= 0 & x[0+1] /= 0 & x[2+1] /= 0) then return true else skip ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var arr : Sequence(int) ; arr := Integer.subrange(1,6)->collect(0) ; var i : int ; i := 0 ; while i < 6 do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; if (right(arr)) then skip else ( var i : int ; i := 0 ; while i < 6 do ( ( arr[i+1] := arr[i+1] + 1 ; if (right(arr)) then ( skip ; break ) else skip ; arr[i+1] := arr[i+1]-(2) ; if (right(arr)) then ( skip ; break ) else skip ; arr[i+1] := arr[i+1] + 1 ; if (i = 5) then skip ; else skip ; ) ; i := i + 1 ) ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class MyClass { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); if(x>0 && y>=0){ if(y==0 && x==1)System.out.println((x-1)*4); else if(x>=y)System.out.println((x-1)*4+1); else { System.out.println((y-1)*4+2); } } else if(x>0 && y<0){ if(x>y*-1){ if(y*-1==x-1)System.out.println((x-1)*4); else System.out.println((x-1)*4+1); } else { System.out.println((y*-1)*4); ; } } else if(x<=0 && y>0){ if(x==0 || x*-1x*-1){ System.out.println((y*-1)*4); } else System.out.println((x*-1-1)*4+3); } } else if(x<0 && y==0){ System.out.println((x*-1)*4-1); } else { System.out.println(0); } } } ------------------------------------------------------------ OCL File: --------- class MyClass { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; if (x > 0 & y >= 0) then ( if (y = 0 & x = 1) then OclFile["System.out"].println((x - 1) * 4) ; else if (x >= y) then OclFile["System.out"].println((x - 1) * 4 + 1) else ( OclFile["System.out"].println((y - 1) * 4 + 2) ) ; ) else if (x > 0 & y < 0) then ( if (x > y * -1) then ( if (y * -1 = x - 1) then OclFile["System.out"].println((x - 1) * 4) ; else OclFile["System.out"].println((x - 1) * 4 + 1) ; ) else ( OclFile["System.out"].println((y * -1) * 4) ; ) ) else if (x <= 0 & y > 0) then ( if (x = 0 or x * -1 < y) then OclFile["System.out"].println((y - 1) * 4 + 2) ; else ( if (y < x * -1) then OclFile["System.out"].println((x * -1 - 1) * 4 + 3) ; else OclFile["System.out"].println((x * -1 - 1) * 4 + 2) ; ) ) else if (x <= 0 & y < 0) then ( if (x = 0) then OclFile["System.out"].println((y * -1) * 4) ; else ( if (y * -1 > x * -1) then ( OclFile["System.out"].println((y * -1) * 4) ) else OclFile["System.out"].println((x * -1 - 1) * 4 + 3) ; ) ) else if (x < 0 & y = 0) then ( OclFile["System.out"].println((x * -1) * 4 - 1) ) else ( OclFile["System.out"].println(0) ) ; ; ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class CalcAvg { static double avgRec(int a[],int i,int 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)); } static double average(int a[],int n){ return avgRec(a,0,n); } public static void main(String[] args){ int arr[]={ 10,2,3,4,5,6,7,8,9 }; int n=arr.length ; System.out.println(average(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class CalcAvg { static operation avgRec( a : Sequence(int), i : int, n : int) : double 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)) ); static operation average( a : Sequence(int), n : int) : double pre: true post: true activity: ( return avgRec(a, 0, n) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{10,2,3,4,5,6,7,8,9} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(average(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; public class TaymyrIsCallingYou { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(st.nextToken()); int z=Integer.parseInt(st.nextToken()); boolean busy[]=new boolean[z+1]; for(int i=n ; i<=z ; i+=n){ busy[i]=true ; } int count=0 ; for(int i=m ; i<=z ; i+=m){ if(busy[i])count++; } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class TaymyrIsCallingYou { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var m : int ; m := (st.next())->toInteger() ; var z : int ; z := (st.next())->toInteger() ; var busy : Sequence(boolean) ; busy := Integer.subrange(1,z + 1)->collect(false) ; var i : int ; i := n ; while i <= z do ( ( busy[i+1] := true ) ; i := i+(n) ) ; var count : int ; count := 0 ; var i : int ; i := m ; while i <= z do ( ( if (busy[i+1]) then count := count + 1 ; else skip ) ; i := i+(m) ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxN=20 ; static int maxM=64 ; static int cntSplits(String s){ if(s.charAt(s.length()-1)=='1')return 0 ; int c_zero=0 ; for(int i=0 ; iat(s->size() - 1+1) = '1') then return 0 else skip ; var c_zero : int ; c_zero := 0 ; var i : int ; i := 0 ; while i < s->size() do ( c_zero := c_zero+(if (s->at(i+1) = '0') then 1 else 0 endif) ; ; i := i + 1 ) ; return 2->pow(c_zero - 1)->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "10010" ; OclFile["System.out"].println(cntSplits(s)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int a=sc.nextInt(); if(xtoInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; if (x < a) then OclFile["System.out"].println("0") ; else OclFile["System.out"].println("10") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.nio.CharBuffer ; import java.util.NoSuchElementException ; public class Main { public static void main(String[] args){ SimpleScanner scanner=new SimpleScanner(System.in); PrintWriter writer=new PrintWriter(System.out); int x=scanner.nextInt(); int a=scanner.nextInt(); writer.println(xintersection(Set{}) ; var n : int ; try ( n := in.read(buffer) ) catch (e : IOException) do ( n := -1 ) if (n <= 0) then ( eof := true ; return '\0' ) else skip ; buffer := buffer.flip() ; ) else skip ; return buffer.get() ); operation checkEof() : void pre: true post: true activity: ( if (eof) then error IncorrectElementException() ; else skip ); operation nextChar() : String pre: true post: true activity: ( execute checkEof() ; var b : String ; b := read() ; execute checkEof() ; return b ); operation next() : String pre: true post: true activity: ( var b : String ; while true do (( b := read() ; execute checkEof() ) ; if ((b->isMatch("[\\t\\n ]")) then skip else break) ; var sb : String ; sb := StringLib.newString() ; while true do (( sb := sb + StringLib.newString(b) ; b := read() ) ; if (not(eof) & not((b->isMatch("[\\t\\n ]"))) then skip else break) ; return sb+"" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); ARounding solver=new ARounding(); solver.solve(1,in,out); out.close(); } static class ARounding { public void solve(int testNumber,InputReader in,PrintWriter out){ int x=in.nextInt(),a=in.nextInt(); out.println(xtoInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ String in=br.readLine(); String chr[]=in.split(" "); int x=Integer.parseInt(chr[0]); int a=Integer.parseInt(chr[1]); System.out.println(xsplit(" ") ; var x : int ; x := (chr[0+1])->toInteger() ; var a : int ; a := (chr[1+1])->toInteger() ; OclFile["System.out"].println(if x < a then 0 else 10 endif) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static List>switchList ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int X=sc.nextInt(); int A=sc.nextInt(); sc.close(); if(X>=A){ System.out.println(10); } else { System.out.println(0); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute switchList : Sequence(Sequence(int)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var X : int ; X := sc.getCurrent()->toInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; skip ; if (X >= A) then ( OclFile["System.out"].println(10) ) else ( OclFile["System.out"].println(0) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); System.out.println((n % 500<=k)? "Yes" : "No"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; OclFile["System.out"].println(if (n mod 500 <= k) then "Yes" else "No" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; import java.util.StringTokenizer ; public class Main { private static final int MOD=(int)Math.pow(10,9); public static void main(String[] args){ FastReader sc=new FastReader(); int n=sc.nextInt(); int coin=sc.nextInt(); int m=(n % 500); if(coin>=m){ System.out.println("Yes"); } else { System.out.println("No"); } } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : int := 10->pow(9)->oclAsType(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var n : int ; n := sc.nextInt() ; var coin : int ; coin := sc.nextInt() ; var m : int ; m := (n mod 500) ; if (coin >= m) then ( OclFile["System.out"].println("Yes") ) else ( OclFile["System.out"].println("No") ) ; ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countDigits(int n){ double ans=0 ; for(int i=1 ; i<=n ; i++)ans+=Math.log10(i); ans=ans*n ; return 1+(int)Math.floor(ans); } public static void main(String[] args){ int n=4 ; System.out.println(countDigits(n)+"\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countDigits( n : int) : int pre: true post: true activity: ( var ans : double ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ans := ans+((i)->log10()) ; ; i := i + 1 ) ; ans := ans * n ; return 1 + (ans)->floor()->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(countDigits(n) + "\n") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); AInfiniteCoins solver=new AInfiniteCoins(); solver.solve(1,in,out); out.close(); } static class AInfiniteCoins { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(); int a=in.nextInt(); int b=n/500 ; out.print(a>=n-b*500 ? "Yes" : "No"); } } static class InputReader implements AutoCloseable { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public void close(){ } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : AInfiniteCoins ; solver := AInfiniteCoins.newAInfiniteCoins() ; solver.solve(1, in, out) ; skip ; ); static class AInfiniteCoins { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var a : int ; a := in.nextInt() ; var b : int ; b := n / 500 ; skip ); } static class InputReader implements AutoCloseable { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation close() : void pre: true post: true activity: skip; } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class TaymyrIsCallingYou { public static void main(String[] args)throws IOException { Reader in=new Reader(); PrintWriter out=new PrintWriter(System.out); int A=in.nextInt(),B=in.nextInt(),K=in.nextInt(); out.println(K/(lcm(A,B))); out.close(); } public static int lcm(int a,int b){ return a/gcd(a,b)*b ; } public static int gcd(int a,int b){ return a==0 ? b : gcd(b % a,a); } static class Reader { BufferedReader in ; StringTokenizer st ; public Reader(){ in=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public String nextLine()throws IOException { st=new StringTokenizer(""); return in.readLine(); } public String next()throws IOException { while(! st.hasMoreTokens()){ st=new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } } public static void sort(int[] arr){ Listlist=new ArrayList<>(); for(int i : arr){ list.add(i); } Collections.sort(list); for(int i=0 ; itoInteger() ; var B : int ; B := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; skip ; skip ; ); static operation lcm( a : int, b : int) : int pre: true post: true activity: ( return a / gcd(a, b) * b ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if a = 0 then b else gcd(b mod a, a) endif ); static class Reader { attribute in : OclFile; attribute st : OclIterator; static operation newReader() : Reader pre: true post: true activity: ( var self : Reader ; self := createReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; st := OclIterator.newOclIterator_String("") ); operation nextLine() : String pre: true post: true activity: ( st := OclIterator.newOclIterator_String("") ; return in.readLine() ); operation next() : String pre: true post: true activity: ( while (not(st.hasNext())) do ( st := OclIterator.newOclIterator_String(in.readLine()) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } static operation sort( arr : Sequence(int)) : void pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{} ; for (i : arr) do ( ( list := list->including(i) ) ) ; list := list->sort() ; var i : int ; i := 0 ; while i < arr->size() do ( ( arr[i+1] := list->at(i+1) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; class Main { public static void main(String args[])throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); Solver solver=new Solver(); solver.init(); solver.readHead(in.readLine()); for(; solver.hasNext(); ){ solver.readBody(in.readLine()); } solver.solve(); } } class Solver { int N ; int cnt ; public void init(){ N=0 ; cnt=0 ; } public void readHead(String str){ String[] strArr=str.split(" "); N=Integer.parseInt(strArr[0]); } public boolean hasNext(){ return cnt<1 ; } int A ; public void readBody(String str){ A=Integer.parseInt(str); cnt++; } public void solve(){ if((N % 500)<=A)System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var solver : Solver ; solver := Solver.newSolver() ; solver.init() ; solver.readHead(in.readLine()) ; while solver.hasNext() do ( ( solver.readBody(in.readLine()) ) ) ; solver.solve() ; ); } class Solver { attribute N : int; attribute cnt : int; operation init() : void pre: true post: true activity: ( N := 0 ; cnt := 0 ); operation readHead( str : String) : void pre: true post: true activity: ( var strArr : Sequence(String) ; strArr := str->split(" ") ; N := (strArr[0+1])->toInteger() ); operation hasNext() : boolean pre: true post: true activity: ( return cnt < 1 ); attribute A : int; operation readBody( str : String) : void pre: true post: true activity: ( A := (str)->toInteger() ; cnt := cnt + 1 ); operation solve() : void pre: true post: true activity: ( if ((N mod 500) <= A) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int n=gi(); int a=gi(); if((n % 500)<=a){ System.out.print("Yes"); } else { System.out.print("No"); } } public static String gs(){ return scanner.next(); } public static int gi(){ return Integer.parseInt(scanner.next()); } public static long gl(){ return Long.parseLong(scanner.next()); } public static double gd(){ return Double.parseDouble(scanner.next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scanner : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := gi() ; var a : int ; a := gi() ; if ((n mod 500) <= a) then ( OclFile["System.out"].print("Yes") ) else ( OclFile["System.out"].print("No") ) ); static operation gs() : String pre: true post: true activity: ( return scanner.getCurrent() ); static operation gi() : int pre: true post: true activity: ( return (scanner.getCurrent())->toInteger() ); static operation gl() : long pre: true post: true activity: ( return (scanner.getCurrent())->toLong() ); static operation gd() : double pre: true post: true activity: ( return (scanner.getCurrent())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char[] a=sc.next().toCharArray(); char[] b=sc.next().toCharArray(); String ans="" ; for(int i=0 ; itoInteger() ; var a : Sequence(String) ; a := sc.getCurrent()->characters() ; var b : Sequence(String) ; b := sc.getCurrent()->characters() ; var ans : String ; ans := "" ; var i : int ; i := 0 ; while i < n do ( ( ans := ans+(a[i+1]) ; ans := ans+(b[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); BStringsWithTheSameLength solver=new BStringsWithTheSameLength(); solver.solve(1,in,out); out.close(); } static class BStringsWithTheSameLength { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(); char[] s=in.next().toCharArray(); char[] t=in.next().toCharArray(); StringBuilder sb=new StringBuilder(); for(int i=0 ; icharacters() ; var t : Sequence(String) ; t := in.next()->characters() ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < n do ( ( sb := sb + StringLib.newString(s[i+1]) + StringLib.newString(t[i+1]) ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Scanner ; import java.util.Collection ; import java.util.Collections ; import java.util.List ; public class Main { public static Scanner scan=new Scanner(System.in); public static void main(String[] args){ int n ; String s,t ; n=nextInt(); s=next(); t=next(); char[] arr=new char[2*n]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[2 * i+1] := s->at(i+1) ; arr[2 * i + 1+1] := t->at(i+1) ) ; i := i + 1 ) ; for (a : arr) do ( ( OclFile["System.out"].printf("%c", a) ) ) ; ); static operation nextInt() : int pre: true post: true activity: ( return (scan.getCurrent())->toInteger() ); static operation nextLong() : long pre: true post: true activity: ( return (scan.getCurrent())->toLong() ); static operation next() : String pre: true post: true activity: ( return scan.getCurrent() ); static operation nextDouble() : double pre: true post: true activity: ( return (scan.getCurrent())->toReal() ); static operation nextFloat() : double pre: true post: true activity: ( return parseFloat(scan.getCurrent()) ); static operation yesNo( flag : boolean) : void pre: true post: true activity: ( if (flag) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); static operation print( a : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println(a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public static void main(String args[]){ java.util.Scanner sc=new java.util.Scanner(System.in); int N=sc.nextInt(); String S[]=sc.next().split(""); String T[]=sc.next().split(""); for(int i=0 ; isplit("") ; var T : Sequence(String) ; T := sc.next()->split("") ; var i : int ; i := 0 ; while i < N do ( ( OclFile["System.out"].print(S[i+1] + T[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.InputStream ; import java.io.PrintStream ; import java.util.Arrays ; import java.util.Scanner ; public class Main { InputStream in=System.in ; PrintStream out=System.out ; public void _main(String[] args){ Scanner sc=new Scanner(in); int N=sc.nextInt(); String S=sc.next(); String T=sc.next(); sc.close(); StringBuilder sb=new StringBuilder(); for(int i=0 ; itoInteger() ; var S : String ; S := sc.getCurrent() ; var T : String ; T := sc.getCurrent() ; skip ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < N do ( ( sb := sb + StringLib.newString(S->at(i+1)) ; sb := sb + StringLib.newString(T->at(i+1)) ) ; i := i + 1 ) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain()._main(args) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { static Scanner scanner=new Scanner(); public static void main(String[] $){ int n=scanner.nextInt(); long ans=0 ; int[] a=new int[n]; for(int i=0 ; itoInteger() ; var ans : long ; ans := 0 ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() - 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( ans := ans+(scanner.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 1 ; while i < n do ( ( c[i - 1+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( if (a[i - 1+1] + 1 = a[i+1]) then ( ans := ans+(c[a[i - 1+1]+1]) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static class Scanner { attribute reader : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), (1*(2->pow(15)))->oclAsType(long)); attribute tokenizer : OclIterator; operation next() : String pre: true post: true activity: ( try ( while (tokenizer = null or not(tokenizer.hasNext())) do ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) ) catch (ignored : IOException) do skip return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); BBuffet solver=new BBuffet(); solver.solve(1,in,out); out.close(); } static class BBuffet { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(); int[] a=in.readIntArray(n); int[] b=in.readIntArray(n); int[] c=in.readIntArray(n-1); for(int i=0 ; i=0 && a[i-1]==a[i]-1){ answer+=c[a[i-1] ]; } } out.println(answer); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public int[] readIntArray(int n){ int[] x=new int[n]; for(int i=0 ; i= 0 & a[i - 1+1] = a[i+1] - 1) then ( answer := answer+(c[a[i - 1+1]+1]) ) else skip ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation readIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := nextInt() ) ; i := i + 1 ) ; return x ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class mpal { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t,j,i ; long n,k,p,d ; t=sc.nextInt(); for(j=1 ; j<=t ; j++){ n=sc.nextLong(); k=sc.nextLong(); if(n % 2==0)System.out.println((k % n)!=0 ?(k % n): n); else { d=n/2 ; p=(k-1)/d ; k+=p ; System.out.println((k % n)!=0 ?(k % n): n); } } } } ------------------------------------------------------------ OCL File: --------- class mpal { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; var j : int ; var i : int ; var n : long ; var k : long ; var p : long ; var d : long ; t := sc.getCurrent()->toInteger() ; j := 1 ; while j <= t do ( ( n := sc.getCurrent()->toLong() ; k := sc.getCurrent()->toLong() ; if (n mod 2 = 0) then OclFile["System.out"].println(if (k mod n) /= 0 then (k mod n) else n endif) ; else ( d := n / 2 ; p := (k - 1) / d ; k := k+(p) ; OclFile["System.out"].println(if (k mod n) /= 0 then (k mod n) else n endif) ) ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); long x=in.nextLong(),y=in.nextLong(); printBin(fillZero(Long.toBinaryString(x & y))); printBin(fillZero(Long.toBinaryString(x | y))); printBin(fillZero(Long.toBinaryString(x ^ y))); } static void printBin(String str){ for(int i=str.length()-32 ; itoLong() ; var y : long ; y := in.getCurrent()->toLong() ; execute printBin(fillZero((MathLib.decimal2binary(MathLib.bitwiseAnd(x,y)) + ""))) ; execute printBin(fillZero((MathLib.decimal2binary(MathLib.bitwiseOr(x,y)) + ""))) ; execute printBin(fillZero((MathLib.decimal2binary(MathLib.bitwiseXor(x,y)) + ""))) ; ); static operation printBin( str : String) : void pre: true post: true activity: ( var i : int ; i := str->size() - 32 ; while i < str->size() do ( OclFile["System.out"].print(str->at(i+1)) ; ; i := i + 1 ) ; OclFile["System.out"].println() ); static operation fillZero( str : String) : String pre: true post: true activity: ( var zero : String ; zero := "" ; if (str->size() < 32) then ( var i : int ; i := 0 ; while i < 32 - str->size() do ( zero := zero+("0") ; ; i := i + 1 ) ) else skip ; return zero+str ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.List ; import java.util.Scanner ; public class Main { private static class Line { public long a ; public long b ; public char op ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); Listlist=new LinkedList(); while(sc.hasNext()){ Line line=new Line(); line.a=sc.nextLong(); line.op=sc.next().charAt(0); line.b=sc.nextLong(); list.add(line); } for(Line line : list){ switch(line.op){ case '+' : System.out.println(line.a+line.b); break ; case '-' : System.out.println(line.a-line.b); break ; case '*' : System.out.println(line.a*line.b); break ; case '/' : System.out.println(line.a/line.b); break ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static class Line { attribute a : long; attribute b : long; attribute op : String; } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var list : Sequence(Line) ; list := Sequence{} ; while (sc.hasNext()) do ( var line : Line ; line := Line.newLine() ; line.a := sc.getCurrent()->toLong() ; line.op := sc.getCurrent()->at(0+1) ; line.b := sc.getCurrent()->toLong() ; list := list->including(line) ; ) ; for (line : list) do ( ( for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (line.op) ; if _switchval = '+' then OclFile["System.out"].println(line.a + line.b) ; break else skip ; if _switchval = '-' then OclFile["System.out"].println(line.a - line.b) ; break else skip ; if _switchval = '*' then OclFile["System.out"].println(line.a * line.b) ; break else skip ; if _switchval = '/' then OclFile["System.out"].println(line.a / line.b) ; break else skip ; ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); ListA=new ArrayList<>(); ListB=new ArrayList<>(); ListC=new ArrayList<>(); for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Sequence{} ; var B : Sequence(int) ; B := Sequence{} ; var C : Sequence(int) ; C := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( A := A->including(scanner.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( B := B->including(scanner.getCurrent()->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( C := C->including(scanner.getCurrent()->toInteger()) ) ; i := i + 1 ) ; skip ; var score : int ; score := 0 ; var tmp : int ; tmp := 0 ; var i : int ; i := 0 ; while i < N do ( ( var num : int ; num := A->at(i+1) ; var current_score : int ; current_score := B->at(num - 1+1) ; score := score+(current_score) ; if (i /= 0 & tmp + 1 = num) then ( score := score+(C->at(tmp - 1+1)) ) else skip ; tmp := num ; ) ; i := i + 1 ) ; OclFile["System.out"].println(score) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=Integer.parseInt(sc.next()); ArrayListlistA=new ArrayList<>(); ArrayListlistB=new ArrayList<>(); ArrayListlistC=new ArrayList<>(); for(int i=0 ; i0){ if(listA.get(i)==listA.get(i-1)+1){ satisfaction+=listC.get(listA.get(i-1)-1); } else { continue ; } } } System.out.println(satisfaction); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := (sc.getCurrent())->toInteger() ; var listA : Sequence(int) ; listA := Sequence{} ; var listB : Sequence(int) ; listB := Sequence{} ; var listC : Sequence(int) ; listC := Sequence{} ; var i : int ; i := 0 ; while i < N do ( ( listA := listA->including((sc.getCurrent())->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( listB := listB->including((sc.getCurrent())->toInteger()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N - 1 do ( ( listC := listC->including((sc.getCurrent())->toInteger()) ) ; i := i + 1 ) ; skip ; var satisfaction : int ; satisfaction := 0 ; var i : int ; i := 0 ; while i < listA->size() do ( ( var tmp : int ; tmp := listA->at(i+1) - 1 ; satisfaction := satisfaction+(listB->at(tmp+1)) ; if (i > 0) then ( if (listA->at(i+1) = listA->at(i - 1+1) + 1) then ( satisfaction := satisfaction+(listC->at(listA->at(i - 1+1) - 1+1)) ) else ( continue ) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(satisfaction) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static Scanner mScanner ; public static void main(String[] args){ mScanner=new Scanner(System.in); int intDishTotal=mScanner.nextInt(); int[] intArrEatOrder=CreateArrayFromInput(intDishTotal); int[] intArrSatisfactionB=CreateArrayFromInput(intDishTotal); int[] intArrSatisfactionC=CreateArrayFromInput(intDishTotal-1); int intSatisFactionSum=0 ; int intDishNoHistory=0 ; for(int i=0 ; itoInteger() ; var intArrEatOrder : Sequence(int) ; intArrEatOrder := CreateArrayFromInput(intDishTotal) ; var intArrSatisfactionB : Sequence(int) ; intArrSatisfactionB := CreateArrayFromInput(intDishTotal) ; var intArrSatisfactionC : Sequence(int) ; intArrSatisfactionC := CreateArrayFromInput(intDishTotal - 1) ; var intSatisFactionSum : int ; intSatisFactionSum := 0 ; var intDishNoHistory : int ; intDishNoHistory := 0 ; var i : int ; i := 0 ; while i < intArrEatOrder->size() do ( ( var intDishNo : int ; intDishNo := intArrEatOrder[i+1] ; intSatisFactionSum := intSatisFactionSum+(intArrSatisfactionB[intDishNo - 1+1]) ; if (intDishNoHistory /= 0 & intDishNoHistory = (intDishNo - 1)) then ( intSatisFactionSum := intSatisFactionSum+(intArrSatisfactionC[intDishNoHistory - 1+1]) ) else skip ; intDishNoHistory := intDishNo ) ; i := i + 1 ) ; OclFile["System.out"].println(intSatisFactionSum) ; ); static operation CreateArrayFromInput( intInCount : int) : Sequence(int) pre: true post: true activity: ( var intArrRet : Sequence(int) ; intArrRet := Integer.subrange(1,intInCount)->collect(0) ; var i : int ; i := 0 ; while i < intInCount do ( ( intArrRet[i+1] := mScanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; return intArrRet ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.awt.*; import static java.lang.System.*; import static java.lang.Math.*; public class Main { public static void main(String[] $){ Scanner sc=new Scanner(in); long a=sc.nextLong(); long b=sc.nextLong(); long c=sc.nextLong(); long ans=2*b ; if(c-b>a){ ans+=a+1 ; } else if(c-b==a){ ans+=a ; } else { ans+=c-b ; } out.println(ans); } static long power(long x,int n){ long mod=1000000007 ; long ans=1 ; while(n>0){ if((n & 1)==1){ ans=(ans*x)% mod ; } x=(x*x)% mod ; n>>=1 ; } return ans ; } static int gcd(int a,int b){ int temp ; while((temp=a % b)!=0){ a=b ; b=temp ; } return b ; } static class UF { static int size=51 ; static int[] par=new int[size]; static void init(){ for(int i=1 ; itoLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var c : long ; c := sc.getCurrent()->toLong() ; var ans : long ; ans := 2 * b ; if (c - b > a) then ( ans := ans+(a + 1) ) else if (c - b = a) then ( ans := ans+(a) ) else ( ans := ans+(c - b) ) ; ; out.println(ans) ; ); static operation power( x : long, n : int) : long pre: true post: true activity: ( var mod : long ; mod := 1000000007 ; var ans : long ; ans := 1 ; while (n > 0) do ( if ((n & 1) = 1) then ( ans := (ans * x) mod mod ) else skip ; x := (x * x) mod mod ; n := n/(2->pow(1)) ) ; return ans ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( var temp : int ; temp := a mod b ; while ((temp) /= 0) do ( skip ; ( a := b ; b := temp ) ; temp := a mod b ; ) ; return b ); static class UF { static attribute size : int := 51; static attribute par : Sequence(int) := Integer.subrange(1,size)->collect(0); static operation init() : void pre: true post: true activity: ( var i : int ; i := 1 ; while i < size do ( ( par[i+1] := i ) ; i := i + 1 ) ); static operation root( x : int) : int pre: true post: true activity: ( if (par[x+1] = x) then ( return x ) else ( return par[x+1] ) ); static operation same( x : int, y : int) : boolean pre: true post: true activity: ( return root(x) = root(y) ); static operation unite( x : int, y : int) : void pre: true post: true activity: ( x := root(x) ; y := root(y) ; if (x = y) then return else skip ; par[x+1] := y ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); APoisonousCookies solver=new APoisonousCookies(); solver.solve(1,in,out); out.close(); } static class APoisonousCookies { public void solve(int testNumber,InputReader in,PrintWriter out){ int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); long d=c-a>0 ? c-a : 0 ; long f=d-b>0 ? d-b : 0 ; long res=Math.min(a,c)+Math.min(d,b)+Math.min(f,1)+b ; out.println(res); } } static class InputReader implements AutoCloseable { private BufferedReader reader ; private StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public void close(){ } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : APoisonousCookies ; solver := APoisonousCookies.newAPoisonousCookies() ; solver.solve(1, in, out) ; skip ; ); static class APoisonousCookies { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var a : int ; a := in.nextInt() ; var b : int ; b := in.nextInt() ; var c : int ; c := in.nextInt() ; var d : long ; d := if c - a > 0 then c - a else 0 endif ; var f : long ; f := if d - b > 0 then d - b else 0 endif ; var res : long ; res := Set{a, c}->min() + Set{d, b}->min() + Set{f, 1}->min() + b ; skip ; ); } static class InputReader implements AutoCloseable { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation close() : void pre: true post: true activity: skip; } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.HashSet ; import java.util.Scanner ; public class Main { public static int matchsticks[]={ 0,2,5,5,4,5,6,3,7,6 }; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int untastyAntidote=sc.nextInt(); int tastyAntidote=sc.nextInt(); int tastyPoison=sc.nextInt(); int ans=0 ; int min=Math.min(untastyAntidote,tastyPoison); ans+=min ; tastyPoison-=min ; min=Math.min(tastyAntidote,tastyPoison); ans+=2*min ; tastyAntidote-=min ; tastyPoison-=min ; if(tastyPoison>0){ ans++; } ans+=tastyAntidote ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute matchsticks : int := Sequence{0,2,5,5,4,5,6,3,7,6}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var untastyAntidote : int ; untastyAntidote := sc.getCurrent()->toInteger() ; var tastyAntidote : int ; tastyAntidote := sc.getCurrent()->toInteger() ; var tastyPoison : int ; tastyPoison := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var min : int ; min := Set{untastyAntidote, tastyPoison}->min() ; ans := ans+(min) ; tastyPoison := tastyPoison-(min) ; min := Set{tastyAntidote, tastyPoison}->min() ; ans := ans+(2 * min) ; tastyAntidote := tastyAntidote-(min) ; tastyPoison := tastyPoison-(min) ; if (tastyPoison > 0) then ( ans := ans + 1 ) else skip ; ans := ans+(tastyAntidote) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.ArrayList ; import java.util.List ; public class Main { public static void main(String[] args)throws Exception { InputStreamReader is=new InputStreamReader(System.in); BufferedReader reader=new BufferedReader(is); Listmylist=new ArrayList<>(); String strinput=reader.readLine(); while(strinput!=null){ mylist.add(strinput); strinput=reader.readLine(); } String arr01[]=mylist.get(0).split(" "); int a=Integer.valueOf(arr01[0]); int b=Integer.valueOf(arr01[1]); int c=Integer.valueOf(arr01[2]); int cnt=0 ; if(c>=a){ cnt+=a ; c-=a ; a=0 ; } else { cnt+=c ; a-=c ; c=0 ; } if(c>=b){ cnt+=b*2 ; c-=b ; b=0 ; if(c>0){ cnt+=1 ; } } else { cnt+=b ; cnt+=c ; } System.out.println(cnt); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var is : OclFile ; is := OclFile.newOclFile_Read(OclFile["System.in"]) ; var reader : OclFile ; reader := OclFile.newOclFile_Read(is) ; var mylist : Sequence(String) ; mylist := Sequence{} ; var strinput : String ; strinput := reader.readLine() ; while (strinput /= null) do ( mylist := mylist->including(strinput) ; strinput := reader.readLine() ) ; var arr01 : Sequence(String) ; arr01 := mylist->at(0+1)->split(" ") ; var a : int ; a := (arr01[0+1])->toInteger() ; var b : int ; b := (arr01[1+1])->toInteger() ; var c : int ; c := (arr01[2+1])->toInteger() ; var cnt : int ; cnt := 0 ; if (c >= a) then ( cnt := cnt+(a) ; c := c-(a) ; a := 0 ) else ( cnt := cnt+(c) ; a := a-(c) ; c := 0 ) ; if (c >= b) then ( cnt := cnt+(b * 2) ; c := c-(b) ; b := 0 ; if (c > 0) then ( cnt := cnt+(1) ) else skip ) else ( cnt := cnt+(b) ; cnt := cnt+(c) ) ; OclFile["System.out"].println(cnt) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ InputReader reader=new InputReader(System.in); int A,B,C ; A=reader.nextInt(); B=reader.nextInt(); C=reader.nextInt(); int ans=B+Math.min(A+B+1,C); System.out.println(ans); } public static class InputReader { private StringTokenizer tokenizer ; private BufferedReader reader ; public InputReader(InputStream in){ assert in!=null ; reader=new BufferedReader(new InputStreamReader(in),Short.MAX_VALUE); } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ tokenizer=null ; try { return reader.readLine(); } catch(IOException e){ throw new RuntimeException(e); } } else { StringBuilder builder=new StringBuilder(); while(tokenizer.hasMoreTokens()){ builder.append(tokenizer.nextToken()); builder.append(' '); } return builder.toString(); } } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public void close(){ try { reader.close(); } catch(IOException e){ throw new RuntimeException(e); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : InputReader ; reader := InputReader.newInputReader(OclFile["System.in"]) ; var A : int ; var B : int ; var C : int ; A := reader.nextInt() ; B := reader.nextInt() ; C := reader.nextInt() ; var ans : int ; ans := B + Set{A + B + 1, C}->min() ; OclFile["System.out"].println(ans) ; ); static class InputReader { attribute tokenizer : OclIterator; attribute reader : OclFile; static operation newInputReader( in : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( assert in /= null ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(in), 32767) ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) else skip ; return tokenizer.next() ); operation nextLine() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( tokenizer := null ; try ( return reader.readLine() ) catch (e : IOException) do ( error ProgramException(e) ) ) else ( var builder : String ; builder := StringLib.newString() ; while (tokenizer.hasNext()) do ( builder := builder + StringLib.newString(tokenizer.next()) ; builder := builder + StringLib.newString(' ') ) ; return builder+"" ) ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation close() : void pre: true post: true activity: ( try ( skip ) catch (e : IOException) do ( error ProgramException(e) ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long ans=(long)N*(N-1)/2 ; System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var ans : long ; ans := N->oclAsType(long) * (N - 1) / 2 ; OclFile["System.out"].println(ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); DModSum solver=new DModSum(); solver.solve(1,in,out); out.close(); } static class DModSum { public void solve(int testNumber,InputReader in,PrintWriter out){ long n=in.nextInt(); out.println(n*(n-1)/2); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : DModSum ; solver := DModSum.newDModSum() ; solver.solve(1, in, out) ; skip ; ); static class DModSum { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : long ; n := in.nextInt() ; skip ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner in=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new AOJ0181().doIt(); } class AOJ0181 { int m,n ; int[] books ; boolean isPossible(int width){ int w=0,cnt=1 ; for(int i=0 ; iwidth)return false ; if(w>width){ cnt++; w=books[i]; } } return cnt>m ? false : true ; } void doIt(){ while(true){ m=in.nextInt(); n=in.nextInt(); if(n+m==0)return ; books=new int[n]; for(int i=0 ; i width) then return false else skip ; if (w > width) then ( cnt := cnt + 1 ; w := books[i+1] ) else skip ) ; i := i + 1 ) ; return if cnt > m then false else true endif ); operation doIt() : void pre: true post: true activity: ( while (true) do ( m := in.getCurrent()->toInteger() ; n := in.getCurrent()->toInteger() ; if (n + m = 0) then return else skip ; books := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( books[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var left : int ; left := 1 ; var right : int ; right := 1500000 ; while (right - left /= 1) do ( var next : int ; next := (left + right) / 2 ; if (isPossible(next)) then right := next ; else left := next ; ) ; OclFile["System.out"].println(right) ; ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Scanner ; import java.util.StringTokenizer ; import java.util.*; public class test { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader scan=new FastReader(); int n=scan.nextInt(); int top=scan.nextInt(); boolean done=false ; int bottom=7-top ; for(int i=0 ; itoInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : FastReader ; scan := FastReader.newFastReader() ; var n : int ; n := scan.nextInt() ; var top : int ; top := scan.nextInt() ; var done : boolean ; done := false ; var bottom : int ; bottom := 7 - top ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := scan.nextInt() ; var b : int ; b := scan.nextInt() ; if (a /= top & a /= bottom & 7 - a /= top & 7 - a /= bottom & b /= top & b /= bottom & 7 - b /= top & 7 - b /= bottom) then ( continue ) else ( OclFile["System.out"].println("NO") ; done := true ; break ) ) ; i := i + 1 ) ; if (done = false) then OclFile["System.out"].println("YES") ; else skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class T1487B { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0 ; i0){ sizeMissed=sizeSerialSegment ; } else { sizeMissed=sizeSerialSegment-1 ; if(sizeMissed==-1){ sizeMissed=0 ; } } k+=sizeMissed ; } int position=k % n ; if(position==0){ position=n ; } System.out.println(position); } } } ------------------------------------------------------------ OCL File: --------- class T1487B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; if (n mod 2 = 0) then skip else ( var lengthSerialSegment : int ; lengthSerialSegment := n / 2 ; var sizeSerialSegment : int ; sizeSerialSegment := k / lengthSerialSegment ; var sizeNewSegment : int ; sizeNewSegment := k mod lengthSerialSegment ; var sizeMissed : int ; if (sizeNewSegment > 0) then ( sizeMissed := sizeSerialSegment ) else ( sizeMissed := sizeSerialSegment - 1 ; if (sizeMissed = -1) then ( sizeMissed := 0 ) else skip ) ; k := k+(sizeMissed) ; ) ; var position : int ; position := k mod n ; if (position = 0) then ( position := n ) else skip ; OclFile["System.out"].println(position) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); final long N=scan.nextLong(); scan.close(); System.out.println(BigInteger.valueOf(N-1).multiply(BigInteger.valueOf(N)).divide(BigInteger.valueOf(2)).toString()); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : long ; N := scan.getCurrent()->toLong() ; skip ; OclFile["System.out"].println((N - 1 + "")->toLong().multiply((N + "")->toLong()).divide((2 + "")->toLong())+"") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); long n=sc.nextLong(); System.out.println(n*(n-1)/2); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; OclFile["System.out"].println(n * (n - 1) / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); int num=in.nextInt(); long n=num-1 ; long res=(n*(n+1))/2 ; out.println(res); out.close(); } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var num : int ; num := in.nextInt() ; var n : long ; n := num - 1 ; var res : long ; res := (n * (n + 1)) / 2 ; skip ; skip ; ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ try { Scanner sc=new Scanner(System.in); int n,ans=0 ; n=Integer.parseInt(sc.next()); int[] h=new int[n]; for(int i=0 ; ih[i+1]){ ans=ans+h[i]-h[i+1]; } } System.out.println(ans+h[n-1]); } catch(Exception e){ System.out.println("out"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; var ans : int ; ans := 0 ; n := (sc.getCurrent())->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( h[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (h[i+1] > h[i + 1+1]) then ( ans := ans + h[i+1] - h[i + 1+1] ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans + h[n - 1+1]) ; ) catch (e : ProgramException) do ( OclFile["System.out"].println("out") ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); CGrandGarden solver=new CGrandGarden(); solver.solve(1,in,out); out.close(); } static class CGrandGarden { public void solve(int testNumber,InputReader in,PrintWriter out){ int n=in.nextInt(),a[]=new int[n]; for(int i=0 ; i=i)++pos ; ++ans ; } } out.println(ans); } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : CGrandGarden ; solver := CGrandGarden.newCGrandGarden() ; solver.solve(1, in, out) ; skip ; ); static class CGrandGarden { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.nextInt() ; var a : Sequence(void) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := in.nextInt() ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= 100 do ( ( var pos : int ; pos := 0 ; while (pos < n) do ( while (pos < n & a[pos+1] < i) do pos := pos + 1 ; ; if (pos = n) then break else skip ; while (pos < n & a[pos+1] >= i) do pos := pos + 1 ; ; ans := ans + 1 ) ) ; i := i + 1 ) ; skip ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ final Scanner scanner=new Scanner(System.in); final int N=scanner.nextInt(); final int[] h=new int[N]; final int maxHeight ; { int maxHeightCandidate=0 ; for(int k=1 ; k<=N ; k++){ h[k-1]=scanner.nextInt(); if(maxHeightCandidate=height){ exists=true ; countPerHeight++; } } } totalCount+=countPerHeight ; } System.out.println(totalCount); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,N)->collect(0) ; var maxHeight : int ; ( var maxHeightCandidate : int ; maxHeightCandidate := 0 ; var k : int ; k := 1 ; while k <= N do ( ( h[k - 1+1] := scanner.getCurrent()->toInteger() ; if (maxHeightCandidate < h[k - 1+1]) then ( maxHeightCandidate := h[k - 1+1] ) else skip ) ; k := k + 1 ) ; maxHeight := maxHeightCandidate ) var totalCount : int ; totalCount := 0 ; var height : int ; height := 1 ; while height <= maxHeight do ( ( var countPerHeight : int ; countPerHeight := 0 ; var exists : boolean ; exists := false ; var k : int ; k := 1 ; while k <= N do ( ( if (exists) then ( if (h[k - 1+1] < height) then ( exists := false ) else skip ) else ( if (h[k - 1+1] >= height) then ( exists := true ; countPerHeight := countPerHeight + 1 ) else skip ) ) ; k := k + 1 ) ; totalCount := totalCount+(countPerHeight) ) ; height := height + 1 ) ; OclFile["System.out"].println(totalCount) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); C solver=new C(); solver.solve(1,in,out); out.close(); } static class C { public void solve(int testNumber,Scanner in,PrintWriter out){ int N=in.nextInt(); int[] h=new int[N+1]; Arrays.fill(h,0); for(int i=0 ; ih[i+1]){ count+=h[i]-h[i+1]; } } out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : C ; solver := C.newC() ; solver.solve(1, in, out) ; skip ; ); static class C { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var N : int ; N := in.getCurrent()->toInteger() ; var h : Sequence(int) ; h := Integer.subrange(1,N + 1)->collect(0) ; h := h->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( h[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N do ( ( if (h[i+1] > h[i + 1+1]) then ( count := count+(h[i+1] - h[i + 1+1]) ) else skip ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int N ; static int[] flowers ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); N=sc.nextInt(); flowers=new int[N]; for(int i=0 ; icur){ ans+=flowers[k]-cur ; } cur=flowers[k]; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute N : int; static attribute flowers : Sequence(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; N := sc.getCurrent()->toInteger() ; flowers := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( flowers[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; var ans : int ; ans := 0 ; var cur : int ; cur := 0 ; var k : int ; k := 0 ; while k < N do ( ( if (flowers[k+1] > cur) then ( ans := ans+(flowers[k+1] - cur) ) else skip ; cur := flowers[k+1] ) ; k := k + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.util.Arrays.deepToString ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } void tr(Object...os){ System.err.println(deepToString(os)); } Scanner sc=new Scanner(System.in); public void run(){ for(; sc.hasNext(); ){ int m=sc.nextInt(); int n=sc.nextInt(); if(n==0 && m==0)break ; int[] w=new int[n]; for(int i=0 ; i1){ int mid=(hi+lo)/2 ; if(possible(mid,m,w))hi=mid ; else lo=mid ; } System.out.println(hi); } } boolean possible(int W,int m,int[] w){ int need=0 ; need++; int pos=0 ; for(int i=0 ; iW){ need++; pos=w[i]; if(w[i]>W)return false ; } else { pos+=w[i]; } } return need<=m ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation tr( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while sc.hasNext() do ( ( var m : int ; m := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0 & m = 0) then break else skip ; var w : Sequence(int) ; w := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( w[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var hi : int ; hi := 10000000 ; var lo : int ; lo := 1 ; while (hi - lo > 1) do ( var mid : int ; mid := (hi + lo) / 2 ; if (possible(mid, m, w)) then hi := mid ; else lo := mid ; ) ; OclFile["System.out"].println(hi) ; ) ) ); operation possible( W : int, m : int, w : Sequence(int)) : boolean pre: true post: true activity: ( var need : int ; need := 0 ; need := need + 1 ; var pos : int ; pos := 0 ; var i : int ; i := 0 ; while i < w->size() do ( ( if (pos + w[i+1] > W) then ( need := need + 1 ; pos := w[i+1] ; if (w[i+1] > W) then return false else skip ) else ( pos := pos+(w[i+1]) ) ) ; i := i + 1 ) ; return need <= m ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); TaskA solver=new TaskA(); solver.solve(1,in,out); out.close(); } static class TaskA { public void solve(int testNumber,InputReader in,PrintWriter out){ int a=in.nextInt(); long[] ans=new long[] { 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,4242538496L,8485076992L,16970153984L,33940307968L }; out.println(ans[a]); } } static class InputReader { private BufferedReader reader ; private StringTokenizer stt ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream)); } public String nextLine(){ try { return reader.readLine(); } catch(IOException e){ return null ; } } public String next(){ while(stt==null || ! stt.hasMoreTokens()){ stt=new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : TaskA ; solver := TaskA.newTaskA() ; solver.solve(1, in, out) ; skip ; ); static class TaskA { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var a : int ; a := in.nextInt() ; var ans : Sequence(long) ; ans := Sequence{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,4242538496L,8485076992L,16970153984L,33940307968L} ; skip ); } static class InputReader { attribute reader : OclFile; attribute stt : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ); operation nextLine() : String pre: true post: true activity: ( try ( return reader.readLine() ) catch (e : IOException) do ( return null ) ); operation next() : String pre: true post: true activity: ( while (stt = null or not(stt.hasNext())) do ( stt := OclIterator.newOclIterator_String(nextLine()) ) ; return stt.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args){ BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); try { int pot=Integer.parseInt(bf.readLine()); if(pot<13){ System.out.println((long)(Math.pow(2,pot))); } else { System.out.println((long)(8092*Math.pow(2,pot-13))); } } catch(NumberFormatException e){ e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var bf : OclFile ; bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var pot : int ; pot := (bf.readLine())->toInteger() ; if (pot < 13) then ( OclFile["System.out"].println((2->pow(pot))->oclAsType(long)) ) else ( OclFile["System.out"].println((8092 * 2->pow(pot - 13))->oclAsType(long)) ) ) catch (e : IncorrectElementException) do ( e.printStackTrace() ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static long n,k ; static void solve(){ long val=0 ; if(n % 2==0)val=k % n ; else val=(k+(k-1)/(n/2))% n ; if(val==0)val=n ; str.append(val).append("\n"); } public static void main(String[] args)throws java.lang.Exception { boolean lenv=false ; BufferedReader bf ; PrintWriter pw ; if(lenv){ bf=new BufferedReader(new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); } else { bf=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out)); } int q1=Integer.parseInt(bf.readLine().trim()); while(q1-->0){ String s[]=bf.readLine().trim().split("\\s+"); n=Long.parseLong(s[0]); k=Long.parseLong(s[1]); solve(); } pw.print(str); pw.flush(); } } ------------------------------------------------------------ OCL File: --------- class Coder { static attribute str : String := StringLib.newString(); static attribute n : long; static operation solve() : void pre: true post: true activity: ( var val : long ; val := 0 ; if (n mod 2 = 0) then val := k mod n else val := (k + (k - 1) / (n / 2)) mod n ; ; if (val = 0) then val := n ; else skip ; str := str + StringLib.newString(val) + StringLib.newString("\n") ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var lenv : boolean ; lenv := false ; var bf : OclFile ; var pw : OclFile ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; var q1 : int ; q1 := (bf.readLine()->trim())->toInteger() ; while (q1 > 0) do ( q1 := q1 - 1 ; skip ; ( var s : Sequence(String) ; s := bf.readLine()->trim()->split("\\s+") ; n := (s[0+1])->toLong() ; k := (s[1+1])->toLong() ; execute solve() ) ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class I { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int a=Integer.parseInt(br.readLine()); long ans=0 ; if(a<13){ ans=1<toInteger() ; var ans : long ; ans := 0 ; if (a < 13) then ( ans := (1*(2->pow(a)))->oclAsType(long) ) else ( ans := 8092L ; var i : int ; i := 13 ; while i < a do ( ans := ans*(2) ; ; i := i + 1 ) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ double x=1 ; int z=new Scanner(System.in).nextInt(); Formatter formatter=new Formatter(System.out); for(int i=0 ; i=c){ ans=0 ; } else { ans=c-a+b ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var ans : int ; if (a - b >= c) then ( ans := 0 ) else ( ans := c - a + b ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); ATransfer solver=new ATransfer(); solver.solve(1,in,out); out.close(); } static class ATransfer { public void solve(int testNumber,InputReader in,PrintWriter out){ int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); int ans=c-(a-b); if(ans>0){ out.println(ans); } else { out.println(0); } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(InputStream stream){ reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : InputReader ; in := InputReader.newInputReader(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : ATransfer ; solver := ATransfer.newATransfer() ; solver.solve(1, in, out) ; skip ; ); static class ATransfer { operation solve( testNumber : int, in : InputReader, out : OclFile) : void pre: true post: true activity: ( var a : int ; a := in.nextInt() ; var b : int ; b := in.nextInt() ; var c : int ; c := in.nextInt() ; var ans : int ; ans := c - (a - b) ; if (ans > 0) then ( skip ) else ( skip ) ; ); } static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int A=sc.nextInt(); int B=sc.nextInt(); int C=sc.nextInt(); int rest=A-B ; int answer=C-rest ; if(answer<0){ System.out.println(0); } else { System.out.println(answer); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var A : int ; A := sc.getCurrent()->toInteger() ; var B : int ; B := sc.getCurrent()->toInteger() ; var C : int ; C := sc.getCurrent()->toInteger() ; var rest : int ; rest := A - B ; var answer : int ; answer := C - rest ; if (answer < 0) then ( OclFile["System.out"].println(0) ) else ( OclFile["System.out"].println(answer) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); A solver=new A(); solver.solve(1,in,out); out.close(); } static class A { public void solve(int testNumber,Scanner in,PrintWriter out){ int a=Integer.parseInt(in.next()); int b=Integer.parseInt(in.next()); int c=Integer.parseInt(in.next()); int ans=c-(a-b); if(ans<0)ans=0 ; out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : A ; solver := A.newA() ; solver.solve(1, in, out) ; skip ; ); static class A { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var a : int ; a := (in.getCurrent())->toInteger() ; var b : int ; b := (in.getCurrent())->toInteger() ; var c : int ; c := (in.getCurrent())->toInteger() ; var ans : int ; ans := c - (a - b) ; if (ans < 0) then ans := 0 ; else skip ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws Exception { Main main=new Main(); main.solve(); } public void solve()throws Exception { Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int A=scan.nextInt(); int B=scan.nextInt(); int C=scan.nextInt(); int ans=Math.max(0,C-(A-B)); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.solve() ); operation solve() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var A : int ; A := scan.getCurrent()->toInteger() ; var B : int ; B := scan.getCurrent()->toInteger() ; var C : int ; C := scan.getCurrent()->toInteger() ; var ans : int ; ans := Set{0, C - (A - B)}->max() ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { Scanner sc=new Scanner(System.in); void run(){ for(; ; ){ int m=sc.nextInt(); int n=sc.nextInt(); if((m | n)==0){ return ; } int book[]=new int[n]; int right=1500000 ; int left=1 ; int min=Integer.MAX_VALUE ; for(int i=0 ; i1){ int mid=(right+left)/2 ; width=0 ; step=1 ; for(int i=0 ; itoInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(m,n)) = 0) then ( return ) else skip ; var book : Sequence(int) ; book := Integer.subrange(1,n)->collect(0) ; var right : int ; right := 1500000 ; var left : int ; left := 1 ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( book[i+1] := sc.getCurrent()->toInteger() ; left := Set{left, book[i+1]}->max() ) ; i := i + 1 ) ; var width : int ; width := 0 ; var step : int ; step := 1 ; while (right - left > 1) do ( var mid : int ; mid := (right + left) / 2 ; width := 0 ; step := 1 ; var i : int ; i := 0 ; while i < n do ( ( if (width + book[i+1] <= mid) then ( width := width+(book[i+1]) ) else ( width := book[i+1] ; step := step + 1 ) ) ; i := i + 1 ) ; if (step <= m) then ( min := Set{min, mid}->min() ; right := mid ) else ( left := mid ) ; ) ; width := 0 ; step := 1 ; var i : int ; i := 0 ; while i < n do ( ( if (width + book[i+1] <= left) then ( width := width+(book[i+1]) ) else ( width := book[i+1] ; step := step + 1 ) ) ; i := i + 1 ) ; if (step <= m) then ( min := Set{min, left}->min() ) else skip ; OclFile["System.out"].println(min) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; class Main { public static void main(String[] args){ Solve s=new Solve(); s.solve(); } } class Solve { Solve(){ } Scanner in=new Scanner(System.in); void solve(){ int n=in.nextInt(),t=in.nextInt(); String str=in.next(); String[] s=str.split("\\+",0); String ns=Integer.toString(n); String ts=Integer.toString(t); BigInteger bi=new BigInteger("0"); for(int i=0 ; itoInteger() ; var t : int ; t := in.getCurrent()->toInteger() ; var str : String ; str := in.getCurrent() ; var s : Sequence(String) ; s := str->split("\\+") ; var ns : String ; ns := ((n) + "") ; var ts : String ; ts := ((t) + "") ; var bi : long ; bi := long("0") ; var i : int ; i := 0 ; while i < s->size() do ( ( var tmp : String ; tmp := s[i+1].subrange(2+1,2) ; var b : long ; b := long(ns) ; bi := bi->excludes(b.pow((tmp)->toInteger())) ) ; i := i + 1 ) ; bi := bi.multiply(long(ts)) ; var tle : long ; tle := long("1000000000") ; if (bi->compareTo(tle) = 1) then ( OclFile["System.out"].println("TLE") ) else ( OclFile["System.out"].println(bi+"") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { final static int sec=1000_000_000 ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; int n,T ; line=br.readLine(); n=parseInt(line.substring(0,line.indexOf(' '))); T=parseInt(line.substring(line.indexOf(' ')+1)); boolean tle=false ; long sum=0 ; line=br.readLine(); outer : for(char c : line.toCharArray()){ if('0'<=c && c<='9'){ int k=c-'0' ; long _sum ; if(k==0){ _sum=1 ; } else { _sum=n ; for(int i=0 ; isec){ tle=true ; break outer ; } } } sum+=_sum ; if(sum>sec){ tle=true ; break outer ; } } } sum*=T ; if(sum>sec){ tle=true ; } System.out.println(tle ? "TLE" : sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sec : int := 1000_000_000; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var n : int ; var T : int ; line := br.readLine() ; n := (line.subrange(0+1,line->indexOf(' ')-1) + "")->toInteger() ; T := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var tle : boolean ; tle := false ; var sum : long ; sum := 0 ; line := br.readLine() ; for (c : line->characters()) do ( ( if ('0' <= c & c <= '9') then ( var k : int ; k := c - ('0')->char2byte() ; var _sum : long ; if (k = 0) then ( _sum := 1 ) else ( _sum := n ; var i : int ; i := 0 ; while i < k - 1 do ( ( _sum := _sum*(n) ; if (_sum > sec) then ( tle := true ; break ) else skip ) ; i := i + 1 ) ) ; sum := sum+(_sum) ; if (sum > sec) then ( tle := true ; break ) else skip ; ) else skip ) ) ; sum := sum*(T) ; if (sum > sec) then ( tle := true ) else skip ; OclFile["System.out"].println(if tle then "TLE" else sum endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Arrays ; import java.util.Collections ; import java.util.LinkedList ; import java.util.ListIterator ; import java.util.PriorityQueue ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String[] fst=sc.nextLine().split(" "); BigInteger n=new BigInteger(fst[0]+""); BigInteger T=new BigInteger(fst[1]+""); BigInteger MAX=new BigInteger("1000000000"); String input=sc.nextLine(); BigInteger sum=new BigInteger("0"); for(String in : input.split("\\+")){ int num=Integer.parseInt(in.split("\\^")[1]); sum=sum.add(n.pow(num).multiply(T)); } System.out.println(sum.compareTo(MAX)<=0 ?(sum+""): "TLE"); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var fst : Sequence(String) ; fst := sc.nextLine()->split(" ") ; var n : long ; n := long(fst[0+1] + "") ; var T : long ; T := long(fst[1+1] + "") ; var MAX : long ; MAX := long("1000000000") ; var input : String ; input := sc.nextLine() ; var sum : long ; sum := long("0") ; for (in : input->split("\\+")) do ( ( var num : int ; num := (in->split("\\^")[1+1])->toInteger() ; sum := sum->excludes(n.pow(num).multiply(T)) ) ) ; OclFile["System.out"].println(if sum->compareTo(MAX) <= 0 then (sum + "") else "TLE" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void printQueries(int n,int a[],int q,int qry[]){ HashSetocc=new HashSet<>(); int[] suffixCount=new int[n+1]; for(int i=n-1 ; i>=0 ; i--){ occ.add(a[i]); suffixCount[i+1]=occ.size(); } for(int i=0 ; icollect(0) ; var i : int ; i := n - 1 ; while i >= 0 do ( ( occ := occ->including(a[i+1]) ; suffixCount[i + 1+1] := occ->size() ) ; i := i - 1 ) ; var i : int ; i := 0 ; while i < q do ( OclFile["System.out"].println(suffixCount[qry[i+1]+1]) ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var q : int ; q := 3 ; var a : Sequence(int) ; a := Sequence{2,4,6,10,2} ; var qry : Sequence(int) ; qry := Sequence{1,3,2} ; execute printQueries(n, a, q, qry) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static final int Big_Num=1000000000 ; static long mul(int n,int h){ int ans=n ; if(h==0)return 1 ; if(h==1)return ans ; for(int i=0 ; i0)System.out.println(ans*t); else System.out.println("TLE"); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute Big_Num : int := 1000000000; static operation mul( n : int, h : int) : long pre: true post: true activity: ( var ans : int ; ans := n ; if (h = 0) then return 1 else skip ; if (h = 1) then return ans else skip ; var i : int ; i := 0 ; while i < h - 1 do ( ( ans := ans*(n) ) ; i := i + 1 ) ; return ans ); static operation f( str : String, n : int) : long pre: true post: true activity: ( var an : Sequence(int) ; an := Integer.subrange(1,str->size())->collect(0) ; var k : int ; k := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( var s : String ; s := str->at(i+1) ; if ((s + "")->isMatch("[0-9]")) then ( an[k+1] := (((s) + ""))->toInteger() ; k := k + 1 ) else skip ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var kk : int ; kk := 0 ; for (aa : an) do ( ( ans := ans+(mul(n, aa)) ; kk := kk + 1 ; if (kk = k) then break else skip ) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var str : String ; str := sc.getCurrent() ; var ans : long ; ans := f(str, n) ; if (ans * t <= Big_Num & ans > 0) then OclFile["System.out"].println(ans * t) else OclFile["System.out"].println("TLE") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static long MAX=1000000000 ; static char[] f ; static int pos ; static int T ; public static void main(String[] args){ int N=sc.nextInt(); T=sc.nextInt(); f=sc.next().toCharArray(); ArrayListpoly=new ArrayList(); while(posMAX){ System.out.println("TLE"); } else { System.out.println(ans); } } static Term parse(){ pos+=2 ; int p=f[pos++]-'0' ; return new Term(p); } static class Term { int p ; Term(int p){ this.p=p ; } long eval(int n){ long ret=T ; for(int i=0 ; i

MAX)return MAX+1 ; } return ret ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute MAX : long := 1000000000; static attribute f : Sequence(String); static attribute pos : int; static attribute T : int; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := sc.getCurrent()->toInteger() ; T := sc.getCurrent()->toInteger() ; f := sc.getCurrent()->characters() ; var poly : Sequence(Term) ; poly := Sequence{} ; while (pos < f->size()) do ( poly := poly->including(parse()) ; pos := pos + 1 ) ; var ans : long ; ans := 0 ; for (t : poly) do ( ( ans := ans+(t.eval(N)) ) ) ; if (ans > MAX) then ( OclFile["System.out"].println("TLE") ) else ( OclFile["System.out"].println(ans) ) ; ); static operation parse() : Term pre: true post: true activity: ( pos := pos+(2) ; var p : int ; p := f[pos+1] - ('0')->char2byte() ; return Term.newTerm(p) ); static class Term { attribute p : int; static operation newTerm( p : int) : Term pre: true post: true activity: ( var self : Term ; self := createTerm(); self.initialise(p); return self ); operation initialise( p : int) : void pre: true post: true activity: ( self.p := p ); operation eval( n : int) : long pre: true post: true activity: ( var ret : long ; ret := T ; var i : int ; i := 0 ; while i < p do ( ( ret := ret*(n) ; if (ret > MAX) then return MAX + 1 else skip ) ; i := i + 1 ) ; return ret ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class obstacle { static int avoidObstacles(int[] obs){ HashSeths=new HashSet(); int max=obs[0]; for(int i=0 ; imax)return i ; } return max+1 ; } public static void main(String[] args){ int a[]=new int[] { 5,3,6,7,9 }; int b=avoidObstacles(a); System.out.println(b); } } ------------------------------------------------------------ OCL File: --------- class obstacle { static operation avoidObstacles( obs : Sequence(int)) : int pre: true post: true activity: ( var hs : Set(int) ; hs := Set{} ; var max : int ; max := obs[0+1] ; var i : int ; i := 0 ; while i < obs->size() do ( ( hs := hs->including(obs[i+1]) ; max := Set{max, obs[i+1]}->max() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= max do ( ( var j : int ; j := i ; while j <= max do ( ( if (hs->includes(j)) then break else skip ) ; j := j + i ) ; if (j > max) then return i else skip ) ; i := i + 1 ) ; return max + 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{5,3,6,7,9} ; var b : int ; b := avoidObstacles(a) ; OclFile["System.out"].println(b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; line=br.readLine(); int N,M ; N=parseInt(line.substring(0,line.indexOf(' '))); M=parseInt(line.substring(line.indexOf(' ')+1)); int[] zs=new int[N]; for(int i=0 ; izs[i+1] % k){ int tmp=zs[i]; zs[i]=zs[i+1]; zs[i+1]=tmp ; } } } for(int i=0 ; iindexOf(' ')-1) + "")->toInteger() ; M := (line.subrange(line->indexOf(' ')-1 + 1+1,line->indexOf(' ')-1 + 1) + "")->toInteger() ; var zs : Sequence(int) ; zs := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( zs[i+1] := (br.readLine() + "")->toInteger() ) ; i := i + 1 ) ; var k : int ; k := 1 ; while k <= M do ( ( var i : int ; i := 0 ; while i < N - 1 do ( ( if (zs[i+1] mod k > zs[i + 1+1] mod k) then ( var tmp : int ; tmp := zs[i+1] ; zs[i+1] := zs[i + 1+1] ; zs[i + 1+1] := tmp ) else skip ) ; i := i + 1 ) ) ; k := k + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( OclFile["System.out"].println(zs[i+1]) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Collections ; import java.util.List ; import java.util.Scanner ; import java.util.stream.Collectors ; import java.util.stream.IntStream ; public class Main { static final Scanner s=new Scanner(System.in); static IntStream REPS(int v){ return IntStream.range(0,v); } static IntStream INS(int n){ return REPS(n).map(i->getInt()); } static int getInt(){ return Integer.parseInt(s.next()); } public static void main(String[] $){ int n=getInt(),m=getInt(); Listst=INS(n).boxed().collect(Collectors.toList()); for(int k=1 ; k<=m ; ++k){ for(int i=0 ; ist.get(i+1)% k)Collections.swap(st,i,i+1); } } st.forEach(System.out :: println); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation REPS( v : int) : Sequence(int) pre: true post: true activity: ( return Integer.subrange(0, v-1) ); static operation INS( n : int) : Sequence(int) pre: true post: true activity: ( return REPS(n)->collect( _x1 | (lambda i : OclAny in getInt())->apply(_x1) ) ); static operation getInt() : int pre: true post: true activity: ( return (s.getCurrent())->toInteger() ); static operation main( $ : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := getInt() ; var m : int ; m := getInt() ; var st : Sequence(int) ; st := INS(n).collect(Collectors.toList()) ; var k : int ; k := 1 ; while k <= m do ( ( var i : int ; i := 0 ; while i < n - 1 do ( ( if (st->at(i+1) mod k > st->at(i + 1+1) mod k) then st := Integer.subrange(1,st.size)->collect( _x | if _x = i+1 then st->at(i + 1+1) else if _x = i + 1+1 then st->at(i+1) else st->at(_x) endif endif ) ; else skip ) ; i := i + 1 ) ) ; k := k + 1 ) ; for _forEach : st do ( skip ;) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { int[] arg=new int[100]; int i=0,sum=0,n=0,m=0 ; int[] bibs=null ; int[][] result=null ; boolean first=true ; try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in))){ String line ; while((line=br.readLine())!=null){ if(first){ String[] str=line.split(" "); n=Integer.parseInt(str[0]); m=Integer.parseInt(str[1]); bibs=new int[n+1]; i=0 ; first=false ; } else { i++; bibs[i]=Integer.parseInt(line); if(i==n){ for(int k=1 ; k<=m ; k++){ for(int j=1 ; jbibs[j+1] % k){ int w=bibs[j]; bibs[j]=bibs[j+1]; bibs[j+1]=w ; } } } for(int j=1 ; jcollect(0) ; var i : int ; i := 0 ; var sum : int ; sum := 0 ; var n : int ; n := 0 ; var m : int ; m := 0 ; var bibs : Sequence(int) ; bibs := null ; var result : Sequence(Sequence(int)) ; result := null ; var first : boolean ; first := true ; try ( var br : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ( var line : String ; line := br.readLine() ; while ((line) /= null) do ( skip ; ( if (first) then ( var str : Sequence(String) ; str := line->split(" ") ; n := (str[0+1])->toInteger() ; m := (str[1+1])->toInteger() ; bibs := Integer.subrange(1,n + 1)->collect(0) ; i := 0 ; first := false ; ) else ( i := i + 1 ; bibs[i+1] := (line)->toInteger() ; if (i = n) then ( var k : int ; k := 1 ; while k <= m do ( ( var j : int ; j := 1 ; while j < n do ( ( if (bibs[j+1] mod k > bibs[j + 1+1] mod k) then ( var w : int ; w := bibs[j+1] ; bibs[j+1] := bibs[j + 1+1] ; bibs[j + 1+1] := w ) else skip ) ; j := j + 1 ) ) ; k := k + 1 ) ; var j : int ; j := 1 ; while j < n + 1 do ( ( OclFile["System.out"].println(bibs[j+1]) ) ; j := j + 1 ) ; break ) else skip ) ) ; line := br.readLine() ; ) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ final int m=sc.nextInt(); final int n=sc.nextInt(); if(m==0 && n==0){ break ; } int[] books=new int[n]; for(int i=0 ; i=m){ flag=false ; break ; } if(wid+books[i]>med){ col++; i--; wid=0 ; } else { wid+=books[i]; } } if(! flag){ lower=med ; } else { upper=med ; } } System.out.println(upper); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var m : int ; m := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; if (m = 0 & n = 0) then ( break ) else skip ; var books : Sequence(int) ; books := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( books[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var upper : int ; upper := 1000000 * n ; var lower : int ; lower := 1 ; while ((upper - lower) /= 1) do ( var med : int ; med := (upper + lower) / 2 ; var col : int ; col := 0 ; var wid : int ; wid := 0 ; var flag : boolean ; flag := true ; var i : int ; i := 0 ; while i < n do ( ( if (col >= m) then ( flag := false ; break ) else skip ; if (wid + books[i+1] > med) then ( col := col + 1 ; i := i - 1 ; wid := 0 ) else ( wid := wid+(books[i+1]) ) ) ; i := i + 1 ) ; if (not(flag)) then ( lower := med ) else ( upper := med ) ; ) ; OclFile["System.out"].println(upper) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int N=sc.nextInt(); static int[] A_i=new int[N]; static int M=sc.nextInt(); public static void main(String[] args){ inputBibs(); swappingBibs(); for(int i=0 ; iA_i[i+1] % k){ int tmp ; tmp=A_i[i]; A_i[i]=A_i[i+1]; A_i[i+1]=tmp ; } } } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute N : int := sc.getCurrent()->toInteger(); static attribute A_i : Sequence(int) := Integer.subrange(1,N)->collect(0); static attribute M : int := sc.getCurrent()->toInteger(); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute inputBibs() ; execute swappingBibs() ; var i : int ; i := 0 ; while i < N do ( ( OclFile["System.out"].println(A_i[i+1]) ) ; i := i + 1 ) ); static operation inputBibs() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < N do ( ( A_i[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ); static operation swappingBibs() : void pre: true post: true activity: ( var k : int ; k := 2 ; while k <= M do ( ( var i : int ; i := 0 ; while i < N - 1 do ( ( if (A_i[i+1] mod k > A_i[i + 1+1] mod k) then ( var tmp : int ; tmp := A_i[i+1] ; A_i[i+1] := A_i[i + 1+1] ; A_i[i + 1+1] := tmp ) else skip ) ; i := i + 1 ) ) ; k := k + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; iarr[j+1] % i){ int tmp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=tmp ; } } } StringBuilder sb=new StringBuilder(); for(int x : arr){ sb.append(x).append("\n"); } System.out.print(sb); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= m do ( ( var j : int ; j := 0 ; while j < n - 1 do ( ( if (arr[j+1] mod i > arr[j + 1+1] mod i) then ( var tmp : int ; tmp := arr[j+1] ; arr[j+1] := arr[j + 1+1] ; arr[j + 1+1] := tmp ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; for (x : arr) do ( ( sb := sb + StringLib.newString(x) + StringLib.newString("\n") ) ) ; OclFile["System.out"].print(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); int max=-1 ; for(int i=1 ; i<=s.length()-1 ; i++){ String x=s.substring(0,i); String y=s.substring(i,s.length()); int xs[]=new int[26]; int ys[]=new int[26]; Arrays.fill(xs,0); Arrays.fill(ys,0); for(int j=0 ; jtoInteger() ; var s : String ; s := sc.getCurrent() ; var max : int ; max := -1 ; var i : int ; i := 1 ; while i <= s->size() - 1 do ( ( var x : String ; x := s.subrange(0+1,i) ; var y : String ; y := s.subrange(i+1,s->size()) ; var xs : Sequence(int) ; xs := Integer.subrange(1,26)->collect(0) ; var ys : Sequence(int) ; ys := Integer.subrange(1,26)->collect(0) ; xs := xs->collect(0) ; ys := ys->collect(0) ; var j : int ; j := 0 ; while j < x->size() do ( ( xs[x->at(j+1) - ('a')->char2byte()+1] := 1 ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < y->size() do ( ( ys[y->at(j+1) - ('a')->char2byte()+1] := 1 ) ; j := j + 1 ) ; var total : int ; total := 0 ; var j : int ; j := 0 ; while j < 26 do ( ( if (xs[j+1] = 1 & ys[j+1] = 1) then ( total := total + 1 ) else skip ) ; j := j + 1 ) ; max := Set{total, max}->max() ; ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Set ; import java.util.HashSet ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String s=br.readLine(); int count=0 ; int max=-1 ; Setset=new HashSet<>(); char[] exist=new char[100]; for(int i=1 ; itoInteger() ; var s : String ; s := br.readLine() ; var count : int ; count := 0 ; var max : int ; max := -1 ; var set : Set(String) ; set := Set{} ; var exist : Sequence(String) ; exist := Integer.subrange(1,100)->collect(0) ; var i : int ; i := 1 ; while i < n do ( ( var sub1 : String ; sub1 := s.subrange(0+1,i) ; var sub2 : String ; sub2 := s.subrange(i+1,i) ; var j : int ; j := 0 ; while j < sub1->size() do ( ( if (sub2->includes(((sub1->at(j+1)) + "")) & not(set->includes(sub1->at(j+1)))) then count := count + 1 ; else skip ; set := set->including(sub1->at(j+1)) ) ; j := j + 1 ) ; max := Set{max, count}->max() ; count := 0 ; set := set->intersection(Set{}) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int CountPS(char str[],int n){ int dp[][]=new int[n][n]; boolean P[][]=new boolean[n][n]; for(int i=0 ; icollect(Integer.subrange(1,n)->collect(0)) ; var P : Sequence(Sequence(boolean)) ; P := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(false)) ; var i : int ; i := 0 ; while i < n do ( P[i+1][i+1] := true ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (str[i+1] = str[i + 1+1]) then ( P[i+1][i + 1+1] := true ; dp[i+1][i + 1+1] := 1 ) else skip ) ; i := i + 1 ) ; var gap : int ; gap := 2 ; while gap < n do ( ( var i : int ; i := 0 ; while i < n - gap do ( ( var j : int ; j := gap + i ; if (str[i+1] = str[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] ; ) ; i := i + 1 ) ) ; gap := gap + 1 ) ; return dp[0+1][n - 1+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "abaab" ; OclFile["System.out"].println(CountPS(str->characters(), str->size())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ new Main().solve(sc); } } void solve(Scanner sc){ int n=sc.nextInt(); char[] s=sc.next().toCharArray(); int ans=0 ; for(int i=0 ; istartSet=new HashSet<>(i); for(int j=0 ; jendSet=new HashSet<>(n-i); for(int j=i ; jtoInteger() ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var startSet : Set(String) ; startSet := Set{} ; var j : int ; j := 0 ; while j < i do ( ( startSet := startSet->including(s[j+1]) ) ; j := j + 1 ) ; var endSet : Set(String) ; endSet := Set{}->union(n - i) ; var j : int ; j := i ; while j < n do ( ( endSet := endSet->including(s[j+1]) ) ; j := j + 1 ) ; startSet := startSet->intersection(endSet) ; ans := Set{ans, startSet->size()}->max() ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.io.PrintStream ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); BCutAndCount solver=new BCutAndCount(); solver.solve(1,in,out); out.close(); } static class BCutAndCount { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); String s=in.next(); int max=0 ; for(int i=0 ; imax){ max=count ; } } System.out.println(max); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : BCutAndCount ; solver := BCutAndCount.newBCutAndCount() ; solver.solve(1, in, out) ; skip ; ); static class BCutAndCount { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var s : String ; s := in.getCurrent() ; var max : int ; max := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( var a : String ; a := s.subrange(0+1,i) ; var b : String ; b := s.subrange(i+1,s->size()) ; var count : int ; count := 0 ; var used : Sequence(boolean) ; used := Integer.subrange(1,26)->collect(false) ; for (c : a->characters()) do ( ( if (used[c - 97+1]) then ( continue ) else skip ; for (d : b->characters()) do ( ( if (c = d) then ( count := count + 1 ; used[c - 97+1] := true ; continue ) else skip ) ) ) ) ; if (count > max) then ( max := count ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.HashMap ; import java.util.Map ; import java.util.Scanner ; public class Main { static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int N=gi(); String S=gs(); int max=0 ; for(int i=1 ; imax){ max=c ; } } System.out.println(max); } public static long d(long n){ String a=String.valueOf(n); return(long)a.length(); } public static String gs(){ return scanner.next(); } public static int gi(){ return Integer.parseInt(scanner.next()); } public static long gl(){ return Long.parseLong(scanner.next()); } public static double gd(){ return Double.parseDouble(scanner.next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scanner : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := gi() ; var S : String ; S := gs() ; var max : int ; max := 0 ; var i : int ; i := 1 ; while i < N - 1 do ( ( var S1 : String ; S1 := S.subrange(0+1,i) ; var S2 : String ; S2 := S.subrange(i+1,i) ; var S3 : String ; S3 := "" ; var c : int ; c := 0 ; var j : int ; j := 0 ; while j < S1->size() do ( ( var m : String ; m := S1.subrange(j+1,j + 1) ; if (S2->includes(m) & not(S3->includes(m))) then ( S3 := S3+(m) ; c := c + 1 ) else skip ) ; j := j + 1 ) ; if (c > max) then ( max := c ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(max) ; ); static operation d( n : long) : long pre: true post: true activity: ( var a : String ; a := ((n) + "") ; return a->size()->oclAsType(long) ); static operation gs() : String pre: true post: true activity: ( return scanner.getCurrent() ); static operation gi() : int pre: true post: true activity: ( return (scanner.getCurrent())->toInteger() ); static operation gl() : long pre: true post: true activity: ( return (scanner.getCurrent())->toLong() ); static operation gd() : double pre: true post: true activity: ( return (scanner.getCurrent())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; import static java.lang.Integer.parseInt ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; String[] words ; StringTokenizer st=new StringTokenizer(br.readLine()); int N,M,T ; N=parseInt(st.nextToken()); M=parseInt(st.nextToken()); T=parseInt(st.nextToken()); int a[]=new int[N+2]; a[0]=-M ; a[N+1]=T+M ; st=new StringTokenizer(br.readLine()); for(int i=0 ; i2*M ? a[i]-a[i-1]-2*M : 0 ; } System.out.println(t); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var line : String ; var words : Sequence(String) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(br.readLine()) ; var N : int ; var M : int ; var T : int ; N := (st.next() + "")->toInteger() ; M := (st.next() + "")->toInteger() ; T := (st.next() + "")->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,N + 2)->collect(0) ; a[0+1] := -M ; a[N + 1+1] := T + M ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < N do ( ( a[i + 1+1] := (st.next() + "")->toInteger() ) ; i := i + 1 ) ; var t : int ; t := 0 ; var i : int ; i := 1 ; while i < N + 2 do ( ( t := t+(if a[i+1] - a[i - 1+1] > 2 * M then a[i+1] - a[i - 1+1] - 2 * M else 0 endif) ) ; i := i + 1 ) ; OclFile["System.out"].println(t) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in=new Scanner(System.in); static final PrintWriter out=new PrintWriter(System.out,false); static boolean debug=false ; static void solve(){ int n=in.nextInt(); int m=in.nextInt(); int t=in.nextInt(); int[] a=new int[n]; for(int i=0 ; i0 ; long start=System.nanoTime(); solve(); out.flush(); long end=System.nanoTime(); dump((end-start)/1000000+" ms"); in.close(); out.close(); } static void dump(Object...o){ if(debug)System.err.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"], false); static attribute debug : boolean := false; static operation solve() : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var t : int ; t := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var f : Sequence(boolean) ; f := Integer.subrange(1,t * 2)->collect(false) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := a[i+1] - m ; while j < a[i+1] + m do ( ( f[j+1] := true ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < t do ( ( if (not(f[i+1])) then ans := ans + 1 ; else skip ) ; i := i + 1 ) ; execute dump(f) ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( debug := args->size() > 0 ; var start : long ; start := nanoTime() ; execute solve() ; skip ; var end : long ; end := nanoTime() ; execute dump((end - start) / 1000000 + " ms") ; skip ; skip ; ); static operation dump( o : Sequence(OclAny)) : void pre: true post: true activity: ( if (debug) then OclFile["System.err"].println((o + "")) ; else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { int m=0,n=0 ; int[] w=null ; boolean IsStorable(int width){ int row=0,c=0,i=0 ; while(iminw){ int mid=(maxw+minw)/2 ; if(IsStorable(mid))maxw=mid ; else minw=mid+1 ; } System.out.println(minw); } } public static void main(String[] a){ new Main().solve(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute m : int := 0; attribute w : Sequence(int) := null; operation IsStorable( width : int) : boolean pre: true post: true activity: ( var row : int ; row := 0 ; var c : int ; c := 0 ; var i : int ; i := 0 ; while (i < n) do ( if (c + w[i+1] <= width) then ( c := c+(w[i+1]) ; i := i + 1 ) else if ((row + 1) < m) then c := 0 else return false ; ) ; return true ); operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( m := sc.getCurrent()->toInteger() ; n := sc.getCurrent()->toInteger() ; if (m = 0 & n = 0) then break else skip ; w := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( w[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var minw : int ; minw := 1 ; var maxw : int ; maxw := 1500000 ; if (not(IsStorable(maxw))) then OclFile["System.out"].println("NA") ; else skip ; while (maxw > minw) do ( var mid : int ; mid := (maxw + minw) / 2 ; if (IsStorable(mid)) then maxw := mid ; else minw := mid + 1 ; ) ; OclFile["System.out"].println(minw) ; ) ); static operation main( a : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; public class Main { Scanner sc=new Scanner(System.in); public void run(){ int n=sc.nextInt(); int m=sc.nextInt(); int t=sc.nextInt(); calc(n,m,t); } public void calc(int n,int m,int t){ int[] memo=new int[10000]; int before=0 ; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; execute calc(n, m, t) ); operation calc( n : int, m : int, t : int) : void pre: true post: true activity: ( var memo : Sequence(int) ; memo := Integer.subrange(1,10000)->collect(0) ; var before : int ; before := 0 ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var start : int ; start := a - m ; var end : int ; end := a + m ; if (start < before) then start := before ; else skip ; var j : int ; j := start ; while j < end do ( ( if (j < t) then memo[j+1] := -1 ; else skip ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; var sum : int ; sum := t ; var i : int ; i := 0 ; while i < t do ( ( sum := sum+(memo[i+1]) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner scn=new Scanner(System.in); int N,M,T ; int a1,a2,delta=0 ; N=scn.nextInt(); M=scn.nextInt(); T=scn.nextInt(); a1=scn.nextInt(); for(int i=1 ; ia2-a1 ? 2*M+a1-a2 : 0 ; a1=a2 ; } a2=T+M ; delta+=2*M>a2-a1 ? 2*M+a1-a2 : 0 ; scn.close(); System.out.println(T+delta-2*M*N); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scn : OclFile ; scn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; var M : int ; var T : int ; var a1 : int ; var a2 : int ; var delta : int ; delta := 0 ; N := scn.getCurrent()->toInteger() ; M := scn.getCurrent()->toInteger() ; T := scn.getCurrent()->toInteger() ; a1 := scn.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i < N do ( ( a2 := scn.getCurrent()->toInteger() ; delta := delta+(if 2 * M > a2 - a1 then 2 * M + a1 - a2 else 0 endif) ; a1 := a2 ) ; i := i + 1 ) ; a2 := T + M ; delta := delta+(if 2 * M > a2 - a1 then 2 * M + a1 - a2 else 0 endif) ; skip ; OclFile["System.out"].println(T + delta - 2 * M * N) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] tmpArray=br.readLine().split(" "); int n=Integer.parseInt(tmpArray[0]); int m=Integer.parseInt(tmpArray[1]); int t=Integer.parseInt(tmpArray[2]); String delivery=br.readLine(); System.out.println(solve(delivery,n,m,t)); } static int solve(String delivery,int n,int m,int t){ String[] tmpArray=delivery.split(" "); int delTime[]=new int[n]; int outsideTime=0 ; for(int i=0 ; im*2){ outsideTime+=m*2 ; } else { outsideTime+=delTime[i]-delTime[i-1]; } } outsideTime+=Math.min(m,t-delTime[n-1]); return t-outsideTime ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var tmpArray : Sequence(String) ; tmpArray := br.readLine()->split(" ") ; var n : int ; n := (tmpArray[0+1])->toInteger() ; var m : int ; m := (tmpArray[1+1])->toInteger() ; var t : int ; t := (tmpArray[2+1])->toInteger() ; var delivery : String ; delivery := br.readLine() ; OclFile["System.out"].println(solve(delivery, n, m, t)) ; ); static operation solve( delivery : String, n : int, m : int, t : int) : int pre: true post: true activity: ( var tmpArray : Sequence(String) ; tmpArray := delivery->split(" ") ; var delTime : Sequence(int) ; delTime := Integer.subrange(1,n)->collect(0) ; var outsideTime : int ; outsideTime := 0 ; var i : int ; i := 0 ; while i < n do ( ( delTime[i+1] := (tmpArray[i+1])->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (i = 0) then ( outsideTime := outsideTime+(m) ) else if (delTime[i+1] - delTime[i - 1+1] > m * 2) then ( outsideTime := outsideTime+(m * 2) ) else ( outsideTime := outsideTime+(delTime[i+1] - delTime[i - 1+1]) ) ; ) ; i := i + 1 ) ; outsideTime := outsideTime+(Set{m, t - delTime[n - 1+1]}->min()) ; return t - outsideTime ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int coin(int totalRupees,int X,int Y,int Z){ float one=0,fifty=0,twentyfive=0,result=0,total=0 ; one=X*1 ; fifty=((Y*1)/2); twentyfive=((Z*1)/4); total=one+fifty+twentyfive ; result=((totalRupees)/total); return(int)result ; } public static void main(String[] args){ int totalRupees=1800 ; int X=1,Y=2,Z=4 ; int Rupees=coin(totalRupees,X,Y,Z); System.out.println("1 rupess coins="+Rupees*1); System.out.println("50 paisa coins="+Rupees*2); System.out.println("25 paisa coins="+Rupees*4); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation coin( totalRupees : int, X : int, Y : int, Z : int) : int pre: true post: true activity: ( var one : double ; one := 0 ; var fifty : double ; fifty := 0 ; var twentyfive : double ; twentyfive := 0 ; var result : double ; result := 0 ; var total : double ; total := 0 ; one := X * 1 ; fifty := ((Y * 1) / 2) ; twentyfive := ((Z * 1) / 4) ; total := one + fifty + twentyfive ; result := ((totalRupees) / total) ; return result->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var totalRupees : int ; totalRupees := 1800 ; var X : int ; X := 1 ; var Y : int ; Y := 2 ; var Z : int ; Z := 4 ; var Rupees : int ; Rupees := coin(totalRupees, X, Y, Z) ; OclFile["System.out"].println("1 rupess coins=" + Rupees * 1) ; OclFile["System.out"].println("50 paisa coins=" + Rupees * 2) ; OclFile["System.out"].println("25 paisa coins=" + Rupees * 4) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int numberOfPaths(int m,int n){ int[] dp=new int[n]; dp[0]=1 ; for(int i=0 ; icollect(0) ; dp[0+1] := 1 ; var i : int ; i := 0 ; while i < m do ( ( var j : int ; j := 1 ; while j < n do ( ( dp[j+1] := dp[j+1]+(dp[j - 1+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return dp[n - 1+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(numberOfPaths(3, 3)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int sum(int h){ return(int)Math.pow(2,h-1); } public static void main(String[] args){ int L=3 ; System.out.println(sum(L)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sum( h : int) : int pre: true post: true activity: ( return 2->pow(h - 1)->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 3 ; OclFile["System.out"].println(sum(L)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Odd_Selection { static InputStreamReader r=new InputStreamReader(System.in); static BufferedReader br=new BufferedReader(r); static PrintWriter p=new PrintWriter(System.out); public static void main(String[] args)throws Exception { int test=1 ; me146 : while(test-->0){ String str[]=splitString(); int n=Integer.parseInt(str[0]); long capacity=Long.parseLong(str[1]); long process=Long.parseLong(str[2]); str=splitString(); long a[]=new long[n]; for(int i=0 ; i=a[index]){ filled+=a[index]; index++; } else { long x=(long)Math.ceil((a[index]-remaining)*1.0/process); answer+=x ; filled=Math.max(0,filled-x*process); } } long x=(long)Math.ceil(filled*1.0/process); answer+=x ; p.println(answer); } p.flush(); } static String formatString(String s){ int len=s.length(); for(int i=0 ; i<19-len ; i++){ s="0"+s ; } return s ; } static String[] splitString()throws IOException { return br.readLine().trim().split(" "); } } ------------------------------------------------------------ OCL File: --------- class Odd_Selection { static attribute r : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute br : OclFile := OclFile.newOclFile_Read(r); static attribute p : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var test : int ; test := 1 ; while (test > 0) do ( test := test - 1 ; skip ; ( var str : Sequence(String) ; str := splitString() ; var n : int ; n := (str[0+1])->toInteger() ; var capacity : long ; capacity := (str[1+1])->toLong() ; var process : long ; process := (str[2+1])->toLong() ; str := splitString() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := (str[i+1])->toLong() ; ; i := i + 1 ) ; var index : int ; index := 0 ; var filled : long ; filled := 0 ; var answer : long ; answer := 0 ; while (index < n) do ( var remaining : long ; remaining := capacity - filled ; if (remaining >= a[index+1]) then ( filled := filled+(a[index+1]) ; index := index + 1 ) else ( var x : long ; x := ((a[index+1] - remaining) * 1.0 / process)->ceil()->oclAsType(long) ; answer := answer+(x) ; filled := Set{0, filled - x * process}->max() ) ) ; var x : long ; x := (filled * 1.0 / process)->ceil()->oclAsType(long) ; answer := answer+(x) ; skip ; ) ; ) ; skip ); static operation formatString( s : String) : String pre: true post: true activity: ( var len : int ; len := s->size() ; var i : int ; i := 0 ; while i < 19 - len do ( ( s := "0" + s ) ; i := i + 1 ) ; return s ); static operation splitString() : Sequence(String) pre: true post: true activity: ( return br.readLine()->trim()->split(" ") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Arrays ; public class B_Vanya_and_Food_Processor { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args)throws IOException { int[] l1=readArray(); int n=l1[0]; int h=l1[1]; int k=l1[2]; int[] pieces=readArray(); long seconds=0 ; int content=0 ; int i=0 ; while(true){ while(ioclAsType(double) / k->oclAsType(double))->ceil()) ; break ) else if (content < k) then ( seconds := seconds + 1 ; content := 0 ) else ( seconds := seconds+((content / k)->oclAsType(long)) ; content := content mod k ) ; ) ; skip ; skip ; ); static operation read() : String pre: true post: true activity: ( return in.readLine() ); static operation readInt() : int pre: true post: true activity: ( return (in.readLine())->toInteger() ); static operation readArray() : Sequence(int) pre: true post: true activity: ( var line : Sequence(String) ; line := in.readLine()->split("\\s") ; var a : Sequence(int) ; a := stream(line)->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->asSequence() ; return a ); static operation readSortedArray() : Sequence(int) pre: true post: true activity: ( var line : Sequence(String) ; line := in.readLine()->split("\\s") ; var a : Sequence(int) ; a := stream(line)->collect( _x1 | (lambda _s : String in _s->toInteger())->apply(_x1) )->sort()->asSequence() ; return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean isVowel(char ch){ if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true ; return false ; } static String createAltStr(String str1,String str2,int start,int l){ String finalStr="" ; for(int i=0,j=start ; j=2)return "no such string" ; if(nv>nc)return(vstr.charAt(0)+createAltStr(cstr,vstr,1,nv)); if(nc>nv)return(cstr.charAt(0)+createAltStr(vstr,cstr,1,nc)); if(cstr.charAt(0)at(i+1)) + str2->at(j+1) ; ; i := i + 1 ; j := j + 1 ) ; return finalStr ); static operation findAltStr( str : String) : String pre: true post: true activity: ( var nv : int ; nv := 0 ; var nc : int ; nc := 0 ; var vstr : String ; vstr := "" ; var cstr : String ; cstr := "" ; var l : int ; l := str->size() ; var i : int ; i := 0 ; while i < l do ( ( var ch : String ; ch := str->at(i+1) ; if (isVowel(ch)) then ( nv := nv + 1 ; vstr := vstr + ch ) else ( nc := nc + 1 ; cstr := cstr + ch ) ) ; i := i + 1 ) ; if (if nv - nc < 0 then -(nv - nc) else nv - nc endif >= 2) then return "no such string" else skip ; if (nv > nc) then return (vstr->at(0+1) + createAltStr(cstr, vstr, 1, nv)) else skip ; if (nc > nv) then return (cstr->at(0+1) + createAltStr(vstr, cstr, 1, nc)) else skip ; if (cstr->at(0+1) < vstr->at(0+1)) then return createAltStr(cstr, vstr, 0, nv) else skip ; return createAltStr(vstr, cstr, 0, nc) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeks" ; OclFile["System.out"].println(findAltStr(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static final int SIZE=26 ; static boolean isVowel(char ch){ if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'){ return true ; } return false ; } static String createAltStr(String str1,String str2,int start,int l){ String finalStr="" ; for(int i=0,j=start ; j=2){ return "no such String" ; } for(int i=0 ; inc){ return(vstr.charAt(0)+createAltStr(cstr,vstr,1,nv)); } if(nc>nv){ return(cstr.charAt(0)+createAltStr(vstr,cstr,1,nc)); } if(cstr.charAt(0)at(i+1)) + str2->at(j+1) ) ; i := i + 1 ; j := j + 1 ) ; return finalStr ); static operation findAltStr( str : String) : String pre: true post: true activity: ( var char_freq : Sequence(int) ; char_freq := Integer.subrange(1,SIZE)->collect(0) ; char_freq := char_freq->collect(0) ; var nv : int ; nv := 0 ; var nc : int ; nc := 0 ; var vstr : String ; vstr := "" ; var cstr : String ; cstr := "" ; var l : int ; l := str->size() ; var i : int ; i := 0 ; while i < l do ( ( var ch : String ; ch := str->at(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 ) ; i := i + 1 ) ; if (if nv - nc < 0 then -(nv - nc) else nv - nc endif >= 2) then ( return "no such String" ) else skip ; var i : int ; i := 0 ; while i < SIZE do ( ( var ch : String ; ch := (i + 97)->oclAsType(String) ; var j : int ; j := 1 ; while j <= char_freq[i+1] do ( ( if (isVowel(ch)) then ( vstr := vstr+(ch) ) else ( cstr := cstr+(ch) ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (nv > nc) then ( return (vstr->at(0+1) + createAltStr(cstr, vstr, 1, nv)) ) else skip ; if (nc > nv) then ( return (cstr->at(0+1) + createAltStr(vstr, cstr, 1, nc)) ) else skip ; if (cstr->at(0+1) < vstr->at(0+1)) then ( return createAltStr(cstr, vstr, 0, nv) ) else skip ; return createAltStr(vstr, cstr, 0, nc) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "aeroplane" ; OclFile["System.out"].println(findAltStr(str)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.util.PriorityQueue ; import java.util.Scanner ; class Stuff implements Comparable{ int v ; int w ; double performance ; Stuff(int v,int w){ this.v=v ; this.w=w ; performance=1.0*v/w ; } public int compareTo(Stuff s){ if(performances.performance)return-1 ; return 0 ; } } public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int w=sc.nextInt(); PriorityQueueque=new PriorityQueue<>(); for(int i=0 ; i0 && ! que.isEmpty()){ Stuff s=que.poll(); if(w>=s.w){ res+=s.v ; w-=s.w ; } else { res+=s.performance*w ; w=0 ; } } System.out.println(BigDecimal.valueOf(res).toPlainString()); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Stuff implements Comparable { attribute v : int; attribute w : int; attribute performance : double; static operation newStuff( v : int, w : int) : Stuff pre: true post: true activity: ( var self : Stuff ; self := createStuff(); self.initialise(v, w); return self ); operation initialise( v : int, w : int) : void pre: true post: true activity: ( self.v := v ; self.w := w ; performance := 1.0 * v / w ); operation compareTo( s : Stuff) : int pre: true post: true activity: ( if (performance < s.performance) then return 1 else skip ; if (performance > s.performance) then return -1 else skip ; return 0 ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var que : Sequence(Stuff) ; que := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var vi : int ; vi := sc.getCurrent()->toInteger() ; var wi : int ; wi := sc.getCurrent()->toInteger() ; que := que->including(Stuff.newStuff(vi, wi)) ) ; i := i + 1 ) ; var res : double ; res := 0 ; while (w > 0 & not(que->isEmpty())) do ( var s : Stuff ; s := que->min() ; if (w >= s.w) then ( res := res+(s.v) ; w := w-(s.w) ) else ( res := res+(s.performance * w) ; w := 0 ) ) ; OclFile["System.out"].println((res + "")->toReal().toPlainString()) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.math.*; import java.util.*; public class Main { static class Tree { final String name ; final ArrayLista=new ArrayList(); Tree(String name){ this.name=name ; } int size(){ if(a.size()==0)return 1 ; int ans=1 ; for(Tree t : a)ans+=t.size(); return ans ; } void out(String s){ System.out.println(s+name); for(Tree t : a)t.out(s+" "); } void out(){ out(""); } } static void add(Tree t,String d){ String[] ss=d.substring(1).split("/"); for(String s : ss){ Tree w=null ; for(Tree r : t.a)if(r.name.equals(s)){ w=r ; break ; } if(w==null){ w=new Tree(s); t.a.add(w); } t=w ; } } public static void main(String[] args)throws Exception { Scanner in=new Scanner(new File("Main.in")); PrintWriter out=new PrintWriter(new File("Main.out")); int tests=in.nextInt(); for(int test=1 ; test<=tests ; test++){ out.print("Case #"+test+": "); int n=in.nextInt(); int m=in.nextInt(); in.nextLine(); Tree t=new Tree(""); for(int i=0 ; isize() = 0) then return 1 else skip ; var ans : int ; ans := 1 ; for (t : a) do ( ans := ans+(t->size()) ; ) ; return ans ); operation out( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s + name) ; for (t : a) do ( t.out(s + " ") ; ) ); operation out() : void pre: true post: true activity: ( execute out("") ); } static operation add( t : Tree, d : String) : void pre: true post: true activity: ( var ss : Sequence(String) ; ss := d.subrange(1+1,1)->split("/") ; for (s : ss) do ( ( var w : Tree ; w := null ; for (r : t.a) do ( if (r.name = s) then ( w := r ; break ) else skip ; ) ; if (w = null) then ( w := Tree.newTree(s) ; t.a->excludes(w) ) else skip ; t := w ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile("Main.in")) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile("Main.out")) ; var tests : int ; tests := in.getCurrent()->toInteger() ; var test : int ; test := 1 ; while test <= tests do ( ( skip ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; skip ; var t : Tree ; t := Tree.newTree("") ; var i : int ; i := 0 ; while i < n do ( ( var d : String ; d := in.nextLine() ; execute add(t, d) ) ; i := i + 1 ) ; var was : int ; was := t->size() ; var i : int ; i := 0 ; while i < m do ( ( var d : String ; d := in.nextLine() ; execute add(t, d) ) ; i := i + 1 ) ; skip ; ) ; test := test + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Solution { class Tree { Mapmp=new HashMap(); public Tree(){ } } Tree root ; int res ; void process(String s,boolean add){ s=s.substring(1); String[] items=s.split("/"); Tree cur=root ; for(int i=0 ; isize() do ( ( if (not(cur.mp.containsKey(items[i+1]))) then ( cur := cur.mp->union(Map{items[i+1] |-> Tree.newTree()}) ; if (add) then res := res + 1 ; else skip ) else skip ; cur := cur.mp->at(items[i+1]+1) ) ; i := i + 1 ) ); operation doMain() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) ; var caseCnt : int ; caseCnt := sc.getCurrent()->toInteger() ; var time : long ; time := OclDate.getSystemTime() ; var caseNum : int ; caseNum := 1 ; while caseNum <= caseCnt do ( ( var have : int ; have := sc.getCurrent()->toInteger() ; var next : int ; next := sc.getCurrent()->toInteger() ; root := Tree.newTree() ; res := 0 ; var i : int ; i := 0 ; while i < have do ( ( execute process(sc.getCurrent(), false) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < next do ( execute process(sc.getCurrent(), true) ; ; i := i + 1 ) ; skip ; OclFile["System.out"].println("Finished testcase " + caseNum + ",time=" + (OclDate.getSystemTime() - time)) ; ) ; caseNum := caseNum + 1 ) ; skip ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Solution.newSolution()).doMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.*; public class A { public void solve()throws FileNotFoundException { Scanner in=new Scanner(new File("A-large.in")); PrintWriter out=new PrintWriter("A-large.out"); int testN=in.nextInt(); for(int test=1 ; test<=testN ; test++){ out.print("Case #"+test+": "); int n=in.nextInt(); int m=in.nextInt(); String[] exists=new String[n]; String[] create=new String[m]; Setex=new HashSet(); for(int i=0 ; ineed=new TreeSet(); for(int i=0 ; itoInteger() ; var test : int ; test := 1 ; while test <= testN do ( ( skip ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var exists : Sequence(String) ; exists := Integer.subrange(1,n)->collect(null) ; var create : Sequence(String) ; create := Integer.subrange(1,m)->collect(null) ; var ex : Set(String) ; ex := Set{} ; var i : int ; i := 0 ; while i < n do ( ( exists[i+1] := in.getCurrent() ; var t : Sequence(String) ; t := exists[i+1]->split("/") ; var r : String ; r := "" ; var j : int ; j := 1 ; while j < t->size() do ( ( r := r + "/" + t[j+1] ; ex := ex->including(r) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var need : Set(String) ; need := Set{} ; var i : int ; i := 0 ; while i < m do ( ( create[i+1] := in.getCurrent() ; var t : Sequence(String) ; t := create[i+1]->split("/") ; var r : String ; r := "" ; var j : int ; j := 1 ; while j < t->size() do ( ( r := r + "/" + t[j+1] ; need := need->including(r) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var res : int ; res := 0 ; for (s : need) do ( ( if (not(ex->includes(s))) then ( res := res + 1 ; ex := ex->including(s) ) else skip ) ) ; skip ; ) ; test := test + 1 ) ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A.newA().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main implements Runnable { public Scanner in ; public PrintWriter out ; Main()throws IOException { in=new Scanner(new File("in")); out=new PrintWriter(new File("out")); } void close()throws IOException { out.close(); } void check(boolean f,String msg){ if(! f){ out.close(); throw new RuntimeException(msg); } } public void run(){ int tn=in.nextInt(); for(int test=1 ; test<=tn ; test++){ int old=in.nextInt(); int create=in.nextInt(); in.nextLine(); Node root=new Node(); for(int i=0 ; i=tokens.length){ return 0 ; } int r=0 ; if(node.children.get(tokens[p])==null){ node.children.put(tokens[p],new Node()); r=1 ; } return r+add(node.children.get(tokens[p]),tokens,p+1); } public class Node { Mapchildren ; Node(){ children=new TreeMap(); } } public static void main(String[] args)throws IOException { new Thread(new Main()).start(); } } ------------------------------------------------------------ OCL File: --------- class Main implements Runnable { attribute in : OclFile; attribute out : OclFile; static operation newMain() : Main pre: true post: true activity: ( var self : Main ; self := createMain(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile("in")) ; out := OclFile.newOclFile_Write(OclFile("out")) ); operation close() : void pre: true post: true activity: ( skip ); operation check( f : boolean, msg : String) : void pre: true post: true activity: ( if (not(f)) then ( skip ; error ProgramException(msg) ) else skip ); operation run() : void pre: true post: true activity: ( var tn : int ; tn := in.getCurrent()->toInteger() ; var test : int ; test := 1 ; while test <= tn do ( ( var old : int ; old := in.getCurrent()->toInteger() ; var create : int ; create := in.getCurrent()->toInteger() ; skip ; var root : Node ; root := Node.newNode() ; var i : int ; i := 0 ; while i < old do ( ( execute add(root, in.nextLine()->split("/"), 1) ) ; i := i + 1 ) ; var r : int ; r := 0 ; var i : int ; i := 0 ; while i < create do ( ( r := r+(add(root, in.nextLine()->split("/"), 1)) ) ; i := i + 1 ) ; skip ; ) ; test := test + 1 ) ; try ( execute close() ) catch (e : IOException) do ( e.printStackTrace() ) ); operation add( node : Node, tokens : Sequence(String), p : int) : int pre: true post: true activity: ( if (p >= tokens->size()) then ( return 0 ) else skip ; var r : int ; r := 0 ; if (node.children->at(tokens[p+1]+1) = null) then ( node := node.children->union(Map{tokens[p+1] |-> Node.newNode()}) ; r := 1 ) else skip ; return r + add(node.children->at(tokens[p+1]+1), tokens, p + 1) ); class Node { attribute children : Map(String,Node); static operation newNode() : Node pre: true post: true activity: ( var self : Node ; self := createNode(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( children := Map{} ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclProcess.newOclProcess(Main.newMain()).start() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class x { static class Directory { int st ; HashMaph ; Directory(int cst){ h=new HashMap(); st=cst ; } Directory create(String name,int sst){ Directory c=h.get(name); if(c!=null)return c ; c=new Directory(sst); h.put(name,c); return c ; } int count(int lst){ int cur=0 ; if(st>lst)++cur ; for(Directory z : h.values())cur+=z.count(lst); return cur ; } } public static void main(String args[])throws Exception { Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int tt=1 ; tt<=t ; tt++){ Directory r=new Directory(0); int n=in.nextInt(),m=in.nextInt(); for(int i=1 ; i<=n+m ; i++){ String[] a=in.next().split("/"); Directory c=r ; for(int j=1 ; jat(name) ; if (c /= null) then return c else skip ; c := Directory.newDirectory(sst) ; h := h->union(Map{name |-> c}) ; return c ); operation count( lst : int) : int pre: true post: true activity: ( var cur : int ; cur := 0 ; if (st > lst) then cur := cur + 1 ; else skip ; for (z : h->values()) do ( cur := cur+(z.count(lst)) ; ) ; return cur ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var tt : int ; tt := 1 ; while tt <= t do ( ( var r : Directory ; r := Directory.newDirectory(0) ; var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= n + m do ( ( var a : Sequence(String) ; a := in.getCurrent()->split("/") ; var c : Directory ; c := r ; var j : int ; j := 1 ; while j < a->size() do ( ( c := c.create(a[j+1], i) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println("Case #" + tt + ": " + r.count(n)) ) ; tt := tt + 1 ) ; ); } ; ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int tc=0 ; tctoInteger() ; var tc : int ; tc := 0 ; while tc < n do ( ( var s : String ; s := sc.getCurrent() ; var t : String ; t := sc.getCurrent() ; OclFile["System.out"].println(if solve(s, t) then "YES" else "NO" endif) ) ; tc := tc + 1 ) ; skip ); static operation solve( s : String, t : String) : boolean pre: true post: true activity: ( var sIndex : int ; sIndex := 0 ; for (tCh : t->characters()) do ( ( if (sIndex < s->size() & tCh = s->at(sIndex+1)) then ( sIndex := sIndex + 1 ) else if (sIndex = 0 or tCh /= s->at((sIndex)->char2byte() - 1+1)) then ( return false ) else skip ; ) ) ; return sIndex = s->size() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int N=s.nextInt(); int M=s.nextInt(); long a[]=new long[N]; long b[]=new long[N]; long c[]=new long[M]; long d[]=new long[M]; long min=0 ; int l=0 ; int i=0,j=0 ; for(i=0 ; iMath.abs(a[i]-c[j])+Math.abs(b[i]-d[j])){ min=Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]); l=j ; } } System.out.println(l+1); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := s.getCurrent()->toInteger() ; var M : int ; M := s.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,N)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,N)->collect(0) ; var c : Sequence(long) ; c := Integer.subrange(1,M)->collect(0) ; var d : Sequence(long) ; d := Integer.subrange(1,M)->collect(0) ; var min : long ; min := 0 ; var l : int ; l := 0 ; var i : int ; i := 0 ; var j : int ; j := 0 ; i := 0 ; while i < N do ( ( a[i+1] := s.getCurrent()->toInteger() ; b[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; i := 0 ; while i < M do ( ( c[i+1] := s.getCurrent()->toInteger() ; d[i+1] := s.getCurrent()->toInteger() ) ; i := i + 1 ) ; i := 0 ; while i < N do ( ( min := if a[i+1] - c[0+1] < 0 then -(a[i+1] - c[0+1]) else a[i+1] - c[0+1] endif + if b[i+1] - d[0+1] < 0 then -(b[i+1] - d[0+1]) else b[i+1] - d[0+1] endif ; l := 0 ; j := 0 ; while j < M do ( ( if (min > if a[i+1] - c[j+1] < 0 then -(a[i+1] - c[j+1]) else a[i+1] - c[j+1] endif + if b[i+1] - d[j+1] < 0 then -(b[i+1] - d[j+1]) else b[i+1] - d[j+1] endif) then ( min := if a[i+1] - c[j+1] < 0 then -(a[i+1] - c[j+1]) else a[i+1] - c[j+1] endif + if b[i+1] - d[j+1] < 0 then -(b[i+1] - d[j+1]) else b[i+1] - d[j+1] endif ; l := j ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println(l + 1) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=br.readLine(); String[] t=str.split("\\ "); int a=Integer.parseInt(t[0]); int b=Integer.parseInt(t[1]); System.out.println(Math.max(a*b,Math.max(a-b,a+b))); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : String ; str := br.readLine() ; var t : Sequence(String) ; t := str->split("\\ ") ; var a : int ; a := (t[0+1])->toInteger() ; var b : int ; b := (t[1+1])->toInteger() ; OclFile["System.out"].println(Set{a * b, Set{a - b, a + b}->max()}->max()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sn=new Scanner(System.in); int A=0 ; int B=0 ; int x=0 ; int y=0 ; int z=0 ; int max=0 ; try { String str=sn.nextLine(); String[] strlist=str.split(" ",0); A=Integer.parseInt(strlist[0]); B=Integer.parseInt(strlist[1]); sn.close(); if(A<-100 || 100split(" ") ; A := (strlist[0+1])->toInteger() ; B := (strlist[1+1])->toInteger() ; skip ; if (A < -100 or 100 < B) then ( return ) else skip ; x := A + B ; y := A - B ; z := A * B ; max := Set{x, y}->max() ; max := Set{max, z}->max() ; OclFile["System.out"].println(max) ; ) catch (e : ProgramException) do ( return ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int ans=Math.max(a*b,a+b); ans=Math.max(ans,a-b); out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var ans : int ; ans := Set{a * b, a + b}->max() ; ans := Set{ans, a - b}->max() ; out.println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.util.PriorityQueue ; import java.util.Scanner ; class Stuff implements Comparable{ int v ; int w ; double performance ; Stuff(int v,int w){ this.v=v ; this.w=w ; performance=1.0*v/w ; } public int compareTo(Stuff s){ if(performances.performance)return-1 ; return 0 ; } } public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int w=sc.nextInt(); PriorityQueueque=new PriorityQueue<>(); for(int i=0 ; i0 && ! que.isEmpty()){ Stuff s=que.poll(); if(w>=s.w){ res+=s.v ; w-=s.w ; } else { res+=s.performance*w ; w=0 ; } } System.out.println(BigDecimal.valueOf(res).toPlainString()); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Stuff implements Comparable { attribute v : int; attribute w : int; attribute performance : double; static operation newStuff( v : int, w : int) : Stuff pre: true post: true activity: ( var self : Stuff ; self := createStuff(); self.initialise(v, w); return self ); operation initialise( v : int, w : int) : void pre: true post: true activity: ( self.v := v ; self.w := w ; performance := 1.0 * v / w ); operation compareTo( s : Stuff) : int pre: true post: true activity: ( if (performance < s.performance) then return 1 else skip ; if (performance > s.performance) then return -1 else skip ; return 0 ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var que : Sequence(Stuff) ; que := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var vi : int ; vi := sc.getCurrent()->toInteger() ; var wi : int ; wi := sc.getCurrent()->toInteger() ; que := que->including(Stuff.newStuff(vi, wi)) ) ; i := i + 1 ) ; var res : double ; res := 0 ; while (w > 0 & not(que->isEmpty())) do ( var s : Stuff ; s := que->min() ; if (w >= s.w) then ( res := res+(s.v) ; w := w-(s.w) ) else ( res := res+(s.performance * w) ; w := 0 ) ) ; OclFile["System.out"].println((res + "")->toReal().toPlainString()) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int a=sc.nextInt(),b=sc.nextInt(); sc.close(); int ans=a+b ; int tmp=a-b ; ans=Math.max(ans,tmp); tmp=a*b ; ans=Math.max(ans,tmp); System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; skip ; var ans : int ; ans := a + b ; var tmp : int ; tmp := a - b ; ans := Set{ans, tmp}->max() ; tmp := a * b ; ans := Set{ans, tmp}->max() ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int[] ans=new int[3]; ans[0]=a+b ; ans[1]=a-b ; ans[2]=a*b ; Arrays.sort(ans); System.out.println(ans[2]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var ans : Sequence(int) ; ans := Integer.subrange(1,3)->collect(0) ; ans[0+1] := a + b ; ans[1+1] := a - b ; ans[2+1] := a * b ; ans := ans->sort() ; OclFile["System.out"].println(ans[2+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void reverse(int arr[],int n,int k){ for(int i=0 ; imin() ; var temp : int ; while (left < right) do ( temp := arr[left+1] ; arr[left+1] := arr[right+1] ; arr[right+1] := temp ; left := left+(1) ; right := right-(1) ; ) ) ; i := i+(k) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5,6,7,8} ; var k : int ; k := 3 ; var n : int ; n := arr->size() ; execute reverse(arr, n, k) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void reverse(int arr[],int n,int k){ for(int i=0 ; imin() ; while (left < right) do ( execute swap(arr, left, right) ) ) ; i := i+(2 * k) ) ); static operation swap( array : Sequence(int), i : int, j : int) : Sequence(int) pre: true post: true activity: ( var temp : int ; temp := array[i+1] ; array[i+1] := array[j+1] ; array[j+1] := temp ; return array ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5,6,7,8,9,10,11,12,13,14} ; var k : int ; k := 3 ; var n : int ; n := arr->size() ; execute reverse(arr, n, k) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(arr[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void reverse(int[] arr,int n,int k,int m){ for(int i=0 ; imin() ; while (left < right) do execute swap(arr, left, right) ; ) ; i := i+(k + m) ) ); static operation swap( arr : Sequence(int), i : int, j : int) : Sequence(int) pre: true post: true activity: ( var temp : int ; temp := arr[i+1] ; arr[i+1] := arr[j+1] ; arr[j+1] := temp ; return arr ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,2,3,4,5,6,7,8,9,10,11,12,13,14} ; var k : int ; k := 3 ; var m : int ; m := 2 ; var n : int ; n := arr->size() ; execute reverse(arr, n, k, m) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].print(arr[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Test { static int arr[]={ 10,20,30,50,10,70,30 }; static void printMaxOfMin(int n){ for(int k=1 ; k<=n ; k++){ int maxOfMin=Integer.MIN_VALUE ; for(int i=0 ; i<=n-k ; i++){ int min=arr[i]; for(int j=1 ; jmaxOfMin)maxOfMin=min ; } System.out.print(maxOfMin+" "); } } public static void main(String[] args){ printMaxOfMin(arr.length); } } ------------------------------------------------------------ OCL File: --------- class Test { static attribute arr : int := Sequence{10,20,30,50,10,70,30}; static operation printMaxOfMin( n : int) : void pre: true post: true activity: ( var k : int ; k := 1 ; while k <= n do ( ( var maxOfMin : int ; maxOfMin := -2147483648 ; var i : int ; i := 0 ; while i <= n - k do ( ( var min : int ; min := arr[i+1] ; var j : int ; j := 1 ; while j < k do ( ( if (arr[i + j+1] < min) then min := arr[i + j+1] ; else skip ) ; j := j + 1 ) ; if (min > maxOfMin) then maxOfMin := min ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].print(maxOfMin + " ") ) ; k := k + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute printMaxOfMin(arr->size()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class TechnohobletOfFire { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int k=sc.nextInt(); int[] p=new int[n+1]; int[] s=new int[n+1]; int[] mp=new int[m+1]; for(int i=1 ; i<=n ; i++){ p[i]=sc.nextInt(); } for(int i=1 ; i<=n ; i++){ s[i]=sc.nextInt(); } for(int i=1 ; i<=n ; i++){ mp[s[i] ]=Math.max(mp[s[i] ],p[i]); } int c=0 ; for(int i=1 ; i<=k ; i++){ int x=sc.nextInt(); if(p[x]!=mp[s[x] ])c++; } System.out.println(c); } } ------------------------------------------------------------ OCL File: --------- class TechnohobletOfFire { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var p : Sequence(int) ; p := Integer.subrange(1,n + 1)->collect(0) ; var s : Sequence(int) ; s := Integer.subrange(1,n + 1)->collect(0) ; var mp : Sequence(int) ; mp := Integer.subrange(1,m + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( ( p[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( s[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( mp[s[i+1]+1] := Set{mp[s[i+1]+1], p[i+1]}->max() ) ; i := i + 1 ) ; var c : int ; c := 0 ; var i : int ; i := 1 ; while i <= k do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; if (p[x+1] /= mp[s[x+1]+1]) then c := c + 1 ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str[]=br.readLine().split(" "); int n=Integer.parseInt(str[0]); int m=Integer.parseInt(str[1]); Pair p[]=new Pair[n]; Pair check[]=new Pair[m]; for(int i=0 ; isplit(" ") ; var n : int ; n := (str[0+1])->toInteger() ; var m : int ; m := (str[1+1])->toInteger() ; var p : Sequence(Map) ; p := Integer.subrange(1,n)->collect(null) ; var check : Sequence(Map) ; check := Integer.subrange(1,m)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( str := br.readLine()->split(" ") ; var a : int ; a := (str[0+1])->toInteger() ; var b : int ; b := (str[1+1])->toInteger() ; p[i+1] := Map(a, b) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( str := br.readLine()->split(" ") ; var c : int ; c := (str[0+1])->toInteger() ; var d : int ; d := (str[1+1])->toInteger() ; check[i+1] := Map(c, d) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var min : int ; min := 2147483647 ; var minI : int ; minI := -1 ; var j : int ; j := 0 ; while j < m do ( ( if (p[i+1].getDist(check[j+1].x, check[j+1].y) < min) then ( min := p[i+1].getDist(check[j+1].x, check[j+1].y) ; minI := j ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println(minI + 1) ) ; i := i + 1 ) ; ); } class Pair { attribute x : int; attribute y : int; static operation newPair( x : int, y : int) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(x, y); return self ); operation initialise( x : int, y : int) : void pre: true post: true activity: ( self.x := x ; self.y := y ); operation getDist( x : int, y : int) : int pre: true post: true activity: ( return if x - self.x < 0 then -(x - self.x) else x - self.x endif + if y - self.y < 0 then -(y - self.y) else y - self.y endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Test { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int k=sc.nextInt(); int[] powers=new int[n]; int[] school=new int[n]; int[] select=new int[k]; for(int i=0 ; iset=new HashMap<>(); for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var powers : Sequence(int) ; powers := Integer.subrange(1,n)->collect(0) ; var school : Sequence(int) ; school := Integer.subrange(1,n)->collect(0) ; var select : Sequence(int) ; select := Integer.subrange(1,k)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( powers[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( school[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k do ( ( select[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var set : Map(int,int) ; set := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var selectedSchool : int ; selectedSchool := school[i+1] ; if (set->keys()->includes(selectedSchool)) then ( var value : int ; value := set->at(selectedSchool) ; set := set->union(Map{selectedSchool |-> Set{powers[i+1], value}->max()}) ) else ( set := set->union(Map{selectedSchool |-> powers[i+1]}) ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < k do ( ( var schoolValue : int ; schoolValue := set->at(school[select[i+1] - 1+1]) ; if (powers[select[i+1] - 1+1] < schoolValue) then ( ans := ans + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAXN=10000000 ; static int minimumSteps(int n,int m,int a,int b){ if(n>m)return MAXN ; if(n==m)return 0 ; return Math.min(1+minimumSteps(n*a,m,a,b),1+minimumSteps(n*b,m,a,b)); } public static void main(String[] args){ int n=120,m=51840 ; int a=2,b=3 ; System.out.println(minimumSteps(n,m,a,b)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAXN : int := 10000000; static operation minimumSteps( n : int, m : int, a : int, b : int) : int pre: true post: true activity: ( if (n > m) 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() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 120 ; var m : int ; m := 51840 ; var a : int ; a := 2 ; var b : int ; b := 3 ; OclFile["System.out"].println(minimumSteps(n, m, a, b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.util.PriorityQueue ; import java.util.Scanner ; class Stuff implements Comparable{ int v ; int w ; double performance ; Stuff(int v,int w){ this.v=v ; this.w=w ; performance=1.0*v/w ; } public int compareTo(Stuff s){ if(performances.performance)return-1 ; return 0 ; } } public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int w=sc.nextInt(); PriorityQueueque=new PriorityQueue<>(); for(int i=0 ; i0 && ! que.isEmpty()){ Stuff s=que.poll(); if(w>=s.w){ res+=s.v ; w-=s.w ; } else { res+=s.performance*w ; w=0 ; } } System.out.println(BigDecimal.valueOf(res).toPlainString()); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Stuff implements Comparable { attribute v : int; attribute w : int; attribute performance : double; static operation newStuff( v : int, w : int) : Stuff pre: true post: true activity: ( var self : Stuff ; self := createStuff(); self.initialise(v, w); return self ); operation initialise( v : int, w : int) : void pre: true post: true activity: ( self.v := v ; self.w := w ; performance := 1.0 * v / w ); operation compareTo( s : Stuff) : int pre: true post: true activity: ( if (performance < s.performance) then return 1 else skip ; if (performance > s.performance) then return -1 else skip ; return 0 ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var que : Sequence(Stuff) ; que := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var vi : int ; vi := sc.getCurrent()->toInteger() ; var wi : int ; wi := sc.getCurrent()->toInteger() ; que := que->including(Stuff.newStuff(vi, wi)) ) ; i := i + 1 ) ; var res : double ; res := 0 ; while (w > 0 & not(que->isEmpty())) do ( var s : Stuff ; s := que->min() ; if (w >= s.w) then ( res := res+(s.v) ; w := w-(s.w) ) else ( res := res+(s.performance * w) ; w := 0 ) ) ; OclFile["System.out"].println((res + "")->toReal().toPlainString()) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static boolean strcheck(String s1,String s2){ if(s1.compareTo(s2)!=0)return false ; return true ; } public static boolean check(String s){ if(s.length()>=10)return true ; for(int i=1 ; icompareTo(s2) /= 0) then return false else skip ; return true ); static operation check( s : String) : boolean pre: true post: true activity: ( if (s->size() >= 10) then return true else skip ; var i : int ; i := 1 ; while i < s->size() do ( ( var j : int ; j := i + 1 ; while j < s->size() do ( ( var k : int ; k := j + 1 ; while k < s->size() do ( ( var s1 : String ; s1 := "" ; var s2 : String ; s2 := "" ; var s3 : String ; s3 := "" ; var s4 : String ; s4 := "" ; try ( s1 := s.subrange(0+1,i) ; s2 := s.subrange(i+1,j - i) ; s3 := s.subrange(j+1,k - j) ; s4 := s.subrange(k+1,s->size() - k) ) catch (e : IndexingException) do skip if (strcheck(s1, s2) & strcheck(s1, s3) & strcheck(s1, s4) & strcheck(s2, s3) & strcheck(s2, s4) & strcheck(s3, s4)) then return true else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "aaabb" ; if (check(str)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Stack ; class Test { static Stackst=new Stack<>(); static void insert_at_bottom(char x){ if(st.isEmpty())st.push(x); else { char a=st.peek(); st.pop(); insert_at_bottom(x); st.push(a); } } static void reverse(){ if(st.size()>0){ char x=st.peek(); st.pop(); reverse(); insert_at_bottom(x); } } public static void main(String[] args){ st.push('1'); st.push('2'); st.push('3'); st.push('4'); System.out.println("Original Stack"); System.out.println(st); reverse(); System.out.println("Reversed Stack"); System.out.println(st); } } ------------------------------------------------------------ OCL File: --------- class Test { static attribute st : Sequence(String) := Sequence{}; static operation insert_at_bottom( x : String) : void pre: true post: true activity: ( if (st->isEmpty()) then st := st->append(x) ; else ( var a : String ; a := st->min() ; st := st->front() ; execute insert_at_bottom(x) ; st := st->append(a) ) ); static operation reverse() : void pre: true post: true activity: ( if (st->size() > 0) then ( var x : String ; x := st->min() ; st := st->front() ; execute reverse() ; execute insert_at_bottom(x) ) else skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( st := st->append('1') ; st := st->append('2') ; st := st->append('3') ; st := st->append('4') ; OclFile["System.out"].println("Original Stack") ; OclFile["System.out"].println(st) ; execute reverse() ; OclFile["System.out"].println("Reversed Stack") ; OclFile["System.out"].println(st) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { public static int MAX_CHAR=256 ; static int kthNonRepeating(String str,int k){ int n=str.length(); int[] count=new int[MAX_CHAR]; int[] index=new int[MAX_CHAR]; for(int i=0 ; isize() ; var count : Sequence(int) ; count := Integer.subrange(1,MAX_CHAR)->collect(0) ; var index : Sequence(int) ; index := Integer.subrange(1,MAX_CHAR)->collect(0) ; var i : int ; i := 0 ; while i < MAX_CHAR do ( ( count[i+1] := 0 ; index[i+1] := n ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var x : String ; x := str->at(i+1) ; count[x+1] := count[x+1] + 1 ; if (count[x+1] = 1) then index[x+1] := i ; else skip ; if (count[x+1] = 2) then index[x+1] := n ; else skip ) ; i := i + 1 ) ; index := index->sort() ; return if (index[k - 1+1] /= n) then index[k - 1+1] else -1 endif ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var k : int ; k := 3 ; var res : int ; res := kthNonRepeating(str, k) ; OclFile["System.out"].println(if res = -1 then "There are less than k non-repeating characters" else "k'th non-repeating character is " + str->at(res+1) endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; class GFG { static void findElements(int arr[],int n){ int first=Integer.MIN_VALUE ; int second=Integer.MAX_VALUE ; for(int i=0 ; ifirst){ second=first ; first=arr[i]; } else if(arr[i]>second)second=arr[i]; } for(int i=0 ; i first) then ( second := first ; first := arr[i+1] ) else if (arr[i+1] > second) then second := arr[i+1] ; else skip ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( if (arr[i+1] < second) then OclFile["System.out"].print(arr[i+1] + " ") ; else skip ; ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,-6,3,5,1} ; var n : int ; n := arr->size() ; execute findElements(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class gfg { static int sub_arrays(int[] a,int n,int k){ int sum[]=new int[n+2]; for(int i=0 ; imp=new HashMap(); for(int i=0 ; i=k){ temp=(int)mp.get(sum[l])-1 ; mp.put(sum[l],temp); l++; } } return ans ; } public static void main(String args[]){ int[] a={ 1,4,2,3,5 }; int n=a.length ; int k=4 ; System.out.print(sub_arrays(a,n,k)); } } ------------------------------------------------------------ OCL File: --------- class gfg { static operation sub_arrays( a : Sequence(int), n : int, k : int) : int pre: true post: true activity: ( var sum : Sequence(int) ; sum := Integer.subrange(1,n + 2)->collect(0) ; var i : int ; i := 0 ; while i < n + 2 do ( ( sum[i+1] := 0 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := a[i+1] - 1 ; a[i+1] := a[i+1] mod k ; sum[i + 1+1] := sum[i + 1+1]+(sum[i+1] + a[i+1]) ; sum[i + 1+1] := sum[i + 1+1] mod k ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var l : int ; l := 0 ; var r : int ; r := 0 ; var mp : Map(int,int) ; mp := Map{} ; var i : int ; i := 0 ; while i < n + 1 do ( ( mp := mp->union(Map{sum[i+1] |-> 0}) ) ; i := i + 1 ) ; var temp : int ; var i : int ; i := 0 ; while i < n + 1 do ( ( ans := ans+(mp->at(sum[i+1])->oclAsType(int)) ; temp := mp->at(sum[i+1])->oclAsType(int) + 1 ; mp := mp->union(Map{sum[i+1] |-> temp}) ; r := r + 1 ; if (r - l >= k) then ( temp := mp->at(sum[l+1])->oclAsType(int) - 1 ; mp := mp->union(Map{sum[l+1] |-> temp}) ; l := l + 1 ) else skip ; ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,4,2,3,5} ; var n : int ; n := a->size() ; var k : int ; k := 4 ; OclFile["System.out"].print(sub_arrays(a, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int lenDoubleString(String s){ int l=s.length(); String first_half=s.substring(0,l/2); String second_half="" ; if(l % 2==0)second_half=s.substring(l/2); else second_half=s.substring(l/2+1); second_half=reverse(second_half); System.out.println(first_half+second_half); if(l % 2==0)System.out.println(l); else System.out.println(l-1); return Integer.MIN_VALUE ; } static String reverse(String input){ char[] temparray=input.toCharArray(); int left,right=0 ; right=temparray.length-1 ; for(left=0 ; leftsize() ; var first_half : String ; first_half := s.subrange(0+1,l / 2) ; var second_half : String ; second_half := "" ; if (l mod 2 = 0) then second_half := s.subrange(l / 2+1,l / 2) else second_half := s.subrange(l / 2 + 1+1,l / 2 + 1) ; ; second_half := reverse(second_half) ; OclFile["System.out"].println(first_half + second_half) ; if (l mod 2 = 0) then OclFile["System.out"].println(l) else OclFile["System.out"].println(l - 1) ; ; return -2147483648 ); static operation reverse( input : String) : String pre: true post: true activity: ( var temparray : Sequence(String) ; temparray := input->characters() ; var left : int ; var right : int ; right := 0 ; right := temparray->size() - 1 ; left := 0 ; while left < right do ( ( var temp : String ; temp := temparray[left+1] ; temparray[left+1] := temparray[right+1] ; temparray[right+1] := temp ) ; left := left + 1 ; right := right - 1 ) ; return (temparray)->sum() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : String ; n := "abba" ; execute lenDoubleString(n) ; n := "abcdedcba" ; execute lenDoubleString(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int t=sc.nextInt(); int n=sc.nextInt(); if(t==0 && n==0)break ; boolean[][] map=new boolean[150][150]; boolean[][] visit=new boolean[150][150]; int p,q,r ; for(int i=0 ; ix=new LinkedList(); LinkedListy=new LinkedList(); int[] a=new int[] { 1,1,0,-1,-1,0 }; int[] b=new int[] { 1,0,1,-1,0,-1 }; x.offer(p); y.offer(q); visit[q][p]=true ; for(int i=0 ; itoInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; if (t = 0 & n = 0) then break else skip ; var map : Sequence(Sequence(boolean)) ; map := Integer.subrange(1,150)->collect(Integer.subrange(1,150)->collect(false)) ; var visit : Sequence(Sequence(boolean)) ; visit := Integer.subrange(1,150)->collect(Integer.subrange(1,150)->collect(false)) ; var p : int ; var q : int ; var r : int ; var i : int ; i := 0 ; while i < n do ( ( p := sc.getCurrent()->toInteger() + 75 ; q := sc.getCurrent()->toInteger() + 75 ; map[q+1][p+1] := true ) ; i := i + 1 ) ; p := sc.getCurrent()->toInteger() + 75 ; q := sc.getCurrent()->toInteger() + 75 ; var cnt : int ; cnt := 1 ; var x : Sequence(int) ; x := Sequence{} ; var y : Sequence(int) ; y := Sequence{} ; var a : Sequence(int) ; a := Sequence{1,1,0,-1,-1,0} ; var b : Sequence(int) ; b := Sequence{1,0,1,-1,0,-1} ; x := x->including(p) ; y := y->including(q) ; visit[q+1][p+1] := true ; var i : int ; i := 0 ; while i < t do ( ( r := x->size() ; var j : int ; j := 0 ; while j < r do ( ( p := x->min() ; x := x->sort()->tail() ; q := y->min() ; y := y->sort()->tail() ; var k : int ; k := 0 ; while k < 6 do ( ( if (visit[q + b[k+1]+1][p + a[k+1]+1] = false & map[q + b[k+1]+1][p + a[k+1]+1] = false) then ( visit[q + b[k+1]+1][p + a[k+1]+1] := true ; x := x->including(p + a[k+1]) ; y := y->including(q + b[k+1]) ; cnt := cnt + 1 ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.util.ArrayList ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); static int[] DX={ 1,1,0,-1,-1,0 }; static int[] DY={ 1,0,-1,-1,0,1 }; public static void main(String[] arg){ while(true){ int T=sc.nextInt(); if(T==0)break ; int N=sc.nextInt(); boolean[][] visited=new boolean[201][201]; for(int i=0 ; ips=new ArrayList(); int sx=sc.nextInt()+100 ; int sy=sc.nextInt()+100 ; visited[sx][sy]=true ; ps.add(new Point(sx,sy)); int ans=1 ; for(int i=0 ; inext=new ArrayList(); for(Point p : ps){ for(int j=0 ; j<6 ; ++j){ int nx=p.x+DX[j]; int ny=p.y+DY[j]; if(! visited[nx][ny]){ visited[nx][ny]=true ; next.add(new Point(nx,ny)); } } } ans+=next.size(); ps=next ; } System.out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute DX : Sequence(int) := Sequence{1,1,0,-1,-1,0}; static attribute DY : Sequence(int) := Sequence{1,0,-1,-1,0,1}; static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( while (true) do ( var T : int ; T := sc.getCurrent()->toInteger() ; if (T = 0) then break else skip ; var N : int ; N := sc.getCurrent()->toInteger() ; var visited : Sequence(Sequence(boolean)) ; visited := Integer.subrange(1,201)->collect(Integer.subrange(1,201)->collect(false)) ; var i : int ; i := 0 ; while i < N do ( ( var x : int ; x := sc.getCurrent()->toInteger() + 100 ; var y : int ; y := sc.getCurrent()->toInteger() + 100 ; visited[x+1][y+1] := true ) ; i := i + 1 ) ; var ps : Sequence(Point) ; ps := Sequence{} ; var sx : int ; sx := sc.getCurrent()->toInteger() + 100 ; var sy : int ; sy := sc.getCurrent()->toInteger() + 100 ; visited[sx+1][sy+1] := true ; ps := ps->including(Point.newPoint(sx, sy)) ; var ans : int ; ans := 1 ; var i : int ; i := 0 ; while i < T do ( ( var next : Sequence(Point) ; next := Sequence{} ; for (p : ps) do ( ( var j : int ; j := 0 ; while j < 6 do ( ( var nx : int ; nx := p.x + DX[j+1] ; var ny : int ; ny := p.y + DY[j+1] ; if (not(visited[nx+1][ny+1])) then ( visited[nx+1][ny+1] := true ; next := next->including(Point.newPoint(nx, ny)) ) else skip ) ; j := j + 1 ) ) ) ; ans := ans+(next->size()) ; ps := next ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner in ; static PrintWriter out ; static String INPUT="" ; public static void main(String[] args)throws Exception { in=INPUT.isEmpty()? new Scanner(System.in): new Scanner(INPUT); out=new PrintWriter(System.out); int N=ni(); int M=ni(); int ab[][]=new int[N][3]; int cd[][]=new int[M][2]; int i,j ; for(i=0 ; i=0 ; j--){ int distance=Math.abs(ab[i][0]-cd[j][0])+Math.abs(ab[i][1]-cd[j][1]); if(min>=distance){ min=distance ; ab[i][2]=j+1 ; } } } for(i=0 ; iisEmpty() then OclFile.newOclFile_Read(OclFile["System.in"]) else OclFile.newOclFile_Read(OclFile.newOclFile(INPUT)) endif ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var N : int ; N := ni() ; var M : int ; M := ni() ; var ab : Sequence(Sequence(int)) ; ab := Integer.subrange(1,N)->collect(Integer.subrange(1,3)->collect(0)) ; var cd : Sequence(Sequence(int)) ; cd := Integer.subrange(1,M)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; var j : int ; i := 0 ; while i < N do ( ( ab[i+1][0+1] := ni() ; ab[i+1][1+1] := ni() ; ab[i+1][2+1] := -1 ) ; i := i + 1 ) ; i := 0 ; while i < M do ( ( cd[i+1][0+1] := ni() ; cd[i+1][1+1] := ni() ) ; i := i + 1 ) ; i := 0 ; while i < N do ( ( var min : int ; min := 400000000 ; j := M - 1 ; while j >= 0 do ( ( var distance : int ; distance := if ab[i+1][0+1] - cd[j+1][0+1] < 0 then -(ab[i+1][0+1] - cd[j+1][0+1]) else ab[i+1][0+1] - cd[j+1][0+1] endif + if ab[i+1][1+1] - cd[j+1][1+1] < 0 then -(ab[i+1][1+1] - cd[j+1][1+1]) else ab[i+1][1+1] - cd[j+1][1+1] endif ; if (min >= distance) then ( min := distance ; ab[i+1][2+1] := j + 1 ) else skip ) ; j := j - 1 ) ) ; i := i + 1 ) ; i := 0 ; while i < N do ( skip ; ; i := i + 1 ) ; skip ; ); static operation ni() : int pre: true post: true activity: ( return (in.getCurrent())->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[][] move={ { 0,1 },{ 1,1 },{ -1,0 },{ 1,0 },{ -1,-1 },{ 0,-1 } }; while(true){ int t=sc.nextInt(); int n=sc.nextInt(); if(t==0 && n==0)break ; boolean[][] map=new boolean[200][200]; while(n--!=0){ int x=sc.nextInt()+100 ; int y=sc.nextInt()+100 ; map[x][y]=true ; } int x=sc.nextInt()+100 ; int y=sc.nextInt()+100 ; map[x][y]=true ; int c=1 ; Listlist=new ArrayList(); list.add(new int[] { x,y } ); while(t--!=0){ Listnext=new ArrayList(); for(int[] a : list){ for(int k=0 ; k<6 ; k++){ int nx=a[0]+move[k][0]; int ny=a[1]+move[k][1]; if(! map[nx][ny]){ map[nx][ny]=true ; c++; next.add(new int[] { nx,ny } ); } } } list=next ; } System.out.println(c); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var move : Sequence(Sequence(int)) ; move := Sequence{Sequence{0,1},Sequence{1,1},Sequence{-1,0},Sequence{1,0},Sequence{-1,-1},Sequence{0,-1}} ; while (true) do ( var t : int ; t := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; if (t = 0 & n = 0) then break else skip ; var map : Sequence(Sequence(boolean)) ; map := Integer.subrange(1,200)->collect(Integer.subrange(1,200)->collect(false)) ; while (n /= 0) do ( skip ; ( var x : int ; x := sc.getCurrent()->toInteger() + 100 ; var y : int ; y := sc.getCurrent()->toInteger() + 100 ; map[x+1][y+1] := true ) ; ) ; var x : int ; x := sc.getCurrent()->toInteger() + 100 ; var y : int ; y := sc.getCurrent()->toInteger() + 100 ; map[x+1][y+1] := true ; var c : int ; c := 1 ; var list : Sequence(Sequence(int)) ; list := Sequence{} ; list := list->including(Sequence{x,y}) ; while (t /= 0) do ( skip ; ( var next : Sequence(Sequence(int)) ; next := Sequence{} ; for (a : list) do ( ( var k : int ; k := 0 ; while k < 6 do ( ( var nx : int ; nx := a[0+1] + move[k+1][0+1] ; var ny : int ; ny := a[1+1] + move[k+1][1+1] ; if (not(map[nx+1][ny+1])) then ( map[nx+1][ny+1] := true ; c := c + 1 ; next := next->including(Sequence{nx,ny}) ) else skip ) ; k := k + 1 ) ) ) ; list := next ) ; ) ; OclFile["System.out"].println(c) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.Arrays ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] tmpArray=br.readLine().split(" "); int n=Integer.parseInt(tmpArray[0]); double totalW=Integer.parseInt(tmpArray[1]); Item[] items=new Item[n]; for(int i=0 ; i0 ; i++){ double w1=Math.min(items[i] .weight,totalW); result+=w1*items[i] .valuePerWeight ; totalW-=w1 ; } System.out.printf("%.8f\n",result); } } class Item implements Comparable{ int value ; int weight ; double valuePerWeight ; Item(int v,int w){ value=v ; weight=w ; valuePerWeight=(double)value/weight ; } @ Override public int compareTo(Item item1){ if(this.valuePerWeightitem1.valuePerWeight){ return-1 ; } else { return 0 ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var tmpArray : Sequence(String) ; tmpArray := br.readLine()->split(" ") ; var n : int ; n := (tmpArray[0+1])->toInteger() ; var totalW : double ; totalW := (tmpArray[1+1])->toInteger() ; var items : Sequence(Item) ; items := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( tmpArray := br.readLine()->split(" ") ; var value : int ; value := (tmpArray[0+1])->toInteger() ; var weight : int ; weight := (tmpArray[1+1])->toInteger() ; items[i+1] := Item.newItem(value, weight) ) ; i := i + 1 ) ; items := items->sort() ; var result : double ; result := 0 ; var i : int ; i := 0 ; while i < n & totalW > 0 do ( ( var w1 : double ; w1 := Set{items[i+1].weight, totalW}->min() ; result := result+(w1 * items[i+1].valuePerWeight) ; totalW := totalW-(w1) ) ; i := i + 1 ) ; OclFile["System.out"].printf("%.8f\n", result) ; ); } class Item implements Comparable { attribute value : int; attribute weight : int; attribute valuePerWeight : double; static operation newItem( v : int, w : int) : Item pre: true post: true activity: ( var self : Item ; self := createItem(); self.initialise(v, w); return self ); operation initialise( v : int, w : int) : void pre: true post: true activity: ( value := v ; weight := w ; valuePerWeight := value->oclAsType(double) / weight ); operation compareTo( item1 : Item) : int pre: true post: true activity: ( if (self.valuePerWeight < item1.valuePerWeight) then ( return 1 ) else if (self.valuePerWeight > item1.valuePerWeight) then ( return -1 ) else ( return 0 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedList ; import java.util.Queue ; import java.util.Scanner ; public class Main { public static final int[] dx={ 0,1,1,0,-1,-1 }; public static final int[] dy={ 1,1,0,-1,-1,0 }; public static void main(String[] args){ Scanner in=new Scanner(System.in); while(true){ int t=in.nextInt(); int n=in.nextInt(); if(t==0 && n==0)break ; boolean[][] block=new boolean[200][200]; for(int i=0 ; iqu=new LinkedList(); qu.add(new Pos(sy,sx,0)); int count=0 ; while(! qu.isEmpty()){ Pos p=qu.poll(); if(used[p.y][p.x])continue ; if(p.turn>t)continue ; used[p.y][p.x]=true ; count++; for(int i=0 ; i<6 ; i++){ int ny=p.y+dy[i]; int nx=p.x+dx[i]; if(block[ny][nx])continue ; qu.add(new Pos(ny,nx,p.turn+1)); } } System.out.println(count); } } } class Pos { int x,y ; int turn ; public Pos(int y,int x,int turn){ this.y=y ; this.x=x ; this.turn=turn ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute dx : Sequence(int) := Sequence{0,1,1,0,-1,-1}; static attribute dy : Sequence(int) := Sequence{1,1,0,-1,-1,0}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var t : int ; t := in.getCurrent()->toInteger() ; var n : int ; n := in.getCurrent()->toInteger() ; if (t = 0 & n = 0) then break else skip ; var block : Sequence(Sequence(boolean)) ; block := Integer.subrange(1,200)->collect(Integer.subrange(1,200)->collect(false)) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := in.getCurrent()->toInteger() + 100 ; var y : int ; y := in.getCurrent()->toInteger() + 100 ; block[y+1][x+1] := true ) ; i := i + 1 ) ; var sx : int ; sx := in.getCurrent()->toInteger() + 100 ; var sy : int ; sy := in.getCurrent()->toInteger() + 100 ; var used : Sequence(Sequence(boolean)) ; used := Integer.subrange(1,200)->collect(Integer.subrange(1,200)->collect(false)) ; var qu : Sequence(Pos) ; qu := Sequence{} ; qu := qu->including(Pos.newPos(sy, sx, 0)) ; var count : int ; count := 0 ; while (not(qu->isEmpty())) do ( var p : Pos ; p := qu->min() ; if (used[p.y+1][p.x+1]) then continue else skip ; if (p.turn > t) then continue else skip ; used[p.y+1][p.x+1] := true ; count := count + 1 ; var i : int ; i := 0 ; while i < 6 do ( ( var ny : int ; ny := p.y + dy[i+1] ; var nx : int ; nx := p.x + dx[i+1] ; if (block[ny+1][nx+1]) then continue else skip ; qu := qu->including(Pos.newPos(ny, nx, p.turn + 1)) ) ; i := i + 1 ) ; ) ; OclFile["System.out"].println(count) ; ) ); } class Pos { attribute x : int; attribute turn : int; static operation newPos( y : int, x : int, turn : int) : Pos pre: true post: true activity: ( var self : Pos ; self := createPos(); self.initialise(y, x,turn); return self ); operation initialise( y : int, x : int, turn : int) : void pre: true post: true activity: ( self.y := y ; self.x := x ; self.turn := turn ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int gcd(int a,int b){ if(a==0 || b==0)return 0 ; if(a==b)return a ; if(a>b)return gcd(a-b,b); return gcd(a,b-a); } static void printResult(int arr[],int n){ int count=0 ; for(int i=1 ; i b) then return gcd(a - b, b) else skip ; return gcd(a, b - a) ); static operation printResult( arr : Sequence(int), n : int) : void pre: true post: true activity: ( var count : int ; count := 0 ; var i : int ; i := 1 ; while i < n do ( if (gcd(arr[i+1], arr[i - 1+1]) /= 1) then count := count + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(count) ; OclFile["System.out"].print(arr[0+1] + " ") ; var i : int ; i := 1 ; while i < n do ( ( if (gcd(arr[i+1], arr[i - 1+1]) /= 1) then OclFile["System.out"].print(1 + " ") ; else skip ; OclFile["System.out"].print(arr[i+1] + " ") ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : Sequence(int) ; A := Sequence{5,10,20} ; var n : int ; n := A->size() ; execute printResult(A, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { static int findOnBulbs(int numberOfBulbs){ int onBulbs=0 ; int bulb=1 ; int person=1 ; for(bulb=1 ; bulb<=numberOfBulbs ; bulb++){ int factors=0 ; for(person=1 ; person*person<=numberOfBulbs ; person++){ if(bulb % person==0){ factors++; if(bulb/person!=person){ factors++; } } } if(factors % 2==1){ System.out.println("Light bulb "+bulb+" will be on"); onBulbs++; } } return onBulbs ; } public static void main(String[] args){ int numberOfBulbs=1000 ; int onBulbs=findOnBulbs(numberOfBulbs); System.out.println("Total "+onBulbs+" light bulbs will be on in the end out of "+numberOfBulbs+" light bulbs"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findOnBulbs( numberOfBulbs : int) : int pre: true post: true activity: ( var onBulbs : int ; onBulbs := 0 ; var bulb : int ; bulb := 1 ; var person : int ; person := 1 ; bulb := 1 ; while bulb <= numberOfBulbs do ( ( var factors : int ; factors := 0 ; person := 1 ; while person * person <= numberOfBulbs do ( ( if (bulb mod person = 0) then ( factors := factors + 1 ; if (bulb / person /= person) then ( factors := factors + 1 ) else skip ) else skip ) ; person := person + 1 ) ; if (factors mod 2 = 1) then ( OclFile["System.out"].println("Light bulb " + bulb + " will be on") ; onBulbs := onBulbs + 1 ) else skip ) ; bulb := bulb + 1 ) ; return onBulbs ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var numberOfBulbs : int ; numberOfBulbs := 1000 ; var onBulbs : int ; onBulbs := findOnBulbs(numberOfBulbs) ; OclFile["System.out"].println("Total " + onBulbs + " light bulbs will be on in the end out of " + numberOfBulbs + " light bulbs") ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countOdd(int L,int R){ int N=(R-L)/2 ; if(R % 2!=0 || L % 2!=0)N++; return N ; } public static void main(String[] args){ int L=3,R=7 ; int odds=countOdd(L,R); int evens=(R-L+1)-odds ; System.out.println("Count of odd numbers is "+odds); System.out.println("Count of even numbers is "+evens); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countOdd( L : int, R : int) : int pre: true post: true activity: ( var N : int ; N := (R - L) / 2 ; if (R mod 2 /= 0 or L mod 2 /= 0) then N := N + 1 ; else skip ; return N ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 3 ; var R : int ; R := 7 ; var odds : int ; odds := countOdd(L, R) ; var evens : int ; evens := (R - L + 1) - odds ; OclFile["System.out"].println("Count of odd numbers is " + odds) ; OclFile["System.out"].println("Count of even numbers is " + evens) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static int maxAND(int L,int R){ if(L==R)return L ; else if((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)); } } public static void main(String[] args){ int L=1,R=632 ; System.out.println(maxAND(L,R)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation maxAND( L : int, R : int) : int pre: true post: true activity: ( if (L = R) then return L else if ((R - L) = 1) then return (R & L) else ( if (((R - 1) & R) > ((R - 2) & (R - 1))) then return ((R - 1) & R) else return ((R - 2) & (R - 1)) ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var L : int ; L := 1 ; var R : int ; R := 632 ; OclFile["System.out"].println(maxAND(L, R)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0)break ; int h=5*n+10 ; int[][] map=new int[h][5]; int d,p,q,max,cnt ; for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; var h : int ; h := 5 * n + 10 ; var map : Sequence(Sequence(int)) ; map := Integer.subrange(1,h)->collect(Integer.subrange(1,5)->collect(0)) ; var d : int ; var p : int ; var q : int ; var max : int ; var cnt : int ; var i : int ; i := 0 ; while i < n do ( ( d := sc.getCurrent()->toInteger() ; p := sc.getCurrent()->toInteger() ; q := sc.getCurrent()->toInteger() - 1 ; if (d = 1) then ( max := -1 ; var j : int ; j := q ; while j < q + p do ( ( cnt := h - 1 ; while (map[cnt+1][j+1] = 0) do ( cnt := cnt - 1 ; if (cnt = -1) then break else skip ) ; max := Set{max, cnt}->max() ) ; j := j + 1 ) ; var j : int ; j := q ; while j < q + p do ( map[max + 1+1][j+1] := 1 ; ; j := j + 1 ) ) else ( cnt := h - 1 ; while (map[cnt+1][q+1] = 0) do ( cnt := cnt - 1 ; if (cnt = -1) then break else skip ) ; var j : int ; j := cnt + 1 ; while j < cnt + 1 + p do ( map[j+1][q+1] := 1 ; ; j := j + 1 ) ) ; cnt := 0 ; var j : int ; j := 0 ; while j < h do ( ( if (map[j+1][0+1] = 1 & map[j+1][1+1] = 1 & map[j+1][2+1] = 1 & map[j+1][3+1] = 1 & map[j+1][4+1] = 1) then continue else skip ; map[cnt+1] := map[j+1] ; cnt := cnt + 1 ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < 5 do ( ( sum := sum+(map[i+1][j+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GfG { static boolean prime[]=new boolean[1000000+5]; static void findPrime(){ Arrays.fill(prime,true); prime[1]=false ; for(int p=2 ; p*p<=1000000 ; p++){ if(prime[p]==true){ for(int i=p*2 ; i<=1000000 ; i+=p)prime[i]=false ; } } } static int lenOfLongSubarr(int arr[],int n){ Mapum=new HashMap(); int sum=0,maxLen=0 ; for(int i=0 ; icollect(false); static operation findPrime() : void pre: true post: true activity: ( prime := prime->collect(true) ; prime[1+1] := false ; var p : int ; p := 2 ; while p * p <= 1000000 do ( ( if (prime[p+1] = true) then ( var i : int ; i := p * 2 ; while i <= 1000000 do ( prime[i+1] := false ; ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ); static operation lenOfLongSubarr( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var um : Map(int,int) ; um := Map{} ; var sum : int ; sum := 0 ; var maxLen : int ; maxLen := 0 ; var i : int ; i := 0 ; while i < n do ( ( sum := sum+(if prime[arr[i+1]+1] = false then -1 else 1 endif) ; if (sum = 1) then maxLen := i + 1 else if (not(um->keys()->includes(sum))) then um := um->union(Map{sum |-> i}) ; else skip ; ; if (um->keys()->includes(sum - 1)) then ( if (maxLen < (i - um->at(sum - 1))) then maxLen := i - um->at(sum - 1) ; else skip ) else skip ) ; i := i + 1 ) ; return maxLen ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute findPrime() ; var arr : Sequence(int) ; arr := Sequence{1,9,3,4,5,6,7,8} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(lenOfLongSubarr(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Division { public static void main(String[] argf){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int x=sc.nextInt(); if(x<=1399){ System.out.println("Division 4"); } if(x>=1400 && x<=1599){ System.out.println("Division 3"); } if(x>=1600 && x<=1899){ System.out.println("Division 2"); } if(x>=1900){ System.out.println("Division 1"); } } } } ------------------------------------------------------------ OCL File: --------- class Division { static operation main( argf : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x <= 1399) then ( OclFile["System.out"].println("Division 4") ) else skip ; if (x >= 1400 & x <= 1599) then ( OclFile["System.out"].println("Division 3") ) else skip ; if (x >= 1600 & x <= 1899) then ( OclFile["System.out"].println("Division 2") ) else skip ; if (x >= 1900) then ( OclFile["System.out"].println("Division 1") ) else skip ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.util.Arrays ; import java.util.Comparator ; import java.util.Scanner ; public class Main { static final Scanner s=new Scanner(System.in); public static void main(String[] __){ int n=s.nextInt(),m=s.nextInt(); Point[] students=new Point[n]; CheckPoint[] cps=new CheckPoint[m]; for(int i=0 ; iMath.abs(o.x-st.x)+Math.abs(o.y-st.y))).get().id); } } class CheckPoint extends Point { int id ; CheckPoint(int id,int x,int y){ super(x,y); this.id=id ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute s : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( __ : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := s.getCurrent()->toInteger() ; var m : int ; m := s.getCurrent()->toInteger() ; var students : Sequence(Point) ; students := Integer.subrange(1,n)->collect(null) ; var cps : Sequence(CheckPoint) ; cps := Integer.subrange(1,m)->collect(null) ; var i : int ; i := 0 ; while i < n do ( students[i+1] := Point.newPoint(s.getCurrent()->toInteger(), s.getCurrent()->toInteger()) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( cps[i+1] := CheckPoint.newCheckPoint(i + 1, s.getCurrent()->toInteger(), s.getCurrent()->toInteger()) ; ; i := i + 1 ) ; for (st : students) do ( OclFile["System.out"].println(stream(cps)->min().get().id) ; ) ; ); } class CheckPoint extends Point { attribute id : int; static operation newCheckPoint( id : int, x : int, y : int) : CheckPoint pre: true post: true activity: ( var self : CheckPoint ; self := createCheckPoint(); self.initialise(id, x,y); return self ); operation initialise( id : int, x : int, y : int) : void pre: true post: true activity: ( execute super(x, y) ; self.id := id ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static final int nbits=32 ; static BitSet bs ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); long a=sc.nextLong(); long b=sc.nextLong(); BitSet bsa=new BitSet(nbits); BitSet bsb=new BitSet(nbits); for(int i=0 ; i=0 ; i--){ if(b.get(i))System.out.print(1); else System.out.print(0); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute nbits : int := 32; static attribute bs : Sequence(boolean); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; var bsa : Sequence(boolean) ; bsa := MathLib.toBitSequence(nbits) ; var bsb : Sequence(boolean) ; bsb := MathLib.toBitSequence(nbits) ; var i : int ; i := 0 ; while i < nbits do ( ( if ((MathLib.bitwiseAnd(a,((1*(2->pow(i)))->oclAsType(long)))) /= 0) then bsa := bsa.setAt(i+1, true) ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < nbits do ( ( if ((MathLib.bitwiseAnd(b,((1*(2->pow(i)))->oclAsType(long)))) /= 0) then bsb := bsb.setAt(i+1, true) ; else skip ) ; i := i + 1 ) ; execute makeBitSet(bsa) ; bs := bs.and(bsb) ; execute printBitSet(bs) ; OclFile["System.out"].print("\n") ; execute makeBitSet(bsa) ; bs := bs.or(bsb) ; execute printBitSet(bs) ; OclFile["System.out"].print("\n") ; execute makeBitSet(bsa) ; bs := bs.xor(bsb) ; execute printBitSet(bs) ; OclFile["System.out"].print("\n") ; ); static operation makeBitSet( b : Sequence(boolean)) : void pre: true post: true activity: ( bs := MathLib.toBitSequence(nbits) ; var i : int ; i := 0 ; while i < nbits do ( ( if (b->at(i+1)) then bs := bs.setAt(i+1, true) ; else skip ) ; i := i + 1 ) ); static operation printBitSet( b : Sequence(boolean)) : void pre: true post: true activity: ( var i : int ; i := nbits - 1 ; while i >= 0 do ( ( if (b->at(i+1)) then OclFile["System.out"].print(1) ; else OclFile["System.out"].print(0) ; ) ; i := i - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int getSingle(int arr[],int n){ int ones=0,twos=0 ; int common_bit_mask ; for(int i=0 ; isize() ; OclFile["System.out"].println("The element with single occurrence is " + getSingle(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.Math.max ; import static java.lang.Math.min ; import static java.lang.Math.abs ; import static java.lang.System.out ; import java.util.*; import java.io.*; import java.math.*; public class Demo4 { public static void main(String[] args){ try { FastReader in=new FastReader(); int testCases=in.nextInt(); while(testCases-->0){ int n=in.nextInt(); if(n<=1399){ System.out.println("Division 4"); } else if(n<=1599){ System.out.println("Division 3"); } else if(n<=1899){ System.out.println("Division 2"); } else if(n>=1900){ System.out.println("Division 1"); } } } catch(Exception e){ e.printStackTrace(); } } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); ; } String next(){ while(st==null || ! st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine().trim(); } catch(Exception e){ e.printStackTrace(); } return str ; } } } ------------------------------------------------------------ OCL File: --------- class Demo4 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : FastReader ; in := FastReader.newFastReader() ; var testCases : int ; testCases := in.nextInt() ; while (testCases > 0) do ( testCases := testCases - 1 ; skip ; ( var n : int ; n := in.nextInt() ; if (n <= 1399) then ( OclFile["System.out"].println("Division 4") ) else if (n <= 1599) then ( OclFile["System.out"].println("Division 3") ) else if (n <= 1899) then ( OclFile["System.out"].println("Division 2") ) else if (n >= 1900) then ( OclFile["System.out"].println("Division 1") ) else skip ; ; ; ) ; ) ) catch (e : ProgramException) do ( e.printStackTrace() ) ); static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine()->trim() ) catch (e : ProgramException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ int n,m ; Scanner sc=new Scanner(System.in); n=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; i<=(n-1); i++){ m=sc.nextInt(); arr[i]=m ; } for(int j=0 ; j<=(n-1); j++){ if(arr[j]<=1399)System.out.println("Division 4"); else if(arr[j]>=1400 && arr[j]<=1599)System.out.println("Division 3"); else if(arr[j]>=1600 && arr[j]<=1899)System.out.println("Division 2"); else System.out.println("Division 1"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; var m : int ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i <= (n - 1) do ( ( m := sc.getCurrent()->toInteger() ; arr[i+1] := m ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j <= (n - 1) do ( ( if (arr[j+1] <= 1399) then OclFile["System.out"].println("Division 4") ; else if (arr[j+1] >= 1400 & arr[j+1] <= 1599) then OclFile["System.out"].println("Division 3") else if (arr[j+1] >= 1600 & arr[j+1] <= 1899) then OclFile["System.out"].println("Division 2") else OclFile["System.out"].println("Division 1") ; ; ; ) ; j := j + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Arrays ; import java.util.Vector ; import java.lang.Math ; public class virtual { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); if(n>=1900){ System.out.println("Division 1"); } else if(n>=1600){ System.out.println("Division 2"); } else if(n>=1400){ System.out.println("Division 3"); } else { System.out.println("Division 4"); } } } } ------------------------------------------------------------ OCL File: --------- class virtual { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n >= 1900) then ( OclFile["System.out"].println("Division 1") ) else if (n >= 1600) then ( OclFile["System.out"].println("Division 2") ) else if (n >= 1400) then ( OclFile["System.out"].println("Division 3") ) else ( OclFile["System.out"].println("Division 4") ) ; ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class C { public static void main(String[] args){ Scanner input=new Scanner(System.in); int times=input.nextInt(); boolean m=true ; while(m){ int test=input.nextInt(); if(test>=1900)System.out.println("Division 1"); else if(test<=1899 && test>=1600)System.out.println("Division 2"); else if(test<=1599 && test>=1400)System.out.println("Division 3"); else System.out.println("Division 4"); times--; if(times==0)m=false ; } } } ------------------------------------------------------------ OCL File: --------- class C { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var times : int ; times := input.getCurrent()->toInteger() ; var m : boolean ; m := true ; while (m) do ( var test : int ; test := input.getCurrent()->toInteger() ; if (test >= 1900) then OclFile["System.out"].println("Division 1") else if (test <= 1899 & test >= 1600) then OclFile["System.out"].println("Division 2") else if (test <= 1599 & test >= 1400) then OclFile["System.out"].println("Division 3") else OclFile["System.out"].println("Division 4") ; ; ; ; times := times - 1 ; if (times = 0) then m := false ; else skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); long a[]=new long[n]; long b[]=new long[n]; for(int i=0 ; i=0 ; i--){ a[i]+=ans ; long c=((a[i]+b[i]-1)/b[i])*b[i]-a[i]; ans+=c ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := in.getCurrent()->toLong() ; b[i+1] := in.getCurrent()->toLong() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( a[i+1] := a[i+1]+(ans) ; var c : long ; c := ((a[i+1] + b[i+1] - 1) / b[i+1]) * b[i+1] - a[i+1] ; ans := ans+(c) ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static final int MOD=(int)Math.pow(10,9)+7 ; static final boolean TEST=false ; static void debug(Object...os){ if(TEST){ StringBuilder sb=new StringBuilder(os.length); for(Object o : os)sb.append(o); System.out.println(sb); } } public static void main(String[] args){ try(Scanner in=new Scanner(System.in)){ do { solve(in); } while(TEST); } } private static void solve(Scanner in){ int N=in.nextInt(); long[] A=new long[N],B=new long[N]; for(int i=0 ; i-1 ; i--){ A[i]+=accum ; long delta=0 ; if(A[i]==0){ delta=0 ; } else if(A[i]pow(9)->oclAsType(int) + 7; static attribute TEST : boolean := false; static operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( if (TEST) then ( var sb : String ; sb := StringLib.newString(os->size()) ; for (o : os) do ( sb := sb + StringLib.newString(o) ; ) ; OclFile["System.out"].println(sb) ) else skip ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( while true do (( execute solve(in) ) ; if (TEST) then skip else break) )) ); static operation solve( in : OclFile) : void pre: true post: true activity: ( var N : int ; N := in.getCurrent()->toInteger() ; var A : Sequence(long) ; A := Integer.subrange(1,N)->collect(0) ; var B : Sequence(long) ; B := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := in.getCurrent()->toInteger() ; B[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var accum : long ; accum := 0 ; var i : int ; i := (N)->char2byte() - 1 ; while i > -1 do ( ( A[i+1] := A[i+1]+(accum) ; var delta : long ; delta := 0 ; if (A[i+1] = 0) then ( delta := 0 ) else if (A[i+1] < B[i+1]) then ( delta := B[i+1] - A[i+1] ) else if (A[i+1] mod B[i+1] /= 0) then ( delta := B[i+1] - (A[i+1] mod B[i+1]) ) else skip ; ; ; A[i+1] := A[i+1]+(delta) ; accum := accum+(delta) ; ans := ans+(delta) ; ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.ArrayList ; public class Main { public static void main(String[] args){ try { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); long n=Integer.parseInt(br.readLine()); ArrayLista=new ArrayList(); ArrayListb=new ArrayList(); for(int i=0 ; i0 ; i--){ Long atmp=a.get((int)(i-1)); atmp=atmp+count ; Long btmp=b.get((int)(i-1)); long tmp=(atmp)% btmp ; if(tmp!=0){ count=count+(btmp-tmp); } } System.out.println(count); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var isr : OclFile ; isr := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(isr) ; var n : long ; n := (br.readLine())->toInteger() ; var a : Sequence(long) ; a := Sequence{} ; var b : Sequence(long) ; b := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( var tmp : Sequence(String) ; tmp := br.readLine()->split(" ") ; a := a->including((tmp[0+1])->toLong()) ; b := b->including((tmp[1+1])->toLong()) ) ; i := i + 1 ) ; var count : long ; count := 0 ; var i : long ; i := n ; while i > 0 do ( ( var atmp : long ; atmp := a->at((i - 1)->oclAsType(int)+1) ; atmp := atmp + count ; var btmp : long ; btmp := b->at((i - 1)->oclAsType(int)+1) ; var tmp : long ; tmp := (atmp) mod btmp ; if (tmp /= 0) then ( count := count + (btmp - (tmp)->char2byte()) ) else skip ; ) ; i := i - 1 ) ; OclFile["System.out"].println(count) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.io.UncheckedIOException ; import java.util.StringTokenizer ; class Main { public static void main(String[] args){ SC sc=new SC(System.in); int N=sc.nextInt(); int[][] sw=new int[N][2]; long cnt=0 ; for(int i=0 ; i=0 ; i--){ if((cnt+sw[i][0])% sw[i][1]==0){ } else { cnt+=sw[i][1]-(cnt+sw[i][0])% sw[i][1]; } } System.out.println(cnt); } static class SC { InputStream inp=System.in ; private BufferedReader reader=null ; private StringTokenizer tokenizer=null ; public SC(InputStream inp){ reader=new BufferedReader(new InputStreamReader(inp)); } public String next(){ if(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new UncheckedIOException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : SC ; sc := SC.newSC(OclFile["System.in"]) ; var N : int ; N := sc.nextInt() ; var sw : Sequence(Sequence(int)) ; sw := Integer.subrange(1,N)->collect(Integer.subrange(1,2)->collect(0)) ; var cnt : long ; cnt := 0 ; var i : int ; i := 0 ; while i < N do ( ( sw[i+1][0+1] := sc.nextInt() ; sw[i+1][1+1] := sc.nextInt() ) ; i := i + 1 ) ; var i : int ; i := N - 1 ; while i >= 0 do ( ( if ((cnt + sw[i+1][0+1]) mod sw[i+1][1+1] = 0) then skip else ( cnt := cnt+(sw[i+1][1+1] - (cnt + sw[i+1][0+1]) mod sw[i+1][1+1]) ) ) ; i := i - 1 ) ; OclFile["System.out"].println(cnt) ; ); static class SC { attribute inp : OclFile := OclFile["System.in"]; attribute reader : OclFile := null; attribute tokenizer : OclIterator := null; static operation newSC( inp : OclFile) : SC pre: true post: true activity: ( var self : SC ; self := createSC(); self.initialise(inp); return self ); operation initialise( inp : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(inp)) ); operation next() : String pre: true post: true activity: ( if (tokenizer = null or not(tokenizer.hasNext())) then ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error UncheckedIOException.newUncheckedIOException(e) ) ) else skip ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] sa=br.readLine().split(" "); int n=Integer.parseInt(sa[0]); int[] a=new int[n]; int[] b=new int[n]; for(int i=0 ; i=0 ; i--){ long c=(a[i]+ans)% b[i]; if(c>0){ ans+=b[i]-c ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sa : Sequence(String) ; sa := br.readLine()->split(" ") ; var n : int ; n := (sa[0+1])->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( sa := br.readLine()->split(" ") ; a[i+1] := (sa[0+1])->toInteger() ; b[i+1] := (sa[1+1])->toInteger() ) ; i := i + 1 ) ; skip ; var ans : long ; ans := 0 ; var i : int ; i := n - 1 ; while i >= 0 do ( ( var c : long ; c := (a[i+1] + ans) mod b[i+1] ; if (c > 0) then ( ans := ans+(b[i+1] - c) ) else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int MAX_CHAR=26 ; static String removeChars(char arr[],int k){ int[] hash=new int[MAX_CHAR]; int n=arr.length ; for(int i=0 ; icollect(0) ; var n : int ; n := arr->size() ; var i : int ; i := 0 ; while i < n do ( hash[arr[i+1] - ('a')->char2byte()+1] := hash[arr[i+1] - ('a')->char2byte()+1] + 1 ; ; i := i + 1 ) ; var ans : String ; ans := "" ; var i : int ; i := 0 ; while i < n do ( ( if (hash[arr[i+1] - ('a')->char2byte()+1] /= k) then ( ans := ans+(arr[i+1]) ) else skip ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : Sequence(String) ; str := "geeksforgeeks"->characters() ; var k : int ; k := 2 ; OclFile["System.out"].print(removeChars(str, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); int m=Integer.parseInt(sc.next()); Integer[] a=new Integer[n]; Integer[] b=new Integer[n]; for(int i=0 ; ilist=new ArrayList<>(); for(int j=0 ; jk).min().getAsInt(); index[i]=Integer.toString(list.indexOf(min)+1); } String result=String.join("\n",index); System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var m : int ; m := (sc.getCurrent())->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(null) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (sc.getCurrent())->toInteger() ; b[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; var c : Sequence(int) ; c := Integer.subrange(1,m)->collect(null) ; var d : Sequence(int) ; d := Integer.subrange(1,m)->collect(null) ; var i : int ; i := 0 ; while i < m do ( ( c[i+1] := (sc.getCurrent())->toInteger() ; d[i+1] := (sc.getCurrent())->toInteger() ) ; i := i + 1 ) ; skip ; var index : Sequence(String) ; index := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( var list : Sequence(int) ; list := Sequence{} ; var j : int ; j := 0 ; while j < m do ( ( var dist : int ; dist := if a[i+1] - c[j+1] < 0 then -(a[i+1] - c[j+1]) else a[i+1] - c[j+1] endif + if b[i+1] - d[j+1] < 0 then -(b[i+1] - d[j+1]) else b[i+1] - d[j+1] endif ; list := list->including(dist) ) ; j := j + 1 ) ; var min : int ; min := list->collect( _x1 | (lambda k : OclAny in k)->apply(_x1) ).min().getAsInt() ; index[i+1] := ((list->indexOf(min)-1 + 1) + "") ) ; i := i + 1 ) ; var result : String ; result := join("\n", index) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int decimalToBinary(int N){ int B_Number=0 ; int cnt=0 ; while(N!=0){ int rem=N % 2 ; double c=Math.pow(10,cnt); B_Number+=rem*c ; N/=2 ; cnt++; } return B_Number ; } public static void main(String[] args){ int N=17 ; System.out.println(decimalToBinary(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation decimalToBinary( N : int) : int pre: true post: true activity: ( var B_Number : int ; B_Number := 0 ; var cnt : int ; cnt := 0 ; while (N /= 0) do ( var rem : int ; rem := N mod 2 ; var c : double ; c := 10->pow(cnt) ; B_Number := B_Number+(rem * c) ; N := N/(2) ; cnt := cnt + 1 ; ) ; return B_Number ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 17 ; OclFile["System.out"].println(decimalToBinary(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int N=1000000 ; static long phi[]=new long[N+5]; static void computeTotient(){ for(int i=1 ; i<=N ; i++)phi[i]=i ; for(int p=2 ; p<=N ; p++){ if(phi[p]==p){ phi[p]=p-1 ; for(int i=2*p ; i<=N ; i+=p){ phi[i]=(phi[i]/p)*(p-1); } } } } static long power(long x,long y,long p){ long 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 ; } static long calculate(long x,long k,long mod){ long arr[]=new long[N]; long count=0 ; while(mod>1){ arr[(int)count++]=mod ; mod=phi[(int)mod]; } long result=1 ; long loop=count+1 ; arr[(int)count]=1 ; for(int i=(int)Math.min(k,loop)-1 ; i>=0 ; i--)result=power(x,result,arr[i]); return result ; } public static void main(String args[]){ computeTotient(); long x=3,k=2,m=3 ; System.out.println(calculate(x,k,m)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute N : int := 1000000; static attribute phi : long := Integer.subrange(1,N + 5)->collect(0); static operation computeTotient() : void pre: true post: true activity: ( var i : int ; i := 1 ; while i <= N do ( phi[i+1] := i ; ; i := i + 1 ) ; var p : int ; p := 2 ; while p <= N do ( ( if (phi[p+1] = p) then ( phi[p+1] := p - 1 ; var i : int ; i := 2 * p ; while i <= N do ( ( phi[i+1] := (phi[i+1] / p) * (p - 1) ) ; i := i+(p) ) ) else skip ) ; p := p + 1 ) ); static operation power( x : long, y : long, p : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; x := x mod p ; while (y > 0) do ( if ((y & 1) > 0) then res := (res * x) mod p ; else skip ; y := (y/(2->pow(1)))->oclAsType(long) ; x := (x * x) mod p ) ; return res ); static operation calculate( x : long, k : long, mod : long) : long pre: true post: true activity: ( var arr : Sequence(long) ; arr := Integer.subrange(1,N)->collect(0) ; var count : long ; count := 0 ; while (mod > 1) do ( arr[count->oclAsType(int)+1] := mod ; count->oclAsType(int) := count->oclAsType(int) + 1 ; mod := phi[mod->oclAsType(int)+1] ) ; var result : long ; result := 1 ; var loop : long ; loop := count + 1 ; arr[count->oclAsType(int)+1] := 1 ; var i : int ; i := Set{k, loop}->min()->oclAsType(int) - 1 ; while i >= 0 do ( result := power(x, result, arr[i+1]) ; ; i := i - 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute computeTotient() ; var x : long ; x := 3 ; var k : long ; k := 2 ; var m : long ; m := 3 ; OclFile["System.out"].println(calculate(x, k, m)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.util.Arrays.*; import static java.lang.Math.*; public class Main { static Scanner sc=new Scanner(System.in); static int N,M ; static int[][][] flr=new int[100][100][2]; static boolean read(){ N=sc.nextInt(); if(N==0)return false ; for(int i=0 ; icollect(Integer.subrange(1,100)->collect(Integer.subrange(1,2)->collect(0))); static operation read() : boolean pre: true post: true activity: ( N := sc.getCurrent()->toInteger() ; if (N = 0) then return false else skip ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < N do ( ( flr[i+1][j+1][0+1] := sc.getCurrent()->toInteger() ; flr[i+1][j+1][1+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; return true ); static attribute step : Sequence(Sequence(int)) := Integer.subrange(1,100)->collect(Integer.subrange(1,100)->collect(0)); static attribute sol : int; static operation solve() : void pre: true post: true activity: ( sol := 0 ; var i : int ; i := 0 ; while i < N do ( execute fill(step[i+1], -1) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < N do ( ( execute rec(j, i, i * N + j) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sol) ); static operation rec( x : int, y : int, s : int) : void pre: true post: true activity: ( if (step[y+1][x+1] = s) then ( sol := sol + 1 ) else if (step[y+1][x+1] = -1) then ( step[y+1][x+1] := s ; execute rec(flr[y+1][x+1][0+1], flr[y+1][x+1][1+1], s) ) else skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( while (read()) do execute solve() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); for(; ; ){ int N=in.nextInt(); if(N==0)return ; jump a[][]=new jump[N][N]; ArrayListAL=new ArrayList(); int field[][]=new int[N][N]; boolean judge[][]=new boolean[N][N]; int cnt=0 ; for(int i=0 ; itoInteger() ; if (N = 0) then return else skip ; var a : Sequence(Sequence(jump)) ; a := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(null)) ; var AL : Sequence(jump) ; AL := Sequence{} ; var field : Sequence(Sequence(int)) ; field := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; var judge : Sequence(Sequence(boolean)) ; judge := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(false)) ; var cnt : int ; cnt := 0 ; var i : int ; i := 0 ; while i < N do ( var j : int ; j := 0 ; while j < N do ( ( var b : jump ; b := jump.newjump(in.getCurrent()->toInteger(), in.getCurrent()->toInteger()) ; a[j+1][i+1] := b ) ; j := j + 1 ) ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( var j : int ; j := 0 ; while j < N do ( ( var xx : int ; xx := j ; var yy : int ; yy := i ; if (field[j+1][i+1] = 0) then while true do ( ( if (field[xx+1][yy+1] = 2) then ( if (judge[xx+1][yy+1] = false) then ( cnt := cnt + 1 ; judge[xx+1][yy+1] := true ) else skip ; break ) else skip ; field[xx+1][yy+1] := 2 ; var b : jump ; b := jump.newjump(xx, yy) ; AL := AL->including(b) ; var tx : int ; tx := a[xx+1][yy+1].x ; var ty : int ; ty := a[xx+1][yy+1].y ; xx := tx ; yy := ty ; ) ) ; else skip ; var k : int ; k := 0 ; while k < AL->size() do ( ( var rex : int ; rex := AL->at(k+1).x ; var rey : int ; rey := AL->at(k+1).y ; judge[rex+1][rey+1] := true ) ; k := k + 1 ) ) ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(cnt) ; ) ) ); } class jump { attribute x : int; attribute y : int; static operation newjump( a : int, b : int) : jump pre: true post: true activity: ( var self : jump ; self := createjump(); self.initialise(a, b); return self ); operation initialise( a : int, b : int) : void pre: true post: true activity: ( x := a ; y := b ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int N ; static int[][][] field ; static int[][] already ; static boolean[][] isLoop ; public static void main(String[] args){ Scanner cin=new Scanner(System.in); for(; ; ){ N=cin.nextInt(); if(N==0)break ; field=new int[N][N][2]; already=new int[N][N]; isLoop=new boolean[N][N]; for(int i=0 ; itoInteger() ; if (N = 0) then break else skip ; field := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(Integer.subrange(1,2)->collect(0))) ; already := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; isLoop := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(false)) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < N do ( ( field[j+1][i+1][0+1] := cin.getCurrent()->toInteger() ; field[j+1][i+1][1+1] := cin.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var cnt : int ; cnt := 1 ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < N do ( ( var a : Sequence(int) ; a := a(j, i, cnt) ; if (a[0+1] = j & a[1+1] = i & not(isLoop[j+1][i+1])) then ( ans := ans + 1 ; execute b(j, i) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ) ); static operation b( y : int, x : int) : void pre: true post: true activity: ( if (isLoop[y+1][x+1]) then return else skip ; isLoop[y+1][x+1] := true ; var a : int ; a := field[y+1][x+1][0+1] ; var b : int ; b := field[y+1][x+1][1+1] ; execute b(a, b) ; ); static operation a( y : int, x : int, cnt : int) : Sequence(int) pre: true post: true activity: ( var a : int ; a := field[y+1][x+1][0+1] ; var b : int ; b := field[y+1][x+1][1+1] ; if (already[y+1][x+1] = cnt) then return Sequence{y,x} else skip ; already[y+1][x+1] := cnt ; return a(a, b, cnt) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { void run(){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0)break ; int[][][] m=new int[n][n][2]; for(int i=0 ; iset=new HashSet(); set.add(i*n+j); int nj=m[i][j][0]; int ni=m[i][j][1]; while(true){ if(u[ni][nj]){ if(set.contains(ni*n+nj))c++; break ; } u[ni][nj]=true ; set.add(ni*n+nj); int ti=ni ; int tj=nj ; nj=m[ti][tj][0]; ni=m[ti][tj][1]; } } } System.out.println(c); } } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var m : Sequence(Sequence(Sequence(int))) ; m := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0))) ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := 0 ; while j < n do ( var k : int ; k := 0 ; while k < 2 do ( m[i+1][j+1][k+1] := sc.getCurrent()->toInteger() ; ; k := k + 1 ) ; ; j := j + 1 ) ; ; i := i + 1 ) ; var u : Sequence(Sequence(boolean)) ; u := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(false)) ; var c : int ; c := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (u[i+1][j+1]) then continue else skip ; u[i+1][j+1] := true ; var set : Set(int) ; set := Set{} ; set := set->including(i * n + j) ; var nj : int ; nj := m[i+1][j+1][0+1] ; var ni : int ; ni := m[i+1][j+1][1+1] ; while (true) do ( if (u[ni+1][nj+1]) then ( if (set->includes(ni * n + nj)) then c := c + 1 ; else skip ; break ) else skip ; u[ni+1][nj+1] := true ; set := set->including(ni * n + nj) ; var ti : int ; ti := ni ; var tj : int ; tj := nj ; nj := m[ti+1][tj+1][0+1] ; ni := m[ti+1][tj+1][1+1] ; ) ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(c) ; ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int INT_MAX=2147483647 ; static int isKthBitSet(int x,int k){ return((x &(1<<(k-1)))>0)? 1 : 0 ; } static int leftmostSetBit(int x){ int count=0 ; while(x>0){ count++; x=x>>1 ; } return count ; } static int isBinPalindrome(int x){ int l=leftmostSetBit(x); int r=1 ; while(l>r){ if(isKthBitSet(x,l)!=isKthBitSet(x,r))return 0 ; l--; r++; } return 1 ; } static int findNthPalindrome(int n){ int pal_count=0 ; int i=0 ; for(i=1 ; i<=INT_MAX ; i++){ if(isBinPalindrome(i)>0){ pal_count++; } if(pal_count==n)break ; } return i ; } public static void main(String[] args){ int n=9 ; System.out.println(findNthPalindrome(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute INT_MAX : int := 2147483647; static operation isKthBitSet( x : int, k : int) : int pre: true post: true activity: ( return if ((x & ((1*(2->pow((k - 1))))->oclAsType(long))) > 0) then 1 else 0 endif ); static operation leftmostSetBit( x : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; while (x > 0) do ( count := count + 1 ; x := (x/(2->pow(1)))->oclAsType(long) ) ; return count ); static operation isBinPalindrome( x : int) : int pre: true post: true activity: ( var l : int ; l := leftmostSetBit(x) ; var r : int ; r := 1 ; while (l > r) do ( if (isKthBitSet(x, l) /= isKthBitSet(x, r)) then return 0 else skip ; l := l - 1 ; r := r + 1 ) ; return 1 ); static operation findNthPalindrome( n : int) : int pre: true post: true activity: ( var pal_count : int ; pal_count := 0 ; var i : int ; i := 0 ; i := 1 ; while i <= INT_MAX do ( ( if (isBinPalindrome(i) > 0) then ( pal_count := pal_count + 1 ) else skip ; if (pal_count = n) then break else skip ) ; i := i + 1 ) ; return i ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 9 ; OclFile["System.out"].println(findNthPalindrome(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=Integer.parseInt(sc.next()); int ans=0 ; if(x<=111){ ans=111 ; } else if(x<=222){ ans=222 ; } else if(x<=333){ ans=333 ; } else if(x<=444){ ans=444 ; } else if(x<=555){ ans=555 ; } else if(x<=666){ ans=666 ; } else if(x<=777){ ans=777 ; } else if(x<=888){ ans=888 ; } else if(x<=999){ ans=999 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := (sc.getCurrent())->toInteger() ; var ans : int ; ans := 0 ; if (x <= 111) then ( ans := 111 ) else if (x <= 222) then ( ans := 222 ) else if (x <= 333) then ( ans := 333 ) else if (x <= 444) then ( ans := 444 ) else if (x <= 555) then ( ans := 555 ) else if (x <= 666) then ( ans := 666 ) else if (x <= 777) then ( ans := 777 ) else if (x <= 888) then ( ans := 888 ) else if (x <= 999) then ( ans := 999 ) else skip ; ; ; ; ; ; ; ; ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int maxdiff(int arr[],int n){ Mapfreq=new HashMap<>(); for(int i=0 ; ifreq.get(arr[j])&& arr[i]>arr[j])ans=Math.max(ans,freq.get(arr[i])-freq.get(arr[j])); else if(freq.get(arr[i])union(Map{arr[i+1] |-> if freq->at(arr[i+1]) = null then 1 else freq->at(arr[i+1]) + 1 endif}) ; ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( if (freq->at(arr[i+1]) > freq->at(arr[j+1]) & arr[i+1] > arr[j+1]) then ans := Set{ans, freq->at(arr[i+1]) - freq->at(arr[j+1])}->max() ; else if (freq->at(arr[i+1]) < freq->at(arr[j+1]) & arr[i+1] < arr[j+1]) then ans := Set{ans, freq->at(arr[j+1]) - freq->at(arr[i+1])}->max() ; else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,1,3,2,3,2} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(maxdiff(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.IOException ; import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Arrays ; import java.util.Comparator ; import java.util.Deque ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); String N=sc.next(); char c=N.charAt(0); boolean allsmall=true ; for(int i=1 ; ic)allsmall=false ; } for(int i=0 ; iat(0+1) ; var allsmall : boolean ; allsmall := true ; var i : int ; i := 1 ; while i < N->size() do ( ( if (N->at(i+1) > c) then allsmall := false ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N->size() do ( OclFile["System.out"].print(if allsmall then "" + c else "" + (c + (('2')->char2byte() - ('1')->char2byte()))->oclAsType(String) endif) ; ; i := i + 1 ) ; OclFile["System.out"].println() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Set ; import java.util.HashSet ; public class CF225_D2_A { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); int up=scanner.nextInt(); while(t--!=0){ Setset=new HashSet<>(); int n1=scanner.nextInt(); int n2=scanner.nextInt(); set.add(n1); set.add(n2); set.add(up); set.add(7-n1); set.add(7-n2); up=7-up ; set.add(up); if(set.size()!=6){ System.out.println("NO"); System.exit(0); } } System.out.println("YES"); scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class CF225_D2_A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; var up : int ; up := scanner.getCurrent()->toInteger() ; while (t /= 0) do ( skip ; ( var set : Set(int) ; set := Set{} ; var n1 : int ; n1 := scanner.getCurrent()->toInteger() ; var n2 : int ; n2 := scanner.getCurrent()->toInteger() ; set := set->including(n1) ; set := set->including(n2) ; set := set->including(up) ; set := set->including(7 - n1) ; set := set->including(7 - n2) ; up := 7 - up ; set := set->including(up) ; if (set->size() /= 6) then ( OclFile["System.out"].println("NO") ; OclProcess.exit(0) ) else skip ; ) ; ) ; OclFile["System.out"].println("YES") ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int calculateSum(int n){ if(n % 2==1)return(n+1)/2 ; return-n/2 ; } public static void main(String ar[]){ int n=8 ; System.out.println(calculateSum(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation calculateSum( n : int) : int pre: true post: true activity: ( if (n mod 2 = 1) then return (n + 1) / 2 else skip ; return -n / 2 ); static operation main( ar : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 8 ; OclFile["System.out"].println(calculateSum(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigDecimal ; import java.math.RoundingMode ; import java.util.Scanner ; public class Main { public static void main(String args[]){ Scanner scanner=new Scanner(System.in); int N=scanner.nextInt(); if(N % 111==0){ System.out.println(N); return ; } int DN=N/111 ; System.out.println(111*(DN+1)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := scanner.getCurrent()->toInteger() ; if (N mod 111 = 0) then ( OclFile["System.out"].println(N) ; return ) else skip ; var DN : int ; DN := N / 111 ; OclFile["System.out"].println(111 * (DN + 1)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class Main { public static void main(String[] args){ solve(); } public static void solve(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int i=0 ; while(true){ if((n+i)% 111==0){ System.out.println(n+i); break ; } i++; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute solve() ); static operation solve() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while (true) do ( if ((n + i) mod 111 = 0) then ( OclFile["System.out"].println(n + i) ; break ) else skip ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Integer list[]={ 111,222,333,444,555,666,777,888,999 }; Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ret=0 ; for(int i=n ; true ; i++){ if(Arrays.asList(list).contains(i)){ ret=i ; break ; } } System.out.println(ret); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{111,222,333,444,555,666,777,888,999} ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var ret : int ; ret := 0 ; var i : int ; i := n ; while true do ( ( if (list->includes(i)) then ( ret := i ; break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ret) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int[][] field=new int[h+2][w+2]; int[] arr=new int[h*w]; for(int i=0 ; itoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var field : Sequence(Sequence(int)) ; field := Integer.subrange(1,h + 2)->collect(Integer.subrange(1,w + 2)->collect(0)) ; var arr : Sequence(int) ; arr := Integer.subrange(1,h * w)->collect(0) ; var i : int ; i := 0 ; while i < h * w do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; arr[x - 1+1] := i ) ; i := i + 1 ) ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < h * w do ( ( var hh : int ; hh := arr[i+1] / w + 1 ; var ww : int ; ww := arr[i+1] mod w + 1 ; var besides : Sequence(int) ; besides := Sequence{field[hh - 1+1][ww+1],field[hh+1][ww - 1+1],field[hh + 1+1][ww+1],field[hh+1][ww + 1+1]} ; besides := besides->sort() ; if (besides[0+1] = -1) then ( field[hh+1][ww+1] := -1 ; count := count + 1 ) else ( var x : int ; x := besides[0+1] ; var j : int ; j := 1 ; while j < 4 do ( ( if (x = 0) then ( x := besides[j+1] ) else ( if (x /= besides[j+1]) then ( field[hh+1][ww+1] := -1 ; count := count + 1 ; break ) else skip ) ) ; j := j + 1 ) ; if (field[hh+1][ww+1] = -1) then ( continue ) else skip ; if (x = 0) then ( field[hh+1][ww+1] := i + 1 ) else ( field[hh+1][ww+1] := x ) ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static double Perimeter(double s,int n){ double perimeter=1 ; perimeter=n*s ; return perimeter ; } public static void main(String[] args){ int n=5 ; double s=2.5,peri ; peri=Perimeter(s,n); System.out.println("Perimeter of Regular Polygon"+" with "+n+" sides of length "+s+"="+peri); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation Perimeter( s : double, n : int) : double pre: true post: true activity: ( var perimeter : double ; perimeter := 1 ; perimeter := n * s ; return perimeter ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var s : double ; s := 2.5 ; var peri : double ; peri := Perimeter(s, n) ; OclFile["System.out"].println("Perimeter of Regular Polygon" + " with " + n + " sides of length " + s + "=" + peri) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { static Listlist=new ArrayList<>(); public static void main(String[] args){ InputReader s=new InputReader(); int n=s.nextInt(); if(n<0)n=-n ; int sum=0 ; for(int i=0 ; ; i++){ sum+=i ; if(n==sum || sum>n &&(sum-n)% 2==0){ System.out.println(i); return ; } } } } class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader(){ reader=new BufferedReader(new InputStreamReader(System.in),32768); tokenizer=null ; } public String next(){ while(tokenizer==null || ! tokenizer.hasMoreTokens()){ try { tokenizer=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){ return Long.parseLong(next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute list : Sequence(Sequence(long)) := Sequence{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : InputReader ; s := InputReader.newInputReader() ; var n : int ; n := s.nextInt() ; if (n < 0) then n := -n ; else skip ; var sum : int ; sum := 0 ; var i : int ; i := 0 ; while true do ( ( sum := sum+(i) ; if (n = sum or sum > n & (sum - n) mod 2 = 0) then ( OclFile["System.out"].println(i) ; return ) else skip ) ; i := i + 1 ) ; ); } class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader() : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int x=Math.abs(sc.nextInt()); System.out.println(minTimes(x)); } sc.close(); } public static long minTimes(long x){ if(x==0){ return 0 ; } long l=0 ; long r=x ; long m=0 ; long near=0 ; while(l<=r){ m=(l+r)/2 ; if(sum(m)>=x){ near=m ; r=m-1 ; } else { l=m+1 ; } } if(sum(near)==x){ return near ; } if(((sum(near)-x)& 1)==1){ near++; } if(((sum(near)-x)& 1)==1){ near++; } return near ; } public static long sum(long n){ return(n*(n+1))/2 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (sc.hasNext()) do ( var x : int ; x := if sc.getCurrent()->toInteger() < 0 then -(sc.getCurrent()->toInteger()) else sc.getCurrent()->toInteger() endif ; OclFile["System.out"].println(minTimes(x)) ) ; skip ); static operation minTimes( x : long) : long pre: true post: true activity: ( if (x = 0) then ( return 0 ) else skip ; var l : long ; l := 0 ; var r : long ; r := x ; var m : long ; m := 0 ; var near : long ; near := 0 ; while (l <= r) do ( m := (l + r) / 2 ; if (sum(m) >= x) then ( near := m ; r := m - 1 ) else ( l := m + 1 ) ) ; if (sum(near) = x) then ( return near ) else skip ; if (((sum(near) - x) & 1) = 1) then ( near := near + 1 ) else skip ; if (((sum(near) - x) & 1) = 1) then ( near := near + 1 ) else skip ; return near ); static operation sum( n : long) : long pre: true post: true activity: ( return (n * (n + 1)) / 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class CF_1447B_NumbersBox { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int count=scanner.nextInt(); for(int i=0 ; iarr[j]){ minNum=arr[j]; } } else { sumNum+=arr[j]; if(minNum>arr[j]){ minNum=arr[j]; } } } if(nagiviteTimes % 2==0){ System.out.println(sumNum); } else { System.out.println(sumNum-minNum*2); } } } } ------------------------------------------------------------ OCL File: --------- class CF_1447B_NumbersBox { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var count : int ; count := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < count do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; var m : int ; m := scanner.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n * m)->collect(0) ; var nagiviteTimes : int ; nagiviteTimes := 0 ; var minNum : int ; minNum := 2147483647 ; var sumNum : int ; sumNum := 0 ; var j : int ; j := 0 ; while j < arr->size() do ( ( arr[j+1] := scanner.getCurrent()->toInteger() ; if (arr[j+1] < 0) then ( arr[j+1] := 0 - arr[j+1] ; nagiviteTimes := nagiviteTimes + 1 ; sumNum := sumNum+(arr[j+1]) ; if (minNum > arr[j+1]) then ( minNum := arr[j+1] ) else skip ) else ( sumNum := sumNum+(arr[j+1]) ; if (minNum > arr[j+1]) then ( minNum := arr[j+1] ) else skip ) ) ; j := j + 1 ) ; if (nagiviteTimes mod 2 = 0) then ( OclFile["System.out"].println(sumNum) ) else ( OclFile["System.out"].println(sumNum - minNum * 2) ) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Comparator ; import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ new Main().solve(); } Scanner in ; PrintWriter out ; int a[]=new int[5]; public void solve(){ in=new Scanner(System.in); out=new PrintWriter(System.out); int t=1 ; while(t-->0){ long n=in.nextLong(),ans=0 ; n=Math.abs(n); long now=0 ; while(true){ Long mid=(now)*(now+1)/2 ; if(mid==n){ ans=now ; break ; } else if(mid>n){ if((mid-n)% 2==0){ ans=now ; break ; } } now++; } out.println(ans); } out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); attribute in : OclFile; attribute out : OclFile; attribute a : int := Integer.subrange(1,5)->collect(0); operation solve() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile["System.in"]) ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : long ; n := in.getCurrent()->toLong() ; var ans : long ; ans := 0 ; n := if n < 0 then -(n) else n endif ; var now : long ; now := 0 ; while (true) do ( var mid : long ; mid := (now) * (now + 1) / 2 ; if (mid = n) then ( ans := now ; break ) else if (mid > n) then ( if ((mid - n) mod 2 = 0) then ( ans := now ; break ) else skip ) else skip ; ; now := now + 1 ) ; skip ; ) ; ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); x=Math.abs(x); if(x==0){ System.out.println("0"); return ; } int ans=0,sum=0,num=1 ; while(sum!=x){ sum+=num ; if(sum>x &&((sum-x)% 2)==0){ ans++; break ; } ans++; num++; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; x := if x < 0 then -(x) else x endif ; if (x = 0) then ( OclFile["System.out"].println("0") ; return ) else skip ; var ans : int ; ans := 0 ; var sum : int ; sum := 0 ; var num : int ; num := 1 ; while (sum /= x) do ( sum := sum+(num) ; if (sum > x & ((sum - x) mod 2) = 0) then ( ans := ans + 1 ; break ) else skip ; ans := ans + 1 ; num := num + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void max_element(int a[],int n){ int[] pre=new int[n]; pre[0]=a[0]; for(int i=1 ; i=0 ; i--)suf[i]=Math.max(suf[i+1],a[i]); for(int i=0 ; icollect(0) ; pre[0+1] := a[0+1] ; var i : int ; i := 1 ; while i < n do ( pre[i+1] := Set{pre[i - 1+1], a[i+1]}->max() ; ; i := i + 1 ) ; var suf : Sequence(int) ; suf := Integer.subrange(1,n)->collect(0) ; suf[n - 1+1] := a[n - 1+1] ; var i : int ; i := n - 2 ; while i >= 0 do ( suf[i+1] := Set{suf[i + 1+1], a[i+1]}->max() ; ; i := i - 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (i = 0) then OclFile["System.out"].print(suf[i + 1+1] + " ") ; else if (i = n - 1) then OclFile["System.out"].print(pre[i - 1+1] + " ") else OclFile["System.out"].print(Set{pre[i - 1+1], suf[i + 1+1]}->max() + " ") ; ; ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{2,5,6,1,3} ; var n : int ; n := a->size() ; execute max_element(a, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findLastIndex(String str,Character x){ for(int i=str.length()-1 ; i>=0 ; i--)if(str.charAt(i)==x)return i ; return-1 ; } public static void main(String[] args){ String str="geeksforgeeks" ; Character x='e' ; int index=findLastIndex(str,x); if(index==-1)System.out.println("Character not found"); else System.out.println("Last index is "+index); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findLastIndex( str : String, x : String) : int pre: true post: true activity: ( var i : int ; i := str->size() - 1 ; while i >= 0 do ( if (str->at(i+1) = x) then return i else skip ; ; i := i - 1 ) ; return -1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var x : String ; x := 'e' ; var index : int ; index := findLastIndex(str, x) ; if (index = -1) then OclFile["System.out"].println("Character not found") ; else OclFile["System.out"].println("Last index is " + index) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileNotFoundException ; import java.util.Scanner ; public class Main { int n ; String[] s ; int[] d ; public static void main(String[] args)throws FileNotFoundException { new Main().run(); } private void run(){ Scanner sc=new Scanner(System.in); while(true){ s=new String[1000]; d=new int[1000]; n=sc.nextInt(); if(n==0)return ; sc.nextLine(); for(int i=0 ; i=0 ; p--){ if(j==d[p]-1){ x=p ; break ; } else if(j>d[p]-1){ break ; } } for(int q=i+1 ; qd[q]-1){ break ; } } if(x==-1 || y==-1){ System.out.print(" "); } else if(y-x>=2){ System.out.print("|"); } else { System.out.print(" "); } } } System.out.println(s[i]); } } } } ------------------------------------------------------------ OCL File: --------- class Main { attribute n : int; attribute s : Sequence(String); attribute d : Sequence(int); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( s := Integer.subrange(1,1000)->collect(null) ; d := Integer.subrange(1,1000)->collect(0) ; n := sc.getCurrent()->toInteger() ; if (n = 0) then return else skip ; skip ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := sc.nextLine() ; var j : int ; j := 0 ; while j < s[i+1]->size() do ( ( if (s[i+1]->at(j+1) /= '.') then ( d[i+1] := j ; break ) else skip ) ; j := j + 1 ) ; s[i+1] := s[i+1].replace(".", "") ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < d[i+1] do ( ( if (j = d[i+1] - 1) then ( OclFile["System.out"].print("+") ) else ( var x : int ; x := -1 ; var y : int ; y := -1 ; var p : int ; p := i - 1 ; while p >= 0 do ( ( if (j = d[p+1] - 1) then ( x := p ; break ) else if (j > d[p+1] - 1) then ( break ) else skip ; ) ; p := p - 1 ) ; var q : int ; q := i + 1 ; while q < n do ( ( if (j = d[q+1] - 1) then ( y := q ; break ) else if (j > d[q+1] - 1) then ( break ) else skip ; ) ; q := q + 1 ) ; if (x = -1 or y = -1) then ( OclFile["System.out"].print(" ") ) else if (y - x >= 2) then ( OclFile["System.out"].print("|") ) else ( OclFile["System.out"].print(" ") ) ; ) ) ; j := j + 1 ) ; OclFile["System.out"].println(s[i+1]) ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.Scanner ; import java.util.StringTokenizer ; public class Main { public static void main(String[] args){ final Scanner sc=new Scanner(System.in); while(true){ final int n=Integer.parseInt(sc.nextLine()); if(n==0){ break ; } char[][] map=new char[n][]; for(int i=0 ; istack=new LinkedList(); for(int i=n-1 ; i>=0 ; i--){ int pos=0 ; if(map[i][pos]!='.'){ continue ; } while(pos=height){ stack.removeLast(); } else { break ; } } for(int high : stack){ map[i][high]='|' ; } map[i][height]='+' ; for(int j=0 ; jtoInteger() ; if (n = 0) then ( break ) else skip ; var map : Sequence(Sequence(String)) ; map := Integer.subrange(1,n)->collect(Sequence{}) ; var i : int ; i := 0 ; while i < n do ( ( map[i+1] := sc.nextLine()->characters() ) ; i := i + 1 ) ; var stack : Sequence(int) ; stack := Sequence{} ; var i : int ; i := n - 1 ; while i >= 0 do ( ( var pos : int ; pos := 0 ; if (map[i+1][pos+1] /= '.') then ( continue ) else skip ; while (pos < map[i+1]->size() & map[i+1][pos+1] = '.') do ( pos := pos + 1 ) ; var height : int ; height := pos - 1 ; while (not(stack->isEmpty())) do ( if (stack->last() >= height) then ( stack := stack->front() ) else ( break ) ) ; for (high : stack) do ( ( map[i+1][high+1] := '|' ) ) ; map[i+1][height+1] := '+' ; var j : int ; j := 0 ; while j < height do ( ( if (map[i+1][j+1] = '.') then ( map[i+1][j+1] := ' ' ) else skip ) ; j := j + 1 ) ; stack := stack->append(height) ; ) ; i := i - 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(map[i+1]) ) ; i := i + 1 ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import static java.lang.Integer.parseInt ; public class Main { static int MAX=999+51 ; static char TERM='Z' ; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line ; while((line=br.readLine())!=null && ! line.isEmpty()){ int n=parseInt(line); if(n==0)break ; char[][] board=new char[n][MAX]; int check=0 ; for(int i=0 ; i='a'){ board[i][j]='+' ; check--; } } } board[i][line.length()]=TERM ; } for(int j=0 ; j0 ; i--){ char c=board[i][j]; if(c=='+'){ for(int k=i-1 ; k>0 ; k--){ if(board[k][j]=='.'){ board[k][j]='|' ; check--; } else break ; } } else if(c=='.'){ board[i][j]=' ' ; check--; } } if(check==0)break ; } for(int i=0 ; iisEmpty())) do ( skip ; ( var n : int ; n := parseInt(line) ; if (n = 0) then break else skip ; var board : Sequence(Sequence(String)) ; board := Integer.subrange(1,n)->collect(Integer.subrange(1,MAX)->collect(0)) ; var check : int ; check := 0 ; var i : int ; i := 0 ; while i < n do ( ( line := br.readLine() ; var j : int ; j := 0 ; while j < line->size() do ( ( var c : String ; c := line->at(j+1) ; board[i+1][j+1] := c ; if (c = '.') then ( check := check + 1 ; if (line->at(j + 1+1) >= 'a') then ( board[i+1][j+1] := '+' ; check := check - 1 ) else skip ) else skip ) ; j := j + 1 ) ; board[i+1][line->size()+1] := TERM ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < MAX do ( ( var i : int ; i := (n)->char2byte() - 1 ; while i > 0 do ( ( var c : String ; c := board[i+1][j+1] ; if (c = '+') then ( var k : int ; k := i - 1 ; while k > 0 do ( ( if (board[k+1][j+1] = '.') then ( board[k+1][j+1] := '|' ; check := check - 1 ) else break ) ; k := k - 1 ) ) else if (c = '.') then ( board[i+1][j+1] := ' ' ; check := check - 1 ) else skip ; ) ; i := i - 1 ) ; if (check = 0) then break else skip ) ; j := j + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < MAX do ( ( var c : String ; c := board[i+1][j+1] ; if (c = TERM) then break else skip ; OclFile["System.out"].print(board[i+1][j+1]) ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.ArrayList ; public class Main { Scanner sc=new Scanner(System.in); public void run(){ while(true){ int n=sc.nextInt(); if(n==0)break ; calc(n); } } public void calc(int n){ char[][] words=new char[n][]; words[0]=sc.next().toCharArray(); for(int i=1 ; i=0 ; j--){ if(words[j][k]==' '){ words[j][k]='|' ; } else break ; } break ; } else { words[i][k]=' ' ; } } } for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; execute calc(n) ) ); operation calc( n : int) : void pre: true post: true activity: ( var words : Sequence(Sequence(String)) ; words := Integer.subrange(1,n)->collect(Sequence{}) ; words[0+1] := sc.getCurrent()->characters() ; var i : int ; i := 1 ; while i < n do ( ( words[i+1] := sc.getCurrent()->characters() ; var before : int ; before := -1 ; var mmax : int ; mmax := 0 ; var k : int ; k := 0 ; while k < words[i+1]->size() do ( ( if (words[i+1][k + 1+1] /= '.') then ( words[i+1][k+1] := '+' ; var j : int ; j := i - 1 ; while j >= 0 do ( ( if (words[j+1][k+1] = ' ') then ( words[j+1][k+1] := '|' ) else break ) ; j := j - 1 ) ; break ) else ( words[i+1][k+1] := ' ' ) ) ; k := k + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( OclFile["System.out"].println(words[i+1]) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); while(true){ int n=in.nextInt(); if(n==0)break ; ArrayList>head=new ArrayList<>(); String[] body=new String[n]; for(int i=0 ; i()); String txt=in.next(); int j=0 ; while(txt.charAt(j)=='.'){ head.get(i).add(' '); j++; } body[i]=txt.substring(j); } for(int i=0 ; iline=head.get(i); int col=line.size()-1 ; if(line.size()==0)continue ; line.set(col,'+'); int j=i-1 ; while(head.get(j).size()-1>col){ head.get(j).set(col,'|'); j--; } } for(int i=0 ; iline=head.get(i); for(int j=0 ; jtoInteger() ; if (n = 0) then break else skip ; var head : Sequence(Sequence(String)) ; head := Sequence{} ; var body : Sequence(String) ; body := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( head := head->including(Sequence{}) ; var txt : String ; txt := in.getCurrent() ; var j : int ; j := 0 ; while (txt->at(j+1) = '.') do ( head->at(i+1)->excludes(' ') ; j := j + 1 ) ; body[i+1] := txt.subrange(j+1,j) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var line : Sequence(String) ; line := head->at(i+1) ; var col : int ; col := line->size() - 1 ; if (line->size() = 0) then continue else skip ; line := line.setAt(col+1,'+') ; var j : int ; j := i - 1 ; while (head->at(j+1)->size() - 1 > col) do ( head := head->at(j+1).setAt(col+1, '|') ; j := j - 1 ) ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var line : Sequence(String) ; line := head->at(i+1) ; var j : int ; j := 0 ; while j < line->size() do ( ( OclFile["System.out"].print(line->at(j+1)) ) ; j := j + 1 ) ; OclFile["System.out"].println(body[i+1]) ) ; i := i + 1 ) ; gc() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int MinimumCost(int a[],int n,int x){ for(int i=1 ; i0){ if(x!=0)sum+=a[ind]; ind++; x=x>>1 ; } return sum ; } public static void main(String[] args){ int a[]={ 20,50,60,90 }; int x=7 ; int n=a.length ; System.out.println(MinimumCost(a,n,x)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation MinimumCost( a : Sequence(int), n : int, x : int) : int pre: true post: true activity: ( var i : int ; i := 1 ; while i < n do ( ( a[i+1] := Set{a[i+1], 2 * a[i - 1+1]}->min() ) ; i := i + 1 ) ; var ind : int ; ind := 0 ; var sum : int ; sum := 0 ; while (x > 0) do ( if (x /= 0) then sum := sum+(a[ind+1]) ; else skip ; ind := ind + 1 ; x := (x/(2->pow(1)))->oclAsType(long) ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{20,50,60,90} ; var x : int ; x := 7 ; var n : int ; n := a->size() ; OclFile["System.out"].println(MinimumCost(a, n, x)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class AP { static void makeAP(int arr[],int n){ int initial_term,common_difference ; if(n==3){ common_difference=arr[2]-arr[1]; initial_term=arr[1]-common_difference ; } else if((arr[1]-arr[0])==arr[2]-arr[1]){ initial_term=arr[0]; common_difference=arr[1]-arr[0]; } else if((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(int i=0 ; isize() ; execute makeAP(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int MAX=1005 ; static int shortestSeq(char[] S,char[] T){ int m=S.length,n=T.length ; int dp[][]=new int[m+1][n+1]; for(int i=0 ; i<=m ; i++){ dp[i][0]=1 ; } for(int i=0 ; i<=n ; i++){ dp[0][i]=MAX ; } for(int i=1 ; i<=m ; i++){ for(int j=1 ; j<=n ; j++){ char ch=S[i-1]; int k ; for(k=j-1 ; k>=0 ; k--){ if(T[k]==ch){ break ; } } if(k==-1){ dp[i][j]=1 ; } else { dp[i][j]=Math.min(dp[i-1][j],dp[i-1][k]+1); } } } int ans=dp[m][n]; if(ans>=MAX){ ans=-1 ; } return ans ; } public static void main(String[] args){ char S[]="babab".toCharArray(); char T[]="babba".toCharArray(); int m=S.length,n=T.length ; System.out.println("Length of shortest"+"subsequence is : "+shortestSeq(S,T)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute MAX : int := 1005; static operation shortestSeq( S : Sequence(String), T : Sequence(String)) : int pre: true post: true activity: ( var m : int ; m := S->size() ; var n : int ; n := T->size() ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,m + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 0 ; while i <= m do ( ( dp[i+1][0+1] := 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= n do ( ( dp[0+1][i+1] := MAX ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= m do ( ( var j : int ; j := 1 ; while j <= n do ( ( var ch : String ; ch := S[i - 1+1] ; var k : int ; k := 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() ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := dp[m+1][n+1] ; if (ans >= MAX) then ( ans := -1 ) else skip ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var S : Sequence(String) ; S := "babab"->characters() ; var T : Sequence(String) ; T := "babba"->characters() ; var m : int ; m := S->size() ; var n : int ; n := T->size() ; OclFile["System.out"].println("Length of shortest" + "subsequence is : " + shortestSeq(S, T)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { public static int sumOfPairs(int n){ ArrayListv=new ArrayList(); int sum=0 ; while(n>0){ v.add(n % 2); n=n/2 ; } Collections.reverse(v); for(int i=0 ; i 0) do ( v := v->including(n mod 2) ; n := n / 2 ) ; v := v->reverse() ; var i : int ; i := 0 ; while i < v->size() - 1 do ( ( var j : int ; j := i + 1 ; while j < v->size() do ( ( if (v->at(i+1) = 0 & v->at(j+1) = 1) then sum := sum+(1) ; else skip ; if (v->at(i+1) = 1 & v->at(j+1) = 1) then sum := sum+(3) ; else skip ; if (v->at(i+1) = 1 & v->at(j+1) = 0) then sum := sum+(2) ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 5 ; OclFile["System.out"].print(sumOfPairs(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GFG { static int largestSubset(int[] a,int n){ Arrays.sort(a); int[] dp=new int[n]; dp[n-1]=1 ; for(int i=n-2 ; i>=0 ; i--){ int mxm=0 ; for(int j=i+1 ; jsort() ; var dp : Sequence(int) ; dp := Integer.subrange(1,n)->collect(0) ; dp[n - 1+1] := 1 ; var i : int ; i := n - 2 ; while i >= 0 do ( ( var mxm : int ; mxm := 0 ; var j : int ; j := i + 1 ; while j < n do ( ( if (a[j+1] mod a[i+1] = 0) then ( mxm := Set{mxm, dp[j+1]}->max() ) else skip ) ; j := j + 1 ) ; dp[i+1] := 1 + mxm ) ; i := i - 1 ) ; return stream(dp).max().getAsInt() ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{1,3,6,13,17,18} ; var n : int ; n := a->size() ; OclFile["System.out"].println(largestSubset(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class AlternateSetBits { static boolean allBitsAreSet(int n){ if(((n+1)& n)==0)return true ; return false ; } static boolean bitsAreInAltOrder(int n){ int num=n ^(n>>>1); return allBitsAreSet(num); } public static void main(String args[]){ int n=10 ; if(bitsAreInAltOrder(n))System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class AlternateSetBits { static operation allBitsAreSet( n : int) : boolean pre: true post: true activity: ( if (((n + 1) & n) = 0) then return true else skip ; return false ); static operation bitsAreInAltOrder( n : int) : boolean pre: true post: true activity: ( var num : int ; num := MathLib.bitwiseXor(n,((n/(2->pow(1)))->oclAsType(long))) ; return allBitsAreSet(num) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; if (bitsAreInAltOrder(n)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int findLastIndex(String str,Character x){ int index=-1 ; for(int i=0 ; isize() do ( if (str->at(i+1) = x) then index := i ; else skip ; ; i := i + 1 ) ; return index ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "geeksforgeeks" ; var x : String ; x := 'e' ; var index : int ; index := findLastIndex(str, x) ; if (index = -1) then OclFile["System.out"].println("Character not found") ; else OclFile["System.out"].println("Last index is " + index) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void findTriangles(int n){ int num=n ; System.out.print(num+" "); System.out.print(num*(num-4)*(num-5)/6); } public static void main(String[] args){ int n ; n=6 ; findTriangles(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findTriangles( n : int) : void pre: true post: true activity: ( var num : int ; num := n ; OclFile["System.out"].print(num + " ") ; OclFile["System.out"].print(num * (num - 4) * (num - 5) / 6) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; execute findTriangles(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayDeque ; import java.util.ArrayList ; import java.util.Deque ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int q=sc.nextInt(); List>list=new ArrayList>(); for(int i=0 ; i()); } for(int i=0 ; itoInteger() ; var q : int ; q := sc.getCurrent()->toInteger() ; var list : Sequence(Sequence(int)) ; list := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( list := list->including(ArrayDeque.newArrayDeque()) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < q do ( ( var query : int ; query := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (query) ; if _switchval = 0 then var x : int ; x := sc.getCurrent()->toInteger() ; list->at(t+1)->excludes(x) ; break else skip ; if _switchval = 1 then if (not((list->at(t+1)->isEmpty()))) then ( OclFile["System.out"].println(list->at(t+1).peekFirst()) ) else skip ; break else skip ; if _switchval = 2 then list := list->at(t+1)->tail() ; break else skip ; ) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { static final int INIT=8 ; static int[] grow(int[] s){ int[] d=new int[s.length*2]; System.arraycopy(s,0,d,0,s.length); return d ; } static class Queue { private int[] data ; private int r,w ; public Queue(){ data=new int[INIT]; } public boolean isEmpty(){ return r==w ; } public void enqueue(int x){ if(w>=data.length){ data=grow(data); } data[w++]=x ; } public int getFront(){ return data[r]; } public void dequeue(){ if(! isEmpty()){ r++; } } } public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int n=sc.nextInt(); Queue[] qq=new Queue[n]; for(int i=0 ; isize() * 2)->collect(0) ; for _x : Integer.subrange(1,s->size()) do d[0 + _x] := s[0 + _x] ; return d ); static class Queue { attribute data : Sequence(int); attribute r : int; static operation newQueue() : Queue pre: true post: true activity: ( var self : Queue ; self := createQueue(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( data := Integer.subrange(1,INIT)->collect(0) ); operation isEmpty() : boolean pre: true post: true activity: ( return r = w ); operation enqueue( x : int) : void pre: true post: true activity: ( if (w >= data->size()) then ( data := grow(data) ) else skip ; data[w+1] := x ; w := w + 1 ); operation getFront() : int pre: true post: true activity: ( return data[r+1] ); operation dequeue() : void pre: true post: true activity: ( if (not(isEmpty())) then ( r := r + 1 ) else skip ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var qq : Sequence(Sequence) ; qq := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( qq[i+1] := Sequence{} ) ; i := i + 1 ) ; var q : int ; q := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var c : int ; c := sc.getCurrent()->toInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (c) ; if _switchval = 0 then var x : int ; x := sc.getCurrent()->toInteger() ; qq[t+1].enqueue(x) ; break else skip ; if _switchval = 1 then if (not(qq[t+1]->isEmpty())) then ( OclFile["System.out"].println(((qq[t+1].getFront()) + "")) ) else skip ; break else skip ; if _switchval = 2 then qq[t+1].dequeue() ; break else skip ; ) ) ; i := i + 1 ) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.ArrayList ; import java.lang.*; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] s=br.readLine().split(" ",0); int n=Integer.parseInt(s[0]); int q=Integer.parseInt(s[1]); Queue[] queues=new Queue[n]; for(int i=0 ; ia ; Queue(){ a=new ArrayList(); } void enqueue(int x){ a.add(x); } void front(){ int size=a.size(); if(size!=0){ System.out.println(a.get(0)); } } void dequeue(){ int size=a.size(); if(size!=0){ a.remove(0); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var s : Sequence(String) ; s := br.readLine()->split(" ") ; var n : int ; n := (s[0+1])->toInteger() ; var q : int ; q := (s[1+1])->toInteger() ; var queues : Sequence(Sequence) ; queues := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( queues[i+1] := Sequence{} ) ; i := i + 1 ) ; var l : Sequence(String) ; var command : String ; var t : int ; var x : int ; var i : int ; i := 0 ; while i < q do ( ( l := br.readLine()->split(" ") ; command := l[0+1] ; t := (l[1+1])->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (command) ; if _switchval = "0" then x := (l[2+1])->toInteger() ; queues[t+1].enqueue(x) ; break else skip ; if _switchval = "1" then queues[t+1].front() ; break else skip ; if _switchval = "2" then queues[t+1].dequeue() ; break else skip ; ) ) ; i := i + 1 ) ; ); } class Queue { attribute a : Sequence(int); static operation newQueue() : Queue pre: true post: true activity: ( var self : Queue ; self := createQueue(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( a := Sequence{} ); operation enqueue( x : int) : void pre: true post: true activity: ( a := a->including(x) ); operation front() : void pre: true post: true activity: ( var size : int ; size := a->size() ; if (size /= 0) then ( OclFile["System.out"].println(a->at(0+1)) ) else skip ); operation dequeue() : void pre: true post: true activity: ( var size : int ; size := a->size() ; if (size /= 0) then ( a := a->excludingAt(0+1) ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); ArrayList>que=new ArrayList>(); int n=in.nextInt(),loop=in.nextInt(); for(int i=0 ; iq=new ArrayDeque<>(); que.add(q); } for(int i=0 ; itoInteger() ; var loop : int ; loop := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var q : Sequence(int) ; q := ArrayDeque.newArrayDeque() ; que := que->including(q) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < loop do ( ( var odr : int ; odr := (in.getCurrent())->toInteger() ; var index : int ; index := (in.getCurrent())->toInteger() ; for _x : Integer.subrange(1,1) do ( var _switchval : OclAny ; _switchval := (odr) ; if _switchval = 0 then que->at(index+1)->excludes((in.getCurrent())->toInteger()) ; break else skip ; if _switchval = 1 then if (not(que->at(index+1)->isEmpty())) then ( skip ) else skip ; break else skip ; if _switchval = 2 then if (not(que->at(index+1)->isEmpty())) then ( que := que->at(index+1).remove() ) else skip ; break else skip ; ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countPairs(int n){ int count=0 ; for(int x=1 ; x ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int n=sc.nextInt(); ArrayList>ar=new ArrayList<>(); for(int i=0 ; i()); int m=sc.nextInt(); for(int i=0 ; itoInteger() ; var ar : Sequence(Sequence(int)) ; ar := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ar := ar->including(ArrayDeque.newArrayDeque()) ; ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( var mode : int ; mode := sc.getCurrent()->toInteger() ; if (mode = 0) then ( ar := ar->at(sc.getCurrent()->toInteger()+1)->append(sc.getCurrent()->toInteger()) ) else if (mode = 1) then ( var temp : int ; temp := sc.getCurrent()->toInteger() ; if (ar->at(temp+1).peekFirst() /= null) then OclFile["System.out"].println(ar->at(temp+1)->first()) ; else skip ) else if (mode = 2) then ( var temp : int ; temp := sc.getCurrent()->toInteger() ; if (ar->at(temp+1).peekFirst() /= null) then ar := ar->at(temp+1)->tail() ; else skip ) else skip ; ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.LinkedHashSet ; import java.util.Scanner ; import java.util.Set ; public class Festive834B { public static void main(String[] args){ Scanner in=new Scanner(System.in); int guest=in.nextInt(); int guard=in.nextInt(); String s=in.next(); Set set=new LinkedHashSet(); int[] arr=new int[26]; String ans="NO" ; for(int i=0 ; iguard){ ans="YES" ; break ; } if(arr[s.charAt(i)-'A']==i)set.remove(s.charAt(i)); } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Festive834B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var guest : int ; guest := in.getCurrent()->toInteger() ; var guard : int ; guard := in.getCurrent()->toInteger() ; var s : String ; s := in.getCurrent() ; var set : Set ; set := Set{} ; var arr : Sequence(int) ; arr := Integer.subrange(1,26)->collect(0) ; var ans : String ; ans := "NO" ; var i : int ; i := 0 ; while i < guest do ( ( arr[s->at(i+1) - ('A')->char2byte()+1] := i ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < guest do ( ( set := set->including(s->at(i+1)) ; if (set->size() > guard) then ( ans := "YES" ; break ) else skip ; if (arr[s->at(i+1) - ('A')->char2byte()+1] = i) then set := set->excludingFirst(s->at(i+1)) ; else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int numberOfGuests=sc.nextInt(); int numberOfGuards=sc.nextInt(); char[] letters=sc.next().toCharArray(); if(numberOfGuests==0){ System.out.println("NO"); return ; } boolean[] isDoorGuarded=new boolean[26]; int usedGuards=0 ; boolean isAtLeastOneDoorUnguarded=false ; for(int i=0 ; inumberOfGuards){ isAtLeastOneDoorUnguarded=true ; break ; } boolean isCurrentGuestTheLast=true ; for(int j=i+1 ; jtoInteger() ; var numberOfGuards : int ; numberOfGuards := sc.getCurrent()->toInteger() ; var letters : Sequence(String) ; letters := sc.getCurrent()->characters() ; if (numberOfGuests = 0) then ( OclFile["System.out"].println("NO") ; return ) else skip ; var isDoorGuarded : Sequence(boolean) ; isDoorGuarded := Integer.subrange(1,26)->collect(false) ; var usedGuards : int ; usedGuards := 0 ; var isAtLeastOneDoorUnguarded : boolean ; isAtLeastOneDoorUnguarded := false ; var i : int ; i := 0 ; while i < letters->size() do ( ( var currentDoorLetter : String ; currentDoorLetter := letters[i+1] ; if (not(isDoorGuarded[(currentDoorLetter)->char2byte() - ('A')->char2byte()+1])) then ( isDoorGuarded[(currentDoorLetter)->char2byte() - ('A')->char2byte()+1] := true ; usedGuards := usedGuards + 1 ) else skip ; if (usedGuards > numberOfGuards) then ( isAtLeastOneDoorUnguarded := true ; break ) else skip ; var isCurrentGuestTheLast : boolean ; isCurrentGuestTheLast := true ; var j : int ; j := i + 1 ; while j < letters->size() do ( ( if (letters[j+1] = currentDoorLetter) then ( isCurrentGuestTheLast := false ; break ) else skip ) ; j := j + 1 ) ; if (isCurrentGuestTheLast) then ( usedGuards := usedGuards - 1 ; isDoorGuarded[(currentDoorLetter)->char2byte() - ('A')->char2byte()+1] := false ) else skip ; ) ; i := i + 1 ) ; if (isAtLeastOneDoorUnguarded) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; public class WriteNow { public static HashSetset=new HashSet<>(); public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); if(k==26){ System.out.println("NO"); return ; } char[] str=scan.next().toCharArray(); int[] arr=new int[26]; HashSetset=new HashSet<>(); for(int i=0 ; itoInteger() ; var k : int ; k := scan.getCurrent()->toInteger() ; if (k = 26) then ( OclFile["System.out"].println("NO") ; return ) else skip ; var str : Sequence(String) ; str := scan.getCurrent()->characters() ; var arr : Sequence(int) ; arr := Integer.subrange(1,26)->collect(0) ; var set : Set(String) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( arr[(str[i+1] - ('A')->char2byte())+1] := arr[(str[i+1] - ('A')->char2byte())+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (not(set->includes(str[i+1]))) then ( k := k - 1 ; if (k < 0) then ( OclFile["System.out"].println("YES") ; return ) else skip ; set := set->including(str[i+1]) ) else skip ; if ((arr[str[i+1] - ('A')->char2byte()+1] - 1) = 0) then ( k := k + 1 ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("NO") ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static void main(String[] args){ int i,j,k,sp,space=4 ; char prt='$' ; for(i=1 ; i<=5 ; i++){ for(sp=space ; sp>=1 ; sp--){ System.out.print(" "); } for(j=1 ; j<=i ; j++){ System.out.print(prt); } for(k=1 ; k<=(i-1); k++){ if(i==1){ continue ; } System.out.print(prt); } System.out.println(); space--; } space=1 ; for(i=4 ; i>=1 ; i--){ for(sp=space ; sp>=1 ; sp--){ System.out.print(" "); } for(j=1 ; j<=i ; j++){ System.out.print(prt); } for(k=1 ; k<=(i-1); k++){ System.out.print(prt); } space++; System.out.println(); } space=3 ; for(i=2 ; i<=5 ; i++){ if((i % 2)!=0){ for(sp=space ; sp>=1 ; sp--){ System.out.print(" "); } for(j=1 ; j<=i ; j++){ System.out.print(prt); } } if((i % 2)!=0){ System.out.println(); space--; } } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var i : int ; var j : int ; var k : int ; var sp : int ; var space : int ; space := 4 ; var prt : String ; prt := '$' ; i := 1 ; while i <= 5 do ( ( sp := space ; while sp >= 1 do ( ( OclFile["System.out"].print(" ") ) ; sp := sp - 1 ) ; j := 1 ; while j <= i do ( ( OclFile["System.out"].print(prt) ) ; j := j + 1 ) ; k := 1 ; while k <= (i - 1) do ( ( if (i = 1) then ( continue ) else skip ; OclFile["System.out"].print(prt) ) ; k := k + 1 ) ; OclFile["System.out"].println() ; space := space - 1 ; ) ; i := i + 1 ) ; space := 1 ; i := 4 ; while i >= 1 do ( ( sp := space ; while sp >= 1 do ( ( OclFile["System.out"].print(" ") ) ; sp := sp - 1 ) ; j := 1 ; while j <= i do ( ( OclFile["System.out"].print(prt) ) ; j := j + 1 ) ; k := 1 ; while k <= (i - 1) do ( ( OclFile["System.out"].print(prt) ) ; k := k + 1 ) ; space := space + 1 ; OclFile["System.out"].println() ; ) ; i := i - 1 ) ; space := 3 ; i := 2 ; while i <= 5 do ( ( if ((i mod 2) /= 0) then ( sp := space ; while sp >= 1 do ( ( OclFile["System.out"].print(" ") ) ; sp := sp - 1 ) ; j := 1 ; while j <= i do ( ( OclFile["System.out"].print(prt) ) ; j := j + 1 ) ) else skip ; if ((i mod 2) /= 0) then ( OclFile["System.out"].println() ; space := space - 1 ) else skip ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static final int MOD=1000000007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0 ; itoInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; arr := arr->sort() ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] /= (i + n mod 2) / 2 * 2 + (n + 1) mod 2) then ( OclFile["System.out"].println(0) ; return ) else skip ) ; i := i + 1 ) ; var ans : int ; ans := 1 ; var i : int ; i := 0 ; while i < n / 2 do ( ( ans := ans*(2) ; ans := ans mod MOD ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static long[] count_color=new long[2]; static void dfs(Vectoradj[],int node,int parent,boolean color){ count_color[color==false ? 0 : 1]++; for(int i=0 ; iadj[],int n){ dfs(adj,1,0,false); return(int)(count_color[0]*count_color[1]-(n-1)); } public static void main(String[] args){ int n=5 ; Vector[] adj=new Vector[n+1]; for(int i=0 ; i(); adj[1] .add(2); adj[1] .add(3); adj[2] .add(4); adj[3] .add(5); System.out.println(findMaxEdges(adj,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute count_color : Sequence(long) := Integer.subrange(1,2)->collect(0); static operation dfs( adj : Sequence(Sequence(int)), node : int, parent : int, color : boolean) : void pre: true post: true activity: ( count_color[if color = false then 0 else 1 endif+1] := count_color[if color = false then 0 else 1 endif+1] + 1 ; var i : int ; i := 0 ; while i < adj[node+1]->size() do ( ( if (adj[node+1]->at(i+1) /= parent) then execute dfs(adj, adj[node+1]->at(i+1), node, not(color)) ; else skip ) ; i := i + 1 ) ); static operation findMaxEdges( adj : Sequence(Sequence(int)), n : int) : int pre: true post: true activity: ( execute dfs(adj, 1, 0, false) ; return (count_color[0+1] * count_color[1+1] - (n - 1))->oclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 5 ; var adj : Sequence(Sequence(int)) ; adj := Integer.subrange(1,n + 1)->collect(null) ; var i : int ; i := 0 ; while i < n + 1 do ( adj[i+1] := Sequence{} ; ; i := i + 1 ) ; adj[1+1]->excludes(2) ; adj[1+1]->excludes(3) ; adj[2+1]->excludes(4) ; adj[3+1]->excludes(5) ; OclFile["System.out"].println(findMaxEdges(adj, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static int digSum(int n){ if(n==0)return 0 ; return(n % 9==0)? 9 :(n % 9); } static int powerDigitSum(int a,int n){ int res=1 ; while(n>0){ if(n % 2==1){ res=res*digSum(a); res=digSum(res); } a=digSum(digSum(a)*digSum(a)); n/=2 ; } return res ; } public static void main(String args[]){ int a=9,n=4 ; System.out.print(powerDigitSum(a,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation digSum( n : int) : int 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 ); static operation powerDigitSum( a : int, n : int) : int pre: true post: true activity: ( var res : int ; res := 1 ; while (n > 0) do ( if (n mod 2 = 1) then ( res := res * digSum(a) ; res := digSum(res) ) else skip ; a := digSum(digSum(a) * digSum(a)) ; n := n/(2) ) ; return res ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 9 ; var n : int ; n := 4 ; OclFile["System.out"].print(powerDigitSum(a, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class GFG { static int maxLength(int arr[],int N){ int product=1,len=0 ; for(int i=0 ; i=0){ return N ; } for(int i=0 ; i= 0) then ( return N ) else skip ; var i : int ; i := 0 ; while i < N do ( ( if (arr[i+1] < 0) then ( len := Set{len, Set{N - i - 1, i}->max()}->max() ) else skip ) ; i := i + 1 ) ; return len ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{-1,1,1,-2,3,2,-1} ; var N : int ; N := arr->size() ; OclFile["System.out"].println(maxLength(arr, N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static VectorgetArray(int n){ Vectorans=new Vector(); long p2=1 ; while(n>0){ if(n % 2==1)ans.add(p2); n>>=1 ; p2*=2 ; } return ans ; } public static void main(String[] args){ int n=15 ; Vectorans=getArray(n); for(Long i : ans)System.out.print(i+" "); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getArray( n : int) : Sequence(long) pre: true post: true activity: ( var ans : Sequence(long) ; ans := Sequence{} ; var p2 : long ; p2 := 1 ; while (n > 0) do ( if (n mod 2 = 1) then ans := ans->including(p2) ; else skip ; n := n/(2->pow(1)) ; p2 := p2*(2) ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 15 ; var ans : Sequence(long) ; ans := getArray(n) ; for (i : ans) do ( OclFile["System.out"].print(i + " ") ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int countPairs(int n){ int count=0 ; for(int x=1 ; xsize() ; var D : int ; D := 5 ; var A : int ; A := 4 ; var B : int ; B := 2 ; OclFile["System.out"].println(findPossibleDerivables(arr, n, D, A, B)) ; var a : Sequence(int) ; a := Sequence{1,2,3} ; n := a->size() ; D := 6 ; A := 3 ; B := 2 ; OclFile["System.out"].println(findPossibleDerivables(a, n, D, A, B)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.io.*; class GFG { static int closetAND(int arr[],int n,int k){ int ans=Integer.MAX_VALUE ; for(int i=0 ; imin() ) ; j := j + 1 ) ) ; i := i + 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{4,7,10} ; var n : int ; n := arr->size() ; var k : int ; k := 2 ; OclFile["System.out"].println(closetAND(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String input[]=br.readLine().split("\\s+"); BigInteger A=new BigInteger(input[0]); BigInteger B=new BigInteger(input[1]); BigInteger ans ; ans=A.divide(B); System.out.println(ans); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute BIG_NUM : int := 2000000000; static attribute MOD : int := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var input : Sequence(String) ; input := br.readLine()->split("\\s+") ; var A : long ; A := long(input[0+1]) ; var B : long ; B := long(input[1+1]) ; var ans : long ; ans := A.divide(B) ; OclFile["System.out"].println(ans) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); BigInteger a=scan.nextBigInteger(); BigInteger b=scan.nextBigInteger(); System.out.println(a.divide(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var a : long ; a := scan.nextBigInteger() ; var b : long ; b := scan.nextBigInteger() ; OclFile["System.out"].println(a.divide(b)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(new BufferedInputStream(System.in)); while(in.hasNext()){ BigInteger a=in.nextBigInteger(),b=in.nextBigInteger(); System.out.println(a.divide(b)); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (in.hasNext()) do ( var a : long ; a := in.nextBigInteger() ; var b : long ; b := in.nextBigInteger() ; OclFile["System.out"].println(a.divide(b)) ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ String s ; Scanner reader=new Scanner(System.in); s=reader.nextLine(); String[] str ; str=s.split(" "); BigInteger a=new BigInteger(str[0]); BigInteger b=new BigInteger(str[1]); BigInteger c=a.divide(b); System.out.println(c); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile["System.in"]) ; s := reader.nextLine() ; var str : Sequence(String) ; str := s->split(" ") ; var a : long ; a := long(str[0+1]) ; var b : long ; b := long(str[1+1]) ; var c : long ; c := a.divide(b) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; class Solver { private final int[] A ; private final int N ; Solver(Scanner in){ N=in.nextInt(); A=new int[N]; for(int i=0 ; i=3){ System.out.println(0); return ; } } System.out.println(BigInteger.valueOf(2).modPow(BigInteger.valueOf(N/2),BigInteger.valueOf(1000000007)).intValue()); } } class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); new Solver(in).solve(); in.close(); } } ------------------------------------------------------------ OCL File: --------- class Solver { attribute A : Sequence(int); attribute N : int; static operation newSolver( in : OclFile) : Solver pre: true post: true activity: ( var self : Solver ; self := createSolver(); self.initialise(in); return self ); operation initialise( in : OclFile) : void pre: true post: true activity: ( N := in.nextInt() ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := in.nextInt() ) ; i := i + 1 ) ); operation solve() : void pre: true post: true activity: ( var count : Sequence(int) ; count := Integer.subrange(1,N)->collect(0) ; count[0+1] := count[0+1] + 1 ; for (a : A) do ( ( count[a+1] := count[a+1] + 1 ; if (count[a+1] >= 3) then ( OclFile["System.out"].println(0) ; return ) else skip ) ) ; OclFile["System.out"].println((2 + "")->toLong().modPow((N / 2 + "")->toLong(), (1000000007 + "")->toLong())->oclAsType(int)) ); } class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; Solver.newSolver(in).solve() ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; import java.util.*; public class Main { public static void main(String[] args){ BigInteger a,b ; Scanner cin=new Scanner(System.in); a=cin.nextBigInteger(); b=cin.nextBigInteger(); System.out.println(a.divide(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : long ; var b : long ; var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; a := cin.nextBigInteger() ; b := cin.nextBigInteger() ; OclFile["System.out"].println(a.divide(b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String input[]=br.readLine().split("\\s+"); BigInteger A=new BigInteger(input[0]); BigInteger B=new BigInteger(input[1]); BigInteger ans ; ans=A.multiply(B); System.out.println(ans); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute BIG_NUM : int := 2000000000; static attribute MOD : int := 1000000007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var input : Sequence(String) ; input := br.readLine()->split("\\s+") ; var A : long ; A := long(input[0+1]) ; var B : long ; B := long(input[1+1]) ; var ans : long ; ans := A.multiply(B) ; OclFile["System.out"].println(ans) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; import java.util.*; public class Main { public static void main(String[] args){ BigInteger a,b ; Scanner cin=new Scanner(System.in); a=cin.nextBigInteger(); b=cin.nextBigInteger(); System.out.println(a.multiply(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : long ; var b : long ; var cin : OclFile ; cin := OclFile.newOclFile_Read(OclFile["System.in"]) ; a := cin.nextBigInteger() ; b := cin.nextBigInteger() ; OclFile["System.out"].println(a.multiply(b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class Solution { public int longestPalindrome(String s){ int[] count=new int[128]; for(char c : s.toCharArray())count[c]++; int ans=0 ; for(int v : count){ ans+=v/2*2 ; if(ans % 2==0 && v % 2==1)ans++; } return ans ; } } ------------------------------------------------------------ OCL File: --------- class Solution { operation longestPalindrome( s : String) : int pre: true post: true activity: ( var count : Sequence(int) ; count := Integer.subrange(1,128)->collect(0) ; for (c : s->characters()) do ( count[c+1] := count[c+1] + 1 ; ) ; var ans : int ; ans := 0 ; for (v : count) do ( ( ans := ans+(v / 2 * 2) ; if (ans mod 2 = 0 & v mod 2 = 1) then ans := ans + 1 ; else skip ) ) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedInputStream ; import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner in=new Scanner(new BufferedInputStream(System.in)); while(in.hasNext()){ BigInteger a=in.nextBigInteger(),b=in.nextBigInteger(); System.out.println(a.multiply(b)); } in.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; while (in.hasNext()) do ( var a : long ; a := in.nextBigInteger() ; var b : long ; b := in.nextBigInteger() ; OclFile["System.out"].println(a.multiply(b)) ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); BigInteger a=new BigInteger(str); str=sc.next(); BigInteger b=new BigInteger(str); System.out.println(a.multiply(b)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str : String ; str := sc.getCurrent() ; var a : long ; a := long(str) ; str := sc.getCurrent() ; var b : long ; b := long(str) ; OclFile["System.out"].println(a.multiply(b)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.Scanner ; public class Main { public static void main(String[] args){ String s ; Scanner reader=new Scanner(System.in); s=reader.nextLine(); String[] str ; str=s.split(" "); BigInteger a=new BigInteger(str[0]); BigInteger b=new BigInteger(str[1]); BigInteger c=a.multiply(b); System.out.println(c); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile["System.in"]) ; s := reader.nextLine() ; var str : Sequence(String) ; str := s->split(" ") ; var a : long ; a := long(str[0+1]) ; var b : long ; b := long(str[1+1]) ; var c : long ; c := a.multiply(b) ; OclFile["System.out"].println(c) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws java.io.IOException { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); while(n!=0){ int a[]=new int[n]; for(int i=0 ; itoInteger() ; while (n /= 0) do ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ; var b : Sequence(int) ; b := Sequence{0,0,0,0,0,0,0} ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1] < 10) then ( b[0+1] := b[0+1] + 1 ) else if (a[i+1] < 20) then ( b[1+1] := b[1+1] + 1 ) else if (a[i+1] < 30) then ( b[2+1] := b[2+1] + 1 ) else if (a[i+1] < 40) then ( b[3+1] := b[3+1] + 1 ) else if (a[i+1] < 50) then ( b[4+1] := b[4+1] + 1 ) else if (a[i+1] < 60) then ( b[5+1] := b[5+1] + 1 ) else ( b[6+1] := b[6+1] + 1 ) ; ; ; ; ; ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 7 do ( ( OclFile["System.out"].println(b[i+1]) ) ; i := i + 1 ) ; n := scan.getCurrent()->toInteger() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { public void run(java.io.InputStream in,java.io.PrintStream out){ java.util.Scanner sc=new java.util.Scanner(in); int[] a,count ; int i,j,n ; count=new int[7]; for(; ; ){ n=sc.nextInt(); if(n==0)break ; a=new int[n]; for(i=0 ; icollect(0) ; while true do ( ( n := sc.nextInt() ; if (n = 0) then break else skip ; a := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < n do ( a[i+1] := sc.nextInt() ; ; i := i + 1 ) ; i := 0 ; while i < 7 do ( count[i+1] := 0 ; ; i := i + 1 ) ; i := 0 ; while i < n do ( ( j := 10 ; while j < 70 do ( if (a[i+1] < j) then ( count[j / 10 - 1+1] := count[j / 10 - 1+1] + 1 ; break ) else skip ; ; j := j+(10) ) ; if (j = 70) then count[j / 10 - 1+1] := count[j / 10 - 1+1] + 1 ; else skip ) ; i := i + 1 ) ; i := 0 ; while i < 7 do ( out.println(count[i+1]) ; ; i := i + 1 ) ; ) ) ; sc.close() ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(OclFile["System.in"], OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { Scanner sc=new Scanner(System.in); public static void main(String[] args){ new Main(); } public Main(){ new A().doIt(); } class A { void cnt(int num,int a[]){ if(num<10)a[0]++; else if(num<20)a[1]++; else if(num<30)a[2]++; else if(num<40)a[3]++; else if(num<50)a[4]++; else if(num<60)a[5]++; else a[6]++; } void doIt(){ while(true){ int n=Integer.parseInt(sc.next()); if(n==0)break ; int a[]=new int[7]; for(int i=0 ; itoInteger() ; if (n = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,7)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var num : int ; num := (sc.getCurrent())->toInteger() ; execute cnt(num, a) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 7 do ( OclFile["System.out"].println(a[i+1]) ; ; i := i + 1 ) ; ) ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { private static boolean isPossible(int n,int[] counter){ if(n % 2==0){ for(int i=1 ; itoInteger() ; var counter : Sequence(int) ; counter := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( counter[(s.getCurrent())->toInteger()+1] := counter[(s.getCurrent())->toInteger()+1] + 1 ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(n, counter)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.util.Arrays.deepToString ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().run(); } void tr(Object...os){ System.err.println(deepToString(os)); } Scanner sc=new Scanner(System.in); public void run(){ for(; sc.hasNext(); ){ int n=sc.nextInt(); if(n==0)break ; int[] count=new int[7]; while(n-->0){ int x=sc.nextInt(); if(x>=60)x=60 ; count[x/10]++; } for(int x : count)System.out.println(x); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation tr( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); operation run() : void pre: true post: true activity: ( while sc.hasNext() do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; if (n = 0) then break else skip ; var count : Sequence(int) ; count := Integer.subrange(1,7)->collect(0) ; while (n > 0) do ( n := n - 1 ; skip ; ( var x : int ; x := sc.getCurrent()->toInteger() ; if (x >= 60) then x := 60 ; else skip ; count[x / 10+1] := count[x / 10+1] + 1 ) ; ) ; for (x : count) do ( OclFile["System.out"].println(x) ; ) ; ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int TrialDivision(int N){ int i=2 ; int k=(int)Math.ceil(Math.sqrt(N)); while(i<=k){ if(N % i==0)return 0 ; i+=1 ; } return 1 ; } public static void main(String[] args){ int N=49 ; int p=TrialDivision(N); if(p!=0)System.out.print("Prime"); else System.out.print("Composite"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation TrialDivision( N : int) : int pre: true post: true activity: ( var i : int ; i := 2 ; var k : int ; k := ((N)->sqrt())->ceil()->oclAsType(int) ; while (i <= k) do ( if (N mod i = 0) then return 0 else skip ; i := i+(1) ) ; return 1 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 49 ; var p : int ; p := TrialDivision(N) ; if (p /= 0) then OclFile["System.out"].print("Prime") ; else OclFile["System.out"].print("Composite") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long binomialCoeff(int n,int k){ long res=1 ; if(k>n-k)k=n-k ; for(int i=0 ; i n - k) then k := n - k ; else skip ; var i : int ; i := 0 ; while i < k do ( ( res := res*((n - i)) ; res := res/((i + 1)) ) ; i := i + 1 ) ; return res ); static operation catalan( n : int) : long pre: true post: true activity: ( var c : long ; c := binomialCoeff(2 * n, n) ; return c / (n + 1) ); static operation findWays( n : int) : long pre: true post: true activity: ( if ((n & 1) /= 0) then return 0 else skip ; return catalan(n / 2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; OclFile["System.out"].println("Total possible expressions of length " + n + " is " + findWays(6)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int maxSum(int arr[],int n,int k){ if(nmax() ) ; i := i + 1 ) ; return max_sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,4,2,10,2,3,1,0,20} ; var k : int ; k := 4 ; var n : int ; n := arr->size() ; OclFile["System.out"].println(maxSum(arr, n, k)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Space { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int i=1 ; i<=T ; i++){ int L=sc.nextInt(); long t=sc.nextLong(); int N=sc.nextInt(); int C=sc.nextInt(); long time=t ; int[] a=new int[1000001]; for(int j=0 ; j0 && index(t/2)){ a[index]-=t/2 ; t=-1 ; } else { t-=a[index]*2 ; index++; } } if(t>0){ time-=t ; } if(index=index ; j--){ if(L>0){ time+=a[j]; L--; } else { time+=a[j]*2 ; } } } System.out.println("Case #"+i+": "+time); } } } ------------------------------------------------------------ OCL File: --------- class Space { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var T : int ; T := sc.getCurrent()->toInteger() ; var i : int ; i := 1 ; while i <= T do ( ( var L : int ; L := sc.getCurrent()->toInteger() ; var t : long ; t := sc.getCurrent()->toLong() ; var N : int ; N := sc.getCurrent()->toInteger() ; var C : int ; C := sc.getCurrent()->toInteger() ; var time : long ; time := t ; var a : Sequence(int) ; a := Integer.subrange(1,1000001)->collect(0) ; var j : int ; j := 0 ; while j < C do ( ( a[j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ; var j : int ; j := C ; while j < N do ( ( a[j+1] := a[j - C+1] ) ; j := j + 1 ) ; var index : int ; index := 0 ; while (t > 0 & index < N) do ( if (a[index+1] > (t / 2)) then ( a[index+1] := a[index+1]-(t / 2) ; t := -1 ) else ( t := t-(a[index+1] * 2) ; index := index + 1 ) ) ; if (t > 0) then ( time := time-(t) ) else skip ; if (index < N) then ( a := a.subrange(1,index)^(a.subrange(index+1,N->oclAsType(int))->sort())^a.subrange(N->oclAsType(int)+1,a.size) ; var j : int ; j := (N - 1)->oclAsType(int) ; while j >= index do ( ( if (L > 0) then ( time := time+(a[j+1]) ; L := L - 1 ) else ( time := time+(a[j+1] * 2) ) ) ; j := j - 1 ) ) else skip ; OclFile["System.out"].println("Case #" + i + ": " + time) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.ArrayList ; import java.util.Collections ; import java.util.List ; import java.util.Scanner ; public class BL { private static final String FILE_NAME="B-large" ; public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new FileReader(FILE_NAME+".in")); Scanner scanner=new Scanner(in); BufferedWriter out=new BufferedWriter(new FileWriter(FILE_NAME+"L.out")); int t=scanner.nextInt(); for(int c=1 ; c<=t ; ++c){ int speedN=scanner.nextInt(); long speedT=scanner.nextLong(); int n=scanner.nextInt(); int cc=scanner.nextInt(); long totalTime=0 ; ListsavedTimes=new ArrayList(); int[] d=new int[cc]; for(int i=0 ; i=speedT){ savedTimes.add((long)time/2); } else if(totalTime+time>speedT){ savedTimes.add(((totalTime+time)-speedT)/2); } totalTime+=time ; } Collections.sort(savedTimes); int len=savedTimes.size(); for(int i=0 ; itoInteger() ; var c : int ; c := 1 ; while c <= t do ( ( var speedN : int ; speedN := scanner.getCurrent()->toInteger() ; var speedT : long ; speedT := scanner.getCurrent()->toLong() ; var n : int ; n := scanner.getCurrent()->toInteger() ; var cc : int ; cc := scanner.getCurrent()->toInteger() ; var totalTime : long ; totalTime := 0 ; var savedTimes : Sequence(long) ; savedTimes := Sequence{} ; var d : Sequence(int) ; d := Integer.subrange(1,cc)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( var time : int ; if (i < cc) then ( d[i+1] := 2 * scanner.getCurrent()->toInteger() ; time := d[i+1] ) else ( time := d[i mod cc+1] ) ; if (totalTime >= speedT) then ( savedTimes := savedTimes->including(time->oclAsType(long) / 2) ) else if (totalTime + time > speedT) then ( savedTimes := savedTimes->including(((totalTime + time) - speedT) / 2) ) else skip ; ; totalTime := totalTime+(time) ) ; i := i + 1 ) ; savedTimes := savedTimes->sort() ; var len : int ; len := savedTimes->size() ; var i : int ; i := 0 ; while i < speedN & i < len do ( ( totalTime := totalTime-(savedTimes->at(len - i - 1+1)) ) ; i := i + 1 ) ; var ans : String ; ans := StringLib.newString() ; ans := ans + StringLib.newString("Case #") ; ans := ans + StringLib.newString(c) ; ans := ans + StringLib.newString(": ") ; ans := ans + StringLib.newString(totalTime) ; skip ; OclFile["System.out"].println(ans+"") ; ) ; c := c + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Solution { public void doMain()throws Exception { Scanner sc=new Scanner(new FileReader("input.txt")); PrintWriter pw=new PrintWriter(new FileWriter("output.txt")); int T=sc.nextInt(); for(int caseNum=1 ; caseNum<=T ; caseNum++){ System.out.println("case "+caseNum); int L=sc.nextInt(); long t=sc.nextLong(); int N=sc.nextInt(); int C=sc.nextInt(); long[] a=new long[N]; for(int i=0 ; ill=new ArrayList(); ll.add(2*a[pos]-t); for(int i=pos+1 ; i=0 && i>=ll.size()-L ; i--){ res-=ll.get(i); } } if(res % 2==1){ System.out.println("failure"); System.exit(0); } else pw.println("Case #"+caseNum+": "+res/2); } sc.close(); pw.flush(); pw.close(); } public static void main(String[] args)throws Exception { (new Solution()).doMain(); } } ------------------------------------------------------------ OCL File: --------- class Solution { operation doMain() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) ; var T : int ; T := sc.getCurrent()->toInteger() ; var caseNum : int ; caseNum := 1 ; while caseNum <= T do ( ( OclFile["System.out"].println("case " + caseNum) ; var L : int ; L := sc.getCurrent()->toInteger() ; var t : long ; t := sc.getCurrent()->toLong() ; var N : int ; N := sc.getCurrent()->toInteger() ; var C : int ; C := sc.getCurrent()->toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < C do ( a[i+1] := sc.getCurrent()->toLong() ; ; i := i + 1 ) ; var i : int ; i := C ; while i < N do ( a[i+1] := a[i - C+1] ; ; i := i + 1 ) ; var res : long ; res := 0 ; var i : int ; i := 0 ; while i < N do ( res := res+(4 * a[i+1]) ; ; i := i + 1 ) ; var pos : int ; pos := 0 ; while (pos < N & 2 * a[pos+1] <= t) do ( t := t-(2 * a[pos+1]) ; pos := pos + 1 ) ; if (pos < N) then ( var ll : Sequence(long) ; ll := Sequence{} ; ll := ll->including(2 * a[pos+1] - t) ; var i : int ; i := pos + 1 ; while i < N do ( ll := ll->including(2 * a[i+1]) ; ; i := i + 1 ) ; ll := ll->sort() ; var i : int ; i := ll->size() - 1 ; while i >= 0 & i >= ll->size() - L do ( ( res := res-(ll->at(i+1)) ) ; i := i - 1 ) ; ) else skip ; if (res mod 2 = 1) then ( OclFile["System.out"].println("failure") ; OclProcess.exit(0) ) else skip ; ; ) ; caseNum := caseNum + 1 ) ; skip ; skip ; skip ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Solution.newSolution()).doMain() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- package CodeJam ; import java.util.*; import java.io.*; public class B { private static String inFilename="B-large.in" ; public static void main(String[] args)throws IOException { Scanner in=new Scanner(new FileReader("src/CodeJam/"+inFilename)); PrintWriter out=new PrintWriter(new FileWriter("src/CodeJam/output.txt")); int T=in.nextInt(); for(int tt=0 ; tt=0 ; l++){ result+=left[j--]; } for(int k=j ; k>=0 ; k--){ result+=left[k]*2 ; } break ; } } out.print("Case #"+(tt+1)+": "+result+"\n"); } in.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class B { static attribute inFilename : String := "B-large.in"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read("src/CodeJam/" + inFilename)) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("src/CodeJam/output.txt"))) ; var T : int ; T := in.getCurrent()->toInteger() ; var tt : int ; tt := 0 ; while tt < T do ( ( var result : long ; result := 0 ; var L : int ; L := in.getCurrent()->toInteger() ; var t : long ; t := in.getCurrent()->toLong() ; var N : int ; N := in.getCurrent()->toInteger() ; var C : int ; C := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,C)->collect(0) ; var i : int ; i := 0 ; while i < C do ( ( a[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var d : Sequence(int) ; d := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( d[i+1] := a[i mod C+1] ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( if (result + d[i+1] * 2 <= t) then ( result := result+(d[i+1] * 2) ) else ( var left0 : int ; left0 := (d[i+1] - (t - result) / 2)->oclAsType(int) ; result := t ; var left : Sequence(int) ; left := Integer.subrange(1,N - i)->collect(0) ; left[0+1] := left0 ; var j : int ; j := 1 ; while j < N - i do ( ( left[j+1] := d[i + j+1] ) ; j := j + 1 ) ; left := left->sort() ; var j : int ; j := left->size() - 1 ; var l : int ; l := 0 ; while l < L & j >= 0 do ( ( result := result + left[j+1] ; j := j - 1 ) ; l := l + 1 ) ; var k : int ; k := j ; while k >= 0 do ( ( result := result+(left[k+1] * 2) ) ; k := k - 1 ) ; break ) ) ; i := i + 1 ) ; skip ; ) ; tt := tt + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static void maxProduct(int arr[],int n){ if(n<2){ System.out.println("No pairs exists"); return ; } if(n==2){ System.out.println(arr[0]+" "+arr[1]); return ; } int posa=Integer.MIN_VALUE,posb=Integer.MIN_VALUE ; int nega=Integer.MIN_VALUE,negb=Integer.MIN_VALUE ; for(int i=0 ; iposa){ posb=posa ; posa=arr[i]; } else if(arr[i]>posb)posb=arr[i]; if(arr[i]<0 && Math.abs(arr[i])>Math.abs(nega)){ negb=nega ; nega=arr[i]; } else if(arr[i]<0 && Math.abs(arr[i])>Math.abs(negb))negb=arr[i]; } if(nega*negb>posa*posb)System.out.println("Max product pair is {"+nega+","+negb+"}"); else System.out.println("Max product pair is {"+posa+","+posb+"}"); } public static void main(String[] args){ int arr[]={ 1,4,3,6,7,0 }; int n=arr.length ; maxProduct(arr,n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation maxProduct( arr : Sequence(int), n : int) : void pre: true post: true activity: ( if (n < 2) then ( OclFile["System.out"].println("No pairs exists") ; return ) else skip ; if (n = 2) then ( OclFile["System.out"].println(arr[0+1] + " " + arr[1+1]) ; return ) else skip ; var posa : int ; posa := -2147483648 ; var posb : int ; posb := -2147483648 ; var nega : int ; nega := -2147483648 ; var negb : int ; negb := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( if (arr[i+1] > posa) then ( posb := posa ; posa := arr[i+1] ) else if (arr[i+1] > posb) then posb := arr[i+1] ; else skip ; ; if (arr[i+1] < 0 & if arr[i+1] < 0 then -(arr[i+1]) else arr[i+1] endif > if nega < 0 then -(nega) else nega endif) then ( negb := nega ; nega := arr[i+1] ) else if (arr[i+1] < 0 & if arr[i+1] < 0 then -(arr[i+1]) else arr[i+1] endif > if negb < 0 then -(negb) else negb endif) then negb := arr[i+1] ; else skip ; ) ; i := i + 1 ) ; if (nega * negb > posa * posb) then OclFile["System.out"].println("Max product pair is {" + nega + "," + negb + "}") else OclFile["System.out"].println("Max product pair is {" + posa + "," + posb + "}") ; ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,4,3,6,7,0} ; var n : int ; n := arr->size() ; execute maxProduct(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int calculateLeaps(int n){ if(n==0 || n==1){ return 1 ; } else { int leaps=0 ; for(int i=0 ; i ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner scanner ; public static void main(String[] args){ scanner=new Scanner(System.in); int N=gi(); int[] A=new int[N]; for(int i=0 ; i0){ a*=2 ; a=a % 1000000007 ; nn--; } System.out.println(a); } public static String gs(){ return scanner.next(); } public static int gi(){ return Integer.parseInt(scanner.next()); } public static long gl(){ return Long.parseLong(scanner.next()); } public static double gd(){ return Double.parseDouble(scanner.next()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute scanner : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := gi() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( A[i+1] := gi() ) ; i := i + 1 ) ; A := A->sort() ; if (N mod 2 = 0) then ( var i : int ; i := 0 ; while i < N do ( ( if (A[i+1] /= floorDiv(i + 2, 2) * 2 - 1) then ( OclFile["System.out"].println(0) ; return ) else skip ) ; i := i + 1 ) ) else ( var i : int ; i := 0 ; while i < N do ( ( if (A[i+1] /= floorDiv(i + 1, 2) * 2) then ( OclFile["System.out"].println(0) ; return ) else skip ) ; i := i + 1 ) ) ; var a : long ; a := 1 ; var nn : long ; nn := floorDiv(N, 2) ; while (nn > 0) do ( a := a*(2) ; a := a mod 1000000007 ; nn := nn - 1 ) ; OclFile["System.out"].println(a) ; ); static operation gs() : String pre: true post: true activity: ( return scanner.getCurrent() ); static operation gi() : int pre: true post: true activity: ( return (scanner.getCurrent())->toInteger() ); static operation gl() : long pre: true post: true activity: ( return (scanner.getCurrent())->toLong() ); static operation gd() : double pre: true post: true activity: ( return (scanner.getCurrent())->toReal() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class ex8 { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextLine(); int count=0 ; int flag=0 ; String s[]=new String[n]; for(int i=0 ; itoInteger() ; skip ; var count : int ; count := 0 ; var flag : int ; flag := 0 ; var s : Sequence(String) ; s := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := " " + sc.nextLine() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var res : String ; res := "" ; count := 0 ; var q : int ; q := 1 ; while q <= 12 do ( ( if (s[i+1]->at(q+1) = 'X') then ( res := " 1x12" ; count := count + 1 ; break ) else skip ) ; q := q + 1 ) ; var j : int ; j := 2 ; while j <= 6 do ( ( flag := 0 ; if (12 mod j = 0) then ( var k : int ; k := 1 ; while k <= 12 / j do ( ( flag := 0 ; var p : int ; p := k ; while p <= 12 do ( ( if (s[i+1]->at(p+1) = 'O') then ( flag := 1 ; break ) else skip ) ; p := p+(12 / j) ) ; if (flag = 0) then ( count := count + 1 ; res := res+(" " + j + "x" + 12 / j) ; break ) else skip ) ; k := k + 1 ) ) else skip ) ; j := j + 1 ) ; flag := 0 ; var l : int ; l := 1 ; while l <= 12 do ( ( if (s[i+1]->at(l+1) = 'O') then ( flag := 1 ; break ) else skip ) ; l := l + 1 ) ; if (flag = 0) then ( res := res+(" 12x1") ; count := count + 1 ) else skip ; OclFile["System.out"].printf("%d%s", count, res) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Geeks { static void ReplaceElements(int arr[],int n){ int max_ele=arr[0]; arr[0]=-1 ; for(int i=1 ; iarr[i])arr[i]=max_ele ; else if(max_ele<=arr[i]){ int temp=arr[i]; arr[i]=max_ele ; max_ele=temp ; } } } public static void main(String args[]){ int arr[]={ 4,5,2,1,7,6 }; int n=arr.length ; ReplaceElements(arr,n); for(int i=0 ; i arr[i+1]) then arr[i+1] := max_ele ; else if (max_ele <= arr[i+1]) then ( var temp : int ; temp := arr[i+1] ; arr[i+1] := max_ele ; max_ele := temp ) else skip ; ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{4,5,2,1,7,6} ; var n : int ; n := arr->size() ; execute ReplaceElements(arr, n) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].println(arr[i+1]) ; ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printString(char[] str,int n){ int ones=0 ; for(int i=0 ; isize() ; execute printString(str->characters(), n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findSmallNum(int N,int K){ int rem=N % K ; if(rem==0)return N ; else return N-rem ; } static int findLargeNum(int N,int K){ int rem=(N+K)% K ; if(rem==0)return N ; else return N+K-rem ; } static int sumDivisibles(int A,int B,int M){ int first=findSmallNum(A,M); int last=findLargeNum(B,M); if(firstB)first-=M ; int n=(B/M)-(A-1)/M ; return n*(first+last)/2 ; } public static void main(String[] args){ int A=6,B=15,M=3 ; System.out.print(sumDivisibles(A,B,M)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findSmallNum( N : int, K : int) : int pre: true post: true activity: ( var rem : int ; rem := N mod K ; if (rem = 0) then return N else return N - rem ); static operation findLargeNum( N : int, K : int) : int pre: true post: true activity: ( var rem : int ; rem := (N + K) mod K ; if (rem = 0) then return N else return N + K - rem ); static operation sumDivisibles( A : int, B : int, M : int) : int pre: true post: true activity: ( var first : int ; first := findSmallNum(A, M) ; var last : int ; last := findLargeNum(B, M) ; if (first < A) then first := first+(M) ; else skip ; if (last > B) then first := first-(M) ; else skip ; var n : int ; n := (B / M) - (A - 1) / M ; return n * (first + last) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var A : int ; A := 6 ; var B : int ; B := 15 ; var M : int ; M := 3 ; OclFile["System.out"].print(sumDivisibles(A, B, M)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class GFG { public static int getSum(int arr[],int n){ int i,sum=0 ; SethashSet=new HashSet<>(); for(i=0 ; iincluding(arr[i+1]) ; ; i := i + 1 ) ; i := 0 ; while i < n do ( ( var sqrtCurrent : double ; sqrtCurrent := (arr[i+1])->sqrt() ; if ((sqrtCurrent)->floor() /= (sqrtCurrent)->ceil()) then continue else skip ; if (hashSet->includes(sqrtCurrent->oclAsType(int))) then ( sum := sum+((sqrtCurrent * sqrtCurrent)) ) else skip ) ; i := i + 1 ) ; return sum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{2,4,5,6,7,8,9,3} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(getSum(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.TreeMap ; import java.util.TreeSet ; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] sa=br.readLine().split(" "); int h=Integer.parseInt(sa[0]); int n=Integer.parseInt(sa[2]); TreeMap>map=new TreeMap<>(); for(int i=0 ; iset=map.get(x); if(set==null){ set=new TreeSet<>(); map.put(x,set); } set.add(y); } br.close(); int x=1 ; int y=1 ; for(int k : map.keySet()){ TreeSetset=map.get(k); y+=k-x-1 ; if(set.floor(y)!=null){ System.out.println(k-1); return ; } if(! set.contains(y+1)){ y++; } x=k ; } System.out.println(h); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var sa : Sequence(String) ; sa := br.readLine()->split(" ") ; var h : int ; h := (sa[0+1])->toInteger() ; var n : int ; n := (sa[2+1])->toInteger() ; var map : Map(int,Set(int)) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( sa := br.readLine()->split(" ") ; var x : int ; x := (sa[0+1])->toInteger() ; var y : int ; y := (sa[1+1])->toInteger() ; var set : Set(int) ; set := map->at(x) ; if (set = null) then ( set := Set{} ; map := map->union(Map{x |-> set}) ) else skip ; set := set->including(y) ; ) ; i := i + 1 ) ; skip ; var x : int ; x := 1 ; var y : int ; y := 1 ; for (k : map->keys()) do ( ( var set : Set(int) ; set := map->at(k) ; y := y+(k - x - 1) ; if (set.floor(y) /= null) then ( OclFile["System.out"].println(k - 1) ; return ) else skip ; if (not(set->includes(y + 1))) then ( y := y + 1 ) else skip ; x := k ; ) ) ; OclFile["System.out"].println(h) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static int H=200000+11 ; static int W=200000+11 ; static List>heights=new ArrayList<>(H); public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int n=sc.nextInt(); for(int i=0 ; i=heights.size()){ heights.add(new TreeSet()); } else { heights.get(i).clear(); } heights.get(i).add(h); } for(int i=0 ; i=w){ break ; } if(! heights.get(current_w+1).contains(current_h)){ current_w+=1 ; } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute H : int := 200000 + 11; static attribute W : int := 200000 + 11; static attribute heights : Sequence(Set(int)) := Sequence{}; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < w do ( ( if (i >= heights->size()) then ( heights := heights->including(Set{}) ) else ( heights := heights->at(i+1)->intersection(Set{}) ) ; heights->at(i+1)->excludes(h) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var h_i : int ; h_i := sc.getCurrent()->toInteger() ; var w_i : int ; w_i := sc.getCurrent()->toInteger() ; h_i := h_i-(1) ; w_i := w_i-(1) ; heights->at(w_i+1)->excludes(h_i) ; ) ; i := i + 1 ) ; var current_h : int ; current_h := 0 ; var current_w : int ; current_w := 0 ; var ans : int ; ans := h ; while (current_h < h & current_w < w) do ( var hh : int ; hh := heights->at(current_w+1).higher(current_h) ; ans := Set{ans, hh}->min() ; current_h := current_h+(1) ; if (heights->at(current_w+1)->includes(current_h)) then ( break ) else skip ; if (current_w + 1 >= w) then ( break ) else skip ; if (not(heights->at(current_w + 1+1)->includes(current_h))) then ( current_w := current_w+(1) ) else skip ; ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; import java.util.TreeSet ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int n=sc.nextInt(); HashMap>map=new HashMap<>(); for(int i=1 ; i<=h ; i++){ map.put(i,new TreeSet<>()); } for(int i=0 ; iyMax+1){ yMax++; } } System.out.println(h); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var map : Map(int,Set(int)) ; map := Map{} ; var i : int ; i := 1 ; while i <= h do ( ( map := map->union(Map{i |-> Set{}}) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var x : int ; x := sc.getCurrent()->toInteger() ; var y : int ; y := sc.getCurrent()->toInteger() ; map->at(x)->excludes(y) ) ; i := i + 1 ) ; var yMax : int ; yMax := 1 ; var i : int ; i := 2 ; while i <= h do ( ( if (map->at(i)->isEmpty()) then ( yMax := yMax + 1 ) else if (map->at(i)->first() <= yMax) then ( OclFile["System.out"].println(i - 1) ; return ) else if (map->at(i)->first() > yMax + 1) then ( yMax := yMax + 1 ) else skip ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(h) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A[]=new int[N]; for(int i=0 ; i0 && i % 2==0 && A[i]!=2){ System.out.println(0); return ; } } } long count=1 ; for(int i=0 ; itoInteger() ; var A : Sequence(int) ; A := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( var temp : int ; temp := sc.getCurrent()->toInteger() ; A[temp+1] := A[temp+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < N do ( ( if (N mod 2 = 0) then ( if (i mod 2 = 1 & A[i+1] /= 2) then ( OclFile["System.out"].println(0) ; return ) else skip ; if (i mod 2 = 0 & A[i+1] /= 0) then ( OclFile["System.out"].println(0) ; return ) else skip ) else ( if (i = 0 & A[i+1] /= 1) then ( OclFile["System.out"].println(0) ; return ) else skip ; if (i mod 2 = 1 & A[i+1] /= 0) then ( OclFile["System.out"].println(0) ; return ) else skip ; if (i > 0 & i mod 2 = 0 & A[i+1] /= 2) then ( OclFile["System.out"].println(0) ; return ) else skip ) ) ; i := i + 1 ) ; var count : long ; count := 1 ; var i : int ; i := 0 ; while i < N / 2 do ( ( count := (count * 2) mod 1000000007 ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static PrintWriter out=new PrintWriter(System.out); static Scanner in=new Scanner(System.in); static BufferedReader re=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter wr=new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args)throws IOException { PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); int T=in.nextInt(); while(T>0){ int n=in.nextInt(); int arr[][]=new int[n][2]; for(int i=0 ; io1[0]-o2[0]); if(n>=2)System.out.println(arr[0][1]+" "+arr[n-1][1]); else System.out.println(1+" "+1); T--; } out.flush(); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute out : OclFile := OclFile.newOclFile_Write(OclFile["System.out"]); static attribute in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static attribute re : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])); static attribute wr : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ; var T : int ; T := in.getCurrent()->toInteger() ; while (T > 0) do ( var n : int ; n := in.getCurrent()->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,n)->collect(Integer.subrange(1,2)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( arr[i+1][0+1] := in.getCurrent()->toInteger() ; arr[i+1][1+1] := i + 1 ) ; i := i + 1 ) ; arr := OclComparator.sortWith(arr, lambda (o1 , o2) : OclAny in o1[0+1] - o2[0+1]) ; if (n >= 2) then OclFile["System.out"].println(arr[0+1][1+1] + " " + arr[n - 1+1][1+1]) else OclFile["System.out"].println(1 + " " + 1) ; ; T := T - 1 ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ String a,b ; long n ; try(Scanner sc=new Scanner(System.in)){ a=sc.next(); b=sc.next(); n=Long.parseLong(a)& Long.parseLong(b); System.out.println(String.format("%32s",Long.toBinaryString(n)).replace(' ','0')); n=Long.parseLong(a)| Long.parseLong(b); System.out.println(String.format("%32s",Long.toBinaryString(n)).replace(' ','0')); n=Long.parseLong(a)^ Long.parseLong(b); System.out.println(String.format("%32s",Long.toBinaryString(n)).replace(' ','0')); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : String ; var b : String ; var n : long ; try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( a := sc.getCurrent() ; b := sc.getCurrent() ; n := MathLib.bitwiseAnd((a)->toLong(),(b)->toLong()) ; OclFile["System.out"].println(StringLib.format("%32s",Sequence{(MathLib.decimal2binary(n) + "")}).replace(' ', '0')) ; n := MathLib.bitwiseOr((a)->toLong(),(b)->toLong()) ; OclFile["System.out"].println(StringLib.format("%32s",Sequence{(MathLib.decimal2binary(n) + "")}).replace(' ', '0')) ; n := MathLib.bitwiseXor((a)->toLong(),(b)->toLong()) ; OclFile["System.out"].println(StringLib.format("%32s",Sequence{(MathLib.decimal2binary(n) + "")}).replace(' ', '0')) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.Arrays ; public class InnaAndChooseOptions { public static boolean isSolution(int columnsCount,String x){ boolean allXs[]=new boolean[columnsCount]; Arrays.fill(allXs,true); for(int i=0 ; i<12 ; i++){ if(x.charAt(i)!='X')allXs[i % columnsCount]=false ; } for(int i=0 ; icollect(false) ; allXs := allXs->collect(true) ; var i : int ; i := 0 ; while i < 12 do ( ( if (x->at(i+1) /= 'X') then allXs[i mod columnsCount+1] := false ; else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < columnsCount do ( if (allXs[i+1]) then return true else skip ; ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var t : int ; t := (br.readLine())->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var possibleSolutions : int ; possibleSolutions := 0 ; var solutions : String ; solutions := StringLib.newString() ; var s : String ; s := br.readLine() ; if (isSolution(12, s)) then ( solutions := solutions + StringLib.newString(" 1x12") ; possibleSolutions := possibleSolutions + 1 ) else skip ; if (isSolution(6, s)) then ( solutions := solutions + StringLib.newString(" 2x6") ; possibleSolutions := possibleSolutions + 1 ) else skip ; if (isSolution(4, s)) then ( solutions := solutions + StringLib.newString(" 3x4") ; possibleSolutions := possibleSolutions + 1 ) else skip ; if (isSolution(3, s)) then ( solutions := solutions + StringLib.newString(" 4x3") ; possibleSolutions := possibleSolutions + 1 ) else skip ; if (isSolution(2, s)) then ( solutions := solutions + StringLib.newString(" 6x2") ; possibleSolutions := possibleSolutions + 1 ) else skip ; if (isSolution(1, s)) then ( solutions := solutions + StringLib.newString(" 12x1") ; possibleSolutions := possibleSolutions + 1 ) else skip ; skip ; skip ; ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class lunarnewyearandcrosscounting { public static void main(String[] args)throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter((System.out)); int n=Integer.parseInt(in.readLine()); String[] M=new String[n]; for(int i=0 ; itoInteger() ; var M : Sequence(String) ; M := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( M[i+1] := in.readLine() ) ; i := i + 1 ) ; var a : int ; a := 0 ; var i : int ; i := 1 ; while i < n - 1 do ( ( var j : int ; j := 1 ; while j < n - 1 do ( ( if (M[i+1]->at(j+1) = 'X') then ( if ((M[i+1]->at(j+1) = M[i - 1+1]->at(j - 1+1)) & (M[i+1]->at(j+1) = M[i - 1+1]->at(j + 1+1)) & (M[i+1]->at(j+1) = M[i + 1+1]->at(j - 1+1)) & (M[i+1]->at(j+1) = M[i + 1+1]->at(j + 1+1))) then ( a := a + 1 ) else skip ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.FileNotFoundException ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import static java.lang.System.in ; import java.util.ArrayList ; public class lunarnewyearandcrosscounting { static PrintWriter go=new PrintWriter(System.out); public static void main(String args[])throws IOException,FileNotFoundException { BufferedReader gi=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(gi.readLine()); int nb=0 ; String[] M=new String[n]; for(int i=0 ; itoInteger() ; var nb : int ; nb := 0 ; var M : Sequence(String) ; M := Integer.subrange(1,n)->collect(null) ; var i : int ; i := 0 ; while i < n do ( ( M[i+1] := gi.readLine() ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n - 1 do ( ( var j : int ; j := 1 ; while j < n - 1 do ( ( if ('X' = M[i+1]->at(j+1) & 'X' = M[i - 1+1]->at(j - 1+1) & 'X' = M[i - 1+1]->at(j + 1+1) & 'X' = M[i + 1+1]->at(j - 1+1) & 'X' = M[i + 1+1]->at(j + 1+1)) then ( nb := nb + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class LunarNewYear { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); char[][] s=new char[n][n]; for(int i=0 ; itoInteger() ; var s : Sequence(Sequence(String)) ; s := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( s[i+1] := input.getCurrent()->characters() ) ; i := i + 1 ) ; var counter : int ; counter := 0 ; var i : int ; i := 1 ; while i < n - 1 do ( ( var j : int ; j := 1 ; while j < n - 1 do ( ( if (s[i+1][j+1] = 'X' & s[i - 1+1][j + 1+1] = 'X' & s[i + 1+1][j + 1+1] = 'X' & s[i - 1+1][j - 1+1] = 'X' & s[i + 1+1][j - 1+1] = 'X') then ( counter := counter + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(counter) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; class GFG { static void findTriplets(int[] arr,int n,int sum){ Arrays.sort(arr); for(int i=0 ; isort() ; var i : int ; i := 0 ; while i < n - 1 do ( ( var l : int ; l := i + 1 ; var r : int ; r := n - 1 ; var x : int ; x := arr[i+1] ; while (l < r) do ( if (x + arr[l+1] + arr[r+1] = sum) then ( OclFile["System.out"].println(x + " " + arr[l+1] + " " + arr[r+1]) ; l := l + 1 ; r := r - 1 ) else if (x + arr[l+1] + arr[r+1] < sum) then l := l + 1 else r := r - 1 ; ; ) ) ; i := i + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{0,-1,2,-3,1} ; var sum : int ; sum := -2 ; var n : int ; n := arr->size() ; execute findTriplets(arr, n, sum) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); int x=in.nextInt(); int tak=0 ; int jup=0 ; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; var tak : int ; tak := 0 ; var jup : int ; jup := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (in.getCurrent()->toInteger() mod 2 = 0) then ( jup := jup + 1 ) else ( tak := tak + 1 ) ) ; i := i + 1 ) ; if (tak = 0 or x mod 2 = 0 & jup = 0 or n = x & tak mod 2 = 0) then ( OclFile["System.out"].println("NO") ) else ( OclFile["System.out"].println("YES") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class OddSelection { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); for(int i=0 ; ioc){ System.out.println(ec>=k-oc ? "YES" : "NO"); } else { if(k % 2==0){ System.out.println(ec>=1 ? "YES" : "NO"); } else System.out.println("YES"); } } } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class OddSelection { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; var oc : int ; oc := 0 ; var ec : int ; ec := 0 ; var j : int ; j := 0 ; while j < n do ( ( var num : int ; num := scanner.getCurrent()->toInteger() ; if (num mod 2 = 0) then ec := ec + 1 ; else oc := oc + 1 ; ) ; j := j + 1 ) ; if (oc = 0) then OclFile["System.out"].println("NO") ; else ( if (oc mod 2 = 0) then oc := oc - 1 ; else skip ; if (k > oc) then ( OclFile["System.out"].println(if ec >= k - oc then "YES" else "NO" endif) ) else ( if (k mod 2 = 0) then ( OclFile["System.out"].println(if ec >= 1 then "YES" else "NO" endif) ) else OclFile["System.out"].println("YES") ; ) ) ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static double cal_speed(double dist,double time){ System.out.print("\n Distance(km): "+dist); System.out.print("\n Time(hr): "+time); return dist/time ; } static double cal_dis(double speed,double time){ System.out.print("\n Time(hr): "+time); System.out.print("\n Speed(km/hr): "+speed); return speed*time ; } static double cal_time(double dist,double speed){ System.out.print("\n Distance(km): "+dist); System.out.print("\n Speed(km/hr): "+speed); return speed*dist ; } public static void main(String[] args){ System.out.println("\n The calculated Speed(km/hr)is : "+cal_speed(45.9,2.0)); System.out.println("\n The calculated Distance(km): "+cal_dis(62.9,2.5)); System.out.println("\n The calculated Time(hr): "+cal_time(48.0,4.5)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation cal_speed( dist : double, time : double) : double pre: true post: true activity: ( OclFile["System.out"].print("\n Distance(km): " + dist) ; OclFile["System.out"].print("\n Time(hr): " + time) ; return dist / time ); static operation cal_dis( speed : double, time : double) : double pre: true post: true activity: ( OclFile["System.out"].print("\n Time(hr): " + time) ; OclFile["System.out"].print("\n Speed(km/hr): " + speed) ; return speed * time ); static operation cal_time( dist : double, speed : double) : double pre: true post: true activity: ( OclFile["System.out"].print("\n Distance(km): " + dist) ; OclFile["System.out"].print("\n Speed(km/hr): " + speed) ; return speed * dist ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println("\n The calculated Speed(km/hr)is : " + cal_speed(45.9, 2.0)) ; OclFile["System.out"].println("\n The calculated Distance(km): " + cal_dis(62.9, 2.5)) ; OclFile["System.out"].println("\n The calculated Time(hr): " + cal_time(48.0, 4.5)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static float trapezoidarea(float r){ if(r<0)return-1 ; float a=(3*(float)Math.sqrt(3)*(float)Math.pow(r,2))/4 ; return a ; } public static void main(String args[]){ float r=5 ; System.out.printf("%.3f",trapezoidarea(r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation trapezoidarea( r : double) : double pre: true post: true activity: ( if (r < 0) then return -1 else skip ; var a : double ; a := (3 * (3)->sqrt()->oclAsType(double) * r->pow(2)->oclAsType(double)) / 4 ; return a ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : double ; r := 5 ; OclFile["System.out"].printf("%.3f", trapezoidarea(r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ new Main().run(); } private void run(){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int count=0 ; count=lMax){ r=mid ; } else { l=mid ; } } int lMax=Integer.MIN_VALUE ; int rMin=Integer.MAX_VALUE ; for(int i=0 ; itoInteger() ; var count : int ; count := 0 ; while count < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var t0 : Sequence(int) ; t0 := Integer.subrange(1,n)->collect(0) ; var xmin : int ; xmin := 2147483647 ; var xmax : int ; xmax := -2147483648 ; var tmax : int ; tmax := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := sc.getCurrent()->toInteger() ; xmin := Set{xmin, x[i+1]}->min() ; xmax := Set{xmax, x[i+1]}->max() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( t0[i+1] := sc.getCurrent()->toInteger() ; tmax := Set{tmax, t0[i+1]}->max() ) ; i := i + 1 ) ; var l : int ; l := tmax ; var r : int ; r := tmax + xmax - xmin ; while (l < r - 1) do ( var mid : int ; mid := l + (r - l) / 2 ; var rMin : int ; rMin := 2147483647 ; var lMax : int ; lMax := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( rMin := Set{rMin, x[i+1] + mid - t0[i+1]}->min() ; lMax := Set{lMax, x[i+1] - mid + t0[i+1]}->max() ) ; i := i + 1 ) ; if (rMin >= lMax) then ( r := mid ) else ( l := mid ) ; ) ; var lMax : int ; lMax := -2147483648 ; var rMin : int ; rMin := 2147483647 ; var i : int ; i := 0 ; while i < n do ( ( lMax := Set{lMax, x[i+1] - r + t0[i+1]}->max() ; rMin := Set{rMin, x[i+1] + r - t0[i+1]}->min() ) ; i := i + 1 ) ; var ans : double ; ans := (rMin + lMax) * 1.0 / 2 ; OclFile["System.out"].println(ans) ; ) ; count := count + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class OnTheLine { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ t--; int n=sc.nextInt(); int[] x=new int[n]; for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; var n : int ; n := sc.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( x[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var minDist : int ; minDist := 2147483647 ; var maxDist : int ; maxDist := -2147483648 ; var i : int ; i := 0 ; while i < n do ( ( var time : int ; time := sc.getCurrent()->toInteger() ; minDist := Set{x[i+1] - time, minDist}->min() ; maxDist := Set{x[i+1] + time, maxDist}->max() ) ; i := i + 1 ) ; OclFile["System.out"].println((minDist + maxDist) * 0.5) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); long M=1_000_000_007 ; char[] s=scanner.next().toCharArray(); long[][] dp=new long[s.length+1][13]; int[] map={ 0,4,8,12,3,7,11,2,6,10,1,5,9 }; dp[0][0]=1 ; for(int i=1 ; i<=s.length ; i++){ char ch=s[i-1]; for(int j=0 ; j<13 ; j++){ if(ch=='?'){ for(int k=0 ; k<10 ; k++){ int l=j-k ; if(l<0)l+=13 ; dp[i][j]+=dp[i-1][map[l] ]; if(dp[i][j]>=M)dp[i][j]-=M ; } } else { int l=j-(ch-'0'); if(l<0)l+=13 ; dp[i][j]=dp[i-1][map[l] ]; } } } System.out.println(dp[s.length][5]); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var M : long ; M := 1_000_000_007 ; var s : Sequence(String) ; s := scanner.getCurrent()->characters() ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,s->size() + 1)->collect(Integer.subrange(1,13)->collect(0)) ; var map : Sequence(int) ; map := Sequence{0,4,8,12,3,7,11,2,6,10,1,5,9} ; dp[0+1][0+1] := 1 ; var i : int ; i := 1 ; while i <= s->size() do ( ( var ch : String ; ch := s[i - 1+1] ; var j : int ; j := 0 ; while j < 13 do ( ( if (ch = '?') then ( var k : int ; k := 0 ; while k < 10 do ( ( var l : int ; l := (j)->char2byte() - k ; if (l < 0) then l := l+(13) ; else skip ; dp[i+1][j+1] := dp[i+1][j+1]+(dp[i - 1+1][map[l+1]+1]) ; if (dp[i+1][j+1] >= M) then dp[i+1][j+1] := dp[i+1][j+1]-(M) ; else skip ) ; k := k + 1 ) ) else ( var l : int ; l := (j)->char2byte() - ((ch)->char2byte() - ('0')->char2byte()) ; if (l < 0) then l := l+(13) ; else skip ; dp[i+1][j+1] := dp[i - 1+1][map[l+1]+1] ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dp[s->size()+1][5+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B278 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); String[] S=new String[N]; for(int n=0 ; ntoInteger() ; var S : Sequence(String) ; S := Integer.subrange(1,N)->collect(null) ; var n : int ; n := 0 ; while n < N do ( ( S[n+1] := in.getCurrent() ) ; n := n + 1 ) ; var c : String ; c := 'a' ; while c <= 'z' do ( ( var found : boolean ; found := false ; for (s : S) do ( ( if (s->indexOf(c)-1 /= -1) then ( found := true ; break ) else skip ) ) ; if (not(found)) then ( OclFile["System.out"].println(c) ; return ) else skip ) ; c := c + 1 ) ; var c1 : String ; c1 := 'a' ; while c1 <= 'z' do ( ( var c2 : String ; c2 := 'a' ; while c2 <= 'z' do ( ( var cand : String ; cand := c1 + "" + c2 ; var found : boolean ; found := false ; for (s : S) do ( ( if (s->includes(cand)) then ( found := true ; break ) else skip ) ) ; if (not(found)) then ( OclFile["System.out"].println(cand) ; return ) else skip ) ; c2 := c2 + 1 ) ) ; c1 := c1 + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int binomialCoeff(int n,int k){ int res=1 ; if(k>n-k)k=n-k ; for(int i=0 ; i0){ if((y & 1)==1)res=res*x ; y=y>>1 ; x=x*x ; } return res ; } static int gcd(int a,int b){ if(b==0)return a ; return gcd(b,a % b); } static void FindProbability(int n){ int up=binomialCoeff(2*n,n); int down=power(2,2*n); int g=gcd(up,down); up/=g ; down/=g ; System.out.println(up+"/"+down); } public static void main(String[] args){ int N=8 ; FindProbability(N); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation binomialCoeff( n : int, k : int) : int pre: true post: true activity: ( var res : int ; res := 1 ; if (k > n - k) then k := n - k ; else skip ; var i : int ; i := 0 ; while i < k do ( ( res := res*((n - i)) ; res := res/((i + 1)) ) ; i := i + 1 ) ; return res ); static operation power( x : int, y : int) : int pre: true post: true activity: ( var res : int ; res := 1 ; while (y > 0) do ( if ((y & 1) = 1) then res := res * x ; else skip ; y := (y/(2->pow(1)))->oclAsType(long) ; x := x * x ) ; return res ); static 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) ); static operation FindProbability( n : int) : void pre: true post: true activity: ( var up : int ; up := binomialCoeff(2 * n, n) ; var down : int ; down := power(2, 2 * n) ; var g : int ; g := gcd(up, down) ; up := up/(g) ; down := down/(g) ; OclFile["System.out"].println(up + "/" + down) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 8 ; execute FindProbability(N) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.LinkedList ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ String s=sc.next(); if(s.equals("0")){ break ; } int n=s.length(); int step=-1 ; boolean flag=false ; LinkedListlist=new LinkedList(); LinkedListnext=new LinkedList(); HashSetset=new HashSet(); list.add(s); while(! list.isEmpty()&& ! flag){ step++; for(String t : list){ if(! set.contains(t)){ set.add(t); char bug[]=t.toCharArray(); boolean b=true ; for(int i=0 ; i(); } System.out.println(flag ? step : "NA"); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var s : String ; s := sc.getCurrent() ; if (s = "0") then ( break ) else skip ; var n : int ; n := s->size() ; var step : int ; step := -1 ; var flag : boolean ; flag := false ; var list : Sequence(String) ; list := Sequence{} ; var next : Sequence(String) ; next := Sequence{} ; var set : Set(String) ; set := Set{} ; list := list->including(s) ; while (not(list->isEmpty()) & not(flag)) do ( step := step + 1 ; for (t : list) do ( ( if (not(set->includes(t))) then ( set := set->including(t) ; var bug : Sequence(String) ; bug := t->characters() ; var b : boolean ; b := true ; var i : int ; i := 0 ; while i < (n)->char2byte() - 1 do ( ( if (bug[i+1] /= bug[i + 1+1]) then ( b := false ; var le : String ; le := bug[i+1] ; var ri : String ; ri := bug[i + 1+1] ; var an : String ; an := if le /= 'r' & ri /= 'r' then 'r' else if le /= 'g' & ri /= 'g' then 'g' else 'b' endif endif ; bug[i+1] := an ; bug[i + 1+1] := an ; next := next->including(StringLib.newString(bug)) ; bug[i+1] := le ; bug[i + 1+1] := ri ; ) else skip ) ; i := i + 1 ) ; if (b) then ( flag := true ; break ) else skip ; ) else skip ) ) ; list := next ; next := Sequence{} ) ; OclFile["System.out"].println(if flag then step else "NA" endif) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class ProblemB { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int test=Integer.parseInt(br.readLine()); while(test-->0){ int n=Integer.parseInt(br.readLine()); String line[]=br.readLine().split(" "); int arr[]=new int[n]; for(int i=0 ; itoInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var n : int ; n := (br.readLine())->toInteger() ; var line : Sequence(String) ; line := br.readLine()->split(" ") ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( arr[i+1] := (line[i+1])->toInteger() ; ; i := i + 1 ) ; arr := arr->sort() ; var ok : boolean ; ok := true ; var ans : int ; ans := 1 ; var i : int ; i := 0 ; while i < n - 1 do ( ( if (arr[i + 1+1] - arr[i+1] = 1) then ok := false ; else skip ) ; i := i + 1 ) ; if (not(ok)) then ans := 2 ; else skip ; sb := sb + StringLib.newString(ans) ; sb := sb + StringLib.newString("\n") ; ) ; ) ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.LinkedList ; import java.util.List ; import java.util.Queue ; import java.util.Scanner ; public class A1249 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int q=scanner.nextInt(); while(q-->0){ int n=scanner.nextInt(); int[] a=new int[n]; for(int i=0 ; iqueue=new LinkedList<>(); for(int i=0 ; itempList=new LinkedList<>(); int ans=0 ; while(! queue.isEmpty()){ int size=queue.size(); for(int i=1 ; i<=size ; i++){ int x=queue.poll(); if(tempList.contains(x+1)|| tempList.contains(x-1)){ queue.add(x); } else { tempList.add(x); } } tempList.clear(); ans++; } System.out.println(ans); } scanner.close(); } } ------------------------------------------------------------ OCL File: --------- class A1249 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := scanner.getCurrent()->toInteger() ; while (q > 0) do ( q := q - 1 ; skip ; ( var n : int ; n := scanner.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; var queue : Sequence(int) ; queue := Sequence{} ; var i : int ; i := 0 ; while i < n do ( ( queue := queue->including(a[i+1]) ) ; i := i + 1 ) ; var tempList : Sequence(int) ; tempList := Sequence{} ; var ans : int ; ans := 0 ; while (not(queue->isEmpty())) do ( var size : int ; size := queue->size() ; var i : int ; i := 1 ; while i <= size do ( ( var x : int ; x := queue->min() ; if (tempList->includes(x + 1) or tempList->includes(x - 1)) then ( queue := queue->including(x) ) else ( tempList := tempList->including(x) ) ) ; i := i + 1 ) ; tempList := tempList->intersection(Set{}) ; ans := ans + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class A1249 { public static void main(String[] args){ Scanner s=new Scanner(System.in); int p=s.nextInt(); while(p-->0){ int n=s.nextInt(); int[] x=new int[n]; for(int i=0 ; i=1 ; i--){ if(x[i]-x[i-1]==1)g=2 ; } System.out.println(g); } } } ------------------------------------------------------------ OCL File: --------- class A1249 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : OclFile ; s := OclFile.newOclFile_Read(OclFile["System.in"]) ; var p : int ; p := s.getCurrent()->toInteger() ; while (p > 0) do ( p := p - 1 ; skip ; ( var n : int ; n := s.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( x[i+1] := s.getCurrent()->toInteger() ; ; i := i + 1 ) ; x := x->sort() ; var g : int ; g := 1 ; var i : int ; i := n - 1 ; while i >= 1 do ( ( if (x[i+1] - x[i - 1+1] = 1) then g := 2 ; else skip ) ; i := i - 1 ) ; OclFile["System.out"].println(g) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class BinaryStr { public static void main(String[] args)throws IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.valueOf(bf.readLine()); for(int i=0 ; itoInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := (bf.readLine())->toInteger() ; var arr : Sequence(String) ; arr := bf.readLine()->characters() ; var arr2 : Sequence(String) ; arr2 := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j <= n - 1 do ( ( arr2[j+1] := arr[j+1] ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j <= n - 1 do ( ( if (j mod 2 = 0) then ( arr2[j+1] := '0' ) else ( arr2[j+1] := '1' ) ) ; j := j + 1 ) ; var cur : int ; cur := 0 ; var k : int ; var j : int ; j := 0 ; while j <= n - 1 do ( ( if (arr[j+1] = arr2[j+1]) then continue else skip ; k := j ; while k <= n - 1 do ( ( if (arr[k+1] = arr2[k+1]) then break else skip ) ; k := k + 1 ) ; cur := cur + 1 ; j := k - 1 ) ; j := j + 1 ) ; var ans : int ; ans := 2147483647 ; ans := Set{ans, cur}->min() ; var j : int ; j := 0 ; while j <= n - 1 do ( ( if (j mod 2 = 1) then ( arr2[j+1] := '0' ) else ( arr2[j+1] := '1' ) ) ; j := j + 1 ) ; cur := 0 ; var j : int ; j := 0 ; while j <= n - 1 do ( ( if (arr[j+1] = arr2[j+1]) then continue else skip ; k := j ; while k <= n - 1 do ( ( if (arr[k+1] = arr2[k+1]) then break else skip ) ; k := k + 1 ) ; cur := cur + 1 ; j := k - 1 ) ; j := j + 1 ) ; ans := Set{ans, cur}->min() ; OclFile["System.out"].println(ans) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.stream.IntStream ; public class A_Yet_Another_Dividing_into_Teams { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int q=sc.nextInt(); for(int tc=0 ; tca[i]+1==a[i+1])? 2 : 1 ; } } ------------------------------------------------------------ OCL File: --------- class A_Yet_Another_Dividing_into_Teams { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var q : int ; q := sc.getCurrent()->toInteger() ; var tc : int ; tc := 0 ; while tc < q do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; OclFile["System.out"].println(solve(a)) ) ; tc := tc + 1 ) ; skip ); static operation solve( a : Sequence(int)) : int pre: true post: true activity: ( a := a->sort() ; return if Integer.subrange(0, a->size() - 1-1)->exists( _x2 | (lambda i : OclAny in a[i+1] + 1 = a[i + 1+1])->apply(_x2) ) then 2 else 1 endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findSubsequence(int arr[],int n){ int len=1 ; int tmp ; int i,j,d ; int[][] dp=new int[n][10]; int[] cnt=new int[10]; int locMax ; tmp=arr[0]; while(tmp>0){ dp[0][tmp % 10]=1 ; tmp/=10 ; } for(i=1 ; i0){ cnt[tmp % 10]=1 ; tmp/=10 ; } for(d=0 ; d<=9 ; d++){ if(cnt[d]>0){ dp[i][d]=1 ; for(j=0 ; j0){ dp[i][d]=locMax ; } } len=Math.max(len,locMax); } return len ; } public static void main(String[] args){ int arr[]={ 1,12,44,29,33,96,89 }; int n=arr.length ; System.out.println(findSubsequence(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findSubsequence( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var len : int ; len := 1 ; var tmp : int ; var i : int ; var j : int ; var d : int ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,n)->collect(Integer.subrange(1,10)->collect(0)) ; var cnt : Sequence(int) ; cnt := Integer.subrange(1,10)->collect(0) ; var locMax : int ; tmp := arr[0+1] ; while (tmp > 0) do ( dp[0+1][tmp mod 10+1] := 1 ; tmp := tmp/(10) ) ; i := 1 ; while i < n do ( ( tmp := arr[i+1] ; locMax := 1 ; var x : int ; x := 0 ; while x < 10 do ( cnt[x+1] := 0 ; ; x := x + 1 ) ; while (tmp > 0) do ( cnt[tmp mod 10+1] := 1 ; tmp := tmp/(10) ) ; d := 0 ; while d <= 9 do ( ( if (cnt[d+1] > 0) then ( dp[i+1][d+1] := 1 ; j := 0 ; while j < i 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() ) ; j := j + 1 ) ) else skip ) ; d := d + 1 ) ; d := 0 ; while d <= 9 do ( ( if (cnt[d+1] > 0) then ( dp[i+1][d+1] := locMax ) else skip ) ; d := d + 1 ) ; len := Set{len, locMax}->max() ; ) ; i := i + 1 ) ; return len ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,12,44,29,33,96,89} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findSubsequence(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=1 ; while(t--!=0){ int n=sc.nextInt(); int m=sc.nextInt(); int[][] a=new int[n][m]; for(int i=0 ; itoInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( a[i+1][j+1] := sc.getCurrent()->toInteger() ; ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( if (a[i+1][0+1] = 1 or a[i+1][m - 1+1] = 1) then ( OclFile["System.out"].println("2") ; return ) else skip ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < m do ( ( if (a[0+1][i+1] = 1 or a[n - 1+1][i+1] = 1) then ( OclFile["System.out"].println("2") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(4) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class A9 { public static void main(String args[]){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); int arr[][]=new int[n+2][m+2]; int ans=4 ; for(int i=1 ; itoInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,n + 2)->collect(Integer.subrange(1,m + 2)->collect(0)) ; var ans : int ; ans := 4 ; var i : int ; i := 1 ; while i < n + 1 do ( ( var j : int ; j := 1 ; while j < m + 1 do ( ( arr[i+1][j+1] := in.getCurrent()->toInteger() ; if ((i = 1 or i = n or j = 1 or j = m) & arr[i+1][j+1] = 1) then ans := 2 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ int n,m ; Scanner sc=new Scanner(System.in); n=sc.nextInt(); m=sc.nextInt(); int a ; for(int i=0 ; itoInteger() ; m := sc.getCurrent()->toInteger() ; var a : int ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( a := sc.getCurrent()->toInteger() ; if (a = 1) then ( if (i = 0 or i = (n - 1)) then ( OclFile["System.out"].println(2) ; OclProcess.exit(0) ) else if (j = 0 or j = (m - 1)) then ( OclFile["System.out"].println(2) ; OclProcess.exit(0) ) else skip ; ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(4) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class TableColoring { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); for(int i=0 ; itoInteger() ; var m : int ; m := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( if (scan.getCurrent()->toInteger() = 1 & (i = 0 or i = n - 1 or j = 0 or j = m - 1)) then ( OclFile["System.out"].println(2) ; return ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(4) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Ideone { public static void main(String[] args)throws java.lang.Exception { long M=1000000007 ; long res=1 ; Scanner in=new Scanner(System.in); int n=in.nextInt(); int k=in.nextInt(); for(int i=0 ; itoInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < k - 1 do ( res := (res * k) mod M ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - k do ( res := (res * (n - k)) mod M ; ; i := i + 1 ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countNums(int l,int r){ int cnt=0 ; for(int i=l ; i<=r ; i++){ int lastDigit=(i % 10); if((lastDigit % 10)==2 ||(lastDigit % 10)==3 ||(lastDigit % 10)==9){ cnt++; } } return cnt ; } public static void main(String[] args){ int l=11,r=33 ; System.out.print(countNums(l,r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNums( l : int, r : int) : int pre: true post: true activity: ( var cnt : int ; cnt := 0 ; var i : int ; i := l ; while i <= r do ( ( var lastDigit : int ; lastDigit := (i mod 10) ; if ((lastDigit mod 10) = 2 or (lastDigit mod 10) = 3 or (lastDigit mod 10) = 9) then ( cnt := cnt + 1 ) else skip ) ; i := i + 1 ) ; return cnt ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 11 ; var r : int ; r := 33 ; OclFile["System.out"].print(countNums(l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void printNumbers(int a[],int n,int x){ boolean flag=false ; for(int i=0 ; isize() ; execute printNumbers(a, n, x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { private static final int MOD=1_000_000_007 ; private static final String YES="YES" ; private static final String NO="NO" ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); String S=sc.next(); System.out.println(solve(S)); } private static long solve(String S){ int[][] dp=new int[S.length()+1][13]; dp[S.length()][0]=1 ; int mul=1 ; for(int i=S.length()-1 ; i>=0 ; i--){ if(S.charAt(i)=='?'){ for(int k=0 ; k<10 ; k++){ for(int j=0 ; j<13 ; j++){ int p=(mul*k+j)% 13 ; dp[i][p]+=dp[i+1][j]; dp[i][p] %=MOD ; } } } else { int k=S.charAt(i)-'0' ; for(int j=0 ; j<13 ; j++){ int p=(mul*k+j)% 13 ; dp[i][p]+=dp[i+1][j]; dp[i][p] %=MOD ; } } mul*=10 ; mul %=13 ; } return dp[0][5] % MOD ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : int := 1_000_000_007; static attribute YES : String := "YES"; static attribute NO : String := "NO"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var S : String ; S := sc.getCurrent() ; OclFile["System.out"].println(solve(S)) ); static operation solve( S : String) : long pre: true post: true activity: ( var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,S->size() + 1)->collect(Integer.subrange(1,13)->collect(0)) ; dp[S->size()+1][0+1] := 1 ; var mul : int ; mul := 1 ; var i : int ; i := S->size() - 1 ; while i >= 0 do ( ( if (S->at(i+1) = '?') then ( var k : int ; k := 0 ; while k < 10 do ( ( var j : int ; j := 0 ; while j < 13 do ( ( var p : int ; p := (mul * k + j) mod 13 ; dp[i+1][p+1] := dp[i+1][p+1]+(dp[i + 1+1][j+1]) ; dp[i+1][p+1] := dp[i+1][p+1] mod MOD ) ; j := j + 1 ) ) ; k := k + 1 ) ) else ( var k : int ; k := S->at(i+1) - ('0')->char2byte() ; var j : int ; j := 0 ; while j < 13 do ( ( var p : int ; p := (mul * k + j) mod 13 ; dp[i+1][p+1] := dp[i+1][p+1]+(dp[i + 1+1][j+1]) ; dp[i+1][p+1] := dp[i+1][p+1] mod MOD ) ; j := j + 1 ) ) ; mul := mul*(10) ; mul := mul mod 13 ) ; i := i - 1 ) ; return dp[0+1][5+1] mod MOD ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findMissing(int arr[],int n,int k,int avg){ int sum=0 ; for(int i=0 ; ioclAsType(int) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var k : int ; k := 3 ; var avg : int ; avg := 4 ; var arr : Sequence(int) ; arr := Sequence{2,7,3} ; var n : int ; n := arr->size() ; OclFile["System.out"].println(findMissing(arr, n, k, avg)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p008 implements EulerSolution { public static void main(String[] args){ System.out.println(new p008().run()); } public String run(){ long maxProd=-1 ; for(int i=0 ; i+ADJACENT<=NUMBER.length(); i++){ long prod=1 ; for(int j=0 ; jsize() do ( ( var prod : long ; prod := 1 ; var j : int ; j := 0 ; while j < ADJACENT do ( prod := prod*(NUMBER->at(i + j+1) - ('0')->char2byte()) ; ; j := j + 1 ) ; maxProd := Set{prod, maxProd}->max() ) ; i := i + 1 ) ; return ((maxProd) + "") ); static attribute ADJACENT : int := 13; static attribute NUMBER : String := "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"; } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ try(Scanner in=new Scanner(System.in)){ int N=in.nextInt(); int A=in.nextInt(); int[] x=new int[N]; for(int i=0 ; i0 && sum>0 && sum==A*n){ count+=dp[N][n][sum]; } } } System.out.println(count); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var N : int ; N := in.getCurrent()->toInteger() ; var A : int ; A := in.getCurrent()->toInteger() ; var x : Sequence(int) ; x := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( ( x[i+1] := in.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(Sequence(Sequence(long))) ; dp := Integer.subrange(1,N + 1)->collect(Integer.subrange(1,51)->collect(Integer.subrange(1,2501)->collect(0))) ; dp[0+1][0+1][0+1] := dp[0+1][0+1][0+1] + 1 ; var i : int ; i := 0 ; while i < N do ( ( var n : int ; n := 0 ; while n < 51 do ( ( var sum : int ; sum := 0 ; while sum < 2501 do ( ( if (dp[i+1][n+1][sum+1] <= 0) then ( continue ) else skip ; dp[i + 1+1][n + 0+1][sum + 0+1] := dp[i + 1+1][n + 0+1][sum + 0+1]+(dp[i+1][n+1][sum+1]) ; dp[i + 1+1][n + 1+1][sum + x[i+1]+1] := dp[i + 1+1][n + 1+1][sum + x[i+1]+1]+(dp[i+1][n+1][sum+1]) ) ; sum := sum + 1 ) ) ; n := n + 1 ) ) ; i := i + 1 ) ; var count : long ; count := 0 ; var n : int ; n := 0 ; while n < 51 do ( ( var sum : int ; sum := 0 ; while sum < 2501 do ( ( if (dp[N+1][n+1][sum+1] > 0 & sum > 0 & sum = A * n) then ( count := count+(dp[N+1][n+1][sum+1]) ) else skip ) ; sum := sum + 1 ) ) ; n := n + 1 ) ; OclFile["System.out"].println(count) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.PrintWriter ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char[] s=sc.next().toCharArray(); BIT[] count=new BIT[26]; for(int j=0 ; j<26 ; j++){ count[j]=new BIT(1+s.length); for(int i=1 ; i<=s.length ; i++){ if((s[i-1]-'a')==j){ count[j] .add(i,1); } } } int q=sc.nextInt(); for(int i=0 ; i0){ ans++; } } System.out.println(ans); } } } static class BIT { int n ; int[] data ; BIT(int n){ this.n=n ; data=new int[n+1]; } void add(int i,int v){ for(; i<=n ; i+=i &(-i))data[i]+=v ; } int get(int i){ int res=0 ; for(; i>0 ; i-=i &(-i))res+=data[i]; return res ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : Sequence(String) ; s := sc.getCurrent()->characters() ; var count : Sequence(BIT) ; count := Integer.subrange(1,26)->collect(null) ; var j : int ; j := 0 ; while j < 26 do ( ( count[j+1] := BIT.newBIT(1 + s->size()) ; var i : int ; i := 1 ; while i <= s->size() do ( ( if ((s[i - 1+1] - ('a')->char2byte()) = j) then ( count[j+1]->excludes(i, 1) ) else skip ) ; i := i + 1 ) ) ; j := j + 1 ) ; var q : int ; q := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < q do ( ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; if (a = 1) then ( var c : String ; c := sc.getCurrent()->at(0+1) ; count[(c)->char2byte() - ('a')->char2byte()+1]->excludes(b, 1) ; count[s[b - 1+1] - ('a')->char2byte()+1]->excludes(b, -1) ; s[b - 1+1] := c ) else ( var c : int ; c := sc.getCurrent()->toInteger() ; var ans : int ; ans := 0 ; var j : int ; j := 0 ; while j < 26 do ( ( if (count[j+1]->at(c+1) - count[j+1]->at(b - 1+1) > 0) then ( ans := ans + 1 ) else skip ) ; j := j + 1 ) ; OclFile["System.out"].println(ans) ) ) ; i := i + 1 ) ; ); static class BIT { attribute n : int; attribute data : Sequence(int); static operation newBIT( n : int) : BIT pre: true post: true activity: ( var self : BIT ; self := createBIT(); self.initialise(n); return self ); operation initialise( n : int) : void pre: true post: true activity: ( self.n := n ; data := Integer.subrange(1,n + 1)->collect(0) ); operation add( i : int, v : int) : void pre: true post: true activity: ( while i <= n do ( data[i+1] := data[i+1]+(v) ; ; i := i+(MathLib.bitwiseAnd(i,(-i))) ) ); operation get( i : int) : int pre: true post: true activity: ( var res : int ; res := 0 ; while i > 0 do ( res := res+(data[i+1]) ; ; i := i-(MathLib.bitwiseAnd(i,(-i))) ) ; return res ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.PrintWriter ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int M=1<toInteger() ; var M : int ; M := (1*(2->pow(N)))->oclAsType(long) ; var cs : Sequence(String) ; cs := sc.getCurrent()->characters() ; var winBig : Sequence(boolean) ; winBig := Integer.subrange(1,M - 1)->collect(false) ; var i : int ; i := 0 ; while i < M - 1 do ( ( winBig[i+1] := cs[i+1] = '1' ) ; i := i + 1 ) ; var winner : Sequence(Sequence(int)) ; winner := Integer.subrange(1,N + 1)->collect(Integer.subrange(1,M)->collect(0)) ; var P : Sequence(int) ; P := Integer.subrange(1,M)->collect(0) ; var i : int ; i := 0 ; while i < M do ( ( P[i+1] := (sc.getCurrent())->toInteger() ; winner[0+1][i+1] := P[i+1] ) ; i := i + 1 ) ; var len : int ; len := 1 ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < M do ( ( var p1 : int ; p1 := winner[i+1][j+1] ; var p2 : int ; p2 := winner[i+1][(j + len) mod M+1] ; var hi : int ; hi := Set{p1, p2}->max() ; var lo : int ; lo := Set{p1, p2}->min() ; winner[i + 1+1][j+1] := if winBig[hi - lo - 1+1] then hi else lo endif ; ) ; j := j + 1 ) ) ; i := i + 1 ; len := len*(2) ) ; var writer : OclFile ; writer := OclFile.newOclFile_Write(OclFile["System.out"]) ; var i : int ; i := 0 ; while i < M do ( ( skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static double sumOfSeries(int n){ double res=0.0 ; int sum=0,prod=1 ; for(int i=1 ; i<=n ; i++){ sum+=i ; prod*=i ; res+=((double)sum/prod); } return res ; } public static void main(String arg[]){ int n=4 ; System.out.println(sumOfSeries(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumOfSeries( n : int) : double pre: true post: true activity: ( var res : double ; res := 0.0 ; var sum : int ; sum := 0 ; var prod : int ; prod := 1 ; var i : int ; i := 1 ; while i <= n do ( ( sum := sum+(i) ; prod := prod*(i) ; res := res+((sum->oclAsType(double) / prod)) ) ; i := i + 1 ) ; return res ); static operation main( arg : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 4 ; OclFile["System.out"].println(sumOfSeries(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void main(String[] args){ String str="Mr John Smith " ; str=str.trim(); str=str.replaceAll("\\s","%20"); System.out.println(str); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "Mr John Smith " ; str := str->trim() ; str := str.replaceAllMatches("\\s", "%20" ) ; OclFile["System.out"].println(str) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class Main { private static int evaluate(final int[] a,final int k){ int res=0 ; int t ; int i ; t=1 ; for(i=0 ; i=k)t/=a[i-k]; t*=a[i]; res=Math.max(res,t); } return(res); } public void run(final java.util.Scanner sc,final java.io.PrintStream out){ int i,j ; for(; ; ){ int[] a ; int n,k ; int r1,r2=0 ; n=sc.nextInt(); k=sc.nextInt(); if(n==0 || k==0)break ; a=new int[n]; for(i=0 ; isize() do ( ( if (i >= k) then t := t/(a[i - k+1]) ; else skip ; t := t*(a[i+1]) ; res := Set{res, t}->max() ) ; i := i + 1 ) ; return (res) ); operation run( sc : Scanner, out : PrintStream) : void pre: true post: true activity: ( var i : int ; var j : int ; while true do ( ( var a : Sequence(int) ; var n : int ; var k : int ; var r1 : int ; var r2 : int ; r2 := 0 ; n := sc.nextInt() ; k := sc.nextInt() ; if (n = 0 or k = 0) then break else skip ; a := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < a->size() do ( a[i+1] := sc.nextInt() ; ; i := i + 1 ) ; r1 := evaluate(a, k) ; i := 0 ; while i < a->size() do ( j := i + 1 ; while j < a->size() do ( ( var t : int ; t := a[i+1] ; a[i+1] := a[j+1] ; a[j+1] := t ; r2 := Set{r2, evaluate(a, k)}->max() ; t := a[i+1] ; a[i+1] := a[j+1] ; a[j+1] := t ; ) ; j := j + 1 ) ; ; i := i + 1 ) ; out.println(if r2 < r1 then "NO GAME" else r2 - r1 endif) ; ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( (Main.newMain()).run(Scanner.newScanner(OclFile["System.in"]), OclFile["System.out"]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.IOException ; import java.util.Arrays ; import java.util.LinkedList ; import java.util.List ; import java.util.ListIterator ; import java.util.PriorityQueue ; import java.util.Scanner ; public class Main { public static long get_max(final int n,int[] array,final int k){ long cur=1 ; for(int i=0 ; inew_max){ System.out.println("NO GAME"); } else { System.out.println(new_max-def_max); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation get_max( n : int, array : Sequence(int), k : int) : long pre: true post: true activity: ( var cur : long ; cur := 1 ; var i : int ; i := 0 ; while i < k do ( ( cur := cur*(array[i+1]) ) ; i := i + 1 ) ; var max : long ; max := cur ; var i : int ; i := k ; while i < n do ( ( cur := cur/(array[i - k+1]) ; cur := cur*(array[i+1]) ; max := Set{max, cur}->max() ) ; i := i + 1 ) ; return max ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; if (n = 0 & k = 0) then ( break ) else skip ; var array : Sequence(int) ; array := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( array[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var def_max : long ; def_max := get_max(n, array, k) ; var new_max : long ; new_max := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var tmp : int ; tmp := array[i+1] ; array[i+1] := array[j+1] ; array[j+1] := tmp ; new_max := Set{new_max, get_max(n, array, k)}->max() ; tmp := array[i+1] ; array[i+1] := array[j+1] ; array[j+1] := tmp ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (def_max > new_max) then ( OclFile["System.out"].println("NO GAME") ) else ( OclFile["System.out"].println(new_max - def_max) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); for(; ; ){ int n=in.nextInt(); int k=in.nextInt(); if((n | k)==0)return ; int a[]=new int[n]; int max=0 ; int cmax=0 ; for(int i=0 ; i=0 ? ans : "NO GAME"); } } static public void debug(Object...o){ System.err.println(Arrays.deepToString(o)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; while true do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var k : int ; k := in.getCurrent()->toInteger() ; if ((MathLib.bitwiseOr(n,k)) = 0) then return else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var max : int ; max := 0 ; var cmax : int ; cmax := 0 ; var i : int ; i := 0 ; while i < n do ( a[i+1] := in.getCurrent()->toInteger() ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n - k + 1 do ( ( var mul : int ; mul := 1 ; var j : int ; j := i ; while j < i + k do ( mul := mul*(a[j+1]) ; ; j := j + 1 ) ; max := Set{max, mul}->max() ) ; i := i + 1 ) ; var ans : int ; ans := -1 ; var i : int ; i := 0 ; while i < n do ( var j : int ; j := i + 1 ; while j < n do ( ( var b : Sequence(int) ; b := a->copy() ; var tmp : int ; tmp := b[i+1] ; b[i+1] := b[j+1] ; b[j+1] := tmp ; var s : int ; s := 0 ; while s < n - k + 1 do ( ( var mul : int ; mul := 1 ; var t : int ; t := s ; while t < s + k do ( mul := mul*(b[t+1]) ; ; t := t + 1 ) ; cmax := Set{cmax, mul}->max() ) ; s := s + 1 ) ; ans := Set{ans, cmax - max}->max() ; ) ; j := j + 1 ) ; ; i := i + 1 ) ; OclFile["System.out"].println(if ans >= 0 then ans else "NO GAME" endif) ; ) ) ); static operation debug( o : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((o + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { int mod=(int)1E9+7 ; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); char[] s=br.readLine().toCharArray(); long dp[]=new long[13]; if(s[0]=='?'){ for(int n=0 ; n<10 ; n++){ dp[n]=1 ; } } else { dp[s[0]-'0']=1 ; } for(int i=1 ; ioclAsType(int) + 7 ; var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var s : Sequence(String) ; s := br.readLine()->characters() ; var dp : Sequence(long) ; dp := Integer.subrange(1,13)->collect(0) ; if (s[0+1] = '?') then ( var n : int ; n := 0 ; while n < 10 do ( ( dp[n+1] := 1 ) ; n := n + 1 ) ) else ( dp[s[0+1] - ('0')->char2byte()+1] := 1 ) ; var i : int ; i := 1 ; while i < s->size() do ( ( var temp : Sequence(long) ; temp := Integer.subrange(1,13)->collect(0) ; var r : int ; r := 0 ; while r < 13 do ( ( if (s[i+1] /= '?') then ( var now : int ; now := s[i+1] - ('0')->char2byte() ; temp[(r * 10 + now) mod 13+1] := temp[(r * 10 + now) mod 13+1]+(dp[r+1]) ) else ( var now : int ; now := 0 ; while now < 10 do ( ( temp[(r * 10 + now) mod 13+1] := temp[(r * 10 + now) mod 13+1]+(dp[r+1]) ) ; now := now + 1 ) ) ) ; r := r + 1 ) ; var r : int ; r := 0 ; while r < 13 do ( ( dp[r+1] := temp[r+1] mod mod ) ; r := r + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(dp[5+1]) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); int k=sc.nextInt(); if(n==0 && k==0)break ; int[] a=new int[n]; for(int i=0 ; itoInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; if (n = 0 & k = 0) then break else skip ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var max : int ; max := 0 ; var temp : int ; temp := 1 ; var p : int ; p := 0 ; while p <= n - k do ( ( temp := 1 ; var q : int ; q := 0 ; while q < k do ( temp := temp*(a[p + q+1]) ; ; q := q + 1 ) ; max := Set{max, temp}->max() ) ; p := p + 1 ) ; var maxorigin : int ; maxorigin := max ; var maxmax : int ; maxmax := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( temp := a[i+1] ; a[i+1] := a[j+1] ; a[j+1] := temp ; max := 0 ; var p : int ; p := 0 ; while p <= n - k do ( ( temp := 1 ; var q : int ; q := 0 ; while q < k do ( temp := temp*(a[p + q+1]) ; ; q := q + 1 ) ; max := Set{max, temp}->max() ) ; p := p + 1 ) ; maxmax := Set{maxmax, max}->max() ; temp := a[i+1] ; a[i+1] := a[j+1] ; a[j+1] := temp ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(maxmax - maxorigin) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.math.*; import java.awt.geom.*; import java.io.*; public class Main { static int INF=2<<27 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); int K=sc.nextInt(); if(n==0 && K==0)break ; int[] c=new int[n]; for(int i=0 ; i=n)break ; int sum=1 ; for(int j=0 ; j=n)break ; int sum=1 ; for(int l=0 ; lpow(27)))->oclAsType(long); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; while (true) do ( var n : int ; n := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; if (n = 0 & K = 0) then break else skip ; var c : Sequence(int) ; c := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( c[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var CMax : int ; CMax := 0 ; var i : int ; i := 0 ; while i < n do ( ( if (i + (K - 1) >= n) then break else skip ; var sum : int ; sum := 1 ; var j : int ; j := 0 ; while j < K do ( ( sum := sum*(c[i + j+1]) ) ; j := j + 1 ) ; CMax := Set{sum, CMax}->max() ) ; i := i + 1 ) ; var AMax : int ; AMax := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var tmp : int ; tmp := c[i+1] ; c[i+1] := c[j+1] ; c[j+1] := tmp ; var k : int ; k := 0 ; while k < n do ( ( if (k + (K - 1) >= n) then break else skip ; var sum : int ; sum := 1 ; var l : int ; l := 0 ; while l < K do ( ( sum := sum*(c[k + l+1]) ) ; l := l + 1 ) ; AMax := Set{sum, AMax}->max() ) ; k := k + 1 ) ; tmp := c[i+1] ; c[i+1] := c[j+1] ; c[j+1] := tmp ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(if AMax < CMax then "NO GAME" else AMax - CMax endif) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static void findNonPalinString(char s[]){ int freq[]=new int[26]; int flag=0 ; for(int i=0 ; icollect(0) ; var flag : int ; flag := 0 ; var i : int ; i := 0 ; while i < s->size() do ( ( if (s[i+1] /= s[0+1]) then flag := 1 ; else skip ; freq[s[i+1] - ('a')->char2byte()+1] := freq[s[i+1] - ('a')->char2byte()+1] + 1 ) ; i := i + 1 ) ; if (flag = 0) then OclFile["System.out"].println("-1") ; else ( var i : int ; i := 0 ; while i < 26 do ( var j : int ; j := 0 ; while j < freq[i+1] do ( OclFile["System.out"].print(('a' + i)->oclAsType(String)) ; ; j := j + 1 ) ; ; i := i + 1 ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; s := "abba" ; execute findNonPalinString(s->characters()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.HashMap ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int k=scanner.nextInt(); int MOD=1000000007 ; HashMap>map=new HashMap<>(); int[][] dp=new int[k+1][n+1]; for(int i=1 ; i<=2000 ; i++){ map.put(i,pre(i)); } dp[0][0]=1 ; for(int i=1 ; i<=n ; i++){ dp[1][i]=1 ; } for(int i=2 ; i<=k ; i++){ for(int j=1 ; j<=n ; j++){ Listlist=map.get(j); for(int p=0 ; ppre(int n){ Listlist=new ArrayList<>(); for(int i=1 ; i<=n ; i++){ if(n % i==0){ list.add(i); } } return list ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scanner.getCurrent()->toInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; var MOD : int ; MOD := 1000000007 ; var map : Map(int,Sequence(int)) ; map := Map{} ; var dp : Sequence(Sequence(int)) ; dp := Integer.subrange(1,k + 1)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= 2000 do ( ( map := map->union(Map{i |-> pre(i)}) ) ; i := i + 1 ) ; dp[0+1][0+1] := 1 ; var i : int ; i := 1 ; while i <= n do ( ( dp[1+1][i+1] := 1 ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= k do ( ( var j : int ; j := 1 ; while j <= n do ( ( var list : Sequence(int) ; list := map->at(j) ; var p : int ; p := 0 ; while p < list->size() do ( ( dp[i+1][j+1] := (dp[i+1][j+1] + dp[i - 1+1][list->at(p+1)+1]) mod MOD ) ; p := p + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( ans := (ans + dp[k+1][i+1]) mod MOD ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation pre( n : int) : Sequence(int) pre: true post: true activity: ( var list : Sequence(int) ; list := Sequence{} ; var i : int ; i := 1 ; while i <= n do ( ( if (n mod i = 0) then ( list := list->including(i) ) else skip ) ; i := i + 1 ) ; return list ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class CF414B { public static Scanner scanner ; public static int MOD=1000000007 ; public static void main(String[] args){ scanner=new Scanner(System.in); int n=scanner.nextInt(); int k=scanner.nextInt(); long[] dp=new long[n+1]; for(int i=1 ; itoInteger() ; var k : int ; k := scanner.getCurrent()->toInteger() ; var dp : Sequence(long) ; dp := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i < dp->size() do ( dp[i+1] := 1 ; ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k - 1 do ( ( var j : int ; j := 1 ; while j <= n do ( ( var sum : long ; sum := 0 ; var a : int ; a := j ; while a <= n do ( ( sum := (sum + dp[a+1]) mod MOD ) ; a := a+(j) ) ; dp[j+1] := sum ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < dp->size() do ( ( sum := (sum + dp[i+1]) mod MOD ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class Solution { static StringBuffer str=new StringBuffer(); static BufferedReader bf ; static PrintWriter pw ; static int n,k ; static long mod=(long)1e9+7 ; static long dp[][]; static void solve(int te)throws Exception { long dp[][]=new long[2][n+1]; for(int i=1 ; i<=n ; i++)dp[1][i]=1 ; for(int x=2 ; x<=k ; x++){ for(int i=1 ; i<=n ; i++){ for(int j=i ; j<=n ; j+=i){ dp[0][j]=((dp[0][j]+dp[1][i])% mod+mod)% mod ; } } for(int i=0 ; i<=n ; i++){ dp[1][i]=dp[0][i]; dp[0][i]=0 ; } } long ans=0 ; for(int i=1 ; i<=n ; i++){ ans=((ans+dp[1][i])% mod+mod)% mod ; } str.append(ans).append("\n"); } public static void main(String[] args)throws java.lang.Exception { boolean lenv=false ; int te=1 ; if(lenv){ bf=new BufferedReader(new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); } else { bf=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out)); } String s[]=bf.readLine().trim().split("\\s+"); n=Integer.parseInt(s[0]); k=Integer.parseInt(s[1]); solve(te); pw.print(str); pw.flush(); } } ------------------------------------------------------------ OCL File: --------- class Solution { static attribute str : String := StringLib.newString(); static attribute bf : OclFile; static attribute pw : OclFile; static attribute n : int; static attribute mod : long := 1e9->oclAsType(long) + 7; static attribute dp : Sequence(Sequence(long)); static operation solve( te : int) : void pre: true post: true activity: ( var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,2)->collect(Integer.subrange(1,n + 1)->collect(0)) ; var i : int ; i := 1 ; while i <= n do ( dp[1+1][i+1] := 1 ; ; i := i + 1 ) ; var x : int ; x := 2 ; while x <= k do ( ( var i : int ; i := 1 ; while i <= n do ( ( var j : int ; j := i ; while j <= n do ( ( dp[0+1][j+1] := ((dp[0+1][j+1] + dp[1+1][i+1]) mod mod + mod) mod mod ) ; j := j+(i) ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i <= n do ( ( dp[1+1][i+1] := dp[0+1][i+1] ; dp[0+1][i+1] := 0 ) ; i := i + 1 ) ) ; x := x + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := 1 ; while i <= n do ( ( ans := ((ans + dp[1+1][i+1]) mod mod + mod) mod mod ) ; i := i + 1 ) ; str := str + StringLib.newString(ans) + StringLib.newString("\n") ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var lenv : boolean ; lenv := false ; var te : int ; te := 1 ; if (lenv) then ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile("input.txt"))) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")))) ) else ( bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; pw := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"])) ) ; var s : Sequence(String) ; s := bf.readLine()->trim()->split("\\s+") ; n := (s[0+1])->toInteger() ; k := (s[1+1])->toInteger() ; execute solve(te) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class nonsub { public static int gcd(int a,int b){ if(b==0)return a ; else return gcd(b,a % b); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t,n,j,i,k,m ; t=sc.nextInt(); for(j=1 ; j<=t ; j++){ n=sc.nextInt(); Listll=new ArrayList<>(); m=1 ; while(ll.size()toInteger() ; j := 1 ; while j <= t do ( ( n := sc.getCurrent()->toInteger() ; var ll : Sequence(int) ; ll := Sequence{} ; m := 1 ; while (ll->size() < n) do ( ll := ll->intersection(Set{}) ; m := m + 1 ; i := m ; while i <= 4 * n do ( ( k := 0 ; while k < ll->size() do ( ( if (i mod ll->at(k+1) = 0 or gcd(i, ll->at(k+1)) = 1) then break else skip ) ; k := k + 1 ) ; if (k = ll->size()) then ll := ll->including(i) ; else skip ; if (ll->size() = n) then break else skip ) ; i := i + 1 ) ) ; i := 0 ; while i < ll->size() do ( OclFile["System.out"].print(ll->at(i+1) + " ") ; ; i := i + 1 ) ; OclFile["System.out"].println() ; ) ; j := j + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while(t-->0){ int n=sc.nextInt(); for(int i=2*n ; i<4*n ; i+=2)System.out.print(i+" "); System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; skip ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var i : int ; i := 2 * n ; while i < 4 * n do ( OclFile["System.out"].print(i + " ") ; ; i := i+(2) ) ; OclFile["System.out"].println() ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Scanner ; public class Question1 { public static void main(String[] args){ Scanner s=new Scanner(System.in); int test=s.nextInt(); for(int i=0 ; iarr=new ArrayList<>(n); for(int j=1 ; j<=(n); j++){ arr.add(4*n-(2*(j-1))); } for(int k=0 ; ktoInteger() ; var i : int ; i := 0 ; while i < test do ( ( var n : int ; n := s.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Sequence{} ; var j : int ; j := 1 ; while j <= (n) do ( ( arr := arr->including(4 * n - (2 * (j - 1))) ) ; j := j + 1 ) ; var k : int ; k := 0 ; while k < arr->size() do ( ( OclFile["System.out"].print(arr->at(k+1) + " ") ) ; k := k + 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); String S=stdIn.next(); int dp[][]=new int[S.length()+5][13]; dp[0][0]=1 ; int z=0 ; while(zsize() + 5)->collect(Integer.subrange(1,13)->collect(0)) ; dp[0+1][0+1] := 1 ; var z : int ; z := 0 ; while (z < S->size()) do ( var a : String ; a := S->at(z+1) ; var y : int ; y := 0 ; var ki : int ; ki := 0 ; if (a = '?') then ( while (y < 10) do ( while (ki < 13) do ( dp[z + 1+1][(ki * 10 + y) mod 13+1] := dp[z + 1+1][(ki * 10 + y) mod 13+1]+(dp[z+1][ki+1]) ; dp[z + 1+1][(ki * 10 + y) mod 13+1] := dp[z + 1+1][(ki * 10 + y) mod 13+1] mod 1000000007 ; ki := ki + 1 ) ; ki := 0 ; y := y + 1 ) ; y := 0 ) else ( y := (a)->char2byte() - ('0')->char2byte() ; while (ki < 13) do ( dp[z + 1+1][(ki * 10 + y) mod 13+1] := dp[z + 1+1][(ki * 10 + y) mod 13+1]+(dp[z+1][ki+1]) ; dp[z + 1+1][(ki * 10 + y) mod 13+1] := dp[z + 1+1][(ki * 10 + y) mod 13+1] mod 1000000007 ; ki := ki + 1 ) ; ki := 0 ) ; z := z + 1 ) ; OclFile["System.out"].println(dp[S->size()+1][5+1]) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class JavaApplication75 { public static void main(String[] args){ Scanner read=new Scanner(System.in); int t=read.nextInt(); while(t-->0){ int n=read.nextInt(); for(int i=n*4 ; i>=n*2 && n!=0 ; i-=2){ System.out.print(i+" "); n--; } System.out.println(); } } } ------------------------------------------------------------ OCL File: --------- class JavaApplication75 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var read : OclFile ; read := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := read.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := read.getCurrent()->toInteger() ; var i : int ; i := n * 4 ; while i >= n * 2 & n /= 0 do ( ( OclFile["System.out"].print(i + " ") ; n := n - 1 ) ; i := i-(2) ) ; OclFile["System.out"].println() ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean checkOrigin(int x1,int y1,int x2,int y2){ return(x1*(y2-y1)==y1*(x2-x1)); } public static void main(String[] args){ if(checkOrigin(1,28,2,56)==true)System.out.println("Yes"); else System.out.println("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation checkOrigin( x1 : int, y1 : int, x2 : int, y2 : int) : boolean pre: true post: true activity: ( return (x1 * (y2 - y1) = y1 * (x2 - x1)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( if (checkOrigin(1, 28, 2, 56) = true) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GfG { static double maxAvgSubArray(int a[],int n,int x,int y){ int prefix[]=new int[n]; prefix[0]=a[0]; for(int i=1 ; i0)sum-=prefix[i-1]; double current=sum/(double)(j-i+1); maximum=Math.max(maximum,current); } } return maximum ; } public static void main(String[] args){ int a[]={ 6,7,8,3,2,4,2 }; int X=2,Y=4 ; int n=a.length ; System.out.println(maxAvgSubArray(a,n,X,Y)); } } ------------------------------------------------------------ OCL File: --------- class GfG { static operation maxAvgSubArray( a : Sequence(int), n : int, x : int, y : int) : double pre: true post: true activity: ( var prefix : Sequence(int) ; prefix := Integer.subrange(1,n)->collect(0) ; prefix[0+1] := a[0+1] ; var i : int ; i := 1 ; while i < n do ( prefix[i+1] := prefix[i - 1+1] + a[i+1] ; ; i := i + 1 ) ; var maximum : double ; maximum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + x - 1 ; while j < i + y & j < n do ( ( var sum : double ; sum := prefix[j+1] ; if (i > 0) then sum := sum-(prefix[i - 1+1]) ; else skip ; var current : double ; current := sum / (j - i + 1)->oclAsType(double) ; maximum := Set{maximum, current}->max() ) ; j := j + 1 ) ) ; i := i + 1 ) ; return maximum ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : Sequence(int) ; a := Sequence{6,7,8,3,2,4,2} ; var X : int ; X := 2 ; var Y : int ; Y := 4 ; var n : int ; n := a->size() ; OclFile["System.out"].println(maxAvgSubArray(a, n, X, Y)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.lang.reflect.Array ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); StringTokenizer st=new StringTokenizer(f.readLine()); int n=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(st.nextToken()); int k=Integer.parseInt(st.nextToken()); out.println(m*(m-1)/2); for(int i=1 ; i<=m ; i++){ for(int j=i+1 ; j<=m ; j++){ if(k>0){ out.println(j+" "+i); } else { out.println(i+" "+j); } } } f.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var f : OclFile ; f := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile["System.out"]))) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(f.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var m : int ; m := (st.next())->toInteger() ; var k : int ; k := (st.next())->toInteger() ; skip ; var i : int ; i := 1 ; while i <= m do ( ( var j : int ; j := i + 1 ; while j <= m do ( ( if (k > 0) then ( skip ) else ( skip ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.Point ; import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class B384 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int M=in.nextInt(); int K=in.nextInt(); Listlist=new ArrayList<>(); for(int from=1 ; fromtoInteger() ; var M : int ; M := in.getCurrent()->toInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var list : Sequence(Point) ; list := Sequence{} ; var from : int ; from := 1 ; while from < M do ( ( var to : int ; to := from + 1 ; while to <= M do ( ( list := list->including(if (K = 0) then Point.newPoint(from, to) else Point.newPoint(to, from) endif) ) ; to := to + 1 ) ) ; from := from + 1 ) ; var out : String ; out := StringLib.newString() ; out := out + StringLib.newString(list->size()) ; for (p : list) do ( ( out := out + StringLib.newString(' ') + StringLib.newString(p.x) + StringLib.newString(' ') + StringLib.newString(p.y) ) ) ; OclFile["System.out"].println(out) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileWriter ; import java.io.IOException ; import java.io.PrintWriter ; import java.math.BigInteger ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { File f1=new File("input.txt"); File f2=new File("output.txt"); Scanner input=new Scanner(f1); PrintWriter output=new PrintWriter(f2); int n=input.nextInt(); String s=input.next(); char ch[]=s.toCharArray(); int L=0 ; int R=0 ; for(int i=0,j=s.length()/2 ; itoInteger() ; var s : String ; s := input.getCurrent() ; var ch : Sequence(String) ; ch := s->characters() ; var L : int ; L := 0 ; var R : int ; R := 0 ; var i : int ; i := 0 ; var j : int ; j := s->size() / 2 ; while i < s->size() / 2 do ( ( if (ch[i+1] = 'L' & ch[j+1] = 'L') then ( skip ) else if (ch[i+1] = 'L' & ch[j+1] = 'R') then ( skip ) else if (ch[i+1] = 'R' & ch[j+1] = 'R') then ( skip ) else ( skip ) ; ; ) ; i := i + 1 ; j := j + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B1062 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); if(N==1){ System.out.println("1 0"); return ; } int maxPower=0 ; int base=1 ; int origN=N ; int min=1 ; for(int d=2 ; d<=1000 ; d++){ int power=0 ; while(N % d==0){ power++; N/=d ; } if(power>maxPower){ maxPower=power ; base=d ; } else if(power==maxPower){ base*=d ; } if(power!=0){ min*=d ; } } if(N!=1){ if(1>maxPower){ maxPower=1 ; base=N ; } else if(1==maxPower){ base*=N ; } min*=N ; } int sqrts=0 ; int p=1 ; while(ptoInteger() ; if (N = 1) then ( OclFile["System.out"].println("1 0") ; return ) else skip ; var maxPower : int ; maxPower := 0 ; var base : int ; base := 1 ; var origN : int ; origN := N ; var min : int ; min := 1 ; var d : int ; d := 2 ; while d <= 1000 do ( ( var power : int ; power := 0 ; while (N mod d = 0) do ( power := power + 1 ; N := N/(d) ) ; if (power > maxPower) then ( maxPower := power ; base := d ) else if (power = maxPower) then ( base := base*(d) ) else skip ; ; if (power /= 0) then ( min := min*(d) ) else skip ) ; d := d + 1 ) ; if (N /= 1) then ( if (1 > maxPower) then ( maxPower := 1 ; base := N ) else if (1 = maxPower) then ( base := base*(N) ) else skip ; ; min := min*(N) ) else skip ; var sqrts : int ; sqrts := 0 ; var p : int ; p := 1 ; while (p < maxPower) do ( sqrts := sqrts + 1 ; p := p*(2) ) ; var sqrtOnly : boolean ; sqrtOnly := false ; if (bitCount(maxPower) = 1) then ( var newN : long ; newN := 1 ; var i : int ; i := 0 ; while i < maxPower do ( ( newN := newN*(base) ) ; i := i + 1 ) ; sqrtOnly := (newN = origN) ) else skip ; var ops : int ; ops := sqrts + (if sqrtOnly then 0 else 1 endif) ; OclFile["System.out"].println(min + " " + ops) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static void findPair(int arr[],int n){ if(n<2){ System.out.print("-1"); return ; } int maximum=arr[0]; for(int i=1 ; imax() ; ; i := i + 1 ) ; var temp : int ; temp := 10000001 ; var r : int ; r := 0 ; var middle : int ; middle := maximum / 2 ; var i : int ; i := 0 ; while i < n do ( ( if (if middle - arr[i+1] < 0 then -(middle - arr[i+1]) else middle - arr[i+1] endif < temp & n mod 2 = 0) then ( temp := if middle - arr[i+1] < 0 then -(middle - arr[i+1]) else middle - arr[i+1] endif ; r := arr[i+1] ) else if (Set{if middle - arr[i+1] < 0 then -(middle - arr[i+1]) else middle - arr[i+1] endif, if middle + 1 - arr[i+1] < 0 then -(middle + 1 - arr[i+1]) else middle + 1 - arr[i+1] endif}->min() < temp & n mod 2 = 1) then ( temp := Set{if middle - arr[i+1] < 0 then -(middle - arr[i+1]) else middle - arr[i+1] endif, if middle + 1 - arr[i+1] < 0 then -(middle + 1 - arr[i+1]) else middle + 1 - arr[i+1] endif}->min() ; r := arr[i+1] ) else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].print("n=" + maximum + " and r=" + r) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{0,2,3,4,1,6,8,9} ; var n : int ; n := arr->size() ; execute findPair(arr, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int countPairs(int s,int K){ if(K>s ||(s-K)% 2==1){ return 0 ; } if((s-K)/2==1 & K==1){ return 0 ; } int setBits=__builtin_popcount(K); int pairsCount=(int)Math.pow(2,setBits); if(s==K){ pairsCount-=2 ; } return pairsCount ; } static int __builtin_popcount(int n){ int count=0 ; while(n>0){ count+=n & 1 ; n>>=1 ; } return count ; } public static void main(String[] args){ int s=9,K=5 ; System.out.println(countPairs(s,K)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countPairs( s : int, K : int) : int pre: true post: true activity: ( if (K > s or (s - K) mod 2 = 1) then ( return 0 ) else skip ; if ((s - K) / 2 = 1 & K = 1) then ( return 0 ) else skip ; var setBits : int ; setBits := __builtin_popcount(K) ; var pairsCount : int ; pairsCount := 2->pow(setBits)->oclAsType(int) ; if (s = K) then ( pairsCount := pairsCount-(2) ) else skip ; return pairsCount ); static operation __builtin_popcount( n : int) : int pre: true post: true activity: ( var count : int ; count := 0 ; while (n > 0) do ( count := count+(n & 1) ; n := n/(2->pow(1)) ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : int ; s := 9 ; var K : int ; K := 5 ; OclFile["System.out"].println(countPairs(s, K)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static final int N=3 ; static void scalarProductMat(int mat[][],int k){ for(int i=0 ; i0 ? dp[i-1][pre] :(pre==0 ? 1 : 0)); dp[i][(base*next+pre)% 13] %=MOD ; } } } else { int next=cs[cs.length-1-i]-'0' ; for(int pre=0 ; pre<13 ; ++pre){ dp[i][(base*next+pre)% 13]+=(i>0 ? dp[i-1][pre] :(pre==0 ? 1 : 0)); dp[i][(base*next+pre)% 13] %=MOD ; } } base=base*10 % 13 ; } System.out.println(dp[dp.length-1][5]); } void tr(Object...objects){ System.out.println(Arrays.deepToString(objects)); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute MOD : long := 1e9->oclAsType(long) + 7; operation run() : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var cs : Sequence(String) ; cs := sc.getCurrent()->characters() ; var dp : Sequence(Sequence(long)) ; dp := Integer.subrange(1,cs->size())->collect(Integer.subrange(1,13)->collect(0)) ; var base : int ; base := 1 ; var i : int ; i := 0 ; while i < cs->size() do ( ( if (cs[cs->size() - 1 - i+1] = '?') then ( var pre : int ; pre := 0 ; while pre < 13 do ( ( var next : int ; next := 0 ; while next < 10 do ( ( dp[i+1][(base * next + pre) mod 13+1] := dp[i+1][(base * next + pre) mod 13+1]+((if i > 0 then dp[i - 1+1][pre+1] else (if pre = 0 then 1 else 0 endif) endif)) ; dp[i+1][(base * next + pre) mod 13+1] := dp[i+1][(base * next + pre) mod 13+1] mod MOD ) ; next := next + 1 ) ) ; pre := pre + 1 ) ) else ( var next : int ; next := cs[cs->size() - 1 - i+1] - ('0')->char2byte() ; var pre : int ; pre := 0 ; while pre < 13 do ( ( dp[i+1][(base * next + pre) mod 13+1] := dp[i+1][(base * next + pre) mod 13+1]+((if i > 0 then dp[i - 1+1][pre+1] else (if pre = 0 then 1 else 0 endif) endif)) ; dp[i+1][(base * next + pre) mod 13+1] := dp[i+1][(base * next + pre) mod 13+1] mod MOD ) ; pre := pre + 1 ) ) ; base := base * 10 mod 13 ) ; i := i + 1 ) ; OclFile["System.out"].println(dp[dp->size() - 1+1][5+1]) ; ); operation tr( objects : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.out"].println((objects + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] prices=new int[4]; for(int i=0 ; i<4 ; i++){ prices[i]=sc.nextInt(); } int[] counts=new int[4]; for(int i=0 ; i<4 ; i++){ counts[i]=sc.nextInt(); } int min=Integer.MAX_VALUE ; for(int i=0 ; ; i++){ int x=i*counts[0]; for(int j=0 ; ; j++){ int y=x+j*counts[1]; for(int k=0 ; ; k++){ int z=y+k*counts[2]; int l=0 ; if(z=n){ break ; } } if(y>=n){ break ; } } if(x>=n){ break ; } } System.out.println(min); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var prices : Sequence(int) ; prices := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( ( prices[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var counts : Sequence(int) ; counts := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( ( counts[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var min : int ; min := 2147483647 ; var i : int ; i := 0 ; while true do ( ( var x : int ; x := i * counts[0+1] ; var j : int ; j := 0 ; while true do ( ( var y : int ; y := x + j * counts[1+1] ; var k : int ; k := 0 ; while true do ( ( var z : int ; z := y + k * counts[2+1] ; var l : int ; l := 0 ; if (z < n) then ( l := (n - z + counts[3+1] - 1) / counts[3+1] ) else skip ; min := Set{min, i * prices[0+1] + j * prices[1+1] + k * prices[2+1] + l * prices[3+1]}->min() ; if (z >= n) then ( break ) else skip ; ) ; k := k + 1 ) ; if (y >= n) then ( break ) else skip ) ; j := j + 1 ) ; if (x >= n) then ( break ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ int N=sc.nextInt(); int[] P=new int[4]; int[] T=new int[4]; for(int i=0 ; i<4 ; i++){ P[i]=sc.nextInt(); } for(int i=0 ; i<4 ; i++){ T[i]=sc.nextInt(); } int[] dp=new int[201]; Arrays.fill(dp,200000); dp[0]=0 ; for(int i=0 ; i<4 ; i++){ for(int j=0 ; j+T[i]toInteger() ; var P : Sequence(int) ; P := Integer.subrange(1,4)->collect(0) ; var T : Sequence(int) ; T := Integer.subrange(1,4)->collect(0) ; var i : int ; i := 0 ; while i < 4 do ( ( P[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 4 do ( ( T[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,201)->collect(0) ; dp := dp->collect(200000) ; dp[0+1] := 0 ; var i : int ; i := 0 ; while i < 4 do ( ( var j : int ; j := 0 ; while j + T[i+1] < dp->size() do ( ( dp[j + T[i+1]+1] := Set{dp[j + T[i+1]+1], dp[j+1] + P[i+1]}->min() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 2147483647 ; var i : int ; i := N ; while i < dp->size() do ( ( ans := Set{ans, dp[i+1]}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); String s,s2 ; int n,de=0 ; s=in.next(); n=in.nextInt(); for(int i=0 ; i0){ if(s2.contains(s)){ de++; break ; } } } System.out.println(de); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; var s2 : String ; var n : int ; var de : int ; de := 0 ; s := in.getCurrent() ; n := in.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( s2 := in.getCurrent() ; var ln : int ; ln := 2 * s2->size() ; s2 := s2 + s2 ; while (ln > 0) do ( ln := ln - 1 ; skip ; ( if (s2->includes(s)) then ( de := de + 1 ; break ) else skip ) ; ) ) ; i := i + 1 ) ; OclFile["System.out"].println(de) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.regex.Matcher ; import java.util.regex.Pattern ; public class Main { public static final int BIG_NUM=2000000000 ; public static final int MOD=1000000007 ; public static final long HUGE_NUM=99999999999999999L ; public static final double EPS=0.000000001 ; public static final int SIZE=21 ; @ SuppressWarnings("unchecked")public static void main(String[] args){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { String pattern=br.readLine(); int N=Integer.parseInt(br.readLine()); int ans=0 ; boolean FLG ; for(int i=0 ; itoInteger() ; var ans : int ; ans := 0 ; var FLG : boolean ; var i : int ; i := 0 ; while i < N do ( ( var T : String ; T := br.readLine() ; var start : int ; start := 0 ; while start < T->size() do ( ( FLG := true ; var k : int ; k := 0 ; while k < pattern->size() do ( ( if (T->at((start + k) mod T->size()+1) /= pattern->at(k+1)) then ( FLG := false ; break ) else skip ) ; k := k + 1 ) ; if (FLG) then ( ans := ans+(1) ; break ) else skip ) ; start := start + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) catch (e : IOException) do ( e.printStackTrace() ) ); } class UTIL { static operation getNUM( tmp_str : String) : int pre: true post: true activity: ( return (tmp_str)->toInteger() ); static operation isNumber( tmp_str : String) : boolean pre: true post: true activity: ( if (tmp_str = null or tmp_str->size() = 0) then ( return false ) else skip ; var pattern : OclRegex ; pattern := OclRegex.compile("\\A[0-9]+\\z") ; var matcher : OclRegex ; matcher := pattern.matcher(tmp_str) ; return matcher.isMatch() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ new Main().run(); } Scanner sc=new Scanner(System.in); int n ; String[] ring ; String s ; int count ; int i,point ; void run(){ while(sc.hasNext()){ s=sc.next(); n=sc.nextInt(); ring=new String[n]; for(i=0 ; i=s.length())find=true ; } else { flag[start]=false ; start=(start+1)% 10 ; point=start ; m=0 ; } cont=! find && flag[start]; } return find ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute n : int; attribute ring : Sequence(String); attribute s : String; attribute count : int; attribute i : int; operation run() : void pre: true post: true activity: ( while (sc.hasNext()) do ( s := sc.getCurrent() ; n := sc.getCurrent()->toInteger() ; ring := Integer.subrange(1,n)->collect(null) ; i := 0 ; while i < n do ( ring[i+1] := sc.getCurrent() ; ; i := i + 1 ) ; count := 0 ; execute solve() ; ) ); operation solve() : void pre: true post: true activity: ( i := 0 ; while i < n do ( if (search(ring[i+1])) then count := count + 1 ; else skip ; ; i := i + 1 ) ; OclFile["System.out"].println(count) ); operation search( c : String) : boolean pre: true post: true activity: ( point := 0 ; var start : int ; start := 0 ; var m : int ; m := 0 ; var cont : boolean ; cont := true ; var flag : Sequence(boolean) ; flag := Integer.subrange(1,c->size())->collect(false) ; flag := flag->collect(true) ; var now : boolean ; now := true ; var find : boolean ; find := false ; while (cont) do ( var tf : boolean ; tf := s.subrange(m+1,m + 1) = c.subrange(point+1,point + 1) ; if (tf) then ( point := (point + 1) mod 10 ; m := m + 1 ; if (m >= s->size()) then find := true ; else skip ) else ( flag[start+1] := false ; start := (start + 1) mod 10 ; point := start ; m := 0 ) ; cont := not(find) & flag[start+1] ) ; return find ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line="" ; while((line=br.readLine())!=null && ! line.isEmpty()){ char[] word=line.toCharArray(); int N=Integer.parseInt(br.readLine()); int count=0 ; outer1 : for(int i=0 ; iisEmpty())) do ( skip ; ( var word : Sequence(String) ; word := line->characters() ; var N : int ; N := (br.readLine())->toInteger() ; var count : int ; count := 0 ; var i : int ; i := 0 ; while i < N do ( ( var ring : Sequence(String) ; ring := br.readLine()->characters() ; var j : int ; j := 0 ; while j < ring->size() + word->size() do ( ( if (ring[j mod ring->size()+1] = word[0+1]) then ( var k : int ; k := 1 ; while k < word->size() do ( ( if (word[k+1] /= ring[(j + k) mod ring->size()+1]) then ( j := j+(k - 1) ; continue ) else skip ) ; k := k + 1 ) ; count := count + 1 ; continue ) else skip ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ) ; line := br.readLine() ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileWriter ; import java.io.IOException ; import java.math.BigInteger ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { File f1=new File("input.txt"); File f2=new File("output.txt"); Scanner input=new Scanner(f1); FileWriter output=new FileWriter(f2); int n=input.nextInt(); String s=input.next(); char ch[]=s.toCharArray(); int L=0 ; int R=0 ; for(int i=0,j=s.length()/2 ; itoInteger() ; var s : String ; s := input.getCurrent() ; var ch : Sequence(String) ; ch := s->characters() ; var L : int ; L := 0 ; var R : int ; R := 0 ; var i : int ; i := 0 ; var j : int ; j := s->size() / 2 ; while i < s->size() / 2 do ( ( if (ch[i+1] = 'L' & ch[j+1] = 'L') then ( skip ) else if (ch[i+1] = 'L' & ch[j+1] = 'R') then ( skip ) else if (ch[i+1] = 'R' & ch[j+1] = 'R') then ( skip ) else ( skip ) ; ; ) ; i := i + 1 ; j := j + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { Scanner sc=new Scanner(System.in); int INF=1<<28 ; double EPS=1e-9 ; void run(){ String s=sc.next(); int n=sc.nextInt(); int a=0 ; for(int i=0 ; i=0){ a++; } } println(""+a); } void debug(Object...os){ System.err.println(Arrays.deepToString(os)); } void print(String s){ System.out.print(s); } void println(String s){ System.out.println(s); } public static void main(String[] args){ new Main().run(); } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); attribute INF : int := (1*(2->pow(28)))->oclAsType(long); attribute EPS : double := 1e-9; operation run() : void pre: true post: true activity: ( var s : String ; s := sc.getCurrent() ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : int ; a := 0 ; var i : int ; i := 0 ; while i < n do ( ( var t : String ; t := sc.getCurrent() ; if ((t + t)->indexOf(s)-1 >= 0) then ( a := a + 1 ) else skip ) ; i := i + 1 ) ; execute println("" + a) ; ); operation debug( os : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((os + "")) ); operation print( s : String) : void pre: true post: true activity: ( OclFile["System.out"].print(s) ); operation println( s : String) : void pre: true post: true activity: ( OclFile["System.out"].println(s) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class NewClass39 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); int p=1 ; while(t-->0){ int n=in.nextInt(); int m=in.nextInt(); if((nm)&&((n+m)% 2==0)){ System.out.println("1"); } else if((nm)&&((n+m)% 2==1)){ System.out.println("2"); } else { System.out.println("0"); } } } } ------------------------------------------------------------ OCL File: --------- class NewClass39 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; var p : int ; p := 1 ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var m : int ; m := in.getCurrent()->toInteger() ; if ((n < m & ((n + m) mod 2 = 1)) or (n > m) & ((n + m) mod 2 = 0)) then ( OclFile["System.out"].println("1") ) else if ((n < m & ((n + m) mod 2 = 0)) or (n > m) & ((n + m) mod 2 = 1)) then ( OclFile["System.out"].println("2") ) else ( OclFile["System.out"].println("0") ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { Fast f=new Fast(System.in); int t=f.nextInt(); while(t--!=0){ int a=f.nextInt(),b=f.nextInt(); if(a==b)System.out.println(0); else if(a>b){ if((a-b)% 2==0)System.out.println(1); else System.out.println(2); } else { if((b-a)% 2!=0)System.out.println(1); else System.out.println(2); } } System.out.flush(); System.out.close(); } } class Fast { StringTokenizer st ; BufferedReader br ; public Fast(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public Fast(String file)throws IOException { br=new BufferedReader(new FileReader(file)); } public Fast(FileReader r){ br=new BufferedReader(r); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader)throws IOException { StringBuilder content=new StringBuilder(); String line ; while((line=reader.readLine())!=null){ content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n)throws IOException { int[] a=new int[n]; for(int i=0 ; i b) then ( if ((a - b) mod 2 = 0) then OclFile["System.out"].println(1) ; else OclFile["System.out"].println(2) ; ) else ( if ((b - a) mod 2 /= 0) then OclFile["System.out"].println(1) ; else OclFile["System.out"].println(2) ; ) ; ) ; ) ; OclFile["System.out"].flush() ; OclFile["System.out"].close() ; ); } class Fast { attribute st : OclIterator; attribute br : OclFile; static operation newFast( s : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newFast( file : String) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(file); return self ); operation initialise( file : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(file)) ); static operation newFast( r : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(r); return self ); operation initialise( r : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(r) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation readAllLines( reader : OclFile) : String pre: true post: true activity: ( var content : String ; content := StringLib.newString() ; var line : String ; line := reader.readLine() ; while ((line) /= null) do ( skip ; ( content := content + StringLib.newString(line) ; content := content + StringLib.newString(lineSeparator()) ) ; line := reader.readLine() ; ) ; return content+"" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); ATwoProblems solver=new ATwoProblems(); solver.solve(1,in,out); out.close(); } static class ATwoProblems { public void solve(int testNumber,InputReader in,PrintWriter out){ int points=in.nextInt(); int t=in.nextInt(); int a=in.nextInt(); int b=in.nextInt(); int ta=in.nextInt(); int tb=in.nextInt(); for(int i=0 ; itoInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class pre133 { public static void main(String args[]){ Scanner obj=new Scanner(System.in); int tc=obj.nextInt(); while(tc--!=0){ int a=obj.nextInt(),b=obj.nextInt(),k=Math.abs(a-b); if(k==0){ System.out.println(0); continue ; } if(a>b){ if(k % 2==0){ System.out.println(1); continue ; } else { System.out.println(2); continue ; } } else { if(k % 2==0){ System.out.println(2); continue ; } else { System.out.println(1); continue ; } } } } } ------------------------------------------------------------ OCL File: --------- class pre133 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var obj : OclFile ; obj := OclFile.newOclFile_Read(OclFile["System.in"]) ; var tc : int ; tc := obj.getCurrent()->toInteger() ; while (tc /= 0) do ( skip ; ( var a : int ; a := obj.getCurrent()->toInteger() ; var b : int ; b := obj.getCurrent()->toInteger() ; var k : int ; k := if a - b < 0 then -(a - b) else a - b endif ; if (k = 0) then ( OclFile["System.out"].println(0) ; continue ) else skip ; if (a > b) then ( if (k mod 2 = 0) then ( OclFile["System.out"].println(1) ; continue ) else ( OclFile["System.out"].println(2) ; continue ) ) else ( if (k mod 2 = 0) then ( OclFile["System.out"].println(2) ; continue ) else ( OclFile["System.out"].println(1) ; continue ) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class AddOddOrSubtractEven { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); int[] out=new int[T]; for(int i=0 ; i0)out[i]=(diff % 2==0)? 1 : 2 ; else out[i]=0 ; } for(int j=0 ; jtoInteger() ; var out : Sequence(int) ; out := Integer.subrange(1,T)->collect(0) ; var i : int ; i := 0 ; while i < T do ( ( var A : int ; var B : int ; A := sc.getCurrent()->toInteger() ; B := sc.getCurrent()->toInteger() ; var diff : int ; diff := A - B ; if (diff < 0) then out[i+1] := if (if diff < 0 then -(diff) else diff endif mod 2 = 0) then 2 else 1 endif else if (diff > 0) then out[i+1] := if (diff mod 2 = 0) then 1 else 2 endif else out[i+1] := 0 ; ; ; ) ; i := i + 1 ) ; var j : int ; j := 0 ; while j < T do ( OclFile["System.out"].println(out[j+1]) ; ; j := j + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { public static void main(String[] args)throws IOException { Fast f=new Fast(System.in); int t=f.nextInt(); while(t--!=0){ int n=f.nextInt(); String s=f.next(); if(s.contains("T")&& s.contains("i")&& s.contains("m")&& s.contains("u")&& s.contains("r")&& s.length()==5)System.out.println("YES"); else System.out.println("NO"); } System.out.flush(); System.out.close(); } } class Fast { StringTokenizer st ; BufferedReader br ; public Fast(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public Fast(String file)throws IOException { br=new BufferedReader(new FileReader(file)); } public Fast(FileReader r){ br=new BufferedReader(r); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader)throws IOException { StringBuilder content=new StringBuilder(); String line ; while((line=reader.readLine())!=null){ content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n)throws IOException { int[] a=new int[n]; for(int i=0 ; iincludes("T") & s->includes("i") & s->includes("m") & s->includes("u") & s->includes("r") & s->size() = 5) then OclFile["System.out"].println("YES") ; else OclFile["System.out"].println("NO") ; ) ; ) ; OclFile["System.out"].flush() ; OclFile["System.out"].close() ; ); } class Fast { attribute st : OclIterator; attribute br : OclFile; static operation newFast( s : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile(s))) ); static operation newFast( file : String) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(file); return self ); operation initialise( file : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(file)) ); static operation newFast( r : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(r); return self ); operation initialise( r : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(r) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation readAllLines( reader : OclFile) : String pre: true post: true activity: ( var content : String ; content := StringLib.newString() ; var line : String ; line := reader.readLine() ; while ((line) /= null) do ( skip ; ( content := content + StringLib.newString(line) ; content := content + StringLib.newString(lineSeparator()) ) ; line := reader.readLine() ; ) ; return content+"" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class QQQ { public static void main(String[] args){ Scanner in=new Scanner(System.in); long t=in.nextLong(); for(int i=0 ; itoLong() ; var i : int ; i := 0 ; while i < t do ( ( var r : long ; r := in.getCurrent()->toLong() ; var b : long ; b := in.getCurrent()->toLong() ; var k : long ; k := 0 ; if (r <= 2) then ( OclFile["System.out"].println(1) ) else OclFile["System.out"].println(((r - 2) / b->oclAsType(double))->ceil()->oclAsType(int) + 1) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Application { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); for(int i=0 ; i2)System.out.println((int)Math.ceil(((a-2.0)/b)+1)); else System.out.println(1); } } } ------------------------------------------------------------ OCL File: --------- class Application { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < n do ( ( var a : int ; a := scan.getCurrent()->toInteger() ; var b : int ; b := scan.getCurrent()->toInteger() ; if (a > 2) then OclFile["System.out"].println((((a - 2.0) / b) + 1)->ceil()->oclAsType(int)) ; else OclFile["System.out"].println(1) ; ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { public static void main(String[] args)throws IOException { Fast f=new Fast(System.in); int t=f.nextInt(); while(t--!=0){ int n=f.nextInt(),x=f.nextInt(); if(n<=2)System.out.println(1); else System.out.println((int)ceil((n-2.0)/x)+1); } System.out.flush(); System.out.close(); } } class Fast { StringTokenizer st ; BufferedReader br ; public Fast(InputStream s){ br=new BufferedReader(new InputStreamReader(s)); } public Fast(String file)throws IOException { br=new BufferedReader(new FileReader(file)); } public Fast(FileReader r){ br=new BufferedReader(r); } public String next()throws IOException { while(st==null || ! st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader)throws IOException { StringBuilder content=new StringBuilder(); String line ; while((line=reader.readLine())!=null){ content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt()throws IOException { return Integer.parseInt(next()); } public long nextLong()throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n)throws IOException { int[] a=new int[n]; for(int i=0 ; ioclAsType(int) + 1) ; ) ; ) ; OclFile["System.out"].flush() ; OclFile["System.out"].close() ; ); } class Fast { attribute st : OclIterator; attribute br : OclFile; static operation newFast( s : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(s); return self ); operation initialise( s : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(s)) ); static operation newFast( file : String) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(file); return self ); operation initialise( file : String) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(file)) ); static operation newFast( r : OclFile) : Fast pre: true post: true activity: ( var self : Fast ; self := createFast(); self.initialise(r); return self ); operation initialise( r : OclFile) : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(r) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do st := OclIterator.newOclIterator_String(br.readLine()) ; ; return st.next() ); operation readAllLines( reader : OclFile) : String pre: true post: true activity: ( var content : String ; content := StringLib.newString() ; var line : String ; line := reader.readLine() ; while ((line) /= null) do ( skip ; ( content := content + StringLib.newString(line) ; content := content + StringLib.newString(lineSeparator()) ) ; line := reader.readLine() ; ) ; return content+"" ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextIntArray( n : int) : Sequence(int) pre: true post: true activity: ( var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( a[i+1] := nextInt() ; ; i := i + 1 ) ; return a ); operation ready() : boolean pre: true post: true activity: ( return br.canRead() ); } class Pair { attribute d : int; attribute k : int; static operation newPair( d : int, k : int) : Pair pre: true post: true activity: ( var self : Pair ; self := createPair(); self.initialise(d, k); return self ); operation initialise( d : int, k : int) : void pre: true post: true activity: ( self.d := d ; self.k := k ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class floor { public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); int x=in.nextInt(); if(n<=2){ System.out.println(1); } else { n-=2 ; System.out.println((n+x-1)/x+1); } } } } ------------------------------------------------------------ OCL File: --------- class floor { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var x : int ; x := in.getCurrent()->toInteger() ; if (n <= 2) then ( OclFile["System.out"].println(1) ) else ( n := n-(2) ; OclFile["System.out"].println((n + x - 1) / x + 1) ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.Scanner ; public class A234 { public static void main(String[] args)throws IOException { Scanner in=new Scanner(new File("input.txt")); PrintWriter out=new PrintWriter(new File("output.txt")); int N=in.nextInt(); char[] S=in.next().toCharArray(); for(int n=0 ; ntoInteger() ; var S : Sequence(String) ; S := in.getCurrent()->characters() ; var n : int ; n := 0 ; while n < N / 2 do ( ( var left : int ; left := n + 1 ; var right : int ; right := left + N / 2 ; if (S[n+1] = 'R' & S[n + N / 2+1] = 'L') then ( skip ) else ( skip ) ) ; n := n + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; import java.util.*; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; InputReader in=new InputReader(inputStream); int T=in.nextInt(); while(T-->0){ int n=in.nextInt(); int x=in.nextInt(); int l=1 ; int r=2 ; int level=1 ; while(l>n || r 0) do ( T := T - 1 ; skip ; ( var n : int ; n := in.nextInt() ; var x : int ; x := in.nextInt() ; var l : int ; l := 1 ; var r : int ; r := 2 ; var level : int ; level := 1 ; while (l > n or r < n) do ( l := r + 1 ; r := (level * x) + 2 ; level := level + 1 ) ; OclFile["System.out"].println(level) ; ) ; ) ); static class InputReader { attribute reader : OclFile; attribute tokenizer : OclIterator; static operation newInputReader( stream : OclFile) : InputReader pre: true post: true activity: ( var self : InputReader ; self := createInputReader(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream), 32768) ; tokenizer := null ); operation next() : String pre: true post: true activity: ( while (tokenizer = null or not(tokenizer.hasNext())) do ( try ( tokenizer := OclIterator.newOclIterator_String(reader.readLine()) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return tokenizer.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p015 implements EulerSolution { public static void main(String[] args){ System.out.println(new p015().run()); } public String run(){ return Library.binomial(40,20).toString(); } } ------------------------------------------------------------ OCL File: --------- class p015 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p015.newp015().run()) ); operation run() : String pre: true post: true activity: ( return Library.binomial(40, 20)+"" ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class S { public static void main(String[] args){ Scanner in=new Scanner(System.in); int x=in.nextInt(),t=in.nextInt(),a=in.nextInt(),b=in.nextInt(),da=in.nextInt(),db=in.nextInt(); int p=a,q=b,temp=0 ; if(x==0)System.out.print("YES"); else { l : for(int i=0 ; itoInteger() ; var t : int ; t := in.getCurrent()->toInteger() ; var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var da : int ; da := in.getCurrent()->toInteger() ; var db : int ; db := in.getCurrent()->toInteger() ; var p : int ; p := a ; var q : int ; q := b ; var temp : int ; temp := 0 ; if (x = 0) then OclFile["System.out"].print("YES") ; else ( var i : int ; i := 0 ; while i < t do ( ( a := a - (i * da) ; if (a = x) then ( temp := 1 ; break ) else skip ; if (a < 0) then a := 0 ; else skip ; var j : int ; j := 0 ; while j < t do ( ( b := b - (j * db) ; if (b = x) then ( temp := 1 ; break ) else skip ; if (b < 0) then b := 0 ; else skip ; var sum : int ; sum := a + b ; if (sum = x) then ( temp := 1 ; break ) else skip ; b := q ; ) ; j := j + 1 ) ; a := p ; ) ; i := i + 1 ) ; if (temp = 1) then OclFile["System.out"].print("YES") ; else OclFile["System.out"].print("NO") ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public final class Main { Scanner sc ; public static void main(String[] args)throws Exception { new Main().run(); } { sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); } void run(){ TreeSetprimes=sieve(1000000); int n=sc.nextInt(); int m=sc.nextInt(); int[][] a=new int[n][m]; for(int i=0 ; isieve(int n){ boolean[] non_primes=new boolean[n+1]; TreeSetset=new TreeSet<>(); for(int i=2 ; i*i<=n ; i++){ if(! non_primes[i]){ for(int j=2*i ; j<=n ; j+=i){ non_primes[j]=true ; } } } for(int i=2 ; i<=n ; i++)if(! non_primes[i])set.add(i); return set ; } } ------------------------------------------------------------ OCL File: --------- class Main { attribute sc : OclFile; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().run() ); operation initialiseInstance() pre: true post: true activity: sc := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; ; operation run() : void pre: true post: true activity: ( var primes : Set(int) ; primes := sieve(1000000) ; var n : int ; n := sc.getCurrent()->toInteger() ; var m : int ; m := sc.getCurrent()->toInteger() ; var a : Sequence(Sequence(int)) ; a := Integer.subrange(1,n)->collect(Integer.subrange(1,m)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < m do ( ( var num : int ; num := sc.getCurrent()->toInteger() ; a[i+1][j+1] := primes.ceiling(num) - num ) ; j := j + 1 ) ) ; i := i + 1 ) ; var min : int ; min := 2147483647 ; for (row : a) do ( ( min := Set{min, stream(row)->sum()}->min() ) ) ; var i : int ; i := 0 ; while i < m do ( ( var sum : int ; sum := 0 ; var j : int ; j := 0 ; while j < n do ( ( sum := sum+(a[j+1][i+1]) ) ; j := j + 1 ) ; min := Set{min, sum}->min() ) ; i := i + 1 ) ; OclFile["System.out"].println(min) ; ); operation sieve( n : int) : Set(int) pre: true post: true activity: ( var non_primes : Sequence(boolean) ; non_primes := Integer.subrange(1,n + 1)->collect(false) ; var set : Set(int) ; set := Set{} ; var i : int ; i := 2 ; while i * i <= n do ( ( if (not(non_primes[i+1])) then ( var j : int ; j := 2 * i ; while j <= n do ( ( non_primes[j+1] := true ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i <= n do ( if (not(non_primes[i+1])) then set := set->including(i) ; else skip ; ; i := i + 1 ) ; return set ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ final long MOD=(long)1e9+7 ; Scanner sc=new Scanner(System.in); int r1=sc.nextInt(); int c1=sc.nextInt(); int r2=sc.nextInt(); int c2=sc.nextInt(); int sumMax=r2+c2+1 ; long[] frac=new long[sumMax+1]; long[] frac_inv=new long[sumMax+1]; frac[0]=1 ; frac_inv[0]=1 ; for(int i=1 ; i<=sumMax ; i++){ frac[i]=(frac[i-1]*i)% MOD ; frac_inv[i]=modinv(frac[i],MOD); } long ans=0 ; for(int i=r1 ; i<=r2 ; i++){ long tmp1=0 ; long tmp2=0 ; tmp1=(frac[i+c2+1]*frac_inv[c2])% MOD ; tmp2=(frac[i+c1]*frac_inv[c1-1])% MOD ; long tmp=(tmp1-tmp2+MOD)% MOD ; tmp=(tmp*frac_inv[i+1])% MOD ; ans=(ans+tmp)% MOD ; } System.out.println(ans); } static long modpow(long a,long n,long mod){ long res=1 ; while(n>0){ if((n & 1)==1){ res=(res*a)% mod ; } a=(a*a)% mod ; n>>=1 ; } return res ; } static long modinv(long a,long mod){ return modpow(a,mod-2,mod); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var MOD : long ; MOD := 1e9->oclAsType(long) + 7 ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var r1 : int ; r1 := sc.getCurrent()->toInteger() ; var c1 : int ; c1 := sc.getCurrent()->toInteger() ; var r2 : int ; r2 := sc.getCurrent()->toInteger() ; var c2 : int ; c2 := sc.getCurrent()->toInteger() ; var sumMax : int ; sumMax := r2 + c2 + 1 ; var frac : Sequence(long) ; frac := Integer.subrange(1,sumMax + 1)->collect(0) ; var frac_inv : Sequence(long) ; frac_inv := Integer.subrange(1,sumMax + 1)->collect(0) ; frac[0+1] := 1 ; frac_inv[0+1] := 1 ; var i : int ; i := 1 ; while i <= sumMax do ( ( frac[i+1] := (frac[i - 1+1] * i) mod MOD ; frac_inv[i+1] := modinv(frac[i+1], MOD) ) ; i := i + 1 ) ; var ans : long ; ans := 0 ; var i : int ; i := r1 ; while i <= r2 do ( ( var tmp1 : long ; tmp1 := 0 ; var tmp2 : long ; tmp2 := 0 ; tmp1 := (frac[i + c2 + 1+1] * frac_inv[c2+1]) mod MOD ; tmp2 := (frac[i + c1+1] * frac_inv[c1 - 1+1]) mod MOD ; var tmp : long ; tmp := (tmp1 - tmp2 + MOD) mod MOD ; tmp := (tmp * frac_inv[i + 1+1]) mod MOD ; ans := (ans + tmp) mod MOD ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation modpow( a : long, n : long, mod : long) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (n > 0) do ( if ((n & 1) = 1) then ( res := (res * a) mod mod ) else skip ; a := (a * a) mod mod ; n := n/(2->pow(1)) ) ; return res ); static operation modinv( a : long, mod : long) : long pre: true post: true activity: ( return modpow(a, mod - 2, mod) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static long fact[]; static long inverse[]; static int mod=1_000_000_007 ; static long pow(long a,int n){ long res=1 ; while(n>0){ if((n-n/2*2)==1){ res=res*a % mod ; } a=a*a % mod ; n>>=1 ; } return res ; } static long modinv(long n){ return pow(n,mod-2); } static long comb(int n,int k){ if(n<0 || k<0 || n 0) do ( if ((n - n / 2 * 2) = 1) then ( res := res * a mod mod ) else skip ; a := a * a mod mod ; n := n/(2->pow(1)) ) ; return res ); static operation modinv( n : long) : long pre: true post: true activity: ( return pow(n, mod - 2) ); static operation comb( n : int, k : int) : long pre: true post: true activity: ( if (n < 0 or k < 0 or n < k) then return 0 else skip ; return fact[n+1] * (inverse[k+1] * inverse[n - k+1] mod mod) mod mod ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; fact := Integer.subrange(1,2400005)->collect(0) ; fact[0+1] := 1 ; inverse := Integer.subrange(1,2400005)->collect(0) ; inverse[0+1] := 1 ; var i : int ; i := 1 ; while i < 2400005 do ( ( fact[i+1] := (fact[i - 1+1] * i->oclAsType(long)) mod mod ; inverse[i+1] := modinv(fact[i+1]) ) ; i := i + 1 ) ; var r1 : int ; r1 := sc.getCurrent()->toInteger() ; var c1 : int ; c1 := sc.getCurrent()->toInteger() ; var r2 : int ; r2 := sc.getCurrent()->toInteger() ; var c2 : int ; c2 := sc.getCurrent()->toInteger() ; var ans : long ; ans := 0L ; var i : int ; i := r1 ; while i < r2 + 1 do ( ( ans := (ans + comb(i + c2 + 1, c2) - comb(i + c1, c1 - 1)) mod mod ) ; i := i + 1 ) ; ans := (ans + mod) mod mod ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int mod=1_000_000_007 ; Combination com=new Combination(n,mod); long ans=0L ; int m=k0){ if((exp & 1)==1){ ret=ret*base % mod ; } base=base*base % mod ; exp>>=1 ; } return ret ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var mod : int ; mod := 1_000_000_007 ; var com : Combination ; com := Combination.newCombination(n, mod) ; var ans : long ; ans := 0L ; var m : int ; m := if k < n then k else n - 1 endif ; var i : int ; i := 0 ; while i <= m do ( ( var z : long ; z := com.comb(n, i) ; var c : long ; c := com.comb(n - 1, i) ; ans := (ans + (z * c mod mod)) mod mod ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; skip ; ); } class Combination { attribute fac : Sequence(long); attribute inv : Sequence(long); attribute mod : int; static operation newCombination( size : int, mod : int) : Combination pre: true post: true activity: ( var self : Combination ; self := createCombination(); self.initialise(size, mod); return self ); operation initialise( size : int, mod : int) : void pre: true post: true activity: ( self.fac := Integer.subrange(1,size + 1)->collect(0) ; self.inv := Integer.subrange(1,size + 1)->collect(0) ; self.mod := mod ; self.fac[0+1] := 1 ; self.inv[0+1] := 1 ; var i : int ; i := 1 ; while i <= size do ( ( fac[i+1] := (fac[i - 1+1] * i) mod mod ; inv[i+1] := modPow(fac[i+1], mod->oclAsType(int) - 2) mod mod ) ; i := i + 1 ) ; ); operation comb( n : int, r : int) : long pre: true post: true activity: ( return fac[n+1] * inv[r+1] mod mod * inv[n - r+1] mod mod ); operation modPow( base : long, exp : int) : long pre: true post: true activity: ( var ret : long ; ret := 1 ; while (exp > 0) do ( if ((exp & 1) = 1) then ( ret := ret * base mod mod ) else skip ; base := base * base mod mod ; exp := exp/(2->pow(1)) ) ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int MAX_FAC=400001 ; static long FAC[]=new long[MAX_FAC]; static long INV_FAC[]=new long[MAX_FAC]; private static long MOD=1_000_000_007 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long k=sc.nextLong(); long ans=0 ; initFAC(); if(k==1){ ans=(n*(n-1))% MOD ; } else { for(long i=1 ; i<=Math.min(k,n-1); i++){ ans+=((bara((int)n,(int)(n-i))*comb((int)n,(int)i))% MOD); ans %=MOD ; } ans++; ans %=MOD ; } System.out.println(ans); } static long comb(int n,int k){ return(((FAC[n]*INV_FAC[n-k])% MOD)*INV_FAC[k])% MOD ; } static void initFAC(){ FAC[0]=1 ; INV_FAC[0]=modinv(FAC[0]); for(int i=1 ; icollect(0); static attribute INV_FAC : long := Integer.subrange(1,MAX_FAC)->collect(0); static attribute MOD : long := 1_000_000_007; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : long ; n := sc.getCurrent()->toLong() ; var k : long ; k := sc.getCurrent()->toLong() ; var ans : long ; ans := 0 ; execute initFAC() ; if (k = 1) then ( ans := (n * (n - 1)) mod MOD ) else ( var i : long ; i := 1 ; while i <= Set{k, n - 1}->min() do ( ( ans := ans+(((bara(n->oclAsType(int), (n - i)->oclAsType(int)) * comb(n->oclAsType(int), i->oclAsType(int))) mod MOD)) ; ans := ans mod MOD ) ; i := i + 1 ) ; ans := ans + 1 ; ans := ans mod MOD ) ; OclFile["System.out"].println(ans) ; ); static operation comb( n : int, k : int) : long pre: true post: true activity: ( return (((FAC[n+1] * INV_FAC[n - k+1]) mod MOD) * INV_FAC[k+1]) mod MOD ); static operation initFAC() : void pre: true post: true activity: ( FAC[0+1] := 1 ; INV_FAC[0+1] := modinv(FAC[0+1]) ; var i : int ; i := 1 ; while i < MAX_FAC do ( ( FAC[i+1] := (i * FAC[i - 1+1]) mod MOD ; INV_FAC[i+1] := modinv(FAC[i+1]) ) ; i := i + 1 ) ); static operation modpow( a : long, b : long) : long pre: true post: true activity: ( if (b = 1) then ( return a mod MOD ) else skip ; if (b = 0) then ( return 1 ) else skip ; var res : long ; res := b / 2 ; var rem : long ; rem := b mod 2 ; var p : long ; p := modpow(a, res) mod MOD ; if (rem = 1) then ( return (((p * p) mod MOD) * a) mod MOD ) else ( return (p * p) mod MOD ) ; ); static operation modinv( a : long) : long pre: true post: true activity: ( return modpow(a, MOD - 2) ); static operation bara( n : int, k : int) : long pre: true post: true activity: ( return comb(n - 1, k - 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; import java.math.*; public class codeforces { public static void main(String args[])throws IOException { File file=new File("input.txt"); Scanner sc=new Scanner(file); FileWriter fw=new FileWriter("output.txt"); int n=sc.nextInt(); String s=sc.next(); String st="" ; int l=s.length(); for(int i=0 ; itoInteger() ; var s : String ; s := sc.getCurrent() ; var st : String ; st := "" ; var l : int ; l := s->size() ; var i : int ; i := 0 ; while i < l / 2 do ( ( var ch1 : String ; ch1 := s->at(i+1) ; var ch2 : String ; ch2 := s->at(l / 2 + i+1) ; if (ch1 = 'R' & ch2 = 'L') then ( st := ((l / 2 + i + 1) + "") + " " + ((i + 1) + "") ) else ( st := ((i + 1) + "") + " " + ((l / 2 + i + 1) + "") ) ; skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static long fact[]; static long inverse[]; static int mod=1_000_000_007 ; static long pow(long a,int n){ long res=1 ; while(n>0){ if((n-n/2*2)==1){ res=res*a % mod ; } a=a*a % mod ; n>>=1 ; } return res ; } static long modinv(long n){ return pow(n,mod-2); } static long comb(int n,int k){ if(n<0 || k<0 || n=n-1){ System.out.println(comb(n+n-1,n-1)); return ; } long ans=0L ; for(int i=0 ; i<=k ; i++){ ans=(ans+comb(n,i)*comb(n-(n-i)+(n-i)-1,n-i-1)% mod)% mod ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute fact : Sequence(long); static attribute inverse : Sequence(long); static attribute mod : int := 1_000_000_007; static operation pow( a : long, n : int) : long pre: true post: true activity: ( var res : long ; res := 1 ; while (n > 0) do ( if ((n - n / 2 * 2) = 1) then ( res := res * a mod mod ) else skip ; a := a * a mod mod ; n := n/(2->pow(1)) ) ; return res ); static operation modinv( n : long) : long pre: true post: true activity: ( return pow(n, mod - 2) ); static operation comb( n : int, k : int) : long pre: true post: true activity: ( if (n < 0 or k < 0 or n < k) then return 0 else skip ; return fact[n+1] * (inverse[k+1] * inverse[n - k+1] mod mod) mod mod ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( fact := Integer.subrange(1,500000)->collect(0) ; fact[0+1] := 1 ; inverse := Integer.subrange(1,500000)->collect(0) ; inverse[0+1] := 1 ; var i : int ; i := 1 ; while i < 500000 do ( ( fact[i+1] := (fact[i - 1+1] * i->oclAsType(long)) mod mod ; inverse[i+1] := modinv(fact[i+1]) ) ; i := i + 1 ) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; if (k >= n - 1) then ( OclFile["System.out"].println(comb(n + n - 1, n - 1)) ; return ) else skip ; var ans : long ; ans := 0L ; var i : int ; i := 0 ; while i <= k do ( ( ans := (ans + comb(n, i) * comb(n - (n - i) + (n - i) - 1, n - i - 1) mod mod) mod mod ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Contest { public static void main(String[] args){ Scanner in=new Scanner(System.in); int x=in.nextInt(); int t=in.nextInt(); int a=in.nextInt(); int b=in.nextInt(); int da=in.nextInt(); int db=in.nextInt(); Setpos=new HashSet<>(); pos.add(0); for(int i=0 ; itoInteger() ; var t : int ; t := in.getCurrent()->toInteger() ; var a : int ; a := in.getCurrent()->toInteger() ; var b : int ; b := in.getCurrent()->toInteger() ; var da : int ; da := in.getCurrent()->toInteger() ; var db : int ; db := in.getCurrent()->toInteger() ; var pos : Set(int) ; pos := Set{} ; pos := pos->including(0) ; var i : int ; i := 0 ; while i < t do ( ( pos := pos->including(a - da * i) ; pos := pos->including(b - db * i) ; var j : int ; j := 0 ; while j < t do ( ( pos := pos->including(a - da * i + b - db * j) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(if pos->includes(x) then "YES" else "NO" endif) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static final long MOD=1000000007 ; static long modpow(long n,long y){ if(y==0){ return 1 ; } else if(y==1){ return n % MOD ; } else { if(y % 2==0){ long r=modpow(n,y/2); return(r*r)% MOD ; } else { long r=modpow(n,y/2); long r2=(r*r)% MOD ; return(r2*n)% MOD ; } } } static long modinv(long n){ return modpow(n,MOD-2); } static long comb(int N,int R,long fact[]){ long ret=fact[N]; ret=(ret*modinv(fact[R]))% MOD ; ret=(ret*modinv(fact[N-R]))% MOD ; return ret ; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); long fact[]=new long[2*n]; fact[0]=1 ; fact[1]=1 ; for(int i=2 ; i=n){ System.out.println(comb(2*n-1,n,fact)); return ; } long S=1 ; for(int i=1 ; i<=k ; ++i){ long x=comb(n,i,fact); long y=comb(n-1,i,fact); S+=(x*y)% MOD ; S=S % MOD ; } System.out.println(S); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute MOD : long := 1000000007; static operation modpow( n : long, y : long) : long pre: true post: true activity: ( if (y = 0) then ( return 1 ) else if (y = 1) then ( return n mod MOD ) else ( if (y mod 2 = 0) then ( var r : long ; r := modpow(n, y / 2) ; return (r * r) mod MOD ) else ( var r : long ; r := modpow(n, y / 2) ; var r2 : long ; r2 := (r * r) mod MOD ; return (r2 * n) mod MOD ) ) ; ); static operation modinv( n : long) : long pre: true post: true activity: ( return modpow(n, MOD - 2) ); static operation comb( N : int, R : int, fact : Sequence(long)) : long pre: true post: true activity: ( var ret : long ; ret := fact[N+1] ; ret := (ret * modinv(fact[R+1])) mod MOD ; ret := (ret * modinv(fact[N - R+1])) mod MOD ; return ret ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var fact : Sequence(long) ; fact := Integer.subrange(1,2 * n)->collect(0) ; fact[0+1] := 1 ; fact[1+1] := 1 ; var i : int ; i := 2 ; while i < fact->size() do ( ( fact[i+1] := ((i)->oclAsType(long) * fact[i - 1+1]) mod MOD ) ; i := i + 1 ) ; if (k >= n) then ( OclFile["System.out"].println(comb(2 * n - 1, n, fact)) ; return ) else skip ; var S : long ; S := 1 ; var i : int ; i := 1 ; while i <= k do ( ( var x : long ; x := comb(n, i, fact) ; var y : long ; y := comb(n - 1, i, fact) ; S := S+((x * y) mod MOD) ; S := S mod MOD ) ; i := i + 1 ) ; OclFile["System.out"].println(S) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class GFG { final static int MAX=100005 ; static void precompute(int prefix[],int suffix[]){ boolean prime[]=new boolean[MAX]; for(int i=0 ; i1 ; i--){ if(prime[i]){ suffix[i]=i ; } else { suffix[i]=suffix[i+1]; } } } static int query(int prefix[],int suffix[],int L,int R){ if(prefix[R]R){ return 0 ; } else { return prefix[R]-suffix[L]; } } public static void main(String[] args){ int q=3 ; int L[]={ 2,2,24 }; int R[]={ 5,2,28 }; int prefix[]=new int[MAX],suffix[]=new int[MAX]; precompute(prefix,suffix); for(int i=0 ; icollect(false) ; var i : int ; i := 0 ; while i < MAX do ( ( prime[i+1] := true ) ; i := i + 1 ) ; var i : int ; i := 2 ; while i * i < MAX do ( ( if (prime[i+1]) then ( var j : int ; j := i + i ; while j < MAX do ( ( prime[j+1] := false ) ; j := j+(i) ) ) else skip ) ; i := i + 1 ) ; prefix[1+1] := 1 ; suffix[MAX - 1+1] := 1e9->oclAsType(int) + 7 ; var i : int ; i := 2 ; while i < MAX do ( ( if (prime[i+1]) then ( prefix[i+1] := i ) else ( prefix[i+1] := prefix[i - 1+1] ) ) ; i := i + 1 ) ; var i : int ; i := 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 ) ; ); static operation query( prefix : Sequence(int), suffix : Sequence(int), L : int, R : int) : int pre: true post: true activity: ( if (prefix[R+1] < L or suffix[L+1] > R) then ( return 0 ) else ( return prefix[R+1] - suffix[L+1] ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var q : int ; q := 3 ; var L : Sequence(int) ; L := Sequence{2,2,24} ; var R : Sequence(int) ; R := Sequence{5,2,28} ; var prefix : Sequence(int) ; prefix := Integer.subrange(1,MAX)->collect(0) ; var suffix : Sequence(void) ; suffix := Integer.subrange(1,MAX)->collect(0) ; execute precompute(prefix, suffix) ; var i : int ; i := 0 ; while i < q do ( ( OclFile["System.out"].println(query(prefix, suffix, L[i+1], R[i+1])) ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static final int V_SUM_MAX=1000 ; static final int N_MAX=100 ; static final int W_MAX=10000000 ; static int dp[][]=new int[V_SUM_MAX+1][N_MAX]; static boolean v[][]=new boolean[V_SUM_MAX+1][N_MAX]; static int solveDp(int r,int i,int w[],int val[],int n){ if(r<=0)return 0 ; if(i==n)return W_MAX ; if(v[r][i])return dp[r][i]; v[r][i]=true ; dp[r][i]=Math.min(solveDp(r,i+1,w,val,n),w[i]+solveDp(r-val[i],i+1,w,val,n)); return dp[r][i]; } static int maxWeight(int w[],int val[],int n,int c){ for(int i=V_SUM_MAX ; i>=0 ; i--){ if(solveDp(i,0,w,val,n)<=c){ return i ; } } return 0 ; } public static void main(String[] args){ int w[]={ 3,4,5 }; int val[]={ 30,50,60 }; int n=w.length ; int C=8 ; System.out.println(maxWeight(w,val,n,C)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static attribute V_SUM_MAX : int := 1000; static attribute N_MAX : int := 100; static attribute W_MAX : int := 10000000; static attribute dp : int := Integer.subrange(1,V_SUM_MAX + 1)->collect(Integer.subrange(1,N_MAX)->collect(0)); static attribute v : boolean := Integer.subrange(1,V_SUM_MAX + 1)->collect(Integer.subrange(1,N_MAX)->collect(false)); static operation solveDp( r : int, i : int, w : Sequence(int), val : Sequence(int), n : int) : int 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] := true ; 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] ); static operation maxWeight( w : Sequence(int), val : Sequence(int), n : int, c : int) : int pre: true post: true activity: ( var i : int ; i := V_SUM_MAX ; while i >= 0 do ( ( if (solveDp(i, 0, w, val, n) <= c) then ( return i ) else skip ) ; i := i - 1 ) ; return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var w : Sequence(int) ; w := Sequence{3,4,5} ; var val : Sequence(int) ; val := Sequence{30,50,60} ; var n : int ; n := w->size() ; var C : int ; C := 8 ; OclFile["System.out"].println(maxWeight(w, val, n, C)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Solve { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t>0){ int n=scanner.nextInt(); int[] arr=new int[n]; for(int i=0 ; i=0 ; i--){ if(remaining0){ remaining=arr[i]; } sb.append(remaining>0 ? 1+" " : 0+" "); remaining--; } System.out.println(sb.reverse()); t--; } } } ------------------------------------------------------------ OCL File: --------- class Solve { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := scanner.getCurrent()->toInteger() ; while (t > 0) do ( var n : int ; n := scanner.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( ( arr[i+1] := scanner.getCurrent()->toInteger() ) ; i := i + 1 ) ; var sb : String ; sb := StringLib.newString() ; var remaining : int ; remaining := 0 ; var i : int ; i := arr->size() - 1 ; while i >= 0 do ( ( if (remaining < arr[i+1] & arr[i+1] > 0) then ( remaining := arr[i+1] ) else skip ; sb := sb + StringLib.newString(if remaining > 0 then 1 + " " else 0 + " " endif) ; remaining := remaining - 1 ) ; i := i - 1 ) ; OclFile["System.out"].println(sb->reverse()) ; t := t - 1 ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; import java.util.Stack ; public class _1501B_NapoleanCake { public static void main(String[] args){ Scanner input=new Scanner(System.in); int test=Integer.parseInt(input.nextLine()); while(test-->0){ int creamUnit=Integer.parseInt(input.nextLine()); Stackcreams=new Stack<>(); int[] result=new int[creamUnit]; for(int i=0 ; i=0){ int num=creams.peek(); if(num==0){ creamUnit--; creams.pop(); continue ; } while(num>0 && creamUnit>=0){ result[creamUnit--]=1 ; if(creams.peek()>num){ num=creams.peek(); } creams.pop(); num-=1 ; } } System.out.println(Arrays.toString(result).replaceAll("[\\[\\],] ","")); } } } ------------------------------------------------------------ OCL File: --------- class _1501B_NapoleanCake { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var test : int ; test := (input.nextLine())->toInteger() ; while (test > 0) do ( test := test - 1 ; skip ; ( var creamUnit : int ; creamUnit := (input.nextLine())->toInteger() ; var creams : Sequence(int) ; creams := Sequence{} ; var result : Sequence(int) ; result := Integer.subrange(1,creamUnit)->collect(0) ; var i : int ; i := 0 ; while i < creamUnit do ( ( creams := creams->including(input.getCurrent()->toInteger()) ) ; i := i + 1 ) ; skip ; creamUnit := creamUnit - 1 ; while (not(creams->isEmpty()) & creamUnit >= 0) do ( var num : int ; num := creams->min() ; if (num = 0) then ( creamUnit := creamUnit - 1 ; creams := creams->front() ; continue ) else skip ; while (num > 0 & creamUnit >= 0) do ( result[creamUnit+1] := 1 ; creamUnit := creamUnit - 1 ; if (creams->min() > num) then ( num := creams->min() ) else skip ; creams := creams->front() ; num := num-(1) ) ) ; OclFile["System.out"].println((result + "").replaceAllMatches("[\\[\\],] ", "" )) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class AA { static int[] gem ; static int[][] dp ; static int d ; static int max=-1 ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0 ; iad=new ArrayDeque(); for(int j=0 ; j0 && ad.peekLast()>lim)ad.pollLast(); } for(int j=0 ; j0 && ad.peekFirst()==j){ System.out.print(0+" "); ad.pollFirst(); } else System.out.print(1+" "); } System.out.println(); } sc.close(); } } ------------------------------------------------------------ OCL File: --------- class AA { static attribute gem : Sequence(int); static attribute dp : Sequence(Sequence(int)); static attribute d : int; static attribute max : int := -1; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := sc.getCurrent()->toInteger() ; var ad : Sequence(int) ; ad := ArrayDeque.newArrayDeque() ; var j : int ; j := 0 ; while j < n do ( ( ad := ad->including(j) ; var q : int ; q := sc.getCurrent()->toInteger() ; var lim : int ; lim := j - q ; while (ad->size() > 0 & ad.peekLast() > lim) do ad := ad->front() ; ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( if (ad->size() > 0 & ad.peekFirst() = j) then ( OclFile["System.out"].print(0 + " ") ; ad := ad->tail() ) else OclFile["System.out"].print(1 + " ") ; ) ; j := j + 1 ) ; OclFile["System.out"].println() ; ) ; i := i + 1 ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static void findValues(int a,int b){ if((a-b)% 2==1){ System.out.println("-1"); return ; } System.out.println(((a-b)/2)+" "+((a+b)/2)); } public static void main(String[] args){ int a=12,b=8 ; findValues(a,b); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findValues( a : int, b : int) : void pre: true post: true activity: ( if ((a - b) mod 2 = 1) then ( OclFile["System.out"].println("-1") ; return ) else skip ; OclFile["System.out"].println(((a - b) / 2) + " " + ((a + b) / 2)) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : int ; a := 12 ; var b : int ; b := 8 ; execute findValues(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner scanner=new Scanner(System.in); public static void main(String[] $){ int n=scanner.nextInt(); int[][] dist=new int[n][n]; long sum=0 ; for(int i=0 ; idist[j][i]+dist[i][k]){ System.out.println(-1); return ; } } } } for(int i=1 ; itoInteger() ; var dist : Sequence(Sequence(int)) ; dist := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( dist[i+1][j+1] := scanner.getCurrent()->toInteger() ; sum := sum+(dist[i+1][j+1]) ) ; j := j + 1 ) ) ; i := i + 1 ) ; sum := sum/(2) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( var k : int ; k := 0 ; while k < n do ( ( if (dist[j+1][k+1] > dist[j+1][i+1] + dist[i+1][k+1]) then ( OclFile["System.out"].println(-1) ; return ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( var j : int ; j := 0 ; while j < i do ( ( var k : int ; k := 0 ; while k < n do ( ( if (i /= k & j /= k & dist[i+1][j+1] = dist[i+1][k+1] + dist[k+1][j+1]) then ( sum := sum-(dist[i+1][j+1]) ; break ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static int n ; static int[][] dist ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); n=sc.nextInt(); dist=new int[n][n]; for(int i=0 ; idist[i][k]+dist[k][j]){ System.out.println(-1); return ; } if(! subtracted[i][j] && dist[i][j]==dist[i][k]+dist[k][j]){ sum-=(long)dist[i][j]; subtracted[i][j]=true ; } } } } System.out.println(sum); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute n : int; static attribute dist : Sequence(Sequence(int)); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; n := sc.getCurrent()->toInteger() ; dist := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( dist[i+1][j+1] := sc.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var sum : long ; sum := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( sum := sum+(dist[i+1][j+1]->oclAsType(long)) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var subtracted : Sequence(Sequence(boolean)) ; subtracted := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(false)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var k : int ; k := 0 ; while k < n do ( ( if (k = i or k = j) then ( continue ) else skip ; if (dist[i+1][j+1] > dist[i+1][k+1] + dist[k+1][j+1]) then ( OclFile["System.out"].println(-1) ; return ) else skip ; if (not(subtracted[i+1][j+1]) & dist[i+1][j+1] = dist[i+1][k+1] + dist[k+1][j+1]) then ( sum := sum-(dist[i+1][j+1]->oclAsType(long)) ; subtracted[i+1][j+1] := true ) else skip ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sum) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class GfG { private static int table[][]; private static int height ; private GfG(int n){ height=(int)Math.ceil(Math.log10(n)/Math.log10(2)); table=new int[n+1][height+1]; } private static void preprocessing(){ for(int i=0 ; ilog10() / (2)->log10())->ceil()->oclAsType(int) ; table := Integer.subrange(1,n + 1)->collect(Integer.subrange(1,height + 1)->collect(0)) ); static operation preprocessing() : void pre: true post: true activity: ( var i : int ; i := 0 ; while i < table->size() do ( ( table[i+1] := table[i+1]->collect(-1) ) ; i := i + 1 ) ); static operation calculateSparse( u : int, v : int) : void pre: true post: true activity: ( table[v+1][0+1] := u ; var i : int ; i := 1 ; while i <= height do ( ( table[v+1][i+1] := table[table[v+1][i - 1+1]+1][i - 1+1] ; if (table[v+1][i+1] = -1) then break else skip ) ; i := i + 1 ) ); static operation kthancestor( V : int, k : int) : int pre: true post: true activity: ( var i : int ; i := 0 ; while i <= height do ( ( if ((k & ((1*(2->pow(i)))->oclAsType(long))) /= 0) then ( V := table[V+1][i+1] ; if (V = -1) then break else skip ) else skip ) ; i := i + 1 ) ; return V ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 6 ; var obj : GfG ; obj := GfG.newGfG(n) ; execute preprocessing() ; execute calculateSparse(1, 2) ; execute calculateSparse(1, 3) ; execute calculateSparse(2, 4) ; execute calculateSparse(2, 5) ; execute calculateSparse(3, 6) ; var K : int ; K := 2 ; var V : int ; V := 5 ; OclFile["System.out"].print(kthancestor(V, K)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ long a=sc.nextLong(); long b=sc.nextLong(); System.out.println(toPaddedBinaryString(a & b)); System.out.println(toPaddedBinaryString(a | b)); System.out.println(toPaddedBinaryString(a ^ b)); } } public static String toPaddedBinaryString(long bin){ String result=String.format("%32s",Long.toBinaryString(bin)).replaceAll(" ","0"); if(result.length()>32)return result.substring(result.length()-32); return result ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; OclFile["System.out"].println(toPaddedBinaryString(MathLib.bitwiseAnd(a,b))) ; OclFile["System.out"].println(toPaddedBinaryString(MathLib.bitwiseOr(a,b))) ; OclFile["System.out"].println(toPaddedBinaryString(MathLib.bitwiseXor(a,b))) ; )) ); static operation toPaddedBinaryString( bin : long) : String pre: true post: true activity: ( var result : String ; result := StringLib.format("%32s",Sequence{(MathLib.decimal2binary(bin) + "")}).replaceAllMatches(" ", "0" ) ; if (result->size() > 32) then return result.subrange(result->size() - 32+1,result->size() - 32) else skip ; return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { private void solve(){ int x=nextInt(); int t=nextInt(); int a=nextInt(); int b=nextInt(); int da=nextInt(); int db=nextInt(); int first ; int second ; boolean ok=false ; for(int i=0 ; itoInteger() ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ; return "END_OF_FILE" ) ) ; return st.next() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); DRestoringRoadNetwork solver=new DRestoringRoadNetwork(); solver.solve(1,in,out); out.close(); } static class DRestoringRoadNetwork { public void solve(int testNumber,Scanner in,PrintWriter out){ int n=in.nextInt(); int[][] remTable=new int[n][n]; long ans=0 ; for(int i=0 ; iremTable[i][k]+remTable[k][j]){ ans=-1 ; break ; } else if(remTable[i][j]==remTable[i][k]+remTable[k][j]){ need=false ; } } if(ans==-1)continue ; if(need){ ans+=remTable[i][j]; } } } out.println(ans); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : OclFile ; in := OclFile.newOclFile_Read(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : DRestoringRoadNetwork ; solver := DRestoringRoadNetwork.newDRestoringRoadNetwork() ; solver.solve(1, in, out) ; skip ; ); static class DRestoringRoadNetwork { operation solve( testNumber : int, in : OclFile, out : OclFile) : void pre: true post: true activity: ( var n : int ; n := in.getCurrent()->toInteger() ; var remTable : Sequence(Sequence(int)) ; remTable := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( remTable[i+1][j+1] := in.getCurrent()->toInteger() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := i + 1 ; while j < n do ( ( var need : boolean ; need := true ; var k : int ; k := 0 ; while k < n do ( ( if (i = k or k = j) then continue else skip ; if (remTable[i+1][j+1] > remTable[i+1][k+1] + remTable[k+1][j+1]) then ( ans := -1 ; break ) else if (remTable[i+1][j+1] = remTable[i+1][k+1] + remTable[k+1][j+1]) then ( need := false ) else skip ; ) ; k := k + 1 ) ; if (ans = -1) then continue else skip ; if (need) then ( ans := ans+(remTable[i+1][j+1]) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public final class Main { public static void main(String[] args){ Scanner s=new Scanner(System.in); int N=s.nextInt(); long[][] length=new long[N][N]; for(int i=0 ; itoInteger() ; var length : Sequence(Sequence(long)) ; length := Integer.subrange(1,N)->collect(Integer.subrange(1,N)->collect(0)) ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := 0 ; while j < N do ( ( length[i+1][j+1] := s.getCurrent()->toLong() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var result : long ; result := 0 ; var i : int ; i := 0 ; while i < N do ( ( var j : int ; j := i + 1 ; while j < N do ( ( var dist : long ; dist := length[i+1][j+1] ; var flag : boolean ; flag := true ; var k : int ; k := 0 ; while k < N do ( ( if (k = i or k = j) then continue else skip ; var sum : long ; sum := length[i+1][k+1] + length[k+1][j+1] ; if (sum < dist) then ( OclFile["System.out"].print(-1) ; return ) else if (sum = dist) then ( flag := false ) else skip ; ) ; k := k + 1 ) ; if (flag) then result := result+(dist) ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].print(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args)throws Exception { FastReader sc=new FastReader(); String s=sc.next(); StringBuffer snew=new StringBuffer(); char d=s.charAt(0); if((int)s.charAt(0)>=97 &&(int)s.charAt(0)<=122)d=(char)(s.charAt(0)-32); snew.append(d); snew.append(s.substring(1)); System.out.println(snew.toString()); } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : FastReader ; sc := FastReader.newFastReader() ; var s : String ; s := sc.next() ; var snew : String ; snew := StringLib.newString() ; var d : String ; d := s->at(0+1) ; if (s->at(0+1)->oclAsType(int) >= 97 & s->at(0+1)->oclAsType(int) <= 122) then d := (s->at(0+1) - 32)->oclAsType(String) ; else skip ; snew := snew + StringLib.newString(d) ; snew := snew + StringLib.newString(s.subrange(1+1,1)) ; OclFile["System.out"].println(snew+"") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.util.Scanner ; public class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s=sc.next(); char[] ch=s.toCharArray(); ch[0]=Character.toUpperCase(ch[0]); for(int i=0 ; icharacters() ; ch[0+1] := (ch[0+1] + "")->toUpperCase() ; var i : int ; i := 0 ; while i < ch->size() do ( OclFile["System.out"].print(ch[i+1]) ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.lang.String ; public class CapialWord { public static void main(String[] args){ String s ; Scanner sc=new Scanner(System.in); s=sc.next(); int i,len=s.length(); char[] ch=new char[len]; ch=s.toCharArray(); ch[0]=Character.toUpperCase(ch[0]); System.out.println(ch); } } ------------------------------------------------------------ OCL File: --------- class CapialWord { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var s : String ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; s := sc.getCurrent() ; var i : int ; var len : int ; len := s->size() ; var ch : Sequence(String) ; ch := Integer.subrange(1,len)->collect(0) ; ch := s->characters() ; ch[0+1] := (ch[0+1] + "")->toUpperCase() ; OclFile["System.out"].println(ch) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s=sc.next(); for(int i=0 ; isize() do ( ( if (i = 0) then ( OclFile["System.out"].print(("" + s->at(0+1))->toUpperCase()) ; continue ) else ( OclFile["System.out"].print(s->at(i+1)) ) ) ; i := i + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.awt.*; import java.util.Scanner ; import java.util.Arrays ; import java.text.NumberFormat ; import java.math.*; public class Main { public static void aMethod(){ Scanner scanner=new Scanner(System.in); String word=scanner.nextLine(); System.out.print(word.substring(0,1).toUpperCase()); System.out.println(word.substring(1,word.length())); } public static void main(String[] args){ aMethod(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation aMethod() : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var word : String ; word := scanner.nextLine() ; OclFile["System.out"].print(word.subrange(0+1,1)->toUpperCase()) ; OclFile["System.out"].println(word.subrange(1+1,word->size())) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( execute aMethod() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static boolean isSubSeqDivisible(String str){ int i,j,k,l=str.length(); int arr[]=new int[l]; for(i=0 ; isize() ; var arr : Sequence(int) ; arr := Integer.subrange(1,l)->collect(0) ; i := 0 ; while i < l do ( arr[i+1] := str->at(i+1) - ('0')->char2byte() ; ; i := i + 1 ) ; i := 0 ; while i < l do ( ( j := i ; while j < l do ( ( k := j ; while k < l 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 ; ; ) ; k := k + 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "3144" ; if (isSubSeqDivisible(str)) then OclFile["System.out"].println("Yes") ; else OclFile["System.out"].println("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static boolean sumSquare(int n){ HashMaps=new HashMap(); for(int i=0 ; i*i<=n ; ++i){ s.put(i*i,1); if(s.containsKey(n-i*i)){ System.out.println((int)Math.sqrt(n-i*i)+"^2+"+i+"^2"); return true ; } } return false ; } public static void main(String[] args){ int n=169 ; System.out.print(sumSquare(n)? "YES\n" : "NO\n"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation sumSquare( n : int) : boolean pre: true post: true activity: ( var s : Map(int,int) ; s := Map{} ; var i : int ; i := 0 ; while i * i <= n do ( ( s := s->union(Map{i * i |-> 1}) ; if (s->keys()->includes(n - i * i)) then ( OclFile["System.out"].println((n - i * i)->sqrt()->oclAsType(int) + "^2+" + i + "^2") ; return true ) else skip ) ; i := i + 1 ) ; return false ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 169 ; OclFile["System.out"].print(if sumSquare(n) then "YES\n" else "NO\n" endif) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileNotFoundException ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; import java.util.Stack ; public class test { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(),t=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(),da=sc.nextInt(),db=sc.nextInt(); boolean found=x==0 ; for(int xa=0 ; xatoInteger() ; var t : int ; t := sc.getCurrent()->toInteger() ; var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var da : int ; da := sc.getCurrent()->toInteger() ; var db : int ; db := sc.getCurrent()->toInteger() ; var found : boolean ; found := x = 0 ; var xa : int ; xa := 0 ; while xa < t do ( ( if (a - da * xa = x) then found := true ; else skip ; var xb : int ; xb := 0 ; while xb < t do ( ( var points : int ; points := (a - da * xa) + (b - db * xb) ; if (points = x or b - db * xb = x) then ( found := true ) else skip ) ; xb := xb + 1 ) ) ; xa := xa + 1 ) ; if (found) then ( OclFile["System.out"].println("YES") ) else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int evenDecimalValue(String str,int n){ int result=0 ; for(int i=0 ; iat(k+1) - ('0')->char2byte()) * powerOf2)) ; powerOf2 := powerOf2*(2) ) ; k := k + 1 ) ; if (decimalValue mod 2 = 0) then result := result + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "10010" ; var n : int ; n := 5 ; OclFile["System.out"].println(evenDecimalValue(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static int count(int n){ if(n<4)return-1 ; int 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 ; } return 0 ; } public static void main(String[] args){ int n=90 ; System.out.println(count(n)); n=143 ; System.out.println(count(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation count( n : int) : int pre: true post: true activity: ( if (n < 4) then return -1 else skip ; var rem : int ; rem := n mod 4 ; if (rem = 0) then return n / 4 else skip ; if (rem = 1) then ( if (n < 9) then return -1 else skip ; return (n - 9) / 4 + 1 ) else skip ; if (rem = 2) then return (n - 6) / 4 + 1 else skip ; if (rem = 3) then ( if (n < 15) then return -1 else skip ; return (n - 15) / 4 + 2 ) else skip ; return 0 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 90 ; OclFile["System.out"].println(count(n)) ; n := 143 ; OclFile["System.out"].println(count(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; class GFG { static int factorial(int N){ if(N==0 || N==1)return 1 ; return N*factorial(N-1); } static int nthTerm(int N){ return(factorial(N)*(N+2)/2); } public static void main(String args[]){ int N=6 ; System.out.println(nthTerm(N)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation factorial( N : int) : int pre: true post: true activity: ( if (N = 0 or N = 1) then return 1 else skip ; return N * factorial(N - 1) ); static operation nthTerm( N : int) : int pre: true post: true activity: ( return (factorial(N) * (N + 2) / 2) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var N : int ; N := 6 ; OclFile["System.out"].println(nthTerm(N)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.Arrays ; class GFG { static int countTripletsLessThanL(int n,int L,int[] arr){ Arrays.sort(arr); int ways=0 ; for(int i=0 ; icharacters() ; var n : int ; n := str->size() ; OclFile["System.out"].println(count.countSubStr(str, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ int n=sc.nextInt(); HashMapmap=new HashMap<>(); for(int i=0 ; itoInteger() ; while (T > 0) do ( T := T - 1 ; skip ; ( var n : int ; n := sc.getCurrent()->toInteger() ; var map : Map(int,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var b : int ; b := sc.getCurrent()->toInteger() ; var d : int ; d := sc.getCurrent()->toInteger() ; map := map->union(Map{d |-> Set{(if map->keys()->contains(d) then map->at(d) else 0 endif), b}->max()}) ) ; i := i + 1 ) ; if (map.size() = 10) then ( var ans : int ; ans := 0 ; for (k : map->keys()) do ( ans := ans+(map->at(k)) ; ) ; OclFile["System.out"].println(ans) ) else OclFile["System.out"].println("MOREPROBLEMS") ; ) ; ) ; skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ new Main().start(); } private void start(){ Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); int[] a=new int[11]; Arrays.fill(a,-1); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,11)->collect(0) ; a := a->collect(-1) ; var i : int ; i := 0 ; while i < n do ( ( var b : int ; b := in.getCurrent()->toInteger() ; var d : int ; d := in.getCurrent()->toInteger() ; a[d+1] := Set{a[d+1], b}->max() ) ; i := i + 1 ) ; var tot : int ; tot := 0 ; var i : int ; i := 1 ; while i <= 10 do ( ( if (a[i+1] = -1) then ( tot := -1 ; break ) else ( tot := tot+(a[i+1]) ) ) ; i := i + 1 ) ; if (tot < 0) then ( OclFile["System.out"].println("MOREPROBLEMS") ) else ( OclFile["System.out"].println(tot) ) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class r10_1 { public static void main(String[] args){ ArrayListl=new ArrayList(); l.add(1); l.add(2); l.add(3); l.add(4); l.add(5); l.add(6); l.add(7); l.add(8); l.add(9); l.add(10); Scanner sc=new Scanner(System.in); long t=sc.nextLong(); for(int i=0 ; ihm=new HashMap<>(); for(int j=0 ; jhm.get(di)){ hm.replace(di,bi); } } else { hm.put(di,bi); } } ArrayListhm2=new ArrayList<>(hm.keySet()); boolean ans=false ; for(int j=1 ; j<=10 ; j++){ if(! hm2.contains(j)){ System.out.println("MOREPROBLEMS"); ans=true ; break ; } } if(! ans){ long sum=0 ; for(Map.Entryentry : hm.entrySet()){ sum+=entry.getValue(); } System.out.println(sum); } } } } ------------------------------------------------------------ OCL File: --------- class r10_1 { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : Sequence(int) ; l := Sequence{} ; l := l->including(1) ; l := l->including(2) ; l := l->including(3) ; l := l->including(4) ; l := l->including(5) ; l := l->including(6) ; l := l->including(7) ; l := l->including(8) ; l := l->including(9) ; l := l->including(10) ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : long ; t := sc.getCurrent()->toLong() ; var i : int ; i := 0 ; while i < t do ( ( var n : long ; n := sc.getCurrent()->toLong() ; var hm : Map(int,long) ; hm := Map{} ; var j : int ; j := 0 ; while j < n do ( ( var bi : long ; bi := sc.getCurrent()->toLong() ; var di : int ; di := sc.getCurrent()->toInteger() ; if (hm->keys()->includes(di)) then ( if (bi > hm->at(di)) then ( hm := hm.replace(di, bi) ) else skip ) else ( hm := hm->union(Map{di |-> bi}) ) ) ; j := j + 1 ) ; var hm2 : Sequence(int) ; hm2 := Sequence{}->union(hm->keys()) ; var ans : boolean ; ans := false ; var j : int ; j := 1 ; while j <= 10 do ( ( if (not(hm2->includes(j))) then ( OclFile["System.out"].println("MOREPROBLEMS") ; ans := true ; break ) else skip ) ; j := j + 1 ) ; if (not(ans)) then ( var sum : long ; sum := 0 ; for (entry : hm->asSet()) do ( ( sum := sum+(entry.getValue()) ) ) ; OclFile["System.out"].println(sum) ) else skip ; ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public class gfg { static int N=10000 ; static long arr[]=new long[N]; static void seive(){ for(int i=2 ; i*icollect(0); static operation seive() : void pre: true post: true activity: ( var i : int ; i := 2 ; while i * i < N do ( ( if (arr[i+1] = 0) then ( var j : int ; j := 2 ; while i * j < N do ( ( arr[i * j+1] := arr[i * j+1]+(i) ) ; j := j + 1 ) ) else skip ) ; i := i + 1 ) ); static operation sum( l : int, r : int) : long pre: true post: true activity: ( execute seive() ; var pref_arr : Sequence(long) ; pref_arr := Integer.subrange(1,r + 1)->collect(0) ; pref_arr[0+1] := arr[0+1] ; var i : int ; i := 1 ; while i <= r do ( ( pref_arr[i+1] := pref_arr[i - 1+1] + arr[i+1] ) ; i := i + 1 ) ; if (l = 1) then return (pref_arr[r+1]) else return (pref_arr[r+1] - pref_arr[l - 1+1]) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var l : int ; l := 5 ; var r : int ; r := 10 ; OclFile["System.out"].println(sum(l, r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger ; public class Codechef { public static void main(String[] args)throws java.lang.Exception { try { InputStreamReader r=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); String s1=br.readLine(); String s2=br.readLine(); int c1=0,c2=0,startS1=-1,startS2=-1 ; for(int i=0 ; i"); else { String t1=s1.substring(startS1,s1.length()); String t2=s2.substring(startS2,s2.length()); if(t1.length()>t2.length())System.out.println(">"); else if(t2.length()>t1.length())System.out.println("<"); else { int p=-1 ; for(int i=0 ; it2.charAt(i)){ System.out.println(">"); p=0 ; break ; } if(t2.charAt(i)>t1.charAt(i)){ System.out.println("<"); p=0 ; break ; } } if(p==-1)System.out.println("="); } } } catch(Exception e){ } } } ------------------------------------------------------------ OCL File: --------- class Codechef { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var r : OclFile ; r := OclFile.newOclFile_Read(OclFile["System.in"]) ; var br : OclFile ; br := OclFile.newOclFile_Read(r) ; var s1 : String ; s1 := br.readLine() ; var s2 : String ; s2 := br.readLine() ; var c1 : int ; c1 := 0 ; var c2 : int ; c2 := 0 ; var startS1 : int ; startS1 := -1 ; var startS2 : int ; startS2 := -1 ; var i : int ; i := 0 ; while i < s1->size() do ( ( if (s1->at(i+1) /= '0') then ( startS1 := i ; break ) else skip ; c1 := c1 + 1 ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < s2->size() do ( ( if (s2->at(i+1) /= '0') then ( startS2 := i ; break ) else skip ; c2 := c2 + 1 ) ; i := i + 1 ) ; if (c1 = s1->size() & c2 = s2->size()) then OclFile["System.out"].println("=") else if (c1 = s1->size()) then OclFile["System.out"].println("<") else if (c2 = s2->size()) then OclFile["System.out"].println(">") else ( var t1 : String ; t1 := s1.subrange(startS1+1,s1->size()) ; var t2 : String ; t2 := s2.subrange(startS2+1,s2->size()) ; if (t1->size() > t2->size()) then OclFile["System.out"].println(">") ; else if (t2->size() > t1->size()) then OclFile["System.out"].println("<") else ( var p : int ; p := -1 ; var i : int ; i := 0 ; while i < t1->size() do ( ( if (t1->at(i+1) > t2->at(i+1)) then ( OclFile["System.out"].println(">") ; p := 0 ; break ) else skip ; if (t2->at(i+1) > t1->at(i+1)) then ( OclFile["System.out"].println("<") ; p := 0 ; break ) else skip ) ; i := i + 1 ) ; if (p = -1) then OclFile["System.out"].println("=") ; else skip ) ; ) ; ; ; ) catch (e : ProgramException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static boolean isSumOfPowersOfTwo(int n){ if(n % 2==1)return false ; else return true ; } public static void main(String args[]){ int n=10 ; if(isSumOfPowersOfTwo(n))System.out.print("Yes"); else System.out.print("No"); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation isSumOfPowersOfTwo( n : int) : boolean pre: true post: true activity: ( if (n mod 2 = 1) then return false else return true ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 10 ; if (isSumOfPowersOfTwo(n)) then OclFile["System.out"].print("Yes") ; else OclFile["System.out"].print("No") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; public class GFG { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String a=br.readLine(); String b=br.readLine(); char charArray1[]=a.toCharArray(); char charArray2[]=b.toCharArray(); int i ; for(i=0 ; ib.length())System.out.println(">"); else if(a.length()0)System.out.println(">"); else System.out.println("="); } } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var a : String ; a := br.readLine() ; var b : String ; b := br.readLine() ; var charArray1 : Sequence(String) ; charArray1 := a->characters() ; var charArray2 : Sequence(String) ; charArray2 := b->characters() ; var i : int ; i := 0 ; while i < a->size() do ( ( if (charArray1[i+1] /= '0') then ( break ) else skip ) ; i := i + 1 ) ; if (i /= a->size()) then a := a.subrange(i+1,i) else a := "0" ; ; i := 0 ; while i < b->size() do ( ( if (charArray2[i+1] /= '0') then ( break ) else skip ) ; i := i + 1 ) ; if (i /= b->size()) then b := b.subrange(i+1,i) else b := "0" ; ; if (a->size() > b->size()) then OclFile["System.out"].println(">") else if (a->size() < b->size()) then OclFile["System.out"].println("<") else ( if (a->compareTo(b) < 0) then OclFile["System.out"].println("<") ; else if (a->compareTo(b) > 0) then OclFile["System.out"].println(">") else OclFile["System.out"].println("=") ; ; ) ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { static Scanner scanner=new Scanner(System.in); public static void main(String[] $){ int n=scanner.nextInt(); int[] a=new int[n]; int[] b=new int[n]; Arrays.setAll(a,i->scanner.nextInt()); Arrays.setAll(b,i->scanner.nextInt()); int ans=0 ; for(int i=1<<28 ; i>0 ; i>>=1){ int count=0 ; for(int j=0 ; j=0 ; j--){ while(p1toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; setAll(a, lambda i : OclAny in scanner.getCurrent()->toInteger()) ; setAll(b, lambda i : OclAny in scanner.getCurrent()->toInteger()) ; var ans : int ; ans := 0 ; var i : int ; i := (1*(2->pow(28)))->oclAsType(long) ; while i > 0 do ( ( var count : int ; count := 0 ; var j : int ; j := 0 ; while j < n do ( ( a[j+1] := MathLib.bitwiseAnd(a[j+1], 2 * i - 1) ; b[j+1] := MathLib.bitwiseAnd(b[j+1], 2 * i - 1) ) ; j := j + 1 ) ; a := a->sort() ; b := b->sort() ; var p1 : int ; p1 := 0 ; var p2 : int ; p2 := 0 ; var p3 : int ; p3 := 0 ; var j : int ; j := n - 1 ; while j >= 0 do ( ( while (p1 < n & a[j+1] + b[p1+1] < i) do p1 := p1 + 1 ; ; while (p2 < n & a[j+1] + b[p2+1] < 2 * i) do p2 := p2 + 1 ; ; while (p3 < n & a[j+1] + b[p3+1] < 3 * i) do p3 := p3 + 1 ; ; count := count+(n + p2 - p1 - p3) ; count := MathLib.bitwiseAnd(count, 1) ; ) ; j := j - 1 ) ; if (count mod 2 = 1) then ( ans := MathLib.bitwiseOr(ans, i) ) else skip ; ) ; i := i/(2->pow(1)) ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.math.BigInteger ; import java.util.*; public class Solution { static MyScanner str=new MyScanner(); public static void main(String[] args)throws IOException { long T=1 ; while(T-->0){ solve(); } } static void solve()throws IOException { int n=i(); int a[]=new int[n]; for(int i=0 ; i 0) do ( T := T - 1 ; skip ; ( execute solve() ) ; ) ); static operation solve() : void pre: true post: true activity: ( var n : int ; n := i() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := i() ; while (a[i+1] mod 2 = 0) do a[i+1] := a[i+1]/(2) ; ; while (a[i+1] mod 3 = 0) do a[i+1] := a[i+1]/(3) ; ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < n do ( ( if (a[i+1] /= a[0+1]) then ( OclFile["System.out"].println("NO") ; return ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println("YES") ; ); static operation i() : int pre: true post: true activity: ( return str.nextInt() ); static operation l() : long pre: true post: true activity: ( return str.nextLong() ); static operation d() : double pre: true post: true activity: ( return str.nextDouble() ); static class MyScanner { attribute br : OclFile; attribute st : OclIterator; static operation newMyScanner() : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=in.nextInt(); HashSetset=new HashSet<>(); for(int i=0 ; itoInteger() ; var set : Set(int) ; set := Set{} ; var i : int ; i := 0 ; while i < n do ( ( var val : int ; val := in.getCurrent()->toInteger() ; while (val mod 2 = 0) do ( val := val/(2) ) ; while (val mod 3 = 0) do ( val := val/(3) ) ; set := set->including(val) ) ; i := i + 1 ) ; if (set->size() = 1) then ( skip ) else ( skip ) ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class WriteNow { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[][] arr=new int[n][6]; int[] count=new int[100]; for(int i1=0 ; i1toInteger() ; var arr : Sequence(Sequence(int)) ; arr := Integer.subrange(1,n)->collect(Integer.subrange(1,6)->collect(0)) ; var count : Sequence(int) ; count := Integer.subrange(1,100)->collect(0) ; var i1 : int ; i1 := 0 ; while i1 < n do ( ( var i : int ; i := 0 ; while i < 6 do ( ( arr[i1+1][i+1] := scan.getCurrent()->toInteger() ) ; i := i + 1 ) ) ; i1 := i1 + 1 ) ; var i1 : int ; i1 := 0 ; while i1 < n do ( ( var i2 : int ; i2 := 0 ; while i2 < 6 do ( ( count[arr[i1+1][i2+1]+1] := 1 ; var i3 : int ; i3 := i1 + 1 ; while i3 < n do ( ( var i4 : int ; i4 := 0 ; while i4 < 6 do ( ( count[arr[i3+1][i4+1]+1] := 1 ; count[arr[i1+1][i2+1] * 10 + arr[i3+1][i4+1]+1] := 1 ; count[arr[i3+1][i4+1] * 10 + arr[i1+1][i2+1]+1] := 1 ) ; i4 := i4 + 1 ) ) ; i3 := i3 + 1 ) ) ; i2 := i2 + 1 ) ) ; i1 := i1 + 1 ) ; var i : int ; i := 1 ; while i < count->size() do ( ( if (count[i+1] = 0) then ( OclFile["System.out"].println(i - 1) ; break ) else skip ) ; i := i + 1 ) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.Arrays ; import java.util.Collections ; import java.util.HashMap ; import java.util.HashSet ; import java.util.Scanner ; import java.util.TreeMap ; import java.util.TreeSet ; public class trailzero { public static void main(String[] args)throws Throwable { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[6*n]; for(int i=0 ; i<6*n ; i++){ a[i]=sc.nextInt(); } ArrayListp=new ArrayList<>(); for(int i=0 ; i<6*n ; i++){ for(int j=0 ; j<6*n ; j++){ p.add(a[i]); if(i/6!=j/6){ p.add(a[i]+10*a[j]); } } } int num=1 ; while(p.contains(num)){ num++; } System.out.println(num-1); } } ------------------------------------------------------------ OCL File: --------- class trailzero { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,6 * n)->collect(0) ; var i : int ; i := 0 ; while i < 6 * n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var p : Sequence(int) ; p := Sequence{} ; var i : int ; i := 0 ; while i < 6 * n do ( ( var j : int ; j := 0 ; while j < 6 * n do ( ( p := p->including(a[i+1]) ; if (i / 6 /= j / 6) then ( p := p->including(a[i+1] + 10 * a[j+1]) ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var num : int ; num := 1 ; while (p->includes(num)) do ( num := num + 1 ) ; OclFile["System.out"].println(num - 1) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.lang.*; class GFG { public static void splitArr(int arr[],int n,int k){ for(int i=0 ; isize() ; var position : int ; position := 2 ; execute splitArr(arr, 6, position) ; var i : int ; i := 0 ; while i < n do ( OclFile["System.out"].print(arr[i+1] + " ") ; ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static class node { char data ; node next ; }; static node add(char data){ node newnode=new node(); newnode.data=data ; newnode.next=null ; return newnode ; } static void print(node head){ while(head!=null){ System.out.print(head.data+"->"); head=head.next ; } System.out.print("null"); } static boolean isSpecialChar(char ch){ if(ch>='a' && ch<='z')return false ; if(ch>='A' && ch<='Z')return false ; if(ch>='0' && ch<='9')return false ; return true ; } static node removeFromLL(node head){ node curr=head ; node prev=head ; while(curr!=null && isSpecialChar(curr.data)){ node temp=curr ; head=curr.next ; curr=curr.next ; temp=null ; } prev=head ; while(curr!=null){ while(curr!=null && isSpecialChar(curr.data)){ node temp=curr ; prev.next=curr.next ; curr=curr.next ; temp=null ; } if(curr==null)break ; prev=curr ; curr=curr.next ; } return head ; } public static void main(String[] args){ node 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); print(head); } } ------------------------------------------------------------ OCL File: --------- class GFG { static class node { attribute data : String; attribute next : node; } static operation add( data : String) : node pre: true post: true activity: ( var newnode : node ; newnode := node.newnode() ; newnode.data := data ; newnode.next := null ; return newnode ); static operation print( head : node) : void pre: true post: true activity: ( while (head /= null) do ( OclFile["System.out"].print(head.data + "->") ; head := head.next ) ; OclFile["System.out"].print("null") ); static operation isSpecialChar( ch : String) : boolean 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 ); static operation removeFromLL( head : node) : node pre: true post: true activity: ( var curr : node ; curr := head ; var prev : node ; prev := head ; while (curr /= null & isSpecialChar(curr.data)) do ( var temp : node ; temp := curr ; head := curr.next ; curr := curr.next ; temp := null ) ; prev := head ; while (curr /= null) do ( while (curr /= null & isSpecialChar(curr.data)) do ( var temp : node ; 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 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var head : node ; 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) ; execute print(head) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class GFG { static long getChicks(int n){ int size=Math.max(n,7); long[] dp=new long[size]; dp[0]=0 ; dp[1]=1 ; for(int i=2 ; i<6 ; i++){ dp[i]=dp[i-1]*3 ; } dp[6]=726 ; for(int i=8 ; i<=n ; i++){ dp[i]=(dp[i-1]-(2*dp[i-6]/3))*3 ; } return dp[n]; } public static void main(String[] args){ int n=3 ; System.out.println(getChicks(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation getChicks( n : int) : long pre: true post: true activity: ( var size : int ; size := Set{n, 7}->max() ; var dp : Sequence(long) ; dp := Integer.subrange(1,size)->collect(0) ; dp[0+1] := 0 ; dp[1+1] := 1 ; var i : int ; i := 2 ; while i < 6 do ( ( dp[i+1] := dp[i - 1+1] * 3 ) ; i := i + 1 ) ; dp[6+1] := 726 ; var i : int ; i := 8 ; while i <= n do ( ( dp[i+1] := (dp[i - 1+1] - (2 * dp[i - 6+1] / 3)) * 3 ) ; i := i + 1 ) ; return dp[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 3 ; OclFile["System.out"].println(getChicks(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.StringTokenizer ; import java.io.IOException ; import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.io.InputStream ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; MyScanner in=new MyScanner(inputStream); PrintWriter out=new PrintWriter(outputStream); D solver=new D(); solver.solve(1,in,out); out.close(); } static class D { private static long MOD=(long)(1e9+7); public void solve(int testNumber,MyScanner in,PrintWriter out){ int N=in.Int(); int K=in.Int(); long ans=0 ; for(long i=K ; i<=N+1 ; i++){ long a=(i*(i-1))/2 ; long b=((N+(N-i+1))*i)/2 ; ans+=b-(a-1); ans %=MOD ; } out.println((ans+MOD)% MOD); } } static class MyScanner { private BufferedReader in ; private StringTokenizer st ; public MyScanner(InputStream stream){ in=new BufferedReader(new InputStreamReader(stream)); } public String next(){ while(st==null || ! st.hasMoreTokens()){ try { String rl=in.readLine(); if(rl==null){ return null ; } st=new StringTokenizer(rl); } catch(IOException e){ throw new RuntimeException(e); } } return st.nextToken(); } public int Int(){ return Integer.parseInt(next()); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var inputStream : OclFile ; inputStream := OclFile["System.in"] ; var outputStream : OclFile ; outputStream := OclFile["System.out"] ; var in : MyScanner ; in := MyScanner.newMyScanner(inputStream) ; var out : OclFile ; out := OclFile.newOclFile_Write(outputStream) ; var solver : D ; solver := D.newD() ; solver.solve(1, in, out) ; skip ; ); static class D { static attribute MOD : long := (1e9 + 7)->oclAsType(long); operation solve( testNumber : int, in : MyScanner, out : OclFile) : void pre: true post: true activity: ( var N : int ; N := in.Int() ; var K : int ; K := in.Int() ; var ans : long ; ans := 0 ; var i : long ; i := K ; while i <= N + 1 do ( ( var a : long ; a := (i * (i - 1)) / 2 ; var b : long ; b := ((N + (N - i + 1)) * i) / 2 ; ans := ans+(b - (a - 1)) ; ans := ans mod MOD ) ; i := i + 1 ) ; skip ; ); } static class MyScanner { attribute in : OclFile; attribute st : OclIterator; static operation newMyScanner( stream : OclFile) : MyScanner pre: true post: true activity: ( var self : MyScanner ; self := createMyScanner(); self.initialise(stream); return self ); operation initialise( stream : OclFile) : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(stream)) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( var rl : String ; rl := in.readLine() ; if (rl = null) then ( return null ) else skip ; st := OclIterator.newOclIterator_String(rl) ) catch (e : IOException) do ( error ProgramException(e) ) ) ; return st.next() ); operation Int() : int pre: true post: true activity: ( return (next())->toInteger() ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class E { public static void main(String[] args){ Scanner in=new Scanner(System.in); int testCases=in.nextInt(); for(int testCase=0 ; testCasetoInteger() ; var testCase : int ; testCase := 0 ; while testCase < testCases do ( ( var n : int ; n := in.getCurrent()->toInteger() ; var s : Sequence(String) ; s := in.getCurrent()->characters() ; var ones : int ; ones := 0 ; var zeros : int ; zeros := 0 ; var sum : int ; sum := 0 ; var i : int ; i := 1 ; while i < n do ( ( if (s[i+1] = s[i - 1+1]) then ( if (s[i+1] = '1') then ( ones := ones + 1 ) else ( zeros := zeros + 1 ) ) else skip ) ; i := i + 1 ) ; sum := Set{ones, zeros}->max() ; OclFile["System.out"].println(sum) ; ) ; testCase := testCase + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] cmd=br.readLine().split(" "); long x=Long.valueOf(cmd[0]); long k=Long.valueOf(cmd[1]); long[] sum1=new long[(int)x+2]; for(long i=1 ; i<=x+1 ; i++){ sum1[(int)i]=sum1[(int)i-1]+i ; } long[] sum2=new long[(int)x+2]; for(long i=x+1 ; i>=1 ; i--){ sum2[(int)(x+2-i)]=sum2[(int)(x+1-i)]+i ; } long ans=0 ; for(long i=k ; i<=x+1 ; i++){ long diff=sum2[(int)i]-sum1[(int)i]+1 ; ans=(ans+diff)% 1000000007 ; } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var cmd : Sequence(String) ; cmd := br.readLine()->split(" ") ; var x : long ; x := (cmd[0+1])->toLong() ; var k : long ; k := (cmd[1+1])->toLong() ; var sum1 : Sequence(long) ; sum1 := Integer.subrange(1,x->oclAsType(int) + 2)->collect(0) ; var i : long ; i := 1 ; while i <= x + 1 do ( ( sum1[i->oclAsType(int)+1] := sum1[i->oclAsType(int) - 1+1] + i ) ; i := i + 1 ) ; var sum2 : Sequence(long) ; sum2 := Integer.subrange(1,x->oclAsType(int) + 2)->collect(0) ; var i : long ; i := x + 1 ; while i >= 1 do ( ( sum2[(x + 2 - i)->oclAsType(int)+1] := sum2[(x + 1 - i)->oclAsType(int)+1] + i ) ; i := i - 1 ) ; var ans : long ; ans := 0 ; var i : long ; i := k ; while i <= x + 1 do ( ( var diff : long ; diff := sum2[i->oclAsType(int)+1] - sum1[i->oclAsType(int)+1] + 1 ; ans := (ans + diff) mod 1000000007 ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0 ; i1){ int m=(l+r)>>1 ; if(la[m]>=key){ r=m ; } else { l=m ; } } return r ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(int) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; skip ; var num : Sequence(long) ; num := Integer.subrange(1,29)->collect(0) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < 29 do ( ( var ta : Sequence(int) ; ta := Integer.subrange(1,n)->collect(0) ; var tb : Sequence(int) ; tb := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( ta[j+1] := a[j+1] mod ((2*(2->pow(i)))->oclAsType(long)) ; tb[j+1] := b[j+1] mod ((2*(2->pow(i)))->oclAsType(long)) ) ; j := j + 1 ) ; tb := tb->sort() ; var pow1 : int ; pow1 := ((2*(2->pow(i)))->oclAsType(long)) / 2 ; var pow2 : int ; pow2 := 2 * pow1 ; var pow3 : int ; pow3 := 3 * pow1 ; var pow4 : int ; pow4 := 4 * pow1 ; var j : int ; j := 0 ; while j < n do ( ( var tmp1 : int ; tmp1 := myBinarySearch(tb, pow1 - ta[j+1]) ; var tmp2 : int ; tmp2 := myBinarySearch(tb, pow2 - ta[j+1]) ; var tmp3 : int ; tmp3 := myBinarySearch(tb, pow3 - ta[j+1]) ; var tmp4 : int ; tmp4 := myBinarySearch(tb, pow4 - ta[j+1]) ; num[i+1] := num[i+1]+(tmp2 - tmp1 + tmp4 - tmp3) ; ) ; j := j + 1 ) ; if (num[i+1] mod 2 = 1) then ans := ans+(((2*(2->pow(i)))->oclAsType(long)) / 2) ; else skip ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation myBinarySearch( la : Sequence(int), key : int) : int pre: true post: true activity: ( var l : int ; l := -1 ; var r : int ; r := la->size() ; while (r - l > 1) do ( var m : int ; m := ((l + r)/(2->pow(1)))->oclAsType(long) ; if (la[m+1] >= key) then ( r := m ) else ( l := m ) ) ; return r ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ long n=sc.nextInt(); long k=sc.nextInt(); long mod=(long)Math.pow(10,9)+7 ; long count=0 ; for(long i=k ; i<=n+1 ; i++){ long min=sum(0,i-1); long max=sum(n-i+1,n); count+=(max-min+1); count %=mod ; } System.out.println(count); } private static long sum(long left,long right){ return(left+right)*(right-left+1)/2 ; } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : long ; n := sc.getCurrent()->toInteger() ; var k : long ; k := sc.getCurrent()->toInteger() ; var mod : long ; mod := 10->pow(9)->oclAsType(long) + 7 ; var count : long ; count := 0 ; var i : long ; i := k ; while i <= n + 1 do ( ( var min : long ; min := sum(0, i - 1) ; var max : long ; max := sum(n - i + 1, n) ; count := count+((max - min + 1)) ; count := count mod mod ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); static operation sum( left : long, right : long) : long pre: true post: true activity: ( return (left + right) * (right - left + 1) / 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws Exception { long num=1000000007 ; BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); StringTokenizer st=new StringTokenizer(bf.readLine()); int n=Integer.parseInt(st.nextToken()); int k=Integer.parseInt(st.nextToken()); long sum=0 ; for(long j=k ; j<=n ; j++){ sum+=(long)((j*(long)(n)-j*j+j+1)); sum %=num ; } out.println(sum+1); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var num : long ; num := 1000000007 ; var bf : OclFile ; bf := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var st : OclIterator ; st := OclIterator.newOclIterator_String(bf.readLine()) ; var n : int ; n := (st.next())->toInteger() ; var k : int ; k := (st.next())->toInteger() ; var sum : long ; sum := 0 ; var j : long ; j := k ; while j <= n do ( ( sum := sum+(((j * (n)->oclAsType(long) - j * j + j + 1))->oclAsType(long)) ; sum := sum mod num ) ; j := j + 1 ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader a=new FastReader(); int n=a.nextInt(); int m=a.nextInt(); int[] arr=new int[n]; for(int i=0 ; i0){ int type=a.nextInt(); if(type==1){ int index=a.nextInt()-1 ; arr[index]=a.nextInt()-sum ; } else if(type==3){ int index=a.nextInt()-1 ; System.out.println(arr[index]+sum); } else { sum+=a.nextInt(); } } } } ------------------------------------------------------------ OCL File: --------- class Main { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( str := br.readLine() ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : FastReader ; a := FastReader.newFastReader() ; var n : int ; n := a.nextInt() ; var m : int ; m := a.nextInt() ; var arr : Sequence(int) ; arr := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < arr->size() do ( arr[i+1] := a.nextInt() ; ; i := i + 1 ) ; var sum : int ; sum := 0 ; var add : Sequence(int) ; add := Integer.subrange(1,n)->collect(0) ; while (m > 0) do ( m := m - 1 ; skip ; ( var type : int ; type := a.nextInt() ; if (type = 1) then ( var index : int ; index := a.nextInt() - 1 ; arr[index+1] := a.nextInt() - sum ) else if (type = 3) then ( var index : int ; index := a.nextInt() - 1 ; OclFile["System.out"].println(arr[index+1] + sum) ) else ( sum := sum+(a.nextInt()) ) ; ) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.next()); HashMapmap=new HashMap(); for(int i=0 ; imax){ max=val ; } } System.out.println(max); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := (sc.getCurrent())->toInteger() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var s : String ; s := sc.getCurrent() ; if (map->at(s) = null) then ( map := map->union(Map{s |-> 1}) ) else ( map := map->union(Map{s |-> map->at(s) + 1}) ) ) ; i := i + 1 ) ; var m : int ; m := (sc.getCurrent())->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( var s : String ; s := sc.getCurrent() ; if (map->at(s) /= null) then ( map := map->union(Map{s |-> map->at(s) - 1}) ) else skip ) ; i := i + 1 ) ; var max : int ; max := 0 ; for (val : map->values()) do ( ( if (val > max) then ( max := val ) else skip ) ) ; OclFile["System.out"].println(max) ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Iterator ; import java.util.Map ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); Mapmap=new HashMap(); for(int i=0 ; iit=map.values().iterator(); int res=0 ; while(it.hasNext()){ int t=it.next(); if(restoInteger() ; var map : Map(String,int) ; map := Map{} ; var i : int ; i := 0 ; while i < N do ( ( var key : String ; key := sc.getCurrent() ; var count : int ; count := map->at(key) ; if (count = null) then count := 1 else count := count + 1 ; ; map := map->union(Map{key |-> count}) ) ; i := i + 1 ) ; var M : int ; M := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < M do ( ( var key : String ; key := sc.getCurrent() ; var count : int ; count := map->at(key) ; if (count = null) then count := -1 else count := count - 1 ; ; map := map->union(Map{key |-> count}) ) ; i := i + 1 ) ; var it : OclIterator ; it := map->values()->iterator() ; var res : int ; res := 0 ; while (it.hasNext()) do ( var t : int ; t := it.next() ; if (res < t) then res := t ; else skip ) ; OclFile["System.out"].println(res) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { static Scanner s=new Scanner(System.in); public static void main(String[] args){ int N=s.nextInt(); String[] bArr=new String[N]; boolean[] bBoolArr=new boolean[N]; for(int i=0 ; itoInteger() ; var bArr : Sequence(String) ; bArr := Integer.subrange(1,N)->collect(null) ; var bBoolArr : Sequence(boolean) ; bBoolArr := Integer.subrange(1,N)->collect(false) ; var i : int ; i := 0 ; while i < N do ( ( bArr[i+1] := s.getCurrent() ; bBoolArr[i+1] := true ) ; i := i + 1 ) ; var M : int ; M := s.getCurrent()->toInteger() ; var rArr : Sequence(String) ; rArr := Integer.subrange(1,M)->collect(null) ; var i : int ; i := 0 ; while i < M do ( ( rArr[i+1] := s.getCurrent() ) ; i := i + 1 ) ; var count : int ; count := 1 ; var ans : int ; ans := 0 ; if (N = 1) then ( var k : int ; k := 0 ; while k < M do ( ( if (rArr[k+1] = bArr[0+1]) then ( OclFile["System.out"].println(0) ; return ) else skip ) ; k := k + 1 ) ; OclFile["System.out"].println(1) ; return ) else skip ; var i : int ; i := 0 ; while i < N do ( ( if (bBoolArr[i+1] = true) then ( count := 1 ; var j : int ; j := i + 1 ; while j < N do ( ( if (bArr[i+1] = bArr[j+1]) then ( bBoolArr[j+1] := false ; count := count + 1 ) else skip ) ; j := j + 1 ) ; var k : int ; k := 0 ; while k < M do ( ( if (bArr[i+1] = rArr[k+1]) then ( count := count - 1 ) else skip ) ; k := k + 1 ) ) else skip ; if (count < 1) then ( count := 0 ) else skip ; if (ans < count) then ( ans := count ) else skip ; bBoolArr[i+1] := false ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args){ HashMapmap=new HashMap<>(); int n=sc.nextInt(); String s ; for(int i=0 ; ie : map.entrySet()){ max=Math.max(max,e.getValue()); } out.println(max); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var map : Map(String,int) ; map := Map{} ; var n : int ; n := sc.getCurrent()->toInteger() ; var s : String ; var i : int ; i := 0 ; while i < n do ( ( s := sc.getCurrent() ; map := map->union(Map{s |-> (if map->keys()->contains(s) then map->at(s) else 0 endif)}) ; map := map->union(Map{s |-> map->at(s) + 1}) ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var i : int ; i := 0 ; while i < m do ( ( s := sc.getCurrent() ; map := map->union(Map{s |-> (if map->keys()->contains(s) then map->at(s) else 0 endif)}) ; map := map->union(Map{s |-> map->at(s) - 1}) ) ; i := i + 1 ) ; var max : int ; max := 0 ; for (e : map->asSet()) do ( ( max := Set{max, e.getValue()}->max() ) ) ; out.println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int K=sc.nextInt(); char[][] arr=new char[h][w]; for(int i=0 ; i>k)& 1)==0 &&((j>>l)& 1)==0 && arr[k][l]=='#'){ black++; } } } if(black==K){ ans++; } } } System.out.println(ans); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var h : int ; h := sc.getCurrent()->toInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var K : int ; K := sc.getCurrent()->toInteger() ; var arr : Sequence(Sequence(String)) ; arr := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( var s : String ; s := sc.getCurrent() ; var j : int ; j := 0 ; while j < s->size() do ( ( arr[i+1][j+1] := s->at(j+1) ) ; j := j + 1 ) ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < ((1*(2->pow(h)))->oclAsType(long)) do ( ( var j : int ; j := 0 ; while j < ((1*(2->pow(w)))->oclAsType(long)) do ( ( var black : int ; black := 0 ; var k : int ; k := 0 ; while k < h do ( ( var l : int ; l := 0 ; while l < w do ( ( if ((((i/(2->pow(k)))->oclAsType(long)) & 1) = 0 & (((j/(2->pow(l)))->oclAsType(long)) & 1) = 0 & arr[k+1][l+1] = '#') then ( black := black + 1 ) else skip ) ; l := l + 1 ) ) ; k := k + 1 ) ; if (black = K) then ( ans := ans + 1 ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); HashMapsmap=new HashMap(); for(int i=0 ; immap=new HashMap(); for(int i=0 ; itoInteger() ; var smap : Map(String,int) ; smap := Map{} ; var i : int ; i := 0 ; while i < n do ( ( var str : String ; str := sc.getCurrent() ; var tmp : int ; tmp := smap->at(str) ; if (tmp = null) then ( smap := smap->union(Map{str |-> 1}) ) else ( smap := smap->union(Map{str |-> tmp + 1}) ) ) ; i := i + 1 ) ; var m : int ; m := sc.getCurrent()->toInteger() ; var mmap : Map(String,int) ; mmap := Map{} ; var i : int ; i := 0 ; while i < m do ( ( var str : String ; str := sc.getCurrent() ; var tmp : int ; tmp := mmap->at(str) ; if (tmp = null) then ( mmap := mmap->union(Map{str |-> 1}) ) else ( mmap := mmap->union(Map{str |-> tmp + 1}) ) ) ; i := i + 1 ) ; var max : int ; max := 0 ; for (key : smap->keys()) do ( ( var val1 : int ; val1 := smap->at(key) ; var val2 : int ; val2 := mmap->at(key) ; if (val2 = null) then ( max := Set{max, val1}->max() ) else ( max := Set{max, val1 - val2}->max() ) ) ) ; OclFile["System.out"].println(max) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int count=0 ; for(; scanner.hasNext(); ){ String input=scanner.next(); String inverse="" ; for(int i=input.length(); i>0 ; i--){ inverse+=input.substring(i-1,i); } if(input.equals(inverse)){ count++; } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; var count : int ; count := 0 ; while scanner.hasNext() do ( ( var input : String ; input := scanner.getCurrent() ; var inverse : String ; inverse := "" ; var i : int ; i := input->size() ; while i > 0 do ( ( inverse := inverse+(input.subrange((i)->char2byte() - 1+1,i)) ) ; i := i - 1 ) ; if (input = inverse) then ( count := count + 1 ) else skip ) ) ; OclFile["System.out"].println(count) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { private static BufferedReader br=null ; static { br=new BufferedReader(new InputStreamReader(System.in)); } public static void main(String[] args){ String stdin=null ; int cnt=0 ; int len=0 ; int fin=0 ; boolean rev=true ; while((stdin=parseStdin())!=null){ rev=true ; len=stdin.length(); fin=len/2 ; for(int n=0 ; nsize() ; fin := len / 2 ; var n : int ; n := 0 ; while n < fin do ( ( if (not((rev))) then ( break ) else skip ) ; n := n + 1 ) ; if (rev) then ( cnt := cnt + 1 ) else skip ; ) ; stdin := parseStdin() ; ) ; OclFile["System.out"].println(cnt) ; ); static operation parseStdin() : String pre: true post: true activity: ( var stdin : String ; stdin := null ; try ( var line : String ; line := br.readLine() ; if (line /= null) then ( if (not(line->isEmpty())) then ( stdin := line ) else skip ) else skip ) catch (e : IOException) do skip return stdin ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashMap ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int A=sc.nextInt(); HashMaptmpSum=new HashMap<>(); for(int i=0 ; iprevMap=new HashMap<>(tmpSum); for(int key : prevMap.keySet()){ addCountMap(tmpSum,key+diff,prevMap.get(key)); } addCountMap(tmpSum,diff,1); } sc.close(); long result ; if(tmpSum.get(0)!=null){ result=tmpSum.get(0); } else { result=0 ; } System.out.println(result); } private static void addCountMap(HashMapmap,int key,long count){ if(map.get(key)==null){ map.put(key,count); } else { map.put(key,map.get(key)+count); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var N : int ; N := sc.getCurrent()->toInteger() ; var A : int ; A := sc.getCurrent()->toInteger() ; var tmpSum : Map(int,long) ; tmpSum := Map{} ; var i : int ; i := 0 ; while i < N do ( ( var diff : int ; diff := sc.getCurrent()->toInteger() - A ; var prevMap : Map(int,long) ; prevMap := Map{}->union(tmpSum) ; for (key : prevMap->keys()) do ( ( execute addCountMap(tmpSum, key + diff, prevMap->at(key)) ) ) ; execute addCountMap(tmpSum, diff, 1) ) ; i := i + 1 ) ; skip ; var result : long ; if (tmpSum->at(0) /= null) then ( result := tmpSum->at(0) ) else ( result := 0 ) ; OclFile["System.out"].println(result) ; ); static operation addCountMap( map : Map(int,long), key : int, count : long) : void pre: true post: true activity: ( if (map->at(key+1) = null) then ( map := map->union(Map{key |-> count}) ) else ( map := map->union(Map{key |-> map->at(key+1) + count}) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long[] a=new long[n]; long[] b=new long[n]; for(int i=0 ; ilow){ mid=((high-low)>>>1)+low ; if(arr[mid]toInteger() ; var a : Sequence(long) ; a := Integer.subrange(1,n)->collect(0) ; var b : Sequence(long) ; b := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := sc.getCurrent()->toLong() ) ; i := i + 1 ) ; var fig : Sequence(long) ; fig := Integer.subrange(1,29)->collect(0) ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < 30 do ( ( var t : long ; t := (1*(2->pow(i)))->oclAsType(long) ; var count : long ; count := 0 ; var aa : Sequence(long) ; aa := Integer.subrange(1,n)->collect(0) ; var bb : Sequence(long) ; bb := Integer.subrange(1,n)->collect(0) ; var j : int ; j := 0 ; while j < n do ( ( aa[j+1] := a[j+1] mod (2 * t) ; bb[j+1] := b[j+1] mod (2 * t) ) ; j := j + 1 ) ; bb := bb->sort() ; var k : int ; k := 0 ; while k < n do ( ( count := count+(lowerBounds(bb, 2 * t - aa[k+1]) - lowerBounds(bb, t - aa[k+1])) ; count := count+(n - lowerBounds(bb, 3 * t - aa[k+1])) ) ; k := k + 1 ) ; ans := MathLib.bitwiseOr(ans, ((MathLib.bitwiseAnd(count,1))*(2->pow(i)))->oclAsType(long)) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); static operation lowerBounds( arr : Sequence(long), value : long) : int pre: true post: true activity: ( var low : int ; low := 0 ; var high : int ; high := arr->size() ; var mid : int ; while (high > low) do ( mid := (((high - low)/(2->pow(1)))->oclAsType(long)) + low ; if (arr[mid+1] < value) then ( low := mid + 1 ) else ( high := mid ) ) ; return low ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.ArrayList ; import java.util.List ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner stdIn=new Scanner(System.in); ListwordList=new ArrayList(); while(stdIn.hasNext()){ wordList.add(stdIn.next()); } int simmetryCount=0 ; for(String i : wordList){ int iDotLength=i.length(); for(int j=0 ; j=iDotLength-1-j){ simmetryCount++; break ; } } } System.out.println(simmetryCount); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var stdIn : OclFile ; stdIn := OclFile.newOclFile_Read(OclFile["System.in"]) ; var wordList : Sequence(String) ; wordList := Sequence{} ; while (stdIn.hasNext()) do ( wordList := wordList->including(stdIn.getCurrent()) ) ; var simmetryCount : int ; simmetryCount := 0 ; for (i : wordList) do ( ( var iDotLength : int ; iDotLength := i->size() ; var j : int ; j := 0 ; while j < iDotLength do ( ( if (i->at(j+1) /= i->at(iDotLength - 1 - j+1)) then ( break ) else if (iDotLength = 1 or i->at(j+1) = i->at(iDotLength - 1 - j+1) & j >= iDotLength - 1 - j) then ( simmetryCount := simmetryCount + 1 ; break ) else skip ; ) ; j := j + 1 ) ) ) ; OclFile["System.out"].println(simmetryCount) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PalindromeCounter pc=new PalindromeCounter(); while(true){ String str=br.readLine(); if(str==null){ break ; } pc.setString(str); } System.out.println(pc.getCount()); } } class PalindromeCounter { int count=0 ; public void setString(String str){ StringBuffer sb=new StringBuffer(str); sb.reverse(); if(str.equals(sb.toString())){ count++; } } public int getCount(){ return count ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var pc : PalindromeCounter ; pc := PalindromeCounter.newPalindromeCounter() ; while (true) do ( var str : String ; str := br.readLine() ; if (str = null) then ( break ) else skip ; pc.setString(str) ) ; OclFile["System.out"].println(pc.getCount()) ); } class PalindromeCounter { attribute count : int := 0; operation setString( str : String) : void pre: true post: true activity: ( var sb : String ; sb := StringLib.newString(str) ; sb := sb->reverse() ; if (str = sb+"") then ( count := count + 1 ) else skip ); operation getCount() : int pre: true post: true activity: ( return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args)throws java.io.IOException { Scanner scan=new Scanner(System.in); int count=0 ; while(scan.hasNext()){ String text=scan.next(); int out=0 ; char character[]=text.toCharArray(); if(character.length==1){ ++count ; } else { for(int i=0 ; i<(character.length)/2 ; i++){ for(int j=character.length-1-i ; j>character.length-2-i ; j--){ if(character[i]==character[j]){ if(i==(character.length)/2-1){ ++count ; } } else { out=1 ; break ; } } if(out==1){ break ; } } } } System.out.println(count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var count : int ; count := 0 ; while (scan.hasNext()) do ( var text : String ; text := scan.getCurrent() ; var out : int ; out := 0 ; var character : Sequence(String) ; character := text->characters() ; if (character->size() = 1) then ( count := count + 1 ) else ( var i : int ; i := 0 ; while i < (character->size()) / 2 do ( ( var j : int ; j := character->size() - 1 - (i)->char2byte() ; while j > character->size() - 2 - (i)->char2byte() do ( ( if (character[i+1] = character[j+1]) then ( if (i = (character->size()) / 2 - 1) then ( count := count + 1 ) else skip ) else ( out := 1 ; break ) ) ; j := j - 1 ) ; if (out = 1) then ( break ) else skip ) ; i := i + 1 ) ) ) ; OclFile["System.out"].println(count) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { public static String prefixSuffix(String a,String b,int l){ String prefix=a.substring(0,l); int lb=b.length(); String suffix=b.substring(lb-l); return(prefix+suffix); } public static void main(String args[])throws IOException { String a="remuneration",b="acquiesce" ; int l=5 ; System.out.println(prefixSuffix(a,b,l)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation prefixSuffix( a : String, b : String, l : int) : String pre: true post: true activity: ( var prefix : String ; prefix := a.subrange(0+1,l) ; var lb : int ; lb := b->size() ; var suffix : String ; suffix := b.subrange((lb)->char2byte() - l+1,(lb)->char2byte() - l) ; return (prefix + suffix) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : String ; a := "remuneration" ; var b : String ; b := "acquiesce" ; var l : int ; l := 5 ; OclFile["System.out"].println(prefixSuffix(a, b, l)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class A { public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=2*in.nextInt(); int[] a=new int[n]; Arrays.setAll(a,i->in.nextInt()); Arrays.sort(a); pw.println(a[n/2]==a[n/2-1] ? "NO" : "YES"); pw.close(); } static void debug(Object...obj){ System.err.println(Arrays.deepToString(obj)); } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var pw : OclFile ; pw := OclFile.newOclFile_Write(OclFile["System.out"]) ; var n : int ; n := 2 * in.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; setAll(a, lambda i : OclAny in in.getCurrent()->toInteger()) ; a := a->sort() ; skip ; skip ; ); static operation debug( obj : Sequence(OclAny)) : void pre: true post: true activity: ( OclFile["System.err"].println((obj + "")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.OutputStream ; import java.io.IOException ; import java.io.InputStream ; import java.io.PrintWriter ; import java.util.Scanner ; public class Main { public static void main(String[] args){ InputStream inputStream=System.in ; OutputStream outputStream=System.out ; Scanner in=new Scanner(inputStream); PrintWriter out=new PrintWriter(outputStream); C solver=new C(); solver.solve(1,in,out); out.close(); } static class C { public void solve(int testNumber,Scanner in,PrintWriter out){ int h=Integer.parseInt(in.next()); int w=Integer.parseInt(in.next()); int k=Integer.parseInt(in.next()); char[][] c=new char[h][w]; for(int i=0 ; itoInteger() ; var w : int ; w := (in.getCurrent())->toInteger() ; var k : int ; k := (in.getCurrent())->toInteger() ; var c : Sequence(Sequence(String)) ; c := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( c[i+1] := in.getCurrent()->characters() ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var bith : int ; bith := 0 ; while bith < ((1*(2->pow(h)))->oclAsType(long)) do ( ( var bitw : int ; bitw := 0 ; while bitw < ((1*(2->pow(w)))->oclAsType(long)) do ( ( var black : int ; black := 0 ; var i : int ; i := 0 ; while i < h do ( ( if ((MathLib.bitwiseAnd(bith,((1*(2->pow(i)))->oclAsType(long)))) = 0) then continue else skip ; var j : int ; j := 0 ; while j < w do ( ( if ((MathLib.bitwiseAnd(bitw,((1*(2->pow(j)))->oclAsType(long)))) = 0) then continue else skip ; if (c[i+1][j+1] = '#') then black := black + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; if (black = k) then ans := ans + 1 ; else skip ) ; bitw := bitw + 1 ) ) ; bith := bith + 1 ) ; skip ; ); } } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.util.Arrays ; public class ChessTourney { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=2*Integer.parseInt(input.nextLine()); int[] ranks=new int[n]; for(int i=0 ; itoInteger() ; var ranks : Sequence(int) ; ranks := Integer.subrange(1,n)->collect(0) ; var i : int ; i := 0 ; while i < n do ( ranks[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; ranks := ranks->sort() ; var i : int ; i := 0 ; var j : int ; j := n - 1 ; while i < n / 2 do ( ( if (ranks[j+1] <= ranks[i+1]) then ( OclFile["System.out"].println("NO") ; return ) else skip ) ; i := i + 1 ; j := j - 1 ) ; OclFile["System.out"].println("YES") ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[2*n]; for(int i=0 ; itoInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,2 * n)->collect(0) ; var i : int ; i := 0 ; while i < a->size() do ( ( a[i+1] := sc.getCurrent()->toInteger() ) ; i := i + 1 ) ; a := a->sort() ; if (a[n - 1+1] < a[n+1]) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int solve(int n,int base){ int result=0 ; while(n>0){ int remainder=n % base ; result=result+remainder ; n=n/base ; } return result ; } static void printSumsOfDigits(int n){ for(int base=2 ; base 0) do ( var remainder : int ; remainder := n mod base ; result := result + remainder ; n := n / base ) ; return result ); static operation printSumsOfDigits( n : int) : void pre: true post: true activity: ( var base : int ; base := 2 ; while base < n do ( OclFile["System.out"].print(solve(n, base) + " ") ; ; base := base + 1 ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 8 ; execute printSumsOfDigits(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class Test { static int maxModValue(int arr[],int n){ int ans=0 ; Arrays.sort(arr); for(int j=n-2 ; j>=0 ; --j){ if(ans>=arr[j])break ; if(arr[j]==arr[j+1])continue ; for(int i=2*arr[j]; i<=arr[n-1]+arr[j]; i+=arr[j]){ int ind=Arrays.binarySearch(arr,i); if(ind<0)ind=Math.abs(ind+1); else { while(arr[ind]==i){ ind--; if(ind==0){ ind=-1 ; break ; } } ind++; } ans=Math.max(ans,arr[ind-1] % arr[j]); } } return ans ; } public static void main(String args[]){ int arr[]={ 3,4,5,9,11 }; System.out.println(maxModValue(arr,arr.length)); } } ------------------------------------------------------------ OCL File: --------- class Test { static operation maxModValue( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var ans : int ; ans := 0 ; arr := arr->sort() ; var j : int ; j := n - 2 ; while j >= 0 do ( ( if (ans >= arr[j+1]) then break else skip ; if (arr[j+1] = arr[j + 1+1]) then continue else skip ; var i : int ; i := 2 * arr[j+1] ; while i <= arr[n - 1+1] + arr[j+1] do ( ( var ind : int ; ind := (arr->indexOf(i) - 1) ; if (ind < 0) then ind := if ind + 1 < 0 then -(ind + 1) else ind + 1 endif else ( while (arr[ind+1] = i) do ( ind := ind - 1 ; if (ind = 0) then ( ind := -1 ; break ) else skip ) ; ind := ind + 1 ) ; ans := Set{ans, arr[ind - 1+1] mod arr[j+1]}->max() ) ; i := i+(arr[j+1]) ) ) ; j := j - 1 ) ; return ans ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{3,4,5,9,11} ; OclFile["System.out"].println(maxModValue(arr, arr->size())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; int idx=-1,max=-1 ; for(int i=0 ; imax){ max=a[i]; idx=i ; } } boolean flag=true ; for(int i=idx+2 ; ia[i-1])flag=false ; } if(flag){ for(int i=idx-2 ; i>=0 ; i--){ if(a[i]>a[i+1])flag=false ; } } if(flag)System.out.println("YES"); else System.out.println("NO"); sc.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n)->collect(0) ; var idx : int ; idx := -1 ; var max : int ; max := -1 ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := sc.getCurrent()->toInteger() ; if (a[i+1] > max) then ( max := a[i+1] ; idx := i ) else skip ) ; i := i + 1 ) ; var flag : boolean ; flag := true ; var i : int ; i := idx + 2 ; while i < n do ( ( if (a[i+1] > a[i - 1+1]) then flag := false ; else skip ) ; i := i + 1 ) ; if (flag) then ( var i : int ; i := idx - 2 ; while i >= 0 do ( ( if (a[i+1] > a[i + 1+1]) then flag := false ; else skip ) ; i := i - 1 ) ) else skip ; if (flag) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static int a[],b[]; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); a=new int[n]; b=new int[n]; st=new StringTokenizer(br.readLine()); for(int i=0 ; i=1 ; i--){ int cntone=0 ; int T=1<<(i-1); for(int j=0 ; j=0 ; j--){ while(p1toInteger() ; a := Integer.subrange(1,n)->collect(0) ; b := Integer.subrange(1,n)->collect(0) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( a[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; st := OclIterator.newOclIterator_String(br.readLine()) ; var i : int ; i := 0 ; while i < n do ( ( b[i+1] := (st.next())->toInteger() ) ; i := i + 1 ) ; var ans : int ; ans := 0 ; var i : int ; i := 29 ; while i >= 1 do ( ( var cntone : int ; cntone := 0 ; var T : int ; T := (1*(2->pow((i - 1))))->oclAsType(long) ; var j : int ; j := 0 ; while j < n do ( ( b[j+1] := b[j+1] & (2 * T - 1) ) ; j := j + 1 ) ; var j : int ; j := 0 ; while j < n do ( ( a[j+1] := a[j+1] & (2 * T - 1) ) ; j := j + 1 ) ; a := a->sort() ; b := b->sort() ; var p1 : int ; p1 := 0 ; var p2 : int ; p2 := 0 ; var p3 : int ; p3 := 0 ; var j : int ; j := n - 1 ; while j >= 0 do ( ( while (p1 < n & a[j+1] + b[p1+1] < T) do p1 := p1 + 1 ; ; while (p2 < n & a[j+1] + b[p2+1] < 2 * T) do p2 := p2 + 1 ; ; while (p3 < n & a[j+1] + b[p3+1] < 3 * T) do p3 := p3 + 1 ; ; cntone := cntone+((p2 - p1) + (n - p3)) ; cntone := MathLib.bitwiseAnd(cntone, 1) ; ) ; j := j - 1 ) ; if (cntone mod 2 = 1) then ans := MathLib.bitwiseOr(ans, T) ; else skip ; ) ; i := i - 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class pillars { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n,a[],i,max,p ; n=sc.nextInt(); a=new int[n]; for(i=0 ; imax){ max=a[i]; p=i ; } } for(i=p+1 ; i0 ; i--){ if(a[i]toInteger() ; a := Integer.subrange(1,n)->collect(0) ; i := 0 ; while i < n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; max := a[0+1] ; p := 0 ; i := 1 ; while i < n do ( ( if (a[i+1] > max) then ( max := a[i+1] ; p := i ) else skip ) ; i := i + 1 ) ; i := p + 1 ; while i < n - 1 do ( ( if (a[i+1] < a[i + 1+1]) then break else skip ) ; i := i + 1 ) ; if (i /= n - 1 & i /= n) then ( OclFile["System.out"].println("NO") ; OclProcess.exit(0) ) else skip ; i := p - 1 ; while i > 0 do ( ( if (a[i+1] < a[i - 1+1]) then break else skip ) ; i := i - 1 ) ; if (i = 0 or i = -1) then OclFile["System.out"].println("YES") else OclFile["System.out"].println("NO") ; ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int minOperations(String str,int n){ int count=0 ; for(int i=0 ; iat(i+1) /= str->at(i + 1+1)) then count := count + 1 ; else skip ) ; i := i + 1 ) ; return (count + 1) / 2 ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var str : String ; str := "000111" ; var n : int ; n := str->size() ; OclFile["System.out"].println(minOperations(str, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str[]=br.readLine().split(""); int ans=0 ; int now=0 ; for(int i=0 ; isplit("") ; var ans : int ; ans := 0 ; var now : int ; now := 0 ; var i : int ; i := 0 ; while i < str->size() do ( ( if (str[i+1] = "(") then ( now := now + 1 ) else if (str[i+1] = ")") then ( now := now - 1 ) else ( ans := now ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=br.readLine(); while(str.contains("()")){ str=str.replaceAll("\\(\\)",""); } char[] input=str.toCharArray(); int starIndex=0 ; for(int i=0 ; i=0){ if(input[left]=='('){ while(right<=input.length-1){ if(input[right]==')'){ result++; break ; } right++; } } left--; } System.out.println(result); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var br : OclFile ; br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var str : String ; str := br.readLine() ; while (str->includes("()")) do ( str := str.replaceAllMatches("\\(\\)", "" ) ) ; var input : Sequence(String) ; input := str->characters() ; var starIndex : int ; starIndex := 0 ; var i : int ; i := 0 ; while i < input->size() do ( ( if (input[i+1] = '*') then ( starIndex := i ) else skip ) ; i := i + 1 ) ; var left : int ; left := starIndex - 1 ; var right : int ; right := starIndex + 1 ; var result : int ; result := 0 ; while (left >= 0) do ( if (input[left+1] = '(') then ( while (right <= input->size() - 1) do ( if (input[right+1] = ')') then ( result := result + 1 ; break ) else skip ; right := right + 1 ) ) else skip ; left := left - 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.math.BigInteger ; import java.util.*; import java.util.stream.Collectors ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); int k=sc.nextInt(); ArrayListc=new ArrayList<>(); for(int i=0 ; iselectedRows=new ArrayList<>(); for(int hi=0 ; hiselectedIndex=new ArrayList<>(); for(int wi=0 ; witoInteger() ; var w : int ; w := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var c : Sequence(Sequence(String)) ; c := Sequence{} ; var i : int ; i := 0 ; while i < h do ( ( c := c->including(sc.getCurrent()->split("")) ) ; i := i + 1 ) ; var result : int ; result := 0 ; var hb : int ; hb := 2->pow(h)->oclAsType(int) ; var wb : int ; wb := 2->pow(w)->oclAsType(int) ; var i : int ; i := 0 ; while i < hb do ( ( var hTmp : String ; hTmp := "000000" + ((i) + "") ; var hSt : String ; hSt := hTmp.subrange(hTmp->size() - h+1,hTmp->size() - h) ; var selectedRows : Sequence(Sequence(String)) ; selectedRows := Sequence{} ; var hi : int ; hi := 0 ; while hi < h do ( ( if (hSt->at(hi+1) = '1') then ( selectedRows := selectedRows->including(c->at(hi+1)) ) else skip ) ; hi := hi + 1 ) ; var j : int ; j := 0 ; while j < wb do ( ( var wTmp : String ; wTmp := "000000" + ((j) + "") ; var wSt : String ; wSt := wTmp.subrange(wTmp->size() - w+1,wTmp->size() - w) ; var selectedIndex : Sequence(int) ; selectedIndex := Sequence{} ; var wi : int ; wi := 0 ; while wi < w do ( ( if (wSt->at(wi+1) = '1') then ( selectedIndex := selectedIndex->including(wi) ) else skip ) ; wi := wi + 1 ) ; var count : int ; count := 0 ; for (strings : selectedRows) do ( ( for (wi : selectedIndex) do ( ( if ("#" = strings[wi+1]) then ( count := count + 1 ) else skip ) ) ) ) ; if (count = k) then ( result := result + 1 ) else skip ; ) ; j := j + 1 ) ; ) ; i := i + 1 ) ; OclFile["System.out"].println(result) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static long mulmod(long a,long b,long mod){ long 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 ; } public static void main(String[] args){ long a=9223372036854775807L,b=9223372036854775807L ; System.out.println(mulmod(a,b,100000000000L)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation mulmod( a : long, b : long, mod : long) : long pre: true post: true activity: ( var res : long ; res := 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/(2) ) ; return res mod mod ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var a : long ; a := 9223372036854775807L ; var b : long ; b := 9223372036854775807L ; OclFile["System.out"].println(mulmod(a, b, 100000000000L)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int parity(int a){ return a % 3 ; } static int solve(int[] array,int size){ int operations=0 ; for(int i=0 ; isize() ; OclFile["System.out"].println(solve(array, size)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int findSDSFunc(int n){ int DP[]=new int[n+1]; DP[0]=0 ; DP[1]=1 ; for(int i=2 ; i<=n ; i++){ if(i % 2==0)DP[i]=DP[i/2]; else DP[i]=DP[(i-1)/2]+DP[(i+1)/2]; } return DP[n]; } public static void main(String[] args){ int n=15 ; System.out.println(findSDSFunc(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation findSDSFunc( n : int) : int pre: true post: true activity: ( var DP : Sequence(int) ; DP := Integer.subrange(1,n + 1)->collect(0) ; DP[0+1] := 0 ; DP[1+1] := 1 ; var i : int ; i := 2 ; while i <= n do ( ( if (i mod 2 = 0) then DP[i+1] := DP[i / 2+1] ; else DP[i+1] := DP[(i - 1) / 2+1] + DP[(i + 1) / 2+1] ; ) ; i := i + 1 ) ; return DP[n+1] ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 15 ; OclFile["System.out"].println(findSDSFunc(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class C { public static void main(String...orange)throws Exception { Scanner input=new Scanner(System.in); int numCases=input.nextInt(); for(int n=0 ; n-40 ; System.out.printf("Case #%d: ",n+1); if(good)System.out.println("GOOD"); else System.out.println("BAD"); } } } ------------------------------------------------------------ OCL File: --------- class C { static operation main( orange : Sequence(String)) : void pre: true post: true activity: ( var input : OclFile ; input := OclFile.newOclFile_Read(OclFile["System.in"]) ; var numCases : int ; numCases := input.getCurrent()->toInteger() ; var n : int ; n := 0 ; while n < numCases do ( ( var N : int ; N := input.getCurrent()->toInteger() ; var arr : Sequence(int) ; arr := Integer.subrange(1,N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( arr[i+1] := input.getCurrent()->toInteger() ; ; i := i + 1 ) ; var data : Sequence(int) ; data := Integer.subrange(1,2 * N)->collect(0) ; var i : int ; i := 0 ; while i < N do ( data[arr[i+1] - i + N+1] := data[arr[i+1] - i + N+1] + 1 ; ; i := i + 1 ) ; var score : double ; score := 0 ; var i : int ; i := 700 ; while i < 1000 do ( score := score+(data[i+1]) ; ; i := i + 1 ) ; var i : int ; i := 1000 ; while i < 1300 do ( score := score-(data[i+1]) ; ; i := i + 1 ) ; var good : boolean ; good := score > -40 ; OclFile["System.out"].printf("Case #%d: ", n + 1) ; if (good) then OclFile["System.out"].println("GOOD") else OclFile["System.out"].println("BAD") ; ; ) ; n := n + 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.FileReader ; import java.io.FileWriter ; import java.io.IOException ; import java.io.PrintWriter ; import java.util.Arrays ; import java.util.Scanner ; public class ProperShuffle { public final static String INPUT_FILE_NAME="C-small-attempt0(1).in" ; public final static String OUTPUT_FILE_NAME="ProperShuffle.out" ; public static void main(String[] args){ try(Scanner in=new Scanner(new FileReader(INPUT_FILE_NAME)); PrintWriter out=new PrintWriter(new FileWriter(OUTPUT_FILE_NAME))){ double[][] rv=new double[1000][1000]; for(int t=0 ; t<1000 ; t++){ double[] cv=new double[1000]; for(int i=0 ; i<1000 ; i++){ if(i==t){ cv[i]=1 ; } else { cv[i]=0 ; } } for(int i=0 ; i<1000 ; i++){ double[] nv=new double[1000]; for(int j=0 ; j<1000 ; j++){ if(i!=j){ nv[j]=cv[j]*.999+cv[i]*.001 ; } } nv[i]=.001 ; cv=nv ; } rv[t]=cv ; } System.out.println("done"); int numT=in.nextInt(); int res=0 ; for(int t=1 ; t<=numT ; t++){ in.nextInt(); double total=0 ; for(int i=0 ; i<1000 ; i++){ int v=in.nextInt(); total+=rv[v][i]; } if(total<=1.005){ out.println("Case #"+t+": GOOD"); res++; } else { out.println("Case #"+t+": BAD"); } } System.out.println(res); } catch(IOException e){ e.printStackTrace(); } } } ------------------------------------------------------------ OCL File: --------- class ProperShuffle { static attribute INPUT_FILE_NAME : String := "C-small-attempt0(1).in"; static attribute OUTPUT_FILE_NAME : String := "ProperShuffle.out"; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var in : OclFile := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile(INPUT_FILE_NAME))) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile_Write(OclFile.newOclFile(OUTPUT_FILE_NAME))) ; ( var rv : Sequence(Sequence(double)) ; rv := Integer.subrange(1,1000)->collect(Integer.subrange(1,1000)->collect(0.0)) ; var t : int ; t := 0 ; while t < 1000 do ( ( var cv : Sequence(double) ; cv := Integer.subrange(1,1000)->collect(0.0) ; var i : int ; i := 0 ; while i < 1000 do ( ( if (i = t) then ( cv[i+1] := 1 ) else ( cv[i+1] := 0 ) ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < 1000 do ( ( var nv : Sequence(double) ; nv := Integer.subrange(1,1000)->collect(0.0) ; var j : int ; j := 0 ; while j < 1000 do ( ( if (i /= j) then ( nv[j+1] := cv[j+1] * .999 + cv[i+1] * .001 ) else skip ) ; j := j + 1 ) ; nv[i+1] := .001 ; cv := nv ) ; i := i + 1 ) ; rv[t+1] := cv ) ; t := t + 1 ) ; OclFile["System.out"].println("done") ; var numT : int ; numT := in.getCurrent()->toInteger() ; var res : int ; res := 0 ; var t : int ; t := 1 ; while t <= numT do ( ( skip ; var total : double ; total := 0 ; var i : int ; i := 0 ; while i < 1000 do ( ( var v : int ; v := in.getCurrent()->toInteger() ; total := total+(rv[v+1][i+1]) ) ; i := i + 1 ) ; if (total <= 1.005) then ( skip ; res := res + 1 ) else ( skip ) ) ; t := t + 1 ) ; OclFile["System.out"].println(res) ; )) catch (e : IOException) do ( e.printStackTrace() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.File ; import java.io.FileInputStream ; import java.util.Arrays ; import java.util.Random ; import java.util.Scanner ; public class ProperShuffle { static Random random=new Random(); private static String file="data/r1c-C-small-attempt0.in" ; private static final int LEN=1000 ; private static final int TRY_COUNT=1000*LEN ; public static void main(String[] args)throws Exception { FileInputStream is=new FileInputStream(new File(file)); Scanner scanner=new Scanner(is); int[][] count=new int[LEN][LEN]; int[] arr=new int[LEN]; for(int i=0 ; i1.0){ out(t,"BAD"); } else { out(t,"GOOD"); } } } static void shuffle(int arr[]){ int len=arr.length ; for(int k=0 ; kcollect(Integer.subrange(1,LEN)->collect(0)) ; var arr : Sequence(int) ; arr := Integer.subrange(1,LEN)->collect(0) ; var i : int ; i := 0 ; while i < LEN do ( ( arr[i+1] := i ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < TRY_COUNT do ( ( var copy : Sequence(int) ; copy := arr->copy() ; execute shuffle(copy) ; var j : int ; j := 0 ; while j < LEN do ( ( count[copy[j+1]+1][j+1] := count[copy[j+1]+1][j+1] + 1 ) ; j := j + 1 ) ) ; i := i + 1 ) ; var T : int ; T := scanner.getCurrent()->toInteger() ; var t : int ; t := 0 ; while t < T do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; var prob : double ; prob := 1.0 ; var i : int ; i := 0 ; while i < n do ( ( var s : int ; s := scanner.getCurrent()->toInteger() ; prob := prob*(count[s+1][i+1]->oclAsType(double) / (TRY_COUNT / LEN)->oclAsType(double)) ) ; i := i + 1 ) ; if (prob > 1.0) then ( execute out(t, "BAD") ) else ( execute out(t, "GOOD") ) ) ; t := t + 1 ) ; ); static operation shuffle( arr : Sequence(int)) : void pre: true post: true activity: ( var len : int ; len := arr->size() ; var k : int ; k := 0 ; while k < len do ( ( var p : int ; p := random.nextInt(len) ; var t : int ; t := arr[p+1] ; arr[p+1] := arr[k+1] ; arr[k+1] := t ) ; k := k + 1 ) ); static operation out( t : int, ans : OclAny) : void pre: true post: true activity: ( OclFile["System.out"].println("Case #" + (t + 1) + ": " + ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { static int MAX=100000 ; static int findSumofEle(int arr1[],int m,int arr2[],int n){ int hash[]=new int[MAX]; for(int i=0 ; icollect(0) ; var i : int ; i := 0 ; while i < n do ( ( hash[arr2[i+1]+1] := hash[arr2[i+1]+1] + 1 ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i < MAX do ( ( hash[i+1] := hash[i+1] + hash[i - 1+1] ) ; i := i + 1 ) ; var maximumFreq : int ; maximumFreq := 0 ; var i : int ; i := 0 ; while i < m do ( ( maximumFreq := Set{maximumFreq, hash[arr1[i+1]+1]}->max() ) ; i := i + 1 ) ; var sumOfElements : int ; sumOfElements := 0 ; var i : int ; i := 0 ; while i < m do ( ( sumOfElements := sumOfElements+(if (maximumFreq = hash[arr1[i+1]+1]) then arr1[i+1] else 0 endif) ) ; i := i + 1 ) ; return sumOfElements ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr1 : Sequence(int) ; arr1 := Sequence{2,5,6,8} ; var arr2 : Sequence(int) ; arr2 := Sequence{4,10} ; var m : int ; m := arr1->size() ; var n : int ; n := arr2->size() ; OclFile["System.out"].println(findSumofEle(arr1, m, arr2, n)) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Arrays ; class Test { static int count(int x,int Y[],int n,int NoOfY[]){ if(x==0)return 0 ; if(x==1)return NoOfY[0]; int idx=Arrays.binarySearch(Y,x); int ans ; if(idx<0){ idx=Math.abs(idx+1); ans=Y.length-idx ; } else { while(idxtoInteger() ; while (test > 0) do ( var n : long ; n := sc.getCurrent()->toLong() ; if ((MathLib.bitwiseAnd(n,(n - 1))) /= 0) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ; test := test - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; import java.io.*; import java.util.*; public class Main { public static void main(String[] args){ int max=-1 ; Scanner sc=new Scanner(System.in); int x=sc.nextInt(); while(x>0){ long n=sc.nextLong(); sc.nextLine(); if(n % 2==1)System.out.println("YES"); else { boolean non=true ; while(n>1){ if(n % 2==1){ non=false ; break ; } n=n/2 ; } if(non)System.out.println("NO"); else System.out.println("YES"); } x=x-1 ; } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var max : int ; max := -1 ; var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var x : int ; x := sc.getCurrent()->toInteger() ; while (x > 0) do ( var n : long ; n := sc.getCurrent()->toLong() ; skip ; if (n mod 2 = 1) then OclFile["System.out"].println("YES") else ( var non : boolean ; non := true ; while (n > 1) do ( if (n mod 2 = 1) then ( non := false ; break ) else skip ; n := n / 2 ) ; if (non) then OclFile["System.out"].println("NO") ; else OclFile["System.out"].println("YES") ; ) ; x := x - 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.HashSet ; import java.util.Scanner ; import java.util.Set ; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int h=Integer.parseInt(scan.next()); int w=Integer.parseInt(scan.next()); int k=Integer.parseInt(scan.next()); int[][] c=new int[h][w]; for(int i=0 ; iiSet=new HashSet(); for(int a=0 ; ajSet=new HashSet(); for(int a=0 ; atoInteger() ; var w : int ; w := (scan.getCurrent())->toInteger() ; var k : int ; k := (scan.getCurrent())->toInteger() ; var c : Sequence(Sequence(int)) ; c := Integer.subrange(1,h)->collect(Integer.subrange(1,w)->collect(0)) ; var i : int ; i := 0 ; while i < h do ( ( var s : Sequence(String) ; s := scan.getCurrent()->split("") ; var j : int ; j := 0 ; while j < w do ( ( if (s[j+1] = ".") then ( c[i+1][j+1] := 0 ) else ( c[i+1][j+1] := 1 ) ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; var ans : long ; ans := 0 ; var i : int ; i := 0 ; while i < ((1*(2->pow(h)))->oclAsType(long)) do ( ( var iSet : Set(int) ; iSet := Set{} ; var a : int ; a := 0 ; while a < h do ( ( if ((MathLib.bitwiseAnd(i,((1*(2->pow(a)))->oclAsType(long)))) /= 0) then ( iSet := iSet->including(a) ) else skip ) ; a := a + 1 ) ; var j : int ; j := 0 ; while j < ((1*(2->pow(w)))->oclAsType(long)) do ( ( var jSet : Set(int) ; jSet := Set{} ; var a : int ; a := 0 ; while a < w do ( ( if ((MathLib.bitwiseAnd(j,((1*(2->pow(a)))->oclAsType(long)))) /= 0) then ( jSet := jSet->including(a) ) else skip ) ; a := a + 1 ) ; var black : int ; black := 0 ; var a : int ; a := 0 ; while a < h do ( ( if (iSet->includes(a)) then ( continue ) else skip ; var b : int ; b := 0 ; while b < w do ( ( if (jSet->includes(b)) then ( continue ) else skip ; black := black+(c[a+1][b+1]) ) ; b := b + 1 ) ) ; a := a + 1 ) ; if (black = k) then ( ans := ans + 1 ) else skip ; ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; import java.util.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); StringTokenizer inputString=new StringTokenizer(reader.readLine()); int t=Integer.parseInt(inputString.nextToken()); while(t>0){ StringTokenizer inputString2=new StringTokenizer(reader.readLine()); long n=Long.parseLong(inputString2.nextToken()); String x="NO" ; for(long i=n ; i>1 ; i=i/2){ if(i % 2!=0){ x="YES" ; i=1 ; } } out.println(x); t--; } reader.close(); out.close(); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; var inputString : OclIterator ; inputString := OclIterator.newOclIterator_String(reader.readLine()) ; var t : int ; t := (inputString.next())->toInteger() ; while (t > 0) do ( var inputString2 : OclIterator ; inputString2 := OclIterator.newOclIterator_String(reader.readLine()) ; var n : long ; n := (inputString2.next())->toLong() ; var x : String ; x := "NO" ; var i : long ; i := n ; while i > 1 do ( ( if (i mod 2 /= 0) then ( x := "YES" ; i := 1 ) else skip ) ; i := i / 2 ) ; skip ; t := t - 1 ; ) ; skip ; skip ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class A_Odd_Divisor { public static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || ! st.hasMoreElements()){ try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str="" ; try { if(st.hasMoreTokens()){ str=st.nextToken("\n"); } else { str=br.readLine(); } } catch(IOException e){ e.printStackTrace(); } return str ; } } public static void main(String[] args){ FastReader reader=new FastReader(); int T=reader.nextInt(); while(T!=0){ T--; long N=reader.nextLong(); if(N % 2==1){ System.out.println("YES"); } else { boolean ans=true ; while(N!=1){ if(N % 2==0){ N=N/2 ; } else { ans=false ; break ; } } if(ans==false){ System.out.println("YES"); } else { System.out.println("NO"); } } } } } ------------------------------------------------------------ OCL File: --------- class A_Odd_Divisor { static class FastReader { attribute br : OclFile; attribute st : OclIterator; static operation newFastReader() : FastReader pre: true post: true activity: ( var self : FastReader ; self := createFastReader(); self.initialise(); return self ); operation initialise() : void pre: true post: true activity: ( br := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ); operation next() : String pre: true post: true activity: ( while (st = null or not(st.hasNext())) do ( try ( st := OclIterator.newOclIterator_String(br.readLine()) ) catch (e : IOException) do ( e.printStackTrace() ) ) ; return st.next() ); operation nextInt() : int pre: true post: true activity: ( return (next())->toInteger() ); operation nextLong() : long pre: true post: true activity: ( return (next())->toLong() ); operation nextDouble() : double pre: true post: true activity: ( return (next())->toReal() ); operation nextLine() : String pre: true post: true activity: ( var str : String ; str := "" ; try ( if (st.hasNext()) then ( str := st.nextToken("\n") ) else ( str := br.readLine() ) ) catch (e : IOException) do ( e.printStackTrace() ) return str ); } static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : FastReader ; reader := FastReader.newFastReader() ; var T : int ; T := reader.nextInt() ; while (T /= 0) do ( T := T - 1 ; var N : long ; N := reader.nextLong() ; if (N mod 2 = 1) then ( OclFile["System.out"].println("YES") ) else ( var ans : boolean ; ans := true ; while (N /= 1) do ( if (N mod 2 = 0) then ( N := N / 2 ) else ( ans := false ; break ) ) ; if (ans = false) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class OddDivisor { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ double a=sc.nextDouble(); if(a % 2==0){ while(a % 2==0){ a=a/2 ; } if(a>1){ System.out.println("YES"); } else { System.out.println("NO"); } } else { System.out.println("YES"); } } } } ------------------------------------------------------------ OCL File: --------- class OddDivisor { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := sc.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var a : double ; a := sc.getCurrent()->toReal() ; if (a mod 2 = 0) then ( while (a mod 2 = 0) do ( a := a / 2 ) ; if (a > 1) then ( OclFile["System.out"].println("YES") ) else ( OclFile["System.out"].println("NO") ) ) else ( OclFile["System.out"].println("YES") ) ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String[] args){ new A().solve(); } Scanner in ; private void solve(){ in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); countLikes(n); } } private void countLikes(int n){ int likes=0 ; int dislikes=0 ; while(n-->0){ int user=in.nextInt(); if(user==1 || user==3){ ++likes ; } else if(user==2){ ++dislikes ; } } System.out.println(likes); } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A.newA().solve() ); attribute in : OclFile; operation solve() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; execute countLikes(n) ) ; ) ); operation countLikes( n : int) : void pre: true post: true activity: ( var likes : int ; likes := 0 ; var dislikes : int ; dislikes := 0 ; while (n > 0) do ( n := n - 1 ; skip ; ( var user : int ; user := in.getCurrent()->toInteger() ; if (user = 1 or user = 3) then ( likes := likes + 1 ) else if (user = 2) then ( dislikes := dislikes + 1 ) else skip ; ) ; ) ; OclFile["System.out"].println(likes) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class exe_A1511 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); int[] ans=new int[t]; for(int i=0 ; itoInteger() ; var ans : Sequence(int) ; ans := Integer.subrange(1,t)->collect(0) ; var i : int ; i := 0 ; while i < t do ( ( var n : int ; n := scanner.getCurrent()->toInteger() ; var j : int ; j := 0 ; while j < n do ( ( var x : int ; x := scanner.getCurrent()->toInteger() ; if (x = 1 or x = 3) then ans[i+1] := ans[i+1] + 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; skip ; for (i : ans) do ( OclFile["System.out"].println(i) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class A { public static void main(String[] args){ new A().solve(); } Scanner in ; private void solve(){ in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); countLikes(n); } } private void countLikes(int n){ int likes=0 ; while(n-->0){ int user=in.nextInt(); if(user==1 || user==3){ ++likes ; } } System.out.println(likes); } } ------------------------------------------------------------ OCL File: --------- class A { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( A.newA().solve() ); attribute in : OclFile; operation solve() : void pre: true post: true activity: ( in := OclFile.newOclFile_Read(OclFile["System.in"]) ; var t : int ; t := in.getCurrent()->toInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var n : int ; n := in.getCurrent()->toInteger() ; execute countLikes(n) ) ; ) ); operation countLikes( n : int) : void pre: true post: true activity: ( var likes : int ; likes := 0 ; while (n > 0) do ( n := n - 1 ; skip ; ( var user : int ; user := in.getCurrent()->toInteger() ; if (user = 1 or user = 3) then ( likes := likes + 1 ) else skip ) ; ) ; OclFile["System.out"].println(likes) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int yoko=scan.nextInt(); int tate=scan.nextInt(); String c=scan.next(); int i ; int y ; for(i=1 ; i<=tate ; i++){ for(y=1 ; y<=yoko ; y++){ if(i==1 && y==1 || i==tate && y==yoko || i==1 && y==yoko || y==1 && i==tate){ System.out.print("+"); } else if(y==1 || y==yoko){ System.out.print("|"); } else if(i==1 || i==tate){ System.out.print("-"); } else if(i==tate/2+1 && y==yoko/2+1){ System.out.print(c); } else { System.out.print("."); } } System.out.println(""); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var yoko : int ; yoko := scan.getCurrent()->toInteger() ; var tate : int ; tate := scan.getCurrent()->toInteger() ; var c : String ; c := scan.getCurrent() ; var i : int ; var y : int ; i := 1 ; while i <= tate do ( ( y := 1 ; while y <= yoko do ( ( if (i = 1 & y = 1 or i = tate & y = yoko or i = 1 & y = yoko or y = 1 & i = tate) then ( OclFile["System.out"].print("+") ) else if (y = 1 or y = yoko) then ( OclFile["System.out"].print("|") ) else if (i = 1 or i = tate) then ( OclFile["System.out"].print("-") ) else if (i = tate / 2 + 1 & y = yoko / 2 + 1) then ( OclFile["System.out"].print(c) ) else ( OclFile["System.out"].print(".") ) ; ; ; ) ; y := y + 1 ) ; OclFile["System.out"].println("") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class DeleteFromTheLeft { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.next(); String t=sc.next(); int w=0 ; while(true){ int i=s.length()-w-1 ; int j=t.length()-w-1 ; if(i>=0 && j>=0 && s.charAt(i)==t.charAt(j)){ w++; } else { break ; } } System.out.println(s.length()+t.length()-2*w); } } ------------------------------------------------------------ OCL File: --------- class DeleteFromTheLeft { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var s : String ; s := sc.getCurrent() ; var t : String ; t := sc.getCurrent() ; var w : int ; w := 0 ; while (true) do ( var i : int ; i := s->size() - (w)->char2byte() - 1 ; var j : int ; j := t->size() - (w)->char2byte() - 1 ; if (i >= 0 & j >= 0 & s->at(i+1) = t->at(j+1)) then ( w := w + 1 ) else ( break ) ) ; OclFile["System.out"].println(s->size() + t->size() - 2 * w) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class Main { void solve(){ Scanner sc=new Scanner(System.in); int W=sc.nextInt(); int H=sc.nextInt(); String c=sc.next(); for(int i=0 ; itoInteger() ; var H : int ; H := sc.getCurrent()->toInteger() ; var c : String ; c := sc.getCurrent() ; var i : int ; i := 0 ; while i < H do ( ( var j : int ; j := 0 ; while j < W do ( ( if (i = 0 & j = 0 or i = 0 & j = W - 1 or i = H - 1 & j = 0 or i = H - 1 & j = W - 1) then ( OclFile["System.out"].print("+") ) else if (i = 0 or i = H - 1) then ( OclFile["System.out"].print("-") ) else if (j = 0 or j = W - 1) then ( OclFile["System.out"].print("|") ) else if (i = H / 2 & j = W / 2) then ( OclFile["System.out"].print(c) ) else ( OclFile["System.out"].print(".") ) ; ; ; ) ; j := j + 1 ) ; OclFile["System.out"].println() ) ; i := i + 1 ) ; ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( Main.newMain().solve() ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.*; public class Main { public static void main(String[] args){ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); try { String str=reader.readLine(); String s[]=str.split(" "); int w=Integer.parseInt(s[0]); int h=Integer.parseInt(s[1]); String c=s[2]; int x=(w/2); int y=(h/2); StringBuilder sb=new StringBuilder(); for(int i=0 ; i0 ? gcd(b,a % b): a ; } static int lcm(int a,int b){ return a*b/gcd(a,b); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var reader : OclFile ; reader := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; try ( var str : String ; str := reader.readLine() ; var s : Sequence(String) ; s := str->split(" ") ; var w : int ; w := (s[0+1])->toInteger() ; var h : int ; h := (s[1+1])->toInteger() ; var c : String ; c := s[2+1] ; var x : int ; x := (w / 2) ; var y : int ; y := (h / 2) ; var sb : String ; sb := StringLib.newString() ; var i : int ; i := 0 ; while i < h do ( ( var j : int ; j := 0 ; while j < w do ( ( if (i = 0 or i = h - 1) then ( if (j = 0 or j = (w)->char2byte() - 1) then ( sb := sb + StringLib.newString("+") ) else ( sb := sb + StringLib.newString("-") ) ) else ( if (j = 0 or j = (w)->char2byte() - 1) then ( sb := sb + StringLib.newString("|") ) else if (i = y & j = x) then ( sb := sb + StringLib.newString(c) ) else ( sb := sb + StringLib.newString(".") ) ; ) ; if (j = (w)->char2byte() - 1 & i /= h - 1) then ( sb := sb + StringLib.newString("\n") ) else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; skip ; ) catch (e : IOException) do ( e.printStackTrace() ) ); static operation gcd( a : int, b : int) : int pre: true post: true activity: ( return if b > 0 then gcd(b, a mod b) else a endif ); static operation lcm( a : int, b : int) : int pre: true post: true activity: ( return a * b / gcd(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Main main=new Main(); main.solve(); } public void solve(){ Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int H=scan.nextInt(); int W=scan.nextInt(); int K=scan.nextInt(); int[][] blacks=new int[H][W]; for(int i=0 ; i>row)& 1)==1)continue ; for(int column=0 ; column>column)& 1)==1)continue ; count+=blacks[row][column]; } } if(count==K)ans+=1 ; } } System.out.println(ans); } private int pow(int base,int count){ if(count==0)return 1 ; if(count % 2==1)return base*pow(base,count-1); int t=pow(base,count/2); return t*t ; } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var main : Main ; main := Main.newMain() ; main.solve() ); operation solve() : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"]))) ; var H : int ; H := scan.getCurrent()->toInteger() ; var W : int ; W := scan.getCurrent()->toInteger() ; var K : int ; K := scan.getCurrent()->toInteger() ; var blacks : Sequence(Sequence(int)) ; blacks := Integer.subrange(1,H)->collect(Integer.subrange(1,W)->collect(0)) ; var i : int ; i := 0 ; while i < H do ( ( var t : Sequence(String) ; t := scan.getCurrent()->characters() ; var j : int ; j := 0 ; while j < W do ( ( if (t[j+1] = '#') then blacks[i+1][j+1] := 1 ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; var max_h : int ; max_h := pow(2, H) ; var max_w : int ; max_w := pow(2, W) ; var ans : int ; ans := 0 ; var i : int ; i := 0 ; while i < max_h do ( ( var j : int ; j := 0 ; while j < max_w do ( ( var count : int ; count := 0 ; var row : int ; row := 0 ; while row < H do ( ( if ((((i/(2->pow(row)))->oclAsType(long)) & 1) = 1) then continue else skip ; var column : int ; column := 0 ; while column < W do ( ( if ((((j/(2->pow(column)))->oclAsType(long)) & 1) = 1) then continue else skip ; count := count+(blacks[row+1][column+1]) ) ; column := column + 1 ) ) ; row := row + 1 ) ; if (count = K) then ans := ans+(1) ; else skip ) ; j := j + 1 ) ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ); operation pow( base : int, count : int) : int pre: true post: true activity: ( if (count = 0) then return 1 else skip ; if (count mod 2 = 1) then return base * pow(base, count - 1) else skip ; var t : int ; t := pow(base, count / 2) ; return t * t ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.util.StringTokenizer ; class Main { public static void main(String[] args){ BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in)); String str="" ; StringTokenizer stk ; String moji="" ; int yoko,tate ; String[] hata ; try { str=bfr.readLine(); if(str==null){ System.exit(0); } else { stk=new StringTokenizer(str," "); yoko=Integer.parseInt(stk.nextToken()); tate=Integer.parseInt(stk.nextToken()); moji=stk.nextToken(); hata=new String[tate]; for(int i=0 ; itoInteger() ; tate := (stk.next())->toInteger() ; moji := stk.next() ; hata := Integer.subrange(1,tate)->collect(null) ; var i : int ; i := 0 ; while i < tate do ( ( hata[i+1] := "" ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < yoko do ( ( if (i = 0 or i = (yoko)->char2byte() - 1) then ( hata[0+1] := hata[0+1] + "+" ; hata[(tate)->char2byte() - 1+1] := hata[(tate)->char2byte() - 1+1] + "+" ; var j : int ; j := 1 ; while j < (tate)->char2byte() - 1 do ( ( hata[j+1] := hata[j+1] + "|" ) ; j := j + 1 ) ) else ( hata[0+1] := hata[0+1] + "-" ; hata[(tate)->char2byte() - 1+1] := hata[(tate)->char2byte() - 1+1] + "-" ; var j : int ; j := 1 ; while j < (tate)->char2byte() - 1 do ( ( if (j /= ((tate)->char2byte() - 1) / 2) then ( hata[j+1] := hata[j+1] + "." ) else ( if (i = ((yoko)->char2byte() - 1) / 2) then ( hata[j+1] := hata[j+1] + moji ) else ( hata[j+1] := hata[j+1] + "." ) ) ) ; j := j + 1 ) ) ) ; i := i + 1 ) ; var l : int ; l := 0 ; while l < tate do ( ( OclFile["System.out"].println(hata[l+1]) ) ; l := l + 1 ) ; ) ) catch (e : IOException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int w=sc.nextInt(); int h=sc.nextInt(); char c=sc.next().charAt(0); StringBuilder sb=new StringBuilder(); sb.append("+"); for(int i=0 ; itoInteger() ; var h : int ; h := sc.getCurrent()->toInteger() ; var c : String ; c := sc.getCurrent()->at(0+1) ; var sb : String ; sb := StringLib.newString() ; sb := sb + StringLib.newString("+") ; var i : int ; i := 0 ; while i < w - 2 do ( ( sb := sb + StringLib.newString("-") ) ; i := i + 1 ) ; sb := sb + StringLib.newString("+\n") ; var y : int ; y := 1 ; while y < h - 1 do ( ( sb := sb + StringLib.newString("|") ; var x : int ; x := 1 ; while x < w - 1 do ( ( if (y = h / 2 & x = w / 2) then ( sb := sb + StringLib.newString(c) ) else ( sb := sb + StringLib.newString(".") ) ) ; x := x + 1 ) ; sb := sb + StringLib.newString("|\n") ) ; y := y + 1 ) ; sb := sb + StringLib.newString("+") ; var i : int ; i := 0 ; while i < w - 2 do ( ( sb := sb + StringLib.newString("-") ) ; i := i + 1 ) ; sb := sb + StringLib.newString("+") ; OclFile["System.out"].println(sb) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class B928 { static Scanner sc=null ; public static void main(String args[]){ sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int a[]=new int[n+1]; for(int i=1 ; i<=n ; i++)a[i]=sc.nextInt(); int dp[]=new int[n+1]; dp[1]=Math.min(k+1,n); for(int i=2 ; i<=n ; i++){ int num=a[i]; if(num==0){ if(k==0){ dp[i]=1 ; } else { int left=Math.min(k,i-1); int right=Math.min(k,n-i); dp[i]=left+right+1 ; } } else { if(k==0){ dp[i]=1+dp[num]; } else { int left=Math.min(k,i-1); int right=Math.min(k,n-i); int l1=Math.max(i-k,1); int r1=Math.min(num+k,n); int d=Math.max(0,r1-l1+1); dp[i]=dp[num]+1+left+right-d ; } } } for(int i=1 ; i<=n ; i++){ System.out.print(dp[i]+" "); } } } ------------------------------------------------------------ OCL File: --------- class B928 { static attribute sc : OclFile := null; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; var n : int ; n := sc.getCurrent()->toInteger() ; var k : int ; k := sc.getCurrent()->toInteger() ; var a : Sequence(int) ; a := Integer.subrange(1,n + 1)->collect(0) ; var i : int ; i := 1 ; while i <= n do ( a[i+1] := sc.getCurrent()->toInteger() ; ; i := i + 1 ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,n + 1)->collect(0) ; dp[1+1] := Set{k + 1, n}->min() ; var i : int ; i := 2 ; while i <= n do ( ( var num : int ; num := a[i+1] ; if (num = 0) then ( if (k = 0) then ( dp[i+1] := 1 ) else ( var left : int ; left := Set{k, i - 1}->min() ; var right : int ; right := Set{k, n - i}->min() ; dp[i+1] := left + right + 1 ) ) else ( if (k = 0) then ( dp[i+1] := 1 + dp[num+1] ) else ( var left : int ; left := Set{k, i - 1}->min() ; var right : int ; right := Set{k, n - i}->min() ; var l1 : int ; l1 := Set{i - k, 1}->max() ; var r1 : int ; r1 := Set{num + k, n}->min() ; var d : int ; d := Set{0, r1 - l1 + 1}->max() ; dp[i+1] := dp[num+1] + 1 + left + right - d ; ) ) ) ; i := i + 1 ) ; var i : int ; i := 1 ; while i <= n do ( ( OclFile["System.out"].print(dp[i+1] + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B928 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int K=in.nextInt(); int[] count=new int[N]; for(int n=0 ; ntoInteger() ; var K : int ; K := in.getCurrent()->toInteger() ; var count : Sequence(int) ; count := Integer.subrange(1,N)->collect(0) ; var n : int ; n := 0 ; while n < N do ( ( var start : int ; start := Set{0, n - K}->max() ; var end : int ; end := Set{N - 1, n + K}->min() ; var previous : int ; previous := in.getCurrent()->toInteger() ; if (previous = 0) then ( count[n+1] := end - start + 1 ) else ( previous := previous - 1 ; var prevEnd : int ; prevEnd := Set{N - 1, previous + K}->min() ; count[n+1] := count[previous+1] + end - Set{start - 1, prevEnd}->max() ) ) ; n := n + 1 ) ; var output : String ; output := StringLib.newString() ; for (c : count) do ( ( output := output + StringLib.newString(c) + StringLib.newString(' ') ) ) ; OclFile["System.out"].println(output) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.PrintWriter ; public class Chat { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); solve(br,pr); pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr)throws IOException { String[] temp=br.readLine().split(" "); int n=Integer.parseInt(temp[0]); int k=Integer.parseInt(temp[1]); int[] nums=new int[n]; temp=br.readLine().split(" "); for(int i=0 ; isplit(" ") ; var n : int ; n := (temp[0+1])->toInteger() ; var k : int ; k := (temp[1+1])->toInteger() ; var nums : Sequence(int) ; nums := Integer.subrange(1,n)->collect(0) ; temp := br.readLine()->split(" ") ; var i : int ; i := 0 ; while i < n do ( ( nums[i+1] := (temp[i+1])->toInteger() ) ; i := i + 1 ) ; var dp : Sequence(int) ; dp := Integer.subrange(1,n)->collect(0) ; dp[0+1] := Set{n, k + 1}->min() ; var i : int ; i := 1 ; while i < n do ( ( var last : int ; last := nums[i+1] ; if (last = 0) then ( var right : int ; right := Set{k, n - i - 1}->min() ; var left : int ; left := Set{k, i}->min() ; dp[i+1] := right + left + 1 ) else ( var j : int ; j := last - 1 ; dp[i+1] := dp[j+1] ; var lastMax : int ; lastMax := j + k ; var currentMax : int ; currentMax := Set{n - 1, i + k}->min() ; var currentMin : int ; currentMin := Set{i - k, 0}->max() ; var overlap : int ; overlap := Set{0, Set{currentMax, lastMax}->min() - currentMin + 1}->max() ; dp[i+1] := dp[i+1]-(overlap) ; var right : int ; right := Set{k, n - i - 1}->min() ; var left : int ; left := Set{k, i}->min() ; dp[i+1] := dp[i+1]+(right + left + 1) ; ) ) ; i := i + 1 ) ; for (i : dp) do ( ( skip ) ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder str=new StringBuilder(""); int t=Integer.parseInt(br.readLine()); while(t-->0){ String h[]=br.readLine().split(" "); int n=Integer.parseInt(h[0]); int k=Integer.parseInt(h[1]); String ans="" ; char a='a' ; int i ; for(i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var h : Sequence(String) ; h := br.readLine()->split(" ") ; var n : int ; n := (h[0+1])->toInteger() ; var k : int ; k := (h[1+1])->toInteger() ; var ans : String ; ans := "" ; var a : String ; a := 'a' ; var i : int ; i := 0 ; while i < k do ( ans := ans+(a) ; ; i := i + 1 ) ; var b : String ; b := 'b' ; var c : String ; c := 'c' ; i := 0 ; while i < (n)->char2byte() - k do ( ( if (i mod 3 = 0) then ans := ans+(b) ; else if (i mod 3 = 1) then ans := ans+(c) else ans := ans+(a) ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(ans) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int k=sc.nextInt(),n=sc.nextInt(); StringBuilder sb=new StringBuilder(k); for(int i=0 ; itoInteger() ; while (t > 0) do ( t := t - 1 ; skip ; ( var k : int ; k := sc.getCurrent()->toInteger() ; var n : int ; n := sc.getCurrent()->toInteger() ; var sb : String ; sb := StringLib.newString(k) ; var i : int ; i := 0 ; while i < n do ( ( sb := sb + StringLib.newString("a") ) ; i := i + 1 ) ; var i : int ; i := 0 ; while i < k - n do ( ( if ((i mod 3) = 0) then ( sb := sb + StringLib.newString("c") ) else if ((i mod 3) = 1) then ( sb := sb + StringLib.newString("b") ) else if ((i mod 3) = 2) then ( sb := sb + StringLib.newString("a") ) else skip ; ; ) ; i := i + 1 ) ; OclFile["System.out"].println(sb) ; ) ; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import static java.lang.System.*; import java.io.IOException ; import java.util.ArrayList ; import java.util.Collections ; import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(in); String word1=sc.nextLine(); String word2=sc.nextLine(); int count=0 ; for(int i=word1.length()-1,j=word2.length()-1 ; i>=0 ; i--,j--){ if(j==-1)break ; if(word1.charAt(i)==word2.charAt(j)){ count=count+2 ; } else { break ; } } out.println(word1.length()+word2.length()-count); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(in) ; var word1 : String ; word1 := sc.nextLine() ; var word2 : String ; word2 := sc.nextLine() ; var count : int ; count := 0 ; var i : int ; i := word1->size() - 1 ; var j : int ; j := word2->size() - 1 ; while i >= 0 do ( ( if (j = -1) then break else skip ; if (word1->at(i+1) = word2->at(j+1)) then ( count := count + 2 ) else ( break ) ) ; i := i - 1 ; j := j - 1 ) ; out.println(word1->size() + word2->size() - (count)->char2byte()) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; class GFG { static int countPairs(int arr[],int n){ HashMapfrequency=new HashMap(); for(int i=0 ; ix : frequency.entrySet()){ int f=x.getValue(); count+=f*(f-1)/2 ; } return count ; } public static void main(String[] args){ int arr[]={ 1,1,1 }; int n=arr.length ; System.out.print(countPairs(arr,n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countPairs( arr : Sequence(int), n : int) : int pre: true post: true activity: ( var frequency : Map(int,int) ; frequency := Map{} ; var i : int ; i := 0 ; while i < n do ( ( if (frequency->keys()->includes(arr[i+1])) then ( frequency := frequency->union(Map{arr[i+1] |-> frequency->at(arr[i+1]) + 1}) ) else ( frequency := frequency->union(Map{arr[i+1] |-> 1}) ) ) ; i := i + 1 ) ; var count : int ; count := 0 ; for (x : frequency->asSet()) do ( ( var f : int ; f := x.getValue() ; count := count+(f * (f - 1) / 2) ) ) ; return count ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var arr : Sequence(int) ; arr := Sequence{1,1,1} ; var n : int ; n := arr->size() ; OclFile["System.out"].print(countPairs(arr, n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Stack ; class GFG { static int countNumber(int n){ int result=0 ; for(int i=1 ; i<=9 ; i++){ Stacks=new Stack<>(); if(i<=n){ s.push(i); result++; } while(! s.empty()){ int tp=s.peek(); s.pop(); for(int j=tp % 10 ; j<=9 ; j++){ int x=tp*10+j ; if(x<=n){ s.push(x); result++; } } } } return result ; } public static void main(String[] args){ int n=15 ; System.out.println(countNumber(n)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation countNumber( n : int) : int pre: true post: true activity: ( var result : int ; result := 0 ; var i : int ; i := 1 ; while i <= 9 do ( ( var s : Sequence(int) ; s := Sequence{} ; if (i <= n) then ( s := s->append(i) ; result := result + 1 ) else skip ; while (not(s->isEmpty())) do ( var tp : int ; tp := s->min() ; s := s->front() ; var j : int ; j := tp mod 10 ; while j <= 9 do ( ( var x : int ; x := tp * 10 + j ; if (x <= n) then ( s := s->append(x) ; result := result + 1 ) else skip ) ; j := j + 1 ) ) ) ; i := i + 1 ) ; return result ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 15 ; OclFile["System.out"].println(countNumber(n)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); System.out.println(new SocialGame(scanner.nextInt(),scanner.nextInt(),scanner.nextInt()).calcDays_to_earn_goal_coins()); scanner.close(); } } class SocialGame { private int daily_coin=0 ; private int weekly_coin=0 ; private int goal_coin=0 ; public SocialGame(int daily_coin,int weekly_coin,int goal_coin){ this.daily_coin=daily_coin ; this.weekly_coin=weekly_coin ; this.goal_coin=goal_coin ; } public int calcDays_to_earn_goal_coins(){ int remain_coin=goal_coin ; int passed_days=0 ; while(true){ passed_days+=1 ; remain_coin-=daily_coin ; if(passed_days % 7==0){ remain_coin-=weekly_coin ; } if(remain_coin<=0){ return passed_days ; } } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scanner : OclFile ; scanner := OclFile.newOclFile_Read(OclFile["System.in"]) ; OclFile["System.out"].println(SocialGame.newSocialGame(scanner.getCurrent()->toInteger(), scanner.getCurrent()->toInteger(), scanner.getCurrent()->toInteger()).calcDays_to_earn_goal_coins()) ; skip ); } class SocialGame { attribute daily_coin : int := 0; attribute weekly_coin : int := 0; attribute goal_coin : int := 0; static operation newSocialGame( daily_coin : int, weekly_coin : int, goal_coin : int) : SocialGame pre: true post: true activity: ( var self : SocialGame ; self := createSocialGame(); self.initialise(daily_coin, weekly_coin,goal_coin); return self ); operation initialise( daily_coin : int, weekly_coin : int, goal_coin : int) : void pre: true post: true activity: ( self.daily_coin := daily_coin ; self.weekly_coin := weekly_coin ; self.goal_coin := goal_coin ); operation calcDays_to_earn_goal_coins() : int pre: true post: true activity: ( var remain_coin : int ; remain_coin := goal_coin ; var passed_days : int ; passed_days := 0 ; while (true) do ( passed_days := passed_days+(1) ; remain_coin := remain_coin-(daily_coin) ; if (passed_days mod 7 = 0) then ( remain_coin := remain_coin-(weekly_coin) ) else skip ; if (remain_coin <= 0) then ( return passed_days ) else skip ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.BufferedReader ; import java.io.InputStreamReader ; class Main { public static void main(String[] args)throws Exception { Integer numWeekday=0 ; Integer result=0 ; Integer total=0 ; try(BufferedReader reader=new BufferedReader(new InputStreamReader(System.in))){ String[] data=reader.readLine().split(" "); Integer a=Integer.parseInt(data[0]); Integer b=Integer.parseInt(data[1]); Integer c=Integer.parseInt(data[2]); while(totalsplit(" ") ; var a : int ; a := (data[0+1])->toInteger() ; var b : int ; b := (data[1+1])->toInteger() ; var c : int ; c := (data[2+1])->toInteger() ; while (total < c) do ( result := result+(1) ; numWeekday := (numWeekday + 1) mod 7 ; total := total+(a) ; if (numWeekday = 0) then ( total := total+(b) ) else skip ) ; OclFile["System.out"].println(result) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class Main { public static void main(String[] args){ int sum,getCoin,getBonus ; int getSum=0,count=0 ; Scanner scan=new Scanner(System.in); getCoin=scan.nextInt(); getBonus=scan.nextInt(); sum=scan.nextInt(); for(int i=0 ; getSumtoInteger() ; getBonus := scan.getCurrent()->toInteger() ; sum := scan.getCurrent()->toInteger() ; var i : int ; i := 0 ; while getSum < sum do ( ( count := count + 1 ; getSum := getSum+(getCoin) ; if ((count) mod 7 = 0) then ( getSum := getSum+(getBonus) ) else skip ) ; i := i + 1 ) ; OclFile["System.out"].println(count) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; class Main { public static void main(String[] args){ try(Scanner sc=new Scanner(System.in)){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int cpw=b+7*a ; int ws=c/cpw ; int rc=c-cpw*ws ; int ds=rc/a ; int rm=rc-a*ds ; if(rm>0){ ds++; } int days=ws*7+ds ; if(b>0 && ds>7){ int wd=(ws+1)*7 ; if(days>wd){ days=wd ; } } System.out.println(String.format("%d",days)); } } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( try ( var sc : OclFile := OclFile.newOclFile_Read(OclFile["System.in"]) ; ( var a : int ; a := sc.getCurrent()->toInteger() ; var b : int ; b := sc.getCurrent()->toInteger() ; var c : int ; c := sc.getCurrent()->toInteger() ; var cpw : int ; cpw := b + 7 * a ; var ws : int ; ws := c / cpw ; var rc : int ; rc := c - cpw * ws ; var ds : int ; ds := rc / a ; var rm : int ; rm := rc - a * ds ; if (rm > 0) then ( ds := ds + 1 ) else skip ; var days : int ; days := ws * 7 + ds ; if (b > 0 & ds > 7) then ( var wd : int ; wd := (ws + 1) * 7 ; if (days > wd) then ( days := wd ) else skip ) else skip ; OclFile["System.out"].println(StringLib.format("%d",Sequence{days})) ; )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.lang.Integer ; import java.lang.String ; import java.io.*; public class Main { public static void main(String args[])throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String s=new String(in.readLine()); String[] li=s.split("+"); int A=Integer.parseInt(li[0]); int B=Integer.parseInt(li[1]); int C=Integer.parseInt(li[2]); int i=0,j=7 ; while((A*7+B)*(i+1)=C)j--; System.out.println(i*7+j); } } ------------------------------------------------------------ OCL File: --------- class Main { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var in : OclFile ; in := OclFile.newOclFile_Read(OclFile.newOclFile_Read(OclFile["System.in"])) ; var s : String ; s := StringLib.newString(in.readLine()) ; var li : Sequence(String) ; li := s->split("+") ; var A : int ; A := (li[0+1])->toInteger() ; var B : int ; B := (li[1+1])->toInteger() ; var C : int ; C := (li[2+1])->toInteger() ; var i : int ; i := 0 ; var j : int ; j := 7 ; while ((A * 7 + B) * (i + 1) < C) do i := i + 1 ; ; while ((A * 7 + B) * i + A * (j - 1) >= C) do j := j - 1 ; ; OclFile["System.out"].println(i * 7 + j) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.io.*; class GFG { static float trianglearea(float r){ if(r<0)return-1 ; return r*r ; } public static void main(String[] args){ float r=5 ; System.out.println(trianglearea(r)); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation trianglearea( r : double) : double pre: true post: true activity: ( if (r < 0) then return -1 else skip ; return r * r ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var r : double ; r := 5 ; OclFile["System.out"].println(trianglearea(r)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static void solve(int n){ double a=n/2 ; if(n % 2!=0){ System.out.println((Math.ceil(a)-1)+" "+(Math.floor(a)+1)); } else { if((int)(a)% 2==0){ System.out.println((Math.ceil(a)-1)+" "+(Math.floor(a)+1)); } else { System.out.println((Math.ceil(a)-2)+" "+(Math.floor(a)+2)); } } } public static void main(String[] args){ int n=34 ; solve(n); } } ------------------------------------------------------------ OCL File: --------- class GFG { static operation solve( n : int) : void pre: true post: true activity: ( var a : double ; a := n / 2 ; if (n mod 2 /= 0) then ( OclFile["System.out"].println(((a)->ceil() - 1) + " " + ((a)->floor() + 1)) ) else ( if ((a)->oclAsType(int) mod 2 = 0) then ( OclFile["System.out"].println(((a)->ceil() - 1) + " " + ((a)->floor() + 1)) ) else ( OclFile["System.out"].println(((a)->ceil() - 2) + " " + ((a)->floor() + 2)) ) ) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var n : int ; n := 34 ; execute solve(n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class B1220 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); long arr[][]=new long[n][n]; for(int i=0 ; itoInteger() ; var arr : Sequence(Sequence(long)) ; arr := Integer.subrange(1,n)->collect(Integer.subrange(1,n)->collect(0)) ; var i : int ; i := 0 ; while i < n do ( ( var j : int ; j := 0 ; while j < n do ( ( arr[i+1][j+1] := in.getCurrent()->toLong() ) ; j := j + 1 ) ) ; i := i + 1 ) ; var zeroIndex : long ; zeroIndex := (((arr[0+1][1+1] * arr[0+1][2+1])->oclAsType(double) / arr[1+1][2+1]))->sqrt()->oclAsType(long) ; OclFile["System.out"].print(zeroIndex + " ") ; var i : int ; i := 1 ; while i < n do ( ( OclFile["System.out"].print(arr[0+1][i+1] / zeroIndex + " ") ) ; i := i + 1 ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- public final class p429 implements EulerSolution { public static void main(String[] args){ System.out.println(new p429().run()); } private static final int LIMIT=Library.pow(10,8); private static final int MODULUS=1000000009 ; public String run(){ int[] primes=Library.listPrimes(LIMIT); long sum=1 ; for(int p : primes){ int power=countFactors(LIMIT,p); sum*=1+Library.powMod(p,power*2,MODULUS); sum %=MODULUS ; } return Long.toString(sum); } private static int countFactors(int n,int p){ if(n==0)return 0 ; else return n/p+countFactors(n/p,p); } } ------------------------------------------------------------ OCL File: --------- class p429 implements EulerSolution { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( OclFile["System.out"].println(p429.newp429().run()) ); static attribute LIMIT : int := Library.pow(10, 8); static attribute MODULUS : int := 1000000009; operation run() : String pre: true post: true activity: ( var primes : Sequence(int) ; primes := Library.listPrimes(LIMIT) ; var sum : long ; sum := 1 ; for (p : primes) do ( ( var power : int ; power := countFactors(LIMIT, p) ; sum := sum*(1 + Library.powMod(p, power * 2, MODULUS)) ; sum := sum mod MODULUS ) ) ; return ((sum) + "") ); static operation countFactors( n : int, p : int) : int pre: true post: true activity: ( if (n = 0) then return 0 else return n / p + countFactors(n / p, p) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.Scanner ; public class cf1005B { public static void main(String[] args){ Scanner scan=new Scanner(System.in); String str1=scan.next(); String str2=scan.next(); int in1=str1.length()-1 ; int in2=str2.length()-1 ; int cntKeep=0 ; while(in1>=0 && in2>=0){ if(str1.charAt(in1)==str2.charAt(in2)){ cntKeep+=2 ; } else { break ; } in1--; in2--; } System.out.println(str1.length()+str2.length()-cntKeep); } } ------------------------------------------------------------ OCL File: --------- class cf1005B { static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var scan : OclFile ; scan := OclFile.newOclFile_Read(OclFile["System.in"]) ; var str1 : String ; str1 := scan.getCurrent() ; var str2 : String ; str2 := scan.getCurrent() ; var in1 : int ; in1 := str1->size() - 1 ; var in2 : int ; in2 := str2->size() - 1 ; var cntKeep : int ; cntKeep := 0 ; while (in1 >= 0 & in2 >= 0) do ( if (str1->at(in1+1) = str2->at(in2+1)) then ( cntKeep := cntKeep+(2) ) else ( break ) ; in1 := in1 - 1 ; in2 := in2 - 1 ) ; OclFile["System.out"].println(str1->size() + str2->size() - cntKeep) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Main { static StringBuilder sb ; public static void main(String[] args){ Scanner sc=new Scanner(System.in); sb=new StringBuilder(); long a=sc.nextLong(); long b=sc.nextLong(); sb.append(to32BitBinaryString(a & b)).append("\n"); sb.append(to32BitBinaryString(a | b)).append("\n"); sb.append(to32BitBinaryString(a ^ b)).append("\n"); PrintWriter out=new PrintWriter(System.out); out.print(sb); out.flush(); sc.close(); } public static String to32BitBinaryString(long l){ String s=String.format("%32s",Long.toBinaryString(l)).replace(" ","0"); return s.substring(s.length()-32,s.length()); } } ------------------------------------------------------------ OCL File: --------- class Main { static attribute sb : String; static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var sc : OclFile ; sc := OclFile.newOclFile_Read(OclFile["System.in"]) ; sb := StringLib.newString() ; var a : long ; a := sc.getCurrent()->toLong() ; var b : long ; b := sc.getCurrent()->toLong() ; sb := sb + StringLib.newString(to32BitBinaryString(MathLib.bitwiseAnd(a,b))) + StringLib.newString("\n") ; sb := sb + StringLib.newString(to32BitBinaryString(MathLib.bitwiseOr(a,b))) + StringLib.newString("\n") ; sb := sb + StringLib.newString(to32BitBinaryString(MathLib.bitwiseXor(a,b))) + StringLib.newString("\n") ; var out : OclFile ; out := OclFile.newOclFile_Write(OclFile["System.out"]) ; skip ; skip ; skip ; ); static operation to32BitBinaryString( l : long) : String pre: true post: true activity: ( var s : String ; s := StringLib.format("%32s",Sequence{(MathLib.decimal2binary(l) + "")}).replace(" ", "0") ; return s.subrange(s->size() - 32+1,s->size()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- class GFG { public static double maxAverageOfPath(int cost[][],int N){ int dp[][]=new int[N+1][N+1]; dp[0][0]=cost[0][0]; for(int i=1 ; icollect(Integer.subrange(1,N + 1)->collect(0)) ; dp[0+1][0+1] := cost[0+1][0+1] ; var i : int ; i := 1 ; while i < N do ( dp[i+1][0+1] := dp[i - 1+1][0+1] + cost[i+1][0+1] ; ; i := i + 1 ) ; var j : int ; j := 1 ; while j < N do ( dp[0+1][j+1] := dp[0+1][j - 1+1] + cost[0+1][j+1] ; ; j := j + 1 ) ; var i : int ; i := 1 ; while i < N do ( var j : int ; j := 1 ; while j < N 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] ; ; j := j + 1 ) ; ; i := i + 1 ) ; return dp[N - 1+1][N - 1+1]->oclAsType(double) / (2 * N - 1) ); static operation main( args : Sequence(String)) : void pre: true post: true activity: ( var cost : Sequence(Sequence(int)) ; cost := Sequence{Sequence{1,2,3},Sequence{6,5,4},Sequence{7,3,9}} ; OclFile["System.out"].println(maxAverageOfPath(cost, 3)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Java Program: ------------- import java.util.*; import java.io.*; public class Train { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=1 ; while(t-->0){ String str[]=br.readLine().trim().split(" "); int n=Integer.parseInt(str[0]); int m=Integer.parseInt(str[1]); int k=Integer.parseInt(str[2]); boolean tohead=false ; str=br.readLine().trim().split(" "); if(str[1] .equals("head"))tohead=true ; else tohead=false ; char a[]=br.readLine().trim().toCharArray(); int time=a.length ; for(int i=0 ; i