src
stringlengths
95
64.6k
complexity
stringclasses
7 values
problem
stringclasses
256 values
from
stringclasses
1 value
import java.io.*; import java.util.*; import java.math.*; public class Main { public static long gcd(long a, long b) { return b==0? a:gcd(b, a%b); } public static long lcm(long a, long b, long c) { long d=a/gcd(a, b)*b; return c/gcd(c, d)*d; } public static long max(...
constant
235_A. LCM Challenge
CODEFORCES
import java.io.*; import java.util.Scanner; import java.util.TreeMap; /** * * @author camoroh13 */ public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); // Scanner sc = new Scanner(new FileInputStream("/home/camoroh13/NetBeansPro...
nlogn
15_A. Cottage Village
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 * * @author an...
quadratic
909_C. Python Indentation
CODEFORCES
import java.io.*; import java.util.*; public class A4 { public BufferedReader input; public PrintWriter output; public StringTokenizer stoken = new StringTokenizer(""); public static void main(String[] args) throws IOException { new A4(); } A4() throws IOException { input = n...
nlogn
1075_C. The Tower is Going Home
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * @author Don Li */ public class TwoSquares { int INF = 1000; void solve() { int[][] s1 = new int[4][2]; for (int i = 0; i <...
constant
994_C. Two Squares
CODEFORCES
import java.util.Scanner; public class Solution { public static void main(String[] args) { // Write your code here Scanner s=new Scanner(System.in); int n=s.nextInt(); char[] seq=new char[n]; for(int i=0;i<n;i++){ seq[i]=s.next().charAt(0); } long mod=(long)Math.pow(10,9)+7; long[][...
quadratic
909_C. Python Indentation
CODEFORCES
import java.util.Scanner; public class prob1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.next(); int n = s.length(); int i = n-1; CharSequence temp; for(i = n-1; i > 0; i--) for(int j = 0 ; j <= n-i; j++) { temp = s.subSequence(j, i+j); ...
cubic
23_A. You're Given a String...
CODEFORCES
import java.io.*; import java.util.*; import java.text.*; public class FollowTrafficRules { public Scanner in = new Scanner(System.in); public PrintStream out = System.out; public double len, d, w, vmax, a; DecimalFormat fmt = new DecimalFormat("0.0000000000000000"); public void main() { a = in.nextDoubl...
constant
5_D. Follow Traffic Rules
CODEFORCES
import java.util.*; import java.io.*; import java.math.BigInteger; public class D { FastScanner in; PrintWriter out; boolean systemIO = true; public void solve() { int n = in.nextInt(); HashMap<Long, Integer> map = new HashMap(); BigInteger sum = BigInteger.ZERO; BigInteger ans = BigInteger.valueOf(0)...
nlogn
903_D. Almost Difference
CODEFORCES
//package round524; 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 D { InputStream is; PrintWriter out; String INPUT = ""; long I = 4000000000000000007L; voi...
logn
1080_D. Olya and magical square
CODEFORCES
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextLong(); if (n == 1 || n == 2) { System.out.println(n); } else if (n % 2 == 0) { if (n % 3 == 0) Syst...
constant
235_A. LCM Challenge
CODEFORCES
// https://codeforces.com/contest/1185/submission/55800229 (rainboy) import java.io.*; import java.util.*; public class CF1185G2 { static final int MD = 1000000007; static int[][] solve1(int[] aa, int t, int n) { int[][] da = new int[t + 1][n + 1]; da[0][0] = 1; for (int i = 0; i < n; i++) { int a = aa[i]; ...
np
1185_G1. Playlist for Polycarp (easy version)
CODEFORCES
import java.util.*; /*Author LAVLESH*/ public class solution { static long gcd(long a,long b){ if(b==0) return a; else return gcd(b,a%b); } public static void main(String[]args){ Scanner in=new Scanner(System.in); long n=in.nextLong(); long m1=0,m2=0; if(n<3)m1=n; else { if((n&1)==1){ ...
constant
235_A. LCM Challenge
CODEFORCES
import java.io.*; import java.util.*; public class C { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; final int INF = Integer.MAX_VALUE / 2; void solve() throws IOException { int n = nextInt(); int m = nextInt(); if (n > m) { int tmp...
np
111_C. Petya and Spiders
CODEFORCES
import java.io.*; import java.util.*; import java.util.List; public class Main { private static StringTokenizer st; private static BufferedReader br; public static long MOD = 1000000007; public static long tenFive = 100000; public static int INF = 100000; public static void print(Object x) { ...
linear
468_B. Two Sets
CODEFORCES
import java.util.Scanner; public class HammingDistancesSum { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.nextLine(), b = sc.nextLine(); long sum = 0; int frequency[][] = new int[200010][2]; for (int i = 1; i <= b.length(); i++) { for (int j = 0; j < ...
linear
608_B. Hamming Distance Sum
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.InputMismatchException; public class R111_D2_A { public static void main(String[] args) { InputReader in = new InputReader(System.in); ...
nlogn
160_A. Twins
CODEFORCES
import java.io.OutputStream; 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.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparat...
quadratic
1000_A. Codehorses T-shirts
CODEFORCES
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.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author...
quadratic
908_C. New Year and Curling
CODEFORCES
import java.util.*; public class Main { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int size = Integer.parseInt(keyboard.nextLine()); int[] arr = new int[size]; int i = 0; while( size != 0 ) { arr[i] = keyboard.nextInt(); ...
nlogn
22_A. Second Order Statistics
CODEFORCES
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numCh...
linear
1004_A. Sonya and Hotels
CODEFORCES
/* * DA-IICT * Author: Jugal Kalal */ import java.util.*; import java.io.*; import java.math.*; import java.text.DecimalFormat; public class Practice{ static long MOD=(long)Math.pow(10,9)+7; public static void main(String args[]) { new Thread(null, new Runnable() { public void run() { ...
logn
817_C. Really Big Numbers
CODEFORCES
import java.io.*; import java.util.*; public class Main { public static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public InputReader(InputStream...
quadratic
908_C. New Year and Curling
CODEFORCES
/* Author: Anthony Ngene Created: 05/10/2020 - 14:12 */ import java.io.*; import java.util.*; public class F { // checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity void solver() throws IOException { int n = in.intNext(); int[] arr = in....
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
// package CF1141; import java.io.*; import java.util.*; public class CF1141F1 { static FastReader s; static PrintWriter out; static String INPUT = "7\n" + "4 1 2 2 1 5 3\n"; public static void main(String[] args) { long time = System.currentTimeMillis(); boolean oj = Syst...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
import java.util.Scanner; public class LuckyDivision{ public static void main(String [] args){ Scanner input = new Scanner(System.in); int a = input.nextInt(); if(a%4 == 0) System.out.println("YES"); else if(a%7 == 0) System.out.println("YES"); else if(a%47 == 0) System.out.p...
constant
122_A. Lucky Division
CODEFORCES
import java.io.*; import java.util.*; public class A { public static void main(String[] args)throws Throwable { MyScanner sc=new MyScanner(); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); String [] s={"M","L","S","XL","XS","XXL","XXS","XXXL","XXXS"}; int [...
linear
1000_A. Codehorses T-shirts
CODEFORCES
import java.util.*; import java.io.*; import java.math.*; public class Solution { static long n, x, y, c; static boolean can (long len) { BigInteger blen = BigInteger.valueOf(len); //BigInteger sum = blen.multiply(blen.add(BigInteger.ONE)).multiply(blen.shiftLeft(1).add(BigInteger...
logn
256_B. Mr. Bender and Square
CODEFORCES
import java.util.Scanner; public class A { public static final boolean DEBUG = false; Scanner sc; public void debug(Object o) { if (DEBUG) { int ln = Thread.currentThread().getStackTrace()[2].getLineNumber(); String fn = Thread.currentThread().getStackTrace()[2].getFileName(); System.out.println("(" + ...
constant
343_A. Rational Resistance
CODEFORCES
/** * author: derrick20 * created: 3/19/21 11:57 PM */ import java.io.*; import java.util.*; import static java.lang.Math.*; public class E2_SquareFreeDivision2 { static FastScanner sc = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { //...
cubic
1497E2
CODEFORCES
import java.io.*; import java.text.*; import java.math.*; import java.util.*; public class Main { private StreamTokenizer in; private BufferedWriter out; public void solve() throws Exception { int n = nextInt(), m = nextInt(); int[] ss = new int[n]; for (int i=0; i<m; i++) ...
np
11_D. A Simple Task
CODEFORCES
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Iterat...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
import java.math.BigInteger; import java.util.Scanner; public class d { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int[] arr = new int[N]; for(int n=0;n<N;n++){ arr[n] = in.nextInt(); } Wavelet waveyMcWaveFace = new Wavelet(arr); BigInteg...
nlogn
903_D. Almost Difference
CODEFORCES
import java.util.Scanner; public class RationalResistance { static long n = 0; static void R(long a, long b) { n += a / b; a %= b; if (a == 0) { return; } R(b, a); } public static void main(String[] args) { Scanner cin = new Scanner(System.in); long a = cin.nextLong(); long b = cin.nextLong();...
constant
343_A. Rational Resistance
CODEFORCES
import java.util.*; import java.io.*; public class main{ static int max = 5000+1; static FastReader in = new FastReader(); static PrintWriter out = new PrintWriter(System.out); static int N = 18; static int[][] mn1 = new int[N][N]; static int[][] mn2 = new int[N][N]; static int[][] dp = new int[1<<N][N]; sta...
np
1102_F. Elongated Matrix
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOExcept...
np
11_D. A Simple Task
CODEFORCES
import java.math.BigInteger; import java.util.*; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.StringTokenizer; import java.util.TreeSet; public class D { publ...
nlogn
903_D. Almost Difference
CODEFORCES
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.util.TreeSet; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author b...
quadratic
1209_A. Paint the Numbers
CODEFORCES
//package com.company; import java.io.*; import java.util.*; import java.math.*; public class Main { static long TIME_START, TIME_END; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); // Scanner sc = new Scanner(new FileInputStream("Test.in")); ...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
//package codeforces; import java.util.Scanner; public class ex5 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String S [] = new String[3]; int m=0,s=0,p=0; int temp=0; for (int i = 0; i < S.length; i++) { S[i]=scan.next(); if(S[i].indexOf('m')!=-1) m++; if(S[i].indexO...
constant
1191_B. Tokitsukaze and Mahjong
CODEFORCES
import java.util.*; public class Beta17PA { boolean[] isPrime = new boolean[1001]; int[] prime = new int[200]; public static void main(String[] args) { // TODO Auto-generated method stub new Beta17PA().solve(); } public void solve() { Scanner scan = new Scanner(System.in); int n, k; n = scan.nextInt(...
linear
17_A. Noldbach problem
CODEFORCES
import java.io.*; import java.math.*; import java.util.*; public class Village { static Scanner in = new Scanner( new BufferedReader( new InputStreamReader( System.in ) ) ); public static void main( String[] args ) { int n = in.nextInt(), t = 2*in.nextInt(), h[][] = new int[n][2], ans = 2; for( int i = 0; i < ...
nlogn
15_A. Cottage Village
CODEFORCES
import java.util.Arrays; import java.util.Scanner; public class P16E { int n; double [][]prob; double []dp; public P16E() { Scanner sc = new Scanner(System.in); n = sc.nextInt(); prob = new double [n][n]; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j...
np
16_E. Fish
CODEFORCES
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; public class C { public static void main(String[] args) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); // Scanner scan = new Scanner(System.in); PrintWriter out = new P...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
import java.math.*; import java.text.*; import java.util.*; public class Main { public static void main(String args[]) { Scanner sca = new Scanner(System.in); long k,n; long ans; long[] pw = new long[33]; pw[1]=4; pw[0]=1; for(int i=2;i<=31;i++) p...
logn
1080_D. Olya and magical square
CODEFORCES
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class C455C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); ArrayList<Integer> listCount = new ArrayList<Integer>(); listCount.add(1); boolean justf...
quadratic
909_C. Python Indentation
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 { static int n,r,x[]; static double ans[]; public static void main(String args[]) throws IOException { Scanner sc ...
quadratic
908_C. New Year and Curling
CODEFORCES
import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class CF008C { public static void main(String[] args) { Scanner s = new Scanner(System.in); int x = s.nextInt(); int y = s.nextInt(); int n = s.nextInt(); int[] xx...
np
8_C. Looking for Order
CODEFORCES
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public c...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
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(), k = sc.nextInt(), kol = 0, prev; boolean ok; ArrayList<Integer> al = new ArrayList<Integer>...
linear
17_A. Noldbach problem
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...
np
1185_G1. Playlist for Polycarp (easy version)
CODEFORCES
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.Locale;...
nlogn
220_A. Little Elephant and Problem
CODEFORCES
import java.util.*; public class Main { static Scanner cin = new Scanner(System.in); private int xs, ys, n; private int[] x, y; public static void main(String[] args) throws Exception { new Main().run(); } class Item implements Comparable<Item> { int w, h, idx; Ite...
np
8_C. Looking for Order
CODEFORCES
import java.io.BufferedReader; import java.io.PrintWriter; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; import java.util.Arrays; public class Main { static Scanner in = new Scanner(); static PrintWriter out = new PrintWriter(System.out); publ...
constant
1036_A. Function Height
CODEFORCES
import java.util.Scanner; public class p84a { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); System.out.println((n/2)*3); } }
constant
84_A. Toy Army
CODEFORCES
import java.io.*; import java.util.*; public class j { public static void main(String aa[])throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); int i=0,m=0,p=0,n=0,k=0,j=0; String s,r; s=b.readLine(); r=s; n=Integer.parseInt(s); s=s.substring(0,s.length()-2); s+=r.charAt(r.length(...
constant
313_A. Ilya and Bank Account
CODEFORCES
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Set; /** * @author Egor Kulikov (egor@egork.net) * Created on 14.03.2010 */ public class TaskA implements Runna...
cubic
23_A. You're Given a String...
CODEFORCES
import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import java.util.Stack; public class C{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); long mod=1000000007l; int cases=sc.nextInt(); while(cases>0) { ...
cubic
1523_C. Compression and Expansion
CODEFORCES
import java.io.FileNotFoundException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); ...
constant
472_A. Design Tutorial: Learn from Math
CODEFORCES
import java.util.*; import java.io.*; public class Main{ public static void pri(ArrayList<Integer> list) { int len=list.size(); for(int i=0;i<len-1;++i) System.out.print(list.get(i)+"."); System.out.println(list.get(len-1)); } public static void main(String[] args) ...
cubic
1523_C. Compression and Expansion
CODEFORCES
import java.util.*; import java.io.*; public class D { static FastIO f; static long ve[][], he[][]; public static void main(String args[]) throws IOException { f = new FastIO(); int n = f.ni(), m = f.ni(), k = f.ni(), i, j; ve = new long[n-1][]; he = new long[n][]; long[][] ans = new long[n][m], pans...
cubic
1517_D. Explorer Space
CODEFORCES
import javafx.util.Pair; import java.io.*; import java.util.*; public class Beacon8 { public static void main(String[] args) throws IOException { // int[] arr = {1, 3, 7, 18}; // int bIndex = Arrays.binarySearch(arr, 4); // System.out.println(bIndex); Scanner scan = new Scanner(Syst...
nlogn
608_C. Chain Reaction
CODEFORCES
import java.util.Scanner; import java.util.Arrays; public class P166A { public static void main(String[] args) { Scanner myScanner = new Scanner(System.in); int n = myScanner.nextInt(); int k = myScanner.nextInt(); Team[] queue = new Team[n]; for (int i = 0; i < n; i++) { queue[i] = new Team(myScann...
nlogn
166_A. Rank List
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class LookingForOrder { static int n; static int []x,y,memo; static StringBuilder sb; static int distance(int i,int j) { int dx=x[i...
np
8_C. Looking for Order
CODEFORCES
import java.util.*; 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(4 + " " + (n - 4)); } else { System.out.println(9 + " " + (n - 9)); } } }
constant
472_A. Design Tutorial: Learn from Math
CODEFORCES
import java.io.*; import java.util.*; public class pr169D implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer str; public void solve() throws IOException { long l = nextLong(); long r = nextLong(); long x = l ^ r; long i = 1; while (x >= i) i *= 2; out.println(x > i ? x : i -...
logn
276_D. Little Girl and Maximum XOR
CODEFORCES
import java.util.*; import java.lang.*; import java.io.*; public class ER23C { static long s; public static void main (String[] args) throws java.lang.Exception { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); long n = in.nextLong(); ...
logn
817_C. Really Big Numbers
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * * @author Haya */ public class CommentaryBoxes { public static void main(String[] args) { FastReader in = new FastReader(); long n = in.nextLo...
linear
990_A. Commentary Boxes
CODEFORCES
import java.util.*; import java.io.*; public class B { public void solve() throws IOException { int n = nextInt(); int k = nextInt(); int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = nextInt(); } int[] num = new int[n]; Set<Integer> set = new HashSet<Integer>(); int s = -1; int l = -1; f...
linear
224_B. Array
CODEFORCES
import java.util.*; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; public class Main { private void solve() { int n = in.nextInt(); int k = in.nextInt(); final int[] p = new int[n]; final int[] t = new int[n]; for(...
nlogn
166_A. Rank List
CODEFORCES
import java.util.Scanner; public class CodeForces { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int ans = 0; long x = n; x = x*(x+1)/2; while (x!=k) { x-=n; n--; ...
logn
1195_B. Sport Mafia
CODEFORCES
import java.lang.*; import java.math.*; import java.util.*; import java.io.*; public class Main{ class Node implements Comparable<Node>{ int l; int r; public Node(int l,int r){ this.l=l; this.r=r; } public int compareTo(Node c){ int t=Integer.compare(this.r,c.r); if(...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
//package C; import java.io.*; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; public class Fire_Again { static int N; static int M; static int K; private class Pos { public int r; public int c; int last; public Pos(int r,int c, int last...
cubic
35_C. Fire Again
CODEFORCES
import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ public class D { private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; private static long[][][] dp; private static long[][] ff; private static long[][] ss; public stati...
cubic
1517_D. Explorer Space
CODEFORCES
/* Roses are red Memes are neat All my test cases time out Lmao yeet */ import java.util.*; import java.io.*; public class B { public static void main(String args[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st...
logn
1195_B. Sport Mafia
CODEFORCES
import java.io.*; import java.util.*; public class Pr468B { public static void main(String[] args) throws IOException { new Pr468B().run(); } BufferedReader in; PrintWriter out; StringTokenizer st; String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokeniz...
linear
468_B. Two Sets
CODEFORCES
import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; import static java.util.Arrays.sort; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public ...
quadratic
1209_A. Paint the Numbers
CODEFORCES
import java.util.*; public class x { public static void main(String args[]) { Scanner obj=new Scanner(System.in); int n; String d="0"; n=obj.nextInt(); if(n%4==0 || n%7==0 || n%47==0 || n%74==0 || n%447==0 || n%474==0 || n%747==0) d="YES"; else if(n%444==0...
constant
122_A. Lucky Division
CODEFORCES
import java.io.*; import java.util.Scanner; public class T { public static void main(String[] args) throws IOException { T t = new T(); t.run(); t.close(); } private void close() { sc.close(); pw.close(); } BufferedReader reader = new BufferedReade...
constant
472_A. Design Tutorial: Learn from Math
CODEFORCES
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; Outpu...
constant
313_A. Ilya and Bank Account
CODEFORCES
import java.io.*; import java.util.*; import java.util.stream.*; public class ProblemF { private static boolean debug = false; private static int N; private static int[] A; private static void solveProblem(InputStream instr) throws Exception { InputReader sc = new InputReader(instr); ...
quadratic
1141_F2. Same Sum Blocks (Hard)
CODEFORCES
import java.awt.Point; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class Solution15A { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null; BufferedReader in; PrintWriter ou...
nlogn
15_A. Cottage Village
CODEFORCES
import java.io.* ; import java.util.* ; import java.text.* ; import java.math.* ; import static java.lang.Math.min ; import static java.lang.Math.max ; import static java.lang.Math.sqrt ; public class Codeshefcode{ public static void main(String[] args) throws IOException{ Solver Machine = new Solver() ; Machine.S...
quadratic
908_C. New Year and Curling
CODEFORCES
import java.util.*; import java.math.*; // **** E1. Rotate Columns (easy version) **** public class E1 { static char [] in = new char [1000000]; public static void main (String [] arg) throws Throwable { int t = nextInt(); C : for (int ii = 0; ii<t; ++ii) { int n = nextInt(); int m = nextInt(); Pair []...
np
1209_E1. Rotate Columns (easy version)
CODEFORCES
//package sept; import java.io.*; import java.util.*; public class TimePass { InputStream is; PrintWriter out; String INPUT = ""; //boolean codechef=true; // String prodKey = "Av#/lL{OyEKiLR+/Ce%(w]^J65;XZe8FVb]]<931_=80E[BVnU^@4xu*J%KG3,CRqIZrUN~JJ+*6QC*CyBd>'$;>O"onO.bQ%{L}"; boolean codec...
linear
1515_B. Phoenix and Puzzle
CODEFORCES
import java.io.*; import java.util.*; public class template { private InputStream is; private PrintWriter pw; static char[][] ch; static int x1,x2,y1,y2,n,m,h,k; static long dist[][]; static boolean boo[][]; void soln() { is = System.in; pw = new PrintWriter(System.out); long s = System...
logn
992_C. Nastya and a Wardrobe
CODEFORCES
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; public class A { static class team implements Comparable<team> { int problems; int penalty; public team(int problems,int penalty) { this.penalty=pena...
nlogn
166_A. Rank List
CODEFORCES
import java.text.DecimalFormat; import java.io.*; import java.util.*; import java.lang.reflect.Array; /** * @author Mukesh Singh * */ public class AB { private InputStream input; private PrintStream output; private Scanner inputSc; public AB(InputStream input, PrintStream output) { this....
linear
468_B. Two Sets
CODEFORCES
// package Practice1.CF35; import java.io.*; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class CF035C { public static void main(String[] args) throws IOException { Scanner s = new Scanner(new File("input.txt")/*System.in*/); int n = s.nextInt(); in...
cubic
35_C. Fire Again
CODEFORCES
import java.lang.reflect.Array; import java.util.Arrays; import java.util.Scanner; /** * Created by 11815 on 2017/7/1. */ public class Main { private static int[] x = new int[26], y = new int[26], dp = new int[1<<24], pre = new int[1<<24]; private static int dis(int i, int j) { return (x[i]-x[j])*(x...
np
8_C. Looking for Order
CODEFORCES
import java.text.*; import java.util.*; public class A { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int t = scan.nextInt(); List<Double> coords = new ArrayList<Double>(); while (n-- > 0) { double x = scan.nextDouble(); double a = scan.nextDo...
nlogn
15_A. Cottage Village
CODEFORCES
import java.util.*; import static java.lang.System.*; import static java.lang.Math.*; public class C { static int[] dp; static int[] f; static void solve(){ dp = new int[1<<n]; f = new int[1<<n]; Arrays.fill(dp, 1<<29); dp[0] = 0; for(int i=0;i<(1<<n);i++){ // ...
np
8_C. Looking for Order
CODEFORCES
import java.util.*; import java.io.*; public class e { private void main() { Scanner stdin = new Scanner(System.in); PrintStream stdout = System.out; int n = stdin.nextInt(); double[][] p = new double[n][n]; double[][] ans = new double[1<<n][n]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) ...
np
16_E. Fish
CODEFORCES
import java.util.Scanner; public class Question267A { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t--!=0){ int x=sc.nextInt(); int y=sc.nextInt(); int max=Math.max(x,y); int min=Math.m...
constant
267_A. Subtractions
CODEFORCES
import java.awt.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.List; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(), m = scanner.nextInt(); int[] vertical ...
nlogn
1075_C. The Tower is Going Home
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.util.*; public class PythonIndentation { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int a[]=new int[t]; int c=0; a[0]=1; long mod=(long) (1e9+7); sc.nextLine(); for(int i=0;i<t;i++) { String s=sc.nextLine(); if(s.equals("f")) ...
quadratic
909_C. Python Indentation
CODEFORCES
import java.io.*; import java.util.*; public class B { public static void main(String[] args) throws Exception { new B().solve(); } void solve() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // Scanner sc = new S...
linear
224_B. Array
CODEFORCES
import java.util.*; import java.io.*; public class A6 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int d = in.nextInt(); int ans=2; int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = in.nextInt(); for(int i=1;i<n;i++) { if(a[i...
linear
1004_A. Sonya and Hotels
CODEFORCES
import java.io.*; import java.util.*; import com.sun.swing.internal.plaf.basic.resources.basic; public class Main { PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); private void solution() t...
np
8_C. Looking for Order
CODEFORCES