src
stringlengths
95
64.6k
complexity
stringclasses
7 values
problem
stringclasses
256 values
from
stringclasses
1 value
import java.io.*; import java.util.*; import static java.util.Arrays.*; public class E implements Runnable { public static void main(String[] args) throws IOException { new Thread(null, new E(), "", 1 << 20).start(); } BufferedReader input; PrintWriter out; String file = "input"...
np
16_E. Fish
CODEFORCES
import java.util.Scanner; /** * Created by Gantushig on 2/18/2016. */ public class A { public static void main(String[] args) { Scanner input = new Scanner(System.in); long n = input.nextLong(); System.out.println("25"); } }
constant
630_A. Again Twenty Five!
CODEFORCES
import javax.crypto.AEADBadTagException; 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...
logn
713_B. Searching Rectangles
CODEFORCES
import java.io.*; import java.awt.geom.Point2D; import java.text.*; import java.math.*; import java.util.*; public class Main implements Runnable { final String filename=""; public void solve() throws Exception { int n = iread(), k = iread(); boolean[] f = new boolean[10000]; ...
linear
17_A. Noldbach problem
CODEFORCES
import java.util.Scanner; public class composite { public static void main(String[] args) { int b; Scanner s3=new Scanner(System.in); b=s3.nextInt(); if(b%2==0) { b=b-4; System.out.println(4+" "+b); } else ...
constant
472_A. Design Tutorial: Learn from Math
CODEFORCES
import java.util.*; public class test { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int t=in.nextInt(); House[] houses=new House[n]; for(int i=0;i<n;i++) { houses[i]=new House(i...
nlogn
15_A. Cottage Village
CODEFORCES
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; public class _v14 { public static void main(String args[]){ PrintWriter out = new PrintWriter(System.out); Reader in = new Reader(); long k = in.nextLong(); ...
logn
1177_B. Digits Sequence (Hard Edition)
CODEFORCES
import java.io.*; import java.util.*; public class Main implements Runnable { public void solution() throws IOException { int n = in.nextInt(); int[] a = new int[n]; int min = Integer.MAX_VALUE; for (int i = 0; i < n; ++i) { a[i] = in.nextInt(); if (a[i] < min) { min = a[i]; } } int res = Int...
nlogn
22_A. Second Order Statistics
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class A { private void solve() throws IOException { int n = nextInt(); int[] a = new int[n]; for (int i = 0; i < ...
nlogn
160_A. Twins
CODEFORCES
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner s = new Scanner(System.in); int len = s.nextInt(); s.nextLine(); String l = s.nextLine(); char[] ca = l.toCharArray(); int h = 0; for (char c : ca) h += A(...
linear
46_C. Hamsters and Tigers
CODEFORCES
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 C { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out ...
logn
817_C. Really Big Numbers
CODEFORCES
import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int distinct = sc.nextInt(); HashMap<Integer, Integer> set = new HashMap<Integer, Intege...
linear
224_B. Array
CODEFORCES
//Edwin Lunando template for online algorithm contest import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.StringTokenizer; public class Main { // class node implements Comparabl...
nlogn
160_A. Twins
CODEFORCES
import java.util.*; import java.math.*; /** * * @author Izhari Ishak Aksa */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Hashtable<Integer, Integer> hi = new Hashtable<Integer, Integer>(); for (int i = 0;...
nlogn
22_A. Second Order Statistics
CODEFORCES
import java.io.*; import java.util.*; public class A { public static boolean ok(int []x,int d,int X) { for(int i=0;i<x.length;i++) if(Math.abs(x[i]-X)<d) return false; return true; } public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); PrintWriter pw=new Pr...
linear
1004_A. Sonya and Hotels
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class...
quadratic
909_C. Python Indentation
CODEFORCES
import java.util.Arrays; import java.util.Scanner; public class LookingForOrder { public static void main(String[] args) { Scanner in = new Scanner(System.in); int bx = in.nextInt(); int by = in.nextInt(); in.nextLine(); int n = in.nextInt(); int[][] objects = new in...
np
8_C. Looking for Order
CODEFORCES
import java.util.*; import java.io.*; import java.awt.Point; import static java.lang.Math.*; public class CF220A { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); Str...
nlogn
220_A. Little Elephant and Problem
CODEFORCES
import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; public class A { /** * @param args */ public static void main(String[] args) { Scanner s = new Scanner(new InputStreamReader(System.in)); int n = s.nextInt(); int [] ar = new int[n]; for (int i = 0; i < n ; i++) { ...
nlogn
22_A. Second Order Statistics
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class C { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.r...
nlogn
135_A. Replacement
CODEFORCES
import java.util.*; import java.lang.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int numSupply = sc.nextInt(); int dev = sc.nextInt(); int socket = sc.nextInt(); int[] sockInSu = new int...
nlogn
257_A. Sockets
CODEFORCES
import java.util.*; import java.io.*; public class Main implements Runnable { public void solve() throws IOException { int N = nextInt(); int M = nextInt(); int B = nextInt(); int[][] burn = new int[B][2]; for(int i = 0; i < B; i++)...
cubic
35_C. Fire Again
CODEFORCES
import java.util.Scanner; //import java.util.Scanner; public class SingleWildcard { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input =new Scanner(System.in); int a = input.nextInt(); int b = input.nextInt(); char[] s1 =new char[a]; s1 = input.next().toCharArr...
linear
1023_A. Single Wildcard Pattern Matching
CODEFORCES
import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Double.parseDouble; import static java.lang.String.*; public class Main { public static void main(String[] args) thro...
constant
235_A. LCM Challenge
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; import java.io.FileNotFoundE...
quadratic
1209_A. Paint the Numbers
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
logn
817_C. Really Big Numbers
CODEFORCES
import java.io.*; import java.math.*; import java.util.*; public class Solution { static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws Exception{ StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); in.nextToken(); int ...
linear
46_C. Hamsters and Tigers
CODEFORCES
import org.omg.PortableServer.AdapterActivator; import java.io.*; import java.lang.reflect.Array; import java.net.CookieHandler; import java.util.*; import java.math.*; import java.lang.*; import java.util.concurrent.LinkedBlockingDeque; import static java.lang.Math.*; public class TaskA implements Runnable { lo...
nlogn
996_B. World Cup
CODEFORCES
import java.util.*; import java.io.*; public class ProblemD { static int mod = (int) (1e9+7); static InputReader in; static PrintWriter out; static void solve() { in = new InputReader(System.in); out = new PrintWriter(System.out); int n = in.nextIn...
quadratic
908_C. New Year and Curling
CODEFORCES
import java.util.Scanner; public class D { public static void main(String[] args) { Scanner in = new Scanner(System.in); double a = in.nextDouble(); double v = in.nextDouble(); double l = in.nextDouble(); double d = in.nextDouble(); double w = in.nextDouble(); ...
constant
5_D. Follow Traffic Rules
CODEFORCES
import java.util.*; public class Main { public static void main(String[] args) { Main iq = new Main(); Scanner sc = new Scanner(System.in); int n; n = sc.nextInt(); int[] naturalNumbers = new int[n]; for (int i = 0; i < naturalNumbers.length; i++) { natur...
linear
25_A. IQ test
CODEFORCES
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; public class B { static Set<Integer> A; static Set<Integer> B; static TreeSet<Integer> ts; static int a; static int b; static boolean noAns...
linear
468_B. Two Sets
CODEFORCES
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may ...
nlogn
527_C. Glass Carving
CODEFORCES
import java.io.*; import java.util.*; public class Main { public void solve() { int n = ni(); int a = ni(); int b = ni(); long ans = 0; HashMap<Long, Long> m = new HashMap<>(); HashMap<String, Long> s = new HashMap<>(); for (int i = 0; i < n; i++) { ...
linear
975_D. Ghosts
CODEFORCES
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) {new Main().run();} FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); void run(){ out.println(work()); out.flush(); } long mod=1000000007; long gcd(long a,long b) { return b==0?...
np
1238_E. Keyboard Purchase
CODEFORCES
import java.util.*; import java.io.*; public class Main{ BufferedReader in; StringTokenizer str = null; PrintWriter out; private String next() throws Exception{ if (str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } ...
np
8_C. Looking for Order
CODEFORCES
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int xs = sc.nextInt(); int ys = sc.nextInt(); int n = sc.nextInt(); int[]x = new int[n], y = new int[n]; for (int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); ...
np
8_C. Looking for Order
CODEFORCES
import java.io.*; import java.util.*; public class Main { InputStream is; PrintWriter out; String INPUT = ""; long MAX = 100000L, MOD = 1000000007L, INF = (long) 1e18; boolean isValid(int x, int y, int n, int m){ return x>=0 && y>=0 && x<n && y<m; } void solve(int TC)...
cubic
35_C. Fire Again
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.TreeMap; import java.util.Map; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at t...
nlogn
527_C. Glass Carving
CODEFORCES
import java.io.*; import java.util.*; public class A992{ long mod = 1000000007L; private void solve() throws Exception { long x = nextLong(); long k = nextLong(); if(x == 0) { out.println(0); return; } x = x%mod; long res = (((x*pow(2,k+1))%mod + (mod-pow(2,k))%mod)%mod+1)%mod; out.printl...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
import java.util.Arrays; import java.util.Scanner; public class E { static int n; static int m; static int[][][] DP; static int[] dx = { 0, 0, 1, -1 }; static int[] dy = { 1, -1, 0, 0 }; static int inf = 1000000; public static int get(int x, int current, int last) { if (x == n) { ...
np
112_E. Petya and Spiders
CODEFORCES
//never leave a uncompleted question in this file, always remove the code after submitting it. import java.io.*; import java.util.*; public class run{ public static void main(String args[]){ Scanner in = new Scanner(System.in); long n = in.nextInt(); long k = in.nextInt(); long ans...
logn
1195_B. Sport Mafia
CODEFORCES
import java.util.*; import java.io.*; public class Solution1{ static class Node{ int start,end; Node(int start, int end){ this.start=start; this.end=end; } public String toString(){ return start+" "+end; } } public static void sameSumBlock(int a[],int n){ HashMap<Long,ArrayList<Node>> map=new ...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
import java.io.*; import java.util.*; public class Main { static class Scanner { StreamTokenizer in; boolean forceMode = false; Scanner(InputStream is, String codePage, boolean forceMode) { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is))); if (!forceMode)...
nlogn
220_A. Little Elephant and Problem
CODEFORCES
/** * Created by Alyssa Herbst on 9/14/19 9:05 AM. */ import java.util.*; import java.io.*; import static java.lang.Math.*; public class B { static StringBuilder sb; static int N; static int[] A; static boolean[] B; public static void main(String[] args) { FastScanner sc = new FastScann...
quadratic
1209_A. Paint the Numbers
CODEFORCES
import java.io.PrintWriter; import java.util.Scanner; public class Problem2 implements Runnable { public void run() { Scanner scanner = new Scanner(System.in); PrintWriter writer = new PrintWriter(System.out); long n = scanner.nextLong(); long k = scanner.nextLong(); long ...
logn
287_B. Pipeline
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Vector; import java.util.HashMap; import java.util.InputMismatchException; import java.io.IOException; import java.util.Stack; import java.io.InputStream; /** * Built using CHelper plug-in...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
import java.util.*; public class Main { static class Node implements Comparable<Node>{ public int l,r; public long s; Node(int l,int r,long s){ this.l=l; this.r=r; this.s=s; } public int compareTo(Node o) { if(o.s==s){ ...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while ( sc.hasNextInt() ) { int n = sc.nextInt(); long m = sc.nextInt(); boolean edge[][] = new boolean[n][n]; long dp[][] = new long[1<<n][n]; for ( long i = 1 ; i<=m ; ++i ) { ...
np
11_D. A Simple Task
CODEFORCES
import java.util.*; public class Dj { public static long run(long l, long r) { if(l == r) { return 0; } long[] sq2 = new long[62]; sq2[0] = 1; for(int i = 1; i < 62; i++) sq2[i] = sq2[i-1]*2; //System.out.println(sq2[61]); for(int i = sq2.length - 1; i >= 0; i--) { //log("L = " + l + " R = " +...
logn
276_D. Little Girl and Maximum XOR
CODEFORCES
import java.util.Arrays; import java.util.Scanner; import static java.lang.Math.*; public class a111 { public static void debug(Object... obs) { System.out.println(Arrays.deepToString(obs)); } public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); ...
nlogn
160_A. Twins
CODEFORCES
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; /* spar5h */ public class cf1 implements Runnable{ public void run() { InputReader s = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int t = 1; while(t-- > 0) { int n = s.nextInt(), m ...
linear
1010_A. Fly
CODEFORCES
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; /** * Built using CHelper plug-in * Actual soluti...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
import java.io.*; import java.util.*; import java.math.*; public class p481a { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long l = sc.nextLong(); long r = sc.nextLong(); if (r - l <= 1) { System.out.println("-1"); } else if (r -...
constant
483_A. Counterexample
CODEFORCES
import java.io.*; import java.util.*; public class E { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) throws IOException { readInput(); out.clo...
cubic
1515_E. Phoenix and Computers
CODEFORCES
import java.util.*; public class cf112e { static int n,m,s; static int[][][] memo; public static void main(String[] args) { Scanner in = new Scanner(System.in); n = in.nextInt(); m = in.nextInt(); if(n > m) { int tmp = n; n = m; m = tmp; ...
np
111_C. Petya and Spiders
CODEFORCES
import java.util.*; import static java.lang.Math.*; public class C { public static void main(String[] args){ Scanner sc = new Scanner(System.in); hx = sc.nextInt(); hy = sc.nextInt(); N = sc.nextInt(); X = new int[N]; Y = new int[N]; for(int i = 0; i < N;i++){ X[i] = sc.nextInt(); Y[i] = sc.nextIn...
np
8_C. Looking for Order
CODEFORCES
import java.io.*; import java.math.*; import java.util.*; public class Main{ public static void main(String[] args){ InputReader reader = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = reader.nextInt(); int r = reader.nextInt(); int[] x = new int[n]; double[]...
quadratic
908_C. New Year and Curling
CODEFORCES
import java.io.*; import java.util.*; public class Main implements Runnable { private BufferedReader in; private PrintWriter out; private StringTokenizer st; private void eat(String line) { st = new StringTokenizer(line); } private String next() throws IOException { ...
nlogn
15_A. Cottage Village
CODEFORCES
import java.io.*; import java.util.*; public class j { public static void main(String a[])throws IOException { BufferedReader b = new BufferedReader(new FileReader("input.txt")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); int l=0,x2=0,x=0,y1=0,y=0,max=-1,min=100000,x1=0,n=0,j=0...
cubic
35_C. Fire Again
CODEFORCES
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc =new Scanner(System.in); long r,l; r = sc.nextLong(); l = sc.nextLong(); if ((r+2)>l) { System.out.print("-1"); return;} if ((r % 2) == 0) { Sys...
constant
483_A. Counterexample
CODEFORCES
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class C { static StringTokenizer st; static BufferedReader br; static PrintWriter pw; ...
logn
817_C. Really Big Numbers
CODEFORCES
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); InputReader in = new InputReader(inpu...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
// practice with rainboy import java.io.*; import java.util.*; public class CF256B extends PrintWriter { CF256B() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF256B o = new CF256B(); o.main(); o.flush(); } long count(int n, int x, int y, int r) { lo...
logn
256_B. Mr. Bender and Square
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jenish */ public class Ma...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
import java.util.*; import java.io.*; public class C { 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.readLi...
cubic
1523_C. Compression and Expansion
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class A { FastScanner in; PrintWriter out; public void run() { try { in = new FastScanner(new InputStreamReader(System.in)); out = new...
constant
483_A. Counterexample
CODEFORCES
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; import java.util.Random; import j...
np
1242_C. Sum Balance
CODEFORCES
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class R035CRetry { public void debug(Object... objects) { System.err.println(Arrays.deepToString(objects)); } pu...
cubic
35_C. Fire Again
CODEFORCES
import java.util.*; import java.math.*; public class Split { 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]; int d[] = new int[n-1]; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); if(i>0) d[i-1] = a[i-1] -...
nlogn
1197_C. Array Splitting
CODEFORCES
import java.math.*; import java.util.*; import java.io.*; public class Main { void solve(){ int n=ni(); int c1[]=new int[9]; int c2[]=new int[9]; for(int i=0;i<n;i++){ String s=ns(); if(s.equals("M")) c1[0]++; else if(s.equals("S")) c1[1]++; ...
linear
1000_A. Codehorses T-shirts
CODEFORCES
import java.util.*; import java.io.*; public class C{ static PrintWriter out; static InputReader in; public static void main(String args[]){ out = new PrintWriter(System.out); in = new InputReader(); new C(); out.flush(); out.close(); } C(){ int a = solve();...
linear
1190_C. Tokitsukaze and Duel
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class CFC { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; private static final long MOD = 1000L * 1000L * 1000L + 7; private...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author wilso */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.i...
cubic
1523_C. Compression and Expansion
CODEFORCES
import java.util.*; public class cf16e { static int n; static double[][] prob; static double[] memo; public static void main(String[] args) { Scanner in = new Scanner(System.in); n = in.nextInt(); prob = new double[n][n]; memo = new double[1<<n]; for(int i=0; i<n; i++) for(int j=0; j<n; j++) prob[...
np
16_E. Fish
CODEFORCES
import java.util.*; public class Q3a { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); String s = in.nextLine(); HashMap<Integer, Integer> seen = new HashMap<>(); for (int i = 0; i < n; i++) { Character c = s.charAt(i); int ci = (...
linear
701_C. They Are Everywhere
CODEFORCES
import java.util.Scanner; public class New_Year_and_Curling { static final double E = 0.00001; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int r = sc.nextInt(); double[] y = new double[n]; ...
quadratic
908_C. New Year and Curling
CODEFORCES
import java.util.Scanner; public class A_YoureGivenAString { //1:11 public static void main(String[] args) { Scanner s = new Scanner(System.in); String str = s.nextLine(); for (int l = str.length()-1; l >= 1; l--) { for (int i = 0; i < str.length()-l+1; i++)...
cubic
23_A. You're Given a String...
CODEFORCES
import java.io.*; import java.util.*; public class A { public static void main(String[] args) throws Exception { new A().solve(); } void solve() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); ...
constant
199_A. Hexadecimal's theorem
CODEFORCES
//package round428; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class E2 { InputStream is; PrintWriter out; String INPUT = ""; // String INPUT = ""; void solve() ...
np
839_E. Mother of Dragons
CODEFORCES
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Saransh */ import java.io.*; import java.util.*; import java.math.*; import java.lang.*; public class Main { /** * @param args the command line arguments */ public static void mai...
constant
84_A. Toy Army
CODEFORCES
import java.util.*; import java.lang.*; import java.io.*; public class Ideone { static long ans=0; public static void Stepgcd(long a,long b) { if (b!=0) {ans+=(a/b);Stepgcd(b,a%b);} } public static void main (String[] args) throws java.lang.Exception { Scanner in=new Scanner(System.in); long a=in.nextLon...
constant
343_A. Rational Resistance
CODEFORCES
import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.FileOutputStream; import java.util.ArrayDeque; import java.io.PrintWriter; import java.io.FileInputStream; import java.util.StringTokenizer; import java.io.InputStream; /** * Built ...
cubic
35_C. Fire Again
CODEFORCES
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while ( sc.hasNextInt() ) { int n = sc.nextInt(); long m = sc.nextInt(); boolean edge[][] = new boolean[n][n]; long dp[][] = new long[1<<n][n]; for ( long i = 1 ; i<=m ; ++i ) { ...
np
11_D. A Simple Task
CODEFORCES
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Edu_46A { public static void main(String[] args) throws IOException { BufferedRea...
linear
1000_A. Codehorses T-shirts
CODEFORCES
import java.util.*; import java.io.*; public class C { public static void main(String[] args) throws Exception { final int fuck = 2001; Scanner in = new Scanner(new File("input.txt")); PrintWriter out = new PrintWriter(new File("output.txt")); int n = in.nextInt(), m = in.nextInt(); int[] D = new int[ fuck...
cubic
35_C. Fire Again
CODEFORCES
import java.io.*; import java.util.*; public class FireAgain { public static void main(String[] args) throws IOException { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream("output.txt")); BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); String s[]...
cubic
35_C. Fire Again
CODEFORCES
// Don't place your source in a package 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; // Please name your class Main public class Main { static FastScanner fs=new FastScanner(); stat...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
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(); double [] left = new double[n]; double [] right = new double[n]; for (int i = 0; i<n; i++){ int ...
nlogn
15_A. Cottage Village
CODEFORCES
import java.io.*; import java.math.BigInteger; import java.util.InputMismatchException; import java.util.PriorityQueue; import java.util.StringTokenizer; public class D { static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new O...
quadratic
1179_B. Tolik and His Uncle
CODEFORCES
import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; public class TwoSets<V> { private static int n; private static int a; private static int b; private static List<Node<Integer>> nodes = new Linke...
linear
468_B. Two Sets
CODEFORCES
import java.util.Scanner; public class B_14 { @SuppressWarnings("resource") public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); for(int test = 0; test < t; test++){ int n = input.nextInt(); if(n % 2 == 0){ if(Math.sqrt(n / 2) == (int)(Math.sqrt(...
linear
1515_B. Phoenix and Puzzle
CODEFORCES
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); if (((n % 4) == 0) || ((n % 7) == 0) || ((n % 44) == 0) || ((n % 47) == 0) || ((n % 74) == 0) || ((n % 77) == 0) || ((n % 444) == 0) || ((n % 447) == 0) || ((n % 474...
constant
122_A. Lucky Division
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
import java.util.Arrays; import java.util.Scanner; public class A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] A = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { A[i] = in.nextInt(); ...
nlogn
160_A. Twins
CODEFORCES
import java.io.*; import java.util.Arrays; public class Main{ public static void main(String[] args) throws Exception { int n = nextInt(); int a = nextInt(); int b = nextInt(); int[] tasks = new int[n]; for(int i = 0; i < n; i++){ tasks[i] = nextInt(); } Arrays.sort(tasks); exit(tasks[b] - task...
nlogn
169_A. Chores
CODEFORCES
import java.util.Scanner; public class TaskD { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = s.nextInt(); } int m = s.nextInt(); int inv = 0; // count inversions for (int i = 0; i < n;...
quadratic
911_D. Inversion Counting
CODEFORCES
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main { static int n, m, k; static int i...
cubic
35_C. Fire Again
CODEFORCES
import java.io.BufferedReader; import static java.lang.Math.*; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class CodeforcesA implements Runnable { public static final String taskname = "A"; Buffer...
nlogn
15_A. Cottage Village
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.ArrayList; public class C{ static long s; public static void main(String[] args)throws IOException { Reader.init(Sys...
logn
817_C. Really Big Numbers
CODEFORCES