1	public class ProblemC{ public static void main( String[] args)throws IOException { init(); new ProblemC().run(); out.flush(); out.close(); } static void init()throws IOException { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(new OutputStreamWriter(System.out)); in.ordinaryChars(0,65535); in.wordChars(0,65535); in.whitespaceChars(' ',' '); in.whitespaceChars('\n','\n'); in.whitespaceChars('\r','\r'); } static final long INFL = 200000000000000000L; static final int INF = 2000000000; static final boolean DEBUG = true; static StreamTokenizer in ; static PrintWriter out ; static void print( String s){ print(s,0); } static void print( String s, int debug){ if ( ((debug == 0) || DEBUG)) {out.print(s); } } static void println( String s){ println(s,0); } static void println( String s, int debug){ if ( ((debug == 0) || DEBUG)) {out.println(s); } } static void sort( int[] a){ Random rnd = new Random(); for ( int i = (a.length - 1);(i > 0);i--) { int index = rnd.nextInt(i); a[i] ^= a[index]; a[index] ^= a[i]; a[i] ^= a[index]; }Arrays.sort(a); } static char[] inChars ; static int inCharsInd ; static String next()throws IOException { in.nextToken(); return in.sval;} static int nextInt()throws IOException { return Integer.valueOf(next());} private void run()throws IOException { solve(); } int K ,L ,M ,N ,P ; private void solve()throws IOException { int[] countChars = new int[('z' + 1)];  boolean[] gotIt = new boolean[('z' + 1)];  int N = nextInt();  int fullCount = 0;  char[] chars = next().toCharArray(); for ( int i = 0;(i < N);i++) {if ( (countChars[chars[i]] == 0)) fullCount++; countChars[chars[i]]++; }countChars = new int[('z' + 1)]; int answer = N;  int start = 0,finish = 0; countChars[chars[start]]++; fullCount--; while(((finish + 1) < N)){finish++; if ( (countChars[chars[finish]] == 0)) {fullCount--; } countChars[chars[finish]]++; while((countChars[chars[start]] > 1)){countChars[chars[start]]--; start++; }while((fullCount == 0)){answer = Math.min(answer,((finish - start) + 1)); countChars[chars[start]]--; if ( (countChars[chars[start]] == 0)) fullCount++; start++; }}out.println(answer); } }
5	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskA solver = new TaskA(); solver.solve(1,in,out); out.close(); } } class TaskA{ public void solve( int testNumber, InputReader in, OutputWriter out){ int size = in.readInt();  int[] array = IOUtils.readIntArray(in,size); Arrays.sort(array); if ( (array[(size - 1)] == 1)) array[(size - 1)] = 2; else array[(size - 1)] = 1; Arrays.sort(array); out.printLine(Array.wrap(array).toArray()); } } class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public static boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(outputStream); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void print( Object... objects){ for ( int i = 0;(i < objects.length);i++) {if ( (i != 0)) writer.print(' '); writer.print(objects[i]); }} public void printLine( Object... objects){ print(objects); writer.println(); } public void close(){ writer.close(); } }
2	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ long n ,x ,y ,c ; public void solve( int testNumber, InputReader in, OutputWriter out){ n = in.readInt(); x = in.readInt(); y = in.readInt(); c = in.readInt(); int lo = -1;  int hi = (int)c; while(((lo + 1) < hi)){ int mi = ((lo + hi) / 2); if ( P(mi)) hi = mi; else lo = mi; }out.printLine(hi); } private boolean P( int t){ if ( (t == -1)) return false; int ans = 0; for ( long i = Math.max(1,(y - t));(i <= Math.min((y + t),n));++i) { long a = Math.abs((y - i)); ans += D(Math.max(1,((x - t) + a)),Math.min(n,((x + t) - a))); if ( (ans >= c)) return true; }return false;} private long D( long a, long b){ return ((b - a) + 1);} } class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void print( Object... objects){ for ( int i = 0;(i < objects.length);i++) {if ( (i != 0)) writer.print(' '); writer.print(objects[i]); }} public void printLine( Object... objects){ print(objects); writer.println(); } public void close(){ writer.close(); } }
1	public class Main{ void run()throws IOException { int n = nint();  char[] s = token().toCharArray();  int h = 0; for ( int i = 0;(i < n);i++) {if ( (s[i] == 'H')) h++; } int r = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int t = 0; for ( int j = i;(j < (i + h));j++) {if ( (s[(j % n)] == 'T')) t++; }r = min(r,t); }out.println(r); } public static void main( String[] args)throws IOException { Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); st = new StringTokenizer(" "); new Main().run(); out.close(); } static BufferedReader in ; static PrintWriter out ; static StringTokenizer st ; String token()throws IOException { while(!st.hasMoreTokens()){st = new StringTokenizer(in.readLine()); }return st.nextToken();} int nint()throws IOException { return Integer.parseInt(token());} }
2	public class B{ final int MOD = ((int)1e9 + 7); final double eps = 1e-12; final int INF = (int)1e9; public B(){ long N = sc.nextInt();  long X = (sc.nextInt() - 1);  long Y = (sc.nextInt() - 1);  long C = sc.nextInt();  long[] A1 = new long[]{X,Y};  long[] A2 = new long[]{X,Y};  long[] B1 = new long[]{X,Y};  long[] B2 = new long[]{X,Y};  long[] C1 = new long[]{X,Y};  long[] C2 = new long[]{X,Y};  long[] D1 = new long[]{X,Y};  long[] D2 = new long[]{X,Y};  long cnt = 1,T = 0; while((cnt < C)){if ( (A1[0] > 0)) --A1[0]; else --A1[1]; if ( (A2[0] > 0)) --A2[0]; else ++A2[1]; if ( (B1[1] > 0)) --B1[1]; else --B1[0]; if ( (B2[1] > 0)) --B2[1]; else ++B2[0]; if ( (C1[0] < (N - 1))) ++C1[0]; else --C1[1]; if ( (C2[0] < (N - 1))) ++C2[0]; else ++C2[1]; if ( (D1[1] < (N - 1))) ++D1[1]; else --D1[0]; if ( (D2[1] < (N - 1))) ++D2[1]; else ++D2[0]; long[] Z = {(B1[0] - A1[0]),(C1[0] - B2[0]),(C2[0] - D2[0]),(D1[0] - A2[0])}; for ( long z :Z) if ( (z >= 0)) cnt += (z + 1); if ( Arrays.equals(A1,A2)) --cnt; if ( Arrays.equals(B1,B2)) --cnt; if ( Arrays.equals(C1,C2)) --cnt; if ( Arrays.equals(D1,D2)) --cnt; ++T; }exit(T); } static MyScanner sc ; static class MyScanner{ public String next(){ newLine(); return line[index++];} public int nextInt(){ return Integer.parseInt(next());} public String[] nextStrings(){ line = null; return readLine().split(" ");} private boolean eol(){ return (index == line.length);} private String readLine(){ try{return r.readLine(); }catch (Exception e){ throw (new Error(e));} } private final BufferedReader r ; MyScanner(){ this(new BufferedReader(new InputStreamReader(System.in))); } MyScanner( BufferedReader r){ try{this.r = r; while(!r.ready())Thread.sleep(1); start(); }catch (Exception e){ throw (new Error(e));} } private String[] line ; private int index ; private void newLine(){ if ( ((line == null) || eol())) {line = readLine().split(" "); index = 0; } } } static void print( Object o, Object... a){ pw.println(build(o,a)); } static void exit( Object o, Object... a){ print(o,a); exit(); } static void exit(){ pw.close(); System.out.flush(); System.err.println("------------------"); System.err.println(("Time: " + ((millis() - t) / 1000.0))); System.exit(0); } static String build( Object... a){ StringBuilder b = new StringBuilder(); for ( Object o :a) append(b,o); return b.toString().trim();} static void append( StringBuilder b, Object o){ if ( o.getClass().isArray()) { int L = Array.getLength(o); for ( int i = 0;(i < L);++i) append(b,Array.get(o,i)); } else if ( (o instanceof Iterable<?>)) {for ( Object p :(Iterable<?>)o) append(b,p); } else b.append(" ").append(o); } public static void main( String[] args){ sc = new MyScanner(); new B(); exit(); } static void start(){ t = millis(); } static PrintWriter pw = new PrintWriter(System.out); static long t ; static long millis(){ return System.currentTimeMillis();} }
1	public class R025A{ int n ; int[] nums ; public R025A(){ Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); nums = new int[n]; for ( int i = 0;(i < n);i++) {nums[i] = scanner.nextInt(); }} private void process(){ int[] c = new int[2];  int[] r = new int[2]; for ( int i = 0;(i < n);i++) {c[(nums[i] % 2)]++; if ( (r[(nums[i] % 2)] == 0)) {r[(nums[i] % 2)] = (i + 1); } }System.out.println(r[((c[0] == 1)?0:1)]); } public static void main( String[] args){ new R025A().process(); } }
4	public class A{ static int dx[] = {1,-1,0,0}; static int dy[] = {0,0,1,-1}; public static void main( String[] args)throws Exception { Scanner sc = new Scanner("input.txt");  PrintWriter out = new PrintWriter("output.txt");  int n = sc.nextInt(),m = sc.nextInt();  int[][] grid = new int[n][m]; for ( int[] i :grid) Arrays.fill(i,-1); Queue<Pair> q = new LinkedList<>();  int k = sc.nextInt(); for ( int i = 0;(i < k);i++) { int x = (sc.nextInt() - 1),y = (sc.nextInt() - 1); grid[x][y] = 0; q.add(new Pair(x,y)); } Pair p = new Pair(-1,-1); while(!q.isEmpty()){p = q.poll(); for ( int i = 0;(i < dx.length);i++) { int tx = (p.x + dx[i]),ty = (p.y + dy[i]); if ( (((((tx >= 0) && (tx < n)) && (ty >= 0)) && (ty < m)) && (grid[tx][ty] == -1))) {grid[tx][ty] = (grid[p.x][p.y] + 1); q.add(new Pair(tx,ty)); } }}out.println(p); out.flush(); out.close(); } static class Pair{ int x ,y ; public Pair( int a, int b){ x = a; y = b; } } static class Scanner{ StringTokenizer st ; BufferedReader br ; public Scanner( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } public Scanner( String r)throws FileNotFoundException{ br = new BufferedReader(new FileReader(r)); } 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 boolean ready()throws IOException { return br.ready();} } }
5	public class Main{ public static void main( String[] args){ new Main().run(); } void run(){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = (sc.nextInt() * 2);  H[] tbl = new H[n]; for ( int i = 0;(i < n);i++) tbl[i] = new H((sc.nextInt() * 2),(sc.nextInt() * 2)); Arrays.sort(tbl); TreeSet<Integer> cand = new TreeSet<Integer>(); for ( int i = 0;(i < n);i++) { int left = ((tbl[i].x - (tbl[i].len / 2)) - (t / 2)); if ( !cand.contains(left)) {if ( ((i > 0) && ((tbl[(i - 1)].x + (tbl[(i - 1)].len / 2)) > (left - (t / 2))))) {} else {cand.add(left); }} int right = ((tbl[i].x + (tbl[i].len / 2)) + (t / 2)); if ( !cand.contains(right)) {if ( ((i < (n - 1)) && ((tbl[(i + 1)].x - (tbl[(i + 1)].len / 2)) < (right + (t / 2))))) {} else {cand.add(right); }} }System.out.println(cand.size()); } class H implements Comparable<H>{ int x ,len ; H( int a, int b){ x = a; len = b; } } }
1	public class Tsk1{ static void metod()throws Exception { Scanner in = new Scanner(System.in);  int n = in.nextInt();  String s = in.next();  String ss = (s + s);  int t = 0; for ( int i = 0;(i < n);i++) {if ( (s.charAt(i) == 'T')) {t++; } }if ( ((t == 1) || (t == (n - 1)))) {System.out.println(0); } else { int sum = 0; for ( int i = 0;(i < t);i++) {if ( (s.charAt(i) == 'T')) {sum++; } } int max = sum; for ( int i = 0;(i < s.length());i++) {if ( (ss.charAt(i) == 'T')) {if ( (ss.charAt((i + t)) == 'H')) {sum--; } } else {if ( (ss.charAt((i + t)) == 'T')) {sum++; max = Math.max(max,sum); } }}System.out.println((t - max)); }} public static void main( String[] args)throws Exception { Tsk1.metod(); } }
1	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 w = solve(); out.print(((w == 0)?"sjfnb":"cslnb")); } int n ; long a[] ; int solve(){ n = in.nextInt(); a = new long[n]; long sum = 0; for ( int i = 0;(i < n);i++) sum += a[i] = in.nextLong(); if ( (sum == 0)) {return 1;} Arrays.sort(a); int c = 0,c0 = 0;  long p = -1,max = 0;  int f = 0;  long t = -1;  int pp = -1; for ( int i = 0;(i < n);i++) {if ( (a[i] == p)) {c++; } else {if ( (p == 0)) c0 = c; if ( (c >= 2)) {f++; t = p; pp = (i - 2); } max = Math.max(max,c); p = a[i]; c = 1; }}max = Math.max(max,c); sum = 0; if ( (c >= 2)) {f++; t = p; pp = (n - 2); } if ( (((max > 2) || (c0 > 1)) || (f > 1))) return 1; if ( (f == 1)) { long v = Arrays.binarySearch(a,(t - 1)); if ( (v >= 0)) return 1; a[pp]--; sum = 1; } p = -1; for ( int i = 0;(i < n);i++) {sum += (a[i] - (p + 1)); a[i] = (p + 1); p = a[i]; }return (1 - (int)(sum % 2));} public static class InputReader{ BufferedReader br ; StringTokenizer st ; InputReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public int nextInt(){ return Integer.parseInt(next());} public long nextLong(){ return Long.parseLong(next());} public String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ } }return st.nextToken();} } }
5	public class A_135{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int[] mas = new int[n]; for ( int i = 0;(i < n);i++) {mas[i] = in.nextInt(); }Arrays.sort(mas); PrintWriter out = new PrintWriter(System.out);  boolean isEd = true; for ( int i = 0;(i < n);i++) if ( (mas[i] != 1)) {isEd = false; break;} if ( !isEd) out.print('1'); for ( int i = 0;(i < (n - 1));i++) {out.print(' '); out.print(mas[i]); }if ( isEd) out.print(" 2"); out.flush(); } }
0	public class MAIN{ public static void main( String[] args){ Scanner sn = new Scanner(System.in);  int n ,n1 ,n2 ,n3 ;  int arr[] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170}; n = sn.nextInt(); if ( (n == 2)) {n1 = n2 = 1; n3 = 0; } else if ( (n == 1)) {n3 = n2 = 0; n1 = 1; } else if ( (n == 0)) {n1 = n2 = n3 = 0; } else if ( (n == 3)) {n1 = n2 = n3 = 1; } else { int index = bsearch(arr,0,(arr.length - 1),n); n1 = arr[(index - 1)]; n2 = arr[(index - 3)]; n3 = arr[(index - 4)]; }System.out.println(((((n3 + " ") + n2) + " ") + n1)); } static int bsearch( int[] arr, int l, int h, int n){ if ( (l > h)) return -1; int mid = ((l + h) / 2); if ( (n == arr[mid])) return mid; else if ( (n > arr[mid])) return bsearch(arr,(mid + 1),h,n); else return bsearch(arr,l,(mid - 1),n);} }
5	public class CodeforcesA implements Runnable{ public static final String taskname = "A"; BufferedReader in ; PrintWriter out ; StringTokenizer tok ; public static void main( String[] args){ new Thread(new CodeforcesA()).start(); } static class Square implements Comparable<Square>{ int x ,a ; public Square( int x, int a){ this.x = x; this.a = a; } int distance( Square a, int t){ double dist = (((a.x - x) - (this.a / 2.0)) - (a.a / 2.0)); if ( (dist > t)) return 2; else if ( (abs((dist - t)) < 1e-9)) return 1; return 0;} } void solve()throws IOException { int n = nextInt(),t = nextInt();  Square[] x = new Square[n]; for ( int i = 0;(i < n);++i) {x[i] = new Square(nextInt(),nextInt()); }Arrays.sort(x); long res = 2; for ( int i = 0;(i < (n - 1));++i) {res += x[i].distance(x[(i + 1)],t); }out.println(res); } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tok == null) || !tok.hasMoreTokens())){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} }
1	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(c); int cur = h;  int i ; for ( i = 0;(i < h);i++) cur -= A(ca[i]); int best = cur; while((i != (h + len))){cur -= A(ca[(i % len)]); cur += A(ca[((i - h) % len)]); best = ((best > cur)?cur:best); i++; }System.out.println(best); } public static int A( char x){ return ((x == 'H')?1:0);} }
1	public class theyareeverywhere{ public static void main( String[] args)throws Exception { BufferedReader r = new BufferedReader(new InputStreamReader(System.in));  PrintWriter w = new PrintWriter(System.out);  int n = Integer.parseInt(r.readLine());  char[] pokemans = r.readLine().toCharArray();  int[] counts = new int[52];  boolean[] exists = new boolean[52]; for ( int i = 0;(i < pokemans.length);i++) {exists[index(pokemans[i])] = true; } int left = 0,right = 0; counts[index(pokemans[0])] = 1; int answer = 1000000000; while(((left < n) && (right < n))){if ( !valid(counts,exists)) {right++; if ( (right < n)) counts[index(pokemans[right])]++; } else {answer = Math.min(answer,((right - left) + 1)); left++; if ( ((left - 1) >= 0)) counts[index(pokemans[(left - 1)])]--; }}w.println(answer); w.flush(); } public static boolean valid( int[] counts, boolean[] exists){ for ( int i = 0;(i < counts.length);i++) {if ( (exists[i] && (counts[i] == 0))) return false; }return true;} public static int index( char c){ if ( ((c >= 'a') && (c <= 'z'))) {return (c - 'a');} else {return ((c - 'A') + 26);}} }
3	public class E1180D{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));  int n = sc.nextInt();  int m = sc.nextInt(); for ( int i = 1;(i <= (m / 2));i++) { int i2 = ((m - i) + 1); for ( int j = 1;(j <= n);j++) { int j2 = ((n - j) + 1); pw.println(((j + " ") + i)); pw.println(((j2 + " ") + i2)); }}if ( ((m % 2) == 1)) { int i2 = ((m / 2) + 1); for ( int j = 1;(j <= (n / 2));j++) { int j2 = ((n - j) + 1); pw.println(((j + " ") + i2)); pw.println(((j2 + " ") + i2)); }if ( ((n % 2) == 1)) { int j = ((n / 2) + 1); pw.println(((j + " ") + i2)); } } pw.flush(); pw.close(); } }
5	public class Flatwile{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  int[] c = new int[n];  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {c[i] = sc.nextInt(); a[i] = sc.nextInt(); }sort(c,a); int res = 1;  double prev = Integer.MIN_VALUE; for ( int i = 0;(i < c.length);i++) {if ( (((c[i] - (a[i] / 2d)) - prev) >= t)) {res++; } if ( ((i != (c.length - 1)) && (((c[(i + 1)] - (a[(i + 1)] / 2d)) - (c[i] + (a[i] / 2d))) > t))) {res++; } prev = (c[i] + (a[i] / 2d)); }System.out.println(res); } static private void sort( int[] a, int[] b){ for ( int i = 0;(i < a.length);i++) {for ( int j = (i + 1);(j < a.length);j++) {if ( (a[i] > a[j])) {swap(a,i,j); swap(b,i,j); } }}} static private void swap( int[] a, int i, int j){ int t = a[i]; a[i] = a[j]; a[j] = t; } }
5	public class Main{ Scanner in ; PrintWriter out ; static class House implements Comparable<House>{ int len ; int pos ; House( Scanner in){ pos = (in.nextInt() * 2); len = (in.nextInt() * 2); } } void solve(){ int n = in.nextInt();  int size = in.nextInt();  House[] h = new House[n]; for ( int i = 0;(i < h.length);i++) {h[i] = new House(in); }Arrays.sort(h); int ans = 2; for ( int i = 0;(i < (h.length - 1));i++) { int next = (i + 1);  int sz = ((h[next].pos - h[i].pos) - ((h[next].len + h[i].len) / 2)); if ( (sz == (size * 2))) {ans++; } else if ( (sz > (size * 2))) {ans += 2; } }out.println(ans); } public void run(){ in = new Scanner(System.in); out = new PrintWriter(System.out); try{solve(); }finally{out.close(); }} public static void main( String[] args){ new Main().run(); } }
3	public class C{ InputStream is ; PrintWriter out ; String INPUT = ""; void solve(){ int n = ni();  int mod = 1000000007;  long[] dp = new long[5005]; dp[0] = 1; for ( int i = 0;(i < n);i++) { char c = nc(); if ( (c == 's')) {if ( (i < (n - 1))) {for ( int j = 5003;(j >= 0);j--) {dp[j] += dp[(j + 1)]; if ( (dp[j] >= mod)) dp[j] -= mod; }} } else {for ( int j = 5003;(j >= 0);j--) {dp[(j + 1)] = dp[j]; }dp[0] = 0; }} long ans = 0; for ( int i = 0;(i < 5005);i++) ans += dp[i]; out.println((ans % mod)); } void run()throws Exception { is = (oj?System.in:new ByteArrayInputStream(INPUT.getBytes())); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(((System.currentTimeMillis() - s) + "ms")); } public static void main( String[] args)throws Exception { new C().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0,ptrbuf = 0; 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++];} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} private char nc(){ return (char)skip();} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private int ni(){ 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(); }} private boolean oj = (System.getProperty("ONLINE_JUDGE") != null); private void tr( Object... o){ if ( !oj) System.out.println(Arrays.deepToString(o)); } }
4	public class incendio{ static StringTokenizer _stk ; static BufferedReader input ; static PrintWriter output ; static String next(){ return _stk.nextToken();} static int nextInt(){ return Integer.parseInt(next());} static String readln()throws IOException { String l = input.readLine(); _stk = ((l == null)?null:new StringTokenizer(l," ")); return l;} public static void main( String[] args)throws IOException { input = new BufferedReader(new FileReader("input.txt")); output = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); new incendio(); output.close(); } incendio()throws IOException{ readln(); M = nextInt(); N = nextInt(); readln(); final int K = nextInt();  int xf[] = new int[K],yf[] = new int[K]; readln(); for ( int i = 0;(i < K);i++) {xf[i] = nextInt(); yf[i] = nextInt(); } int best = -1,xbest = 0,ybest = 0; for ( int i = 1;(i <= M);i++) {for ( int j = 1;(j <= N);j++) { int dist = Integer.MAX_VALUE; for ( int k = 0;(k < K);k++) {dist = Math.min(dist,(Math.abs((i - xf[k])) + Math.abs((j - yf[k])))); }if ( (dist > best)) {best = dist; xbest = i; ybest = j; } }}output.println(((xbest + " ") + ybest)); } int M ,N ; }
3	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{ int mod = 1000000007; public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.readInt();  int[][] dp = new int[(n + 1)][5002];  char[] a = new char[n]; for ( int i = 0;(i < n);i++) a[i] = in.readCharacter(); for ( int i = 0;(i < dp[n].length);i++) dp[n][i] = 1; for ( int i = (n - 1);(i >= 0);i--) {for ( int j = 0;(j < n);j++) {if ( (a[i] == 's')) {if ( (j > 0)) dp[i][j] = dp[i][(j - 1)]; dp[i][j] = (int)((dp[i][j] + (long)dp[(i + 1)][j]) % mod); } else {if ( (j > 0)) dp[i][j] = dp[i][(j - 1)]; dp[i][j] = (int)((((dp[i][j] + (long)dp[(i + 1)][(j + 1)]) - (long)dp[(i + 1)][j]) + mod) % mod); }}}out.println(dp[0][0]); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char readCharacter(){ int c = read(); while(isSpaceChar(c))c = read(); return (char)c;} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
1	public class SFly{ public static void main( String[] args)throws IOException { BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));  int planet = Integer.parseInt(lector.readLine());  int ini = Integer.parseInt(lector.readLine());  double peso = ini;  int[] desp = new int[planet];  int[] ater = new int[planet];  String[] temp = lector.readLine().split(" "); for ( int i = 0;(i < planet);i++) {desp[i] = Integer.parseInt(temp[i]); if ( (desp[i] == 1)) {System.out.println(-1); lector.close(); return ;} }temp = lector.readLine().split(" "); for ( int i = 0;(i < planet);i++) {ater[i] = Integer.parseInt(temp[i]); if ( (ater[i] == 1)) {System.out.println(-1); lector.close(); return ;} }temp = null; int i = (planet - 1); peso = ((peso * ater[0]) / (ater[0] - 1)); while((i > 0)){peso = ((peso * desp[i]) / (desp[i] - 1)); peso = ((peso * ater[i]) / (ater[i] - 1)); i--; }peso = ((peso * desp[0]) / (desp[0] - 1)); peso = (peso - ini); System.out.println(peso); lector.close(); } }
6	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);  TaskF solver = new TaskF(); solver.solve(1,in,out); out.close(); } static class TaskF{ final int INF = ((int)1e9 + 5); int n ; int m ; int[][][] dp ; int[][] diff ; int[][] diffStartLast ; int two( int x){ return (1 << x);} boolean contain( int mask, int x){ return ((mask & two(x)) > 0);} int rec( int start, int pre, int mask){ if ( (mask == (two(n) - 1))) return INF; int res = dp[start][pre][mask]; if ( (res != -1)) return res; res = 0; for ( int i = 0;(i < n);i++) if ( (contain(mask,i) == false)) { int diffPre = ((mask == 0)?INF:diff[pre][i]);  int diffLast = (((mask | two(i)) == (two(n) - 1))?diffStartLast[start][i]:INF); res = Math.max(res,Math.min(rec(start,i,(mask | two(i))),Math.min(diffLast,diffPre))); } dp[start][pre][mask] = res; return res;} public void solve( int testNumber, InputReader in, PrintWriter out){ n = in.nextInt(); m = in.nextInt(); int[][] grid = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) grid[i][j] = in.nextInt(); if ( (n == 1)) { int res = INF; for ( int i = 0;((i + 1) < m);i++) {res = Math.min(res,Math.abs((grid[0][i] - grid[0][(i + 1)]))); }out.println(res); return ;} diff = new int[n][n]; diffStartLast = new int[n][n]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {diff[i][j] = INF; diffStartLast[i][j] = INF; for ( int k = 0;(k < m);k++) {diff[i][j] = Math.min(diff[i][j],Math.abs((grid[i][k] - grid[j][k]))); if ( ((k + 1) < m)) {diffStartLast[i][j] = Math.min(diffStartLast[i][j],Math.abs((grid[i][(k + 1)] - grid[j][k]))); } }}}dp = new int[n][n][two(n)]; for ( int[][] aux :dp) for ( int[] aux2 :aux) Arrays.fill(aux2,-1); int ans = 0; for ( int start = 0;(start < n);start++) {ans = Math.max(ans,rec(start,start,two(start))); }out.println(ans); } } static class InputReader{ private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputStream stream ; public InputReader( InputStream stream){ this.stream = stream; } private boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isWhitespace(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isWhitespace(c));return (res * sgn);} } }
0	public class HexTheorem{ public static void main( String[] args)throws NumberFormatException,IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in));  int x = Integer.parseInt(read.readLine()); System.out.println(("0 0 " + x)); } }
1	public class A{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int a[] = new int[100]; for ( int i = 0;(i < n);i++) a[i] = (in.nextInt() % 2); if ( ((a[0] == a[1]) || (a[0] == a[2]))) {for ( int i = 1;(i < n);i++) if ( (a[i] != a[0])) {System.out.println((i + 1)); break;} } else {System.out.println(1); }} }
5	public class C{ Scanner sc ; BufferedReader in ; PrintStream out ; StringTokenizer tok ; public C()throws NumberFormatException,IOException{ in = new BufferedReader(new InputStreamReader(System.in)); out = System.out; run(); } void run()throws NumberFormatException,IOException { int[] array ;  int n = nextInt(); array = new int[n]; int max = 0;  int pos = 0; for ( int i = 0;(i < n);i++) { int l = nextInt(); if ( (l > max)) {pos = i; max = l; } array[i] = l; }if ( (max == 1)) array[pos] = 2; else array[pos] = 1; Arrays.sort(array); out.print(array[0]); for ( int i = 1;(i < n);i++) out.print((" " + array[i])); out.println(); } public static void main( String[] args)throws NumberFormatException,IOException { new C(); } String nextToken()throws IOException { if ( ((tok == null) || !tok.hasMoreTokens())) tok = new StringTokenizer(in.readLine()); return tok.nextToken();} int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(nextToken());} }
5	public class Main implements Runnable{ class House implements Comparable<House>{ int x ; int a ; public House( int x, int a){ this.x = x; this.a = a; } } private void solution()throws IOException { int n = in.nextInt();  int t = in.nextInt();  House[] h = new House[n]; for ( int i = 0;(i < h.length);++i) {h[i] = new House(in.nextInt(),in.nextInt()); }Arrays.sort(h); int res = 2; for ( int i = 0;(i < (h.length - 1));++i) { double dist = ((h[(i + 1)].x - (h[(i + 1)].a / 2.0)) - (h[i].x + (h[i].a / 2.0))); if ( (dist >= t)) {if ( (dist == t)) {++res; } else {res += 2; }} }out.println(res); } private class Scanner{ private BufferedReader reader ; private StringTokenizer tokenizer ; public Scanner( Reader reader){ this.reader = new BufferedReader(reader); this.tokenizer = new StringTokenizer(""); } public boolean hasNext()throws IOException { while(!tokenizer.hasMoreTokens()){ String next = reader.readLine(); if ( (next == null)) {return false;} tokenizer = new StringTokenizer(next); }return true;} public String next()throws IOException { hasNext(); return tokenizer.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(next());} } public static void main( String[] args)throws IOException { new Thread(null,new Main(),"",(1 << 28)).start(); } PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); Scanner in = new Scanner(new InputStreamReader(System.in)); }
2	public class Main{ static long[] dx = new long[]{0,1,0,-1}; static long[] dy = new long[]{-1,0,1,0}; public static void main( String[] args){ Scanner r = new Scanner(System.in);  long N = r.nextLong();  long X = r.nextLong();  long Y = r.nextLong();  long C = r.nextLong();  long lo = 0,hi = (N * 2); while((lo < hi)){ long T = ((lo + hi) / 2);  long[] NX = new long[4];  long[] NY = new long[4]; for ( int d = 0;(d < 4);d++) {NX[d] = (X + (dx[d] * T)); NY[d] = (Y + (dy[d] * T)); } long ret = (((T + 1) * (T + 1)) + (T * T)); ret -= half((1 - NY[0])); ret -= half((NY[2] - N)); ret -= half((NX[1] - N)); ret -= half((1 - NX[3])); ret += quarter(((1 - NY[0]) - ((N - X) + 1))); ret += quarter(((1 - NY[0]) - X)); ret += quarter(((NY[2] - N) - ((N - X) + 1))); ret += quarter(((NY[2] - N) - X)); if ( (ret < C)) lo = (T + 1); else hi = T; }System.out.println(lo); } static private long half( long x){ if ( (x <= 0)) return 0; else return ((2 * quarter(x)) - x);} static private long quarter( long x){ if ( (x <= 0)) return 0; return ((x * (x + 1)) / 2);} }
6	public class G1{ static int n ,T ,duration[] ,type[] ; static long dp[][][] ,mod = ((long)1e9 + 7); public static void main( String[] args)throws Exception { new Thread(null,new Runnable(){},"Main",(1 << 28)).start(); } public static void solveIt()throws Exception { Scanner in = new Scanner(System.in);  PrintWriter pw = new PrintWriter(System.out); n = in.nextInt(); T = in.nextInt(); dp = new long[4][(T + 1)][(1 << n)]; duration = new int[n]; type = new int[n]; for ( int i = 0;(i < n);i++) {duration[i] = in.nextInt(); type[i] = (in.nextInt() - 1); }for ( long[][] a :dp) for ( long[] b :a) Arrays.fill(b,-1); pw.println(solve(3,T,0)); pw.close(); } static long solve( int lastType, int rem, int mask){ if ( (rem == 0)) return 1; if ( (rem < 0)) return 0; if ( (dp[lastType][rem][mask] != -1)) return dp[lastType][rem][mask]; long res = 0; for ( int i = 0;(i < n);i++) {if ( ((!check(mask,i) && (lastType != type[i])) && ((rem - duration[i]) >= 0))) {res += solve(type[i],(rem - duration[i]),set(mask,i)); if ( (res >= mod)) res -= mod; } }return dp[lastType][rem][mask] = res;} static boolean check( int N, int pos){ return ((N & (1 << pos)) != 0);} static int set( int N, int pos){ return N = (N | (1 << pos));} }
3	public class D{ 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 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());} String nextLine(){ String str = ""; try{str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str;} } public static void main( String[] args)throws IOException { FastReader fr = new FastReader();  FastWriter fw = new FastWriter();  int n = fr.nextInt();  int m = fr.nextInt(); for ( int r = 0;(r < (n / 2));r++) {for ( int c = 0;(c < m);c++) {fw.println((((r + 1) + " ") + (c + 1))); fw.println((((n - r) + " ") + (m - c))); }}if ( ((n % 2) != 0)) { int r = (n / 2); for ( int c = 0;(c < (m / 2));c++) {fw.println((((r + 1) + " ") + (c + 1))); fw.println((((r + 1) + " ") + (m - c))); }if ( ((m % 2) != 0)) fw.println((((r + 1) + " ") + ((m / 2) + 1))); } fw.close(); } }
4	public class FireAgain{ static Queue q = new LinkedList<>(); static boolean[][] fired ; static Pair index = null; public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new FileReader("input.txt"));  BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));  StringTokenizer s = new StringTokenizer(in.readLine());  int n = Integer.parseInt(s.nextToken());  int m = Integer.parseInt(s.nextToken()); fired = new boolean[n][m]; Pair result = null; s = new StringTokenizer(in.readLine()); int firenum = Integer.parseInt(s.nextToken()); s = new StringTokenizer(in.readLine()); int i ;  ArrayList<Integer> tree = new ArrayList<>(); for ( i = 0;(i < (firenum * 2));i++) {tree.add((Integer.parseInt(s.nextToken()) - 1)); }for ( i = 0;(i < ((2 * firenum) - 1));i += 2) {fired[tree.get(i)][tree.get((i + 1))] = true; q.add(new Pair(tree.get(i),tree.get((i + 1)))); }index = (Pair)q.peek(); result = bfs((int)index.getKey(),(int)index.getValue(),n,m); int x1 = ((int)result.getKey() + 1);  int x2 = ((int)result.getValue() + 1);  String str = ((x1 + " ") + x2); writer.write(str); writer.close(); } public static Pair bfs( int x, int y, int xmax, int ymax){ fired[x][y] = true; while(!q.isEmpty()){index = (Pair)q.poll(); int i = (int)index.getKey();  int j = (int)index.getValue(); if ( ((i - 1) >= 0)) {if ( !fired[(i - 1)][j]) {fired[(i - 1)][j] = true; q.add(new Pair((i - 1),j)); } } if ( ((j - 1) >= 0)) {if ( !fired[i][(j - 1)]) {fired[i][(j - 1)] = true; q.add(new Pair(i,(j - 1))); } } if ( ((i + 1) < xmax)) {if ( !fired[(i + 1)][j]) {fired[(i + 1)][j] = true; q.add(new Pair((i + 1),j)); } } if ( ((j + 1) < ymax)) {if ( !fired[i][(j + 1)]) {fired[i][(j + 1)] = true; q.add(new Pair(i,(j + 1))); } } }return index;} }
4	public class ArFireAgain{ int n ,m ,k ; int dx[] = {0,0,1,-1,1,1,-1,-1}; int dy[] = {1,-1,0,0,1,-1,1,-1}; int[][] dist ; ArrayList<Pair> arr ; Scanner sc ; PrintWriter out ; public void solve(){ try{sc = new Scanner(new FileReader("input.txt")); out = new PrintWriter("output.txt"); }catch (FileNotFoundException e){ e.printStackTrace(); } n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt(); arr = new ArrayList<Pair>(); for ( int i = 0;(i < k);i++) { int x = (sc.nextInt() - 1);  int y = (sc.nextInt() - 1);  Pair p = new Pair(x,y); arr.add(p); } Pair last = bfs(); out.println(((last.x + " ") + last.y)); out.flush(); out.close(); } boolean isValid( int x, int y){ return ((((x >= 0) && (y >= 0)) && (x < n)) && (y < m));} private Pair bfs(){ Queue<Pair> q = new LinkedList<Pair>(); dist = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {dist[i][j] = -1; }}for ( int i = 0;(i < k);i++) {dist[arr.get(i).x][arr.get(i).y] = 0; q.add(arr.get(i)); }while(!q.isEmpty()){ Pair cur = q.remove(); for ( int d = 0;(d < 4);d++) { int X = (cur.x + dx[d]);  int Y = (cur.y + dy[d]); if ( (isValid(X,Y) && (dist[X][Y] == -1))) {dist[X][Y] = (dist[cur.x][cur.y] + 1); Pair p = new Pair(X,Y); q.add(p); } }} Pair res = null;  int maxx = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (dist[i][j] > maxx)) {maxx = dist[i][j]; res = new Pair((i + 1),(j + 1)); } }}return res;} class Pair{ int x ,y ; Pair( int x, int y){ this.x = x; this.y = y; } } public static void main( String[] args){ new ArFireAgain().solve(); } }
2	public class Main{ public static void main( String[] args)throws IOException { Scanner c = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  long N = (c.nextLong() - 1);  long K = (c.nextLong() - 1);  long tot = ((K * (K + 1)) / 2); if ( (N > tot)) {System.out.println(-1); return ;} long lo = 1;  long hi = K; while(((hi - lo) >= 10)){ long mid = ((hi + lo) / 2);  long sum = ((mid * (mid - 1)) / 2);  long left = ((mid * K) - sum); if ( (left >= N)) hi = (mid + 1); else lo = (mid - 1); }for ( int num = ((int)lo - 1000);(num < (lo + 1000));num++) {if ( (num >= 0)) { long sum = (((long)num * (num - 1)) / 2);  long left = (((long)num * K) - sum); if ( (left >= N)) {System.out.println(num); return ;} } }out.close(); } }
3	public class c{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int numbOfStatements = in.nextInt();  long[] dp = new long[numbOfStatements]; dp[0] = 1L; boolean priorFor = in.next().equals("f"); for ( int i = 0;(i < (numbOfStatements - 1));i++) { String type = in.next(); if ( priorFor) {for ( int j = (numbOfStatements - 1);(j > 0);j--) {dp[j] = dp[(j - 1)]; }dp[0] = 0L; } else { long sum = 0; for ( int j = (numbOfStatements - 1);(j >= 0);--j) {sum = ((sum + dp[j]) % 1000000007); dp[j] = sum; }}priorFor = type.equals("f"); } long ans = 0; for ( int j = 0;(j < numbOfStatements);j++) {ans = ((ans + dp[j]) % 1000000007); }System.out.println(ans); } }
1	public class Round42CC{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = Integer.parseInt(sc.nextLine());  String s = sc.nextLine();  int k = 0; for ( int i = 0;(i < n);i++) {if ( (s.charAt(i) == 'H')) {k++; } }s = (s + s.substring(0,k)); String ss = "";  int max = 0; for ( int i = 0;(i < (s.length() - k));i++) {ss = s.substring(i,(i + k)); int count = 0; for ( int j = 0;(j < ss.length());j++) {if ( (ss.charAt(j) == 'H')) {count++; } }if ( (count > max)) {max = count; } }System.out.println((k - max)); } }
5	public class A{ public static void main( String[] args){ new A().solve(); } public void solve(){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  float[] left = new float[n];  float[] right = new float[n]; for ( int i = 0;(i < n);++i) { int c = sc.nextInt();  int w = sc.nextInt(); left[i] = (float)(c - (((float)w * 1.0) / 2)); right[i] = (float)(c + (((float)w * 1.0) / 2)); }for ( int i = 0;(i < n);++i) for ( int j = (i + 1);(j < n);++j) if ( (left[j] < left[i])) { float tmp = left[i]; left[i] = left[j]; left[j] = tmp; tmp = right[i]; right[i] = right[j]; right[j] = tmp; } int res = 2; for ( int i = 1;(i < n);++i) { float dis = (left[i] - right[(i - 1)]); if ( (Math.abs((dis - t)) < 0.000001)) res++; if ( ((dis - t) > 0.000001)) res += 2; }System.out.println(res); } }
5	public class C{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { if ( ONLINE_JUDGE) {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"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new C().run(); } public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println(("Time = " + (t2 - t1))); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } void solve()throws IOException { int n = readInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = readInt(); } boolean c = true; for ( int i = 0;(i < n);i++) {if ( (a[i] != 1)) {c = false; break;} }if ( c) {for ( int i = 0;(i < (n - 1));i++) {out.print((a[i] + " ")); }out.println(2); return ;} Utils.mergeSort(a); out.print((1 + " ")); for ( int i = 1;(i < n);i++) {out.print((a[(i - 1)] + " ")); }} static long gcd( long a, long b){ if ( (min(a,b) == 0)) return max(a,b); return gcd((max(a,b) % min(a,b)),min(a,b));} }
5	public class A{ static int[] reverse = new int[257]; public static void main( String[] arg){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int[] A = new int[n]; for ( int i = 0;(i < A.length);++i) A[i] = sc.nextInt(); Arrays.sort(A); if ( (n == 1)) {System.out.println(((A[0] == 1)?"2":"1")); return ;} else if ( ((A[0] == A[(A.length - 1)]) && (A[0] == 1))) {System.out.print("1"); for ( int i = 1;(i < (n - 1));++i) System.out.print((" " + A[i])); System.out.println(" 2"); return ;} else if ( (A[0] == A[(A.length - 1)])) {System.out.print("1"); for ( int i = 1;(i < n);++i) System.out.print((" " + A[i])); System.out.println(); return ;} for ( int i = 0;(i < A.length);++i) { int prev = ((i == 0)?Integer.MAX_VALUE:A[(i - 1)]);  int next = ((i == (A.length - 1))?Integer.MAX_VALUE:A[(i + 1)]);  int ans = Math.min(prev,Math.min(next,A[i])); if ( (i == 0)) ans = 1; System.out.print(((i == 0)?("" + ans):(" " + ans))); }System.out.println(); } }
1	public class A25{ public void run(){ try{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(in.readLine().trim());  String[] toks = in.readLine().trim().split("[ ]+");  int counter = 0;  boolean even = true;  int e = -1,o = -1;  int ec = 0,oc = 0; for ( int i = 0;(i < toks.length);i++) { int x = Integer.parseInt(toks[i]); if ( ((x % 2) == 0)) {ec++; if ( (e == -1)) {e = (i + 1); } } else {oc++; if ( (o == -1)) {o = (i + 1); } }}if ( (ec == 1)) {System.out.println(e); } else if ( (oc == 1)) {System.out.println(o); } }catch (Exception e){ e.printStackTrace(); } } public static void main( String[] args){ new A25().run(); } }
1	public class Solution{ public static void main( String[] args)throws Exception { Scanner sc = new Scanner(new InputStreamReader(System.in));  int n = sc.nextInt();  String s = sc.next(); sc.close(); int cH = 0; for ( int i = 0;(i < s.length());i++) if ( (s.charAt(i) == 'H')) cH++;  int best = cH; for ( int st = 0;(st < s.length());st++) { int cur = st;  int cnt = cH; for ( int i = 0;(i < cH);i++) {if ( (s.charAt(cur) == 'H')) cnt--; cur++; if ( (cur == s.length())) cur = 0; }best = Math.min(best,cnt); }System.out.println(best); } }
2	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } static class TaskB{ int n ; int startrow ; int startcol ; long want ; boolean check( long time){ long max = ((((long)2 * time) * (time + 1)) + 1);  long highest = (startrow - time); if ( (highest < 0)) {max -= (Math.abs(highest) * Math.abs(highest)); } long lowest = (startrow + time); if ( (lowest >= n)) {max -= (Math.abs(((lowest - n) + 1)) * Math.abs(((lowest - n) + 1))); } long leftmost = (startcol - time); if ( (leftmost < 0)) {max -= (Math.abs(leftmost) * Math.abs(leftmost)); } long rightmost = (startcol + time); if ( (rightmost >= n)) {max -= (Math.abs(((rightmost - n) + 1)) * Math.abs(((rightmost - n) + 1))); } long upperright = ((time - (startrow + 1)) - (n - startcol)); if ( (upperright >= 0)) {max += (((upperright + 1) * (upperright + 2)) / 2); } long lowerright = ((time - (n - startrow)) - (n - startcol)); if ( (lowerright >= 0)) {max += (((lowerright + 1) * (lowerright + 2)) / 2); } long upperleft = ((time - (startrow + 1)) - (startcol + 1)); if ( (upperleft >= 0)) {max += (((upperleft + 1) * (upperleft + 2)) / 2); } long lowerleft = ((time - (n - startrow)) - (startcol + 1)); if ( (lowerleft >= 0)) {max += (((lowerleft + 1) * (lowerleft + 2)) / 2); } return (max >= want);} public void solve( int testNumber, InputReader in, OutputWriter out){ n = in.readInt(); startrow = (in.readInt() - 1); startcol = (in.readInt() - 1); want = in.readLong(); long low = 0,high = (2 * n); while((low < high)){ long mid = ((low + high) / 2); if ( check(mid)) high = mid; else low = (mid + 1); }out.printLine(low); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public long readLong(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } static class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void close(){ writer.close(); } public void printLine( long i){ writer.println(i); } } }
3	public class PythonIndentation{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  boolean[] lst = new boolean[n]; for ( int i = 0;(i < n);i++) {lst[i] = (in.next()?false:true); }System.out.println(dp(lst)); } static int dp( boolean[] lst){ int[][] dp = new int[2][lst.length]; dp[0][0] = 1; for ( int i = 1;(i < lst.length);i++) {for ( int j = 0;(j < lst.length);j++) {if ( lst[(i - 1)]) {if ( (j == 0)) dp[(i % 2)][j] = 0; else dp[(i % 2)][j] = dp[((i - 1) % 2)][(j - 1)]; } else {if ( (j == 0)) { int temp = 0; for ( int k = 0;(k < lst.length);k++) temp = ((temp + dp[((i - 1) % 2)][k]) % 1000000007); dp[(i % 2)][j] = temp; } else dp[(i % 2)][j] = ((dp[(i % 2)][(j - 1)] - dp[((i - 1) % 2)][(j - 1)]) % 1000000007); }}} int ans = 0; for ( int i = 0;(i < lst.length);i++) {ans = ((ans + dp[((lst.length - 1) % 2)][i]) % 1000000007); }if ( (ans < 0)) ans = (ans + 1000000007); return ans;} }
3	public class CFC{ BufferedReader br ; PrintWriter out ; StringTokenizer st ; boolean eof ; final long MOD = (((1000L * 1000L) * 1000L) + 7); int[] dx = {0,-1,0,1}; int[] dy = {1,0,-1,0}; void solve()throws IOException { int n = nextInt();  long[] dp0 = new long[(10 + n)];  long[] dp1 = new long[(10 + n)];  long[] pre = new long[(10 + n)]; dp0[0] = 1; String[] arr = new String[n]; for ( int i = 0;(i < n);i++) {arr[i] = nextString(); } String s = "s"; for ( int i = 0;(i < n);i++) {Arrays.fill(dp1,0); if ( (i == 0)) {dp0[0] = 1; dp1[0] = 1; } else {if ( arr[(i - 1)].equals(s)) {for ( int j = 0;(j <= (n + 5));j++) {dp1[j] = pre[j]; }} else {for ( int j = 1;(j <= (n + 5));j++) {dp1[j] = dp0[(j - 1)]; }}}Arrays.fill(pre,0); pre[(n + 5)] = dp1[(n + 5)]; for ( int j = (n + 4);(j >= 0);j--) {pre[j] = (pre[(j + 1)] + dp1[j]); pre[j] %= MOD; }for ( int j = 0;(j <= (n + 5));j++) {dp0[j] = dp1[j]; }} long res = 0; for ( int j = 0;(j <= (n + 5));j++) {res += dp0[j]; res %= MOD; }out(res); } private void out( Object o){ out.print(o); } public CFC()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 CFC(); } public String nextToken(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ eof = true; return null;} }return st.nextToken();} public String nextString(){ try{return br.readLine(); }catch (IOException e){ eof = true; return null;} } public int nextInt()throws IOException { return Integer.parseInt(nextToken());} public long nextLong()throws IOException { return Long.parseLong(nextToken());} }
1	public class A{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int n = scan.nextInt();  int odd = -1;  int even = -1;  int oc = 0;  int ec = 0; for ( int i = 0;(i < n);i++) {if ( ((scan.nextInt() % 2) == 0)) {ec++; even = (i + 1); } else {oc++; odd = (i + 1); }}if ( (ec == 1)) System.out.println(even); else System.out.println(odd); } }
5	public class A{ public static void main( String[] args){ try{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  String[] s = in.readLine().split(" ");  int n = Integer.parseInt(s[0]);  int t = (Integer.parseInt(s[1]) * 2);  int[] walls = new int[(n * 2)]; for ( int i = 0;(i < n);i++) {s = in.readLine().split(" "); int x = (Integer.parseInt(s[0]) * 2);  int a = Integer.parseInt(s[1]); walls[(i * 2)] = (x - a); walls[((i * 2) + 1)] = (x + a); }Arrays.sort(walls); int count = 2; for ( int i = 1;(i < ((n * 2) - 2));i += 2) { int space = (walls[(i + 1)] - walls[i]); if ( (space == t)) count += 1; else if ( (space > t)) count += 2; }System.out.println(count); }catch (NumberFormatException e){ throw (new RuntimeException(e));} catch (IOException e){ throw (new RuntimeException(e));} } }
1	public class Main{ BufferedReader in ; StringTokenizer str = null; PrintWriter out ; private String next()throws Exception { while(((str == null) || !str.hasMoreElements()))str = new StringTokenizer(in.readLine()); return str.nextToken();} private int nextInt()throws Exception { return Integer.parseInt(next());} final int oo = Integer.MAX_VALUE; int[][] s ; int n ,ALL ; public void run()throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); n = nextInt(); char[] a = next().toCharArray(); s = new int[n][52]; boolean[] set = new boolean[52]; for ( int i = 0;(i < n);++i) { int pos = get(a[i]); if ( !set[pos]) {++ALL; set[pos] = true; } for ( int j = 0;(j < 52);++j) {if ( (i > 0)) {s[i][j] += s[(i - 1)][j]; } if ( (j == pos)) {s[i][j]++; } }} int ret = oo; for ( int i = 0;(i < n);++i) {ret = Math.min(ret,get(i)); }out.println(ret); out.close(); } private int get( int i){ int lo = (i - 1),hi = n; while(((hi - lo) > 1)){ int m = (lo + ((hi - lo) / 2));  int c = 0; for ( int j = 0;(j < 52);++j) {if ( (sum(j,i,m) > 0)) {++c; } }if ( (c < ALL)) {lo = m; } else {hi = m; }}if ( (hi != n)) {return ((hi - i) + 1);} return oo;} private int sum( int pos, int l, int r){ int ret = s[r][pos]; if ( (l > 0)) ret -= s[(l - 1)][pos]; return ret;} private int get( char x){ if ( (('a' <= x) && (x <= 'z'))) return (int)(x - 'a'); return (int)((x - 'A') + 26);} public static void main( String[] args)throws Exception { new Main().run(); } }
6	@SuppressWarnings("unused") public class Solution{ static long inf = ((long)1e18 + 100); static final long mod = ((long)1e9 + 7); @SuppressWarnings public static void main( String[] args)throws IOException { FastScanner fs = new FastScanner();  PrintWriter out = new PrintWriter(System.out);  int tt = 1; outer:while((tt-- > 0)){ int n = fs.nextInt(),T = fs.nextInt();  int[] t = new int[n],g = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = fs.nextInt(); g[i] = fs.nextInt(); } long[][] dp = new long[(1 << n)][4]; dp[0][0] = 1; long ans = 0; for ( int mask = 0;(mask < (1 << n));mask++) {for ( int pre = 0;(pre <= 3);pre++) {for ( int i = 0;(i < n);i++) if ( (((mask & (1 << i)) == 0) && (g[i] != pre))) dp[(mask ^ (1 << i))][g[i]] = add(dp[(mask ^ (1 << i))][g[i]],dp[mask][pre]);  int sum = 0; for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) != 0)) sum += t[i]; }if ( (sum == T)) ans = add(ans,dp[mask][pre]); }}out.println(ans); }out.close(); } static long add( long a, long b){ a += b; if ( (a > mod)) return (a - mod); return a;} static final Random random = new Random(); 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 int nextInt(){ return Integer.parseInt(next());} } }
5	public class Solution15A{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { if ( ONLINE_JUDGE) {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"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new Solution15A().run(); } public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println(("Time = " + (t2 - t1))); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } class Square implements Comparable<Square>{ public Square( int x, int a){ this.x = x; this.a = a; } public int a ,x ; } void solve()throws IOException { int n = readInt();  int t = readInt();  Square[] houses = new Square[n]; for ( int i = 0;(i < n);i++) { int a = readInt();  int b = readInt(); houses[i] = new Square(a,b); }Arrays.sort(houses); int count = 0; for ( int i = 0;(i < n);i++) {if ( (i == 0)) count++; else {if ( (((houses[i].x - (houses[i].a / 2.0)) - t) > (houses[(i - 1)].x + (houses[(i - 1)].a / 2.0)))) count++; }if ( (i == (n - 1))) count++; else {if ( (((houses[i].x + (houses[i].a / 2.0)) + t) <= (houses[(i + 1)].x - (houses[(i + 1)].a / 2.0)))) count++; }}out.println(count); } static long gcd( long a, long b){ while((a != b)){if ( (a < b)) a -= b; else b -= a; }return a;} }
2	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();} private long nextLong()throws Exception { return Long.parseLong(next());} public void run()throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); long n = nextLong(); if ( (n == 1)) {System.out.println(0); return ;} long k = nextLong();  long t = (((1 - (k - 1)) + ((k * (k + 1)) / 2)) - 1); if ( (t < n)) {System.out.println(-1); return ;} long l = 0;  long r = k; while(((r - l) > 1)){ long m = ((r + l) / 2);  long s = (((1 - m) + ((k * (k + 1)) / 2)) - (((k - m) * ((k - m) + 1)) / 2)); if ( (s >= n)) {r = m; } else {l = m; }}System.out.println(r); out.close(); } public static void main( String[] args)throws Exception { new Main().run(); } }
1	public class HamstersTigers{ private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; int solve( String a, int k){ int n = a.length(),ret = 0;  int temp[] = new int[n]; for ( int i = 0;(i < n);i++) temp[(((n + i) - k) % n)] = ((a.charAt(i) == 'T')?1:0); int left = 0,right = (n - 1); while((left < right)){while((temp[left] == 0))left++; while((temp[right] == 1))right--; if ( (left < right)) { int t = temp[left]; temp[left] = temp[right]; temp[right] = t; ret++; } }return ret;} void solve()throws IOException { int n = nextInt();  String a = next();  int ans = Integer.MAX_VALUE; for ( int fix = 0;(fix < n);fix++) {ans = Math.min(ans,solve(a,fix)); }out.println(ans); } HamstersTigers()throws IOException{ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); eat(""); solve(); in.close(); out.close(); } private void eat( String str){ st = new StringTokenizer(str); } String next()throws IOException { while(!st.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) {return null;} eat(line); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args)throws IOException { new HamstersTigers(); } }
6	public class Main{ static class Task{ int NN = 1000006; int MOD = 998244353; int INF = 2000000000; long INFINITY = 1000000000000000000L; long[][] a ; long[][] w ,w1 ; long[][] dp ; int countBit( int num){ int ret = 0; while((num > 0)){if ( ((num & 1) != 0)) ++ret; num >>= 1; }return ret;} long rec( int at, int mask, int n, int start){ long ans = -INFINITY; if ( (dp[at][mask] != -1)) return dp[at][mask]; if ( (countBit(mask) == n)) {return dp[at][mask] = w1[start][at];} for ( int i = 0;(i < n);++i) {if ( (((mask >> i) & 1) == 0)) {ans = Math.max(ans,Math.min(w[at][i],rec(i,(mask | (1 << i)),n,start))); } }return dp[at][mask] = ans;} public void solve( InputReader in, PrintWriter out){ int n = in.nextInt(),m = in.nextInt(); dp = new long[n][(1 << n)]; a = new long[n][m]; w = new long[n][n]; w1 = new long[n][n]; for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < m);++j) {a[i][j] = in.nextLong(); }}for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < n);++j) {w[i][j] = INFINITY; if ( (i == j)) continue; for ( int k = 0;(k < m);++k) {w[i][j] = Math.min(w[i][j],Math.abs((a[j][k] - a[i][k]))); }}}for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < n);++j) {w1[i][j] = INFINITY; for ( int k = 1;(k < m);++k) {w1[i][j] = Math.min(w1[i][j],Math.abs((a[i][k] - a[j][(k - 1)]))); }}} long ans = 0; for ( int start = 0;(start < n);++start) {for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < (1 << n));++j) dp[i][j] = -1; }ans = Math.max(ans,rec(start,(1 << start),n,start)); }out.println(ans); } } static void prepareIO( boolean isFileIO){ Task solver = new Task(); if ( !isFileIO) { InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream); solver.solve(in,out); out.close(); } else { String IPfilePath = (System.getProperty("user.home") + "/Downloads/ip.in");  String OPfilePath = (System.getProperty("user.home") + "/Downloads/op.out");  InputReader fin = new InputReader(IPfilePath);  PrintWriter fout = null; try{fout = new PrintWriter(new File(OPfilePath)); }catch (FileNotFoundException e){ e.printStackTrace(); } solver.solve(fin,fout); fout.close(); }} public static void main( String[] args){ prepareIO(false); } static class InputReader{ public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader( InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream),32768); tokenizer = null; } public InputReader( String filePath){ File file = new File(filePath); try{reader = new BufferedReader(new FileReader(file)); }catch (FileNotFoundException e){ e.printStackTrace(); } 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());} } }
6	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]; for ( int s = (t - 1);(s >= 0);s--) for ( int m = 0;(m < n);m++) { int x = da[s][m]; if ( (x != 0)) { int s_ = (s + a); if ( (s_ <= t)) da[s_][(m + 1)] = ((da[s_][(m + 1)] + x) % MD); } }}return da;} static int[][][] solve2( int[] aa, int[] bb, int t, int na, int nb){ int[][] da = solve1(aa,t,na);  int[][][] dab = new int[(t + 1)][(na + 1)][(nb + 1)]; for ( int s = 0;(s <= t);s++) for ( int ma = 0;(ma <= na);ma++) dab[s][ma][0] = da[s][ma]; for ( int i = 0;(i < nb);i++) { int b = bb[i]; for ( int s = (t - 1);(s >= 0);s--) for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb < nb);mb++) { int x = dab[s][ma][mb]; if ( (x != 0)) { int s_ = (s + b); if ( (s_ <= t)) dab[s_][ma][(mb + 1)] = ((dab[s_][ma][(mb + 1)] + x) % MD); } }}return dab;} static int[][][] init( int n, int na, int nb, int nc){ int[][][] dp = new int[(na + 1)][(nb + 1)][(nc + 1)];  int[][][][] dq = new int[(na + 1)][(nb + 1)][(nc + 1)][3]; for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) for ( int mc = 0;(mc <= nc);mc++) if ( (((ma == 0) && (mb == 0)) && (mc == 0))) {dp[ma][mb][mc] = 1; dq[ma][mb][mc][0] = dq[ma][mb][mc][1] = dq[ma][mb][mc][2] = 1; } else { int x0 = ((ma > 0)?(int)(((long)dq[(ma - 1)][mb][mc][0] * ma) % MD):0);  int x1 = ((mb > 0)?(int)(((long)dq[ma][(mb - 1)][mc][1] * mb) % MD):0);  int x2 = ((mc > 0)?(int)(((long)dq[ma][mb][(mc - 1)][2] * mc) % MD):0); dp[ma][mb][mc] = (int)((((long)x0 + x1) + x2) % MD); dq[ma][mb][mc][0] = ((x1 + x2) % MD); dq[ma][mb][mc][1] = ((x2 + x0) % MD); dq[ma][mb][mc][2] = ((x0 + x1) % MD); }return dp;} 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 t = Integer.parseInt(st.nextToken());  int[] aa = new int[n];  int[] bb = new int[n];  int[] cc = new int[n];  int na = 0,nb = 0,nc = 0; for ( int i = 0;(i < n);i++) {st = new StringTokenizer(br.readLine()); int a = Integer.parseInt(st.nextToken());  int g = Integer.parseInt(st.nextToken()); if ( (g == 1)) aa[na++] = a; else if ( (g == 2)) bb[nb++] = a; else cc[nc++] = a; } int[][][] dp = init(n,na,nb,nc);  int[][][] dab = solve2(aa,bb,t,na,nb);  int[][] dc = solve1(cc,t,nc);  int ans = 0; for ( int tab = 0;(tab <= t);tab++) { int tc = (t - tab); for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) { int xab = dab[tab][ma][mb]; if ( (xab == 0)) continue; for ( int mc = 0;(mc <= nc);mc++) { int xc = dc[tc][mc]; if ( (xc == 0)) continue; ans = (int)((ans + ((((long)xab * xc) % MD) * dp[ma][mb][mc])) % MD); }}}System.out.println(ans); } }
1	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 = (int)c.charValue(); seen.put(ci,((seen.get(ci) == null)?1:(seen.get(ci) + 1))); } HashMap<Integer,Integer> sub = new HashMap<Integer,Integer>();  int start = 0;  int min = 10000000; for ( int i = 0;(i < n);i++) { Character c = s.charAt(i);  int ci = (int)c.charValue(); sub.put(ci,((sub.get(ci) == null)?1:(sub.get(ci) + 1))); while((sub.size() == seen.size())){min = Math.min(min,((i - start) + 1)); c = s.charAt(start); start++; ci = (int)c.charValue(); if ( (sub.get(ci) == 1)) sub.remove(ci); else sub.put(ci,(sub.get(ci) - 1)); }}System.out.print(min); in.close(); } }
3	public class maestro{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int N = sc.nextInt();  long mod = ((long)Math.pow(10,9) + 7);  long[][] arr = new long[N][N]; arr[0][0] = 1; for ( int i = 1;(i < N);i++) { char c = sc.next().charAt(0); if ( (c == 'f')) {for ( int j = 1;(j < N);j++) arr[i][j] = arr[(i - 1)][(j - 1)]; } else { long sum = 0; for ( int j = (N - 1);(j >= 0);j--) {sum = ((sum + arr[(i - 1)][j]) % mod); arr[i][j] = sum; }}} long ans = 0; for ( int i = 0;(i < N);i++) ans = ((ans + arr[(N - 1)][i]) % mod); System.out.println(ans); } }
1	public class C46{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int number = in.nextInt();  String s = in.next();  int cH = 0;  int n = s.length(); for ( int i = 0;(i < n);i++) if ( (s.charAt(i) == 'H')) cH++;  String ss = ""; for ( int i = 0;(i < cH);i++) ss += "H"; for ( int i = 0;(i < (n - cH));i++) ss += "T"; int res = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int cur = countDifference(ss,s); res = Math.min(res,cur); ss = (ss.substring(1) + ss.charAt(0)); }System.out.println(res); } public static int countDifference( String ss, String s){ int cnt = 0; for ( int i = 0;(i < ss.length());i++) if ( (ss.charAt(i) != s.charAt(i))) cnt++; return (cnt / 2);} }
1	public class CF364C{ public static void main( String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  PrintWriter pw = new PrintWriter(System.out);  int n = Integer.parseInt(br.readLine());  String input = br.readLine();  Set<Character> set = new HashSet<Character>(); for ( int i = 0;(i < input.length());i++) {set.add(input.charAt(i)); } StringBuilder sb = new StringBuilder(); for ( char x :set) {sb.append(x); } String substring1 = sb.toString(); System.out.println(solve(input,substring1).length()); pw.close(); br.close(); } public static String solve( String S, String T){ HashMap<Character,Integer> D = new HashMap<>();  HashMap<Character,Integer> GET = new HashMap<>();  int B ,E ; for ( int i = 0;(i < T.length());i++) { char c = T.charAt(i); if ( !D.containsKey(c)) {D.put(c,1); } else {D.put(c,(D.get(c) + 1)); }} int ccc = 0; B = 0; E = 0; int min = Integer.MAX_VALUE;  String RESULT = ""; while((E < S.length())){ char c = S.charAt(E); if ( D.containsKey(c)) {if ( GET.containsKey(c)) {if ( (GET.get(c) < D.get(c))) ccc++; GET.put(c,(GET.get(c) + 1)); } else {GET.put(c,1); ccc++; }} if ( (ccc == T.length())) { char test = S.charAt(B); while((!GET.containsKey(test) || (GET.get(test) > D.get(test)))){if ( (GET.containsKey(test) && (GET.get(test) > D.get(test)))) GET.put(test,(GET.get(test) - 1)); B++; test = S.charAt(B); }if ( (((E - B) + 1) < min)) {RESULT = S.substring(B,(E + 1)); min = ((E - B) + 1); } } E++; }return RESULT;} }
5	public class A{ static class House{ int x ,a ; } public static void main(final String[] args){ final Scanner in = new Scanner(System.in); final PrintWriter out = new PrintWriter(System.out); try{final int n = in.nextInt(); final int t = in.nextInt(); final House[] h = new House[n]; for ( int i = 0;(i < h.length);++i) {h[i] = new House(); h[i].x = in.nextInt(); h[i].a = in.nextInt(); }Arrays.sort(h,new Comparator<House>(){}); int ans = 2; for ( int i = 1;(i < n);++i) {final int dspace = (((2 * h[i].x) - h[i].a) - ((2 * h[(i - 1)].x) + h[(i - 1)].a)); if ( (dspace == (2 * t))) {++ans; } else if ( (dspace > (2 * t))) {ans += 2; } }out.println(ans); }finally{in.close(); out.close(); }} }
2	public class Main{ public static void main( String[] args)throws IOException { new Main().run(); } StreamTokenizer in ; PrintWriter out ; long nextLong()throws IOException { in.nextToken(); return (long)in.nval;} void run()throws IOException { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); out.flush(); } @SuppressWarnings void solve()throws IOException { BufferedReader re = new BufferedReader(new InputStreamReader(System.in));  Scanner sc = new Scanner(System.in);  long n = sc.nextLong(),k = sc.nextLong(); if ( (((k * (k - 1)) / 2) < (n - 1))) System.out.println("-1"); else { long ff = ((k * (k - 1)) / 2); ff = (-2 * ((n - 1) - ff)); long up = k,dw = 0; while(((up - dw) > 1)){ long c = ((up + dw) / 2); if ( ((c * (c - 1)) <= ff)) dw = c; else up = c; }if ( (n == 1)) {System.out.println("0"); return ;} System.out.println((k - dw)); }} }
3	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);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ private final int MOD = (int)(1e9 + 7); public void solve( int testNumber, FastScanner in, PrintWriter out){ int n = in.nextInt();  String[] arr = new String[n]; for ( int i = 0;(i < n);i++) {arr[i] = in.nextString(); } int[] dp = new int[n]; Arrays.parallelSetAll(dp,(i)->0); dp[0] = 1; int cnt = 0; for ( int i = 0;(i < n);i++) {if ( arr[i].equals("f")) {cnt++; continue;} calc(dp,n,cnt); cnt = 0; } int sum = 0; for ( int i = 0;(i < n);i++) {sum += dp[i]; sum %= MOD; }out.println(sum); } private void calc( int[] dp, int n, int cnt){ for ( int i = (n - 1);(i >= 0);i--) {if ( (i != (n - 1))) dp[i] += dp[(i + 1)]; dp[i] %= MOD; } int[] tmp = new int[n]; for ( int i = 0;(i < n);i++) {tmp[((i + cnt) % n)] = dp[i]; }Arrays.parallelSetAll(dp,(i)->tmp[i]); } } static class FastScanner{ private BufferedReader br ; private StringTokenizer st ; public FastScanner( File f){ try{br = new BufferedReader(new FileReader(f)); }catch (FileNotFoundException e){ e.printStackTrace(); } } public FastScanner( InputStream f){ br = new BufferedReader(new InputStreamReader(f)); } public String nextString(){ while(((st == null) || !st.hasMoreTokens())){ String s = null; try{s = br.readLine(); }catch (IOException e){ e.printStackTrace(); } if ( (s == null)) return null; st = new StringTokenizer(s); }return st.nextToken();} public int nextInt(){ return Integer.parseInt(nextString());} } }
5	public class Main{ static PrintWriter out ; static StreamTokenizer in ; static int next()throws Exception { in.nextToken(); return (int)in.nval;} public static void main( String[] args)throws Exception { out = new PrintWriter(System.out); in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int n = next();  int t = (2 * next());  int[] x = new int[n];  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {x[i] = ((2 * next()) + 2000); a[i] = next(); } int[] srt = new int[n]; for ( int i = 0;(i < n);i++) srt[i] = ((10000 * x[i]) + a[i]); Arrays.sort(srt); for ( int i = 0;(i < n);i++) {x[i] = (srt[i] / 10000); a[i] = (srt[i] % 10000); } int answ = 2; for ( int i = 0;(i < (n - 1));i++) {if ( ((x[(i + 1)] - x[i]) > ((a[i] + a[(i + 1)]) + t))) answ++; if ( ((x[(i + 1)] - x[i]) >= ((a[i] + a[(i + 1)]) + t))) answ++; }out.println(answ); out.close(); } }
4	public class Main{ public static void main( String[] args)throws IOException { InputStream input = System.in;  OutputStream output = System.out;  InputReader in = new InputReader(new FileReader(new File("input.txt")));  PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));  Solution s = new Solution(); s.solve(1,in,out); out.close(); } static class Solution{ static int[][] grid ; static int[] dx = {0,0,1,-1}; static int[] dy = {1,-1,0,0}; static int n ,m ; public void solve( int cs, InputReader in, PrintWriter out){ n = in.nextInt(); m = in.nextInt(); int k = in.nextInt(); grid = new int[n][m]; for ( int[] d :grid) Arrays.fill(d,-1); for ( int i = 0;(i < k);i++) { Pair tree = new Pair((in.nextInt() - 1),(in.nextInt() - 1)); bfs(tree); } int max = 0,idx1 = 0,idx2 = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (grid[i][j] > max)) {max = grid[i][j]; idx1 = i; idx2 = j; } }}out.printf("%d %d%n",(idx1 + 1),(idx2 + 1)); } public boolean isValid( int i, int j){ return ((((i >= 0) && (i < n)) && (j >= 0)) && (j < m));} static class Pair{ int x ,y ; public Pair( int x, int y){ this.x = x; this.y = y; } } public void bfs( Pair src){ Queue<Pair> q = new LinkedList<>(); grid[src.x][src.y] = 0; q.add(src); while(!q.isEmpty()){ Pair p = q.poll(); for ( int k = 0;(k < 4);k++) { int nx = (p.x + dx[k]);  int ny = (p.y + dy[k]); if ( isValid(nx,ny)) {if ( ((grid[nx][ny] > (grid[p.x][p.y] + 1)) || (grid[nx][ny] == -1))) {grid[nx][ny] = (grid[p.x][p.y] + 1); q.add(new Pair(nx,ny)); } } }}} } static class InputReader{ BufferedReader br ; StringTokenizer st ; public InputReader( InputStream i){ br = new BufferedReader(new InputStreamReader(i),32768); st = null; } public InputReader( FileReader s){ br = new BufferedReader(s); st = null; } 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());} } }
6	public class Main{ static final int MOD = ((int)1e9 + 7); static int n ; static int[] t ; static int[] g ; static int[][] memo ; static int dp( int mask, int rem, int last){ if ( (rem == 0)) return 1; if ( (memo[last][mask] != -1)) return memo[last][mask]; int ans = 0; for ( int i = 0;(i < n);i++) {if ( ((((mask & (1 << i)) == 0) && (rem >= t[i])) && (g[i] != last))) ans += dp((mask | (1 << i)),(rem - t[i]),g[i]); if ( (ans >= MOD)) ans -= MOD; }return memo[last][mask] = ans;} public static void main( String[] args)throws java.lang.Exception { InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream); n = in.nextInt(); int T = in.nextInt(); t = new int[n]; g = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = in.nextInt(); g[i] = (in.nextInt() - 1); }memo = new int[4][(1 << n)]; for ( int[] x :memo) {Arrays.fill(x,-1); }out.println(dp(0,T,3)); out.close(); } static class InputReader{ BufferedReader reader ; 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());} } }
2	public class B176{ public static void main( String[] args){ Scanner in = new Scanner(new BufferedInputStream(System.in));  PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));  long n = (in.nextLong() - 1);  long k = (in.nextLong() - 1); if ( (((k * (k + 1)) / 2) < n)) out.println(-1); else if ( (n == 0)) out.println(0); else if ( (n < k)) out.println(1); else { long t = binSearch(n,k,1,k);  long ans = ((k - t) + 1); if ( ((((k * (k + 1)) / 2) - ((t * (t - 1)) / 2)) != n)) ans++; out.println(ans); }out.close(); } static private long binSearch( long n, long k, long from, long to){ if ( (from == to)) return from; long mid = ((from + to) / 2); if ( ((((k * (k + 1)) / 2) - ((mid * (mid - 1)) / 2)) > n)) return binSearch(n,k,(mid + 1),to); else return binSearch(n,k,from,mid);} }
1	public class Solution{ public static void main( String[] args)throws IOException { PrintWriter pw = new PrintWriter(System.out);  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  StringTokenizer st = new StringTokenizer(br.readLine());  int n = Integer.parseInt(st.nextToken());  int k = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); String str = st.nextToken();  char[] arr = str.toCharArray(); Arrays.sort(arr); int weight = (arr[0] - 96);  char a = arr[0];  int included = 1; for ( int i = 1;(i < arr.length);++i) {if ( (included == k)) break; char c = arr[i]; if ( ((c - a) < 2)) continue; weight += (arr[i] - 96); ++included; a = arr[i]; }if ( (included == k)) pw.println(weight); else pw.println(-1); pw.close(); } }
4	public class Main{ static class Run implements Runnable{ final boolean consoleIO = false; final String inFile = "input.txt"; final String outFile = "output.txt"; int n ,m ,k ; int[][] field ; boolean[][] visited ; LinkedList<Point> queue ; int[][] steps = {{0,1},{1,0},{0,-1},{-1,0}}; void wave(){ for ( Point p :queue) visited[p.y][p.x] = true; while(!queue.isEmpty()){ Point cur = queue.removeFirst(); for ( int i = 0;(i < steps.length);++i) { Point tmp = new Point((cur.x + steps[i][0]),(cur.y + steps[i][1])); if ( (ok(tmp) && !visited[tmp.y][tmp.x])) {queue.add(tmp); visited[tmp.y][tmp.x] = true; field[tmp.y][tmp.x] = (field[cur.y][cur.x] + 1); } }}} boolean ok( Point p){ return ((((p.x >= 0) && (p.y >= 0)) && (p.x < n)) && (p.y < m));} @Override public void run(){ n = nextInt(); m = nextInt(); k = nextInt(); queue = new LinkedList<Point>(); for ( int i = 0;(i < k);++i) queue.add(new Point((nextInt() - 1),(nextInt() - 1))); field = new int[m][n]; visited = new boolean[m][n]; wave(); Point maxP = new Point(0,0);  int maxV = Integer.MIN_VALUE; for ( int i = 0;(i < m);++i) for ( int j = 0;(j < n);++j) if ( (field[i][j] > maxV)) {maxV = field[i][j]; maxP = new Point(j,i); } print((((maxP.x + 1) + " ") + (maxP.y + 1))); close(); } BufferedReader in ; PrintWriter out ; StringTokenizer strTok ; Run(){ if ( consoleIO) {initConsoleIO(); } else {initFileIO(); }} void initConsoleIO(){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); } void initFileIO(){ try{in = new BufferedReader(new FileReader(inFile)); out = new PrintWriter(new FileWriter(outFile)); }catch (FileNotFoundException e){ e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } } void close(){ try{in.close(); out.close(); }catch (IOException e){ e.printStackTrace(); } } int nextInt(){ return Integer.parseInt(nextToken());} boolean hasMoreTokens(){ return ((strTok == null) || strTok.hasMoreTokens());} String nextToken(){ while(((strTok == null) || !strTok.hasMoreTokens())){ String line ; try{line = in.readLine(); strTok = new StringTokenizer(line); }catch (IOException e){ e.printStackTrace(); } }return strTok.nextToken();} void print( Object o){ out.write(o.toString()); } void println( Object o){ out.write((o.toString() + '\n')); } void printf( String format, Object... args){ out.printf(format,args); } } public static void main( String[] args)throws IOException { Run run = new Run();  Thread thread = new Thread(run); thread.run(); } }
1	public class C{ public static void main( String[] args){ InputReader in = new InputReader(System.in);  PrintWriter out = new PrintWriter(System.out);  Solver solver = new Solver(); solver.solve(in,out); out.close(); } static class Solver{ public void solve( InputReader in, PrintWriter out){ int n = in.nextInt();  String s = in.next();  HashMap<Character,Integer> map = new HashMap<>(); for ( int i = 0;(i < n);++i) {map.put(s.charAt(i),0); } int l = 0,r = 0,cnt = 0,ans = n;  char c ; while((l < n)){while(((r < n) && (cnt < map.size()))){c = s.charAt(r); map.put(c,(map.get(c) + 1)); if ( (map.get(c) == 1)) ++cnt; ++r; }if ( ((cnt == map.size()) && ((r - l) < ans))) ans = (r - l); c = s.charAt(l); map.put(c,(map.get(c) - 1)); if ( (map.get(c) == 0)) --cnt; ++l; }out.println(ans); } } static class InputReader{ BufferedReader reader ; StringTokenizer tokenizer ; public InputReader( InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream)); } 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());} } }
5	public class Main{ static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tok ; static boolean hasNext(){ while(((tok == null) || !tok.hasMoreTokens()))try{tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return false;} return true;} static String next(){ hasNext(); return tok.nextToken();} static int nextInt(){ return Integer.parseInt(next());} static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); public static void main( String[] args){ Map<Integer,Integer> map = new HashMap(); map.put(0,1); int n = nextInt();  int m = nextInt();  int index = -1;  int a[] = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); if ( (a[i] == m)) index = i; } int sum = 0; for ( int i = 0;(i < index);i++) {if ( (a[i] < m)) sum--; else sum++; if ( map.containsKey(sum)) {map.put(sum,(map.get(sum) + 1)); } else {map.put(sum,1); }} long ans = 0; for ( int i = index;(i < n);i++) {if ( (a[i] < m)) sum--; else if ( (a[i] > m)) sum++; if ( map.containsKey(sum)) ans += map.get(sum); if ( map.containsKey((sum - 1))) ans += map.get((sum - 1)); }out.print(ans); out.flush(); } }
4	public class Solution{ static int[] dx = {1,-1,0,0}; static int[] dy = {0,0,1,-1}; static Queue<Pair> q ; static boolean[][] visited ; static Pair result = new Pair(0,0); static int n ,m ,k ; public static void main( String[] args){ try(BufferedReader in=new BufferedReader(new FileReader("input.txt"));BufferedWriter out=new BufferedWriter(new FileWriter("output.txt"))){ StringTokenizer s = new StringTokenizer(in.readLine()); n = Integer.parseInt(s.nextToken()); m = Integer.parseInt(s.nextToken()); k = Integer.parseInt(in.readLine()); visited = new boolean[n][m]; q = new LinkedList<>(); s = new StringTokenizer(in.readLine()); for ( int i = 0;(i < k);i++) { int x = Integer.parseInt(s.nextToken());  int y = Integer.parseInt(s.nextToken()); q.add(new Pair(--x,--y)); }bfs(); String ans = ((("" + (result.x + 1)) + " ") + (result.y + 1)); out.write(ans); }catch (IOException e){ } } static void bfs(){ while(!q.isEmpty()){ Pair temp = q.poll(); if ( visited[temp.x][temp.y]) continue; visited[temp.x][temp.y] = true; result.x = temp.x; result.y = temp.y; for ( int i = 0;(i < 4);i++) { int x = (temp.x + dx[i]);  int y = (temp.y + dy[i]); if ( (((((x >= 0) && (x < n)) && (y >= 0)) && (y < m)) && !visited[x][y])) q.add(new Pair(x,y)); }}} } class Pair{ int x ,y ; public Pair( int x, int y){ this.x = x; this.y = y; } }
5	public class p15a{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int t = in.nextInt(); if ( (n == 1)) {System.out.println(2); return ;} house[] all = new house[n]; for ( int i = 0;(i < all.length);i++) {all[i] = new house(in.nextInt(),in.nextInt()); }Arrays.sort(all); int count = 0; for ( int i = 0;(i < all.length);i++) { double left = (all[i].center - ((all[i].side * 1.0) / 2));  double right = (all[i].center + ((all[i].side * 1.0) / 2)); if ( (i == 0)) {count++; double left2 = (all[(i + 1)].center - ((all[(i + 1)].side * 1.0) / 2)); if ( ((right + t) < left2)) {count++; } continue;} if ( (i == (all.length - 1))) {count++; double right2 = (all[(i - 1)].center + ((all[(i - 1)].side * 1.0) / 2)); if ( ((left - t) >= right2)) {count++; } continue;} double left2 = (all[(i + 1)].center - ((all[(i + 1)].side * 1.0) / 2));  double right2 = (all[(i - 1)].center + ((all[(i - 1)].side * 1.0) / 2)); if ( ((right + t) < left2)) {count++; } if ( ((left - t) >= right2)) count++; }System.out.println(count); } } class house implements Comparable<house>{ int center ; int side ; public house( int a, int b){ center = a; side = b; } }
5	public class c{ public static void main( String[] args)throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in),1);  String s = r.readLine();  int n = Integer.parseInt(s);  String s2 = r.readLine();  StringTokenizer st = new StringTokenizer(s2," ");  int a[] = new int[n]; for ( int i = 0;(i < n);i++) a[i] = Integer.parseInt(st.nextToken()); Arrays.sort(a); if ( (a[(n - 1)] == 1)) a[(n - 1)] = 2; else {a[(n - 1)] = 1; Arrays.sort(a); }for ( int i = 0;(i < n);i++) System.out.println(a[i]); } }
4	public class Codes{ public static void main( String[] args)throws IOException { InputReader input = new InputReader(new FileReader("input.txt"));  int n = input.nextInt();  int m = input.nextInt();  int k = input.nextInt();  boolean[][] visited = new boolean[n][m];  Queue<Point> bfs = new LinkedList<Point>(); for ( int i = 0;(i < k);i++) { int x = input.nextInt();  int y = input.nextInt(); visited[(x - 1)][(y - 1)] = true; bfs.add(new Point((x - 1),(y - 1))); } Point last = bfs.peek(); while(!bfs.isEmpty()){ Point current = bfs.poll();  int curX = current.x;  int curY = current.y; if ( ((curX - 1) >= 0)) {if ( !visited[(curX - 1)][curY]) {bfs.add(new Point((curX - 1),curY)); visited[(curX - 1)][curY] = true; } } if ( ((curY + 1) < m)) {if ( !visited[curX][(curY + 1)]) {bfs.add(new Point(curX,(curY + 1))); visited[curX][(curY + 1)] = true; } } if ( ((curX + 1) < n)) {if ( !visited[(curX + 1)][curY]) {bfs.add(new Point((curX + 1),curY)); visited[(curX + 1)][curY] = true; } } if ( ((curY - 1) >= 0)) {if ( !visited[curX][(curY - 1)]) {bfs.add(new Point(curX,(curY - 1))); visited[curX][(curY - 1)] = true; } } if ( (bfs.peek() != null)) last = bfs.peek(); } PrintWriter out = new PrintWriter(new File("output.txt")); out.println((((last.x + 1) + " ") + (last.y + 1))); out.close(); } static class Point{ int x ; int y ; public Point( int x2, int y2){ x = x2; y = y2; } } static class InputReader{ private BufferedReader reader ; private StringTokenizer tokenizer ; public InputReader( InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public InputReader( FileReader stream){ reader = new BufferedReader(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());} } }
5	public class A{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int n = scan.nextInt();  int t = scan.nextInt();  List<List<Double>> coords = new ArrayList<List<Double>>(); while((n-- > 0)){ double x = scan.nextDouble();  double a = (scan.nextDouble() / 2); coords.add(Arrays.asList((x - a),(x + a))); }Collections.sort(coords,new Comparator<List<Double>>(){}); int count = 2;  ChoiceFormat f = new ChoiceFormat("-1#0|0#1|0<2"); for ( int i = 0;(i < (coords.size() - 1));i++) { double l = ((coords.get((i + 1)).get(0) - coords.get(i).get(1)) - t); count += new Integer(f.format(l)); }System.out.println(count); } }
4	public class Main implements Runnable{ BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void mergeSort( int[] a){ mergeSort(a,0,(a.length - 1)); } static private void mergeSort( int[] a, int leftIndex, int rightIndex){ final int MAGIC_VALUE = 50; if ( (leftIndex < rightIndex)) {if ( ((rightIndex - leftIndex) <= MAGIC_VALUE)) {insertionSort(a,leftIndex,rightIndex); } else { int middleIndex = ((leftIndex + rightIndex) / 2); mergeSort(a,leftIndex,middleIndex); mergeSort(a,(middleIndex + 1),rightIndex); merge(a,leftIndex,middleIndex,rightIndex); }} } static private void merge( int[] a, int leftIndex, int middleIndex, int rightIndex){ int length1 = ((middleIndex - leftIndex) + 1);  int length2 = (rightIndex - middleIndex);  int[] leftArray = new int[length1];  int[] rightArray = new int[length2]; System.arraycopy(a,leftIndex,leftArray,0,length1); System.arraycopy(a,(middleIndex + 1),rightArray,0,length2); for ( int k = leftIndex,i = 0,j = 0;(k <= rightIndex);k++) {if ( (i == length1)) {a[k] = rightArray[j++]; } else if ( (j == length2)) {a[k] = leftArray[i++]; } else {a[k] = ((leftArray[i] <= rightArray[j])?leftArray[i++]:rightArray[j++]); }}} static private void insertionSort( int[] a, int leftIndex, int rightIndex){ for ( int i = (leftIndex + 1);(i <= rightIndex);i++) { int current = a[i];  int j = (i - 1); while(((j >= leftIndex) && (a[j] > current))){a[(j + 1)] = a[j]; j--; }a[(j + 1)] = current; }} public static void main( String[] args){ new Main().run(); } public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println(("Time = " + (t2 - t1))); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } int mini = Integer.MAX_VALUE; int maxi = Integer.MIN_VALUE; int ans = 0; int ans2 = 0; int sum = 0; void solve()throws IOException { int n = readInt();  int m = readInt();  int maxi = 0;  int[][] a = new int[n][m];  int k = readInt();  ArrayDeque<Point> dq = new ArrayDeque<Point>();  Point p = new Point(); for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) {a[i][j] = Integer.MAX_VALUE; }for ( int i = 0;(i < k);i++) { int x = (readInt() - 1);  int y = (readInt() - 1); p.x = x; p.y = y; dq.add(new Point(x,y)); a[x][y] = 0; }while(!dq.isEmpty()){ Point v = dq.pollFirst();  Point u = new Point(); if ( ((v.x - 1) != -1)) {if ( (a[(v.x - 1)][v.y] > (a[v.x][v.y] + 1))) {a[(v.x - 1)][v.y] = (a[v.x][v.y] + 1); maxi = max(maxi,a[(v.x - 1)][v.y]); u.x = (v.x - 1); u.y = v.y; dq.add(new Point(u.x,u.y)); } } if ( ((v.y - 1) != -1)) {if ( (a[v.x][(v.y - 1)] > (a[v.x][v.y] + 1))) {a[v.x][(v.y - 1)] = (a[v.x][v.y] + 1); maxi = max(maxi,a[v.x][(v.y - 1)]); u.y = (v.y - 1); u.x = v.x; dq.add(new Point(u.x,u.y)); } } if ( ((v.x + 1) != n)) {if ( (a[(v.x + 1)][v.y] > (a[v.x][v.y] + 1))) {a[(v.x + 1)][v.y] = (a[v.x][v.y] + 1); maxi = max(maxi,a[(v.x + 1)][v.y]); u.x = (v.x + 1); u.y = v.y; dq.add(new Point(u.x,u.y)); } } if ( ((v.y + 1) != m)) {if ( (a[v.x][(v.y + 1)] > (a[v.x][v.y] + 1))) {a[v.x][(v.y + 1)] = (a[v.x][v.y] + 1); maxi = max(maxi,a[v.x][(v.y + 1)]); u.y = (v.y + 1); u.x = v.x; dq.add(new Point(u.x,u.y)); } } }for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) {if ( (maxi == a[i][j])) {out.print((((i + 1) + " ") + (j + 1))); return ;} }} char c[] ; void per( int left, int right){ if ( (left == right)) {for ( int i = 0;(i <= right);i++) {out.print(c[i]); }out.println(); } else {for ( int i = left;(i <= right);i++) { char k = c[left]; c[left] = c[i]; c[i] = k; per((left + 1),right); k = c[left]; c[left] = c[i]; c[i] = k; }}} }
6	public class G{ static private int M = 1000000007,MM = 998244353; static private int N = 15,n ,T ; static private int[] time ,gi ; static private int[][][] dp ; public static void process()throws IOException { n = sc.nextInt(); T = sc.nextInt(); time = new int[(n + 1)]; gi = new int[(n + 1)]; for ( int i = 0;(i < n);i++) { int a = sc.nextInt(),b = sc.nextInt(); time[i] = a; gi[i] = (b - 1); }dp = new int[(1 << n)][(T + 1)][3]; for ( int i = 0;(i < (1 << n));i++) {for ( int j = 0;(j < (T + 1));j++) {for ( int k = 0;(k < 3);k++) dp[i][j][k] = -1; }} int ans = 0; for ( int i = 0;(i < n);i++) {if ( (time[i] <= T)) {ans = ((ans + solve((1 << i),time[i],gi[i])) % M); } }println(ans); } static private int solve( int mask, int tim, int code){ if ( (tim == T)) return 1; if ( (dp[mask][tim][code] != -1)) return dp[mask][tim][code]; int ans = 0; for ( int i = 0;(i < n);i++) {if ( (((mask >> i) & 1) > 0)) continue; if ( (code == gi[i])) continue; if ( ((tim + time[i]) > T)) continue; ans = ((ans + solve((mask | (1 << i)),(time[i] + tim),gi[i])) % M); }return dp[mask][tim][code] = (ans % M);} static FastScanner sc ; static PrintWriter out ; public static void main( String[] args)throws IOException { boolean oj = true; if ( oj) {sc = new FastScanner(); out = new PrintWriter(System.out); } else {sc = new FastScanner(100); out = new PrintWriter("output.txt"); } int t = 1; while((t-- > 0)){process(); }out.flush(); out.close(); } static void println( Object o){ out.println(o); } static void println(){ out.println(); } static void print( Object o){ out.print(o); } static int max( int x, int y){ return Math.max(x,y);} static int min( int x, int y){ return Math.min(x,y);} static int abs( int x){ return Math.abs(x);} static long abs( long x){ return Math.abs(x);} static long max( long x, long y){ return Math.max(x,y);} static long min( long x, long y){ return Math.min(x,y);} public static int gcd( int a, int b){ BigInteger b1 = BigInteger.valueOf(a);  BigInteger b2 = BigInteger.valueOf(b);  BigInteger gcd = b1.gcd(b2); return gcd.intValue();} public static long gcd( long a, long b){ BigInteger b1 = BigInteger.valueOf(a);  BigInteger b2 = BigInteger.valueOf(b);  BigInteger gcd = b1.gcd(b2); return gcd.longValue();} static class FastScanner{ BufferedReader br ; StringTokenizer st ; FastScanner()throws FileNotFoundException{ br = new BufferedReader(new InputStreamReader(System.in)); } FastScanner( int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt")); } String next()throws IOException { while(((st == null) || !st.hasMoreElements())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(next());} long nextLong()throws IOException { return Long.parseLong(next());} } }
5	public class ProblemA{ private void solve()throws IOException { Scanner stdin = new Scanner(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));  int n = Integer.valueOf(stdin.nextInt());  int[] p = new int[n]; for ( int i = 0;(i < n);i++) {p[i] = stdin.nextInt(); }Arrays.sort(p); if ( (p[(n - 1)] == 1)) {p[(n - 1)] = 2; } else {p[(n - 1)] = 1; out.print((p[(n - 1)] + " ")); n--; }for ( int i = 0;(i < n);i++) {out.print((p[i] + " ")); }out.flush(); out.close(); } public static void main( String[] args)throws IOException { ProblemA solver = new ProblemA(); solver.solve(); } }
5	public class village{ static int[] X ,A ; public void solve(){ Scanner in = new Scanner(System.in);  int N = in.nextInt(),T = in.nextInt(); X = new int[N]; A = new int[N]; for ( int i = 0;(i < N);i++) {X[i] = in.nextInt(); A[i] = in.nextInt(); }if ( (N == 1)) {System.out.println("2"); return ;} List<Integer> x = new ArrayList<Integer>(); for ( int i = 0;(i < N);i++) {x.add(i); }Collections.sort(x,new Comp()); int places = 0; for ( int i = 0;(i < (N - 1));i++) { double space = (((X[x.get((i + 1))] - X[x.get(i)]) - (A[x.get((i + 1))] / 2.0)) - (A[x.get(i)] / 2.0)); if ( (space < T)) {continue;} if ( ((space - T) < 1e-9)) {places++; } else if ( (space > T)) {places += 2; } }System.out.println((places + 2)); } public class Comp implements Comparator<Integer>{ } public static void main( String[] args){ new village().solve(); } }
2	public class A{ BufferedReader in ; PrintWriter out ; StringTokenizer st ; public String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(in.readLine()); }catch (Exception e){ } }return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} int n ,x ,y ,c ; long cnt( int m){ long ret = 0; for ( int i = max(1,(y - m));(i <= min(n,(y + m)));i++) { int x1 = max(1,(x - (m - abs((i - y)))));  int x2 = min(n,(x + (m - abs((i - y))))); ret += ((x2 - x1) + 1); }return ret;} public void run(){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); n = nextInt(); x = nextInt(); y = nextInt(); c = nextInt(); int l = 0,r = 1000000;  int ans = 0; while((l <= r)){ int m = ((l + r) / 2); if ( (cnt(m) >= c)) {ans = m; r = (m - 1); } else l = (m + 1); }out.println(ans); out.close(); } int sign( long x){ if ( (x < 0)) return -1; if ( (x > 0)) return 1; return 0;} public static void main( String[] args)throws Exception { new A().run(); } }
5	public class TaskA{ BufferedReader br ; PrintWriter out ; StringTokenizer stok ; String nextToken()throws IOException { while(((stok == null) || !stok.hasMoreTokens())){ String s = br.readLine(); if ( (s == null)) {return "-1";} stok = new StringTokenizer(s); }return stok.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} void solve()throws IOException { int n = nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); }Arrays.sort(a); a[(n - 1)] = ((a[(n - 1)] == 1)?2:1); Arrays.sort(a); for ( int i = 0;(i < n);i++) {out.print(a[i]); out.print(' '); }} void run()throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); br.close(); out.close(); } public static void main( String[] args)throws IOException { new TaskA().run(); } }
3	public class C{ static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main( String[] args){ int n = in.nextInt();  int[] sol = new int[n]; sol[0] = 1; int mod = 1000000007;  int maxind = 0;  boolean f = true; for ( int i = 0;(i < n);i++) {if ( !f) {for ( int j = 1;(j <= maxind);j++) {sol[j] += sol[(j - 1)]; sol[j] %= mod; }} if ( in.next().equals("f")) {maxind++; f = true; } else {f = false; }} int ans = 0; for ( int i = 0;(i <= maxind);i++) {ans += sol[i]; ans %= mod; }out.println(ans); finish(); } public static void finish(){ out.close(); in.close(); System.exit(0); } static class InputReader implements Iterator<String>,Closeable{ private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; public InputReader( InputStream i){ r = new BufferedReader(new InputStreamReader(i)); } public int nextInt(){ return Integer.parseInt(nextToken());} public String next(){ return nextToken();} public void close(){ try{r.close(); }catch (IOException e){ } } private String peekToken(){ if ( (token == null)) try{while(((st == null) || !st.hasMoreTokens())){line = r.readLine(); if ( (line == null)) return null; st = new StringTokenizer(line); }token = st.nextToken(); }catch (IOException e){ } return token;} private String nextToken(){ String ans = peekToken(); token = null; return ans;} } }
5	public class Main{ BufferedReader in ; PrintWriter out ; StringTokenizer st ; void solve()throws IOException { int n = ni();  int t = ni();  int[] center = new int[n];  int[] width = new int[n]; for ( int i = 0;(i < n);i++) {center[i] = ni(); width[i] = ni(); }for ( int i = 0;(i < n);i++) {for ( int j = i;(j < n);j++) {if ( (center[i] > center[j])) { int cent = center[i];  int wid = width[i]; center[i] = center[j]; width[i] = width[j]; center[j] = cent; width[j] = wid; } }} int count = 2; for ( int i = 0;(i < (n - 1));i++) { double ideal = ((((double)width[i] / 2) + ((double)width[(i + 1)] / 2)) + t);  double real = (center[(i + 1)] - center[i]); if ( (ideal == real)) count++; else {if ( (ideal < real)) count = (count + 2); }}out.println(count); } public Main()throws IOException{ Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } String ns()throws IOException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(in.readLine()); }return st.nextToken();} int ni()throws IOException { return Integer.valueOf(ns());} public static void main( String[] args)throws IOException { new Main(); } }
3	public class PythInd{ public static final int MOD = 1000000007; public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = Integer.parseInt(sc.nextLine());  String[] sTypes = new String[n]; for ( int i = 0;(i < n);i++) {sTypes[i] = sc.nextLine(); }sc.close(); int[][] dp = new int[n][n]; dp[0][0] = 1; for ( int i = 0;(i < (dp.length - 1));i++) {if ( sTypes[i].equals("s")) { int curSum = 0; for ( int j = (i + 1);(j >= 0);j--) {curSum = ((dp[i][j] + curSum) % MOD); dp[(i + 1)][j] += curSum; dp[(i + 1)][j] %= MOD; }} else {for ( int j = 1;(j <= (i + 1));j++) {dp[(i + 1)][j] += dp[i][(j - 1)]; dp[(i + 1)][j] %= MOD; }}} int ans = 0; for ( int i = 0;(i < dp[0].length);i++) {ans = ((ans + dp[(n - 1)][i]) % MOD); }System.out.println(ans); } }
0	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()); if ( (n == 0)) {System.out.println("0 0 0"); return ;} int p2 = 0;  int p1 = 1; while(true){ int now = (p2 + p1); if ( (n == now)) {System.out.println(((("0 " + p1) + " ") + p2)); return ;} else {p2 = p1; p1 = now; }}} }
0	public class two_squares{ public static void main( String[] args)throws Exception { new two_squares().run(); } public void run()throws Exception { FastIO file = new FastIO();  double x1 = file.nextInt();  double y1 = file.nextInt();  double x2 = file.nextInt();  double y2 = file.nextInt();  double x3 = file.nextInt();  double y3 = file.nextInt();  double x4 = file.nextInt();  double y4 = file.nextInt();  double minx1 ,maxx1 ,miny1 ,maxy1 ; minx1 = Math.min(x1,Math.min(x2,Math.min(x3,x4))); maxx1 = Math.max(x1,Math.max(x2,Math.max(x3,x4))); miny1 = Math.min(y1,Math.min(y2,Math.min(y3,y4))); maxy1 = Math.max(y1,Math.max(y2,Math.max(y3,y4))); double x5 = file.nextInt();  double y5 = file.nextInt();  double x6 = file.nextInt();  double y6 = file.nextInt();  double x7 = file.nextInt();  double y7 = file.nextInt();  double x8 = file.nextInt();  double y8 = file.nextInt();  double minx2 ,maxx2 ,miny2 ,maxy2 ; minx2 = Math.min(x5,Math.min(x6,Math.min(x7,x8))); maxx2 = Math.max(x5,Math.max(x6,Math.max(x7,x8))); miny2 = Math.min(y5,Math.min(y6,Math.min(y7,y8))); maxy2 = Math.max(y5,Math.max(y6,Math.max(y7,y8))); Point _1 ,_2 ,_3 ,_4 ,_5 ,_6 ,_7 ,_8 ,_9 ,_10 ,_11 ,_12 ,_13 ,_14 ,_15 ,_16 ; _1 = new Point(x1,y1); _2 = new Point(x2,y2); _3 = new Point(x3,y3); _4 = new Point(x4,y4); _5 = new Point(x5,y5); _6 = new Point(x6,y6); _7 = new Point(x7,y7); _8 = new Point(x8,y8); _9 = new Point(minx1,maxy1); _10 = new Point(minx1,miny1); _11 = new Point(maxx1,maxy1); _12 = new Point(maxx1,miny1); double m1 = ((minx2 + maxx2) / 2);  double m2 = ((miny2 + maxy2) / 2); _13 = new Point(minx2,m2); _14 = new Point(m1,miny2); _15 = new Point(maxx2,m2); _16 = new Point(m1,maxy2); Point[] a = {_1,_2,_3,_4};  Point[] b = {_5,_6,_7,_8};  boolean works = false;  Line[] aa = {new Line(_9,_10),new Line(_10,_12),new Line(_12,_11),new Line(_11,_9)};  Line[] bb = {new Line(_13,_14),new Line(_14,_15),new Line(_15,_16),new Line(_16,_13)}; for ( int i = 0;(i < 4);i++) {for ( int j = 0;(j < 4);j++) {if ( (aa[i].intersection(bb[i]) != null)) {works = true; } }}for ( Point p :b) {if ( ((((p.x >= minx1) && (p.x <= maxx1)) && (p.y >= miny1)) && (p.y <= maxy1))) {works = true; } }for ( Point p :a) { boolean result = false; for ( int i = 0,j = (b.length - 1);(i < b.length);j = i++) {if ( (((b[i].y > p.y) != (b[j].y > p.y)) && (p.x < ((((b[j].x - b[i].x) * (p.y - b[i].y)) / (b[j].y - b[i].y)) + b[i].x)))) {result = !result; } }if ( result) works = true; }System.out.println((works?"YES":"NO")); } public static class Point{ double x ,y ; public Point( double a, double b){ x = a; y = b; } } public static class Line{ Point a ,b ; public Line( Point x, Point y){ a = x; b = y; } public Point intersection( Line o){ double x1 = a.x;  double y1 = a.y;  double x2 = b.x;  double y2 = b.y;  double x3 = o.a.x;  double y3 = o.a.y;  double x4 = o.b.x;  double y4 = o.b.y;  double denom = (((y4 - y3) * (x2 - x1)) - ((x4 - x3) * (y2 - y1)));  double ua = ((((x4 - x3) * (y1 - y3)) - ((y4 - y3) * (x1 - x3))) / denom);  double ub = ((((x2 - x1) * (y1 - y3)) - ((y2 - y1) * (x1 - x3))) / denom); if ( ((((ua >= 0.0f) && (ua <= 1.0f)) && (ub >= 0.0f)) && (ub <= 1.0f))) {return new Point((int)(x1 + (ua * (x2 - x1))),(int)(y1 + (ua * (y2 - y1))));} return null;} } public static class FastIO{ BufferedReader br ; StringTokenizer st ; public FastIO(){ 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());} } public static long pow( long n, long p, long mod){ if ( (p == 0)) return 1; if ( (p == 1)) return (n % mod); if ( ((p % 2) == 0)) { long temp = pow(n,(p / 2),mod); return ((temp * temp) % mod);} else { long temp = pow(n,(p / 2),mod); temp = ((temp * temp) % mod); return ((temp * n) % mod);}} public static long pow( long n, long p){ if ( (p == 0)) return 1; if ( (p == 1)) return n; if ( ((p % 2) == 0)) { long temp = pow(n,(p / 2)); return (temp * temp);} else { long temp = pow(n,(p / 2)); temp = (temp * temp); return (temp * n);}} public static long gcd( long x, long y){ if ( (x == 0)) return y; else return gcd((y % x),x);} }
0	public class A{ public static void main( String[] args)throws FileNotFoundException { Scanner s = new Scanner(System.in);  int T = s.nextInt(); System.out.println(("0 0 " + T)); } }
2	public class B{ public static final boolean DEBUG = false; Scanner sc ; public void pln( Object o){ System.out.println(o); } long getNumber( int x, int y, int n, int m){ int n1 = Math.max(0,((x + m) - n));  int n2 = Math.max(0,((y + m) - n));  int n3 = Math.max(0,(1 - (x - m)));  int n4 = Math.max(0,(1 - (y - m)));  int n12 = Math.max(0,(((n1 + n2) - m) - 1));  int n23 = Math.max(0,(((n2 + n3) - m) - 1));  int n34 = Math.max(0,(((n3 + n4) - m) - 1));  int n41 = Math.max(0,(((n4 + n1) - m) - 1));  int m1 = (m + 1);  long nr = ((1 + (((long)m1 * m1) * 2)) - (m1 * 2)); nr -= (((((long)n1 * n1) + ((long)n2 * n2)) + ((long)n3 * n3)) + ((long)n4 * n4)); nr += ((((((long)n12 * (n12 + 1)) / 2) + (((long)n23 * (n23 + 1)) / 2)) + (((long)n34 * (n34 + 1)) / 2)) + (((long)n41 * (n41 + 1)) / 2)); return nr;} public void run(){ sc = new Scanner(System.in); int n = sc.nextInt();  int x = sc.nextInt();  int y = sc.nextInt();  int c = sc.nextInt(); if ( (c <= 1)) {pln(0); return ;} int ll = 0;  int rr = ((2 * n) + 20); while(true){ int m = ((ll + rr) / 2); if ( (getNumber(x,y,n,m) >= c)) {rr = m; } else {ll = m; }if ( ((rr - ll) < 3)) {for ( int m2 = ll;(m2 <= rr);m2++) {if ( (getNumber(x,y,n,m2) >= c)) {pln(m2); return ;} }} }} public static void main( String[] args){ B t = new B(); t.run(); } }
1	public class Main{ public static void main( String[] args)throws IOException { new Thread(null,new Runnable(){public void run(){ try{try{if ( new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt"));  }catch (SecurityException e){ } new Main().run(); }catch (IOException e){ e.printStackTrace(); } } },"1",(1L << 24)).start(); } BufferedReader in ; PrintWriter out ; StringTokenizer st = new StringTokenizer(""); int N ; int[] a ; int[] b ; int[] c ; int T ,H ; void run()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); N = nextInt(); char[] s = nextToken().toCharArray(); a = new int[N]; H = 0; T = 0; for ( int i = 0;(i < s.length);i++) {a[i] = ((s[i] == 'T')?1:0); if ( (s[i] == 'T')) T++; else H++; }if ( ((T == 1) || (H == 1))) {out.println(0); out.close(); return ;} b = Arrays.copyOf(a,a.length); c = Arrays.copyOf(a,a.length); sort(c); int ans = 100000000; for ( int o = 0;(o < N);o++) {for ( int i = 0;(i < N);i++) b[((i + o) % N)] = a[i]; int cur = 0; for ( int i = 0;(i < N);i++) if ( (b[i] != c[i])) cur++; ans = min(ans,(cur / 2)); }out.println(ans); out.close(); } String nextToken()throws IOException { while(!st.hasMoreTokens()){st = new StringTokenizer(in.readLine()); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
4	public class Cbeta35{ public static void main( String[] args){ new Cbeta35(); } Scanner in ; PrintWriter out ; int t ; int n ,m ,k ,oo ; int[][] grid ; boolean debug = !true,multi = !true; Cbeta35(){ if ( multi) t = in.nextInt(); do {if ( multi) if ( z(t--)) break; try{in = new Scanner(new File("input.txt")); out = new PrintWriter(new File("output.txt")); }catch (Exception e){ in = new Scanner(System.in); out = new PrintWriter(System.out); } n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); oo = ((n + m) + 1); grid = new int[n][m]; for ( int i = 0;(i < n);i++) Arrays.fill(grid[i],oo); for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); for ( int j = 0;(j < n);j++) for ( int kk = 0;(kk < m);kk++) { int dx = (((j - x) < 0)?(x - j):(j - x));  int dy = (((kk - y) < 0)?(y - kk):(kk - y)); grid[j][kk] = min(grid[j][kk],(dx + dy)); }} int x = 0,y = 0;  int max = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (max < grid[i][j])) {max = grid[i][j]; x = i; y = j; } out.printf("%d %d%n",(x + 1),(y + 1)); }while((debug || multi));out.close(); } int min( int a, int b){ if ( (a < b)) return a; return b;} long min( long a, long b){ if ( (a < b)) return a; return b;} boolean z( int x){ if ( (x == 0)) return true; return false;} boolean z( long x){ if ( (x == 0)) return true; return false;} void sort( int[] arr){ int szArr = arr.length;  Random r = new Random(); for ( int i = 0;(i < szArr);i++) { int j = r.nextInt(szArr); arr[i] = (arr[j] ^ (arr[i] ^ (arr[j] = arr[i]))); }Arrays.sort(arr); } }
4	public class Pjar{ static int a[][] ; public static void main( String[] args)throws FileNotFoundException { Scanner in = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter("output.txt");  int N = in.nextInt();  int M = in.nextInt(); a = new int[N][M]; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < M);j++) {a[i][j] = Integer.MAX_VALUE; }} int k = in.nextInt(); in.nextLine(); for ( int i = 0;(i < k);i++) { int x = in.nextInt();  int y = in.nextInt(); a[(x - 1)][(y - 1)] = 1; burn((x - 1),(y - 1)); } int max = Integer.MIN_VALUE;  int x = 0;  int y = 0; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < M);j++) {if ( (a[i][j] > max)) {max = a[i][j]; x = (i + 1); y = (j + 1); } }}out.printf("%d %d",x,y); out.close(); in.close(); } static void burn( int i, int j){ for ( int k = 0;(k < a.length);k++) {for ( int l = 0;(l < a[k].length);l++) {if ( (a[k][l] > (Math.abs((k - i)) + Math.abs((l - j))))) {a[k][l] = (Math.abs((k - i)) + Math.abs((l - j))); } }}} }
4	public class practice{ public static void main( String[] args)throws FileNotFoundException { Scanner scn = new Scanner(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt"));  int n = scn.nextInt(),m = scn.nextInt(),k = scn.nextInt();  int[][] inf = new int[k][2]; for ( int i = 0;(i < k);i++) {inf[i][0] = scn.nextInt(); inf[i][1] = scn.nextInt(); } int ans = 0,x = 1,y = 1; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) { int temp = Integer.MAX_VALUE; for ( int l = 0;(l < k);l++) {temp = Math.min(temp,(Math.abs((i - inf[l][0])) + Math.abs((j - inf[l][1])))); }if ( (temp > ans)) {ans = temp; x = i; y = j; } }}out.print(((x + " ") + y)); out.close(); } }
0	public class Main{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  long n = in.nextLong(); out.println(((((0 + " ") + 0) + " ") + n)); in.close(); out.close(); } }
2	public class Main{ long sum( long n){ return ((n * (n + 1)) / 2);} public void solve()throws Exception { Scanner in = new Scanner(System.in);  long n = (in.nextLong() - 1);  long k = (in.nextLong() - 1);  long lo = 0,hi = k,mi ; while((lo < hi)){mi = ((lo + hi) / 2); if ( ((sum(k) - sum(((k - mi) - 1))) <= n)) lo = (mi + 1); else hi = mi; } long ans = lo; n -= (sum(k) - sum((k - ans))); k -= ans; if ( (n > k)) println("-1"); else if ( (n == 0)) println(ans); else println((ans + 1)); } public static void main( String[] args)throws Exception { new Main().solve(); } public static void print( Object o){ System.out.print(o); } public static void println( Object o){ System.out.println(o); } public static void println(){ System.out.println(); } }
1	public class First{ StreamTokenizer in ; PrintWriter out ; int nextInt()throws IOException { in.nextToken(); return (int)in.nval;} String nextString()throws IOException { in.nextToken(); return in.sval;} void run()throws IOException { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); solve(); out.flush(); } void solve()throws IOException { int n = nextInt(),k = nextInt(),sum = 0,count = 0;  String str = nextString();  char[] arr = str.toCharArray();  boolean[] bool = new boolean[26]; for ( char ch :arr) {bool[((int)ch - 97)] = true; }for ( int i = 0;(i < 26);i++) {if ( bool[i]) {sum += (i + 1); count++; i += 1; } if ( (count == k)) break; }if ( (count == k)) out.println(sum); else out.println(-1); } public static void main( String[] args)throws IOException { new First().run(); } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} PandaScanner in = new PandaScanner(inputStream);  PrintWriter out = new PrintWriter(outputStream);  C solver = new C(); solver.solve(1,in,out); out.close(); } } class C{ final int dx[] = {-1,0,1,0}; final int dy[] = {0,-1,0,1}; final int SHIFT = 15; final int COLUMN_MASK = ((1 << SHIFT) - 1); public void solve( int testNumber, PandaScanner in, PrintWriter out){ int n = in.nextInt();  int m = in.nextInt();  boolean burning[][] = new boolean[n][m];  int k = in.nextInt();  ArrayDeque<Integer> q = new ArrayDeque<>(); for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); burning[x][y] = true; q.add(((x << SHIFT) + y)); } int last = 0; while(!q.isEmpty()){last = q.poll(); int x = (last >> SHIFT);  int y = (last & COLUMN_MASK); for ( int d = 0;(d < 4);d++) { int nx = (x + dx[d]);  int ny = (y + dy[d]); if ( (((((nx >= 0) && (nx < n)) && (ny >= 0)) && (ny < m)) && !burning[nx][ny])) {burning[nx][ny] = true; q.add(((nx << SHIFT) + ny)); } }}out.printf("%d %d\n",((last >> SHIFT) + 1),((last & COLUMN_MASK) + 1)); } } class PandaScanner{ public BufferedReader br ; public StringTokenizer st ; public InputStream in ; public PandaScanner( InputStream in){ br = new BufferedReader(new InputStreamReader(this.in = in)); } public String nextLine(){ try{return br.readLine(); }catch (Exception e){ return null;} } public String next(){ if ( ((st == null) || !st.hasMoreTokens())) {st = new StringTokenizer(nextLine().trim()); return next();} return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} }
2	public class B2{ public static void main( String[] args)throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  String line = reader.readLine();  StringTokenizer tokenizer = new StringTokenizer(line);  long n = Long.parseLong(tokenizer.nextToken());  long k = Long.parseLong(tokenizer.nextToken()); if ( (n == 1)) {System.out.println("0"); return ;} if ( (n <= k)) {System.out.println("1"); return ;} long first = 0;  long end = k;  long mid ; while((first < end)){mid = (first + ((end - first) / 2)); if ( is_exist(n,k,(mid - 1))) {end = mid; } else {first = (mid + 1); }}if ( is_exist(n,k,(end - 1))) {System.out.println(end); return ;} System.out.println("-1"); return ;} static boolean is_exist( long n, long k, long x){ long res = (n - (((((k - 1) + k) - x) * (((k - 1) - (k - x)) + 1)) / 2)); if ( (res <= (k - x))) {return true;} return false;} }
1	public class Cf2207C{ static private InputReader in = new InputReader(System.in); static private OutputWriter out = new OutputWriter(System.out); static private void solve()throws Exception { int n = in.readInt();  String s = in.readString();  int[] count = new int[200];  boolean[] flag = new boolean[200]; for ( int i = 0;(i < n);++i) {flag[s.charAt(i)] = true; } int ref = 0; for ( int i = 0;(i < 200);++i) {if ( flag[i]) {ref++; } } int total = 0;  int min = Integer.MAX_VALUE;  int j = 0; for ( int i = 0;(i < n);++i) {if ( ((j == n) && (total < ref))) {break;} if ( (total == ref)) {min = Math.min(min,(j - i)); count[s.charAt(i)]--; if ( (count[s.charAt(i)] == 0)) {total--; } continue;} for ( ;(j < n);++j) {count[s.charAt(j)]++; if ( (count[s.charAt(j)] == 1)) {total++; } if ( (total == ref)) {min = Math.min(min,((j - i) + 1)); j++; break;} }count[s.charAt(i)]--; if ( (count[s.charAt(i)] == 0)) {total--; } }out.println(min); } public static void main( String[] args)throws Exception { solve(); out.close(); } static private class InputReader{ private InputStream stream ; private byte[] buffer ; private int currentIndex ; private int bytesRead ; public InputReader( InputStream stream){ this.stream = stream; buffer = new byte[16384]; } public InputReader( InputStream stream, int bufferSize){ this.stream = stream; buffer = new byte[bufferSize]; } private int read()throws IOException { if ( (currentIndex >= bytesRead)) {currentIndex = 0; bytesRead = stream.read(buffer); if ( (bytesRead <= 0)) {return -1;} } return buffer[currentIndex++];} public String readString()throws IOException { int c = read(); while(!isPrintable(c)){c = read(); } StringBuilder result = new StringBuilder(); do {result.appendCodePoint(c); c = read(); }while(isPrintable(c));return result.toString();} public int readInt()throws Exception { int c = read();  int sign = 1; while(!isPrintable(c)){c = read(); }if ( (c == '-')) {sign = -1; c = read(); } int result = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} result *= 10; result += (c - '0'); c = read(); }while(isPrintable(c));return (sign * result);} private boolean isPrintable( int c){ return ((c > 32) && (c < 127));} } static private class OutputWriter{ private PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void print( Object... objects){ for ( int i = 0;(i < objects.length);i++) {if ( (i != 0)) {writer.print(' '); } writer.print(objects[i]); }} public void println( Object... objects){ print(objects); writer.println(); } public void close(){ writer.close(); } public void flush(){ writer.flush(); } } }
4	public class Main{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new FileReader("input.txt"));  StringBuilder out = new StringBuilder();  StringTokenizer tk ;  PrintWriter pw = new PrintWriter("output.txt","UTF-8");  int[] dx = {-1,1,0,0},dy = {0,0,-1,1}; tk = new StringTokenizer(in.readLine()); int n = parseInt(tk.nextToken()),m = parseInt(tk.nextToken());  int k = parseInt(in.readLine());  int[][] dist = new int[n][m]; for ( int i = 0;(i < n);i++) Arrays.fill(dist[i],-1); int ans = -1,atx = -1,aty = -1;  Queue<point> q = new LinkedList<point>(); tk = new StringTokenizer(in.readLine()); while((k-- > 0)){ int x = (parseInt(tk.nextToken()) - 1),y = (parseInt(tk.nextToken()) - 1); dist[x][y] = 0; q.add(new point(x,y)); }while(!q.isEmpty()){ point p = q.remove(); if ( (dist[p.x][p.y] > ans)) {ans = dist[p.x][p.y]; atx = (p.x + 1); aty = (p.y + 1); } for ( int i = 0;(i < 4);i++) { int nx = (p.x + dx[i]);  int ny = (p.y + dy[i]); if ( (((((nx >= 0) && (nx < n)) && (ny >= 0)) && (ny < m)) && (dist[nx][ny] == -1))) {dist[nx][ny] = (dist[p.x][p.y] + 1); q.add(new point(nx,ny)); } }}pw.println(((atx + " ") + aty)); pw.close(); } } class point{ int x ,y ; public point( int x, int y){ this.x = x; this.y = y; } }
5	public class A{ private Scanner in ; private PrintWriter out ; public void solve(){ int n = ni();  int t = ni();  Pair[] p = new Pair[n]; for ( int i = 0;(i < n);i++) {p[i] = new Pair(); p[i].x = ni(); p[i].a = ni(); }Arrays.sort(p); int ct = 2; for ( int i = 0;(i < (n - 1));i++) { float d = (((p[(i + 1)].x - ((float)p[(i + 1)].a / 2)) - p[i].x) - ((float)p[i].a / 2)); if ( (Math.abs((d - t)) < EPS)) {ct++; } else if ( (d > t)) {ct += 2; } }out.println(ct); } double EPS = 0.0001; static private class Pair implements Comparable<Pair>{ public int x ; public int a ; } public void run()throws Exception { in = new Scanner(System.in); System.setOut(new PrintStream(new BufferedOutputStream(System.out))); out = new PrintWriter(System.out); int n = 1; for ( int i = 1;(i <= n);i++) { long t = System.currentTimeMillis(); solve(); out.flush(); }} public static void main( String[] args)throws Exception { new A().run(); } private int ni(){ return Integer.parseInt(in.next());} }
6	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);  F solver = new F(); solver.solve(1,in,out); out.close(); } static class F{ public void solve( int testNumber, FastScanner in, PrintWriter out){ int n = in.ni(),m = in.ni();  int[][] a = new int[n][m]; for ( int i = 0;(i < n);i++) {a[i] = in.na(m); }if ( (n == 1)) { int ans = Integer.MAX_VALUE; for ( int i = 1;(i < m);i++) {ans = Math.min(ans,Math.abs((a[0][i] - a[0][(i - 1)]))); }out.println(ans); return ;} int[][] mk = new int[n][n];  int[][] mk1 = new int[n][n]; for ( int i = 0;(i < n);i++) {for ( int j = (i + 1);(j < n);j++) { int minK = Integer.MAX_VALUE;  int minK1 = Integer.MAX_VALUE;  int minK2 = Integer.MAX_VALUE; for ( int l = 0;(l < m);l++) {minK = Math.min(minK,Math.abs((a[i][l] - a[j][l]))); if ( (l > 0)) {minK1 = Math.min(minK1,Math.abs((a[i][l] - a[j][(l - 1)]))); minK2 = Math.min(minK2,Math.abs((a[i][(l - 1)] - a[j][l]))); } }mk[i][j] = mk[j][i] = minK; mk1[i][j] = minK1; mk1[j][i] = minK2; }} int ans = 0; for ( int first = 0;(first < n);first++) { int[][] dp = new int[(1 << n)][n]; for ( int mask = 1;(mask < ((1 << n) - 1));mask++) { int bc = Integer.bitCount(mask); if ( ((mask & (1 << first)) != 0)) {if ( (bc == 1)) {dp[mask][first] = Integer.MAX_VALUE; } for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) != 0)) {for ( int j = 0;(j < n);j++) {if ( ((mask & (1 << j)) == 0)) {dp[(mask | (1 << j))][j] = Math.max(dp[(mask | (1 << j))][j],Math.min(dp[mask][i],mk[i][j])); } }} }} }for ( int i = 0;(i < n);i++) {if ( (i != first)) {ans = Math.max(ans,Math.min(dp[((1 << n) - 1)][i],mk1[first][i])); } }}out.println(ans); } } static class FastScanner{ private BufferedReader in ; private StringTokenizer st ; public FastScanner( InputStream stream){ in = new BufferedReader(new InputStreamReader(stream)); } public String ns(){ 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 ni(){ return Integer.parseInt(ns());} public int[] na( int n){ int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = ni(); return a;} } }
3	public class C{ public static void main( String[] args){ FastScanner scan = new FastScanner();  PrintWriter out = new PrintWriter(System.out); n = scan.nextInt(); mod = ((int)1e9 + 7); in = new char[n]; for ( int i = 0;(i < n);i++) in[i] = scan.next().charAt(0); dp = new Long[n][n]; out.println(go(0,0)); out.close(); } static long go( int at, int i){ if ( (at == (n - 1))) return 1; if ( (dp[at][i] != null)) return dp[at][i]; long res = 0; if ( (in[at] == 's')) {res += go((at + 1),i); res %= mod; if ( (i > 0)) {res += go(at,(i - 1)); res %= mod; } } else {res += go((at + 1),(i + 1)); res %= mod; }return dp[at][i] = res;} static Long[][] dp ; static int n ,mod ; static char[] in ; static class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner(){ try{br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); }catch (Exception e){ e.printStackTrace(); } } public String next(){ if ( st.hasMoreTokens()) return st.nextToken(); try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ e.printStackTrace(); } return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} public long nextLong(){ return Long.parseLong(next());} public double nextDouble(){ return Double.parseDouble(next());} } }
2	@SuppressWarnings("unused") public class round176B{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st = new StringTokenizer(""); static String next()throws Exception { while(true){if ( st.hasMoreTokens()) {return st.nextToken();} String s = br.readLine(); if ( (s == null)) {return null;} st = new StringTokenizer(s); }} public static void main( String[] args)throws Exception { long n = parseLong(next());  long k = parseLong(next()); if ( (n == 1)) {System.out.println(0); return ;} if ( (n <= k)) {System.out.println(1); return ;} if ( (((((k * (k + 1)) / 2) - 1) - (k - 2)) < n)) {System.out.println(-1); } else { long lo = 1;  long hi = (k + 1);  int best = Integer.MAX_VALUE; while((lo < hi)){ long mid = (lo + ((hi - lo) / 2));  long first = (((mid * (2 + (2 + (mid - 1)))) / 2) - (mid - 1));  long last = (((mid * (((k - mid) + 1) + k)) / 2) - (mid - 1)); if ( (n < first)) {hi = mid; } else {if ( ((n >= first) && (n <= last))) {hi = mid; best = min(best,(int)mid); } else lo = (mid + 1); }}System.out.println(best); }} }
3	public class utkarsh{ BufferedReader br ; void solve(){ br = new BufferedReader(new InputStreamReader(System.in)); int i ,j ,n ,mod = (int)(1e9 + 7); n = ni(); char c[] = new char[n]; for ( i = 0;(i < n);i++) c[i] = ns().charAt(0); long dp[][] = new long[n][n]; dp[0][0] = 1; for ( i = 1;(i < n);i++) {if ( (c[(i - 1)] == 'f')) {for ( j = 0;(j < i);j++) {dp[i][(j + 1)] = dp[(i - 1)][j]; }} else {for ( j = (i - 1);(j >= 0);j--) {dp[i][j] = (dp[(i - 1)][j] + dp[i][(j + 1)]); dp[i][j] %= mod; }}} long ans = 0; for ( long x :dp[(n - 1)]) {ans += x; ans %= mod; }System.out.println(ans); } int ni(){ return Integer.parseInt(ns());} String ip[] ; int len ,sz ; String ns(){ if ( (len >= sz)) {try{ip = br.readLine().split(" "); len = 0; sz = ip.length; }catch (IOException e){ throw (new InputMismatchException());} if ( (sz <= 0)) return "-1"; } return ip[len++];} public static void main( String[] args){ new utkarsh().solve(); } }
4	public class CF035C{ public static void main( String[] args)throws IOException { Scanner s = new Scanner(new File("input.txt"));  int n = s.nextInt();  int m = s.nextInt();  int k = s.nextInt();  Queue<pair> q = new LinkedList<>();  PrintWriter out = new PrintWriter(new FileWriter("output.txt"));  boolean[][] visited = new boolean[n][m]; for ( int i = 0;(i < k);i++) { int x = (s.nextInt() - 1);  int y = (s.nextInt() - 1); visited[x][y] = true; pair p = new pair(x,y); q.add(p); }q.add(null); int[] dx = {0,0,1,-1};  int[] dy = {1,-1,0,0};  int ansX = q.peek().x;  int ansY = q.peek().y; while(true){if ( (q.peek() == null)) {q.poll(); q.add(null); } pair p = q.poll(); if ( (p == null)) {break;} for ( int i = 0;(i < 4);i++) {if ( (isValid((p.x + dx[i]),(p.y + dy[i]),n,m) && !visited[(p.x + dx[i])][(p.y + dy[i])])) {q.add(new pair((p.x + dx[i]),(p.y + dy[i]))); ansX = (p.x + dx[i]); ansY = (p.y + dy[i]); visited[ansX][ansY] = true; } }}out.println((((ansX + 1) + " ") + (ansY + 1))); out.close(); } public static boolean isValid( int x, int y, int n, int m){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} static private class pair{ int x ; int y ; public pair( int x, int y){ this.x = x; this.y = y; } } }
6	public class Main{ public static void main( String[] args)throws Exception { Thread thread = new Thread(null,new TaskAdapter(),"",(1 << 27)); thread.start(); thread.join(); } static class TaskAdapter implements Runnable{ } static class FElongatedMatrix{ public void solve( int testNumber, FastInput in, FastOutput out){ int n = in.readInt();  int m = in.readInt();  int[][] mat = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {mat[i][j] = in.readInt(); }} int[][] minDist = new int[n][n]; SequenceUtils.deepFill(minDist,(int)1e9); for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < m);k++) {minDist[i][j] = Math.min(minDist[i][j],Math.abs((mat[i][k] - mat[j][k]))); }}} int[][] minDistBetweenHeadAndTail = new int[n][n]; SequenceUtils.deepFill(minDistBetweenHeadAndTail,(int)1e9); for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {for ( int k = 1;(k < m);k++) {minDistBetweenHeadAndTail[i][j] = Math.min(minDistBetweenHeadAndTail[i][j],Math.abs((mat[i][k] - mat[j][(k - 1)]))); }}} Log2 log2 = new Log2();  BitOperator bo = new BitOperator();  int[][][] dp = new int[(1 << n)][n][n]; for ( int i = 1;(i < (1 << n));i++) {if ( (i == Integer.lowestOneBit(i))) {dp[i][log2.floorLog(i)][log2.floorLog(i)] = (int)1e9; continue;} for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < n);k++) {if ( (bo.bitAt(i,j) == 0)) {continue;} for ( int t = 0;(t < n);t++) {dp[i][j][k] = Math.max(dp[i][j][k],Math.min(dp[bo.setBit(i,j,false)][t][k],minDist[j][t])); }}}} int ans = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {ans = Math.max(ans,Math.min(dp[((1 << n) - 1)][i][j],minDistBetweenHeadAndTail[j][i])); }}out.println(ans); } } static class Log2{ public int floorLog( int x){ return (31 - Integer.numberOfLeadingZeros(x));} } static class FastInput{ private final InputStream is ; private byte[] buf = new byte[(1 << 13)]; private int bufLen ; private int bufOffset ; private int next ; public FastInput( InputStream is){ this.is = is; } private int read(){ while((bufLen == bufOffset)){bufOffset = 0; try{bufLen = is.read(buf); }catch (IOException e){ bufLen = -1; } if ( (bufLen == -1)) {return -1;} }return buf[bufOffset++];} public void skipBlank(){ while(((next >= 0) && (next <= 32))){next = read(); }} public int readInt(){ int sign = 1; skipBlank(); if ( ((next == '+') || (next == '-'))) {sign = ((next == '+')?1:-1); next = read(); } int val = 0; if ( (sign == 1)) {while(((next >= '0') && (next <= '9'))){val = (((val * 10) + next) - '0'); next = read(); }} else {while(((next >= '0') && (next <= '9'))){val = (((val * 10) - next) + '0'); next = read(); }}return val;} } static class BitOperator{ public int bitAt( int x, int i){ return ((x >> i) & 1);} public int setBit( int x, int i, boolean v){ if ( v) {x |= (1 << i); } else {x &= (1 << i); }return x;} } static class FastOutput implements AutoCloseable,Closeable{ private StringBuilder cache = new StringBuilder((10 << 20)); private final Writer os ; public FastOutput( Writer os){ this.os = os; } public FastOutput( OutputStream os){ this(new OutputStreamWriter(os)); } public FastOutput println( int c){ cache.append(c).append('\n'); return this;} public FastOutput flush(){ try{os.append(cache); os.flush(); cache.setLength(0); }catch (IOException e){ throw (new UncheckedIOException(e));} return this;} public void close(){ flush(); try{os.close(); }catch (IOException e){ throw (new UncheckedIOException(e));} } public String toString(){ return cache.toString();} } }
5	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 x = sc.nextInt();  int a = sc.nextInt();  double l = (x - ((double)a / 2));  double r = (x + ((double)a / 2)); left[i] = l; right[i] = r; } int answer = 2; quickSort(left,right,0,(n - 1)); for ( int i = 0;(i < (n - 1));i++) {if ( ((left[(i + 1)] - right[i]) == t)) {answer++; } if ( ((left[(i + 1)] - right[i]) > t)) {answer += 2; } }System.out.println(answer); } int partition( double[] arr, int left, int right){ int i = left,j = right;  double tmp ;  double pivot = arr[((left + right) / 2)]; while((i <= j)){while((arr[i] < pivot))i++; while((arr[j] > pivot))j--; if ( (i <= j)) {tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; } };return i;} void quickSort( double[] arr, int left, int right){ int index = partition(arr,left,right); if ( (left < (index - 1))) quickSort(arr,left,(index - 1)); if ( (index < right)) quickSort(arr,index,right); } static int partition( double[] arr, double[] arr2, int left, int right){ int i = left,j = right;  double tmp ;  double tmp2 ;  double pivot = arr[((left + right) / 2)]; while((i <= j)){while((arr[i] < pivot))i++; while((arr[j] > pivot))j--; if ( (i <= j)) {tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; tmp2 = arr2[i]; arr2[i] = arr2[j]; arr2[j] = tmp2; i++; j--; } };return i;} static void quickSort( double[] arr, double[] arr2, int left, int right){ int index = partition(arr,arr2,left,right); if ( (left < (index - 1))) quickSort(arr,arr2,left,(index - 1)); if ( (index < right)) quickSort(arr,arr2,index,right); } }
4	public class C35C_BFS_Fire{ public static boolean[][] burning ; public static LinkedList<int[]> LitTrees ; public static int N ,M ; public static int[] lastTree ; public static void main( String[] args)throws IOException { BufferedReader input = new BufferedReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));  StringTokenizer dataR = new StringTokenizer(input.readLine()); N = Integer.parseInt(dataR.nextToken()); M = Integer.parseInt(dataR.nextToken()); burning = new boolean[(N + 1)][(M + 1)]; StringTokenizer dataR1 = new StringTokenizer(input.readLine());  int K = Integer.parseInt(dataR1.nextToken());  StringTokenizer dataR2 = new StringTokenizer(input.readLine()); LitTrees = new LinkedList<int[]>(); for ( int j = 0;(j < K);j++) { int x = Integer.parseInt(dataR2.nextToken());  int y = Integer.parseInt(dataR2.nextToken());  int[] coord = {x,y}; LitTrees.add(coord); burning[x][y] = true; }spread(); out.println(((lastTree[0] + " ") + lastTree[1])); out.close(); } public static void spread(){ while(!LitTrees.isEmpty()){ int[] studying = LitTrees.removeFirst();  int[] studying1 = {(studying[0] - 1),studying[1]};  int[] studying2 = {studying[0],(studying[1] - 1)};  int[] studying3 = {studying[0],(studying[1] + 1)};  int[] studying4 = {(studying[0] + 1),studying[1]}; if ( ((studying1[0] >= 1) && !burning[studying1[0]][studying1[1]])) {LitTrees.add(studying1); burning[studying1[0]][studying1[1]] = true; } if ( ((studying2[1] >= 1) && !burning[studying2[0]][studying2[1]])) {LitTrees.add(studying2); burning[studying2[0]][studying2[1]] = true; } if ( ((studying3[1] < (M + 1)) && !burning[studying3[0]][studying3[1]])) {LitTrees.add(studying3); burning[studying3[0]][studying3[1]] = true; } if ( ((studying4[0] < (N + 1)) && !burning[studying4[0]][studying4[1]])) {LitTrees.add(studying4); burning[studying4[0]][studying4[1]] = true; } lastTree = studying; }} }
3	public class PhytonIndenter{ static private Scanner scanner = new Scanner(System.in); static private int lineCount ; static private String[] commands ; public static void main( String[] args){ lineCount = scanner.nextInt(); scanner.nextLine(); commands = new String[lineCount]; for ( int i = 0;(i < lineCount);i++) {commands[i] = scanner.nextLine(); }resolveWithDP(); } static private void resolveWithDP(){ long dp[][] = new long[lineCount][5002];  long mod = 1000000007; dp[0][0] = 1; for ( int i = 1;(i < lineCount);i++) {if ( "f".equalsIgnoreCase(commands[(i - 1)])) {dp[i][0] = 0; for ( int j = 1;(j <= i);j++) {dp[i][j] = dp[(i - 1)][(j - 1)]; }} else { long sum = 0; for ( int j = (i - 1);(j >= 0);j--) {sum += (dp[(i - 1)][j] % mod); dp[i][j] = sum; }}} long result = 0; for ( int i = 0;(i < lineCount);i++) {result += (dp[(lineCount - 1)][i] % mod); result %= mod; }System.out.println((result % mod)); } }
1	public class Main{ InputStreamReader inp = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(inp); boolean test = false; String[] inData = {"9","HTHTHTHHT"}; static int id = -1; public String readLine()throws IOException { id++; if ( test) return inData[id]; else return in.readLine();} public Main()throws Throwable{ int animalNr = Integer.valueOf(readLine());  String animals = readLine();  boolean[] state = new boolean[animalNr];  int tigerCount = 0; for ( int i = 0;(i < animals.length());i++) {if ( ('T' == animals.charAt(i))) {state[i] = true; tigerCount++; } } int best = Integer.MAX_VALUE; for ( int i = 0;(i < state.length);i++) { int swaps = 0; for ( int j = i;(j < (i + tigerCount));j++) {if ( (state[(j % animalNr)] == false)) {swaps++; } }if ( (swaps < best)) {best = swaps; } }System.out.println(best); } public static void main( String[] args)throws Throwable { new Main(); } }
5	public class A implements Runnable{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { if ( ONLINE_JUDGE) {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"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new Thread(null,new A(),"",(256 * (1L << 20))).start(); } void solve()throws IOException { int n = readInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = readInt(); }Arrays.sort(a); a[(n - 1)] = ((a[(n - 1)] == 1)?2:1); Arrays.sort(a); for ( int i = 0;(i < n);i++) {out.print((a[i] + " ")); }} }
2	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, InputReader in, OutputWriter out){ long n = in.nextLong();  long x = in.nextLong();  long y = in.nextLong();  long c = in.nextLong();  long tl ,tr ,tt = -1,t ; tl = 0; tr = (long)4e9; while((tl < tr)){t = ((tl + tr) >> 1); long cc = f(n,t,x,y); if ( (cc >= c)) {tt = t; tr = t; } else tl = (t + 1); }out.writeln(tt); } public static long f( long n, long t, long x, long y){ long res = (((((t * t) + t) / 2) * 4) + 1);  long s ; if ( ((x - t) < 1)) {s = ((t - x) + 1); res -= (s * s); } if ( ((y - t) < 1)) {s = ((t - y) + 1); res -= (s * s); } if ( ((x + t) > n)) {s = ((x + t) - n); res -= (s * s); } if ( ((y + t) > n)) {s = ((y + t) - n); res -= (s * s); } s = ((t - (Math.abs((x - 1)) + Math.abs((y - 1)))) - 1); if ( (s > 0)) res += (((s * s) + s) / 2); s = ((t - (Math.abs((x - 1)) + Math.abs((n - y)))) - 1); if ( (s > 0)) res += (((s * s) + s) / 2); s = ((t - (Math.abs((n - x)) + Math.abs((n - y)))) - 1); if ( (s > 0)) res += (((s * s) + s) / 2); s = ((t - (Math.abs((n - x)) + Math.abs((y - 1)))) - 1); if ( (s > 0)) res += (((s * s) + s) / 2); return res;} } class InputReader{ private BufferedReader reader ; private 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 long nextLong(){ return Long.parseLong(next());} } class OutputWriter{ private PrintWriter out ; public OutputWriter( Writer out){ this.out = new PrintWriter(out); } public OutputWriter( OutputStream out){ this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out))); } public void write( Object... o){ for ( Object x :o) out.print(x); } public void writeln( Object... o){ write(o); out.println(); } public void close(){ out.close(); } }
5	public class A{ void run(){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int[] a = new int[n];  boolean dif = false; for ( int i = 0;(i < n);i++) a[i] = sc.nextInt(); Arrays.sort(a); if ( (n == 1)) {System.out.println(((a[0] == 1)?2:1)); return ;} int[] m = new int[n]; for ( int i = 1;(i < n);i++) if ( (a[i] != a[(i - 1)])) dif = true; m[0] = 1; for ( int i = 1;(i < n);i++) m[i] = a[(i - 1)]; if ( (!dif && (a[0] == 1))) m[(n - 1)]++; for ( int i = 0;(i < n);i++) System.out.print((m[i] + ((i == (n - 1))?"\n":" "))); } public static void main( String[] args){ new A().run(); } }
4	public class Problem implements Runnable{ static private final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); private BufferedReader in ; private PrintWriter out ; private StringTokenizer tok = new StringTokenizer(""); private void init()throws FileNotFoundException { Locale.setDefault(Locale.US); String fileName = ""; in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } String readString(){ while(!tok.hasMoreTokens()){try{tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null;} }return tok.nextToken();} int readInt(){ return Integer.parseInt(readString());} public static void main( String[] args){ new Problem().run(); } long timeBegin ,timeEnd ; void time(){ timeEnd = System.currentTimeMillis(); System.err.println(("Time = " + (timeEnd - timeBegin))); } @Override public void run(){ try{timeBegin = System.currentTimeMillis(); init(); solve(); out.close(); time(); }catch (Exception e){ e.printStackTrace(); System.exit(-1); } } int[][] dist ; int n ,m ; P v ; ArrayDeque<P> q = new ArrayDeque<>(); private void solve()throws IOException { n = readInt(); m = readInt(); int k = readInt(); dist = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) dist[i][j] = -1; for ( int i = 0;(i < k);i++) { int x = (readInt() - 1),y = (readInt() - 1); dist[x][y] = 0; q.add(new P(x,y)); }bfs(); out.println((((v.x + 1) + " ") + (v.y + 1))); } public void bfs(){ int[] dx = {0,1,0,-1};  int[] dy = {1,0,-1,0}; while(!q.isEmpty()){v = q.poll(); for ( int i = 0;(i < 4);i++) { int nx = (v.x + dx[i]);  int ny = (v.y + dy[i]); if ( (inside(nx,ny) && (dist[nx][ny] == -1))) {q.add(new P(nx,ny)); dist[nx][ny] = (dist[v.x][v.y] + 1); } }}} public boolean inside( int x, int y){ if ( ((((x < n) && (y < m)) && (x >= 0)) && (y >= 0))) {return true;} return false;} } class P{ int x ,y ; public P( int x, int y){ this.x = x; this.y = y; } }
5	public class A{ static class Sort implements Comparable<Sort>{ int x ,a ; } public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  Sort[] a = new Sort[n]; for ( int i = 0;(i < n);i++) {a[i] = new Sort(); a[i].x = sc.nextInt(); a[i].a = sc.nextInt(); }Arrays.sort(a); int ans = 2; for ( int i = 1;(i < n);i++) { double d = (((a[i].x - (a[i].a / 2.0)) - a[(i - 1)].x) - (a[(i - 1)].a / 2.0)); if ( (d == t)) ans++; else if ( (d > t)) ans += 2; }System.out.println(ans); } }
4	public class Main{ public static void main( String[] args)throws IOException,URISyntaxException { Reader.init(new FileInputStream("input.txt")); StringBuilder s = new StringBuilder();  boolean[][] vis = new boolean[Reader.nextInt()][Reader.nextInt()];  int k = Reader.nextInt(),r ,c ;  Queue<Point> q = new LinkedList<Point>(); while((k-- > 0)){r = (Reader.nextInt() - 1); c = (Reader.nextInt() - 1); vis[r][c] = true; q.add(new Point(r,c)); } Point end = null;  int[] x = {0,0,1,-1},y = {1,-1,0,0};  int a ,b ,i ; while(!q.isEmpty()){end = q.poll(); for ( i = 0;(i < 4);i++) {a = (end.x + x[i]); b = (end.y + y[i]); if ( (((((a >= 0) && (b >= 0)) && (a < vis.length)) && (b < vis[a].length)) && !vis[a][b])) {vis[a][b] = true; q.add(new Point(a,b)); } }}s.append((end.x + 1)).append(' ').append((end.y + 1)); PrintWriter p = new PrintWriter("output.txt"); p.println(s); p.close(); } }
4	public class QA{ static long MOD = 1000000007; static boolean b[] ,b1[] ,check ; static ArrayList<Integer>[] amp ,pa ; static ArrayList<Pair>[] amp1 ; static ArrayList<Pair>[][] damp ; static int left[] ,right[] ,end[] ,sum[] ,dist[] ,cnt[] ,start[] ,color[] ,parent[] ,prime[] ,size[] ; static int ans = 0,k ; static int p = 0; static FasterScanner sc = new FasterScanner(System.in); static BufferedWriter log ; static HashSet<Pair> hs ; static HashMap<Pair,Integer> hm ; static PriorityQueue<Integer> pri[] ; static ArrayList<Integer>[] level ; static Stack<Integer> st ; static boolean boo[][] ; static Pair prr[] ; static long parent1[] ,parent2[] ,size1[] ,size2[] ,arr1[] ,SUM[] ,lev[] ,fibo[] ; static int arr[] ,ver[][] ; private static PrintWriter out = new PrintWriter(System.out); public static void main( String[] args)throws Exception { new Thread(null,new Runnable(){},"1",(1 << 26)).start(); } static private boolean oj = (System.getProperty("ONLINE_JUDGE") != null); static int dp[][] ; static int N ,K ,T ,A ,B ; static long time ; static int cost[][] ; static boolean b11[] ; static HashMap<Integer,Integer> h = new HashMap<>(); static HashSet<Pair> chec ; static long ans1 ; static long ans2 ; static int BLOCK ,MAX = 1000001; static double pi = Math.PI; static int Arr[] ,Brr[] ,pow[] ,M ; static long fact[] = new long[(100000 + 1)]; static HashMap<Integer,Long> hm1 ; static HashSet<Integer> hs1[] ,hs2[] ; static String[] str2 ; static char[] ch1 ,ch2 ; static int[] s ,f ,D ; static int tf ,ts ; static int see[][] = new int[2050][2050]; static boolean bee[][] = new boolean[2050][2050]; static Queue<Pair> q = new LinkedList<>(); public static void soln()throws IOException { FasterScanner sc = new FasterScanner(new FileInputStream("input.txt"));  PrintWriter log = new PrintWriter("output.txt");  int n = sc.nextInt(),m = sc.nextInt();  int k = sc.nextInt(); for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= m);j++) see[i][j] = 100000000; for ( int i = 0;(i < k);i++) { int x = sc.nextInt(),y = sc.nextInt(); bee[x][y] = true; see[x][y] = 0; q.add(new Pair(x,y)); }while(!q.isEmpty()){ int x = q.peek().u,y = q.poll().v; if ( (x > 1)) {see[(x - 1)][y] = min((see[x][y] + 1),see[(x - 1)][y]); if ( !bee[(x - 1)][y]) q.add(new Pair((x - 1),y)); bee[(x - 1)][y] = true; } if ( (x < n)) {see[(x + 1)][y] = min((see[x][y] + 1),see[(x + 1)][y]); if ( !bee[(x + 1)][y]) q.add(new Pair((x + 1),y)); bee[(x + 1)][y] = true; } if ( (y > 1)) {see[x][(y - 1)] = min((see[x][y] + 1),see[x][(y - 1)]); if ( !bee[x][(y - 1)]) q.add(new Pair(x,(y - 1))); bee[x][(y - 1)] = true; } if ( (y < m)) {see[x][(y + 1)] = min((see[x][y] + 1),see[x][(y + 1)]); if ( !bee[x][(y + 1)]) q.add(new Pair(x,(y + 1))); bee[x][(y + 1)] = true; } } int ans = -1;  Pair temp = null; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) {if ( (see[i][j] > ans)) {ans = see[i][j]; temp = new Pair(i,j); } }}log.write(((temp.u + " ") + temp.v)); log.close(); } static int min( int a, int b){ if ( (a > b)) return b; return a;} static private double dfs( int cur, int prev){ double r = 0,n = 0; for ( int i :amp[cur]) {if ( (i != prev)) {r += (1 + dfs(i,cur)); n++; } }if ( (n != 0)) {r = (r / n); } return r;} static double fa1 = 0; static int fa = -1; static class Node{ Node arr[] = new Node[2]; int cnt[] = new int[2]; } static double power( double x, long y){ if ( (y == 0)) return 1; double p = power(x,(y / 2)); p = (p * p); return (((y % 2) == 0)?p:(x * p));} static int Dfs( int x, int val){ b[x] = true; for ( int p :hs2[x]) {if ( !b[p]) {if ( !hs1[x].contains(p)) val++; val += Dfs(p,0); } }return val;} static void dfs1( int x, int p){ arr1[x] += lev[x]; for ( int v :amp[x]) {if ( (v != p)) {dfs1(v,x); } }} static class Pair implements Comparable<Pair>{ int u ; int v ; int ans ; public Pair(){ u = 0; v = 0; } public Pair( int u, int v){ this.u = u; this.v = v; } public String toString(){ return (((("[u=" + u) + ", v=") + v) + "]");} } static long min( long a, long b, long c){ if ( ((a < b) && (a < c))) return a; if ( (b < c)) return b; return c;} static void computeLPSArray( String pat, int M, int[] lps){ int len = 0;  int i = 1; lps[0] = 0; while((i < M)){if ( (pat.charAt(i) == pat.charAt(len))) {len++; lps[i] = len; i++; } else {if ( (len != 0)) {len = lps[(len - 1)]; } else {lps[i] = len; i++; }}}} static private void permutation( String prefix, String str){ int n = str.length(); if ( (n == 0)) ; else {for ( int i = 0;(i < n);i++) permutation((prefix + str.charAt(i)),(str.substring(0,i) + str.substring((i + 1),n))); }} static class Node2{ Node2 left = null; Node2 right = null; Node2 parent = null; int data ; } public static long max( long x, long y, long z){ if ( ((x >= y) && (x >= z))) return x; if ( ((y >= x) && (y >= z))) return y; return z;} static long modInverse( long a, long mOD2){ return power(a,(mOD2 - 2),mOD2);} static long power( long x, long y, long m){ if ( (y == 0)) return 1; long p = (power(x,(y / 2),m) % m); p = ((p * p) % m); return (((y % 2) == 0)?p:((x * p) % m));} static long d ,x ,y ; public static void extendedEuclidian( long a, long b){ if ( (b == 0)) {d = a; x = 1; y = 0; } else {extendedEuclidian(b,(a % b)); int temp = (int)x; x = y; y = (temp - ((a / b) * y)); }} public static long gcd( long n, long m){ if ( (m != 0)) return gcd(m,(n % m)); else return n;} static BufferedReader reader ; static StringTokenizer tokenizer ; static PrintWriter writer ; static class FasterScanner{ private final InputStream stream ; private final byte[] buf = new byte[8192]; private int curChar ,snumChars ; private SpaceCharFilter filter ; public FasterScanner( InputStream stream){ this.stream = stream; } public int snext(){ if ( (snumChars == -1)) throw (new InputMismatchException()); if ( (curChar >= snumChars)) {curChar = 0; try{snumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (snumChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} public long nextLong(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} public int[] nextIntArray( int n){ int a[] = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); }return a;} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
0	public class Main{ public static void main( String[] args){ Scanner scanner = new Scanner(System.in);  long n = scanner.nextLong();  long x = scanner.nextLong(),y = scanner.nextLong();  long whiteSteps ,blackSteps ; if ( ((x == 1) || (y == 1))) {whiteSteps = ((x - 1) + (y - 1)); } else {whiteSteps = Math.min(((x - 1) + Math.abs((y - x))),((y - 1) + Math.abs((y - x)))); }if ( ((x == n) || (y == n))) {blackSteps = ((n - x) + (n - y)); } else {blackSteps = Math.min(((n - x) + Math.abs((y - x))),((n - y) + Math.abs((y - x)))); }if ( (whiteSteps <= blackSteps)) {System.out.println("White"); } else {System.out.println("Black"); }} }
1	public class Contest25_A{ static int[] parity ; public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int numberEntries = scan.nextInt(); scan.nextLine(); String[] numbers = scan.nextLine().split(" "); numbers = parity(numbers); int evenOdd = evenOdd(parity); for ( int i = 0;(i < parity.length);i++) {if ( (parity[i] == evenOdd)) {System.out.println((i + 1)); System.exit(0); } }} public static int evenOdd( int[] parity){ int numberOnes = 0;  int numberZeroes = 0;  int one = parity[0];  int two = parity[1];  int three = parity[2]; if ( (one == 1)) numberOnes++; else numberZeroes++; if ( (two == 1)) numberOnes++; else numberZeroes++; if ( (three == 1)) numberOnes++; else numberZeroes++; if ( (numberOnes >= 2)) return 0; else return 1;} public static String[] parity( String[] numbers){ parity = new int[numbers.length]; for ( int i = 0;(i < numbers.length);i++) {parity[i] = (Integer.parseInt(numbers[i]) % 2); numbers[i] = Integer.toString(parity[i]); }return numbers;} }
0	public class Main{ public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  List<Integer> fibs = new ArrayList<Integer>();  int fib0 = 0;  int fib1 = 1;  int fibN = (fib0 + fib1); fibs.add(fib0); fibs.add(fib1); while((fibN < 1000000000)){fibs.add(fibN); fib0 = fib1; fib1 = fibN; fibN = (fib0 + fib1); } int n = Integer.parseInt(br.readLine()); if ( (n == 0)) {System.out.println(((((0 + " ") + 0) + " ") + 0)); } else {if ( (n == 1)) {System.out.println(((((0 + " ") + 0) + " ") + 1)); } else {if ( (n == 2)) {System.out.println(((((0 + " ") + 1) + " ") + 1)); } else { int i = fibs.indexOf(n); System.out.println(((((fibs.get((i - 4)) + " ") + fibs.get((i - 3))) + " ") + fibs.get((i - 1)))); }}}} }
2	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);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, Scanner in, PrintWriter out){ long n = in.nextLong();  long k = in.nextLong(); if ( (n == 1)) {out.println(0); return ;} if ( ((k * (k - 1)) < (2 * (n - 1)))) {out.println(-1); return ;} long sq2 = (((((4 * k) * k) - (4 * k)) + 1) - (4 * ((2 * n) - 2)));  double sqrt = Math.sqrt(sq2);  long sq = (long)sqrt; if ( (((sq + 1) * (sq + 1)) == sq2)) {sq = (sq + 1); } else if ( (((sq - 1) * (sq - 1)) == sq2)) {sq = (sq - 1); } if ( ((sq * sq) == sq2)) { long kmin = ((sq + 3) / 2); out.println(((k - kmin) + 1)); } else { long km = Math.max(2,((long)((sqrt + 3) / 2.0) - 2)); while(((((km + k) - 2) * ((k - km) + 1)) >= (2 * (n - 1)))){++km; }out.println(((k - km) + 2)); }} }
0	public class Test{ public static void main( String[] args){ Scanner s = new Scanner(System.in);  int n = s.nextInt();  int k = 1;  int t = 0;  int y = 2;  int[] a = new int[100000]; if ( (n == 0)) {System.out.println(((((0 + " ") + 0) + " ") + 0)); } else if ( (n == 1)) {System.out.println(((((0 + " ") + 0) + " ") + 1)); } else if ( (n == 2)) {System.out.println(((((0 + " ") + 1) + " ") + 1)); } else {a[0] = 0; a[1] = 1; a[y] = (a[(y - 2)] + a[(y - 1)]); while((a[(y - 1)] < n)){a[y] = (a[(y - 2)] + a[(y - 1)]); ++y; }System.out.println(((((a[(y - 2)] + " ") + a[(y - 4)]) + " ") + a[(y - 5)])); }} }
4	public class Main{ public static void main( String[] args)throws IOException { Scanner scn = new Scanner(new File("input.txt"));  BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));  int r = scn.nextInt();  int c = scn.nextInt();  int[][] a = new int[r][c]; for ( int[] i :a) Arrays.fill(i,(1 << 30)); int k = scn.nextInt();  Queue<State> q = new LinkedList<State>(); for ( int l = 0;(l < k);l++) { int i = (scn.nextInt() - 1);  int j = (scn.nextInt() - 1); a[i][j] = 0; q.add(new State(i,j,0)); }while(!q.isEmpty()){ State st = q.poll(); a[st.i][st.j] = st.c; for ( int d = 0;(d < 4);d++) { int ii = (st.i + di[d]);  int jj = (st.j + dj[d]); if ( ((((ii < 0) || (ii >= r)) || (jj < 0)) || (jj >= c))) continue; if ( (a[ii][jj] != (1 << 30))) continue; a[ii][jj] = (st.c + 1); q.add(new State(ii,jj,(st.c + 1))); }} int max = 0; for ( int i = 0;(i < r);i++) for ( int j = 0;(j < c);j++) max = Math.max(max,a[i][j]); for ( int i = 0;(i < r);i++) for ( int j = 0;(j < c);j++) if ( (a[i][j] == max)) {out.write((((i + 1) + " ") + (j + 1))); out.newLine(); out.close(); return ;} } static int[] di = {0,0,-1,1}; static int[] dj = {1,-1,0,0}; } class State{ int i ,j ,c ; public State( int ii, int ji, int ci){ i = ii; j = ji; c = ci; } }
3	public class Solution{ 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());} } public static void main( String[] args){ FastReader sc = new FastReader();  int n = sc.nextInt();  int m = sc.nextInt();  int[] arr = new int[105]; for ( int i = 0;(i < m);i++) { int a = sc.nextInt(); arr[a]++; }for ( int i = 1;(i <= 1000);i++) { int sum = 0; for ( int a :arr) {if ( (a != 0)) {sum += (a / i); } }if ( (sum < n)) {System.out.println((i - 1)); return ;} }} }
4	public class Main{ static private StreamTokenizer in ; static private PrintWriter out ; static private BufferedReader inB ; static private int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} {try{inB = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); out = new PrintWriter(new FileOutputStream("output.txt")); }catch (Exception e){ } in = new StreamTokenizer(inB); }static private int[][] mind ; static private boolean[][] used ; static private int n ,m ; public static void main( String[] args)throws Exception { n = nextInt(); m = nextInt(); int k = nextInt();  int[][] mas = new int[k][2]; for ( int i = 0;(i < k);i++) {mas[i][0] = (nextInt() - 1); mas[i][1] = (nextInt() - 1); }mind = new int[n][m]; used = new boolean[n][m]; for ( int i = 0;(i < n);i++) {Arrays.fill(mind[i],Integer.MAX_VALUE); } ArrayDeque<int[]> ad = new ArrayDeque<int[]>(); for ( int i = 0;(i < k);i++) {ad.add(new int[]{mas[i][0],mas[i][1],0}); }while(!ad.isEmpty()){ int[] cur = ad.remove(); if ( used[cur[0]][cur[1]]) continue; int x = cur[0];  int y = cur[1];  int d = cur[2]; mind[x][y] = ++d; used[x][y] = true; if ( (isValid((x + 1),y) && !used[(x + 1)][y])) ad.add(new int[]{(x + 1),y,d}); if ( (isValid(x,(y + 1)) && !used[x][(y + 1)])) ad.add(new int[]{x,(y + 1),d}); if ( (isValid(x,(y - 1)) && !used[x][(y - 1)])) ad.add(new int[]{x,(y - 1),d}); if ( (isValid((x - 1),y) && !used[(x - 1)][y])) ad.add(new int[]{(x - 1),y,d}); } int max = Integer.MIN_VALUE;  int maxx = 0,maxy = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (mind[i][j] > max)) {max = mind[i][j]; maxx = (i + 1); maxy = (j + 1); } }}out.println(((maxx + " ") + maxy)); out.flush(); } static private boolean isValid( int x, int y){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} static private void println( Object o)throws Exception { System.out.println(o); } static private void exit( Object o)throws Exception { println(o); exit(); } static private void exit(){ System.exit(0); } }
5	public class Main{ public static void main( String[] args)throws Exception { MyScanner scan = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n = scan.nextInt();  int[] vals = new int[n]; for ( int i = 0;(i < n);i++) {vals[i] = scan.nextInt(); }for ( int i = 0;(i < n);i++) {if ( solve(i,vals)) {out.print('A'); } else {out.print('B'); }}out.close(); } static HashMap<Integer,Boolean> dpResult = new HashMap<>(); static private boolean solve( int pos, int[] vals){ if ( dpResult.containsKey(pos)) return dpResult.get(pos); int val = vals[pos];  boolean hasLose = false; for ( int i = pos;(i < vals.length);i += val) {if ( (i == pos)) continue; if ( (vals[i] <= vals[pos])) continue; if ( hasLose) break; if ( !solve(i,vals)) {hasLose = true; } }for ( int i = pos;(i >= 0);i -= val) {if ( (i == pos)) continue; if ( (vals[i] <= vals[pos])) continue; if ( hasLose) break; if ( !solve(i,vals)) {hasLose = true; } }dpResult.put(pos,hasLose); return hasLose;} 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());} } }
4	public class TaskC extends Thread{ public TaskC(){ try{this.input = new BufferedReader(new FileReader("input.txt")); this.output = new PrintWriter("output.txt"); this.setPriority(Thread.MAX_PRIORITY); }catch (Throwable e){ System.exit(666); } } private void solve()throws Throwable { int n = nextInt();  int m = nextInt();  int k = nextInt();  Queue<Integer> qX = new ArrayDeque<Integer>();  Queue<Integer> qY = new ArrayDeque<Integer>();  boolean[][] was = new boolean[n][m]; for ( int i = 0;(i < k);++i) { int x = (nextInt() - 1),y = (nextInt() - 1); qX.add(x); qY.add(y); was[x][y] = true; } int lastX = -1,lastY = -1; while(!qX.isEmpty()){lastX = qX.poll(); lastY = qY.poll(); for ( int i = 0;(i < dx.length);++i) { int nextX = (lastX + dx[i]),nextY = (lastY + dy[i]); if ( (((((nextX < n) && (nextY < m)) && (nextX >= 0)) && (nextY >= 0)) && !was[nextX][nextY])) {qX.add(nextX); qY.add(nextY); was[nextX][nextY] = true; } }}++lastX; ++lastY; output.println(((lastX + " ") + lastY)); } public static void main( String[] args){ new TaskC().start(); } private int nextInt()throws IOException { return Integer.parseInt(nextToken());} private String nextToken()throws IOException { while(((tokens == null) || !tokens.hasMoreTokens())){tokens = new StringTokenizer(input.readLine()); }return tokens.nextToken();} static final int PRIME = 3119; static final int[] dx = {1,-1,0,0},dy = {0,0,-1,1}; private BufferedReader input ; private PrintWriter output ; private StringTokenizer tokens = null; }
5	public class CottageTown{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  String[] in = sc.nextLine().split(" ");  int n = Integer.parseInt(in[0]);  int t = Integer.parseInt(in[1]);  int[] coor = new int[n];  int[] side = new int[n]; for ( int i = 0;(i < n);i++) {in = sc.nextLine().split(" "); coor[i] = Integer.parseInt(in[0]); side[i] = Integer.parseInt(in[1]); }quickSort(coor,0,(n - 1),side); int count = 2;  double dist ; for ( int i = 0;(i < (n - 1));i++) {dist = ((coor[(i + 1)] - coor[i]) - ((double)(side[(i + 1)] + side[i]) / 2.0)); if ( (dist > t)) {count += 2; } else if ( (dist == t)) {count += 1; } }System.out.println(count); } static private int partition( int[] arr, int left, int right, int[] temp){ int i = left,j = right;  int tmp ;  int pivot = arr[((left + right) / 2)]; while((i <= j)){while((arr[i] < pivot)){i++; }while((arr[j] > pivot)){j--; }if ( (i <= j)) {tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; tmp = temp[i]; temp[i] = temp[j]; temp[j] = tmp; i++; j--; } }return i;} static private void quickSort( int[] arr, int left, int right, int[] temp){ int index = partition(arr,left,right,temp); if ( (left < (index - 1))) {quickSort(arr,left,(index - 1),temp); } if ( (index < right)) {quickSort(arr,index,right,temp); } } }
0	public class Hexadecimaltheorem{ public static void main( String[] args){ BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));  int x ;  ArrayList<Integer> arr = new ArrayList<Integer>(); arr.add(0); arr.add(1); try{while(((x = Integer.parseInt(buf.readLine())) != -1)){if ( (x == 1)) {System.out.println(((((arr.get(0) + " ") + arr.get(0)) + " ") + arr.get(1))); } else if ( (x == 0)) {System.out.println(((((arr.get(0) + " ") + arr.get(0)) + " ") + arr.get(0))); } else { int i = 1; while((x > arr.get((arr.size() - 1)))){arr.add((arr.get(i) + arr.get((i - 1)))); i++; }System.out.println(((((arr.get(0) + " ") + arr.get((i - 2))) + " ") + arr.get((i - 1)))); }} }catch (NumberFormatException e){ e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } } }
2	public class Main{ public static long howMany( long n, long x, long y, long s){ long res = 0;  int cnt = 0;  long[] px = new long[9];  long[] py = new long[9]; if ( ((x - s) < 1)) {px[cnt] = 1; py[cnt++] = (((((y - x) + s) + 1) <= n)?(((y - x) + s) + 1):n); px[cnt] = 1; py[cnt++] = (((((x + y) - s) - 1) > 0)?(((x + y) - s) - 1):1); res += 6; } else {px[cnt] = (x - s); py[cnt++] = y; res += 2; }if ( ((y - s) < 1)) {py[cnt] = 1; px[cnt++] = (((((x + y) - s) - 1) > 0)?(((x + y) - s) - 1):1); py[cnt] = 1; px[cnt++] = ((((x - (y - s)) + 1) <= n)?(((x - y) + s) + 1):n); res += 6; } else {px[cnt] = x; py[cnt++] = (y - s); res += 2; }if ( ((x + s) > n)) {px[cnt] = n; py[cnt++] = ((((y - (x + s)) + n) > 0)?((y - (x + s)) + n):1); px[cnt] = n; py[cnt++] = (((((x + s) + y) - n) <= n)?(((x + s) + y) - n):n); res += 6; } else {px[cnt] = (x + s); py[cnt++] = y; res += 2; }if ( ((y + s) > n)) {py[cnt] = n; px[cnt++] = (((((x + y) + s) - n) <= n)?(((x + y) + s) - n):n); py[cnt] = n; px[cnt++] = (((n - ((y + s) - x)) > 0)?(n - ((y + s) - x)):1); res += 6; } else {px[cnt] = x; py[cnt++] = (y + s); res += 2; }px[cnt] = px[0]; py[cnt] = py[0]; long ret = 0;  long sum = 0; for ( int i = 0;(i < cnt);i++) {ret += ((px[i] * py[(i + 1)]) - (py[i] * px[(i + 1)])); sum += (Math.max(Math.abs((px[i] - px[(i + 1)])),Math.abs((py[i] - py[(i + 1)]))) + 1); }return ((((4 * ret) + (4 * sum)) - res) / 8);} public static void main( String[] args)throws Exception { BufferedReader r = new BufferedReader(new InputStreamReader(System.in));  StringTokenizer str = new StringTokenizer(r.readLine());  int n = Integer.parseInt(str.nextToken());  int x = Integer.parseInt(str.nextToken());  int y = Integer.parseInt(str.nextToken());  long c = Long.parseLong(str.nextToken()); if ( (c == 1)) {System.out.println(0); return ;} long high = 1; while((howMany(n,x,y,high) < c)){high <<= 1; } long low = (high >> 1); while(((high - low) > 1)){ long med = ((high + low) / 2); if ( (howMany(n,x,y,med) < c)) {low = med; } else {high = med; }}System.out.println(high); } }
0	public class N1_CF_199A{ public static void main( String[] args){ int n = new Scanner(System.in).nextInt(); if ( (n == 0)) {System.out.println(0); System.out.println(0); System.out.println(0); return ;} int i = 0,j = 1; while(true){ int t = (i + j); if ( (t == n)) break; i = j; j = t; }System.out.println(i); System.out.println(j); System.out.println(0); } }
5	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 < n);i++) {h[i][0] = (2 * in.nextInt()); h[i][1] = in.nextInt(); }Arrays.sort(h,new Comp()); for ( int i = 1;(i < n);i++) { int d = ((h[i][0] - h[i][1]) - (h[(i - 1)][0] + h[(i - 1)][1])); if ( (d > t)) ans += 2; if ( (d == t)) ans++; }System.out.println(ans); } static class Comp implements Comparator<int[]>{ } }
6	public class Songs{ static class Reader{ private final int BUFFER_SIZE = (1 << 16); private DataInputStream din ; private byte[] buffer ; private int bufferPointer ,bytesRead ; public Reader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader( String file_name)throws IOException{ din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt()throws IOException { int ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} private void fillBuffer()throws IOException { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } private byte read()throws IOException { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} public void close()throws IOException { if ( (din == null)) return ; din.close(); } } public static void main( String[] args)throws IOException { Reader sc = new Reader();  PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));  int i ,j ;  int n = sc.nextInt();  int tt = sc.nextInt();  int t[] = new int[n];  int g[] = new int[n];  int last = 0;  int M = 1000000007;  long sum = 0; for ( i = 0;(i < n);i++) {t[i] = sc.nextInt(); g[i] = (sc.nextInt() - 1); } int d[][] = new int[(1 << n)][4]; d[0][3] = 1; for ( i = 0;(i < (1 << n));i++) {for ( last = 0;(last < 4);last++) {for ( j = 0;(j < n);j++) {if ( ((g[j] != last) && ((i & (1 << j)) == 0))) {d[(i ^ (1 << j))][g[j]] = ((d[(i ^ (1 << j))][g[j]] + d[i][last]) % M); } }} int dur = 0; for ( j = 0;(j < n);j++) {if ( ((i & (1 << j)) > 0)) {dur += t[j]; } }if ( (dur == tt)) {sum = ((((sum + d[i][0]) + d[i][1]) + d[i][2]) % M); } }pw.println(sum); pw.close(); } }
2	public class Main{ static int d[][] ; static int N ; static boolean used[] ; static point dats[] ; public static void main( String[] args){ Scanner scan = new Scanner(System.in);  long n = scan.nextLong();  long k = scan.nextLong(); if ( (n == 1)) {System.out.print("0"); return ;} if ( (n <= k)) {System.out.print("1"); return ;} long d = (9 - (4 * (((2 * n) - (k * k)) + k))); if ( (d < 0)) {System.out.print("-1"); return ;} double a = ((3 + Math.sqrt(d)) / 2); if ( (a >= 1)) System.out.println(Math.max(2,((k - (long)a) + 1))); else System.out.println(-1); } }
4	public class ProblemD{ static int n ; static int m ; static boolean[][] fire ; public static void main( String[] args)throws FileNotFoundException { Scanner sc = new Scanner(new File("input.txt")); n = sc.nextInt(); m = sc.nextInt(); int k = sc.nextInt(); fire = new boolean[n][m]; Queue<Pos> q = new LinkedList<Pos>(); for ( int i = 0;(i < k);i++) { int x = sc.nextInt();  int y = sc.nextInt(); q.add(new Pos((x - 1),(y - 1))); fire[(x - 1)][(y - 1)] = true; } int[] di = new int[]{1,-1,0,0};  int[] dj = new int[]{0,0,1,-1};  Pos last = null; while((q.size() > 0)){ Pos pos = q.poll(); last = pos; for ( int kk = 0;(kk < 4);kk++) { int ni = (pos.i + di[kk]);  int nj = (pos.j + dj[kk]); if ( ((((ni >= 0) && (nj >= 0)) && (ni < n)) && (nj < m))) {if ( !fire[ni][nj]) {fire[ni][nj] = true; q.add(new Pos(ni,nj)); } } }} PrintWriter out = new PrintWriter(new File("output.txt")); out.println((((last.i + 1) + " ") + (last.j + 1))); out.flush(); out.close(); } } class Pos{ int i ,j ; public Pos( int i, int j){ super(); this.i = i; this.j = j; } }
4	public class C35{ public static int mod = 1000000007; public static long INF = (1L << 60); static int n ,m ; static class Pair{ int x ,y ; Pair( int x, int y){ this.x = x; this.y = y; } } static boolean[][] burned ; static int[] dx = {-1,0,1,0}; static int[] dy = {0,-1,0,1}; static boolean isvalid( int x, int y){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} public static void main( String[] args)throws IOException { Scanner in = new Scanner("input.txt");  PrintWriter out = new PrintWriter(new FileWriter("output.txt")); n = in.nextInt(); m = in.nextInt(); burned = new boolean[n][m]; int k = in.nextInt();  Queue<Pair> queue = new LinkedList<>();  Pair prev = null; for ( int i = 0;(i < k);i++) { int x = in.nextInt();  int y = in.nextInt(); burned[(x - 1)][(y - 1)] = true; queue.add(prev = new Pair((x - 1),(y - 1))); }while(!queue.isEmpty()){ Queue<Pair> tempqueue = new LinkedList<>(); for ( Pair p :queue) { int x = p.x;  int y = p.y; prev = p; for ( int i = 0;(i < 4);i++) {if ( (isvalid((x + dx[i]),(y + dy[i])) && !burned[(x + dx[i])][(y + dy[i])])) {tempqueue.add(new Pair((x + dx[i]),(y + dy[i]))); burned[(x + dx[i])][(y + dy[i])] = true; } }}queue = tempqueue; }out.printf("%d %d\n",(prev.x + 1),(prev.y + 1)); out.close(); } public static long gcd( long n1, long n2){ long r ; while((n2 != 0)){r = (n1 % n2); n1 = n2; n2 = r; }return n1;} 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 boolean ready()throws IOException { return br.ready();} } }
3	public class Main{ static int N ; static int[][] dp ; static int M = (int)(1e9 + 7); static ArrayList<Integer> l ; static int f( int idx, int b){ if ( (idx == l.size())) return 1; if ( (dp[idx][b] != -1)) return dp[idx][b]; long ret = f((idx + 1),(b + l.get(idx))); if ( (b > 0)) ret += f(idx,(b - 1)); return dp[idx][b] = (int)(ret % M);} public static void main( String[] args)throws IOException { Scanner sc = new Scanner(); N = sc.nextInt(); int[] val = new int[N]; for ( int i = 0;(i < N);++i) if ( (sc.next().charAt(0) == 's')) val[i] = 0; else val[i] = 1; l = new ArrayList<Integer>(); l.add(val[0]); for ( int i = 1;(i < N);++i) if ( ((val[i] == val[(i - 1)]) && (val[i] == 1))) { int prev = l.get((l.size() - 1)); l.set((l.size() - 1),++prev); } else if ( (val[(i - 1)] == 0)) {l.add(val[i]); } dp = new int[(l.size() + 1)][(N + 1)]; for ( int i = 0;(i <= l.size());++i) Arrays.fill(dp[i],-1); System.out.println(f(0,0)); } static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner(){ br = new BufferedReader(new InputStreamReader(System.in)); } 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());} } }
2	public class B{ final String filename = new String("B").toLowerCase(); int n ; int r ,c ; void solve()throws Exception { n = nextInt(); r = (nextInt() - 1); c = (nextInt() - 1); long count = nextLong();  long left = -1,right = (n * 2L); while((left < (right - 1))){ long mid = ((left + right) / 2); if ( (getSq(n,r,c,mid) >= count)) {right = mid; } else {left = mid; }}out.println(right); } long getSq( int n, int x, int y, long size){ long cur = (((size + 1) * (size + 1)) + (size * size)); cur -= get(((x + size) - (n - 1))); cur -= get(((y + size) - (n - 1))); cur -= get((x - size)); cur -= get((y - size)); cur += getCorner((((x + 1) + (y + 1)) - (size + 1))); cur += getCorner((((x + 1) + (n - y)) - (size + 1))); cur += getCorner((((n - x) + (y + 1)) - (size + 1))); cur += getCorner((((n - x) + (n - y)) - (size + 1))); return cur;} private long getCorner( long min){ if ( (min >= 0)) {return 0;} min = -min; return ((min * (min + 1)) / 2);} long get( long a){ if ( (a <= 0)) {return 0;} return (a * a);} void run(){ try{in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } BufferedReader in ; StringTokenizer st ; PrintWriter out ; String nextToken()throws Exception { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(nextToken());} long nextLong()throws Exception { return Long.parseLong(nextToken());} public static void main( String[] args){ new B().run(); } }
6	public class CF1102F{ 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[][] aa = new int[n][m]; for ( int i = 0;(i < n);i++) {st = new StringTokenizer(br.readLine()); for ( int j = 0;(j < m);j++) aa[i][j] = Integer.parseInt(st.nextToken()); } int[][] dd = new int[n][n]; for ( int i = 0;(i < n);i++) for ( int j = (i + 1);(j < n);j++) { int d = Integer.MAX_VALUE; for ( int h = 0;(h < m);h++) d = Math.min(d,Math.abs((aa[i][h] - aa[j][h]))); dd[i][j] = dd[j][i] = d; } int[][] dd_ = new int[n][n]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) { int d = Integer.MAX_VALUE; for ( int h = 0;(h < (m - 1));h++) d = Math.min(d,Math.abs((aa[i][h] - aa[j][(h + 1)]))); dd_[i][j] = d; }if ( (n == 1)) {System.out.println(dd_[0][0]); return ;} int[] ii = new int[(1 << n)]; for ( int i = 0;(i < n);i++) ii[(1 << i)] = i; int[][][] dp = new int[(1 << n)][n][n]; for ( int b = 0;(b < (1 << n));b++) for ( int u = b;(u > 0);u &= (u - 1)) { int i = ii[(u & -u)]; for ( int v = (b ^ (1 << i));(v > 0);v &= (v - 1)) { int j = ii[(v & -v)]; if ( (b == ((1 << i) ^ (1 << j)))) dp[b][i][j] = dd[i][j]; else { int x = 0; for ( int w = ((b ^ (1 << i)) ^ (1 << j));(w > 0);w &= (w - 1)) { int k = ii[(w & -w)]; x = Math.max(x,Math.min(dp[(b ^ (1 << j))][i][k],dd[k][j])); }dp[b][i][j] = x; }}} int b = ((1 << n) - 1);  int x = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) if ( (i != j)) x = Math.max(x,Math.min(dp[b][i][j],dd_[i][j])); System.out.println(x); } }
1	public class javatemp{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int ans = 1000; in.readLine(); String s = in.readLine();  int H = 0; for ( int i = 0;(i < s.length());i++) if ( (s.charAt(i) == 'H')) H++; for ( int i = 0;(i < s.length());i++) { int count = 0; for ( int j = 0;(j < H);j++) if ( (s.charAt(((i + j) % s.length())) == 'T')) count++; ans = Math.min(ans,count); }System.out.println(ans); } }
4	public class R035CRetry{ public static final int INF = 987654321; public static final long LINF = 987654321987654321L; public static final double EPS = 1e-9; Scanner scanner ; PrintWriter out ; boolean[][] bss ; public R035CRetry(){ try{this.scanner = new Scanner(new File("input.txt")); this.out = new PrintWriter("output.txt"); }catch (FileNotFoundException ex){ ex.printStackTrace(); } } class Point implements Comparable<Point>{ int x ,y ,count ; Point( int x, int y){ this.x = x; this.y = y; } } int[] dx = new int[]{0,0,-1,1}; int[] dy = new int[]{-1,1,0,0}; int n ,m ; Queue<Point> q ; Point bfs(){ int max = -INF;  Point p = null; while(!q.isEmpty()){ Point cur = q.remove(); if ( (max < cur.count)) {max = cur.count; p = cur; } for ( int i = 0;(i < dx.length);i++) { int nx = (cur.x + dx[i]);  int ny = (cur.y + dy[i]); if ( ((nx < 0) || (nx >= n))) {continue;} if ( ((ny < 0) || (ny >= m))) {continue;} Point np = new Point(nx,ny); if ( bss[nx][ny]) {continue;} np.count = (cur.count + 1); bss[nx][ny] = true; q.add(np); }}return p;} private void solve(){ this.n = scanner.nextInt(); this.m = scanner.nextInt(); this.bss = new boolean[n][m]; int k = scanner.nextInt(); q = new PriorityQueue<Point>(); for ( int i = 0;(i < k);i++) { int x = (scanner.nextInt() - 1);  int y = (scanner.nextInt() - 1);  Point init = new Point(x,y); init.count = 1; q.add(init); bss[x][y] = true; } Point p = bfs(); out.println((((p.x + 1) + " ") + (p.y + 1))); } private void finish(){ this.out.close(); } public static void main( String[] args){ R035CRetry obj = new R035CRetry(); obj.solve(); obj.finish(); } }
1	public class ProblemC{ public static void main( String[] args){ ProblemC problem = new ProblemC(); problem.solve(); } private void solve(){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  String s = sc.next();  int ret = n;  int toth = 0;  int tott = 0; for ( int j = 0;(j < n);j++) {if ( (s.charAt(j) == 'H')) {toth++; } else {tott++; }}for ( int j = 0;(j < n);j++) { int cnth = 0; for ( int k = 0;(k < toth);k++) { int pos = ((j + k) % n); if ( (s.charAt(pos) == 'H')) {cnth++; } } int makeh = (toth - cnth); ret = Math.min(ret,makeh); }System.out.println(ret); } }
1	public class IQ{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  ArrayList<Integer> e = new ArrayList<Integer>();  ArrayList<Integer> o = new ArrayList<Integer>();  int size = sc.nextInt(); for ( int w = 0;(w < size);w++) { int x = sc.nextInt(); if ( ((x % 2) == 0)) e.add((w + 1)); else o.add((w + 1)); }if ( (e.size() == 1)) System.out.println(e.get(0)); else System.out.println(o.get(0)); } }
4	public class A_GENERAL{ static StringBuilder sb = new StringBuilder(); static long seive_size = (long)1e6; static String alpha = "abcdefghijklmnopqrstuvwxyz"; static ArrayList<Integer> primes = new ArrayList<>(); static boolean[] seive_set = new boolean[((int)seive_size + 1)]; static int n ,m ,k ; static ArrayList<Integer>[] adj ; static boolean[] vis ; static ArrayDeque<Integer> q = new ArrayDeque<>(); static final long MOD = 998244353; static int[] dx = new int[]{1,0,-1,0,1,-1,1,-1}; static int[] dy = new int[]{0,1,0,-1,-1,1,1,-1}; static long[][] arr ; static int[] rank ; static int[] parent ; static int[] s ; static long[] a ; public static void main( String[] args)throws FileNotFoundException { Scanner sc = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter("output.txt"); n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt(); ArrayDeque<iPair> qq = new ArrayDeque<>();  boolean[][] vis = new boolean[(n + 1)][(m + 1)]; for ( int i = 0;(i < k);i++) { int u = sc.nextInt();  int v = sc.nextInt(); qq.add(new iPair(u,v)); vis[u][v] = true; } iPair last = null; while(!qq.isEmpty()){ iPair pp = qq.poll();  int i = pp.f;  int j = pp.s; if ( (isValid((i - 1),j) && !vis[(i - 1)][j])) {qq.add(new iPair((i - 1),j)); vis[(i - 1)][j] = true; } if ( (isValid((i + 1),j) && !vis[(i + 1)][j])) {qq.add(new iPair((i + 1),j)); vis[(i + 1)][j] = true; } if ( (isValid(i,(j - 1)) && !vis[i][(j - 1)])) {qq.add(new iPair(i,(j - 1))); vis[i][(j - 1)] = true; } if ( (isValid(i,(j + 1)) && !vis[i][(j + 1)])) {qq.add(new iPair(i,(j + 1))); vis[i][(j + 1)] = true; } last = pp; }out.println(((last.f + " ") + last.s)); sc.close(); out.close(); } public static boolean isValid( int i, int j){ if ( ((((i < 1) || (i > n)) || (j < 1)) || (j > m))) return false; return true;} public static class iPair implements Comparable<iPair>{ int f ; int s ; iPair( int f, int s){ this.f = f; this.s = s; } } public static long choose( long n, long k){ return ((k == 0)?1:((n * choose((n - 1),(k - 1))) / k));} public static long gcd( long a, long b){ return ((a == 0)?b:gcd((b % a),a));} public static long max( long... as){ long max = Long.MIN_VALUE; for ( long a :as) max = Math.max(a,max); return max;} public static long min( int... as){ long min = Long.MAX_VALUE; for ( long a :as) min = Math.min(a,min); return min;} public static long modpow( long x, long n, long mod){ if ( (n == 0)) return (1 % mod); long u = modpow(x,(n / 2),mod); u = ((u * u) % mod); if ( ((n % 2) == 1)) u = ((u * x) % mod); return u;} public static void permute( String str){ permute(str,0,(str.length() - 1)); } public static void permute( String str, int l, int r){ if ( (l == r)) System.out.println(str); else {for ( int i = l;(i <= r);i++) {str = swap(str,l,i); permute(str,(l + 1),r); str = swap(str,l,i); }}} public static String swap( String a, int i, int j){ char temp ;  char[] charArray = a.toCharArray(); temp = charArray[i]; charArray[i] = charArray[j]; charArray[j] = temp; return String.valueOf(charArray);} public static int find( int u){ if ( (parent[u] == u)) return u; int v = find(parent[u]); parent[u] = v; return v;} }
0	public class Solve4{ public static void main( String[] args)throws IOException { FastReader sc = new FastReader();  int x = sc.nextInt();  int y = sc.nextInt();  int z = sc.nextInt();  int t1 = sc.nextInt();  int t2 = sc.nextInt();  int t3 = sc.nextInt(); if ( ((Math.abs((x - y)) * t1) < (((Math.abs((x - z)) + Math.abs((x - y))) * t2) + (3 * t3)))) System.out.println("NO"); else System.out.println("YES"); } static class FastReader{ BufferedReader br ; StringTokenizer st ; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public String next()throws IOException { if ( ((st == null) || !st.hasMoreTokens())) {st = new StringTokenizer(br.readLine()); } return st.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(next());} } }
4	public class C{ public static void main( String[] args)throws Exception { File in = new File("input.txt"),out = new File("output.txt");  Scanner s ;  PrintWriter pw ; if ( in.exists()) {s = new Scanner(in); pw = new PrintWriter(out); } else {s = new Scanner(System.in); pw = new PrintWriter(System.out); } int n = s.nextInt(),m = s.nextInt();  int k = s.nextInt();  List<int[]> list = new ArrayList<int[]>(); for ( int t = 0;(t < k);++t) {list.add(new int[]{(s.nextInt() - 1),(s.nextInt() - 1)}); } int max = 0,mi = 1,mj = 1; for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < m);++j) { int min = Integer.MAX_VALUE; for ( int[] p :list) {min = Math.min(min,(Math.abs((i - p[0])) + Math.abs((j - p[1])))); }if ( (min > max)) {max = Math.max(max,min); mi = (i + 1); mj = (j + 1); } }}pw.println(((mi + " ") + mj)); pw.close(); } }
3	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ long MOD = ((long)1e9 + 7); long[][] dp ; int[] a ; public void solve( int testNumber, InputReader in, OutputWriter out){ int N = in.nextInt(); a = new int[N]; dp = new long[N][N]; int i ; for ( i = 0;(i < N);i++) { char c = in.nextChar(); if ( (c == 'f')) {a[i] = 1; } }out.printLine(iterative()); } public long iterative(){ int i ,j ,N = a.length,lastLevel = 0; dp[0][0] = 1; for ( i = 1;(i < N);i++) {if ( (a[(i - 1)] == 1)) {lastLevel++; for ( j = 1;(j <= lastLevel);j++) {dp[i][j] = dp[(i - 1)][(j - 1)]; }} else {dp[i][(N - 1)] = dp[(i - 1)][(N - 1)]; for ( j = (N - 2);(j >= 0);j--) {dp[i][j] = ((dp[i][(j + 1)] + dp[(i - 1)][j]) % MOD); }}} long ans = 0; for ( i = 0;(i < N);i++) {ans += dp[(N - 1)][i]; }return (ans % MOD);} } static class InputReader{ BufferedReader in ; StringTokenizer tokenizer = null; public InputReader( InputStream inputStream){ in = new BufferedReader(new InputStreamReader(inputStream)); } public String next(){ try{while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(in.readLine()); }return tokenizer.nextToken(); }catch (IOException e){ return null;} } public int nextInt(){ return Integer.parseInt(next());} public char nextChar(){ return next().charAt(0);} } static class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void print( Object... objects){ for ( int i = 0;(i < objects.length);i++) {if ( (i != 0)) writer.print(' '); writer.print(objects[i]); }} public void printLine( Object... objects){ print(objects); writer.println(); } public void close(){ writer.close(); } } }
0	public class ElevatorOrStairs{ static private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static private final OutputStreamWriter writer = new OutputStreamWriter(System.out); public static void main( String... strings)throws Exception { String[] specs = reader.readLine().split(" ");  int x = Integer.parseInt(specs[0]);  int y = Integer.parseInt(specs[1]);  int z = Integer.parseInt(specs[2]);  int t1 = Integer.parseInt(specs[3]);  int t2 = Integer.parseInt(specs[4]);  int t3 = Integer.parseInt(specs[5]); reader.close(); String ans = solve(x,y,z,t1,t2,t3); writer.append(ans); writer.flush(); writer.close(); } static private String solve( int x, int y, int z, int t1, int t2, int t3){ int time_using_stairs = (Math.abs((x - y)) * t1);  int elevator_time_between_floor = (Math.abs((x - z)) * t2);  int elevator_from_z_to_x = (elevator_time_between_floor + (2 * t3));  int time_using_elevator = ((elevator_from_z_to_x + (Math.abs((x - y)) * t2)) + t3); if ( (time_using_elevator <= time_using_stairs)) {return "YES";} return "NO";} }
5	public class Main{ static int sum = 0; public static void main( String[] args)throws Exception { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = ni(sc),x[] = new int[(n + 1)]; for ( int i = 1;(i <= n);i++) x[i] = ni(sc); sort(x); if ( (x[n] == 1)) {x[n] = 2; for ( int i = 1;(i <= n);i++) System.out.print((x[i] + " ")); } else {x[0] = 1; for ( int i = 0;(i < n);i++) System.out.print((x[i] + " ")); }}} static int ni( Scanner in){ return in.nextInt();} }
3	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);  C909 solver = new C909(); solver.solve(1,in,out); out.close(); } static class C909{ int N ; long MOD = 1_000_000_007; boolean[] type ; long[][] memo ; long dp( int cmd, int dep){ if ( (dep < 0)) return 0; if ( (cmd == N)) return 1; if ( (memo[cmd][dep] != -1)) return memo[cmd][dep]; boolean safe = ((cmd == 0)?true:!type[(cmd - 1)]);  int d = (type[cmd]?1:0);  long ways = 0; if ( !safe) {ways += dp((cmd + 1),(dep + d)); ways %= MOD; } else {ways += dp((cmd + 1),(dep + d)); ways %= MOD; ways += dp(cmd,(dep - 1)); ways %= MOD; }return memo[cmd][dep] = ways;} public void solve( int testNumber, FastScanner s, PrintWriter out){ N = s.nextInt(); type = new boolean[N]; for ( int i = 0;(i < N);i++) {type[i] = (s.next().charAt(0) == 'f'); }memo = new long[N][(N + 1)]; for ( long[] a :memo) Arrays.fill(a,-1); out.println(dp(0,0)); } } static class FastScanner{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public FastScanner( InputStream stream){ this.stream = stream; } int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public int nextInt(){ return Integer.parseInt(next());} public String next(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} } }
3	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ public void solve( int testNumber, InputReader in, OutputWriter out){ int n = in.readInt();  boolean[] isF = new boolean[n]; for ( int i = 0;(i < n);i++) {isF[i] = (in.readCharacter() == 'f'); } int[][] mem = new int[(n + 1)][(n + 1)]; mem[n][0] = 1; for ( int idx = (n - 1);(idx >= 0);idx--) {for ( int indentLevel = 0;(indentLevel < n);indentLevel++) {mem[(idx + 1)][(indentLevel + 1)] += mem[(idx + 1)][indentLevel]; mem[(idx + 1)][(indentLevel + 1)] %= MiscUtils.MOD7; int res = (isF[idx]?(mem[(idx + 1)][(indentLevel + 1)] - mem[(idx + 1)][indentLevel]):mem[(idx + 1)][indentLevel]); mem[idx][indentLevel] = ((res + MiscUtils.MOD7) % MiscUtils.MOD7); }}out.printLine(mem[0][0]); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char readCharacter(){ int c = read(); while(isSpaceChar(c)){c = read(); }return (char)c;} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } static class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void close(){ writer.close(); } public void printLine( int i){ writer.println(i); } } }
1	public class Main{ public static void main( String[] args){ Scanner stdin = new Scanner(System.in); test(stdin); stdin.close(); } public static void test( Scanner stdin){ int n = stdin.nextInt();  int min = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int a = stdin.nextInt(); if ( ((int)((1.0 * a) / Math.max(i,((n - i) - 1))) < min)) {min = (int)((1.0 * a) / Math.max(i,((n - i) - 1))); } }System.out.println(min); } }
3	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);  E solver = new E(); solver.solve(1,in,out); out.close(); } static class E{ public void solve( int testNumber, FastScanner in, PrintWriter out){ int n = in.ni(),K = in.ni();  long mod = 998244353;  long[][] dp = new long[(n + 1)][(n + 1)]; for ( int lim = 1;(lim <= n);lim++) { long sum = 1; dp[0][lim] = 1; for ( int i = 1;(i <= n);i++) {dp[i][lim] = ((dp[i][lim] + sum) % mod); sum = ((sum + dp[i][lim]) % mod); if ( (i >= lim)) sum = (((sum - dp[(i - lim)][lim]) + mod) % mod); }} long ans = 0; for ( int k = 1;(k < Math.min(K,(n + 1)));k++) { long h = (dp[n][k] - dp[n][(k - 1)]);  int lim = (K / k); if ( ((K % k) == 0)) lim--; if ( (lim > n)) lim = n; ans += ((dp[n][lim] * h) % mod); }out.println(((2 * ans) % mod)); } } static class FastScanner{ private BufferedReader in ; private StringTokenizer st ; public FastScanner( InputStream stream){ in = new BufferedReader(new InputStreamReader(stream)); } public String ns(){ 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 ni(){ return Integer.parseInt(ns());} } }
2	public class PipelineSolver{ private long n ; private long k ; public static void main( String[] args){ PipelineSolver solver = new PipelineSolver(); solver.readData(); int solution = solver.solve(); solver.print(solution); } private int gcd( int a, int b){ return ((b == 0)?a:gcd(b,(a % b)));} private void print( int[] values){ StringBuilder builder = new StringBuilder(); for ( int value :values) {builder.append(value); builder.append(" "); }print(builder); } private void print( Object value){ System.out.println(value); } private void print( boolean value){ System.out.println((value?"YES":"NO")); } private void print( int value){ System.out.println(value); } private void print( long value){ System.out.println(value); } private void print( double value){ System.out.printf(Locale.ENGLISH,"%.10f",value); } private void readData(){ Scanner scanner = new Scanner(System.in); n = scanner.nextLong(); k = scanner.nextLong(); } private int solve(){ if ( (n == 1)) {return 0;} if ( (n <= k)) {return 1;} int result ;  long l ;  long d = (((5 - (2 * k)) * (5 - (2 * k))) - (4 * (((2 * n) - (4 * k)) + 4))); if ( (d < 0)) {result = -1; } else {l = Math.min(Math.max((int)((((2 * k) - 3) - Math.sqrt(d)) / 2),0),Math.max((int)((((2 * k) - 3) + Math.sqrt(d)) / 2),0)); long difference = ((n - (k * (l + 1))) + ((l * (l + 3)) / 2)); if ( (l > (k - 2))) {result = -1; } else if ( (l == (k - 2))) {result = ((difference == 0)?(int)(l + 1):-1); } else {result = (int)((l + 1) + ((difference == 0)?0:1)); }}return result;} }
5	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);  CGlassCarving solver = new CGlassCarving(); solver.solve(1,in,out); out.close(); } static class CGlassCarving{ public void solve( int testNumber, FastReader s, PrintWriter out){ TreeMap<Long,Integer> mapH = new TreeMap<>();  TreeMap<Long,Integer> mapV = new TreeMap<>();  TreeMap<Long,Integer> hDiff = new TreeMap<>();  TreeMap<Long,Integer> vDiff = new TreeMap<>();  long width = s.nextInt();  long height = s.nextInt(); mapH.put(0L,1); mapV.put(0L,1); mapV.put(width,1); mapH.put(height,1); vDiff.put(width,1); hDiff.put(height,1); long maxV = height;  long maxH = width;  int n = s.nextInt(); for ( int i = 0;(i < n);i++) { char ch = s.nextCharacter();  long cut = s.nextInt(); if ( (ch == 'H')) { Long next = mapH.higherKey(cut);  Long prev = mapH.lowerKey(cut);  Long diff = (next - prev);  int freq = hDiff.get(diff); if ( (freq == 1)) {hDiff.remove(diff); } else {hDiff.put(diff,(freq - 1)); }hDiff.put((next - cut),(hDiff.getOrDefault((next - cut),0) + 1)); hDiff.put((cut - prev),(hDiff.getOrDefault((cut - prev),0) + 1)); mapH.put(cut,(mapH.getOrDefault(cut,0) + 1)); } else { Long next = mapV.higherKey(cut);  Long prev = mapV.lowerKey(cut);  Long diff = (next - prev);  int freq = vDiff.get(diff); if ( (freq == 1)) {vDiff.remove(diff); } else {vDiff.put(diff,(freq - 1)); }vDiff.put((next - cut),(vDiff.getOrDefault((next - cut),0) + 1)); vDiff.put((cut - prev),(vDiff.getOrDefault((cut - prev),0) + 1)); mapV.put(cut,(mapV.getOrDefault(cut,0) + 1)); }out.println((hDiff.lastKey() * vDiff.lastKey())); }} } static class FastReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private FastReader.SpaceCharFilter filter ; public FastReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char nextCharacter(){ int c = read(); while(isSpaceChar(c)){c = read(); }return (char)c;} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
5	public class CottageVillage{ Scanner in ; PrintWriter out ; CottageVillage(){ in = new Scanner(System.in); out = new PrintWriter(System.out); } public void finalize(){ out.flush(); in.close(); out.close(); } int ans( House a, House b, int t){ int diff = (b.cordl - a.cordr); if ( (diff < t)) return 0; if ( (diff == t)) return 1; return 2;} void solve(){ int n = in.nextInt(),t = (in.nextInt() * 2);  House[] hs = new House[n]; for ( int i = 0;(i < n);++i) { int c = in.nextInt(),l = in.nextInt(); hs[i] = new House(((2 * c) - l),((2 * c) + l)); }Arrays.sort(hs); int co = 2; for ( int i = 0;(i < (n - 1));++i) co += ans(hs[i],hs[(i + 1)],t); out.println(co); } public static void main( String[] args)throws FileNotFoundException { CottageVillage t = new CottageVillage(); t.solve(); t.finalize(); } } class House implements Comparable<House>{ public int cordl ,cordr ; public House( int c, int l){ cordl = c; cordr = l; } }
2	public class Pipeline{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  long n = in.nextLong();  long k = in.nextLong(); if ( (n == 1)) {System.out.println(0); return ;} if ( (k >= n)) {System.out.println(1); return ;} long total = ((((k + 2) * (k - 1)) / 2) - (k - 2)); if ( (total < n)) {System.out.println(-1); return ;} int i = 2,j = (int)k; while((i < j)){ int m = (((i + j) + 1) / 2); total = ((((k + m) * ((k - m) + 1)) / 2) - (k - m)); if ( (total < n)) j = (m - 1); else i = m; }System.out.println(((k - i) + 1)); } }
2	public class B{ public static void main( String[] args){ MScanner sc = new MScanner();  PrintWriter out = new PrintWriter(System.out);  long N = sc.nextLong();  long X = sc.nextLong();  long Y = sc.nextLong();  long C = sc.nextLong();  long low = 0;  long high = (N * 2);  long mid = 0;  long ans = 0; while((low <= high)){mid = ((low + high) >> 1); long painted = F(mid,(X - 1),(Y - 1),N); if ( (painted < C)) {low = (mid + 1); } else {ans = mid; high = (mid - 1); }}out.println(ans); out.close(); } static private long F( long mid, long x, long y, long n){ long base = (((2 * mid) * (mid + 1)) + 1); base -= excess((mid - x)); base -= excess((mid - y)); base -= excess((mid - ((n - 1) - x))); base -= excess((mid - ((n - 1) - y))); base += corner((mid - ((x + y) + 1))); base += corner((mid - ((x + ((n - y) - 1)) + 1))); base += corner((mid - ((((n - x) - 1) + y) + 1))); base += corner((mid - ((1 + ((n - 1) - y)) + ((n - 1) - x)))); return base;} static private long corner( long a){ if ( (a < 0)) return 0; return (((a * a) + a) >> 1);} static private long excess( long thing){ if ( (thing < 0)) return 0; return (thing * thing);} static class MScanner{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public MScanner(){ stream = System.in; } int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} boolean isEndline( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} int nextInt(){ return Integer.parseInt(next());} int[] nextInt( int N){ int[] ret = new int[N]; for ( int a = 0;(a < N);a++) ret[a] = nextInt(); return ret;} int[][] nextInt( int N, int M){ int[][] ret = new int[N][M]; for ( int a = 0;(a < N);a++) ret[a] = nextInt(M); return ret;} long nextLong(){ return Long.parseLong(next());} long[] nextLong( int N){ long[] ret = new long[N]; for ( int a = 0;(a < N);a++) ret[a] = nextLong(); return ret;} double nextDouble(){ return Double.parseDouble(next());} double[] nextDouble( int N){ double[] ret = new double[N]; for ( int a = 0;(a < N);a++) ret[a] = nextDouble(); return ret;} String next(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} String[] next( int N){ String[] ret = new String[N]; for ( int a = 0;(a < N);a++) ret[a] = next(); return ret;} String nextLine(){ int c = read(); while(isEndline(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isEndline(c));return res.toString();} String[] nextLine( int N){ String[] ret = new String[N]; for ( int a = 0;(a < N);a++) ret[a] = nextLine(); return ret;} } }
6	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(new BufferedWriter(new OutputStreamWriter(System.out)));  int T = 1; for ( int t = 0;(t < T);t++) { int n = Int(),k = Int();  int A[][] = new int[n][2]; for ( int i = 0;(i < n);i++) {A[i][0] = Int(); A[i][1] = Int(); } Solution sol = new Solution(out); sol.solution(A,k); }out.close(); } public static int Int(){ return fs.Int();} public static long Long(){ return fs.Long();} public static String Str(){ return fs.Str();} } class Solution{ PrintWriter out ; public Solution( PrintWriter out){ this.out = out; } long dp[][] ; int mod = 1000000007; int time ; public void solution( int[][] A, int t){ this.time = t; dp = new long[4][(1 << (A.length + 2))]; for ( int i = 0;(i < dp.length);i++) {Arrays.fill(dp[i],-1); } long a = dfs(A,0,((1 << A.length) - 1)); out.println(a); } public long dfs( int[][] A, int pre, int state){ int use = cal(A,state); if ( ((time - use) == 0)) {return 1;} if ( ((time < use) || (state == 0))) {return 0;} if ( (dp[pre][state] != -1)) return dp[pre][state]; long res = 0; for ( int i = 0;(i < A.length);i++) {if ( (((state & (1 << i)) != 0) && (A[i][1] != pre))) {res += dfs(A,A[i][1],(state ^ (1 << i))); res %= mod; } }dp[pre][state] = res; return res;} public int cal( int[][] A, int state){ int t = 0; for ( int i = 0;(i < A.length);i++) {if ( ((state & (1 << i)) == 0)) {t += A[i][0]; } }return t;} }
5	public class CottageVillage{ public Scanner in = new Scanner(System.in); public PrintStream out = System.out; public int n ,t ; public Pair[] v ; public void main(){ n = in.nextInt(); t = in.nextInt(); int i ; v = new Pair[n]; for ( i = 0;(i < n);++i) v[i] = new Pair((in.nextInt() * 2),in.nextInt()); Arrays.sort(v); int res = 2; for ( i = 0;((i + 1) < n);++i) {if ( (((v[i].x + v[i].y) + (2 * t)) == (v[(i + 1)].x - v[(i + 1)].y))) ++res; else if ( (((v[i].x + v[i].y) + (2 * t)) < (v[(i + 1)].x - v[(i + 1)].y))) res += 2; }out.println(res); } private class Pair implements Comparable<Pair>{ public int x ,y ; public Pair( int xx, int yy){ x = xx; y = yy; } } public static void main( String[] args){ new CottageVillage().main(); } }
4	public class x35C{ public static void main( String[] hi)throws Exception { BufferedReader infile = new BufferedReader(new FileReader("input.txt"));  StringTokenizer st = new StringTokenizer(infile.readLine());  int N = Integer.parseInt(st.nextToken());  int M = Integer.parseInt(st.nextToken());  int K = Integer.parseInt(infile.readLine());  int[][] grid = new int[N][M]; for ( int i = 0;(i < N);i++) Arrays.fill(grid[i],-1); ArrayDeque<Integer> q = new ArrayDeque<Integer>(); st = new StringTokenizer(infile.readLine()); while((K-- > 0)){ int a = (Integer.parseInt(st.nextToken()) - 1);  int b = (Integer.parseInt(st.nextToken()) - 1); grid[a][b] = 0; q.add(a); q.add(b); }while((q.size() > 0)){ int x = q.poll();  int y = q.poll(); if ( ((x > 0) && (grid[(x - 1)][y] == -1))) {grid[(x - 1)][y] = (grid[x][y] + 1); q.add((x - 1)); q.add(y); } if ( ((y > 0) && (grid[x][(y - 1)] == -1))) {grid[x][(y - 1)] = (grid[x][y] + 1); q.add(x); q.add((y - 1)); } if ( (((x + 1) < N) && (grid[(x + 1)][y] == -1))) {grid[(x + 1)][y] = (grid[x][y] + 1); q.add((x + 1)); q.add(y); } if ( (((y + 1) < M) && (grid[x][(y + 1)] == -1))) {grid[x][(y + 1)] = (grid[x][y] + 1); q.add(x); q.add((y + 1)); } } int r = 0;  int c = 0; for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) if ( (grid[r][c] < grid[i][j])) {r = i; c = j; } r++; c++; System.setOut(new PrintStream(new File("output.txt"))); System.out.println(((r + " ") + c)); } }
4	public class Main{ public static void main( String[] args)throws IOException { File f = new File("input.txt");  Scanner sc = new Scanner(f);  BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.txt")));  int n = sc.nextInt();  int m = sc.nextInt();  boolean[][] grid = new boolean[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) grid[i][j] = false; Queue<Pair> q = new LinkedList<>();  int cnt = sc.nextInt(); for ( int i = 0;(i < cnt);i++) { int x = sc.nextInt();  int y = sc.nextInt(); x--; y--; grid[x][y] = true; q.add(new Pair(x,y)); } Pair last = new Pair(-1,-1); while(!q.isEmpty()){ Pair current = q.poll(); last = current; for ( int i = -1;(i <= 1);i++) {for ( int j = -1;(j <= 1);j++) {if ( ((i != 0) && (j != 0))) continue; if ( (inside((current.x + i),(current.y + j),n,m) && !grid[(current.x + i)][(current.y + j)])) {grid[(current.x + i)][(current.y + j)] = true; q.add(new Pair((current.x + i),(current.y + j))); } }}}bw.append(((((last.x + 1) + " ") + (last.y + 1)) + "\n")); bw.flush(); bw.close(); sc.close(); } static class Pair{ int x ; int y ; Pair( int x, int y){ this.x = x; this.y = y; } } static private boolean inside( int a, int b, int n, int m){ return ((((a >= 0) && (a < n)) && (b >= 0)) && (b < m));} }
1	public class C{ static String s ; static long val[] ; static int N ,size ; static int index( char c){ if ( (c <= 'Z')) {return (c - 'A');} else {return ((c - 'a') + (('Z' - 'A') + 1));}} static int l( int i){ return ((i << 1) + 1);} static int r( int i){ return ((i << 1) + 2);} static void setup( int l, int r, int i){ if ( (l == r)) {val[i] = (1L << index(s.charAt(l))); } else { int mid = ((l + r) / 2); setup(l,mid,l(i)); setup((mid + 1),r,r(i)); val[i] = (val[l(i)] | val[r(i)]); }} static long query( int min, int max, int l, int r, int i){ if ( ((min <= l) && (r <= max))) {return val[i];} if ( ((max < l) || (r < min))) return 0; int mid = ((l + r) / 2); return (query(min,max,l,mid,l(i)) | query(min,max,(mid + 1),r,r(i)));} static long query( int min, int max){ return query(min,max,0,(N - 1),0);} static int binarySearch( int start, long toFind){ int max = (N - 1);  int min = start; if ( (query(start,max) != toFind)) return (1 << 29); if ( (query(start,start) == toFind)) {return 1;} int ret = ((max - min) + 1); while(((min + 1) < max)){ int mid = ((min + max) / 2); if ( (query(start,mid) == toFind)) {max = mid; } else {min = mid; }}return ((max - start) + 1);} public static void main( String[] args){ Scanner sc = new Scanner(System.in); N = sc.nextInt(); s = sc.next(); int size = 1; while((size <= N))size *= 2; val = new long[(size * 2)]; setup(0,(N - 1),0); long toFind = query(0,(N - 1),0,(N - 1),0);  long ans = (1L << 29); for ( int i = 0;(i < N);i++) ans = Math.min(ans,binarySearch(i,toFind)); System.out.println(ans); } }
1	public class TestClass11{ public static void main( String[] args){ InputReader in = new InputReader(System.in);  OutputWriter out = new OutputWriter(System.out);  int n = in.readInt();  String s = in.readString();  int low[] = new int[26];  int upper[] = new int[26];  boolean islow[] = new boolean[26];  boolean isupper[] = new boolean[26]; Arrays.fill(low,Integer.MAX_VALUE); Arrays.fill(upper,Integer.MAX_VALUE); int ans[] = new int[n];  int finalsans = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int c = s.charAt(i); if ( ((c >= 'a') && (c <= 'z'))) {islow[(c - 'a')] = true; } else {isupper[(c - 'A')] = true; }}for ( int i = (n - 1);(i >= 0);i--) { int c = s.charAt(i); if ( ((c >= 'a') && (c <= 'z'))) {low[(c - 'a')] = i; } else {upper[(c - 'A')] = i; }for ( int j = 0;(j < 26);j++) {if ( (islow[j] == true)) {ans[i] = Math.max(ans[i],low[j]); } }for ( int j = 0;(j < 26);j++) {if ( (isupper[j] == true)) {ans[i] = Math.max(ans[i],upper[j]); } }finalsans = Math.min(((ans[i] - i) + 1),finalsans); }System.out.println(finalsans); } } class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void print( Object... objects){ for ( int i = 0;(i < objects.length);i++) {if ( (i != 0)) writer.print(' '); writer.print(objects[i]); }} public void close(){ writer.close(); } public void flush(){ writer.flush(); } }
2	public class P{ public static void main( String[] args)throws NumberFormatException,IOException { Scanner sc = new Scanner();  PrintWriter out = new PrintWriter(System.out);  int N = sc.nextInt(),x = sc.nextInt(),y = sc.nextInt();  long C = sc.nextLong();  int lo = 0,hi = (int)1e6;  int answer = -1; while((lo <= hi)){ int L = (lo + ((hi - lo) / 2));  long area = 0; for ( int steps = 0;(steps <= L);++steps) {if ( ((y + steps) > N)) break; long up = Math.min(x,((1 + L) - steps)),down = Math.min((N - x),(L - steps)); area += (up + down); }for ( int steps = 1;(steps <= L);++steps) {if ( ((y - steps) < 1)) break; long up = Math.min(x,((1 + L) - steps)),down = Math.min((N - x),(L - steps)); area += (up + down); }if ( (area >= C)) {answer = L; hi = (L - 1); } else lo = (L + 1); }out.println(answer); out.flush(); out.close(); } static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner(){ br = new BufferedReader(new InputStreamReader(System.in)); } Scanner( String file)throws FileNotFoundException{ br = new BufferedReader(new FileReader(file)); } String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(next());} long nextLong()throws NumberFormatException,IOException { return Long.parseLong(next());} } }
5	public class P15A{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int n = scan.nextInt(),t = scan.nextInt();  TreeMap<Integer,Integer> hm = new TreeMap<Integer,Integer>(); for ( int i = 0;(i < n);i++) hm.put(scan.nextInt(),scan.nextInt()); int _x = 0,_a = 0,res = 2;  boolean started = false; for ( Integer key :hm.keySet()) {if ( !started) {_x = key; _a = hm.get(_x); started = true; continue;} if ( (((key - _x) - (((Integer)hm.get(key) + _a) / 2.0)) > t)) res += 2; else if ( (((key - _x) - (((Integer)hm.get(key) + _a) / 2.0)) == t)) res++; _x = key; _a = hm.get(_x); }System.out.println(res); } }
4	public class Main{ static class Point{ int x ; int y ; Point( int a, int b){ x = a; y = b; } } public static void main( String[] args)throws IOException { File f = new File("input.txt");  Scanner sc = new Scanner(f);  BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.txt")));  int n = sc.nextInt();  int m = sc.nextInt();  boolean[][] board = new boolean[n][m];  int count = sc.nextInt();  Point[] burningTrees = new Point[count]; for ( int i = 0;(i < count);i++) {burningTrees[i] = new Point((sc.nextInt() - 1),(sc.nextInt() - 1)); } Point last = findLastPoint(board,burningTrees); bw.append(((((last.x + 1) + " ") + (last.y + 1)) + "\n")); bw.flush(); bw.close(); sc.close(); } public static Point findLastPoint( boolean[][] board, Point[] burningTree){ Queue<Point> queue = new LinkedList<Point>(); for ( int i = 0;(i < burningTree.length);i++) {queue.add(burningTree[i]); board[burningTree[i].x][burningTree[i].y] = true; } Point lastPoint = new Point(-1,-1); while(!queue.isEmpty()){ Point p = queue.poll(); lastPoint = p; ArrayList<Point> neighbours = getNeighbours(p,board); for ( int i = 0;(i < neighbours.size());i++) {queue.add(neighbours.get(i)); board[neighbours.get(i).x][neighbours.get(i).y] = true; }}return lastPoint;} public static ArrayList<Point> getNeighbours( Point p, boolean[][] board){ ArrayList<Point> neighbours = new ArrayList<>(); for ( int i = -1;(i <= 1);i++) {for ( int j = -1;(j <= 1);j++) {if ( (Math.abs(i) != Math.abs(j))) { int x = (p.x + i);  int y = (p.y + j); if ( ((((x >= 0) && (x < board.length)) && (y >= 0)) && (y < board[0].length))) {if ( (board[x][y] == false)) {neighbours.add(new Point(x,y)); } } } }}return neighbours;} }
1	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 n = (int)in.nval; in.nextToken(); String st = in.sval;  char[] a = new char[n]; for ( int i = 0;(i < n);i++) a[i] = st.charAt(i); int kH = 0;  int kT = 0; for ( int i = 0;(i < n);i++) if ( (a[i] == 'T')) kT++; else kH++; int kol = 0;  int min = Integer.MAX_VALUE;  int poz ; for ( int i = 0;(i < n);i++) {kol = 0; if ( (a[i] == 'T')) {for ( int j = 0;(j < kT);j++) {poz = ((i + j) % n); if ( (a[poz] == 'H')) kol++; }if ( (kol < min)) min = kol; } else {for ( int j = 0;(j < kH);j++) {poz = ((i + j) % n); if ( (a[poz] == 'T')) kol++; }if ( (kol < min)) min = kol; }}out.print(min); out.flush(); } }
1	public class P3{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  String s = ""; while((s.length() == 0)){s = sc.nextLine(); } char[] pokemons = s.toCharArray();  Set<Character> pokemonTypes = new HashSet<>(); for ( int i = 0;(i < n);i++) {pokemonTypes.add(pokemons[i]); } int types = pokemonTypes.size();  int l = 0;  int r = 0;  int min = n;  Map<Character,Integer> currentPokemons = new HashMap<>(); while((r < n)){while(((currentPokemons.size() < types) && (r < n))){ char pokemon = pokemons[r++]; currentPokemons.merge(pokemon,1,(a,b)->(a + b)); }min = Math.min((r - l),min); while((currentPokemons.size() == types)){ char pokemon = pokemons[l++]; if ( (currentPokemons.get(pokemon) == 1)) {currentPokemons.remove(pokemon); } else {min = Math.min((r - l),min); currentPokemons.put(pokemon,(currentPokemons.get(pokemon) - 1)); }}}min = Math.min(min,((r - l) + 1)); min = Math.max(min,types); System.out.println(min); } }
3	public class Main{ public static void main( String[] args)throws IOException { PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));  FastScanner sc = new FastScanner();  int dp[][] = new int[6000][6000];  char a[] = new char[6000]; final int n = sc.nextInt();  boolean flag = false;  int cnt = 0;  char pre = 'f'; for ( int i = 1;(i <= n);i++) {a[i] = sc.next().charAt(0); }dp[1][1] = 1; final int mod = ((int)1e9 + 7); dp[1][1] = 1; for ( int i = 2;(i <= n);i++) {if ( (a[(i - 1)] == 's')) { int now = 0; for ( int j = 5050;(j >= 1);j--) {now = ((now + dp[(i - 1)][j]) % mod); dp[i][j] = now; }} else {for ( int j = 5050;(j >= 1);j--) {dp[i][j] = (dp[(i - 1)][(j - 1)] % mod); }}} int ans = 0; for ( int i = 0;(i <= 5050);i++) {ans += (dp[n][i] % mod); ans %= mod; }out.println((ans % mod)); out.flush(); } static class FastScanner{ BufferedReader br ; StringTokenizer st ; private FastScanner(){ try{br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); }catch (Exception e){ e.printStackTrace(); } } private String next(){ if ( st.hasMoreTokens()) return st.nextToken(); try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ e.printStackTrace(); } return st.nextToken();} private int nextInt(){ return Integer.parseInt(next());} private long nextLong(){ return Long.parseLong(next());} private double nextDouble(){ return Double.parseDouble(next());} } }
6	public class B{ static int n ,t[] ,g[] ,MOD = ((int)1e9 + 7); static int[][] memo ; static int dp( int msk, int rem, int lastG){ if ( (rem == 0)) return 1; if ( (memo[lastG][msk] != -1)) return memo[lastG][msk]; int ans = 0; for ( int i = 0;(i < n);i++) {if ( ((((msk & (1 << i)) == 0) && (rem >= t[i])) && (g[i] != lastG))) ans += dp((msk | (1 << i)),(rem - t[i]),g[i]); if ( (ans >= MOD)) ans -= MOD; }return memo[lastG][msk] = ans;} public static void main( String[] args)throws IOException { Scanner sc = new Scanner();  PrintWriter out = new PrintWriter(System.out); n = sc.nextInt(); int T = sc.nextInt(); t = new int[n]; g = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = sc.nextInt(); g[i] = (sc.nextInt() - 1); }memo = new int[4][(1 << n)]; for ( int[] x :memo) Arrays.fill(x,-1); out.println(dp(0,T,3)); out.close(); } static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner(){ br = new BufferedReader(new InputStreamReader(System.in)); } Scanner( String fileName)throws FileNotFoundException{ br = new BufferedReader(new FileReader(fileName)); } 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());} boolean ready()throws IOException { return br.ready();} } }
5	public class Main{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int[][] point = new int[n][]; for ( int i = 0;(i < n);i++) point[i] = new int[]{sc.nextInt(),sc.nextInt()}; Arrays.sort(point,(a,b)->((a[0] - a[1]) - (b[0] - b[1]))); TreeMap<Integer,Integer> tm = new TreeMap<>();  int ans = 0; for ( int i = (n - 1);(i >= 0);i--) { int x = point[i][0],w = point[i][1];  Map.Entry<Integer,Integer> cur = tm.ceilingEntry((x + w));  int curRes ; if ( (cur == null)) curRes = 1; else curRes = (cur.getValue() + 1); ans = Math.max(ans,curRes); Map.Entry<Integer,Integer> upper = tm.ceilingEntry((x - w)); if ( ((upper == null) || (upper.getValue() < curRes))) tm.put((x - w),curRes); }System.out.println(ans); } }
5	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);  TaskG solver = new TaskG(); solver.solve(1,in,out); out.close(); } static class TaskG{ static int[][] g ; static int n ; static int[] a ; static int[][] edges ; static long[] dp ; static long[] dpPathToRootWithDetours ; static int time = 0; static int[] appearance ; static int[] firstAppearance ; static int[] depth ; public static void dfs( int i, int parE){ firstAppearance[i] = time; appearance[time++] = i; dp[i] = a[i]; for ( int eIndex :g[i]) {if ( (eIndex == parE)) continue; int child = ((i ^ edges[eIndex][0]) ^ edges[eIndex][1]); dfs(child,eIndex); appearance[time++] = i; dp[i] += Math.max((dp[child] - (edges[eIndex][2] * 2)),0); }} public static void dfs2( int i, int parE){ if ( (i == 0)) {dpPathToRootWithDetours[i] = dp[i]; } else { int par = ((i ^ edges[parE][0]) ^ edges[parE][1]); depth[i] = (depth[par] + 1); dpPathToRootWithDetours[i] = (dpPathToRootWithDetours[par] - Math.max(0,(dp[i] - (edges[parE][2] * 2)))); dpPathToRootWithDetours[i] -= edges[parE][2]; dpPathToRootWithDetours[i] += dp[i]; long myPathWeight = Math.max((dp[i] - (edges[parE][2] * 2)),0);  long change = ((dp[par] - myPathWeight) - (edges[parE][2] * 2)); change = Math.max(change,0); dp[i] += change; }for ( int eIndex :g[i]) {if ( (eIndex == parE)) continue; dfs2(((i ^ edges[eIndex][0]) ^ edges[eIndex][1]),eIndex); }} public void solve( int testNumber, InputReader in, PrintWriter out){ n = in.NextInt(); int q = in.NextInt(); a = in.NextIntArray(n); edges = new int[(n - 1)][3]; { long[] count = new long[n]; for ( int i = 0;(i < (n - 1));i++) { int u = (in.NextInt() - 1);  int v = (in.NextInt() - 1);  int w = in.NextInt(); edges[i][0] = u; edges[i][1] = v; edges[i][2] = w; count[u]++; count[v]++; }g = new int[n][]; for ( int i = 0;(i < n);i++) {g[i] = new int[(int)count[i]]; }for ( int i = 0;(i < (n - 1));i++) {for ( int j = 0;(j < 2);j++) {g[edges[i][j]][(int)--count[edges[i][j]]] = i; }}}dp = new long[n]; dpPathToRootWithDetours = new long[n]; depth = new int[n]; firstAppearance = new int[n]; appearance = new int[(((n - 1) * 2) + 1)]; dfs(0,-1); dfs2(0,-1); GraphLowestCommonAncestor.LCA lca = GraphLowestCommonAncestor.createLCA(appearance,firstAppearance,depth); firstAppearance = null; depth = null; appearance = null; edges = null; g = null; for ( int i = 0;(i < q);i++) { int u = (in.NextInt() - 1);  int v = (in.NextInt() - 1);  int lcaI = lca.getLCA(u,v);  long res = (((dpPathToRootWithDetours[u] + dpPathToRootWithDetours[v]) - (2 * dpPathToRootWithDetours[lcaI])) + dp[lcaI]); out.println(res); }} } static class MinRangeSparseTable implements ISearchInRange{ private final int[][] sparseTables ; private final long[] array ; private final boolean reverseOrdered ; public MinRangeSparseTable( long[] array, boolean reverseOrdered){ this.reverseOrdered = reverseOrdered; this.array = array; int LCALength = IntegerExtension.getNumberOfBits(array.length); sparseTables = new int[LCALength][]; sparseTables[0] = new int[array.length]; for ( int i = 0;(i < array.length);i++) {sparseTables[0][i] = i; }for ( int i = 1;(i < LCALength);i++) { int size = (1 << i);  int jumpSize = (1 << (i - 1)); sparseTables[i] = new int[((sparseTables[0].length - size) + 1)]; for ( int j = 0;(j < sparseTables[i].length);j++) {sparseTables[i][j] = min(sparseTables[(i - 1)][j],sparseTables[(i - 1)][(j + jumpSize)]); }}} private int min( int a, int b){ return (((array[a] < array[b]) ^ reverseOrdered)?a:b);} public Pair<Long,Long> queryIndexValueInRange( long l, long r){ int size = (int)((r - l) + 1);  int LCAIndex = (IntegerExtension.getNumberOfBits(size) - 1);  int sizeNeeded = (1 << LCAIndex);  int res = min(sparseTables[LCAIndex][(int)l],sparseTables[LCAIndex][(int)((r - sizeNeeded) + 1)]); return new Pair<>((long)res,array[res]);} public MinRangeSparseTable( long[] array){ this(array,false); } } static class InputReader{ BufferedReader reader ; 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()," \t\n\r\f,"); }catch (IOException e){ throw (new RuntimeException(e));} }return tokenizer.nextToken();} public int NextInt(){ return Integer.parseInt(next());} public int[] NextIntArray( int n){ return NextIntArray(n,0);} public int[] NextIntArray( int n, int offset){ int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = (NextInt() + offset); }return a;} } static interface ISearchInRange{ } }
1	public class Main{ FastScanner in ; PrintWriter out ; static final String FILE = ""; public void solve(){ int n = in.nextInt();  TreeMap<Character,Integer> map = new TreeMap<>();  ArrayList<Integer> list = new ArrayList<>();  String s = in.next(); for ( int i = 0;(i < n);i++) { char ch = s.charAt(i); if ( !map.containsKey(ch)) map.put(ch,map.size()); list.add(map.get(ch)); } int l = 0;  int ans = Integer.MAX_VALUE;  int nad = map.size();  int cnt[] = new int[n]; for ( int i = 0;(i < list.size());i++) {if ( (cnt[list.get(i)] == 0)) nad--; cnt[list.get(i)]++; if ( (nad == 0)) {ans = min(ans,((i - l) + 1)); while(true){if ( (cnt[list.get(l)] == 1)) {ans = min(ans,((i - l) + 1)); cnt[list.get(l)]--; l++; nad++; break;} else {cnt[list.get(l)]--; l++; }}} }out.print(ans); } public void run(){ if ( FILE.equals("")) {in = new FastScanner(System.in); out = new PrintWriter(System.out); } else {try{in = new FastScanner(new FileInputStream((FILE + ".in"))); out = new PrintWriter(new FileOutputStream((FILE + ".out"))); }catch (FileNotFoundException e){ e.printStackTrace(); } }solve(); out.close(); } public static void main( String[] args){ new Main().run(); } class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner( InputStream is){ br = new BufferedReader(new InputStreamReader(is)); } public String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } }return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} } }
1	public class C{ Scanner in ; PrintWriter out ; String INPUT = ""; void solve(){ int n = ni();  char[] x = in.next().toCharArray();  int t = 0; for ( int i = 0;(i < n);i++) {if ( (x[i] == 'T')) {t++; } } int min = 9999; for ( int i = 0;(i < n);i++) { int y = 0; for ( int j = i;(j < (i + t));j++) {if ( (x[(j % n)] == 'T')) {y++; } }min = Math.min(min,(t - y)); }out.println(min); } void run()throws Exception { in = (INPUT.isEmpty()?new Scanner(System.in):new Scanner(INPUT)); out = new PrintWriter(System.out); solve(); out.flush(); } public static void main( String[] args)throws Exception { new C().run(); } int ni(){ return Integer.parseInt(in.next());} }
1	public class Round364_div2_C{ public static void main( String[] args)throws IOException { FastReader in = new FastReader(System.in);  PrintWriter out = new PrintWriter(System.out); solve(in,out); out.flush(); } public static void solve( FastReader in, PrintWriter out){ int n = in.readInt();  String s = in.readString();  int totalCnt = (int)s.chars().distinct().count();  Map<Character,Integer> curCnts = new HashMap<>();  int solution = s.length();  int i = 0; for ( int j = 0;(j < s.length());j++) { char sj = s.charAt(j); curCnts.put(sj,(curCnts.getOrDefault(sj,0) + 1)); while((curCnts.getOrDefault(s.charAt(i),0) > 1)){ char si = s.charAt(i);  int siCnt = curCnts.get(si); if ( (siCnt > 1)) {curCnts.put(si,(siCnt - 1)); } else {curCnts.remove(si); }i++; }if ( (curCnts.size() == totalCnt)) {solution = Math.min(solution,((j - i) + 1)); } }out.println(solution); } static class FastReader{ private final InputStream stream ; private int current ; private int size ; private byte[] buffer = new byte[(1024 * 8)]; public FastReader( InputStream stream){ this.stream = stream; current = 0; size = 0; } public int readInt(){ int sign = 1;  int abs = 0;  int c = readNonEmpty(); if ( (c == '-')) {sign = -1; c = readAny(); } do {if ( ((c < '0') || (c > '9'))) {throw (new IllegalStateException());} abs = ((10 * abs) + (c - '0')); c = readAny(); }while(!isEmpty(c));return (sign * abs);} public String readString(){ StringBuffer sb = new StringBuffer();  int c ; do {c = readAny(); }while(isEmpty(c));do {sb.append((char)c); c = readAny(); }while(!isEmpty(c));return sb.toString();} private int readAny(){ try{if ( (current >= size)) {current = 0; size = stream.read(buffer); if ( (size < 0)) {return -1;} } }catch (IOException e){ throw (new RuntimeException("Failed to readAny next byte",e));} return buffer[current++];} private int readNonEmpty(){ int result ; do {result = readAny(); }while(isEmpty(result));return result;} static private boolean isEmpty( int c){ return (((((c == ' ') || (c == '\t')) || (c == '\n')) || (c == '\r')) || (c == -1));} } }
5	public class AAA{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = in.nextInt(); int max = a[0];  int ind = 0; for ( int k = 1;(k < n);k++) {if ( (a[k] > max)) {max = a[k]; ind = k; } }if ( (max != 1)) {a[ind] = 1; Arrays.sort(a); for ( int i = 0;(i < (a.length - 1));i++) System.out.print((a[i] + " ")); System.out.println(a[(a.length - 1)]); } else {a[0] = 2; Arrays.sort(a); for ( int i = 0;(i < (a.length - 1));i++) System.out.print((a[i] + " ")); System.out.println(a[(a.length - 1)]); }} }
4	public class C2{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(new File("input.txt"));  PrintWriter pw = new PrintWriter(new File("output.txt"));  int n = sc.nextInt();  int m = sc.nextInt();  int k = sc.nextInt();  int[] x = new int[(k + 1)],y = new int[(k + 1)]; for ( int i = 1;(i <= k);i++) {y[i] = sc.nextInt(); x[i] = sc.nextInt(); } int max = -1,y0 = 0,x0 = 0; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) { int min = ((n + m) + 2); for ( int j2 = 1;(j2 <= k);j2++) {min = Math.min(min,(Math.abs((i - y[j2])) + Math.abs((j - x[j2])))); }if ( (min > max)) {max = min; y0 = i; x0 = j; } }}pw.println(((y0 + " ") + x0)); pw.close(); } }
1	public class Main{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt();  String line = in.next();  int h = 0; for ( int i = 0;(i < line.length());i++) {if ( (line.charAt(i) == 'H')) h++; }line = (line + line); int min = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int ans = 0; for ( int j = i;(j < (i + h));j++) {if ( (line.charAt(j) != 'H')) ans++; }if ( (min > ans)) min = ans; }out.print(min); in.close(); out.close(); } }
4	public class Main{ public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new FileReader("input.txt"));  String dimensions = br.readLine();  String extractDim = "";  int n = 0,m ; for ( int i = 0;(i < dimensions.length());i++) {if ( (dimensions.charAt(i) == ' ')) {n = Integer.parseInt(extractDim); extractDim = ""; continue;} extractDim += dimensions.charAt(i); }m = Integer.parseInt(extractDim); String burningTrees = br.readLine();  int k = Integer.parseInt(burningTrees);  Point[] coord = new Point[k];  String coordSet = br.readLine();  int spaceCount = 0;  String newCoord = "";  int s = 0; for ( int i = 0;(i < coordSet.length());i++) {if ( (coordSet.charAt(i) == ' ')) spaceCount++; if ( (spaceCount == 2)) { String extractCoord = "";  int x = 0,y ; for ( int j = 0;(j < newCoord.length());j++) {if ( (newCoord.charAt(j) == ' ')) {x = Integer.parseInt(extractCoord); extractCoord = ""; continue;} extractCoord += newCoord.charAt(j); }y = Integer.parseInt(extractCoord); coord[s] = new Point(x,y); s++; newCoord = ""; spaceCount = 0; continue;} newCoord += coordSet.charAt(i); } String extractCoord = "";  int x = 0,y ; for ( int j = 0;(j < newCoord.length());j++) {if ( (newCoord.charAt(j) == ' ')) {x = Integer.parseInt(extractCoord); extractCoord = ""; continue;} extractCoord += newCoord.charAt(j); }y = Integer.parseInt(extractCoord); coord[s] = new Point(x,y); s++; br.close(); int[][] forest = new int[(n + 2)][(m + 2)]; for ( int i = 0;(i < forest.length);i++) {for ( int j = 0;(j < forest[i].length);j++) {if ( ((((i == 0) || (i == (n + 1))) || (j == 0)) || (j == (m + 1)))) forest[i][j] = 0; else forest[i][j] = 1; }} Queue<Point> q = new LinkedList<>(); for ( int i = 0;(i < coord.length);i++) {forest[coord[i].x][coord[i].y] = 0; q.add(coord[i]); } Point tree = new Point(); while(!q.isEmpty()){ Point temp = q.remove(); forest[temp.x][temp.y] = 0; if ( q.isEmpty()) tree = new Point(temp.x,temp.y); for ( int i = -1;(i <= 1);i++) {for ( int j = -1;(j <= 1);j++) {if ( (((i != 0) && (j != 0)) || ((i == 0) && (j == 0)))) continue; if ( (forest[(temp.x + i)][(temp.y + j)] == 0)) continue; else {forest[(temp.x + i)][(temp.y + j)] = 0; q.add(new Point((temp.x + i),(temp.y + j))); }}}} BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt")); bw.write(((tree.x + " ") + tree.y)); bw.close(); } }
3	public class p3sol{ static char[] c ; static int[][] dp ; static int mod = ((int)1e9 + 7); public static void main( String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(br.readLine()); c = new char[n]; for ( int i = 0;(i < n);i++) c[i] = br.readLine().charAt(0); dp = new int[(n + 1)][(n + 1)]; dp[0][0] = 1; for ( int i = 0;(i < (n - 1));i++) {if ( (c[i] == 's')) { int prev = 0; for ( int j = i;(j >= 0);j--) {prev += dp[i][j]; prev %= mod; dp[(i + 1)][j] += prev; dp[(i + 1)][j] %= mod; }} else {for ( int j = 1;(j <= n);j++) {dp[(i + 1)][j] += dp[i][(j - 1)]; dp[(i + 1)][j] %= mod; }}} int ans = 0; for ( int i = 0;(i < n);i++) {ans += dp[(n - 1)][i]; ans %= mod; }System.out.println(ans); br.close(); } public static void print( int[][] a){ for ( int i = 0;(i < a.length);i++) {for ( int j = 0;(j < a[0].length);j++) System.out.print((a[i][j] + " ")); System.out.println(""); }} }
5	public class Solution{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt();  int[] a = new int[n];  boolean has_more_than_one = false; for ( int i = 0;(i < n);i++) {a[i] = in.nextInt(); if ( (a[i] > 1)) has_more_than_one = true; }Arrays.sort(a); if ( (n == 1)) {if ( (a[0] == 1)) out.print(2); else out.print(1); } else {out.print((1 + " ")); for ( int i = 1;(i < n);i++) {if ( (has_more_than_one || (i < (n - 1)))) out.print((a[(i - 1)] + " ")); else out.println(2); }}out.close(); } }
0	public class A{ static Scanner scan = new Scanner(System.in); static PrintStream out = System.out; static void go( int n){ if ( (n == 0)) {System.out.println(((((0 + " ") + 0) + " ") + 0)); return ;} int a = 0,b = 1;  int c = (a + b); while((n > c)){a = b; b = c; c = (a + b); }System.out.println(((((0 + " ") + a) + " ") + b)); } public static void main( String[] args){ int n = scan.nextInt(); go(n); } }
3	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{ static final int modular = (int)(1e9 + 7); public void solve( int testNum, InputReader in, PrintWriter out){ int n = in.nextInt();  int ans = 0;  String[] g = new String[n];  int[][] dp = new int[2][n]; for ( int i = 0;(i < n);i++) {g[i] = in.next(); }if ( (n == 1)) {out.println(1); return ;} dp[0][0] = 1; for ( int i = 1;(i < n);i++) {if ( g[(i - 1)].equals("f")) {dp[1][0] = 0; for ( int j = 1;(j < n);j++) {dp[1][j] = dp[0][(j - 1)]; }} else {dp[1][(n - 1)] = dp[0][(n - 1)]; for ( int j = (n - 2);(j >= 0);j--) {dp[1][j] = (dp[1][(j + 1)] + dp[0][j]); dp[1][j] = (dp[1][j] % modular); }}for ( int j = 0;(j < n);j++) {dp[0][j] = dp[1][j]; }if ( (i == (n - 1))) {for ( int j = 0;(j < n);j++) {ans = (ans + dp[1][j]); ans = (ans % modular); }} }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());} } }
5	public class a{ static long mod = 1000000007; static boolean[][] blacks ; public static void main( String[] args)throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(new PrintStream(System.out));  int n = input.nextInt(),t = input.nextInt();  int res = 2;  Cottage[] data = new Cottage[n];  int[] xs = new int[n],as = new int[n]; for ( int i = 0;(i < n);i++) {data[i] = new Cottage(input.nextInt(),input.nextInt()); }Arrays.sort(data); for ( int i = 0;(i < n);i++) {xs[i] = data[i].x; as[i] = data[i].a; }for ( int i = 0;(i < (n - 1));i++) {if ( ((2 * (xs[(i + 1)] - xs[i])) == (((2 * t) + as[i]) + as[(i + 1)]))) res++; else if ( ((2 * (xs[(i + 1)] - xs[i])) > (((2 * t) + as[i]) + as[(i + 1)]))) res += 2; }out.println(res); out.close(); } static class Cottage implements Comparable<Cottage>{ int x ,a ; public Cottage( int xx, int aa){ x = xx; a = aa; } } static long pow( long a, long p){ if ( (p == 0)) return 1; if ( ((p & 1) == 0)) { long sqrt = pow(a,(p / 2)); return ((sqrt * sqrt) % mod);} else return ((a * pow(a,(p - 1))) % mod);} }
0	public class CF125D2A{ public static void main( String[] args){ Scanner sc = new Scanner(System.in); System.out.println(("0 0 " + sc.nextInt())); } }
6	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  ScanReader in = new ScanReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  G1playlist solver = new G1playlist(); solver.solve(1,in,out); out.close(); } static class G1playlist{ int mod = 1000000007; public void solve( int testNumber, ScanReader in, PrintWriter out){ int n = in.scanInt();  int T = in.scanInt();  int[][] song = new int[n][2]; for ( int i = 0;(i < n);i++) {song[i][0] = in.scanInt(); song[i][1] = (in.scanInt() - 1); } int[][][] dp = new int[(T + 1)][(1 << n)][3]; for ( int i = 0;(i < n);i++) if ( (song[i][0] <= T)) {dp[song[i][0]][(1 << i)][song[i][1]] = 1; } for ( int t = 0;(t <= T);t++) {for ( int i = 0;(i < (1 << n));i++) {for ( int j = 0;(j < 3);j++) {if ( (dp[t][i][j] == 0)) continue; for ( int k = 0;(k < n);k++) {if ( (((((1 << k) & i) == 0) && ((t + song[k][0]) <= T)) && (song[k][1] != j))) dp[(t + song[k][0])][((1 << k) | i)][song[k][1]] = ((dp[(t + song[k][0])][((1 << k) | i)][song[k][1]] + dp[t][i][j]) % mod); }}}} long ans = 0; for ( int i = 0;(i < (1 << n));i++) {for ( int j = 0;(j < 3);j++) {ans = ((ans + dp[T][i][j]) % mod); }}out.println(ans); } } static class ScanReader{ private byte[] buf = new byte[(4 * 1024)]; private int index ; private BufferedInputStream in ; private int total ; public ScanReader( InputStream inputStream){ in = new BufferedInputStream(inputStream); } private int scan(){ if ( (index >= total)) {index = 0; try{total = in.read(buf); }catch (Exception e){ e.printStackTrace(); } if ( (total <= 0)) return -1; } return buf[index++];} public int scanInt(){ int integer = 0;  int n = scan(); while(isWhiteSpace(n))n = scan(); int neg = 1; if ( (n == '-')) {neg = -1; n = scan(); } while(!isWhiteSpace(n)){if ( ((n >= '0') && (n <= '9'))) {integer *= 10; integer += (n - '0'); n = scan(); } }return (neg * integer);} private boolean isWhiteSpace( int n){ if ( (((((n == ' ') || (n == '\n')) || (n == '\r')) || (n == '\t')) || (n == -1))) return true; else return false;} } }
2	public class B{ public static void main( String[] args){ doIt(); } static void doIt(){ Scanner sc = new Scanner(System.in);  PrintWriter pw = new PrintWriter(System.out);  long n = sc.nextLong();  long k = sc.nextLong();  long msum = ((((k - 1) * k) / 2) + 1);  long u = k;  long l = 0;  long m = ((u + l) / 2); while((l < u)){m = (((u + l) / 2) + ((u + l) % 2)); long sum = (((m - 1) * m) / 2); if ( (n <= (msum - sum))) l = m; else u = (m - 1); }m = (((u + l) / 2) + ((u + l) % 2)); if ( ((msum - (((m - 1) * m) / 2)) < n)) System.out.println(-1); else System.out.println((k - m)); } }
4	public class C_Round_35_Div2{ public static long MOD = 1000000007; static int[] X = {0,1,0,-1}; static int[] Y = {1,0,-1,0}; static int[][][] dp ; public static void main( String[] args)throws FileNotFoundException { PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")));  Scanner in = new Scanner();  int n = in.nextInt();  int m = in.nextInt();  int k = in.nextInt();  int[][] map = new int[n][m];  LinkedList<Point> q = new LinkedList();  int reX = -1;  int reY = -1; for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); reX = x; reY = y; map[x][y] = 1; q.add(new Point(x,y)); }while(!q.isEmpty()){ Point p = q.poll(); for ( int i = 0;(i < 4);i++) { int x = (p.x + X[i]);  int y = (p.y + Y[i]); if ( (((((x >= 0) && (y >= 0)) && (x < n)) && (y < m)) && (map[x][y] == 0))) {map[x][y] = (1 + map[p.x][p.y]); if ( (map[x][y] > map[reX][reY])) {reX = x; reY = y; } q.add(new Point(x,y)); } }}out.println((((reX + 1) + " ") + (reY + 1))); out.close(); } public static class Point implements Comparable<Point>{ int x ,y ; public Point( int start, int end){ this.x = start; this.y = end; } } public static long gcd( long a, long b){ if ( (b == 0)) {return a;} return gcd(b,(a % b));} public static long pow( long a, long b){ if ( (b == 0)) {return 1;} if ( (b == 1)) {return a;} long val = pow(a,(b / 2)); if ( ((b % 2) == 0)) {return ((val * val) % MOD);} else {return ((val * ((val * a) % MOD)) % MOD);}} static class Scanner{ BufferedReader br ; StringTokenizer st ; public Scanner()throws FileNotFoundException{ br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ throw (new RuntimeException());} }return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} } }
4	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);  ProblemCFireAgain solver = new ProblemCFireAgain(); solver.solve(1,in,out); out.close(); } static class ProblemCFireAgain{ static private final byte[] dx = {-1,0,0,1}; static private final byte[] dy = {0,-1,1,0}; static private int[][] lvl ; static private int max ; static private int n ; static private int m ; static private int k ; static private ProblemCFireAgain.Pair[] bgn ; static private ProblemCFireAgain.Pair res ; static private void bfs2d(){ Queue<ProblemCFireAgain.Pair> bfsq = new LinkedList<ProblemCFireAgain.Pair>(); for ( ProblemCFireAgain.Pair src :bgn) {lvl[src.a][src.b] = 0; bfsq.add(src); }while(!bfsq.isEmpty()){ ProblemCFireAgain.Pair op = bfsq.poll();  int plvl = lvl[op.a][op.b]; if ( (plvl > max)) {res = op; max = plvl; } for ( int i = 0;(i < 4);i++) { int newX = (op.a + dx[i]);  int newY = (op.b + dy[i]); if ( (((((newX > 0) && (newX <= n)) && (newY > 0)) && (newY <= m)) && (lvl[newX][newY] == -1))) {bfsq.add(new ProblemCFireAgain.Pair(newX,newY)); lvl[newX][newY] = (plvl + 1); } }}} public void solve( int testNumber, InputReader _in, PrintWriter _out){ try(InputReader in=new InputReader(new FileInputStream("input.txt"));PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")))){n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); bgn = new ProblemCFireAgain.Pair[k]; for ( int i = 0;(i < k);i++) {bgn[i] = new ProblemCFireAgain.Pair(in.nextInt(),in.nextInt()); }max = Integer.MIN_VALUE; lvl = new int[(n + 5)][(m + 5)]; for ( int i = 0;(i < (n + 4));i++) {Arrays.fill(lvl[i],-1); }bfs2d(); out.println(res); }catch (Exception e){ } } } static class InputReader implements AutoCloseable{ private BufferedReader reader ; private StringTokenizer tokenizer ; public InputReader( InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next(){ while(((tokenizer == null) || !tokenizer.hasMoreTokens())){try{ String str ; if ( ((str = reader.readLine()) != null)) tokenizer = new StringTokenizer(str); else return null; }catch (IOException e){ throw (new RuntimeException(e));} }return tokenizer.nextToken();} public int nextInt(){ return Integer.parseInt(next());} public void close()throws Exception { reader.close(); } } }
0	public class A199{ static int n[][] = new int[][]{{-1,0},{1,0},{0,-1},{0,1}}; public static void main( String[] args)throws IOException { new A199().solve(); } public void solve()throws IOException { Scanner scan = new Scanner(System.in);  int N = scan.nextInt(); System.out.println(("0 0 " + N)); } }
5	public class A{ public A()throws IOException{ String input = r.readLine();  int N = Integer.parseInt(input);  int[] A = new int[N]; input = r.readLine(); String[] S = input.split(" "); for ( int i = 0;(i < N);++i) A[i] = Integer.parseInt(S[i]); solve(N,A); } public void solve( int N, int[] A){ t = millis(); Arrays.sort(A); if ( (A[(N - 1)] > 1)) A[(N - 1)] = 1; else A[(N - 1)] = 2; Arrays.sort(A); System.out.print(A[0]); for ( int i = 1;(i < N);++i) System.out.print((" " + A[i])); System.out.println(); } static BufferedReader r ; static long t ; static void print2( Object o){ System.out.println(o); } static void print( Object o){ print2(o); System.exit(0); } static void run()throws IOException { r = new BufferedReader(new InputStreamReader(System.in)); new A(); } public static void main( String[] args)throws IOException { run(); } static long millis(){ return System.currentTimeMillis();} }
1	public class Main{ public static void main( String[] args){ try{ Parserdoubt pd = new Parserdoubt(System.in);  int t = pd.nextInt();  int inde = 0,indo = 0,o = 0,e = 0; for ( int i = 0;(i < t);i++) {if ( ((pd.nextInt() % 2) == 0)) {inde = i; e++; } else {o++; indo = i; }}if ( (o == 1)) {System.out.println((indo + 1)); } else {System.out.println((inde + 1)); } }catch (Exception e){ } } } class Parserdoubt{ private final int BUFFER_SIZE = (1 << 17); private DataInputStream din ; private byte[] buffer ; private int bufferPointer ,bytesRead ; public Parserdoubt( InputStream in){ din = new DataInputStream(in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt()throws Exception { int ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); c = read(); }while((c > ' '));if ( neg) return -ret; return ret;} private void fillBuffer()throws Exception { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } private byte read()throws Exception { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} }
2	public class B2{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  long n = in.nextLong();  long k = in.nextLong();  long upn = k;  long tmp = upn; if ( (n == 1)) {System.out.println(0); return ;} if ( (n <= k)) {System.out.println(1); return ;} if ( !bS(n,k,upn)) {System.out.println(-1); return ;} boolean flag = false; while(bS(n,k,upn)){tmp = upn; flag = true; upn = ((5 * upn) / 6); if ( (tmp == upn)) break; } long ans = tmp; if ( !flag) upn = 0; for ( int i = (int)tmp;(i >= upn);i--) {if ( bS(n,k,i)) {ans = i; } else break;}System.out.println(ans); } static boolean bS( long key, long k, long n){ long pipe = ((n * (((k - n) + k) + 1)) / 2); pipe = ((pipe - n) + 1); if ( (pipe >= key)) {return true;} else return false;} }
3	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")) c++; else {for ( int j = 1;(j <= c);j++) {a[j] = (int)(((a[j] % mod) + (a[(j - 1)] % mod)) % mod); }}}System.out.println(a[c]); sc.close(); } }
3	public class PythonIndentation{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int N = Integer.parseInt(in.readLine());  int[][] dp = new int[N][N]; dp[0][0] = 1; for ( int i = 1;(i < N);++i) { char lastCmd = in.readLine().charAt(0);  int[] sum = new int[N]; sum[(N - 1)] = dp[(i - 1)][(N - 1)]; for ( int j = (N - 2);(j >= 0);--j) sum[j] = ((sum[(j + 1)] + dp[(i - 1)][j]) % 1000000007); for ( int j = 0;(j < N);++j) {if ( ((lastCmd == 'f') && (j > 0))) dp[i][j] = dp[(i - 1)][(j - 1)]; else if ( (lastCmd == 's')) dp[i][j] = sum[j]; }} int ans = 0; for ( int i = 0;(i < N);++i) ans = ((ans + dp[(N - 1)][i]) % 1000000007); System.out.println(ans); } }
6	public class q5{ static NoD[] arr ; static int index ,count ,zc ; static ArrayList<NoD> pos ,neg ; static long[][][][] dp ; static long solve( int a, int b, int c, int d, long mod){ long[][][][] a2 = dp;  int p = -1; if ( (((a == 0) && (b == 0)) && (c == 0))) return 1; if ( (dp[a][b][c][d] != -1)) return dp[a][b][c][d]; long tr = 0; if ( ((a > 0) && (d != 1))) {tr = (+a * solve((a - 1),b,c,1,mod)); tr %= mod; } if ( ((b > 0) && (d != 2))) {tr += (b * solve(a,(b - 1),c,2,mod)); tr %= mod; } if ( ((c > 0) && (d != 3))) {tr += (c * solve(a,b,(c - 1),3,mod)); tr %= mod; } tr %= mod; return dp[a][b][c][d] = tr;} public static void main( String[] args)throws IOException { Reader.init(System.in); PrintWriter out = new PrintWriter(System.out);  int n = Reader.nextInt(),t = Reader.nextInt();  long mod = ((long)1e9 + 7),fact[] = new long[16]; dp = new long[16][16][16][4]; for ( int i = 0;(i < 16);i++) {for ( int j = 0;(j < 16);j++) {for ( int k = 0;(k < 16);k++) Arrays.fill(dp[i][j][k],-1); }}fact[0] = 1; for ( int i = 1;(i <= 15);i++) {fact[i] = (i * fact[(i - 1)]); fact[i] %= mod; } NoD[] arr = new NoD[n]; for ( int i = 0;(i < n);i++) { int a = Reader.nextInt(),b = Reader.nextInt(); arr[i] = new NoD(a,b); } long ans = 0; for ( int i = 0;(i < (1 << n));i++) { int time = 0;  int prev = -1;  int t1 = 0,t2 = 0,t3 = 0;  long[] c = {i};  BitSet b = BitSet.valueOf(c); for ( int j = 0;(j < n);j++) {if ( b.get(j)) {time += arr[j].val; prev = arr[j].index; if ( (arr[j].index == 1)) t1++; else if ( (arr[j].index == 2)) t2++; else t3++; } }if ( (time == t)) { long v = 1;  long v2 = 1; v *= solve(t1,t2,t3,0,mod); v %= mod; ans += v; ans %= mod; } }out.println(ans); out.flush(); } } class NoD{ int val ,index ; NoD( int v, int i){ val = v; index = i; } }
1	public class Main3{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  int N = sc.nextInt();  String S = sc.next();  HashSet<Character> unique = new HashSet<>(); for ( char c :S.toCharArray()) {unique.add(c); } int number = unique.size();  Hashtable<Character,Integer> indexes = new Hashtable<>();  TreeSet<Integer> tree = new TreeSet<>();  int min = (N + 1);  int total = 0; for ( int i = 0;(i < N);i++) { char c = S.charAt(i); if ( !indexes.containsKey(c)) {total++; indexes.put(c,i); tree.add(i); } else { int old = indexes.get(c); indexes.put(c,i); tree.remove(old); tree.add(i); }if ( (total == number)) { int dist = ((tree.last() - tree.first()) + 1); min = Math.min(dist,min); } }System.out.println(min); } }
3	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();  long MOD = 1000000007;  long[] current = new long[(n + 3)]; current[0] = 1; for ( int i = 0;(i < (n - 1));i++) { String s = in.next(); if ( s.equals("f")) {for ( int j = (i + 1);(j > 0);j--) {current[j] = current[(j - 1)]; current[j] %= MOD; }current[0] = 0; } else {for ( int j = (i + 1);(j >= 0);j--) {current[j] = (current[(j + 1)] + current[j]); current[j] %= MOD; }}} long result = 0; for ( int i = 0;(i <= n);i++) {result += current[i]; result %= MOD; }out.println(result); } } static class InputReader{ static private BufferedReader in ; static private StringTokenizer tok ; public InputReader( InputStream in){ this.in = new BufferedReader(new InputStreamReader(in)); } public int nextInt(){ return Integer.parseInt(next());} public String next(){ try{while(((tok == null) || !tok.hasMoreTokens())){tok = new StringTokenizer(in.readLine()); } }catch (IOException ex){ System.err.println(("An IOException was caught :" + ex.getMessage())); } return tok.nextToken();} } }
4	public class c{ static boolean used[][] ; static int n ; static int m ; static int a[][] ; public static void main( String[] args)throws Exception { Scanner in = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt")); n = in.nextInt(); m = in.nextInt(); int k = in.nextInt();  int x[] = new int[k];  int y[] = new int[k]; for ( int i = 0;(i < k);i++) {x[i] = in.nextInt(); y[i] = in.nextInt(); } int max = 0;  int xx = 1;  int yy = 1; for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= m);j++) { int count = Integer.MAX_VALUE; for ( int l = 0;(l < k);l++) count = Math.min((Math.abs((i - x[l])) + Math.abs((j - y[l]))),count); if ( (max < count)) {max = count; xx = i; yy = j; } }out.println(((xx + " ") + yy)); out.close(); } }
6	public class Main{ public static void main( String[] args){ new Thread(null,new Runnable(){},"1",(1 << 26)).start(); } void solve(){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  ScanReader in = new ScanReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  FElongatedMatrix solver = new FElongatedMatrix(); solver.solve(1,in,out); out.close(); } static class FElongatedMatrix{ int[][] G ; int[][] G1 ; public int findIt( int[] map, int n, int start){ int[][] mask = new int[(1 << n)][n]; for ( int i = 0;(i < n);i++) mask[(1 << i)][i] = G[start][map[i]]; for ( int i = 1;(i < (1 << n));i++) {for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < n);k++) {if ( (((k != j) && ((i & (1 << k)) == 0)) && ((i & (1 << j)) != 0))) {mask[(i | (1 << k))][k] = Math.max(mask[(i | (1 << k))][k],Math.min(mask[i][j],G[map[j]][map[k]])); } }}} int ans = 0; for ( int i = 0;(i < n);i++) ans = Math.max(ans,Math.min(mask[((1 << n) - 1)][i],G1[start][map[i]])); return ans;} public void solve( int testNumber, ScanReader in, PrintWriter out){ int n = in.scanInt();  int m = in.scanInt(); G = new int[n][n]; G1 = new int[n][n]; int[][] ar = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {ar[i][j] = in.scanInt(); }}if ( (n == 1)) { int ans = Integer.MAX_VALUE; for ( int i = 0;(i < (m - 1));i++) ans = Math.min(ans,Math.abs((ar[0][i] - ar[0][(i + 1)]))); out.println(ans); return ;} for ( int i = 0;(i < n);i++) {for ( int j = (i + 1);(j < n);j++) { int min = Integer.MAX_VALUE; for ( int k = 0;(k < m);k++) min = Math.min(min,Math.abs((ar[i][k] - ar[j][k]))); G[i][j] = G[j][i] = min; }}for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( (i == j)) continue; int min = Integer.MAX_VALUE; for ( int k = 1;(k < m);k++) min = Math.min(min,Math.abs((ar[i][k] - ar[j][(k - 1)]))); G1[i][j] = min; }} int[] map ;  int ans = 0; for ( int i = 0;(i < n);i++) {map = new int[(n - 1)]; int tl = 0; for ( int temp = 0;(temp < n);temp++) {if ( (temp == i)) continue; map[tl++] = temp; }ans = Math.max(ans,findIt(map,(n - 1),i)); }out.println(ans); } } static class ScanReader{ private byte[] buf = new byte[(4 * 1024)]; private int index ; private BufferedInputStream in ; private int total ; public ScanReader( InputStream inputStream){ in = new BufferedInputStream(inputStream); } private int scan(){ if ( (index >= total)) {index = 0; try{total = in.read(buf); }catch (Exception e){ e.printStackTrace(); } if ( (total <= 0)) return -1; } return buf[index++];} public int scanInt(){ int integer = 0;  int n = scan(); while(isWhiteSpace(n))n = scan(); int neg = 1; if ( (n == '-')) {neg = -1; n = scan(); } while(!isWhiteSpace(n)){if ( ((n >= '0') && (n <= '9'))) {integer *= 10; integer += (n - '0'); n = scan(); } }return (neg * integer);} private boolean isWhiteSpace( int n){ if ( (((((n == ' ') || (n == '\n')) || (n == '\r')) || (n == '\t')) || (n == -1))) return true; else return false;} } }
3	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{ String[] str ; long mod = ((long)1e9 + 7); long[][] dp ; public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.nextInt(); str = new String[n]; dp = new long[(n + 2)][(n + 2)]; for ( int i = 0;(i < dp.length);i++) {Arrays.fill(dp[i],-1); }for ( int i = 0;(i < n);i++) {str[i] = in.readString(); }if ( (str[0].charAt(0) == 'f')) {out.print(solve(1,1)); } else {out.print(solve(1,0)); }} long solve( int n, int horiz){ if ( (horiz < 0)) return 0; if ( (n >= (str.length - 1))) {return 1;} if ( (dp[n][horiz] != -1)) {return dp[n][horiz];} if ( (str[n].charAt(0) == 'f')) {return dp[n][horiz] = solve((n + 1),(horiz + 1));} else { long ans1 = solve(n,(horiz - 1)); ans1 += solve((n + 1),horiz); ans1 = (ans1 % mod); return dp[n][horiz] = ans1;}} } static class InputReader{ private final InputStream stream ; private final byte[] buf = new byte[8192]; private int curChar ; private int snumChars ; public InputReader( InputStream st){ this.stream = st; } public int read(){ if ( (snumChars == -1)) throw (new InputMismatchException()); if ( (curChar >= snumChars)) {curChar = 0; try{snumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (snumChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c)){c = read(); } StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } }
4	public class Main{ public static void main( String[] args)throws IOException { Scanner in = new Scanner(new FileInputStream("input.txt"));  File file = new File("output.txt");  FileOutputStream fos = new FileOutputStream(file); if ( !file.exists()) {file.createNewFile(); } int N = in.nextInt();  int M = in.nextInt();  int K = in.nextInt();  int[][] fireTime = new int[N][M]; for ( int i = 0;(i < K);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); fireTime[x][y] = -1; for ( int j = 1;(j <= (x + y));j++) {for ( int p = 0;(p <= j);p++) {if ( (((((x - j) + p) >= 0) && ((y - p) >= 0)) && ((fireTime[((x - j) + p)][(y - p)] == 0) || (fireTime[((x - j) + p)][(y - p)] > j)))) {fireTime[((x - j) + p)][(y - p)] = j; } }}for ( int j = 1;(j <= (((x + M) - 1) - y));j++) {for ( int p = 0;(p <= j);p++) {if ( (((((x - j) + p) >= 0) && ((y + p) < M)) && ((fireTime[((x - j) + p)][(y + p)] == 0) || (fireTime[((x - j) + p)][(y + p)] > j)))) {fireTime[((x - j) + p)][(y + p)] = j; } }}for ( int j = 1;(j <= (((N - 1) - x) + y));j++) {for ( int p = 0;(p < j);p++) {if ( (((((x + j) - p) < N) && ((y - p) >= 0)) && ((fireTime[((x + j) - p)][(y - p)] == 0) || (fireTime[((x + j) - p)][(y - p)] > j)))) {fireTime[((x + j) - p)][(y - p)] = j; } }}for ( int j = 1;(j <= (((((N - 1) - x) + M) - 1) - y));j++) {for ( int p = 0;(p <= j);p++) {if ( (((((x + j) - p) < N) && ((y + p) < M)) && ((fireTime[((x + j) - p)][(y + p)] == 0) || (fireTime[((x + j) - p)][(y + p)] > j)))) {fireTime[((x + j) - p)][(y + p)] = j; } }}} int max = -1;  int tx = 1;  int ty = 1; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < M);j++) {if ( (fireTime[i][j] > max)) {max = fireTime[i][j]; tx = (i + 1); ty = (j + 1); } }} String output = ((tx + " ") + ty);  byte[] bA = output.getBytes(); fos.write(bA); fos.flush(); } }
3	public class C{ static long mod = 1000000007; static int n ; static long w[][] ; static void MainMethod()throws Exception { n = reader.nextInt(); w = new long[(n + 2)][(n + 2)]; for ( int i = 0;(i <= (n + 1));i++) Arrays.fill(w[i],0); w[1][0] = 1; String prev ,next ; prev = reader.next(); long s[] = new long[(n + 2)]; for ( int i = 2;(i <= n);i++) {next = reader.next(); if ( prev.equals("f")) for ( int lv = 0;(lv <= n);lv++) w[i][(lv + 1)] = w[(i - 1)][lv]; else for ( int lv = n;(lv >= 0);lv--) {w[i][lv] = ((w[(i - 1)][lv] + w[i][(lv + 1)]) % mod); }prev = next; } long res = 0; for ( int i = 0;(i <= n);i++) res = ((res + w[n][i]) % mod); printer.print(res); } public static void main( String[] args)throws Exception { MainMethod(); printer.close(); } static PrintWriter printer = new PrintWriter(new OutputStreamWriter(System.out)); }
1	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++) {naturalNumbers[i] = sc.nextInt(); }System.out.println(iq.diffInEvenness(n,naturalNumbers)); } public int diffInEvenness( int n, int[] naturalNumbers){ int even ,odd ,lastEvenIndex ,lastOddIndex ; even = odd = lastEvenIndex = lastOddIndex = 0; for ( int i = 0;(i < naturalNumbers.length);i++) {if ( ((naturalNumbers[i] % 2) == 0)) {even++; lastEvenIndex = (i + 1); } else {odd++; lastOddIndex = (i + 1); }}return ((even > odd)?lastOddIndex:lastEvenIndex);} }
3	public class ProblemC{ static long MOD = 1_000_000_007; public static void main( String[] args){ Scanner input = new Scanner(System.in);  int n = input.nextInt();  boolean[] isFor = new boolean[n]; for ( int a = 0;(a < n);a++) {isFor[a] = (input.next().charAt(0) == 'f'); } long[][] array = new long[(n + 1)][(n + 1)]; array[0][0] = 1; boolean isPreviousFor = false; for ( int idx = 0;(idx < n);idx++) { long heightCache = 0; for ( int height = (n - 1);(height >= 0);height--) {if ( isPreviousFor) {array[(idx + 1)][(height + 1)] += array[idx][height]; array[(idx + 1)][(height + 1)] %= MOD; } else {heightCache += array[idx][height]; heightCache %= MOD; array[(idx + 1)][height] += heightCache; array[(idx + 1)][height] %= MOD; }}isPreviousFor = isFor[idx]; } long sum = 0; for ( int height = 0;(height <= n);height++) {sum += array[n][height]; }System.out.println((sum % MOD)); } }
0	public class HexadecimalTheorem{ public static void main( String[] args){ Scanner read = new Scanner(System.in);  int num = read.nextInt();  int zero ,one ,two ,three ; zero = 0; one = 1; two = 1; three = 2; if ( (num == 0)) System.out.println("0 0 0"); else if ( (num == 1)) System.out.println("0 0 1"); else {while((num != three)){zero = one; one = two; two = three; three = (three + one); }System.out.println(((((zero + " ") + one) + " ") + one)); }} }
3	public class C{ static int[][] memo ; static int n ; static char[] c ; static int mod = ((int)1e9 + 7); static int dp( int ind, int loops){ if ( (ind == n)) return ((loops == 0)?1:0); if ( (memo[ind][loops] != -1)) return memo[ind][loops]; long ans = 0; if ( (c[ind] == 's')) {ans = ((ans + dp((ind + 1),loops)) % mod); if ( (loops > 0)) ans = ((ans + dp(ind,(loops - 1))) % mod); } else {ans = ((ans + dp((ind + 1),(loops + 1))) % mod); }return memo[ind][loops] = (int)ans;} public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out); n = sc.nextInt(); memo = new int[(n + 1)][(n + 1)]; for ( int[] i :memo) Arrays.fill(i,-1); c = new char[n]; for ( int i = 0;(i < c.length);i++) {c[i] = sc.next().charAt(0); }out.println(dp(0,0)); out.flush(); out.close(); } static class Scanner{ BufferedReader bf ; StringTokenizer st ; public Scanner( InputStream i){ bf = new BufferedReader(new InputStreamReader(i)); } public String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(bf.readLine()); return st.nextToken();} public int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(next());} } }
1	public class Task25a{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int a1 = 0,a2 = 0;  int n1 = 0,n2 = 0; for ( int i = 1;(i <= n);i++) { int c = sc.nextInt(); if ( ((c % 2) == 1)) {a1 = i; n1++; } else {a2 = i; n2++; }}if ( (n1 == 1)) {System.out.println(a1); } else {System.out.println(a2); }} }
5	public class Main{ public static void main( String[] args){ new Main().solve(); } void solve(){ Scanner cin = new Scanner(System.in); while(cin.hasNextInt()){ int n = cin.nextInt();  int arr[] = new int[n]; for ( int i = 0;(i < n);++i) {arr[i] = cin.nextInt(); }Arrays.sort(arr); int ret[] = new int[n]; ret[0] = 1; for ( int i = 0;(i < (n - 1));++i) {ret[(i + 1)] = arr[i]; }if ( (arr[(n - 1)] == 1)) {ret[(n - 1)] = 2; } String glue = ""; for ( int i = 0;(i < n);++i) {System.out.print((glue + ret[i])); glue = " "; }System.out.println(); }} }
6	public class EMatrix{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  TaskE solver = new TaskE(); solver.solve(1,in,out); out.flush(); out.close(); } static class TaskE{ final int max = (int)1E9; int n ,m ; int a[][] ; int gm[] ; boolean visit[][] ; int dp[][] ; boolean check( int d){ if ( (n == 1)) {for ( int i = 0;(i < (m - 1));i++) {if ( (Math.abs((a[0][i] - a[0][(i + 1)])) < d)) return false; }return true;} int nm[] = new int[n],pm[] = new int[n]; for ( int i = 0;(i < n);i++) { boolean r ; for ( int j = 0;(j < n);j++) {if ( (j == i)) continue; r = true; for ( int k = 0;(k < m);k++) {if ( (Math.abs((a[i][k] - a[j][k])) < d)) {r = false; break;} }if ( r) {nm[i] |= (1 << j); } r = true; for ( int k = 0;(k < (m - 1));k++) {if ( (Math.abs((a[i][(k + 1)] - a[j][k])) < d)) {r = false; break;} }if ( r) {pm[i] |= (1 << j); } }}for ( int i = 0;(i < n);i++) {gm = new int[n]; gm[i] = nm[i]; for ( int j = 0;(j < n);j++) {if ( (j == i)) continue; if ( ((nm[j] & (1 << i)) != 0)) {gm[j] = (nm[j] ^ (1 << i)); } else {gm[j] = nm[j]; }}for ( int j = 0;(j < n);j++) {if ( (j == i)) continue; if ( (((pm[i] >> j) % 2) == 1)) {gm[j] |= (1 << i); } }visit = new boolean[n][(1 << n)]; dp = new int[n][(1 << n)]; if ( (dfs(i,i,(1 << i)) == n)) {return true;} }return false;} int dfs( int u, int r, int mask){ if ( ((u == r) && (mask == ((1 << n) - 1)))) return 0; if ( visit[u][mask]) return dp[u][mask]; visit[u][mask] = true; int val = 0; for ( int i = 0;(i < n);i++) {if ( ((((gm[u] >> i) % 2) == 1) && (((i == r) && (mask == ((1 << n) - 1))) || (((mask >> i) % 2) != 1)))) {val = Math.max(val,(1 + dfs(i,r,(mask | (1 << i))))); } }return dp[u][mask] = val;} public void solve( int testNumber, InputReader in, PrintWriter out){ n = in.nextInt(); m = in.nextInt(); a = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {a[i][j] = in.nextInt(); }} int l = 0,r = max,ans = 0; while((l <= r)){ int m = ((l + r) >> 1); if ( check(m)) {ans = m; l = (m + 1); } else {r = (m - 1); }}out.println(ans); } } static class InputReader{ BufferedReader br ; StringTokenizer st ; public InputReader( InputStream stream){ br = new BufferedReader(new InputStreamReader(stream)); st = null; } String next(){ while(((st == null) || !st.hasMoreTokens())){ String s = null; try{s = br.readLine(); }catch (IOException e){ e.printStackTrace(); } if ( (s == null)) return null; st = new StringTokenizer(s); }return st.nextToken();} boolean hasMoreTokens(){ while(((st == null) || !st.hasMoreTokens())){ String s = null; try{s = br.readLine(); }catch (IOException e){ e.printStackTrace(); } if ( (s == null)) return false; st = new StringTokenizer(s); }return true;} public int nextInt(){ return Integer.parseInt(next());} } }
4	public class ViewAngle{ static private int V ,level[][] ,count = -1,lev_dfs[] ,degree = 0,no_vert_conn_comp = 0; static private Stack<Integer> st = new Stack(); static private LinkedList<Integer> adj[] ; static private boolean[][] Visite ; static private boolean[] Visited ; static private TreeSet<Integer> ts = new TreeSet(); static private Queue<Pair> queue = new LinkedList<Pair>(); ViewAngle( int V){ V++; this.V = V; adj = new LinkedList[V]; Visite = new boolean[100][100]; Visited = new boolean[V]; lev_dfs = new int[V]; for ( int i = 0;(i < V);i++) adj[i] = new LinkedList<Integer>(); } static File inFile ,outFile ; static FileWriter fWriter ; static PrintWriter pWriter ; public static void main( String[] args)throws IOException { inFile = new File("input.txt"); outFile = new File("output.txt"); fWriter = new FileWriter(outFile); pWriter = new PrintWriter(fWriter); Scanner sc = new Scanner(inFile);  int n = sc.nextInt();  int m = sc.nextInt();  char c[][] = new char[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {c[i][j] = '.'; }}setup(n,m); int k = sc.nextInt(); for ( int i = 0;(i < k);i++) { int x = sc.nextInt();  int y = sc.nextInt(); queue.add(new Pair((x - 1),(y - 1))); c[(x - 1)][(y - 1)] = 'X'; level[(x - 1)][(y - 1)] = -1; Visite[(x - 1)][(y - 1)] = true; }BFS(c,n,m); pWriter.close(); sc.close(); } public void get( int from, int to){ int h = (lev_dfs[from] - lev_dfs[to]); if ( (h <= 0)) {System.out.println(-1); } else {System.out.println((h - 1)); }} public static void setup( int n, int m){ level = new int[n][m]; Visite = new boolean[n][m]; } static private boolean check( int x, int y, char[][] c){ if ( ((((x >= 0) && (y >= 0)) && ((x < c.length) && (y < c[0].length))) && (c[x][y] == '.'))) {return true;} return false;} public static int BFS( char[][] c, int n, int m){ int count = 0; while(!queue.isEmpty()){ Pair temp = queue.poll();  int x = temp.w;  int y = temp.h; Visite[x][y] = true; if ( (check((x + 1),y,c) && !Visite[(x + 1)][y])) {level[(x + 1)][y] = (level[x][y] + 1); queue.add(new Pair((x + 1),y)); Visite[(x + 1)][y] = true; } if ( (check((x - 1),y,c) && !Visite[(x - 1)][y])) {level[(x - 1)][y] = (level[x][y] + 1); queue.add(new Pair((x - 1),y)); Visite[(x - 1)][y] = true; } if ( (check(x,(y + 1),c) && !Visite[x][(y + 1)])) {level[x][(y + 1)] = (level[x][y] + 1); queue.add(new Pair(x,(y + 1))); Visite[x][(y + 1)] = true; } if ( (check(x,(y - 1),c) && !Visite[x][(y - 1)])) {level[x][(y - 1)] = (level[x][y] + 1); queue.add(new Pair(x,(y - 1))); Visite[x][(y - 1)] = true; } } int prev_lev = -1,x = -1,y = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (level[i][j] >= prev_lev)) {prev_lev = level[i][j]; x = i; y = j; } }}pWriter.println((((x + 1) + " ") + (y + 1))); return V;} private long dfsUtil( int startVertex, boolean[] Visited){ int c = 1;  long cout = 0; degree = 0; Visited[startVertex] = true; st.push(startVertex); while(!st.isEmpty()){ int top = st.pop();  Iterator<Integer> i = adj[top].listIterator(); degree += adj[top].size(); while(i.hasNext()){ int n = i.next(); if ( !Visited[n]) {Visited[n] = true; st.push(n); lev_dfs[n] = top; } }}for ( int i = 1;(i < V);i++) {if ( (lev_dfs[i] != 0)) {System.out.print((lev_dfs[i] + " ")); } }return cout;} } class Pair implements Comparable<Pair>{ int w ; int h ; Pair( int w, int h){ this.w = w; this.h = h; } }
1	public class C{ public static void main( String[] args){ Kattio sc = new Kattio(System.in);  int n = sc.getInt();  String s = sc.getWord();  int[] found = new int[('z' + 1)];  int amount = 0; for ( int i = 0;(i < s.length());i++) { char c = s.charAt(i); if ( (found[c] == 0)) amount++; found[c]++; } int contains[] = new int[('z' + 1)];  int min = n;  int start = 0;  int end = 0;  int in = 0; while(true){if ( (in < amount)) {if ( (end == n)) break; char c = s.charAt(end); if ( (contains[c] == 0)) in++; contains[c]++; end++; } else {if ( (min > (end - start))) min = (end - start);  char c = s.charAt(start); if ( (contains[c] == 1)) in--; contains[c]--; start++; }}System.out.println(min); } } class Kattio extends PrintWriter{ public Kattio( InputStream i){ super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Kattio( InputStream i, OutputStream o){ super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens(){ return (peekToken() != null);} public int getInt(){ return Integer.parseInt(nextToken());} public String getWord(){ return nextToken();} private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; private String peekToken(){ if ( (token == null)) try{while(((st == null) || !st.hasMoreTokens())){line = r.readLine(); if ( (line == null)) return null; st = new StringTokenizer(line); }token = st.nextToken(); }catch (IOException e){ } return token;} private String nextToken(){ String ans = peekToken(); token = null; return ans;} }
1	public class Main{ public static void main( String[] args)throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } static private void solve()throws Exception { int n = nextInt();  int co = 0,ce = 0;  int[] v = new int[n]; for ( int i = 0;(i < n);i++) {v[i] = nextInt(); }for ( int i = 0;(i < n);i++) {if ( ((v[i] % 2) == 0)) {co++; } else {ce++; }}if ( (co == 1)) {for ( int i = 0;(i < n);i++) {if ( ((v[i] % 2) == 0)) {out.println((i + 1)); return ;} }} else {for ( int i = 0;(i < n);i++) {if ( ((v[i] % 2) != 0)) {out.println((i + 1)); return ;} }}} static private BufferedReader in ; static private PrintWriter out ; static private StringTokenizer st ; static String nextString()throws IOException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(in.readLine()); }return st.nextToken();} static int nextInt()throws IOException { return Integer.parseInt(nextString());} }
4	public class Solution implements Runnable{ BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); private void init()throws FileNotFoundException { String file = "123"; if ( !file.equals("")) {in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } else {in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); }} public static void main( String[] args){ new Thread(new Solution()).start(); } private String readString(){ while(!tok.hasMoreTokens()){try{tok = new StringTokenizer(in.readLine()); }catch (IOException e){ e.printStackTrace(); } }return tok.nextToken();} private int readInt(){ return Integer.parseInt(readString());} int[] counts = new int[1000]; private void solve(){ int n = (readInt() + 2);  int m = (readInt() + 2);  boolean[][] graph = new boolean[n][m]; for ( int i = 0;(i < n);i++) {graph[i][(m - 1)] = true; graph[i][0] = true; }for ( int i = 0;(i < m);i++) {graph[(n - 1)][i] = true; graph[0][i] = true; } int k = readInt();  int inFire = 0;  Queue<Point> q = new ArrayDeque<>(); for ( int i = 0;(i < k);i++) { int x = readInt();  int y = readInt();  Point p = new Point(x,y); graph[x][y] = true; q.add(p); }while(!q.isEmpty()){ Point current = q.poll(); inFire++; if ( !graph[(current.x + 1)][current.y]) {graph[(current.x + 1)][current.y] = true; q.add(new Point((current.x + 1),current.y)); } if ( !graph[(current.x - 1)][current.y]) {graph[(current.x - 1)][current.y] = true; q.add(new Point((current.x - 1),current.y)); } if ( !graph[current.x][(current.y + 1)]) {graph[current.x][(current.y + 1)] = true; q.add(new Point(current.x,(current.y + 1))); } if ( !graph[current.x][(current.y - 1)]) {graph[current.x][(current.y - 1)] = true; q.add(new Point(current.x,(current.y - 1))); } if ( q.isEmpty()) {out.print(((current.x + " ") + current.y)); return ;} }} class Point{ int x ,y ; public Point( int x, int y){ this.x = x; this.y = y; } } }
2	public class P287B{ Scanner sc = new Scanner(System.in); long n ,k ; void run(){ n = sc.nextLong(); k = sc.nextLong(); solve(); } void solve(){ long left = -1,right = (k + 1); for ( ;((right - left) > 1);) { long m = ((left + right) / 2);  long ub = ((((k * (k + 1)) / 2) - (((k - m) * ((k - m) + 1)) / 2)) - (m - 1)); if ( (ub >= n)) {right = m; } else {left = m; }}println(("" + ((right > k)?-1:right))); } void println( String s){ System.out.println(s); } public static void main( String[] args){ Locale.setDefault(Locale.US); new P287B().run(); } }
1	public class C43{ static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(System.out); static int nextInt()throws IOException { in.nextToken(); return Integer.valueOf(in.sval);} static String nextString()throws IOException { in.nextToken(); return in.sval;} {in.ordinaryChars('0','9'); in.wordChars('0','9'); in.ordinaryChars('.','.'); in.wordChars('.','.'); in.ordinaryChars('-','-'); in.wordChars('-','-'); }public static void main( String[] args)throws IOException { int n = nextInt();  char[] s = nextString().toCharArray();  int h = 0; for ( int i = 0;(i < n);i++) if ( (s[i] == 'H')) h++;  int ans = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int p = i,t = 0; for ( int j = 0;(j < h);j++,p = ((p + 1) % n)) if ( (s[p] == 'T')) t++; ans = Math.min(ans,t); }out.println(ans); out.flush(); } }
6	public class Main{ static private boolean check( int n, int m, int k){ for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {for ( int l = 0;(l < (1 << n));l++) {dp[i][j][l] = -1; }}}for ( int i = 0;(i < n);i++) {if ( dfs(i,i,n,m,k,0)) {return true;} }return false;} static private boolean dfs( int first, int current, int n, int m, int k, int bitmap){ bitmap |= (1 << current); if ( (bitmap == ((1 << n) - 1))) {if ( (n == 1)) {if ( (m > 1)) {if ( (rowMinDist[current] >= k)) {return true;} else {return false;}} else {return true;}} else {if ( (m > 1)) {if ( (minDistBetweenHeadAndTail[first][current] >= k)) {return true;} else {return false;}} else {return true;}}} else {if ( (dp[first][current][bitmap] >= 0)) {if ( (dp[first][current][bitmap] > 0)) {return true;} else {return false;}} short ans = 0; for ( int i = 0;(i < n);i++) {if ( (((bitmap & (1 << i)) == 0) && (minDistBetweenRow[current][i] >= k))) {if ( dfs(first,i,n,m,k,bitmap)) {ans = 1; break;} } }dp[first][current][bitmap] = ans; if ( (ans > 0)) {return true;} else {return false;}}} static private short[][][] dp = new short[20][20][(1 << 17)]; static private int[][] input = new int[20][10010]; static private int[][] minDistBetweenRow = new int[20][20]; static private int[][] minDistBetweenHeadAndTail = new int[20][20]; static private int[] rowMinDist = new int[20]; public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int i ,j ,k ,n ,m ; n = scan.nextInt(); m = scan.nextInt(); for ( i = 0;(i < n);i++) {for ( j = 0;(j < m);j++) {input[i][j] = scan.nextInt(); }}for ( i = 0;(i < n);i++) {for ( j = (i + 1);(j < n);j++) { int minDist = -1; for ( k = 0;(k < m);k++) { int dist = Math.abs((input[i][k] - input[j][k])); if ( ((dist < minDist) || (minDist < 0))) {minDist = dist; } }minDistBetweenRow[i][j] = minDistBetweenRow[j][i] = minDist; }}for ( i = 0;(i < n);i++) {for ( j = 0;(j < n);j++) {if ( (i != j)) { int minDist = -1; for ( k = 0;(k < (m - 1));k++) { int dist = Math.abs((input[j][k] - input[i][(k + 1)])); if ( ((dist < minDist) || (minDist < 0))) {minDist = dist; } }minDistBetweenHeadAndTail[i][j] = minDist; } }}for ( i = 0;(i < n);i++) { int minDist = -1; for ( j = 0;(j < (m - 1));j++) { int dist = Math.abs((input[i][j] - input[i][(j + 1)])); if ( ((dist < minDist) || (minDist < 0))) {minDist = dist; } }rowMinDist[i] = minDist; } int low = 0,high = 1000000010; while((low < high)){ int mid = ((low + high) / 2); if ( check(n,m,mid)) {low = (mid + 1); } else {high = mid; }}System.out.println((high - 1)); } }
5	public class ProblemA{ public static void main( String[] args)throws IOException { BufferedReader s = new BufferedReader(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(System.out);  String[] line = s.readLine().split(" ");  int n = Integer.valueOf(line[0]);  int ht = Integer.valueOf(line[1]);  int[][] house = new int[n][2];  Set<Integer> candidates = new HashSet<Integer>(); for ( int i = 0;(i < n);i++) { String[] data = s.readLine().split(" "); house[i][0] = (Integer.valueOf(data[0]) * 2); house[i][1] = Integer.valueOf(data[1]); candidates.add(((house[i][0] - house[i][1]) - ht)); candidates.add(((house[i][0] + house[i][1]) + ht)); } int ans = 0; for ( int p :candidates) { int f = (p - ht);  int t = (p + ht);  boolean isok = true; for ( int i = 0;(i < n);i++) {if ( ((house[i][0] + house[i][1]) <= f)) {} else if ( ((house[i][0] - house[i][1]) >= t)) {} else {isok = false; break;}}if ( isok) {ans++; } }out.println(ans); out.flush(); } }
1	public class Main{ static private boolean _READ_FROM_FILE = (System.getProperty("ONLINE_JUDGE") == null); static private Scanner in ; static private void core(){ int n = in.nextInt();  ArrayList<Character> all = new ArrayList<Character>(); for ( char ch :in.next().toCharArray()) {all.add(ch); } int res = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int now = calc(all); res = Math.min(res,now); all.add(all.get(0)); all.remove(0); }System.out.println(res); } static private int calc( ArrayList<Character> all){ int nh = 0; for ( char ch :all) {if ( (ch == 'H')) ++nh; } int r1 = 0; for ( int i = 0;(i < nh);i++) {if ( (all.get(i) != 'H')) ++r1; } int nt = (all.size() - nh);  int r2 = 0; for ( int i = 0;(i < nt);i++) {if ( (all.get(i) != 'T')) ++r2; }return Math.min(r1,r2);} public static void main( String[] args)throws FileNotFoundException { if ( _READ_FROM_FILE) System.setIn(new FileInputStream("in.in")); in = new Scanner(System.in); core(); } }
1	public class Main{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt(); if ( ((n >= 3) && (n <= 100))) { int num[] = new int[n]; for ( int i = 0;(i < n);i++) {num[i] = in.nextInt(); } int even = 0,odd = 0,ceven = 0,codd = 0; for ( int i = 0;(i < n);i++) {if ( ((num[i] % 2) == 0)) {even++; ceven = (i + 1); } else {odd++; codd = (i + 1); }}if ( (odd == 1)) {System.out.println(("" + codd)); } else {System.out.println(("" + ceven)); }} } }
5	public class CodeForce{ private void solve()throws IOException { final int N = nextInt();  int[] A = new int[N]; for ( int i = 0;(i < N);i++) A[i] = nextInt(); Arrays.sort(A); if ( (A[(N - 1)] == 1)) A[(N - 1)] = 2; else A[(N - 1)] = 1; Arrays.sort(A); for ( int i = 0;(i < N);i++) System.out.print((A[i] + " ")); } public static void main( String[] args){ new CodeForce().run(); } BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter writer ; public void run(){ try{reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(new FileOutputStream(new File("output.txt"))); solve(); reader.close(); writer.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} }
5	public class Beta97B{ static Scanner in ; static StreamTokenizer st ; static int n ; static int[] a ; static int max = 1; public static void main( String[] args)throws IOException { st = new StreamTokenizer(new InputStreamReader(System.in)); n = nextInt(); a = new int[n]; int ind = 0; for ( int i = 0;(i < n);++i) {a[i] = nextInt(); if ( (a[i] > max)) {max = a[i]; ind = i; } }if ( (max == 1)) {a[0] = 2; } else {a[ind] = 1; }Arrays.sort(a); for ( int i = 0;(i < n);++i) System.out.print((a[i] + " ")); } static private int nextInt()throws IOException { st.nextToken(); return (int)st.nval;} }
0	public class C{ static StringBuilder st = new StringBuilder(); public static void main( String[] args)throws Exception { Scanner sc = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  Point[] square = new Point[4];  Point[] rotSquare = new Point[4]; for ( int i = 0;(i < 4);i++) square[i] = new Point(sc.nextInt(),sc.nextInt()); for ( int i = 0;(i < 4);i++) rotSquare[i] = new Point(sc.nextInt(),sc.nextInt()); boolean can = false; for ( int x = -100;(x <= 100);x++) for ( int y = -100;(y <= 100);y++) can |= (inside(new Point(x,y),square) & inside(new Point(x,y),rotSquare)); out.println((can?"YES":"NO")); out.flush(); out.close(); } static int crossProduct( Point a, Point b){ int ans = ((a.x * b.y) - (a.y * b.x)); if ( (ans < 0)) return -1; if ( (ans == 0)) return 0; return 1;} static boolean inside( Point a, Point[] points){ boolean allPos = true;  boolean allNeg = true; for ( int i = 0;(i < 4);i++) { Point v1 = new Point((points[i].x - a.x),(points[i].y - a.y));  Point v2 = new Point((points[((i + 1) % 4)].x - a.x),(points[((i + 1) % 4)].y - a.y)); allPos &= (crossProduct(v1,v2) >= 0); allNeg &= (crossProduct(v1,v2) <= 0); }return (allPos | allNeg);} static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner( InputStream in){ br = new BufferedReader(new InputStreamReader(System.in)); } String next()throws Exception { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(next());} } }
4	@SuppressWarnings("unused") public class Fire35C{ InputStream is ; PrintWriter out ; String INPUT = ""; int mod = (int)(Math.pow(10,9) + 7); int v = 0; int max = 0; StringBuilder st = new StringBuilder(); File outFile = new File("output.txt"); void solve()throws IOException { int n = ni();  int m = ni();  boolean visited[][] = new boolean[n][m];  boolean inq[][] = new boolean[n][m];  Queue<Integer> x = new LinkedList<>();  Queue<Integer> y = new LinkedList<>();  Queue<Integer> lev = new LinkedList<>();  int a = -1,b = -1,max = 0;  int k = ni(); while((k-- > 0)){ int u = (ni() - 1);  int v = (ni() - 1); x.add(u); y.add(v); lev.add(1); inq[u][v] = true; }while((x.size() != 0)){ int u = x.poll();  int v = y.poll();  int l = lev.poll(); if ( (max < l)) {a = u; b = v; max = l; } visited[u][v] = true; if ( ((((u - 1) >= 0) && !visited[(u - 1)][v]) && !inq[(u - 1)][v])) {x.add((u - 1)); y.add(v); lev.add((l + 1)); inq[(u - 1)][v] = true; } if ( ((((u + 1) < n) && !visited[(u + 1)][v]) && !inq[(u + 1)][v])) {x.add((u + 1)); y.add(v); lev.add((l + 1)); inq[(u + 1)][v] = true; } if ( ((((v - 1) >= 0) && !visited[u][(v - 1)]) && !inq[u][(v - 1)])) {x.add(u); y.add((v - 1)); lev.add((l + 1)); inq[u][(v - 1)] = true; } if ( ((((v + 1) < m) && !visited[u][(v + 1)]) && !inq[u][(v + 1)])) {x.add(u); y.add((v + 1)); lev.add((l + 1)); inq[u][(v + 1)] = true; } }a++; b++; out.println(((a + " ") + b)); out.close(); } void run()throws Exception { is = (INPUT.isEmpty()?new FileInputStream(new File("input.txt")):new ByteArrayInputStream(INPUT.getBytes())); out = new PrintWriter(new BufferedWriter(new FileWriter(outFile))); long s = System.currentTimeMillis(); solve(); out.flush(); if ( !INPUT.isEmpty()) tr(((System.currentTimeMillis() - s) + "ms")); } public static void main( String[] args)throws Exception { new Fire35C().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0,ptrbuf = 0; 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++];} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while((isSpaceChar(b) && (b != ' '))){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private int ni(){ 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(); }} static long __gcd( long a, long b){ if ( (b == 0)) {return a;} else {return __gcd(b,(a % b));}} static long power( long x, long y, long p){ long res = 1; x = (x % p); while((y > 0)){if ( ((y % 2) == 1)) res = ((res * x) % p); y = (y >> 1); x = ((x * x) % p); }return res;} static long modInverse( long a, int m){ if ( (__gcd(a,m) != 1)) {return -1;} else {return power(a,(m - 2),m);}} static private void tr( Object... o){ System.out.println(Arrays.deepToString(o)); } }
3	public class Main{ public static void main( String[] args){ File file = new File("in.txt");  File fileOut = new File("out.txt");  InputStream inputStream = null;  OutputStream outputStream = null; inputStream = System.in; outputStream = System.out; InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  Task solver = new Task(); solver.solve(1,in,out); out.close(); } } class Task{ private final int mod = 1000000007; public void solve( int testNumber, InputReader in, PrintWriter out){ Integer n = in.nextInt();  List<Character> comm = new ArrayList<>(n); for ( int i = 0;(i < n);i++) {comm.add(in.next().charAt(0)); } long[][] dp = new long[n][n]; dp[0][0] = 1; for ( int i = 1;(i < n);i++) { Character lastComm = comm.get((i - 1)); if ( lastComm.equals('f')) {dp[i][0] = 0; for ( int j = 1;(j < n);j++) {dp[i][j] = dp[(i - 1)][(j - 1)]; }} else { Long suffixSum = dp[(i - 1)][(n - 1)]; for ( int j = (n - 1);(j >= 0);j--) {dp[i][j] = suffixSum; if ( (j > 0)) {suffixSum += (dp[(i - 1)][(j - 1)] % mod); } }}} Long finalSum = 0L; for ( int i = 0;(i < n);i++) {finalSum += (dp[(n - 1)][i] % mod); }out.println((finalSum % mod)); } } 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());} }
4	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){ this.r = r; this.c = c; this.last = last; } } static ArrayList<Pos> pos = new ArrayList<>(); static boolean[][] used ; static int[] rows = {-1,1,0,0}; static int[] cols = {0,0,-1,1}; int LAST = 0; int lastRow = 1; int lastCol = 1; public static void main( String[] args)throws IOException { Fire_Again fire_again = new Fire_Again();  BufferedReader bufferedReader = new BufferedReader(new FileReader("input.txt"));  String[] nm = bufferedReader.readLine().split(" "); N = (Integer.parseInt(nm[0]) + 1); M = (Integer.parseInt(nm[1]) + 1); K = Integer.parseInt(bufferedReader.readLine()); used = new boolean[N][M]; String[] rc = bufferedReader.readLine().split(" "); for ( int k = 0;(k < rc.length);k += 2) { int r = Integer.parseInt(rc[k]);  int c = Integer.parseInt(rc[(k + 1)]); pos.add(new Pos(r,c,0)); }fire_again.bfs(); PrintStream ps = new PrintStream("output.txt"); ps.printf("%d %d\n",fire_again.lastRow,fire_again.lastCol); ps.flush(); ps.close(); } Queue<Pos> queue = new LinkedList<>(); private void bfs(){ queue.addAll(pos); for ( Pos p :pos) {used[p.r][p.c] = true; }while(!queue.isEmpty()){ Pos p = queue.poll(); if ( (p.last > LAST)) {LAST = p.last; lastRow = p.r; lastCol = p.c; } for ( int i = 0;(i < rows.length);i++) { int currR = p.r;  int currC = p.c; if ( ((((((currR + rows[i]) >= 1) && ((currR + rows[i]) < N)) && ((currC + cols[i]) >= 1)) && ((currC + cols[i]) < M)) && !used[(currR + rows[i])][(currC + cols[i])])) {queue.add(new Pos((currR + rows[i]),(currC + cols[i]),(p.last + 1))); used[(currR + rows[i])][(currC + cols[i])] = true; } }}} }
6	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);  G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion(); solver.solve(1,in,out); out.close(); } static class G1PlaylistForPolycarpEasyVersion{ static final int mod = ((int)1e9 + 7); public void solve( int testNumber, inputClass sc, PrintWriter out){ int n = sc.nextInt();  int t = sc.nextInt();  G1PlaylistForPolycarpEasyVersion.Song[] songs = new G1PlaylistForPolycarpEasyVersion.Song[n]; for ( int i = 0;(i < n);i++) {songs[i] = new G1PlaylistForPolycarpEasyVersion.Song(sc.nextInt(),sc.nextInt()); } long ans = 0; for ( int mask = 1;(mask < (1 << n));mask++) { int nb = 0;  int tot = 0;  int type1 = 0;  int type2 = 0;  int type3 = 0; for ( int j = 0;(j < n);j++) {if ( (((1 << j) & mask) > 0)) {nb++; tot += songs[j].l; if ( (songs[j].type == 1)) {type1++; } else if ( (songs[j].type == 2)) {type2++; } else {type3++; }} }if ( (tot == t)) { long[][][][][] dp = new long[(nb + 1)][3][(type1 + 1)][(type2 + 1)][(type3 + 1)];  boolean[][][][][] go = new boolean[(nb + 1)][3][(type1 + 1)][(type2 + 1)][(type3 + 1)]; if ( (type1 > 0)) {go[1][0][(type1 - 1)][type2][type3] = true; dp[1][0][(type1 - 1)][type2][type3] = type1; } if ( (type2 > 0)) {go[1][1][type1][(type2 - 1)][type3] = true; dp[1][1][type1][(type2 - 1)][type3] = type2; } if ( (type3 > 0)) {go[1][2][type1][type2][(type3 - 1)] = true; dp[1][2][type1][type2][(type3 - 1)] = type3; } for ( int i = 0;(i < nb);i++) {for ( int m = 0;(m < 3);m++) {for ( int j = 0;(j <= type1);j++) {for ( int k = 0;(k <= type2);k++) {for ( int l = 0;(l <= type3);l++) {if ( go[i][m][j][k][l]) {if ( (m == 0)) {if ( (k > 0)) {dp[(i + 1)][1][j][(k - 1)][l] += (dp[i][m][j][k][l] * k); dp[(i + 1)][1][j][(k - 1)][l] %= mod; go[(i + 1)][1][j][(k - 1)][l] = true; } if ( (l > 0)) {dp[(i + 1)][2][j][k][(l - 1)] += (dp[i][m][j][k][l] * l); dp[(i + 1)][2][j][k][(l - 1)] %= mod; go[(i + 1)][2][j][k][(l - 1)] = true; } } else if ( (m == 1)) {if ( (j > 0)) {dp[(i + 1)][0][(j - 1)][k][l] += (dp[i][m][j][k][l] * j); dp[(i + 1)][0][(j - 1)][k][l] %= mod; go[(i + 1)][0][(j - 1)][k][l] = true; } if ( (l > 0)) {dp[(i + 1)][2][j][k][(l - 1)] += (dp[i][m][j][k][l] * l); dp[(i + 1)][2][j][k][(l - 1)] %= mod; go[(i + 1)][2][j][k][(l - 1)] = true; } } else {if ( (j > 0)) {dp[(i + 1)][0][(j - 1)][k][l] += (dp[i][m][j][k][l] * j); dp[(i + 1)][0][(j - 1)][k][l] %= mod; go[(i + 1)][0][(j - 1)][k][l] = true; } if ( (k > 0)) {dp[(i + 1)][1][j][(k - 1)][l] += (dp[i][m][j][k][l] * k); dp[(i + 1)][1][j][(k - 1)][l] %= mod; go[(i + 1)][1][j][(k - 1)][l] = true; } }} }}}}} long toadd = 0; for ( int i = 0;(i < 3);i++) {toadd += dp[nb][i][0][0][0]; }ans += toadd; ans %= ((int)1e9 + 7); } }out.println(ans); } } 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());} } }
2	public class MrBenderAndSquare{ static long n ,x ,y ,c ; public static void main( String[] args)throws IOException { Kattio io = new Kattio(System.in); n = io.getLong(); x = io.getLong(); y = io.getLong(); c = io.getLong(); long lo = 0;  long hi = c; while((lo < hi)){ long mid = (lo + ((hi - lo) / 2)); if ( (f(mid) >= c)) {hi = mid; } else {lo = (mid + 1); }}io.println(lo); io.close(); } static long f( long t){ long res = 0;  long left = Math.max(0,(t - (x - 1))); res -= (left * left); long right = Math.max(0,(t - (n - x))); res -= (right * right); long up = Math.max(0,(t - (y - 1))); res -= (up * up); long down = Math.max(0,(t - (n - y))); res -= (down * down); res += (1 + ((2 * t) * (t + 1))); long upLeft = Math.max(0,((t - (x + y)) + 1));  long upRight = Math.max(0,((t - (((n - x) + 1) + y)) + 1));  long downLeft = Math.max(0,((t - (((x + n) - y) + 1)) + 1));  long downRight = Math.max(0,((t - (((((n - x) + 1) + n) - y) + 1)) + 1)); res += ((upLeft * (upLeft + 1)) / 2); res += ((upRight * (upRight + 1)) / 2); res += ((downLeft * (downLeft + 1)) / 2); res += ((downRight * (downRight + 1)) / 2); return res;} static class Kattio extends PrintWriter{ public Kattio( InputStream i){ super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Kattio( InputStream i, OutputStream o){ super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens(){ return (peekToken() != null);} public long getLong(){ return Long.parseLong(nextToken());} private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; private String peekToken(){ if ( (token == null)) try{while(((st == null) || !st.hasMoreTokens())){line = r.readLine(); if ( (line == null)) return null; st = new StringTokenizer(line); }token = st.nextToken(); }catch (IOException e){ } return token;} private String nextToken(){ String ans = peekToken(); token = null; return ans;} } }
2	public class B{ public static void main( String[] args){ Scanner input = new Scanner(System.in);  long n = input.nextLong();  long k = input.nextLong(); System.out.println(solve(n,k)); input.close(); } public static long solve( long n, long k){ long dis = (n - k); if ( (n == 1)) return 0; if ( (((((k - 2) * ((k - 2) + 1)) / 2) + 1) <= dis)) return -1; if ( (k >= n)) return 1; long ans = 2;  long now = (((((k - 2) * ((k - 2) + 1)) / 2) + 1) + k);  long dist = Math.abs((now - n));  long delta = (1 + (8 * dist));  double ret = ((1 + Math.sqrt(delta)) / 2); now = (((((k - 2) * ((k - 2) + 1)) / 2) + 1) + k); dist = Math.abs((now - k)); delta = (1 + (8 * dist)); double nret = ((1 + Math.sqrt(delta)) / 2);  double back = (nret - ret); ans = (long)back; return (ans + 2);} }
5	public class A{ public static void main( String[] args)throws IOException { new A().solveProblem(); out.close(); } static Scanner in = new Scanner(new InputStreamReader(System.in)); static PrintStream out = new PrintStream(new BufferedOutputStream(System.out)); public void solveProblem(){ int n = in.nextInt();  E[] get = new E[n]; for ( int i = 0;(i < n);i++) {get[i] = new E(i,in.nextInt()); }sort(get); if ( (get[(n - 1)].g == 1)) {get[(n - 1)].g = 2; } else {get[(n - 1)].g = 1; }sort(get); for ( int i = 0;(i < (n - 1));i++) out.print((get[i].g + " ")); out.println(get[(n - 1)].g); } class E implements Comparable<E>{ int g ; int index ; public E( int index, int g){ this.g = g; this.index = index; } } }
3	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{ static private final int MOD = ((int)1e9 + 7); static private final int N = 5000; public void solve( int testNumber, Scanner in, PrintWriter out){ int n = in.nextInt();  int[] dp = new int[N]; Arrays.fill(dp,0); dp[0] = 1; String pre = null,ch ; for ( int i = 0;(i < n);++i) {ch = in.next(); if ( (i > 0)) {if ( pre.equals("s")) { int j = (N - 1); while((dp[j] == 0)){--j; } long sum = 0; for ( ;(j >= 0);--j) {sum += dp[j]; sum %= MOD; dp[j] = (int)sum; }} else {for ( int k = (N - 1);(k > 0);--k) {dp[k] = dp[(k - 1)]; }dp[0] = 0; }} pre = ch; } long sum = 0; for ( int i = 0;(i < N);++i) {sum += dp[i]; sum %= MOD; }out.println(sum); } } }
5	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskD solver = new TaskD(); solver.solve(1,in,out); out.close(); } static class TaskD{ public void solve( int testNumber, InputReader in, OutputWriter out){ try{ int n = in.readInt();  int[] x = new int[n],w = new int[n]; in.readIntArrays(x,w); int[] begin = new int[n],end = new int[n]; Arrays.setAll(begin,(i)->(x[i] - w[i])); Arrays.setAll(end,(i)->(x[i] + w[i])); int m = ArrayUtils.compress(begin,end).length;  int[] dp = new int[(m + 1)],order = ArrayUtils.order(end);  int idx = 0; for ( int i = 0;(i < m);i++) {if ( (i > 0)) {dp[i] = dp[(i - 1)]; } while(((idx < n) && (end[order[idx]] == i))){dp[i] = Math.max(dp[i],(dp[begin[order[idx]]] + 1)); idx++; }} int res = dp[(m - 1)]; out.printLine(res); }catch (Exception e){ e.printStackTrace(); } } } static interface IntList extends IntReversableCollection{ public abstract int get( int index); public abstract void set( int index, int value); public abstract void addAt( int index, int value); public abstract void removeAt( int index); public default void swap( int first, int second){ if ( (first == second)) {return ;} int temp = get(first); set(first,get(second)); set(second,temp); } public default IntIterator intIterator(){ return new IntIterator(){private int at ; private boolean removed ; public int value(){ if ( removed) {throw (new IllegalStateException());} return get(at);} public boolean advance(){ at++; removed = false; return isValid();} public boolean isValid(){ return (!removed && (at < size()));} };} public default void add( int value){ addAt(size(),value); } public default IntList sort( IntComparator comparator){ Sorter.sort(this,comparator); return this;} default IntList unique(){ int last = Integer.MIN_VALUE;  IntList result = new IntArrayList();  int size = size(); for ( int i = 0;(i < size);i++) { int current = get(i); if ( (current != last)) {result.add(current); last = current; } }return result;} public default IntList subList(final int from,final int to){ return new IntList(){private final int shift ; private final int size ; {if ( (((from < 0) || (from > to)) || (to > this.size()))) {throw (new IndexOutOfBoundsException(((((("from = " + from) + ", to = ") + to) + ", size = ") + size())));} shift = from; size = (to - from); }public int size(){ return size;} public int get( int at){ if ( ((at < 0) || (at >= size))) {throw (new IndexOutOfBoundsException(((("at = " + at) + ", size = ") + size())));} return this.get((at + shift));} public void addAt( int index, int value){ throw (new UnsupportedOperationException());} public void removeAt( int index){ throw (new UnsupportedOperationException());} public void set( int at, int value){ if ( ((at < 0) || (at >= size))) {throw (new IndexOutOfBoundsException(((("at = " + at) + ", size = ") + size())));} this.set((at + shift),value); } };} } static interface IntComparator{ IntComparator DEFAULT = Integer::compare; int compare( int first, int second); } static interface IntReversableCollection extends IntCollection{ } static class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void close(){ writer.close(); } public void printLine( int i){ writer.println(i); } } static interface IntStream extends Iterable<Integer>,Comparable<IntStream>{ IntIterator intIterator(); } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public void readIntArrays( int[]... arrays){ for ( int i = 0;(i < arrays[0].length);i++) {for ( int j = 0;(j < arrays.length);j++) {arrays[j][i] = readInt(); }}} public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ boolean isSpaceChar( int ch); } } static interface IntCollection extends IntStream{ public int size(); public default void add( int value){ throw (new UnsupportedOperationException());} public default int[] toArray(){ int size = size();  int[] array = new int[size];  int i = 0; for ( IntIterator it = intIterator();it.isValid();it.advance()) {array[i++] = it.value(); }return array;} public default IntCollection addAll( IntStream values){ for ( IntIterator it = values.intIterator();it.isValid();it.advance()) {add(it.value()); }return this;} } static class IntArray extends IntAbstractStream implements IntList{ private int[] data ; public IntArray( int[] arr){ data = arr; } public int size(){ return data.length;} public int get( int at){ return data[at];} public void addAt( int index, int value){ throw (new UnsupportedOperationException());} public void removeAt( int index){ throw (new UnsupportedOperationException());} public void set( int index, int value){ data[index] = value; } } static interface IntIterator{ public int value()throws NoSuchElementException ; public boolean advance(); public boolean isValid(); } static class IntArrayList extends IntAbstractStream implements IntList{ private int size ; private int[] data ; public IntArrayList(){ this(3); } public IntArrayList( int capacity){ data = new int[capacity]; } public IntArrayList( IntCollection c){ this(c.size()); addAll(c); } public IntArrayList( IntStream c){ this(); if ( (c instanceof IntCollection)) {ensureCapacity((IntCollection)c); } addAll(c); } public IntArrayList( IntArrayList c){ size = c.size(); data = c.data.clone(); } public IntArrayList( int[] arr){ size = arr.length; data = arr.clone(); } public int size(){ return size;} public int get( int at){ if ( (at >= size)) {throw (new IndexOutOfBoundsException(((("at = " + at) + ", size = ") + size)));} return data[at];} private void ensureCapacity( int capacity){ if ( (data.length >= capacity)) {return ;} capacity = Math.max((2 * data.length),capacity); data = Arrays.copyOf(data,capacity); } public void addAt( int index, int value){ ensureCapacity((size + 1)); if ( ((index > size) || (index < 0))) {throw (new IndexOutOfBoundsException(((("at = " + index) + ", size = ") + size)));} if ( (index != size)) {System.arraycopy(data,index,data,(index + 1),(size - index)); } data[index] = value; size++; } public void removeAt( int index){ if ( ((index >= size) || (index < 0))) {throw (new IndexOutOfBoundsException(((("at = " + index) + ", size = ") + size)));} if ( (index != (size - 1))) {System.arraycopy(data,(index + 1),data,index,((size - index) - 1)); } size--; } public void set( int index, int value){ if ( (index >= size)) {throw (new IndexOutOfBoundsException(((("at = " + index) + ", size = ") + size)));} data[index] = value; } public int[] toArray(){ return Arrays.copyOf(data,size);} } }
1	public class C{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  char[] s = new char[n];  String line = in.next();  int ct = 0,ht = 0; for ( int i = 0;(i < n);i++) if ( (line.charAt(i) == 'T')) ct++; else ht++; int cnt = 1000000000;  int[] c = new int[2];  char[] cc = new char[2]; if ( (ct < ht)) {c[0] = ct; c[1] = ht; cc[0] = 'T'; cc[1] = 'H'; } else {c[0] = ht; c[1] = ct; cc[0] = 'H'; cc[1] = 'T'; }for ( int i = 0;(i < n);i++) { int ptr = i; for ( int j = 0;(j < c[0]);j++) {s[ptr] = cc[0]; ptr = ((ptr + 1) % n); }for ( int j = 0;(j < c[1]);j++) {s[ptr] = cc[1]; ptr = ((ptr + 1) % n); } int ch = 0; for ( int j = 0;(j < n);j++) if ( ((s[j] != line.charAt(j)) && (s[j] == cc[0]))) ch++; cnt = Math.min(cnt,ch); }System.out.print(cnt); } }
1	public class Main{ public static void main( String[] args)throws NumberFormatException,IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(in.readLine());  String in1 = in.readLine();  String store = "";  HashSet<Character> contain = new HashSet<Character>(); for ( int i = 0;(i < n);i++) {if ( !contain.contains(in1.charAt(i))) {store += in1.charAt(i); contain.add(in1.charAt(i)); } } int[] index = new int[store.length()]; for ( int i = 0;(i < store.length());i++) {index[i] = -1; } HashSet<Integer> index2 = new HashSet<Integer>();  ArrayList<Integer> index3 = new ArrayList<Integer>();  int min = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int index4 = store.indexOf(in1.charAt(i)); if ( (index[index4] == -1)) {index[index4] = i; index2.add(i); index3.add(i); } else {index2.remove(index[index4]); index2.add(i); index3.add(i); index[index4] = i; }if ( (index2.size() == index.length)) {while(!index2.contains(index3.get(0))){index3.remove(0); }min = Math.min(min,((i - index3.get(0)) + 1)); } }System.out.println(min); } }
6	public class G1{ static int n ,T ,duration[] ,type[] ; static long dp[][][] ,mod = ((long)1e9 + 7); public static void main( String[] args)throws Exception { new Thread(null,new Runnable(){},"Main",(1 << 28)).start(); } public static void solveIt()throws Exception { Scanner in = new Scanner(System.in);  PrintWriter pw = new PrintWriter(System.out); n = in.nextInt(); T = in.nextInt(); dp = new long[3][(T + 1)][(1 << n)]; duration = new int[n]; type = new int[n]; for ( int i = 0;(i < n);i++) {duration[i] = in.nextInt(); type[i] = (in.nextInt() - 1); }for ( long[][] a :dp) for ( long[] b :a) Arrays.fill(b,-1); pw.println(solve(0,T,0)); pw.close(); } static long solve( int lastType, int rem, int mask){ if ( (rem == 0)) return 1; if ( (rem < 0)) return 0; if ( (dp[lastType][rem][mask] != -1)) return dp[lastType][rem][mask]; long res = 0; for ( int i = 0;(i < n);i++) {if ( ((!check(mask,i) && ((lastType != type[i]) || (mask == 0))) && ((rem - duration[i]) >= 0))) {res += solve(type[i],(rem - duration[i]),set(mask,i)); if ( (res >= mod)) res -= mod; } }return dp[lastType][rem][mask] = res;} static boolean check( int N, int pos){ return ((N & (1 << pos)) != 0);} static int set( int N, int pos){ return N = (N | (1 << pos));} }
5	public class CottageVillage{ class cl{ int x = 0; int a = 0; cl( int x, int a){ this.x = x; this.a = a; } } class cmp implements Comparator<cl>{ } public CottageVillage(){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int k = sc.nextInt();  cl[] w = new cl[n]; for ( int i = 0;(i < n);i++) w[i] = new cl(sc.nextInt(),sc.nextInt()); Arrays.sort(w,new cmp()); int cnt = 2,diff = 0; for ( int i = 1;(i < n);i++) {diff = (Math.abs(((((2 * w[i].x) - (2 * w[(i - 1)].x)) - w[i].a) - w[(i - 1)].a)) - (2 * k)); if ( (diff > 0)) cnt += 2; else if ( (diff == 0)) cnt++; }System.out.println(cnt); } public static void main( String... args){ new CottageVillage(); } }
4	public class Solution implements Runnable{ public static void main( String... strings)throws InterruptedException { new Thread(new Solution()).start(); } BufferedReader in ; PrintWriter out ; StringTokenizer st ; String next()throws Exception { if ( ((st == null) || !st.hasMoreElements())) st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(next());} int n ,m ,k ,xor = 0; boolean[][] used ; HashSet<Long>[] set ; void solve()throws Exception { n = nextInt(); m = nextInt(); k = nextInt(); used = new boolean[n][m]; set = new HashSet[2]; for ( int i = 0;(i < 2);set[i++] = new HashSet<Long>()) ;for ( int i = 0;(i < k);i++) { int x = (nextInt() - 1),y = (nextInt() - 1); used[x][y] = true; set[0].add(((10000L * x) + y)); }for ( ;;xor ^= 1) {set[(xor ^ 1)].clear(); int ansx = -1,ansy = -1; for ( long i :set[xor]) { int x = (int)(i / 10000),y = (int)(i % 10000); if ( (ansx < 0)) {ansx = (x + 1); ansy = (y + 1); } add((x + 1),y); add((x - 1),y); add(x,(y + 1)); add(x,(y - 1)); }if ( (set[(xor ^ 1)].size() == 0)) {out.println(((ansx + " ") + ansy)); break;} }} public void add( int x, int y){ if ( (((((x >= 0) && (y >= 0)) && (x < n)) && (y < m)) && !used[x][y])) return ; set[(xor ^ 1)].add(((10000L * x) + y)); used[x][y] = true; } }
3	public class PythonIndentation{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  boolean[] lst = new boolean[n]; for ( int i = 0;(i < n);i++) {lst[i] = (in.next()?false:true); }System.out.println(dp(lst)); } static int dp( boolean[] lst){ int[][] dp = new int[2][lst.length]; dp[0][0] = 1; for ( int i = 1;(i < lst.length);i++) {for ( int j = 0;(j < lst.length);j++) {if ( lst[(i - 1)]) {if ( (j == 0)) dp[(i % 2)][j] = 0; else dp[(i % 2)][j] = dp[((i - 1) % 2)][(j - 1)]; } else {if ( (j == 0)) { int temp = 0; for ( int k = 0;(k < lst.length);k++) temp = ((temp + dp[((i - 1) % 2)][k]) % 1000000007); dp[(i % 2)][j] = temp; } else dp[(i % 2)][j] = ((dp[(i % 2)][(j - 1)] - dp[((i - 1) % 2)][(j - 1)]) % 1000000007); }}} int ans = 0; for ( int i = 0;(i < lst.length);i++) {ans = ((ans + dp[((lst.length - 1) % 2)][i]) % 1000000007); }if ( (ans < 0)) ans = (ans + 1000000007); return ans;} }
6	public class ElongatedMatrix{ public static void main( String[] args){ InputStream input ;  OutputStream output ; try{input = new FileInputStream("input.txt"); output = new FileOutputStream("output.txt"); }catch (FileNotFoundException e){ input = System.in; output = System.out; } Kattio io = new Kattio(input,output); new Solve(io).main(); io.close(); if ( (input instanceof FileInputStream)) try{input.close(); }catch (IOException e){ } if ( (output instanceof FileOutputStream)) try{output.close(); }catch (IOException e){ } } } class Solve{ static final int oo = (int)1e9; Kattio io ; int n ,m ; int[][] a ; int[][][] dp ; int[][] diff ; int[][] slant ; Solve( Kattio io){ this.io = io; } int getbit( int x, int n){ n--; return ((x >> n) & 1);} int setbit( int x, int n){ n--; return (x | (1 << n));} int caldp( int currentRow, int firstRow, int mask){ if ( (dp[currentRow][firstRow][mask] != -1)) return dp[currentRow][firstRow][mask]; dp[currentRow][firstRow][mask] = 0; if ( (mask == ((1 << n) - 1))) dp[currentRow][firstRow][mask] = slant[currentRow][firstRow]; else {for ( int i = 1;(i <= n);i++) if ( (getbit(mask,i) == 0)) {dp[currentRow][firstRow][mask] = Math.max(Math.min(caldp(i,firstRow,setbit(mask,i)),diff[currentRow][i]),dp[currentRow][firstRow][mask]); } }return dp[currentRow][firstRow][mask];} void main(){ n = io.getInt(); m = io.getInt(); a = new int[(n + 1)][(m + 1)]; dp = new int[(n + 1)][(n + 1)][(1 << n)]; for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= m);j++) a[i][j] = io.getInt(); diff = new int[(n + 1)][(n + 1)]; for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= n);j++) {diff[i][j] = oo; for ( int x = 1;(x <= m);x++) diff[i][j] = Math.min(diff[i][j],Math.abs((a[i][x] - a[j][x]))); }slant = new int[(n + 1)][(n + 1)]; for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= n);j++) {slant[i][j] = oo; for ( int x = 1;((x + 1) <= m);x++) slant[i][j] = Math.min(slant[i][j],Math.abs((a[i][x] - a[j][(x + 1)]))); }for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= n);j++) Arrays.fill(dp[i][j],-1); int res = 0; for ( int i = 1;(i <= n);i++) res = Math.max(res,caldp(i,i,setbit(0,i))); io.print(res); } } class Kattio extends PrintWriter{ public Kattio( InputStream i){ super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Kattio( InputStream i, OutputStream o){ super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens(){ return (peekToken() != null);} public int getInt(){ return Integer.parseInt(nextToken());} private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; private String peekToken(){ if ( (token == null)) try{while(((st == null) || !st.hasMoreTokens())){line = r.readLine(); if ( (line == null)) return null; st = new StringTokenizer(line); }token = st.nextToken(); }catch (IOException e){ } return token;} private String nextToken(){ String ans = peekToken(); token = null; return ans;} }
2	public class B{ public static BufferedReader in ; public static PrintWriter out ; public static void main( String[] args)throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); boolean showLineError = true; if ( showLineError) {solve(); out.close(); } else {try{solve(); }catch (Exception e){ } finally{out.close(); }}} static private void solve()throws IOException { String[] line = in.readLine().split(" ");  long n = (Long.parseLong(line[0]) - 1);  long k = (Long.parseLong(line[1]) - 1); if ( (f(1,k) < n)) {out.println(-1); return ;} if ( (n == 0)) {out.println(0); return ;} long lo = 0l;  long hi = k; while(((lo + 1l) < hi)){ long m = ((lo + hi) / 2l);  long f = f(((k - m) + 1),k); if ( (f < n)) {lo = m; } else {hi = m; }}out.println(hi); } static private long f( long lo, long hi){ return (((lo + hi) * ((hi - lo) + 1l)) / 2l);} }
4	public class practice{ static class Reader{ private final int BUFFER_SIZE = (1 << 16); private DataInputStream din ; private byte[] buffer ; private int bufferPointer ,bytesRead ; public Reader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader( String file_name)throws IOException{ din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt()throws IOException { int ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} private void fillBuffer()throws IOException { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } private byte read()throws IOException { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} public void close()throws IOException { if ( (din == null)) return ; din.close(); } } public static void main( String[] args)throws IOException { Reader scn = new Reader("input.txt");  PrintWriter out = new PrintWriter(new File("output.txt"));  int n = scn.nextInt(),m = scn.nextInt(),k = scn.nextInt();  int[][] inf = new int[k][2]; for ( int i = 0;(i < k);i++) {inf[i][0] = scn.nextInt(); inf[i][1] = scn.nextInt(); } int ans = 0,x = 1,y = 1; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) { int temp = Integer.MAX_VALUE; for ( int l = 0;(l < k);l++) {temp = Math.min(temp,(Math.abs((i - inf[l][0])) + Math.abs((j - inf[l][1])))); }if ( (temp > ans)) {ans = temp; x = i; y = j; } }}out.print(((x + " ") + y)); out.close(); } }
6	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);  G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion(); solver.solve(1,in,out); out.close(); } static class G1PlaylistForPolycarpEasyVersion{ public void solve( int testNumber, InputReader sc, PrintWriter out){ int n = sc.nextInt();  int T = sc.nextInt();  int mod = ((int)1e9 + 7);  int dp[][][] = new int[(1 << n)][226][3];  int t[] = new int[n];  int g[] = new int[n]; for ( int i = 0;(i < n);++i) {t[i] = sc.nextInt(); g[i] = (sc.nextInt() - 1); dp[(1 << i)][t[i]][g[i]] = 1; }for ( int i = 0;(i < (1 << n));++i) {for ( int j = 0;(j < n);++j) {if ( (((i >> j) & 1) == 1)) { int newMask = (i ^ (1 << j)); for ( int k = t[j];(k <= T);++k) {for ( int l = 0;(l < 3);++l) {if ( (l == g[j])) continue; dp[i][k][g[j]] = ((dp[i][k][g[j]] + dp[newMask][(k - t[j])][l]) % mod); }}} }} long ans = 0; for ( int i = 0;(i < (1 << n));++i) {for ( int j = 0;(j < 3);++j) {ans += dp[i][T][j]; }}ans %= mod; out.print(ans); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} FastScanner in = new FastScanner(inputStream);  FastPrinter out = new FastPrinter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ public void solve( int testNumber, FastScanner in, FastPrinter out){ int n = in.nextInt();  int m = in.nextInt();  int p = in.nextInt();  int[] x = new int[p];  int[] y = new int[p]; for ( int i = 0;(i < p);i++) {x[i] = in.nextInt(); y[i] = in.nextInt(); } int X = x[0];  int Y = y[0];  int D = -1; for ( int dx = 1;(dx <= n);dx++) { int x1 = dx;  int y1 = 1;  int xx = 0;  int yy = 0;  int minD = Integer.MAX_VALUE; for ( int j = 0;(j < p);j++) { int d = (Math.abs((x1 - x[j])) + Math.abs((y1 - y[j]))); if ( (d < minD)) {minD = d; xx = x1; yy = y1; } }if ( (((D < minD) && (minD != 0)) && (minD != Integer.MAX_VALUE))) {D = minD; X = xx; Y = yy; } }for ( int dx = 1;(dx <= n);dx++) { int x1 = dx;  int y1 = m;  int xx = 0;  int yy = 0;  int minD = Integer.MAX_VALUE; for ( int j = 0;(j < p);j++) { int d = (Math.abs((x1 - x[j])) + Math.abs((y1 - y[j]))); if ( (d < minD)) {minD = d; xx = x1; yy = y1; } }if ( (((D < minD) && (minD != 0)) && (minD != Integer.MAX_VALUE))) {D = minD; X = xx; Y = yy; } }for ( int dy = 1;(dy <= m);dy++) { int x1 = 1;  int y1 = dy;  int xx = 0;  int yy = 0;  int minD = Integer.MAX_VALUE; for ( int j = 0;(j < p);j++) { int d = (Math.abs((x1 - x[j])) + Math.abs((y1 - y[j]))); if ( (d < minD)) {minD = d; xx = x1; yy = y1; } }if ( (((D < minD) && (minD != 0)) && (minD != Integer.MAX_VALUE))) {D = minD; X = xx; Y = yy; } }for ( int dy = 1;(dy <= m);dy++) { int x1 = n;  int y1 = dy;  int xx = 0;  int yy = 0;  int minD = Integer.MAX_VALUE; for ( int j = 0;(j < p);j++) { int d = (Math.abs((x1 - x[j])) + Math.abs((y1 - y[j]))); if ( (d < minD)) {minD = d; xx = x1; yy = y1; } }if ( (((D < minD) && (minD != 0)) && (minD != Integer.MAX_VALUE))) {D = minD; X = xx; Y = yy; } }for ( int i = 1;(i <= Math.min(m,n));i++) { int x1 = i;  int y1 = i;  int xx = 0;  int yy = 0;  int minD = Integer.MAX_VALUE; for ( int j = 0;(j < p);j++) { int d = (Math.abs((x1 - x[j])) + Math.abs((y1 - y[j]))); if ( (d < minD)) {minD = d; xx = x1; yy = y1; } }if ( (((D < minD) && (minD != 0)) && (minD != Integer.MAX_VALUE))) {D = minD; X = xx; Y = yy; } }for ( int i = 1,ii = m;((i <= n) && (ii >= 1));i++,ii--) { int x1 = i;  int y1 = ii;  int xx = 0;  int yy = 0;  int minD = Integer.MAX_VALUE; for ( int j = 0;(j < p);j++) { int d = (Math.abs((x1 - x[j])) + Math.abs((y1 - y[j]))); if ( (d < minD)) {minD = d; xx = x1; yy = y1; } }if ( (((D < minD) && (minD != 0)) && (minD != Integer.MAX_VALUE))) {D = minD; X = xx; Y = yy; } }out.println(((X + " ") + Y)); } } static class FastScanner{ public BufferedReader br ; public StringTokenizer st ; public FastScanner( InputStream is){ br = new BufferedReader(new InputStreamReader(is)); } public FastScanner( File f){ try{br = new BufferedReader(new FileReader(f)); }catch (FileNotFoundException e){ e.printStackTrace(); } } public String next(){ while(((st == null) || !st.hasMoreElements())){ String s = null; try{s = br.readLine(); }catch (IOException e){ e.printStackTrace(); } if ( (s == null)) return null; st = new StringTokenizer(s); }return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} } static class FastPrinter extends PrintWriter{ public FastPrinter( OutputStream out){ super(out); } public FastPrinter( Writer out){ super(out); } } }
5	public class p1096f{ static long MOD = 998244353; public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  BIT invert = new BIT((n + 5));  BIT neg = new BIT((n + 5));  long res = 0;  int[] arr = new int[n];  boolean[] has = new boolean[(n + 1)];  long num1 = 0; for ( int i = 0;(i < n);i++) {arr[i] = in.nextInt(); if ( (arr[i] != -1)) {res += (invert.read((n + 5)) - invert.read(arr[i])); res %= MOD; invert.update(arr[i],1); has[arr[i]] = true; } else num1++; }if ( (num1 == 0)) {System.out.println(res); return ;} for ( int i = 1;(i <= n);i++) if ( !has[i]) neg.update(i,1);  long invertNum1 = modInv(num1,MOD); res += (((num1 * (num1 - 1)) % MOD) * modInv(4,MOD)); res %= MOD; long cnt = 0; for ( int i = 0;(i < n);i++) {if ( (arr[i] == -1)) {cnt++; continue;} res += ((((neg.read((n + 5)) - neg.read(arr[i])) * cnt) % MOD) * invertNum1); res %= MOD; }cnt = 0; for ( int i = (n - 1);(i >= 0);i--) {if ( (arr[i] == -1)) {cnt++; continue;} res += (((neg.read(arr[i]) * cnt) % MOD) * invertNum1); res %= MOD; }System.out.println(res); } static class BIT{ int n ; int[] tree ; public BIT( int n){ this.n = n; tree = new int[(n + 1)]; } int read( int i){ int sum = 0; while((i > 0)){sum += tree[i]; i -= (i & -i); }return sum;} void update( int i, int val){ while((i <= n)){tree[i] += val; i += (i & -i); }} } static long modInv( long x, long mod){ return BigInteger.valueOf(x).longValue();} static long modInv( long a, long b, long y0, long y1, long q0, long q1){ long y2 = (y0 - (y1 * q0)); return ((b == 0)?y2:modInv(b,(a % b),y1,y2,q1,(a / b)));} static long gcd( long a, long b){ return ((b == 0)?a:gcd(b,(a % b)));} }
4	public class FireAgain{ public static void main( String[] args){ File in = new File("input.txt");  File out = new File("output.txt");  Scanner sc ;  PrintWriter pw ; try{sc = new Scanner(in); pw = new PrintWriter(out); }catch (Exception e){ sc = new Scanner(System.in); pw = null; } int max_x = sc.nextInt();  int max_y = sc.nextInt();  int start_num = sc.nextInt();  HashSet<int[]> start = new HashSet<int[]>(); for ( int i = 0;(i < start_num);i++) { int[] cell = new int[2]; cell[0] = sc.nextInt(); cell[1] = sc.nextInt(); start.add(cell); } int[] result = new int[]{1,1};  int resultLen = 0; for ( int i = 1;(i <= max_x);i++) {for ( int j = 1;(j <= max_y);j++) { int[] sh = new int[]{1,1};  int shLen = Integer.MAX_VALUE; for ( int[] fired :start) { int len = (Math.abs((i - fired[0])) + Math.abs((j - fired[1]))); if ( (len < shLen)) {sh[0] = i; sh[1] = j; shLen = len; } }if ( (shLen > resultLen)) {result[0] = sh[0]; result[1] = sh[1]; resultLen = shLen; } }}pw.print(((result[0] + " ") + result[1])); pw.close(); return ;} }
5	public class A{ static int[] solve( int[] a){ int n = a.length; Arrays.sort(a); a[(n - 1)] = ((a[(n - 1)] > 1)?1:2); int[] b = Arrays.copyOf(a,n); Arrays.sort(b); return b;} public static void main( String[] args)throws Exception { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); setTime(); int n = nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); } int[] b = solve(a); for ( int v :b) {writer.print((v + " ")); }printTime(); printMemory(); writer.close(); } static BufferedReader reader ; static PrintWriter writer ; static StringTokenizer tok = new StringTokenizer(""); static long systemTime ; static void setTime(){ systemTime = System.currentTimeMillis(); } static void printTime(){ System.err.println(("Time consumed: " + (System.currentTimeMillis() - systemTime))); } static void printMemory(){ System.err.println((("Memory consumed: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000)) + "kb")); } static String next(){ while(!tok.hasMoreTokens()){ String w = null; try{w = reader.readLine(); }catch (Exception e){ e.printStackTrace(); } if ( (w == null)) return null; tok = new StringTokenizer(w); }return tok.nextToken();} static int nextInt(){ return Integer.parseInt(next());} }
2	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);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, Scanner in, PrintWriter out){ long n = in.nextLong();  long k = in.nextLong(); if ( (n == 1)) {out.println(0); return ;} if ( ((k * (k - 1)) < (2 * (n - 1)))) {out.println(-1); return ;} long sq2 = (((((4 * k) * k) - (4 * k)) + 1) - (4 * ((2 * n) - 2)));  long km = Math.max(2,((long)((Math.sqrt(sq2) + 3) / 2.0) - 3)); while(((((km + k) - 2) * ((k - km) + 1)) >= (2 * (n - 1)))){++km; }out.println(((k - km) + 2)); } }
5	public class CottageVillage{ static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st ; static String LINE()throws Exception { return stdin.readLine();} static String TOKEN()throws Exception { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(LINE()); return st.nextToken();} static int INT()throws Exception { return Integer.parseInt(TOKEN());} static DecimalFormat DF = new DecimalFormat("0.000",new DecimalFormatSymbols(Locale.ENGLISH)); public static final double EPSILON = 1E-9; public static void main( String[] args)throws Exception { int N = INT(),T = INT();  House[] list = new House[N]; for ( int i = 0;(i < N);i++) {list[i] = new House(INT(),INT()); }Arrays.sort(list); int cnt = 2; for ( int i = 1;(i < N);i++) { int room = (list[i].center - list[(i - 1)].center); if ( ((2 * T) < (((2 * room) - list[i].side) - list[(i - 1)].side))) cnt += 2; else if ( ((2 * T) == (((2 * room) - list[i].side) - list[(i - 1)].side))) cnt++; }System.out.println(cnt); } static private class House implements Comparable<House>{ int center ,side ; House( int c, int s){ this.center = c; this.side = s; } } }
2	public class BBi implements Runnable{ public static void main( String[] args){ new Thread(new BBi()).run(); } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer in ; PrintWriter out = new PrintWriter(System.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 long nextLong()throws IOException { return Long.parseLong(nextToken());} int n ,x ,y ; public long count( long z){ long total = 0;  long[][] c = new long[][]{{x,y},{y,((n - x) + 1)},{((n - x) + 1),((n - y) + 1)},{((n - y) + 1),x}}; for ( int i = 0;(i < c.length);i++) { long inside = z; for ( int j = 0;(j < c[i].length);j++) {if ( (z > c[i][j])) {total += (Math.min((z - c[i][j]),c[i][(1 - j)]) * c[i][j]); inside -= (z - c[i][j]); } }if ( ((z > c[i][0]) && (z > c[i][1]))) {total -= (Math.min((z - c[i][0]),c[i][1]) * Math.min((z - c[i][1]),c[i][0])); } if ( (inside > 0)) total += ((inside * (inside + 1)) / 2); }for ( int i = 0;(i < c.length);i++) {total -= Math.min(z,c[i][0]); }return (total + 1);} public long solve( int n, int x, int y, long c)throws IOException { this.n = n; this.x = x; this.y = y; long l = 0;  long r = ((2L * n) + 2); while(((r - l) > 1)){ long z = ((l + r) / 2); if ( (c <= count(z))) {r = z; } else {l = z; }}return (r - 1);} public void run(){ try{out.println(solve(nextInt(),nextInt(),nextInt(),nextLong())); out.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } }
5	public class Solution implements Runnable{ public static BufferedReader br ; public static PrintWriter out ; public static StringTokenizer stk ; public static boolean isStream = true; public static void main( String[] args)throws IOException { if ( isStream) {br = new BufferedReader(new InputStreamReader(System.in)); } else {br = new BufferedReader(new FileReader("in.txt")); }out = new PrintWriter(System.out); new Thread(new Solution()).start(); } public void loadLine(){ try{stk = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } public Integer nextInt(){ while(((stk == null) || !stk.hasMoreTokens()))loadLine(); return Integer.valueOf(stk.nextToken());} }
2	public class Main{ long k ; private void solve()throws IOException { long n = nl(); k = nl(); if ( (n == 1)) {prln(0); return ;} if ( (n <= k)) {prln(1); return ;} long l = 1,r = (k - 1);  long mid = (((l + r) + 1) / 2);  long old = -1; while((old != mid)){old = mid; if ( (take(mid) >= n)) r = mid; if ( (take(mid) < n)) l = mid; mid = (((l + r) + 1) / 2); }if ( ((mid >= k) || (mid <= 0))) {prln(-1); return ;} if ( (take(mid) == n)) {prln(mid); return ;} if ( (mid == (k - 1))) prln(-1); else if ( (take(mid) < n)) prln((mid + 1)); else prln(mid); } long take( long t){ return (((k * t) - ((t * (t - 1)) / 2)) - (t - 1));} public static void main( String[] args){ new Main().run(); } public void run(){ try{if ( isFileIO) {pw = new PrintWriter(new File("output.out")); br = new BufferedReader(new FileReader("input.in")); } else {pw = new PrintWriter(System.out); br = new BufferedReader(new InputStreamReader(System.in)); }solve(); pw.close(); br.close(); }catch (IOException e){ System.err.println("IO Error"); } } private void prln( Object o){ pw.println(o); } private void prln(){ pw.println(); } long nl()throws IOException { return Long.parseLong(nextToken());} private String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(br.readLine()); }return tokenizer.nextToken();} private BufferedReader br ; private StringTokenizer tokenizer ; private PrintWriter pw ; private final boolean isFileIO = false; }
3	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);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ static final long MODULO = (long)(1e9 + 7); public void solve( int testNumber, FastReader in, PrintWriter out){ int n = in.nextInt();  long[][] dp = new long[(n + 100)][(n + 100)]; dp[0][0] = 1; for ( int i = 0;(i < n);++i) { char current = in.nextCharacter(); if ( (current == 'f')) {for ( int j = 0;(j < n);++j) {dp[(i + 1)][(j + 1)] += dp[i][j]; dp[(i + 1)][(j + 1)] %= MODULO; }} else { long runningSum = 0; for ( int j = n;(j >= 0);--j) {runningSum += dp[i][j]; runningSum %= MODULO; dp[(i + 1)][j] += runningSum; dp[(i + 1)][j] %= MODULO; }}}out.println(dp[n][0]); } } static class FastReader{ private InputStream stream ; private byte[] buf = new byte[8192]; private int curChar ; private int pnumChars ; public FastReader( InputStream stream){ this.stream = stream; } private int pread(){ if ( (pnumChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= pnumChars)) {curChar = 0; try{pnumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (pnumChars <= 0)) {return -1;} } return buf[curChar++];} public int nextInt(){ int c = pread(); while(isSpaceChar(c))c = pread(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = pread(); } int res = 0; do {if ( (c == ',')) {c = pread(); } if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = pread(); }while(!isSpaceChar(c));return (res * sgn);} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char nextCharacter(){ int c = pread(); while(isSpaceChar(c))c = pread(); return (char)c;} } }
0	@SuppressWarnings("unused") public class A{ public static void main( String[] args)throws Exception { Scanner in = new Scanner(System.in);  long n = in.nextLong(); System.out.println(("0 0 " + n)); } }
1	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();  String s = in.next();  HashMap<Character,Integer> indexMap = new HashMap<>(); for ( int i = 0;(i < n);i++) { char c = s.charAt(i); if ( !indexMap.containsKey(c)) {indexMap.put(c,indexMap.size()); } } int[] last = new int[indexMap.size()]; Arrays.fill(last,-1_000_000); int answer = n; for ( int i = 0;(i < n);i++) { int index = indexMap.get(s.charAt(i)); last[index] = i; int first = i; for ( int a :last) first = Math.min(first,a); int visits = ((i - first) + 1); answer = Math.min(answer,visits); }out.println(answer); } } }
5	public class Cottage{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  List<Point> houses = new ArrayList<Point>(); for ( int i = 0;(i < n);i++) { int x = sc.nextInt();  int a = sc.nextInt(); houses.add(new Point(x,a)); }Collections.sort(houses,new Comparator<Point>(){}); int pos = 2; for ( int i = 0;(i < (n - 1));i++) { double end = (houses.get(i).x + ((houses.get(i).y + 0.0) / 2));  double start = (houses.get((i + 1)).x - ((houses.get((i + 1)).y + 0.0) / 2));  double diff = (start - end); if ( (Math.abs((diff - t)) < 0.0000001)) {pos++; } if ( (diff > t)) {pos += 2; } }System.out.println(pos); } }
3	public class Codeforces455Div2C{ public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  String[] sp = br.readLine().split(" ");  int n = Integer.parseInt(sp[0]);  char[] list = new char[n]; for ( int i = 0;(i < n);i++) {sp = br.readLine().split(" "); list[i] = sp[0].charAt(0); } int[] list2 = new int[n];  int counter = 0; for ( int i = 0;(i < n);i++) {if ( (list[i] == 's')) {counter++; } else {list2[counter]++; }} int[][] dp = new int[counter][((n - counter) + 1)];  int[][] dpsum = new int[counter][((n - counter) + 1)];  int[] count = new int[counter]; count[0] = list2[0]; for ( int i = 1;(i < counter);i++) {count[i] = (count[(i - 1)] + list2[i]); }for ( int i = 0;(i <= count[0]);i++) {dp[0][i] = 1; dpsum[0][i] = (i + 1); }for ( int i = 1;(i < counter);i++) {for ( int j = 0;(j <= count[i]);j++) {dp[i][j] = dpsum[(i - 1)][Math.min(j,count[(i - 1)])]; }dpsum[i][0] = dp[i][0]; for ( int j = 1;(j <= count[i]);j++) {dpsum[i][j] = ((dpsum[i][(j - 1)] + dp[i][j]) % 1000000007); }}System.out.println(dp[(counter - 1)][(n - counter)]); } }
3	public class C{ InputStream in ; PrintWriter out ; void solve(){ int n = ni();  long dp[] = new long[(n + 1)]; dp[0] = 1; for ( int i = 0;(i < n);) {i++; if ( (nc() == 'f')) {i++; int k = 1; while((nc() != 's')){i++; k++; }for ( int j = (n - 1);(j >= 0);j--) {dp[j] = add(dp[j],dp[(j + 1)]); }for ( int j = n;(j >= k);j--) {dp[j] = dp[(j - k)]; }for ( int j = 0;(j < k);j++) dp[j] = 0; } else {for ( int j = (n - 1);(j >= 0);j--) {dp[j] = add(dp[j],dp[(j + 1)]); }}} long sum = 0; for ( int i = 0;(i <= n);i++) sum = add(sum,dp[i]); out.println(sum); } long mod = ((long)1e9 + 7); long add( long a, long b){ long x = (a + b); while((x >= mod))x -= mod; return x;} long mul( long a, long b){ a %= mod; b %= mod; long x = (a * b); return (x % mod);} void run()throws Exception { String INPUT = "C:/Users/ayubs/Desktop/input.txt"; in = (oj?System.in:new FileInputStream(INPUT)); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(((System.currentTimeMillis() - s) + "ms")); } public static void main( String[] args)throws Exception { new C().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0,ptrbuf = 0; private int readByte(){ if ( (lenbuf == -1)) throw (new InputMismatchException()); if ( (ptrbuf >= lenbuf)) {ptrbuf = 0; try{lenbuf = in.read(inbuf); }catch (IOException e){ throw (new InputMismatchException());} if ( (lenbuf <= 0)) return -1; } return inbuf[ptrbuf++];} private boolean inSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && inSpaceChar(b)));return b;} private char nc(){ return (char)skip();} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!inSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !inSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private int ni(){ 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(); }} private boolean oj = (System.getProperty("ONLINE_JUDGE") != null); private void tr( Object... o){ if ( !oj) System.out.println(Arrays.deepToString(o)); } }
4	public class Main{ public static void main( String[] args)throws IOException { InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter("output.txt");  TaskB solver = new TaskB(); solver.solve(in,out); out.close(); } static private class TaskB{ static final long max = 1000000000000000000L; static final double eps = 0.0000001; static final long mod = 1000000007; static int N ,M ,K ; static long X ,Y ; static boolean F[][][] ; static int D[][] ; void solve( InputReader in, PrintWriter out)throws IOException { N = in.nextInt(); M = in.nextInt(); K = in.nextInt(); F = new boolean[K][N][M]; D = new int[N][M]; for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) D[i][j] = Integer.MAX_VALUE; List<Pair> list = new ArrayList<>(); for ( int i = 0;(i < K);i++) {list.add(new Pair((in.nextInt() - 1),(in.nextInt() - 1))); }for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) for ( int k = 0;(k < K);k++) D[i][j] = Math.min(D[i][j],(Math.abs((list.get(k).X - i)) + Math.abs((list.get(k).Y - j)))); int res = Integer.MIN_VALUE; for ( int j = 0;(j < N);j++) for ( int k = 0;(k < M);k++) if ( (D[j][k] > res)) {X = (j + 1); Y = (k + 1); res = D[j][k]; } out.println(((X + " ") + Y)); } class Pair{ int X ,Y ; Pair( int X, int Y){ this.X = X; this.Y = Y; } } long gcd( long A, long B){ if ( (B == 0)) return A; return gcd(B,(A % B));} long pow( long A, long B, long MOD){ if ( (B == 0)) {return 1;} if ( (B == 1)) {return A;} long val = pow(A,(B / 2),MOD); if ( ((B % 2) == 0)) {return ((val * val) % MOD);} else {return ((val * ((val * A) % MOD)) % MOD);}} } static private class InputReader{ StringTokenizer st ; BufferedReader br ; public InputReader( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } public InputReader( FileReader s)throws FileNotFoundException{ br = new BufferedReader(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());} public boolean ready(){ try{return br.ready(); }catch (IOException e){ throw (new RuntimeException(e));} } } }
3	public class PythonIndentation{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  boolean[] lst = new boolean[n]; for ( int i = 0;(i < n);i++) {lst[i] = (in.next()?false:true); }System.out.println(dp(lst)); } static long dp( boolean[] lst){ long[][] dp = new long[lst.length][lst.length]; dp[0][0] = 1; for ( int i = 1;(i < lst.length);i++) {for ( int j = 0;(j < lst.length);j++) {if ( lst[(i - 1)]) {if ( (j == 0)) dp[i][j] = 0; else dp[i][j] = dp[(i - 1)][(j - 1)]; } else {if ( (j == 0)) {for ( int k = 0;(k < lst.length);k++) dp[i][j] = ((dp[i][j] + dp[(i - 1)][k]) % 1000000007); } else dp[i][j] = ((dp[i][(j - 1)] - dp[(i - 1)][(j - 1)]) % 1000000007); }}} long ans = 0; for ( int i = 0;(i < lst.length);i++) {ans = ((ans + dp[(lst.length - 1)][i]) % 1000000007); }if ( (ans < 0)) ans = (ans + 1000000007); return ans;} }
1	public class C{ static private BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static private PrintStream out = System.out; public static void main( String[] args)throws NumberFormatException,IOException { int n = Integer.parseInt(in.readLine());  char[] s = in.readLine().toCharArray();  HashSet<Character> all = new HashSet<Character>(); for ( char c :s) all.add(c); int totalCount = all.size();  HashMap<Character,Integer> cnts = new HashMap<Character,Integer>();  int ans = Integer.MAX_VALUE;  int x = 0; for ( int y = 0;(y < n);++y) {if ( !cnts.containsKey(s[y])) cnts.put(s[y],0); cnts.put(s[y],(cnts.get(s[y]) + 1)); if ( (cnts.size() < totalCount)) continue; while((cnts.get(s[x]) > 1)){cnts.put(s[x],(cnts.get(s[x]) - 1)); ++x; }ans = Math.min(ans,((y - x) + 1)); }out.println(ans); } }
5	public class A{ BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter writer ; void run(){ try{reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens()))tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} void solve()throws IOException { int n = nextInt();  int[] a = new int[n]; for ( int i = 0;(i < a.length);i++) {a[i] = nextInt(); }Arrays.sort(a); if ( (a[(a.length - 1)] == 1)) {for ( int i = 0;(i < (a.length - 1));i++) {writer.print((1 + " ")); }writer.println((2 + "")); return ;} for ( int i = 0;(i < a.length);i++) {if ( (i == 0)) writer.print((1 + " ")); else writer.print((a[(i - 1)] + " ")); }writer.println(); } public static void main( String[] args){ new A().run(); } }
1	public class IQ{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int n = scan.nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = scan.nextInt(); for ( int i = 0;(i < n);i++) { boolean x = ((a[i] % 2) == 0);  int c = 0; for ( int j = 0;(j < n);j++) {if ( (x != ((a[j] % 2) == 0))) c++; }if ( (c == (n - 1))) {System.out.println((i + 1)); break;} }} }
5	public class Solution{ static class Cottage implements Comparable<Cottage>{ public int x ; public double a ; public Cottage( int x, int a){ this.x = x; this.a = a; } } static final double e = 1e-9; public static void main( String[] args){ Scanner in = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt();  int t = in.nextInt();  Cottage[] cottages = new Cottage[n]; for ( int i = 0;(i < n);i++) cottages[i] = new Cottage(in.nextInt(),in.nextInt()); Arrays.sort(cottages); int ans = 2; for ( int i = 1;(i < cottages.length);i++) { double diff = (((cottages[i].x - cottages[(i - 1)].x) - (cottages[(i - 1)].a / 2)) - (cottages[i].a / 2)); ans = ((Math.abs((diff - t)) < e)?(ans + 1):(((diff - t) < -e)?ans:(ans + 2))); }out.print(ans); out.close(); } }
4	public class MainF{ public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new FileReader(new File("input.txt")));  BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.txt")));  String S = br.readLine();  String[] J = S.split(" ");  int N = Integer.parseInt(J[0]);  int M = Integer.parseInt(J[1]);  int K = Integer.parseInt(br.readLine());  int[] x = new int[K];  int[] y = new int[K]; S = br.readLine(); J = S.split(" "); for ( int i = 0;(i < (2 * K));i = (i + 2)) {x[(i / 2)] = Integer.parseInt(J[i]); y[(i / 2)] = Integer.parseInt(J[(i + 1)]); } int ans = -1;  int ansX = -1;  int ansY = -1; for ( int i = 1;(i <= N);i++) {for ( int j = 1;(j <= M);j++) { int W = (M + N); for ( int k = 0;(k < K);k++) {W = Math.min(W,(Math.abs((i - x[k])) + Math.abs((j - y[k])))); }if ( (W < ans)) continue; ans = W; ansX = i; ansY = j; }}bw.write(((Integer.toString(ansX) + " ") + Integer.toString(ansY))); br.close(); bw.close(); } }
0	public class cf2{ static final double EPS = 1e-9; public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  int xr1 = sc.nextInt(),yr1 = sc.nextInt(),xr2 = sc.nextInt(),yr2 = sc.nextInt();  int xr3 = sc.nextInt(),yr3 = sc.nextInt(),xr4 = sc.nextInt(),yr4 = sc.nextInt();  Point pr1 = new Point(xr1,yr1);  Point pr2 = new Point(xr2,yr2);  Point pr3 = new Point(xr3,yr3);  Point pr4 = new Point(xr4,yr4);  LineSegment lr1 = new LineSegment(pr1,pr2);  LineSegment lr2 = new LineSegment(pr2,pr3);  LineSegment lr3 = new LineSegment(pr3,pr4);  LineSegment lr4 = new LineSegment(pr4,pr1);  int xd1 = sc.nextInt(),yd1 = sc.nextInt(),xd2 = sc.nextInt(),yd2 = sc.nextInt();  int xd3 = sc.nextInt(),yd3 = sc.nextInt(),xd4 = sc.nextInt(),yd4 = sc.nextInt();  Point p1 = new Point(xd1,yd1);  Point p2 = new Point(xd2,yd2);  Point p3 = new Point(xd3,yd3);  Point p4 = new Point(xd4,yd4);  Point[] pt = new Point[5]; pt[0] = p1; pt[1] = p2; pt[2] = p3; pt[3] = p4; pt[4] = p1; Polygon pg = new Polygon(pt); if ( (((pg.inside(pr1) || pg.inside(pr2)) || pg.inside(pr3)) || pg.inside(pr4))) {System.out.println("YES"); return ;} LineSegment ld1 = new LineSegment(p1,p2);  LineSegment ld2 = new LineSegment(p2,p3);  LineSegment ld3 = new LineSegment(p3,p4);  LineSegment ld4 = new LineSegment(p4,p1);  Rectangle rec = new Rectangle(new Point(Math.min(Math.min(xr3,xr4),Math.min(xr1,xr2)),Math.min(Math.min(yr3,yr4),Math.min(yr1,yr2))),new Point(Math.max(Math.max(xr3,xr4),Math.max(xr1,xr2)),Math.max(Math.max(yr3,yr4),Math.max(yr1,yr2)))); if ( (((rec.contains(p1) || rec.contains(p2)) || rec.contains(p3)) || rec.contains(p4))) {System.out.println("YES"); return ;} if ( (((ld1.intersect(lr1) || ld1.intersect(lr3)) || ld1.intersect(lr3)) || ld1.intersect(lr4))) {System.out.println("YES"); return ;} if ( (((ld2.intersect(lr1) || ld2.intersect(lr3)) || ld2.intersect(lr3)) || ld2.intersect(lr4))) {System.out.println("YES"); return ;} if ( (((ld3.intersect(lr1) || ld3.intersect(lr3)) || ld3.intersect(lr3)) || ld3.intersect(lr4))) {System.out.println("YES"); return ;} if ( (((ld4.intersect(lr1) || ld4.intersect(lr3)) || ld4.intersect(lr3)) || ld4.intersect(lr4))) {System.out.println("YES"); return ;} System.out.println("NO"); } public static class Polygon{ static final double EPS = 1e-9; Point[] g ; Polygon( Point[] o){ g = o; } double area(){ double area = 0.0; for ( int i = 0;(i < (g.length - 1));++i) area += ((g[i].x * g[(i + 1)].y) - (g[i].y * g[(i + 1)].x)); return (Math.abs(area) / 2.0);} boolean inside( Point p){ double sum = 0.0; for ( int i = 0;(i < (g.length - 1));++i) { double angle = Point.angle(g[i],p,g[(i + 1)]); if ( (((Math.abs(angle) < EPS) || (Math.abs((angle - Math.PI)) < EPS)) && p.between(g[i],g[(i + 1)]))) return true; if ( Point.ccw(p,g[i],g[(i + 1)])) sum += angle; else sum -= angle; }return (Math.abs(((2 * Math.PI) - Math.abs(sum))) < EPS);} } static class LineSegment{ Point p ,q ; LineSegment( Point a, Point b){ p = a; q = b; } boolean intersect( LineSegment ls){ Line l1 = new Line(p,q),l2 = new Line(ls.p,ls.q); if ( l1.parallel(l2)) {if ( l1.same(l2)) return (((p.between(ls.p,ls.q) || q.between(ls.p,ls.q)) || ls.p.between(p,q)) || ls.q.between(p,q)); return false;} Point c = l1.intersect(l2); return (c.between(p,q) && c.between(ls.p,ls.q));} } static class Rectangle{ static final double EPS = 1e-9; Point ll ,ur ; Rectangle( Point a, Point b){ ll = a; ur = b; } double area(){ return ((ur.x - ll.x) * (ur.y - ll.y));} boolean contains( Point p){ return ((((p.x <= (ur.x + EPS)) && ((p.x + EPS) >= ll.x)) && (p.y <= (ur.y + EPS))) && ((p.y + EPS) >= ll.y));} Rectangle intersect( Rectangle r){ Point ll = new Point(Math.max(this.ll.x,r.ll.x),Math.max(this.ll.y,r.ll.y));  Point ur = new Point(Math.min(this.ur.x,r.ur.x),Math.min(this.ur.y,r.ur.y)); if ( ((((((Math.abs((ur.x - ll.x)) > EPS) && (Math.abs((ur.y - ll.y)) > EPS)) && this.contains(ll)) && this.contains(ur)) && r.contains(ll)) && r.contains(ur))) return new Rectangle(ll,ur); return null;} } static class Line{ static final double INF = 1e9,EPS = 1e-9; double a ,b ,c ; Line( Point p, Point q){ if ( (Math.abs((p.x - q.x)) < EPS)) {a = 1; b = 0; c = -p.x; } else {a = ((p.y - q.y) / (q.x - p.x)); b = 1.0; c = ((a * p.x) + p.y); }} Line( Point p, double m){ a = -m; b = 1; c = ((a * p.x) + p.y); } boolean parallel( Line l){ return ((Math.abs((a - l.a)) < EPS) && (Math.abs((b - l.b)) < EPS));} boolean same( Line l){ return (parallel(l) && (Math.abs((c - l.c)) < EPS));} Point intersect( Line l){ if ( parallel(l)) return null; double x = (((b * l.c) - (c * l.b)) / ((a * l.b) - (b * l.a)));  double y ; if ( (Math.abs(b) < EPS)) y = ((-l.a * x) - l.c); else y = ((-a * x) - c); return new Point(x,y);} } public static class Vector{ double x ,y ; Vector( double a, double b){ x = a; y = b; } Vector( Point a, Point b){ this((b.x - a.x),(b.y - a.y)); } Vector scale( double s){ return new Vector((x * s),(y * s));} double dot( Vector v){ return ((x * v.x) + (y * v.y));} double cross( Vector v){ return ((x * v.y) - (y * v.x));} double norm2(){ return ((x * x) + (y * y));} } static class Point implements Comparable<Point>{ static final double EPS = 1e-9; double x ,y ; Point( double a, double b){ x = a; y = b; } static double angle( Point a, Point o, Point b){ Vector oa = new Vector(o,a),ob = new Vector(o,b); return Math.acos((oa.dot(ob) / Math.sqrt((oa.norm2() * ob.norm2()))));} static boolean ccw( Point p, Point q, Point r){ return (new Vector(p,q).cross(new Vector(p,r)) > 0);} public double dist( Point p){ return Math.sqrt((sq((x - p.x)) + sq((y - p.y))));} static double sq( double x){ return (x * x);} boolean between( Point p, Point q){ return ((((x < (Math.max(p.x,q.x) + EPS)) && ((x + EPS) > Math.min(p.x,q.x))) && (y < (Math.max(p.y,q.y) + EPS))) && ((y + EPS) > Math.min(p.y,q.y)));} } 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 Scanner( String file)throws FileNotFoundException{ br = new BufferedReader(new FileReader(file)); } public int nextInt()throws IOException { return Integer.parseInt(next());} public boolean ready()throws IOException { return br.ready();} } }
3	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 int mod = ((int)Math.pow(10,9) + 7); public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.readInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = ((in.readString().charAt(0) == 'f')?1:0); } long[][] ans = new long[n][(n + 2)]; ans[0][0] = 1; int indent = 0; if ( (a[0] == 1)) indent++; for ( int i = 1;(i < n);i++) {if ( (a[(i - 1)] == 1)) {for ( int j = (indent - 1);(j >= 1);j--) {ans[i][j] = ans[(i - 1)][(j - 1)]; }ans[i][indent] = 1; } else {for ( int j = indent;(j >= 0);j--) {ans[i][j] = ((ans[i][(j + 1)] + ans[(i - 1)][j]) % mod); }}indent += a[i]; } long aa = 0; for ( int i = 0;(i < (n + 2));i++) {aa = ((aa + ans[(n - 1)][i]) % mod); }out.println(aa); } } static class InputReader{ private final InputStream stream ; private final byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public InputReader( InputStream stream){ this.stream = stream; } private int read(){ try{if ( (curChar >= numChars)) {curChar = 0; numChars = stream.read(buf); if ( (numChars <= 0)) return -1; } }catch (IOException e){ throw (new RuntimeException(e));} return buf[curChar++];} public int readInt(){ return (int)readLong();} public long readLong(){ int c = read(); while(isSpaceChar(c)){c = read(); if ( (c == -1)) throw (new RuntimeException()); } boolean negative = false; if ( (c == '-')) {negative = true; c = read(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (negative?res:res);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.append((char)c); c = read(); }while(!isSpaceChar(c));return res.toString();} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } }
2	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, InputReader in, OutputWriter out){ int side = in.readInt();  int row = (in.readInt() - 1);  int column = (in.readInt() - 1);  int required = in.readInt();  long left = 0;  long right = ((2 * side) - 2); while((left < right)){ long current = ((left + right) / 2);  long result = ((((calculate(row,column,current) + calculate(column,((side - row) - 1),current)) + calculate(((side - row) - 1),((side - column) - 1),current)) + calculate(((side - column) - 1),row,current)) + 1); if ( (result >= required)) right = current; else left = (current + 1); }out.printLine(left); } private long calculate( int row, int column, long current){ column++; long total = 0;  long mn = Math.min(row,column);  long mx = Math.max(row,column); if ( (current <= mn)) return ((current * (current + 1)) / 2); total += ((mn * (mn + 1)) / 2); current -= mn; mx -= mn; if ( (current <= mx)) return (total + (mn * current)); total += (mn * mx); current -= mx; if ( (current < mn)) return ((total + (((mn - 1) * mn) / 2)) - ((((mn - current) - 1) * (mn - current)) / 2)); return (total + (((mn - 1) * mn) / 2));} } class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void print( Object... objects){ for ( int i = 0;(i < objects.length);i++) {if ( (i != 0)) writer.print(' '); writer.print(objects[i]); }} public void printLine( Object... objects){ print(objects); writer.println(); } public void close(){ writer.close(); } }
4	public class Main{ static BufferedReader br ; static PrintWriter out ; static StringTokenizer st ; static int[][] moves = new int[][]{{0,1},{1,0},{-1,0},{0,-1}}; static boolean correct( int x, int y, int n, int m){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} static void solve()throws Exception { int n = nextInt();  int m = nextInt();  int k = nextInt();  int[][] order = new int[n][m];  boolean[][] used = new boolean[n][m];  Queue<Integer[]> q = new LinkedList<>();  Set<String> set = new HashSet<String>(); for ( int i = 0;(i < k);i++) { int x = (nextInt() - 1);  int y = (nextInt() - 1); order[x][y] = 1; used[x][y] = true; q.add(new Integer[]{x,y}); set.add(((x + "") + y)); }while(!q.isEmpty()){ Integer[] v = q.remove(); for ( int[] move :moves) { int x = (v[0] + move[0]);  int y = (v[1] + move[1]); if ( (correct(x,y,n,m) && !used[x][y])) {q.add(new Integer[]{x,y}); used[x][y] = true; order[x][y] = (order[v[0]][v[1]] + 1); } }} int max = Integer.MIN_VALUE;  int maxI = -1;  int maxJ = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (order[i][j] > max)) {max = order[i][j]; maxI = i; maxJ = j; } }}maxI++; maxJ++; out.println(((maxI + " ") + maxJ)); } static int nextInt()throws IOException { return Integer.parseInt(next());} static String next()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String line = br.readLine(); if ( (line == null)) {return null;} st = new StringTokenizer(line); }return st.nextToken();} public static void main( String[] args){ try{ InputStream input = System.in;  OutputStream output = System.out; br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); out = new PrintWriter(new PrintStream(new File("output.txt"))); solve(); out.close(); br.close(); }catch (Throwable t){ t.printStackTrace(); } } }
5	public class A{ final String filename = new String("A").toLowerCase(); void solve()throws Exception { int n = nextInt();  int[] a = new int[n];  int m = -1; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); if ( ((m == -1) || (a[i] > a[m]))) {m = i; } }if ( (a[m] == 1)) a[m] = 2; else a[m] = 1; Arrays.sort(a); for ( int i = 0;(i < n);i++) {out.print((a[i] + " ")); }} void run(){ try{in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } BufferedReader in ; StringTokenizer st ; PrintWriter out ; String nextToken()throws Exception { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(nextToken());} public static void main( String[] args){ new A().run(); } }
4	public class FireAgain{ Scanner in ; PrintWriter out ; public static void main( String[] args)throws IOException { new FireAgain().run(); } void run()throws IOException { in = new Scanner(new FileReader("input.txt")); out = new PrintWriter(new FileWriter("output.txt")); solve(); in.close(); out.close(); } private void solve(){ int N = in.nextInt();  int M = in.nextInt();  int[][] burn = new int[(N + 1)][(M + 1)];  int K = in.nextInt();  int[] qx = new int[(N * M)];  int[] qy = new int[(N * M)];  int first = 0;  int last = 0; for ( int i = 0;(i < K);i++) {qx[last] = in.nextInt(); qy[last] = in.nextInt(); burn[qx[last]][qy[last]] = 1; last++; }while((first < last)){ int x = qx[first];  int y = qy[first]; if ( (((x - 1) > 0) && (burn[(x - 1)][y] == 0))) {burn[(x - 1)][y] = 1; qx[last] = (x - 1); qy[last] = y; last++; } if ( (((y - 1) > 0) && (burn[x][(y - 1)] == 0))) {burn[x][(y - 1)] = 1; qx[last] = x; qy[last] = (y - 1); last++; } if ( (((x + 1) <= N) && (burn[(x + 1)][y] == 0))) {burn[(x + 1)][y] = 1; qx[last] = (x + 1); qy[last] = y; last++; } if ( (((y + 1) <= M) && (burn[x][(y + 1)] == 0))) {burn[x][(y + 1)] = 1; qx[last] = x; qy[last] = (y + 1); last++; } first++; }out.println(((qx[(last - 1)] + " ") + qy[(last - 1)])); } }
4	public class R035CRetry{ public static final int INF = 987654321; public static final long LINF = 987654321987654321L; public static final double EPS = 1e-9; Scanner scanner ; PrintWriter out ; boolean[][] bss ; public R035CRetry(){ try{this.scanner = new Scanner(new File("input.txt")); this.out = new PrintWriter("output.txt"); }catch (FileNotFoundException ex){ ex.printStackTrace(); } } class Point implements Comparable<Point>{ int x ,y ,count ; Point( int x, int y){ this.x = x; this.y = y; } } int[] dx = new int[]{0,0,-1,1}; int[] dy = new int[]{-1,1,0,0}; int n ,m ; Queue<Point> q ; Point bfs(){ int max = -INF;  Point p = null; while(!q.isEmpty()){ Point cur = q.remove(); if ( (max < cur.count)) {max = cur.count; p = cur; } for ( int i = 0;(i < dx.length);i++) { int nx = (cur.x + dx[i]);  int ny = (cur.y + dy[i]); if ( ((nx < 0) || (nx >= n))) {continue;} if ( ((ny < 0) || (ny >= m))) {continue;} Point np = new Point(nx,ny); if ( bss[nx][ny]) {continue;} np.count = (cur.count + 1); bss[nx][ny] = true; q.add(np); }}return p;} private void solve(){ this.n = scanner.nextInt(); this.m = scanner.nextInt(); this.bss = new boolean[n][m]; int k = scanner.nextInt(); q = new LinkedList<Point>(); for ( int i = 0;(i < k);i++) { int x = (scanner.nextInt() - 1);  int y = (scanner.nextInt() - 1);  Point init = new Point(x,y); init.count = 1; q.add(init); bss[x][y] = true; } Point p = bfs(); out.println((((p.x + 1) + " ") + (p.y + 1))); } private void finish(){ this.out.close(); } public static void main( String[] args){ R035CRetry obj = new R035CRetry(); obj.solve(); obj.finish(); } }
6	public class G extends PrintWriter{ void run(){ long mod = (1_000_000_000 + 7);  int n = nextInt();  int m = nextInt();  int[] t = new int[n];  int[] g = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = nextInt(); g[i] = (nextInt() - 1); } int k = (1 << n);  long[][] dp = new long[k][n]; for ( int i = 0;(i < n);i++) {dp[(1 << i)][i] = 1; }for ( int mask = 0;(mask < k);mask++) {if ( (Integer.bitCount(mask) <= 1)) {continue;} for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) != 0)) {for ( int j = 0;(j < n);j++) {if ( (((mask & (1 << j)) == 0) || (g[i] == g[j]))) {continue;} dp[mask][i] = ((dp[mask][i] + dp[(mask ^ (1 << i))][j]) % mod); }} }} long ans = 0; for ( int mask = 0;(mask < k);mask++) { int sum = 0; for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) != 0)) {sum += t[i]; } }if ( (sum == m)) {for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) != 0)) {ans = ((ans + dp[mask][i]) % mod); } }} }println(ans); } String next(){ while(!tokenizer.hasMoreTokens())tokenizer = new StringTokenizer(nextLine()); return tokenizer.nextToken();} boolean hasNext(){ while(!tokenizer.hasMoreTokens()){ String line = nextLine(); if ( (line == null)) {return false;} tokenizer = new StringTokenizer(line); }return true;} int nextInt(){ return Integer.parseInt(next());} long nextLong(){ return Long.parseLong(next());} String nextLine(){ try{return reader.readLine(); }catch (IOException err){ return null;} } public G( OutputStream outputStream){ super(outputStream); } static BufferedReader reader ; static StringTokenizer tokenizer = new StringTokenizer(""); static Random rnd = new Random(); static boolean OJ ; public static void main( String[] args)throws IOException { OJ = (System.getProperty("ONLINE_JUDGE") != null); G solution = new G(System.out); if ( OJ) {reader = new BufferedReader(new InputStreamReader(System.in)); solution.run(); } else {reader = new BufferedReader(new FileReader(new File((G.class.getName() + ".txt")))); long timeout = System.currentTimeMillis(); while(solution.hasNext()){solution.run(); solution.println(); solution.println("----------------------------------"); }solution.println(("time: " + (System.currentTimeMillis() - timeout))); }solution.close(); reader.close(); } }
5	public class Main{ public static void main( String[] args)throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(r.readLine());  String[] line = r.readLine().split("[ ]+");  int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = Integer.parseInt(line[i]); Arrays.sort(a); boolean found = false; for ( int i = 0;((i < n) && !found);i++) if ( (a[i] != 1)) found = true; if ( found) {System.out.println(1); for ( int i = 1;(i < n);i++) System.out.println(a[(i - 1)]); } else {for ( int i = 0;(i < (n - 1));i++) System.out.println(1); System.out.println(2); }} }
6	public class F{ 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 M = Integer.parseInt(st.nextToken());  int[][] grid = new int[N][M]; for ( int i = 0;(i < N);i++) grid[i] = readArr(M,infile,st); int[][] mindiff = new int[N][N]; for ( int a = 0;(a < N);a++) for ( int b = (a + 1);(b < N);b++) { int val = Integer.MAX_VALUE; for ( int i = 0;(i < M);i++) val = Math.min(val,Math.abs((grid[a][i] - grid[b][i]))); mindiff[a][b] = mindiff[b][a] = val; } int res = 0; for ( int start = 0;(start < N);start++) { int[][] dp = new int[(1 << N)][N]; Arrays.fill(dp[0],Integer.MAX_VALUE); for ( int mask = 0;(mask < (1 << N));mask++) {if ( ((Integer.bitCount(mask) == 1) && (mask != (1 << start)))) continue; for ( int prev = 0;(prev < N);prev++) if ( (((mask & (1 << prev)) > 0) || (mask == 0))) {for ( int b = 0;(b < N);b++) if ( ((mask & (1 << b)) == 0)) { int submask = (mask | (1 << b)); if ( (mask == 0)) dp[submask][b] = Integer.MAX_VALUE; else dp[submask][b] = Math.max(dp[submask][b],Math.min(dp[mask][prev],mindiff[prev][b])); } } }for ( int b = 0;(b < N);b++) { int temp = dp[((1 << N) - 1)][b]; for ( int i = 0;(i < (M - 1));i++) temp = Math.min(temp,Math.abs((grid[b][i] - grid[start][(i + 1)]))); res = Math.max(res,temp); }}System.out.println(res); } public static int[] readArr( int N, BufferedReader infile, StringTokenizer st)throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for ( int i = 0;(i < N);i++) arr[i] = Integer.parseInt(st.nextToken()); return arr;} }
3	public class C{ static StringTokenizer st ; static BufferedReader br ; static PrintWriter pw ; public static void main( String[] args)throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n = nextInt();  int[] dp1 = new int[(n + 1)];  int[] dp2 = new int[(n + 1)]; dp1[1] = 1; int mod = (int)(1e9 + 7);  char[] instruction = new char[(n + 1)]; instruction[0] = 's'; int[] sum = new int[(n + 1)]; for ( int i = 1;(i <= n);i++) {instruction[i] = next().charAt(0); for ( int j = 1;(j <= i);j++) {sum[j] = (sum[(j - 1)] + dp1[j]); if ( (sum[j] >= mod)) sum[j] -= mod; }for ( int j = 1;(j <= i);j++) {if ( (instruction[(i - 1)] == 'f')) dp2[j] = dp1[(j - 1)]; else {dp2[j] = (sum[i] - sum[(j - 1)]); if ( (dp2[j] < 0)) dp2[j] += mod; }}for ( int j = 1;(j <= i);j++) {dp1[j] = dp2[j]; }} int ans = 0; for ( int i = 1;(i <= n);i++) {ans += dp1[i]; if ( (ans >= mod)) ans -= mod; }System.out.println(ans); pw.close(); } static private int nextInt()throws IOException { return Integer.parseInt(next());} static private String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} }
6	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);  G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion(); solver.solve(1,in,out); out.close(); } static class G1PlaylistForPolycarpEasyVersion{ long mod = ((int)1e9 + 7); public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.nextInt();  int T = in.nextInt();  int[] t = new int[n];  int[] g = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = in.nextInt(); g[i] = in.nextInt(); } long[] fact = new long[(n + 1)]; fact[0] = 1; for ( int i = 1;(i <= n);i++) {fact[i] = ((fact[(i - 1)] * i) % mod); } ArrayList<Integer> masks = new ArrayList<>();  long val = 0; for ( int i = 1;(i < (1 << n));i++) { int time = 0;  int[] count = new int[3]; for ( int j = 0;(j < n);j++) {if ( ((i & (1 << j)) != 0)) {time += t[j]; count[(g[j] - 1)]++; } }if ( (time == T)) {masks.add(i); Arrays.sort(count); long v = ((((fact[count[0]] * fact[count[1]]) % mod) * fact[count[2]]) % mod); val += ((countUtil(count[0],count[1],count[2]) * v) % mod); } }out.println((val % mod)); } long countWays( int p, int q, int r, int last){ if ( (((p < 0) || (q < 0)) || (r < 0))) return 0; if ( ((((p == 1) && (q == 0)) && (r == 0)) && (last == 0))) return 1; if ( ((((p == 0) && (q == 1)) && (r == 0)) && (last == 1))) return 1; if ( ((((p == 0) && (q == 0)) && (r == 1)) && (last == 2))) return 1; if ( (last == 0)) return ((countWays((p - 1),q,r,1) + countWays((p - 1),q,r,2)) % mod); if ( (last == 1)) return ((countWays(p,(q - 1),r,0) + countWays(p,(q - 1),r,2)) % mod); if ( (last == 2)) return ((countWays(p,q,(r - 1),0) + countWays(p,q,(r - 1),1)) % mod); return 0;} long countUtil( int p, int q, int r){ return ((((countWays(p,q,r,0) + countWays(p,q,r,1)) % mod) + countWays(p,q,r,2)) % mod);} } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } }
5	public class A implements Runnable{ public static void main( String[] args)throws IOException { new Thread(null,new A(),"",(1 << 20)).start(); } String file = "input"; BufferedReader input ; PrintWriter out ; int N ,T ; void solve()throws IOException { StringTokenizer st = tokens(); N = nextInt(st); T = nextInt(st); T *= 2; ArrayList<Pair> list = new ArrayList<Pair>(); for ( int i = 0;(i < N);i++) {st = tokens(); int c = nextInt(st),L = nextInt(st); c *= 2; L *= 2; list.add(new Pair((c - (L / 2)),(c + (L / 2)))); }Collections.sort(list); HashSet<Integer> set = new HashSet<Integer>(); for ( int i = 0;(i < list.size());i++) {if ( ((i == 0) || ((list.get(i).x - list.get((i - 1)).y) >= T))) {set.add((list.get(i).x - (T / 2))); } if ( ((i == (list.size() - 1)) || ((list.get((i + 1)).x - list.get(i).y) >= T))) {set.add((list.get(i).y + (T / 2))); } }System.out.println(set.size()); } class Pair implements Comparable<Pair>{ int x ,y ; public Pair( int x, int y){ this.x = x; this.y = y; } } StringTokenizer tokens()throws IOException { return new StringTokenizer(input.readLine());} int nextInt()throws IOException { return Integer.parseInt(input.readLine());} int nextInt( StringTokenizer st){ return Integer.parseInt(st.nextToken());} }
5	public class A{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int t = (in.nextInt() * 2);  Point[] A = new Point[n]; for ( int i = 0;(i < n);i++) { int center = (in.nextInt() * 2);  int side = in.nextInt(); A[i] = new Point((center - side),(center + side)); }Arrays.sort(A,new Comparator<Point>(){}); int ans = 2; for ( int i = 1;(i < n);i++) {if ( ((A[i].x - A[(i - 1)].y) > t)) ans += 2; else if ( ((A[i].x - A[(i - 1)].y) == t)) ans++; }System.out.println(ans); } }
4	public class P035C{ private class Pair{ private int x ; private int y ; private Pair( int x, int y){ this.x = x; this.y = y; } } private boolean[][] visited ; private final int N ; private final int M ; private final int k ; private ArrayList<Pair> fires = new ArrayList<Pair>(); private ArrayList<Pair> neighbors = new ArrayList<Pair>(); public P035C()throws IOException{ Scanner sc = new Scanner(new File("input.txt")); N = sc.nextInt(); M = sc.nextInt(); visited = new boolean[N][M]; k = sc.nextInt(); for ( int i = 0;(i < k);i++) { int x = (sc.nextInt() - 1);  int y = (sc.nextInt() - 1); fires.add(new Pair(x,y)); }bfs(); } private void bfs()throws IOException { java.util.Queue<Pair> queue = new ArrayDeque<Pair>(); for ( Pair p :fires) {queue.add(p); visited[p.x][p.y] = true; } Pair last = fires.get(0); while(!queue.isEmpty()){ Pair p = last = queue.poll(); for ( Pair pn :getNeighbors(p)) {if ( !visited[pn.x][pn.y]) {queue.add(pn); visited[pn.x][pn.y] = true; } }} PrintWriter output = new PrintWriter(new FileWriter(new File("output.txt"))); output.printf("%d %d\n",(last.x + 1),(last.y + 1)); output.close(); } private Collection<Pair> getNeighbors( Pair p){ neighbors.clear(); if ( (p.x > 0)) neighbors.add(new Pair((p.x - 1),p.y)); if ( (p.x < (N - 1))) neighbors.add(new Pair((p.x + 1),p.y)); if ( (p.y > 0)) neighbors.add(new Pair(p.x,(p.y - 1))); if ( (p.y < (M - 1))) neighbors.add(new Pair(p.x,(p.y + 1))); return neighbors;} public static void main( String[] args)throws IOException { P035C solution = new P035C(); } }
3	public class init{ static int mod = 1000000007; 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++) { char c = s.next().charAt(0); if ( (c == 'f')) a[i] = 1; } int dp[][] = new int[(n + 1)][(n + 1)]; for ( int i = 0;(i <= n);i++) {for ( int j = 0;(j <= n);j++) dp[i][j] = -1; }System.out.println(ans(dp,1,0,a,n)); } public static int ans( int[][] dp, int i, int j, int[] a, int n){ if ( (i == n)) {return 1;} if ( (dp[i][j] != -1)) {return dp[i][j];} if ( (a[(i - 1)] == 1)) { int x = ans(dp,(i + 1),(j + 1),a,n); if ( (x != -1)) dp[i][j] = (x % mod); } else { int x = -1; if ( (j != 0)) x = ans(dp,i,(j - 1),a,n);  int y = ans(dp,(i + 1),j,a,n); if ( (x != -1)) dp[i][j] = (x % mod); if ( (y != -1)) {if ( (dp[i][j] == -1)) dp[i][j] = (y % mod); else dp[i][j] += (y % mod); } }return dp[i][j];} }
4	@SuppressWarnings("unchecked") public class P35C{ static final int[] DX = {-1,1,0,0}; static final int[] DY = {0,0,-1,1}; public void run()throws Exception { int m = nextInt();  int n = nextInt();  boolean[][] burned = new boolean[n][m];  List<Integer> burn = new ArrayList(); for ( int k = nextInt();(k > 0);k--) { int x = (nextInt() - 1);  int y = (nextInt() - 1); burned[y][x] = true; burn.add(((x * 10000) + y)); } int lastXY = 0;  List<Integer> newBurn = null; do {lastXY = burn.get(0); newBurn = new ArrayList(); for ( int xy :burn) { int x = (xy / 10000);  int y = (xy % 10000); for ( int i = 0;(i < 4);i++) { int nx = (x + DX[i]);  int ny = (y + DY[i]); if ( (((((ny >= 0) && (ny < n)) && (nx >= 0)) && (nx < m)) && burned)) {burned[ny][nx] = true; newBurn.add(((nx * 10000) + ny)); } }}burn = newBurn; }while((newBurn.size() > 0));println(((((lastXY / 10000) + 1) + " ") + ((lastXY % 10000) + 1))); } public static void main( String... args)throws Exception { br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream("output.txt"))); new P35C().run(); br.close(); pw.close(); System.err.println((("\n[Time : " + (System.currentTimeMillis() - startTime)) + " ms]")); } static long startTime = System.currentTimeMillis(); static BufferedReader br ; static PrintWriter pw ; StringTokenizer stok ; String nextToken()throws IOException { while(((stok == null) || !stok.hasMoreTokens())){ String s = br.readLine(); if ( (s == null)) {return null;} stok = new StringTokenizer(s); }return stok.nextToken();} void print( byte b){ print(("" + b)); } void print( int i){ print(("" + i)); } void print( long l){ print(("" + l)); } void print( double d){ print(("" + d)); } void print( char c){ print(("" + c)); } void print( Object o){ if ( (o instanceof int[])) {print(Arrays.toString((int[])o)); } else if ( (o instanceof long[])) {print(Arrays.toString((long[])o)); } else if ( (o instanceof char[])) {print(Arrays.toString((char[])o)); } else if ( (o instanceof byte[])) {print(Arrays.toString((byte[])o)); } else if ( (o instanceof short[])) {print(Arrays.toString((short[])o)); } else if ( (o instanceof boolean[])) {print(Arrays.toString((boolean[])o)); } else if ( (o instanceof float[])) {print(Arrays.toString((float[])o)); } else if ( (o instanceof double[])) {print(Arrays.toString((double[])o)); } else if ( (o instanceof Object[])) {print(Arrays.toString((Object[])o)); } else {print(("" + o)); }} void print( String s){ pw.print(s); } void println(){ println(""); } void println( byte b){ println(("" + b)); } void println( int i){ println(("" + i)); } void println( long l){ println(("" + l)); } void println( double d){ println(("" + d)); } void println( char c){ println(("" + c)); } void println( Object o){ print(o); println(); } void println( String s){ pw.println(s); } int nextInt()throws IOException { return Integer.parseInt(nextToken());} long nextLong()throws IOException { return Long.parseLong(nextToken());} double nextDouble()throws IOException { return Double.parseDouble(nextToken());} String nextLine()throws IOException { return br.readLine();} }
1	public class Main{ public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); do { int n = Integer.parseInt(br.readLine());  int[] ns = new int[args = br.readLine().split(" ")];  int evenCount = 0,oddCount = 0,evI = 1,oddI = 1; for ( int i = 0;(i < ns.length);i++) {if ( (((ns[i] = Integer.parseInt(args[i])) % 2) == 0)) {evenCount++; evI = i; } else {oddCount++; oddI = i; }}if ( (evenCount == 1)) System.out.println((evI + 1)); else System.out.println((oddI + 1)); }while(br.ready());} }
6	public class F{ static Scanner in = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); static int n ,m ,res = 0; static int[][] a = new int[20][10005],Min = new int[20][20],Min1 = new int[20][20]; static int[][][] f = new int[(1 << 16)][20][20]; static int GetBit( int x, int k){ return ((x >> k) & 1);} static int TurnBit( int x, int k){ return (x ^ (1 << k));} public static void main( String[] args){ n = in.nextInt(); m = in.nextInt(); for ( int i = 0;(i < n);i++) for ( int j = 1;(j <= m);j++) a[i][j] = in.nextInt(); if ( (n == 1)) {res = (int)1e9; for ( int i = 1;(i < m);i++) res = Math.min(res,Math.abs((a[0][i] - a[0][(i + 1)]))); out.print(res); out.close(); return ;} for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) {Min[i][j] = Min1[i][j] = (int)1e9; for ( int t = 1;(t <= m);t++) Min[i][j] = Math.min(Min[i][j],Math.abs((a[i][t] - a[j][t]))); for ( int t = 1;(t < m);t++) Min1[i][j] = Math.min(Min1[i][j],Math.abs((a[i][t] - a[j][(t + 1)]))); }for ( int i = 0;(i < n);i++) f[(1 << i)][i][i] = (int)1e9; for ( int mask = 0;(mask < (1 << n));mask++) if ( (Integer.bitCount(mask) > 1)) for ( int i = 0;(i < n);i++) if ( (GetBit(mask,i) == 1)) for ( int j = 0;(j < n);j++) if ( ((i != j) && (GetBit(mask,j) == 1))) {for ( int t = 0;(t < n);t++) if ( ((j != t) && (GetBit(mask,t) == 1))) f[mask][i][j] = Math.max(f[mask][i][j],Math.min(f[TurnBit(mask,j)][i][t],Min[j][t])); if ( (mask == ((1 << n) - 1))) res = Math.max(res,Math.min(f[mask][i][j],Min1[j][i])); }  out.print(res); out.close(); } }
6	public class cf1102f{ public static void main( String[] args)throws IOException { int n = rni(),m = ni(),a[][] = new int[n][]; for ( int i = 0;(i < n);++i) {a[i] = ria(m); } int delta[][] = new int[n][n],end_delta[][] = new int[n][n],dp[][][] = new int[n][(1 << n)][n]; for ( int i = 0;(i < n);++i) {fill(delta[i],IBIG); fill(end_delta[i],IBIG); delta[i][i] = 0; }for ( int i = 0;(i < (n - 1));++i) {for ( int j = (i + 1);(j < n);++j) {for ( int k = 0;(k < m);++k) {delta[i][j] = delta[j][i] = min(delta[i][j],abs((a[i][k] - a[j][k]))); }}}for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < n);++j) {for ( int k = 1;(k < m);++k) {end_delta[i][j] = min(end_delta[i][j],abs((a[j][k] - a[i][(k - 1)]))); }}}for ( int[][] layer :dp) {for ( int[] row :layer) {fill(row,IBIG); }}for ( int i = 1;(i < (1 << n));++i) { boolean one_bit = (Integer.bitCount(i) == 1); for ( int j = 0;(j < n);++j) {if ( ((i & (1 << j)) > 0)) {for ( int l = 0;(l < n);++l) {if ( ((i & (1 << l)) == 0)) { int max = 0; for ( int k = 0;(k < n);++k) {if ( ((one_bit || (j != k)) && ((i & (1 << k)) > 0))) {max = max(max,min(dp[j][i][k],delta[k][l])); } }dp[j][(i | (1 << l))][l] = max; } }} }} int ans = 0; for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < n);++j) {if ( (i != j)) {ans = max(ans,min(dp[i][((1 << n) - 1)][j],end_delta[j][i])); } }}if ( (n == 1)) {ans = maxof(end_delta[0]); } prln(ans); close(); } static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input ; static Random __rand = new Random(); static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final int IMIN = -2147483648; static final long LMAX = 9223372036854775807L; static final long LMIN = -9223372036854775808L; static int maxof( int a, int b, int c){ return max(a,max(b,c));} static int maxof( int... x){ if ( (x.length == 1)) return x[0]; if ( (x.length == 2)) return max(x[0],x[1]); if ( (x.length == 3)) return max(x[0],max(x[1],x[2])); int max = x[0]; for ( int i = 1;(i < x.length);++i) if ( (x[i] > max)) max = x[i]; return max;} static long maxof( long a, long b, long c){ return max(a,max(b,c));} static long maxof( long... x){ if ( (x.length == 1)) return x[0]; if ( (x.length == 2)) return max(x[0],x[1]); if ( (x.length == 3)) return max(x[0],max(x[1],x[2])); long max = x[0]; for ( int i = 1;(i < x.length);++i) if ( (x[i] > max)) max = x[i]; return max;} static int gcf( int a, int b){ return ((b == 0)?a:gcf(b,(a % b)));} static long gcf( long a, long b){ return ((b == 0)?a:gcf(b,(a % b)));} static int randInt( int min, int max){ return (__rand.nextInt(((max - min) + 1)) + min);} static void shuffle( int[] a){ int n = (a.length - 1); for ( int i = 0;(i < n);++i) { int ind = randInt(i,n);  int swap = a[i]; a[i] = a[ind]; a[ind] = swap; }} static void shuffle( long[] a){ int n = (a.length - 1); for ( int i = 0;(i < n);++i) { int ind = randInt(i,n);  long swap = a[i]; a[i] = a[ind]; a[ind] = swap; }} static void shuffle( double[] a){ int n = (a.length - 1); for ( int i = 0;(i < n);++i) { int ind = randInt(i,n);  double swap = a[i]; a[i] = a[ind]; a[ind] = swap; }} static void r()throws IOException { input = new StringTokenizer(rline()); } static int[] ria( int n)throws IOException { int[] a = new int[n]; r(); for ( int i = 0;(i < n);++i) a[i] = ni(); return a;} static String rline()throws IOException { return __in.readLine();} static String n(){ return input.nextToken();} static int rni()throws IOException { r(); return ni();} static int ni(){ return Integer.parseInt(n());} static long nl(){ return Long.parseLong(n());} static double nd(){ return Double.parseDouble(n());} static void pr( int i){ __out.print(i); } static void prln( int i){ __out.println(i); } static void pr( long l){ __out.print(l); } static void prln( long l){ __out.println(l); } static void pr( double d){ __out.print(d); } static void prln( double d){ __out.println(d); } static void pr( char c){ __out.print(c); } static void prln( char c){ __out.println(c); } static void pr( char[] s){ __out.print(new String(s)); } static void prln( char[] s){ __out.println(new String(s)); } static void pr( String s){ __out.print(s); } static void prln( String s){ __out.println(s); } static void pr( Object o){ __out.print(o); } static void prln( Object o){ __out.println(o); } static void prln(){ __out.println(); } static void prln( int... a){ for ( int i = 0,len = (a.length - 1);(i < len);pr(a[i]),pr(' '),++i) ;if ( (a.length > 0)) prln(a[(a.length - 1)]); else prln(); } static void prln( long... a){ for ( int i = 0,len = (a.length - 1);(i < len);pr(a[i]),pr(' '),++i) ;if ( (a.length > 0)) prln(a[(a.length - 1)]); else prln(); } static void prln( double... a){ for ( int i = 0,len = (a.length - 1);(i < len);pr(a[i]),pr(' '),++i) ;if ( (a.length > 0)) prln(a[(a.length - 1)]); else prln(); } static <T> void prln( Collection<T> c){ int n = (c.size() - 1);  Iterator<T> iter = c.iterator(); for ( int i = 0;(i < n);pr(iter.next()),pr(' '),++i) ;if ( (n >= 0)) prln(iter.next()); else prln(); } static void flush(){ __out.flush(); } static void close(){ __out.close(); } }
1	public class HamstersAndTigers{ Scanner in ; PrintWriter out ; HamstersAndTigers(){ in = new Scanner(System.in); out = new PrintWriter(System.out); } HamstersAndTigers( String i, String o)throws FileNotFoundException{ in = new Scanner(new File(i)); out = new PrintWriter(new File(o)); } public void finalize(){ out.flush(); in.close(); out.close(); } void solve(){ int i = 0,h = 0,n = in.nextInt();  String buf = "";  char[] ht = in.next().toCharArray(); for ( i = 0;(i < n);++i) if ( (ht[i] == 'H')) ++h; for ( i = 0;(i < h);++i) buf += 'H'; for ( i = 0;(i < (n - h));++i) buf += 'T'; int diff = (1 << 28); for ( i = 0;(i < n);++i) { int tmp = 0; for ( int j = 0;(j < n);++j) if ( (buf.charAt(j) != ht[((i + j) % n)])) ++tmp; diff = Math.min(tmp,diff); }out.println((diff / 2)); } public static void main( String[] args)throws FileNotFoundException { HamstersAndTigers t = new HamstersAndTigers(); t.solve(); t.finalize(); } }
0	public class Main{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int x = scan.nextInt(); solve(x); } public static void solve( int x){ int z = 0; System.out.print((z + " ")); System.out.print((z + " ")); System.out.print(x); } }
1	public class Main{ public static void main( String[] args)throws NumberFormatException,IOException { Scanner sc = new Scanner(new InputStreamReader(System.in));  int n = sc.nextInt(),even = 0,odd = 0,evI = 0,OdI = 0; for ( int i = 0;(i < n);i++) {if ( ((sc.nextInt() % 2) == 1)) {odd++; OdI = (i + 1); } else {even++; evI = (i + 1); }}if ( (even < odd)) System.out.println(evI); else System.out.println(OdI); } }
2	public class Main implements Runnable{ private BufferedReader br ; private StringTokenizer tok ; private PrintWriter out ; static final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); int[] a ; int[] b ; int[] p ; int getCeils( int id, int step){ if ( (step > ((a[id] + b[id]) - 1))) {return 0;} if ( (a[id] < b[id])) {if ( (step < a[id])) {return step;} if ( ((step >= a[id]) && (step <= b[id]))) {return a[id];} ++p[id]; return (a[id] - p[id]);} else {if ( (step < b[id])) {return step;} if ( ((step >= b[id]) && (step <= a[id]))) {return b[id];} ++p[id]; return (b[id] - p[id]);}} void solve()throws IOException { int n = nextInt(),x = nextInt(),y = nextInt(),c = nextInt();  long s = 1;  int step = 0; a = new int[4]; b = new int[4]; p = new int[4]; a[0] = (x - 1); b[0] = (n - y); a[1] = (x - 1); b[1] = (y - 1); a[2] = (n - x); b[2] = (y - 1); a[3] = (n - x); b[3] = (n - y); int xf = (x + 1),xb = (x - 1),yf = (y + 1),yb = (y - 1); while((s < c)){++step; if ( (xf <= n)) {++s; ++xf; } if ( (xb > 0)) {++s; --xb; } if ( (yf <= n)) {++s; ++yf; } if ( (yb > 0)) {++s; --yb; } if ( (step == 1)) {continue;} for ( int i = 0;(i < 4);++i) {s += getCeils(i,(step - 1)); }}out.println(step); } public void run(){ try{if ( ONLINE_JUDGE) {br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else {br = new BufferedReader(new FileReader(new File("input.txt"))); out = new PrintWriter(new File("output.txt")); }solve(); br.close(); out.close(); }catch (IOException e){ e.printStackTrace(); System.exit(1); } } public static void main( String[] args){ new Main().run(); } String nextToken()throws IOException { while(((tok == null) || !tok.hasMoreTokens()))tok = new StringTokenizer(br.readLine()); return tok.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
1	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 < n);i++) a[i] = sc.nextInt(); Arrays.sort(a); int t = 1,c = 0; for ( int i = 1;(i < n);i++) {if ( (a[i] == a[(i - 1)])) {if ( (((i - 2) >= 0) && (a[(i - 2)] == (a[(i - 1)] - 1)))) {System.out.println("cslnb"); return ;} c++; } if ( ((a[i] == a[(i - 1)]) && (a[i] == 0))) {System.out.println("cslnb"); return ;} }if ( (c > 1)) {System.out.println("cslnb"); return ;} for ( int i = 0;(i < n);i++) {if ( (((a[i] - i) % 2) != 0)) t = (t ^ 1); }if ( (t == 1)) System.out.println("cslnb"); else System.out.println("sjfnb"); } }
1	public class Main{ public static void main( String[] args){ ConsoleIO io = new ConsoleIO(); new Main(io).solve(); io.close(); } ConsoleIO io ; Main( ConsoleIO io){ this.io = io; } ArrayList<ArrayList<Integer>> gr ; boolean[] visit ; long MOD = 1_000_000_007; int N ,M ,K ; double[][] map ; public void solve(){ String s = io.readLine(); N = Integer.parseInt(s); char[] a = io.readLine().toCharArray();  int[] look = new int[256]; Arrays.fill(look,10000); int k = 0; for ( int i = 0;(i < a.length);i++) {if ( (look[a[i]] == 10000)) {look[a[i]] = k; k++; } } int res = N;  long need = ((1L << k) - 1);  long mask = 0;  int head = 0;  int tail = 0;  int[] c = new int[k]; while((head < a.length)){while(((head < a.length) && (mask != need))){ int v = look[a[head]]; if ( (c[v] == 0)) mask |= (1L << v); c[v]++; head++; }while(((tail < head) && (mask == need))){res = Math.min(res,(head - tail)); int v = look[a[tail]]; c[v]--; if ( (c[v] == 0)) mask ^= (1L << v); tail++; }}io.writeLine((res + "")); } long gcd( long a, long b){ if ( (a < b)) return gcd(b,a); if ( (b == 0)) return a; return gcd(b,(a % b));} } class ConsoleIO{ BufferedReader br ; PrintWriter out ; public ConsoleIO(){ br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } public void flush(){ this.out.flush(); } public void close(){ this.out.close(); } public void writeLine( String s){ this.out.println(s); } public int read( char[] buf, int len){ try{return br.read(buf,0,len); }catch (Exception ex){ return -1;} } public String readLine(){ try{return br.readLine(); }catch (Exception ex){ return "";} } }
5	public class A{ static Comparator<Point> cmp = new Comparator<Point>(){}; public static void main( String[] args){ Scanner scan = new Scanner(System.in); while(scan.hasNextInt()){ int n = scan.nextInt();  int k = scan.nextInt();  Point[] a = new Point[n]; for ( int i = 0;(i < n);i++) {a[i] = new Point(); a[i].x = scan.nextInt(); a[i].y = scan.nextInt(); }Arrays.sort(a,cmp); int rtn = 0;  ArrayList<Double> ans = new ArrayList<Double>(); for ( int i = 0;(i < n);i++) { double lb = ((a[i].x - (a[i].y / 2.0)) - k);  double pos = (lb + (k / 2.0));  boolean good = true; for ( int j = 0;(j < ans.size());j++) if ( (Math.abs((ans.get(j) - pos)) < 0.0000001)) good = false; if ( (good && ((i == 0) || ((a[(i - 1)].x + (a[(i - 1)].y / 2.0)) <= lb)))) {rtn++; ans.add(pos); } double rb = ((a[i].x + (a[i].y / 2.0)) + k); pos = (rb - (k / 2.0)); good = true; for ( int j = 0;(j < ans.size());j++) if ( (Math.abs((ans.get(j) - pos)) < 0.0000001)) good = false; if ( (good && ((i == (n - 1)) || ((a[(i + 1)].x - (a[(i + 1)].y / 2.0)) >= rb)))) {rtn++; ans.add(pos); } }System.out.println(rtn); }} }
5	public class Main{ BufferedReader reader ; FastScanner sc ; void solve()throws Exception { int n = sc.nextInt();  int[] arr = new int[n]; for ( int i = 0;(i < n);i++) {arr[i] = sc.nextInt(); }Arrays.sort(arr); if ( (arr[(n - 1)] == 1)) arr[(n - 1)] = 2; else arr[(n - 1)] = 1; Arrays.sort(arr); for ( int i = 0;(i < n);i++) {System.out.print((arr[i] + " ")); }System.out.println(); } public static void main( String[] args)throws Exception { new Main().solve(); } Main()throws Exception{ if ( (System.getProperty("ONLINE_JUDGE") == null)) {} reader = new BufferedReader(new InputStreamReader(System.in)); sc = new FastScanner(reader); } } class FastScanner{ BufferedReader reader ; StringTokenizer strTok ; public FastScanner( BufferedReader reader){ this.reader = reader; } public String nextToken()throws IOException { if ( ((strTok == null) || !strTok.hasMoreTokens())) {strTok = new StringTokenizer(reader.readLine()); } return strTok.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
0	public class JavaApplication2{ public static void main( String[] args){ Scanner s = new Scanner(System.in);  int n ; n = s.nextInt(); System.out.print(((n + " ") + "0 0")); } }
3	public class A{ InputStream is ; PrintWriter out ; String INPUT = ""; public void solve(){ int n = ni();  char[] arr = new char[n]; for ( int i = 0;(i < n);i++) {arr[i] = ns().charAt(0); } long mod = 1000000007;  long[][] memo = new long[n][n]; memo[0][0] = 1L; int k = 0; for ( int i = 1;(i < n);i++) {if ( (((arr[i] == 'f') && (arr[(i - 1)] == 's')) || ((arr[i] == 's') && (arr[(i - 1)] == 's')))) { long sum = 0; for ( int j = k;(j >= 0);j--) {sum = ((sum + (memo[(i - 1)][j] % mod)) % mod); memo[i][j] = sum; }} else {k += 1; for ( int j = 1;(j <= k);j++) {memo[i][j] = (memo[(i - 1)][(j - 1)] % mod); }}} long sum = 0; for ( int i = 0;(i <= k);i++) {sum = ((sum + (memo % mod)) % mod); }out.println(sum); } void print( int n, long[][] memo){ for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {out.print((memo[i][j] + " ")); }out.println(); }} void run(){ is = new DataInputStream(System.in); out = new PrintWriter(System.out); int t = 1; while((t-- > 0))solve(); out.flush(); } public static void main( String[] args)throws Exception { new A().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0,ptrbuf = 0; 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++];} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private int ni(){ 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(); }} static int i( long x){ return (int)Math.round(x);} }
5	public class A implements Runnable{ public static void main( String[] args){ new A().run(); } class FastScanner{ BufferedReader br ; StringTokenizer st ; boolean eof ; String buf ; public FastScanner( String fileName)throws FileNotFoundException{ br = new BufferedReader(new FileReader(fileName)); nextToken(); } public FastScanner( InputStream stream){ br = new BufferedReader(new InputStreamReader(stream)); nextToken(); } String nextToken(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ eof = true; break;} } String ret = buf; buf = (eof?"-1":st.nextToken()); return ret;} int nextInt(){ return Integer.parseInt(nextToken());} long nextLong(){ return Long.parseLong(nextToken());} double nextDouble(){ return Double.parseDouble(nextToken());} void close(){ try{br.close(); }catch (Exception e){ } } } FastScanner sc ; PrintWriter out ; public void run(){ Locale.setDefault(Locale.US); try{sc = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); sc.close(); out.close(); }catch (Throwable e){ e.printStackTrace(); System.exit(1); } } int nextInt(){ return sc.nextInt();} String nextToken(){ return sc.nextToken();} long nextLong(){ return sc.nextLong();} double nextDouble(){ return sc.nextDouble();} class House{ int x ,t ; public House( int x, int t){ this.x = x; this.t = t; } } void solve(){ int n = nextInt();  int t = nextInt();  House[] h = new House[n]; for ( int i = 0;(i < n);i++) {h[i] = new House(nextInt(),nextInt()); }Arrays.sort(h,new Comparator<House>(){}); int ans = 0; for ( int i = 0;(i < n);i++) {if ( ((i == 0) || (((((h[i].x - h[(i - 1)].x) * 2) - h[i].t) - h[(i - 1)].t) >= (2 * t)))) {++ans; } if ( ((i == (n - 1)) || (((((h[(i + 1)].x - h[i].x) * 2) - h[(i + 1)].t) - h[i].t) > (2 * t)))) {++ans; } }out.println(ans); } }
6	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]; static int n ,m ; static void solve(){ n = in.nextInt(); m = in.nextInt(); int[][] a = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) a[i][j] = in.nextInt(); for ( int i = 0;(i < n);i++) {Arrays.fill(mn1[i],Integer.MAX_VALUE); Arrays.fill(mn2[i],Integer.MAX_VALUE); }for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) for ( int k = 0;(k < m);k++) {mn1[i][j] = Math.min(mn1[i][j],Math.abs((a[i][k] - a[j][k]))); if ( (k <= (m - 2))) mn2[i][j] = Math.min(mn2[i][j],Math.abs((a[i][k] - a[j][(k + 1)]))); } int ans = 0; for ( int i = 0;(i < n);i++) {for ( int x = 0;(x < (1 << n));x++) Arrays.fill(dp[x],-1); for ( int j = 0;(j < n);j++) dp[(1 << j)][j] = 0; dp[(1 << i)][i] = Integer.MAX_VALUE; for ( int j = 0;(j < n);j++) ans = Math.max(ans,Math.min(mn2[j][i],calc(((1 << n) - 1),j))); }out.println(ans); } static int calc( int mask, int v){ if ( (dp[mask][v] != -1)) return dp[mask][v]; dp[mask][v] = 0; for ( int u = 0;(u < n);u++) if ( ((v != u) && (((mask >> u) & 1) > 0))) dp[mask][v] = Math.max(dp[mask][v],Math.min(mn1[u][v],calc((mask ^ (1 << v)),u))); return dp[mask][v];} public static void main( String[] args){ solve(); out.close(); } static class FastReader{ BufferedReader br ; StringTokenizer st ; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader( String s)throws Exception{ br = new BufferedReader(new FileReader(s)); } 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(in.next());} } }
6	public class f{ 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[][] arr = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {arr[i][j] = sc.nextInt(); }}if ( (n == 1)) { int min = Integer.MAX_VALUE; for ( int i = 0;(i < (m - 1));i++) {min = Math.min(min,Math.abs((arr[0][i] - arr[0][(i + 1)]))); }out.println(min); out.close(); } int[][] adj = new int[n][n];  int[][] edgeadj = new int[n][n]; for ( int i = 0;(i < n);i++) {for ( int j = (i + 1);(j < n);j++) { int min = Integer.MAX_VALUE; for ( int k = 0;(k < m);k++) {min = Math.min(min,Math.abs((arr[i][k] - arr[j][k]))); }adj[i][j] = min; adj[j][i] = min; int min1 = Integer.MAX_VALUE;  int min2 = Integer.MAX_VALUE; for ( int k = 0;(k < (m - 1));k++) {min1 = Math.min(min1,Math.abs((arr[i][k] - arr[j][(k + 1)]))); min2 = Math.min(min2,Math.abs((arr[i][(k + 1)] - arr[j][k]))); }edgeadj[i][j] = min1; edgeadj[j][i] = min2; }} int power = (int)Math.pow(2,n);  int[][][] dp = new int[power][n][n]; for ( int i = 0;(i < n);i++) {dp[(int)Math.pow(2,i)][i][i] = Integer.MAX_VALUE; }for ( int bit = 0;(bit < power);bit++) {for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < n);k++) {if ( ((((bit & (1 << j)) > 0) && ((bit & (1 << k)) > 0)) && (j != k))) { int temp = bit; temp &= (1 << k); int ans = 0; for ( int l = 0;(l < n);l++) {if ( ((temp & (1 << l)) > 0)) { int min = Math.min(dp[temp][j][l],adj[l][k]); ans = Math.max(ans,min); } }if ( (j != k)) {dp[bit][j][k] = ans; } } }}} int answer = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( (i != j)) { int ans = Math.min(dp[(power - 1)][i][j],edgeadj[i][j]); answer = Math.max(answer,ans); } }}out.println(answer); 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());} } }
6	public class Main{ void pre()throws Exception { } int n ,t ; void solve( int TC)throws Exception { n = ni(); t = ni(); int[][] song = new int[n][]; for ( int i = 0;(i < n);i++) song[i] = new int[]{ni(),(ni() - 1)}; long[][] dp = new long[(1 << n)][3]; for ( int i = 0;(i < dp.length);i++) for ( int j = 0;(j < dp[i].length);j++) dp[i][j] = -1; pn(start(dp,song,0,-1)); } long start( long[][] dp, int[][] song, int mask, int prev){ long ti = 0; for ( int i = 0;(i < n);i++) {if ( (((mask >> i) & 1) == 1)) ti += song[i][0]; }if ( (ti == t)) return 1; if ( ((prev != -1) && (dp[mask][prev] != -1))) return dp[mask][prev]; long ans = 0; for ( int i = 0;(i < n);i++) {if ( (((((mask >> i) & 1) == 0) && (song[i][1] != prev)) && ((ti + song[i][0]) <= t))) ans = ((ans + start(dp,song,(mask | (1 << i)),song[i][1])) % mod); }if ( (prev != -1)) dp[mask][prev] = ans; return ans;} long mod = ((long)1e9 + 7),IINF = (long)1e18; final int INF = (int)1e9,MX = ((int)2e5 + 5); DecimalFormat df = new DecimalFormat("0.00000000000"); double PI = 3.141592653589793238462643383279502884197169399,eps = 1e-8; static boolean multipleTC = false,memory = false; FastReader in ; PrintWriter out ; void run()throws Exception { in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC?ni():1); pre(); for ( int t = 1;(t <= T);t++) solve(t); out.flush(); out.close(); } public static void main( String[] args)throws Exception { if ( memory) new Thread(null,new Runnable(){public void run(){ try{new Main().run(); }catch (Exception e){ e.printStackTrace(); } } },"1",(1 << 28)).start(); else new Main().run(); } long gcd( long a, long b){ return ((b == 0)?a:gcd(b,(a % b)));} int gcd( int a, int b){ return ((b == 0)?a:gcd(b,(a % b)));} int bit( long n){ return ((n == 0)?0:(1 + bit((n & (n - 1)))));} void pn( Object o){ out.println(o); } int ni()throws Exception { return Integer.parseInt(in.next());} class FastReader{ BufferedReader br ; StringTokenizer st ; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader( String s)throws Exception{ br = new BufferedReader(new FileReader(s)); } String next()throws Exception { while(((st == null) || !st.hasMoreElements())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ throw (new Exception(e.toString()));} }return st.nextToken();} String nextLine()throws Exception { String str = ""; try{str = br.readLine(); }catch (IOException e){ throw (new Exception(e.toString()));} return str;} } }
1	public class Main{ Scanner in ; PrintWriter out ; StreamTokenizer ST ; BufferedReader br ; void solve()throws IOException { br.readLine(); char[] s = br.readLine().toCharArray();  int n = s.length;  int h = 0; for ( int i = 0;(i < n);++i) if ( (s[i] == 'H')) ++h;  int res = 1000000; for ( int i = 0;(i < n);++i) { int t = 0; for ( int j = 0;(j < h);++j) {if ( (s[((i + j) % n)] == 'T')) ++t; }res = Math.min(res,t); }out.println(res); } public void run()throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); ST = new StreamTokenizer(br); in = new Scanner(br); out = new PrintWriter(System.out); solve(); in.close(); out.close(); br.close(); } public static void main( String[] args)throws Exception { new Main().run(); } }
6	public class Main2{ static int mod = 1000000007; static FastScanner scanner ; public static void main( String[] args){ scanner = new FastScanner(); int n = scanner.nextInt();  int T = scanner.nextInt();  int[][] songs = new int[n][2]; for ( int i = 0;(i < n);i++) {songs[i][0] = scanner.nextInt(); songs[i][1] = (scanner.nextInt() - 1); } int[] mapping = new int[65536];  int mask = 1; for ( int k = 0;(k < n);k++) {for ( int i = 1;(i < mapping.length);i++) {if ( ((i & mask) != 0)) mapping[i] += songs[k][0]; }mask <<= 1; } int[][][] dp = new int[17][65536][3]; mask = 1; for ( int i = 0;(i < n);i++) {dp[1][mask][songs[i][1]] = 1; mask <<= 1; }for ( int i = 1;(i < n);i++) {mask = 1; for ( int k = 0;(k < n);k++) { int cg = songs[k][1];  int g1 ,g2 ; if ( (cg == 0)) {g1 = 1; g2 = 2; } else if ( (cg == 1)) {g1 = 0; g2 = 2; } else {g1 = 0; g2 = 1; }for ( int j = 1;(j < 65536);j++) {if ( ((j & mask) != 0)) continue; dp[(i + 1)][(j | mask)][cg] = ((dp[(i + 1)][(j | mask)][cg] + ((dp[i][j][g1] + dp[i][j][g2]) % mod)) % mod); }mask <<= 1; }} int res = 0; for ( int k = 0;(k < 17);k++) for ( int i = 1;(i < 65536);i++) {if ( (mapping[i] == T)) res = ((((res + dp[k][i][0]) + dp[k][i][1]) + dp[k][i][2]) % mod); }System.out.println(res); } public static class FastScanner{ BufferedReader br ; StringTokenizer st ; 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();} int nextInt(){ return Integer.parseInt(nextToken());} long nextLong(){ return Long.parseLong(nextToken());} } static class PrefixSums{ long[] sums ; public PrefixSums( long[] sums){ this.sums = sums; } } }
4	public class Main{ public static void main( String[] args)throws FileNotFoundException,IOException { File file = new File("input.txt");  Scanner sc = new Scanner(file);  File outFile = new File("output.txt");  PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));  int w = sc.nextInt();  int h = sc.nextInt();  boolean[][] map = new boolean[(h + 1)][(w + 1)];  int x = -1,y = -1;  Queue<Point> open = new LinkedList<Point>();  int k = sc.nextInt(); for ( int i = 0;(i < k);i++) { int tx = sc.nextInt();  int ty = sc.nextInt(); map[ty][tx] = true; x = tx; y = ty; open.add(new Point(x,y)); } int dx[] = {1,-1,0,0};  int dy[] = {0,0,1,-1}; while(!open.isEmpty()){ Point p = open.poll(); for ( int i = 0;(i < 4);i++) { int nx = (p.x + dx[i]);  int ny = (p.y + dy[i]); if ( (((((nx > 0) && (nx <= w)) && (ny > 0)) && (ny <= h)) && !map[ny][nx])) {map[ny][nx] = true; x = nx; y = ny; open.add(new Point(nx,ny)); } }}pw.println(((x + " ") + y)); pw.close(); } }
4	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)throws Exception { helper hp = new helper(MOD,(int)MAX); hp.initIO("input.txt","output.txt"); int n = hp.nextInt(),m = hp.nextInt();  boolean[][] a = new boolean[n][m];  int k = hp.nextInt();  ArrayDeque<int[]> q = new ArrayDeque<>(); for ( int i = 0;(i < k);i++) { int x = (hp.nextInt() - 1);  int y = (hp.nextInt() - 1); a[x][y] = true; q.add(new int[]{x,y}); } int lastX = 0,lastY = 0;  int[] dx = new int[]{1,-1,0,0};  int[] dy = new int[]{0,0,1,-1}; while(!q.isEmpty()){ int[] X = q.pollFirst(); for ( int i = 0;(i < 4);i++) { int x = (X[0] + dx[i]);  int y = (X[1] + dy[i]); if ( (isValid(x,y,n,m) && !a[x][y])) {a[x][y] = true; lastX = x; lastY = y; q.add(new int[]{x,y}); } }}hp.println((((lastX + 1) + " ") + (lastY + 1))); hp.flush(); } boolean TestCases = false; public static void main( String[] args)throws Exception { new Main().run(); } void run()throws Exception { is = (INPUT.isEmpty()?System.in:new ByteArrayInputStream(INPUT.getBytes())); out = new PrintWriter(System.out); long s = System.currentTimeMillis();  int T = (TestCases?ni():1); for ( int t = 1;(t <= T);t++) solve(t); out.flush(); if ( !INPUT.isEmpty()) tr(((System.currentTimeMillis() - s) + "ms")); } double PI = 3.141592653589793238462643383279502884197169399; int ni(){ 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(); }} int BUF_SIZE = (1024 * 8); byte[] inbuf = new byte[BUF_SIZE]; int lenbuf = 0,ptrbuf = 0; 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++];} boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} void tr( Object... o){ if ( (INPUT.length() > 0)) System.out.println(Arrays.deepToString(o)); } } class helper{ final long MOD ; final int MAXN ; final Random rnd ; public helper( long mod, int maxn){ MOD = mod; MAXN = maxn; rnd = new Random(); } static final int BUFSIZE = (1 << 20); static byte[] buf ; static int index ,total ; static InputStream in ; static BufferedWriter bw ; public void initIO( InputStream is, OutputStream os){ try{in = is; bw = new BufferedWriter(new OutputStreamWriter(os)); buf = new byte[BUFSIZE]; }catch (Exception e){ } } public void initIO( String inputFile, String outputFile){ try{in = new FileInputStream(inputFile); bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile))); buf = new byte[BUFSIZE]; }catch (Exception e){ e.printStackTrace(); } } private int scan()throws Exception { if ( (index >= total)) {index = 0; total = in.read(buf); if ( (total <= 0)) return -1; } return buf[index++];} public int nextInt()throws Exception { int c ,val = 0; for ( c = scan();(c <= 32);c = scan()) ; boolean neg = (c == '-'); if ( ((c == '-') || (c == '+'))) c = scan(); for ( ;((c >= '0') && (c <= '9'));c = scan()) val = (((val << 3) + (val << 1)) + (c & 15)); return (neg?-val:val);} public void println( Object a)throws Exception { bw.write((a.toString() + "\n")); } public void print( Object a)throws Exception { bw.write(a.toString()); } public void flush()throws Exception { bw.flush(); } public static int[] sieve ; public static ArrayList<Integer> primes ; }
5	public class C{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(in.readLine());  String[] S = in.readLine().split(" ");  int[] A = new int[n];  boolean allOnes = true; for ( int i = 0;(i < n);i++) {A[i] = Integer.parseInt(S[i]); allOnes &= (A[i] == 1); }Arrays.sort(A); if ( (A[(A.length - 1)] > 1)) A[(A.length - 1)] = 1; else A[(A.length - 1)] = 2; Arrays.sort(A); for ( int i = 0;(i < A.length);i++) System.out.print((A[i] + " ")); System.out.println(); } }
1	public class Solution{ static BufferedReader br = null; static PrintWriter pw = null; static StringTokenizer st = null; static String FILENAME = ""; void nline(){ try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } int ni(){ while(((st == null) || !st.hasMoreTokens()))nline(); return Integer.parseInt(st.nextToken());} String nstr(){ String s = ""; try{s = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return s;} public void solve(){ int n = ni();  String s = nstr();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = ((s.charAt(i) == 'H')?0:1); int hc = 0; for ( int i = 0;(i < n);i++) if ( (a[i] == 0)) hc++;  int min = 1000000; for ( int ss = 0;(ss < n);ss++) { int rc = 0; for ( int i = 0;(i < hc);i++) if ( (a[((i + ss) % n)] == 0)) rc++; if ( ((hc - rc) < min)) min = (hc - rc); }pw.print(min); } public void run(){ solve(); pw.close(); } public static void main( String[] args){ br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); new Solution().run(); } }
1	public class Main{ 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 < n);i++) {arr[i] = sc.nextInt(); } int min = 1000000000,temp ; for ( int i = 0;(i < n);i++) {temp = (arr[i] / Math.max(i,((n - 1) - i))); if ( (temp < min)) min = temp; }System.out.println(min); } }
1	public class R364C{ public static void main( String[] args)throws NumberFormatException,IOException { Scanner s = new Scanner(System.in);  BufferedReader f = new BufferedReader(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(System.out);  int n = Integer.parseInt(f.readLine());  char[] a = f.readLine().toCharArray();  int difTypes = 0;  TreeSet<Character> types = new TreeSet<Character>(); for ( int i = 0;(i < n);i++) {if ( !types.contains(a[i])) {types.add(a[i]); } } int i = 0,j = 0; difTypes = types.size(); int curTypes = 0;  int min = Integer.MAX_VALUE;  TreeSet<Character> has = new TreeSet<Character>();  HashMap<Character,Integer> freq = new HashMap<Character,Integer>(); while(((i < n) && (j < n))){has.add(a[j]); if ( !freq.containsKey(a[j])) {freq.put(a[j],1); } else {freq.put(a[j],(freq.get(a[j]) + 1)); }j++; curTypes = has.size(); if ( (curTypes == difTypes)) min = Math.min(min,(j - i)); while(((i < n) && (has.size() == difTypes))){ int Freq = freq.get(a[i]); if ( ((Freq - 1) == 0)) {has.remove(a[i]); freq.put(a[i],(freq.get(a[i]) - 1)); i++; break;} freq.put(a[i],(freq.get(a[i]) - 1)); i++; if ( (curTypes == difTypes)) min = Math.min(min,(j - i)); }curTypes = has.size(); }System.out.println(min); } }
2	public class P287B{ Scanner sc = new Scanner(System.in); int INF = (1 << 28); double EPS = 1e-9; long n ,k ; void run(){ n = sc.nextLong(); k = sc.nextLong(); solve(); } void solve(){ long left = -1,right = (k + 1); for ( ;((right - left) > 1);) { long m = ((left + right) / 2);  long lb = ((((k * (k + 1)) / 2) - (((k - m) * ((k - m) + 1)) / 2)) - (m - 1)); if ( (lb >= n)) {right = m; } else {left = m; }}println(("" + ((right > k)?-1:right))); } void println( String s){ System.out.println(s); } void print( String s){ System.out.print(s); } public static void main( String[] args){ Locale.setDefault(Locale.US); new P287B().run(); } }
4	public class FireAgain{ static int dx[] = {0,0,1,-1}; static int dy[] = {1,-1,0,0}; public static void main( String[] args)throws IOException { Scanner sc = new Scanner(new File("input.txt"));  BufferedWriter write = new BufferedWriter(new FileWriter("output.txt"));  int n = sc.nextInt();  int m = sc.nextInt();  boolean[][] v = new boolean[n][m];  int k = sc.nextInt();  Queue<Integer> q = new LinkedList<Integer>(); for ( int i = 0;(i < k);i++) { int x = (sc.nextInt() - 1);  int y = (sc.nextInt() - 1); q.add(x); q.add(y); v[x][y] = true; } int lastx = 0;  int lasty = 0; while(!q.isEmpty()){lastx = q.poll(); lasty = q.poll(); for ( int i = 0;(i < 4);i++) { int r = (lastx + dx[i]);  int c = (lasty + dy[i]); if ( (((((r >= 0) && (c >= 0)) && (r < n)) && (c < m)) && !v[r][c])) {v[r][c] = true; q.add(r); q.add(c); } }}write.write((((lastx + 1) + " ") + (lasty + 1))); write.close(); } }
5	public class Main{ static int N ; static int[] U ,V ; static int[] A ; public static void main( String[] args){ FastScanner sc = new FastScanner(System.in); N = sc.nextInt(); U = new int[(N - 1)]; V = new int[(N - 1)]; for ( int i = 0;(i < (N - 1));i++) {U[i] = (sc.nextInt() - 1); V[i] = (sc.nextInt() - 1); }A = sc.nextIntArray(N,-1); System.out.println((solve()?"Yes":"No")); } static boolean solve(){ if ( (A[0] != 0)) return false; int[][] G = adjB(N,U,V);  Map<Integer,Integer> parents = new HashMap<>(); for ( Node node :orderFromRoot(N,G,0)) {parents.put(node.a,node.parent); } ArrayDeque<Integer> q = new ArrayDeque<>(); for ( int next :G[0]) {q.add(0); } int idx = 1; while(!q.isEmpty()){ int p = q.poll();  int a = A[idx++]; if ( (parents.get(a) != p)) {return false;} for ( int next :G[a]) {if ( (next == p)) continue; q.add(a); }}return true;} static int[][] adjB( int n, int[] from, int[] to){ int[][] adj = new int[n][];  int[] cnt = new int[n]; for ( int f :from) {cnt[f]++; }for ( int t :to) {cnt[t]++; }for ( int i = 0;(i < n);i++) {adj[i] = new int[cnt[i]]; }for ( int i = 0;(i < from.length);i++) {adj[from[i]][--cnt[from[i]]] = to[i]; adj[to[i]][--cnt[to[i]]] = from[i]; }return adj;} static Node[] orderFromRoot( int N, int[][] G, int root){ ArrayDeque<Node> q = new ArrayDeque<>();  Node[] ret = new Node[N];  int idx = 0; q.add(new Node(-1,root)); while(!q.isEmpty()){ Node n = q.poll(); ret[idx++] = n; for ( int next :G[n.a]) {if ( (next == n.parent)) continue; q.add(new Node(n.a,next)); }}return ret;} static class Node{ int parent ,a ; public Node( int parent, int a){ this.parent = parent; this.a = a; } } @SuppressWarnings("unused") static class FastScanner{ private BufferedReader reader ; private StringTokenizer tokenizer ; FastScanner( InputStream in){ reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } String next(){ if ( ((tokenizer == null) || !tokenizer.hasMoreTokens())) {try{tokenizer = new StringTokenizer(reader.readLine()); }catch (IOException e){ throw (new RuntimeException(e));} } return tokenizer.nextToken();} long nextLong(){ return Long.parseLong(next());} int nextInt(){ return Integer.parseInt(next());} int[] nextIntArray( int n){ int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = nextInt(); return a;} int[] nextIntArray( int n, int delta){ int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = (nextInt() + delta); return a;} } static int max( int... as){ int max = Integer.MIN_VALUE; for ( int a :as) max = Math.max(a,max); return max;} static int min( int... as){ int min = Integer.MAX_VALUE; for ( int a :as) min = Math.min(a,min); return min;} }
3	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  TaskC.InputReader in = new TaskC.InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  TaskC solver = new TaskC(); solver.Solve(in,out); out.close(); } static class TaskC{ private long mod = 1_000_000_007; private int n ; private boolean[] s ; public void Solve( InputReader in, PrintWriter out){ n = in.NextInt(); s = new boolean[n]; for ( int i = 0;(i < n);i++) { String ss = in.Next(); s[i] = (ss.charAt(0) == 'f'); }if ( s[(n - 1)]) {out.println(0); return ;} long[] dpSum = new long[(n + 1)],lastDpSum = new long[(n + 1)]; for ( int i = 0;(i <= n);i++) {lastDpSum[i] = (i + 1); }for ( int i = (n - 2);(i >= 0);i--) {for ( int j = 0;(j <= i);j++) {if ( !s[i]) {dpSum[j] = lastDpSum[j]; } else {dpSum[j] = (lastDpSum[(j + 1)] - lastDpSum[j]); }if ( (j != 0)) {dpSum[j] += dpSum[(j - 1)]; } dpSum[j] %= mod; while((dpSum[j] < 0))dpSum[j] += mod; } long[] temp = dpSum; dpSum = lastDpSum; lastDpSum = temp; }out.println(lastDpSum[0]); } public static int GetMax( int[] ar){ int max = Integer.MIN_VALUE; for ( int a :ar) {max = Math.max(max,a); }return max;} public static int[] GetCount( int[] ar){ return GetCount(ar,GetMax(ar));} public static int[] GetCount( int[] ar, int maxValue){ int[] dp = new int[(maxValue + 1)]; for ( int a :ar) {dp[a]++; }return dp;} } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} FastReader in = new FastReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  FireAgain solver = new FireAgain(); solver.solve(1,in,out); out.close(); } static class FireAgain{ public void solve( int testNumber, FastReader in, PrintWriter out){ int n = in.nextInt();  int m = in.nextInt();  int k = in.nextInt();  int INF = 10000000;  int[][] g = new int[n][m]; for ( int[] temp :g) Arrays.fill(temp,-1); ArrayDeque<IntPair> q = new ArrayDeque<>(); for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); g[x][y] = 0; q.add(new IntPair(x,y)); }while(!q.isEmpty()){ IntPair cur = q.poll();  int x = cur.getFirst();  int y = cur.getSecond(); for ( int i = -1;(i <= 1);i++) {for ( int j = -1;(j <= 1);j++) {if ( (((i == 0) && (j == 0)) || ((Math.abs(i) + Math.abs(j)) != 1))) continue; int xx = (x + i);  int yy = (y + j); if ( ((((xx < 0) || (xx >= n)) || (yy < 0)) || (yy >= m))) continue; if ( (g[xx][yy] != -1)) continue; g[xx][yy] = (g[x][y] + 1); q.add(new IntPair(xx,yy)); }}} int ans = 0,x = -1,y = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (g[i][j] >= ans)) {ans = g[i][j]; x = (i + 1); y = (j + 1); } }}out.println(((x + " ") + y)); } } static class IntPair implements Comparable<IntPair>{ int first ; int second ; public IntPair( int first, int second){ this.first = first; this.second = second; } public int getFirst(){ return first;} public int getSecond(){ return second;} } static class FastReader{ BufferedReader reader ; StringTokenizer st ; public FastReader( InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream)); st = null; } public String next(){ while(((st == null) || !st.hasMoreTokens())){try{ String line = reader.readLine(); if ( (line == null)) {return null;} st = new StringTokenizer(line); }catch (Exception e){ throw (new RuntimeException());} }return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} } }
1	public class Main implements Runnable{ BufferedReader in ; PrintStream out ; StringTokenizer st = new StringTokenizer(""); static boolean local = false; public static void main( String[] args)throws Exception { if ( (args.length > 0)) local = true; new Thread(new Main()).start(); } boolean seekForToken(){ try{while(!st.hasMoreTokens()){ String s = in.readLine(); if ( (s == null)) {return false;} st = new StringTokenizer(s); }return true; }catch (IOException e){ e.printStackTrace(); return false;} } int nextInt(){ return Integer.parseInt(nextToken());} String nextToken(){ seekForToken(); return st.nextToken();} }
6	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);  G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion(); solver.solve(1,in,out); out.close(); } static class G1PlaylistForPolycarpEasyVersion{ static ArrayList<Integer> list ; static int n ; static int req ; static int mod = ((int)1e9 + 7); static int[] dur ; static int[] genre ; static Integer[][][] memo ; public void solve( int testNumber, Scanner sc, PrintWriter pw){ n = sc.nextInt(); req = sc.nextInt(); dur = new int[n]; genre = new int[n]; list = new ArrayList<>(); for ( int i = 0;(i < n);i++) {dur[i] = sc.nextInt(); genre[i] = sc.nextInt(); } int ans = 0; memo = new Integer[(1 << n)][(n + 1)][4]; for ( int i = 0;(i <= n);i++) ans += (bf(0,0,0,i) % mod); pw.print((ans % mod)); } private int bf( int idx, int msk, int before, int max){ if ( (idx == max)) { int sum = 0; for ( int x :list) sum += x; if ( (sum == req)) return 1; return 0;} if ( (memo[msk][max][before] != null)) return (memo[msk][max][before] % mod); int toRet = 0; for ( int i = 0;(i < n);i++) {if ( ((genre[i] != before) && ((msk & (1 << i)) == 0))) {list.add(dur[i]); toRet += bf((idx + 1),(msk | (1 << i)),genre[i],max); toRet %= mod; list.remove((list.size() - 1)); } }return memo[msk][max][before] = (toRet % mod);} } 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());} } }
5	public class Solution implements Runnable{ static private BufferedReader br = null; static private PrintWriter out = null; static private StringTokenizer stk = null; public static void main( String[] args){ br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); new Thread(new Solution()).start(); } private void loadLine(){ try{stk = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } private Integer nextInt(){ while(((stk == null) || !stk.hasMoreTokens()))loadLine(); return Integer.parseInt(stk.nextToken());} private Double nextDouble(){ while(((stk == null) || !stk.hasMoreTokens()))loadLine(); return Double.parseDouble(stk.nextToken());} }
1	public class SonyaExhibition{ static BufferedReader br ; static StringTokenizer tokenizer ; public static void main( String[] args)throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); int n = nextInt();  int[] arr = {0,1}; for ( int i = 0;(i < n);i++) {System.out.print(arr[(i % 2)]); }System.out.println(); } public static String next()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){ String line = br.readLine(); if ( (line == null)) throw (new IOException()); tokenizer = new StringTokenizer(line); }return tokenizer.nextToken();} public static int nextInt()throws IOException { return Integer.parseInt(next());} }
5	public class Main{ StreamTokenizer in ; PrintWriter out ; public static void main( String[] args)throws IOException { new Main().run(); } int ni()throws IOException { in.nextToken(); return (int)in.nval;} void run()throws IOException { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(new OutputStreamWriter(System.out)); int n = ni(),t = ni(); if ( (n == 0)) {out.println(0); out.flush(); return ;} House[] h = new House[n]; for ( int i = 0;(i < n);i++) {h[i] = new House(); h[i].x = ni(); h[i].a = ni(); }Arrays.sort(h); int ret = 2; for ( int i = 0;(i < (n - 1));i++) {if ( ((((2 * (h[(i + 1)].x - h[i].x)) - h[i].a) - h[(i + 1)].a) > (2 * t))) ret += 2; else if ( ((((2 * (h[(i + 1)].x - h[i].x)) - h[i].a) - h[(i + 1)].a) == (2 * t))) ret++; }out.println(ret); out.flush(); } class House implements Comparable<House>{ int x ,a ; } }
5	public class A{ BufferedReader in ; StringTokenizer st ; PrintWriter out ; String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(next());} void solve()throws Exception { int n = nextInt();  int a[] = new int[n]; for ( int i = 0;(i < n);i++) a[i] = nextInt(); Arrays.sort(a); if ( (a[(n - 1)] == 1)) {for ( int i = 1;(i < n);i++) out.print("1 "); out.print(2); return ;} Arrays.sort(a); out.print(1); for ( int i = 1;(i < n);i++) out.print((" " + a[(i - 1)])); } void run(){ try{Locale.setDefault(Locale.US); boolean oj = (System.getProperty("ONLINE_JUDGE") != null);  Reader reader = (oj?new InputStreamReader(System.in):new FileReader("input.txt"));  Writer writer = (oj?new OutputStreamWriter(System.out):new FileWriter("output.txt")); in = new BufferedReader(reader); out = new PrintWriter(writer); solve(); out.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } public static void main( String[] args){ new A().run(); } }
5	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);  TaskD solver = new TaskD(); solver.solve(1,in,out); out.close(); } static class TaskD{ public void solve( int testNumber, FastReader in, PrintWriter out){ int n = in.nextInt();  TaskD.Pair[] p = new TaskD.Pair[n]; for ( int i = 0;(i < n);++i) {p[i] = new TaskD.Pair(in.nextLong(),in.nextLong()); }Arrays.sort(p); int last = 0;  int ans = 1; for ( int i = 1;(i < n);++i) {if ( ((p[i].x - p[i].w) >= (p[last].x + p[last].w))) {last = i; ++ans; } }out.println(ans); } } static class FastReader{ private InputStream stream ; private byte[] buf = new byte[8192]; private int curChar ; private int pnumChars ; public FastReader( InputStream stream){ this.stream = stream; } private int pread(){ if ( (pnumChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= pnumChars)) {curChar = 0; try{pnumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (pnumChars <= 0)) {return -1;} } return buf[curChar++];} public int nextInt(){ int c = pread(); while(isSpaceChar(c))c = pread(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = pread(); } int res = 0; do {if ( (c == ',')) {c = pread(); } if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = pread(); }while(!isSpaceChar(c));return (res * sgn);} public long nextLong(){ int c = pread(); while(isSpaceChar(c))c = pread(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = pread(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = pread(); }while(!isSpaceChar(c));return (res * sgn);} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } }
2	public class Main{ private void solve()throws IOException { int n = nextInt();  int x = nextInt();  int y = nextInt();  int c = nextInt();  int lux = x;  int luy = (y + 1);  int rux = (x + 1);  int ruy = y;  int ldx = (x - 1);  int ldy = y;  int rdx = x;  int rdy = (y - 1);  int k = 1;  int res = 0; while((k < c)){lux--; luy--; rux--; ruy++; rdx++; rdy++; ldx++; ldy--; int p = 0; p += lu((x - 1),luy,lux,y,n); p += ru(x,ruy,rux,(y + 1),n); p += ld(x,ldy,ldx,(y - 1),n); p += rd((x + 1),rdy,rdx,y,n); k += p; res++; }println(res); } private int lu( int x1, int y1, int x2, int y2, int n){ if ( ((y1 > 0) && (x2 > 0))) {return ((x1 - x2) + 1);} else if ( ((y1 > 0) && (x2 < 1))) {return x1;} else if ( ((y1 < 1) && (x2 > 0))) {return y2;} else if ( ((x1 - (1 - y1)) > 0)) {return lu((x1 - (1 - y1)),1,x2,y2,n);} else {return 0;}} private int ru( int x1, int y1, int x2, int y2, int n){ if ( ((y1 <= n) && (x2 > 0))) {return ((x1 - x2) + 1);} else if ( ((y1 <= n) && (x2 < 1))) {return x1;} else if ( ((y1 > n) && (x2 > 0))) {return ((n - y2) + 1);} else if ( ((x1 - (y1 - n)) > 0)) {return ru((x1 - (y1 - n)),n,x2,y2,n);} else {return 0;}} private int ld( int x1, int y1, int x2, int y2, int n){ if ( ((y1 > 0) && (x2 <= n))) {return ((x2 - x1) + 1);} else if ( ((y1 > 0) && (x2 > n))) {return ((n - x1) + 1);} else if ( ((y1 < 1) && (x2 <= n))) {return y2;} else if ( ((x1 + (1 - y1)) <= n)) {return ld((x1 + (1 - y1)),1,x2,y2,n);} else {return 0;}} private int rd( int x1, int y1, int x2, int y2, int n){ if ( ((y1 <= n) && (x2 <= n))) {return ((x2 - x1) + 1);} else if ( ((y1 <= n) && (x2 > n))) {return ((n - x1) + 1);} else if ( ((y1 > n) && (x2 <= n))) {return ((n - y2) + 1);} else if ( ((x1 + (y1 - n)) <= n)) {return rd((x1 + (y1 - n)),n,x2,y2,n);} else {return 0;}} private String next()throws IOException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(reader.readLine()); }return st.nextToken();} @SuppressWarnings private int nextInt()throws IOException { return Integer.parseInt(next());} @SuppressWarnings private void println( Object o){ writer.println(o); } @SuppressWarnings private void print( Object o){ writer.print(o); } private BufferedReader reader ; private PrintWriter writer ; private StringTokenizer st ; private void run()throws IOException { long time = System.currentTimeMillis(); Locale.setDefault(Locale.US); reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); solve(); writer.close(); System.err.println((System.currentTimeMillis() - time)); } public static void main( String[] args)throws IOException { new Main().run(); } }
1	public class Watermelon{ static class Passengers{ public int floor ; public int time ; public Passengers( int floor, int time){ this.floor = floor; this.time = time; } } public static void main( String[] args){ Scanner in = new Scanner(System.in);  int x = in.nextInt(),y = in.nextInt();  ArrayList<Passengers> list = new ArrayList<>(); for ( int i = 1;(i <= x);++i) {list.add(new Passengers(in.nextInt(),in.nextInt())); } int sum = 0; for ( int i = (list.size() - 1);(i >= 0);--i) { int s = (y - list.get(i).floor); sum = (sum + s); if ( (sum < list.get(i).time)) {sum = (sum + (list.get(i).time - sum)); } y = list.get(i).floor; }if ( (list.get((list.size() - 1)).floor != 0)) {sum = (sum + list.get(0)); } System.out.println(sum); } }
5	public class Main implements Runnable{ final String filename = ""; public void solve()throws Exception { int n = iread();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = iread(); Arrays.sort(a); boolean test = true; for ( int i = 0;(i < n);i++) {if ( (a[i] != 1)) test = false;  int min = ((i == 0)?1:a[(i - 1)]); if ( (test && (i == (n - 1)))) out.write(((min + 1) + "")); else out.write((min + "")); if ( (i == (n - 1))) out.write("\n"); else out.write(" "); }} public int iread()throws Exception { return Integer.parseInt(readword());} BufferedReader in ; BufferedWriter out ; public String readword()throws IOException { StringBuilder b = new StringBuilder();  int c ; c = in.read(); while(((c >= 0) && (c <= ' ')))c = in.read(); if ( (c < 0)) return ""; while((c > ' ')){b.append((char)c); c = in.read(); }return b.toString();} public static void main( String[] args){ try{Locale.setDefault(Locale.US); }catch (Exception e){ } new Thread(null,new Main(),"1",(1 << 25)).start(); } }
5	public class Village{ private class House implements Comparable<House>{ Double Coordinate ; Double Sidelength ; public House( double coordinate, double sidelength){ Coordinate = coordinate; Sidelength = sidelength; } public int compareTo( House o){ return Coordinate.compareTo(o.Coordinate);} } public static void main( String[] args){ Village v = new Village(); v.solve(); } public void solve(){ Scanner in = new Scanner(System.in);  int numhouse = in.nextInt();  double requireside = in.nextDouble();  ArrayList<House> coordinate = new ArrayList<House>();  ArrayList<Double> sidelength = new ArrayList<Double>(); while(in.hasNext()){ double coo = in.nextDouble();  double side = in.nextDouble(); coordinate.add(new House(coo,side)); sidelength.add(side); }Collections.sort(coordinate); ArrayList<Double> edges = new ArrayList<Double>();  int count = 2; for ( int i = 0;(i < coordinate.size());i++) {edges.add((coordinate.get(i).Coordinate - ((double)coordinate.get(i).Sidelength / (double)2))); edges.add((coordinate.get(i).Coordinate + ((double)coordinate.get(i).Sidelength / (double)2))); } ArrayList<Double> difference = new ArrayList<Double>(); for ( int i = 1;(i < (edges.size() - 1));i++) {difference.add(Math.abs((edges.get(i) - edges.get((i + 1))))); }for ( int i = 0;(i < difference.size());i += 2) {if ( (difference.get(i) == requireside)) count++; else if ( (difference.get(i) > requireside)) count += 2; }System.out.println(count); } }
3	public class _909C{ static private final int MOD = 1000000007; static private void solve( Scanner scan, PrintWriter pw){ int n = scan.nextInt(); scan.nextLine(); int[][] dp = new int[n][n];  int[][] dpSums = new int[n][n]; dp[0][0] = 1; for ( int i = 0;(i < n);i++) {dpSums[0][i] = 1; } boolean lastIsSimple = scan.nextLine().equals("s"); for ( int i = 1;(i < n);i++) {if ( lastIsSimple) {dp[i][0] = dpSums[(i - 1)][(n - 1)]; dpSums[i][0] = dp[i][0]; for ( int j = 1;(j < n);j++) {dp[i][j] = (((dpSums[(i - 1)][(n - 1)] - dpSums[(i - 1)][(j - 1)]) + MOD) % MOD); dpSums[i][j] = ((dp[i][j] + dpSums[i][(j - 1)]) % MOD); }} else {dp[i][0] = 0; dpSums[i][0] = 0; for ( int j = 1;(j < n);j++) {dp[i][j] = dp[(i - 1)][(j - 1)]; dpSums[i][j] = ((dp[i][j] + dpSums[i][(j - 1)]) % MOD); }}lastIsSimple = scan.nextLine().equals("s"); }System.out.println(dpSums[(n - 1)][(n - 1)]); } public static void main( String[] args){ Scanner scan = new Scanner(new BufferedInputStream(System.in,(1024 * 64)));  PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out,(1024 * 64))); solve(scan,pw); pw.flush(); } }
1	public class main{ public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static PrintWriter pw = new PrintWriter(System.out); public static String line ; public static StringTokenizer st ; public static ArrayList<ArrayList<Integer>> adjList ; public static int[] dr = {-1,0,1,0,-1,1,1,-1}; public static int[] dc = {0,1,0,-1,1,1,-1,-1}; public static void main( String[] args)throws Exception { int N = Integer.parseInt(br.readLine());  char[] A = br.readLine().toCharArray();  HashSet<Character> cndD = new HashSet<Character>(); for ( int i = 0;(i < N);i++) {cndD.add(A[i]); } int cnt = cndD.size();  int a = 0;  int b = 0;  int ans = (1 << 30);  HashMap<Character,Integer> d = new HashMap<Character,Integer>(); while((b < N)){if ( d.containsKey(A[b])) {if ( (A[a] == A[b])) {a++; while((d.get(A[a]) > 1)){d.put(A[a],(d.get(A[a]) - 1)); a++; }} else {d.put(A[b],(d.get(A[b]) + 1)); }} else {d.put(A[b],1); }if ( (d.size() == cnt)) {ans = Math.min(((b - a) + 1),ans); } b++; }pw.print((ans + "\n")); pw.close(); br.close(); } }
0	public class Solver{ StringTokenizer st ; BufferedReader in ; PrintWriter out ; public static void main( String[] args)throws NumberFormatException,IOException { Solver solver = new Solver(); solver.open(); solver.solve(); solver.close(); } public void open()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } public String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(in.readLine()); }return st.nextToken();} public int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(nextToken());} public void solve()throws NumberFormatException,IOException { int n = nextInt(); out.println(((((0 + " ") + 0) + " ") + n)); } public void close(){ out.flush(); out.close(); } }
6	public class codeforces{ public static long cnt = 0; public static void f( int g1, int g2, int g3, int last){ if ( (((g1 == 0) && (g2 == 0)) && (g3 == 0))) cnt++; if ( ((g1 > 0) && (last != 1))) f((g1 - 1),g2,g3,1); if ( ((g2 > 0) && (last != 2))) f(g1,(g2 - 1),g3,2); if ( ((g3 > 0) && (last != 3))) f(g1,g2,(g3 - 1),3); } public static void main( String[] args)throws IOException { BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));  StringTokenizer st = new StringTokenizer(scan.readLine());  int n = Integer.parseInt(st.nextToken());  int t = Integer.parseInt(st.nextToken());  int T[] = new int[n];  int G[] = new int[n]; for ( int i = 0;(i < n);i++) {st = new StringTokenizer(scan.readLine()); T[i] = Integer.parseInt(st.nextToken()); G[i] = Integer.parseInt(st.nextToken()); } long ans = 0; for ( int mask = 1;(mask < (1 << n));mask++) { int sum = 0;  int g1 = 0;  int g2 = 0;  int g3 = 0; for ( int i = 0;(i < n);i++) {if ( (((1 << i) & mask) > 0)) {sum += T[i]; if ( (G[i] == 1)) g1++; if ( (G[i] == 2)) g2++; if ( (G[i] == 3)) g3++; } }cnt = 0; if ( (sum == t)) f(g1,g2,g3,-1); for ( long i = 1;(i <= g1);i++) cnt *= i; for ( long i = 1;(i <= g2);i++) cnt *= i; for ( long i = 1;(i <= g3);i++) cnt *= i; ans += cnt; }System.out.println((ans % 1000000007)); } }
2	public class B{ public static void main( String[] args){ PrintWriter out = new PrintWriter(System.out);  Scanner sc = new Scanner(System.in);  long N = sc.nextLong();  long K = sc.nextLong(); if ( (N == 1)) {out.println(0); } else if ( (N <= K)) {out.println(1); } else if ( (N > ((((K - 1) * K) / 2) + 1))) {out.println(-1); } else { long lo = 1;  long hi = Math.max((K - 2),1);  long big = (((K - 2) * (K - 1)) / 2);  long prevmid = -1; for ( int i = 0;(i < 10000);i++) { long mid = ((lo + hi) / 2);  long tmp = ((((K - 2) - mid) * (((K - 2) - mid) + 1)) / 2); if ( (((K + big) - tmp) > N)) {hi = mid; } else if ( (((K + big) - tmp) < N)) {lo = mid; if ( (prevmid == mid)) lo++; lo = Math.min(lo,hi); prevmid = mid; } else {lo = mid; break;}}out.println(((long)lo + 1)); }sc.close(); out.close(); } }
0	public class Main{ public static void main( String[] YAHIA_MOSTAFA){ Scanner sc = new Scanner(System.in);  long n = sc.nextLong(),x = sc.nextLong(),y = sc.nextLong();  long xb ,xw ,yb ,yw ; xw = (x - 1); yw = (y - 1); xb = (n - x); yb = (n - y); if ( ((x == n) && (y == n))) {System.out.println("Black"); return ;} long c1 = 0,c2 = 0;  long f = Math.max(xb,yb);  long h = Math.max(xw,yw); if ( (h <= f)) System.out.println("White"); else System.out.println("Black"); } }
1	public class Main{ public static void main( String[] args){ Scanner cin = new Scanner(System.in);  int n ; n = cin.nextInt(); String s = cin.next();  int ans = n;  int cntH = 0,cntT = 0; for ( int i = 0;(i < n);i++) {if ( (s.charAt(i) == 'H')) cntH++; }cntT = (n - cntH); for ( int i = 0;((i + cntH) < n);i++) { int tmp = 0; for ( int j = i;(j < (i + cntH));j++) if ( (s.charAt(j) == 'T')) tmp++; if ( (ans > tmp)) ans = tmp; }for ( int i = 0;((i + cntT) < n);i++) { int tmp = 0; for ( int j = i;(j < (i + cntT));j++) if ( (s.charAt(j) == 'H')) tmp++; if ( (ans > tmp)) ans = tmp; }System.out.println(ans); } }
6	public class Solution{ public static long mod = 1000000007; public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(System.out);  StringTokenizer st = new StringTokenizer(br.readLine());  int n = Integer.parseInt(st.nextToken());  int t = Integer.parseInt(st.nextToken());  int[] d = new int[n];  int[] g = new int[n]; for ( int i = 0;(i < n);i++) {st = new StringTokenizer(br.readLine()); d[i] = Integer.parseInt(st.nextToken()); g[i] = (Integer.parseInt(st.nextToken()) - 1); } long[][] dp = new long[(1 << n)][3]; for ( int i = 0;(i < n);i++) {dp[(1 << i)][g[i]] = 1; } long res = 0; for ( int i = 1;(i < (1 << n));i++) { int k = i;  int sum = 0; for ( int j = (n - 1);(j >= 0);j--) {if ( (k >= (1 << j))) {k -= (1 << j); sum += d[j]; } else {for ( int r = 0;(r < 3);r++) if ( (r != g[j])) dp[(i + (1 << j))][g[j]] += dp[i][r]; dp[(i + (1 << j))][g[j]] %= mod; }}if ( (sum == t)) {res += ((dp[i][0] + dp[i][1]) + dp[i][2]); res %= mod; } }out.println(res); out.flush(); } }
6	public class ElongatedMatrix{ static int[][][] memo ; static int mn1[][] ; static int mn2[][] ; static int r ,c ; static int dp( int mask, int first, int lastvisited){ if ( (memo[first][lastvisited][mask] != -1)) return memo[first][lastvisited][mask]; int ans = 0; for ( int i = 0;(i < r);i++) {if ( ((mask & (1 << i)) == 0)) {if ( (Integer.bitCount(mask) != (r - 1))) {ans = Math.max(ans,Math.min(mn1[lastvisited][i],dp((mask | (1 << i)),first,i))); } else ans = Math.max(ans,Math.min(mn2[first][i],mn1[lastvisited][i])); } }return memo[first][lastvisited][mask] = ans;} public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  StringTokenizer st = new StringTokenizer(br.readLine());  PrintWriter out = new PrintWriter(System.out); r = Integer.parseInt(st.nextToken()); c = Integer.parseInt(st.nextToken()); int[][] arr = new int[r][c]; memo = new int[r][r][(1 << r)]; mn1 = new int[r][r]; mn2 = new int[r][r]; for ( int i = 0;(i < r);i++) {st = new StringTokenizer(br.readLine()); for ( int j = 0;(j < c);j++) {arr[i][j] = Integer.parseInt(st.nextToken()); }}for ( int i = 0;(i < r);i++) {Arrays.fill(mn1[i],(int)1e9); Arrays.fill(mn2[i],(int)1e9); }for ( int i = 0;(i < r);i++) {for ( int j = 0;(j < r);j++) {Arrays.fill(memo[i][j],-1); }}for ( int i = 0;(i < r);i++) {for ( int j = 0;(j < r);j++) {for ( int k = 0;(k < c);k++) {mn1[i][j] = Math.min(mn1[i][j],Math.abs((arr[i][k] - arr[j][k]))); }}}for ( int i = 0;(i < r);i++) {for ( int j = 0;(j < r);j++) {for ( int k = 0;(k < (c - 1));k++) {mn2[i][j] = Math.min(mn2[i][j],Math.abs((arr[j][k] - arr[i][(k + 1)]))); }}} int ans = 0; for ( int i = 0;(i < r);i++) {ans = Math.max(ans,dp((1 << i),i,i)); }if ( (r == 1)) ans = mn2[0][0]; out.println(ans); out.flush(); } }
5	public class _P015A{ Scanner sc = new Scanner(System.in); int INF = (1 << 28); double EPS = 1e-9; int n ,t ; int[][] a ; void run(){ n = sc.nextInt(); t = sc.nextInt(); a = new int[n][2]; for ( int i = 0;(i < n);i++) {a[i][0] = sc.nextInt(); a[i][1] = sc.nextInt(); }solve(); } void solve(){ sort(a,new Comparator<int[]>(){}); int ans = 2; for ( int i = 0;(i < (n - 1));i++) { int s = (((a[(i + 1)][0] * 2) - a[(i + 1)][1]) - ((a[i][0] * 2) + a[i][1])); if ( (s > (t * 2))) {ans += 2; } else if ( (s == (t * 2))) {ans++; } }println((ans + "")); } void println( String s){ System.out.println(s); } void print( String s){ System.out.print(s); } public static void main( String[] args){ new _P015A().run(); } }
0	public class Main{ public static void main( String[] args){ Scanner r = new Scanner(System.in);  int N = r.nextInt(); System.out.println(((((N + " ") + 0) + " ") + 0)); } }
1	public class ProblemA{ public static void main( String[] args)throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  PrintWriter writer = new PrintWriter(System.out);  int n = Integer.parseInt(reader.readLine());  String[] split = reader.readLine().split("\\s+");  int value ;  int[] count = new int[2];  int[] pos = new int[2]; for ( int i = 0;(i < split.length);i++) {value = Integer.parseInt(split[i]); count[(value % 2)]++; pos[(value % 2)] = (i + 1); }writer.println(((count[0] == 1)?pos[0]:pos[1])); writer.flush(); writer.close(); } }
1	public class Main{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  int n = scan.nextInt();  int m = scan.nextInt();  int[] game = new int[n];  int[] bill = new int[m]; for ( int i = 0;(i < n);i++) {game[i] = scan.nextInt(); }for ( int i = 0;(i < m);i++) {bill[i] = scan.nextInt(); } int i = 0;  int j = 0;  int ans = 0; while((i < m)){ boolean f = true; for ( int k = j;(k < n);k++) {if ( (bill[i] >= game[k])) {ans++; i++; j = (k + 1); f = false; break;} }if ( f) {break;} }System.out.println(ans); } }
1	public class R025A{ int n ; int[] nums ; public R025A(){ Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); nums = new int[n]; for ( int i = 0;(i < n);i++) {nums[i] = scanner.nextInt(); }} private void process(){ int odd = 0;  int even = 0;  int lastOdd = 0;  int lastEven = 0; for ( int i = 0;(i < n);i++) {if ( ((nums[i] % 2) == 0)) {even++; lastEven = (i + 1); } else {odd++; lastOdd = (i + 1); }}if ( (odd == 1)) System.out.println(lastOdd); else System.out.println(lastEven); } public static void main( String[] args){ new R025A().process(); } }
4	public class Main{ public static void main( String[] Args)throws Exception { Scanner sc = new Scanner(new FileReader("input.txt"));  int n ,m ,k ;  Integer lx ,ly ;  boolean d[][] ; n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt(); d = new boolean[(n + 1)][(m + 1)]; for ( int i = 0;(i <= n);++i) for ( int j = 0;(j <= m);++j) d[i][j] = false; Queue<pair> q = new LinkedList<pair>(); lx = ly = -1; for ( int i = 0;(i < k);++i) { int x ,y ; x = sc.nextInt(); y = sc.nextInt(); q.add(new pair(x,y)); lx = x; ly = y; d[x][y] = true; } int dx[] = {0,0,1,-1};  int dy[] = {-1,1,0,0}; while(!q.isEmpty()){ pair tp = q.remove();  int x = tp.x;  int y = tp.y; for ( int i = 0;(i < 4);++i) { int nx = (x + dx[i]);  int ny = (y + dy[i]); if ( (((((nx < 1) || (nx > n)) || (ny < 1)) || (ny > m)) || d[nx][ny])) continue; d[nx][ny] = true; q.add(new pair(nx,ny)); lx = nx; ly = ny; }} FileWriter fw = new FileWriter("output.txt"); fw.write(lx.toString()); fw.write(" "); fw.write(ly.toString()); ;fw.flush(); } } class pair{ public int x ,y ; public pair( int _x, int _y){ x = _x; y = _y; } }
2	public class Main{ public static void main( String[] args){ Scanner cin = new Scanner(System.in);  long z = ((cin.nextLong() - 1) << 1),n = cin.nextInt(),l = -1,r = (1 + n),m ; while((l < (m = ((l + r) >> 1))))if ( (z > (((m + n) - 1) * (n - m)))) r = m; else l = m; if ( (0 < l)) l = (n - l); System.out.print(l); } }
1	public class Main{ public static void main( String[] args)throws NumberFormatException,IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in));  int size = Integer.parseInt(r.readLine());  String line = r.readLine();  int counter = 0; for ( int i = 0;(i < line.length());i++) {if ( (line.charAt(i) == 'H')) counter++; } int minimum = Integer.MAX_VALUE; for ( int i = 0;(i < line.length());i++) {if ( (line.charAt(i) == 'H')) { int current = 0; for ( int j = i;(j < (i + counter));j++) {if ( (line.charAt((j % line.length())) == 'T')) current++; }minimum = Math.min(current,minimum); } }System.out.println(minimum); } }
4	public class FireAgain{ static int n ; static int m ; public static void main( String[] args)throws IOException { BufferedReader r = new BufferedReader(new FileReader("input.txt"));  String s = r.readLine();  String[] sp = s.split(" "); n = new Integer(sp[0]); m = new Integer(sp[1]); boolean[][] v = new boolean[n][m]; r.readLine(); s = r.readLine(); sp = s.split(" "); Queue<Integer> q = new LinkedList<Integer>(); for ( int i = 0;(i < sp.length);i += 2) {v[(new Integer(sp[i]) - 1)][(new Integer(sp[(i + 1)]) - 1)] = true; q.add((new Integer(sp[i]) - 1)); q.add((new Integer(sp[(i + 1)]) - 1)); } int[] dx = {1,-1,0,0};  int[] dy = {0,0,1,-1};  int lx = -1;  int ly = -1; while(!q.isEmpty()){ int x = q.remove();  int y = q.remove(); lx = x; ly = y; for ( int i = 0;(i < dy.length);i++) { int nx = (x + dx[i]);  int ny = (y + dy[i]); if ( (valid(nx,ny) && !v[nx][ny])) {v[nx][ny] = true; q.add(nx); q.add(ny); } }}lx++; ly++; BufferedWriter wr = new BufferedWriter(new FileWriter("output.txt")); wr.write(((("" + lx) + " ") + ly)); wr.newLine(); wr.close(); } static private boolean valid( int nx, int ny){ return ((((nx >= 0) && (nx < n)) && (ny >= 0)) && (ny < m));} }
4	public class C{ String line ; StringTokenizer inputParser ; BufferedReader is ; FileInputStream fstream ; DataInputStream in ; void openInput( String file){ if ( (file == null)) is = new BufferedReader(new InputStreamReader(System.in)); else {try{fstream = new FileInputStream(file); in = new DataInputStream(fstream); is = new BufferedReader(new InputStreamReader(in)); }catch (Exception e){ System.err.println(e); } }} void readNextLine(){ try{line = is.readLine(); inputParser = new StringTokenizer(line," "); }catch (IOException e){ System.err.println(("Unexpected IO ERROR: " + e)); } } int NextInt(){ String n = inputParser.nextToken();  int val = Integer.parseInt(n); return val;} void closeInput(){ try{is.close(); }catch (IOException e){ System.err.println(("Unexpected IO ERROR: " + e)); } } public static void main( String[] argv){ String filePath = null; if ( (argv.length > 0)) filePath = argv[0];  C c = new C(filePath); } public C( String inputFile){ inputFile = "input.txt"; openInput(inputFile); PrintWriter writer = null; try{writer = new PrintWriter("output.txt"); }catch (FileNotFoundException e){ e.printStackTrace(); } readNextLine(); int N = NextInt();  int M = NextInt(); readNextLine(); int K = NextInt(); readNextLine(); int[][] p = new int[N][M];  int[][] init = new int[K][2]; for ( int i = 0;(i < K);i++) { int x = (NextInt() - 1);  int y = (NextInt() - 1); p[x][y] = 0; init[i][0] = x; init[i][1] = y; } int max = -1;  int maxX = -1,maxY = -1; for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) {p[i][j] = 10000; for ( int k = 0;(k < K);k++) { int n = (Math.abs((init[k][0] - i)) + Math.abs((init[k][1] - j))); if ( (n < p[i][j])) p[i][j] = n; }if ( (p[i][j] > max)) {max = p[i][j]; maxX = (i + 1); maxY = (j + 1); } }writer.println(((maxX + " ") + maxY)); closeInput(); writer.close(); } }
6	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(new BufferedWriter(new OutputStreamWriter(System.out)));  int T = 1; for ( int t = 0;(t < T);t++) { int n = Int();  int k = Int();  int A[][] = new int[n][2];  int a = 0,b = 0,c = 0; for ( int i = 0;(i < A.length);i++) {A[i][0] = Int(); A[i][1] = (Int() - 1); if ( (A[i][1] == 0)) a++; else if ( (A[i][1] == 1)) b++; else c++; }Arrays.sort(A,(x,y)->{return (x[0] - y[0]);}); Solution sol = new Solution(out); sol.solution(A,k,a,b,c); }out.close(); } public static int Int(){ return fs.Int();} public static long Long(){ return fs.Long();} public static String Str(){ return fs.Str();} } class Solution{ PrintWriter out ; public Solution( PrintWriter out){ this.out = out; } int mod = 1000000007; long dp3[][][][] ; public void solution( int[][] A, int T, int x, int y, int z){ long res = 0;  int n = A.length;  long dp1[][] = new long[(x + 2)][(T + 1)];  long dp2[][][] = new long[(y + 2)][(z + 2)][(T + 2)]; dp3 = new long[(x + 2)][(y + 2)][(z + 2)][3]; long f[] = new long[(n + 10)]; f[0] = f[1] = 1; for ( int i = 2;(i < f.length);i++) {f[i] = (f[(i - 1)] * i); f[i] %= mod; }for ( int i = 0;(i < dp3.length);i++) {for ( int j = 0;(j < dp3[0].length);j++) {for ( int k = 0;(k < dp3[0][0].length);k++) {Arrays.fill(dp3[i][j][k],-1); }}}dp1[0][0] = 1; for ( int i = 0;(i < A.length);i++) { int p = A[i][0],type = A[i][1]; if ( (type == 0)) { long newdp[][] = new long[dp1.length][dp1[0].length]; for ( int cnt = 1;(cnt <= x);cnt++) {for ( int j = 1;(j < dp1[0].length);j++) {if ( (j >= p)) {newdp[cnt][j] += dp1[(cnt - 1)][(j - p)]; newdp[cnt][j] %= mod; } }}for ( int cnt = 0;(cnt <= x);cnt++) {for ( int j = 0;(j < dp1[0].length);j++) {newdp[cnt][j] += dp1[cnt][j]; newdp[cnt][j] %= mod; }}dp1 = newdp; } }dp2[0][0][0] = 1; for ( int i = 0;(i < A.length);i++) { int p = A[i][0],type = A[i][1]; if ( (type != 0)) { long newdp[][][] = new long[dp2.length][dp2[0].length][dp2[0][0].length]; for ( int a = 0;(a < dp2.length);a++) {for ( int b = 0;(b < dp2[0].length);b++) {for ( int j = 0;(j < dp2[0][0].length);j++) {if ( (j >= p)) {if ( (type == 1)) {if ( ((a - 1) >= 0)) {newdp[a][b][j] += dp2[(a - 1)][b][(j - p)]; } } else {if ( ((b - 1) >= 0)) {newdp[a][b][j] += dp2[a][(b - 1)][(j - p)]; } }} newdp[a][b][j] %= mod; }}}for ( int a = 0;(a < dp2.length);a++) {for ( int b = 0;(b < dp2[0].length);b++) {for ( int j = 0;(j < dp2[0][0].length);j++) {newdp[a][b][j] += dp2[a][b][j]; newdp[a][b][j] %= mod; }}}dp2 = newdp; } }dp3[1][0][0][0] = 1; dp3[0][1][0][1] = 1; dp3[0][0][1][2] = 1; for ( int i = 0;(i < dp3.length);i++) {for ( int j = 0;(j < dp3[0].length);j++) {for ( int k = 0;(k < dp3[0][0].length);k++) {for ( x = 0;(x < dp3[0][0][0].length);x++) {if ( (dp3[i][j][k][x] == -1)) {dfs(i,j,k,x); } }}}}for ( int i = 0;(i < dp3.length);i++) {for ( int j = 0;(j < dp3[0].length);j++) {for ( int k = 0;(k < dp3[0][0].length);k++) {for ( int cur = 0;(cur < 3);cur++) {for ( int t = 0;(t <= T);t++) { int aprice = t;  int bcprice = (T - t);  long cnt1 = dp1[i][aprice];  long cnt2 = dp2[j][k][bcprice];  long combination = dp3[i][j][k][cur];  long p1 = ((cnt1 * f[i]) % mod);  long p2 = ((((f[j] * f[k]) % mod) * cnt2) % mod);  long p3 = ((p1 * p2) % mod); res += ((p3 * combination) % mod); res %= mod; }}}}}out.println(res); } public long dfs( int a, int b, int c, int cur){ if ( (((a < 0) || (b < 0)) || (c < 0))) {return 0;} if ( (((a == 0) && (b == 0)) && (c == 0))) {return 0;} if ( (dp3[a][b][c][cur] != -1)) return dp3[a][b][c][cur]; long res = 0; if ( (cur == 0)) {res += dfs((a - 1),b,c,1); res %= mod; res += dfs((a - 1),b,c,2); res %= mod; } else if ( (cur == 1)) {res += dfs(a,(b - 1),c,0); res %= mod; res += dfs(a,(b - 1),c,2); res %= mod; } else {res += dfs(a,b,(c - 1),0); res %= mod; res += dfs(a,b,(c - 1),1); res %= mod; }res %= mod; dp3[a][b][c][cur] = res; return res;} }
3	public class _909C{ int mod = ((int)1e9 + 7); public void solve()throws FileNotFoundException { InputStream inputStream = System.in;  InputHelper in = new InputHelper(inputStream);  int n = in.readInteger();  char[] a = new char[n]; for ( int i = 0;(i < n);i++) {a[i] = in.read().charAt(0); } int[][][] dp = new int[2][(n + 1)][2]; dp[0][0][0] = dp[0][0][1] = 1; for ( int i = 1;(i < n);i++) {for ( int j = n;(j >= 0);j--) {if ( (a[(i - 1)] == 's')) {dp[1][j][0] = dp[1][j][1] = dp[0][j][1]; } else {if ( (j > 0)) dp[1][j][0] = dp[1][j][1] = dp[0][(j - 1)][0]; }}for ( int j = 0;(j <= n);j++) {dp[0][j][0] = dp[1][j][0]; dp[0][j][1] = dp[1][j][1]; dp[1][j][0] = 0; dp[1][j][1] = 0; }for ( int j = (n - 1);(j >= 0);j--) {dp[0][j][1] += dp[0][(j + 1)][1]; dp[0][j][1] %= mod; }}System.out.println(dp[0][0][1]); } public static void main( String[] args)throws FileNotFoundException { new _909C().solve(); } class InputHelper{ StringTokenizer tokenizer = null; private BufferedReader bufferedReader ; public InputHelper( InputStream inputStream){ InputStreamReader inputStreamReader = new InputStreamReader(inputStream); bufferedReader = new BufferedReader(inputStreamReader,16384); } public String read(){ while(((tokenizer == null) || !tokenizer.hasMoreTokens())){try{ String line = bufferedReader.readLine(); if ( (line == null)) {return null;} tokenizer = new StringTokenizer(line); }catch (IOException e){ e.printStackTrace(); } }return tokenizer.nextToken();} public Integer readInteger(){ return Integer.parseInt(read());} } }
4	public class FireAgain implements Runnable{ private BufferedReader in ; private PrintWriter out ; private StringTokenizer tok ; private void solve()throws IOException { int n = nextInt(),m = nextInt();  int[][] sources = readIntMatrix(nextInt(),2);  int max = -1,maxI = 0,maxJ = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int min = Integer.MAX_VALUE; for ( int[] source :sources) { int dist = (abs((source[0] - i)) + abs((source[1] - j))); if ( (dist < min)) {min = dist; } }if ( (min > max)) {max = min; maxI = i; maxJ = j; } }}out.print((((maxI + 1) + " ") + (maxJ + 1))); } public static void main( String[] args){ new FireAgain().run(); } @Override public void run(){ try{in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new FileWriter("output.txt")); tok = null; solve(); in.close(); out.close(); }catch (IOException e){ System.exit(0); } } private String nextToken()throws IOException { while(((tok == null) || !tok.hasMoreTokens())){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(nextToken());} private int[][] readIntMatrix( int n, int m)throws IOException { int[][] mx = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {mx[i][j] = (nextInt() - 1); }}return mx;} }
6	public class Main{ static int MOD = 1000000007; void solve()throws IOException { int[] nT = ril(2);  int n = nT[0];  int T = nT[1];  int[][] tg = new int[n][]; for ( int i = 0;(i < n);i++) tg[i] = ril(2); int[][][] dp = new int[(T + 1)][(1 << n)][3]; for ( int ti = 1;(ti <= T);ti++) {for ( int mask = 1;(mask <= (1 << n));mask++) {for ( int j = 0;(j < n);j++) {if ( (((1 << j) & mask) == 0)) continue; int time = tg[j][0];  int genre = (tg[j][1] - 1); if ( ((ti - time) < 0)) continue; long base = dp[ti][mask][genre];  long add = 0; if ( ((ti - time) == 0)) {add = 1; } else {for ( int g = 0;(g < 3);g++) add += dp[(ti - time)][(mask ^ (1 << j))][g]; add -= dp[(ti - time)][(mask ^ (1 << j))][genre]; }dp[ti][mask][genre] = (int)((base + add) % MOD); }}} long ans = 0; for ( int g = 0;(g < 3);g++) ans += dp[T][((1 << n) - 1)][g]; pw.println((ans % MOD)); } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); public static void main( String[] args)throws IOException { Main m = new Main(); m.solve(); m.close(); } void close()throws IOException { pw.flush(); pw.close(); br.close(); } int[] ril( int n)throws IOException { int[] nums = new int[n];  int c = 0; for ( int i = 0;(i < n);i++) { int sign = 1; c = br.read(); int x = 0; if ( (c == '-')) {sign = -1; c = br.read(); } while(((c >= '0') && (c <= '9'))){x = (((x * 10) + c) - '0'); c = br.read(); }nums[i] = (x * sign); }while(((c != '\n') && (c != -1)))c = br.read(); return nums;} long[] rll( int n)throws IOException { long[] nums = new long[n];  int c = 0; for ( int i = 0;(i < n);i++) { int sign = 1; c = br.read(); long x = 0; if ( (c == '-')) {sign = -1; c = br.read(); } while(((c >= '0') && (c <= '9'))){x = (((x * 10) + c) - '0'); c = br.read(); }nums[i] = (x * sign); }while(((c != '\n') && (c != -1)))c = br.read(); return nums;} void sort( int[] A){ Random r = new Random(); for ( int i = (A.length - 1);(i > 0);i--) { int j = r.nextInt((i + 1));  int temp = A[i]; A[i] = A[j]; A[j] = temp; }Arrays.sort(A); } }
3	public final class py_indent{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static FastScanner sc = new FastScanner(br); static PrintWriter out = new PrintWriter(System.out); static Random rnd = new Random(); static int maxn = (int)(5e3 + 5); static long mod = (long)(1e9 + 7); static int add( long a, long b){ long ret = (a + b); if ( (ret >= mod)) {ret %= mod; } return (int)ret;} public static void main( String[] args)throws Exception { int n = sc.nextInt();  char[] a = new char[(n + 1)]; a[0] = 's'; for ( int i = 1;(i <= n);i++) {a[i] = sc.next().charAt(0); } int[][] dp = new int[(n + 1)][maxn],sum = new int[(n + 1)][maxn]; dp[0][0] = 1; sum[0][0] = 1; for ( int i = 1;(i < maxn);i++) {sum[0][i] = add(sum[0][i],sum[0][(i - 1)]); }for ( int i = 1;(i <= n);i++) {if ( (a[i] == 'f')) {continue;} int curr = 0,idx = 0; for ( int j = (i - 1);(j >= 0);j--) {if ( (a[j] == 's')) {idx = j; break;} else {curr++; }}for ( int j = 0;(j < maxn);j++) { int up = Math.max(0,(j - curr));  long now = (sum[idx][(maxn - 1)] - ((up == 0)?0:sum[idx][(up - 1)])); now = add(now,mod); dp[i][j] = add(dp[i][j],now); }sum[i][0] = dp[i][0]; for ( int j = 1;(j < maxn);j++) {sum[i][j] = add(dp[i][j],sum[i][(j - 1)]); }}out.println(dp[n][0]); out.close(); } } class FastScanner{ BufferedReader in ; StringTokenizer st ; public FastScanner( BufferedReader in){ this.in = in; } public String nextToken()throws Exception { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(in.readLine()); }return st.nextToken();} public String next()throws Exception { return nextToken().toString();} public int nextInt()throws Exception { return Integer.parseInt(nextToken());} }
1	public class TheyAreEverywhere{ static StringTokenizer st ; static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in),325678); static int[] id = new int[100000]; public static void main( String[] args)throws IOException { int n = in();  String s = next();  int total = 0;  int[] seq = new int[n];  boolean[] c = new boolean[100000]; for ( int i = 0;(i < n);i++) {seq[i] = s.charAt(i); if ( !c[seq[i]]) {total++; c[seq[i]] = true; } }Arrays.fill(id,-1); int best = Integer.MAX_VALUE;  TreeSet<Integer> q = new TreeSet<Integer>(new Comparator<Integer>(){}); for ( int i = 0;(i < n);i++) {q.remove(seq[i]); id[seq[i]] = i; q.add(seq[i]); if ( (q.size() == total)) {best = Math.min(best,((i - id[q.first()]) + 1)); } }System.out.println(best); } public static int in()throws IOException { return Integer.parseInt(next());} public static String next()throws IOException { if ( ((st == null) || !st.hasMoreTokens())) st = new StringTokenizer(bf.readLine()); return st.nextToken();} }
5	public class Solution{ BufferedReader in ; PrintWriter out ; StringTokenizer st ; boolean isCross( double l1, double r1, double l2, double r2){ double r = min(r1,r2);  double l = max(l1,l2); return (r > l);} boolean check( double xl, double xr, double[] l, double[] r, int n){ boolean ok = false; for ( int j = 0;(j < n);++j) ok |= isCross(xl,xr,l[j],r[j]); return ok;} void solve()throws IOException { int n = ni();  double t = ni();  double[] l = new double[n];  double[] r = new double[n]; for ( int i = 0;(i < l.length);i++) { double x = ni();  double len = ni(); l[i] = (x - (len / 2.0)); r[i] = (x + (len / 2.0)); } HashSet<Double> set = new HashSet<Double>(); for ( int i = 0;(i < n);++i) { double xl = (l[i] - t);  double xr = l[i];  boolean ok = check(xl,xr,l,r,n); if ( !ok) set.add(xl); xl = r[i]; xr = (r[i] + t); ok = check(xl,xr,l,r,n); if ( !ok) set.add(xl); }out.println(set.size()); } public Solution()throws IOException{ Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } String ns()throws IOException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(in.readLine()); }return st.nextToken();} int ni()throws IOException { return Integer.valueOf(ns());} public static void main( String[] args)throws IOException { new Solution(); } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } } class TaskC{ public void solve( int testNumber, InputReader in, PrintWriter out){ int N = in.nextInt();  int M = in.nextInt();  int K = in.nextInt();  int[][] dist = new int[(N + 1)][(M + 1)]; for ( int[] ini :dist) Arrays.fill(ini,(1 << 30)); int best = 0;  ArrayList<Integer> result = new ArrayList<Integer>();  Queue<Integer> q = new LinkedList<Integer>(); for ( int k = 0;(k < K);++k) { int x = in.nextInt();  int y = in.nextInt(); dist[x][y] = 0; q.offer(x); q.offer(y); } int[] dx = new int[]{1,-1,0,0};  int[] dy = new int[]{0,0,1,-1}; while(!q.isEmpty()){ int a = q.poll();  int b = q.poll(); for ( int r = 0;(r < 4);++r) { int x = (a + dx[r]);  int y = (b + dy[r]); if ( (((((x >= 1) && (x <= N)) && (y >= 1)) && (y <= M)) && (dist[x][y] > (dist[a][b] + 1)))) {dist[x][y] = (dist[a][b] + 1); q.offer(x); q.offer(y); } }}for ( int i = 1;(i <= N);++i) for ( int j = 1;(j <= M);++j) best = Math.max(best,dist[i][j]); for ( int a = 1;(a <= N);++a) for ( int b = 1;(b <= M);++b) if ( (dist[a][b] == best)) {result.add(a); result.add(b); } if ( (result.size() > 0)) {out.print(((result.get(0) + " ") + result.get(1))); } out.println(); } } 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());} }
1	public class Main{ final boolean ONLINE_JUDGE = new File("input.txt").exists(); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { if ( ONLINE_JUDGE) {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"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new Main().run(); } public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println(("Time = " + (t2 - t1))); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } long modulo = (((1000 * 1000) * 1000) + 7); long binPow( long a, long b){ if ( (b == 0)) return 1; long c = binPow(a,(b / 2));  long ans = ((c * c) % modulo); if ( ((b % 2) == 1)) ans = ((ans * a) % modulo); return ans;} int[] gcd( int a, int b){ int[] res = new int[3]; if ( (a == 0)) {res[0] = b; res[1] = 0; res[2] = -1; return res;} res = gcd((b % a),a); int x = (res[2] + ((b / a) * res[1]));  int y = -res[1]; res[1] = x; res[2] = y; return res;} public void solve()throws IOException { int n = readInt();  HashMap<Character,Integer> mapa = new HashMap<>();  char[] s = readString().toCharArray(); for ( int i = 0;(i < n);i++) {if ( mapa.containsKey(s[i])) { int x = mapa.get(s[i]); mapa.replace(s[i],(x + 1)); } else mapa.put(s[i],1); } int sz = mapa.size(); mapa = new HashMap<>(); int i = 0; while((mapa.size() < sz)){if ( mapa.containsKey(s[i])) { int x = mapa.get(s[i]); mapa.replace(s[i],(x + 1)); } else mapa.put(s[i],1); i++; } int ans = i;  int left = 0;  int right = (i - 1); while((right < n)){while((left < right)){ int y = mapa.get(s[left]); if ( (y == 1)) mapa.remove(s[left]); else mapa.replace(s[left],(y - 1)); if ( (mapa.size() == sz)) {ans = Math.min(ans,(right - left)); left++; } else {left++; break;}}right++; if ( (right < n)) {if ( mapa.containsKey(s[right])) { int x = mapa.get(s[right]); mapa.replace(s[right],(x + 1)); } else mapa.put(s[right],1); } }out.print(ans); } }
2	public class Main implements Runnable{ int n ; boolean inBound( int x, int y){ return ((((x >= 1) && (y >= 1)) && (x <= n)) && (y <= n));} void solve()throws Exception { n = sc.nextInt(); int y = sc.nextInt();  int x = sc.nextInt();  int c = sc.nextInt();  int yu = y;  int yd = y;  int xl = x;  int xr = x;  int current = 1;  int time = 0; while((current < c)){time++; yu--; yd++; xl--; xr++; { int cur = (time - 1); if ( (yu < 1)) {cur -= yu; } if ( (xl < 1)) {cur -= xl; } if ( (cur > 0)) {current += cur; } }{ int cur = (time - 1); if ( (yu < 1)) {cur -= yu; } if ( (xr > n)) {cur -= ((xr - n) - 1); } if ( (cur > 0)) {current += cur; } }{ int cur = (time - 1); if ( (yd > n)) {cur -= ((yd - n) - 1); } if ( (xl < 1)) {cur -= xl; } if ( (cur > 0)) {current += cur; } }{ int cur = (time - 1); if ( (yd > n)) {cur -= ((yd - n) - 1); } if ( (xr > n)) {cur -= ((xr - n) - 1); } if ( (cur > 0)) {current += cur; } }if ( inBound(x,yd)) current++; if ( inBound(x,yu)) current++; if ( inBound(xl,y)) current++; if ( inBound(xr,y)) current++; }out.println(time); } BufferedReader in ; PrintWriter out ; FastScanner sc ; static Throwable uncaught ; public static void main( String[] args)throws Throwable { Thread t = new Thread(null,new Main(),"",(1 << 26)); t.start(); t.join(); if ( (uncaught != null)) {throw (uncaught);} } } class FastScanner{ BufferedReader reader ; StringTokenizer strTok ; public FastScanner( BufferedReader reader){ this.reader = reader; } public String nextToken()throws IOException { while(((strTok == null) || !strTok.hasMoreTokens())){strTok = new StringTokenizer(reader.readLine()); }return strTok.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
4	public class P35C{ public static void main( String[] args)throws FileNotFoundException { InputStream inputStream = new FileInputStream("input.txt");  OutputStream outputStream = new FileOutputStream("output.txt");  InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  Task solver = new Task(); solver.solve(in,out); out.close(); } static class Task{ private class Point{ int x ,y ; public Point( int x, int y){ this.x = x; this.y = y; } } private int dis( int i, int j, Point p2){ return (Math.abs((i - p2.x)) + Math.abs((j - p2.y)));} public void solve( InputReader in, PrintWriter out){ int n = in.nextInt(),m = in.nextInt();  int k = in.nextInt();  Point[] ps = new Point[k]; for ( int i = 0;(i < k);i++) {ps[i] = new Point((in.nextInt() - 1),(in.nextInt() - 1)); } int max = 0;  Point argmax = ps[0]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int val = dis(i,j,ps[0]); for ( int l = 1;(l < k);l++) {val = Math.min(val,dis(i,j,ps[l])); }if ( (val > max)) {max = val; argmax = new Point(i,j); } }}out.println((((argmax.x + 1) + " ") + (argmax.y + 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 int nextInt(){ return Integer.parseInt(next());} } }
6	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;(t < T);t++) { int n = Int();  int m = Int();  int A[][] = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {A[i][j] = Int(); }} Sol sol = new Sol(); sol.solution(out,A); }out.flush(); } public static int Int(){ return fs.Int();} public static long Long(){ return fs.Long();} public static String Str(){ return fs.Str();} } class Sol{ int dif[][] ; int dp[][][] ; public void solution( PrintWriter out, int[][] A){ int n = A.length;  int m = A[0].length;  int res = 0; dif = new int[n][n]; for ( int i = 0;(i < n);i++) {for ( int j = (i + 1);(j < A.length);j++) { int mn = Integer.MAX_VALUE; for ( int k = 0;(k < m);k++) {mn = Math.min(mn,Math.abs((A[i][k] - A[j][k]))); }dif[i][j] = mn; dif[j][i] = mn; }} int state = ((1 << n) - 1); dp = new int[(state + 5)][(n + 1)][(n + 1)]; for ( int i = 0;(i < dp.length);i++) {for ( int j = 0;(j < dp[0].length);j++) {Arrays.fill(dp[i][j],-1); }}for ( int i = 0;(i < n);i++) {res = Math.max(res,dfs(A,(state ^ (1 << i)),i,i)); }out.println(res); } public int dfs( int[][] A, int state, int pre, int start){ if ( (state == 0)) { int mn = Integer.MAX_VALUE; for ( int i = 1;(i < A[0].length);i++) {mn = Math.min(mn,Math.abs((A[start][i] - A[pre][(i - 1)]))); }return mn;} if ( (dp[state][pre][start] != -1)) {return dp[state][pre][start];} int res = 0; for ( int i = 0;(i < A.length);i++) {if ( ((state & (1 << i)) != 0)) { int di = dif[pre][i]; res = Math.max(res,Math.min(di,dfs(A,(state ^ (1 << i)),i,start))); } }dp[state][pre][start] = res; return res;} }
1	public class Main{ public static void main( String[] args){ Scanner in = new Scanner(new BufferedInputStream(System.in));  int n = in.nextInt();  char b[] = in.next().toCharArray();  int bb[] = new int[b.length];  int Mark[] = new int[((26 * 2) + 1)];  int Mark1[] = new int[((26 * 2) + 1)];  int ans = 0; for ( int i = 0;(i < b.length);i++) { char f = b[i];  int a ; if ( ((f >= 'a') && (f <= 'z'))) a = (f - 'a'); else a = ((f - 'A') + 26); bb[i] = a; if ( (Mark1[a] == 0)) {ans++; Mark1[a] = 1; } } int i ;  int L = 0,nowsum = 0,Ans = n,R = 0; for ( i = 0;(i < n);i++) {if ( (Mark[bb[i]] == 0)) nowsum++; Mark[bb[i]]++; if ( (nowsum == ans)) {R = i; break;} }Ans = ((R - L) + 1); for ( i = L;(i < n);i++) {if ( (Mark == 0)) { int ok = 0; for ( int j = (R + 1);(j < n);j++) {Mark[bb[j]]++; if ( (bb[j] == bb[i])) {ok = 1; R = j; break;} }if ( (ok == 0)) break; } if ( (Ans > (R - i))) Ans = (R - i); }System.out.println(Ans); } }
6	public class realfast implements Runnable{ static private final int INF = (int)1e9; int time[] = new int[15]; int g[] = new int[15]; public void solve()throws IOException { int n = readInt();  int t = readInt(); for ( int i = 0;(i < n);i++) {time[i] = readInt(); g[i] = readInt(); } long dp[][] = new long[(int)Math.pow(2,n)][4]; for ( int i = 0;(i < (int)Math.pow(2,n));i++) {for ( int j = 0;(j <= 3);j++) dp[i][j] = -1; } long val = cal(dp,0,0,0,t); out.println(val); } public long cal( long[][] dp, int mask, int genre, int t, int T){ int val = dp.length; if ( (t > T)) {return 0;} if ( (t == T)) {return 1;} if ( (dp[mask][genre] != -1)) return dp[mask][genre]; dp[mask][genre] = 0; int i = 1;  int count = 0; while((i < val)){if ( (((i & mask) == 0) && (g[count] != genre))) {dp[mask][genre] = (((dp[mask][genre] % 1000000007) + (cal(dp,(mask | i),g[count],(t + time[count]),T) % 1000000007)) % 1000000007); } i = (2 * i); count++; }return dp[mask][genre];} public static void main( String[] args){ new Thread(null,new realfast(),"",(128 * (1L << 20))).start(); } static private final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); private BufferedReader reader ; private StringTokenizer tokenizer ; private PrintWriter out ; private String readString()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} @SuppressWarnings private int readInt()throws IOException { return Integer.parseInt(readString());} }
1	public class IQTest{ public static void main( String[] args){ try{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  String str = in.readLine();  int n = Integer.parseInt(str);  int odd = -1,even = -1,odds = 0,evens = 0; str = in.readLine(); String[] numbers = str.split(" ");  int index = 1; for ( String number :numbers) { int i = Integer.parseInt(number); if ( ((i % 2) == 0)) {++evens; if ( (even == -1)) even = index; } else {++odds; if ( (odd == -1)) odd = index; }++index; }System.out.println(((evens > odds)?odd:even)); }catch (Exception e){ e.printStackTrace(); } } }
6	public class F531{ public static void main( String[] args){ MyScanner sc = new MyScanner();  PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));  int n = sc.nextInt();  int m = sc.nextInt();  long[][] mn1 = new long[n][n];  long[][] mn2 = new long[n][n];  long[][] grid = new long[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) grid[i][j] = sc.nextInt(); }if ( (n == 1)) { long ans = Integer.MAX_VALUE; for ( int i = 0;(i < (m - 1));i++) ans = Math.min(ans,Math.abs((grid[0][i] - grid[0][(i + 1)]))); out.println(ans); out.close(); return ;} for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( (i == j)) continue; long min = Long.MAX_VALUE; for ( int k = 0;(k < m);k++) min = Math.min(min,Math.abs((grid[i][k] - grid[j][k]))); mn1[i][j] = min; }}for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( (i == j)) continue; long min = Long.MAX_VALUE; for ( int k = 0;(k < (m - 1));k++) min = Math.min(min,Math.abs((grid[i][k] - grid[j][(k + 1)]))); mn2[i][j] = min; }} long[][] dp = new long[(1 << n)][n];  long ans = 0; for ( int i = 0;(i < n);i++) {for ( long[] a :dp) Arrays.fill(a,-1); for ( int j = 0;(j < n);j++) {if ( (j == i)) dp[(1 << j)][j] = Long.MAX_VALUE; else dp[(1 << j)][j] = 0; }for ( int mask = 1;(mask < (1 << n));mask++) {for ( int last = 0;(last < n);last++) {if ( (dp[mask][last] != -1)) continue; for ( int prev = 0;(prev < n);prev++) {if ( (prev == last)) continue; if ( (((mask >> prev) & 1) == 1)) {dp[mask][last] = Math.max(dp[mask][last],Math.min(mn1[prev][last],dp[(mask ^ (1 << last))][prev])); } }}}for ( int j = 0;(j < n);j++) { long end = mn2[j][i]; ans = Math.max(ans,Math.min(dp[((1 << n) - 1)][j],end)); }}out.println(ans); out.close(); } 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());} } }
6	public class Main{ static final long MOD = 1_000_000_007,INF = 1_000_000_000_000_000_000L; static final int INf = 1_000_000_000; static FastReader reader ; static PrintWriter writer ; public static void main( String[] args){ Thread t = new Thread(null,new O(),"Integer.MAX_VALUE",100000000); t.start(); } static class O implements Runnable{ } static class FastReader{ private final int BUFFER_SIZE = (1 << 16); private DataInputStream din ; private byte[] buffer ; private int bufferPointer ,bytesRead ; public FastReader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastReader( String file_name)throws IOException{ din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt()throws IOException { int ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} private void fillBuffer()throws IOException { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } private byte read()throws IOException { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} public void close()throws IOException { if ( (din == null)) return ; din.close(); } } static int n ,m ,pre[][] ,pre_stop_and_start[][] ,mat[][] ,dp[][][] ; static void magic()throws IOException { reader = new FastReader(); writer = new PrintWriter(System.out,true); n = reader.nextInt(); m = reader.nextInt(); mat = new int[n][m]; for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < m);++j) {mat[i][j] = reader.nextInt(); }}if ( (n == 1)) { int ans = Integer.MAX_VALUE; for ( int i = 0;((i + 1) < m);++i) {ans = min(ans,abs((mat[0][i] - mat[0][(i + 1)]))); }writer.println(ans); System.exit(0); } pre = new int[n][n]; pre_stop_and_start = new int[n][n]; for ( int i = 0;(i < n);++i) {for ( int j = (i + 1);(j < n);++j) { int min = Integer.MAX_VALUE; for ( int k = 0;(k < m);++k) {min = min(min,abs((mat[i][k] - mat[j][k]))); }pre[i][j] = pre[j][i] = min; }}for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < n);++j) {if ( (j == i)) {continue;} int min = Integer.MAX_VALUE; for ( int k = 0;((k + 1) < m);++k) {min = min(min,abs((mat[j][(k + 1)] - mat[i][k]))); }pre_stop_and_start[i][j] = min; }}dp = new int[(1 << n)][n][n]; for ( int i = 0;(i < (1 << n));++i) {for ( int j = 0;(j < n);++j) {for ( int k = 0;(k < n);++k) {dp[i][j][k] = -1; }}} int ans = 0; for ( int i = 0;(i < n);++i) {ans = max(ans,f((1 << i),i,i)); }writer.println(ans); } static int f( int mask_already, int prev, int first){ if ( (mask_already == ((1 << n) - 1))) {return pre_stop_and_start[prev][first];} if ( (dp[mask_already][prev][first] != -1)) {return dp[mask_already][prev][first];} int max = 0; for ( int i = 0;(i < n);++i) {if ( ((mask_already & (1 << i)) == 0)) {max = max(max,min(pre[prev][i],f((mask_already | (1 << i)),i,first))); } }return dp[mask_already][prev][first] = max;} }
6	public class f{ static int n ,m ; static int start ; static int[][] memo ; static int[][] arr ; static int[][] costs ; static int[][] wrapCosts ; public static void main( String[] args)throws IOException { FastScanner in = new FastScanner(System.in);  PrintWriter out = new PrintWriter(System.out); n = in.nextInt(); m = in.nextInt(); arr = new int[n][m]; costs = new int[n][n]; wrapCosts = new int[n][n]; for ( int r = 0;(r < n);r++) {for ( int c = 0;(c < m);c++) {arr[r][c] = in.nextInt(); }}for ( int i = 0;(i < n);i++) {for ( int j = (i + 1);(j < n);j++) {costs[i][j] = Integer.MAX_VALUE; for ( int c = 0;(c < m);c++) {costs[i][j] = Math.min(costs[i][j],Math.abs((arr[i][c] - arr[j][c]))); }costs[j][i] = costs[i][j]; }}for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {wrapCosts[i][j] = Integer.MAX_VALUE; for ( int c = 0;(c < (m - 1));c++) {wrapCosts[i][j] = Math.min(wrapCosts[i][j],Math.abs((arr[i][(c + 1)] - arr[j][c]))); }}}memo = new int[n][(1 << n)]; long best = 0; for ( start = 0;(start < n);start++) {for ( int[] a :memo) Arrays.fill(a,-1); best = Math.max(best,go(start,(((1 << n) - 1) - (1 << start)))); }out.println(best); out.close(); } static int go( int cur, int mask){ if ( (mask == 0)) {return wrapCosts[start][cur];} if ( (memo[cur][mask] != -1)) return memo[cur][mask]; int ans = 0; for ( int next = 0;(next < n);next++) { int bit = (1 << next); if ( ((mask & bit) == 0)) continue; ans = Math.max(ans,Math.min(costs[cur][next],go(next,(mask ^ bit)))); }return memo[cur][mask] = ans;} static class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner( InputStream i){ br = new BufferedReader(new InputStreamReader(i)); st = new StringTokenizer(""); } public String next()throws IOException { if ( st.hasMoreTokens()) return st.nextToken(); else st = new StringTokenizer(br.readLine()); return next();} public int nextInt()throws IOException { return Integer.parseInt(next());} } }
4	public class FireAgain{ public static void main( String[] args)throws IOException { BufferedReader readData = new BufferedReader(new FileReader("input.txt"));  PrintWriter writer = new PrintWriter(new File("output.txt"));  String line = readData.readLine();  String[] temp = line.split(" ");  int n = Integer.valueOf(temp[0]);  int m = Integer.valueOf(temp[1]);  int x = 0,y = 0; line = readData.readLine(); int k = Integer.valueOf(line);  boolean[][] visited = new boolean[(n + 1)][(m + 1)];  Queue<Integer> qX = new LinkedList<Integer>();  Queue<Integer> qY = new LinkedList<Integer>(); line = readData.readLine(); String[] temp2 = line.split(" "); for ( int i = 0;(i < (temp2.length - 1));i += 2) {x = Integer.valueOf(temp2[i]); y = Integer.valueOf(temp2[(i + 1)]); visited[x][y] = true; qX.add(x); qY.add(y); }while(!qX.isEmpty()){x = qX.poll(); y = qY.poll(); if ( ((x >= 2) && !visited[(x - 1)][y])) {visited[(x - 1)][y] = true; qX.add((x - 1)); qY.add(y); } if ( (((x + 1) <= n) && !visited[(x + 1)][y])) {visited[(x + 1)][y] = true; qX.add((x + 1)); qY.add(y); } if ( ((y >= 2) && !visited[x][(y - 1)])) {visited[x][(y - 1)] = true; qX.add(x); qY.add((y - 1)); } if ( (((y + 1) <= m) && !visited[x][(y + 1)])) {visited[x][(y + 1)] = true; qX.add(x); qY.add((y + 1)); } }writer.write((x + " ")); writer.write((y + " ")); writer.close(); } }
3	public class code5{ InputStream is ; PrintWriter out ; static long mod = (pow(10,9) + 7); static int dx[] = {0,0,1,-1},dy[] = {1,-1,0,0}; String arr[] ; long dp[][] ; void solve()throws IOException { int n = ni(); arr = new String[n]; for ( int i = 0;(i < n);i++) arr[i] = ns(); dp = new long[(n + 1)][(n + 1)]; dp[0][0] = 1; for ( int i = 0;(i < n);i++) { long next[] = new long[(n + 1)]; for ( int j = 0;(j <= i);j++) {if ( (arr[i].charAt(0) == 's')) {next[0] += dp[i][j]; next[(j + 1)] -= dp[i][j]; } else {next[(j + 1)] += dp[i][j]; next[(j + 2)] -= dp[i][j]; }} long count = 0; for ( int j = 0;(j < n);j++) {count += next[j]; count = ((count + mod) % mod); dp[(i + 1)][j] = count; }} long ans = 0; for ( int i = 0;(i < n);i++) {ans += dp[(n - 1)][i]; ans %= mod; }out.print(ans); } long rec( int index, int level){ if ( (index >= (arr.length - 1))) return 1; if ( (dp[index][level] != -1)) return dp[index][level]; dp[index][level] = 0; if ( (arr[index].charAt(0) == 's')) {dp[index][level] += rec((index + 1),level); dp[index][level] %= mod; if ( (level > 0)) {dp[index][level] += rec((index + 1),0); dp[index][level] %= mod; } } else {dp[index][level] += rec((index + 1),(level + 1)); dp[index][level] %= mod; }return dp[index][level];} double a[] ,b[] ,p ; ArrayList<Integer> al[] ; static long d ,x ,y ; void extendedEuclid( long A, long B){ if ( (B == 0)) {d = A; x = 1; y = 0; } else {extendedEuclid(B,(A % B)); long temp = x; x = y; y = (temp - ((A / B) * y)); }} public static void mergeSort( int[] arr, int l, int r){ if ( ((r - l) >= 1)) { int mid = ((l + r) / 2); mergeSort(arr,l,mid); mergeSort(arr,(mid + 1),r); merge(arr,l,r,mid); } } public static void merge( int[] arr, int l, int r, int mid){ int n1 = ((mid - l) + 1),n2 = (r - mid);  int left[] = new int[n1];  int right[] = new int[n2]; for ( int i = 0;(i < n1);i++) left[i] = arr[(l + i)]; for ( int i = 0;(i < n2);i++) right[i] = arr[((mid + 1) + i)]; int i = 0,j = 0,k = l; while(((i < n1) && (j < n2))){if ( (left[i] > right[j])) {arr[k++] = right[j++]; } else {arr[k++] = left[i++]; }}while((i < n1))arr[k++] = left[i++]; while((j < n2))arr[k++] = right[j++]; } public static void mergeSort( long[] arr, int l, int r){ if ( ((r - l) >= 1)) { int mid = ((l + r) / 2); mergeSort(arr,l,mid); mergeSort(arr,(mid + 1),r); merge(arr,l,r,mid); } } public static void merge( long[] arr, int l, int r, int mid){ int n1 = ((mid - l) + 1),n2 = (r - mid);  long left[] = new long[n1];  long right[] = new long[n2]; for ( int i = 0;(i < n1);i++) left[i] = arr[(l + i)]; for ( int i = 0;(i < n2);i++) right[i] = arr[((mid + 1) + i)]; int i = 0,j = 0,k = l; while(((i < n1) && (j < n2))){if ( (left[i] > right[j])) {arr[k++] = right[j++]; } else {arr[k++] = left[i++]; }}while((i < n1))arr[k++] = left[i++]; while((j < n2))arr[k++] = right[j++]; } public static long gcd( long x, long y){ if ( (y == 0)) return x; else return gcd(y,(x % y));} public static int gcd( int x, int y){ if ( (y == 0)) return x; return gcd(y,(x % y));} public static long gcdExtended( long a, long b, long[] x){ if ( (a == 0)) {x[0] = 0; x[1] = 1; return b;} long[] y = new long[2];  long gcd = gcdExtended((b % a),a,y); x[0] = (y[1] - ((b / a) * y[0])); x[1] = y[0]; return gcd;} public static int abs( int a, int b){ return (int)Math.abs((a - b));} public static long abs( long a, long b){ return (long)Math.abs((a - b));} public static long pow( long n, long p, long m){ long result = 1; if ( (p == 0)) return 1; if ( (p == 1)) return n; while((p != 0)){if ( ((p % 2) == 1)) result *= n; if ( (result >= m)) result %= m; p >>= 1; n *= n; if ( (n >= m)) n %= m; }return result;} public static long pow( long n, long p){ long result = 1; if ( (p == 0)) return 1; if ( (p == 1)) return n; while((p != 0)){if ( ((p % 2) == 1)) result *= n; p >>= 1; n *= n; }return result;} void run()throws Exception { is = System.in; out = new PrintWriter(System.out); solve(); out.flush(); } public static void main( String[] args)throws Exception { new Thread(null,new Runnable(){public void run(){ try{new code5().run(); }catch (Exception e){ e.printStackTrace(); } } },"1",(1 << 26)).start(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0,ptrbuf = 0; 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++];} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private long[] nl( int n){ long[] a = new long[n]; for ( int i = 0;(i < n);i++) a[i] = nl(); return a;} private int ni(){ 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(); }} private long nl(){ long num = 0;  int 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(); }} }
1	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();  String word = in.next();  int cnt[] = new int[1000];  int let = 0;  Set<Character> set = new TreeSet<>(); for ( int i = 0;(i < word.length());i++) {set.add(word.charAt(i)); } int uniq = set.size();  int i = 0,j = -1;  int ans = Integer.MAX_VALUE; while(((i < N) && (j < N))){while((((j + 1) < N) && (let < uniq))){j++; if ( (cnt[word.charAt(j)] == 0)) {let++; } cnt[word.charAt(j)]++; }if ( (let == uniq)) ans = Math.min(ans,((j - i) + 1)); cnt[word.charAt(i)]--; if ( (cnt[word.charAt(i)] == 0)) let--; i++; }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());} } }
0	public class program{ public static void main( String[] args)throws Exception { Scanner sc = new Scanner(System.in);  int n = sc.nextInt(); if ( (n == 0)) {System.out.println("0 0 0"); return ;} else if ( (n == 1)) {System.out.println("0 0 1"); return ;} else if ( (n == 2)) {System.out.println("0 1 1"); return ;} else { int ppp = 0;  int pp = 1;  int c = 2; while(true){if ( (((ppp + pp) + c) == n)) {System.out.println(((((ppp + " ") + pp) + " ") + c)); return ;} else {c = ((c + pp) + ppp); int temp = pp; pp = (pp + ppp); ppp = temp; }}}} }
2	public class ProblemB{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out)); long[] readInts()throws IOException { String[] strings = reader.readLine().split(" ");  long[] ints = new long[strings.length]; for ( int i = 0;(i < ints.length);i++) {ints[i] = Long.parseLong(strings[i]); }return ints;} long foo( long a){ return ((a > 0)?(a * a):0);} long boo( long a){ return ((a <= 0)?0:((a * (a + 1)) / 2));} void solve()throws IOException { long[] tt = readInts();  long n = tt[0];  long x = tt[1];  long y = tt[2];  long c = tt[3];  long lo = -1,hi = ((((2 * 1000) * 1000) * 1000) + 2); while(((hi - lo) > 1)){ long m = ((lo + hi) / 2);  long s = ((((2 * m) * m) + (2 * m)) + 1); s -= (((foo(((m - x) + 1)) + foo(((m - y) + 1))) + foo(((x + m) - n))) + foo(((y + m) - n))); s += (((boo(((m + 1) - (((((n + 1) + n) + 1) - x) - y))) + boo(((m + 1) - (((n + 1) - x) + y)))) + boo(((m + 1) - (((n + 1) - y) + x)))) + boo(((m + 1) - (x + y)))); if ( (s < c)) lo = m; else hi = m; }writer.println(hi); writer.flush(); } public static void main( String[] args)throws IOException { new ProblemB().solve(); } }
6	public class G1_PlaylistForPolycarp{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader inp = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  Solver solver = new Solver(); solver.solve(inp,out); out.close(); } static private class Solver{ private void solve( InputReader inp, PrintWriter out){ int n = inp.nextInt(),t = inp.nextInt();  int[][] tracks = new int[n][2];  long MOD = 1000000007; for ( int i = 0;(i < n);i++) {tracks[i][0] = inp.nextInt(); tracks[i][1] = (inp.nextInt() - 1); } long[][] dp = new long[(2 << n)][4]; dp[0][3] = 1; int curr = 1; while((curr <= n)){ int mask = 0; for ( int i = 0;(i < curr);i++) mask |= (1 << i); while((mask < (2 << n))){for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) != 0)) {for ( int j = 0;(j < 4);j++) {if ( (j == tracks[i][1])) continue; dp[mask][tracks[i][1]] += dp[(mask - (1 << i))][j]; }} }mask = nextNumberXBits(mask); }curr++; } long res = 0; for ( int i = 0;(i < (2 << n));i++) { int time = 0; for ( int j = 0;(j < n);j++) {if ( ((i & (1 << j)) != 0)) time += tracks[j][0]; }if ( (time == t)) {for ( int j = 0;(j < 4);j++) {res += dp[i][j]; }res %= MOD; } }out.print(res); } static private int nextNumberXBits( int mask){ int c = (mask & -mask);  int r = (mask + c); return ((((r ^ mask) >> 2) / c) | r);} } static class InputReader{ BufferedReader reader ; StringTokenizer tokenizer ; 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());} } }
1	public class C{ public static void main( String[] args)throws IOException { File inputFile = new File("entradaC"); if ( inputFile.exists()) System.setIn(new FileInputStream(inputFile));  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  StringBuilder out = new StringBuilder();  String line = ""; while(((line = in.readLine()) != null)){ int n = Integer.parseInt(line);  char[] p = in.readLine().toCharArray();  HashMap<Character,Integer> dif = new HashMap<>(); for ( int i = 0;(i < p.length);i++) dif.put(p[i],0); int ndif = dif.size();  int head = 0,tail = 0,cnt = 0,ans = Integer.MAX_VALUE,cur ; while((head < n)){cur = dif.get(p[head]); if ( (cur == 0)) cnt++; dif.put(p[head],(cur + 1)); head++; if ( (cnt == ndif)) ans = Math.min(ans,(head - tail)); while(((tail < head) && (cnt == ndif))){cur = dif.get(p[tail]); if ( (cur == 1)) cnt--; dif.put(p[tail],(cur - 1)); tail++; if ( (cnt == ndif)) ans = Math.min(ans,(head - tail)); }}if ( (ndif == 1)) ans = 1; out.append((ans + "\n")); }System.out.print(out); } }
4	public class CodeForces{ public static void main( String[] args)throws FileNotFoundException { FastIO io = new FastIO();  int width = io.nextInt();  int height = io.nextInt();  int initials = io.nextInt();  boolean[][] visited = new boolean[width][height];  Queue<Coordinate> q = new ArrayDeque<>(); for ( int i = 0;(i < initials);i++) {q.add(new Coordinate((io.nextInt() - 1),(io.nextInt() - 1))); } Coordinate oneOfLast = null; while(!q.isEmpty()){ int len = q.size(); for ( int times = 0;(times < len);times++) { Coordinate c = q.poll(); if ( visited[c.x][c.y]) {continue;} oneOfLast = c; visited[c.x][c.y] = true; int[][] deltas = new int[][]{{-1,0},{0,-1},{1,0},{0,1}}; for ( int[] delta :deltas) { int ci = (c.y + delta[0]);  int cj = (c.x + delta[1]); if ( ((((ci >= 0) && (cj >= 0)) && (ci < height)) && (cj < width))) {q.add(new Coordinate(cj,ci)); } }}}io.println((((oneOfLast.x + 1) + " ") + (oneOfLast.y + 1))); io.close(); } static class Coordinate{ int x ; int y ; public Coordinate( int x, int y){ this.x = x; this.y = y; } } static class FastIO extends PrintWriter{ BufferedReader br ; StringTokenizer st ; public FastIO()throws FileNotFoundException{ super(new BufferedOutputStream(new FileOutputStream("output.txt"))); br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } 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());} String nextToken(){ while(((st == null) || !st.hasMoreElements())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } }return st.nextToken();} } }
6	public class Main{ static long dp[][][][] = new long[16][16][16][4]; static void ini(){ for ( int i = 0;(i < 16);i++) {for ( int j = 0;(j < 16);j++) {for ( int k = 0;(k < 16);k++) {for ( int l = 0;(l < 4);l++) {dp[i][j][k][l] = -1L; }}}}} static int chk( long i){ if ( (i == 0L)) return 1; else return 0;} static long f( long a, long b, long c, int taken){ int got = (int)((a + b) + c);  int have = ((chk(a) + chk(b)) + chk(c)); if ( (have == 2)) {if ( (got == 1)) return 1L; else return 0L;} if ( (dp[(int)a][(int)b][(int)c][taken] != -1)) {return dp[(int)a][(int)b][(int)c][taken];} long ans = 0L; if ( (taken == 0)) {if ( (a != 0)) ans += ((a * f((a - 1),b,c,1)) % mod); ans %= mod; if ( (b != 0)) ans += ((b * f(a,(b - 1),c,2)) % mod); ans %= mod; if ( (c != 0)) ans += ((c * f(a,b,(c - 1),3)) % mod); ans %= mod; } else {ans += ((((taken == 1) || (a == 0))?0L:((a * f((a - 1),b,c,1)) % mod)) % mod); ans %= mod; ans += ((((taken == 2) || (b == 0))?0L:((b * f(a,(b - 1),c,2)) % mod)) % mod); ans %= mod; ans += ((((taken == 3) || (c == 0))?0L:((c * f(a,b,(c - 1),3)) % mod)) % mod); ans %= mod; }dp[(int)a][(int)b][(int)c][taken] = ans; return ans;} public static void main( String[] args){ InputReader in = new InputReader(System.in);  PrintWriter pw = new PrintWriter(System.out);  int n = in.nextInt();  int total = in.nextInt();  int t[] = new int[n];  int g[] = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = in.nextInt(); g[i] = in.nextInt(); } long ans = 0L; for ( int i = 0;(i < (1 << n));i++) { int sum = 0;  int a[] = new int[4]; for ( int j = 0;(j < n);j++) {if ( (((i >> j) & 1) == 1)) {sum += t[j]; a[g[j]]++; } }if ( (sum == total)) {ini(); ans = ((ans + f(a[1],a[2],a[3],0)) % mod); } }pw.println(ans); pw.flush(); pw.close(); } static class InputReader{ private final InputStream stream ; private final byte[] buf = new byte[8192]; private int curChar ,snumChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int snext(){ if ( (snumChars == -1)) throw (new InputMismatchException()); if ( (curChar >= snumChars)) {curChar = 0; try{snumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (snumChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } public static long mod = 1000000007; public static int d ; public static int p ; public static int q ; public static int GCD( int a, int b){ if ( (b == 0)) return a; else return GCD(b,(a % b));} public static long GCD( long a, long b){ if ( (b == 0)) return a; else return GCD(b,(a % b));} public static void extendedEuclid( int A, int B){ if ( (B == 0)) {d = A; p = 1; q = 0; } else {extendedEuclid(B,(A % B)); int temp = p; p = q; q = (temp - ((A / B) * q)); }} public static int modularExponentiation( int x, int n, int M){ int result = 1; while((n > 0)){if ( ((n % 2) == 1)) result = ((result * x) % M); x = (((x % M) * x) % M); n = (n / 2); }return result;} public static long modularExponentiation( long x, long n, long M){ long result = 1; while((n > 0)){if ( ((n % 2) == 1)) result = ((((result % M) * x) % M) % M); x = ((((x % M) * x) % M) % M); n = (n / 2); }return result;} }
2	public class Solution{ static long n ,x ,y ,c ; static boolean can( long len){ BigInteger blen = BigInteger.valueOf(len);  BigInteger sum = BigInteger.ONE; sum = sum.add(blen.multiply(blen.add(BigInteger.ONE)).shiftLeft(1)); long a1 = Math.max(0,(len - x)); sum = sum.subtract(BigInteger.valueOf(a1).multiply(BigInteger.valueOf(a1))); long a2 = Math.max(0,(len - y)); sum = sum.subtract(BigInteger.valueOf(a2).multiply(BigInteger.valueOf(a2))); long a3 = Math.max(0,(len - ((n - 1) - x))); sum = sum.subtract(BigInteger.valueOf(a3).multiply(BigInteger.valueOf(a3))); long a4 = Math.max(0,(len - ((n - 1) - y))); sum = sum.subtract(BigInteger.valueOf(a4).multiply(BigInteger.valueOf(a4))); if ( (((y - a1) + 1) < 0)) { long b1 = Math.abs(((y - a1) + 1)); sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf((b1 + 1))).shiftRight(1)); } if ( (((y - a3) + 1) < 0)) { long b1 = Math.abs(((y - a3) + 1)); sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf((b1 + 1))).shiftRight(1)); } if ( (((y + a1) - 1) >= n)) { long b1 = ((y + a1) - n); sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf((b1 + 1))).shiftRight(1)); } if ( (((y + a3) - 1) >= n)) { long b1 = ((y + a3) - n); sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf((b1 + 1))).shiftRight(1)); } return (sum.compareTo(BigInteger.valueOf(c)) >= 0);} public static void main( String[] argv){ Scanner in = new Scanner(System.in); n = in.nextLong(); x = in.nextLong(); y = in.nextLong(); c = in.nextLong(); x--; y--; long lf = 0,rg = ((((2 * 1000) * 1000) * 1000) + 3); while((lf != rg)){ long mid = ((lf + rg) >> 1); if ( can(mid)) rg = mid; else lf = (mid + 1); }System.out.println(lf); } }
1	public class Test{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  String s = in.readLine();  String[] p = in.readLine().split(" ");  List<Integer> a = new ArrayList<Integer>(); for ( String k :p) {a.add(Integer.parseInt(k)); } int n = a.size();  int c1 = 0;  int c2 = 0;  int c1p = 0;  int c2p = 0; for ( int i = 0;(i < n);i++) {if ( ((a.get(i) % 2) == 0)) {c1++; c1p = i; } else {c2++; c2p = i; }}if ( (c1 < c2)) {System.out.println((c1p + 1)); } else {System.out.println((c2p + 1)); }} }
5	public class C15A{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  double nm[][] = new double[n][2];  int a = 0;  int b = 0; for ( int i = 0;(i < n);i++) {a = sc.nextInt(); b = sc.nextInt(); nm[i][0] = (a - ((double)b / 2)); nm[i][1] = (a + ((double)b / 2)); }Arrays.sort(nm,new ArrayColumnComparator(1)); int sum = 0; for ( int i = 0;(i < (n - 1));i++) {if ( ((nm[(i + 1)][0] - nm[i][1]) == t)) sum++; else if ( ((nm[(i + 1)][0] - nm[i][1]) > t)) {sum += 2; } }System.out.println((sum + 2)); } } class ArrayColumnComparator implements Comparator{ private int cm = 0; ArrayColumnComparator( int cm){ this.cm = cm; } }
4	public class SolutionC{ public static void main( String[] args)throws Exception { Scanner sc = new Scanner(new File("input.txt"));  PrintWriter output = new PrintWriter("output.txt");  int N = sc.nextInt();  int M = sc.nextInt();  int K = sc.nextInt();  int[] x = new int[K];  int[] y = new int[K]; for ( int i = 0;(i < K);i++) {x[i] = sc.nextInt(); y[i] = sc.nextInt(); } int max = -1,max_x = -1,max_y = -1; for ( int i = 1;(i <= N);i++) {for ( int j = 1;(j <= M);j++) { int min = Integer.MAX_VALUE; for ( int k = 0;(k < K);k++) {min = Math.min(min,(Math.abs((x[k] - i)) + Math.abs((y[k] - j)))); }if ( (min > max)) {max = min; max_x = i; max_y = j; } }}output.println(((max_x + " ") + max_y)); output.flush(); } }
1	public class A{ static double eps = (double)1e-15; static long mod = ((int)1e9 + 7); public static void main( String[] args){ InputReader in = new InputReader(System.in);  OutputStream outputStream = System.out;  PrintWriter out = new PrintWriter(outputStream);  int n = in.nextInt();  int l = 0,r = 0;  String s = in.nextLine();  HashSet<Character> size = new HashSet<>(); for ( int i = 0;(i < n);i++) { char p = s.charAt(i); size.add(p); } int chk = size.size();  HashMap<Character,Integer> hm = new HashMap<>();  int ans = Integer.MAX_VALUE; while((l < n)){if ( ((hm.size() < chk) && (r < n))) { char p = s.charAt(r); if ( hm.containsKey(p)) {hm.put(p,(hm.get(p) + 1)); } else {hm.put(p,1); }r++; } else { char p = s.charAt(l); if ( (hm.get(p) == 1)) {hm.remove(p); } else {hm.put(p,(hm.get(p) - 1)); }l++; }if ( (hm.size() == chk)) {ans = Math.min(ans,(r - l)); } }out.println(ans); out.close(); } static class InputReader{ public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader( InputStream inputstream){ reader = new BufferedReader(new InputStreamReader(inputstream)); tokenizer = null; } public String nextLine(){ String fullLine = null; while(((tokenizer == null) || !tokenizer.hasMoreTokens())){try{fullLine = reader.readLine(); }catch (IOException e){ throw (new RuntimeException(e));} return fullLine;}return fullLine;} 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());} } }
1	public class A{ public static void main( String[] args)throws Exception { Scanner scan = new Scanner(System.in);  int n = scan.nextInt();  List<Integer> list = new ArrayList<Integer>(),list2 ; for ( ;(n-- > 0);) {list.add(scan.nextInt()); }list2 = new ArrayList<Integer>(list); Collections.sort(list2,new Comparator<Integer>(){}); System.out.println((list.indexOf(list2.get((((list2.get(1) % 2) > 0)?0:(list2.size() - 1)))) + 1)); } }
3	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);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ private final int MOD = (int)(1e9 + 7); public void solve( int testNumber, FastScanner in, PrintWriter out){ int n = in.nextInt();  String[] arr = new String[n]; for ( int i = 0;(i < n);i++) {arr[i] = in.nextString(); } int[] dp = new int[n]; Arrays.parallelSetAll(dp,(i)->0); dp[0] = 1; int cnt = 0; for ( int i = 0;(i < n);i++) {if ( arr[i].equals("f")) {cnt++; continue;} calc(dp,n,cnt); cnt = 0; } int sum = 0; for ( int i = 0;(i < n);i++) {sum += dp[i]; sum %= MOD; }out.println(sum); } private void calc( int[] dp, int n, int cnt){ for ( int i = (n - 1);(i >= 0);i--) {if ( (i != (n - 1))) dp[i] += dp[(i + 1)]; dp[i] %= MOD; } int prev = dp[0]; for ( int i = 0,y = 0;(i < MathUtil.gcdInt(n,cnt));i++) {y = i; prev = dp[i]; do { int nextId = ((y + cnt) % n);  int tmp = dp[nextId]; dp[nextId] = prev; prev = tmp; y = nextId; }while((y != i));}} } static class FastScanner{ private BufferedReader br ; private StringTokenizer st ; public FastScanner( File f){ try{br = new BufferedReader(new FileReader(f)); }catch (FileNotFoundException e){ e.printStackTrace(); } } public FastScanner( InputStream f){ br = new BufferedReader(new InputStreamReader(f)); } public String nextString(){ while(((st == null) || !st.hasMoreTokens())){ String s = null; try{s = br.readLine(); }catch (IOException e){ e.printStackTrace(); } if ( (s == null)) return null; st = new StringTokenizer(s); }return st.nextToken();} public int nextInt(){ return Integer.parseInt(nextString());} } }
1	public class Main{ public static void main( String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  int n = 0; n = Integer.parseInt(br.readLine()); String inp = ""; inp = br.readLine(); int no[] = new int[n];  String tinp[] = inp.split(" "); for ( int i = 0;(i < n);i++) {no[i] = Integer.parseInt(tinp[i]); } int eve = 0,odd = 0; for ( int i = 0;(i < 3);i++) { int rem = (no[i] % 2); if ( (rem == 0)) eve++; else odd++; }if ( (eve > 1)) {for ( int i = 0;(i < n);i++) {if ( ((no[i] % 2) == 1)) {System.out.println((i + 1)); break;} }} else {for ( int i = 0;(i < n);i++) {if ( ((no[i] % 2) == 0)) {System.out.println((i + 1)); break;} }}} }
4	public class C35C_BFS_Fire{ public static boolean[][] burning ; public static LinkedList<int[]> LitTrees ; public static int N ,M ; public static int[] lastTree ; public static void main( String[] args)throws IOException { BufferedReader input = new BufferedReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));  StringTokenizer dataR = new StringTokenizer(input.readLine()); N = Integer.parseInt(dataR.nextToken()); M = Integer.parseInt(dataR.nextToken()); burning = new boolean[(N + 1)][(M + 1)]; StringTokenizer dataR1 = new StringTokenizer(input.readLine());  int K = Integer.parseInt(dataR1.nextToken());  StringTokenizer dataR2 = new StringTokenizer(input.readLine()); LitTrees = new LinkedList<int[]>(); for ( int j = 0;(j < K);j++) { int x = Integer.parseInt(dataR2.nextToken());  int y = Integer.parseInt(dataR2.nextToken());  int[] coord = {x,y}; LitTrees.add(coord); burning[x][y] = true; }spread(); out.println(((lastTree[0] + " ") + lastTree[1])); out.close(); } public static void spread(){ while(!LitTrees.isEmpty()){ int[] studying = LitTrees.remove();  LinkedList<int[]> ll = new LinkedList<int[]>(); if ( ((studying[0] - 1) >= 1)) ll.add(new int[]{(studying[0] - 1),studying[1]}); if ( ((studying[1] - 1) >= 1)) ll.add(new int[]{studying[0],(studying[1] - 1)}); if ( ((studying[1] + 1) < (M + 1))) ll.add(new int[]{studying[0],(studying[1] + 1)}); if ( ((studying[0] + 1) < (N + 1))) ll.add(new int[]{(studying[0] + 1),studying[1]}); while(!ll.isEmpty()){ int[] focus = ll.remove(); if ( !burning[focus[0]][focus[1]]) {LitTrees.add(focus); burning[focus[0]][focus[1]] = true; } }lastTree = studying; }} }
2	public class CodeforcesRound176B{ public static void main( String[] args){ Scanner kde = new Scanner(System.in);  Long n = kde.nextLong();  Long k = kde.nextLong(); if ( ((((k - 1) * (k - 2)) + (2 * k)) < (n * (long)2))) {System.out.println(-1); return ;} Long a ,b ; if ( (n == 1)) {System.out.println(0); return ;} if ( (k >= n)) {System.out.println(1); return ;} else {a = (long)2; b = (k - 1); } boolean flag = false; while(true){if ( (a >= b)) {break;} long c = ((a + b) / 2); if ( (((2 * ((k - c) + 1)) + (((((k - 1) + k) - c) + 1) * (c - 1))) < (n * 2))) {a = (c + 1); } else {b = c; }flag = true; }if ( (flag == true)) {System.out.println(a); } else {System.out.println(a); }} }
4	public class Main{ static int n ,m ,k ; static int inf = (int)1e9; static class Pair{ int x ,y ; Pair( int a, int b){ x = a; y = b; } } static int[] dx = {1,-1,0,0},dy = {0,0,1,-1}; static boolean valid( int x, int y){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} public static void main( String[] args)throws IOException { Scanner in = new Scanner();  int n = in.nextInt();  int m = in.nextInt();  int k = in.nextInt();  int x[] = new int[k];  int y[] = new int[k];  int trees[][] = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) trees[i][j] = Integer.MAX_VALUE; for ( int i = 0;(i < k);i++) {x[i] = (in.nextInt() - 1); y[i] = (in.nextInt() - 1); trees[x[i]][y[i]] = 0; } int dis = Integer.MIN_VALUE; ; int xp = 0; ; int yp = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (trees[i][j] != 0)) for ( int j2 = 0;(j2 < k);j2++) trees[i][j] = Math.min(trees[i][j],(Math.abs((i - x[j2])) + Math.abs((j - y[j2])))); for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (trees[i][j] > dis)) {dis = trees[i][j]; xp = (i + 1); yp = (j + 1); } PrintWriter out = new PrintWriter("output.txt"); out.printf("%d %d\n",xp,yp); out.close(); } static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner()throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt")); } 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());} } }
3	public class Main{ public static void main( String[] args)throws Exception { FastReader sc = new FastReader();  OutputStream outputStream = System.out;  PrintWriter out = new PrintWriter(outputStream);  int n = sc.nextInt();  int[] font = new int[n];  int[] cost = new int[n]; for ( int i = 0;(i < n);i++) {font[i] = sc.nextInt(); }for ( int i = 0;(i < n);i++) {cost[i] = sc.nextInt(); } int[] dou = new int[n]; for ( int i = 0;(i < n);i++) { int min = Integer.MAX_VALUE; for ( int j = 0;(j < i);j++) {if ( (font[j] < font[i])) {if ( (min > (cost[i] + cost[j]))) {min = (cost[i] + cost[j]); } } }dou[i] = min; } int ans = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int min = Integer.MAX_VALUE; for ( int j = 0;(j < i);j++) {if ( ((dou[j] != Integer.MAX_VALUE) && (font[j] < font[i]))) {if ( (min > (dou[j] + cost[i]))) {min = (dou[j] + cost[i]); } } }if ( (min < ans)) {ans = min; } }if ( (ans == Integer.MAX_VALUE)) {System.out.println(-1); } else {System.out.println(ans); }} } 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());} }
5	public class Task15a{ public static class House implements Comparable<House>{ int x ,s ; public House( int x, int s){ super(); this.x = x; this.s = s; } } public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = (sc.nextInt() * 2);  House[] hs = new House[n]; for ( int i = 0;(i < n);i++) {hs[i] = new House((sc.nextInt() * 2),sc.nextInt()); }Arrays.sort(hs); int res = 2; for ( int i = 0;(i < (n - 1));i++) { int curr = (((hs[(i + 1)].x - hs[i].x) - hs[(i + 1)].s) - hs[i].s); if ( (curr > t)) res += 2; if ( (curr == t)) res += 1; }System.out.println(res); } }
4	public class Main{ static private BufferedReader br ; static private StringTokenizer st ; static private PrintWriter pw ; public static void main( String[] args)throws Exception { br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); int qq = Integer.MAX_VALUE; for ( int casenum = 1;(casenum <= qq);casenum++) { int r = readInt();  int c = readInt();  int n = readInt();  int[][] dist = new int[r][c]; for ( int i = 0;(i < r);i++) {Arrays.fill(dist[i],(1 << 25)); } LinkedList<State> q = new LinkedList<State>(); while((n-- > 0)){q.add(new State((readInt() - 1),(readInt() - 1))); dist[q.peekLast().x][q.peekLast().y] = 0; } int[] dx = new int[]{-1,1,0,0};  int[] dy = new int[]{0,0,-1,1};  State ret = q.peekLast(); while(!q.isEmpty()){ State curr = q.removeFirst(); ret = curr; for ( int k = 0;(k < dx.length);k++) { int nx = (curr.x + dx[k]);  int ny = (curr.y + dy[k]); if ( (((((nx >= 0) && (nx < r)) && (ny >= 0)) && (ny < c)) && (dist[nx][ny] > (1 + dist[curr.x][curr.y])))) {dist[nx][ny] = (1 + dist[curr.x][curr.y]); q.add(new State(nx,ny)); } }}pw.println((((ret.x + 1) + " ") + (ret.y + 1))); }exitImmediately(); } static class State{ public int x ,y ; public State( int x, int y){ super(); this.x = x; this.y = y; } } static private void exitImmediately(){ pw.close(); System.exit(0); } static private int readInt()throws IOException { return Integer.parseInt(nextToken());} static private String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){if ( !br.ready()) {exitImmediately(); } st = new StringTokenizer(br.readLine().trim()); }return st.nextToken();} }
0	public class Main{ static Scanner scan = new Scanner(System.in); static PrintStream out = System.out; static int n ; static void solve(){ System.out.println(((((0 + " ") + 0) + " ") + n)); } public static void main( String[] args){ n = scan.nextInt(); solve(); } }
5	public class A{ public static void main( String[] args)throws Exception { new A().run(); } void run()throws Exception { BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(sc.readLine());  ArrayList<Integer> a = new ArrayList<Integer>();  StringTokenizer st = new StringTokenizer(sc.readLine()," ");  boolean allOne = true; for ( int i = 0;(i < n);i++) { int val = Integer.parseInt(st.nextToken()); if ( (val != 1)) allOne = false; a.add(val); }if ( allOne) {a.remove((n - 1)); a.add(2); } else a.add(1); Collections.sort(a); System.out.print(a.get(0)); for ( int i = 1;(i < n);i++) System.out.print((" " + a.get(i))); System.out.println(); } }
3	public class C455{ static int N ; static final int mod = 1_000_000_007; static int[][] memo ; static int[] list ; public static void main( String[] args){ FS scan = new FS(System.in); N = scan.nextInt(); list = new int[N]; for ( int i = 0;(i < N);i++) {list[i] = (scan.next().equals("s")?0:1); }if ( (list[(N - 1)] == 1)) {System.out.println(0); return ;} memo = new int[(N + 1)][(N + 2)]; Arrays.fill(memo[N],1); int[] sum = new int[(N + 2)]; for ( int i = (N - 1);(i >= 0);i--) {sum[0] = memo[(i + 1)][0]; for ( int j = 1;(j < sum.length);j++) {sum[j] = (sum[(j - 1)] + memo[(i + 1)][j]); sum[j] %= mod; }for ( int j = 0;(j <= N);j++) {if ( ((list[i] == 1) && ((i == 0) || (list[(i - 1)] == 1)))) memo[i][j] = memo[(i + 1)][(j + 1)]; else if ( ((i == 0) || (list[(i - 1)] == 1))) memo[i][j] = memo[(i + 1)][j]; else if ( (list[i] == 1)) {memo[i][j] = ((sum[(j + 1)] - sum[0]) + mod); memo[i][j] %= mod; } else if ( (list[i] == 0)) {memo[i][j] = sum[j]; } }}System.out.println(memo[0][0]); } static private class FS{ BufferedReader br ; StringTokenizer st ; public FS( InputStream in){ br = new BufferedReader(new InputStreamReader(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());} } }
0	public class Contest1_1{ public static void main( String[] ar)throws Exception { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));  int input = Integer.parseInt(buff.readLine()); if ( (input == 0)) {System.out.println("0 0 0"); } else if ( (input == 1)) {System.out.println("0 0 1"); } else if ( (input == 2)) {System.out.println("0 1 1"); } else if ( (input == 3)) {System.out.println("1 1 1"); } else { int output[] = checkFibo(input);  int get[] = checkFibo(output[1]); output[0] = get[1]; output[1] = get[2]; System.out.print(output[0]); System.out.print((" " + output[1])); System.out.println((" " + output[2])); }} public static int[] checkFibo( int input){ int output[] = new int[3];  int fibo_1 = 0;  int fibo_2 = 1;  int temp = 0; while((fibo_2 != input)){temp = fibo_2; output[1] = fibo_1; output[2] = fibo_2; fibo_2 += fibo_1; fibo_1 = temp; }return output;} }
5	public class Main{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  StringTokenizer split = new StringTokenizer(in.readLine());  int n = Integer.parseInt(split.nextToken());  double t = Double.parseDouble(split.nextToken());  House[] xaxis = new House[n]; for ( int i = 0;(i < n);i++) {split = new StringTokenizer(in.readLine()); xaxis[i] = new House(Double.parseDouble(split.nextToken()),Double.parseDouble(split.nextToken())); }Arrays.sort(xaxis); int count = 2; for ( int i = 0;(i < (xaxis.length - 1));i++) { double free = ((xaxis[(i + 1)].getX() - (xaxis[(i + 1)].getSize() / 2.0)) - (xaxis[i].getX() + (xaxis[i].getSize() / 2.0))); if ( ((free / t) == 1.0)) {count++; } else if ( ((free / t) > 1.0)) {count += 2; } }System.out.println(count); } } class House implements Comparable<House>{ private double x ; private double size ; public House( double x, double size){ this.x = x; this.size = size; } public double getX(){ return x;} public double getSize(){ return size;} }
3	public class D{ int[][] fast( int n, int m){ int[][] ans = new int[2][(n * m)];  int c = 0; for ( int left = 1,right = m;(left < right);left++,right--) {for ( int l = 1,r = n;((l <= n) && (r >= 1));l++,r--) {ans[0][c] = l; ans[1][c++] = left; ans[0][c] = r; ans[1][c++] = right; }}if ( ((m % 2) == 1)) { int x = ((m / 2) + 1); for ( int l = 1,r = n;(l < r);l++,r--) {ans[0][c] = l; ans[1][c++] = x; ans[0][c] = r; ans[1][c++] = x; if ( (((n % 2) == 1) && ((l + 2) == r))) {ans[0][c] = (l + 1); ans[1][c++] = x; } }} if ( ((n == 1) && ((m % 2) == 1))) {ans[0][c] = 1; ans[1][c] = ((m / 2) + 1); } return ans;} void stress(){ for ( int i = 3;(i <= 5);i++) {for ( int j = 2;(j <= 5);j++) { int[][] ans = new int[2][]; try{ans = fast(i,j); }catch (Exception e){ out.println("ошибка"); out.print(((i + " ") + j)); return ;} boolean[][] check = new boolean[i][j]; for ( int c = 0;(c < ans[0].length);c++) { int x = (ans[0][c] - 1);  int y = (ans[1][c] - 1); check[x][y] = true; }for ( int c = 0;(c < i);c++) {for ( int q = 0;(q < j);q++) {if ( !check[c][q]) {out.println(((i + " ") + j)); out.println("точки"); for ( int w = 0;(w < ans[0].length);w++) {out.println(((ans[0][w] + " ") + ans[1][w])); }return ;} }} HashSet<String> set = new HashSet<>(); for ( int c = 1;(c < ans[0].length);c++) { int x = (ans[0][c] - ans[0][(c - 1)]);  int y = (ans[1][c] - ans[1][(c - 1)]); set.add(((x + " ") + y)); }if ( (set.size() < ((i * j) - 1))) {out.println(((i + " ") + j)); out.println("вектора"); for ( int w = 0;(w < ans[0].length);w++) {out.println(((ans[0][w] + " ") + ans[1][w])); }return ;} }}} void normal(){ int n = readInt();  int m = readInt();  int[][] ans = fast(n,m); for ( int i = 0;(i < ans[0].length);i++) {out.println(((ans[0][i] + " ") + ans[1][i])); }} boolean stress = false; void solve(){ if ( stress) stress(); else normal(); } public static void main( String[] args){ new D().run(); } void run(){ init(); solve(); out.close(); } BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init(){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } String readLine(){ try{return in.readLine(); }catch (Exception ex){ throw (new RuntimeException(ex));} } String readString(){ while(!tok.hasMoreTokens()){ String nextLine = readLine(); if ( (nextLine == null)) return null; tok = new StringTokenizer(nextLine); }return tok.nextToken();} int readInt(){ return Integer.parseInt(readString());} }
1	public class C{ static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st ; static PrintWriter out = new PrintWriter(System.out); static String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String s = bf.readLine(); if ( (s == null)) return null; st = new StringTokenizer(s); }return st.nextToken();} static int nextInt()throws IOException { return Integer.parseInt(nextToken());} static String nextStr()throws IOException { return nextToken();} static int f( byte[] s, int n){ int l = 0,r = (n - 1);  int res = 0; do {while(((l < n) && (s[l] == 'H')))l++; while(((r >= 0) && (s[r] == 'T')))r--; if ( (l < r)) {res++; } l++; r--; }while((l < r));return res;} public static void main( String[] args)throws IOException { int n = nextInt();  byte s[] = nextStr().getBytes();  int res = f(s,n); for ( int i = 1;(i < n);i++) { byte c = s[0]; for ( int j = 0;(j < (n - 1));j++) s[j] = s[(j + 1)]; s[(n - 1)] = c; res = Math.min(res,f(s,n)); }out.println(res); out.flush(); } }
1	public class Main{ void change( int[] all, char c, int val){ if ( Character.isUpperCase(c)) all[((c - 'A') + 26)] += val; else all[(c - 'a')] += val; } int countDistinct( int[] a){ int res = 0; for ( int i = 0;(i < a.length);i++) {if ( (a[i] > 0)) res++; }return res;} public void solve()throws IOException { int n = nextInt();  String s = next();  int[] all = new int[52]; for ( int i = 0;(i < s.length());i++) { char c = s.charAt(i); change(all,c,1); } int distinct = countDistinct(all);  int[] window = new int[52];  int best = n; for ( int i = 0,j = 0;(i < s.length());i++) {if ( (i > 0)) {change(window,s.charAt((i - 1)),-1); } while((j < s.length())){if ( (countDistinct(window) == distinct)) break; change(window,s.charAt(j),1); j++; }if ( (countDistinct(window) < distinct)) break; best = Math.min(best,(j - i)); }out.println(best); } BufferedReader bf ; StringTokenizer st ; PrintWriter out ; public String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(bf.readLine()); return st.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(next());} public Main()throws IOException{ bf = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); bf.close(); out.close(); } public static void main( String[] args)throws IOException { new Main(); } }
5	public class A{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int t = in.nextInt();  pt[] P = new pt[n]; for ( int i = 0;(i < n);++i) P[i] = new pt(in.nextInt(),in.nextInt()); Arrays.sort(P); int res = 2; for ( int i = 0;((i + 1) < n);++i) { double d = (((P[(i + 1)].x - P[i].x) - (P[(i + 1)].a / 2.)) - (P[i].a / 2.)); if ( (Math.abs((d - t)) <= 1e-11)) ++res; else if ( (d > t)) res += 2; }System.out.println(res); } } class pt implements Comparable<pt>{ int x ,a ; pt( int x, int a){ this.x = x; this.a = a; } }
6	public class A{ static MyScanner sc ; static PrintWriter pw ; public static void main( String[] args)throws Throwable { sc = new MyScanner(); pw = new PrintWriter(System.out); n = sc.nextInt(); int m = sc.nextInt();  int[][] a = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) a[i][j] = sc.nextInt(); val = new int[n][n]; for ( int i = 0;(i < n);i++) Arrays.fill(val[i],Integer.MAX_VALUE); for ( int i = 0;(i < n);i++) for ( int j = i;(j < n);j++) {for ( int k = 0;(k < m);k++) val[i][j] = val[j][i] = Math.min(val[i][j],Math.abs((a[i][k] - a[j][k]))); }val2 = new int[n][n]; for ( int i = 0;(i < n);i++) Arrays.fill(val2[i],Integer.MAX_VALUE); for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < (m - 1));k++) val2[i][j] = Math.min(val2[i][j],Math.abs((a[i][k] - a[j][(k + 1)]))); }mem = new Integer[n][n][(1 << n)]; int ans = 0; for ( int i = 0;(i < n);i++) {ans = Math.max(ans,dp(i,i,(1 << i))); }if ( (n == 1)) pw.println(val2[0][0]); else pw.println(ans); pw.flush(); pw.close(); } static int n ; static int[][] val ,val2 ; static Integer[][][] mem ; static int dp( int st, int lst, int msk){ int bits = Integer.bitCount(msk); if ( (mem[st][lst][msk] != null)) return mem[st][lst][msk]; int ans = 0; for ( int i = 0;(i < n);i++) if ( ((msk & (1 << i)) == 0)) { int newMsk = (msk | (1 << i)); if ( (bits < (n - 1))) ans = Math.max(ans,Math.min(val[lst][i],dp(st,i,newMsk))); else ans = Math.max(ans,Math.min(val[lst][i],val2[i][st])); } return mem[st][lst][msk] = ans;} 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());} } }
2	public class b{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  long n = (sc.nextLong() - 1),k = (sc.nextLong() - 1);  int a = 0; if ( ((((k + 1) * k) / 2) < n)) {System.out.println(-1); return ;} while(((n > 0) && (k > 0))){ long min = go(n,k); a += ((k - min) + 1); n -= (((k + min) * ((k - min) + 1)) / 2); k = Math.min((min - 1),n); }if ( (n == 0)) System.out.println(a); else System.out.println(-1); } static long go( long n, long k){ long low = 1,high = k; while(((low + 1) < high)){ long mid = ((low + high) / 2); if ( ((((k + mid) * ((k - mid) + 1)) / 2) <= n)) {high = mid; } else low = mid; }return high;} }
1	public class C43 implements Runnable{ public Scanner in ; public PrintWriter out ; static final String TASK_NAME = ""; C43()throws IOException{ in = new Scanner(System.in); out = new PrintWriter(System.out); } void close()throws IOException { out.close(); } public void solve()throws IOException { int n = in.nextInt();  char[] c = in.next().toCharArray();  int t = 0; for ( int i = 0;(i < n);i++) {if ( (c[i] == 'T')) {t++; } } int ct = 0; for ( int i = 0;(i < t);i++) {if ( (c[i] == 'T')) {ct++; } } int r = 0; for ( int i = 0;(i < n);i++) {r = Math.max(r,ct); if ( (c[i] == 'T')) {ct--; } if ( (c[((i + t) % n)] == 'T')) {ct++; } }out.println((t - r)); } public static void main( String[] args)throws IOException { new Thread(new C43()).start(); } }
1	public final class round_364_c{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static FastScanner sc = new FastScanner(br); static PrintWriter out = new PrintWriter(System.out); public static void main( String[] args)throws Exception { int n = sc.nextInt();  char[] arr = sc.next().toCharArray();  int[] sum = new int[123];  int[][] pre = new int[123][(n + 1)];  char[] a = new char[(n + 1)]; for ( int i = 1;(i <= n);i++) {a[i] = arr[(i - 1)]; } boolean[] v = new boolean[123]; for ( int i = 1;(i <= n);i++) {sum[a[i]]++; v[a[i]] = true; for ( int j = 65;(j <= 90);j++) {pre[j][i] = sum[j]; }for ( int j = 97;(j <= 122);j++) {pre[j][i] = sum[j]; }} long min = Integer.MAX_VALUE; for ( int i = 1;(i <= n);i++) { int low = 0,high = ((n - i) + 1);  boolean got = false; while((low < high)){ int mid = ((low + high) >> 1);  boolean curr = true; for ( int j = 65;(j <= 90);j++) {if ( v[j]) {if ( ((pre[j][(i + mid)] - pre[j][(i - 1)]) <= 0)) {curr = false; break;} } }for ( int j = 97;(j <= 122);j++) {if ( v[j]) {if ( ((pre[j][(i + mid)] - pre[j][(i - 1)]) <= 0)) {curr = false; break;} } }if ( curr) {got = true; high = mid; } else {low = (mid + 1); }}if ( got) {min = Math.min(min,(((i + low) - i) + 1)); } }out.println(min); out.close(); } } class FastScanner{ BufferedReader in ; StringTokenizer st ; public FastScanner( BufferedReader in){ this.in = in; } public String nextToken()throws Exception { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(in.readLine()); }return st.nextToken();} public String next()throws Exception { return nextToken().toString();} public int nextInt()throws Exception { return Integer.parseInt(nextToken());} }
1	public class C364{ static HashMap<Character,Integer> freq ; static int unique = 0; public static void main( String[] args)throws Exception { FastScanner in = new FastScanner();  PrintWriter pw = new PrintWriter(System.out);  int n = in.nextInt();  char[] s = in.next().toCharArray(); freq = new HashMap<Character,Integer>(); for ( int i = 0;(i < n);i++) { char c = s[i]; if ( !freq.containsKey(c)) freq.put(c,0); } int k = freq.size();  int l = 0,r = 0,best = n; inc(s[0]); while((r < n)){if ( (unique == k)) {best = Math.min(best,((r + 1) - l)); dec(s[l++]); } else {if ( (++r == n)) break; inc(s[r]); }}pw.println(best); pw.flush(); pw.close(); } static void inc( char c){ int cur = freq.get(c); if ( (cur == 0)) unique++; freq.put(c,(cur + 1)); } static void dec( char c){ int cur = freq.get(c); if ( (cur == 1)) unique--; freq.put(c,(cur - 1)); } static class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner(){ br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } String next()throws Exception { while(!st.hasMoreTokens())st = new StringTokenizer(br.readLine()); return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(next());} } }
3	public class Main{ BufferedReader br ; PrintWriter pw ; StringTokenizer st ; long mod = (long)(1e9 + 7); public static void main( String[] args){ new Main().run(); } void solve()throws IOException { int n = nextInt();  boolean p[] = new boolean[n]; for ( int i = 0;(i < n);i++) { String s = nextToken(); if ( (s.charAt(0) == 'f')) p[i] = true; } long d[][] = new long[n][n]; d[0][0] = 1; for ( int i = 1;(i < n);i++) {if ( p[(i - 1)]) {d[i][0] = 0; for ( int j = 1;(j < n);j++) {d[i][j] = d[(i - 1)][(j - 1)]; }} else { long sum = 0; for ( int j = (n - 1);(j >= 0);j--) {sum += d[(i - 1)][j]; sum %= mod; d[i][j] = sum; }}} long sum = 0; for ( int i = 0;(i < n);i++) {sum += d[(n - 1)][i]; sum %= mod; }pw.print(sum); } void run(){ try{br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); solve(); pw.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(br.readLine()); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
1	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();  String s = in.next();  int[] cnt = new int[26];  int[] cnt2 = new int[26];  int j = 0;  int res = n;  HashSet<Character> set = new HashSet<Character>(); for ( char c :s.toCharArray()) {set.add(c); } int m = set.size(); for ( int i = 0;(i < n);++i) {if ( Character.isLowerCase(s.charAt(i))) {cnt[(s.charAt(i) - 'a')]++; } else {cnt2[(s.charAt(i) - 'A')]++; }while(isOK(cnt,cnt2,m)){res = Math.min(res,((i - j) + 1)); if ( Character.isLowerCase(s.charAt(j))) {cnt[(s.charAt(j) - 'a')]--; } else {cnt2[(s.charAt(j) - 'A')]--; }++j; }}out.println(res); } boolean isOK( int[] cnt, int[] cnt2, int m){ int c = 0; for ( int i = 0;(i < 26);++i) {if ( (cnt[i] > 0)) {++c; } }for ( int i = 0;(i < 26);++i) {if ( (cnt2[i] > 0)) {++c; } }return (c >= m);} } }
1	public class A{ public static void main( String[] args){ Scanner s = new Scanner(System.in); while(s.hasNext()){ int n = s.nextInt();  int[] a = new int[n];  int odd = 0;  int even = 0;  int po = -1;  int ev = -1; for ( int i = 0;(i < n);i++) {a[i] = s.nextInt(); if ( ((a[i] % 2) == 0)) {even++; ev = (i + 1); } else {odd++; po = (i + 1); }}if ( (odd == 1)) {System.out.println(po); } else {System.out.println(ev); }}} }
5	public class Main implements Runnable{ class Home implements Comparable<Home>{ int st ,end ; } public void solve()throws IOException { int n = nextInt(),t = (nextInt() * 2);  Home[] h = new Home[n]; for ( int i = 0;(i < n);++i) { int x = (nextInt() * 2),a = (nextInt() * 2); h[i] = new Home(); h[i].st = (x - (a / 2)); h[i].end = (x + (a / 2)); }Arrays.sort(h); int ans = 2; for ( int i = 0;((i + 1) < n);++i) { int delta = (h[(i + 1)].st - h[i].end); if ( (delta == t)) ans++; if ( (delta > t)) ans += 2; }pw.println(ans); } static final String filename = "A"; static final boolean fromConsole = true; private StringTokenizer st ; private BufferedReader in ; private PrintWriter pw ; boolean hasNext()throws IOException { while(!st.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) {return false;} st = new StringTokenizer(line); }return st.hasMoreTokens();} String next()throws IOException { return (hasNext()?st.nextToken():null);} int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args){ new Thread(new Main()).start(); } }
5	public class CottageVillage{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int size = sc.nextInt();  int side = sc.nextInt();  ArrayList<Pair> lis = new ArrayList<Pair>(); for ( int x = 0;(x < size);x++) {lis.add(new Pair(sc.nextInt(),sc.nextInt())); }Collections.sort(lis); int count = 2; for ( int x = 0;(x < (lis.size() - 1));x++) { Pair a = lis.get(x);  Pair b = lis.get((x + 1));  double na = (a.x + (a.len / 2));  double nb = (b.x - (b.len / 2)); if ( (na < nb)) { double dif = Math.abs((nb - na)); if ( (dif == side)) count++; else if ( (dif > side)) count += 2; } }System.out.println(count); } } class Pair implements Comparable<Pair>{ int x ; double len ; public Pair( int a, int b){ x = a; len = b; } }
2	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);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, Scanner in, PrintWriter out){ long n = in.nextLong();  int k = in.nextInt();  long top = (((((1L * k) * (k + 1)) / 2L) - k) + 1); if ( (n == 1L)) {out.print(0); return ;} if ( (n > top)) {out.print(-1); return ;} int ans = 0; if ( (n > 0)) {++ans; n -= k; k -= 2; } while((n > 0)){++ans; n -= k; k--; }out.print(ans); } }
2	public class Main{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  long n = scan.nextLong(),k = scan.nextLong(); if ( (n > ((((k - 2) * (k - 1)) / 2) + k))) {System.out.println("-1"); } else if ( (n == 1)) {System.out.println("0"); } else if ( ((n <= k) && (n > 1))) {System.out.println("1"); } else {n -= k; long start = (k - 2);  long x ;  long left = 1,right = (k - 2); while((left <= right)){x = ((left + right) / 2); if ( (n > cumSum(x,start))) {left = (x + 1); } else if ( (n < cumSum((x - 1),start))) {right = (x - 1); } else {System.out.println((1 + x)); break;}}}} public static long cumSum( long x, long start){ return ((x * (((2 * start) + 1) - x)) / 2);} }
1	public class C implements Runnable{ static private final boolean USE_FILE_IO = false; static private final String FILE_IN = "c.in"; static private final String FILE_OUT = "c.out"; BufferedReader in ; PrintWriter out ; StringTokenizer tokenizer = new StringTokenizer(""); public static void main( String[] args){ new Thread(new C()).start(); } int n ,h ,t ; char[] c ; private void solve()throws IOException { n = nextInt(); c = nextToken().toCharArray(); if ( (c.length != n)) {throw (new IllegalStateException());} for ( char l :c) if ( (l == 'H')) {h++; } t = (n - h); if ( (h == 0)) {out.print(0); return ;} int answer = Integer.MAX_VALUE; for ( int hLo = 0;(hLo < n);hLo++) if ( (c[hLo] == 'H')) { int hHi = ((hLo + h) % n);  int current = 0;  int j = hLo; while((j != hHi)){if ( (c[j] == 'T')) {current++; } j = ((j + 1) % n); }answer = Math.min(answer,current); } out.print(answer); } private String nextToken()throws IOException { while(!tokenizer.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) {return null;} tokenizer = new StringTokenizer(line); }return tokenizer.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
4	public class Main{ public static void main( String[] args)throws FileNotFoundException { Scanner sc = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt"));  int n = sc.nextInt();  int m = sc.nextInt();  int k = sc.nextInt();  ArrayList<ArrayList<Integer>> fire = new ArrayList<ArrayList<Integer>>(); while((k-- != 0)){ ArrayList<Integer> t = new ArrayList<Integer>(); t.add(sc.nextInt()); t.add(sc.nextInt()); fire.add(t); } int maxI = 0,maxJ = 0,maxManhatten = -1; for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= m);j++) { int curManhatten = Integer.MAX_VALUE; for ( int u = 0;(u < fire.size());u++) curManhatten = Math.min(curManhatten,manhatten(i,j,fire.get(u).get(0),fire.get(u).get(1))); if ( (curManhatten > maxManhatten)) {maxManhatten = curManhatten; maxI = i; maxJ = j; } }out.print(((maxI + " ") + maxJ)); out.flush(); out.close(); } static private int manhatten( int i, int j, Integer a, Integer b){ return (Math.abs((i - a)) + Math.abs((j - b)));} }
3	public class GFG{ static int count = 0; public static void main( String[] args){ Scanner ob = new Scanner(System.in);  int n ;  long MOD = (long)(1e9 + 7);  int f = 0,s = 0; n = ob.nextInt(); long dp[][] = new long[(n + 2)][(n + 2)]; dp[0][1] = 1; char ch = 's';  char p ; for ( int i = 1;(i <= n);i++) {p = ch; ch = ob.next().charAt(0); if ( (p == 'f')) {for ( int j = 1;(j <= n);j++) dp[i][(j + 1)] = dp[(i - 1)][j]; } else {for ( int j = n;(j > 0);j--) {dp[i][j] = ((dp[i][(j + 1)] + dp[(i - 1)][j]) % MOD); }}} long ans = 0; for ( int i = 1;(i <= n);i++) {ans = ((ans + dp[n][i]) % MOD); }System.out.println(ans); } }
6	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);  G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion(); solver.solve(1,in,out); out.close(); } static class G1PlaylistForPolycarpEasyVersion{ long mod = ((long)1e9 + 7); public void solve( int testNumber, InputReader s, PrintWriter w){ int n = s.nextInt(),T = s.nextInt();  int[] t = new int[(n + 1)];  int[] g = new int[(n + 1)];  int[] f = new int[4]; for ( int i = 1;(i <= n);i++) {t[i] = s.nextInt(); g[i] = s.nextInt(); f[g[i]]++; } long[] fact = new long[(n + 1)]; fact[0] = 1; for ( int i = 1;(i <= n);i++) fact[i] = ((fact[(i - 1)] * i) % mod); long[][][][] perm = new long[(f[1] + 1)][(f[2] + 1)][(f[3] + 1)][(3 + 1)];  long[][][] sumPerm = new long[(f[1] + 1)][(f[2] + 1)][(f[3] + 1)]; perm[0][0][0][0] = 1; for ( int a = 0;(a <= f[1]);a++) {for ( int b = 0;(b <= f[2]);b++) {for ( int c = 0;(c <= f[3]);c++) {if ( ((a - 1) >= 0)) perm[a][b][c][1] = (((sumPerm[(a - 1)][b][c] - perm[(a - 1)][b][c][1]) + mod) % mod); if ( ((b - 1) >= 0)) perm[a][b][c][2] = (((sumPerm[a][(b - 1)][c] - perm[a][(b - 1)][c][2]) + mod) % mod); if ( ((c - 1) >= 0)) perm[a][b][c][3] = (((sumPerm[a][b][(c - 1)] - perm[a][b][(c - 1)][3]) + mod) % mod); for ( int i = 0;(i <= 3);i++) sumPerm[a][b][c] = ((sumPerm[a][b][c] + perm[a][b][c][i]) % mod); }}} long[][][][][] dp = new long[(n + 1)][(f[1] + 1)][(f[2] + 1)][(f[3] + 1)][(T + 1)]; dp[0][0][0][0][0] = 1; for ( int i = 1;(i <= n);i++) {for ( int a = 0;(a <= f[1]);a++) {for ( int b = 0;(b <= f[2]);b++) {for ( int c = 0;(c <= f[3]);c++) {for ( int j = 0;(j <= T);j++) {dp[i][a][b][c][j] = dp[(i - 1)][a][b][c][j]; if ( ((j - t[i]) >= 0)) {if ( ((g[i] == 1) && (a > 0))) {dp[i][a][b][c][j] = ((dp[i][a][b][c][j] + dp[(i - 1)][(a - 1)][b][c][(j - t[i])]) % mod); } else if ( ((g[i] == 2) && (b > 0))) {dp[i][a][b][c][j] = ((dp[i][a][b][c][j] + dp[(i - 1)][a][(b - 1)][c][(j - t[i])]) % mod); } else if ( ((g[i] == 3) && (c > 0))) {dp[i][a][b][c][j] = ((dp[i][a][b][c][j] + dp[(i - 1)][a][b][(c - 1)][(j - t[i])]) % mod); } } }}}}} long res = 0; for ( int a = 0;(a <= f[1]);a++) for ( int b = 0;(b <= f[2]);b++) for ( int c = 0;(c <= f[3]);c++) res = ((res + ((((((((dp[n][a][b][c][T] * sumPerm[a][b][c]) % mod) * fact[a]) % mod) * fact[b]) % mod) * fact[c]) % mod)) % mod); w.println(res); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
3	public class C{ static private int[][][] dp ; static private boolean[] wasLoop ; static private int MOD = 1000000007; static private int n ; public static void solve( FastScanner fs){ n = fs.nextInt(); dp = new int[2][n][n]; for ( int i = 0;(i < dp.length);i++) for ( int j = 0;(j < dp[i].length);j++) Arrays.fill(dp[i][j],-1); wasLoop = new boolean[n]; for ( int i = 0;(i < n);i++) wasLoop[i] = fs.next().equals("f"); int ans = go(0,0,0); System.out.println(ans); } static private int go( int firstInLoop, int index, int indentLevel){ if ( (index >= n)) return 1; if ( (dp[firstInLoop][index][indentLevel] != -1)) return dp[firstInLoop][index][indentLevel]; if ( (firstInLoop == 1)) return dp[firstInLoop][index][indentLevel] = go((wasLoop[index]?1:0),(index + 1),(indentLevel + (wasLoop[index]?1:0))); if ( (indentLevel == 0)) {return dp[firstInLoop][index][indentLevel] = go((wasLoop[index]?1:0),(index + 1),(wasLoop[index]?1:0));} else { int total = 0; total += go(firstInLoop,index,(indentLevel - 1)); total += go((wasLoop[index]?1:0),(index + 1),(indentLevel + (wasLoop[index]?1:0))); total %= MOD; return dp[firstInLoop][index][indentLevel] = total;}} public static void main( String[] args)throws NumberFormatException,IOException { FastScanner scanner = new FastScanner(System.in); solve(scanner); } static private class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner( InputStream in){ br = new BufferedReader(new InputStreamReader(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());} } }
1	public class A_IQTest{ static int n ; public static void main( String[] args){ Scanner s = new Scanner(System.in); n = s.nextInt(); int[] nums = new int[n]; for ( int i = 0;(i < n);i++) {nums[i] = s.nextInt(); } int ei = -1;  int oi = -1;  int ecnt = 0;  int ocnt = 0; for ( int i = 0;(i < n);i++) {if ( ((nums[i] % 2) == 0)) {ei = i; ecnt++; } else {oi = i; ocnt++; }}if ( (ecnt == 1)) {System.out.println((ei + 1)); } else {System.out.println((oi + 1)); }} }
5	public class Main{ public Main(){ super(); } public static void main( String... args){ Main main = new Main(); main.start(); } public void start(){ Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));  int n = in.nextInt();  int t = in.nextInt();  House list[] = new House[n]; for ( int i = 0;(i < n);i++) { int x = in.nextInt();  int a = in.nextInt(); list[i] = new House(x,a); }Arrays.sort(list); int c = 2; for ( int i = 1;(i < n);i++) { float d = (list[i].left - list[(i - 1)].right); if ( (d == t)) c++; else if ( (d > t)) c += 2; }System.out.println(c); } } class House implements Comparable<House>{ public int x ; public float left ,right ; public House( int x, int a){ this.x = x; float h = (a / 2f); this.left = (x - h); this.right = (x + h); } }
5	public class Main{ static private Node[] node ; public static void main( String[] args){ Scanner cin = new Scanner(System.in);  int ret = 2,del ;  int n = cin.nextInt();  int t = (cin.nextInt() * 2); node = new Node[n]; for ( int i = 0;(i < n);i++) { int x = cin.nextInt();  int a = cin.nextInt(); node[i] = new Node(((x * 2) - a),((x * 2) + a)); }Arrays.sort(node); for ( int i = 1;(i < n);i++) {del = (node[i].l - node[(i - 1)].r); if ( (del > t)) {ret += 2; } else if ( (del == t)) {ret++; } }System.out.println(ret); } static private class Node implements Comparable<Node>{ public int l ; public int r ; public Node( int l, int r){ this.l = l; this.r = r; } } }
2	public class Main{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  String s = sc.nextLine();  String[] info = s.split(" ");  long n = Long.parseLong(info[0]);  long k = Long.parseLong(info[1]); sc.close(); long maximum = (((k * (k - 1)) / 2) + 1); if ( (n == 1)) System.out.println(0); else if ( (n > maximum)) System.out.println(-1); else { long left = 0,right = (k - 1); while(((left + 1) < right)){ long mid = ((right + left) / 2); if ( ((((mid * (((k - 1) + k) - mid)) / 2) + 1) >= n)) right = mid; else left = mid; }System.out.println(right); }} }
0	public class CF125D2A{ public static void main( String[] args){ Scanner sc = new Scanner(System.in); System.out.println(("0 0 " + sc.nextInt())); } }
1	public class evenness{ public static void main( String[] args){ try{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int i ,n ,temp = 1;  String str = "";  int[] arr ;  int r ; while((temp != '\n')){temp = System.in.read(); str = str.concat(Character.toString((char)temp)); }str = str.replaceAll("[^0-9]",""); n = Integer.parseInt(str); temp = 1; str = ""; arr = new int[n]; for ( i = 0;(i < n);i++) {while(((temp != ' ') && (temp != -1))){temp = System.in.read(); str = str.concat(Character.toString((char)temp)); }str = str.replaceAll("[^0-9]",""); arr[i] = Integer.parseInt(str); str = ""; temp = 1; }r = (arr[2] % 2); if ( ((arr[0] % 2) == (arr[1] % 2))) {r = (arr[0] % 2); } for ( i = 0;(i < n);i++) {if ( ((arr[i] % 2) != r)) {System.out.println((i + 1)); break;} } }catch (Exception e){ System.out.println(("OH NOES " + e)); } } }
1	public class a{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int a[] = new int[n]; for ( int i = 0;(i < n);i++) a[i] = (in.nextInt() % 2); int z = 0; for ( int i = 0;(i < n);i++) z += ((a[i] == 0)?1:0); if ( (z == 1)) z = 0; else z = 1; for ( int i = 0;(i < n);i++) if ( (a[i] == z)) {System.out.println((i + 1)); break;} } }
2	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 count = 1; if ( (n == 1)) {writer.println(0); writer.close(); return ;} if ( (k >= n)) {writer.println(1); writer.close(); return ;} long answer = 0; while((k > 1)){if ( (k > 2000)) {if ( ((count + k) <= n)) {if ( ((count + ((((k - 1) + k) - 1000) * 500)) <= n)) {count += ((((k - 1) + k) - 1000) * 500); k -= 1000; answer += 1000; } } } if ( (((count + k) - 1) <= n)) {count += (k - 1); answer++; } if ( (((count + k) - 100000000000000000l) > n)) {k -= 99999999999999999l; } if ( (((count + k) - 10000000000000000l) > n)) {k -= 9999999999999999l; } if ( (((count + k) - 1000000000000000l) > n)) {k -= 999999999999999l; } if ( (((count + k) - 100000000000000l) > n)) {k -= 99999999999999l; } if ( (((count + k) - 10000000000000l) > n)) {k -= 9999999999999l; } if ( (((count + k) - 1000000000000l) > n)) {k -= 999999999999l; } if ( (((count + k) - 100000000000l) > n)) {k -= 99999999999l; } if ( (((count + k) - 10000000000l) > n)) {k -= 9999999999l; } if ( (((count + k) - 1000000000l) > n)) {k -= 999999999l; } if ( (((count + k) - 100000000l) > n)) {k -= 99999999l; } if ( (((count + k) - 10000000l) > n)) {k -= 9999999l; } if ( (((count + k) - 1000000l) > n)) {k -= 999999l; } if ( (((count + k) - 100000l) > n)) {k -= 99999l; } if ( (((count + k) - 10000l) > n)) {k -= 9999l; } if ( (((count + k) - 1000l) > n)) {k -= 999l; } if ( (((count + k) - 100l) > n)) {k -= 99l; } if ( (((n - count) + 1) < k)) {k = ((n - count) + 1); } else {k--; }}if ( (count == n)) {writer.println(answer); } else {writer.println(-1); }writer.close(); } public static void main( String[] args){ new Problem2().run(); } }
0	public class A{ public static void main( String[] args){ long fib[] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073L,4807526976L,7778742049L,12586269025L,20365011074L,32951280099L,53316291173L,86267571272L,139583862445L,225851433717L,365435296162L,591286729879L,956722026041L,1548008755920L,2504730781961L,4052739537881L,6557470319842L,10610209857723L};  int i = Arrays.binarySearch(fib,new Scanner(System.in).nextLong()); if ( (i < 4)) if ( (i == 3)) System.out.println("0 1 1"); else if ( (fib[i] == 1)) System.out.println("0 0 1"); else System.out.println("0 0 0"); else System.out.println(((((fib[(i - 4)] + " ") + fib[(i - 3)]) + " ") + fib[(i - 1)])); } }
2	public class palin{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(System.out);  Scanner scan = new Scanner(System.in);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } } class TaskC{ public void solve( int testNumber, InputReader in, PrintWriter out){ long n = (in.nextLong() - 1);  long k = (in.nextLong() - 1); if ( (n == 0)) {out.print("0"); } else {if ( (k >= n)) {out.print("1"); } else {if ( (((k * (k + 1)) / 2) < n)) {out.print("-1"); } else { long t = binsearch(n,k,1,k);  long ans = ((k - t) + 1); if ( ((((k * (k + 1)) / 2) - ((t * (t - 1)) / 2)) != n)) ans++; System.out.println(ans); }}}} public static long binsearch( long n, long k, long from, long to){ if ( (from == to)) {return from;} long mid = ((from + to) / 2); if ( ((((k * (k + 1)) / 2) - ((mid * (mid - 1)) / 2)) > n)) return binsearch(n,k,(mid + 1),to); else return binsearch(n,k,from,mid);} } class InputReader{ BufferedReader br ; StringTokenizer st ; public InputReader( InputStream in){ br = new BufferedReader(new InputStreamReader(in)); st = null; } 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 long nextLong(){ return Long.parseLong(next());} }
3	public class Main{ static BufferedReader in ; static PrintStream out ; static StringTokenizer tok ; @SuppressWarnings public static void main( String[] args)throws NumberFormatException,IOException,Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = System.out; long mod = ((long)1e9 + 7);  int n = nextInt();  long[][] dp = new long[(n + 1)][(n + 1)];  Character[] line = new Character[(n + 1)]; line[0] = 'a'; for ( int i = 1;(i <= n);i++) {line[i] = nextToken().charAt(0); if ( (line[(i - 1)] == 'f')) {for ( int j = 0;(j < i);j++) {dp[i][(j + 1)] = dp[(i - 1)][j]; }} else if ( (line[(i - 1)] == 's')) { long temp = 0; for ( int j = i;(j >= 0);j--) {temp = ((temp + dp[(i - 1)][j]) % mod); dp[i][j] = temp; }} else dp[i][0] = 1; } long total = 0; for ( int j = 0;(j <= n);j++) total = ((total + dp[n][j]) % mod); out.println(total); } static String nextToken()throws IOException { String line = ""; while(((tok == null) || !tok.hasMoreTokens())){if ( ((line = in.readLine()) != null)) tok = new StringTokenizer(line); else return null;}return tok.nextToken();} static int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(nextToken());} }
5	public class A{ InputStream is ; PrintWriter out ; String INPUT = ""; void solve(){ int n = ni();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = ni(); }Arrays.sort(a); if ( (a[(n - 1)] > 1)) {a[(n - 1)] = 1; Arrays.sort(a); } else {a[(n - 1)] = 2; }for ( int i = 0;(i < n);i++) {if ( (i > 0)) out.print(" "); out.print(a[i]); }out.println(); } void run()throws Exception { is = (oj?System.in:new ByteArrayInputStream(INPUT.getBytes())); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(((System.currentTimeMillis() - s) + "ms")); } public static void main( String[] args)throws Exception { new A().run(); } public int ni(){ try{ int num = 0;  boolean minus = false; while((((num = is.read()) != -1) && (((num >= '0') && (num <= '9')) || (num == '-'))));if ( (num == '-')) {num = 0; minus = true; } else {num -= '0'; }while(true){ int b = is.read(); if ( ((b >= '0') && (b <= '9'))) {num = ((num * 10) + (b - '0')); } else {return (minus?-num:num);}} }catch (IOException e){ } return -1;} public String ns(){ try{ int b = 0;  StringBuilder sb = new StringBuilder(); while((((b = is.read()) != -1) && (((b == '\r') || (b == '\n')) || (b == ' '))));if ( (b == -1)) return ""; sb.append((char)b); while(true){b = is.read(); if ( (b == -1)) return sb.toString(); if ( (((b == '\r') || (b == '\n')) || (b == ' '))) return sb.toString(); sb.append((char)b); } }catch (IOException e){ } return "";} public char[] ns( int n){ char[] buf = new char[n]; try{ int b = 0,p = 0; while((((b = is.read()) != -1) && (((b == ' ') || (b == '\r')) || (b == '\n'))));if ( (b == -1)) return null; buf[p++] = (char)b; while((p < n)){b = is.read(); if ( ((((b == -1) || (b == ' ')) || (b == '\r')) || (b == '\n'))) break; buf[p++] = (char)b; }return Arrays.copyOf(buf,p); }catch (IOException e){ } return null;} boolean oj = (System.getProperty("ONLINE_JUDGE") != null); void tr( Object... o){ if ( !oj) System.out.println(Arrays.deepToString(o)); } }
2	public class Main{ 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]);  int x = Integer.parseInt(S[1]);  int y = Integer.parseInt(S[2]);  int c = Integer.parseInt(S[3]);  int lo = 0;  int hi = 1000000000; while(((hi - lo) >= 10)){ int steps = ((hi + lo) / 2);  long total = (((f(x,y,steps) + f(((N - x) + 1),y,steps)) + f(((N - x) + 1),((N - y) + 1),steps)) + f(x,((N - y) + 1),steps)); total -= 3; total -= Math.min(steps,(x - 1)); total -= Math.min(steps,(y - 1)); total -= Math.min(steps,(N - x)); total -= Math.min(steps,(N - y)); if ( (total >= c)) hi = (steps + 1); else lo = (steps - 1); }for ( int steps = lo;(steps <= hi);steps++) { long total = (((f(x,y,steps) + f(((N - x) + 1),y,steps)) + f(((N - x) + 1),((N - y) + 1),steps)) + f(x,((N - y) + 1),steps)); total -= 3; total -= Math.min(steps,(x - 1)); total -= Math.min(steps,(y - 1)); total -= Math.min(steps,(N - x)); total -= Math.min(steps,(N - y)); if ( (total >= c)) {System.out.println(steps); return ;} }} public static long f( long a, long b, long steps){ steps++; long A = Math.min(a,b);  long B = Math.max(a,b);  long ans = 0; if ( (steps >= (A + B))) {ans = (A * B); } else if ( (steps <= A)) {ans = ((steps * (steps + 1)) / 2); } else if ( ((steps > A) && (steps <= B))) {ans = (((A * (A + 1)) / 2) + ((steps - A) * A)); } else if ( (steps > B)) {ans = (((((A * (A + 1)) / 2) + ((B - A) * A)) + ((steps - B) * A)) - (((steps - B) * ((steps - B) + 1)) / 2)); } return ans;} }
2	public class Solution{ BufferedReader in ; PrintWriter out ; StringTokenizer st ; String nextToken()throws Exception { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(nextToken());} long fang( int s, int x, int y){ if ( (x > y)) { int t = x; x = y; y = t; } if ( ((s + 1) <= x)) {return (((long)(s + 1) * (s + 2)) / 2);} if ( ((s + 1) <= y)) {return ((((long)x * (x + 1)) / 2) + ((long)((s + 1) - x) * x));} if ( ((s + 1) >= ((x + y) - 1))) {return ((long)x * y);} long q = ((((x + y) - 1) - s) - 1); return (((long)x * y) - ((q * (q + 1)) / 2));} long f( int s, int n, int x, int y){ long ans = (((fang(s,((n - x) + 1),((n - y) + 1)) + fang(s,((n - x) + 1),y)) + fang(s,x,((n - y) + 1))) + fang(s,x,y)); ans -= (((Math.min((s + 1),((n - x) + 1)) + Math.min((s + 1),x)) + Math.min((s + 1),((n - y) + 1))) + Math.min((s + 1),y)); return (ans + 1);} void solve()throws Exception { int n = nextInt();  int x = nextInt(),y = nextInt();  long c = nextInt(); if ( (c == 1)) {out.println(0); return ;} int bg = 0,ed = (2 * n); while((ed > (bg + 1))){ int mm = ((bg + ed) / 2); if ( (f(mm,n,x,y) >= c)) ed = mm; else bg = mm; }out.println(ed); } void run(){ try{Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } finally{out.close(); }} public static void main( String[] args){ new Solution().run(); } }
5	public class a{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  double w = in.nextDouble();  int tot = 2;  Interval[] houses = new Interval[n]; for ( int i = 0;(i < n);i++) { double center = in.nextDouble();  double wid = in.nextDouble(); houses[i] = new Interval((center - (wid / 2)),(center + (wid / 2))); }Arrays.sort(houses); for ( int i = 1;(i < n);i++) { double dist = (houses[i].s - houses[(i - 1)].e); if ( ((dist + 1e-6) >= w)) {tot += 2; if ( (Math.abs((w - dist)) < 1e-6)) tot--; } }System.out.println(tot); } } class Interval implements Comparable<Interval>{ double s ,e ; Interval( double a, double b){ s = a; e = b; } }
1	public class C{ MyScanner in ; PrintWriter out ; public static void main( String[] args)throws Exception { new C().run(); } public void run()throws Exception { in = new MyScanner(); out = new PrintWriter(System.out); solve(); out.close(); } public void solve()throws Exception { int n = in.nextInt();  char[] a = in.next().toCharArray();  int h = 0; for ( int i = 0;(i < a.length);i++) {if ( (a[i] == 'H')) h++; } char[] b = new char[((2 * a.length) - 1)]; for ( int i = 0;(i < b.length);i++) {b[i] = a[(i % a.length)]; } int maxh = 0;  int hh = 0; for ( int i = 0;(i < (b.length - h));i++) {hh = 0; for ( int j = 0;(j < h);j++) {if ( (b[(i + j)] == 'H')) hh++; }maxh = Math.max(maxh,hh); }out.println((h - maxh)); } class MyScanner{ BufferedReader br ; StringTokenizer st ; public MyScanner()throws Exception{ br = new BufferedReader(new InputStreamReader(System.in)); } String next()throws Exception { if ( ((st == null) || st.hasMoreTokens())) {st = new StringTokenizer(br.readLine()); } return st.nextToken();} int nextInt()throws Exception { return Integer.parseInt(next());} } }
3	public class Solution{ public static void main( String[] args){ 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[][] arr = new long[n][n]; arr[0][0] = 1; for ( int i = 1;(i < n);i++) {if ( (seq[(i - 1)] == 'f')) {for ( int j = 1;(j < n);j++) {arr[i][j] = arr[(i - 1)][(j - 1)]; }} else { long sum = 0; for ( int j = (n - 1);(j >= 0);j--) {sum = ((sum + arr[(i - 1)][j]) % mod); arr[i][j] = sum; }}} long ans = 0; for ( int i = 0;(i < n);i++) {ans = ((ans + arr[(n - 1)][i]) % mod); }System.out.println(ans); } }
6	public class ElongatedMatrix2{ public static void main( String[] args){ FastScanner scanner = new FastScanner();  int N = scanner.nextInt();  int M = scanner.nextInt();  int[][] arr = new int[N][M]; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < M);j++) {arr[i][j] = scanner.nextInt(); }} int[][] distRow = new int[N][N];  int[][] distTop = new int[N][N]; for ( int i = 0;(i < N);i++) {for ( int j = (i + 1);(j < N);j++) { int curMin = Integer.MAX_VALUE; for ( int k = 0;(k < M);k++) {curMin = Math.min(curMin,Math.abs((arr[i][k] - arr[j][k]))); }distRow[i][j] = distRow[j][i] = curMin; }}for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < N);j++) { int curMin = Integer.MAX_VALUE; for ( int k = 0;((k + 1) < M);k++) {curMin = Math.min(curMin,Math.abs((arr[i][k] - arr[j][(k + 1)]))); }distTop[i][j] = curMin; }} int maxMask = (1 << N);  int[][][] dp = new int[maxMask][N][N]; for ( int i = 0;(i < maxMask);i++) {for ( int j = 0;(j < N);j++) {Arrays.fill(dp[i][j],Integer.MAX_VALUE); }}for ( int mask = 1;(mask < maxMask);mask++) {for ( int j = 0;(j < N);j++) {if ( ((mask & (1 << j)) == 0)) continue; for ( int k = 0;(k < N);k++) {if ( ((mask & (1 << k)) == 0)) continue; if ( ((j == k) && ((mask - (1 << k)) != 0))) continue; for ( int i = 0;(i < N);i++) {if ( ((mask & (1 << i)) > 0)) continue; int curMask = (mask | (1 << i)); if ( (dp[curMask][i][k] != Integer.MAX_VALUE)) dp[curMask][i][k] = Math.max(dp[curMask][i][k],Math.min(dp[mask][j][k],distRow[i][j])); else dp[curMask][i][k] = Math.min(dp[mask][j][k],distRow[i][j]); }}}}maxMask--; int max = 0; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < N);j++) {if ( ((i == j) && (N != 1))) continue; max = Math.max(max,Math.min(dp[maxMask][i][j],distTop[i][j])); }}System.out.println(max); } public static class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner( Reader in){ br = new BufferedReader(in); } public FastScanner(){ this(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());} } }
4	public class FireAgain{ int k ,i ,j ,n ,m ,x ,y ; void run(){ try{ BufferedReader bfd = new BufferedReader(new FileReader("input.txt"));  BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));  StringTokenizer tk = new StringTokenizer(bfd.readLine()); n = Integer.parseInt(tk.nextToken()); m = Integer.parseInt(tk.nextToken()); boolean vis[][] = new boolean[n][m]; k = Integer.parseInt(bfd.readLine()); tk = new StringTokenizer(bfd.readLine()); Queue<Point> q = new LinkedList<Point>();  Point last = new Point(0,0); while((k-- > 0)){x = (Integer.parseInt(tk.nextToken()) - 1); y = (Integer.parseInt(tk.nextToken()) - 1); q.add(new Point(x,y)); vis[x][y] = true; }while(!q.isEmpty()){ Point frnt = q.poll(); for ( i = (frnt.x - 1);(i <= (frnt.x + 1));++i) for ( j = (frnt.y - 1);(j <= (frnt.y + 1));++j) if ( ((val(i,j) && !vis[i][j]) && ((frnt.x == i) || (frnt.y == j)))) {q.add(new Point(i,j)); last = new Point(i,j); vis[i][j] = true; } }out.write(((((last.x + 1) + " ") + (last.y + 1)) + "\n")); out.flush(); out.close(); }catch (Exception e){ } } boolean val( int x, int y){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} public static void main( String[] args){ new FireAgain().run(); } }
6	public class Main implements Runnable{ static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } public static void main( String[] args)throws Exception { new Thread(null,new Main(),"Main",(1 << 26)).start(); } static long gcd( long a, long b){ if ( (b == 0)) return a; return gcd(b,(a % b));} static long modPow( long a, long p, long m){ if ( (a == 1)) return 1; long ans = 1; while((p > 0)){if ( ((p % 2) == 1)) ans = ((ans * a) % m); a = ((a * a) % m); p >>= 1; }return ans;} static long sol_x ,sol_y ,gcd_a_b ; static void extendedEuclid( long a, long b){ if ( (b == 0)) {gcd_a_b = a; sol_x = 1; sol_y = 0; } else {extendedEuclid(b,(a % b)); long temp = sol_x; sol_x = sol_y; sol_y = (temp - ((a / b) * sol_y)); }} long f( int start, int end, int mask, Long[][][] dp, int n, int[][] cost, int[][] costRight){ if ( (dp[start][end][mask] != null)) return dp[start][end][mask]; long ans = Integer.MIN_VALUE; for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) == 0)) { int newMask = (mask | (1 << i)); if ( (((1 << n) - 1) != (mask | (1 << i)))) {ans = Math.max(ans,Math.min(cost[end][i],f(start,i,newMask,dp,n,cost,costRight))); } else {ans = Math.max(ans,Math.min(cost[end][i],costRight[start][i])); }} }return dp[start][end][mask] = ans;} }
0	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(in,out); out.close(); } } class TaskA{ int n ; int m ; String answer = "I'm too stupid to solve this problem"; public void solve( InputReader in, PrintWriter out){ n = in.nextInt(); out.println(("0 0 " + n)); } } class InputReader{ private BufferedReader reader ; private 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());} }
1	public class Homyak implements Runnable{ private void solve()throws IOException { int n = nextInt();  String seq = nextToken();  int nh = 0;  int nt = 0; for ( int i = 0;(i < n);++i) if ( (seq.charAt(i) == 'H')) ++nh; else ++nt; int res = n; for ( int delta = 0;(delta < n);++delta) { int changed = 0;  int at = delta; for ( int i = 0;(i < nh);++i) {if ( (seq.charAt(at) != 'H')) ++changed; ++at; if ( (at >= n)) at = 0; }for ( int i = 0;(i < nt);++i) {if ( (seq.charAt(at) != 'T')) ++changed; ++at; if ( (at >= n)) at = 0; }res = Math.min(res,(changed / 2)); }writer.println(res); } public static void main( String[] args){ new Homyak().run(); } BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter writer ; public void run(){ try{reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} }
5	public class Replacement{ public static void main( String[] args)throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in));  String s = r.readLine();  int n = new Integer(s);  int[] arr = new int[n];  String[] sp = r.readLine().split("[ ]+"); for ( int i = 0;(i < sp.length);i++) {arr[i] = new Integer(sp[i]); }Arrays.sort(arr); if ( (arr[(arr.length - 1)] == 1)) {arr[(arr.length - 1)] = 2; Arrays.sort(arr); for ( int i = 0;(i < n);i++) {if ( (i == (n - 1))) {System.out.println(arr[i]); } else System.out.print((arr[i] + " ")); }return ;} arr[(arr.length - 1)] = 1; Arrays.sort(arr); for ( int i = 0;(i < n);i++) {if ( (i == (n - 1))) {System.out.println(arr[i]); } else System.out.print((arr[i] + " ")); }} }
5	public class P15A_CottageVillage{ public static void main( String[] args){ Scanner scanner = new Scanner(System.in);  int n = scanner.nextInt();  int t = scanner.nextInt(); scanner.nextLine(); int[] x = new int[n];  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {x[i] = scanner.nextInt(); a[i] = scanner.nextInt(); scanner.nextLine(); }scanner.close(); for ( int i = 0;(i < (n - 1));i++) {for ( int j = (i + 1);(j < n);j++) {if ( (x[i] > x[j])) {swap(x,i,j); swap(a,i,j); } }} int countPositions = 2; for ( int i = 1;(i < n);i++) { double left = (x[(i - 1)] + ((a[(i - 1)] * 1.0) / 2));  double right = (x[i] - ((a[i] * 1.0) / 2));  double length = (right - left); if ( (length == (double)t)) {countPositions++; } else if ( (length > t)) {countPositions += 2; } }System.out.println(countPositions); } static private void swap( int[] numbers, int i, int j){ int temp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = temp; } }
0	public class TaskA extends Thread{ public TaskA( String inputFileName, String outputFileName){ try{if ( (inputFileName != null)) {this.input = new BufferedReader(new FileReader(inputFileName)); } else {this.input = new BufferedReader(new InputStreamReader(System.in)); }if ( (outputFileName != null)) {this.output = new PrintWriter(outputFileName); } else {this.output = new PrintWriter(System.out); }this.setPriority(Thread.MAX_PRIORITY); }catch (Throwable e){ System.err.println(e.getMessage()); e.printStackTrace(); System.exit(666); } } private void solve()throws Throwable { long n = nextLong(); output.println(("0 0 " + n)); } public static void main( String... args){ new TaskA(null,null).start(); } private long nextLong()throws IOException { return Long.parseLong(next());} private String next()throws IOException { while(((tokens == null) || !tokens.hasMoreTokens())){tokens = new StringTokenizer(input.readLine()); }return tokens.nextToken();} private StringTokenizer tokens ; private BufferedReader input ; private PrintWriter output ; }
6	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);  G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion(); solver.solve(1,in,out); out.close(); } static class G1PlaylistForPolycarpEasyVersion{ public static final int GENRES_COUNT = 3; private int songsCount ; private int totalDuration ; private Song[] songs ; private int[][][] mem ; static final int mod = 1000000007; public void solve( int testNumber, InputReader in, PrintWriter out){ songsCount = in.nextInt(); totalDuration = in.nextInt(); songs = new Song[songsCount]; for ( int i = 0;(i < songsCount);i++) {songs[i] = new Song(in.nextInt(),(in.nextInt() - 1)); } long ret = 0;  int chosenSongs = 0; mem = new int[(GENRES_COUNT + 1)][][]; for ( int i = 0;(i < GENRES_COUNT);i++) {mem[i] = new int[(totalDuration + 1)][]; for ( int j = 0;(j <= totalDuration);j++) {mem[i][j] = new int[(1 << songsCount)]; for ( int k = 0;(k < (1 << songsCount));k++) {mem[i][j][k] = -1; }}}for ( int i = 0;(i < songsCount);i++) {chosenSongs = (1 << i); ret += search((totalDuration - songs[i].duration),songs[i].genre,chosenSongs); }out.println((ret % mod)); } private long search( int timeLeft, int lastGenre, int chosen){ if ( (timeLeft < 0)) {return 0;} if ( (timeLeft == 0)) {return 1;} if ( (mem[lastGenre][timeLeft][chosen] != -1)) {return mem[lastGenre][timeLeft][chosen];} long ret = 0; for ( int i = 0;(i < songsCount);i++) {if ( ((((1 << i) & chosen) == 0) && (songs[i].genre != lastGenre))) {ret += search((timeLeft - songs[i].duration),songs[i].genre,(chosen | (1 << i))); if ( (ret > mod)) {ret = (ret % mod); } } }mem[lastGenre][timeLeft][chosen] = (int)(ret % mod); return mem[lastGenre][timeLeft][chosen];} class Song{ public int duration ; public int genre ; public Song( int duration, int genre){ this.duration = duration; this.genre = genre; } } } 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());} } }
3	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{ private long MOD = (long)(1e9 + 7); int[][] dp = new int[5001][5001]; public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.nextInt();  ArrayList<Character> commands = new ArrayList<>(); for ( int i = 0;(i < n);i++) { char ch = in.next().charAt(0); commands.add(ch); }for ( int[] a :dp) Arrays.fill(a,-1); out.println(count(0,commands,0)); } public int count( int index, ArrayList<Character> commands, int deepCount){ if ( (deepCount < 0)) {return 0;} if ( (index == commands.size())) {return 1;} else {if ( (dp[index][deepCount] != -1)) return dp[index][deepCount]; long result = 0;  char ch = commands.get(index); result = count(index,commands,(deepCount - 1)); if ( (ch == 's')) {result += count((index + 1),commands,deepCount); } else {result += count((index + 1),commands,(deepCount + 1)); result -= count((index + 1),commands,deepCount); }if ( (result >= MOD)) {result -= MOD; } if ( (result < 0)) {result += MOD; } return dp[index][deepCount] = (int)result;}} } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c)){c = read(); } StringBuilder res = new StringBuilder(); do {if ( Character.isValidCodePoint(c)) {res.appendCodePoint(c); } c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public String next(){ return readString();} public int nextInt(){ return readInt();} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
3	public class C{ static final long MOD = 1_000_000_007; public static void main( String[] args)throws Exception { FastScanner sc = new FastScanner();  PrintWriter out = new PrintWriter(System.out);  int N = sc.nextInt();  long[][] dp = new long[N][N]; dp[0][0] = 1L; for ( int i = 0;(i < (N - 1));i++) { char oper = sc.next().charAt(0); if ( (oper == 'f')) {dp[(i + 1)][0] = 0L; for ( int j = 1;(j < N);j++) {dp[(i + 1)][j] = dp[i][(j - 1)]; }} else {dp[(i + 1)][(N - 1)] = dp[i][(N - 1)]; for ( int j = (N - 2);(j >= 0);j--) {dp[(i + 1)][j] = ((dp[(i + 1)][(j + 1)] + dp[i][j]) % MOD); }}} long res = 0; for ( int i = 0;(i < N);i++) {res += dp[(N - 1)][i]; res %= MOD; }out.println(res); out.flush(); } static class FastScanner{ public BufferedReader reader ; public StringTokenizer tokenizer ; public FastScanner(){ 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());} } }
4	public class P35C{ int n ,m ; int[][] fire ; public P35C()throws FileNotFoundException{ Scanner in = new Scanner(new FileReader("input.txt")); n = in.nextInt(); m = in.nextInt(); int k = in.nextInt(); fire = new int[k][2]; for ( int i = 0;(i < k);i++) {fire[i][0] = in.nextInt(); fire[i][1] = in.nextInt(); }in.close(); int[] last = new int[2];  int lastBurn = -1; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) { int burn = Integer.MAX_VALUE; for ( int l = 0;(l < k);l++) { int burnAux = dist(i,j,fire[l][0],fire[l][1]); burn = Math.min(burn,burnAux); }if ( (burn >= lastBurn)) {lastBurn = burn; last[0] = i; last[1] = j; } }} PrintStream out = new java.io.PrintStream("output.txt"); out.print(((last[0] + " ") + last[1])); out.close(); } int dist( int x1, int y1, int x2, int y2){ return (Math.abs((x2 - x1)) + Math.abs((y2 - y1)));} public static void main( String[] args)throws FileNotFoundException { new P35C(); } }
5	public class a{ public static void main( String[] args)throws Exception { Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  int[][] xa = new int[n][2]; for ( int i = 0;(i < n);++i) {xa[i][0] = sc.nextInt(); xa[i][1] = sc.nextInt(); }Arrays.sort(xa,new Comparator<int[]>(){}); int ans = 2; for ( int i = 0;(i < (n - 1));i++) { int s = (((xa[(i + 1)][0] * 2) - xa[(i + 1)][1]) - ((xa[i][0] * 2) + xa[i][1])); if ( (s > (t * 2))) {ans += 2; } else if ( (s == (t * 2))) {ans++; } }System.out.println((ans + "")); } }
3	public class Solution{ static MyScanner sc ; static private PrintWriter out ; static long M2 = (1_000_000_000L + 7); static private HashMap<Long,Long>[] mods ; public static void main( String[] s)throws Exception { StringBuilder stringBuilder = new StringBuilder(); if ( (stringBuilder.length() == 0)) {sc = new MyScanner(System.in); } else {sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString()))); }out = new PrintWriter(new OutputStreamWriter(System.out)); initData(); solve(); out.flush(); } static private void solve()throws IOException { int n = sc.nextInt();  boolean[] k = new boolean[n]; for ( int r = 0;(r < n);r++) {k[r] = (sc.next().charAt(0) == 'f'); }if ( k[(n - 1)]) {out.println(0); return ;} long[][] res = new long[(n + 1)][(n + 1)]; res[0][0] = 1; for ( int t = 0;(t < n);t++) { boolean pl = ((t != 0) && k[(t - 1)]); if ( pl) {System.arraycopy(res[t],0,res[(t + 1)],1,n); } else { long last = 0; for ( int f = n;(f >= 0);f--) {last += res[t][f]; last %= M2; res[(t + 1)][f] = last; }}} long pp = 0; for ( long kk :res[n]) {pp += kk; pp %= M2; }out.println(pp); } static private void initData(){ } static char[][] data ; static String cmd ; static private long gcd( long l, long l1){ if ( (l > l1)) return gcd(l1,l); if ( (l == 0)) return l1; return gcd((l1 % l),l);} static private long pow( long a, long b, long m){ if ( (b == 0)) return 1; if ( (b == 1)) return a; long pp = pow(a,(b / 2),m); pp *= pp; pp %= m; return ((pp * (((b % 2) == 0)?1:a)) % m);} static class MyScanner{ BufferedReader br ; StringTokenizer st ; MyScanner( BufferedReader br){ this.br = br; } public MyScanner( InputStream in){ this(new BufferedReader(new InputStreamReader(in))); } void findToken(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ throw (new RuntimeException(e));} }} String next(){ findToken(); return st.nextToken();} int nextInt(){ return Integer.parseInt(next());} int fi(){ String t = next();  int cur = 0;  boolean n = (t.charAt(0) == '-'); for ( int a = (n?1:0);(a < t.length());a++) {cur = (((cur * 10) + t.charAt(a)) - '0'); }return (n?-cur:cur);} long nextLong(){ return Long.parseLong(next());} } }
6	public class G1{ public static void main( String[] args)throws Exception { new G1().run(); } int MOD = 1_000_000_007; public void run()throws Exception { FastScanner f = new FastScanner();  PrintWriter out = new PrintWriter(System.out);  int n = f.nextInt(),t = f.nextInt();  int[][] dp = new int[(1 << n)][3];  int[] tarr = new int[n];  int[] garr = new int[n]; for ( int i = 0;(i < n);i++) {tarr[i] = f.nextInt(); garr[i] = (f.nextInt() - 1); if ( (tarr[i] <= t)) dp[(1 << i)][garr[i]] = 1; } int[] time = new int[(1 << n)]; for ( int i = 0;(i < dp.length);i++) {for ( int bi = 0;(bi < n);bi++) if ( ((i & (1 << bi)) != 0)) time[i] += tarr[bi]; }for ( int i = 0;(i < dp.length);i++) { int j = time[i]; for ( int k = 0;(k < 3);k++) {if ( (dp[i][k] == 0)) continue; for ( int bi = 0;(bi < n);bi++) if ( ((((tarr[bi] + j) <= t) && ((i & (1 << bi)) == 0)) && (garr[bi] != k))) {dp[(i | (1 << bi))][garr[bi]] = ((dp[(i | (1 << bi))][garr[bi]] + dp[i][k]) % MOD); } }} long ans = 0; for ( int i = 0;(i < dp.length);i++) for ( int j = 0;(j < 3);j++) if ( (time[i] == t)) ans = ((ans + dp[i][j]) % MOD); out.println(ans); out.flush(); } static class FastScanner{ public BufferedReader reader ; public StringTokenizer tokenizer ; public FastScanner(){ 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());} } }
2	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  FastScanner in = new FastScanner(inputStream);  FastPrinter out = new FastPrinter(outputStream);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ long n ,x ,y ,c ; public void solve( int testNumber, FastScanner in, FastPrinter out){ n = in.nextLong(); x = in.nextLong(); y = in.nextLong(); c = in.nextLong(); long td = -1,tup = (2 * (n - 1)); while((Math.abs((td - tup)) > 1)){ long mid = ((td + tup) / 2); if ( chk(mid)) tup = mid; else td = mid; }out.println(tup); } private boolean chk( long t){ long ct = -3;  long d = x,w = y; if ( (w > d)) { long tt = w; w = d; d = tt; } if ( (t >= ((d + w) - 2))) ct += (d * w); else if ( ((t < w) && (t < d))) {ct += (((t + 1) * (t + 2)) / 2); } else if ( ((t >= w) && (t < d))) {ct += ((w * (w + 1)) / 2); long k = (t - (w - 1)); ct += (k * w); } else if ( ((t >= w) && (t >= d))) {ct += (w * d); long k = ((w - 2) - (t - d)); ct -= ((k * (k + 1)) / 2); } w = x; d = ((n + 1) - y); if ( (w > d)) { long tt = w; w = d; d = tt; } if ( (t >= ((d + w) - 2))) ct += (d * w); else if ( ((t < w) && (t < d))) {ct += (((t + 1) * (t + 2)) / 2); } else if ( ((t >= w) && (t < d))) {ct += ((w * (w + 1)) / 2); long k = (t - (w - 1)); ct += (k * w); } else if ( ((t >= w) && (t >= d))) {ct += (w * d); long k = ((w - 2) - (t - d)); ct -= ((k * (k + 1)) / 2); } w = ((n + 1) - x); d = y; if ( (w > d)) { long tt = w; w = d; d = tt; } if ( (t >= ((d + w) - 2))) ct += (d * w); else if ( ((t < w) && (t < d))) {ct += (((t + 1) * (t + 2)) / 2); } else if ( ((t >= w) && (t < d))) {ct += ((w * (w + 1)) / 2); long k = (t - (w - 1)); ct += (k * w); } else if ( ((t >= w) && (t >= d))) {ct += (w * d); long k = ((w - 2) - (t - d)); ct -= ((k * (k + 1)) / 2); } w = ((n + 1) - x); d = ((n + 1) - y); if ( (w > d)) { long tt = w; w = d; d = tt; } if ( (t >= ((d + w) - 2))) ct += (d * w); else if ( ((t < w) && (t < d))) {ct += (((t + 1) * (t + 2)) / 2); } else if ( ((t >= w) && (t < d))) {ct += ((w * (w + 1)) / 2); long k = (t - (w - 1)); ct += (k * w); } else if ( ((t >= w) && (t >= d))) {ct += (w * d); long k = ((w - 2) - (t - d)); ct -= ((k * (k + 1)) / 2); } ct -= Math.min(t,(x - 1)); ct -= Math.min(t,(y - 1)); ct -= Math.min(t,(n - x)); ct -= Math.min(t,(n - y)); if ( (ct >= c)) return true; else return false;} } class FastScanner extends BufferedReader{ public FastScanner( InputStream is){ super(new InputStreamReader(is)); } public int read(){ try{ int ret = super.read(); return ret; }catch (IOException e){ throw (new InputMismatchException());} } public String next(){ StringBuilder sb = new StringBuilder();  int c = read(); while(isWhiteSpace(c)){c = read(); }if ( (c < 0)) {return null;} while(((c >= 0) && !isWhiteSpace(c))){sb.appendCodePoint(c); c = read(); }return sb.toString();} static boolean isWhiteSpace( int c){ return ((c >= 0) && (c <= 32));} public long nextLong(){ return Long.parseLong(next());} } class FastPrinter extends PrintWriter{ public FastPrinter( OutputStream out){ super(out); } public FastPrinter( Writer out){ super(out); } }
5	public class A implements Runnable{ BufferedReader in ; PrintWriter out ; StringTokenizer st ; public static final String filename = "a"; class I implements Comparable<I>{ int x ; int a ; I( int x, int a){ this.x = x; this.a = a; } } public void solve()throws IOException { int n = nextInt();  int t = nextInt();  I[] a = new I[n]; for ( int i = 0;(i < n);i++) {a[i] = new I(nextInt(),nextInt()); } int res = 2; Arrays.sort(a); for ( int i = 1;(i < n);i++) {if ( (((a[i].x - a[(i - 1)].x) - ((1.0 * (a[i].a + a[(i - 1)].a)) / 2)) >= t)) res++; if ( (((a[i].x - a[(i - 1)].x) - ((1.0 * (a[i].a + a[(i - 1)].a)) / 2)) > t)) res++; }out.println(res); } public static void main( String[] args){ new Thread(new A()).start(); } public String nextToken()throws IOException { while(!st.hasMoreTokens()){st = new StringTokenizer(in.readLine()); }return st.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
5	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 { while(!st.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) return null; eat(line); }return st.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args){ new Thread(new Main()).start(); } public void go()throws IOException { int n = nextInt(),t = nextInt();  int[] x = new int[n],a = new int[n]; for ( int i = 0;(i < n);++i) {x[i] = nextInt(); a[i] = nextInt(); }out.println(new Algo().solve(n,t,x,a)); } } final class Algo{ public int solve( int n, int t,final int[] x,final int[] a){ Integer[] order = new Integer[n]; for ( int i = 0;(i < n);++i) order[i] = i; Arrays.sort(order,new Comparator<Integer>(){}); int result = 2; for ( int i = 0;((i + 1) < n);++i) { int u = order[i],v = order[(i + 1)];  int dist = ((2 * (x[v] - x[u])) - (a[v] + a[u])); if ( (dist > (2 * t))) result += 2; else if ( (dist == (2 * t))) ++result; }return result;} }
2	public class Main{ public static void main( String[] args)throws Exception { Scanner scan = new Scanner(System.in);  long n = scan.nextLong();  long k = scan.nextLong();  long total = (((k * (k - 1)) / 2) + 1); if ( (total < n)) {System.out.println(-1); return ;} long left = (total - n);  long low = 1;  long high = (k - 1); while((low < high)){ long mid = ((low + high) / 2);  long temp = ((mid * (mid + 1)) / 2); if ( (temp < left)) {low = (mid + 1); } else {high = mid; }} long temp = ((low * (low + 1)) / 2); if ( (temp == left)) {System.out.println(((k - 1) - low)); } else {System.out.println((k - low)); }} }
2	public class Solution{ public static void main( String[] args)throws IOException { boolean online = "true".equals(System.getProperty("ONLINE_JUDGE")); if ( online) {in = new InputReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else {in = new InputReader(new FileReader("input.txt")); out = new PrintWriter(new File("output.txt")); }new Solution().run(); out.close(); } long sum( int x){ return (((x * 1l) * (x + 1)) / 2);} int bins( long n, int k){ int l = 1,r = k; while((l < r)){ int w = ((l + r) / 2);  long s = (sum(k) - sum((w - 1))); if ( (s == n)) return w; if ( (s < n)) r = w; else l = (w + 1); }return l;} private void run(){ long n = in.nextLong();  int k = in.nextInt(); if ( (n == 1)) {out.println(0); return ;} if ( ((1 + sum((k - 1))) < n)) {out.println(-1); return ;} int c = bins((n - 1),(k - 1)); if ( (((1 + sum((k - 1))) - sum((c - 1))) == n)) out.println((k - c)); else out.println(((k - c) + 1)); } static private InputReader in ; static private PrintWriter out ; } class InputReader{ public InputReader( Reader r){ buff = new BufferedReader(r); try{str = new StringTokenizer(buff.readLine()); }catch (IOException e){ e.printStackTrace(); } } public String next(){ while(!str.hasMoreTokens())try{str = new StringTokenizer(buff.readLine()); }catch (IOException e){ e.printStackTrace(); } return str.nextToken();} public int nextInt(){ return Integer.parseInt(this.next());} public long nextLong(){ return Long.parseLong(this.next());} static private BufferedReader buff ; static private StringTokenizer str ; }
2	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(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, InputReader in, PrintWriter out){ long N = in.nextLong();  long K = in.nextLong(); if ( (N == 1)) {out.println(0); return ;} if ( (N <= K)) {out.println(1); return ;} long st = 1;  long dr = (K - 1);  long m ;  long ans = -1; while((st <= dr)){m = ((st + dr) / 2); if ( (get(m,K) <= N)) {ans = m; st = (m + 1); } else dr = (m - 1); }N -= get(ans,K); if ( ((ans == -1) || ((ans == (K - 1)) && (N > 0)))) {out.println(-1); return ;} if ( (N > 0)) ans++; out.println(ans); } private long get( long p, long K){ long sum = (((((K - p) + 1) + K) * p) / 2);  long extra = (p - 1); return (sum - extra);} } class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public long nextLong(){ return Long.parseLong(nextString());} public String nextString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuffer res = new StringBuffer(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} }
2	public class B{ public static void main( String[] args){ FastScanner sc = new FastScanner();  long n = sc.nextLong();  int k = sc.nextInt(); if ( (n == 1)) {System.out.println(0); return ;} n = (n - 1); int count = 0;  long nextK = (k - 1); while(true){if ( ((nextK < 1) || ((nextK <= 1) && (n > 1)))) {System.out.println(-1); return ;} nextK = Math.min(n,nextK); if ( (n == nextK)) {System.out.println((count + 1)); return ;} long bSum = ((nextK * (nextK + 1)) / 2);  long a = nextK;  long decrement = 1; while((((bSum - (((a - 1) * a) / 2)) <= n) && (a >= 1))){a -= decrement; decrement *= 2; }a += (decrement / 2); count += ((nextK - a) + 1); long nDecr = (bSum - ((a * (a - 1)) / 2)); n -= nDecr; nextK = (a - 1); if ( (n == 0)) {System.out.println(count); return ;} }} public static 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();} int nextInt(){ return Integer.parseInt(nextToken());} long nextLong(){ return Long.parseLong(nextToken());} } }
5	public class Village{ private class House implements Comparable<House>{ Double Coordinate ; Double Sidelength ; private House( double coordinate, double sidelength){ Coordinate = coordinate; Sidelength = sidelength; } public int compareTo( House o){ return Coordinate.compareTo(o.Coordinate);} } private void solve(){ Scanner in = new Scanner(System.in); in.next(); double requireside = in.nextDouble();  ArrayList<House> coordinate = new ArrayList<House>(); while(in.hasNext()){ double coo = in.nextDouble();  double side = in.nextDouble(); coordinate.add(new House(coo,side)); }Collections.sort(coordinate); ArrayList<Double> edges = new ArrayList<Double>();  int count = 2; for ( int i = 0;(i < coordinate.size());i++) {edges.add((coordinate.get(i).Coordinate - ((double)coordinate.get(i).Sidelength / (double)2))); edges.add((coordinate.get(i).Coordinate + ((double)coordinate.get(i).Sidelength / (double)2))); } ArrayList<Double> difference = new ArrayList<Double>(); for ( int i = 1;(i < (edges.size() - 1));i++) {difference.add(Math.abs((edges.get(i) - edges.get((i + 1))))); }for ( int i = 0;(i < difference.size());i += 2) {if ( (difference.get(i) == requireside)) count++; else if ( (difference.get(i) > requireside)) count += 2; }System.out.println(count); } public static void main( String[] args){ Village v = new Village(); v.solve(); } }
2	public class ProblemB{ public static void main( String[] args)throws IOException { ProblemB solver = new ProblemB(); solver.init(); solver.solve(); } private void init(){ } private void solve()throws IOException { Reader in = new Reader(System.in);  PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));  int n = in.nextInt();  int x = in.nextInt();  int y = in.nextInt();  int c = in.nextInt();  long lo = 0;  long hi = (2 * n); while((lo < hi)){ long mid = ((lo + hi) / 2);  long r = count(n,x,y,mid); if ( (r < c)) {lo = (mid + 1); } else {hi = mid; ;}}out.println(lo); out.flush(); out.close(); } private long count( int n, int x, int y, long steps){ long r = (1 + ((2 * steps) * (1 + steps))); r -= countWall(((x - 1) - steps)); r -= countWall(((y - 1) - steps)); r -= countWall((n - (x + steps))); r -= countWall((n - (y + steps))); r += countCorner((((steps - (x - 1)) - (y - 1)) - 1)); r += countCorner((((steps - (y - 1)) - (n - x)) - 1)); r += countCorner((((steps - (n - x)) - (n - y)) - 1)); r += countCorner((((steps - (x - 1)) - (n - y)) - 1)); return r;} private long countCorner( long x){ if ( (x <= 0)) return 0; return ((x * (x + 1)) / 2);} private long countWall( long x){ if ( (x >= 0)) return 0; return (x * x);} static private class Reader{ BufferedReader reader ; StringTokenizer tokenizer ; Reader( InputStream input){ reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } public String next()throws IOException { while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(next());} } }
2	public class B implements Runnable{ static private final String TASK_NAME_FOR_IO = ""; static private final String FILE_IN = (TASK_NAME_FOR_IO + ".in"); static private final String FILE_OUT = (TASK_NAME_FOR_IO + ".out"); BufferedReader in ; PrintWriter out ; StringTokenizer tokenizer = new StringTokenizer(""); public static void main( String[] args){ new Thread(new B()).start(); } private void solve()throws IOException { long n = nextLong();  long k = nextLong(); n--; k--; long answer = 0; while(((n > 0) && (k >= 1))){if ( (k > 2000)) { long step1000 = ((k + (k - 999)) * 500); if ( ((n - step1000) >= 0)) {n -= step1000; answer += 1000; k -= 1000; continue;} } if ( ((n - k) >= 0)) {n -= k; answer++; } k--; k = Math.min(n,k); }if ( (n == 0)) {out.println(answer); } else {out.println(-1); }} private String nextToken()throws IOException { while(!tokenizer.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) {return null;} tokenizer = new StringTokenizer(line); }return tokenizer.nextToken();} private long nextLong()throws IOException { return Long.parseLong(nextToken());} }
1	public class _1036_B_DiagonalWalkingV2{ public static void main( String[] args)throws IOException { int Q = readInt(); while((Q-- > 0)){ long n = readLong(),m = readLong(),k = readLong(); if ( (Math.max(n,m) > k)) println(-1); else { long ans = k; if ( ((n % 2) != (k % 2))) ans--; if ( ((m % 2) != (k % 2))) ans--; println(ans); }}exit(); } static private final int BUFFER_SIZE = (1 << 16); static private DataInputStream din = new DataInputStream(System.in); static private byte[] buffer = new byte[BUFFER_SIZE]; static private int bufferPointer = 0,bytesRead = 0; static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static String read()throws IOException { byte[] ret = new byte[1024];  int idx = 0;  byte c = Read(); while((c <= ' ')){c = Read(); }do {ret[idx++] = c; c = Read(); }while(((((c != -1) && (c != ' ')) && (c != '\n')) && (c != '\r')));return new String(ret,0,idx);} public static int readInt()throws IOException { int ret = 0;  byte c = Read(); while((c <= ' '))c = Read(); boolean neg = (c == '-'); if ( neg) c = Read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = Read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} public static long readLong()throws IOException { long ret = 0;  byte c = Read(); while((c <= ' '))c = Read(); boolean neg = (c == '-'); if ( neg) c = Read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = Read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} static private void fillBuffer()throws IOException { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } static private byte Read()throws IOException { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} static void print( Object o){ pr.print(o); } static void println( Object o){ pr.println(o); } static void flush(){ pr.flush(); } static void println(){ pr.println(); } static void exit()throws IOException { din.close(); pr.close(); System.exit(0); } }
5	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));  String out = "";  String[] p = br.readLine().split("[ ]");  int n = Integer.valueOf(p[0]);  double t = Double.valueOf(p[1]);  int offset = 5000;  boolean[] flags = new boolean[(offset + 5000)]; for ( int i = 0;(i < n);i++) { int[] q = toIntArray(br.readLine());  int c = (2 * q[0]); for ( int j = -q[1];(j < q[1]);j++) {flags[((c + offset) + j)] = true; }} int buf = 0;  int last = -1;  int index = 0; for ( ;(index < flags.length);index++) {if ( flags[index]) {if ( (last == -1)) {buf++; } else {if ( (Math.abs(((index - last) - ((2 * t) + 1))) < 1e-10)) buf++; else if ( ((index - last) > ((2 * t) + 1))) buf += 2; }last = index; } }buf++; out = (("" + buf) + "\r\n"); bw.write(out,0,out.length()); br.close(); bw.close(); } static int[] toIntArray( String line){ String[] p = line.trim().split("\\s+");  int[] out = new int[p.length]; for ( int i = 0;(i < out.length);i++) out[i] = Integer.valueOf(p[i]); return out;} }
3	public class A{ public static int mod = 1000000007; public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  char s[] = new char[n]; for ( int i = 0;(i < n);i++) s[i] = sc.next().charAt(0); int dp[][] = new int[5001][5001];  int sum[][] = new int[5001][5001]; dp[0][0] = 1; sum[0][0] = 1; for ( int i = 1;(i < n);i++) {for ( int j = (n - 1);(j >= 0);j--) {if ( ((s[(i - 1)] == 'f') && (j > 0))) {dp[i][j] = (dp[(i - 1)][(j - 1)] % mod); } else if ( (s[(i - 1)] == 's')) {dp[i][j] = (sum[(i - 1)][j] % mod); } sum[i][j] = ((sum[i][(j + 1)] + dp[i][j]) % mod); }}System.out.println(sum[(n - 1)][0]); } }
6	public class EdC{ static long[] mods = {1000000007,998244353,1000000009}; static long mod = mods[0]; public static MyScanner sc ; public static PrintWriter out ; static char[][] grid ; static int n ; static int t ; static int[][] dp ; static int[] times ; static int[] genre ; public static void main( String[] omkar)throws Exception { sc = new MyScanner(); out = new PrintWriter(System.out); n = sc.nextInt(); t = sc.nextInt(); times = new int[n]; genre = new int[n]; for ( int j = 0;(j < n);j++) {times[j] = sc.nextInt(); genre[j] = sc.nextInt(); }dp = new int[(1 << n)][4]; for ( int j = 0;(j < (1 << n));j++) Arrays.fill(dp[j],-1); int ans = 0; for ( int j = 0;(j < (1 << n));j++) { int time = 0; for ( int k = 0;(k < n);k++) {if ( (((1 << k) & j) != 0)) {time += times[k]; } }if ( (time == t)) {letsgodp(j,1); letsgodp(j,2); letsgodp(j,3); ans += dp[j][1]; ans %= mod; ans += dp[j][2]; ans %= mod; ans += dp[j][3]; ans %= mod; } }out.println(ans); out.close(); } public static void letsgodp( int mask, int dg){ if ( (dp[mask][dg] != -1)) return ; dp[mask][dg] = 0; for ( int j = 0;(j < n);j++) {if ( ((((1 << j) & mask) != 0) && (genre[j] == dg))) { int submask = (mask - (1 << j));  int og1 = (((genre[j] + 1) > 3)?(genre[j] - 2):(genre[j] + 1));  int og2 = (((genre[j] + 2) > 3)?(genre[j] - 1):(genre[j] + 2)); if ( (submask != 0)) {letsgodp(submask,og1); letsgodp(submask,og2); dp[mask][dg] += (dp[submask][og1] + dp[submask][og2]); dp[mask][dg] %= mod; } else {dp[mask][dg] = 1; }} }} public static void sort( int[] array){ ArrayList<Integer> copy = new ArrayList<Integer>(); for ( int i :array) copy.add(i); Collections.sort(copy); for ( int i = 0;(i < array.length);i++) array[i] = copy.get(i); } static long power( long x, long y){ if ( (y == 0)) return 1; if ( ((y % 2) == 1)) return ((x * power(x,(y - 1))) % mod); return (power(((x * x) % mod),(y / 2)) % mod);} 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());} } }
2	public class B2{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  BigInteger n = new BigInteger(scan.next());  BigInteger k = new BigInteger(scan.next());  BigInteger a = k.subtract(bi(1));  BigInteger lim = k.multiply(a).divide(bi(2)); lim = lim.add(bi(1)); if ( (n.compareTo(lim) > 0)) {System.out.println(-1); } else {if ( n.equals(1)) {System.out.println(0); } else { BigInteger remain2 = lim.subtract(n).add(bi(1)); remain2 = remain2.multiply(bi(2)); double temp = remain2.doubleValue();  long flr = (long)Math.sqrt(temp);  BigInteger flr2 = bi(flr);  BigInteger rnd2 = remain2.subtract(flr2.multiply(flr2));  long rnd = (remain2.longValue() - (flr * flr)); if ( (rnd2.compareTo(flr2) <= 0)) {System.out.println(k.subtract(flr2)); } else {System.out.println(k.subtract(flr2.add(bi(1)))); }}}} public static BigInteger bi( int n1){ return new BigInteger(("" + n1));} public static BigInteger bi( long n1){ return new BigInteger(("" + n1));} }
6	public class cf2{ static int x0 ; static int y0 ; static int x1 ; static int y1 ; static HashMap<Integer,HashSet<Integer>> allowed ; static HashMap<Integer,HashMap<Integer,Integer>> cost ; static int[] dx = {-1,-1,-1,0,0,0,1,1,1}; static int[] dy = {-1,0,1,-1,0,1,-1,0,1}; static int highbound = (int)1e9; static boolean valid( int i, int j){ if ( ((((((i >= 1) && (i <= highbound)) && (j >= 1)) && (j <= highbound)) && allowed.containsKey(i)) && allowed.get(i).contains(j))) return true; return false;} static long ans ; static class Triple implements Comparable<Triple>{ int i ,j ,cost ; Triple( int x, int y, int z){ i = x; j = y; cost = z; } public int compareTo( Triple t){ return (this.cost - t.cost);} public String toString(){ return ((((i + " ") + j) + " ") + cost);} } static int t ; static int n ; static int[] ds ; static int[] gs ; static int[][] memo ; static int dp( int lastg, int msk, int sum){ if ( (sum == t)) return 1; if ( (msk == ((1 << n) - 1))) {return 0;} if ( (memo[lastg][msk] != -1)) return memo[lastg][msk]; int tot = 0; for ( int i = 0;(i < n);i++) {if ( ((((1 << i) & msk) == 0) && (gs[i] != lastg))) {tot = ((tot + dp(gs[i],(msk | (1 << i)),(sum + ds[i]))) % 1000000007); } }return memo[lastg][msk] = tot;} public static void main( String[] args)throws IOException { MScanner sc = new MScanner(System.in);  PrintWriter pw = new PrintWriter(System.out); n = sc.nextInt(); t = sc.nextInt(); ds = new int[n]; gs = new int[n]; for ( int i = 0;(i < n);i++) {ds[i] = sc.nextInt(); gs[i] = sc.nextInt(); }memo = new int[4][(1 << n)]; for ( int[] i :memo) Arrays.fill(i,-1); pw.println(dp(0,0,0)); pw.flush(); } static long gcd( long a, long b){ if ( (b == 0)) return a; return gcd(b,(a % b));} static int[] primes ; static int sizeofp = 0; static int[] isComposite ; static class MScanner{ StringTokenizer st ; BufferedReader br ; public MScanner( 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 boolean ready()throws IOException { return br.ready();} } }
3	public class C909{ 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.nextInt();  int ar[] = new int[(n + 1)];  int count = 1; ar[0] = 1; for ( int i = 0;(i < n);i++) { char c = in.next().charAt(0); if ( (c == 'f')) count++; else {for ( int j = 1;(j < count);j++) {ar[j] = ((ar[j] + ar[(j - 1)]) % (int)(1e9 + 7)); }}}out.println(ar[(count - 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 int nextInt(){ return Integer.parseInt(next());} } }
6	public class x1185G1b{ static long MOD = 1000000007L; public static void main( String[] args)throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  StringTokenizer st = new StringTokenizer(infile.readLine());  int N = Integer.parseInt(st.nextToken());  int T = Integer.parseInt(st.nextToken());  Song[] arr = new Song[N]; for ( int i = 0;(i < N);i++) {st = new StringTokenizer(infile.readLine()); int a = Integer.parseInt(st.nextToken());  int b = (Integer.parseInt(st.nextToken()) - 1); arr[i] = new Song(a,b); } long[][] dp = new long[(1 << N)][3]; Arrays.fill(dp[0],1L); for ( int mask = 0;(mask < dp.length);mask++) {for ( int i = 0;(i < N);i++) if ( ((mask & (1 << i)) == 0)) { Song c = arr[i]; if ( ((mask == 0) && (c.t <= T))) {dp[(mask | (1 << i))][c.g]++; dp[(mask | (1 << i))][c.g] %= MOD; } else {for ( int gen = 0;(gen < 3);gen++) if ( (gen != c.g)) {dp[(mask | (1 << i))][c.g] += dp[mask][gen]; dp[(mask | (1 << i))][c.g] %= MOD; } }} } long res = 0L; for ( int mask = 1;(mask < dp.length);mask++) for ( int i = 0;(i < 3);i++) { int sum = 0; for ( int b = 0;(b < N);b++) if ( ((mask & (1 << b)) > 0)) sum += arr[b].t; if ( (sum == T)) res = ((res + dp[mask][i]) % MOD); }System.out.println(res); } } class Song{ public int t ; public int g ; public Song( int a, int b){ t = a; g = b; } }
1	public class A implements Runnable{ String file = "input"; void init()throws IOException { input = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedOutputStream(System.out)); } void solve()throws IOException { int odd = 0,even = 0;  int n = nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); if ( ((a[i] % 2) == 0)) even++; else odd++; }if ( (even >= 2)) {for ( int i = 0;(i < n);i++) if ( ((a[i] % 2) == 1)) {System.out.println((i + 1)); return ;} } else {for ( int i = 0;(i < n);i++) if ( ((a[i] % 2) == 0)) {System.out.println((i + 1)); return ;} }} String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(input.readLine()); return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(next());} BufferedReader input ; PrintWriter out ; StringTokenizer st ; int test ; public static void main( String[] args)throws IOException { new Thread(null,new A(),"",(1 << 20)).start(); } }
5	public class ProblemA{ static ArrayList<Point2> houses = new ArrayList<Point2>(); public static void main( String[] args){ ProblemA a = new ProblemA();  Scanner in = new Scanner(System.in); while(in.hasNextInt()){ int n = in.nextInt();  double t = in.nextDouble(); for ( int k = 0;(k < n);k++) {houses.add(new Point2(in.nextDouble(),in.nextDouble())); }Collections.sort(houses); int ans = 2; for ( int k = 0;(k < (n - 1));k++) { Point2 cur = houses.get(k);  Point2 next = houses.get((k + 1));  double dist = ((next.x - (next.y / 2)) - (cur.x + (cur.y / 2))); if ( (dist == t)) ans++; if ( (dist > t)) ans += 2; }System.out.println(ans); }} }
2	public class Main{ static BigInteger n ,x ,y ,c ; static BigInteger mk[] = new BigInteger[8]; public static BigInteger f( BigInteger t){ return t.multiply(t);} public static BigInteger g( BigInteger t){ return t.multiply(t.add(BigInteger.ONE)).shiftRight(1);} public static int solve( BigInteger z){ BigInteger ret = z.multiply(z.add(BigInteger.ONE)).shiftLeft(1); ret = ret.add(BigInteger.ONE); for ( int i = 0;(i < 8);i += 2) {if ( (z.compareTo(mk[i]) > 0)) {ret = ret.subtract(f(z.subtract(mk[i]))); } }for ( int i = 1;(i < 8);i += 2) {if ( (z.compareTo(mk[i]) > 0)) {ret = ret.add(g(z.subtract(mk[i]))); } }if ( (ret.compareTo(c) >= 0)) return 1; return 0;} public static void main( String[] args){ Scanner cin = new Scanner(System.in); while(cin.hasNext()){n = cin.nextBigInteger(); x = cin.nextBigInteger(); y = cin.nextBigInteger(); c = cin.nextBigInteger(); mk[0] = x.subtract(BigInteger.ONE); mk[2] = n.subtract(y); mk[4] = n.subtract(x); mk[6] = y.subtract(BigInteger.ONE); mk[1] = mk[0].add(mk[2]).add(BigInteger.ONE); mk[3] = mk[2].add(mk[4]).add(BigInteger.ONE); mk[5] = mk[4].add(mk[6]).add(BigInteger.ONE); mk[7] = mk[6].add(mk[0]).add(BigInteger.ONE); BigInteger beg = BigInteger.ZERO,end = mk[0],mid ; for ( int i = 1;(i < 8);++i) if ( (end.compareTo(mk[i]) < 0)) end = mk[i]; while((beg.compareTo(end) < 0)){mid = beg.add(end).shiftRight(1); if ( (solve(mid) == 1)) end = mid; else beg = mid.add(BigInteger.ONE); }System.out.println(end); }} }
3	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(); } @SuppressWarnings("Duplicates") static class TaskC{ public void solve( int testNumber, InputReader in, PrintWriter out){ int MAX = 6000;  int MOD = 1000000007;  int n = in.nextInt();  int[][] dp = new int[n][MAX]; dp[0][0] = 1; char next ;  int current ; for ( int i = 0;(i < n);i++) {next = in.next().charAt(0); if ( (i == (n - 1))) continue; current = 0; for ( int j = (MAX - 1);(j >= 0);j--) {if ( (dp[i][j] != 0)) {if ( (next == 'f')) {if ( (j < (MAX - 1))) dp[(i + 1)][(j + 1)] = ((dp[(i + 1)][(j + 1)] + dp[i][j]) % MOD); } else {current = ((current + dp[i][j]) % MOD); }} if ( (next == 's')) dp[(i + 1)][j] = current; }} int res = 0; for ( int i = 0;(i < MAX);i++) {res = ((res + dp[(n - 1)][i]) % MOD); }out.print(res); } } static class InputReader{ private final BufferedReader reader ; private StringTokenizer tokenizer ; public InputReader( InputStream in){ reader = new BufferedReader(new InputStreamReader(in)); } public int nextInt(){ return Integer.parseInt(next());} public String next(){ while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(readLine()); }return tokenizer.nextToken();} public String readLine(){ String line ; try{line = reader.readLine(); }catch (IOException e){ throw (new RuntimeException(e));} return line;} } }
4	public class C{ static class Struct{ int x ,y ,count ; public Struct( int xx, int yy, int c){ x = xx; y = yy; count = c; } } public static void main( String[] args)throws IOException { Scanner sc = new Scanner(new FileReader("input.txt"));  int n = sc.nextInt();  int m = sc.nextInt();  FileWriter fw = new FileWriter("output.txt");  boolean[][] grid = new boolean[n][m];  int[] dx = new int[]{1,0,-1,0};  int[] dy = new int[]{0,-1,0,1};  int k = sc.nextInt();  LinkedList<Struct> a = new LinkedList<Struct>(); for ( int i = 0;(i < k);i++) {a.add(new Struct((sc.nextInt() - 1),(sc.nextInt() - 1),0)); } int max = Integer.MIN_VALUE,maxX = -1,maxY = -1; while(!a.isEmpty()){ Struct tmp = a.remove(); if ( (grid[tmp.x][tmp.y] == true)) continue; grid[tmp.x][tmp.y] = true; if ( (tmp.count > max)) {max = tmp.count; maxX = tmp.x; maxY = tmp.y; } for ( int i = 0;(i < 4);i++) { int nx = (tmp.x + dx[i]);  int ny = (tmp.y + dy[i]); if ( ((((nx < n) && (nx >= 0)) && (ny < m)) && (ny >= 0))) {if ( (grid[nx][ny] == false)) {a.add(new Struct(nx,ny,(tmp.count + 1))); } } }}fw.write(((((maxX + 1) + " ") + (maxY + 1)) + "\n")); System.out.println((((maxX + 1) + " ") + (maxY + 1))); fw.flush(); } }
5	public class A implements Runnable{ static private BufferedReader br = null; static private PrintWriter out = null; static private StringTokenizer stk = null; public static void main( String[] args){ br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); new Thread(new A()).start(); } private void loadLine(){ try{stk = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } private Integer nextInt(){ while(((stk == null) || !stk.hasMoreTokens()))loadLine(); return Integer.parseInt(stk.nextToken());} }
1	public class Abra{ void solve()throws IOException { int n = nextInt(); br.readLine(); int h = 0,t = 0;  String s = br.readLine(); for ( int i = 0;(i < n);i++) {if ( ((char)s.charAt(i) == 'H')) h++; else t++; } int m = 10001; for ( int j = 0;(j < n);j++) { int z = 0; for ( int i = 0;(i < n);i++) {if ( ((i + 1) <= h)) {if ( (s.charAt(((i + j) % n)) != 'H')) z++; } else {if ( (s.charAt(((i + j) % n)) != 'T')) z++; }}if ( (z < m)) m = z; }out.println((m / 2)); } public static void main( String[] args)throws IOException { new Abra().run(); } static class myLib{ long gcd( long a, long b){ if ( ((a == 0) || (b == 0))) return 1; if ( (a < b)) { long c = b; b = a; a = c; } while(((a % b) != 0)){a = (a % b); if ( (a < b)) { long c = b; b = a; a = c; } }return b;} int gcd( int a, int b){ if ( ((a == 0) || (b == 0))) return 1; if ( (a < b)) { int c = b; b = a; a = c; } while(((a % b) != 0)){a = (a % b); if ( (a < b)) { int c = b; b = a; a = c; } }return b;} int partition( int n, int l, int m){ if ( (n < l)) return 0; if ( (n < (l + 2))) return 1; if ( (l == 1)) return 1; int c = 0; for ( int i = Math.min(((n - l) + 1),m);(i >= (((n + l) - 1) / l));i--) {c += partition((n - i),(l - 1),i); }return c;} String numSym = "0123456789ABCDEF"; static boolean stringContainsOf( String x, String c){ for ( int i = 0;(i < x.length());i++) {if ( (c.indexOf(x.charAt(i)) == -1)) return false; }return true;} long pow( long a, long n){ if ( (n == 0)) return 1; long k = n,b = 1,c = a; while((k != 0)){if ( ((k % 2) == 0)) {k /= 2; c *= c; } else {k--; b *= c; }}return b;} int pow( int a, int n){ if ( (n == 0)) return 1; int k = n,b = 1,c = a; while((k != 0)){if ( ((k % 2) == 0)) {k /= 2; c *= c; } else {k--; b *= c; }}return b;} double pow( double a, int n){ if ( (n == 0)) return 1; double k = n,b = 1,c = a; while((k != 0)){if ( ((k % 2) == 0)) {k /= 2; c *= c; } else {k--; b *= c; }}return b;} class NotANumberException extends Exception{ static private final long serialVersionUID = 1L; String mistake ; NotANumberException(){ mistake = "Unknown."; } NotANumberException( String message){ mistake = message; } } int[] rotateDice( int[] a, int n){ int[] c = new int[6]; if ( (n == 0)) {c[0] = a[1]; c[1] = a[5]; c[2] = a[2]; c[3] = a[0]; c[4] = a[4]; c[5] = a[3]; } if ( (n == 1)) {c[0] = a[2]; c[1] = a[1]; c[2] = a[5]; c[3] = a[3]; c[4] = a[0]; c[5] = a[4]; } if ( (n == 2)) {c[0] = a[3]; c[1] = a[0]; c[2] = a[2]; c[3] = a[5]; c[4] = a[4]; c[5] = a[1]; } if ( (n == 3)) {c[0] = a[4]; c[1] = a[1]; c[2] = a[0]; c[3] = a[3]; c[4] = a[5]; c[5] = a[2]; } if ( (n == 4)) {c[0] = a[0]; c[1] = a[2]; c[2] = a[3]; c[3] = a[4]; c[4] = a[1]; c[5] = a[5]; } if ( (n == 5)) {c[0] = a[0]; c[1] = a[4]; c[2] = a[1]; c[3] = a[2]; c[4] = a[3]; c[5] = a[5]; } return c;} int min( int... a){ int c = Integer.MAX_VALUE; for ( int d :a) if ( (d < c)) c = d; return c;} final double goldenRatio = ((1 + Math.sqrt(5)) / 2); final double aGoldenRatio = ((1 - Math.sqrt(5)) / 2); Random random = new Random(); } StreamTokenizer in ; PrintWriter out ; boolean oj ; BufferedReader br ; void init()throws IOException { oj = (System.getProperty("ONLINE_JUDGE") != null); Reader reader = (oj?new InputStreamReader(System.in):new FileReader("input.txt"));  Writer writer = (oj?new OutputStreamWriter(System.out):new FileWriter("output.txt")); br = new BufferedReader(reader); in = new StreamTokenizer(br); out = new PrintWriter(writer); } long selectionTime = 0; void run()throws IOException { long beginTime = System.currentTimeMillis();  long beginMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); init(); solve(); long endMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());  long endTime = System.currentTimeMillis(); if ( !oj) {System.out.println(("Memory used = " + (endMem - beginMem))); System.out.println(("Total memory = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()))); System.out.println(("Running time = " + (endTime - beginTime))); } out.flush(); } int nextInt()throws IOException { in.nextToken(); return (int)in.nval;} myLib lib = new myLib(); }
5	public class A135{ 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;(i < n);i++) {arr[i] = s.nextInt(); }Arrays.sort(arr); int[] ans = new int[n]; if ( (arr[(n - 1)] == 1)) {for ( int i = 0;(i < n);i++) {ans[i] = arr[i]; }ans[(n - 1)] = 2; } else {ans[0] = 1; for ( int i = 1;(i < n);i++) {ans[i] = arr[(i - 1)]; }} StringBuffer buf = new StringBuffer(); for ( int i = 0;(i < n);i++) {buf.append(ans[i]); if ( (i != (n - 1))) buf.append(' '); }System.out.print(buf.toString()); } }
5	public class Task{ static final boolean readFromFile = false; static final String fileInputName = "input.txt",fileOutputName = "output.txt"; public static void main( String[] args){ FileInputStream fileInputStream ;  FileOutputStream fileOutputStream ;  InputStream inputStream = System.in;  OutputStream outputStream = System.out; if ( readFromFile) {try{fileInputStream = new FileInputStream(new File(fileInputName)); fileOutputStream = new FileOutputStream(new File(fileOutputName)); }catch (FileNotFoundException e){ throw (new RuntimeException(e));} } PrintWriter out = new PrintWriter((readFromFile?fileOutputStream:outputStream));  InputReader in = new InputReader((readFromFile?fileInputStream:inputStream));  Solver s = new Solver(in,out); s.solve(); out.close(); } } class Solver{ private PrintWriter out ; private InputReader in ; public void solve(){ int n = in.nextInt();  double t = in.nextDouble(),a[] = new double[n],x[] = new double[n]; for ( int i = 0;(i < n);i++) {x[i] = in.nextDouble(); a[i] = in.nextDouble(); } int ans = 2; for ( int i = 0;(i < (n - 1));i++) for ( int j = (i + 1);(j < n);j++) if ( (x[j] < x[i])) { double buf = x[i]; x[i] = x[j]; x[j] = buf; buf = a[i]; a[i] = a[j]; a[j] = buf; } for ( int i = 0;(i < (n - 1));i++) {if ( (((x[i] + (a[i] / 2)) + t) < (x[(i + 1)] - (a[(i + 1)] / 2)))) ans += 2; if ( (((x[i] + (a[i] / 2)) + t) == (x[(i + 1)] - (a[(i + 1)] / 2)))) ans++; }out.println(ans); } Solver( InputReader in, PrintWriter out){ this.in = in; this.out = out; } } class InputReader{ StringTokenizer tok ; BufferedReader buf ; InputReader( InputStream in){ tok = null; buf = new BufferedReader(new InputStreamReader(in)); } InputReader( FileInputStream in){ tok = null; buf = new BufferedReader(new InputStreamReader(in)); } public String next(){ while(((tok == null) || !tok.hasMoreTokens())){try{tok = new StringTokenizer(buf.readLine()); }catch (IOException e){ throw (new RuntimeException(e));} }return tok.nextToken();} public int nextInt(){ return Integer.parseInt(next());} public double nextDouble(){ return Double.parseDouble(next());} }
0	public class Main{ public static void main( String[] args){ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try{ String parameterStringList[] = reader.readLine().split(" ");  int x = Integer.parseInt(parameterStringList[0]);  int y = Integer.parseInt(parameterStringList[1]);  int z = Integer.parseInt(parameterStringList[2]);  int t1 = Integer.parseInt(parameterStringList[3]);  int t2 = Integer.parseInt(parameterStringList[4]);  int t3 = Integer.parseInt(parameterStringList[5]);  int T1 = (Math.abs((x - y)) * t1);  int T2 = (((Math.abs((x - z)) * t2) + (3 * t3)) + (Math.abs((x - y)) * t2)); if ( (T2 <= T1)) System.out.println("YES"); else System.out.println("NO"); }catch (IOException e){ e.printStackTrace(); } } }
1	public class Solution{ StreamTokenizer in ; PrintWriter out ; public static void main( String[] args)throws Exception { new Solution().run(); } public void run()throws Exception { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); out.flush(); } int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} String next()throws Exception { in.nextToken(); return in.sval;} public void solve()throws Exception { int n = nextInt();  String s = next();  String ss = (s + s);  int t = 0; for ( int i = 0;(i < n);i++) {if ( (s.charAt(i) == 'T')) {t++; } }if ( ((t == 1) || (t == (n - 1)))) {out.println(0); } else { int sum = 0; for ( int i = 0;(i < t);i++) {if ( (s.charAt(i) == 'T')) {sum++; } } int max = sum; for ( int i = 0;(i < s.length());i++) {if ( (ss.charAt(i) == 'T')) {if ( (ss.charAt((i + t)) == 'H')) {sum--; } } else {if ( (ss.charAt((i + t)) == 'T')) {sum++; max = Math.max(max,sum); } }}out.println((t - max)); }} }
3	public final class PythonIndentation{ public static void main( String[] args){ new PythonIndentation(System.in,System.out); } static class Solver implements Runnable{ static final int MOD = ((int)1e9 + 7); int n ; char[] arr ; long[][] dp ; BufferedReader in ; PrintWriter out ; void solve()throws IOException { n = Integer.parseInt(in.readLine()); arr = new char[n]; dp = new long[(n + 1)][(n + 1)]; for ( int i = 0;(i < n);i++) arr[i] = in.readLine().charAt(0); for ( int i = 0;(i <= n);i++) Arrays.fill(dp[i],-1); dp[0][0] = 1; if ( (arr[0] == 's')) out.println(find(1,0)); else out.println(find(1,1)); } long find( int curr, int backIndents){ if ( (backIndents < 0)) return 0; if ( (curr == n)) return dp[curr][backIndents] = 1; if ( (dp[curr][backIndents] != -1)) return dp[curr][backIndents]; long ans ; if ( (arr[curr] == 's')) {if ( (arr[(curr - 1)] == 'f')) ans = find((curr + 1),backIndents); else ans = CMath.mod((find((curr + 1),backIndents) + find(curr,(backIndents - 1))),MOD); } else {ans = find((curr + 1),(backIndents + 1)); if ( (arr[(curr - 1)] != 'f')) {ans = CMath.mod((ans + find(curr,(backIndents - 1))),MOD); } }return dp[curr][backIndents] = ans;} public Solver( BufferedReader in, PrintWriter out){ this.in = in; this.out = out; } } private PythonIndentation( InputStream inputStream, OutputStream outputStream){ BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));  PrintWriter out = new PrintWriter(outputStream);  Thread thread = new Thread(null,new Solver(in,out),"PythonIndentation",(1 << 29)); try{thread.start(); thread.join(); }catch (InterruptedException e){ e.printStackTrace(); } finally{try{in.close(); }catch (IOException e){ e.printStackTrace(); } out.flush(); out.close(); }} }
3	public class C{ static private final int MOD = ((int)1e9 + 7); public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int[][] DP = new int[n][(n + 1)]; DP[0][0] = 1; for ( int i = 0;(i < (n - 1));i++) {if ( (in.next().charAt(0) == 'f')) {for ( int j = 1;(j < n);j++) DP[(i + 1)][j] = DP[i][(j - 1)]; } else {for ( int j = (n - 1);(j >= 0);j--) DP[(i + 1)][j] = ((DP[i][j] + DP[(i + 1)][(j + 1)]) % MOD); }} int answer = 0; for ( int i = 0;(i < n);i++) answer = ((answer + DP[(n - 1)][i]) % MOD); System.out.println(answer); } }
1	public class Main implements Runnable{ public void _main()throws IOException { int n = nextInt();  int[] a = new int[n];  String s = next(); for ( int i = 0;(i < n);i++) a[i] = ((s.charAt(i) == 'H')?1:0); int res = (10 * n); for ( int i = 0;(i < n);i++) { int[] b = new int[n]; for ( int j = 0;(j < n);j++) b[j] = a[((i + j) % n)]; res = Math.min(res,solve(b,0)); res = Math.min(res,solve(b,1)); }out.print(res); } private int solve( int[] a, int x){ int n = a.length;  int j ; for ( j = (n - 1);(j >= 0);j--) if ( (a[j] == x)) break; if ( (a[j] != x)) return 0; int res = 0; for ( int i = 0;(i < j);i++) if ( (a[i] != x)) {--j; while(((j >= i) && (a[j] != x)))--j; ++res; } return res;} private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; private String next()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String rl = in.readLine(); if ( (rl == null)) return null; st = new StringTokenizer(rl); }return st.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args){ Locale.setDefault(Locale.UK); new Thread(new Main()).start(); } }
1	public class Main{ public static void main( String[] args)throws Exception { int i ,j ,k ;  int counter[] = new int[2];  int a[] = new int[200];  int needed ;  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  int N = Integer.parseInt(br.readLine());  StringTokenizer st = new StringTokenizer(br.readLine()); for ( i = 1;(i <= N);i++) {a[i] = Integer.parseInt(st.nextToken()); counter[(a[i] % 2)]++; }if ( (counter[0] == 1)) {needed = 0; } else {needed = 1; }for ( i = 1;(i <= N);i++) {if ( ((a[i] % 2) == needed)) {System.out.println(i); return ;} }} }
5	public class A{ BufferedReader br ; PrintWriter out ; StringTokenizer st ; boolean eof ; void solve()throws IOException { int n = nextInt();  int[] a = new int[n];  boolean onlyOnes = true; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); if ( (a[i] != 1)) onlyOnes = false; }Arrays.sort(a); if ( onlyOnes) {for ( int i = 0;(i < (n - 1));i++) out.print("1 "); out.print(2); } else {out.print("1 "); for ( int i = 0;(i < (n - 1));i++) out.print((a[i] + " ")); }} void inp()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 A().inp(); } String nextToken(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ eof = true; return "0";} }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
0	public class Hexadecimal{ public static void main( String[] args){ Scanner s = new Scanner(new InputStreamReader(System.in));  int x = s.nextInt(); System.out.println(((((x + " ") + 0) + " ") + 0)); } }
4	public class Main{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));  PrintWriter pw = new PrintWriter(new File("output.txt"));  StringTokenizer st ; st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()),m = Integer.parseInt(st.nextToken()),k = Integer.parseInt(in.readLine());  int[][] A = new int[n][m]; st = new StringTokenizer(in.readLine()); for ( int i = 0;(i < k);i++) { int x1 = (Integer.parseInt(st.nextToken()) - 1),y1 = (Integer.parseInt(st.nextToken()) - 1); A[x1][y1] = -10000000; for ( int j = 0;(j < n);j++) {for ( int g = 0;(g < m);g++) {if ( ((A[j][g] == 0) || (A[j][g] > (Math.abs((y1 - g)) + Math.abs((x1 - j)))))) {A[j][g] = (Math.abs((y1 - g)) + Math.abs((x1 - j))); } }}} int f = 0,h = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (A[i][j] != -10000000)) {f = i; h = j; } }}for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( ((A[i][j] > A[f][h]) && (A[i][j] != -10000000))) {f = i; h = j; } }}pw.println((((f + 1) + " ") + (h + 1))); pw.close(); } }
4	public class FireAgain{ public static void main( String[] args)throws IOException { FileInputStream in = null;  FileOutputStream out = null; try{in = new FileInputStream("input.txt"); out = new FileOutputStream("output.txt"); Scanner sc = new Scanner(in);  int h = sc.nextInt();  int w = sc.nextInt();  int k = sc.nextInt();  int[] xk = new int[k];  int[] yk = new int[k]; for ( int i = 0;(i < k);i++) { int y = (sc.nextInt() - 1);  int x = (sc.nextInt() - 1); xk[i] = x; yk[i] = y; } int best = -1;  int bestx = -1;  int besty = -1; for ( int x = 0;(x < w);x++) {for ( int y = 0;(y < h);y++) { int cur = 99999; for ( int f = 0;(f < k);f++) {cur = Math.min(cur,(Math.abs((xk[f] - x)) + Math.abs((yk[f] - y)))); }if ( (cur > best)) {best = cur; bestx = x; besty = y; } }} String s = (((besty + 1) + " ") + (bestx + 1)); out.write(s.getBytes()); }finally{if ( (in != null)) {in.close(); } if ( (out != null)) {out.close(); } }} }
4	public class R035C{ public static final int INF = 987654321; public static final long LINF = 987654321987654321L; public static final double EPS = 1e-9; Scanner scanner ; PrintWriter out ; int[][] iss ; public R035C(){ try{this.scanner = new Scanner(new File("input.txt")); this.out = new PrintWriter("output.txt"); }catch (FileNotFoundException ex){ ex.printStackTrace(); } } class Point implements Comparable<Point>{ int x ,y ,count ; Point( int x, int y){ this.x = x; this.y = y; } } int[] dx = new int[]{0,0,-1,1}; int[] dy = new int[]{-1,1,0,0}; int n ,m ; Queue<Point> q ; Point bfs(){ int max = -INF;  Point p = null; while(!q.isEmpty()){ Point cur = q.remove(); if ( (max < cur.count)) {max = cur.count; p = cur; } for ( int i = 0;(i < dx.length);i++) { int nx = (cur.x + dx[i]);  int ny = (cur.y + dy[i]); if ( ((nx < 0) || (nx >= n))) {continue;} if ( ((ny < 0) || (ny >= m))) {continue;} Point np = new Point(nx,ny); if ( (iss[nx][ny] != 0)) {continue;} np.count = (cur.count + 1); iss[nx][ny] = np.count; q.add(np); }}return p;} private void solve(){ this.n = scanner.nextInt(); this.m = scanner.nextInt(); this.iss = new int[n][m]; int k = scanner.nextInt(); q = new PriorityQueue<Point>(); for ( int i = 0;(i < k);i++) { int x = (scanner.nextInt() - 1);  int y = (scanner.nextInt() - 1);  Point init = new Point(x,y); init.count = 1; q.add(init); iss[x][y] = 1; } Point p = bfs(); out.println((((p.x + 1) + " ") + (p.y + 1))); } private void finish(){ this.out.close(); } public static void main( String[] args){ R035C obj = new R035C(); obj.solve(); obj.finish(); } }
5	public class A{ static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static int nextInt()throws IOException { in.nextToken(); return (int)in.nval;} static PrintWriter out = new PrintWriter(System.out); public static void main( String[] args)throws IOException { int n = nextInt(),t = nextInt(),x[] = new int[n],a[] = new int[n]; for ( int i = 0;(i < n);i++) {x[i] = nextInt(); a[i] = nextInt(); }for ( int i = 0;(i < (n - 1));i++) for ( int j = (i + 1);(j < n);j++) if ( (x[i] > x[j])) { int p = x[i]; x[i] = x[j]; x[j] = p; p = a[i]; a[i] = a[j]; a[j] = p; } double l[] = new double[n];  double r[] = new double[n]; for ( int i = 0;(i < n);i++) {l[i] = (x[i] - (a[i] / 2.0)); r[i] = (x[i] + (a[i] / 2.0)); } int res = 2; for ( int i = 1;(i < n);i++) {if ( (Math.abs(((l[i] - r[(i - 1)]) - t)) < 0.000001)) res++; else if ( ((l[i] - r[(i - 1)]) > t)) res += 2; }out.println(res); out.flush(); } }
1	public class Main{ static private Scanner in = new Scanner(System.in); public static void main( String[] args){ int n = in.nextInt();  String s = in.next(); if ( (n == 1)) System.out.println("1"); else { int j = 0,i = 1,ans = s.length();  int h[] = new int[128]; h[(int)s.charAt(0)] = 1; while((i < n)){if ( (h[(int)s.charAt(i)] == 0)) ans = ((i - j) + 1); h[(int)s.charAt(i)]++; while(((j < i) && (h[(int)s.charAt(j)] > 1))){h[(int)s.charAt(j)]--; j++; ans = Math.min(ans,((i - j) + 1)); }i++; }System.out.println(ans); }} }
3	public class C{ static char[] arr ; static int mod = ((int)1e9 + 7); static int[][] memo ; static int n ; static int solve( int idx, int depth){ if ( (idx == n)) {return ((depth == 0)?1:0);} if ( (memo[idx][depth] != -1)) return memo[idx][depth]; int ret = 0; if ( (arr[idx] == 's')) {if ( (depth > 0)) ret = (ret + solve(idx,(depth - 1))); ret = ((ret + solve((idx + 1),depth)) % mod); } if ( ((arr[idx] == 'f') || (arr[idx] == 'z'))) ret = ((ret + solve((idx + 1),(depth + 1))) % mod); return memo[idx][depth] = ret;} public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in); n = sc.nextInt(); arr = new char[n]; for ( int i = 0;(i < n);i++) arr[i] = sc.next().charAt(0); memo = new int[(n + 1)][(n + 1)]; for ( int[] x :memo) Arrays.fill(x,-1); System.out.println(solve(0,0)); } 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 boolean ready()throws IOException { return br.ready();} } }
5	public class Main{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  int n = sc.nextInt(),t = sc.nextInt(),x ,a ,kol = 2;  ArrayList<Double> al = new ArrayList<Double>(); for ( int i = 0;(i < n);i++) {x = sc.nextInt(); a = sc.nextInt(); al.add((x - (a / 2.))); al.add((x + (a / 2.))); }Collections.sort(al); double d0 = 0;  int k = 0,kn = al.size(); for ( Double d :al) {if ( (k == 2)) {if ( ((d - d0) > t)) kol += 2; else if ( ((d - d0) == t)) kol++; d0 = d; k = 1; } else {k++; d0 = d; }}System.out.print(kol); } }
6	public class Main{ static private final int SIM = 1; static private final int NAO = 2; public static void main( String[] args){ Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));  int n = in.nextInt();  int m = in.nextInt();  int[][] a = new int[n][m];  int[][] graphVerticial = null;  int[][] graphDiagonal = null; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {a[i][j] = in.nextInt(); }}graphVerticial = createGraphVertical(n,m,a); graphDiagonal = createGraphDiagonal(n,m,a); int result = 0;  int k = 1;  int piso = 0;  int teto = 1000000000; while(true){k = ((int)Math.ceil(((teto - piso) / 2.0)) + piso); if ( isOk(n,k,graphVerticial,graphDiagonal)) {result = Math.max(result,k); piso = k; } else {teto = (k - 1); }if ( (teto <= piso)) break; }System.out.println(result); } public static int[][] createGraphVertical( int n, int m, int[][] a){ int[][] graph = new int[n][n]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( (i == j)) continue; if ( (i > j)) {graph[i][j] = graph[j][i]; continue;} graph[i][j] = Integer.MAX_VALUE; for ( int k = 0;(k < m);k++) {graph[i][j] = Math.min(graph[i][j],Math.abs((a[i][k] - a[j][k]))); }}}return graph;} public static int[][] createGraphDiagonal( int n, int m, int[][] a){ int[][] graph = new int[n][n]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {graph[i][j] = Integer.MAX_VALUE; for ( int k = 0;(k < (m - 1));k++) {graph[i][j] = Math.min(graph[i][j],Math.abs((a[j][k] - a[i][(k + 1)]))); }}}return graph;} public static int hasPath( int n, int k, int origem, int destino, int conjunto, int[][] graph, int[][][] pd){ if ( (pd[origem][destino][conjunto] != 0)) return pd[origem][destino][conjunto]; if ( (conjunto == 0)) {return ((origem == destino)?SIM:NAO);} else if ( (origem == destino)) {return NAO;} for ( int i = 0;(i < n);i++) {if ( (i == origem)) continue; int novoConjunto = (conjunto - (1 << i));  boolean pertenceConjunto = (((conjunto >> i) % 2) == 1); if ( ((pertenceConjunto && (graph[origem][i] >= k)) && (hasPath(n,k,i,destino,novoConjunto,graph,pd) == SIM))) {pd[origem][destino][conjunto] = SIM; return pd[origem][destino][conjunto];} }pd[origem][destino][conjunto] = NAO; return pd[origem][destino][conjunto];} public static boolean isOk( int n, int k, int[][] graphVertical, int[][] graphDiagonal){ int conjunto = ((int)Math.pow(2,n) - 1);  int[][][] pd = new int[n][n][(int)Math.pow(2,n)]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( ((i == j) && (n > 1))) continue; int novoConjunto = (conjunto - (1 << i)); if ( ((graphDiagonal[i][j] >= k) && (hasPath(n,k,i,j,novoConjunto,graphVertical,pd) == SIM))) {return true;} }}return false;} public static void print( int[][] graph){ for ( int i = 0;(i < graph.length);i++) {for ( int j = 0;(j < graph.length);j++) {System.out.print((graph[i][j] + " ")); }System.out.println(); }} public static void print( int n){ List<Integer> bits = new Vector<>(); while((n > 0)){bits.add((n % 2)); n /= 2; }for ( int i = (bits.size() - 1);(i >= 0);i--) {System.out.print(bits.get(i)); }System.out.println(); } }
5	public class main{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int houses = sc.nextInt();  int size = sc.nextInt();  hizzy[] array = new hizzy[houses];  long total = 2; for ( int a = 0;(a < houses);a++) array[a] = new hizzy(sc.nextInt(),sc.nextInt()); Arrays.sort(array); for ( int a = 0;(a < (houses - 1));a++) { double L = (array[a].loc + (array[a].size / 2));  double R = (array[(a + 1)].loc - (array[(a + 1)].size / 2)); if ( ((R - L) > size)) total += 2; else if ( ((R - L) == size)) total++; }System.out.println(total); } } class hizzy implements Comparable{ double loc ; double size ; hizzy( double l, double s){ this.loc = l; this.size = s; } }
3	public class Main{ public static void main( String[] args){ Main main = new Main(); main.solveC(); } private void solveC(){ Scanner sc = new Scanner(System.in); final long MOD_NUM = 1000000007L;  int N = sc.nextInt();  long[] level = new long[(N + 2)]; level[0] = 1; sc.nextLine(); String pre = "s"; for ( int i = 0;(i < N);i++) { String line = sc.nextLine();  long[] next_level = new long[(N + 2)]; if ( pre.equals("f")) {for ( int j = 1;(j < (N + 1));j++) {next_level[j] = level[(j - 1)]; }} if ( pre.equals("s")) {for ( int j = N;(j >= 0);j--) {next_level[j] = ((next_level[(j + 1)] + level[j]) % MOD_NUM); }} pre = line; level = next_level; } long answer = 0L; for ( int i = 0;(i < (N + 1));i++) {answer = ((answer + level[i]) % MOD_NUM); }System.out.println(answer); } interface Graph{ void link( int from, int to, long cost); Optional<Long> getCost( int from, int to); int getVertexNum(); } interface FlowResolver{ ; } }
0	public class e{ public 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 (Exception r){ r.printStackTrace(); } }return st.nextToken();} int nextInt(){ return Integer.parseInt(next());} } static ArrayList<String> list1 = new ArrayList<String>(); static void combine( String instr, StringBuffer outstr, int index, int k){ if ( (outstr.length() == k)) {list1.add(outstr.toString()); return ;} if ( (outstr.toString().length() == 0)) outstr.append(instr.charAt(index)); for ( int i = 0;(i < instr.length());i++) {outstr.append(instr.charAt(i)); combine(instr,outstr,(i + 1),k); outstr.deleteCharAt((outstr.length() - 1)); }index++; } static ArrayList<ArrayList<Integer>> l = new ArrayList<>(); static void comb( int n, int k, int ind, ArrayList<Integer> list){ if ( (k == 0)) {l.add(new ArrayList<>(list)); return ;} for ( int i = ind;(i <= n);i++) {list.add(i); comb(n,(k - 1),(ind + 1),list); list.remove((list.size() - 1)); }} public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main( String[] args){ FastReader in = new FastReader();  HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();  int n = in.nextInt();  int r = in.nextInt();  double theta = ((double)360 / (double)n);  double b = (1 - ((double)2 / (double)(1 - Math.cos((((double)2 * Math.PI) / (double)n)))));  double x = (Math.sqrt((1 - b)) - 1);  double ans = ((double)r / (double)x); System.out.println(ans); } }
5	public class codeforces{ public static void main( String[] args){ InputReader in = new InputReader(System.in);  PrintWriter pw = new PrintWriter(System.out);  int n = in.nextInt();  long U = in.nextLong();  long[] E = new long[n];  double max = -1; for ( int i = 0;(i < n);i++) E[i] = in.nextLong(); for ( int k = 1;(k < (n - 1));k++) { int i = (k + 1),j = (n - 1),mid = 0;  double T = 0; while((i < j)){mid = (int)Math.ceil(((double)(i + j) / 2)); if ( ((E[mid] - E[(k - 1)]) <= U)) i = mid; else j = (mid - 1); }j = k; k = i; i = (j - 1); T = (E[k] - E[j]); T /= (E[k] - E[i]); if ( ((E[k] - E[i]) <= U)) max = Math.max(max,T); k = j; }pw.println(max); pw.flush(); pw.close(); } public static long GCD( long a, long b){ if ( (b == 0)) return a; else return GCD(b,(a % b));} static class InputReader{ private final InputStream stream ; private final byte[] buf = new byte[8192]; private int curChar ,snumChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int snext(){ if ( (snumChars == -1)) throw (new InputMismatchException()); if ( (curChar >= snumChars)) {curChar = 0; try{snumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (snumChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} public long nextLong(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
0	public class Main{ final int INF = (Integer.MAX_VALUE / 2); private void doit(){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt(); if ( (n == 0)) {System.out.println("0 0 0"); } else if ( (n == 1)) {System.out.println("0 0 1"); } else { ArrayList<Integer> fibList = new ArrayList<Integer>();  int pre = 0;  int next = 1; fibList.add(pre); fibList.add(next); while((next != n)){ int temp = next; next += pre; fibList.add(next); pre = temp; } int len = fibList.size();  int a = fibList.get((len - 4));  int b = fibList.get((len - 3));  int c = fibList.get((len - 3)); System.out.println(((((a + " ") + b) + " ") + c)); }} public static void main( String[] args){ Main obj = new Main(); obj.doit(); } }
5	public class A{ public static void main( String[] args){ new A(new Scanner(System.in)); } public A( Scanner in){ int n = in.nextInt();  int t = in.nextInt();  int tt = (2 * t);  rect[] rs = new rect[n]; for ( int i = 0;(i < n);i++) rs[i] = new rect(in.nextInt(),in.nextInt()); Arrays.sort(rs); int res = 2; for ( int i = 1;(i < n);i++) { rect a = rs[(i - 1)];  rect b = rs[i];  int d = (b.p - a.p);  int dd = (a.t + b.t);  int tv = ((2 * d) - dd); if ( (tt == tv)) res++; if ( (tv > tt)) res += 2; }System.out.printf("%d%n",res); } } class rect implements Comparable<rect>{ int p ; int t ; public rect( int pp, int tt){ p = pp; t = tt; } }
3	public final class PythonIndentation{ public static void main( String[] args){ new PythonIndentation(System.in,System.out); } static class Solver implements Runnable{ static final int MOD = ((int)1e9 + 7); int n ; char[] arr ; long[][] dp ; BufferedReader in ; PrintWriter out ; void solve()throws IOException { n = Integer.parseInt(in.readLine()); arr = new char[n]; dp = new long[(n + 1)][(n + 1)]; for ( int i = 0;(i < n);i++) arr[i] = in.readLine().charAt(0); for ( int i = 0;(i <= n);i++) Arrays.fill(dp[i],-1); dp[0][0] = 1; if ( (arr[0] == 's')) out.println(find(1,0)); else out.println(find(1,1)); } long find( int curr, int backIndents){ if ( (backIndents < 0)) return 0; if ( (curr == n)) return 1; if ( (dp[curr][backIndents] != -1)) return dp[curr][backIndents]; long ans ; if ( (arr[curr] == 's')) ans = find((curr + 1),backIndents); else ans = find((curr + 1),(backIndents + 1)); if ( (arr[(curr - 1)] != 'f')) ans = CMath.mod((ans + find(curr,(backIndents - 1))),MOD); return dp[curr][backIndents] = ans;} public Solver( BufferedReader in, PrintWriter out){ this.in = in; this.out = out; } } private PythonIndentation( InputStream inputStream, OutputStream outputStream){ BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));  PrintWriter out = new PrintWriter(outputStream);  Thread thread = new Thread(null,new Solver(in,out),"PythonIndentation",(1 << 29)); try{thread.start(); thread.join(); }catch (InterruptedException e){ e.printStackTrace(); } finally{try{in.close(); }catch (IOException e){ e.printStackTrace(); } out.flush(); out.close(); }} }
3	public class Main{ static private final int MAX = (5000 + 10),mod = 1000000007; static private char[] S ; static private int n ; static private Integer[][] dp = new Integer[MAX][MAX]; static private int solve( int pos, int open){ if ( (pos == n)) return ((open == 0)?1:0); if ( (dp[pos][open] != null)) return dp[pos][open]; int res = 0; if ( (S[pos] == 's')) {res = solve((pos + 1),open); if ( (open > 0)) res += solve(pos,(open - 1)); if ( (res >= mod)) res -= mod; } else {res = solve((pos + 1),(open + 1)); }return dp[pos][open] = res;} public static void main( String[] args)throws Exception { IO io = new IO(null,null); n = io.getNextInt(); S = new char[n]; for ( int i = 0;(i < n);i++) S[i] = io.getNext().charAt(0); io.println(solve(0,0)); io.close(); } } class IO{ private BufferedReader br ; private StringTokenizer st ; private PrintWriter writer ; private String inputFile ,outputFile ; public String getNext()throws FileNotFoundException,IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} public int getNextInt()throws FileNotFoundException,IOException { return Integer.parseInt(getNext());} public void print( double x, int num_digits)throws IOException { writer.printf((("%." + num_digits) + "f"),x); } public void println( double x, int num_digits)throws IOException { writer.printf((("%." + num_digits) + "f\n"),x); } public void print( Object o)throws IOException { writer.print(o.toString()); } public void println( Object o)throws IOException { writer.println(o.toString()); } public IO( String x, String y)throws FileNotFoundException,IOException{ inputFile = x; outputFile = y; if ( (x != null)) br = new BufferedReader(new FileReader(inputFile)); else br = new BufferedReader(new InputStreamReader(System.in)); if ( (y != null)) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); else writer = new PrintWriter(new OutputStreamWriter(System.out)); } protected void close()throws IOException { br.close(); writer.close(); } }
1	public class A{ int n ; void run()throws IOException { Scanner sc = new Scanner(new InputStreamReader(System.in)); n = sc.nextInt(); int i ,tmp ,even ,odd ,e ,o ; even = odd = e = o = 0; for ( i = 1;(i <= n);i++) {tmp = sc.nextInt(); if ( ((tmp % 2) == 0)) {e++; if ( (even == 0)) even = i; } else {o++; if ( (odd == 0)) odd = i; }}if ( (e > 1)) System.out.println(odd); else System.out.println(even); } public static void main( String[] args)throws IOException { new A().run(); } }
5	public class Main{ static private StreamTokenizer in ; static private PrintWriter out ; static private int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} public static void main( String[] args)throws Exception { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); int n = nextInt(),t = (nextInt() * 2);  int[][] a = new int[n][2]; for ( int i = 0;(i < n);i++) {a[i][0] = (nextInt() * 2); a[i][1] = (nextInt() * 2); }Arrays.sort(a,new Comparator<int[]>(){}); int s = 2; for ( int i = 0;(i < (n - 1));i++) { int g = ((a[(i + 1)][0] - a[i][0]) - ((a[(i + 1)][1] + a[i][1]) / 2)); if ( (g > t)) s += 2; if ( (g == t)) s += 1; }out.println(s); out.flush(); } }
5	public class A implements Runnable{ private MyScanner in ; private PrintWriter out ; private void solve(){ int n = in.nextInt();  int[] a = new int[n];  int max = -1,maxp = -1; for ( int i = 0;(i < n);++i) {a[i] = in.nextInt(); if ( (a[i] > max)) {max = a[i]; maxp = i; } }if ( (max == 1)) {for ( int i = 0;(i < (n - 1));++i) {out.print((1 + " ")); }out.println(2); return ;} a[maxp] = 1; Arrays.sort(a); for ( int i = 0;(i < n);++i) {out.print((a[i] + " ")); }out.println(); } @Override public void run(){ in = new MyScanner(); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } public static void main( String[] args){ new A().run(); } static class MyScanner{ private BufferedReader br ; private StringTokenizer st ; public MyScanner(){ br = new BufferedReader(new InputStreamReader(System.in)); } public void close(){ try{br.close(); }catch (IOException e){ e.printStackTrace(); } } private String nextToken(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); return null;} }return st.nextToken();} public int nextInt(){ return Integer.parseInt(nextToken());} } }
4	public class Main{ public static void main( String[] args)throws IOException { Scanner scan = new Scanner("input.txt");  PrintWriter out = new PrintWriter(new FileWriter("output.txt"));  int n ,m ; n = scan.nextInt(); m = scan.nextInt(); boolean visited[][] = new boolean[n][m];  int numOfStartingPoints ; numOfStartingPoints = scan.nextInt(); int resX = 0,resY = 0;  Queue<Point> que = new LinkedList<Point>(); for ( int i = 0;(i < numOfStartingPoints);i++) { int x = (scan.nextInt() - 1);  int y = (scan.nextInt() - 1); que.add(new Point(x,y)); visited[x][y] = true; }while(true){ Point current = que.poll(); if ( (current == null)) {break;} else {resX = current.x; resY = current.y; if ( (((current.x + 1) < n) && !visited[(current.x + 1)][current.y])) {que.add(new Point((current.x + 1),current.y)); visited[(current.x + 1)][current.y] = true; } if ( (((current.y + 1) < m) && !visited[current.x][(current.y + 1)])) {que.add(new Point(current.x,(current.y + 1))); visited[current.x][(current.y + 1)] = true; } if ( (((current.x - 1) >= 0) && !visited[(current.x - 1)][current.y])) {que.add(new Point((current.x - 1),current.y)); visited[(current.x - 1)][current.y] = true; } if ( (((current.y - 1) >= 0) && !visited[current.x][(current.y - 1)])) {que.add(new Point(current.x,(current.y - 1))); visited[current.x][(current.y - 1)] = true; } }}out.printf("%d %d\n",++resX,++resY); out.close(); } 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 boolean ready()throws IOException { return br.ready();} } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} FastScanner in = new FastScanner(inputStream);  FastPrinter out = new FastPrinter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ static private final int[] dx = {-1,0,+1,0}; static private final int[] dy = {0,+1,0,-1}; static private final int WHITE = 123456789; public void solve( int testNumber, FastScanner in, FastPrinter out){ int n = in.nextInt();  int m = in.nextInt();  int[][] map = new int[n][m]; for ( int i = 0;(i < n);i++) {Arrays.fill(map[i],WHITE); } int k = in.nextInt();  int qh = 0;  int qt = 0;  int[] q = new int[(int)7e6]; for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); map[x][y] = 0; q[qh++] = ((x * m) + y); } int d = 0;  int X = (q[0] / m);  int Y = (q[0] % m); while((qt < qh)){ int pos = q[qt++];  int x = (pos / m);  int y = (pos % m); for ( int i = 0;(i < 4);i++) { int xx = (x + dx[i]);  int yy = (y + dy[i]); if ( ((isValid(xx,n) && isValid(yy,m)) && (map[xx][yy] == WHITE))) {map[xx][yy] = (map[x][y] + 1); q[qh++] = ((xx * m) + yy); if ( (d < map[xx][yy])) {d = map[xx][yy]; X = xx; Y = yy; } } }}out.println((((X + 1) + " ") + (Y + 1))); } private boolean isValid( int x, int X){ return ((x >= 0) && (x < X));} } static class FastScanner{ public BufferedReader br ; public StringTokenizer st ; public FastScanner( InputStream is){ br = new BufferedReader(new InputStreamReader(is)); } public FastScanner( File f){ try{br = new BufferedReader(new FileReader(f)); }catch (FileNotFoundException e){ e.printStackTrace(); } } public String next(){ while(((st == null) || !st.hasMoreElements())){ String s = null; try{s = br.readLine(); }catch (IOException e){ e.printStackTrace(); } if ( (s == null)) return null; st = new StringTokenizer(s); }return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} } static class FastPrinter extends PrintWriter{ public FastPrinter( OutputStream out){ super(out); } public FastPrinter( Writer out){ super(out); } } }
2	public class B{ BufferedReader br ; PrintWriter out ; StringTokenizer st ; boolean eof ; long f( int x, int y, int sz){ if ( (x > y)) { int tmp = x; x = y; y = tmp; } if ( (sz <= x)) return (((long)sz * (sz + 1)) / 2); if ( (sz >= ((x + y) - 1))) return ((long)x * y); long val = ((x * (x + 1)) / 2); if ( (sz <= y)) return (val + ((long)(sz - x) * x)); long rest = (((x + y) - 1) - sz); return (((long)x * y) - (((long)rest * (rest + 1)) / 2));} long count( int x, int y, int n, int time){ long DL = f((x + 1),(y + 1),(time + 1));  long DR = f((n - x),(y + 1),(time + 1));  long UL = f((x + 1),(n - y),(time + 1));  long UR = f((n - x),(n - y),(time + 1));  long L = Math.min((x + 1),(time + 1));  long R = Math.min((n - x),(time + 1));  long U = Math.min((n - y),(time + 1));  long D = Math.min((y + 1),(time + 1)); return ((((((((DL + DR) + UL) + UR) - L) - R) - U) - D) + 1);} void solve()throws IOException { int n = nextInt();  int x = (nextInt() - 1);  int y = (nextInt() - 1);  long need = nextLong(); if ( (need == 1)) {out.println(0); return ;} int low = 0;  int high = (Math.max(x,((n - 1) - x)) + Math.max(y,((n - 1) - y))); while((low < (high - 1))){ int mid = (int)(((long)low + high) / 2); if ( (count(x,y,n,mid) >= need)) high = mid; else low = mid; }out.println(high); } B()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 B(); } String nextToken(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ eof = true; return null;} }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} long nextLong()throws IOException { return Long.parseLong(nextToken());} }
1	public class A{ public static void main( String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br.readLine(); String[] ss = br.readLine().split(" ");  int n = ss.length;  int[] a = new int[n]; for ( int i = 0;(i < n);++i) a[i] = Integer.parseInt(ss[i]); for ( int i = 0;(i < n);++i) { boolean ok = true; for ( int j = 0;(j < n);++j) if ( ((j != i) && ((a[j] % 2) == (a[i] % 2)))) ok = false; if ( ok) System.out.println((i + 1)); }} }
1	public class ProblemA{ public void solve(){ boolean oj = true; try{ Reader reader = (oj?new InputStreamReader(System.in):new FileReader("A.in"));  Writer writer = (oj?new OutputStreamWriter(System.out):new FileWriter("A.out"));  BufferedReader br = new BufferedReader(reader);  StreamTokenizer st = new StreamTokenizer(reader);  PrintWriter out = new PrintWriter(writer);  int n = Integer.valueOf(br.readLine());  String s = br.readLine();  MyTokenizer tok = new MyTokenizer(s);  int[] a = new int[2];  int[] ind = new int[2];  int[] c = new int[2]; for ( int i = 0;(i < n);i++) { int p = (int)tok.getNum(); c[(p % 2)]++; a[(p % 2)] = p; ind[(p % 2)] = i; } int b = ind[0]; if ( (c[0] > c[1])) b = ind[1]; out.printf("%d",(b + 1)); br.close(); out.close(); reader.close(); writer.close(); }catch (Exception ex){ ex.printStackTrace(); } } public static void main( String[] args){ ProblemA f = new ProblemA(); f.solve(); } private class MyTokenizer{ private String s ; private int cur ; public MyTokenizer( String s){ this.s = s; cur = 0; } public void skip(){ while(((cur < s.length()) && ((s.charAt(cur) == ' ') || (s.charAt(cur) == '\n')))){cur++; }} public double getNum(){ skip(); String snum = ""; while(((cur < s.length()) && ((((s.charAt(cur) >= '0') && (s.charAt(cur) <= '9')) || (s.charAt(cur) == '.')) || (s.charAt(cur) == '-')))){snum += s.charAt(cur); cur++; }return Double.valueOf(snum);} } }
0	public class A{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int f1 = 0;  int f2 = 1;  int f3 = 1; while((f3 < n)){f1 = f2; f2 = f3; f3 = (f1 + f2); }if ( (n == 0)) {System.out.println(((((0 + " ") + 0) + " ") + 0)); } else if ( (f3 == n)) {System.out.println(((((f1 + " ") + f1) + " ") + (f2 - f1))); } else {System.out.println("I'm too stupid to solve this problem"); }} }
6	public class Main{ static private FastScanner sc = new FastScanner(); static private long mod = 1000000007; public static void main( String[] args){ int n = sc.nextInt();  int T = sc.nextInt();  int[] t = new int[n];  int[] g = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = sc.nextInt(); g[i] = (sc.nextInt() - 1); } long[][][] dp = new long[(T + 1)][3][(1 << 15)]; for ( int i = 1;(i <= T);i++) {for ( int j = 0;(j < n);j++) {if ( ((i - t[j]) == 0)) {dp[i][g[j]][(1 << j)] = ((dp[i][g[j]][(1 << j)] + 1) % mod); } else if ( ((i - t[j]) > 0)) {for ( int k = 0;(k < (1 << 15));k++) {if ( (((k >> j) & 1) == 1)) {continue;} dp[i][g[j]][(k + (1 << j))] = (((dp[i][g[j]][(k + (1 << j))] + dp[(i - t[j])][((g[j] + 1) % 3)][k]) + dp[(i - t[j])][((g[j] + 2) % 3)][k]) % mod); }} }} long ans = 0; for ( int j = 0;(j < 3);j++) {for ( int k = 0;(k < (1 << 15));k++) {ans = ((ans + dp[T][j][k]) % mod); }}System.out.println(ans); } static long power( long m, long n){ if ( (n == 0)) {return 1;} else if ( (n == 1)) {return m;} else if ( ((n % 2) == 0)) { long s = power(m,(n / 2)); return (((s % mod) * (s % mod)) % mod);} else {return (((m % mod) * (power(m,(n - 1)) % mod)) % mod);}} static class FastScanner{ private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte(){ if ( (ptr < buflen)) {return true;} else {ptr = 0; try{buflen = in.read(buffer); }catch (IOException e){ e.printStackTrace(); } if ( (buflen <= 0)) {return false;} }return true;} private int readByte(){ if ( hasNextByte()) return buffer[ptr++]; else return -1;} static private boolean isPrintableChar( int c){ return ((33 <= c) && (c <= 126));} private void skipUnprintable(){ while((hasNextByte() && !isPrintableChar(buffer[ptr])))ptr++; } public boolean hasNext(){ skipUnprintable(); return hasNextByte();} public String next(){ if ( !hasNext()) throw (new NoSuchElementException()); StringBuilder sb = new StringBuilder();  int b = readByte(); while(isPrintableChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} public int nextInt(){ return Integer.parseInt(next());} } }
2	public class Main{ static Scanner cin = new Scanner(System.in); static int n ,x ,y ; static long c ; static private long f( int mid){ long block = (1 + (((4 * (long)(mid + 1)) * mid) / 2));  int l = (y - mid);  int r = (y + mid);  int u = (x - mid);  int d = (x + mid); if ( (l <= 0)) block -= ((long)(1 - l) * (1 - l)); if ( (r > n)) block -= ((long)(r - n) * (r - n)); if ( (u <= 0)) block -= ((long)(1 - u) * (1 - u)); if ( (d > n)) block -= ((long)(d - n) * (d - n)); if ( ((u <= 0) && ((1 - u) > ((n - y) + 1)))) { int t = ((1 - u) - ((n - y) + 1)); block += (((long)t * (1 + t)) / 2); } if ( ((u <= 0) && ((1 - u) > y))) { int t = ((1 - u) - y); block += (((long)t * (1 + t)) / 2); } if ( ((d > n) && ((d - n) > ((n - y) + 1)))) { int t = ((d - n) - ((n - y) + 1)); block += (((long)t * (1 + t)) / 2); } if ( ((d > n) && ((d - n) > y))) { int t = ((d - n) - y); block += (((long)t * (1 + t)) / 2); } return block;} public static void main( String[] args){ n = cin.nextInt(); x = cin.nextInt(); y = cin.nextInt(); c = cin.nextLong(); int low = 0,high = 1000000000;  int ans = -1; while((low <= high)){ int mid = ((low + high) / 2); if ( (f(mid) >= c)) {ans = mid; high = (mid - 1); } else {low = (mid + 1); }}System.out.println(ans); } }
5	public class Main{ static Scanner in = new Scanner(System.in); public static void main( String[] args){ int n = in.nextInt();  int t = in.nextInt();  List<Integer> v = new ArrayList<Integer>(n); for ( int i = 0;(i < n);i++) { int a = in.nextInt();  int b = in.nextInt(); v.add(((2 * a) - b)); v.add(((2 * a) + b)); }Collections.sort(v); int ans = 2; for ( int i = 2;(i < v.size());i += 2) {if ( ((v.get(i) - v.get((i - 1))) > (2 * t))) ans += 2; if ( ((v.get(i) - v.get((i - 1))) == (2 * t))) ans++; }System.out.println(ans); } }
0	public class CodeForces{ public void solve()throws IOException { int n = nextInt();  int arr[] = new int[1000]; arr[0] = 0; arr[1] = 1; arr[2] = 1; if ( (n == 0)) {out.print("0 0 0"); } else if ( (n == 1)) {out.print("0 0 1"); } else { int c = 2; while((arr[c] != n)){c++; arr[c] = (arr[(c - 1)] + arr[(c - 2)]); }out.print(((((arr[(c - 2)] + " ") + arr[(c - 2)]) + " ") + arr[(c - 3)])); }} public static void main( String[] args){ new CodeForces().run(); } BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter out ; boolean isOuterFile = false; public void run(){ try{if ( isOuterFile) {reader = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); out = new PrintWriter(System.out); } else {reader = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); }tokenizer = null; solve(); reader.close(); out.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} }
4	public class BetaRound35_C implements Runnable{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws IOException { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new Thread(new BetaRound35_C()).start(); } void solve()throws IOException { int n = readInt();  int m = readInt();  int k = readInt();  Queue<Point> q = new ArrayDeque<Point>();  boolean[][] visited = new boolean[(n + 2)][(m + 2)]; for ( int j = 0;(j < (m + 2));j++) {visited[0][j] = true; visited[(n + 1)][j] = true; }for ( int i = 0;(i < (n + 2));i++) {visited[i][0] = true; visited[i][(m + 1)] = true; }for ( int i = 0;(i < k);i++) { int x = readInt();  int y = readInt(); q.add(new Point(x,y)); visited[x][y] = true; } Point p = null; while(!q.isEmpty()){p = q.poll(); int x = p.x,y = p.y; if ( !visited[(x + 1)][y]) {q.add(new Point((x + 1),y)); visited[(x + 1)][y] = true; } if ( !visited[(x - 1)][y]) {q.add(new Point((x - 1),y)); visited[(x - 1)][y] = true; } if ( !visited[x][(y + 1)]) {q.add(new Point(x,(y + 1))); visited[x][(y + 1)] = true; } if ( !visited[x][(y - 1)]) {q.add(new Point(x,(y - 1))); visited[x][(y - 1)] = true; } }out.print(((p.x + " ") + p.y)); } }
5	public class TaskA implements Runnable{ private InputReader in ; private PrintWriter out ; public static void main( String[] args){ new Thread(new TaskA()).start(); } public TaskA(){ in = new InputReader(System.in); out = new PrintWriter(System.out); } static private class InputReader{ private InputStream stream ; private byte[] buf = new byte[1000]; private int curChar ,numChars ; public InputReader( InputStream stream){ this.stream = stream; } private int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuffer res = new StringBuffer(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private String readLine0(){ StringBuffer buf = new StringBuffer();  int c = read(); while(((c != '\n') && (c != -1))){buf.appendCodePoint(c); c = read(); }return buf.toString();} public String readLine(){ String s = readLine0(); while((s.trim().length() == 0))s = readLine0(); return s;} public String readLine( boolean ignoreEmptyLines){ if ( ignoreEmptyLines) return readLine(); else return readLine0();} } }
3	public class R455D2PC{ public static void main( String[] args){ final int MAX = 5000; final int MODULO = 1000000007;  Scanner in = new Scanner(System.in);  int n = in.nextInt(); in.nextLine(); int pre = 0;  int size = 0;  int[] block = new int[MAX]; for ( int i = 0;(i < n);i++) { String command = in.nextLine(); if ( command.startsWith("s")) {block[size++] = pre; pre = 0; } else {pre++; }}if ( (pre != 0)) {System.out.println(0); return ;} int[][] result = new int[2][(MAX + 1)];  int currentMax = 0;  int preIndex = 0; result[preIndex][0] = 1; for ( int i = 1;(i < size);i++) { int currentIndex = (preIndex ^ 1);  int j = block[(i - 1)]; for ( int k = currentMax;(k >= 0);k--) {result[currentIndex][(k + j)] = ((result[currentIndex][((k + j) + 1)] + result[preIndex][k]) % MODULO); }for ( int k = (j - 1);(k >= 0);k--) {result[currentIndex][k] = result[currentIndex][j]; }currentMax += j; preIndex = currentIndex; } int sum = 0; for ( int i = 0;(i <= currentMax);i++) {sum = ((sum + result[preIndex][i]) % MODULO); }System.out.println(sum); } }
4	public class Problem implements Runnable{ static private final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); private BufferedReader in ; private PrintWriter out ; private StringTokenizer tok = new StringTokenizer(""); private void init()throws FileNotFoundException { Locale.setDefault(Locale.US); String fileName = ""; in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } String readString(){ while(!tok.hasMoreTokens()){try{tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null;} }return tok.nextToken();} int readInt(){ return Integer.parseInt(readString());} public static void main( String[] args){ new Problem().run(); } long timeBegin ,timeEnd ; void time(){ timeEnd = System.currentTimeMillis(); System.err.println(("Time = " + (timeEnd - timeBegin))); } @Override public void run(){ try{timeBegin = System.currentTimeMillis(); init(); solve(); out.close(); time(); }catch (Exception e){ e.printStackTrace(); System.exit(-1); } } int[][] dist ; int n ,m ; private void solve()throws IOException { n = readInt(); m = readInt(); int k = readInt(); dist = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) dist[i][j] = -1; for ( int i = 0;(i < k);i++) {dist[(readInt() - 1)][(readInt() - 1)] = 0; }for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (dist[i][j] == 0)) bfs(i,j);  int max = 0,X = 0,Y = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (dist[i][j] >= max)) {max = dist[i][j]; X = (i + 1); Y = (j + 1); } out.println(((X + " ") + Y)); } public void bfs( int x, int y){ int[] dx = {0,1,0,-1};  int[] dy = {1,0,-1,0}; dist[x][y] = 0; ArrayDeque<P> q = new ArrayDeque<>(); q.add(new P(x,y)); while(!q.isEmpty()){ P v = q.poll(); for ( int i = 0;(i < 4);i++) { int nx = (v.x + dx[i]);  int ny = (v.y + dy[i]); if ( (inside(nx,ny) && ((dist[nx][ny] == -1) || ((dist[nx][ny] > (dist[v.x][v.y] + 1)) && (dist[nx][ny] != 0))))) {q.add(new P(nx,ny)); dist[nx][ny] = (dist[v.x][v.y] + 1); } }}} public boolean inside( int x, int y){ if ( ((((x < n) && (y < m)) && (x >= 0)) && (y >= 0))) {return true;} return false;} } class P{ int x ,y ; public P( int x, int y){ this.x = x; this.y = y; } }
1	public class C{ public static void main( String[] args){ CIO io = new CIO(); try{ Csolver solver = new Csolver(io); solver.solve(); }finally{io.close(); }} } class Csolver{ CIO io ; public Csolver( CIO io){ this.io = io; } public void solve(){ int n = io.nextInt();  String input = io.next();  int[] count = new int[1000];  int pokemonsInRange = 0;  int answer = Integer.MAX_VALUE;  int a = 0;  int b = 0; for ( ;(b < n);b++) { char end = input.charAt(b); if ( (count[end] == 0)) {pokemonsInRange++; answer = Integer.MAX_VALUE; } count[end]++; while((count[input.charAt(a)] > 1)){count[input.charAt(a)]--; a++; }answer = Math.min(answer,((b - a) + 1)); }io.println(answer); } } class CIO extends PrintWriter{ private InputStreamReader r ; static private final int BUFSIZE = (1 << 15); private char[] buf ; private int bufc ; private int bufi ; private StringBuilder sb ; public CIO(){ super(new BufferedOutputStream(System.out)); r = new InputStreamReader(System.in); buf = new char[BUFSIZE]; bufc = 0; bufi = 0; sb = new StringBuilder(); } private void fillBuf()throws IOException { bufi = 0; bufc = 0; while((bufc == 0)){bufc = r.read(buf,0,BUFSIZE); if ( (bufc == -1)) {bufc = 0; return ;} }} private boolean pumpBuf()throws IOException { if ( (bufi == bufc)) {fillBuf(); } return (bufc != 0);} private boolean isDelimiter( char c){ return (((((c == ' ') || (c == '\t')) || (c == '\n')) || (c == '\r')) || (c == '\f'));} private void eatDelimiters()throws IOException { while(true){if ( (bufi == bufc)) {fillBuf(); if ( (bufc == 0)) throw (new RuntimeException("IO: Out of input.")); } if ( !isDelimiter(buf[bufi])) break; ++bufi; }} public String next(){ try{sb.setLength(0); eatDelimiters(); int start = bufi; while(true){if ( (bufi == bufc)) {sb.append(buf,start,(bufi - start)); fillBuf(); start = 0; if ( (bufc == 0)) break; } if ( isDelimiter(buf[bufi])) break; ++bufi; }sb.append(buf,start,(bufi - start)); return sb.toString(); }catch (IOException e){ throw (new RuntimeException("IO.next: Caught IOException."));} } public int nextInt(){ try{ int ret = 0; eatDelimiters(); boolean positive = true; if ( (buf[bufi] == '-')) {++bufi; if ( !pumpBuf()) throw (new RuntimeException("IO.nextInt: Invalid int.")); positive = false; } boolean first = true; while(true){if ( !pumpBuf()) break; if ( isDelimiter(buf[bufi])) {if ( first) throw (new RuntimeException("IO.nextInt: Invalid int.")); break;} first = false; if ( ((buf[bufi] >= '0') && (buf[bufi] <= '9'))) {if ( (ret < -214748364)) throw (new RuntimeException("IO.nextInt: Invalid int.")); ret *= 10; ret -= (int)(buf[bufi] - '0'); if ( (ret > 0)) throw (new RuntimeException("IO.nextInt: Invalid int.")); } else {throw (new RuntimeException("IO.nextInt: Invalid int."));}++bufi; }if ( positive) {if ( (ret == -2147483648)) throw (new RuntimeException("IO.nextInt: Invalid int.")); ret = -ret; } return ret; }catch (IOException e){ throw (new RuntimeException("IO.nextInt: Caught IOException."));} } }
4	public class Solution{ BufferedReader in ; StringTokenizer st ; PrintWriter out ; int n ,m ,k ; int[] x ,y ; char[] qx = new char[4000000],qy = new char[4000000]; int b ,e ; char[][] d ; int[] dx = {-1,0,1,0},dy = {0,-1,0,1}; void bfs(){ b = e = 0; for ( int i = 0;(i < d.length);i++) {Arrays.fill(d[i],(char)(1 << 14)); }for ( int i = 0;(i < k);++i) {qx[e] = (char)x[i]; qy[e++] = (char)y[i]; d[x[i]][y[i]] = 0; }for ( ;(b < e);++b) { int x = qx[b];  int y = qy[b]; for ( int i = 0;(i < 4);++i) { int nx = (x + dx[i]);  int ny = (y + dy[i]); if ( ((((nx >= 0) && (nx < n)) && (ny >= 0)) && (ny < m))) if ( (d[nx][ny] > (d[x][y] + 1))) {d[nx][ny] = (char)(d[x][y] + 1); qx[e] = (char)nx; qy[e++] = (char)ny; } }}} void solve()throws IOException { n = ni(); m = ni(); k = ni(); x = new int[k]; y = new int[k]; for ( int i = 0;(i < k);++i) {x[i] = (ni() - 1); y[i] = (ni() - 1); }d = new char[n][m]; bfs(); int x = -1,y = -1,last = -1; for ( int i = 0;(i < n);++i) for ( int j = 0;(j < m);++j) if ( (d[i][j] > last)) {last = d[i][j]; x = i; y = j; } ++x; ++y; out.println(((x + " ") + y)); } public Solution()throws IOException{ Locale.setDefault(Locale.US); in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); solve(); in.close(); out.close(); } String nline()throws IOException { return in.readLine();} String ns()throws IOException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(nline()); }return st.nextToken();} int ni()throws IOException { return Integer.valueOf(ns());} public static void main( String[] args)throws IOException { new Solution(); } }
1	public class C364C{ static StringTokenizer st ; static BufferedReader br ; static PrintWriter pw ; static int n ; static int[] a ; public static void main( String[] args)throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); n = nextInt(); int ans = n,cc ,cur = 0; a = new int[52]; char[] c = next().toCharArray();  int l = 0,len = 0; for ( int i = 0;(i < n);++i) {if ( Character.isUpperCase(c[i])) {cur = ((26 + c[i]) - 'A'); } else cur = (c[i] - 'a'); if ( (a[cur] == 0)) {a[cur]++; len++; ans = ((i - l) + 1); } else {a[cur]++; for ( ;(l < i);++l) {if ( Character.isUpperCase(c[l])) {cc = ((26 + c[l]) - 'A'); } else cc = (c[l] - 'a'); if ( (a[cc] > 1)) {--a[cc]; } else break;}if ( (((i - l) + 1) < ans)) {ans = ((i - l) + 1); } }}pw.print(ans); pw.close(); } static private int nextInt()throws IOException { return Integer.parseInt(next());} static private String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} }
5	public class Main{ public static void main( String[] args)throws Exception { int n = nextInt();  int[] mas = new int[n]; for ( int i = 0;(i < n);i++) {mas[i] = nextInt(); }Arrays.sort(mas); if ( (mas[(n - 1)] == 1)) {for ( int i = 0;(i < (n - 1));i++) {out.print((1 + " ")); }out.println(2); out.flush(); exit(); } out.print("1 "); for ( int i = 0;(i < (n - 1));i++) {out.print((mas[i] + " ")); }out.println(); out.flush(); } static private StreamTokenizer in ; static private PrintWriter out ; static private BufferedReader inB ; static private boolean FILE = false; static private int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} {try{out = new PrintWriter((FILE?new FileOutputStream("output.txt"):System.out)); inB = new BufferedReader(new InputStreamReader((FILE?new FileInputStream("input.txt"):System.in))); }catch (Exception e){ e.printStackTrace(); } in = new StreamTokenizer(inB); }static private void println( Object o)throws Exception { out.println(o); out.flush(); } static private void exit( Object o)throws Exception { println(o); exit(); } static private void exit(){ System.exit(0); } static private final int INF = Integer.MAX_VALUE; static private final int MINF = Integer.MIN_VALUE; }
0	public class A{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  long n = sc.nextLong();  List<Long> fi = new ArrayList<Long>(); fi.add((long)0); fi.add((long)1); while((fi.get((fi.size() - 1)) < n)){fi.add((fi.get((fi.size() - 1)) + fi.get((fi.size() - 2)))); } int last = (fi.size() - 1);  long z = (((last - 1) >= 0)?fi.get((last - 1)):0);  long y = (((last - 3) >= 0)?fi.get((last - 3)):0);  long x = (((last - 4) >= 0)?fi.get((last - 4)):0); if ( (((x + y) + z) < n)) x = 1; System.out.println(((((x + " ") + y) + " ") + z)); } }
5	public class ProblemA{ public static void main( String[] args){ Scanner s = new Scanner(System.in);  int n = s.nextInt();  int t = s.nextInt();  TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>(); while(s.hasNextInt()){ int i = s.nextInt();  int j = s.nextInt(); map.put(i,j); } int count = 0;  double left = -100000;  double right ;  int size ; for ( Integer i :map.keySet()) {size = map.get(i); right = ((double)i - ((double)size / 2.0)); if ( ((right - left) > t)) {count += 2; } if ( ((right - left) == t)) {count++; } left = ((double)i + ((double)size / 2.0)); }System.out.println(count); } }
5	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(in.nextInt(),in.nextInt()); }Arrays.sort(houses); int count = 2; for ( int i = 0;(i < (n - 1));i++) { double start = (houses[i].x + ((double)houses[i].a / 2));  double end = (houses[(i + 1)].x - ((double)houses[(i + 1)].a / 2)); if ( ((end - start) == t)) count++; if ( ((end - start) > t)) count += 2; }System.out.println(count); } } class House implements Comparable<House>{ int x ; int a ; public House( int _x, int _a){ x = _x; a = _a; } }
0	public class HexadecimalsTheorem{ public void solve(){ Scanner sc = new Scanner(System.in);  long n = sc.nextLong();  ArrayList<Long> a = new ArrayList<Long>(); a.add(0l); a.add(1L); a.add(1L); int i = 1,j = 2; while(((a.get(i) + a.get(j)) <= n)){a.add((a.get(i) + a.get(j))); i++; j++; }if ( a.contains(n)) {if ( (n == 0)) {System.out.println("0 0 0"); } else if ( (n == 1)) {System.out.println("0 0 1"); } else if ( (n == 2)) {System.out.println("0 1 1"); } else {System.out.println(((((a.get((j - 4)) + " ") + a.get((j - 3))) + " ") + a.get((j - 1)))); }} else {System.out.println("I'm too stupid to solve this problem"); }} public static void main( String[] args){ new HexadecimalsTheorem().solve(); } }
0	public class a extends Thread{ BufferedReader bf ; PrintWriter out ; FastScanner in ; void solve()throws Exception { long n = in.nextLong();  long f[] = new long[2001];  int i = 2; f[0] = 0; f[1] = 1; while(true){f[i] = (f[(i - 1)] + f[(i - 2)]); if ( (f[i] < n)) i++; else break;}if ( (n == 1)) out.println("1 0 0"); else if ( (n == 0)) out.println("0 0 0"); else if ( ((i - 3) >= 0)) out.println(((((f[(i - 2)] + " ") + f[(i - 2)]) + " ") + f[(i - 3)])); else out.println("I'm too stupid to solve this problem"); } public static void main( String[] args){ new a().start(); } class FastScanner{ BufferedReader bf ; StringTokenizer st ; public FastScanner( BufferedReader bf){ this.bf = bf; } public String nextToken()throws Exception { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(bf.readLine()); }return st.nextToken();} public long nextLong()throws Exception { return Long.parseLong(nextToken());} } }
1	public class IQTest implements Runnable{ public static void main( String[] args)throws Exception { new IQTest().run(); } private void solve()throws Exception { int n = nextInt();  int a[] = new int[n]; for ( int i = 0;(i < a.length);i++) {a[i] = nextInt(); } int c0 = 0,c1 = 0; for ( int i = 0;(i < a.length);i++) {a[i] = (a[i] % 2); if ( (a[i] == 0)) c0++; else c1++; } int f = 0; if ( (c0 > c1)) f = 1; else f = 0; int r = 0; for ( int i = 0;(i < a.length);i++) {if ( (a[i] == f)) {r = (i + 1); break;} }out.println(r); } private BufferedReader in ; PrintWriter out ; StringTokenizer tokenizer ; public void run(){ try{in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedOutputStream(System.out)); solve(); out.flush(); in.close(); out.close(); }catch (Exception e){ e.printStackTrace(); } } String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(in.readLine()); }return tokenizer.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
0	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()); System.out.println(("0 0 " + n)); } }
2	public class B{ public static void main( String[] args)throws Exception { new B().solve(System.in,System.out); } void solve( InputStream _in, PrintStream out)throws IOException { Scanner sc = new Scanner(_in);  long n = sc.nextLong();  long x = (sc.nextLong() - 1);  long y = (sc.nextLong() - 1);  long c = sc.nextLong();  long ub = (2 * n);  long lb = -1; while(((lb + 1) < ub)){ long k = ((lb + ub) / 2);  long l ,u ,r ,d ; l = Math.max(0,(x - k)); u = Math.max(0,(y - k)); r = Math.min((n - 1),(x + k)); d = Math.min((n - 1),(y + k)); long ss = 0;  long lu = (x - (k - (y - u))); if ( (l < lu)) { long a = (lu - l); ss += ((a * (a + 1)) / 2); } long ld = (x - (k - (d - y))); if ( (l < ld)) { long a = (ld - l); ss += ((a * (a + 1)) / 2); } long ru = (x + (k - (y - u))); if ( (ru < r)) { long a = (r - ru); ss += ((a * (a + 1)) / 2); } long rd = (x + (k - (d - y))); if ( (rd < r)) { long a = (r - rd); ss += ((a * (a + 1)) / 2); } long cc = ((((r + 1) - l) * ((d + 1) - u)) - ss); if ( (c <= cc)) {ub = k; } else {lb = k; }}out.println(ub); } }
6	public class r568p8{ static private InputReader sc ; static private PrintWriter pw ; static private long mod ; static class InputReader{ private final InputStream stream ; private final byte[] buf = new byte[8192]; private int curChar ,snumChars ; private SpaceCharFilter filter ; InputReader( InputStream stream){ this.stream = stream; } int snext(){ if ( (snumChars == -1)) throw (new InputMismatchException()); if ( (curChar >= snumChars)) {curChar = 0; try{snumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (snumChars <= 0)) return -1; } return buf[curChar++];} int nextInt(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} public interface SpaceCharFilter{ boolean isSpaceChar( int ch); } } public static void main( String[] args){ sc = new InputReader(System.in); pw = new PrintWriter(System.out); int t = 1; while((t-- > 0))solve(); pw.flush(); pw.close(); } static private void fill_matrix( long[][][][] dp, int a, int b, int c, int end){ if ( ((((((a == 0) && (b == 0)) && (c == 0)) || ((a == 0) && (end == 0))) || ((b == 0) && (end == 1))) || ((c == 0) && (end == 2)))) {dp[a][b][c][end] = 0; return ;} if ( (((a > 1) && (b == 0)) && (c == 0))) {dp[a][b][c][end] = 0; return ;} if ( (((b > 1) && (a == 0)) && (c == 0))) {dp[a][b][c][end] = 0; return ;} if ( (((c > 1) && (a == 0)) && (b == 0))) {dp[a][b][c][end] = 0; return ;} if ( ((((a == 1) && (end == 0)) && (b == 0)) && (c == 0))) {dp[a][b][c][end] = 1; return ;} if ( ((((b == 1) && (end == 1)) && (a == 0)) && (c == 0))) {dp[a][b][c][end] = 1; return ;} if ( ((((c == 1) && (end == 2)) && (b == 0)) && (a == 0))) {dp[a][b][c][end] = 1; return ;} if ( (end == 0)) {fill_matrix(dp,(a - 1),b,c,1); fill_matrix(dp,(a - 1),b,c,2); dp[a][b][c][0] = (((dp[(a - 1)][b][c][1] % mod) + (dp[(a - 1)][b][c][2] % mod)) % mod); } else if ( (end == 1)) {fill_matrix(dp,a,(b - 1),c,0); fill_matrix(dp,a,(b - 1),c,2); dp[a][b][c][1] = (((dp[a][(b - 1)][c][0] % mod) + (dp[a][(b - 1)][c][2] % mod)) % mod); } else {fill_matrix(dp,a,b,(c - 1),0); fill_matrix(dp,a,b,(c - 1),1); dp[a][b][c][2] = (((dp[a][b][(c - 1)][0] % mod) + (dp[a][b][(c - 1)][1] % mod)) % mod); }} static private long cal( int[] count){ int a = count[0],b = count[1],c = count[2];  long dp[][][][] = new long[(a + 1)][(b + 1)][(c + 1)][3];  long factorial[] = new long[20]; factorial[0] = 1; factorial[1] = 1; for ( int i = 2;(i < 20);i++) factorial[i] = ((((factorial[(i - 1)] % mod) * i) % mod) % mod); fill_matrix(dp,a,b,c,0); fill_matrix(dp,a,b,c,1); fill_matrix(dp,a,b,c,2); long p = ((((dp[a][b][c][0] % mod) + (dp[a][b][c][1] % mod)) + (dp[a][b][c][2] % mod)) % mod);  long ans = ((((((((((p % mod) * factorial[a]) % mod) % mod) * factorial[b]) % mod) % mod) * factorial[c]) % mod) % mod); return ans;} static private void solve(){ int n = sc.nextInt(),T = sc.nextInt();  int len[] = new int[n],genre[] = new int[n]; for ( int i = 0;(i < n);i++) {len[i] = sc.nextInt(); genre[i] = sc.nextInt(); } int sum[] = new int[(1 << n)]; mod = ((long)1e9 + 7); long ans = 0; for ( int i = 1;(i < (1 << n));i++) {for ( int j = 0;(j < 15);j++) {if ( ((i & (1 << j)) != 0)) {sum[i] = (sum[(i ^ (1 << j))] + len[j]); break;} }if ( (sum[i] == T)) { int count[] = {0,0,0}; for ( int j = 0;(j < 15);j++) {if ( ((i & (1 << j)) != 0)) count[(genre[j] - 1)]++; }ans = (((ans % mod) + (cal(count) % mod)) % mod); } }pw.println(+ans); } }
2	public class b2{ public static void main( String[] args)throws IOException { input.init(System.in); int n = input.nextInt(),x = input.nextInt(),y = input.nextInt(),c = input.nextInt();  long lo = 0,hi = (2 * n); while((hi > (lo + 1))){ long mid = ((hi + lo) / 2);  long covered = go(n,x,y,mid); if ( (covered < c)) lo = mid; else hi = mid; }if ( (go(n,x,y,lo) < c)) lo++; System.out.println(lo); } public static long go( int n, int x, int y, long d){ long res = ((d * d) + ((d + 1) * (d + 1)));  long maxLeft = (d - x); if ( (maxLeft >= 0)) res -= ((maxLeft + 1) * (maxLeft + 1));  long maxTop = (d - y); if ( (maxTop >= 0)) res -= ((maxTop + 1) * (maxTop + 1));  long maxRight = (d - ((n + 1) - x)); if ( (maxRight >= 0)) res -= ((maxRight + 1) * (maxRight + 1));  long maxBot = (d - ((n + 1) - y)); if ( (maxBot >= 0)) res -= ((maxBot + 1) * (maxBot + 1));  long maxTopLeft = (d - (x + y)); if ( (maxTopLeft >= 0)) res += (((maxTopLeft + 1) * (maxTopLeft + 2)) / 2);  long maxTopRight = (d - (((n + 1) - x) + y)); if ( (maxTopRight >= 0)) res += (((maxTopRight + 1) * (maxTopRight + 2)) / 2);  long maxBotLeft = (d - (x + ((n + 1) - y))); if ( (maxBotLeft >= 0)) res += (((maxBotLeft + 1) * (maxBotLeft + 2)) / 2);  long maxBotRight = (d - (((n + 1) - x) + ((n + 1) - y))); if ( (maxBotRight >= 0)) res += (((maxBotRight + 1) * (maxBotRight + 2)) / 2); return res;} }
5	public class Main implements Runnable{ class Segment{ int l ,r ; Segment( int l, int r){ this.l = l; this.r = r; } } public void _main()throws IOException { int n = nextInt();  int t = nextInt();  int[] x = new int[n];  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {x[i] = nextInt(); a[i] = nextInt(); } Set<Segment> set = new HashSet<Segment>(); for ( int i = 0;(i < n);i++) { int l = ((2 * x[i]) + a[i]);  int r = (((2 * x[i]) + a[i]) + (2 * t));  boolean ok = true; for ( int j = 0;(j < n);j++) {if ( (i == j)) continue; int L = Math.max(l,((2 * x[j]) - a[j]));  int R = Math.min(r,((2 * x[j]) + a[j])); if ( (L < R)) {ok = false; break;} }if ( ok) set.add(new Segment(l,r)); l = (((2 * x[i]) - a[i]) - (2 * t)); r = ((2 * x[i]) - a[i]); ok = true; for ( int j = 0;(j < n);j++) {if ( (i == j)) continue; int L = Math.max(l,((2 * x[j]) - a[j]));  int R = Math.min(r,((2 * x[j]) + a[j])); if ( (L < R)) {ok = false; break;} }if ( ok) set.add(new Segment(l,r)); }out.print(set.size()); } private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; private String next()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String rl = in.readLine(); if ( (rl == null)) return null; st = new StringTokenizer(rl); }return st.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args){ new Thread(new Main()).start(); } }
4	public class sdffsdf{ public static void main( String[] args){ try{ File file = new File("input.txt");  Scanner sc = new Scanner(file);  String s = sc.nextLine();  String[] seperatedd = s.split(" ");  int x = Integer.parseInt(seperatedd[0]);  int y = Integer.parseInt(seperatedd[1]);  int[][] grid = new int[x][y]; for ( int i = 0;(i < x);i++) {for ( int j = 0;(j < y);j++) {grid[i][j] = 0; }}s = sc.nextLine(); int z = Integer.parseInt(s);  LinkedList<Point> BFS = new LinkedList<Point>(); s = sc.nextLine(); String[] seperated = s.split(" "); for ( int i = 0;(i < seperated.length);i = (i + 2)) { Point temp = new Point(); temp.x = (Integer.parseInt(seperated[i]) - 1); temp.y = (Integer.parseInt(seperated[(i + 1)]) - 1); grid[temp.x][temp.y] = 1; BFS.addLast(temp); }while(!BFS.isEmpty()){ Point temp = new Point(); temp = BFS.removeFirst(); int k = temp.x;  int l = temp.y; if ( (((l + 1) >= y) || (grid[k][(l + 1)] == 1))) { Point temp1 = new Point(); temp1.x = k; temp1.y = (l + 1); grid[temp1.x][temp1.y] = 1; BFS.addLast(temp1); } if ( (((k + 1) >= x) || (grid[(k + 1)][l] == 1))) { Point temp1 = new Point(); temp1.x = (k + 1); temp1.y = l; grid[temp1.x][temp1.y] = 1; BFS.addLast(temp1); } if ( (((l - 1) < 0) || (grid[k][(l - 1)] == 1))) { Point temp1 = new Point(); temp1.x = k; temp1.y = (l - 1); grid[temp1.x][temp1.y] = 1; BFS.addLast(temp1); } if ( (((k - 1) < 0) || (grid[(k - 1)][l] == 1))) { Point temp1 = new Point(); temp1.x = (k - 1); temp1.y = l; grid[temp1.x][temp1.y] = 1; BFS.addLast(temp1); } if ( BFS.isEmpty()) {try{ File fil = new File("output.txt");  PrintWriter out = new PrintWriter(fil);  int v1 = ((int)temp.getX() + 1);  int v2 = ((int)temp.getY() + 1); out.println(((v1 + " ") + v2)); out.close(); }catch (Exception e){ } } } }catch (Exception e){ System.out.println("nbvnb"); } } }
5	public class A{ static final Scanner sc = new Scanner(System.in); void run(){ int n = sc.nextInt();  int[] xs = new int[n]; for ( int i = 0;(i < n);i++) {xs[i] = sc.nextInt(); }Arrays.sort(xs); xs[(n - 1)] = ((xs[(n - 1)] == 1)?2:1); Arrays.sort(xs); for ( int i = 0;(i < n);i++) System.out.print((xs[i] + " ")); } public static void main( String[] args){ new A().run(); } }
1	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);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ public int[] parse( FastScanner in, int n){ String s = in.next();  int[] temp = new int[n]; for ( int i = 0;(i < n);++i) {temp[i] = (s.charAt(i) - 'A'); }return temp;} public void solve( int testNumber, FastScanner in, PrintWriter out){ int n = in.nextInt();  int[] s = parse(in,n);  Map<Integer,TreeSet<Integer>> map = new HashMap<>(); for ( int i = 0;(i < n);++i) {if ( map.containsKey(s[i])) {map.get(s[i]).add(i); } else { TreeSet<Integer> temp = new TreeSet<>(); temp.add(i); map.put(s[i],temp); }} int ans = Integer.MAX_VALUE; for ( int i = 0;(i < n);++i) { int finalI = i; final Int integer = new Int(); integer.x = i; map.forEach((Integer x,TreeSet set)->{if ( (x != s[finalI])) { Integer temp = (Integer)set.higher(finalI); if ( (temp == null)) {integer.x = -2; } else {if ( (integer.x != -2)) integer.x = Integer.max(integer.x,temp); }} else {}}); if ( (integer.x != -2)) {ans = Integer.min(ans,((integer.x - i) + 1)); } }out.print(ans); } public class Int{ int x ; public Int(){ x = -1; } } } static class FastScanner{ private BufferedReader br ; private StringTokenizer st ; public FastScanner( File f){ try{br = new BufferedReader(new FileReader(f)); }catch (FileNotFoundException e){ e.printStackTrace(); } } public FastScanner( InputStream inputStream){ br = new BufferedReader(new InputStreamReader(inputStream)); } public String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } }return st.nextToken();} public int nextInt(){ return Integer.parseInt(next());} } }
1	public class CTask{ public static void main( String[] args)throws IOException { MyInputReader in = new MyInputReader(System.in);  HashMap<Character,Integer> m = new HashMap<Character,Integer>();  int n = in.nextInt();  char[] s = in.next().toCharArray(); for ( int i = 0;(i < n);i++) {m.put(s[i],0); } int mx = m.size();  int start = 0;  int end = 0;  int min = Integer.MAX_VALUE;  int cur = 0; while((end < n)){while(((end < n) && (cur != mx))){ int x = m.get(s[end]); if ( (x == 0)) {cur += 1; } m.put(s[end],(x + 1)); end += 1; }while(((start <= end) && (cur == mx))){ int x = m.get(s[start]); m.put(s[start],(x - 1)); if ( ((x - 1) == 0)) {cur -= 1; } start += 1; }min = Math.min(min,((end - start) + 1)); }System.out.println(min); } static class MyInputReader{ public BufferedReader reader ; public StringTokenizer tokenizer ; public MyInputReader( 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());} } }
3	public class Main{ private FastScanner in ; private PrintWriter out ; private void solve()throws IOException { solveC(); } private void solveC()throws IOException { int n = in.nextInt(),prev = -1;  long sum ,mod = ((long)1e9 + 7),p ;  long[] deep = new long[(n + 10)]; deep[0] = 1; char c ; for ( int cur = 0;(cur < n);cur++) {c = in.nextLine().charAt(0); if ( ((prev + 1) != cur)) {sum = 0; if ( (c == 'f')) {for ( int i = (deep.length - 1);(i > 0);i--) {sum += deep[(i - 1)]; sum %= mod; deep[i] = sum; }deep[0] = 0; } else {for ( int i = (deep.length - 1);(i >= 0);i--) {sum += deep[i]; sum %= mod; deep[i] = sum; }}} if ( (c != 's')) {if ( (cur == (prev + 1))) {for ( int i = (deep.length - 1);(i > 0);i--) {deep[i] = deep[(i - 1)]; }deep[0] = 0; } prev = cur; } } long ans = 0; for ( int i = 0;(i < deep.length);i++) {ans += deep[i]; ans %= mod; }out.println(ans); } class FastScanner{ StringTokenizer st ; BufferedReader br ; FastScanner( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } 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());} String nextLine()throws IOException { return br.readLine();} } private void run()throws IOException { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); } public static void main( String[] args)throws IOException { new Main().run(); } }
5	public class A{ Scanner in = new Scanner(System.in); public class Houses implements Comparable<Houses>{ double x ; double a ; public Houses( double xVal, double aVal){ x = (xVal - (aVal / 2)); a = aVal; } } public void solve2( ArrayList<Houses> list, int t){ Collections.sort(list); int count = 2; for ( int f = 0;(f < (list.size() - 1));f++) {if ( (((list.get((f + 1)).x - list.get(f).x) - list.get(f).a) > t)) {count += 2; } else if ( (((list.get((f + 1)).x - list.get(f).x) - list.get(f).a) == t)) {count++; } }System.out.println(count); } public void solve(){ ArrayList<Houses> list = new ArrayList<Houses>();  int n = in.nextInt();  int t = in.nextInt(); for ( int i = 0;(i < n);i++) {list.add(new Houses(in.nextDouble(),in.nextDouble())); }solve2(list,t); } public static void main( String[] args){ A p = new A(); p.solve(); } }
2	public class Solver{ StringTokenizer st ; BufferedReader in ; PrintWriter out ; public static void main( String[] args)throws NumberFormatException,IOException { Solver solver = new Solver(); solver.open(); solver.solve(); solver.close(); } public void open()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } public String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String line = in.readLine(); if ( (line == null)) return null; st = new StringTokenizer(line); }return st.nextToken();} public int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(nextToken());} public long nextLong()throws NumberFormatException,IOException { return Long.parseLong(nextToken());} int n ; class Otr{ int x1 ,y1 ,x2 ,y2 ; int dx ,dy ; public Otr( int x, int y, int dx, int dy){ super(); this.x1 = x; this.y1 = y; this.x2 = x; this.y2 = y; this.dx = dx; this.dy = dy; } int getAns(){ if ( ((x1 == x2) && (y1 == y2))) { int nx1 = (x1 + dx);  int ny2 = (y2 + dy); if ( (((nx1 <= 0) || (nx1 > n)) && ((ny2 <= 0) || (ny2 > n)))) {return 0;} } x1 += dx; if ( (x1 <= 0)) {x1 = 1; y1 += dy; } if ( (x1 > n)) {x1 = n; y1 += dy; } y2 += dy; if ( (y2 <= 0)) {y2 = 1; x2 += dx; } if ( (y2 > n)) {y2 = n; x2 += dx; } return (Math.abs((x1 - x2)) + 1);} } int[] dxs = {-1,-1,1,1}; int[] dys = {-1,1,-1,1}; public void solve()throws NumberFormatException,IOException { n = nextInt(); int x = nextInt();  int y = nextInt();  long c = nextLong();  long now = 1;  Otr[] otr = new Otr[4]; for ( int i = 0;(i < 4);i++) {otr[i] = new Otr(x,y,dxs[i],dys[i]); } int result = 0; while((now < c)){for ( int i = 0;(i < 4);i++) {now += otr[i].getAns(); }for ( int i = 0;(i < 3);i++) {for ( int j = (i + 1);(j < 4);j++) { Otr o1 = otr[i];  Otr o2 = otr[j]; if ( ((o1.x1 != o1.x2) || (o1.y1 != o1.y2))) {if ( ((o2.x1 != o2.x2) || (o2.y1 != o2.y2))) {if ( ((o1.x1 == o2.x1) && (o1.y1 == o2.y1))) {now--; } if ( ((o1.x1 == o2.x2) && (o1.y1 == o2.y2))) {now--; } if ( ((o1.x2 == o2.x1) && (o1.y2 == o2.y1))) {now--; } if ( ((o1.x2 == o2.x2) && (o1.y2 == o2.y2))) {now--; } } else {if ( ((o1.x1 == o2.x1) && (o1.y1 == o2.y1))) {now--; } if ( ((o1.x2 == o2.x1) && (o1.y2 == o2.y1))) {now--; } }} else {if ( ((o2.x1 != o2.x2) || (o2.y1 != o2.y2))) {if ( ((o1.x2 == o2.x1) && (o1.y2 == o2.y1))) {now--; } if ( ((o1.x2 == o2.x2) && (o1.y2 == o2.y2))) {now--; } } else {if ( ((o1.x1 == o2.x1) && (o1.y1 == o2.y1))) {now--; } }}}}result++; }out.println(result); } public void close(){ out.flush(); out.close(); } }
5	public class BetaRound15_A implements Runnable{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws IOException { if ( ONLINE_JUDGE) {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"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new Thread(new BetaRound15_A()).start(); } class House implements Comparable<House>{ int left ,right ; House( int left, int right){ this.left = left; this.right = right; } } int getAns( House h1, House h2, int t){ int d = (h2.left - h1.right); if ( (d < t)) return 0; if ( (d == t)) return 1; return 2;} void solve()throws IOException { int n = readInt();  int t = (readInt() * 2);  House[] h = new House[n]; for ( int i = 0;(i < n);i++) { int c = (readInt() * 2);  int b = readInt(); h[i] = new House((c - b),(c + b)); }Arrays.sort(h); int ans = 2; for ( int i = 1;(i < n);i++) {ans += getAns(h[(i - 1)],h[i],t); }out.print(ans); } }
5	public class a{ private void solve()throws Exception { int n = nextInt(),t = nextInt();  int[] x = new int[n],a = new int[n]; for ( int i = 0;(i < n);++i) {x[i] = nextInt(); a[i] = nextInt(); }for ( int i = 0;(i < n);++i) for ( int j = 0;(j < (n - 1));++j) {if ( (x[j] > x[(j + 1)])) { int tmp = x[j]; x[j] = x[(j + 1)]; x[(j + 1)] = tmp; tmp = a[j]; a[j] = a[(j + 1)]; a[(j + 1)] = tmp; } } int res = 2; for ( int i = 1;(i < n);++i) { int betw = ((((x[i] - x[(i - 1)]) * 2) - a[i]) - a[(i - 1)]); if ( (betw == (t * 2))) ++res; else if ( (betw > (t * 2))) res += 2; }out.print(res); } public void run(){ try{solve(); }catch (Exception e){ NOO(e); } finally{out.close(); }} PrintWriter out ; BufferedReader in ; StringTokenizer St ; void NOO( Exception e){ e.printStackTrace(); System.exit(1); } int nextInt(){ return Integer.parseInt(nextToken());} String nextToken(){ while(!St.hasMoreTokens()){try{ String line = in.readLine(); St = new StringTokenizer(line); }catch (Exception e){ NOO(e); } }return St.nextToken();} private a( String name){ try{in = new BufferedReader(new FileReader((name + ".in"))); St = new StringTokenizer(""); out = new PrintWriter(new FileWriter((name + ".out"))); }catch (Exception e){ NOO(e); } } private a(){ try{in = new BufferedReader(new InputStreamReader(System.in)); St = new StringTokenizer(""); out = new PrintWriter(System.out); }catch (Exception e){ NOO(e); } } public static void main( String[] args){ new a().run(); } }
4	public class CF_35C{ public static void main( String[] args)throws IOException { BufferedReader f = new BufferedReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));  StringTokenizer st1 = new StringTokenizer(f.readLine());  int n = Integer.parseInt(st1.nextToken());  int m = Integer.parseInt(st1.nextToken());  boolean[][] visited = new boolean[n][m];  int k = Integer.parseInt(f.readLine());  LinkedList<state1> ll = new LinkedList<state1>();  StringTokenizer st = new StringTokenizer(f.readLine()); for ( int i = 0;(i < k);i++) { int x = Integer.parseInt(st.nextToken());  int y = Integer.parseInt(st.nextToken()); ll.add(new state1((x - 1),(y - 1))); visited[(x - 1)][(y - 1)] = true; } int lastx = 1;  int lasty = 1; while(!ll.isEmpty()){ state1 focus = ll.remove(); lastx = (focus.x + 1); lasty = (focus.y + 1); visited[focus.x][focus.y] = true; if ( (((focus.x + 1) < n) && !visited[(focus.x + 1)][focus.y])) {ll.add(new state1((focus.x + 1),focus.y)); visited[(focus.x + 1)][focus.y] = true; } if ( (((focus.x - 1) >= 0) && !visited[(focus.x - 1)][focus.y])) {ll.add(new state1((focus.x - 1),focus.y)); visited[(focus.x - 1)][focus.y] = true; } if ( (((focus.y + 1) < m) && !visited[focus.x][(focus.y + 1)])) {ll.add(new state1(focus.x,(focus.y + 1))); visited[focus.x][(focus.y + 1)] = true; } if ( (((focus.y - 1) >= 0) && !visited[focus.x][(focus.y - 1)])) {ll.add(new state1(focus.x,(focus.y - 1))); visited[focus.x][(focus.y - 1)] = true; } }out.println(((lastx + " ") + lasty)); out.close(); } } class state1{ int x ,y ; state1( int x, int y){ this.x = x; this.y = y; } }
3	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{ long mod = ((long)1e9 + 7); public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.nextInt();  char ar[] = new char[n]; for ( int i = 0;(i < n);i++) {ar[i] = in.readString().charAt(0); } long dp[][] = new long[(n + 1)][(n + 1)]; for ( int i = 0;(i < n);i++) {dp[(n - 1)][i] = 1; } long prev = n; for ( int i = (n - 2);(i >= 0);i--) {if ( (ar[i] == 'f')) {if ( (ar[(i + 1)] == 's')) {for ( int j = (n - 2);(j >= 0);j--) {dp[i][j] = dp[(i + 1)][(j + 1)]; }} else {for ( int j = (n - 2);(j >= 0);j--) {dp[i][j] = dp[(i + 1)][(j + 1)]; }}} else {for ( int j = (n - 1);(j >= 0);j--) {if ( (prev < 0)) {prev += mod; } dp[i][j] = prev; prev = (prev - dp[(i + 1)][j]); }}prev = 0; for ( int j = 0;(j < n);j++) {prev += dp[i][j]; prev = (prev % mod); }}out.println((dp[0][0] % mod)); } } static class InputReader{ private final InputStream stream ; private final byte[] buf = new byte[8192]; private int curChar ; private int snumChars ; public InputReader( InputStream st){ this.stream = st; } public int read(){ if ( (snumChars == -1)) throw (new InputMismatchException()); if ( (curChar >= snumChars)) {curChar = 0; try{snumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (snumChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c)){c = read(); } StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } }
5	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 < n);i++) {h[i][0] = (2 * in.nextInt()); h[i][1] = in.nextInt(); }Arrays.sort(h,new Comp()); for ( int i = 1;(i < n);i++) { int d = ((h[i][0] - h[i][1]) - (h[(i - 1)][0] + h[(i - 1)][1])); if ( (d > t)) ans += 2; else if ( (d == t)) ans++; }System.out.println(ans); } static class Comp implements Comparator<int[]>{ } }
2	public class Main{ public static void main( String[] args){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  PrintWriter pw = new PrintWriter(System.out);  String[] param = br.readLine().split(" ");  long n = (Long.parseLong(param[0]) - 1);  long k = (Long.parseLong(param[1]) - 1);  long max = ((k * (k + 1)) / 2);  long answer ; if ( (n > max)) answer = -1; else { long margin = (max - n);  long m = Math.max(0,((long)Math.floor(((1.0 + Math.sqrt((1 + (8 * margin)))) / 2.0)) - 1));  long min = ((m * (m + 1)) / 2); while((min <= margin)){m++; min = ((m * (m + 1)) / 2); }answer = ((k - m) + 1); }pw.println(answer); pw.close(); br.close(); }catch (IOException e){ e.printStackTrace(); return ;} } }
2	public class B{ InputStream is ; PrintWriter out ; String INPUT = ""; void solve(){ int n = ni(),x = ni(),y = ni();  long c = nl();  int l = (x - 1),r = (n - x);  int u = (y - 1),d = (n - y);  long low = -1,high = ((2 * n) + 3); while(((high - low) > 1)){ long t = ((high + low) / 2);  long num = ((((((((diag(t,l,u) + diag(t,r,u)) + diag(t,l,d)) + diag(t,r,d)) + hor(t,l)) + hor(t,r)) + hor(t,u)) + hor(t,d)) + 1); if ( (num >= c)) {high = t; } else {low = t; }}out.println(high); } long hor( long t, int n){ return Math.min(t,n);} long diag( long t, long r, long u){ if ( (t > (((2 + r) + u) - 2))) {return (r * u);} long ret = ((t * (t - 1)) / 2); if ( (t > r)) ret -= (((t - r) * ((t - r) - 1)) / 2); if ( (t > u)) ret -= (((t - u) * ((t - u) - 1)) / 2); return ret;} void run()throws Exception { is = (oj?System.in:new ByteArrayInputStream(INPUT.getBytes())); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(((System.currentTimeMillis() - s) + "ms")); } public static void main( String[] args)throws Exception { new B().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0,ptrbuf = 0; 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++];} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private int ni(){ 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(); }} private long nl(){ long num = 0;  int 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(); }} private boolean oj = (System.getProperty("ONLINE_JUDGE") != null); private void tr( Object... o){ if ( !oj) System.out.println(Arrays.deepToString(o)); } }
4	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 * fuck)],dx = new int[]{1,-1,0,0},dy = new int[]{0,0,-1,1}; Arrays.fill(D,-1); ArrayDeque<Integer> Q = new ArrayDeque<>();  int k = in.nextInt(),ans = 0; for ( int i = 0;(i < k);++i) { int x = in.nextInt(),y = in.nextInt(); D[ans = ((x * fuck) + y)] = 0; Q.offer(ans); }while(!Q.isEmpty()){ int idx = Q.poll();  int x = (idx / fuck),y = (idx % fuck); for ( int i = 0;(i < 4);++i) { int wtf = (((dx[i] + x) * fuck) + (dy[i] + y)); if ( ((((((dx[i] + x) <= n) && ((dx[i] + x) >= 1)) && ((dy[i] + y) <= m)) && ((dy[i] + y) >= 1)) && (D[wtf] == -1))) {D[wtf] = (D[idx] + 1); Q.offer(wtf); if ( (D[wtf] >= D[ans])) ans = wtf; } }}out.println((((ans / fuck) + " ") + (ans % fuck))); out.close(); in.close(); } }
5	public class codeforces{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int[] data = new int[n]; for ( int i = 0;(i < n);i++) data[i] = sc.nextInt(); Arrays.sort(data); if ( (data[(n - 1)] != 1)) data[(n - 1)] = 1; else data[(n - 1)] = 2; Arrays.sort(data); for ( int i = 0;(i < n);i++) {System.out.print(data[i]); if ( (i != (n - 1))) System.out.print(" "); }return ;} }
5	public class A{ static class Entity implements Comparable{ public Entity( int x, int a){ this.x = x; this.a = a; } public int x ,a ; } public static void main( String[] args){ Scanner scanner = new Scanner(System.in);  int n = scanner.nextInt(),t = (2 * scanner.nextInt()); if ( (1 == n)) {System.out.println(2); } else { int rez = 2;  ArrayList<Entity> list = new ArrayList<Entity>(); for ( int i = 0;(i < n);i++) {list.add(new Entity(scanner.nextInt(),scanner.nextInt())); }Collections.sort(list); for ( int i = 1;(i < n);i++) { int num = (((2 * (list.get(i).x - list.get((i - 1)).x)) - list.get(i).a) - list.get((i - 1)).a); if ( (t < num)) {rez += 2; } else if ( (t == num)) {rez++; } }System.out.println(rez); }} }
3	public class Main3 implements Runnable{ public static void main( String[] args){ new Thread(null,new Main3(),"",((128 * 1024) * 1024)).start(); } static private Scanner in = new Scanner(System.in); }
0	public class Hexadecimal{ public static void main( String[] args){ Scanner input = new Scanner(System.in);  int n = input.nextInt(); System.out.print(("0 0 " + n)); } }
1	public class C{ String line ; StringTokenizer inputParser ; BufferedReader is ; FileInputStream fstream ; DataInputStream in ; void openInput( String file){ if ( (file == null)) is = new BufferedReader(new InputStreamReader(System.in)); else {try{fstream = new FileInputStream(file); in = new DataInputStream(fstream); is = new BufferedReader(new InputStreamReader(in)); }catch (Exception e){ System.err.println(e); } }} void readNextLine(){ try{line = is.readLine(); inputParser = new StringTokenizer(line," "); }catch (IOException e){ System.err.println(("Unexpected IO ERROR: " + e)); } } int NextInt(){ String n = inputParser.nextToken();  int val = Integer.parseInt(n); return val;} void closeInput(){ try{is.close(); }catch (IOException e){ System.err.println(("Unexpected IO ERROR: " + e)); } } public static void main( String[] argv){ String filePath = null; if ( (argv.length > 0)) filePath = argv[0];  C c = new C(filePath); } public C( String inputFile){ openInput(inputFile); readNextLine(); int N = NextInt();  boolean[] p = new boolean[N]; readNextLine(); int h = 0; for ( int i = 0;(i < N);i++) {p[i] = (line.charAt(i) == 'H'); if ( p[i]) h++; } int ret = N; for ( int i = 0;(i < N);i++) { int m = 0; for ( int j = i;(j < (i + h));j++) { int n = (j % N); if ( !p[n]) m++; }ret = Math.min(ret,m); }System.out.println(ret); closeInput(); } }
2	public class B{ static long n ,k ; static long sum( long mid){ long tmpSum = ((k * (k + 1)) / 2);  long nsum = (((mid - 1) * mid) / 2); return (tmpSum - nsum);} public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(System.out);  StringTokenizer sc = new StringTokenizer(br.readLine()); n = (Long.parseLong(sc.nextToken()) - 1); k = (Long.parseLong(sc.nextToken()) - 1); if ( (n == 0)) out.println(0); else if ( (sum(1) < n)) out.println(-1); else { long lo = 1;  long hi = k;  long mid ; while((lo < hi)){mid = ((lo + hi) / 2); long sum = sum(mid); if ( ((n - sum) < 0)) lo = (mid + 1); else if ( ((n - sum) < mid)) {hi = mid; } else hi = (mid - 1); }out.println((((k - lo) + 1) + (((n - sum(lo)) == 0)?0:1))); }br.close(); out.close(); } }
3	public class CFC{ static int n ; static int[][] dp ; static boolean[] s ; public static void main( String[] args)throws IOException { FastScanner in = new FastScanner(System.in); n = in.nextInt(); if ( (n == 1)) {System.out.println(1); return ;} dp = new int[n][(n + 1)]; s = new boolean[n]; for ( int i = 0;(i < n);i++) s[i] = in.next().equals("s"); for ( int j = 0;(j < n);j++) {if ( s[(n - 2)]) dp[(n - 1)][j] = (j + 1); else dp[(n - 1)][j] = 1; } int suma ,sumb ; for ( int i = (n - 2);(i >= 0);i--) {if ( ((i == 0)?true:s[(i - 1)])) {if ( s[i]) {for ( int j = 0;(j < n);j++) {dp[i][j] = ((((j == 0)?0:dp[i][(j - 1)]) + dp[(i + 1)][j]) % 1000000007); }} else {for ( int j = 0;(j < n);j++) {dp[i][j] = ((((j == 0)?0:dp[i][(j - 1)]) + dp[(i + 1)][(j + 1)]) % 1000000007); }}} else {if ( s[i]) {for ( int j = 0;(j < n);j++) {dp[i][j] = dp[(i + 1)][j]; }} else {for ( int j = 0;(j < n);j++) {dp[i][j] = dp[(i + 1)][(j + 1)]; }}}}System.out.println(dp[0][0]); } static private class FastScanner{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public FastScanner( InputStream stream){ this.stream = stream; } int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} boolean isEndline( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} public int nextInt(){ return Integer.parseInt(next());} public String next(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} } }
3	public class C{ public static void main( String[] args){ Scanner s = new Scanner(System.in);  int n = s.nextInt();  List<String> commands = IntStream.range(0,n).boxed().map((x)->s.next()).collect(Collectors.toList());  List<Integer> ways = new ArrayList<>(); ways.add(1); boolean lastWasS = false; for ( String command :commands) { boolean isS = "s".equals(command); if ( lastWasS) {for ( int i = 1;(i < ways.size());++i) { int waysNumber = ((ways.get((i - 1)) + ways.get(i)) % 1_000_000_007); ways.set(i,waysNumber); }} if ( !isS) {ways.add(0); } lastWasS = isS; }System.out.println(ways.stream().reduce(0,(a,b)->((a + b) % 1_000_000_007))); } }
6	public class CFContest{ public static void main( String[] args)throws Exception { boolean local = (System.getProperty("ONLINE_JUDGE") == null);  boolean async = false;  Charset charset = Charset.forName("ascii");  FastIO io = (local?new FastIO(new FileInputStream("D:\\DATABASE\\TESTCASE\\Code.in"),System.out,charset):new FastIO(System.in,System.out,charset));  Task task = new Task(io,new Debug(local)); if ( async) { Thread t = new Thread(null,task,"dalt",(1 << 27)); t.setPriority(Thread.MAX_PRIORITY); t.start(); t.join(); } else {task.run(); }if ( local) {io.cache.append((("\n\n--memory -- \n" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20)) + "M")); } io.flush(); } public static class Task implements Runnable{ final FastIO io ; final Debug debug ; int inf = ((int)1e9 + 2); BitOperator bitOperator = new BitOperator(); Modular modular = new Modular(((int)1e9 + 7)); public Task( FastIO io, Debug debug){ this.io = io; this.debug = debug; } @Override public void run(){ solve(); } int[][][] f ; int n ; int t ; int[] songTimes ; int[] songTypes ; int mask ; public void solve(){ n = io.readInt(); t = io.readInt(); mask = (1 << n); f = new int[4][mask][(t + 1)]; for ( int i = 0;(i < 4);i++) {for ( int j = 0;(j < mask);j++) {for ( int k = 0;(k <= t);k++) {f[i][j][k] = -1; }}}songTimes = new int[(n + 1)]; songTypes = new int[(n + 1)]; for ( int i = 1;(i <= n);i++) {songTimes[i] = io.readInt(); songTypes[i] = io.readInt(); } int ans = 0; for ( int i = 0;(i < 4);i++) {for ( int j = 0;(j < mask);j++) {ans = modular.plus(ans,f(i,j,t)); }}io.cache.append(ans); } int f( int i, int j, int k){ if ( (j == 0)) {return (((k == 0) && (i == 0))?1:0);} if ( (k < 0)) {return 0;} if ( (f[i][j][k] == -1)) {f[i][j][k] = 0; for ( int x = 1;(x <= n);x++) {if ( ((songTypes[x] != i) || (bitOperator.bitAt(j,(x - 1)) == 0))) {continue;} for ( int y = 0;(y < 4);y++) {if ( (y == i)) {continue;} f[i][j][k] = modular.plus(f[i][j][k],f(y,bitOperator.setBit(j,(x - 1),false),(k - songTimes[x]))); }}} return f[i][j][k];} } public static class Modular{ int m ; public Modular( int m){ this.m = m; } public int valueOf( int x){ x %= m; if ( (x < 0)) {x += m; } return x;} public int valueOf( long x){ x %= m; if ( (x < 0)) {x += m; } return (int)x;} public int plus( int x, int y){ return valueOf((x + y));} @Override public String toString(){ return ("mod " + m);} } public static class BitOperator{ public int bitAt( int x, int i){ return ((x >> i) & 1);} public int bitAt( long x, int i){ return (int)((x >> i) & 1);} public int setBit( int x, int i, boolean v){ if ( v) {x |= (1 << i); } else {x &= (1 << i); }return x;} public long setBit( long x, int i, boolean v){ if ( v) {x |= (1L << i); } else {x &= (1L << i); }return x;} public long merge( long x, long y){ return (x | y);} public long intersect( long x, long y){ return (x & y);} } public static class Splay implements Cloneable{ public static final Splay NIL = new Splay(); {NIL.left = NIL; NIL.right = NIL; NIL.father = NIL; NIL.size = 0; NIL.key = Integer.MIN_VALUE; NIL.sum = 0; } Splay left = NIL; Splay right = NIL; Splay father = NIL; int size = 1; int key ; long sum ; public static void splay( Splay x){ if ( (x == NIL)) {return ;} Splay y ,z ; while(((y = x.father) != NIL)){if ( ((z = y.father) == NIL)) {y.pushDown(); x.pushDown(); if ( (x == y.left)) {zig(x); } else {zag(x); }} else {z.pushDown(); y.pushDown(); x.pushDown(); if ( (x == y.left)) {if ( (y == z.left)) {zig(y); zig(x); } else {zig(x); zag(x); }} else {if ( (y == z.left)) {zag(x); zig(x); } else {zag(y); zag(x); }}}}x.pushDown(); x.pushUp(); } public static void zig( Splay x){ Splay y = x.father;  Splay z = y.father;  Splay b = x.right; y.setLeft(b); x.setRight(y); z.changeChild(y,x); y.pushUp(); } public static void zag( Splay x){ Splay y = x.father;  Splay z = y.father;  Splay b = x.left; y.setRight(b); x.setLeft(y); z.changeChild(y,x); y.pushUp(); } public void setLeft( Splay x){ left = x; x.father = this; } public void setRight( Splay x){ right = x; x.father = this; } public void changeChild( Splay y, Splay x){ if ( (left == y)) {setLeft(x); } else {setRight(x); }} public void pushUp(){ if ( (this == NIL)) {return ;} size = ((left.size + right.size) + 1); sum = ((left.sum + right.sum) + key); } public void pushDown(){ } public static int toArray( Splay root, int[] data, int offset){ if ( (root == NIL)) {return offset;} offset = toArray(root.left,data,offset); data[offset++] = root.key; offset = toArray(root.right,data,offset); return offset;} public static void toString( Splay root, StringBuilder builder){ if ( (root == NIL)) {return ;} root.pushDown(); toString(root.left,builder); builder.append(root.key).append(','); toString(root.right,builder); } public Splay clone(){ try{return (Splay)super.clone(); }catch (CloneNotSupportedException e){ throw (new RuntimeException(e));} } public static Splay cloneTree( Splay splay){ if ( (splay == NIL)) {return NIL;} splay = splay.clone(); splay.left = cloneTree(splay.left); splay.right = cloneTree(splay.right); return splay;} public static Splay add( Splay root, Splay node){ if ( (root == NIL)) {return node;} Splay p = root; while((root != NIL)){p = root; root.pushDown(); if ( (root.key < node.key)) {root = root.right; } else {root = root.left; }}if ( (p.key < node.key)) {p.setRight(node); } else {p.setLeft(node); }p.pushUp(); splay(node); return node;} public static Splay selectMinAsRoot( Splay root){ if ( (root == NIL)) {return root;} root.pushDown(); while((root.left != NIL)){root = root.left; root.pushDown(); }splay(root); return root;} public static Splay selectMaxAsRoot( Splay root){ if ( (root == NIL)) {return root;} root.pushDown(); while((root.right != NIL)){root = root.right; root.pushDown(); }splay(root); return root;} public static Splay deleteRoot( Splay root){ root.pushDown(); Splay left = splitLeft(root);  Splay right = splitRight(root); return merge(left,right);} public static Splay splitLeft( Splay root){ root.pushDown(); Splay left = root.left; left.father = NIL; root.setLeft(NIL); root.pushUp(); return left;} public static Splay splitRight( Splay root){ root.pushDown(); Splay right = root.right; right.father = NIL; root.setRight(NIL); root.pushUp(); return right;} public static Splay merge( Splay a, Splay b){ if ( (a == NIL)) {return b;} if ( (b == NIL)) {return a;} a = selectMaxAsRoot(a); a.setRight(b); a.pushUp(); return a;} @Override public String toString(){ StringBuilder builder = new StringBuilder().append(key).append(":"); toString(cloneTree(this),builder); return builder.toString();} } public static class FastIO{ public final StringBuilder cache = new StringBuilder(); private final InputStream is ; private final OutputStream os ; private final Charset charset ; private StringBuilder defaultStringBuf = new StringBuilder((1 << 8)); private byte[] buf = new byte[(1 << 13)]; private int bufLen ; private int bufOffset ; private int next ; public FastIO( InputStream is, OutputStream os, Charset charset){ this.is = is; this.os = os; this.charset = charset; } public FastIO( InputStream is, OutputStream os){ this(is,os,Charset.forName("ascii")); } private int read(){ while((bufLen == bufOffset)){bufOffset = 0; try{bufLen = is.read(buf); }catch (IOException e){ throw (new RuntimeException(e));} if ( (bufLen == -1)) {return -1;} }return buf[bufOffset++];} public void skipBlank(){ while(((next >= 0) && (next <= 32))){next = read(); }} public int readInt(){ int sign = 1; skipBlank(); if ( ((next == '+') || (next == '-'))) {sign = ((next == '+')?1:-1); next = read(); } int val = 0; if ( (sign == 1)) {while(((next >= '0') && (next <= '9'))){val = (((val * 10) + next) - '0'); next = read(); }} else {while(((next >= '0') && (next <= '9'))){val = (((val * 10) - next) + '0'); next = read(); }}return val;} public String readString( StringBuilder builder){ skipBlank(); while((next > 32)){builder.append((char)next); next = read(); }return builder.toString();} public String readString(){ defaultStringBuf.setLength(0); return readString(defaultStringBuf);} public int readString( char[] data, int offset){ skipBlank(); int originalOffset = offset; while((next > 32)){data[offset++] = (char)next; next = read(); }return (offset - originalOffset);} public int readString( byte[] data, int offset){ skipBlank(); int originalOffset = offset; while((next > 32)){data[offset++] = (byte)next; next = read(); }return (offset - originalOffset);} public void flush(){ try{os.write(cache.toString().getBytes(charset)); os.flush(); cache.setLength(0); }catch (IOException e){ throw (new RuntimeException(e));} } } public static class Debug{ private boolean allowDebug ; public Debug( boolean allowDebug){ this.allowDebug = allowDebug; } public void fail(){ throw (new RuntimeException());} private void outputName( String name){ System.out.print((name + " = ")); } } }
1	public class Main{ private MyScanner scan = new MyScanner(); private PrintWriter out = new PrintWriter(System.out); private final double PI = Math.PI; private final int INF = (int)1e9; private final double EPS = 1e-6; private final int SIZEN = (int)1e7; private final int MOD = (int)(1e9 + 7); private final long MODH = 10000000007L,BASE = 10007; private final int[] DX = {0,1,0,-1},DY = {-1,0,1,0}; int n ; int[] sum ; int[][] a ; public int getId( char c){ return (((c >= 'a') && (c <= 'z'))?(c - 'a'):((c - 'A') + 26));} public boolean isOk( int len){ for ( int i = 0;((i + len) <= n);++i) { boolean flag = true; for ( int j = 0;(j < 52);++j) {if ( (((a[(i + len)][j] - a[i][j]) == 0) && (sum[j] != 0))) {flag = false; break;} }if ( flag) {return true;} }return false;} public void foo(){ n = scan.nextInt(); char[] s = scan.next().toCharArray(); a = new int[(n + 1)][52]; sum = new int[52]; for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < 52);++j) a[(i + 1)][j] = a[i][j]; ++a[(i + 1)][getId(s[i])]; ++sum[getId(s[i])]; } int left = 1,right = n,ans = n; while((left <= right)){ int mid = ((left + right) >> 1); if ( isOk(mid)) {ans = mid; right = (mid - 1); } else {left = (mid + 1); }}out.println(ans); } public static void main( String[] args){ Main m = new Main(); m.foo(); m.out.close(); } public long gcd( long a, long b){ return ((0 == b)?a:gcd(b,(a % b)));} class MyScanner{ private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; BufferedInputStream bis = new BufferedInputStream(System.in); public int read(){ if ( (-1 == numChars)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = bis.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String next(){ int c = read(); while(isSpaceChar(c)){c = read(); } StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} private boolean isSpaceChar( int c){ return (((((' ' == c) || ('\n' == c)) || ('\r' == c)) || ('\t' == c)) || (-1 == c));} } }
5	public class Solution implements Runnable{ public static void main( String[] args){ new Thread(new Solution()).start(); } BufferedReader in ; PrintWriter out ; StringTokenizer st ; String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} class Dom implements Comparable<Dom>{ int x ,a ; } void solve()throws Exception { int n = nextInt();  int t = (nextInt() * 2);  Dom[] a = new Dom[n]; for ( int i = 0;(i < n);i++) {a[i] = new Dom(); a[i].x = (nextInt() * 2); a[i].a = nextInt(); }Arrays.sort(a); int ans = 2; for ( int i = 0;(i < (n - 1));i++) {if ( (t < (((a[(i + 1)].x - a[(i + 1)].a) - a[i].x) - a[i].a))) ans += 2; if ( (t == (((a[(i + 1)].x - a[(i + 1)].a) - a[i].x) - a[i].a))) ans += 1; }out.print(ans); } }
1	public class B{ static private StreamTokenizer in ; static private PrintWriter out ; static private int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} static private String nextString()throws Exception { in.nextToken(); return in.sval;} {in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); }public static void main( String[] args)throws Exception { int n = nextInt();  char[] c = nextString().toCharArray();  int tc = 0,hc = 0; for ( int i = 0;(i < c.length);i++) {if ( (c[i] == 'T')) tc++; else hc++; } int max = -1;  int pos = 0; for ( int i = 0;(i < c.length);i++) { int a = 0; for ( int j = 0;(j < tc);j++) { int k = (i + j); if ( (k >= n)) k -= n; if ( (c[k] == 'T')) {a++; } }if ( (a > max)) {max = a; pos = i; } } int min1 = (tc - max); max = -1; pos = 0; for ( int i = 0;(i < c.length);i++) { int a = 0; for ( int j = 0;(j < hc);j++) { int k = (i + j); if ( (k >= n)) k -= n; if ( (c[k] == 'H')) {a++; } }if ( (a > max)) {max = a; pos = i; } } int min2 = (hc - max); out.println(Math.min(min1,min2)); out.flush(); } }
3	public class C{ static ArrayList<Integer> statements ; static final int MOD = ((int)1e9 + 7); static int[][] memo ; static int solve( int i, int c){ if ( (i == statements.size())) return 1; if ( (memo[i][c] != -1)) return memo[i][c]; long ans = solve((i + 1),(c + statements.get(i))); if ( (c > 0)) ans += solve(i,(c - 1)); return memo[i][c] = (int)(ans % MOD);} public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  int n = sc.nextInt(); statements = new ArrayList<>(); char[] c = new char[n]; for ( int i = 0;(i < n);i++) {c[i] = sc.next().charAt(0); }if ( (c[0] == 's')) statements.add(0); else statements.add(1); for ( int i = 1;(i < n);i++) {if ( (c[(i - 1)] == 'f')) {if ( (c[i] == 'f')) statements.set((statements.size() - 1),(statements.get((statements.size() - 1)) + 1)); } else {if ( (c[i] == 's')) statements.add(0); else statements.add(1); }}memo = new int[statements.size()][(n + 1)]; for ( int[] a :memo) Arrays.fill(a,-1); out.println(solve(0,0)); out.flush(); out.close(); } static class Scanner{ StringTokenizer st ; BufferedReader br ; public Scanner( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } public Scanner( String file)throws FileNotFoundException{ br = new BufferedReader(new FileReader(file)); } 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 boolean ready()throws IOException { return br.ready();} } }
5	public class A{ int IOMode = 0; String taskName = ""; void solve()throws IOException { int n = nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = nextInt(); Arrays.sort(a); int z = 0; for ( int i = 0;(i < n);i++) {if ( (a[i] != 1)) z++; }if ( ((z == 0) && (n > 1))) a[(n - 2)] = 2; if ( ((n == 1) && (a[0] == 1))) {out.println(2); return ;} out.print("1 "); for ( int i = 0;(i < (n - 1));i++) out.print((a[i] + " ")); } public static void main( String[] args)throws IOException { if ( ((args.length > 0) && args[0].equals("Abra"))) debugMode = true; new A().run(); } long startTime = System.nanoTime(),tempTime = startTime,finishTime = startTime; long startMem = Runtime.getRuntime().totalMemory(),finishMem = startMem; void run()throws IOException { init(); if ( debugMode) {con.println("Start"); con.println("Console output:"); } solve(); finishTime = System.nanoTime(); finishMem = Runtime.getRuntime().totalMemory(); out.flush(); if ( debugMode) { int maxSymbols = 1000,c = 0;  BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));  char[] a = new char[maxSymbols]; tbr.read(a); if ( (a[0] != 0)) {con.println(); con.println("File input:"); con.print(a); } boolean left = true; for ( int i = 0;(i < maxSymbols);i++) left = (left && (a[i] != 0)); if ( left) con.println("..."); else con.println(); tbr = new BufferedReader(new FileReader("output.txt")); a = new char[maxSymbols]; tbr.read(a); if ( (a[0] != 0)) {con.println(); con.println("File output:"); con.print(a); } left = true; for ( int i = 0;(i < maxSymbols);i++) left = (left && (a[i] != 0)); if ( left) con.println("..."); else con.println(); con.println((("Time passed: " + ((finishTime - startTime) / 1000000000.0)) + " sec")); con.println((("Memory used: " + (finishMem - startMem)) + " bytes")); con.println((("Total memory: " + Runtime.getRuntime().totalMemory()) + " bytes")); } } static boolean debugMode = false; PrintStream con = System.out; void init()throws IOException { if ( (debugMode && (IOMode != 3))) {br = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new FileWriter("output.txt")); } else switch(IOMode){ case 0:br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); break; case 1:br = new BufferedReader(new FileReader((taskName + ".in"))); out = new PrintWriter(new FileWriter((taskName + ".out"))); break; case 2:br = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new FileWriter("output.txt")); break; case 3:out = new PrintWriter(new FileWriter("input.txt")); break; } } BufferedReader br ; PrintWriter out ; StringTokenizer in ; boolean hasMoreTokens()throws IOException { while(((in == null) || !in.hasMoreTokens())){ String line = br.readLine(); if ( (line == null)) return false; in = new StringTokenizer(line); }return true;} String nextString()throws IOException { return (hasMoreTokens()?in.nextToken():null);} int nextInt()throws IOException { return Integer.parseInt(nextString());} }
4	public class C implements Runnable{ static private final Random rnd = new Random(); static private final String fileName = ""; private void solve(){ int n = readInt();  int m = readInt();  int k = readInt();  Point[] starts = readPointArray(k); for ( Point start :starts) {start.x--; start.y--; } Point furthest = bfs(n,m,starts); out.println((((furthest.x + 1) + " ") + (furthest.y + 1))); } private Point bfs( int n, int m, Point[] starts){ final int INF = ((n * m) + 1);  boolean[][] used = new boolean[n][m];  Queue<Integer> queue = new ArrayDeque<>(); for ( Point start :starts) {used[start.x][start.y] = true; queue.add(((start.x * m) + start.y)); } int last = -1; while((queue.size() > 0)){ int from = queue.poll(); last = from; int fromX = (from / m),fromY = (from % m); for ( int[] step :steps) { int toX = (fromX + step[0]);  int toY = (fromY + step[1]); if ( !checkCell(toX,n,toY,m)) continue; if ( used[toX][toY]) continue; used[toX][toY] = true; queue.add(((toX * m) + toY)); }}return new Point((last / m),(last % m));} static private final boolean FIRST_INPUT_STRING = false; static private final boolean MULTIPLE_TESTS = true; private final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); static private final int MAX_STACK_SIZE = 128; static private final boolean OPTIMIZE_READ_NUMBERS = false; private BufferedReader in ; private OutputWriter out ; private StringTokenizer tok = new StringTokenizer(""); public static void main( String[] args){ new Thread(null,new C(),"",(MAX_STACK_SIZE * (1L << 20))).start(); } private void init()throws FileNotFoundException { Locale.setDefault(Locale.US); in = new BufferedReader(new FileReader("input.txt")); out = new OutputWriter("output.txt"); } private long timeBegin ; private void timeInit(){ this.timeBegin = System.currentTimeMillis(); } private void time(){ long timeEnd = System.currentTimeMillis(); System.err.println(("Time = " + (timeEnd - timeBegin))); } private String delim = " "; private String readLine(){ try{return in.readLine(); }catch (IOException e){ throw (new RuntimeIOException(e));} } private String readString(){ try{while(!tok.hasMoreTokens()){tok = new StringTokenizer(readLine()); }return tok.nextToken(delim); }catch (NullPointerException e){ return null;} } private final char NOT_A_SYMBOL = '\0'; private char[] readCharArray(){ return readLine().toCharArray();} private long optimizedReadLong(){ int sign = 1;  long result = 0;  boolean started = false; while(true){try{ int j = in.read(); if ( (-1 == j)) {if ( started) return (sign * result); throw (new NumberFormatException());} if ( (j == '-')) {if ( started) throw (new NumberFormatException()); sign = -sign; } if ( (('0' <= j) && (j <= '9'))) {result = (((result * 10) + j) - '0'); started = true; } else if ( started) {return (sign * result);} }catch (IOException e){ throw (new RuntimeIOException(e));} }} private int readInt(){ if ( !OPTIMIZE_READ_NUMBERS) {return Integer.parseInt(readString());} else {return (int)optimizedReadLong();}} private int[] readIntArray( int size){ int[] array = new int[size]; for ( int index = 0;(index < size);++index) {array[index] = readInt(); }return array;} private int[] readIntArrayWithDecrease( int size){ int[] array = readIntArray(size); for ( int i = 0;(i < size);++i) {array[i]--; }return array;} private long readLong(){ if ( !OPTIMIZE_READ_NUMBERS) {return Long.parseLong(readString());} else {return optimizedReadLong();}} private double readDouble(){ return Double.parseDouble(readString());} private Point readPoint(){ int x = readInt();  int y = readInt(); return new Point(x,y);} private Point[] readPointArray( int size){ Point[] array = new Point[size]; for ( int index = 0;(index < size);++index) {array[index] = readPoint(); }return array;} static private class GraphBuilder{ final int size ; final List<Integer>[] edges ; private GraphBuilder( List<Integer>[] edges){ this.size = edges.length; this.edges = edges; } public void addDirectedEdge( int from, int to){ edges[from].add(to); } } static private class IntIndexPair{ static Comparator<IntIndexPair> increaseComparator = new Comparator<C.IntIndexPair>(){}; static Comparator<IntIndexPair> decreaseComparator = new Comparator<C.IntIndexPair>(){}; int value ,index ; IntIndexPair( int value, int index){ super(); this.value = value; this.index = index; } } static private class OutputWriter extends PrintWriter{ final int DEFAULT_PRECISION = 12; private int precision ; private String format ,formatWithSpace ; {precision = DEFAULT_PRECISION; format = createFormat(precision); formatWithSpace = (format + " "); }OutputWriter( OutputStream out){ super(out); } OutputWriter( String fileName)throws FileNotFoundException{ super(fileName); } String createFormat( int precision){ return (("%." + precision) + "f");} @Override public void print( double d){ printf(format,d); } void printWithSpace( double d){ printf(formatWithSpace,d); } void printAll( double... d){ for ( int i = 0;(i < (d.length - 1));++i) {printWithSpace(d[i]); }print(d[(d.length - 1)]); } @Override public void println( double d){ printlnAll(d); } void printlnAll( double... d){ printAll(d); println(); } } static private class RuntimeIOException extends RuntimeException{ static private final long serialVersionUID = -6463830523020118289L; RuntimeIOException( Throwable cause){ super(cause); } } static private final int[][] steps = {{-1,0},{1,0},{0,-1},{0,1}}; static private final int[][] steps8 = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{1,-1},{-1,1}}; static private boolean checkCell( int row, int rowsCount, int column, int columnsCount){ return (checkIndex(row,rowsCount) && checkIndex(column,columnsCount));} static private boolean checkIndex( int index, int lim){ return ((0 <= index) && (index < lim));} static private long gcd( long a, long b){ return ((a == 0)?b:gcd((b % a),a));} static private int[] castInt( List<Integer> list){ int[] array = new int[list.size()]; for ( int i = 0;(i < array.length);++i) {array[i] = list.get(i); }return array;} }
0	public class HexadecimalsTheorem{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int num = in.nextInt();  LinkedList<Integer> result = new LinkedList<Integer>();  int temp0 = 1;  int temp1 = 1;  int temp2 = 0; result.add(0); result.add(0); result.add(0); result.add(temp0); result.add(temp1); if ( (num == 2)) {System.out.println(((((0 + " ") + 1) + " ") + 1)); } else if ( (num == 0)) {System.out.println(((((0 + " ") + 0) + " ") + 0)); } else {while((temp2 < num)){temp2 = (temp1 + temp0); result.add(temp2); temp0 = temp1; temp1 = temp2; } int length = result.size(); System.out.println(((((result.get((length - 5)) + " ") + result.get((length - 4))) + " ") + result.get((length - 2)))); }} }
4	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,k = 0,p = 0,m = 0,i = 0;  String s ; s = b.readLine(); StringTokenizer c = new StringTokenizer(s); n = Integer.parseInt(c.nextToken()); m = Integer.parseInt(c.nextToken()); k = Integer.parseInt(b.readLine()); int e[][] = new int[k][2]; s = b.readLine(); StringTokenizer z = new StringTokenizer(s); for ( i = 0;(i < k);i++) {e[i][0] = Integer.parseInt(z.nextToken()); e[i][1] = Integer.parseInt(z.nextToken()); }for ( i = 1;(i <= n);i++) {for ( j = 1;(j <= m);j++) {for ( l = 0;(l < k);l++) {p = ((int)Math.abs((e[l][0] - i)) + (int)Math.abs((e[l][1] - j))); if ( (p < min)) {min = p; x1 = i; y1 = j; } }if ( (min > max)) {max = min; x = x1; y = y1; } min = 100000; }}out.print(((x + " ") + y)); out.close(); } }
2	public class P255D{ @SuppressWarnings public void run()throws Exception { long n = nextLong();  long x = nextLong();  long y = nextLong();  long c = nextLong(); if ( ((n == 1) || (c == 1))) {println(0); return ;} x = Math.min(x,((n - x) + 1)); y = Math.min(y,((n - y) + 1)); long t = 0;  long s = 1; while((s < c)){t++; s += ((((((((t * 4) + ((t >= (x + y))?(((t - x) - y) + 1):0)) - ((t >= x)?(((t - x) * 2) + 1):0)) - ((t >= y)?(((t - y) * 2) + 1):0)) + ((t >= (((x + n) - y) + 1))?(((t - x) - n) + y):0)) + ((t >= (((n - x) + 1) + y))?(((t - n) + x) - y):0)) - ((t >= ((n - x) + 1))?(((((t - n) + x) - 1) * 2) + 1):0)) - ((t >= ((n - y) + 1))?(((((t - n) + y) - 1) * 2) + 1):0)); }println(t); } public static void main( String... args)throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P255D().run(); br.close(); pw.close(); } static BufferedReader br ; static PrintWriter pw ; StringTokenizer stok ; String nextToken()throws IOException { while(((stok == null) || !stok.hasMoreTokens())){ String s = br.readLine(); if ( (s == null)) {return null;} stok = new StringTokenizer(s); }return stok.nextToken();} void print( byte b){ print(("" + b)); } void print( int i){ print(("" + i)); } void print( long l){ print(("" + l)); } void print( double d){ print(("" + d)); } void print( char c){ print(("" + c)); } void print( Object o){ if ( (o instanceof int[])) {print(Arrays.toString((int[])o)); } else if ( (o instanceof long[])) {print(Arrays.toString((long[])o)); } else if ( (o instanceof char[])) {print(Arrays.toString((char[])o)); } else if ( (o instanceof byte[])) {print(Arrays.toString((byte[])o)); } else if ( (o instanceof short[])) {print(Arrays.toString((short[])o)); } else if ( (o instanceof boolean[])) {print(Arrays.toString((boolean[])o)); } else if ( (o instanceof float[])) {print(Arrays.toString((float[])o)); } else if ( (o instanceof double[])) {print(Arrays.toString((double[])o)); } else if ( (o instanceof Object[])) {print(Arrays.toString((Object[])o)); } else {print(("" + o)); }} void print( String s){ pw.print(s); } void println(){ println(""); } void println( byte b){ println(("" + b)); } void println( int i){ println(("" + i)); } void println( long l){ println(("" + l)); } void println( double d){ println(("" + d)); } void println( char c){ println(("" + c)); } void println( Object o){ print(o); println(""); } void println( String s){ pw.println(s); } int nextInt()throws IOException { return Integer.parseInt(nextToken());} long nextLong()throws IOException { return Long.parseLong(nextToken());} double nextDouble()throws IOException { return Double.parseDouble(nextToken());} String nextLine()throws IOException { return br.readLine();} }
4	public class ProblemC{ static int[] dx = {1,0,0,-1}; static int[] dy = {0,1,-1,0}; public static void main( String[] args)throws IOException { BufferedReader s = new BufferedReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new FileWriter("output.txt"));  String[] nm = s.readLine().split(" ");  int n = Integer.valueOf(nm[0]);  int m = Integer.valueOf(nm[1]);  int k = Integer.valueOf(s.readLine());  int[][] dp = new int[n][m]; for ( int i = 0;(i < n);i++) {Arrays.fill(dp[i],Integer.MAX_VALUE); } String[] st = s.readLine().split(" ");  int[][] trees = new int[k][2]; for ( int l = 0;(l < k);l++) {trees[l][0] = (Integer.valueOf(st[(l * 2)]) - 1); trees[l][1] = (Integer.valueOf(st[((l * 2) + 1)]) - 1); } int maxtime = -1;  int max_x = -1;  int max_y = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int minDist = (n + m); for ( int l = 0;(l < k);l++) {minDist = Math.min(minDist,(Math.abs((i - trees[l][0])) + Math.abs((j - trees[l][1])))); }if ( (maxtime < minDist)) {maxtime = minDist; max_x = (i + 1); max_y = (j + 1); } }}out.println(((max_x + " ") + max_y)); out.flush(); } }
1	public class cf1 implements Runnable{ static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } public static void main( String[] args)throws Exception { new Thread(null,new cf1(),"cf1",(1 << 26)).start(); } }
3	public class CC{ public static void main( String[] args)throws Throwable { MyScanner sc = new MyScanner();  PrintWriter pw = new PrintWriter(System.out); n = sc.nextInt(); s = new char[n]; for ( int i = 0;(i < n);i++) s[i] = sc.next().charAt(0); mem = new int[((2 * n) + 1)][(n + 1)]; for ( int[] x :mem) Arrays.fill(x,-1); pw.println(dp(0,0)); pw.flush(); pw.close(); } static int n ; static char[] s ; static int[][] mem ; static int dp( int i, int j){ if ( (i == n)) return ((j == 0)?1:0); if ( (mem[i][j] != -1)) return mem[i][j]; int ans = 0; if ( (s[i] == 'f')) {ans += dp((i + 1),(j + 1)); ans %= mod; } else {ans += dp((i + 1),j); ans %= mod; if ( (j > 0)) {ans += dp(i,(j - 1)); ans %= mod; } }return mem[i][j] = ans;} static int mod = (int)(1e9 + 7); 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());} } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } } class TaskC{ public void solve( int testNumber, InputReader in, OutputWriter out){ int maxdist = -1,maxrow = -1,maxcol = -1;  int rows = in.ri(),cols = in.ri();  int k = in.ri();  IntPair[] points = new IntPair[k]; for ( int i = 0;(i < k);i++) points[i] = new IntPair(in.ri(),in.ri()); for ( int row = 1;(row <= rows);row++) {for ( int col = 1;(col <= cols);col++) { int mindist = Integer.MAX_VALUE; for ( int i = 0;(i < k);i++) mindist = Math.min(mindist,(Math.abs((row - points[i].first)) + Math.abs((col - points[i].second)))); if ( (mindist > maxdist)) {maxdist = mindist; maxrow = row; maxcol = col; } }}out.printLine(maxrow,maxcol); } } class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int ri(){ return readInt();} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void print( Object... objects){ for ( int i = 0;(i < objects.length);i++) {if ( (i != 0)) writer.print(' '); writer.print(objects[i]); }} public void printLine( Object... objects){ print(objects); writer.println(); } public void close(){ writer.close(); } } class IntPair implements Comparable<IntPair>{ public int first ,second ; public IntPair( int first, int second){ this.first = first; this.second = second; } }
4	public class C{ public static void main( String[] args)throws Exception { new C(new Scanner(new File("input.txt")),new PrintWriter("output.txt")); } int oo = 987654321; int W ,H ; public C( Scanner in, PrintWriter out){ W = in.nextInt(); H = in.nextInt(); int[][] grid = new int[W][H]; for ( int[] gri :grid) Arrays.fill(gri,oo); ArrayDeque<Node> q = new ArrayDeque<Node>();  int K = in.nextInt(); for ( int u = 0;(u < K);u++) {q.add(new Node((in.nextInt() - 1),(in.nextInt() - 1),0)); while((q.size() > 0)){ Node cur = q.poll(); if ( (grid[cur.x][cur.y] <= cur.d)) continue; grid[cur.x][cur.y] = cur.d; if ( ((cur.x + 1) < W)) q.add(new Node((cur.x + 1),cur.y,(cur.d + 1))); if ( (cur.x > 0)) q.add(new Node((cur.x - 1),cur.y,(cur.d + 1))); if ( ((cur.y + 1) < H)) q.add(new Node(cur.x,(cur.y + 1),(cur.d + 1))); if ( (cur.y > 0)) q.add(new Node(cur.x,(cur.y - 1),(cur.d + 1))); }} int res = 0; for ( int j = 0;(j < H);j++) for ( int i = 0;(i < W);i++) res = Math.max(res,grid[i][j]); for ( int j = 0;(j < H);j++) for ( int i = 0;(i < W);i++) if ( (res == grid[i][j])) {out.printf("%d %d%n",(i + 1),(j + 1)); out.close(); return ;} } } class Node{ int x ,y ,d ; public Node( int xx, int yy, int dd){ x = xx; y = yy; d = dd; } }
5	public class Main{ public static void main( String[] args)throws IOException { try{if ( new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt"));  }catch (SecurityException e){ } new Main().run(); } BufferedReader in ; PrintWriter out ; StringTokenizer st = new StringTokenizer(""); private void run()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int n = nextInt();  int m[] = new int[n]; for ( int i = 0;(i < n);i++) m[i] = nextInt(); sort(m); m[(n - 1)] = ((m[(n - 1)] != 1)?1:2); sort(m); for ( int i = 0;(i < n);i++) {if ( (i != 0)) out.print(" "); out.print(m[i]); }out.println(); in.close(); out.close(); } String nextToken()throws IOException { while(!st.hasMoreTokens())st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
1	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 { while(!st.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) return null; eat(line); }return st.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args){ new Thread(new Main()).start(); } public void go()throws IOException { int n = nextInt();  int[] v = new int[n],count = new int[2]; for ( int i = 0;(i < n);++i) {v[i] = nextInt(); ++count[(v[i] % 2)]; } int residue = ((count[0] == 1)?0:1); for ( int i = 0;(i < n);++i) if ( ((v[i] % 2) == residue)) out.println((i + 1)); } }
1	public class IQTest implements Runnable{ BufferedReader in ; PrintWriter out ; StringTokenizer tok ; public static void main( String[] args){ new Thread(new IQTest()).start(); } void solve()throws IOException { int n = nextInt();  List<Integer> l1 = new ArrayList<Integer>();  List<Integer> l2 = new ArrayList<Integer>(); for ( int i = 0;(i < n);++i) { int k = nextInt(); if ( ((k % 2) == 0)) l1.add((i + 1)); else l2.add((i + 1)); }if ( (l1.size() == 1)) out.println(l1.get(0)); else out.println(l2.get(0)); } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tok == null) || !tok.hasMoreTokens())){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} }
5	public class A015{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt(),t = in.nextInt();  int[] centers = new int[n],sides = new int[n]; for ( int x = 0;(x < n);x++) {centers[x] = in.nextInt(); sides[x] = in.nextInt(); } int count = 0; for ( int x = -4000;(x <= 4000);x++) { boolean touch = false; for ( int i = 0;(i < n);i++) { int d = ((2 * centers[i]) - x); d = ((d > 0)?d:-d); int s = (t + sides[i]); if ( (s == d)) {touch = true; } else if ( (s > d)) {continue big;} }if ( touch) count++; }System.out.println(count); } }
3	public class C{ static int N ; static char[] a ; static int[][] memo ; static int[] ind ; static final 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(); a = new char[N]; for ( int i = 0;(i < N);i++) a[i] = sc.nextChar(); if ( (N == 1)) {out.println(1); out.flush(); return ;} memo = new int[N][(N + 5)]; for ( int[] a :memo) Arrays.fill(a,-1); out.println(dp(0,1)); out.flush(); out.close(); } static int dp( int i, int ind){ if ( (i == (N - 1))) return ((a[(i - 1)] == 'f')?1:ind); if ( (i == 0)) return dp((i + 1),((a[i] == 's')?1:2)); if ( (memo[i][ind] != -1)) return memo[i][ind]; int ans = 0; if ( (a[(i - 1)] == 'f')) ans = dp((i + 1),((a[i] == 's')?ind:(ind + 1))); else {if ( (ind > 1)) ans = ((ans + dp(i,(ind - 1))) % MOD); ans = ((ans + dp((i + 1),((a[i] == 's')?ind:(ind + 1)))) % MOD); }return memo[i][ind] = ans;} static class Scanner{ StringTokenizer st ; BufferedReader br ; Scanner( InputStream system){ br = new BufferedReader(new InputStreamReader(system)); } Scanner( String file)throws FileNotFoundException{ br = new BufferedReader(new FileReader(file)); } 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());} char nextChar()throws IOException { return next().charAt(0);} boolean ready()throws IOException { return br.ready();} } }
0	public class A125D2{ public static void main( String[] args)throws Exception { InputReader in = new InputReader(System.in); System.out.println(((((0 + " ") + 0) + " ") + in.nextInt())); } static class InputReader{ private BufferedReader reader ; private 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());} } }
5	public class Solution{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  TreeMap<Integer,Integer> h = new TreeMap<Integer,Integer>(); for ( int i = 0;(i < n);i++) { int key = sc.nextInt(); h.put(key,sc.nextInt()); } int ans = 2;  Integer lastKey = h.firstKey();  Integer last = h.get(lastKey); h.remove(lastKey); for ( int i = 1;(i < n);i++) { int key = h.firstKey();  int val = h.get(key); if ( (Math.abs(((key - ((val * 1.0) / 2)) - (lastKey + ((last * 1.0) / 2)))) == t)) {ans++; } else if ( (Math.abs(((key - ((val * 1.0) / 2)) - (lastKey + ((last * 1.0) / 2)))) > t)) {ans += 2; } lastKey = key; last = val; h.remove(lastKey); }System.out.println(ans); sc.close(); } }
5	public class Main{ static double eps = 1e-8; public static void main( String[] args){ Scanner r = new Scanner(System.in);  int n = r.nextInt();  int t = r.nextInt();  House[] a = new House[n]; for ( int i = 0;(i < n);i++) { double c = r.nextInt();  double l = r.nextInt(); a[i] = new House((c - (l / 2)),l); }Arrays.sort(a); int res = 0; for ( int i = 0;(i < (n - 1));i++) { double dist = (a[(i + 1)].s - (a[i].s + a[i].l)); if ( (Math.abs((dist - t)) < eps)) res++; else if ( (dist > t)) res += 2; }System.out.println((res + 2)); } } class House implements Comparable<House>{ double s ,l ; public House( double si, double li){ s = si; l = li; } }
5	public class CodeForces{ public void solve()throws IOException { int n = nextInt();  int t = nextInt();  double larr[] = new double[n];  double rarr[] = new double[n]; for ( int i = 0;(i < n);i++) { double x = nextDouble();  double r = nextDouble(); larr[i] = (x - (r / 2)); rarr[i] = (x + (r / 2)); }Arrays.sort(larr); Arrays.sort(rarr); int counter = 2; for ( int i = 1;(i < n);i++) {if ( ((larr[i] - rarr[(i - 1)]) > t)) {counter += 2; } else if ( ((larr[i] - rarr[(i - 1)]) == t)) {counter++; } }writer.print(counter); } public static void main( String[] args){ new CodeForces().run(); } BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter writer ; public void run(){ try{reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } int nextInt()throws IOException { return Integer.parseInt(nextToken());} double nextDouble()throws IOException { return Double.parseDouble(nextToken());} String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} }
6	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);  G1PleilistDlyaPolikarpaUproshennayaVersiya solver = new G1PleilistDlyaPolikarpaUproshennayaVersiya(); solver.solve(1,in,out); out.close(); } static class G1PleilistDlyaPolikarpaUproshennayaVersiya{ static final int MOD = ((int)1e9 + 7); int n ; int t ; int[][] a = new int[15][2]; long[][] mem = new long[(1 << 15)][4]; public void solve( int testNumber, InputReader in, PrintWriter out){ for ( int i = 0;(i < (1 << 15));i++) {for ( int h = 0;(h < 4);h++) {mem[i][h] = -1; }}n = in.nextInt(); t = in.nextInt(); for ( int i = 0;(i < n);i++) {a[i][0] = in.nextInt(); a[i][1] = in.nextInt(); }out.println(doit(0,0,0)); } private long doit( int mask, int genre, int sum){ if ( (mem[mask][genre] != -1)) {return mem[mask][genre];} if ( (sum > t)) {mem[mask][genre] = 0; return mem[mask][genre];} if ( (sum == t)) {mem[mask][genre] = 1; return mem[mask][genre];} long ct = 0; for ( int i = 0;(i < n);i++) {if ( (((mask & (1 << i)) > 0) || (genre == a[i][1]))) {continue;} ct = ((ct + doit((mask | (1 << i)),a[i][1],(sum + a[i][0]))) % MOD); }mem[mask][genre] = ct; return mem[mask][genre];} } 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());} } }
2	public class ehsan{ public static BigInteger f( BigInteger m, BigInteger n){ BigInteger s ,l ; s = n.multiply(m.add(BigInteger.valueOf(1))); l = m.multiply(m.add(BigInteger.valueOf(1))); l = l.divide(BigInteger.valueOf(2)); s = s.subtract(l); s = s.subtract(m); return s;} public static BigInteger bs( BigInteger a, BigInteger b, BigInteger n, BigInteger d){ BigInteger c ,e ; c = a.add(b); c = c.divide(BigInteger.valueOf(2)); e = f(c,n); if ( e.equals(d)) return c.add(BigInteger.valueOf(1)); if ( a.equals(b.add(BigInteger.valueOf(-1)))) return b.add(BigInteger.valueOf(1)); if ( (e.compareTo(d) > 0)) return bs(a,c,n,d); return bs(c,b,n,d);} public static void main( String[] args){ Scanner sc = new Scanner(System.in);  BigInteger bi1 = sc.nextBigInteger();  BigInteger bi2 = sc.nextBigInteger();  BigInteger i ,n = bi2;  BigInteger i2 = BigInteger.valueOf(1);  BigInteger sum = BigInteger.valueOf(0); if ( (bi1.compareTo(bi2) < 0)) {System.out.println(0); return ;} if ( (bi1.compareTo(bi2) == 0)) {System.out.println(1); return ;} bi2 = n.multiply(n.add(BigInteger.valueOf(1))).subtract(n.subtract(BigInteger.valueOf(1))); if ( (bi1.compareTo(bi2) > 0)) System.out.println(-1); else {System.out.println(bs(BigInteger.valueOf(0),n.add(BigInteger.valueOf(-2)),n,bi1)); }} }
1	public class C701{ static FastReader in = null; static PrintWriter out = null; public static void solve(){ int n = in.nint();  String pk = in.next();  boolean[] occ = new boolean[52]; for ( int i = 0;(i < n);i++) { char c = pk.charAt(i);  int val = (Character.isUpperCase(c)?(int)(c - 'A'):(int)((c - 'a') + 26)); occ[val] = true; } int[][] next = new int[n][52]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < 52);j++) next[i][j] = -1; for ( int i = (n - 1);(i >= 0);i--) { char c = pk.charAt(i);  int val = (Character.isUpperCase(c)?(int)(c - 'A'):(int)((c - 'a') + 26)); next[i][val] = i; if ( (i < (n - 1))) for ( int j = 0;(j < 52);j++) {if ( (j != val)) {next[i][j] = next[(i + 1)][j]; } } } int min = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int maxd = 0;  boolean endearly = false; for ( int j = 0;(j < 52);j++) {if ( (occ[j] && (next[i][j] == -1))) {endearly = true; break;} else if ( occ[j]) {maxd = Math.max(maxd,((next[i][j] - i) + 1)); } }if ( endearly) break; min = Math.min(min,maxd); }out.println(min); } public static void main( String[] args){ in = new FastReader(System.in); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); } static class FastReader{ BufferedReader read ; StringTokenizer tokenizer ; public FastReader( InputStream in){ read = new BufferedReader(new InputStreamReader(in)); } public String next(){ while(((tokenizer == null) || !tokenizer.hasMoreTokens())){try{tokenizer = new StringTokenizer(read.readLine()); }catch (Exception e){ throw (new RuntimeException(e));} }return tokenizer.nextToken();} public int nint(){ return Integer.parseInt(next());} public long nlong(){ return Long.parseLong(next());} } }
4	public class Main{ public String[][] a ; public void run()throws Exception { Scanner in = new Scanner(new File("input.txt"));  PrintWriter pw = new PrintWriter(new File("output.txt"));  int n = in.nextInt();  int m = in.nextInt();  int k = in.nextInt();  int[] xx = new int[k];  int[] yy = new int[k]; for ( int i = 0;(i < k);i++) {xx[i] = in.nextInt(); yy[i] = in.nextInt(); } int x = 0,y = 0,r ; r = -1; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) { int rr = 1000000; for ( int q = 0;(q < k);q++) rr = Math.min(rr,(Math.abs(((xx[q] - 1) - i)) + Math.abs(((yy[q] - 1) - j)))); if ( (rr > r)) {r = rr; x = i; y = j; } }pw.print((((x + 1) + " ") + (y + 1))); pw.close(); } public static void main( String[] args)throws Exception { new Main().run(); } }
2	public class TaskB{ static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer str ; static String SK ; static String next()throws IOException { while(((str == null) || str.hasMoreTokens())){SK = in.readLine(); if ( (SK == null)) return null; str = new StringTokenizer(SK); }return str.nextToken();} static int nextInt()throws IOException { return Integer.parseInt(next());} static long nextLong()throws IOException { return Long.parseLong(next());} public static void main( String[] args)throws IOException { long n = nextLong();  int k = nextInt(); if ( (n == 1)) {System.out.println(0); return ;} long sum = ((((2 + (long)k) * ((long)k - 1)) / 2) - ((long)k - 2)); if ( (n > sum)) {System.out.println(-1); return ;} else if ( (n <= k)) {System.out.println(1); return ;} long cnt = 0;  long sum2 = 0;  int index = binSearch(2,k,k,n); sum2 = ((((long)(index)+k * (long)((k - index) + 1)) / 2) - (long)(k - index)); cnt = ((k - index) + 1); if ( (sum2 == n)) {System.out.println(cnt); return ;} if ( (sum2 > n)) for ( int kk = index;(kk <= k);kk++) {sum2 = ((((long)(kk)+k * (long)((k - kk) + 1)) / 2) - (long)(k - kk)); cnt--; if ( (sum2 <= n)) {System.out.println((cnt + 1)); return ;} } else {for ( int kk = (index - 1);(kk >= 2);kk--) {sum2 = ((((long)(kk)+k * (long)((k - kk) + 1)) / 2) - (long)(k - kk)); cnt++; if ( (sum2 >= n)) {System.out.println(cnt); return ;} }}System.out.println(-1); return ;} static int binSearch( int l, int r, int k, long n){ while(true){ int mid = (l + ((r - l) / 2));  long sum2 = ((((long)(mid)+k * (long)((k - mid) + 1)) / 2) - (long)(k - mid)); if ( ((l >= r) || (sum2 == n))) {return mid;} else if ( (sum2 > n)) {l = (mid + 1); } else if ( (sum2 < n)) {r = mid; } }} }
5	public class ProblemA{ private final BufferedReader in ; private final PrintStream out ; private StringTokenizer tok = new StringTokenizer(""); private String nextLine = null; public static void main( String[] args)throws Exception { new ProblemA(); } private ProblemA()throws Exception{ in = new BufferedReader(new InputStreamReader(System.in)); out = System.out; start(); end(); } private int nextInt(){ return Integer.parseInt(nextWord());} private String nextWord(){ if ( tok.hasMoreTokens()) {return tok.nextToken();} else {while(!tok.hasMoreTokens()){try{nextLine = in.readLine(); if ( (nextLine == null)) {return null;} else {tok = new StringTokenizer(nextLine); } }catch (IOException ex){ Logger.getLogger(ProblemA.class.getName()).log(Level.SEVERE,null,ex); } }return tok.nextToken();}} private void start(){ int n = nextInt();  int[] a = new int[n];  boolean allOne = true; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); if ( (a[i] != 1)) {allOne = false; } }Arrays.sort(a); int[] res = new int[n]; res[0] = 1; for ( int i = 1;(i < n);i++) {res[i] = a[(i - 1)]; }if ( allOne) {for ( int i = 0;(i < (n - 1));i++) {out.print((a[i] + " ")); }out.print(2); } else {for ( int i = 0;(i < n);i++) {out.print((res[i] + " ")); }}} private void end(){ out.close(); } }
1	public class HamstersAndTigers{ public static void main( String[] args){ Scanner sc = new Scanner(new BufferedInputStream(System.in));  int numAnimals = sc.nextInt();  String positions = sc.next();  int numTigers = 0;  int numHamsters = 0; for ( int i = 0;(i < positions.length());i++) {if ( (positions.charAt(i) == 'T')) {numTigers++; } else {numHamsters++; }} int minDifference = Integer.MAX_VALUE;  StringBuilder tigerChars = new StringBuilder(1000);  StringBuilder hamsterChars = new StringBuilder(1000); for ( int i = 0;(i < numHamsters);i++) {hamsterChars.append('H'); } StringBuilder remainingTigerChars = new StringBuilder(1000); for ( int i = 0;(i < numTigers);i++) {remainingTigerChars.append('T'); }for ( int i = 0;(i <= numTigers);i++) { StringBuilder generated = new StringBuilder(); generated.append(tigerChars); generated.append(hamsterChars); generated.append(remainingTigerChars); if ( (remainingTigerChars.length() >= 1)) {remainingTigerChars.deleteCharAt((remainingTigerChars.length() - 1)); } tigerChars.append('T'); int diffCount = stringDiffCount(positions,generated.toString()); if ( (diffCount < minDifference)) {minDifference = diffCount; } }hamsterChars = new StringBuilder(1000); tigerChars = new StringBuilder(1000); for ( int i = 0;(i < numTigers);i++) {tigerChars.append('T'); } StringBuilder remainingHamsterChars = new StringBuilder(1000); for ( int i = 0;(i < numHamsters);i++) {remainingHamsterChars.append('H'); }for ( int i = 0;(i <= numHamsters);i++) { StringBuilder generated = new StringBuilder(); generated.append(hamsterChars); generated.append(tigerChars); generated.append(remainingHamsterChars); if ( (remainingHamsterChars.length() >= 1)) {remainingHamsterChars.deleteCharAt((remainingHamsterChars.length() - 1)); } hamsterChars.append('H'); int diffCount = stringDiffCount(positions,generated.toString()); if ( (diffCount < minDifference)) {minDifference = diffCount; } }System.out.println((minDifference / 2)); } static private int stringDiffCount( String strOne, String strTwo){ int diffCount = 0; for ( int i = 0;(i < strOne.length());i++) {if ( (strOne.charAt(i) != strTwo.charAt(i))) {diffCount++; } }return diffCount;} }
2	public class Contest176B{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  long n = sc.nextLong();  int k = sc.nextInt(); if ( ((((((long)k * (long)(k + 1)) / 2) - 1) - (k - 2)) < n)) {System.out.println(-1); return ;} if ( (n == 1)) {System.out.println(0); return ;} if ( (n <= k)) {System.out.println(1); return ;} int ans = rek(2,k,n,k); System.out.println(ans); } static private int rek( int s, int e, long n, int k){ if ( (s == e)) {return ((k - s) + 1);} if ( ((s + 1) == e)) {if ( (sum(e,k) >= n)) return ((k - e) + 1); return ((k - s) + 1);} int m = ((s + e) / 2);  long ans = sum(m,k); if ( (ans == n)) return ((k - m) + 1); if ( (ans < n)) return rek(s,(m - 1),n,k); else return rek(m,e,n,k);} static private long sum( int a, int b){ long sum1 = (((long)a * (long)(a - 1)) / 2);  long sum2 = (((long)b * (long)(b + 1)) / 2);  int numelement = ((b - a) + 1); return ((sum2 - sum1) - (numelement - 1));} }
2	public class Problem{ public static void main( String[] args)throws Exception { Scanner input = new Scanner(System.in);  int side = (input.nextInt() - 1);  int x = (input.nextInt() - 1);  int y = (input.nextInt() - 1);  long target = input.nextLong();  int[] to_sides = {y,(side - x),(side - y),x};  int[] to_corners = {((y + 1) + ((side - x) + 1)),(((side - x) + 1) + ((side - y) + 1)),(((side - y) + 1) + (x + 1)),((x + 1) + (y + 1))};  int min = Math.min(Math.min(y,x),Math.min((side - x),(side - y)));  int[] after_pass = {1,1,1,1};  int[] corner_share = {1,1,1,1};  int steps = 0,i ;  long init = 1;  int grown = 4; while((init < target)){init += grown; steps++; if ( (steps >= min)) {for ( i = 0;(i < 4);i++) {if ( (steps > to_sides[i])) {init -= after_pass[i]; after_pass[i] += 2; } if ( (steps >= to_corners[i])) {init += corner_share[i]++; } }} grown += 4; }System.out.println(steps); } }
4	public class C{ Scanner in ; PrintWriter out ; String INPUT = ""; void solve(){ int n = ni();  int m = ni();  int k = ni();  int[][] f = new int[k][2]; for ( int i = 0;(i < k);i++) {f[i][0] = (ni() - 1); f[i][1] = (ni() - 1); } int mx = -1;  int resx = 0;  int resy = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int min = Integer.MAX_VALUE; for ( int l = 0;(l < k);l++) {min = Math.min(min,(Math.abs((f[l][0] - i)) + Math.abs((f[l][1] - j)))); }if ( (min > mx)) {mx = min; resx = i; resy = j; } }}out.println((((resx + 1) + " ") + (resy + 1))); } void run()throws Exception { in = (INPUT.isEmpty()?new Scanner(new File("input.txt")):new Scanner(INPUT)); out = (INPUT.isEmpty()?new PrintWriter("output.txt"):new PrintWriter(System.out)); solve(); out.flush(); } public static void main( String[] args)throws Exception { new C().run(); } int ni(){ return Integer.parseInt(in.next());} }
5	public class CottageVillage{ public static void main( String... args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int k = sc.nextInt();  TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>(); while((n-- > 0)){tm.put(sc.nextInt(),sc.nextInt()); } int cnt = 2,x = 0,a = 0;  double diff = 0; for ( Map.Entry<Integer,Integer> e :tm.entrySet()) {if ( ((x != 0) || (a != 0))) {diff = Math.abs((((e.getKey() - x) - (e.getValue() * 0.5)) - (a * 0.5))); if ( ((diff - k) > 0)) cnt += 2; else if ( ((diff - k) == 0)) cnt++; } x = e.getKey(); a = e.getValue(); }System.out.println(cnt); } }
5	public class Main implements Runnable{ private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; private Random rnd ; private void solve()throws IOException { int n = nextInt();  int[] a = new int[n];  int max = 0; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); if ( (a[i] > a[max])) max = i; } int value = 1; if ( (a[max] == 1)) value = 2; a[max] = value; Arrays.sort(a); for ( int i = 0;(i < n);i++) {out.print(a[i]); out.print(' '); }} public static void main( String[] args){ new Main().run(); } public void run(){ try{try{in = new BufferedReader(new FileReader("INPUT.TXT")); out = new PrintWriter(new FileWriter("OUTPUT.TXT")); }catch (FileNotFoundException e){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } st = null; rnd = new Random(); solve(); out.close(); }catch (IOException e){ e.printStackTrace(); } } private String nextToken()throws IOException,NullPointerException { while(((st == null) || !st.hasMoreTokens())){st = new StringTokenizer(in.readLine()); }return st.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
4	public class PracticeProblem{ public static class FastReader{ BufferedReader br ; StringTokenizer st ; public FastReader()throws FileNotFoundException{ br = new BufferedReader(new FileReader(new File("input.txt"))); } 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());} } public static FastReader in ; public static PrintWriter out ; public static final int INF = Integer.MAX_VALUE; public static int n ,m ; public static final int[] dr = {-1,0,0,+1}; public static final int[] dc = {0,-1,+1,0}; public static void main( String[] args)throws FileNotFoundException { in = new FastReader(); out = new PrintWriter(new File("output.txt")); solve(); out.close(); } static private void solve(){ n = in.nextInt(); m = in.nextInt(); int k = in.nextInt();  int[][] timeToBurn = new int[n][m]; for ( int i = 0;(i < n);i++) Arrays.fill(timeToBurn[i],INF); for ( int i = 0;(i < k);i++) { int r = (in.nextInt() - 1);  int c = (in.nextInt() - 1); for ( int j = 0;(j < n);j++) {for ( int l = 0;(l < m);l++) {timeToBurn[j][l] = min(timeToBurn[j][l],(abs((r - j)) + abs((c - l)))); }}} int max = -1;  Point p = null; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (timeToBurn[i][j] > max)) {max = timeToBurn[i][j]; p = new Point(i,j); } }}out.println((((p.x + 1) + " ") + (p.y + 1))); } }
1	public class Main implements Runnable{ public InputReader in ; public PrintWriter out ; public void solve()throws Exception { int N = in.nextInt();  int[] houses = new int[N];  boolean[] exist = new boolean[52]; for ( int i = 0;(i < N);i++) { char c = in.nextChar(); if ( (('a' <= c) && (c <= 'z'))) {houses[i] = (26 + (c - 'a')); } else {houses[i] = (c - 'A'); }exist[houses[i]] = true; } int[][] pokemons = new int[N][52]; pokemons[0][houses[0]] = 1; for ( int i = 1;(i < N);i++) {System.arraycopy(pokemons[(i - 1)],0,pokemons[i],0,pokemons[i].length); pokemons[i][houses[i]]++; } int uniques = 0; for ( boolean bool :exist) if ( bool) uniques++; if ( (uniques == 1)) {out.print(1); return ;} int last_variant = -1; for ( int i = 0;(i < (N - 1));i++) {if ( (pokemons[i][houses[i]] == pokemons[(N - 1)][houses[i]])) {last_variant = i; break;} } int minimum = N; for ( int i = 0;(i <= last_variant);i++) {if ( (houses[i] == houses[(i + 1)])) continue; int low = (i + 1);  int high = (N - 1); while((low < high)){ int mid = ((low + high) / 2);  boolean allPresent = true; for ( int j = 0;(j < 52);j++) {if ( (((j != houses[i]) && exist[j]) && (pokemons[mid][j] == pokemons[i][j]))) {allPresent = false; break;} }if ( allPresent) {high = mid; } else {low = (mid + 1); }}minimum = min(minimum,((low - i) + 1)); }out.print(minimum); } static int min( int a, int b){ return ((a < b)?a:b);} static long min( long a, long b){ return ((a < b)?a:b);} public static void main( String[] args){ new Thread(null,new Main(),"Main",(1 << 28)).start(); } static boolean OJ = (System.getProperty("ONLINE_JUDGE") != null); @SuppressWarnings({"Duplicates","unused"}) static class InputReader{ private InputStream stream ; private byte[] buf = new byte[2048]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader(){ this.stream = System.in; } public InputReader( InputStream stream){ this.stream = stream; } public InputReader( SpaceCharFilter filter){ this.stream = System.in; this.filter = filter; } public InputReader( InputStream stream, SpaceCharFilter filter){ this.stream = stream; this.filter = filter; } public int read(){ if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public char nextChar(){ int c = read(); while(isSpaceChar(c))c = read(); return (char)c;} public int nextInt(){ int c = read(); while(isSpaceChar(c))c = read(); boolean negative = false; if ( (c == '-')) {negative = true; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (negative?-res:res);} public final long nextLong(){ int c = read(); while(isSpaceChar(c)){c = read(); } boolean negative = false; if ( (c == '-')) {negative = true; c = read(); } long res = 0; do {res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (negative?-res:res);} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public boolean isEndChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return ((((c == '\n') || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
4	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[] = r.readLine().split("\\s+");  int n = Integer.parseInt(s[0]);  int m = Integer.parseInt(s[1]);  int k = Integer.parseInt(r.readLine());  int[][] a = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) a[i][j] = Integer.MAX_VALUE; }assert ((k >= 1) && (k < (n * m))); int max = 0;  StringTokenizer st = new StringTokenizer(r.readLine()); assert (st.countTokens() == k); for ( ;(k > 0);k--) { int x = (Integer.parseInt(st.nextToken()) - 1);  int y = (Integer.parseInt(st.nextToken()) - 1); assert ((((x >= 1) && (x <= n)) && (y >= 1)) && (y <= n)); for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int d = (Math.abs((i - x)) + Math.abs((j - y))); if ( (a[i][j] > d)) a[i][j] = d; if ( ((k == 1) && (a[i][j] > max))) max = a[i][j]; }}}for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (a[i][j] == max)) {System.out.println((((i + 1) + " ") + (j + 1))); return ;} }}} }
1	public class Main{ public static void main( String[] args){ new Main().run(); } Scanner sc = new Scanner(System.in); void run(){ int n = sc.nextInt();  char[] cs = sc.next().toCharArray();  int h = 0; for ( int i = 0;(i < n);i++) if ( (cs[i] == 'H')) h++;  int res = n; for ( int i = 0;(i < n);i++) { int val = 0; for ( int j = 0;(j < h);j++) if ( (cs[((i + j) % n)] == 'T')) val++; res = min(res,val); }System.out.println(res); } }
2	public class ProblemB{ InputReader in ; PrintWriter out ; void solve(){ int n = in.nextInt();  int x = in.nextInt();  int y = in.nextInt();  int c = in.nextInt();  int cur = 1; for ( int k = 1;(k <= c);k++) {if ( (cur >= c)) {out.println((k - 1)); return ;} int iLess = (n - x);  int iMore = ((y + k) - n); if ( (iLess > k)) iLess = k; if ( (iMore < 0)) iMore = 0;  int add = ((iLess - iMore) + 1); if ( (add < 0)) add = 0; cur += add; iLess = (n - x); iMore = ((1 + k) - y); if ( (iLess > k)) iLess = k; if ( (iMore < 0)) iMore = 0; add = ((iLess - iMore) + 1); if ( (add < 0)) add = 0; cur += add; iLess = (x - 1); iMore = ((1 + k) - y); if ( (iLess > k)) iLess = k; if ( (iMore < 0)) iMore = 0; add = ((iLess - iMore) + 1); if ( (add < 0)) add = 0; cur += add; iLess = (x - 1); iMore = ((y + k) - n); if ( (iLess > k)) iLess = k; if ( (iMore < 0)) iMore = 0; add = ((iLess - iMore) + 1); if ( (add < 0)) add = 0; cur += add; if ( ((x + k) <= n)) cur--; if ( ((y - k) >= 1)) cur--; if ( ((x - k) >= 1)) cur--; if ( ((y + k) <= n)) cur--; }} ProblemB(){ boolean oj = (System.getProperty("ONLINE_JUDGE") != null); try{if ( oj) {in = new InputReader(System.in); out = new PrintWriter(System.out); } else { Writer w = new FileWriter("output.txt"); in = new InputReader(new FileReader("input.txt")); out = new PrintWriter(w); } }catch (Exception e){ throw (new RuntimeException(e));} solve(); out.close(); } public static void main( String[] args){ new ProblemB(); } } class InputReader{ private BufferedReader reader ; private StringTokenizer tokenizer ; public InputReader( InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public InputReader( FileReader fr){ reader = new BufferedReader(fr); 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());} }
0	public class Main{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt(); out.println((n + " 0 0")); in.close(); out.close(); } }
2	public class B{ public static void main( String[] args)throws NumberFormatException,IOException { Scanner sc = new Scanner(System.in);  long n = sc.nextLong(),k = sc.nextLong(); if ( (n == 1)) {System.out.println(0); return ;} if ( (n <= k)) {System.out.println(1); return ;} long seg = ((((k + 1) * k) / 2) - 1); seg += (2 - k); if ( (seg < n)) {System.out.println(-1); return ;} long s = 1,f = k;  long mid = ((s + f) / 2); while(((s + 1) < f)){ long seg_m = ((((mid + k) - 1) * (k - mid)) / 2); if ( (seg_m >= (n - 1))) {s = mid; } else f = mid; mid = ((s + f) / 2); }System.out.println((k - s)); } }
4	public class Main{ public static void main( String[] args)throws IOException { Scanner c = new Scanner(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt"));  int N = c.nextInt();  int M = c.nextInt();  int A[][] = new int[N][M]; for ( int i = 0;(i < N);i++) Arrays.fill(A[i],(Integer.MAX_VALUE / 100)); int K = c.nextInt(); for ( int i = 0;(i < K);i++) { int x = (c.nextInt() - 1);  int y = (c.nextInt() - 1); for ( int i1 = 0;(i1 < N);i1++) {for ( int j1 = 0;(j1 < M);j1++) A[i1][j1] = Math.min(A[i1][j1],(Math.abs((i1 - x)) + Math.abs((j1 - y)))); }} int maxi = 0;  int maxj = 0; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < M);j++) {if ( (A[i][j] > A[maxi][maxj])) {maxi = i; maxj = j; } }}out.println((((maxi + 1) + " ") + (maxj + 1))); out.close(); } }
0	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());  StringTokenizer tok = new StringTokenizer(br.readLine());  int ax = Integer.parseInt(tok.nextToken());  int ay = Integer.parseInt(tok.nextToken()); tok = new StringTokenizer(br.readLine()); int bx = Integer.parseInt(tok.nextToken());  int by = Integer.parseInt(tok.nextToken()); tok = new StringTokenizer(br.readLine()); int cx = Integer.parseInt(tok.nextToken());  int cy = Integer.parseInt(tok.nextToken());  boolean ans = (((((((bx < ax) && (cx < ax)) && (by < ay)) && (cy < ay)) || ((((bx < ax) && (cx < ax)) && (by > ay)) && (cy > ay))) || ((((bx > ax) && (cx > ax)) && (by < ay)) && (cy < ay))) || ((((bx > ax) && (cx > ax)) && (by > ay)) && (cy > ay))); System.out.print((ans?"YES":"NO")); } }
2	public class PipelineRedo{ public static void main( String[] args){ FastScanner sc = new FastScanner();  long n = (sc.nextLong() - 1);  long k = (sc.nextInt() - 1); if ( (n == 0)) {System.out.println(0); return ;} else if ( (n <= k)) {System.out.println(1); return ;} else if ( (n > ((k * (k + 1)) / 2))) {System.out.println(-1); return ;} long rightSum = ((k * (k + 1)) / 2);  long lo = 1;  long hi = k; while((lo < hi)){ long mid = (lo + (((hi - lo) + 1) / 2));  long val = (rightSum - ((mid * (mid - 1)) / 2)); if ( (val <= n)) {hi = (mid - 1); } else {lo = mid; }}if ( ((rightSum - (((lo + 1) * lo) / 2)) == n)) {System.out.println(((k - (lo + 1)) + 1)); } else {System.out.println((1 + ((k - (lo + 1)) + 1))); }} public static 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();} int nextInt(){ return Integer.parseInt(nextToken());} long nextLong(){ return Long.parseLong(nextToken());} } }
5	public class Solution{ private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; static class House implements Comparable<House>{ int x ,a ; public House( int x, int a){ this.x = x; this.a = a; } } void solve()throws IOException { int n = nextInt();  int t = nextInt();  House[] hs = new House[n]; for ( int i = 0;(i < n);++i) {hs[i] = new House(nextInt(),nextInt()); }Arrays.sort(hs); int ans = 2; for ( int i = 0;(i < (n - 1));++i) {if ( (((hs[i].a + hs[(i + 1)].a) + (2 * t)) < (2 * (hs[(i + 1)].x - hs[i].x)))) {ans += 2; } else if ( (((hs[i].a + hs[(i + 1)].a) + (2 * t)) == (2 * (hs[(i + 1)].x - hs[i].x)))) {ans++; } }out.println(ans); } Solution()throws IOException{ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); eat(""); solve(); in.close(); out.close(); } private void eat( String str){ st = new StringTokenizer(str); } String next()throws IOException { while(!st.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) {return null;} eat(line); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args)throws IOException { new Solution(); } }
1	public class A25{ static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(System.out); static int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} public static void main( String[] args)throws Exception { int n = nextInt();  int[] c = new int[2];  int[] f = new int[2]; for ( int i = 0;(i < n);i++) { int x = nextInt(),p = (x % 2); if ( (c[p]++ == 0)) f[p] = (i + 1); }out.println(((c[0] == 1)?f[0]:f[1])); out.flush(); } }
5	public class ProblemA_15{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { if ( ONLINE_JUDGE) {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"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new ProblemA_15().run(); } public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println(("Time = " + (t2 - t1))); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } void solve()throws IOException { int n = readInt();  int t = readInt();  Point[] a = new Point[n]; for ( int i = 0;(i < n);i++) {a[i] = new Point(readInt(),readInt()); } int count = 2; Arrays.sort(a,new Comparator<Point>(){}); for ( int i = 1;(i < n);i++) { double li = (a[(i - 1)].x + ((double)a[(i - 1)].y / 2));  double ri = (a[i].x - ((double)a[i].y / 2)); if ( ((ri - li) > t)) {count += 2; } if ( ((ri - li) == t)) {count++; } }out.print(count); } }
4	public class Main{ public static void main( String[] args)throws IOException { PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));  Scanner in = new Scanner(new File("input.txt"));  int n ,m ,k ; n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); Vector<Integer> vec = new Vector<Integer>();  Vector<Integer> temp = new Vector<Integer>();  boolean[][] mas = new boolean[n][m];  long time = System.currentTimeMillis(); for ( int i = 0;(i < k);i++) {vec.add((in.nextInt() - 1)); vec.add((in.nextInt() - 1)); mas[vec.get((vec.size() - 2))][vec.get((vec.size() - 1))] = true; } int x ,y ; x = y = 0; while((vec.size() != 0)){for ( int i = 0;(i < vec.size());i += 2) {x = vec.get(i); y = vec.get((i + 1)); if ( ((x > 0) && !mas[(x - 1)][y])) {temp.add((x - 1)); temp.add(y); mas[(x - 1)][y] = true; } if ( ((x < (n - 1)) && !mas[(x + 1)][y])) {temp.add((x + 1)); temp.add(y); mas[(x + 1)][y] = true; } if ( ((y > 0) && !mas[x][(y - 1)])) {temp.add(x); temp.add((y - 1)); mas[x][(y - 1)] = true; } if ( ((y < (m - 1)) && !mas[x][(y + 1)])) {temp.add(x); temp.add((y + 1)); mas[x][(y + 1)] = true; } }vec = temp; temp = new Vector<Integer>(); }pw.println((((x + 1) + " ") + (y + 1))); System.out.println((System.currentTimeMillis() - time)); in.close(); pw.close(); } }
2	public class B{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  long n = sc.nextLong();  long k = sc.nextLong(); if ( (n == 1)) {System.out.println(0); } else if ( (n <= k)) {System.out.println(1); } else {n--; k--; BigInteger K = BigInteger.valueOf(k);  BigInteger N = BigInteger.valueOf(n);  BigInteger high = BigInteger.valueOf((k + 1));  BigInteger low = BigInteger.valueOf(1);  BigInteger mid ; while((low.compareTo(high) < 0)){mid = low.add(high.subtract(low).shiftRight(1)); BigInteger elemCnt = K.subtract(mid).add(BigInteger.ONE);  BigInteger sum = elemCnt.multiply(mid.shiftLeft(1).add(elemCnt.subtract(BigInteger.ONE))).shiftRight(1); if ( (sum.compareTo(N) > 0)) {low = mid.add(BigInteger.valueOf(1)); } else {high = mid; }} BigInteger elemCnt = K.subtract(low).add(BigInteger.ONE);  BigInteger sum = elemCnt.multiply(low.shiftLeft(1).add(elemCnt.subtract(BigInteger.ONE))).shiftRight(1);  BigInteger rem = N.subtract(sum); if ( rem.equals(BigInteger.ZERO)) {System.out.println(elemCnt); } else if ( (rem.compareTo(low) < 0)) {System.out.println(elemCnt.add(BigInteger.ONE)); } else {System.out.println(-1); }}} }
2	public class B{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  long n = sc.nextLong();  long k = sc.nextLong(); if ( (((((k - 1) * k) / 2) + 1) < n)) {System.out.println(-1); return ;} long left = 0;  long right = k; while((left < right)){ long m = ((left + right) / 2); if ( (((((k * (k - 1)) / 2) - (((k - m) * ((k - m) - 1)) / 2)) + 1) < n)) left = (m + 1); else right = m; }System.out.println(left); } }
2	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);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, Scanner in, PrintWriter out){ long n = in.nextLong();  long k = in.nextInt(); if ( (n == 1)) {out.println(0); return ;} long max = (((k * (k - 1)) / 2) + 1); if ( (max < n)) {out.println("-1"); return ;} long low = 1,high = (k - 1);  long ans = (k - 1); while((low <= high)){ long mid = ((low + high) / 2);  long val = ((((mid * mid) - (mid * ((2 * k) - 1))) + (2 * n)) - 2); if ( (val > 0)) {low = (mid + 1); } else {ans = mid; high = (mid - 1); }}out.println(ans); } }
3	public class C{ static int MOD = 1_000_000_007; public static void main( String[] args){ MyScanner in = new MyScanner();  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt();  char prev = ' ';  int[][] dp = new int[(n + 1)][(n + 2)]; dp[0][0] = 1; for ( int i = 0;(i < n);++i) { char ch = in.next().charAt(0); if ( (prev == 's')) { int sum = 0; for ( int j = n;(j >= 0);--j) {sum = ((sum + dp[(i - 1)][j]) % MOD); dp[i][j] = sum; }} else if ( (prev == 'f')) {for ( int j = 0;(j < n);++j) {dp[i][(j + 1)] = dp[(i - 1)][j]; }} prev = ch; } int result = 0; for ( int i = 0;(i <= n);++i) {result = ((result + dp[(n - 1)][i]) % MOD); }out.println(result); out.close(); } 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());} } }
1	public class a implements Runnable{ private void solve()throws IOException { int n = nextInt();  int oddcnt = 0,evencnt = 0;  int odd = 0,even = 0; for ( int i = 0;(i < n);i++) { int a = nextInt(); if ( ((a % 2) == 0)) {even = (i + 1); evencnt++; } else {odd = (i + 1); oddcnt++; }}if ( (oddcnt == 1)) {System.out.println(odd); } else {System.out.println(even); }} public static void main( String[] args){ new Thread(new a()).start(); } BufferedReader br ; StringTokenizer st ; PrintWriter out ; boolean eof = false; String nextToken(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ eof = true; return "0";} }return st.nextToken();} int nextInt(){ return Integer.parseInt(nextToken());} }
1	public class A{ public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(br.readLine());  StringTokenizer st = new StringTokenizer(br.readLine());  int[] list = new int[n]; for ( int i = 0;(i < list.length);i++) list[i] = Integer.parseInt(st.nextToken()); int odd = 0;  int even = 0; for ( int x :list) if ( ((x % 2) == 1)) {odd++; } else {even++; }for ( int i = 1;(i <= list.length);i++) {if ( (((list[(i - 1)] % 2) == 1) && (odd == 1))) {System.out.println(i); return ;} else if ( (((list[(i - 1)] % 2) == 0) && (even == 1))) {System.out.println(i); return ;} }} }
4	public class Main{ static boolean used[][] ; static int n ; static int m ; public static void main( String[] args)throws IOException { br = new BufferedReader(new FileReader("input.txt")); PrintWriter out = new PrintWriter("output.txt"); n = nextInt(); m = nextInt(); int k = nextInt(); used = new boolean[n][m]; Deque<point> deq = new ArrayDeque<>(); for ( int i = 0;(i < k);i++) {deq.addLast(new point((nextInt() - 1),(nextInt() - 1))); used[deq.peekLast().x][deq.peekLast().y] = true; } point last = new point(0,0); while(!deq.isEmpty()){ point v = deq.pollFirst();  int x = v.x;  int y = v.y; if ( checker(x,(y + 1))) {last = new point(x,(y + 1)); deq.addLast(new point(x,(y + 1))); used[x][(y + 1)] = true; } if ( checker(x,(y - 1))) {last = new point(x,(y - 1)); deq.addLast(new point(x,(y - 1))); used[x][(y - 1)] = true; } if ( checker((x + 1),y)) {last = new point((x + 1),y); deq.addLast(new point((x + 1),y)); used[(x + 1)][y] = true; } if ( checker((x - 1),y)) {last = new point((x - 1),y); deq.addLast(new point((x - 1),y)); used[(x - 1)][y] = true; } }out.println((((last.x + 1) + " ") + (last.y + 1))); out.close(); } static boolean checker( int x, int y){ if ( (((((x < n) && (y < m)) && (x >= 0)) && (y >= 0)) && !used[x][y])) return true; return false;} static StringTokenizer st = new StringTokenizer(""); static BufferedReader br ; static String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} static int nextInt()throws IOException { return Integer.parseInt(next());} } class point{ int x ,y ; public point( int x, int y){ this.x = x; this.y = y; } }
3	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 = false;  int p = 1000000007;  long ans = 0; for ( int x = 0;(x < n);x++) { String next = sc.nextLine(); if ( next.equals("f")) {if ( justf) {listCount.add(0); } else {for ( int i = 1;(i < listCount.size());i++) { int sum = ((listCount.get((i - 1)) + listCount.get(i)) % p); listCount.set(i,sum); }listCount.add(0); }justf = true; } else {if ( justf) {justf = false; } else {for ( int i = 1;(i < listCount.size());i++) { int sum = ((listCount.get((i - 1)) + listCount.get(i)) % p); listCount.set(i,sum); }}}}for ( int i = 0;(i < listCount.size());i++) {ans += listCount.get(i); }System.out.print((ans % p)); } }
5	public class TaskA{ void Run()throws IOException { int n = ReadInt();  int[] arr = new int[n]; for ( int i = 0;(i < n);++i) arr[i] = ReadInt(); Arrays.sort(arr); boolean one = true; for ( int x :arr) if ( (x != 1)) {one = false; break;} if ( one) {for ( int i = 1;(i < n);++i) output.print("1 "); output.print("2"); return ;} int prev = 1; for ( int x :arr) if ( (x == prev)) {output.print(prev); output.print(" "); } else {output.print(prev); output.print(" "); prev = x; }} public static void main( String[] args)throws IOException { boolean oj = (System.getProperty("ONLINE_JUDGE") != null);  Reader reader ; reader = (oj?new InputStreamReader(System.in):new FileReader("input.txt")); input = new BufferedReader(reader); Writer writer = new OutputStreamWriter(System.out); writer = new BufferedWriter(writer); output = new PrintWriter(writer); new TaskA().Run(); output.close(); } static int ReadInt()throws IOException { return Integer.parseInt(ReadString());} static String ReadString()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens()))tokenizer = new StringTokenizer(input.readLine()); return tokenizer.nextToken();} static StringTokenizer tokenizer ; static BufferedReader input ; static PrintWriter output ; }
4	public class cf35c{ public static void main( String[] args)throws Exception { Scanner in = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt"));  int[] dx = {0,0,1,-1};  int[] dy = {1,-1,0,0};  int n = in.nextInt();  int m = in.nextInt();  int[][] seen = new int[n][m]; for ( int i = 0;(i < n);i++) Arrays.fill(seen[i],-1); Queue<Integer> q = new LinkedList<Integer>();  int k = in.nextInt(); for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); q.add(x); q.add(y); q.add(0); seen[x][y] = 0; }while(!q.isEmpty()){ int x = q.poll();  int y = q.poll();  int t = q.poll(); for ( int i = 0;(i < dx.length);i++) { int nx = (x + dx[i]);  int ny = (y + dy[i]); if ( ((((nx < 0) || (nx >= n)) || (ny < 0)) || (ny >= m))) continue; if ( (seen[nx][ny] != -1)) continue; seen[nx][ny] = (t + 1); q.add(nx); q.add(ny); q.add((t + 1)); }} int best = -1,x = 0,y = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (seen[i][j] > best)) {best = seen[i][j]; x = (i + 1); y = (j + 1); } out.println(((x + " ") + y)); out.close(); } }
5	public class A135{ public static void main( String[] args)throws Exception { BufferedReader r = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(r.readLine());  int[] ar = new int[n];  StringTokenizer st = new StringTokenizer(r.readLine()); for ( int x = 0;(x < n);x++) {ar[x] = Integer.parseInt(st.nextToken()); }Arrays.sort(ar); if ( (n == 1)) {System.out.println(((ar[0] == 1)?"2":"1")); return ;} if ( (ar[(n - 1)] == 1)) {ar[(n - 2)] = 2; } System.out.print("1"); for ( int x = 0;(x < (n - 1));x++) {System.out.print((" " + ar[x])); }System.out.println(); } }
3	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{ final int P = ((int)1e9 + 7); int n ; char[] commands ; int[][] memo ; public void solve( int testNumber, InputReader in, PrintWriter out){ n = in.nextInt(); commands = new char[n]; memo = new int[n][12345]; for ( int i = 0;(i < n);i++) {commands[i] = in.next().charAt(0); for ( int j = 0;(j < 12345);j++) {memo[i][j] = -1; }}out.print(solve(1,0)); } int add( int a, int b){ return (((a % P) + (b % P)) % P);} int solve( int i, int indents){ if ( (i == n)) return 1; if ( (memo[i][indents] != -1)) return memo[i][indents]; int answer ; if ( (commands[(i - 1)] == 'f')) {answer = solve((i + 1),(indents + 1)); } else {if ( (indents == 0)) {answer = solve((i + 1),indents); } else {answer = add(solve(i,(indents - 1)),solve((i + 1),indents)); }}return memo[i][indents] = answer;} } static class InputReader{ private StringTokenizer tokenizer ; private BufferedReader reader ; public InputReader( InputStream inputStream){ reader = new BufferedReader(new InputStreamReader(inputStream)); } private void fillTokenizer(){ if ( ((tokenizer == null) || !tokenizer.hasMoreTokens())) {try{tokenizer = new StringTokenizer(reader.readLine()); }catch (Exception e){ throw (new RuntimeException(e));} } } public String next(){ fillTokenizer(); return tokenizer.nextToken();} public int nextInt(){ return Integer.parseInt(next());} } }
2	public class ehsan{ public static BigInteger f( BigInteger m, BigInteger n){ BigInteger s ,l ; s = n.multiply(m.add(BigInteger.valueOf(1))); l = m.multiply(m.add(BigInteger.valueOf(1))); l = l.divide(BigInteger.valueOf(2)); s = s.subtract(l); s = s.subtract(m); return s;} public static BigInteger bs( BigInteger a, BigInteger b, BigInteger n, BigInteger d){ BigInteger c ,e ; c = a.add(b); c = c.divide(BigInteger.valueOf(2)); e = f(c,n); if ( e.equals(d)) return c.add(BigInteger.valueOf(1)); if ( a.equals(b.add(BigInteger.valueOf(-1)))) return b.add(BigInteger.valueOf(1)); if ( (e.compareTo(d) > 0)) return bs(a,c,n,d); return bs(c,b,n,d);} public static void main( String[] args){ Scanner sc = new Scanner(System.in);  BigInteger bi1 = sc.nextBigInteger();  BigInteger bi2 = sc.nextBigInteger();  BigInteger i ,n = bi2;  BigInteger i2 = BigInteger.valueOf(1);  BigInteger sum = BigInteger.valueOf(0); if ( (bi1.compareTo(bi2) < 0)) {System.out.println(0); return ;} else if ( (bi1.compareTo(bi2) == 0)) {System.out.println(1); return ;} bi2 = n.multiply(n.add(BigInteger.valueOf(1))).subtract(n.subtract(BigInteger.valueOf(1))); if ( (bi1.compareTo(bi2) > 0)) System.out.println(-1); else {System.out.println(bs(BigInteger.valueOf(0),n.add(BigInteger.valueOf(-2)),n,bi1)); }} }
6	public class EdC{ static long[] mods = {1000000007,998244353,1000000009}; static long mod = mods[0]; public static MyScanner sc ; public static PrintWriter out ; static char[][] grid ; static int n ; static int t ; static int[][] dp ; static int[] times ; static int[] genre ; public static void main( String[] omkar)throws Exception { sc = new MyScanner(); out = new PrintWriter(System.out); n = sc.nextInt(); t = sc.nextInt(); times = new int[n]; genre = new int[n]; for ( int j = 0;(j < n);j++) {times[j] = sc.nextInt(); genre[j] = sc.nextInt(); }dp = new int[(1 << n)][4]; for ( int j = 0;(j < (1 << n));j++) Arrays.fill(dp[j],-1); for ( int j = 0;(j < (1 << n));j++) {letsgodp(j,1); letsgodp(j,2); letsgodp(j,3); } int ans = 0; for ( int j = 0;(j < (1 << n));j++) { int time = 0; for ( int k = 0;(k < n);k++) {if ( (((1 << k) & j) != 0)) {time += times[k]; } }if ( (time == t)) {ans += dp[j][1]; ans %= mod; ans += dp[j][2]; ans %= mod; ans += dp[j][3]; ans %= mod; } }out.println(ans); out.close(); } public static void letsgodp( int mask, int dg){ if ( (dp[mask][dg] != -1)) return ; dp[mask][dg] = 0; for ( int j = 0;(j < n);j++) {if ( ((((1 << j) & mask) != 0) && (genre[j] == dg))) { int submask = (mask - (1 << j));  int og1 = (((genre[j] + 1) > 3)?(genre[j] - 2):(genre[j] + 1));  int og2 = (((genre[j] + 2) > 3)?(genre[j] - 1):(genre[j] + 2)); if ( (submask != 0)) {letsgodp(submask,og1); letsgodp(submask,og2); dp[mask][dg] += (dp[submask][og1] + dp[submask][og2]); dp[mask][dg] %= mod; } else {dp[mask][dg] = 1; }} }} public static void sort( int[] array){ ArrayList<Integer> copy = new ArrayList<Integer>(); for ( int i :array) copy.add(i); Collections.sort(copy); for ( int i = 0;(i < array.length);i++) array[i] = copy.get(i); } static long power( long x, long y){ if ( (y == 0)) return 1; if ( ((y % 2) == 1)) return ((x * power(x,(y - 1))) % mod); return (power(((x * x) % mod),(y / 2)) % mod);} 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());} } }
4	public class Main{ public static int n ,m ; public static void main( String[] arg){ FastScanner scan = null;  PrintWriter out = null; try{scan = new FastScanner(new FileInputStream("input.txt")); out = new PrintWriter(new FileOutputStream("output.txt")); }catch (FileNotFoundException e){ scan = new FastScanner(System.in); out = new PrintWriter(System.out); } n = scan.nextInt(); m = scan.nextInt(); int k = scan.nextInt();  int[][] board = new int[(n + 1)][(m + 1)];  String[] ins = scan.nextLine().split(" ",-1);  List<Integer> ps = new ArrayList<Integer>(); for ( int i = 0;(i < (2 * k));i += 2) { int a = Integer.parseInt(ins[i]);  int b = Integer.parseInt(ins[(i + 1)]); board[a][b] = 1; ps.add(((a * 2001) + b)); } int retx = 1,rety = 1;  int[] dx = {0,1,0,-1};  int[] dy = {1,0,-1,0}; while(true){ boolean find = false;  List<Integer> ps2 = new ArrayList<Integer>(); for ( Integer p :ps) { int i = (p / 2001);  int j = (p % 2001); for ( int q = 0;(q < 4);q++) { int nx = (i + dx[q]);  int ny = (j + dy[q]); if ( (in(nx,ny) && (board[nx][ny] == 0))) {board[nx][ny] = 1; retx = nx; rety = ny; find = true; ps2.add(((nx * 2001) + ny)); } }board[i][j] = 2; }ps = ps2; if ( !find) break; }out.println(((retx + " ") + rety)); out.close(); } public static boolean in( int i, int j){ return (((1 <= i) && (i <= n)) && ((1 <= j) && (j <= m)));} static class FastScanner{ BufferedReader br ; StringTokenizer st ; FastScanner( InputStream is){ try{br = new BufferedReader(new InputStreamReader(is)); }catch (Exception e){ e.printStackTrace(); } } String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ return null;} }return st.nextToken();} String nextLine(){ try{return br.readLine(); }catch (Exception e){ return null;} } int nextInt(){ return Integer.parseInt(next());} } }
1	public class A{ static private StreamTokenizer in ; static private PrintWriter out ; static private int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} public static void main( String[] args)throws Exception { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); ArrayList<Integer> p = new ArrayList<Integer>();  ArrayList<Integer> o = new ArrayList<Integer>();  int n = nextInt(); for ( int i = 0;(i < n);i++) { int a = nextInt(); if ( ((a % 2) == 0)) p.add((i + 1)); else o.add((i + 1)); }if ( (p.size() < o.size())) out.println(p.get(0)); else out.println(o.get(0)); out.flush(); } }
3	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);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ static final long MODULO = (long)(1e9 + 7); public void solve( int testNumber, FastReader in, PrintWriter out){ int n = in.nextInt();  long[][] dp = new long[(n + 100)][(n + 100)]; dp[0][0] = 1; for ( int i = 0;(i < n);++i) { char current = in.nextCharacter(); if ( (current == 'f')) {for ( int j = 0;(j < n);++j) {dp[(i + 1)][(j + 1)] += dp[i][j]; dp[(i + 1)][(j + 1)] %= MODULO; }} else { long runningSum = 0; for ( int j = n;(j >= 0);--j) {runningSum += dp[i][j]; runningSum %= MODULO; dp[(i + 1)][j] += runningSum; dp[(i + 1)][j] %= MODULO; }}}out.println(dp[n][0]); } } static class FastReader{ private InputStream stream ; private byte[] buf = new byte[8192]; private int curChar ; private int pnumChars ; public FastReader( InputStream stream){ this.stream = stream; } private int pread(){ if ( (pnumChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= pnumChars)) {curChar = 0; try{pnumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (pnumChars <= 0)) {return -1;} } return buf[curChar++];} public int nextInt(){ int c = pread(); while(isSpaceChar(c))c = pread(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = pread(); } int res = 0; do {if ( (c == ',')) {c = pread(); } if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = pread(); }while(!isSpaceChar(c));return (res * sgn);} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char nextCharacter(){ int c = pread(); while(isSpaceChar(c))c = pread(); return (char)c;} } }
3	public final class PythonIndentation{ public static void main( String[] args){ new PythonIndentation(System.in,System.out); } static class Solver implements Runnable{ static final int MOD = ((int)1e9 + 7); int n ; char[] arr ; long[][] dp ; BufferedReader in ; PrintWriter out ; void solve()throws IOException { n = Integer.parseInt(in.readLine()); arr = new char[n]; dp = new long[(n + 1)][(n + 1)]; for ( int i = 0;(i < n);i++) arr[i] = in.readLine().charAt(0); for ( int i = 0;(i <= n);i++) Arrays.fill(dp[i],-1); dp[0][0] = 1; if ( (arr[0] == 's')) out.println(find(1,0)); else out.println(find(1,1)); } long find( int curr, int backIndents){ if ( (backIndents < 0)) return 0; if ( (curr == n)) return 1; if ( (dp[curr][backIndents] != -1)) return dp[curr][backIndents]; long ans ; if ( (arr[curr] == 's')) {if ( (arr[(curr - 1)] == 'f')) ans = find((curr + 1),backIndents); else ans = CMath.mod((find((curr + 1),backIndents) + find(curr,(backIndents - 1))),MOD); } else {ans = find((curr + 1),(backIndents + 1)); if ( (arr[(curr - 1)] != 'f')) ans = CMath.mod((ans + find(curr,(backIndents - 1))),MOD); }return dp[curr][backIndents] = ans;} public Solver( BufferedReader in, PrintWriter out){ this.in = in; this.out = out; } } private PythonIndentation( InputStream inputStream, OutputStream outputStream){ BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));  PrintWriter out = new PrintWriter(outputStream);  Thread thread = new Thread(null,new Solver(in,out),"PythonIndentation",(1 << 29)); try{thread.start(); thread.join(); }catch (InterruptedException e){ e.printStackTrace(); } finally{try{in.close(); }catch (IOException e){ e.printStackTrace(); } out.flush(); out.close(); }} }
4	public class Watermelon{ static int[][] ans ; static int n ,m ; static boolean[][] vis ; public static void main( String[] args)throws IOException { Scanner sc = new Scanner(new File("input.txt"));  PrintWriter pw = new PrintWriter("output.txt");  int n = sc.nextInt(),m = sc.nextInt(),k = sc.nextInt();  Queue<Integer> pq = new ArrayDeque<>();  boolean[] vis = new boolean[(n * m)]; for ( int i = 0;(i < k);i++) { int r = (sc.nextInt() - 1),c = (sc.nextInt() - 1); pq.add(((m * r) + c)); vis[((m * r) + c)] = true; }sc.close(); int ans = 0; while((pq.size() != 0)){ int x = pq.remove(); ans = x; if ( ((n != 1) && ((x % n) == 0))) {if ( (((x + m) < (n * m)) && !vis[(x + m)])) {pq.add((x + m)); vis[(x + m)] = true; } if ( (((x - m) >= 0) && !vis[(x - m)])) {pq.add((x - m)); vis[(x - m)] = true; } if ( (((x + 1) < (n * m)) && !vis[(x + 1)])) {pq.add((x + 1)); vis[(x + 1)] = true; } } else if ( ((n != 1) && (((x + 1) % n) == 0))) {if ( (((x + m) < (n * m)) && !vis[(x + m)])) {pq.add((x + m)); vis[(x + m)] = true; } if ( (((x - m) >= 0) && !vis[(x - m)])) {pq.add((x - m)); vis[(x - m)] = true; } if ( (((x - 1) >= 0) && !vis[(x - 1)])) {pq.add((x - 1)); vis[(x - 1)] = true; } } else {if ( (((x + m) < (n * m)) && !vis[(x + m)])) {pq.add((x + m)); vis[(x + m)] = true; } if ( (((x - m) >= 0) && !vis[(x - m)])) {pq.add((x - m)); vis[(x - m)] = true; } if ( (((x - 1) >= 0) && !vis[(x - 1)])) {pq.add((x - 1)); vis[(x - 1)] = true; } if ( (((x + 1) < (n * m)) && !vis[(x + 1)])) {pq.add((x + 1)); vis[(x + 1)] = true; } }}pw.println(((((ans / m) + 1) + " ") + ((ans % m) + 1))); pw.close(); } }
1	public class Solution implements Runnable{ private BufferedReader br = null; private PrintWriter pw = null; private StringTokenizer stk = new StringTokenizer(""); public static void main( String[] args){ new Thread(new Solution()).run(); } public void run(){ br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); solver(); pw.close(); } private void nline(){ try{if ( !stk.hasMoreTokens()) stk = new StringTokenizer(br.readLine());  }catch (IOException e){ throw (new RuntimeException("KaVaBUnGO!!!",e));} } private String nstr(){ while(!stk.hasMoreTokens())nline(); return stk.nextToken();} private int ni(){ return Integer.valueOf(nstr());} private void solver(){ int n = ni();  ArrayList<Integer> ar = new ArrayList<Integer>();  int sum = 0; for ( int i = 0;(i < n);i++) {ar.add((ni() % 2)); sum += ar.get(i); } int flag = 0; if ( (sum == 1)) flag = 1; for ( int i = 0;(i < n);i++) if ( (ar.get(i) == flag)) System.out.println((i + 1)); } void exit(){ System.exit(0); } }
1	public class Solution{ public static void main( String[] args){ Scanner scanner = new Scanner(System.in);  int n = scanner.nextInt();  int[] arr = new int[n]; for ( int i = 0;(i < n);++i) {arr[i] = scanner.nextInt(); } boolean isOdd = false; if ( (((((arr[0] % 2) == 0) && ((arr[1] % 2) == 0)) || (((arr[0] % 2) == 0) && ((arr[2] % 2) == 0))) || (((arr[1] % 2) == 0) && ((arr[2] % 2) == 0)))) {isOdd = true; } if ( isOdd) {for ( int i = 0;(i < n);++i) {if ( ((arr[i] % 2) == 1)) {System.out.println((i + 1)); break;} }} else {for ( int i = 0;(i < n);++i) {if ( ((arr[i] % 2) == 0)) {System.out.println((i + 1)); break;} }}} }
3	public class PythonIndentation{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  boolean[] lst = new boolean[n]; for ( int i = 0;(i < n);i++) {lst[i] = (in.next()?false:true); }System.out.println(dp(lst)); } static long dp( boolean[] lst){ long[][] dp = new long[lst.length][lst.length]; dp[0][0] = 1; for ( int i = 1;(i < lst.length);i++) {for ( int j = 0;(j < lst.length);j++) {if ( lst[(i - 1)]) {if ( (j == 0)) dp[i][j] = 0; else dp[i][j] = dp[(i - 1)][(j - 1)]; } else {if ( (j == 0)) {for ( int k = 0;(k < lst.length);k++) dp[i][j] = ((dp[i][j] + dp[(i - 1)][k]) % 1000000007); } else dp[i][j] = ((dp[i][(j - 1)] - dp[(i - 1)][(j - 1)]) % 1000000007); }}} long ans = 0; for ( int i = 0;(i < lst.length);i++) {ans = ((ans + dp[(lst.length - 1)][i]) % 1000000007); }if ( (ans < 0)) ans = (ans + 1000000007); return ans;} }
2	public class JavaApplication4{ static long k ,n ,ans ; private static long binsearch( long l, long r){ if ( (l == r)) return l; long m = ((l + r) / 2);  long res = ((m * (((k + k) - m) + 1)) / 2); if ( (res >= n)) return binsearch(l,m); else return binsearch((m + 1),r);} public static void main( String[] args){ Scanner in = new Scanner(System.in); n = in.nextLong(); k = in.nextLong(); n--; k--; if ( (((k * (k + 1)) / 2) < n)) ans = -1; else ans = binsearch(0,k); System.out.println(ans); } }
4	public class C{ public static void main( String[] args)throws Exception { Scanner in = new Scanner(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt"));  int N = in.nextInt();  int M = in.nextInt();  int K = in.nextInt();  int[] X = new int[K],Y = new int[K]; for ( int i = 0;(i < K);i++) {X[i] = in.nextInt(); Y[i] = in.nextInt(); } int d = -1;  int a = -1;  int b = -1; for ( int i = 1;(i <= N);i++) for ( int j = 1;(j <= M);j++) { int h = Integer.MAX_VALUE; for ( int p = 0;(p < K);p++) h = Math.min(h,(Math.abs((i - X[p])) + Math.abs((j - Y[p])))); if ( (h > d)) {d = h; a = i; b = j; } }out.print(((a + " ") + b)); out.close(); } }
6	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);  TaskF solver = new TaskF(); solver.solve(1,in,out); out.close(); } static class TaskF{ public void solve( int testNumber, Scanner in, PrintWriter out){ int n = in.nextInt();  int m = in.nextInt();  int[][] graph = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) graph[i][j] = in.nextInt(); } int[][] mn1 = new int[n][n];  int[][] mn2 = new int[n][n]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) { int min_val = Integer.MAX_VALUE; for ( int k = 0;(k < m);k++) min_val = Math.min(min_val,Math.abs((graph[i][k] - graph[j][k]))); mn1[i][j] = min_val; min_val = Integer.MAX_VALUE; for ( int k = 0;(k < (m - 1));k++) {min_val = Math.min(min_val,Math.abs((graph[i][k] - graph[j][(k + 1)]))); }mn2[i][j] = min_val; } int[][] dp = new int[(1 << (n + 2))][n];  int ans = 0; for ( int i = 0;(i < n);i++) {for ( int[] temp :dp) Arrays.fill(temp,-1); for ( int j = 0;(j < n);j++) {dp[(1 << j)][j] = ((j == i)?Integer.MAX_VALUE:0); }for ( int j = 0;(j < n);j++) {ans = Math.max(ans,Math.min(mn2[j][i],calc(((1 << n) - 1),j,dp,mn1,n))); }}out.println(ans); } public int calc( int mask, int v, int[][] dp, int[][] mn1, int n){ if ( (dp[mask][v] != -1)) return dp[mask][v]; dp[mask][v] = 0; for ( int u = 0;(u < n);u++) {if ( ((u != v) && (((mask >> u) & 1) == 1))) dp[mask][v] = Math.max(dp[mask][v],Math.min(mn1[u][v],calc((mask ^ (1 << v)),u,dp,mn1,n))); }return dp[mask][v];} } }
6	public class Main{ static PrintWriter out ; static InputReader ir ; static void solve(){ int n = ir.nextInt();  int t = ir.nextInt();  int[][] a = new int[n][]; for ( int i = 0;(i < n);i++) a[i] = ir.nextIntArray(2); long[] f = fact(15);  long res = 0; for ( int i = 0;(i < (1 << n));i++) { int[] ct = new int[4];  int tot = 0; for ( int j = 0;(j < n);j++) {if ( (((1 << j) & i) != 0)) {tot += a[j][0]; ct[a[j][1]]++; } }if ( (tot != t)) continue; long[][][][] dp = new long[(ct[1] + 1)][(ct[2] + 1)][(ct[3] + 1)][4]; dp[0][0][0][0] = 1; for ( int j = 0;(j < ((ct[1] + ct[2]) + ct[3]));j++) {for ( int k = 0;(k <= ct[1]);k++) {for ( int l = 0;(l <= ct[2]);l++) {if ( (((k + l) > j) || (((j - k) - l) > ct[3]))) continue; for ( int m = 0;(m <= 3);m++) {for ( int o = 0;(o <= 3);o++) {if ( (m == o)) continue; if ( ((o == 1) && (k == ct[1]))) continue; if ( ((o == 2) && (l == ct[2]))) continue; if ( ((o == 3) && (((j - k) - l) == ct[3]))) continue; if ( (o == 1)) {dp[(k + 1)][l][((j - k) - l)][1] = add(dp[(k + 1)][l][((j - k) - l)][1],dp[k][l][((j - k) - l)][m]); } if ( (o == 2)) {dp[k][(l + 1)][((j - k) - l)][2] = add(dp[k][(l + 1)][((j - k) - l)][2],dp[k][l][((j - k) - l)][m]); } if ( (o == 3)) {dp[k][l][(((j - k) - l) + 1)][3] = add(dp[k][l][(((j - k) - l) + 1)][3],dp[k][l][((j - k) - l)][m]); } }}}}}for ( int m = 0;(m <= 3);m++) res = add(res,mul(mul(f[ct[1]],f[ct[2]]),mul(f[ct[3]],dp[ct[1]][ct[2]][ct[3]][m]))); }out.println(res); } static long mod = ((long)1e9 + 7); static long add( long a, long b){ return ((a + b) % mod);} static long mul( long a, long b){ return ((a * b) % mod);} static long div( long a, long b){ return ((a * mod_inverse(b)) % mod);} static private long[] fact( int n){ long[] ret = new long[(n + 1)]; ret[0] = (1 % mod); for ( int i = 1;(i <= n);i++) {ret[i] = mul(ret[(i - 1)],i); }return ret;} public static long mod_inverse( long a){ long[] ret = extgcd(a,mod); return add(mod,(ret[0] % mod));} public static long[] extgcd( long a, long b){ long[] ret = new long[3]; ret[2] = _extgcd(a,b,ret); return ret;} static private long _extgcd( long a, long b, long[] x){ long g = a; x[0] = 1; x[1] = 0; if ( (b != 0)) {g = _extgcd(b,(a % b),x); long temp = x[0]; x[0] = x[1]; x[1] = temp; x[1] -= ((a / b) * x[0]); } return g;} public static void main( String[] args){ ir = new InputReader(System.in); out = new PrintWriter(System.out); solve(); out.flush(); } static class InputReader{ private InputStream in ; private byte[] buffer = new byte[1024]; private int curbuf ; private int lenbuf ; public InputReader( InputStream in){ this.in = in; this.curbuf = this.lenbuf = 0; } public boolean hasNextByte(){ if ( (curbuf >= lenbuf)) {curbuf = 0; try{lenbuf = in.read(buffer); }catch (IOException e){ throw (new InputMismatchException());} if ( (lenbuf <= 0)) return false; } return true;} private int readByte(){ if ( hasNextByte()) return buffer[curbuf++]; else return -1;} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private void skip(){ while((hasNextByte() && isSpaceChar(buffer[curbuf])))curbuf++; } public boolean hasNext(){ skip(); return hasNextByte();} public String next(){ if ( !hasNext()) throw (new NoSuchElementException()); StringBuilder sb = new StringBuilder();  int b = readByte(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} public int nextInt(){ if ( !hasNext()) throw (new NoSuchElementException()); int c = readByte(); while(isSpaceChar(c))c = readByte(); boolean minus = false; if ( (c == '-')) {minus = true; c = readByte(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res = (((res * 10) + c) - '0'); c = readByte(); }while(!isSpaceChar(c));return (minus?-res:res);} public long nextLong(){ if ( !hasNext()) throw (new NoSuchElementException()); int c = readByte(); while(isSpaceChar(c))c = readByte(); boolean minus = false; if ( (c == '-')) {minus = true; c = readByte(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res = (((res * 10) + c) - '0'); c = readByte(); }while(!isSpaceChar(c));return (minus?-res:res);} public int[] nextIntArray( int n){ int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = nextInt(); return a;} } }
1	public class C{ InputStream is ; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/C4"; FastScanner in ; PrintWriter out ; int charToIndex( char c){ if ( Character.isLowerCase(c)) return (c - 'a'); else if ( Character.isUpperCase(c)) return ((c - 'A') + 26); return -1;} int CH_NUM = 52; public void solve(){ int n = in.nextInt();  String s = in.next();  boolean[] exist = new boolean[CH_NUM];  int typeNum = 0; for ( int i = 0;(i < n);i++) { int idx = charToIndex(s.charAt(i)); if ( !exist[idx]) {exist[idx] = true; typeNum++; } } int get = 0;  int tail = 0,head = 0;  int res = Integer.MAX_VALUE;  int[] cnt = new int[CH_NUM]; while(((tail < n) || (head < n))){if ( ((head == n) || (typeNum == get))) { int idx = charToIndex(s.charAt(tail++)); if ( (cnt[idx] == 1)) get--; cnt[idx]--; } else { int idx = charToIndex(s.charAt(head++)); if ( (cnt[idx] == 0)) get++; cnt[idx]++; }if ( (typeNum == get)) res = Math.min(res,(head - tail)); }System.out.println(res); } public void run(){ if ( (__FILE_DEBUG_FLAG__ == __t__)) {try{is = new FileInputStream(__DEBUG_FILE_NAME__); }catch (FileNotFoundException e){ e.printStackTrace(); } System.out.println("FILE_INPUT!"); } else {is = System.in; }in = new FastScanner(is); out = new PrintWriter(System.out); solve(); } public static void main( String[] args){ new C().run(); } class FastScanner{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public FastScanner( InputStream stream){ this.stream = stream; } int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} boolean isEndline( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} int nextInt(){ return Integer.parseInt(next());} int[] nextIntArray( int n){ return nextIntArray(n,0);} int[] nextIntArray( int n, int margin){ int[] array = new int[(n + margin)]; for ( int i = 0;(i < n);i++) array[(i + margin)] = nextInt(); return array;} long nextLong(){ return Long.parseLong(next());} long[] nextLongArray( int n){ return nextLongArray(n,0);} long[] nextLongArray( int n, int margin){ long[] array = new long[(n + margin)]; for ( int i = 0;(i < n);i++) array[(i + margin)] = nextLong(); return array;} double nextDouble(){ return Double.parseDouble(next());} double[] nextDoubleArray( int n){ return nextDoubleArray(n,0);} double[] nextDoubleArray( int n, int margin){ double[] array = new double[(n + margin)]; for ( int i = 0;(i < n);i++) array[(i + margin)] = nextDouble(); return array;} String next(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} } }
4	public class C implements Runnable{ BufferedReader in ; PrintWriter out ; StringTokenizer st ; Random rnd ; short[] qx ,qy ; boolean[][] used ; final int[] dx = {1,-1,0,0}; final int[] dy = {0,0,1,-1}; void solve()throws IOException { int n = nextInt(),m = nextInt(); qx = new short[(n * m)]; qy = new short[(n * m)]; used = new boolean[n][m]; int k = nextInt(),qs = 0,qt = 0; for ( int i = 0;(i < k);i++) { int x = (nextInt() - 1),y = (nextInt() - 1); used[x][y] = true; qx[qt] = (short)x; qy[qt] = (short)y; ++qt; } int rx = 0,ry = 0; while((qs < qt)){ int cx = qx[qs],cy = qy[qs]; ++qs; rx = cx; ry = cy; for ( int z = 0;(z < 4);z++) { int nx = (cx + dx[z]),ny = (cy + dy[z]); if ( (((((nx >= 0) && (ny >= 0)) && (nx < n)) && (ny < m)) && !used[nx][ny])) {used[nx][ny] = true; qx[qt] = (short)nx; qy[qt] = (short)ny; ++qt; } }}out.println((((rx + 1) + " ") + (ry + 1))); } public static void main( String[] args){ final boolean oldChecker = false; if ( oldChecker) {new Thread(null,new C(),"yarrr",(1 << 24)).start(); } else {new C().run(); }} public void run(){ try{try{in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new FileWriter("output.txt")); }catch (FileNotFoundException e){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } rnd = new Random(); solve(); out.close(); }catch (IOException e){ e.printStackTrace(); System.exit(42); } } String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String line = in.readLine(); if ( (line == null)) {return null;} st = new StringTokenizer(line); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
4	public class Main{ public static void main( String[] args)throws IOException { InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter("output.txt");  TaskB solver = new TaskB(); solver.solve(in,out); out.close(); } static private class TaskB{ static final long max = 1000000000000000000L; static final double eps = 0.0000001; static final long mod = 1000000007; static int N ,M ,K ; static long X ,Y ; static boolean F[][][] ; static int D[][] ; void solve( InputReader in, PrintWriter out)throws IOException { N = in.nextInt(); M = in.nextInt(); K = in.nextInt(); F = new boolean[K][N][M]; D = new int[N][M]; for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) D[i][j] = Integer.MAX_VALUE; List<Pair> list = new ArrayList<>(); for ( int i = 0;(i < K);i++) {list.add(new Pair((in.nextInt() - 1),(in.nextInt() - 1))); }for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) for ( int k = 0;(k < K);k++) D[i][j] = Math.min(D[i][j],(Math.abs((list.get(k).X - i)) + Math.abs((list.get(k).Y - j)))); int res = Integer.MIN_VALUE; for ( int j = 0;(j < N);j++) for ( int k = 0;(k < M);k++) if ( (D[j][k] > res)) {X = (j + 1); Y = (k + 1); res = D[j][k]; } out.println(((X + " ") + Y)); } boolean check( int X, int Y){ return ((((X < 0) || (X >= N)) || (Y < 0)) || (Y >= M));} class Pair{ int X ,Y ; Pair( int X, int Y){ this.X = X; this.Y = Y; } } long gcd( long A, long B){ if ( (B == 0)) return A; return gcd(B,(A % B));} long pow( long A, long B, long MOD){ if ( (B == 0)) {return 1;} if ( (B == 1)) {return A;} long val = pow(A,(B / 2),MOD); if ( ((B % 2) == 0)) {return ((val * val) % MOD);} else {return ((val * ((val * A) % MOD)) % MOD);}} } static private class InputReader{ StringTokenizer st ; BufferedReader br ; public InputReader( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } public InputReader( FileReader s)throws FileNotFoundException{ br = new BufferedReader(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());} public boolean ready(){ try{return br.ready(); }catch (IOException e){ throw (new RuntimeException(e));} } } }
3	public class Main{ Scanner scanner = new Scanner(System.in); public static void main( String[] args){ new Main().solve(); } void solve(){ int n = scanner.nextInt(); scanner.nextLine(); String s1 = scanner.nextLine();  String s2 = scanner.nextLine();  int ans = 0;  boolean a[] = new boolean[30];  boolean b[] = new boolean[30]; for ( int i = 0;(i < n);i++) {if ( (s1.charAt(i) != s2.charAt(i))) {ans++; a[(s1.charAt(i) - 'a')] = true; b[(s2.charAt(i) - 'a')] = true; } }for ( int i = 0;(i < n);i++) {if ( (((s1.charAt(i) != s2.charAt(i)) && a[(s2.charAt(i) - 'a')]) && b[(s1.charAt(i) - 'a')])) {for ( int j = (i + 1);(j < n);j++) {if ( ((s1.charAt(i) == s2.charAt(j)) && (s1.charAt(j) == s2.charAt(i)))) {out.println((ans - 2)); out.println((((i + 1) + " ") + (j + 1))); return ;} }} }for ( int i = 0;(i < n);i++) {if ( ((s1.charAt(i) != s2.charAt(i)) && (a[(s2.charAt(i) - 'a')] || b[(s1.charAt(i) - 'a')]))) {for ( int j = (i + 1);(j < n);j++) {if ( ((s1.charAt(j) != s2.charAt(j)) && ((s1.charAt(i) == s2.charAt(j)) || (s1.charAt(j) == s2.charAt(i))))) {out.println((ans - 1)); out.println((((i + 1) + " ") + (j + 1))); return ;} }} }out.println(ans); out.println(((-1 + " ") + -1)); } }
3	public class D{ private void solve(){ br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int n = nextInt(),m = nextInt(),u = 1,d = n; while((u < d)){for ( int i = 1;(i <= m);i++) {out.println(((u + " ") + i)); out.println(((d + " ") + ((m - i) + 1))); }u++; d--; }if ( (u == d)) { int l = 1,r = m; while((l < r)){out.println(((u + " ") + l++)); out.println(((d + " ") + r--)); }if ( (l == r)) out.println(((u + " ") + l)); } out.close(); } public static void main( String[] args){ new D().solve(); } private BufferedReader br ; private StringTokenizer st ; private PrintWriter out ; private String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ throw (new RuntimeException(e));} }return st.nextToken();} private int nextInt(){ return Integer.parseInt(next());} }
4	public class Main1{ static class pair{ int x ; int y ; public pair( int k, int p){ x = k; y = p; } } public static void main( String[] args)throws IOException { Scanner sc = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter("output.txt");  Queue<pair> q = new LinkedList<>();  int n = sc.nextInt();  int m = sc.nextInt();  int t = sc.nextInt();  int mark[][] = new int[(n + 2)][(m + 2)]; while((t-- > 0)){ int a = sc.nextInt();  int b = sc.nextInt(); mark[a][b] = 1; q.add(new pair(a,b)); } int ansx = 1;  int ansy = 1; while((q.size() != 0)){ pair p = q.remove(); if ( (mark[Math.max(1,(p.x - 1))][p.y] == 0)) {q.add(new pair(Math.max(1,(p.x - 1)),p.y)); mark[Math.max(1,(p.x - 1))][p.y] = 1; ansx = Math.max(1,(p.x - 1)); ansy = p.y; } if ( (mark[Math.min(n,(p.x + 1))][p.y] == 0)) {q.add(new pair(Math.min(n,(p.x + 1)),p.y)); mark[Math.min(n,(p.x + 1))][p.y] = 1; ansx = Math.min(n,(p.x + 1)); ansy = p.y; } if ( (mark[p.x][Math.max(1,(p.y - 1))] == 0)) {q.add(new pair(p.x,Math.max(1,(p.y - 1)))); mark[p.x][Math.max(1,(p.y - 1))] = 1; ansx = p.x; ansy = Math.max(1,(p.y - 1)); } if ( (mark[p.x][Math.min(m,(p.y + 1))] == 0)) {q.add(new pair(p.x,Math.min(m,(p.y + 1)))); mark[p.x][Math.min(m,(p.y + 1))] = 1; ansx = p.x; ansy = Math.min(m,(p.y + 1)); } }out.println(((ansx + " ") + ansy)); out.flush(); } }
3	public class c implements Runnable{ int N ; int[] arr ; public static void main( String[] args){ new Thread(null,new c(),"",(1 << 27)).start(); } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = null; int line_ptr = 0; void read(){ try{line = br.readLine().split(" "); }catch (IOException ioe){ System.err.println("bad input"); line = null; } } void ensure(){ while(((line == null) || (line.length <= line_ptr))){read(); line_ptr = 0; }} int nextInt(){ ensure(); return Integer.parseInt(line[line_ptr++]);} String nextString(){ ensure(); return line[line_ptr++];} }
0	public class Hexadec implements Runnable{ static final String taskname = "filename"; public void solve()throws Exception { int n = Integer.parseInt(in.readLine()); out.write(((((n + " ") + 0) + " ") + 0)); } BufferedReader in ; BufferedWriter out ; public String readword()throws IOException { StringBuilder b = new StringBuilder();  int c ; c = in.read(); while(((c >= 0) && (c <= ' ')))c = in.read(); if ( (c < 0)) return ""; while((c > ' ')){b.append((char)c); c = in.read(); }return b.toString();} public static void main( String[] args){ new Thread(new Hexadec()).start(); } }
2	public class D{ static long n ; static long x ; static long y ; static long c ; static long f( long t){ long s = 0; if ( (t == 0)) s = 1; else {s = ((((4 + (4 * t)) / 2) * t) + 1); }if ( ((x + t) > n)) { long c = ((x + t) - n); s -= (c * c); } if ( ((x - t) <= 0)) { long c = ((t - x) + 1); s -= (c * c); } if ( ((y + t) > n)) { long c = ((y + t) - n); s -= (c * c); } if ( ((y - t) <= 0)) { long c = ((t - y) + 1); s -= (c * c); } if ( (t > ((x + y) - 1))) { long m = (((t - x) - y) + 1); s += ((m * (m + 1)) / 2); } if ( (t > ((x + n) - y))) { long m = (((t - x) - n) + y); s += ((m * (m + 1)) / 2); } if ( (t > ((n - x) + y))) { long m = (((t - n) - y) + x); s += ((m * (m + 1)) / 2); } if ( (t > ((((n - x) + n) - y) + 1))) { long m = ((((t - (2 * n)) + x) + y) - 1); s += ((m * (m + 1)) / 2); } return s;} public static void main( String[] args){ Scanner in = new Scanner(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(System.out); n = in.nextLong(); x = in.nextLong(); y = in.nextLong(); c = in.nextLong(); long l = 0;  long r = (2 * n); while((l < r)){ long m = ((l + r) / 2);  long ff = f(m); if ( (ff < c)) {l = (m + 1); } else {r = m; }}out.println(l); out.close(); } }
1	public class C701{ public static int f( char c){ if ( ((c >= 'a') && (c <= 'z'))) {return (c - 'a');} else {return ((26 + c) - 'A');}} public static void main( String[] args)throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(reader.readLine());  char[] ch = reader.readLine().toCharArray();  LinkedList<Integer>[] p = new LinkedList[52]; for ( int i = 0;(i < 52);i++) {p[i] = new LinkedList<>(); } int[] fc = new int[n]; for ( int i = 0;(i < n);i++) { int cc = f(ch[i]); p[cc].add(i); fc[i] = cc; } int en = 0; for ( int i = 0;(i < 52);i++) {if ( (p[i].size() > 0)) en = Math.max(en,p[i].poll()); } int mx = (en + 1); for ( int i = 0;(i < n);i++) {if ( (p[fc[i]].size() == 0)) break; en = Math.max(en,p[fc[i]].poll()); mx = Math.min(mx,(en - i)); }System.out.println(mx); } }
6	public class ACMIND{ static FastReader scan ; static PrintWriter pw ; static long MOD = 1_000_000_007; static long INF = 1_000_000_000_000_000_000L; static long inf = 2_000_000_000; public static void main( String[] args){ new Thread(null,null,"BaZ",(1 << 25)){}.start(); } static int n ,g[] ,t[] ,T ; static int dp[][] ; static void solve()throws IOException { scan = new FastReader(); pw = new PrintWriter(System.out,true); StringBuilder fast = new StringBuilder(); n = ni(); T = ni(); g = new int[n]; t = new int[n]; for ( int i = 0;(i < n);++i) {t[i] = ni(); g[i] = ni(); } int MAX = (1 << n); dp = new int[MAX][4]; for ( int i = 0;(i < MAX);++i) {for ( int j = 0;(j < 4);++j) {dp[i][j] = -1; }}pl(f(((1 << n) - 1),0)); pw.flush(); pw.close(); } static int f( int mask, int prev){ if ( (dp[mask][prev] != -1)) {return dp[mask][prev];} int left = T; for ( int i = 0;(i < n);++i) {if ( ((mask & (1 << i)) == 0)) {left -= t[i]; } }if ( (left == 0)) {return 1;} int cnt = 0; for ( int i = 0;(i < n);++i) {if ( ((mask & (1 << i)) != 0)) {if ( ((g[i] != prev) && (left >= t[i]))) {cnt += f((mask ^ (1 << i)),g[i]); if ( (cnt >= MOD)) {cnt -= MOD; } } } }return dp[mask][prev] = cnt;} static int ni()throws IOException { return scan.nextInt();} static void pl(){ pw.println(); } static void p( Object o){ pw.print((o + " ")); } static void pl( Object o){ pw.println(o); } static class FastReader{ private final int BUFFER_SIZE = (1 << 16); private DataInputStream din ; private byte[] buffer ; private int bufferPointer ,bytesRead ; public FastReader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastReader( String file_name)throws IOException{ din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt()throws IOException { int ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} public long nextLong()throws IOException { long ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} public double nextDouble()throws IOException { double ret = 0,div = 1;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( (c == '.')) while((((c = read()) >= '0') && (c <= '9')))ret += ((c - '0') / (div *= 10)); if ( neg) return -ret; return ret;} private void fillBuffer()throws IOException { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } private byte read()throws IOException { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} public void close()throws IOException { if ( (din == null)) return ; din.close(); } } }
3	public class java2{ public static void main( String[] args){ Scanner r = new Scanner(System.in);  int n = r.nextInt();  int[] l = new int[1005];  int[] ri = new int[1005];  int[] candy = new int[1005]; for ( int i = 1;(i <= n);++i) {l[i] = r.nextInt(); }for ( int i = 1;(i <= n);++i) {ri[i] = r.nextInt(); }for ( int i = 1;(i <= n);++i) {if ( ((l[i] > (i - 1)) || (ri[i] > (n - i)))) {System.out.println("NO"); System.exit(0); } candy[i] = ((n - l[i]) - ri[i]); }for ( int i = 1;(i <= n);++i) { int left = 0,right = 0; for ( int j = 1;(j <= (i - 1));++j) {if ( (candy[j] > candy[i])) {++left; } }for ( int j = (i + 1);(j <= n);++j) {if ( (candy[j] > candy[i])) {++right; } }if ( ((left != l[i]) || (right != ri[i]))) {System.out.println("NO"); System.exit(0); } }System.out.println("YES"); for ( int i = 1;(i <= n);++i) {System.out.print((candy[i] + " ")); }} }
1	public class Main{ static class FastReader{ private InputStream mIs ; private byte[] buf = new byte[1024]; private int curChar ,numChars ; public FastReader(){ this(System.in); } public FastReader( InputStream is){ mIs = is; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = mIs.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public String next(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public long l(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public int i(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} public void scanIntArr( int[] arr){ for ( int li = 0;(li < arr.length);++li) {arr[li] = i(); }} } public static void main( String[] args)throws IOException { PrintWriter pw = new PrintWriter(System.out);  FastReader fr = new FastReader();  int n = fr.i();  int[] arr = new int[n]; fr.scanIntArr(arr); int min = Integer.MAX_VALUE;  int max = Integer.MIN_VALUE;  long sum = 0; if ( (n == 1)) {pw.println(arr[0]); pw.flush(); pw.close(); return ;} for ( int i = 0;(i < n);++i) {if ( (arr[i] < min)) min = arr[i]; if ( (arr[i] > max)) max = arr[i]; sum += Math.abs(arr[i]); }if ( (min > 0)) {sum -= (2 * min); } if ( (max < 0)) {sum += (2 * max); } pw.println(sum); pw.flush(); pw.close(); } }
2	public class Pipeline{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  long n = sc.nextLong();  long k = sc.nextLong(); sc.close(); if ( ((((k * (k - 1)) / 2) + 1) < n)) {System.out.println(-1); } else { long l = -1,r = k; while(((r - l) > 1)){ long m = ((r + l) / 2); if ( (cantidadPosible(k,m) >= n)) {r = m; } else {l = m; }}System.out.println(r); }} static private long cantidadPosible( long k, long usadas){ return ((((k * (k - 1)) / 2) + 1) - (((k - usadas) * ((k - usadas) - 1)) / 2));} }
0	public class A{ public static void main( String[] args){ Scanner s = new Scanner(System.in);  int n = s.nextInt();  int prev2 = 0;  int prev1 = 1;  int prev = 1;  int curr = 2; if ( (n == 0)) {System.out.println("0 0 0"); return ;} else if ( (n == 1)) {System.out.println("0 0 1"); return ;} while(true){if ( (curr == n)) break; prev2 = prev1; prev1 = prev; int temp = (prev + curr); prev = curr; curr = temp; }System.out.println(((((prev2 + " ") + prev1) + " ") + prev1)); } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } } class TaskC{ public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.nextInt();  int m = in.nextInt();  int k = in.nextInt();  Queue<Point> points = new LinkedList<Point>();  int[][] burnTime = new int[n][m];  boolean[][] visited = new boolean[n][m]; for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); visited[x][y] = true; burnTime[x][y] = 0; points.add(new Point(x,y)); } int[] dx = new int[]{-1,0,0,1};  int[] dy = new int[]{0,-1,1,0}; while((points.size() != 0)){ Point cur = points.poll();  int x = cur.x;  int y = cur.y; for ( int i = 0;(i < dx.length);i++) { int nextX = (x + dx[i]);  int nextY = (y + dy[i]); if ( (((((nextX >= 0) && (nextX < n)) && (nextY >= 0)) && (nextY < m)) && (((burnTime[x][y] + 1) < burnTime[nextX][nextY]) || !visited[nextX][nextY]))) {points.add(new Point(nextX,nextY)); visited[nextX][nextY] = true; burnTime[nextX][nextY] = (burnTime[x][y] + 1); } }} int x ,y ; x = y = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (burnTime[i][j] > burnTime[x][y])) {x = i; y = j; } }}out.printf("%d %d",(x + 1),(y + 1)); } } class Point{ int x ; int y ; public Point( int x, int y){ this.x = x; this.y = y; } } 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());} }
1	public class Main{ public static StreamTokenizer in ; public static PrintStream out ; public static BufferedReader br ; public static String readLine()throws IOException { return br.readLine();} public static int genans( String ss){ int n = ss.length();  char[] s = ss.toCharArray();  int res = 0; while(true){ int firstT = -1; for ( int i = 0;(i < n);i++) if ( (s[i] == 'T')) {firstT = i; break;} int lastH = -1; for ( int i = (n - 1);(i >= 0);i--) if ( (s[i] == 'H')) {lastH = i; break;} if ( (firstT < lastH)) {res++; s[firstT] = 'H'; s[lastH] = 'T'; } else break;}return res;} public static void main( String[] args)throws IOException { in = new StreamTokenizer(new InputStreamReader(System.in)); br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintStream(System.out); readLine(); String s = readLine();  int n = s.length();  String kk = s;  int ans = (n * 100); for ( int tr = 0;(tr < (n + 2));tr++) { String kk2 = ""; for ( int i = 1;(i < n);i++) kk2 = (kk2 + kk.charAt(i)); kk2 = (kk2 + kk.charAt(0)); kk = kk2; int cur = genans(kk); if ( (cur < ans)) ans = cur; }out.println(ans); } }
1	public class IQTest{ public static void main( String[] args)throws Exception { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));  String line ; line = stdin.readLine(); int n = Integer.parseInt(line); line = stdin.readLine(); List even = new ArrayList();  List odd = new ArrayList();  String[] kk = line.split(" "); for ( int i = 0;(i < n);i++) {if ( ((Integer.parseInt(kk[i]) % 2) == 0)) even.add(i); else odd.add(i); }if ( (even.size() == 1)) System.out.println(((Integer)even.get(0) + 1)); else System.out.println(((Integer)odd.get(0) + 1)); } }
6	public class D{ static int bot ; static int n ,m ; static int[][] a ; static int[][] Min ; static int[][] memo ; static int K ; static int dp( int msk, int ones, int last){ if ( (ones == n)) {return ((Min[last][bot] >= K)?1:0);} if ( (memo[last][msk] != -1)) return memo[last][msk]; int ans = 0; for ( int nxt = 0;(nxt < n);nxt++) if ( (((msk & (1 << nxt)) == 0) && (Min[last][nxt] >= K))) {ans |= dp((msk | (1 << nxt)),(ones + 1),nxt); } return memo[last][msk] = ans;} static boolean check( int top, int bottom){ for ( int j = 0;((j + 1) < m);j++) { int diff = Math.abs((a[bottom][j] - a[top][(j + 1)])); if ( (diff < K)) return false; }return true;} public static void main( String[] args)throws IOException { Scanner sc = new Scanner();  PrintWriter out = new PrintWriter(System.out); n = sc.nextInt(); m = sc.nextInt(); a = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) a[i][j] = sc.nextInt(); Min = new int[n][n]; if ( (n == 1)) { int lo = 0,hi = (int)1e9;  int ans = 0; while((lo <= hi)){K = ((lo + hi) >> 1); if ( check(0,0)) {ans = K; lo = (K + 1); } else hi = (K - 1); }System.out.println(ans); return ;} for ( int i1 = 0;(i1 < n);i1++) for ( int i2 = 0;(i2 < n);i2++) {if ( (i1 == i2)) continue; int min = (int)1e9; for ( int j = 0;(j < m);j++) min = Math.min(Math.abs((a[i1][j] - a[i2][j])),min); Min[i1][i2] = min; }memo = new int[n][(1 << n)]; int ans = 0;  int lo = 0,hi = (int)1e9; while((lo <= hi)){K = ((lo + hi) >> 1); for ( int[] x :memo) Arrays.fill(x,-1); int ok = 0; for ( int top = 0;((top < n) && (ok == 0));top++) for ( int bottom = 0;((bottom < n) && (ok == 0));bottom++) {bot = bottom; if ( ((top == bottom) || !check(top,bottom))) continue; int dp = dp(((1 << top) | (1 << bottom)),2,top); ok |= dp; }if ( (ok == 1)) {ans = K; lo = (K + 1); } else hi = (K - 1); }out.println(ans); out.close(); } static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner(){ br = new BufferedReader(new InputStreamReader(System.in)); } Scanner( String fileName)throws FileNotFoundException{ br = new BufferedReader(new FileReader(fileName)); } 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());} } }
4	public class Solution{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} InputReader in = new InputReader(inputStream);  PrintWriter out = new PrintWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ int[][] or ; int n ; int m ; public void solve( int testNumber, InputReader in, PrintWriter out){ n = in.nextInt(); m = in.nextInt(); int k = in.nextInt();  ArrayList<Point> arr1 = new ArrayList<>();  ArrayList<Point> arr2 = new ArrayList<>(); for ( int i = 0;(i < k);i++) {arr1.add(new Point(in.nextInt(),in.nextInt())); }or = new int[(n + 1)][(m + 1)]; for ( int i = 0;(i < k);i++) {or[arr1.get(i).x][arr1.get(i).y] = -1; } Point lastValue = arr1.get(0); while(((arr1.size() > 0) || (arr2.size() > 0))){for ( Point p :arr1) {if ( valid(new Point((p.x - 1),p.y))) {arr2.add(new Point((p.x - 1),p.y)); } if ( valid(new Point((p.x + 1),p.y))) {arr2.add(new Point((p.x + 1),p.y)); } if ( valid(new Point(p.x,(p.y - 1)))) {arr2.add(new Point(p.x,(p.y - 1))); } if ( valid(new Point(p.x,(p.y + 1)))) {arr2.add(new Point(p.x,(p.y + 1))); } }arr1.clear(); if ( (arr2.size() > 0)) {lastValue = arr2.get(0); } for ( Point p :arr2) {if ( valid(new Point((p.x - 1),p.y))) {arr1.add(new Point((p.x - 1),p.y)); } if ( valid(new Point((p.x + 1),p.y))) {arr1.add(new Point((p.x + 1),p.y)); } if ( valid(new Point(p.x,(p.y - 1)))) {arr1.add(new Point(p.x,(p.y - 1))); } if ( valid(new Point(p.x,(p.y + 1)))) {arr1.add(new Point(p.x,(p.y + 1))); } }arr2.clear(); if ( (arr1.size() > 0)) {lastValue = arr1.get(0); } }out.println(((lastValue.x + " ") + lastValue.y)); } boolean valid( Point p){ if ( ((((p.x < 1) || (p.x > n)) || ((p.y < 1) || (p.y > m))) || (or[p.x][p.y] == -1))) {return false;} or[p.x][p.y] = -1; return true;} class Point{ int x ; int y ; public Point( int a, int b){ x = a; y = b; } } } 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());} } }
2	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(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, InputReader in, PrintWriter out){ long n = in.nextInt();  long x = in.nextInt();  long y = in.nextInt();  long c = in.nextInt(); if ( (c == 1)) {out.println(0); return ;} long left = 1,right = (2 * n),middle ,res = -1;  long val = getNumberOfCells(x,y,n,2); while((left <= right)){middle = ((left + right) / 2); long numberOfCells = getNumberOfCells(x,y,n,middle); if ( (numberOfCells < c)) {left = (middle + 1); } else {res = middle; right = (middle - 1); }}out.println(res); } private long getNumberOfCells( long x, long y, long n, long middle){ long res = 0; res += calc(x,y,(middle + 1)); res += calc(((n - x) + 1),y,(middle + 1)); res += calc(x,((n - y) + 1),(middle + 1)); res += calc(((n - x) + 1),((n - y) + 1),(middle + 1)); res -= calcX(x,n,middle); res -= calcX(y,n,middle); --res; return res;} private long calcX( long x, long n, long size){ long left = (x - size);  long right = (x + size); left = Math.max(left,1); right = Math.min(right,n); if ( (left <= right)) {return ((right - left) + 1);} return 0;} private long calc( long x, long y, long size){ if ( (size <= Math.min(x,y))) {return (((1 + size) * size) / 2);} if ( (size >= ((x + y) - 1))) {return (x * y);} if ( (size > Math.max(x,y))) {return ((x * y) - calc(x,y,(((x + y) - 1) - size)));} long min = Math.min(x,y);  long res = (((1 + min) * min) / 2);  long rest = (size - min); res += (rest * min); return res;} } 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 nextString(){ while(((stt == null) || !stt.hasMoreTokens())){stt = new StringTokenizer(nextLine()); }return stt.nextToken();} public int nextInt(){ return Integer.parseInt(nextString());} }
1	@SuppressWarnings("unchecked") public class P701A{ Map<Character,Integer> cc = new HashMap(72); void add( char c){ cc.put(c,(cc.getOrDefault(c,0) + 1)); } void rem( char c){ Integer cnt = (cc.get(c) - 1); if ( (cnt != 0)) {cc.put(c,cnt); } else {cc.remove(c); }} public void run()throws Exception { int n = nextInt();  char[] s = next().toCharArray();  BitSet bs = new BitSet(); for ( char c :s) {bs.set(c); } int t = bs.cardinality();  int m = Integer.MAX_VALUE; for ( int i = 0,j = 0;(i < n);i++) {while(((j < n) && (cc.size() < t))){add(s[j]); j++; }if ( (cc.size() == t)) {m = Math.min(m,(j - i)); } rem(s[i]); }println(m); } public static void main( String... args)throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P701A().run(); br.close(); pw.close(); System.err.println((("\n[Time : " + (System.currentTimeMillis() - startTime)) + " ms]")); } static long startTime = System.currentTimeMillis(); static BufferedReader br ; static PrintWriter pw ; StringTokenizer stok ; String nextToken()throws IOException { while(((stok == null) || !stok.hasMoreTokens())){ String s = br.readLine(); if ( (s == null)) {return null;} stok = new StringTokenizer(s); }return stok.nextToken();} void print( byte b){ print(("" + b)); } void print( int i){ print(("" + i)); } void print( long l){ print(("" + l)); } void print( double d){ print(("" + d)); } void print( char c){ print(("" + c)); } void print( Object o){ if ( (o instanceof int[])) {print(Arrays.toString((int[])o)); } else if ( (o instanceof long[])) {print(Arrays.toString((long[])o)); } else if ( (o instanceof char[])) {print(Arrays.toString((char[])o)); } else if ( (o instanceof byte[])) {print(Arrays.toString((byte[])o)); } else if ( (o instanceof short[])) {print(Arrays.toString((short[])o)); } else if ( (o instanceof boolean[])) {print(Arrays.toString((boolean[])o)); } else if ( (o instanceof float[])) {print(Arrays.toString((float[])o)); } else if ( (o instanceof double[])) {print(Arrays.toString((double[])o)); } else if ( (o instanceof Object[])) {print(Arrays.toString((Object[])o)); } else {print(("" + o)); }} void print( String s){ pw.print(s); } void println(){ println(""); } void println( byte b){ println(("" + b)); } void println( int i){ println(("" + i)); } void println( long l){ println(("" + l)); } void println( double d){ println(("" + d)); } void println( char c){ println(("" + c)); } void println( Object o){ print(o); println(); } void println( String s){ pw.println(s); } int nextInt()throws IOException { return Integer.parseInt(nextToken());} long nextLong()throws IOException { return Long.parseLong(nextToken());} double nextDouble()throws IOException { return Double.parseDouble(nextToken());} String next()throws IOException { return nextToken();} String nextLine()throws IOException { return br.readLine();} int gcd( int a, int b){ return ((b > 0)?gcd(b,(a % b)):a);} }
2	public class Pipeline{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  long n = in.nextLong();  long k = in.nextLong(); if ( (n == 1)) {System.out.println(0); return ;} if ( (k >= n)) {System.out.println(1); return ;} long total = ((((k + 2) * (k - 1)) / 2) - (k - 2)); if ( (total < n)) {System.out.println(-1); return ;} int i = 2,j = (int)k; while((i <= j)){ int m = ((i + j) / 2); total = ((((k + m) * ((k - m) + 1)) / 2) - (k - m)); if ( (total == n)) {System.out.println(((k - m) + 1)); return ;} if ( (total < n)) j = (m - 1); else i = (m + 1); }System.out.println(((k - i) + 2)); } }
2	public class TC{ static long N ; static int k ; static long WHOLESUM ; static long SUM( long k){ long res = ((k * (k + 1)) / 2); return (res - 1);} static long returnPipes( int mid){ long not = SUM((mid - 1));  long totpipes = (WHOLESUM - not);  int number = ((k - mid) + 1);  long res = ((totpipes - number) + 1); return res;} static long binarySearch( int lo, int hi){ int res = Integer.MAX_VALUE;  int val = 0; while((lo <= hi)){ int mid = ((lo + hi) / 2);  long cnt = returnPipes(mid); val = ((k - mid) + 1); ;if ( (cnt < N)) {hi = (mid - 1); continue;} else {res = Math.min(val,res); lo = (mid + 1); }}if ( (res == Integer.MAX_VALUE)) return -1; else return res;} public static void main( String[] args)throws IOException { Scanner s = new Scanner(System.in); N = s.nextLong(); k = s.nextInt(); WHOLESUM = SUM(k); if ( (N <= 1)) System.out.println(0); else System.out.println(binarySearch(2,k)); } }
0	public class MAIN{ public static void main( String[] args){ Scanner sn = new Scanner(System.in);  int n ,n1 ,n2 ,n3 ;  int arr[] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170}; n = sn.nextInt(); if ( (n == 2)) {n1 = n2 = 1; n3 = 0; } else if ( (n == 1)) {n3 = n2 = 0; n1 = 1; } else if ( (n == 0)) {n1 = n2 = n3 = 0; } else if ( (n == 3)) {n1 = n2 = n3 = 1; } else { int index = bsearch(arr,0,(arr.length - 1),n); n1 = arr[(index - 1)]; n2 = arr[(index - 3)]; n3 = arr[(index - 4)]; }System.out.println(((((n3 + " ") + n2) + " ") + n1)); } static int bsearch( int[] arr, int l, int h, int n){ if ( (l > h)) return -1; int mid = ((l + h) / 2); if ( (n == arr[mid])) return mid; else if ( (n > arr[mid])) return bsearch(arr,(mid + 1),h,n); else return bsearch(arr,l,(mid - 1),n);} }
5	public class j{ public static void main( String[] a)throws IOException { BufferedReader b = new BufferedReader(new InputStreamReader(System.in));  int k = 0,i = 0,j = 0,n = 0,p = 0,t = 0;  String s ; s = b.readLine(); StringTokenizer c = new StringTokenizer(s); n = Integer.parseInt(c.nextToken()); k = Integer.parseInt(c.nextToken()); int d[] = new int[n];  int e[] = new int[n]; for ( i = 0;(i < n);i++) {s = b.readLine(); StringTokenizer z = new StringTokenizer(s); d[i] = Integer.parseInt(z.nextToken()); e[i] = Integer.parseInt(z.nextToken()); }for ( i = 0;(i < (n - 1));i++) {for ( j = (i + 1);(j < n);j++) {if ( (d[j] < d[i])) {t = d[j]; d[j] = d[i]; d[i] = t; t = e[j]; e[j] = e[i]; e[i] = t; } }}for ( i = 0;(i < (n - 1));i++) {if ( (((d[(i + 1)] - (e[(i + 1)] / 2.0)) - (d[i] + (e[i] / 2.0))) > k)) p += 2; if ( (((d[(i + 1)] - (e[(i + 1)] / 2.0)) - (d[i] + (e[i] / 2.0))) == k)) p++; }System.out.print((p + 2)); } }
3	public class c{ static boolean seq[] ; static long memo[][] ,mod = ((long)1e9 + 7); static long go( int n, int d){ long ans = 0; if ( (d < 0)) return 0; if ( (n == seq.length)) return 1; int f = 1; if ( (n > 0)) f = (seq[(n - 1)]?1:0); if ( (memo[n][d] != -1)) return memo[n][d]; if ( (f == 0)) {ans += go((n + 1),(d + (seq[n]?1:0))); ans %= mod; ans += go(n,(d - 1)); ans %= mod; } if ( (f == 1)) {ans += go((n + 1),(d + (seq[n]?1:0))); ans %= mod; } return memo[n][d] = ans;} public static void main( String[] args)throws IOException { FastScanner in = new FastScanner(System.in);  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt(); seq = new boolean[n]; for ( int i = 0;(i < n);i++) {seq[i] = (in.next().charAt(0) == 'f'); }memo = new long[n][(n + 1)]; for ( int i = 0;(i < n);i++) {Arrays.fill(memo[i],-1); }System.out.println(go(0,0)); out.close(); } static class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner( InputStream i){ br = new BufferedReader(new InputStreamReader(i)); st = null; } 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());} } }
2	public class Main{ public static void main( String[] args)throws IOException { new Main().solve(); } public Main(){ } MyReader in = new MyReader(); PrintWriter out = new PrintWriter(System.out); void solve()throws IOException { long n = in.nextLong();  long k = in.nextLong();  long sum = 1;  long count = 0;  long index = (k - 1);  long[] delta = {1000000000,100000000,10000000,1000000,100000,10000,1000,100,10,1,0}; while((index > 0)){if ( ((index + sum) <= n)) {for ( int d = 0;(d < delta.length);d++) {if ( (delta[d] < index)) { long m = ((((2 * index) - delta[d]) * (delta[d] + 1)) / 2); if ( ((m + sum) <= n)) {sum += m; index -= (delta[d] + 1); count += (delta[d] + 1); } } }} else {index = (n - sum); }}if ( (sum == n)) {out.println(count); } else {out.println(-1); }out.close(); } } class MyReader{ private BufferedReader in ; String[] parsed ; int index = 0; public MyReader(){ in = new BufferedReader(new InputStreamReader(System.in)); } public long nextLong()throws NumberFormatException,IOException { if ( ((parsed == null) || (parsed.length == index))) {read(); } return Long.parseLong(parsed[index++]);} private void read()throws IOException { parsed = in.readLine().split(" "); index = 0; } public String readLine()throws IOException { return in.readLine();} }
6	public class l{ static long mod = (int)(1e9 + 7); static int n ; static StringBuilder sol ; static boolean is ; static int[][][] memo ; static int[] val ,gen ; static int dp( int last, int rem, int msk){ if ( (rem == 0)) return 1; if ( (memo[last][rem][msk] != -1)) return memo[last][rem][msk]; int ans = 0; for ( int i = 0;(i < n);i++) {if ( ((msk & (1 << i)) == 0)) {if ( ((gen[i] != last) && (val[i] <= rem))) {ans += dp(gen[i],(rem - val[i]),(msk | (1 << i))); ans %= mod; } } }return memo[last][rem][msk] = ans;} public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  PrintWriter pw = new PrintWriter(System.out); n = sc.nextInt(); int t = sc.nextInt(); gen = new int[n]; val = new int[n]; for ( int i = 0;(i < n);i++) {val[i] = sc.nextInt(); gen[i] = sc.nextInt(); }memo = new int[4][(t + 1)][(1 << n)]; for ( int[][] x :memo) for ( int[] a :x) Arrays.fill(a,-1); pw.println(dp(0,t,0)); pw.flush(); } 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()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 boolean ready()throws IOException { return br.ready();} } }
5	public class A15{ static StreamTokenizer in ; static PrintWriter out ; static int nextInt()throws IOException { in.nextToken(); return (int)in.nval;} public static void main( String[] args)throws IOException { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); int n = nextInt(),t = nextInt();  int[] x = new int[n];  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {x[i] = nextInt(); a[i] = nextInt(); } int ans = 0; for ( int i = 0;(i < n);i++) { boolean left = true,right = true; for ( int j = 0;(j < n);j++) if ( ((x[j] < x[i]) && (((a[i] + (2 * t)) + a[j]) >= (2 * Math.abs((x[i] - x[j])))))) left = false; else if ( ((x[j] > x[i]) && (((a[i] + (2 * t)) + a[j]) > (2 * Math.abs((x[i] - x[j])))))) right = false; if ( left) ans++; if ( right) ans++; }out.println(ans); out.flush(); } }
4	public class Main{ public static void main( String[] args)throws NumberFormatException,IOException { Scanner sc = new Scanner(new File("input.txt"));  int n = sc.nextInt();  int m = sc.nextInt(); sc.nextLine(); int k = sc.nextInt();  int les[][] = new int[n][m];  PrintWriter out = new PrintWriter(new FileWriter("output.txt"));  ArrayList<Integer[]> list = new ArrayList(); sc.nextLine(); for ( int i = 0;(i < k);i++) { Integer[] ii = new Integer[2]; ii[0] = (sc.nextInt() - 1); ii[1] = (sc.nextInt() - 1); list.add(ii); }sc.close(); int maxr = 0;  int maxi = 0;  int maxj = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int minr = 100000;  int mini = 0;  int minj = 0; for ( int f = 0;(f < k);f++) { Integer[] ii = list.get(f);  int ww = Math.abs((ii[0] - i));  int hh = Math.abs((ii[1] - j));  int r = (ww + hh); if ( (r < minr)) {minr = r; mini = i; minj = j; } }if ( ((maxr < minr) && (minr < 100000))) {maxi = mini; maxj = minj; maxr = minr; } }}out.print((((maxi + 1) + " ") + (maxj + 1))); out.close(); } }
1	public class Third{ static long mod = 1000000007; public static void main( String[] args)throws Exception { InputReader in = new InputReader(System.in);  PrintWriter pw = new PrintWriter(System.out);  int n = in.readInt();  String a = in.readString();  char c[] = a.toCharArray();  HashSet<Character> ht = new HashSet<Character>();  Deque<Character> q = new LinkedList<Character>();  HashSet<Character> hs = new HashSet<Character>();  HashMap<Character,Integer> hm = new HashMap<Character,Integer>(); for ( int i = 0;(i < n);i++) {ht.add(c[i]); } int t = ht.size(); q.addLast(c[0]); hs.add(c[0]); hm.put(c[0],1); int ans = Integer.MAX_VALUE; if ( (hs.size() == t)) {ans = min(ans,q.size()); } for ( int i = 1;(i < n);i++) {q.addLast(c[i]); hs.add(c[i]); if ( hm.containsKey(c[i])) { int x = hm.get(c[i]); hm.put(c[i],(x + 1)); } else hm.put(c[i],1); while((hs.size() == t)){ans = min(ans,q.size()); char ch = q.peekFirst();  int x = hm.get(ch); if ( (x == 1)) break; else {hm.put(ch,(x - 1)); q.pollFirst(); }}}pw.println(ans); pw.close(); } public static long gcd( long x, long y){ if ( ((x % y) == 0)) return y; else return gcd(y,(x % y));} public static int gcd( int x, int y){ if ( ((x % y) == 0)) return y; else return gcd(y,(x % y));} public static int abs( int a, int b){ return (int)Math.abs((a - b));} public static long abs( long a, long b){ return (long)Math.abs((a - b));} public static int min( int a, int b){ if ( (a > b)) return b; else return a;} public static long min( long a, long b){ if ( (a > b)) return b; else return a;} public static long pow( long n, long p, long m){ long result = 1; if ( (p == 0)) return 1; if ( (p == 1)) return n; while((p != 0)){if ( ((p % 2) == 1)) result *= n; if ( (result >= m)) result %= m; p >>= 1; n *= n; if ( (n >= m)) n %= m; }return result;} public static long pow( long n, long p){ long result = 1; if ( (p == 0)) return 1; if ( (p == 1)) return n; while((p != 0)){if ( ((p % 2) == 1)) result *= n; p >>= 1; n *= n; }return result;} static long mergeSort( int[] a, int[] b, long left, long right){ long c = 0; if ( (left < right)) { long mid = (left + ((right - left) / 2)); c = mergeSort(a,b,left,mid); c += mergeSort(a,b,(mid + 1),right); c += merge(a,b,left,(mid + 1),right); } return c;} static long merge( int[] a, int[] b, long left, long mid, long right){ long c = 0;  int i = (int)left;  int j = (int)mid;  int k = (int)left; while(((i <= ((int)mid - 1)) && (j <= (int)right))){if ( (a[i] <= a[j])) {b[k++] = a[i++]; } else {b[k++] = a[j++]; c += (mid - i); }}while((i <= ((int)mid - 1)))b[k++] = a[i++]; while((j <= (int)right))b[k++] = a[j++]; for ( i = (int)left;(i <= (int)right);i++) a[i] = b[i]; return c;} static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } }
0	public class TwoSquares{ int INF = 1000; void solve(){ int[][] s1 = new int[4][2]; for ( int i = 0;(i < 4);i++) {s1[i][0] = in.nextInt(); s1[i][1] = in.nextInt(); } int[][] s2 = new int[4][2]; for ( int i = 0;(i < 4);i++) {s2[i][0] = in.nextInt(); s2[i][1] = in.nextInt(); }if ( ok(s1,s2)) {out.println("Yes"); return ;} rotate(s1); rotate(s2); if ( ok(s2,s1)) {out.println("Yes"); return ;} out.println("No"); } void rotate( int[][] s){ for ( int i = 0;(i < 4);i++) { int x = s[i][0],y = s[i][1]; s[i][0] = (x - y); s[i][1] = (x + y); }} boolean ok( int[][] s1, int[][] s2){ int xmin = INF,xmax = -INF,ymin = INF,ymax = -INF; for ( int i = 0;(i < 4);i++) {xmin = Math.min(xmin,s1[i][0]); xmax = Math.max(xmax,s1[i][0]); ymin = Math.min(ymin,s1[i][1]); ymax = Math.max(ymax,s1[i][1]); }for ( int i = 0;(i < 4);i++) {if ( ((((s2[i][0] >= xmin) && (s2[i][0] <= xmax)) && (s2[i][1] >= ymin)) && (s2[i][1] <= ymax))) return true; } int[] mid2 = new int[]{(s2[0][0] + s2[2][0]),(s2[0][1] + s2[2][1])}; return ((((mid2[0] >= (xmin * 2)) && (mid2[0] <= (xmax * 2))) && (mid2[1] >= (ymin * 2))) && (mid2[1] <= (ymax * 2)));} public static void main( String[] args){ in = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); new TwoSquares().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());} } }
4	public class C{ void run()throws IOException { int n = ni(),m = ni(),k = ni(),q = (n * m),h = 0,t = 0,inf = 123456;  int[] x = new int[q],y = new int[q];  int[][] d = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) d[i][j] = inf; for ( int i = 0;(i < k);i++) { int u = (ni() - 1),v = (ni() - 1); d[u][v] = 0; x[t] = u; y[t] = v; t++; }if ( (k < q)) while((t != h)){ int u = x[h],v = y[h];  int l = (d[u][v] + 1); h++; if ( ((u > 0) && (d[(u - 1)][v] > l))) {d[(u - 1)][v] = l; x[t] = (u - 1); y[t] = v; t++; } if ( ((u < (n - 1)) && (d[(u + 1)][v] > l))) {d[(u + 1)][v] = l; x[t] = (u + 1); y[t] = v; t++; } if ( ((v > 0) && (d[u][(v - 1)] > l))) {d[u][(v - 1)] = l; x[t] = u; y[t] = (v - 1); t++; } if ( ((v < (m - 1)) && (d[u][(v + 1)] > l))) {d[u][(v + 1)] = l; x[t] = u; y[t] = (v + 1); t++; } } int max = 0,tx = 0,ty = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (d[i][j] > max)) {max = d[i][j]; tx = i; ty = j; } pw.print((((1 + tx) + " ") + (1 + ty))); } String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} int ni()throws IOException { return Integer.parseInt(next());} PrintWriter pw ; BufferedReader br ; StringTokenizer st ; public static void main( String[] args)throws IOException { BufferedReader _br = new BufferedReader(new FileReader(new File("input.txt")));  PrintWriter _pw = new PrintWriter(new FileWriter(new File("output.txt"))); new C(_br,_pw).run(); _br.close(); _pw.close(); } public C( BufferedReader _br, PrintWriter _pw){ br = _br; pw = _pw; } }
6	public class D{ static int dp( int i, int start, int msk){ if ( (Integer.bitCount(msk) == n)) return s_e[i][start]; if ( (dp[i][start][msk] != -1)) return dp[i][start][msk]; int max = 0; for ( int k = 0;(k < n);k++) { int min = Integer.MAX_VALUE; if ( ((msk & (1 << k)) == 0)) {min = diff[i][k]; min = Math.min(min,dp(k,start,(msk | (1 << k)))); max = Math.max(max,min); } }return dp[i][start][msk] = max;} static int n ,m ,a[][] ,dp[][][] ,diff[][] ,s_e[][] ; public static void main( String[] args)throws IOException { Scanner sc = new Scanner();  PrintWriter pw = new PrintWriter(System.out); n = sc.nextInt(); m = sc.nextInt(); a = new int[n][m]; diff = new int[n][n]; s_e = new int[n][n]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) a[i][j] = sc.nextInt(); dp = new int[n][n][70000]; int ans = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) {Arrays.fill(dp[i][j],-1); diff[i][j] = Integer.MAX_VALUE; s_e[i][j] = Integer.MAX_VALUE; for ( int k = 0;(k < (m - 1));k++) {diff[i][j] = Math.min(Math.abs((a[i][k] - a[j][k])),diff[i][j]); s_e[i][j] = Math.min(Math.abs((a[i][k] - a[j][(k + 1)])),s_e[i][j]); }diff[i][j] = Math.min(Math.abs((a[i][(m - 1)] - a[j][(m - 1)])),diff[i][j]); }for ( int i = 0;(i < n);i++) ans = Math.max(ans,dp(i,i,(1 << i))); pw.print(ans); pw.close(); } static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner(){ br = new BufferedReader(new InputStreamReader(System.in)); } 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());} } }
6	public class Main{ static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static long mod = ((long)1e9 + 7); static long mod1 = 998244353; static boolean sieve[] ; static ArrayList<Integer> primes ; static long factorial[] ,invFactorial[] ; static HashSet<Pair> graph[] ; static boolean oj = (System.getProperty("ONLINE_JUDGE") != null); static int n ,T ,input[] ,type[] ; static long dp[][] ; static long dfs( int mask, int t){ if ( (dp[mask][t] != -1)) {return dp[mask][t];} int s = 0; for ( int i = 0;(i < n);i++) {if ( ((mask & (1 << i)) != 0)) {s += input[i]; } }if ( (s > T)) {return 0;} if ( (s == T)) {dp[mask][t] = 1; return dp[mask][t];} long ans = 0; for ( int i = 0;(i < n);i++) {if ( (((mask & (1 << i)) == 0) && (type[i] != t))) {ans = ((ans + dfs((mask | (1 << i)),type[i])) % mod); } }dp[mask][t] = ans; return dp[mask][t];} public static void main( String[] args)throws Exception { String st[] = nl(); n = pi(st[0]); T = pi(st[1]); input = new int[n]; type = new int[n]; for ( int i = 0;(i < n);i++) {st = nl(); input[i] = pi(st[0]); type[i] = pi(st[1]); }dp = new long[(1 << n)][4]; for ( long[] arr :dp) Arrays.fill(arr,-1); long ans = dfs(0,0); out.println(ans); out.flush(); out.close(); } static String[] nl()throws Exception { return br.readLine().split(" ");} static int pi( String str){ return Integer.parseInt(str);} static class Pair implements Comparable<Pair>{ int u ; int v ; int index = -1; public Pair( int u, int v){ this.u = u; this.v = v; } } }
4	public class P{ static int N ,M ,K ; static int dx[] = {0,0,1,-1,1,1,-1,-1}; static int dy[] = {1,-1,0,0,1,-1,1,-1}; static Pair[] b ; static boolean isValid( int x, int y){ return ((((x >= 0) && (y >= 0)) && (x < N)) && (y < M));} static class Pair{ int x ,y ; Pair( int i, int j){ x = i; y = j; } } static Pair bfs(){ Queue<Pair> q = new LinkedList<Pair>();  int[][] dist = new int[N][M]; for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) dist[i][j] = -1; for ( int i = 0;(i < K);i++) {dist[b[i].x][b[i].y] = 0; q.add(b[i]); }while(!q.isEmpty()){ Pair cur = q.remove(); for ( int d = 0;(d < 4);d++) { int X = (cur.x + dx[d]);  int Y = (cur.y + dy[d]); if ( (isValid(X,Y) && (dist[X][Y] == -1))) {dist[X][Y] = (dist[cur.x][cur.y] + 1); Pair P = new Pair(X,Y); q.add(P); } }} int max = -1;  Pair MX = null; for ( int i = 0;(i < N);i++) for ( int j = 0;(j < M);j++) {if ( (dist[i][j] > max)) {max = dist[i][j]; MX = new Pair((i + 1),(j + 1)); } }return MX;} public static void main( String[] args)throws IOException { Scanner sc = new Scanner("input.txt");  PrintWriter out = new PrintWriter("output.txt"); N = sc.nextInt(); M = sc.nextInt(); K = sc.nextInt(); b = new Pair[K]; for ( int i = 0;(i < K);i++) b[i] = new Pair((sc.nextInt() - 1),(sc.nextInt() - 1)); Pair last = bfs(); out.println(((last.x)+" " + last.y)); out.flush(); out.close(); } static class Scanner{ StringTokenizer st ; BufferedReader br ; public Scanner( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } public Scanner( String f)throws FileNotFoundException{ br = new BufferedReader(new FileReader(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 Integer.parseInt(next());} public long nextLong()throws IOException { return Long.parseLong(next());} public boolean ready()throws IOException { return br.ready();} public int[] nextIntArray( int n)throws IOException { int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = nextInt(); return a;} public long[] nextLongArray( int n)throws IOException { long[] a = new long[n]; for ( int i = 0;(i < n);i++) a[i] = nextLong(); return a;} } }
2	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){ long a = ((((2L * r) * r) + (2 * r)) + 1);  int w ; if ( ((w = (1 - (x - r))) > 0)) a -= ((long)w * w); if ( ((w = (1 - (y - r))) > 0)) a -= ((long)w * w); if ( ((w = ((x + r) - n)) > 0)) a -= ((long)w * w); if ( ((w = ((y + r) - n)) > 0)) a -= ((long)w * w); if ( ((w = (((r - 1) - (x - 1)) - (y - 1))) > 0)) a += (((long)w * (w + 1)) / 2); if ( ((w = (((r - 1) - (x - 1)) - (n - y))) > 0)) a += (((long)w * (w + 1)) / 2); if ( ((w = (((r - 1) - (n - x)) - (y - 1))) > 0)) a += (((long)w * (w + 1)) / 2); if ( ((w = (((r - 1) - (n - x)) - (n - y))) > 0)) a += (((long)w * (w + 1)) / 2); return a;} void main(){ int n = sc.nextInt();  int x = sc.nextInt();  int y = sc.nextInt();  int c = sc.nextInt();  int lower = -1,upper = c; while(((upper - lower) > 1)){ int r = ((lower + upper) / 2); if ( (count(n,x,y,r) >= c)) upper = r; else lower = r; }println(upper); } }
6	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);  TaskG1 solver = new TaskG1(); solver.solve(1,in,out); out.close(); } static class TaskG1{ final int mod = ((int)1e9 + 7); int[][][] dp ; int rec( int mask, int time, int T, int genre, int[] ts, int[] gs){ if ( (time > T)) return 0; if ( (time == T)) return 1; if ( (mask == ((1 << ts.length) - 1))) return 0; int res = dp[genre][time][mask]; if ( (res != -1)) return res; res = 0; for ( int i = 0;(i < ts.length);i++) {if ( (((mask & (1 << i)) == 0) && ((mask == 0) || (gs[i] != genre)))) {res += rec((mask | (1 << i)),(time + ts[i]),T,gs[i],ts,gs); if ( (res >= mod)) res -= mod; } }return dp[genre][time][mask] = res;} public void solve( int testNumber, InputReader in, PrintWriter out){ int n = in.nextInt();  int[] ts = new int[n];  int[] gs = new int[n];  int T = in.nextInt(); for ( int i = 0;(i < n);i++) {ts[i] = in.nextInt(); gs[i] = (in.nextInt() - 1); }dp = new int[3][T][(1 << n)]; for ( int[][] aux :dp) {for ( int[] aux2 :aux) Arrays.fill(aux2,-1); } int ans = rec(0,0,T,0,ts,gs); out.println(ans); } } static class InputReader{ private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputStream stream ; public InputReader( InputStream stream){ this.stream = stream; } private boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isWhitespace(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isWhitespace(c));return (res * sgn);} } }
1	public class C{ static StringTokenizer st ; static BufferedReader br ; static PrintWriter pw ; public static void main( String[] args)throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n = nextInt();  char[] a = next().toCharArray();  int[] cnt = new int[256]; for ( int i = 0;(i < n);i++) {cnt[a[i]]++; } int alldiff = 0; for ( int i = 0;(i < 256);i++) {if ( (cnt[i] > 0)) alldiff++; }Arrays.fill(cnt,0); int diff = 0,right = -1,ans = (n + 5); for ( int i = 0;(i < n);i++) {if ( (right < i)) {cnt[a[i]]++; diff = 1; right = i; } while(((right < (n - 1)) && (diff < alldiff))){right++; cnt[a[right]]++; if ( (cnt[a[right]] == 1)) diff++; }if ( ((diff == alldiff) && (((right - i) + 1) < ans))) {ans = ((right - i) + 1); } cnt[a[i]]--; if ( (cnt[a[i]] == 0)) diff--; }System.out.println(ans); pw.close(); } static private int nextInt()throws IOException { return Integer.parseInt(next());} static private String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken();} }
0	public class Main{ public static void main( String[] args)throws IOException { new Main().solve(); } void solve()throws IOException { MyReader in = new MyReader();  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt(); out.print("0 0 "); out.print(n); out.close(); } } class MyReader{ private BufferedReader in ; String[] parsed ; int index = 0; public MyReader(){ in = new BufferedReader(new InputStreamReader(System.in)); } public int nextInt()throws NumberFormatException,IOException { if ( ((parsed == null) || (parsed.length == index))) {read(); } return Integer.parseInt(parsed[index++]);} private void read()throws IOException { parsed = in.readLine().split(" "); index = 0; } public String readLine()throws IOException { return in.readLine();} }
3	public class C{ public static void main( String[] args){ try(Scanner sc=new Scanner(System.in)){final int N = sc.nextInt();  String[] ins = new String[N]; for ( int i = 0;(i < N);i++) {ins[i] = sc.next(); }final long MOD = 1000000007;  long[] DP = new long[N];  long[] nextDP = new long[N]; DP[0] = 1; for ( int i = 1;(i < N);i++) {Arrays.fill(nextDP,0); if ( "f".equals(ins[(i - 1)])) {for ( int j = 0;(j < (N - 1));j++) {nextDP[(j + 1)] += DP[j]; nextDP[(j + 1)] %= MOD; }} else {for ( int j = (N - 1);(j >= 0);j--) {nextDP[j] += DP[j]; nextDP[j] %= MOD; if ( (j < (N - 1))) {nextDP[j] += nextDP[(j + 1)]; nextDP[j] %= MOD; } }}{ long[] tmp = DP; DP = nextDP; nextDP = tmp; }} long answer = 0; for ( int i = 0;(i < N);i++) {answer += DP[i]; answer %= MOD; }System.out.println(answer); }} public static class Scanner implements Closeable{ private BufferedReader br ; private StringTokenizer tok ; public Scanner( InputStream is){ br = new BufferedReader(new InputStreamReader(is)); } private void getLine(){ try{while(!hasNext()){tok = new StringTokenizer(br.readLine()); } }catch (IOException e){ } } private boolean hasNext(){ return ((tok != null) && tok.hasMoreTokens());} public String next(){ getLine(); return tok.nextToken();} public int nextInt(){ return Integer.parseInt(next());} public void close(){ try{br.close(); }catch (IOException e){ } } } }
1	public class A{ private BufferedReader in ; private StringTokenizer st ; void solve()throws IOException { int n = nextInt();  int i = 0;  int[] nums = new int[n];  int numeven = 0;  int numodd = 0; while((n-- > 0)){nums[i] = nextInt(); if ( ((nums[i] % 2) == 0)) numeven++; else numodd++; i++; }for ( int j = 0;(j < nums.length);j++) {if ( ((numeven == 1) && ((nums[j] % 2) == 0))) {System.out.println((j + 1)); break;} if ( ((numodd == 1) && ((nums[j] % 2) != 0))) {System.out.println((j + 1)); break;} }} A()throws IOException{ in = new BufferedReader(new InputStreamReader(System.in)); eat(""); solve(); } private void eat( String str){ st = new StringTokenizer(str); } String next()throws IOException { while(!st.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) {return null;} eat(line); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args)throws IOException { new A(); } int gcd( int a, int b){ if ( (b > a)) return gcd(b,a); if ( (b == 0)) return a; return gcd(b,(a % b));} }
4	public class Contest35_3{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new FileReader("input.txt"));  String[] s = in.readLine().split(" ");  int n = Integer.parseInt(s[0]);  int m = Integer.parseInt(s[1]);  int k = Integer.parseInt(in.readLine()); s = in.readLine().split(" "); Point[] inp = new Point[k];  int p = 0; for ( int i = 0;(i < k);i++) {inp[i] = new Point(Integer.parseInt(s[p++]),Integer.parseInt(s[p++])); } int max = -1;  int maxx = -1;  int maxy = -1;  int i ;  int j ,dist ; for ( i = 1;(i <= n);i++) {for ( j = 1;(j <= m);j++) {dist = 1000000; for ( int l = 0;(l < inp.length);l++) {dist = Math.min((Math.abs((inp[l].x - i)) + Math.abs((inp[l].y - j))),dist); }if ( (dist > max)) {max = dist; maxx = i; maxy = j; } }} String res = (((maxx + " ") + maxy) + "\n");  FileWriter out = new FileWriter(new File("output.txt")); out.append(res); out.flush(); out.close(); } }
4	public class Main{ int n ,m ; int d[][] ; Queue<int[]> q = new LinkedList<int[]>(); int cur[] ; public void run()throws Exception { Scanner in = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt")); n = in.nextInt(); m = in.nextInt(); int k = in.nextInt(); d = new int[n][m]; for ( int i = 0;(i < n);i++) Arrays.fill(d[i],(Integer.MAX_VALUE / 2)); for ( int i = 0;(i < k);i++) { int x = (in.nextInt() - 1);  int y = (in.nextInt() - 1); d[x][y] = 0; q.add(new int[]{x,y}); }while((q.size() > 0)){cur = q.poll(); int x = cur[0];  int y = cur[1]; add(x,(y + 1)); add((x + 1),y); add((x - 1),y); add(x,(y - 1)); } int max = 0;  int x = 0;  int y = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (max < d[i][j])) {max = d[i][j]; x = i; y = j; } out.println((((x + 1) + " ") + (y + 1))); out.close(); } private void add( int x, int y){ if ( ((x < 0) || (y < 0))) return ; if ( ((x >= n) || (y >= m))) return ; if ( (d[x][y] > (d[cur[0]][cur[1]] + 1))) {d[x][y] = (d[cur[0]][cur[1]] + 1); q.add(new int[]{x,y}); } } public static void main( String[] args)throws Exception { new Main().run(); } }
1	public class A{ public static void main( String[] args){ new A().run(); } private void run(){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int ce = 0;  int co = 0;  int le = 0;  int lo = 0; for ( int i = 0;(i < n);i++) { int x = sc.nextInt(); if ( ((x % 2) == 0)) {ce++; le = (i + 1); } else {co++; lo = (i + 1); }}System.out.println(((ce == 1)?le:lo)); } }
6	public class Main{ void solve(){ int n = ni(),m = ni();  int a[][] = new int[(n + 1)][(m + 1)]; for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= m);j++) a[i][j] = ni(); if ( (n == 1)) { int mn = Integer.MAX_VALUE; for ( int i = 1;(i < m);i++) mn = Math.min(mn,Math.abs((a[1][i] - a[1][(i + 1)]))); pw.println(mn); return ;} mn1 = new int[(n + 1)][(n + 1)]; mn2 = new int[(n + 1)][(n + 1)]; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= n);j++) {if ( (i == j)) continue; mn1[i][j] = mn2[i][j] = Integer.MAX_VALUE; for ( int k = 1;(k <= m);k++) {mn1[i][j] = Math.min(mn1[i][j],Math.abs((a[i][k] - a[j][k]))); }for ( int k = 1;(k < m);k++) {mn2[i][j] = Math.min(mn2[i][j],Math.abs((a[i][(k + 1)] - a[j][k]))); }}}dp = new int[17][(1 << 16)][17]; for ( int i = 1;(i < 17);i++) for ( int j = 0;(j < (1 << 16));j++) Arrays.fill(dp[i][j],-1); int ans = 0; for ( int i = 1;(i <= n);i++) {ans = Math.max(ans,go(2,(1 << (i - 1)),i,i,n)); }pw.println(ans); } int mn1[][] ,mn2[][] ; int dp[][][] ; int go( int i, int mask, int prev, int first, int n){ if ( (i > n)) {return mn2[first][prev];} if ( (dp[first][mask][prev] != -1)) return dp[first][mask][prev]; int cc = 0; for ( int k = 1;(k <= n);k++) {if ( ((mask & (1 << (k - 1))) == 0)) {cc = Math.max(cc,Math.min(mn1[prev][k],go((i + 1),(mask | (1 << (k - 1))),k,first,n))); } }dp[first][mask][prev] = cc; return cc;} long M = ((long)1e9 + 7); InputStream is ; PrintWriter pw ; String INPUT = ""; void run()throws Exception { is = (INPUT.isEmpty()?System.in:new ByteArrayInputStream(INPUT.getBytes())); pw = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); pw.flush(); if ( !INPUT.isEmpty()) tr(((System.currentTimeMillis() - s) + "ms")); } public static void main( String[] args)throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0,ptrbuf = 0; 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++];} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private int ni(){ 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(); }} private boolean oj = (System.getProperty("ONLINE_JUDGE") != null); private void tr( Object... o){ if ( (INPUT.length() > 0)) System.out.println(Arrays.deepToString(o)); } }
5	public class C implements Runnable{ private void Solution()throws IOException { int n = nextInt(),max = 0,maxi = 0;  ArrayList<Integer> mas = new ArrayList<Integer>(); for ( int i = 0;(i < n);i++) { int num = nextInt(); if ( (num > max)) {max = num; maxi = i; } mas.add(num); }mas.remove(maxi); mas.add(((max == 1)?2:1)); Collections.shuffle(mas); Collections.sort(mas); for ( int i = 0;(i < n);i++) System.out.print((mas.get(i) + " ")); } public static void main( String[] args){ new C().run(); } BufferedReader in ; StringTokenizer tokenizer ; public void run(){ try{in = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; Solution(); in.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens()))tokenizer = new StringTokenizer(in.readLine()); return tokenizer.nextToken();} }
3	public class Main{ static int mod = (int)(1e9 + 7); static int MAX = ((int)2e5 + 5); static void solve(){ int n = i();  String[] s = new String[n]; for ( int i = 0;(i < n);i++) {s[i] = s(); } int[][] dp = new int[n][n]; dp[0][0] = 1; for ( int i = 1;(i < n);i++) {if ( s[(i - 1)].equals("f")) {for ( int j = (i - 1);(j >= 0);j--) {dp[i][(j + 1)] = dp[(i - 1)][j]; }} else { int suff = 0; for ( int j = (i - 1);(j >= 0);j--) {suff += dp[(i - 1)][j]; if ( (suff >= mod)) suff -= mod; dp[i][j] = suff; }}} int sum = 0; for ( int i = 0;(i < n);i++) {sum = (sum + dp[(n - 1)][i]); if ( (sum >= mod)) sum -= mod; }out.println(sum); out.close(); } static InputReader sc = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main( String[] args){ new Thread(null,new Runnable(){},"1",(1 << 26)).start(); } static long gcd( long x, long y){ if ( (y == 0)) return x; else return gcd(y,(x % y));} static int gcd( int x, int y){ if ( (y == 0)) return x; else return gcd(y,(x % y));} static long gcdExtended( long a, long b, long[] x){ if ( (a == 0)) {x[0] = 0; x[1] = 1; return b;} long[] y = new long[2];  long gcd = gcdExtended((b % a),a,y); x[0] = (y[1] - ((b / a) * y[0])); x[1] = y[0]; return gcd;} static int abs( int a, int b){ return (int)Math.abs((a - b));} public static long abs( long a, long b){ return (long)Math.abs((a - b));} static class InputReader{ private final InputStream stream ; private final byte[] buf = new byte[8192]; private int curChar ,snumChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int snext(){ if ( (snumChars == -1)) throw (new InputMismatchException()); if ( (curChar >= snumChars)) {curChar = 0; try{snumChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (snumChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} public long nextLong(){ int c = snext(); while(isSpaceChar(c)){c = snext(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = snext(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = snext(); }while(!isSpaceChar(c));return (res * sgn);} public int[] nextIntArray( int n){ int a[] = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); }return a;} public long[] nextLongArray( int n){ long a[] = new long[n]; for ( int i = 0;(i < n);i++) {a[i] = nextLong(); }return a;} public String nextLine(){ int c = snext(); while(isSpaceChar(c))c = snext(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = snext(); }while(!isEndOfLine(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } static int i(){ return sc.nextInt();} static String s(){ return sc.nextLine();} }
3	public class C_Round_455_Div2{ static long[][] dp ; static long MOD = ((long)1e9 + 7); public static void main( String[] args){ Scanner in = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out);  int n = in.nextInt();  char[] data = new char[n]; dp = new long[n][n]; for ( long[] a :dp) {Arrays.fill(a,-1); }for ( int i = 0;(i < n);i++) {data[i] = in.next().charAt(0); }out.println(cal(0,0,data)); out.close(); } static long cal( int index, int nested, char[] data){ if ( ((index + 1) == data.length)) {return 1;} if ( (dp[index][nested] != -1)) {return dp[index][nested];} long result = 0;  boolean isLoop = (data[index] == 'f'); if ( isLoop) {result = cal((index + 1),(nested + 1),data); } else {result = cal((index + 1),nested,data); if ( (nested > 0)) {result += cal(index,(nested - 1),data); result %= MOD; } }return dp[index][nested] = result;} }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} 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 M = in.nextInt();  int[][] dist = new int[N][M]; for ( int[] ini :dist) Arrays.fill(ini,(1 << 30)); int K = in.nextInt();  Queue<Integer> q = new LinkedList<Integer>(); for ( int k = 0;(k < K);++k) { int r = (in.nextInt() - 1);  int c = (in.nextInt() - 1); dist[r][c] = 0; q.offer(r); q.offer(c); } int[] dx = new int[]{1,-1,0,0};  int[] dy = new int[]{0,0,1,-1}; while(!q.isEmpty()){ int rr = q.poll();  int cc = q.poll(); for ( int a = 0;(a < 4);++a) { int x = (dx[a] + rr);  int y = (dy[a] + cc); if ( ((((x >= 0) && (x < N)) && (y >= 0)) && (y < M))) {if ( (dist[x][y] > (dist[rr][cc] + 1))) {dist[x][y] = (dist[rr][cc] + 1); q.offer(x); q.offer(y); } } }} int max = 0; for ( int i = 0;(i < N);++i) for ( int j = 0;(j < M);++j) max = Math.max(max,dist[i][j]); for ( int i = 0;(i < N);++i) {for ( int j = 0;(j < M);++j) {if ( (max == dist[i][j])) {out.println((((i + 1) + " ") + (j + 1))); return ;} }}} } 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());} } }
5	public class R015A{ final double EPS = 1e-9; boolean isEqual( double x, double y){ return (Math.abs((x - y)) <= (EPS * Math.max(Math.abs(x),Math.abs(y))));} class Pair implements Comparable<Pair>{ double left ; double right ; Pair( double left, double right){ this.left = left; this.right = right; } } public R015A(){ } private void process(){ Scanner scanner = new Scanner(System.in);  int n = scanner.nextInt();  int t = scanner.nextInt();  int[] x = new int[n];  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {x[i] = scanner.nextInt(); a[i] = scanner.nextInt(); } List<Pair> pairs = new ArrayList<Pair>(); for ( int i = 0;(i < n);i++) { double left = (x[i] - (a[i] / 2.0));  double right = (x[i] + (a[i] / 2.0)); pairs.add(new Pair(left,right)); }Collections.sort(pairs); Set<Pair> newPairs = new HashSet<Pair>(); newPairs.add(new Pair((pairs.get(0).left - t),pairs.get(0).left)); for ( int i = 0;(i < (pairs.size() - 1));i++) {if ( ((pairs.get((i + 1)).left - pairs.get(i).right) >= t)) {newPairs.add(new Pair(pairs.get(i).right,(pairs.get(i).right + t))); newPairs.add(new Pair((pairs.get((i + 1)).left - t),pairs.get((i + 1)).left)); } }newPairs.add(new Pair(pairs.get((pairs.size() - 1)).right,(pairs.get((pairs.size() - 1)).right + t))); System.out.println(newPairs.size()); } public static void main( String[] args){ new R015A().process(); } }
4	public class C{ static private boolean marked[][] ; public static void main( String[] args)throws Exception { File file = new File("input.txt");  Scanner s = new Scanner(file);  int n = s.nextInt();  int m = s.nextInt(); marked = new boolean[(n + 1)][(m + 1)]; int k = s.nextInt();  Queue<Point> queue = new LinkedList<Point>(); for ( int i = 0;(i < k);++i) { int tempX = s.nextInt();  int tempY = s.nextInt(); marked[tempX][tempY] = true; queue.add(new Point(tempX,tempY)); } Point c = null; while(!queue.isEmpty()){c = queue.poll(); if ( ((c.x > 1) && !marked[(c.x - 1)][c.y])) {marked[(c.x - 1)][c.y] = true; queue.add(new Point((c.x - 1),c.y)); } if ( ((c.y > 1) && !marked[c.x][(c.y - 1)])) {marked[c.x][(c.y - 1)] = true; queue.add(new Point(c.x,(c.y - 1))); } if ( ((c.x < n) && !marked[(c.x + 1)][c.y])) {marked[(c.x + 1)][c.y] = true; queue.add(new Point((c.x + 1),c.y)); } if ( ((c.y < m) && !marked[c.x][(c.y + 1)])) {marked[c.x][(c.y + 1)] = true; queue.add(new Point(c.x,(c.y + 1))); } } PrintWriter out = new PrintWriter(new File("output.txt")); out.println(((c.x + " ") + c.y)); out.close(); } static class Point{ int x ; int y ; public Point( int x, int y){ this.x = x; this.y = y; } } }
3	public class HelloWorld{ public static void main( String[] args){ final long MOD = 1000000007;  Scanner scan = new Scanner(System.in);  int now = 1;  int maxStatements = scan.nextInt();  long[] dp = new long[(maxStatements + 1)]; dp[now] = 1; while((maxStatements > 0)){ String add = scan.next(); if ( add.equals("f")) {now++; } else {for ( int k = 1;(k <= now);k++) {dp[k] = ((dp[k] + dp[(k - 1)]) % MOD); }}maxStatements--; }System.out.println(dp[now]); } }
1	public class TaskB{ public static int strIndex ; public static void main( String[] args)throws IOException { Scanner scanner = new Scanner(System.in);  int n = scanner.nextInt();  char[] s = scanner.next().toCharArray();  int[][] r = new int[n][54];  Set<Character> chars = new HashSet<>(); for ( int i = 0;(i < n);++i) chars.add(s[i]); List<Character> all = new ArrayList<>(); for ( Character c :chars) all.add(c); for ( int i = (n - 1);(i >= 0);--i) {for ( int j = 0;(j < 54);++j) {if ( (i == (n - 1))) {r[i][j] = -1; } else {r[i][j] = r[(i + 1)][j]; }}r[i][getCode(s[i])] = i; } int res = n; for ( int i = 0;(i < n);++i) { int mx = 1;  boolean fl = false; for ( Character c :all) {if ( (r[i][getCode(c)] == -1)) {fl = true; break;} mx = Math.max(mx,((r[i][getCode(c)] - i) + 1)); }if ( fl) {System.out.println(res); return ;} res = Math.min(res,mx); }System.out.println(res); scanner.close(); } public static int getCode( char a){ if ( Character.isUpperCase(a)) return (a - 'A'); return ((a - 'a') + 26);} }
6	public class ElongatedMatrix{ static private int n ; static private int[][] minCost ; static private int[][] minCostEndpoints ; static private HashMap<Integer,Integer> costs = new HashMap<>(); public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  int[] params = Arrays.stream(br.readLine().split(" ")).mapToInt((x)->Integer.parseInt(x)).toArray(); n = params[0]; int m = params[1];  int[][] matrix = new int[n][m]; for ( int i = 0;(i < n);i++) {matrix[i] = Arrays.stream(br.readLine().split(" ")).mapToInt((x)->Integer.parseInt(x)).toArray(); }minCost = new int[n][n]; minCostEndpoints = new int[n][n]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( (i > j)) {minCost[i][j] = Integer.MAX_VALUE; for ( int k = 0;(k < m);k++) { int diff = Math.abs((matrix[i][k] - matrix[j][k])); if ( (diff < minCost[i][j])) {minCost[i][j] = diff; } }minCost[j][i] = minCost[i][j]; } minCostEndpoints[i][j] = Integer.MAX_VALUE; for ( int k = 0;(k < (m - 1));k++) { int diff = Math.abs((matrix[i][(k + 1)] - matrix[j][k])); if ( (diff < minCostEndpoints[i][j])) {minCostEndpoints[i][j] = diff; } }}} int maxCost = ((n == 1)?minCostEndpoints[0][0]:0); for ( int i = 0;(i < n);i++) {costs.clear(); for ( int j = 0;(j < n);j++) {if ( (i != j)) { int bitmask = ((1 << i) | (1 << j));  int state = (bitmask + (j << 16)); costs.put(state,minCost[i][j]); } }for ( int j = 0;(j < n);j++) {if ( (i != j)) {if ( (minCostEndpoints[i][j] <= maxCost)) {continue;} else { int pathCost = Math.min(minCostEndpoints[i][j],findMaxCost(i,j,((1 << n) - 1))); maxCost = Math.max(maxCost,pathCost); }} }}System.out.println(maxCost); br.close(); } static private int findMaxCost( int st, int end, int set){ int state = (set + (end << 16)); if ( costs.containsKey(state)) {return costs.get(state);} int maxCost = 0; for ( int i = 0;(i < n);i++) {if ( (((i != st) && (i != end)) && ((set & (1 << i)) != 0))) { int setWithoutEnd = (set - (1 << end));  int pathCost = Math.min(findMaxCost(st,i,setWithoutEnd),minCost[i][end]); maxCost = Math.max(pathCost,maxCost); } }costs.put(state,maxCost); return maxCost;} }
2	public class SolutionB{ BufferedReader in ; StringTokenizer str ; PrintWriter out ; String SK ; String next()throws IOException { while(((str == null) || str.hasMoreTokens())){SK = in.readLine(); if ( (SK == null)) return null; str = new StringTokenizer(SK); }return str.nextToken();} long nextLong()throws IOException { return Long.parseLong(next());} public static void main( String[] args)throws IOException { new SolutionB().run(); } void run()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } void solve()throws IOException { long n = nextLong();  long k = nextLong();  long m = num1(k); if ( (m < n)) {out.println(-1); return ;} if ( (m == n)) {out.println((k - 1)); return ;} long ans = binS(n,k); out.println((k - ans)); } long num1( long k){ long r = (((k * (k + 1)) / 2) - 1); r = (r - (k - 2)); return r;} long num2( long k){ return (num1(k) - 1);} long binS( long n, long k){ long start ,end ,mid ; start = 2; end = k; long ret = -1; while((start <= end)){mid = ((start + end) / 2); if ( ((num1(k) - num2(mid)) == n)) {return mid;} else if ( ((num1(k) - num2(mid)) < n)) {end = (mid - 1); } else {ret = mid; start = (mid + 1); }}return ret;} }
4	public class Main implements Runnable{ public void _main()throws IOException { int height = nextInt();  int width = nextInt();  int k = nextInt();  int[] r = new int[k];  int[] c = new int[k]; for ( int i = 0;(i < k);i++) {r[i] = (nextInt() - 1); c[i] = (nextInt() - 1); } int res = 0,R = r[0],C = c[0]; for ( int i = 0;(i < height);i++) for ( int j = 0;(j < width);j++) { int cur = Integer.MAX_VALUE; for ( int z = 0;(z < k);z++) cur = Math.min(cur,(Math.abs((i - r[z])) + Math.abs((j - c[z])))); if ( (res < cur)) {res = cur; R = i; C = j; } }out.print((((R + 1) + " ") + (C + 1))); } private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; private String next()throws IOException { while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(in.readLine()); return st.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args){ new Thread(new Main()).start(); } }
3	public class Main{ static private void solve(){ int n = ni();  String[] lines = new String[n]; for ( int i = 0;(i < n);i++) {lines[i] = next(); } int mod = (1000000000 + 7);  long[][] dp = new long[2][(n + 1)]; dp[0][0] = 1; for ( int i = 0;(i < n);i++) { int from = (i % 2);  int to = ((i + 1) % 2);  boolean flg = ((i == 0) || lines[(i - 1)].equals("s")); if ( flg) { long v = Arrays.stream(dp[from]).sum(); for ( int j = 0;(j <= n);j++) {dp[to][j] += v; dp[to][j] %= mod; v -= dp[from][j]; }} else {for ( int j = 0;(j < n);j++) {dp[to][(j + 1)] += dp[from][j]; dp[to][(j + 1)] %= mod; }}Arrays.fill(dp[from],0); } long ret = (Arrays.stream(dp[(n % 2)]).sum() % mod); System.out.println(ret); } public static void main( String[] args){ new Thread(null,new Runnable(){},"",64000000).start(); } static private java.io.InputStream is = System.in; static private java.io.PrintWriter out = new java.io.PrintWriter(System.out); static private java.util.StringTokenizer tokenizer = null; static private java.io.BufferedReader reader ; public static String next(){ while(((tokenizer == null) || !tokenizer.hasMoreTokens())){try{tokenizer = new java.util.StringTokenizer(reader.readLine()); }catch (Exception e){ throw (new RuntimeException(e));} }return tokenizer.nextToken();} static private long nl(){ return Long.parseLong(next());} static private int ni(){ return Integer.parseInt(next());} static private void tr( Object... o){ if ( (is != System.in)) System.out.println(java.util.Arrays.deepToString(o)); } }
0	public class HexadecimalTheorem{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  PrintWriter out = new PrintWriter(System.out); out.printf("%d %d %d%n",0,0,n); out.flush(); } }
6	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]; for ( int s = (t - 1);(s >= 0);s--) for ( int m = 0;(m < n);m++) { int x = da[s][m]; if ( (x != 0)) { int s_ = (s + a); if ( (s_ <= t)) da[s_][(m + 1)] = ((da[s_][(m + 1)] + x) % MD); } }}return da;} static int[][][] solve2( int[] aa, int[] bb, int t, int na, int nb){ int[][] da = solve1(aa,t,na);  int[][][] dab = new int[(t + 1)][(na + 1)][(nb + 1)]; for ( int s = 0;(s <= t);s++) for ( int ma = 0;(ma <= na);ma++) dab[s][ma][0] = da[s][ma]; for ( int i = 0;(i < nb);i++) { int b = bb[i]; for ( int s = (t - 1);(s >= 0);s--) for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb < nb);mb++) { int x = dab[s][ma][mb]; if ( (x != 0)) { int s_ = (s + b); if ( (s_ <= t)) dab[s_][ma][(mb + 1)] = ((dab[s_][ma][(mb + 1)] + x) % MD); } }}return dab;} static long power( int a, int k){ if ( (k == 0)) return 1; long p = power(a,(k / 2)); p = ((p * p) % MD); if ( ((k % 2) == 1)) p = ((p * a) % MD); return p;} static int[] ff ,gg ; static int ch( int n, int k){ return (int)(((((long)ff[n] * gg[(n - k)]) % MD) * gg[k]) % MD);} static int[][][] init( int n, int na, int nb, int nc){ ff = new int[(n + 1)]; gg = new int[(n + 1)]; for ( int i = 0,f = 1;(i <= n);i++) {ff[i] = f; gg[i] = (int)power(f,(MD - 2)); f = (int)(((long)f * (i + 1)) % MD); } int[][][] dp = new int[(na + 1)][(nb + 1)][(nc + 1)]; for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) for ( int mc = 0;(mc <= nc);mc++) { int x = (int)(((((((long)ff[((ma + mb) + mc)] * gg[ma]) % MD) * gg[mb]) % MD) * gg[mc]) % MD); for ( int ma_ = ((ma == 0)?0:1);(ma_ <= ma);ma_++) { int cha = ((ma == 0)?1:ch((ma - 1),(ma_ - 1))); for ( int mb_ = ((mb == 0)?0:1);(mb_ <= mb);mb_++) { int chb = ((mb == 0)?1:ch((mb - 1),(mb_ - 1))); for ( int mc_ = ((mc == 0)?0:1);(mc_ <= mc);mc_++) { int chc = ((mc == 0)?1:ch((mc - 1),(mc_ - 1)));  int y = dp[ma_][mb_][mc_]; if ( (y == 0)) continue; x = (int)((x - ((((((long)y * cha) % MD) * chb) % MD) * chc)) % MD); }}}if ( (x < 0)) x += MD; dp[ma][mb][mc] = x; }for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) for ( int mc = 0;(mc <= nc);mc++) dp[ma][mb][mc] = (int)(((((((long)dp[ma][mb][mc] * ff[ma]) % MD) * ff[mb]) % MD) * ff[mc]) % MD); return dp;} 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 t = Integer.parseInt(st.nextToken());  int[] aa = new int[n];  int[] bb = new int[n];  int[] cc = new int[n];  int na = 0,nb = 0,nc = 0; for ( int i = 0;(i < n);i++) {st = new StringTokenizer(br.readLine()); int a = Integer.parseInt(st.nextToken());  int g = Integer.parseInt(st.nextToken()); if ( (g == 1)) aa[na++] = a; else if ( (g == 2)) bb[nb++] = a; else cc[nc++] = a; } int[][][] dp = init(n,na,nb,nc);  int[][][] dab = solve2(aa,bb,t,na,nb);  int[][] dc = solve1(cc,t,nc);  int ans = 0; for ( int tab = 0;(tab <= t);tab++) { int tc = (t - tab); for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) { int xab = dab[tab][ma][mb]; if ( (xab == 0)) continue; for ( int mc = 0;(mc <= nc);mc++) { int xc = dc[tc][mc]; if ( (xc == 0)) continue; ans = (int)((ans + (((long)xab * xc) * dp[ma][mb][mc])) % MD); }}}System.out.println(ans); } }
6	public class cf1185g1_3{ public static void main( String[] args)throws IOException { int n = rni(),t = ni(),song[][] = new int[n][2]; for ( int i = 0;(i < n);++i) {song[i][0] = rni(); song[i][1] = (ni() - 1); } int dp[][] = new int[(1 << n)][4],sum[] = new int[(1 << n)],ans = 0; dp[0][3] = 1; for ( int i = 0;(i < (1 << n));++i) {for ( int j = 0;(j < 4);++j) {for ( int k = 0;(k < n);++k) {if ( (((i & (1 << k)) == 0) && (song[k][1] != j))) {dp[(i | (1 << k))][song[k][1]] = madd(dp[(i | (1 << k))][song[k][1]],dp[i][j]); sum[(i | (1 << k))] = (sum[i] + song[k][0]); } }}}for ( int i = 0;(i < (1 << n));++i) {if ( (sum[i] == t)) {ans = madd(ans,dp[i][0],dp[i][1],dp[i][2]); } }prln(ans); close(); } static int mmod = 1000000007; static int madd( int a, int b){ return ((a + b) % mmod);} static int madd( int... a){ int ans = a[0]; for ( int i = 1;(i < a.length);++i) {ans = madd(ans,a[i]); }return ans;} static int mmul( int a, int b){ return (int)(((long)a * b) % mmod);} static int mmul( int... a){ int ans = a[0]; for ( int i = 1;(i < a.length);++i) {ans = mmul(ans,a[i]); }return ans;} static BufferedReader __i = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __o = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input ; static Random __r = new Random(); static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final long LMAX = 9223372036854775807L; static int gcf( int a, int b){ return ((b == 0)?a:gcf(b,(a % b)));} static long gcf( long a, long b){ return ((b == 0)?a:gcf(b,(a % b)));} static int[] exgcd( int a, int b){ if ( (b == 0)) return new int[]{1,0}; int[] y = exgcd(b,(a % b)); return new int[]{y[1],(y[0] - (y[1] * (a / b)))};} static long[] exgcd( long a, long b){ if ( (b == 0)) return new long[]{1,0}; long[] y = exgcd(b,(a % b)); return new long[]{y[1],(y[0] - (y[1] * (a / b)))};} static int randInt( int min, int max){ return (__r.nextInt(((max - min) + 1)) + min);} static void shuffle( int[] a){ int n = (a.length - 1); for ( int i = 0;(i < n);++i) { int ind = randInt(i,n);  int swap = a[i]; a[i] = a[ind]; a[ind] = swap; }} static void shuffle( long[] a){ int n = (a.length - 1); for ( int i = 0;(i < n);++i) { int ind = randInt(i,n);  long swap = a[i]; a[i] = a[ind]; a[ind] = swap; }} static void shuffle( double[] a){ int n = (a.length - 1); for ( int i = 0;(i < n);++i) { int ind = randInt(i,n);  double swap = a[i]; a[i] = a[ind]; a[ind] = swap; }} static void r()throws IOException { input = new StringTokenizer(rline()); } static String rline()throws IOException { return __i.readLine();} static String n(){ return input.nextToken();} static int rni()throws IOException { r(); return ni();} static int ni(){ return Integer.parseInt(n());} static long nl(){ return Long.parseLong(n());} static double nd(){ return Double.parseDouble(n());} static void pr( int i){ __o.print(i); } static void prln( int i){ __o.println(i); } static void pr( long l){ __o.print(l); } static void prln( long l){ __o.println(l); } static void pr( double d){ __o.print(d); } static void prln( double d){ __o.println(d); } static void pr( char c){ __o.print(c); } static void prln( char c){ __o.println(c); } static void pr( char[] s){ __o.print(new String(s)); } static void prln( char[] s){ __o.println(new String(s)); } static void pr( String s){ __o.print(s); } static void prln( String s){ __o.println(s); } static void pr( Object o){ __o.print(o); } static void prln( Object o){ __o.println(o); } static void prln(){ __o.println(); } static void prln( int... a){ for ( int i = 0,len = (a.length - 1);(i < len);pr(a[i]),pr(' '),++i) ;if ( (a.length > 0)) prln(a[(a.length - 1)]); else prln(); } static void prln( long... a){ for ( int i = 0,len = (a.length - 1);(i < len);pr(a[i]),pr(' '),++i) ;if ( (a.length > 0)) prln(a[(a.length - 1)]); else prln(); } static void prln( double... a){ for ( int i = 0,len = (a.length - 1);(i < len);pr(a[i]),pr(' '),++i) ;if ( (a.length > 0)) prln(a[(a.length - 1)]); else prln(); } static <T> void prln( Collection<T> c){ int n = (c.size() - 1);  Iterator<T> iter = c.iterator(); for ( int i = 0;(i < n);pr(iter.next()),pr(' '),++i) ;if ( (n >= 0)) prln(iter.next()); else prln(); } static void flush(){ __o.flush(); } static void close(){ __o.close(); } }
2	public class B{ public static void main( String[] argv){ Scanner in = new Scanner(System.in);  long n = in.nextLong();  long k = in.nextLong();  long max = (((k * (k - 1)) / 2L) + 1L);  long ans = -1; if ( (n == 1)) {System.out.println(0); return ;} if ( (max < n)) {ans = -1; } else if ( (max == n)) {ans = (k - 1); } else {if ( (k >= n)) {ans = 1; } else { long low = 1;  long high = (k - 1); while((high > (low + 1))){ long mid = ((low + high) / 2);  long sum = ((((mid + (k - 1)) * (k - mid)) / 2) + 1); if ( (sum >= n)) {low = mid; } else {high = mid; }}ans = (k - low); }}System.out.println(ans); return ;} }
5	public class Prob015A{ public static void main( String[] Args){ Scanner scan = new Scanner(System.in);  int numHouses = scan.nextInt();  int side = (scan.nextInt() * 2);  ArrayList<Integer> sides = new ArrayList<Integer>(); for ( int x = 0;(x < numHouses);x++) { int c = (scan.nextInt() * 2);  int s = scan.nextInt();  int l = (c - s);  int r = (c + s);  int li = Collections.binarySearch(sides,l);  int ri = Collections.binarySearch(sides,r); if ( ((li >= 0) && (ri >= 0))) {sides.remove(li); sides.remove(li); } else if ( (li >= 0)) sides.set(li,r); else if ( (ri >= 0)) sides.set(ri,l); else {sides.add((-li - 1),r); sides.add((-li - 1),l); }} int possibilities = 2; for ( int x = 1;(x < (sides.size() - 1));x += 2) if ( ((sides.get((x + 1)) - sides.get(x)) > side)) possibilities += 2; else if ( ((sides.get((x + 1)) - sides.get(x)) == side)) possibilities += 1; System.out.println(possibilities); } }
2	public class acm{ public static BigInteger n ; public static BigInteger TWO = new BigInteger("2"); public static BigInteger solve( BigInteger x, BigInteger y, BigInteger c){ BigInteger res = c.add(BigInteger.ONE).multiply(c.add(BigInteger.ONE)); res = res.add(c.multiply(c)); BigInteger k ; k = c.subtract(x.subtract(BigInteger.ONE)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.subtract(k.multiply(k)); k = c.subtract(y.subtract(BigInteger.ONE)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.subtract(k.multiply(k)); k = c.subtract(n.subtract(x)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.subtract(k.multiply(k)); k = c.subtract(n.subtract(y)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.subtract(k.multiply(k)); k = c.subtract(x.add(y).subtract(BigInteger.ONE)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO)); k = c.subtract(x.add(n).subtract(y)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO)); k = c.subtract(y.add(n).subtract(x)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO)); k = c.subtract(n.subtract(x).add(n.subtract(y)).add(BigInteger.ONE)); if ( (k.compareTo(BigInteger.ZERO) > 0)) res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO)); return res;} public static void main( String[] args){ TWO = new BigInteger("2"); Scanner in = new Scanner(System.in); n = new BigInteger(in.next()); BigInteger x = new BigInteger(in.next());  BigInteger y = new BigInteger(in.next());  BigInteger c = new BigInteger(in.next());  BigInteger left = new BigInteger("0");  BigInteger right = new BigInteger("1000000000000"); while((left.compareTo(right) < 0)){ BigInteger val = left.add(right).divide(TWO); if ( (solve(x,y,val).compareTo(c) >= 0)) right = val; else left = val.add(BigInteger.ONE); }System.out.println(left); } }
1	public class Codeshefcode{ static final long r = 1000000007; static FasterScanner ip = new FasterScanner(); static PrintWriter op = new PrintWriter(System.out); public static void main( String[] args)throws IOException { int n = ip.i();  TreeMap<Character,Integer> map = new TreeMap<Character,Integer>();  TreeSet<Character> set = new TreeSet<Character>();  char c[] = ip.S().toCharArray(); for ( char t :c) set.add(t); int size = set.size(); for ( int i = 0;(i < size);i++) map.put(set.pollFirst(),i); int a[] = new int[n]; for ( int i = 0;(i < n);i++) a[i] = map.get(c[i]); int erl[][] = new int[size][n]; for ( int i = 0;(i < size);i++) for ( int j = (n - 1);(j >= 0);j--) erl[i][j] = ((a[j] == i)?j:((j == (n - 1))?-1:erl[i][(j + 1)])); long min = Long.MAX_VALUE; for ( int i = 0;(i < n);i++) { long maxt = Long.MIN_VALUE; for ( int j = 0;(j < size);j++) if ( (erl[j][i] != -1)) maxt = Long.max(maxt,((erl[j][i] - i) + 1)); else {maxt = Long.MAX_VALUE; break;}min = Long.min(min,maxt); }op.print(min); Finish(); } static void Finish(){ op.flush(); op.close(); } } class FasterScanner{ private InputStream mIs ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public FasterScanner(){ this(System.in); } public FasterScanner( InputStream is){ mIs = is; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = mIs.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public String S(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public int i(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} }
5	public class Test{ public static void main( String[] args)throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  String[] line = reader.readLine().split(" ");  int w = Integer.valueOf(line[0]);  int h = Integer.valueOf(line[1]);  int n = Integer.valueOf(line[2]);  Request[] requests = new Request[n]; for ( int i = 0;(i < n);i++) {line = reader.readLine().split(" "); requests[i] = new Request(line[0],Integer.valueOf(line[1])); }for ( long e :solve(h,w,requests)) System.out.println(e); } static private long[] solve( int h, int w, Request[] requests){ TreeSet<Integer> hTree = new TreeSet<>();  TreeSet<Integer> wTree = new TreeSet<>();  Queue<CoordinateWithSize> hHeap = new PriorityQueue<>();  Queue<CoordinateWithSize> wHeap = new PriorityQueue<>(); hTree.add(0); hTree.add(h); wTree.add(0); wTree.add(w); hHeap.add(new CoordinateWithSize(0,h)); wHeap.add(new CoordinateWithSize(0,w)); long[] res = new long[requests.length]; for ( int i = 0;(i < requests.length);i++) { Request request = requests[i]; switch(request.type){ case "H":{if ( !hTree.contains(request.coordinate)) { int higher = hTree.higher(request.coordinate);  int lower = hTree.lower(request.coordinate); hHeap.add(new CoordinateWithSize(lower,(request.coordinate - lower))); hHeap.add(new CoordinateWithSize(request.coordinate,(higher - request.coordinate))); hTree.add(request.coordinate); } break;} case "V":{if ( !wTree.contains(request.coordinate)) { int higher = wTree.higher(request.coordinate);  int lower = wTree.lower(request.coordinate); wHeap.add(new CoordinateWithSize(lower,(request.coordinate - lower))); wHeap.add(new CoordinateWithSize(request.coordinate,(higher - request.coordinate))); wTree.add(request.coordinate); } break;} default :throw (new IllegalStateException((("Unknown type [type=" + request.type) + "]"))); } while(true){ CoordinateWithSize c = hHeap.peek(); if ( ((hTree.higher(c.coordinate) - c.coordinate) == c.size)) break; hHeap.remove(); }while(true){ CoordinateWithSize c = wHeap.peek(); if ( ((wTree.higher(c.coordinate) - c.coordinate) == c.size)) break; wHeap.remove(); }res[i] = ((1L * hHeap.peek().size) * wHeap.peek().size); }return res;} static private class CoordinateWithSize implements Comparable<CoordinateWithSize>{ private final int coordinate ; private final int size ; public CoordinateWithSize( int coordinate, int size){ this.coordinate = coordinate; this.size = size; } } static private class Request{ private final String type ; private final int coordinate ; public Request( String type, int coordinate){ this.type = type; this.coordinate = coordinate; } } }
1	public class A{ private Scanner in ; private PrintWriter out ; private String INPUT = ""; public void solve(){ int n = ni();  int[] u = new int[n];  int fe = -1,fo = -1;  int ne = -1,no = -1; for ( int i = 0;(i < n);i++) {u[i] = ni(); if ( ((u[i] % 2) == 0)) {if ( (fe == -1)) {fe = (i + 1); } else {ne = (i + 1); }} else {if ( (fo == -1)) {fo = (i + 1); } else {no = (i + 1); }}}if ( (ne > 0)) {out.println(fo); } else {out.println(fe); }} public void run()throws Exception { in = (INPUT.isEmpty()?new Scanner(System.in):new Scanner(INPUT)); out = new PrintWriter(System.out); solve(); out.flush(); } public static void main( String[] args)throws Exception { new A().run(); } private int ni(){ return Integer.parseInt(in.next());} }
2	public class B{ public static void main( String[] args)throws IOException { Scanner in = new Scanner(System.in);  long n = in.nextLong();  long k = in.nextLong(); if ( (n == 1)) {System.out.println(0); return ;} if ( (n <= k)) {System.out.println(1); return ;} long lb = 2,ub = k;  long sum = ((k * (k - 1)) / 2); if ( ((sum + 1) < n)) {System.out.println(-1); return ;} while(((ub - lb) > 1)){ long mid = ((lb + ub) / 2);  long s = (((mid - 1) * (mid - 2)) / 2); if ( ((n - ((sum - s) + 1)) < 0)) lb = mid; else ub = mid; } long rem = (n - ((sum - (((ub - 1) * (ub - 2)) / 2)) + 1));  long res = ((k - ub) + 1); if ( (rem == 0)) {System.out.println(res); return ;} rem++; if ( ((rem >= 2) && (rem < ub))) {System.out.println(-1); return ;} System.out.println((res + 1)); } }
6	public class G_PlaylistForPolycarp{ static final int mod = 1000000007; static int dp[][] ; public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));  String[] dat = br.readLine().split(" ");  int n = Integer.parseInt(dat[0]);  int T = Integer.parseInt(dat[1]);  int[] st = new int[n];  byte[] sg = new byte[n]; dp = new int[(1 << (n + 1))][4]; for ( int j = 0;(j < (1 << (n + 1)));j++) {for ( int k = 0;(k < 4);k++) {dp[j][k] = -1; }}for ( int i = 0;(i < n);i++) {dat = br.readLine().split(" "); st[i] = Integer.parseInt(dat[0]); sg[i] = Byte.parseByte(dat[1]); } short visited = 0;  int count = recur(0,visited,st,sg,T,0); bw.write((count + "\n")); bw.close(); } static private int recur( int time, short visited, int[] st, byte[] sg, int T, int last){ int count = 0; if ( (dp[visited][last] != -1)) {return dp[visited][last];} for ( int i = 0;(i < st.length);i++) {if ( (((visited & (1 << i)) == 0) && (sg[i] != last))) {if ( ((time + st[i]) == T)) {count += 1; } else if ( ((time + st[i]) < T)) { short visitedc = (short)(visited | (1 << i)); count += recur((time + st[i]),visitedc,st,sg,T,sg[i]); if ( (count > mod)) {count = (count % mod); } } } }return dp[visited][last] = (count % mod);} }
1	public class A{ public static void main( String[] args){ Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  String[] number = new String[n]; sc.nextLine(); String l = sc.nextLine(); number = l.split(" "); int oe = 1; if ( ((((Integer.valueOf(number[0]) % 2) + (Integer.valueOf(number[1]) % 2)) + (Integer.valueOf(number[2]) % 2)) > 1)) {oe = 0; } for ( int i = 0;(i < n);i++) {if ( ((Integer.valueOf(number[i]) % 2) == oe)) {System.out.println((i + 1)); break;} }} }
5	public class A{ public A()throws Exception{ int n = in.nextInt();  int[] arr = new int[n]; for ( int i = 0;(i < n);i++) arr[i] = in.nextInt(); if ( ((n == 1) && (arr[0] == 1))) {System.out.println(2); return ;} Arrays.sort(arr); if ( (arr[(n - 1)] == 1)) arr[(n - 2)] = 2; buf.append(1); for ( int i = 0;(i < (n - 1));i++) buf.append(' ').append(arr[i]); buf.append('\n'); System.out.print(buf); } Scanner in = new Scanner(System.in); StringBuilder buf = new StringBuilder(); public static void main( String[] args)throws Exception { new A(); } }
2	public class Example{ BufferedReader in ; PrintWriter out ; StringTokenizer st ; String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(in.readLine()); }catch (Exception e){ } }return st.nextToken();} long nextLong(){ return Long.parseLong(next());} public void run()throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); in.close(); } long n ,x ,y ,c ; boolean check( long z){ long res = (1 + ((2 * z) * (z + 1)));  long bx1 = ((z - x) + 1);  long by1 = ((z - y) + 1);  long bxn = ((z - n) + x);  long byn = ((z - n) + y); if ( (bx1 > 0)) {res -= (bx1 * bx1); } if ( (bxn > 0)) {res -= (bxn * bxn); } if ( (by1 > 0)) {res -= (by1 * by1); } if ( (byn > 0)) {res -= (byn * byn); } if ( (z > ((x + y) - 1))) { long m = (((z - x) - y) + 1); res += ((m * (m + 1)) / 2); } if ( (z > ((x + n) - y))) { long m = (((z - x) - n) + y); res += ((m * (m + 1)) / 2); } if ( (z > ((n - x) + y))) { long m = (((z - n) - y) + x); res += ((m * (m + 1)) / 2); } if ( (z > ((((n - x) + n) - y) + 1))) { long m = ((((z - (2 * n)) + x) + y) - 1); res += ((m * (m + 1)) / 2); } return (res >= c);} public void solve()throws Exception { n = nextLong(); x = nextLong(); y = nextLong(); c = nextLong(); long l = 0;  long r = (2 * n); while((r > l)){ long mid = ((r + l) / 2); if ( check(mid)) {r = mid; } else {l = (mid + 1); }}out.println(r); } public static void main( String[] args)throws Exception { new Example().run(); } }
5	public class A15{ final double eps = 10e-9; class Pair implements Comparable<Pair>{ int x ; int length ; Pair( int x, int length){ this.x = x; this.length = length; } } private void Solution()throws IOException { int n = nextInt(),t = nextInt(),ans = 2;  Pair[] pairs = new Pair[n]; for ( int i = 0;(i < n);i++) { int x = nextInt(),length = nextInt(); pairs[i] = new Pair(x,length); }Arrays.sort(pairs); for ( int i = 0;(i < (n - 1));i++) { double place = (((pairs[(i + 1)].x - pairs[i].x) - ((double)pairs[(i + 1)].length / 2)) - ((double)pairs[i].length / 2)); if ( (place > t)) ans += 2; else if ( ((int)(place + eps) == t)) ans++; }System.out.println(ans); } public static void main( String[] args){ new A15().run(); } BufferedReader in ; StringTokenizer tokenizer ; public void run(){ try{in = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; Solution(); in.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens()))tokenizer = new StringTokenizer(in.readLine()); return tokenizer.nextToken();} }
6	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(new BufferedWriter(new OutputStreamWriter(System.out)));  int T = 1; for ( int t = 0;(t < T);t++) { int n = Int();  int k = Int();  int A[][] = new int[n][2]; for ( int i = 0;(i < A.length);i++) {A[i][0] = Int(); A[i][1] = (Int() - 1); }Arrays.sort(A,(a,b)->{return (a[1] - b[1]);}); Solution sol = new Solution(out); sol.solution(A,k); }out.close(); } public static int Int(){ return fs.Int();} public static long Long(){ return fs.Long();} public static String Str(){ return fs.Str();} } class Solution{ PrintWriter out ; public Solution( PrintWriter out){ this.out = out; } int mod = 1000000007; long dp3[][][][] ; public void solution( int[][] A, int T){ long res = 0;  int n = A.length;  long dp1[][] = new long[(n + 1)][(T + 1)];  long dp2[][][] = new long[(n + 1)][(n + 1)][(T + 1)]; dp3 = new long[(n + 1)][(n + 1)][(n + 1)][3]; long f[] = new long[(n + 1)]; f[0] = f[1] = 1; for ( int i = 2;(i < f.length);i++) {f[i] = (f[(i - 1)] * i); f[i] %= mod; }for ( int i = 0;(i < dp3.length);i++) {for ( int j = 0;(j < dp3[0].length);j++) {for ( int k = 0;(k < dp3[0][0].length);k++) {Arrays.fill(dp3[i][j][k],-1); }}}dp1[0][0] = 1; for ( int i = 0;(i < A.length);i++) { int p = A[i][0],type = A[i][1]; if ( (type == 0)) { long newdp[][] = new long[dp1.length][dp1[0].length]; for ( int cnt = 1;(cnt <= n);cnt++) {for ( int j = 1;(j < dp1[0].length);j++) {if ( (j >= p)) {newdp[cnt][j] += dp1[(cnt - 1)][(j - p)]; newdp[cnt][j] %= mod; } }}for ( int cnt = 0;(cnt <= n);cnt++) {for ( int j = 0;(j < dp1[0].length);j++) {newdp[cnt][j] += dp1[cnt][j]; newdp[cnt][j] %= mod; }}dp1 = newdp; } else {break;}}dp2[0][0][0] = 1; for ( int i = 0;(i < A.length);i++) { int p = A[i][0],type = A[i][1]; if ( (type != 0)) { long newdp[][][] = new long[dp2.length][dp2[0].length][dp2[0][0].length]; for ( int a = 0;(a < dp2.length);a++) {for ( int b = 0;(b < dp2[0].length);b++) {for ( int j = 0;(j < dp2[0][0].length);j++) {if ( (j >= p)) {if ( (type == 1)) {if ( ((a - 1) >= 0)) {newdp[a][b][j] += dp2[(a - 1)][b][(j - p)]; } } else {if ( ((b - 1) >= 0)) {newdp[a][b][j] += dp2[a][(b - 1)][(j - p)]; } }} newdp[a][b][j] %= mod; }}}for ( int a = 0;(a < dp2.length);a++) {for ( int b = 0;(b < dp2[0].length);b++) {for ( int j = 0;(j < dp2[0][0].length);j++) {newdp[a][b][j] += dp2[a][b][j]; newdp[a][b][j] %= mod; }}}dp2 = newdp; } }dp3[1][0][0][0] = 1; dp3[0][1][0][1] = 1; dp3[0][0][1][2] = 1; dfs(n,n,n,0); dfs(n,n,n,1); dfs(n,n,n,2); for ( int i = 0;(i < dp3.length);i++) {for ( int j = 0;(j < dp3[0].length);j++) {for ( int k = 0;(k < dp3[0][0].length);k++) {for ( int cur = 0;(cur < 3);cur++) {for ( int t = 0;(t <= T);t++) { int aprice = t;  int bcprice = (T - t);  long cnt1 = dp1[i][aprice];  long cnt2 = dp2[j][k][bcprice];  long combination = dp3[i][j][k][cur];  long p1 = ((cnt1 * f[i]) % mod);  long p2 = ((((f[j] * f[k]) % mod) * cnt2) % mod);  long p3 = ((p1 * p2) % mod); res += ((p3 * combination) % mod); res %= mod; }}}}}out.println(res); } public long dfs( int a, int b, int c, int cur){ if ( (((a < 0) || (b < 0)) || (c < 0))) {return 0;} if ( (((a == 0) && (b == 0)) && (c == 0))) {return 0;} if ( (dp3[a][b][c][cur] != -1)) return dp3[a][b][c][cur]; long res = 0; if ( (cur == 0)) {res += dfs((a - 1),b,c,1); res %= mod; res += dfs((a - 1),b,c,2); res %= mod; } else if ( (cur == 1)) {res += dfs(a,(b - 1),c,0); res %= mod; res += dfs(a,(b - 1),c,2); res %= mod; } else {res += dfs(a,b,(c - 1),0); res %= mod; res += dfs(a,b,(c - 1),1); res %= mod; }res %= mod; dp3[a][b][c][cur] = res; return res;} }
3	public class Solution{ public static void main( String[] args)throws Exception { MyReader reader = new MyReader(System.in);  MyWriter writer = new MyWriter(System.out); new Solution().run(reader,writer); writer.close(); } private void run( MyReader reader, MyWriter writer)throws IOException,InterruptedException { int n = reader.nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = reader.nextString().charAt(0); } long[][] d = new long[(n + 1)][(n + 1)]; d[0][0] = 1; long mod = 1_000_000_007; for ( int i = 1;(i < n);i++) {for ( int j = (n - 1);(j >= 0);j--) {if ( (a[(i - 1)] == 'f')) {d[i][(j + 1)] = d[(i - 1)][j]; } else {d[i][j] = ((d[(i - 1)][j] + d[i][(j + 1)]) % mod); }}} long ans = 0; for ( int i = 0;(i <= n);i++) {ans += d[(n - 1)][i]; }writer.print((ans % mod)); } static class MyReader{ final BufferedInputStream in ; final int bufSize = (1 << 16); final byte buf[] = new byte[bufSize]; int i = bufSize; int k = bufSize; boolean end = false; final StringBuilder str = new StringBuilder(); MyReader( InputStream in){ this.in = new BufferedInputStream(in,bufSize); } int nextInt()throws IOException { return (int)nextLong();} int[] nextIntArray( int n)throws IOException { int[] m = new int[n]; for ( int i = 0;(i < n);i++) {m[i] = nextInt(); }return m;} long nextLong()throws IOException { int c ;  long x = 0;  boolean sign = true; while(((c = nextChar()) <= 32));if ( (c == '-')) {sign = false; c = nextChar(); } if ( (c == '+')) {c = nextChar(); } while((c >= '0')){x = ((x * 10) + (c - '0')); c = nextChar(); }return (sign?x:-x);} int nextChar()throws IOException { if ( (i == k)) {k = in.read(buf,0,bufSize); i = 0; } return ((i >= k)?-1:buf[i++]);} String nextString()throws IOException { if ( end) {return null;} str.setLength(0); int c ; while((((c = nextChar()) <= 32) && (c != -1)));if ( (c == -1)) {end = true; return null;} while((c > 32)){str.append((char)c); c = nextChar(); }return str.toString();} char[] nextCharArray()throws IOException { return nextString().toCharArray();} } static class MyWriter{ final BufferedOutputStream out ; final int bufSize = (1 << 16); final byte buf[] = new byte[bufSize]; int i = 0; final byte c[] = new byte[30]; static final String newLine = System.getProperty("line.separator"); MyWriter( OutputStream out){ this.out = new BufferedOutputStream(out,bufSize); } void print( long x)throws IOException { int j = 0; if ( ((i + 30) >= bufSize)) {flush(); } if ( (x < 0)) {buf[i++] = (byte)'-'; x = -x; } while(((j == 0) || (x != 0))){c[j++] = (byte)((x % 10) + '0'); x /= 10; }while((j-- > 0))buf[i++] = c[j]; } void print( int[] m)throws IOException { for ( int a :m) {print(a); print(' '); }} void print( long[] m)throws IOException { for ( long a :m) {print(a); print(' '); }} void print( String s)throws IOException { for ( int i = 0;(i < s.length());i++) {print(s.charAt(i)); }} void print( char x)throws IOException { if ( (i == bufSize)) {flush(); } buf[i++] = (byte)x; } void print( char[] m)throws IOException { for ( char c :m) {print(c); }} void println( String s)throws IOException { print(s); println(); } void println()throws IOException { print(newLine); } void flush()throws IOException { out.write(buf,0,i); out.flush(); i = 0; } void close()throws IOException { flush(); out.close(); } } }
4	public class Main{ public static InputStream IN ; public static OutputStream OUT ; public static PrintWriter out ; public static BufferedReader in ; public static StringTokenizer st = null; public static int ni()throws Exception { for ( ;((st == null) || !st.hasMoreTokens());) {st = new StringTokenizer(in.readLine()); }return Integer.parseInt(st.nextToken());} public static void main( String[] args)throws Exception { IN = new FileInputStream("input.txt"); OUT = new FileOutputStream("output.txt"); out = new PrintWriter(OUT); in = new BufferedReader(new InputStreamReader(IN)); int n = ni();  int m = ni();  int k = ni();  int[] x = new int[k];  int[] y = new int[k]; for ( int i = 0;(i < k);i++) {x[i] = (ni() - 1); y[i] = (ni() - 1); } int w = Integer.MIN_VALUE;  int aa = -1;  int ab = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int min = Integer.MAX_VALUE; for ( int q = 0;(q < k);q++) { int cur = (Math.abs((i - x[q])) + Math.abs((j - y[q]))); min = Math.min(cur,min); }if ( (min > w)) {w = min; aa = i; ab = j; } }}out.println((((aa + 1) + " ") + (ab + 1))); out.flush(); } }
4	public class A{ static int[] dx = {-1,0,1,0}; static int[] dy = {0,1,0,-1}; public static void main( String[] args)throws Exception { Scanner sc = new Scanner("input.txt");  PrintWriter out = new PrintWriter("output.txt");  int n = sc.nextInt(),m = sc.nextInt(),k = sc.nextInt();  int[][] dist = new int[n][m]; for ( int[] a :dist) Arrays.fill(a,-1); Queue<Point> q = new LinkedList<>(); for ( int i = 0;(i < k);i++) { int x = (sc.nextInt() - 1),y = (sc.nextInt() - 1); dist[x][y] = 0; q.add(new Point(x,y)); } int ansX = -1,ansY = -1; while(!q.isEmpty()){ Point cur = q.remove(); ansX = cur.x; ansY = cur.y; for ( int i = 0;(i < 4);i++) { int x = (cur.x + dx[i]),y = (cur.y + dy[i]); if ( (((((x != -1) && (y != -1)) && (x != n)) && (y != m)) && (dist[x][y] == -1))) {q.add(new Point(x,y)); dist[x][y] = (dist[cur.x][cur.y] + 1); } }}out.println((((ansX + 1) + " ") + (ansY + 1))); out.flush(); out.close(); } static class Scanner{ StringTokenizer st ; BufferedReader br ; public Scanner( InputStream system){ br = new BufferedReader(new InputStreamReader(system)); } public Scanner( String file)throws Exception{ br = new BufferedReader(new FileReader(file)); } 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 boolean ready()throws IOException { return br.ready();} } }
5	public class CottageVillage{ public static void main( String[] args){ Scanner scan = new Scanner(System.in); while(scan.hasNext()){ int counter = 0;  int numbCottages = scan.nextInt();  int t = scan.nextInt();  House[] cottages = new House[numbCottages]; for ( int i = 0;(i < numbCottages);i++) { int centre = scan.nextInt();  int length = scan.nextInt();  double beginning = (centre - ((double)length / 2));  double end = (centre + ((double)length / 2)); cottages[i] = new House(beginning,end); }Arrays.sort(cottages); for ( int i = 0;(i < (numbCottages - 1));i++) {if ( ((cottages[i].end + t) <= cottages[(i + 1)].beginning)) {counter++; } if ( ((cottages[(i + 1)].beginning - t) >= cottages[i].end)) {counter++; } if ( (Math.abs(((cottages[i].end + t) - cottages[(i + 1)].beginning)) < 1e-8)) {counter--; } }System.out.println((counter + 2)); }} static class House implements Comparable<House>{ double beginning ; double end ; House( double _beginning, double _end){ beginning = _beginning; end = _end; } @Override public int compareTo( House house){ return Double.valueOf(beginning).compareTo(house.beginning);} } }
4	public class C{ public static void main( String[] args)throws FileNotFoundException { Scanner in = new Scanner(new FileReader(new File("input.txt")));  PrintWriter out = new PrintWriter(new File("output.txt"));  int n = in.nextInt();  int m = in.nextInt();  int[][] T = new int[n][m];  int k = in.nextInt();  int[] X = new int[k];  int[] Y = new int[k]; for ( int i = 0;(i < k);i++) {X[i] = (in.nextInt() - 1); Y[i] = (in.nextInt() - 1); } int max = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) { int min = Integer.MAX_VALUE; for ( int ii = 0;(ii < k);ii++) min = Math.min(min,(Math.abs((i - X[ii])) + Math.abs((j - Y[ii])))); max = Math.max(max,T[i][j] = min); }for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (T[i][j] == max)) {out.println((((i + 1) + " ") + (j + 1))); out.flush(); return ;} } }
5	public class Median_Segments_general{ public static void main( String[] args){ Scanner s = new Scanner(System.in);  int n = s.nextInt();  int m = s.nextInt();  int[] arr = new int[n]; for ( int i = 0;(i < n);i++) {arr[i] = s.nextInt(); }System.out.println((func(n,m,arr) - func(n,(m + 1),arr))); } public static long func( int n, int m, int[] arr){ HashMap<Long,Integer> map = new HashMap<>(); map.put((long)0,1); long sum = 0;  long res = 0;  long add = 0; for ( int i = 0;(i < n);i++) {if ( (arr[i] < m)) {sum--; if ( map.containsKey(sum)) {add -= map.get(sum); } } else {if ( map.containsKey(sum)) {add += map.get(sum); } sum++; }res += add; if ( map.containsKey(sum)) {map.put(sum,(map.get(sum) + 1)); } else {map.put(sum,1); }}return res;} }
5	public class Flatville{ public static void main( String[] args){ class SquareHouse implements Comparable<SquareHouse>{ public SquareHouse( double posLeft, double sideLen){ _posLeft = posLeft; _sideLen = sideLen; } public double posLeft(){ return _posLeft;} public double posRight(){ return (_posLeft + _sideLen);} private double _posLeft ; private double _sideLen ; } Scanner scanner = new Scanner(System.in); final int nHouses = scanner.nextInt(); final double sideLen = scanner.nextDouble();  ArrayList<SquareHouse> houses = new ArrayList<SquareHouse>(); for ( int iHouse = 0;(iHouse < nHouses);++iHouse) { double pos = scanner.nextDouble();  double size = scanner.nextDouble();  double posLeft = (pos - (size / 2.0)); houses.add(new SquareHouse(posLeft,size)); }Collections.sort(houses); int nPositions = 2; for ( int iHouse = 0;(iHouse < (nHouses - 1));++iHouse) { double space = (houses.get((iHouse + 1)).posLeft() - houses.get(iHouse).posRight()); if ( (sideLen < space)) nPositions += 2; else if ( (sideLen == space)) nPositions++; }out.println(nPositions); } }
5	public class A{ 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 t = Integer.parseInt(st.nextToken());  State[] s = new State[n]; for ( int i = 0;(i < n);i++) {st = new StringTokenizer(br.readLine()); s[i] = new State(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken())); }Arrays.sort(s); int num = 2; for ( int i = 1;(i < s.length);i++) { int dist = (s[i].x - s[(i - 1)].x); dist *= 2; int size = (s[i].d + s[(i - 1)].d); size += (2 * t); if ( (dist == size)) num++; else if ( (dist > size)) num += 2; }System.out.println(num); } static class State implements Comparable<State>{ public int x ,d ; public State( int a, int b){ x = a; d = b; } } }
5	public class Houses implements Runnable{ private void solve()throws IOException { int n = nextInt();  int t = nextInt();  int[] x = new int[n];  int[] a = new int[n]; for ( int i = 0;(i < n);++i) {x[i] = (nextInt() * 2); a[i] = nextInt(); } Set<Integer> res = new HashSet<Integer>(); for ( int i = 0;(i < n);++i) {if ( valid(n,t,x,a,((x[i] + a[i]) + t))) res.add(((x[i] + a[i]) + t)); if ( valid(n,t,x,a,((x[i] - a[i]) - t))) res.add(((x[i] - a[i]) - t)); }writer.println(res.size()); } private boolean valid( int n, int t, int[] x, int[] a, int pos){ for ( int i = 0;(i < n);++i) {if ( (Math.abs((pos - x[i])) < (a[i] + t))) return false; }return true;} public static void main( String[] args){ new Houses().run(); } BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter writer ; public void run(){ try{reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); }catch (Exception e){ e.printStackTrace(); System.exit(1); } } int nextInt()throws IOException { return Integer.parseInt(nextToken());} String nextToken()throws IOException { while(((tokenizer == null) || !tokenizer.hasMoreTokens())){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} }
1	public class GenerateLogin{ public static void main( String[] args){ Scanner scan = new Scanner(System.in);  String a = scan.next();  String b = scan.next();  char last = b.charAt(0);  String ans = ("" + a.charAt(0)); for ( int i = 1;(i < a.length());i++) {if ( (a.charAt(i) >= last)) break; ans += a.charAt(i); }ans += last; System.out.println(ans); } }
1	public class A{ public static void main( String[] args)throws NumberFormatException,IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  int nums = Integer.parseInt(reader.readLine());  String line = reader.readLine();  int[] ar = new int[nums];  String[] par = line.split(" "); for ( int i = 0;(i < nums);i++) {ar[i] = Integer.parseInt(par[i]); } A a = new A(); System.out.print(a.getDif(ar)); } private int getDif( int[] input){ int odd = 0,even = 0,d = 0;  int p = 0,q = 0; for ( int i = 0;(i < input.length);i++) { int t = (input[i] % 2); if ( (t == 0)) {even++; p = (i + 1); } else {odd++; q = (i + 1); }if ( (((odd > 0) && (even > 0)) && (odd != even))) {if ( (even > odd)) return q; else return p;} }return d;} }
4	public class Solution35C{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { if ( ONLINE_JUDGE) {in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } else {in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new Solution35C().run(); } public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println(("Time = " + (t2 - t1))); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } void solve()throws IOException { int n = readInt();  int m = readInt();  int k = readInt();  Point[] focuses = new Point[k]; for ( int i = 0;(i < k);i++) { int a = (readInt() - 1);  int b = (readInt() - 1); focuses[i] = new Point(a,b); } int maxI = 0,maxJ = 0;  int max = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) { int curMin = 1000000; for ( int r = 0;(r < k);r++) if ( ((abs((focuses[r].x - i)) + abs((focuses[r].y - j))) < curMin)) {curMin = (abs((focuses[r].x - i)) + abs((focuses[r].y - j))); if ( (curMin < max)) break; } if ( (curMin > max)) {max = curMin; maxI = i; maxJ = j; } }maxI++; maxJ++; out.println(((maxI + " ") + maxJ)); } static long gcd( long a, long b){ while((a != b)){if ( (a < b)) a -= b; else b -= a; }return a;} }
0	public class A{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt(); System.out.println(("0 0 " + n)); } }
4	public class C35{ public static int mod = 1000000007; public static long INF = (1L << 60); static int n ,m ; static class Pair{ int x ,y ; Pair( int x, int y){ this.x = x; this.y = y; } } static boolean[][] burned ; static int[] dx = {-1,0,1,0}; static int[] dy = {0,-1,0,1}; static boolean isvalid( int x, int y){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} public static void main( String[] args)throws IOException { Scanner in = new Scanner("input.txt");  PrintWriter out = new PrintWriter(new FileWriter("output.txt")); n = in.nextInt(); m = in.nextInt(); burned = new boolean[n][m]; int k = in.nextInt();  Set<Pair> set = new HashSet<Pair>();  Pair prev = null; for ( int i = 0;(i < k);i++) { int x = in.nextInt();  int y = in.nextInt(); burned[(x - 1)][(y - 1)] = true; set.add(prev = new Pair((x - 1),(y - 1))); }while(!set.isEmpty()){ Set<Pair> tempset = new HashSet<>(); for ( Pair p :set) { int x = p.x;  int y = p.y; prev = p; for ( int i = 0;(i < 4);i++) {if ( (isvalid((x + dx[i]),(y + dy[i])) && !burned[(x + dx[i])][(y + dy[i])])) {tempset.add(new Pair((x + dx[i]),(y + dy[i]))); burned[(x + dx[i])][(y + dy[i])] = true; } }}set = tempset; }out.printf("%d %d\n",(prev.x + 1),(prev.y + 1)); out.close(); } public static long gcd( long n1, long n2){ long r ; while((n2 != 0)){r = (n1 % n2); n1 = n2; n2 = r; }return n1;} 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 boolean ready()throws IOException { return br.ready();} } }
4	public class C35{ public static void main( String[] args)throws IOException { Scanner in = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter("output.txt");  int n = in.nextInt(),m = in.nextInt();  int k = in.nextInt();  int[] x = new int[k];  int[] y = new int[k];  int res = 0; for ( int i = 0;(i < k);i++) {x[i] = in.nextInt(); y[i] = in.nextInt(); } int xx = 1,yy = 1; for ( int i = 1;(i <= n);i++) for ( int j = 1;(j <= m);j++) { int cnt = Integer.MAX_VALUE; for ( int l = 0;(l < k);l++) { int time = (Math.abs((i - x[l])) + Math.abs((j - y[l]))); cnt = Math.min(cnt,time); }if ( (cnt > res)) {res = cnt; xx = i; yy = j; } res = Math.max(res,cnt); }out.print(((xx + " ") + yy)); out.close(); } }
6	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]; for ( int s = (t - 1);(s >= 0);s--) for ( int m = 0;(m < n);m++) { int x = da[s][m]; if ( (x != 0)) { int s_ = (s + a); if ( (s_ <= t)) da[s_][(m + 1)] = ((da[s_][(m + 1)] + x) % MD); } }}return da;} static int[][][] solve2( int[] aa, int[] bb, int t, int na, int nb){ int[][] da = solve1(aa,t,na);  int[][][] dab = new int[(t + 1)][(na + 1)][(nb + 1)]; for ( int s = 0;(s <= t);s++) for ( int ma = 0;(ma <= na);ma++) dab[s][ma][0] = da[s][ma]; for ( int i = 0;(i < nb);i++) { int b = bb[i]; for ( int s = (t - 1);(s >= 0);s--) for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb < nb);mb++) { int x = dab[s][ma][mb]; if ( (x != 0)) { int s_ = (s + b); if ( (s_ <= t)) dab[s_][ma][(mb + 1)] = ((dab[s_][ma][(mb + 1)] + x) % MD); } }}return dab;} static long power( int a, int k){ if ( (k == 0)) return 1; long p = power(a,(k / 2)); p = ((p * p) % MD); if ( ((k % 2) == 1)) p = ((p * a) % MD); return p;} static int[] ff ,gg ; static int ch( int n, int k){ return (int)(((((long)ff[n] * gg[(n - k)]) % MD) * gg[k]) % MD);} static int[][][] init( int n, int na, int nb, int nc){ ff = new int[(n + 1)]; gg = new int[(n + 1)]; for ( int i = 0,f = 1;(i <= n);i++) {ff[i] = f; gg[i] = (int)power(f,(MD - 2)); f = (int)(((long)f * (i + 1)) % MD); } int[][][] dp = new int[(na + 1)][(nb + 1)][(nc + 1)]; for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) for ( int mc = 0;(mc <= nc);mc++) { int x = (int)(((((((long)ff[((ma + mb) + mc)] * gg[ma]) % MD) * gg[mb]) % MD) * gg[mc]) % MD); for ( int ma_ = ((ma == 0)?0:1);(ma_ <= ma);ma_++) { int cha = ((ma == 0)?1:ch((ma - 1),(ma_ - 1))); for ( int mb_ = ((mb == 0)?0:1);(mb_ <= mb);mb_++) { int chb = ((mb == 0)?1:ch((mb - 1),(mb_ - 1))); for ( int mc_ = ((mc == 0)?0:1);(mc_ <= mc);mc_++) { int chc = ((mc == 0)?1:ch((mc - 1),(mc_ - 1)));  int y = dp[ma_][mb_][mc_]; if ( (y == 0)) continue; x = (int)((x - ((((((long)y * cha) % MD) * chb) % MD) * chc)) % MD); }}}if ( (x < 0)) x += MD; dp[ma][mb][mc] = x; }for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) for ( int mc = 0;(mc <= nc);mc++) dp[ma][mb][mc] = (int)(((((((long)dp[ma][mb][mc] * ff[ma]) % MD) * ff[mb]) % MD) * ff[mc]) % MD); return dp;} 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 t = Integer.parseInt(st.nextToken());  int[] aa = new int[n];  int[] bb = new int[n];  int[] cc = new int[n];  int na = 0,nb = 0,nc = 0; for ( int i = 0;(i < n);i++) {st = new StringTokenizer(br.readLine()); int a = Integer.parseInt(st.nextToken());  int g = Integer.parseInt(st.nextToken()); if ( (g == 1)) aa[na++] = a; else if ( (g == 2)) bb[nb++] = a; else cc[nc++] = a; } int[][][] dp = init(n,na,nb,nc);  int[][][] dab = solve2(aa,bb,t,na,nb);  int[][] dc = solve1(cc,t,nc);  int ans = 0; for ( int tab = 0;(tab <= t);tab++) { int tc = (t - tab); for ( int ma = 0;(ma <= na);ma++) for ( int mb = 0;(mb <= nb);mb++) { int xab = dab[tab][ma][mb]; if ( (xab == 0)) continue; for ( int mc = 0;(mc <= nc);mc++) { int xc = dc[tc][mc]; if ( (xc == 0)) continue; ans = (int)((ans + ((((long)xab * xc) % MD) * dp[ma][mb][mc])) % MD); }}}System.out.println(ans); } }
0	public class Fibonacci{ public static void main( String[] args){ Scanner input = new Scanner(System.in);  long num = 0; num = input.nextLong(); while(((num < 0) || (num > Math.pow(10,9)))){System.out.println("Invalid"); num = input.nextLong(); }System.out.println(("0 0 " + num)); } }
1	public class Main{ static Reader scan ; static PrintWriter pw ; static int n ,k ,left[] ,right[] ,arr[] ; static long MOD = 1000000007,count[] ,dp[] ; public static void main( String[] args){ new Thread(null,null,"BaZ",(1 << 25)){}.start(); } static void solve()throws IOException { scan = new Reader(); pw = new PrintWriter(System.out,true); StringBuilder sb = new StringBuilder(); n = ni(); k = ni(); int stack[] = new int[1000001];  int top = -1; arr = new int[n]; left = new int[n]; right = new int[n]; for ( int i = 0;(i < n);++i) {arr[i] = ni(); while(((top >= 0) && (arr[stack[top]] <= arr[i])))top--; if ( (top == -1)) left[i] = 0; else left[i] = (stack[top] + 1); stack[++top] = i; }top = -1; for ( int i = (n - 1);(i >= 0);--i) {while(((top >= 0) && (arr[stack[top]] < arr[i])))top--; if ( (top == -1)) right[i] = (n - 1); else right[i] = (stack[top] - 1); stack[++top] = i; }dp = new long[(n + 1)]; for ( int i = 0;(i <= n);++i) {if ( (i < k)) continue; dp[i] = (dp[((i - k) + 1)] + ((i - k) + 1)); }count = new long[n]; long ans = 0; for ( int i = 0;(i < n);++i) { int len = ((right[i] - left[i]) + 1);  int lef = (i - left[i]);  int rig = (right[i] - i);  long count = ((dp[len] - dp[lef]) - dp[rig]); if ( (count >= MOD)) count %= MOD; ans += (count * arr[i]); if ( (ans >= MOD)) ans %= MOD; }pl(ans); pw.flush(); pw.close(); } static int ni()throws IOException { return scan.nextInt();} static void pl(){ pw.println(); } static void p( Object o){ pw.print((o + " ")); } static void pl( Object o){ pw.println(o); } static class Reader{ private final int BUFFER_SIZE = (1 << 16); private DataInputStream din ; private byte[] buffer ; private int bufferPointer ,bytesRead ; public Reader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader( String file_name)throws IOException{ din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt()throws IOException { int ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} public long nextLong()throws IOException { long ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} public double nextDouble()throws IOException { double ret = 0,div = 1;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( (c == '.')) while((((c = read()) >= '0') && (c <= '9')))ret += ((c - '0') / (div *= 10)); if ( neg) return -ret; return ret;} private void fillBuffer()throws IOException { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } private byte read()throws IOException { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} public void close()throws IOException { if ( (din == null)) return ; din.close(); } } }
0	public class ChessKing{ public static void main( String[] args){ Scanner input = new Scanner(System.in);  long size = input.nextLong();  long a = input.nextLong();  long b = input.nextLong();  long sum = (a + b);  long d = (sum - 2);  long d1 = ((size * 2) - sum); if ( (d < d1)) System.out.println("White"); else if ( (d > d1)) System.out.println("Black"); else System.out.println("White"); } }
1	public class Round364C{ public static void main( String[] args)throws NumberFormatException,IOException { Scanner sc = new Scanner(System.in); n = sc.nextInt(); k = 0; String line = sc.nextLine();  ArrayList<Character> poks = new ArrayList<Character>();  boolean ex[] = new boolean[256]; for ( int i = 0;(i < n);i++) {if ( !ex[line.charAt(i)]) {ex[line.charAt(i)] = true; poks.add(line.charAt(i)); } } int l = 0;  int r = 0;  int dist = 1;  int occ[] = new int[256]; occ[line.charAt(0)] = 1; int min = n; while((r < n)){if ( (dist == poks.size())) min = Math.min(min,((r - l) + 1)); if ( ((l < r) && (dist == poks.size()))) {occ[line.charAt(l)]--; if ( (occ[line.charAt(l)] == 0)) dist--; l++; continue;} if ( (r < (n - 1))) {occ[line.charAt((r + 1))]++; if ( (occ[line.charAt((r + 1))] == 1)) dist++; } r++; }System.out.println(min); } static int n ,k ; static int dp[][][] ; static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner( FileReader f){ br = new BufferedReader(f); } public boolean ready()throws IOException { return br.ready();} Scanner( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } String next()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 NumberFormatException,IOException { return Integer.parseInt(next());} } }
0	public class CF125A{ private void work()throws IOException { Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));  int n = sc.nextInt(); System.out.printf("%d %d %d\n",0,0,n); System.out.close(); } public static void main( String[] args)throws IOException { new CF125A().work(); } }
0	public class KingEscape{ public static void main( String[] args){ Reader read = new Reader();  int n = read.nextInt();  int a1 = read.nextInt();  int a2 = read.nextInt();  int b1 = read.nextInt();  int b2 = read.nextInt();  int c1 = read.nextInt();  int c2 = read.nextInt(); if ( ((((b1 > a1) && (b2 > a2)) && (c1 > a1)) && (c2 > a2))) System.out.print("YES"); else if ( ((((b1 > a1) && (b2 < a2)) && (c1 > a1)) && (c2 < a2))) System.out.print("YES"); else if ( ((((b1 < a1) && (b2 > a2)) && (c1 < a1)) && (c2 > a2))) System.out.print("YES"); else if ( ((((b1 < a1) && (b2 < a2)) && (c1 < a1)) && (c2 < a2))) System.out.print("YES"); else System.out.print("NO"); } static private class Reader{ private final BufferedReader reader ; private final String separator ; private String ln ; private String[] tokens ; private int ptr ; Reader( String separator, InputStream input){ this.reader = new BufferedReader(new InputStreamReader(input)); this.separator = separator; this.ptr = -1; } Reader( String separator){ this(separator,System.in); } Reader(){ this(" "); } String nextStr(){ if ( Objects.isNull(ln)) {try{ln = reader.readLine(); }catch (IOException e){ System.out.println(e.getMessage()); } if ( Objects.nonNull(ln)) {tokens = ln.split(separator); ptr = 0; } else {throw (new NoSuchElementException("no next element"));}} else if ( (ptr == tokens.length)) {ln = null; tokens = null; ptr = -1; return nextStr();} return tokens[ptr++];} int nextInt(){ return Integer.parseInt(nextStr());} } }
1	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ public void solve( int testNumber, InputReader in, OutputWriter out){ int n = in.readInt();  char[] str = IOUtils.readCharArray(in,n); for ( int i = 0;(i < n);i++) {if ( (str[i] <= 'Z')) {str[i] = (char)(str[i] - 'A'); } else {str[i] = (char)((str[i] - 'a') + 26); }} IntHashSet set = new IntHashSet(); for ( char c :str) {set.add(c); } int max = (26 + 26);  int[][] next = new int[max][n]; ArrayUtils.fill(next,-1); for ( int i = (n - 2);(i >= 0);i--) {for ( int ch = 0;(ch < max);ch++) {next[ch][i] = next[ch][(i + 1)]; }next[str[(i + 1)]][i] = (i + 1); } int ans = (int)1e9; final int tagetCnt = set.size(); for ( int s = 0;(s < n);s++) { boolean[] used = new boolean[max]; used[str[s]] = true; int cnt = 1;  int pos = s; while((cnt < tagetCnt)){ int nextPos = n; for ( int ch = 0;(ch < max);ch++) {if ( !used[ch]) {if ( (next[ch][pos] == -1)) {continue;} nextPos = Math.min(nextPos,next[ch][pos]); } }pos = nextPos; if ( (nextPos == n)) {break;} ++cnt; used[str[nextPos]] = true; }if ( (pos == n)) {break;} ans = Math.min(ans,((pos - s) + 1)); }out.printLine(ans); } } static interface IntCollection extends IntStream{ public int size(); public default void add( int value){ throw (new UnsupportedOperationException());} public default IntCollection addAll( IntStream values){ for ( IntIterator it = values.intIterator();it.isValid();it.advance()) {add(it.value()); }return this;} } static interface IntStream extends Iterable<Integer>,Comparable<IntStream>{ public IntIterator intIterator(); } static class IntHashSet extends IntAbstractStream implements IntSet{ static private final Random RND = new Random(); static private final int[] SHIFTS = new int[4]; static private final byte PRESENT_MASK = 1; static private final byte REMOVED_MASK = 2; private int size ; private int realSize ; private int[] values ; private byte[] present ; private int step ; private int ratio ; {for ( int i = 0;(i < 4);i++) {SHIFTS[i] = (RND.nextInt(31) + 1); }}public IntHashSet(){ this(3); } public IntHashSet( int capacity){ capacity = Math.max(capacity,3); values = new int[capacity]; present = new byte[capacity]; ratio = 2; initStep(capacity); } public IntHashSet( IntCollection c){ this(c.size()); addAll(c); } public IntHashSet( int[] arr){ this(new IntArray(arr)); } private void initStep( int capacity){ step = (RND.nextInt((capacity - 2)) + 1); while((IntegerUtils.gcd(step,capacity) != 1)){step++; }} public IntIterator intIterator(){ return new IntIterator(){private int position = ((size == 0)?values.length:-1); public int value()throws NoSuchElementException { if ( (position == -1)) {advance(); } if ( (position >= values.length)) {throw (new NoSuchElementException());} if ( ((present[position] & PRESENT_MASK) == 0)) {throw (new IllegalStateException());} return values[position];} public boolean advance()throws NoSuchElementException { if ( (position >= values.length)) {throw (new NoSuchElementException());} position++; while(((position < values.length) && ((present[position] & PRESENT_MASK) == 0))){position++; }return isValid();} public boolean isValid(){ return (position < values.length);} };} public int size(){ return size;} public void add( int value){ ensureCapacity((((realSize + 1) * ratio) + 2)); int current = getHash(value); while((present[current] != 0)){if ( (((present[current] & PRESENT_MASK) != 0) && (values[current] == value))) {return ;} current += step; if ( (current >= values.length)) {current -= values.length; } }while(((present[current] & PRESENT_MASK) != 0)){current += step; if ( (current >= values.length)) {current -= values.length; } }if ( (present[current] == 0)) {realSize++; } present[current] = PRESENT_MASK; values[current] = value; size++; } private int getHash( int value){ int hash = IntHash.hash(value);  int result = hash; for ( int i :SHIFTS) {result ^= (hash >> i); }result %= values.length; if ( (result < 0)) {result += values.length; } return result;} private void ensureCapacity( int capacity){ if ( (values.length < capacity)) {capacity = Math.max((capacity * 2),values.length); rebuild(capacity); } } private void rebuild( int capacity){ initStep(capacity); int[] oldValues = values;  byte[] oldPresent = present; values = new int[capacity]; present = new byte[capacity]; size = 0; realSize = 0; for ( int i = 0;(i < oldValues.length);i++) {if ( ((oldPresent[i] & PRESENT_MASK) == PRESENT_MASK)) {add(oldValues[i]); } }} } static interface IntList extends IntReversableCollection{ public abstract int get( int index); public abstract void addAt( int index, int value); public abstract void removeAt( int index); public default IntIterator intIterator(){ return new IntIterator(){private int at ; private boolean removed ; public int value(){ if ( removed) {throw (new IllegalStateException());} return get(at);} public boolean advance(){ at++; removed = false; return isValid();} public boolean isValid(){ return (!removed && (at < size()));} };} public default void add( int value){ addAt(size(),value); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char readCharacter(){ int c = read(); while(isSpaceChar(c)){c = read(); }return (char)c;} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } static interface IntReversableCollection extends IntCollection{ } static class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void close(){ writer.close(); } public void printLine( int i){ writer.println(i); } } static class IntArray extends IntAbstractStream implements IntList{ private int[] data ; public IntArray( int[] arr){ data = arr; } public int size(){ return data.length;} public int get( int at){ return data[at];} public void addAt( int index, int value){ throw (new UnsupportedOperationException());} public void removeAt( int index){ throw (new UnsupportedOperationException());} } static interface IntSet extends IntCollection{ } static interface IntIterator{ public int value()throws NoSuchElementException ; public boolean advance(); public boolean isValid(); } }
6	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);  FElongatedMatrix solver = new FElongatedMatrix(); solver.solve(1,in,out); out.close(); } static class FElongatedMatrix{ int n ; int m ; int[][] arr ; int[][] memo ; int[][][] memo2 ; int first ; public void readInput( Scanner sc){ n = sc.nextInt(); m = sc.nextInt(); arr = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) arr[i][j] = sc.nextInt(); } public void solve( int testNumber, Scanner sc, PrintWriter pw){ int tc = 1; while((tc-- > 0)){readInput(sc); int max = 0; memo2 = new int[2][n][n]; for ( int[][] x :memo2) for ( int[] y :x) Arrays.fill(y,-1); for ( int i = 0;(i < n);i++) {memo = new int[n][(1 << n)]; for ( int[] y :memo) Arrays.fill(y,-1); first = i; max = Math.max(max,dp((1 << i),i)); }pw.println(max); }} private int dp( int msk, int prev){ if ( (msk == ((1 << n) - 1))) return getLast(first,prev); if ( (memo[prev][msk] != -1)) return memo[prev][msk]; int max = 0; for ( int i = 0;(i < n);i++) {if ( ((msk & (1 << i)) == 0)) max = Math.max(max,Math.min(getDiff(prev,i),dp((msk | (1 << i)),i))); }return memo[prev][msk] = max;} private int getLast( int i, int j){ if ( (memo2[0][i][j] != -1)) return memo2[0][i][j]; int min = Integer.MAX_VALUE; for ( int k = 0;(k < (m - 1));k++) min = Math.min(min,Math.abs((arr[i][k] - arr[j][(k + 1)]))); return memo2[0][i][j] = min;} private int getDiff( int i, int j){ if ( (memo2[1][i][j] != -1)) return memo2[1][i][j]; int min = Integer.MAX_VALUE; for ( int k = 0;(k < m);k++) min = Math.min(min,Math.abs((arr[i][k] - arr[j][k]))); return memo2[1][i][j] = min;} } static class Scanner{ StringTokenizer st ; BufferedReader br ; public Scanner( InputStream s){ br = new BufferedReader(new InputStreamReader(s)); } public String next(){ try{while(((st == null) || !st.hasMoreTokens()))st = new StringTokenizer(br.readLine()); return st.nextToken(); }catch (Exception e){ throw (new RuntimeException(e));} } public int nextInt(){ return Integer.parseInt(next());} } }
6	public class Main{ public static void main( String[] args)throws Exception { Thread thread = new Thread(null,new TaskAdapter(),"",(1 << 27)); thread.start(); thread.join(); } static class TaskAdapter implements Runnable{ } static class FElongatedMatrix{ public void solve( int testNumber, FastInput in, FastOutput out){ int n = in.readInt();  int m = in.readInt();  int[][] mat = new int[n][m]; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {mat[i][j] = in.readInt(); }} int[][] minDist = new int[n][n]; SequenceUtils.deepFill(minDist,(int)1e9); for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < m);k++) {minDist[i][j] = Math.min(minDist[i][j],Math.abs((mat[i][k] - mat[j][k]))); }}} int[][] minDistBetweenHeadAndTail = new int[n][n]; SequenceUtils.deepFill(minDistBetweenHeadAndTail,(int)1e9); for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {for ( int k = 1;(k < m);k++) {minDistBetweenHeadAndTail[i][j] = Math.min(minDistBetweenHeadAndTail[i][j],Math.abs((mat[i][k] - mat[j][(k - 1)]))); }}} Log2 log2 = new Log2();  BitOperator bo = new BitOperator();  int[][][] dp = new int[(1 << n)][n][n]; for ( int i = 1;(i < (1 << n));i++) {if ( (i == Integer.lowestOneBit(i))) {dp[i][log2.floorLog(i)][log2.floorLog(i)] = (int)1e9; continue;} for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < n);k++) {if ( (bo.bitAt(i,j) == 0)) {continue;} for ( int t = 0;(t < n);t++) {dp[i][j][k] = Math.max(dp[i][j][k],Math.min(dp[bo.setBit(i,j,false)][t][k],minDist[j][t])); }}}} int ans = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {ans = Math.max(ans,Math.min(dp[((1 << n) - 1)][i][j],minDistBetweenHeadAndTail[j][i])); }}out.println(ans); } } static class Log2{ public int floorLog( int x){ return (31 - Integer.numberOfLeadingZeros(x));} } static class FastInput{ private final InputStream is ; private byte[] buf = new byte[(1 << 13)]; private int bufLen ; private int bufOffset ; private int next ; public FastInput( InputStream is){ this.is = is; } private int read(){ while((bufLen == bufOffset)){bufOffset = 0; try{bufLen = is.read(buf); }catch (IOException e){ bufLen = -1; } if ( (bufLen == -1)) {return -1;} }return buf[bufOffset++];} public void skipBlank(){ while(((next >= 0) && (next <= 32))){next = read(); }} public int readInt(){ int sign = 1; skipBlank(); if ( ((next == '+') || (next == '-'))) {sign = ((next == '+')?1:-1); next = read(); } int val = 0; if ( (sign == 1)) {while(((next >= '0') && (next <= '9'))){val = (((val * 10) + next) - '0'); next = read(); }} else {while(((next >= '0') && (next <= '9'))){val = (((val * 10) - next) + '0'); next = read(); }}return val;} } static class BitOperator{ public int bitAt( int x, int i){ return ((x >> i) & 1);} public int setBit( int x, int i, boolean v){ if ( v) {x |= (1 << i); } else {x &= (1 << i); }return x;} } static class FastOutput implements AutoCloseable,Closeable{ private StringBuilder cache = new StringBuilder((10 << 20)); private final Writer os ; public FastOutput( Writer os){ this.os = os; } public FastOutput( OutputStream os){ this(new OutputStreamWriter(os)); } public FastOutput println( int c){ cache.append(c).append('\n'); return this;} public FastOutput flush(){ try{os.append(cache); os.flush(); cache.setLength(0); }catch (IOException e){ throw (new UncheckedIOException(e));} return this;} public void close(){ flush(); try{os.close(); }catch (IOException e){ throw (new UncheckedIOException(e));} } public String toString(){ return cache.toString();} } }
5	public class A{ public static double EPS = .001; public class House implements Comparable<House>{ int x ; int a ; public House( int mx, int ma){ x = mx; a = ma; } public double right(){ return ((double)x + ((double)a / 2.0));} public double left(){ return ((double)x - ((double)a / 2.0));} } public static void main( String[] args){ new A().solve(); } public void solve(){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int t = in.nextInt();  ArrayList<House> houses = new ArrayList<House>(); for ( int i = 0;(i < n);i++) { int x = in.nextInt();  int a = in.nextInt(); houses.add(new House(x,a)); }Collections.sort(houses); int total = 2; for ( int i = 0;(i < (houses.size() - 1));i++) { House me = houses.get(i);  House next = houses.get((i + 1));  double meright = me.right();  double nextleft = next.left();  double diff = (nextleft - meright); if ( ((diff - EPS) > (double)t)) {total += 2; } else if ( ((diff + EPS) > (double)t)) {total += 1; } }System.out.println(total); } }
4	public class Solution implements Runnable{ Scanner input ; PrintWriter output ; private void solve()throws Exception { int n = nextInt();  int m = nextInt();  int k = nextInt();  int[] r = new int[k];  int[] c = new int[k]; for ( int i = 0;(i < k);i++) {r[i] = nextInt(); c[i] = nextInt(); } int best = -1;  int bestr = -1;  int bestc = -1; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) { int d = (n + m); for ( int q = 0;(q < k);q++) {d = Math.min(d,(Math.abs((i - r[q])) + Math.abs((j - c[q])))); }if ( (d < best)) continue; best = d; bestr = i; bestc = j; }}out(((bestr + " ") + bestc)); } private int nextInt()throws Exception { return input.nextInt();} private void out( String s){ output.println(s); } public Solution()throws IOException{ input = new Scanner(new FileReader("input.txt")); output = new PrintWriter("output.txt"); } public static void main( String[] args)throws IOException { Locale.setDefault(Locale.US); new Thread(new Solution()).start(); } }
3	public class codeforces implements Runnable{ static final long mod = ((long)1e9 + 7); static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public String next(){ return readString();} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } public static void main( String[] args)throws Exception { new Thread(null,new codeforces(),"codeforces",(1 << 26)).start(); } }
2	public class Main{ static class Reader{ private InputStream mIs ; private byte[] buf = new byte[1024]; private int curChar ,numChars ; public Reader(){ this(System.in); } public Reader( InputStream is){ mIs = is; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = mIs.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public String s(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public long l(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public int i(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public boolean isEndOfLine( int c){ return (((c == '\n') || (c == '\r')) || (c == -1));} } public static long check( long mid, long x, long y, long n){ long ans = ((((2 * mid) * mid) + (2 * mid)) + 1);  long uleft = Math.max(0,((mid - x) + 1));  long dleft = Math.max(0,(mid - (n - x)));  long lleft = Math.max(0,((mid - y) + 1));  long rleft = Math.max(0,(mid - (n - y))); ans -= ((((uleft * uleft) + (dleft * dleft)) + (lleft * lleft)) + (rleft * rleft)); ans += ((Math.max(0,(mid - ((x + y) - 1))) * (Math.max(0,(mid - ((x + y) - 1))) + 1)) / 2); ans += ((Math.max(0,(mid - ((x + n) - y))) * (Math.max(0,(mid - ((x + n) - y))) + 1)) / 2); ans += ((Math.max(0,(mid - ((y + n) - x))) * (Math.max(0,(mid - ((y + n) - x))) + 1)) / 2); ans += ((Math.max(0,(mid - ((((n - x) + n) - y) + 1))) * (Math.max(0,(mid - ((((n - x) + n) - y) + 1))) + 1)) / 2); return ans;} public static void main( String[] args)throws IOException { PrintWriter out = new PrintWriter(System.out);  Reader sc = new Reader();  long n = sc.l();  long x = sc.l();  long y = sc.l();  long c = sc.l();  long low = 0;  long high = (long)Math.pow(10,9); while((low < high)){ long mid = ((low + high) / 2); if ( (check(mid,x,y,n) >= c)) high = mid; else low = (mid + 1); }out.println(low); out.flush(); } }
4	public class A{ static final int[] dx = {0,0,-1,1}; static final int[] dy = {-1,1,0,0}; public static void main( String[] args)throws IOException { Scanner sc = new Scanner("input.txt");  PrintWriter out = new PrintWriter(new FileWriter("output.txt"));  int N = sc.nextInt(),M = sc.nextInt();  int[][] dist = new int[N][M];  Queue<Integer> q = new LinkedList<>();  int K = sc.nextInt(); while((K-- > 0)){ int x = (sc.nextInt() - 1),y = (sc.nextInt() - 1); q.add(((x * M) + y)); dist[x][y] = 1; } int max = 0,ansX = -1,ansY = -1; while(!q.isEmpty()){ int u = q.remove(),x = (u / M),y = (u % M); if ( (dist[x][y] > max)) max = dist[ansX = x][ansY = y]; for ( int k = 0;(k < 4);++k) { int nx = (x + dx[k]),ny = (y + dy[k]); if ( (((((nx >= 0) && (ny >= 0)) && (nx < N)) && (ny < M)) && (dist[nx][ny] == 0))) {dist[nx][ny] = (dist[x][y] + 1); q.add(((nx * M) + ny)); } }}out.printf("%d %d\n",(ansX + 1),(ansY + 1)); out.close(); } 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 boolean ready()throws IOException { return br.ready();} } }
4	public class Main{ public static void main( String[] args){ InputStream inputStream ; try{inputStream = new FileInputStream("input.txt"); }catch (IOException e){ throw (new RuntimeException(e));} OutputStream outputStream ; try{outputStream = new FileOutputStream("output.txt"); }catch (IOException e){ throw (new RuntimeException(e));} InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  CFireAgain solver = new CFireAgain(); solver.solve(1,in,out); out.close(); } static class CFireAgain{ private int n ; private int m ; private int K ; private boolean[][] vis ; private Queue<Util.Pair<Integer>> queue = new LinkedList<>(); private Util.Pair<Integer> p ; private boolean isValid( int x, int y){ return (((((x >= 1) && (x <= n)) && (y >= 1)) && (y <= m)) && !vis[x][y]);} private void bfs(){ while(!queue.isEmpty()){p = queue.poll(); if ( isValid((p.x + 1),p.y)) {queue.offer(new Util.Pair<>((p.x + 1),p.y)); vis[(p.x + 1)][p.y] = true; } if ( isValid((p.x - 1),p.y)) {queue.offer(new Util.Pair<>((p.x - 1),p.y)); vis[(p.x - 1)][p.y] = true; } if ( isValid(p.x,(p.y + 1))) {queue.offer(new Util.Pair<>(p.x,(p.y + 1))); vis[p.x][(p.y + 1)] = true; } if ( isValid(p.x,(p.y - 1))) {queue.offer(new Util.Pair<>(p.x,(p.y - 1))); vis[p.x][(p.y - 1)] = true; } }} public void solve( int testNumber, InputReader in, OutputWriter out){ n = in.nextInt(); m = in.nextInt(); K = in.nextInt(); vis = new boolean[(n + 1)][(m + 1)]; for ( int i = 0;(i < K);i++) { int a = in.nextInt(),b = in.nextInt(); vis[a][b] = true; queue.offer(new Util.Pair<>(a,b)); }bfs(); out.println(((p.x + " ") + p.y)); out.flush(); } } static class OutputWriter{ private final PrintWriter writer ; private ArrayList<String> res = new ArrayList<>(); private StringBuilder sb = new StringBuilder(""); public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void println( Object... objects){ for ( int i = 0;(i < objects.length);i++) {sb.append(objects[i]); }res.add(sb.toString()); sb = new StringBuilder(""); } public void close(){ writer.close(); } public void flush(){ for ( String str :res) writer.printf("%s\n",str); res.clear(); sb = new StringBuilder(""); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[8192]; private int curChar ; private int numChars ; public InputReader( InputStream stream){ this.stream = stream; } public InputReader( FileInputStream file){ this.stream = file; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int nextInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res = ((((res << 3) + (res << 1)) + c) - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } }
4	public class C{ static private int[] dx = {1,-1,0,0}; static private int[] dy = {0,0,-1,1}; public static void main( String[] args)throws Exception { Thread t = new Thread(null,null,"~",Runtime.getRuntime().maxMemory()){}; t.start(); t.join(); } public static void solve()throws Exception { Scanner in = new Scanner(new File("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt"));  int n = in.nextInt();  int m = in.nextInt();  int[][] time = new int[n][m]; for ( int i = 0;(i < n);++i) {Arrays.fill(time[i],Integer.MAX_VALUE); } int qq = in.nextInt();  int[] xs = new int[qq];  int[] ys = new int[qq]; for ( int i = 0;(i < qq);++i) {xs[i] = (in.nextInt() - 1); ys[i] = (in.nextInt() - 1); }for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < m);++j) {for ( int k = 0;(k < qq);++k) { int dist = (Math.abs((i - xs[k])) + Math.abs((j - ys[k]))); time[i][j] = Math.min(time[i][j],dist); }}} int max = -1;  int x = -1;  int y = -1; for ( int i = 0;(i < n);++i) {for ( int j = 0;(j < m);++j) if ( (max < time[i][j])) {max = time[i][j]; x = (i + 1); y = (j + 1); } }out.println(((x + " ") + y)); out.flush(); out.close(); } }
6	public class G1{ static final int mod = (int)(1e9 + 7); static final int UNCALC = -1; static int[][][] memo ; static int n ,t[] ,genre[] ; public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out); n = sc.nextInt(); t = new int[n]; int T = sc.nextInt(); genre = new int[n]; for ( int i = 0;(i < n);i++) {t[i] = sc.nextInt(); genre[i] = sc.nextInt(); }memo = new int[4][(1 << n)][(T + 1)]; for ( int[][] a :memo) for ( int[] b :a) Arrays.fill(b,UNCALC); out.println(dp(0,0,T)); out.flush(); out.close(); } static int dp( int last, int mask, int rem){ if ( (rem == 0)) return 1; if ( (memo[last][mask][rem] != UNCALC)) return memo[last][mask][rem]; int cnt = 0; for ( int i = 0;(i < n);i++) {if ( (((genre[i] == last) || (t[i] > rem)) || ((mask & (1 << i)) != 0))) continue; cnt = ((cnt + dp(genre[i],(mask | (1 << i)),(rem - t[i]))) % mod); }return memo[last][mask][rem] = cnt;} static class Scanner{ StringTokenizer st ; BufferedReader br ; public Scanner( InputStream system){ br = new BufferedReader(new InputStreamReader(system)); } 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 double nextDouble()throws IOException { return Double.parseDouble(next());} public Long nextLong()throws IOException { return Long.parseLong(next());} public boolean ready()throws IOException { return br.ready();} } }
1	public class A{ int n ; int[] arr ; void run(){ Scanner s = new Scanner(System.in); n = s.nextInt(); arr = new int[n]; int even ,odd ; even = 0; odd = 0; for ( int i = 0;(i < n);i++) {arr[i] = s.nextInt(); if ( ((arr[i] % 2) == 0)) even++; else odd++; }if ( (even > odd)) {for ( int i = 0;(i < n);i++) {if ( ((arr[i] % 2) == 1)) {System.out.println((i + 1)); System.exit(0); } }} else {for ( int i = 0;(i < n);i++) {if ( ((arr[i] % 2) == 0)) {System.out.println((i + 1)); System.exit(0); } }}} public static void main( String[] args){ new A().run(); } }
0	public class C125{ public static void main( String[] args)throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in));  String s = r.readLine();  int n = new Integer(s); System.out.println(("0 0 " + n)); } }
0	public class Main{ public static void main( String[] args){ Scanner cin = new Scanner(System.in);  int n = cin.nextInt();  long res = 2;  long[] a = new long[4]; a[0] = 0; a[1] = 1; a[2] = 1; a[3] = 2; if ( (n == 1)) {System.out.println("0 0 1"); return ;} if ( (n == 2)) {System.out.println("0 1 1"); return ;} if ( (n == 0)) {System.out.println("0 0 0"); return ;} if ( (n == 3)) {System.out.println("1 1 1"); return ;} do {a[3] = res; res = (a[2] + a[3]); if ( (res == n)) {System.out.println(((((a[0] + " ") + a[1]) + " ") + a[3])); return ;} a[0] = a[1]; a[1] = a[2]; a[2] = a[3]; }while(true);} }
1	public class C{ static int[] arr ; static int L ; public static void rotate(){ int tmp = arr[0]; for ( int i = 1;(i < L);i++) arr[(i - 1)] = arr[i]; arr[(L - 1)] = tmp; } public static void main( String[] args){ Scanner input = new Scanner(System.in); L = input.nextInt(); String s = input.next(); arr = new int[L]; for ( int i = 0;(i < L);i++) {arr[i] = ((s.charAt(i) == 'H')?1:0); } int count = 99999; for ( int A = 0;(A < L);A++) { int[] tmp = new int[L]; System.arraycopy(arr,0,tmp,0,arr.length); int ans = 0; for ( int i = 0;(i < L);i++) {if ( (tmp[i] == 1)) continue; for ( int j = (L - 1);(j > i);j--) {if ( (tmp[j] == 0)) continue; ans++; tmp[i] = 1; tmp[j] = 0; break;}}count = Math.min(count,ans); rotate(); }System.out.println(count); } }
4	public class Abc{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(new FileReader("input.txt"));  PrintWriter out = new PrintWriter(new File("output.txt"));  int n = sc.nextInt(),m = sc.nextInt(),k = sc.nextInt();  boolean vis[][] = new boolean[n][m];  LinkedList<Integer> q = new LinkedList<>(); for ( int i = 0;(i < k);i++) { int x = (sc.nextInt() - 1),y = (sc.nextInt() - 1); vis[x][y] = true; q.add(x); q.add(y); } int lastx = -1,lasty = -1;  int dirX[] = {1,-1,0,0},dirY[] = {0,0,1,-1}; while(!q.isEmpty()){ int x = q.removeFirst();  int y = q.removeFirst(); lastx = x; lasty = y; for ( int i = 0;(i < 4);i++) { int newx = (x + dirX[i]),newy = (y + dirY[i]); if ( (((((newx >= 0) && (newx < n)) && (newy >= 0)) && (newy < m)) && !vis[newx][newy])) {vis[newx][newy] = true; q.add(newx); q.add(newy); } }}out.println((((lastx + 1) + " ") + (lasty + 1))); out.close(); } }
3	public class indent{ static int N ,M ,K ; static String s ; static StringTokenizer st ; static int[] d ; static long MOD = ((int)1e9 + 7); public static void main( String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  int N = Integer.parseInt(br.readLine());  char[] d = new char[N]; for ( int i = 0;(i < N);i++) {d[i] = br.readLine().charAt(0); } long[][] dp = new long[N][N];  boolean det = (d[0] == 'f'); dp[0][0] = 1; for ( int i = 1;(i < N);i++) { long sum = 0; for ( int j = 0;(j < N);j++) {sum = ((((dp[(i - 1)][j] % MOD) + (sum % MOD)) + MOD) % MOD); }if ( (d[i] == 'f')) {if ( det) {for ( int j = 1;(j < N);j++) {dp[i][j] = (dp[(i - 1)][(j - 1)] % MOD); }continue;} for ( int j = 0;(j < N);j++) {dp[i][j] = (sum % MOD); sum -= (dp[(i - 1)][j] % MOD); }det = true; } else if ( (d[i] == 's')) {if ( det) {det = false; for ( int j = 1;(j < N);j++) {dp[i][j] = (dp[(i - 1)][(j - 1)] % MOD); }continue;} for ( int j = 0;(j < N);j++) {dp[i][j] = (sum % MOD); sum = ((((sum - dp[(i - 1)][j]) % MOD) + MOD) % MOD); }} } long ans = 0; for ( long e :dp[(dp.length - 1)]) {ans = (((ans + e) + MOD) % MOD); }System.out.println(ans); } }
2	public class B{ public static void main( String[] args){ Pipes pipes = new Pipes(); pipes.solve(); pipes.print(); } } class Pipes{ Pipes(){ Scanner scr = new Scanner(System.in); n = scr.nextLong(); k = scr.nextLong(); } long bs( long nb, long nk){ long left = 2;  long ls = (((((nk - left) + 1) * (nk + left)) / 2) - (nk - left));  long right = nk;  long rs = nk; if ( (nb > ls)) {return -1;} long mid = left; while((rs < ls)){mid = ((left + right) / 2); long ms = (((((nk - mid) + 1) * (nk + mid)) / 2) - (nk - mid)); if ( (nb > ms)) {right = mid; rs = ms; } else if ( (nb < ms)) {left = (mid + 1); ls = (((((nk - left) + 1) * (nk + left)) / 2) - (nk - left)); } else {left = mid; break;}}return left;} void solve(){ long nn = n;  long kk = k; ans = 0; long ps = 1;  long add ; if ( (n == 1)) {ans = 0; return ;} nn = (n - (ps - 1)); while((nn > kk)){add = bs(nn,kk); if ( (add == -1)) {ans = -1; return ;} else {ans = (ans + ((kk - add) + 1)); } long addn = (((((kk - add) + 1) * (kk + add)) / 2) - (kk - add)); ps = ((ps - 1) + addn); if ( (ps == n)) return ; nn = (nn - (ps - 1)); kk = (add - 1); }if ( (nn > 0)) {ans++; } } void print(){ System.out.println(ans); } long ans ; long n ; long k ; }
0	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();} long nextLong(){ return Long.parseLong(next());} } 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 { FastReader fr = new FastReader();  long n = fr.nextLong();  long x = fr.nextLong();  long y = fr.nextLong();  long w = (((Long.min(x,y) - 1) + (x - Long.min(x,y))) + (y - Long.min(x,y)));  long b = (((n - Long.max(x,y)) + (Long.max(x,y) - x)) + (Long.max(x,y) - y)); if ( (w <= b)) System.out.println("White"); else System.out.println("Black"); } }
5	public class A{ void solve()throws Exception { int n = nextInt();  int[] a = new int[n]; for ( int i = 0;(i < n);i++) a[i] = nextInt(); Arrays.sort(a); int[] res = new int[n]; for ( int i = 0;(i < n);i++) {if ( (i == 0)) res[i] = 1; else res[i] = a[(i - 1)]; }if ( (a[(n - 1)] == 1)) res[(n - 1)] = 2; for ( int i = 0;(i < n);i++) {if ( (i == (n - 1))) writer.println(res[i]); else writer.print((res[i] + " ")); }} BufferedReader reader ; PrintWriter writer ; StringTokenizer stk ; void run()throws Exception { reader = new BufferedReader(new InputStreamReader(System.in)); stk = null; writer = new PrintWriter(new PrintWriter(System.out)); solve(); reader.close(); writer.close(); } int nextInt()throws Exception { return Integer.parseInt(nextToken());} String nextLine()throws Exception { return reader.readLine();} String nextToken()throws Exception { if ( ((stk == null) || !stk.hasMoreTokens())) {stk = new StringTokenizer(nextLine()); return nextToken();} return stk.nextToken();} public static void main( String[] args)throws Exception { new A().run(); } }
6	public class F{ public static void main( String[] args){ FastScanner scanner = new FastScanner();  int N = scanner.nextInt();  int M = scanner.nextInt();  int[][] matrix = new int[N][M]; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < M);j++) {matrix[i][j] = scanner.nextInt(); }} int[][] maxDist = new int[N][N]; for ( int i = 0;(i < N);i++) {Arrays.fill(maxDist[i],Integer.MAX_VALUE); }for ( int i = 0;(i < M);i++) {for ( int j = 0;(j < N);j++) {for ( int k = (j + 1);(k < N);k++) {maxDist[j][k] = Math.min(maxDist[j][k],Math.abs((matrix[k][i] - matrix[j][i]))); maxDist[k][j] = maxDist[j][k]; }}} int[][] distTop = new int[N][N]; for ( int i = 0;(i < N);i++) {Arrays.fill(distTop[i],Integer.MAX_VALUE); }for ( int i = 0;(i < (M - 1));i++) {for ( int j = 0;(j < N);j++) {for ( int k = 0;(k < N);k++) {distTop[j][k] = Math.min(distTop[j][k],Math.abs((matrix[j][i] - matrix[k][(i + 1)]))); }}}if ( (N == 1)) {System.out.println(distTop[0][0]); System.exit(0); } int[] bitLoc = new int[(1 << N)]; for ( int i = 0;(i < N);i++) {bitLoc[(1 << i)] = i; } int[][][] dp = new int[(1 << N)][N][N]; for ( int mask = 1;(mask < (1 << N));mask++) {for ( int smask = mask;(smask > 0);smask &= (smask - 1)) { int i = bitLoc[Integer.lowestOneBit(smask)]; for ( int ss = (mask ^ (1 << i));(ss > 0);ss &= (ss - 1)) { int j = bitLoc[Integer.lowestOneBit(ss)]; if ( (mask == ((1 << i) ^ (1 << j)))) dp[mask][i][j] = maxDist[i][j]; else { int x = 0; for ( int sss = ((mask ^ (1 << i)) ^ (1 << j));(sss > 0);sss &= (sss - 1)) { int k = bitLoc[(sss & -sss)]; x = Math.max(x,Math.min(dp[(mask ^ (1 << j))][i][k],maxDist[k][j])); }dp[mask][i][j] = x; }}}} int mxMsk = ((1 << N) - 1);  int max = 0; for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < N);j++) {if ( (i == j)) continue; max = Math.max(max,Math.min(dp[mxMsk][i][j],distTop[i][j])); }}System.out.println(max); } public static class FastScanner{ BufferedReader br ; StringTokenizer st ; public FastScanner( Reader in){ br = new BufferedReader(in); } public FastScanner(){ this(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());} } }
3	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ public void solve( int testNumber, InputReader in, OutputWriter out){ int n = in.readInt();  boolean[] isF = new boolean[n]; for ( int i = 0;(i < n);i++) {isF[i] = (in.readCharacter() == 'f'); } FenwickTree[] fenwickTrees = new FenwickTree[(n + 1)]; for ( int i = 0;(i < fenwickTrees.length);i++) {fenwickTrees[i] = new FenwickTree((n + 1)); }fenwickTrees[n].add(0,1); for ( int idx = (n - 1);(idx >= 0);idx--) {for ( int indentLevel = 0;(indentLevel < n);indentLevel++) { long fenwickRes ; if ( isF[idx]) {fenwickRes = fenwickTrees[(idx + 1)].get((indentLevel + 1),(indentLevel + 1)); } else {fenwickRes = fenwickTrees[(idx + 1)].get(0,indentLevel); }fenwickTrees[idx].add(indentLevel,(fenwickRes % MiscUtils.MOD7)); }}out.printLine(fenwickTrees[0].get(0,0)); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char readCharacter(){ int c = read(); while(isSpaceChar(c)){c = read(); }return (char)c;} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } static class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void close(){ writer.close(); } public void printLine( long i){ writer.println(i); } } static class FenwickTree{ private final long[] value ; public FenwickTree( int size){ value = new long[size]; } public long get( int from, int to){ return (get(to) - get((from - 1)));} private long get( int to){ to = Math.min(to,(value.length - 1)); long result = 0; while((to >= 0)){result += value[to]; to = ((to & (to + 1)) - 1); }return result;} public void add( int at, long value){ while((at < this.value.length)){this.value[at] += value; at = (at | (at + 1)); }} } }
2	public class ProblemB{ public static void main( String[] args)throws IOException { BufferedReader s = new BufferedReader(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(System.out);  String[] line = s.readLine().split(" ");  long n = Long.valueOf(line[0]);  long y = Long.valueOf(line[1]);  long x = Long.valueOf(line[2]);  long c = Long.valueOf(line[3]);  long min = 0;  long max = ((n * 2L) + 20); for ( int cnt = 0;(cnt < 300);cnt++) { long med = ((min + max) / 2L);  long ct = isok(med,n,x,y,c); if ( (ct >= c)) {max = med; } else {min = (med + 1); }} long lst = max; for ( long d = -2;(d <= 2);d++) {if ( (((max + d) >= 0) && (isok((max + d),n,x,y,c) >= c))) {lst = Math.min(lst,(max + d)); } }out.println(lst); out.flush(); } static private long isok( long time, long n, long x, long y, long c){ long total = (((time * 2) * (time + 1)) + 1);  long top = (y - time); if ( (top <= 0)) { long dy = (Math.abs(top) + 1); total -= (dy * dy); long over = (dy - x); if ( (over >= 1)) {total += (((1L + over) * over) / 2); } over = (dy - ((n + 1) - x)); if ( (over >= 1)) {total += (((1L + over) * over) / 2); } } long bottom = (y + time); if ( (bottom > n)) { long dy = Math.abs((bottom - n)); total -= (dy * dy); long over = (dy - x); if ( (over >= 1)) {total += (((1L + over) * over) / 2); } over = (dy - ((n + 1) - x)); if ( (over >= 1)) {total += (((1L + over) * over) / 2); } } long left = (x - time); if ( (left <= 0)) { long dy = (Math.abs(left) + 1); total -= (dy * dy); } long right = (x + time); if ( (right > n)) { long dy = Math.abs((right - n)); total -= (dy * dy); } return total;} }
1	public class Main{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  int[] a = new int[1010]; while(in.hasNext()){ int n = in.nextInt();  String s = in.next();  int sum = 0; for ( int i = 0;(i < n);++i) {if ( (s.charAt(i) == 'H')) {a[i] = 1; ++sum; } else a[i] = 0; } int min = 10010; for ( int i = 0;(i < (n - sum));++i) { int count = 0; for ( int j = (i + sum);(j < n);++j) {if ( (a[j] == 1)) ++count; }for ( int j = 0;(j < i);++j) {if ( (a[j] == 1)) ++count; }if ( (count < min)) min = count; }sum = (n - sum); for ( int i = 0;(i < (n - sum));++i) { int count = 0; for ( int j = (i + sum);(j < n);++j) {if ( (a[j] == 0)) ++count; }for ( int j = 0;(j < i);++j) {if ( (a[j] == 0)) ++count; }if ( (count < min)) min = count; }System.out.println(min); }} }
4	@SuppressWarnings("unchecked") public class P35C{ static final int SHIFT = 11; static final int MASK = ((1 << SHIFT) - 1); static final int[] DX = {-1,1,0,0}; static final int[] DY = {0,0,-1,1}; public void run()throws Exception { int m = nextInt();  int n = nextInt();  boolean[][] burned = new boolean[n][m];  List<Integer> burn = new ArrayList(); for ( int k = nextInt();(k > 0);k--) { int x = (nextInt() - 1);  int y = (nextInt() - 1); burned[y][x] = true; burn.add(((x << SHIFT) | y)); } int lastXY = 0;  List<Integer> newBurn = null; do {lastXY = burn.get(0); newBurn = new ArrayList(); for ( int xy :burn) { int x = (xy >> SHIFT);  int y = (xy & MASK); for ( int i = 0;(i < 4);i++) { int nx = (x + DX[i]);  int ny = (y + DY[i]); if ( (((((ny >= 0) && (ny < n)) && (nx >= 0)) && (nx < m)) && burned)) {burned[ny][nx] = true; newBurn.add(((nx << SHIFT) | ny)); } }}burn = newBurn; }while((newBurn.size() > 0));println(((((lastXY >> SHIFT) + 1) + " ") + ((lastXY & MASK) + 1))); } public static void main( String... args)throws Exception { br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream("output.txt"))); new P35C().run(); br.close(); pw.close(); System.err.println((("\n[Time : " + (System.currentTimeMillis() - startTime)) + " ms]")); } static long startTime = System.currentTimeMillis(); static BufferedReader br ; static PrintWriter pw ; StringTokenizer stok ; String nextToken()throws IOException { while(((stok == null) || !stok.hasMoreTokens())){ String s = br.readLine(); if ( (s == null)) {return null;} stok = new StringTokenizer(s); }return stok.nextToken();} void print( byte b){ print(("" + b)); } void print( int i){ print(("" + i)); } void print( long l){ print(("" + l)); } void print( double d){ print(("" + d)); } void print( char c){ print(("" + c)); } void print( Object o){ if ( (o instanceof int[])) {print(Arrays.toString((int[])o)); } else if ( (o instanceof long[])) {print(Arrays.toString((long[])o)); } else if ( (o instanceof char[])) {print(Arrays.toString((char[])o)); } else if ( (o instanceof byte[])) {print(Arrays.toString((byte[])o)); } else if ( (o instanceof short[])) {print(Arrays.toString((short[])o)); } else if ( (o instanceof boolean[])) {print(Arrays.toString((boolean[])o)); } else if ( (o instanceof float[])) {print(Arrays.toString((float[])o)); } else if ( (o instanceof double[])) {print(Arrays.toString((double[])o)); } else if ( (o instanceof Object[])) {print(Arrays.toString((Object[])o)); } else {print(("" + o)); }} void print( String s){ pw.print(s); } void println(){ println(""); } void println( byte b){ println(("" + b)); } void println( int i){ println(("" + i)); } void println( long l){ println(("" + l)); } void println( double d){ println(("" + d)); } void println( char c){ println(("" + c)); } void println( Object o){ print(o); println(); } void println( String s){ pw.println(s); } int nextInt()throws IOException { return Integer.parseInt(nextToken());} long nextLong()throws IOException { return Long.parseLong(nextToken());} double nextDouble()throws IOException { return Double.parseDouble(nextToken());} String nextLine()throws IOException { return br.readLine();} }
1	public class CommentaryBoxes{ public static void main( String[] args){ FastReader in = new FastReader();  long n = in.nextLong();  long m = in.nextLong();  long a = in.nextLong();  long b = in.nextLong();  long total = 0;  long val = (n % m); if ( ((n % m) != 0)) { long x = (val * b);  long y = ((m - val) * a); total = Math.min(x,y); } System.out.println(Math.abs(total)); } 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();} long nextLong(){ return Long.parseLong(next());} } }
6	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);  G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion(); solver.solve(1,in,out); out.close(); } static class G1PlaylistForPolycarpEasyVersion{ final long mod = 1000000007; PrintWriter out ; InputReader in ; int n ; int time ; int[][] arr ; long[][][] dp ; long go( int last, int t, int mask){ if ( (t > time)) return 0; if ( (t == time)) {return 1l;} if ( (mask == ((1 << n) - 1))) return 0; if ( (dp[last][t][mask] != -1)) return dp[last][t][mask]; long cnt = 0;  int i = 0,j = 0; for ( i = 0;(i < n);i++) {if ( (((mask & (1 << i)) == 0) && (arr[i][1] != last))) {cnt += go(arr[i][1],(t + arr[i][0]),(mask | (1 << i))); cnt %= mod; } }dp[last][t][mask] = cnt; return cnt;} public void solve( int testNumber, InputReader in, PrintWriter out){ this.out = out; this.in = in; n = ni(); time = ni(); arr = new int[n][2]; int i = 0; for ( i = 0;(i < n);i++) {arr[i][0] = ni(); arr[i][1] = (ni() - 1); }dp = new long[3][(time + 1)][(1 << n)]; for ( i = 0;(i < 3);i++) {for ( int j = 0;(j <= time);j++) Arrays.fill(dp[i][j],-1); } long ans = ((((go(0,0,0) + go(1,0,0)) % mod) + go(2,0,0)) % mod); ans *= modPow(2,(mod - 2)); ans %= mod; pn(ans); } int ni(){ return in.nextInt();} void pn( Object o){ out.println(o); } long modPow( long a, long p){ long o = 1; while((p > 0)){if ( ((p & 1) == 1)) o = mul(o,a); a = mul(a,a); p >>= 1; }return o;} long mul( long a, long b){ if ( (a >= mod)) a %= mod; if ( (b >= mod)) b %= mod; a *= b; if ( (a >= mod)) a %= mod; return a;} } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new UnknownError()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new UnknownError());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int nextInt(){ return Integer.parseInt(next());} public String next(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuffer res = new StringBuffer(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} } }
4	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++) {burn[i][0] = nextInt(); burn[i][1] = nextInt(); } int ansx = -1;  int ansy = -1;  int ans = -1; for ( int i = 1;(i <= N);i++) {for ( int j = 1;(j <= M);j++) { int burnAt = Integer.MAX_VALUE; for ( int k = 0;(k < B);k++) { int now = distance(i,j,burn[k][0],burn[k][1]); burnAt = Math.min(burnAt,now); }if ( (burnAt >= ans)) {ans = burnAt; ansx = i; ansy = j; } }}out.println(((ansx + " ") + ansy)); } private int distance( int x, int y, int xx, int yy){ return (Math.abs((xx - x)) + Math.abs((yy - y)));} public static void main( String[] args){ new Main().run(); } public void run(){ try{in = new BufferedReader(new FileReader(new File("input.txt"))); out = new PrintWriter(new FileWriter(new File("output.txt"))); tok = null; solve(); in.close(); out.close(); }catch (IOException e){ System.exit(0); } } public String nextToken()throws IOException { while(((tok == null) || !tok.hasMoreTokens())){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} public int nextInt()throws IOException { return Integer.parseInt(nextToken());} PrintWriter out ; BufferedReader in ; StringTokenizer tok ; }
1	public class Main implements Runnable{ public void _main()throws IOException { int n = nextInt();  int even = 0,odd = 0,atEven = -1,atOdd = -1; for ( int i = 0;(i < n);i++) {if ( ((nextInt() % 2) == 0)) {atEven = i; ++even; } else {atOdd = i; ++odd; }}if ( (odd == 1)) out.print((atOdd + 1)); else out.print((atEven + 1)); } private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; private String next()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String rl = in.readLine(); if ( (rl == null)) return null; st = new StringTokenizer(rl); }return st.nextToken();} private int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args){ new Thread(new Main()).start(); } }
2	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);  TaskB solver = new TaskB(); solver.solve(1,in,out); out.close(); } } class TaskB{ public void solve( int testNumber, Scanner in, PrintWriter out){ long N = in.nextLong();  int K = in.nextInt();  long pipes = 1; if ( (N == 1)) {out.println(0); return ;} long left = 0,right = (K - 1),find = -1; while((left <= right)){ long mid = ((left + right) / 2); if ( ((((mid * mid) + ((1 - (2 * K)) * mid)) + (2 * (N - 1))) <= 0)) {find = mid; right = (mid - 1); } else left = (mid + 1); }out.println(find); } }
5	public class Main{ static class Run implements Runnable{ final boolean consoleIO = true; final String inFile = "input.txt"; final String outFile = "output.txt"; Pair<Double,Double>[] p ; int n ,t ; int find(){ int count = 2; for ( int i = 0;(i < (n - 1));++i) { double dif = (p[(i + 1)].a - p[i].b);  int comp = Double.compare(dif,t); if ( (comp == 0)) count += 1; else if ( (comp > 0)) count += 2; }return count;} @Override public void run(){ n = nextInt(); t = nextInt(); p = new Pair[n]; for ( int i = 0;(i < n);++i) { int x = (nextInt() + 1000);  int a = nextInt();  double h = (a / (double)2); p[i] = new Pair<Double,Double>((x - h),(x + h)); }Arrays.sort(p,new PComparator()); print(find()); close(); } class PComparator implements Comparator<Pair<Double,Double>>{ @Override public int compare( Pair<Double,Double> o1, Pair<Double,Double> o2){ return Double.compare(o1.a,o2.a);} } BufferedReader in ; PrintWriter out ; StringTokenizer strTok ; Run(){ if ( consoleIO) {initConsoleIO(); } else {initFileIO(); }} void initConsoleIO(){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); } void initFileIO(){ try{in = new BufferedReader(new FileReader(inFile)); out = new PrintWriter(new FileWriter(outFile)); }catch (FileNotFoundException e){ e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } } void close(){ try{in.close(); out.close(); }catch (IOException e){ e.printStackTrace(); } } int nextInt(){ return Integer.parseInt(nextToken());} boolean hasMoreTokens(){ return ((strTok == null) || strTok.hasMoreTokens());} String nextToken(){ while(((strTok == null) || !strTok.hasMoreTokens())){ String line ; try{line = in.readLine(); strTok = new StringTokenizer(line); }catch (IOException e){ e.printStackTrace(); } }return strTok.nextToken();} void print( Object o){ out.write(o.toString()); } void println( Object o){ out.write((o.toString() + '\n')); } void printf( String format, Object... args){ out.printf(format,args); } } public static void main( String[] args)throws IOException { Run run = new Run();  Thread thread = new Thread(run); thread.run(); } }
3	public class A{ void solve(){ int n = ni(); s = new char[(n + 1)]; s[0] = '.'; for ( int i = 1;(i <= n);i++) s[i] = ns().charAt(0); dp = new long[5001][5001]; dp[1][0] = 1; long sum[] = new long[(n + 2)]; sum[0] = 1; for ( int i = 2;(i <= n);i++) {for ( int j = 0;(j <= n);j++) {if ( (s[(i - 1)] == 'f')) {if ( ((j - 1) >= 0)) dp[i][j] = dp[(i - 1)][(j - 1)]; else dp[i][j] = 0; } else {dp[i][j] = sum[j]; }}for ( int j = n;(j >= 0);j--) {sum[j] = ((sum[(j + 1)] + dp[i][j]) % M); }} long ans = 0; for ( int i = 0;(i <= n);i++) {ans += dp[n][i]; if ( (ans >= M)) ans %= M; }pw.println(ans); } char s[] ; long dp[][] ; long go( int x, int cnt, int n){ if ( (x > n)) return 1; long cc = 0; if ( (dp[x][cnt] != -1)) return dp[x][cnt]; if ( (s[x] == 'f')) {cc = ((cc + go((x + 1),(cnt + 1),n)) % M); } else {for ( int j = cnt;(j >= 0);j--) cc = ((cc + go((x + 1),j,n)) % M); if ( (x == n)) cc = (((cc - cnt) + M) % M); }cc %= M; dp[x][cnt] = cc; return cc;} long M = ((long)1e9 + 7); InputStream is ; PrintWriter pw ; String INPUT = ""; void run()throws Exception { is = (INPUT.isEmpty()?System.in:new ByteArrayInputStream(INPUT.getBytes())); pw = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); pw.flush(); if ( !INPUT.isEmpty()) tr(((System.currentTimeMillis() - s) + "ms")); } public static void main( String[] args)throws Exception { new A().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0,ptrbuf = 0; 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++];} private boolean isSpaceChar( int c){ return ((c >= 33) && (c <= 126));} private int skip(){ int b ; while((((b = readByte()) != -1) && isSpaceChar(b)));return b;} private String ns(){ int b = skip();  StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){sb.appendCodePoint(b); b = readByte(); }return sb.toString();} private char[] ns( int n){ char[] buf = new char[n];  int b = skip(),p = 0; while(((p < n) && !isSpaceChar(b))){buf[p++] = (char)b; b = readByte(); }return ((n == p)?buf:Arrays.copyOf(buf,p));} private int ni(){ 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(); }} private void tr( Object... o){ if ( (INPUT.length() > 0)) System.out.println(Arrays.deepToString(o)); } }
4	public class Main{ final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null); BufferedReader in ; PrintWriter out ; StringTokenizer tok = new StringTokenizer(""); void init()throws FileNotFoundException { if ( ONLINE_JUDGE) {in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } else {in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); }} String readString()throws IOException { while(!tok.hasMoreTokens()){tok = new StringTokenizer(in.readLine()); }return tok.nextToken();} int readInt()throws IOException { return Integer.parseInt(readString());} public static void main( String[] args){ new Main().run(); } public static void mergeSort( int[] a){ mergeSort(a,0,(a.length - 1)); } static private void mergeSort( int[] a, int levtIndex, int rightIndex){ final int MAGIC_VALUE = 50; if ( (levtIndex < rightIndex)) {if ( ((rightIndex - levtIndex) <= MAGIC_VALUE)) {insertionSort(a,levtIndex,rightIndex); } else { int middleIndex = ((levtIndex + rightIndex) / 2); mergeSort(a,levtIndex,middleIndex); mergeSort(a,(middleIndex + 1),rightIndex); merge(a,levtIndex,middleIndex,rightIndex); }} } static private void merge( int[] a, int levtIndex, int middleIndex, int rightIndex){ int length1 = ((middleIndex - levtIndex) + 1);  int length2 = (rightIndex - middleIndex);  int[] levtArray = new int[length1];  int[] rightArray = new int[length2]; System.arraycopy(a,levtIndex,levtArray,0,length1); System.arraycopy(a,(middleIndex + 1),rightArray,0,length2); for ( int k = levtIndex,i = 0,j = 0;(k <= rightIndex);k++) {if ( (i == length1)) {a[k] = rightArray[j++]; } else if ( (j == length2)) {a[k] = levtArray[i++]; } else {a[k] = ((levtArray[i] <= rightArray[j])?levtArray[i++]:rightArray[j++]); }}} static private void insertionSort( int[] a, int levtIndex, int rightIndex){ for ( int i = (levtIndex + 1);(i <= rightIndex);i++) { int current = a[i];  int j = (i - 1); while(((j >= levtIndex) && (a[j] > current))){a[(j + 1)] = a[j]; j--; }a[(j + 1)] = current; }} public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println(("Time = " + (t2 - t1))); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } class Point{ double x ; double y ; Point( double x, double y){ this.x = x; this.y = y; } } public long gcd( long a, long b){ if ( ((a == 0) || (b == 0))) return max(a,b); if ( ((a % b) == 0)) return b; else return gcd(b,(a % b));} ArrayList<Integer> primes ; boolean[] isPrime ; public long binPowMod( long a, long b, long mod){ if ( (b == 0)) {return (1 % mod);} if ( ((b % 2) != 0)) {return (((a % mod) * (binPowMod(a,(b - 1),mod) % mod)) % mod);} else { long temp = (binPowMod(a,(b / 2),mod) % mod);  long ans = ((temp * temp) % mod); return ans;}} int type[] ; boolean vis[] ; HashMap<Integer,HashSet<Integer>> g ; int componentNum[] ; int p[] ; int find( int x){ if ( (x == p[x])) {return x;} return p[x] = find(p[x]);} boolean merge( int x, int y){ x = find(x); y = find(y); if ( (p[x] == p[y])) {return false;} p[y] = x; return true;} int s ; int n ; int m ; boolean isVisited[][] ; char[][] maze ; int[] dx = {0,0,-1,1}; int[] dy = {1,-1,0,0}; void dfs( int x, int y){ isVisited[x][y] = true; for ( int i = 0;(i < 4);i++) { int currX = (x + dx[i]);  int currY = (y + dy[i]); if ( ((maze[currX][currY] == '.') && !isVisited[currX][currY])) {dfs(currX,currY); } }} public void solve()throws IOException { n = readInt(); m = readInt(); maze = new char[(n + 2)][(m + 2)]; for ( int i = 0;(i < (n + 2));i++) {maze[i][0] = '#'; maze[i][(m + 1)] = '#'; }for ( int j = 0;(j < (m + 2));j++) {maze[0][j] = '#'; maze[(n + 1)][j] = '#'; }for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) {maze[i][j] = '.'; }} int[][] dist = new int[(n + 2)][(m + 2)]; for ( int i = 0;(i < (n + 2));i++) {for ( int j = 0;(j < (m + 2));j++) {dist[i][j] = Integer.MAX_VALUE; }} ArrayDeque<Integer> xValues = new ArrayDeque<Integer>();  ArrayDeque<Integer> yValues = new ArrayDeque<Integer>();  int k = readInt(); for ( int i = 0;(i < k);i++) { int currX = readInt();  int currY = readInt(); xValues.add(currX); yValues.add(currY); dist[currX][currY] = 0; }while(!xValues.isEmpty()){ int x = xValues.poll();  int y = yValues.poll(); for ( int i = 0;(i < 4);i++) { int currX = (x + dx[i]);  int currY = (y + dy[i]); if ( ((maze[currX][currY] == '.') && (dist[currX][currY] > (dist[x][y] + 1)))) {dist[currX][currY] = (dist[x][y] + 1); xValues.add(currX); yValues.add(currY); } }} int maxDist = 0;  int indexX = 0;  int indexY = 0; for ( int i = 1;(i <= n);i++) {for ( int j = 1;(j <= m);j++) {if ( (dist[i][j] >= maxDist)) {maxDist = dist[i][j]; indexX = i; indexY = j; } }}out.print(((indexX + " ") + indexY)); } }
0	public class Round125ProblemA{ public static void main( String[] args){ InputStream in = System.in;  OutputStream out = System.out;  InputReader reader = new InputReader(in);  PrintWriter writer = new PrintWriter(out); solve(reader,writer); writer.close(); } static void solve( InputReader in, PrintWriter out){ long fib = in.nextLong(); out.write(((((("" + 0) + " ") + 0) + " ") + fib)); } static class InputReader{ private BufferedReader reader ; private 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 long nextLong(){ return Long.parseLong(next());} } }
5	public class Solution implements Runnable{ public void solve()throws Exception { int n = nextInt();  int a[] = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); }Arrays.sort(a); if ( (n == 1)) {if ( (a[0] == 1)) {out.print(2); } else {out.print(1); }} else {out.print(1); for ( int i = 1;(i < n);i++) {if ( ((i == (n - 1)) && (a[i] == 1))) {out.print((" " + 2)); } else {out.print((" " + a[(i - 1)])); }}}} BufferedReader in ; PrintWriter out ; StringTokenizer st ; long stime = 0; private String next()throws Exception { while(((st == null) || !st.hasMoreElements()))st = new StringTokenizer(in.readLine()); return st.nextToken();} private int nextInt()throws Exception { return Integer.parseInt(next());} public static void main( String[] args)throws Exception { new Thread(null,new Solution(),"",(1 << 25)).start(); } }
5	public class Main{ public static void main( String[] args)throws IOException { try{if ( new File("input.txt").exists()) {System.setIn(new FileInputStream("input.txt")); } }catch (SecurityException e){ } new Main().run(); } BufferedReader in ; PrintWriter out ; StringTokenizer st = new StringTokenizer(""); void run()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int N = nextInt();  int T = nextInt();  Pair[] p = new Pair[N]; for ( int i = 0;(i < N);i++) p[i] = new Pair(nextInt(),nextInt()); sort(p); int ans = 2; for ( int i = 1;(i < N);i++) { int dif = (((2 * p[i].x) - p[i].a) - ((2 * p[(i - 1)].x) + p[(i - 1)].a)); if ( (dif == (2 * T))) ans++; else if ( (dif > (2 * T))) ans += 2; }out.println(ans); out.close(); } class Pair implements Comparable<Pair>{ int x ,a ; public Pair( int xx, int aa){ x = xx; a = aa; } } String nextToken()throws IOException { while(!st.hasMoreTokens())st = new StringTokenizer(in.readLine()); return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
2	public class cf256b{ public static void main( String[] args){ Scanner in = new Scanner(System.in);  long n = in.nextLong();  long x = (in.nextLong() - 1);  long y = (in.nextLong() - 1);  long c = in.nextLong();  long lo = 0,hi = ((2 * n) + 10); while(((hi - lo) > 2)){ long mid = ((hi + lo) / 2); if ( (calc(n,x,y,mid) >= c)) hi = mid; else lo = mid; }while((calc(n,x,y,lo) < c))lo++; System.out.println(lo); } static long calc( long n, long x, long y, long t){ long ans = (((2 * t) * (t + 1)) + 1);  long top = Math.max(0,(t - x));  long bottom = Math.max(0,(t - ((n - 1) - x)));  long left = Math.max(0,(t - y));  long right = Math.max(0,(t - ((n - 1) - y))); ans -= ((((top * top) + (bottom * bottom)) + (left * left)) + (right * right)); long tl = Math.max(0,(t - ((x + y) + 1)));  long tr = Math.max(0,(t - ((x + ((n - 1) - y)) + 1)));  long bl = Math.max(0,(t - ((((n - 1) - x) + y) + 1)));  long br = Math.max(0,(t - ((((n - 1) - x) + ((n - 1) - y)) + 1))); ans += ((((((tl * tl) + tl) / 2) + (((tr * tr) + tr) / 2)) + (((bl * bl) + bl) / 2)) + (((br * br) + br) / 2)); return ans;} }
4	public class Main{ public static void main( String[] args)throws FileNotFoundException { Scanner read = new Scanner(new FileInputStream(new File("input.txt")));  PrintWriter out = new PrintWriter(new File("output.txt"));  int n = read.nextInt(),m = read.nextInt(),k = read.nextInt(),tree[][] = new int[n][m],a[] = new int[k],b[] = new int[k],x = 0,y = 0,max = -1,d = 0; for ( int i = 0;(i < k);i++) {a[i] = (read.nextInt() - 1); b[i] = (read.nextInt() - 1); tree[a[i]][b[i]] = 0; }for ( int i = 0;(i < n);i++) {Arrays.fill(tree[i],Integer.MAX_VALUE); }for ( int o = 0;(o < k);o++) {for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {d = (Math.abs((a[o] - i)) + Math.abs((b[o] - j))); if ( (d < tree[i][j])) tree[i][j] = d; }}}for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (tree[i][j] > max)) {max = tree[i][j]; x = i; y = j; } }}out.println((((x + 1) + " ") + (y + 1))); out.close(); } }
1	public class Main{ static private StreamTokenizer in ; static private PrintWriter out ; static private int nextInt()throws Exception { in.nextToken(); return (int)in.nval;} public static void main( String[] args)throws Exception { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); int n = nextInt();  byte f = (byte)nextInt();  byte s = (byte)nextInt();  byte t = (byte)nextInt();  boolean bf = false;  boolean bs = false;  boolean bt = false; if ( ((f & 1) == 0)) {bf = true; } if ( ((s & 1) == 0)) {bs = true; } if ( ((t & 1) == 0)) {bt = true; } if ( ((bf && bs) && bt)) {System.out.println(1); return ;} if ( ((bf && bs) && bt)) {System.out.println(2); return ;} if ( ((bf && bs) && bt)) {System.out.println(3); return ;} if ( ((bf && !bs) && !bt)) {System.out.println(1); return ;} if ( ((!bf && bs) && !bt)) {System.out.println(2); return ;} if ( ((!bf && !bs) && bt)) {System.out.println(3); return ;} for ( int i = 4;(i <= n);i++) { byte g = (byte)nextInt(); if ( (((g + f) & 1) == 1)) {System.out.println(i); return ;} }out.flush(); } }
6	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]; static int n ,m ; static void solve(){ n = in.nextInt(); m = in.nextInt(); int[][] a = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) a[i][j] = in.nextInt(); for ( int i = 0;(i < n);i++) {Arrays.fill(mn1[i],Integer.MAX_VALUE); Arrays.fill(mn2[i],Integer.MAX_VALUE); }for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) for ( int k = 0;(k < m);k++) {mn1[i][j] = Math.min(mn1[i][j],Math.abs((a[i][k] - a[j][k]))); if ( (k <= (m - 2))) mn2[i][j] = Math.min(mn2[i][j],Math.abs((a[i][k] - a[j][(k + 1)]))); } int ans = 0; for ( int i = 0;(i < n);i++) {for ( int x = 0;(x < (1 << n));x++) Arrays.fill(dp[x],-1); for ( int j = 0;(j < n);j++) dp[(1 << j)][j] = 0; dp[(1 << i)][i] = Integer.MAX_VALUE; for ( int j = 0;(j < n);j++) ans = Math.max(ans,Math.min(mn2[j][i],calc(((1 << n) - 1),j))); }out.println(ans); } static int calc( int mask, int v){ if ( (dp[mask][v] != -1)) return dp[mask][v]; dp[mask][v] = 0; for ( int u = 0;(u < n);u++) if ( ((v != u) && (((mask >> u) & 1) > 0))) dp[mask][v] = Math.max(dp[mask][v],Math.min(mn1[u][v],calc((mask ^ (1 << v)),u))); return dp[mask][v];} public static void main( String[] args){ solve(); out.flush(); out.close(); } static class FastReader{ BufferedReader br ; StringTokenizer st ; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader( String s)throws Exception{ br = new BufferedReader(new FileReader(s)); } 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(in.next());} } }
1	public class D999{ public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int m = sc.nextInt();  int req = (n / m);  int arr[] = new int[(n + 1)];  int size[] = new int[m];  List<Integer> list[] = new ArrayList[m]; for ( int i = 0;(i < m);i++) {list[i] = new ArrayList<>(); }for ( int i = 1;(i <= n);i++) {arr[i] = sc.nextInt(); size[(arr[i] % m)]++; list[(arr[i] % m)].add(i); } long tot = 0;  int x = 0,y = 0;  List<Integer> idx = new ArrayList<>(); for ( int i = 0;(i < (2 * m));i++) {if ( (size[(i % m)] > req)) {for ( int j = 0;(j < (size[(i % m)] - req));j++) {idx.add(list[(i % m)].get(j)); y++; }size[(i % m)] = req; } else if ( (size[(i % m)] < req)) {while(((x != y) && (size[(i % m)] < req))){ int num = arr[idx.get(x)];  int gg = (i - (num % m)); tot += gg; arr[idx.get(x)] += gg; x++; size[(i % m)]++; }} }System.out.println(tot); for ( int i = 1;(i <= n);i++) {System.out.print((arr[i] + " ")); }} }
4	public class Main1{ static int dr[] = {0,0,1,-1}; static int dc[] = {1,-1,0,0}; static boolean isValid( int r, int c){ if ( ((((r >= n) || (r < 0)) || (c >= m)) || (c < 0))) return false; return true;} static int grid[][] ; static int n ,m ; public static void main( String[] args)throws IOException { FastReader input = new FastReader();  PrintWriter out = new PrintWriter("output.txt"); n = input.nextInt(); m = input.nextInt(); grid = new int[n][m]; int k = input.nextInt(); for ( int i = 0;(i < n);i++) {Arrays.fill(grid[i],Integer.MAX_VALUE); } Queue<Pair> q = new LinkedList<Pair>(); for ( int i = 0;(i < k);i++) { int x = (input.nextInt() - 1);  int y = (input.nextInt() - 1); q.add(new Pair(x,y)); grid[x][y] = 0; while(!q.isEmpty()){ Pair cur = q.poll(); for ( int j = 0;(j < dr.length);j++) { int r = cur.x;  int c = cur.y;  int nr = (r + dr[j]);  int nc = (c + dc[j]);  int dist = (grid[r][c] + 1); if ( (isValid(nr,nc) && (grid[nr][nc] > dist))) {grid[nr][nc] = dist; q.add(new Pair(nr,nc)); } }}} int max = -1;  int x = -1;  int y = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) {if ( (grid[i][j] > max)) {max = grid[i][j]; x = (i + 1); y = (j + 1); } }}out.println(((x + " ") + y)); out.flush(); } static class FastReader{ BufferedReader br ; StringTokenizer st ; public FastReader()throws FileNotFoundException{ br = new BufferedReader(new FileReader(new File("input.txt"))); } String next()throws IOException { while(((st == null) || !st.hasMoreElements())){st = new StringTokenizer(br.readLine()); }return st.nextToken();} int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(next());} } static class Pair implements Comparable<Pair>{ int x ; int y ; Pair( int x, int y){ this.x = x; this.y = y; } } static int gcd( int a, int b){ return ((b == 0)?a:gcd(b,(a % b)));} }
3	public class PythonIndentiation{ PrintWriter pw = new PrintWriter(System.out); static final boolean debugmode = true; public static int k = 7; public static int STMOD = (1000000000 + k); public static Reader sc = new Reader(); public static void main( String[] args)throws IOException { int commands = sc.nextInt();  int[][] dp = new int[5000][5000];  int interesting = 0;  String prgm = ""; while((interesting < commands)){ byte q = sc.read(); if ( (q == 115)) {interesting += 1; prgm += "s"; } else if ( (q == 102)) {prgm += "f"; interesting += 1; } }dp[0][0] = 1; for ( int line = 1;(line < commands);line++) {if ( (prgm.charAt((line - 1)) == 'f')) {for ( int indent = 1;(indent < Math.min(((2 * line) + 1),5000));indent++) {dp[line][indent] = dp[(line - 1)][(indent - 1)]; }} else if ( (prgm.charAt((line - 1)) == 's')) { int w = 0; for ( int indent = Math.min(((2 * line) + 1),4999);(indent >= 0);indent--) {w = ((w + dp[(line - 1)][indent]) % STMOD); dp[line][indent] = w; }} } int q = 0; for ( int i = 0;(i < 5000);i++) {q = ((q + dp[(commands - 1)][i]) % STMOD); }System.out.println(q); } static class Reader{ private final int BUFFER_SIZE = (1 << 16); private DataInputStream din ; private byte[] buffer ; private int bufferPointer ,bytesRead ; public Reader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader( String file_name)throws IOException{ din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt()throws IOException { int ret = 0;  byte c = read(); while((c <= ' '))c = read(); boolean neg = (c == '-'); if ( neg) c = read(); do {ret = (((ret * 10) + c) - '0'); }while((((c = read()) >= '0') && (c <= '9')));if ( neg) return -ret; return ret;} private void fillBuffer()throws IOException { bytesRead = din.read(buffer,bufferPointer = 0,BUFFER_SIZE); if ( (bytesRead == -1)) buffer[0] = -1; } private byte read()throws IOException { if ( (bufferPointer == bytesRead)) fillBuffer(); return buffer[bufferPointer++];} public void close()throws IOException { if ( (din == null)) return ; din.close(); } } }
1	public class Iq{ static void metod()throws Exception { Scanner in = new Scanner(System.in);  int n = in.nextInt();  int[] m = new int[n]; for ( int i = 0;(i < n);i++) m[i] = in.nextInt(); byte k = 0; if ( ((m[0] % 2) == 0)) {if ( ((m[1] % 2) == 0)) {k = 0; } else {if ( ((m[2] % 2) == 0)) {System.out.println(2); return ;} else {System.out.println(1); return ;}}} else {if ( ((m[1] % 2) == 1)) {k = 1; } else {if ( ((m[2] % 2) == 0)) {System.out.println(1); return ;} else {System.out.println(2); return ;}}}if ( (k == 0)) {for ( int i = 0;(i < m.length);i++) {if ( ((m[i] % 2) == 1)) {System.out.println((i + 1)); break;} }} else {for ( int i = 0;(i < m.length);i++) {if ( ((m[i] % 2) == 0)) {System.out.println((i + 1)); break;} }}} public static void main( String[] args)throws Exception { Iq.metod(); } }
5	public class AA{ static class Pair implements Comparable<Pair>{ public int x ,y ; public Pair( int x, int y){ this.x = x; this.y = y; } } public static void main( String[] args){ Scanner in = new Scanner(System.in);  int n = in.nextInt();  int t = (in.nextInt() * 2);  List<Pair> l = new ArrayList<Pair>(); for ( int i = 0;(i < n);i++) { int c = (in.nextInt() * 2);  int a = in.nextInt(); l.add(new Pair((c - a),(c + a))); }Collections.sort(l); int ret = 2; for ( int i = 1;(i < n);i++) {if ( ((l.get(i).x - l.get((i - 1)).y) > t)) ret += 2; else if ( ((l.get(i).x - l.get((i - 1)).y) == t)) ret += 1; }System.out.println(ret); } }
5	public class House{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  int t = sc.nextInt();  ArrayList<HS> list = new ArrayList<HS>(); for ( int i = 0;(i < n);i++) {list.add(new HS(sc.nextInt(),sc.nextInt())); }Collections.sort(list); int count = 0; if ( (n >= 1)) count = 2; for ( int i = 0;(i < (list.size() - 1));i++) { double d = Math.abs((list.get((i + 1)).x - list.get(i).x)); d -= (((1.0 * list.get(i).a) / 2.0) + ((1.0 * list.get((i + 1)).a) / 2.0)); if ( ((d >= t) && ((d - t) <= 0.00000001))) {count++; } else if ( (d > t)) {count += 2; } }System.out.println(count); } } class HS implements Comparable<HS>{ public int x ; public int a ; public HS( int x, int a){ this.x = x; this.a = a; } }
3	public class Codeshefcode{ public static void main( String[] args)throws IOException { Solver Machine = new Solver(); Machine.Solve(); Machine.Finish(); } } class Solver{ Reader ip = new Reader(System.in); PrintWriter op = new PrintWriter(System.out); long dp[][] ; public void Solve()throws IOException { int n = ip.i();  int arr[] = new int[n]; dp = new long[n][n]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) dp[i][j] = -1; for ( int i = 0;(i < n);i++) { String s = ip.s(); if ( (s.compareTo("s") == 0)) arr[i] = 0; else if ( (s.compareTo("f") == 0)) arr[i] = 1; else throw (new IOException());}for ( int j = 0;(j < n);j++) dp[(n - 1)][j] = 1; for ( int i = (n - 2);(i >= 0);i--) { long cuml[] = new long[n]; for ( int j = 0;(j < n);j++) cuml[j] = ((dp[(i + 1)][j] + ((j == 0)?0:cuml[(j - 1)])) % Mod.mod); for ( int j = 0;(j < n);j++) dp[i][j] = ((arr[i] == 0)?cuml[j]:((j == (n - 1))?-1:dp[(i + 1)][(j + 1)])); }pln(dp[0][0]); } void Finish(){ op.flush(); op.close(); } void pln( Object o){ op.println(o); } } class Reader{ BufferedReader reader ; StringTokenizer tokenizer ; Reader( InputStream input){ reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } String s()throws IOException { while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine()); }return tokenizer.nextToken();} int i()throws IOException { return Integer.parseInt(s());} }
0	public class ProblemA{ public static void main( String[] args){ Scanner sc = new Scanner(System.in);  long n = sc.nextLong();  long[] answer = new long[3]; if ( (n == 1)) {answer[0] = 0; answer[1] = 0; answer[2] = 1; } else if ( (n > 1)) { long f1 = 0;  long f2 = 1;  long m = 0; while((m < n)){answer[0] = answer[1]; answer[1] = f1; answer[2] = f2; m = (f1 + f2); f1 = f2; f2 = m; }answer[2] = answer[1]; } System.out.println(((((answer[0] + " ") + answer[1]) + " ") + answer[2])); } }
4	public class FireAgain{ static int n ,m ,k ; static int inf = (int)1e9; static class Pair{ int x ,y ; Pair( int a, int b){ x = a; y = b; } } static int[] dx = {1,-1,0,0},dy = {0,0,1,-1}; static boolean valid( int x, int y){ return ((((x >= 0) && (x < n)) && (y >= 0)) && (y < m));} static int[][] bfs( int[] xs, int[] ys){ int[][] dist = new int[n][m]; for ( int i = 0;(i < n);i++) Arrays.fill(dist[i],inf); Queue<Pair> q = new LinkedList<>(); for ( int i = 0;(i < k);i++) {dist[xs[i]][ys[i]] = 0; q.add(new Pair(xs[i],ys[i])); }while(!q.isEmpty()){ Pair p = q.remove(); for ( int d = 0;(d < 4);d++) { int nx = (p.x + dx[d]),ny = (p.y + dy[d]); if ( (valid(nx,ny) && (dist[nx][ny] == inf))) {dist[nx][ny] = (dist[p.x][p.y] + 1); q.add(new Pair(nx,ny)); } }}return dist;} public static void main( String[] args)throws IOException { Scanner sc = new Scanner(); n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt(); int[] xs = new int[k],ys = new int[k]; for ( int i = 0;(i < k);i++) {xs[i] = (sc.nextInt() - 1); ys[i] = (sc.nextInt() - 1); } int[][] dist = bfs(xs,ys);  int x = 0,y = 0; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) if ( (dist[i][j] > dist[x][y])) {x = i; y = j; } x++; y++; PrintWriter out = new PrintWriter("output.txt"); out.println(((x + " ") + y)); out.flush(); out.close(); } static class Scanner{ BufferedReader br ; StringTokenizer st ; Scanner()throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt")); } 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());} } }
5	public class Beta15PA{ public static void main( String[] args){ Beta15PA temp = new Beta15PA(); temp.solve(); } public void solve(){ Scanner scan = new Scanner(System.in);  int n = scan.nextInt(),t = scan.nextInt();  House[] houses = new House[n]; for ( int i = 0;(i < n);i++) {houses[i] = new House(scan.nextInt(),scan.nextInt()); }Arrays.sort(houses); int res = 2; for ( int i = 0;(i < (n - 1));i++) { double cnt = (houses[(i + 1)].coordinate - houses[i].coordinate); cnt -= ((1.0 * (houses[(i + 1)].side + houses[i].side)) / 2); if ( (cnt > t)) res += 2; else if ( (Math.abs((cnt - t)) < 1e-7)) res += 1; }System.out.println(res); } public class House implements Comparable<House>{ public int coordinate ,side ; public House( int coordinate, int side){ this.coordinate = coordinate; this.side = side; } } }
5	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.nextDouble() / 2); coords.add((x - a)); coords.add((x + a)); }Collections.sort(coords); int count = 2;  ChoiceFormat f = new ChoiceFormat("-1#0|0#1|0<2"); for ( int i = 1;(i < (coords.size() - 2));i += 2) {count += new Integer(f.format(((coords.get((i + 1)) - coords.get(i)) - t))); }System.out.println(count); } }
3	public class TaskC{ public static void main( String[] args){ new TaskC().run(); } void solve(){ int n = in.nextInt();  String s[] = new String[n]; for ( int i = 0;(i < n);i++) s[i] = in.next(); if ( (s[(n - 1)].compareTo("f") == 0)) {out.println(0); return ;} int dp[] = new int[(n + 2)];  int mod = (((1000 * 1000) * 1000) + 7); dp[0] = 1; for ( int i = (n - 1);(i >= 0);i--) {if ( (s[i].compareTo("s") == 0)) { int ss = 0; for ( int j = 0;(j <= n);j++) {ss += dp[j]; if ( (ss >= mod)) ss -= mod; dp[j] = ss; }} else {for ( int j = 0;(j < n);j++) {dp[j] = dp[(j + 1)]; }dp[n] = 0; }}out.println(dp[0]); } FastScanner in ; PrintWriter out ; void run(){ in = new FastScanner(System.in); out = new PrintWriter(System.out); int tests = 1; while((tests > 0)){solve(); tests--; }out.close(); } class FastScanner{ StringTokenizer st ; BufferedReader bf ; public FastScanner( InputStream is){ bf = new BufferedReader(new InputStreamReader(is)); } public FastScanner( File f){ try{bf = new BufferedReader(new FileReader(f)); }catch (IOException ex){ ex.printStackTrace(); } } String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(bf.readLine()); }catch (Exception ex){ ex.printStackTrace(); } }return st.nextToken();} int nextInt(){ return Integer.parseInt(next());} } }
4	public class FireAgain{ Point coordinate ; Queue<Point> q = new LinkedList<Point>(); int m ,n ; boolean[][] arr ; PrintStream out ; void bfs( Point start){ while(!q.isEmpty()){ Point front = q.poll();  Point p = new Point(); p.x = (front.x - 1); p.y = front.y; if ( ((((p.x >= 1) && (p.x <= n)) && (p.y <= m)) && (p.y >= 1))) {if ( !arr[p.x][p.y]) {arr[p.x][p.y] = true; q.add(p); } } p = new Point(); p.x = (front.x + 1); p.y = front.y; if ( ((((p.x >= 1) && (p.x <= n)) && (p.y <= m)) && (p.y >= 1))) if ( !arr[p.x][p.y]) {arr[p.x][p.y] = true; q.add(p); } p = new Point(); p.x = front.x; p.y = (front.y + 1); if ( ((((p.x >= 1) && (p.x <= n)) && (p.y <= m)) && (p.y >= 1))) if ( !arr[p.x][p.y]) {arr[p.x][p.y] = true; q.add(p); } p = new Point(); p.x = front.x; p.y = (front.y - 1); if ( ((((p.x >= 1) && (p.x <= n)) && (p.y <= m)) && (p.y >= 1))) if ( !arr[p.x][p.y]) {arr[p.x][p.y] = true; q.add(p); } if ( (q.size() == 0)) out.print(((front.x + " ") + front.y)); }} public static void main( String[] args)throws FileNotFoundException { FireAgain fa = new FireAgain();  Scanner Scan = new Scanner(new FileInputStream("input.txt")); fa.out = new PrintStream(new File("output.txt")); fa.n = Scan.nextInt(); fa.m = Scan.nextInt(); int k = Scan.nextInt(); fa.arr = new boolean[2001][2001]; for ( int i = 0;(i < k);i++) {fa.coordinate = new Point(); fa.coordinate.x = Scan.nextInt(); fa.coordinate.y = Scan.nextInt(); fa.q.add(fa.coordinate); fa.arr[fa.coordinate.x][fa.coordinate.y] = true; }fa.bfs(fa.q.peek()); } }
4	public class Main{ public static void main( String[] args)throws IOException { InputReader in = new InputReader(new FileReader(new File("input.txt")));  PrintWriter out = new PrintWriter(new FileWriter(new File("output.txt")));  Solution s = new Solution(); s.solve(1,in,out); out.close(); } static class Solution{ double EPS = 0.0000001; public void solve( int cs, InputReader in, PrintWriter out){ int n = in.nextInt(),m = in.nextInt();  Graph g = new Graph(n,m);  int k = in.nextInt(); for ( int[] v :g.vis) Arrays.fill(v,-1); while((k-- > 0)){ Pair start = new Pair((in.nextInt() - 1),(in.nextInt() - 1)); g.bfs(start); } int idx1 = 0,idx2 = 0,max = 0; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);++j) {if ( (g.vis[i][j] > max)) {idx1 = i; idx2 = j; max = g.vis[i][j]; } }}out.println((((idx1 + 1) + " ") + (idx2 + 1))); } static class Pair{ int x ,y ; public Pair( int x, int y){ this.x = x; this.y = y; } } static class Graph{ LinkedList<Integer> adj[] ; int n ,e ; int[][] vis ; public Graph( int n, int e){ this.n = n; this.e = e; adj = new LinkedList[n]; for ( int i = 0;(i < n);++i) adj[i] = new LinkedList<>(); vis = new int[n][e]; } int[] dx = {0,0,1,-1}; int[] dy = {1,-1,0,0}; void bfs( Pair src){ Queue<Pair> q = new LinkedList<>(); vis[src.x][src.y] = 0; q.add(src); while(!q.isEmpty()){ Pair p = q.poll(); for ( int k = 0;(k < 4);k++) { int ni = (p.x + dx[k]);  int nj = (p.y + dy[k]); if ( (isValid(ni,nj) && ((vis[ni][nj] == -1) || ((vis[p.x][p.y] + 1) < vis[ni][nj])))) {vis[ni][nj] = (vis[p.x][p.y] + 1); q.add(new Pair(ni,nj)); } }}} boolean isValid( int i, int j){ return ((((i >= 0) && (i < n)) && (j >= 0)) && (j < e));} } } static class InputReader{ BufferedReader br ; StringTokenizer st ; public InputReader( InputStream i){ br = new BufferedReader(new InputStreamReader(i),32768); st = null; } public InputReader( FileReader s){ br = new BufferedReader(s); st = null; } 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());} } }
1	public class Main{ void run()throws IOException { int n = in.nextInt();  char[] c = in.next().toCharArray();  int[][] t = new int[n][n];  int[][] h = new int[n][n];  int allt = 0,allh = 0; for ( int i = 0;(i < n);i++) {if ( (c[i] == 'T')) {allt++; } else {allh++; }}for ( int i = 0;(i < n);i++) {if ( (c[i] == 'T')) {t[i][i] = 1; h[i][i] = 0; } else {t[i][i] = 0; h[i][i] = 1; }for ( int j = (i + 1);(j < n);j++) {if ( (c[j] == 'T')) {t[i][j] = (t[i][(j - 1)] + 1); h[i][j] = h[i][(j - 1)]; } else {h[i][j] = (h[i][(j - 1)] + 1); t[i][j] = t[i][(j - 1)]; }}}for ( int i = 1;(i < n);i++) {t[i][(i - 1)] = allt; h[i][(i - 1)] = allh; for ( int j = 0;(j < (i - 1));j++) {t[i][j] = (allt - t[(j + 1)][(i - 1)]); h[i][j] = (allh - h[(j + 1)][(i - 1)]); }} int r = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < n);j++) {if ( (h[i][j] == t[((j + 1) % n)][(((i - 1) + n) % n)])) {r = min(r,h[i][j]); } if ( (t[i][j] == h[((j + 1) % n)][(((i - 1) + n) % n)])) {r = min(r,t[i][j]); } }}out.println(r); } static PrintWriter out ; static Scanner in ; public static void main( String[] args)throws IOException { Locale.setDefault(Locale.US); in = new Scanner(System.in); out = new PrintWriter(System.out); new Main().run(); out.close(); } }
2	public class MainA{ public static void main( String[] args)throws Exception { Scanner in = new Scanner(new BufferedInputStream(System.in));  PrintStream out = new PrintStream(System.out);  Solution solution = new Solution(in,out); solution.solve(); in.close(); out.close(); } private static class Solution{ final int inf = (int)1e9; int n ,x ,y ,c ; int f( int u, int r, int sec){ if ( ((u == 0) && (r == 0))) return 0; if ( (u == 0)) {return (r - 1);} if ( (r == 0)) {return (u - 1);} return Math.min((sec - 1),(((u - 1) + r) - 1));} boolean isok( int sec){ int up = (x - 1);  int down = (n - x);  int right = (n - y);  int left = (y - 1);  int u = 0,d = 0,r = 0,l = 0;  int total = 1;  int add = 4; for ( int i = 1;(i <= sec);i++) { int cc = 0; if ( ((i > up) && (++cc > 0))) u++; if ( ((i > down) && (++cc > 0))) d++; if ( ((i > right) && (++cc > 0))) r++; if ( ((i > left) && (++cc > 0))) l++; total += (add - cc); total -= Math.max(0,f(u,r,i)); total -= Math.max(0,f(u,l,i)); total -= Math.max(0,f(d,r,i)); total -= Math.max(0,f(d,l,i)); if ( (total >= c)) return true; add += 4; }return false;} public void solve(){ n = in.nextInt(); x = in.nextInt(); y = in.nextInt(); c = in.nextInt(); if ( (c == 1)) {out.println(0); return ;} int lo = 0,hi = 60000; while((lo < hi)){ int mid = ((lo + hi) / 2); if ( isok(mid)) {hi = mid; } else {lo = (mid + 1); }}out.println(lo); } public Solution( Scanner in, PrintStream out){ this.in = in; this.out = out; } Scanner in ; PrintStream out ; } }
5	public class C{ public static void main( String... args){ Scanner sc = new Scanner(System.in);  int n = sc.nextInt(); sc.nextLine(); int[] x = new int[n];  int max = 0,pos = -1; for ( int i = 0;(i < n);i++) {x[i] = sc.nextInt(); if ( (max < x[i])) {max = x[i]; pos = i; } }x[pos] = ((max == 1)?2:1); Arrays.sort(x); for ( int i = 0;(i < n);i++) System.out.print((x[i] + " ")); } }
4	public class C{ Scanner in ; PrintWriter out ; String INPUT = ""; void solve(){ int n = ni();  int m = ni();  int k = ni();  int[] x = new int[k];  int[] y = new int[k]; for ( int i = 0;(i < k);i++) {x[i] = (ni() - 1); y[i] = (ni() - 1); } int max = -1;  int maxi = -1;  int maxj = -1; for ( int i = 0;(i < n);i++) {for ( int j = 0;(j < m);j++) { int min = Integer.MAX_VALUE; for ( int l = 0;(l < k);l++) {min = Math.min(min,(Math.abs((x[l] - i)) + Math.abs((y[l] - j)))); }if ( (min > max)) {max = min; maxi = i; maxj = j; } }}out.println((((maxi + 1) + " ") + (maxj + 1))); } void run()throws Exception { in = (INPUT.isEmpty()?new Scanner(new File("input.txt")):new Scanner(INPUT)); out = (INPUT.isEmpty()?new PrintWriter("output.txt"):new PrintWriter(System.out)); solve(); out.flush(); } public static void main( String[] args)throws Exception { new C().run(); } int ni(){ return Integer.parseInt(in.next());} }
1	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 kisu = 0;  int gusu = 0; for ( int i = 0;(i < n);i++) {nums[i] = sc.nextInt(); if ( ((nums[i] % 2) == 0)) gusu++; if ( ((nums[i] % 2) == 1)) kisu++; } int ans = -1; if ( (gusu == 1)) {for ( int i = 0;(i < n);i++) {if ( ((nums[i] % 2) == 0)) {ans = (i + 1); break;} }} else {for ( int i = 0;(i < n);i++) {if ( ((nums[i] % 2) == 1)) {ans = (i + 1); break;} }}System.out.println(ans); } }
5	public class Village{ static class House implements Comparable<House>{ public double center ,length ; public House( double center, double length){ this.center = center; this.length = length; } public double getRight(){ return (center + (length / 2));} public double getLeft(){ return (center - (length / 2));} } public static void main( String[] args){ Scanner in = new Scanner(System.in);  String[] fline = in.nextLine().split("\\s+");  int N = Integer.parseInt(fline[0]);  int T = Integer.parseInt(fline[1]);  House[] houses = new House[N]; for ( int i = 0;(i < N);i++) { String[] house = in.nextLine().split("\\s+"); houses[i] = new House(Double.parseDouble(house[0]),Double.parseDouble(house[1])); }Arrays.sort(houses); int count = 2; for ( int i = 0;(i < (houses.length - 1));i++) { double diff = (houses[(i + 1)].getLeft() - houses[i].getRight()); if ( (diff < T)) continue; if ( (Math.abs((diff - T)) < 1E-12)) count++; else count += 2; }System.out.println(count); } }
4	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 * fuck)],Q = new int[(fuck * (fuck + 1))],dx = new int[]{1,-1,0,0},dy = new int[]{0,0,-1,1}; Arrays.fill(D,-1); int H = -1,T = 0;  int k = in.nextInt(),ans = 0; for ( int i = 0;(i < k);++i) { int x = in.nextInt(),y = in.nextInt(); D[((x * fuck) + y)] = 0; ++H; H %= Q.length; ans = Q[H] = ((x * fuck) + y); }while((H >= T)){ int idx = Q[T++]; T %= Q.length; int x = (idx / fuck),y = (idx % fuck); for ( int i = 0;(i < 4);++i) { int wtf = (((dx[i] + x) * fuck) + (dy[i] + y)); if ( ((((((dx[i] + x) <= n) && ((dx[i] + x) >= 1)) && ((dy[i] + y) <= m)) && ((dy[i] + y) >= 1)) && (D[wtf] == -1))) {D[wtf] = (D[idx] + 1); ++H; H %= Q.length; Q[H] = wtf; if ( (D[wtf] >= D[ans])) ans = wtf; } }}out.println((((ans / fuck) + " ") + (ans % fuck))); out.close(); in.close(); } }
2	public class bender{ static long[] dx = new long[]{0,1,0,-1}; static long[] dy = new long[]{-1,0,1,0}; static long n ,x ,y ,c ; public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  StringTokenizer dxdync = new StringTokenizer(in.readLine()); n = Long.parseLong(dxdync.nextToken()); x = Long.parseLong(dxdync.nextToken()); y = Long.parseLong(dxdync.nextToken()); c = Long.parseLong(dxdync.nextToken()); long a = 0;  long b = c; while((a < b)){ long m = ((a + b) / 2);  long[] dxn = new long[4];  long[] dyn = new long[4]; for ( int d = 0;(d < 4);d++) {dxn[d] = (x + (dx[d] * m)); dyn[d] = (y + (dy[d] * m)); } long ret = (((m + 1) * (m + 1)) + (m * m)); ret -= h((1 - dyn[0])); ret -= h((dyn[2] - n)); ret -= h((dxn[1] - n)); ret -= h((1 - dxn[3])); ret += q(((1 - dyn[0]) - ((n - x) + 1))); ret += q(((1 - dyn[0]) - x)); ret += q(((dyn[2] - n) - ((n - x) + 1))); ret += q(((dyn[2] - n) - x)); if ( (ret < c)) a = (m + 1); else b = m; }System.out.println(a); } public static long h( long x){ if ( (x <= 0)) return 0; return ((2 * q(x)) - x);} static private long q( long x){ if ( (x <= 0)) return 0; return ((x * (x + 1)) / 2);} }
1	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();  char[] poks = in.next().toCharArray();  boolean[] was = new boolean[52]; for ( int i = 0;(i < n);i++) {if ( Character.isLowerCase(poks[i])) {was[(poks[i] - 'a')] = true; } else {was[((poks[i] - 'A') + 26)] = true; }} int count = 0; for ( int i = 0;(i < 52);i++) {count += (was[i]?1:0); } int[] vis = new int[52];  int pre = 0;  int chr = 0;  int ans = Integer.MAX_VALUE; for ( int i = 0;(i < n);i++) { int pos = (poks[i] - 'a'); if ( Character.isUpperCase(poks[i])) {pos = ((poks[i] - 'A') + 26); } if ( (vis[pos] == 0)) {chr++; } vis[pos]++; while((chr == count)){ans = Math.min(ans,((i - pre) + 1)); pos = (poks[pre] - 'a'); if ( Character.isUpperCase(poks[pre])) {pos = ((poks[pre] - 'A') + 26); } vis[pos]--; if ( (vis[pos] == 0)) chr--; pre++; }}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; 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());} } }
1	public class B{ public static void main( String[] args)throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));  int n = Integer.parseInt(bf.readLine());  StringTokenizer st = new StringTokenizer(bf.readLine());  Integer[] a = new Integer[n]; for ( int i = 0;(i < n);i++) a[i] = Integer.parseInt(st.nextToken()); Arrays.sort(a); int[] b = new int[n]; for ( int i = 0;(i < n);i++) b[i] = a[i].intValue(); boolean diff = false;  boolean diff2 = false;  Set<Integer> vals = new HashSet<Integer>(); vals.add(b[0]); int valval = 0; for ( int i = 1;(i < n);i++) {vals.add(b[i]); if ( (b[i] == b[(i - 1)])) {if ( !diff) {diff = true; valval = b[i]; } else diff2 = true; } } long sum = 0; for ( int i :b) sum += i; sum -= (((1L * n) * (n - 1)) / 2); if ( (diff && !diff2)) {if ( (!vals.contains((valval - 1)) && (valval > 0))) {if ( ((sum % 2) == 0)) out.println("cslnb"); else out.println("sjfnb"); } else out.println("cslnb"); } else if ( diff2) out.println("cslnb"); else if ( ((sum % 2) == 0)) out.println("cslnb"); else out.println("sjfnb"); out.close(); System.exit(0); } }
0	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].indexOf('s') != -1)) s++; if ( (S[i].indexOf('p') != -1)) p++; } int n1 = Integer.parseInt(S[0].substring(0,1));  int n2 = Integer.parseInt(S[1].substring(0,1));  int n3 = Integer.parseInt(S[2].substring(0,1));  int d3 = Math.abs((n1 - n2));  int d4 = Math.abs((n1 - n3));  int d5 = Math.abs((n2 - n3)); if ( (((m == 3) || (s == 3)) || (p == 3))) {if ( (((((d3 == 1) & (d5 == 1)) & (d4 == 2)) || (((d3 == 1) & (d4 == 1)) & (d5 == 2))) || (((d5 == 1) & (d4 == 1)) & (d3 == 2)))) System.out.println(0); else if ( ((d3 == 0) & (d4 == 0))) System.out.println(0); else if ( ((d3 < d5) & (d3 < d4))) {if ( (((d3 == 1) || (d3 == 2)) || (d3 == 0))) System.out.println(1); else System.out.println(2); } else if ( ((d5 < d4) & (d5 < d3))) {if ( (((d5 == 1) || (d5 == 2)) || (d5 == 0))) System.out.println(1); else System.out.println(2); } else if ( ((d4 < d5) & (d4 < d3))) {if ( (((d4 == 1) || (d4 == 2)) || (d4 == 0))) System.out.println(1); else System.out.println(2); } else if ( (((((((d3 == 2) & (d5 == 2)) || ((d4 == 2) & (d5 == 2))) || ((d3 == 2) & (d4 == 2))) || ((d3 == 1) & (d5 == 1))) || ((d4 == 1) & (d5 == 1))) || ((d3 == 2) & (d4 == 1)))) System.out.println(1); else System.out.println(2); } if ( (((m == 2) || (s == 2)) || (p == 2))) { char c1 = S[0].charAt(1);  char c2 = S[1].charAt(1);  char c3 = S[2].charAt(1); if ( (c1 == c2)) {if ( (n1 == n2)) System.out.println(1); else if ( ((d3 == 1) || (d3 == 2))) System.out.println(1); else System.out.println(2); } if ( (c1 == c3)) {if ( (n1 == n3)) System.out.println(1); else if ( ((d4 == 1) || (d4 == 2))) System.out.println(1); else System.out.println(2); } if ( (c2 == c3)) {if ( (n2 == n3)) System.out.println(1); else if ( ((d5 == 1) || (d5 == 2))) System.out.println(1); else System.out.println(2); } } if ( (((m == 1) & (s == 1)) & (p == 1))) System.out.println(2); } }
5	public class A{ static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st ; static PrintWriter out = new PrintWriter(System.out); static String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String s = bf.readLine(); if ( (s == null)) return null; st = new StringTokenizer(s); }return st.nextToken();} static int nextInt()throws IOException { return Integer.parseInt(nextToken());} public static void main( String[] args)throws IOException { int n = nextInt();  int a[] = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = nextInt(); }Arrays.sort(a); for ( int q = 0;(q < n);q++) {if ( (a[q] != 1)) {out.print("1"); for ( int i = 1;(i < n);i++) {out.print((" " + a[(i - 1)])); }out.flush(); return ;} }for ( int i = 0;(i < (n - 1));i++) {out.print("1 "); }out.println("2"); out.flush(); } }
0	public class C994{ static double area( double x1, double y1, double x2, double y2, double x3, double y3){ return Math.abs(((((x1 * (y2 - y3)) + (x2 * (y3 - y1))) + (x3 * (y1 - y2))) / 2.0));} 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 x11 = sc.nextInt();  int y11 = sc.nextInt();  int x12 = sc.nextInt();  int y12 = sc.nextInt();  int x13 = sc.nextInt();  int y13 = sc.nextInt();  int x14 = sc.nextInt();  int y14 = sc.nextInt();  double x1c = ((((x11 + x12) + x13) + x14) / 4.0);  double y1c = ((((y11 + y12) + y13) + y14) / 4.0);  int x21 = sc.nextInt();  int y21 = sc.nextInt();  int x22 = sc.nextInt();  int y22 = sc.nextInt();  int x23 = sc.nextInt();  int y23 = sc.nextInt();  int x24 = sc.nextInt();  int y24 = sc.nextInt();  double x2c = ((((x21 + x22) + x23) + x24) / 4.0);  double y2c = ((((y21 + y22) + y23) + y24) / 4.0);  double a1 = (area(x11,y11,x12,y12,x13,y13) + area(x11,y11,x13,y13,x14,y14));  double a2 = (area(x21,y21,x22,y22,x23,y23) + area(x21,y21,x23,y23,x24,y24)); if ( (a1 == (((area(x11,y11,x12,y12,x21,y21) + area(x11,y11,x21,y21,x14,y14)) + area(x21,y21,x12,y12,x13,y13)) + area(x21,y21,x14,y14,x13,y13)))) {pw.println("YES"); pw.close(); return ;} if ( (a1 == (((area(x11,y11,x12,y12,x22,y22) + area(x11,y11,x22,y22,x14,y14)) + area(x22,y22,x12,y12,x13,y13)) + area(x22,y22,x14,y14,x13,y13)))) {pw.println("YES"); pw.close(); return ;} if ( (a1 == (((area(x11,y11,x12,y12,x23,y23) + area(x11,y11,x23,y23,x14,y14)) + area(x23,y23,x12,y12,x13,y13)) + area(x23,y23,x14,y14,x13,y13)))) {pw.println("YES"); pw.close(); return ;} if ( (a1 == (((area(x11,y11,x12,y12,x24,y24) + area(x11,y11,x24,y24,x14,y14)) + area(x24,y24,x12,y12,x13,y13)) + area(x24,y24,x14,y14,x13,y13)))) {pw.println("YES"); pw.close(); return ;} if ( (a1 == (((area(x11,y11,x12,y12,x2c,y2c) + area(x11,y11,x2c,y2c,x14,y14)) + area(x2c,y2c,x12,y12,x13,y13)) + area(x2c,y2c,x14,y14,x13,y13)))) {pw.println("YES"); pw.close(); return ;} if ( (a2 == (((area(x21,y21,x22,y22,x11,y11) + area(x21,y21,x11,y11,x24,y24)) + area(x11,y11,x22,y22,x23,y23)) + area(x11,y11,x24,y24,x23,y23)))) {pw.println("YES"); pw.close(); return ;} if ( (a2 == (((area(x21,y21,x22,y22,x12,y12) + area(x21,y21,x12,y12,x24,y24)) + area(x12,y12,x22,y22,x23,y23)) + area(x12,y12,x24,y24,x23,y23)))) {pw.println("YES"); pw.close(); return ;} if ( (a2 == (((area(x21,y21,x22,y22,x13,y13) + area(x21,y21,x13,y13,x24,y24)) + area(x13,y13,x22,y22,x23,y23)) + area(x13,y13,x24,y24,x23,y23)))) {pw.println("YES"); pw.close(); return ;} if ( (a2 == (((area(x21,y21,x22,y22,x14,y14) + area(x21,y21,x14,y14,x24,y24)) + area(x14,y14,x22,y22,x23,y23)) + area(x14,y14,x24,y24,x23,y23)))) {pw.println("YES"); pw.close(); return ;} if ( (a2 == (((area(x21,y21,x22,y22,x1c,y1c) + area(x21,y21,x14,y14,x2c,y2c)) + area(x1c,y1c,x22,y22,x23,y23)) + area(x1c,y1c,x24,y24,x23,y23)))) {pw.println("YES"); pw.close(); return ;} pw.println("NO"); pw.close(); } }
2	public class B{ static Scanner in ; static PrintWriter out ; public static long count( long k, long x, long y, long n){ long sum = (((2 * k) * (k + 1)) + 1); if ( (k >= (x - 1))) {sum -= (((k - x) + 1) * ((k - x) + 1)); } if ( (k >= (y - 1))) {sum -= (((k - y) + 1) * ((k - y) + 1)); } if ( ((k + x) >= n)) {sum -= (((k + x) - n) * ((k + x) - n)); } if ( ((k + y) >= n)) {sum -= (((k + y) - n) * ((k + y) - n)); } if ( (k > ((x + y) - 1))) {sum += (((((k + 1) - x) - y) * ((((k + 1) - x) - y) + 1)) / 2); } if ( (k > ((n - x) + y))) {sum += (((((k + x) - n) - y) * ((((k + x) - n) - y) + 1)) / 2); } if ( (k > ((n - y) + x))) {sum += (((((k + y) - n) - x) * ((((k + y) - n) - x) + 1)) / 2); } if ( (k > ((((2 * n) - x) - y) + 1))) {sum += ((((((k - (2 * n)) + x) + y) - 1) * (((k - (2 * n)) + x) + y)) / 2); } return sum;} public static void main( String[] args)throws Exception { in = new Scanner(System.in); out = new PrintWriter(System.out); long n = in.nextLong(),x = in.nextLong(),y = in.nextLong(),c = in.nextLong();  long res = 0; while((count(res,x,y,n) < c))res++; out.println(res); out.println(); out.close(); } }
3	public class Main{ public static void main( String[] args){ solve(System.in,System.out); } static void solve( InputStream inStream, PrintStream printStream){ Scanner in = new Scanner(inStream);  int n = in.nextInt();  long[] sums = new long[n]; for ( int i = 1;(i < n);i++) {sums[i] = 0; }sums[0] = 1; long mod = 1000000007; for ( int i = 0;(i < n);i++) {if ( in.next().equals("f")) {for ( int j = (n - 1);(j > 0);j--) {sums[j] = sums[(j - 1)]; }sums[0] = 0; } else {for ( int j = (n - 2);(j >= 0);j--) {sums[j] += sums[(j + 1)]; if ( (sums[j] >= mod)) {sums[j] -= mod; } }}}printStream.println(sums[0]); } }
1	public class TaskA implements Runnable{ private InputReader in ; private PrintWriter out ; public static void main( String[] args){ new Thread(new TaskA()).start(); } public TaskA(){ in = new InputReader(System.in); out = new PrintWriter(System.out); } static private class InputReader{ private InputStream stream ; private byte[] buf = new byte[1000]; private int curChar ,numChars ; public InputReader( InputStream stream){ this.stream = stream; } private int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuffer res = new StringBuffer(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} private boolean isSpaceChar( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} private String readLine0(){ StringBuffer buf = new StringBuffer();  int c = read(); while(((c != '\n') && (c != -1))){buf.appendCodePoint(c); c = read(); }return buf.toString();} public String readLine(){ String s = readLine0(); while((s.trim().length() == 0))s = readLine0(); return s;} public String readLine( boolean ignoreEmptyLines){ if ( ignoreEmptyLines) return readLine(); else return readLine0();} } }
6	public class A{ static MyScanner sc ; static PrintWriter pw ; public static void main( String[] args)throws Throwable { sc = new MyScanner(); pw = new PrintWriter(System.out); n = sc.nextInt(); int m = sc.nextInt();  int[][] a = new int[n][m]; for ( int i = 0;(i < n);i++) for ( int j = 0;(j < m);j++) a[i][j] = sc.nextInt(); val = new int[n][n]; for ( int i = 0;(i < n);i++) Arrays.fill(val[i],Integer.MAX_VALUE); for ( int i = 0;(i < n);i++) for ( int j = i;(j < n);j++) {for ( int k = 0;(k < m);k++) val[i][j] = val[j][i] = Math.min(val[i][j],Math.abs((a[i][k] - a[j][k]))); }val2 = new int[n][n]; for ( int i = 0;(i < n);i++) Arrays.fill(val2[i],Integer.MAX_VALUE); for ( int i = 0;(i < n);i++) for ( int j = 0;(j < n);j++) {for ( int k = 0;(k < (m - 1));k++) val2[i][j] = Math.min(val2[i][j],Math.abs((a[i][k] - a[j][(k + 1)]))); }mem = new Long[n][n][(1 << n)]; long ans = 0; for ( int i = 0;(i < n);i++) {ans = Math.max(ans,dp(i,i,(1 << i))); }if ( (n == 1)) pw.println(val2[0][0]); else pw.println(ans); pw.flush(); pw.close(); } static int n ; static int[][] val ,val2 ; static Long[][][] mem ; static long dp( int st, int lst, int msk){ int bits = Integer.bitCount(msk); if ( (mem[st][lst][msk] != null)) return mem[st][lst][msk]; long ans = 0; for ( int i = 0;(i < n);i++) if ( ((msk & (1 << i)) == 0)) { int newMsk = (msk | (1 << i)); if ( (bits < (n - 1))) ans = Math.max(ans,Math.min(val[lst][i],dp(st,i,newMsk))); else ans = Math.max(ans,Math.min(val[lst][i],val2[i][st])); } return mem[st][lst][msk] = ans;} 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());} } }
5	public class A{ static InputStreamReader in = new InputStreamReader(System.in); static BufferedReader bf = new BufferedReader(in); static StreamTokenizer st = new StreamTokenizer(bf); static Scanner sc = new Scanner(System.in); static class Sort implements Comparable<Sort>{ int x ,a ; } public static void main( String[] args)throws IOException { int n = nextInt();  double t = nextInt();  Sort[] p = new Sort[n]; for ( int i = 0;(i < n);i++) {p[i] = new Sort(); p[i].x = nextInt(); p[i].a = nextInt(); } int ans = 2; Arrays.sort(p); for ( int i = 1;(i < p.length);i++) { double k = (((p[i].x - (p[i].a / 2.0)) - p[(i - 1)].x) - (p[(i - 1)].a / 2.0)); if ( (t == k)) ans++; else if ( (k > t)) ans += 2; }System.out.println(ans); } static private int nextInt()throws IOException { st.nextToken(); return (int)st.nval;} }
5	public class A{ BufferedReader in ; StringTokenizer st ; PrintWriter out ; static class House implements Comparable<House>{ final int x ,a ; House( int x, int a){ this.x = x; this.a = a; } } void solve()throws IOException { int n = nextInt();  int t = nextInt();  House[] h = new House[n]; for ( int i = 0;(i < n);++i) {h[i] = new House((2 * nextInt()),nextInt()); }Arrays.sort(h); int ans = 2; for ( int i = 1;(i < n);++i) { House prev = h[(i - 1)];  House curr = h[i];  int diff = (((2 * t) + curr.a) + prev.a); if ( ((curr.x - prev.x) == diff)) {++ans; } else if ( ((curr.x - prev.x) > diff)) {ans += 2; } }out.println(ans); } public void run()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); eat(""); solve(); out.close(); in.close(); } void eat( String s){ st = new StringTokenizer(s); } String next()throws IOException { while(!st.hasMoreTokens()){ String line = in.readLine(); if ( (line == null)) {return null;} eat(line); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(next());} public static void main( String[] args)throws IOException { new A().run(); } }
5	public class C{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = null; private void solution()throws IOException { int n = nextInt();  int[] mas = new int[n]; for ( int i = 0;(i < n);i++) {mas[i] = nextInt(); }Arrays.sort(mas); if ( (mas[(n - 1)] == 1)) {mas[(n - 1)] = 2; } else {mas[(n - 1)] = 1; }Arrays.sort(mas); for ( int i = 0;(i < n);i++) {System.out.print((mas[i] + " ")); }} String nextToken()throws IOException { if ( ((st == null) || !st.hasMoreTokens())) {st = new StringTokenizer(bf.readLine()); } return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} public static void main( String[] args)throws IOException { new C().solution(); } }
5	public class l{ static long mod = (int)(1e9 + 7); static int n ; static StringBuilder sol ; static boolean is ; public static void main( String[] args)throws IOException { Scanner sc = new Scanner(System.in);  PrintWriter pw = new PrintWriter(System.out);  int m = sc.nextInt();  int n = sc.nextInt();  int q = sc.nextInt();  TreeSet<Integer> length = new TreeSet<>(); length.add(0); length.add(n); TreeSet<Integer> width = new TreeSet<>(); width.add(0); width.add(m); TreeMap<Integer,Integer> len = new TreeMap<>(); len.put(n,1); TreeMap<Integer,Integer> wid = new TreeMap<>(); wid.put(m,1); while((q-- > 0)){ String t = sc.next(); if ( t.equals("H")) { int x = sc.nextInt();  int k1 = length.ceiling(x);  int k2 = length.floor(x); if ( (x != k1)) { int s = (k1 - k2);  int con = len.get(s); if ( (con == 1)) len.remove(s); else len.put(s,(con - 1)); len.put((k1 - x),(len.getOrDefault((k1 - x),0) + 1)); len.put((x - k2),(len.getOrDefault((x - k2),0) + 1)); length.add(x); } } else { int x = sc.nextInt();  int k1 = width.ceiling(x);  int k2 = width.floor(x); if ( (x != k1)) { int s = (k1 - k2);  int con = wid.get(s); if ( (con == 1)) wid.remove(s); else wid.put(s,(con - 1)); wid.put((k1 - x),(wid.getOrDefault((k1 - x),0) + 1)); wid.put((x - k2),(wid.getOrDefault((x - k2),0) + 1)); width.add(x); } }pw.println(((1l * len.lastKey()) * wid.lastKey())); }pw.flush(); } 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()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 boolean ready()throws IOException { return br.ready();} } }
4	public class Problem{ public static Pair solve( Forest f, List<Pair> queue){ Pair current = null,next = null;  int index = 0; while((queue.size() > 0)){current = queue.remove(0); index = f.desk[current.x][current.y]; if ( (current.x > 0)) {next = new Pair((current.x - 1),current.y); if ( (f.desk[next.x][next.y] == 0)) {f.desk[next.x][next.y] = (index + 1); queue.add(next); } } if ( (current.x < (f.N - 1))) {next = new Pair((current.x + 1),current.y); if ( (f.desk[next.x][next.y] == 0)) {f.desk[next.x][next.y] = (index + 1); queue.add(next); } } if ( (current.y > 0)) {next = new Pair(current.x,(current.y - 1)); if ( (f.desk[next.x][next.y] == 0)) {f.desk[next.x][next.y] = (index + 1); queue.add(next); } } if ( (current.y < (f.M - 1))) {next = new Pair(current.x,(current.y + 1)); if ( (f.desk[next.x][next.y] == 0)) {f.desk[next.x][next.y] = (index + 1); queue.add(next); } } }return f.findMax();} public static void main( String[] args){ String buffer = null;  StringTokenizer st = null;  Forest f = null;  List<Pair> pairs = new LinkedList<Pair>();  Integer N ,M ,K ,x ,y ; try{ BufferedReader in = new BufferedReader(new FileReader("input.txt"));  FileWriter out = new FileWriter("output.txt"); buffer = in.readLine(); st = new StringTokenizer(buffer); N = new Integer(st.nextToken()); M = new Integer(st.nextToken()); f = new Forest(N,M); buffer = in.readLine(); st = new StringTokenizer(buffer); K = new Integer(st.nextToken()); buffer = in.readLine(); st = new StringTokenizer(buffer); for ( int i = 0;(i < K);i++) {x = new Integer(st.nextToken()); y = new Integer(st.nextToken()); f.desk[(x - 1)][(y - 1)] = 1; pairs.add(new Pair((x - 1),(y - 1))); } Pair res = solve(f,pairs); out.write(res.toString()); out.flush(); }catch (Exception e){ } } } class Pair{ public Pair( int i, int j){ x = i; y = j; } public String toString(){ return (((x + 1) + " ") + (y + 1));} public int x ; public int y ; } class Forest{ public Forest( int n, int m){ N = n; M = m; desk = new int[N][M]; } public Pair findMax(){ Pair max = new Pair(0,0); for ( int i = 0;(i < N);i++) {for ( int j = 0;(j < M);j++) {if ( (desk[i][j] > desk[max.x][max.y])) {max.x = i; max.y = j; } }}return max;} public int N ; public int M ; public int[][] desk ; }
4	public class Main{ public static void main( String[] args)throws IOException { new Thread(null,new Runnable(){public void run(){ try{try{if ( new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt"));  }catch (SecurityException e){ } new Main().run(); }catch (IOException e){ e.printStackTrace(); } } },"1",(1L << 24)).start(); } BufferedReader in ; PrintWriter out ; StringTokenizer st = new StringTokenizer(""); int N ; int M ; boolean[][] used ; Queue<Integer> queue ; int[] dx = {-1,0,1,0}; int[] dy = {0,-1,0,1}; int ans = -1; void run()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter("output.txt"); N = nextInt(); M = nextInt(); used = new boolean[N][M]; queue = new ArrayDeque<Integer>((N * M)); for ( int K = nextInt();(K-- > 0);) addState((nextInt() - 1),(nextInt() - 1)); while(!queue.isEmpty()){ int cv = queue.poll();  int cx = (cv / M);  int cy = (cv % M); for ( int d = 0;(d < dx.length);d++) { int nx = (cx + dx[d]);  int ny = (cy + dy[d]); if ( (((((0 <= nx) && (nx < N)) && (0 <= ny)) && (ny < M)) && !used[nx][ny])) addState(nx,ny); }}out.println((((1 + (ans / M)) + " ") + (1 + (ans % M)))); out.close(); } void addState( int x, int y){ used[x][y] = true; queue.add(ans = code(x,y)); } int code( int x, int y){ return ((x * M) + y);} String nextToken()throws IOException { while(!st.hasMoreTokens()){st = new StringTokenizer(in.readLine()); }return st.nextToken();} int nextInt()throws IOException { return Integer.parseInt(nextToken());} }
3	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  InputReader in = new InputReader(inputStream);  OutputWriter out = new OutputWriter(outputStream);  TaskC solver = new TaskC(); solver.solve(1,in,out); out.close(); } static class TaskC{ public void solve( int testNumber, InputReader in, OutputWriter out){ int n = in.readInt();  boolean[] isF = new boolean[n]; for ( int i = 0;(i < n);i++) {isF[i] = (in.readCharacter() == 'f'); } long[][] mem = new long[(n + 1)][(n + 1)]; mem[n][0] = 1; for ( int idx = (n - 1);(idx >= 0);idx--) {for ( int indentLevel = 0;(indentLevel < n);indentLevel++) {mem[(idx + 1)][(indentLevel + 1)] += mem[(idx + 1)][indentLevel]; long res = (isF[idx]?(mem[(idx + 1)][(indentLevel + 1)] - mem[(idx + 1)][indentLevel]):mem[(idx + 1)][indentLevel]); mem[idx][indentLevel] = (res % MiscUtils.MOD7); }}out.printLine(mem[0][0]); } } static class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private InputReader.SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) {throw (new InputMismatchException());} if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) {return -1;} } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c)){c = read(); } int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) {throw (new InputMismatchException());} res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public boolean isSpaceChar( int c){ if ( (filter != null)) {return filter.isSpaceChar(c);} return isWhitespace(c);} public static boolean isWhitespace( int c){ return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public char readCharacter(){ int c = read(); while(isSpaceChar(c)){c = read(); }return (char)c;} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } } static class OutputWriter{ private final PrintWriter writer ; public OutputWriter( OutputStream outputStream){ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter( Writer writer){ this.writer = new PrintWriter(writer); } public void close(){ writer.close(); } public void printLine( long i){ writer.println(i); } } }
4	public class Main{ void solve(){ int R = sc.nextInt();  int C = sc.nextInt();  int K = sc.nextInt();  int[] x = new int[K];  int[] y = new int[K]; for ( int i = 0;(i < K);i++) {x[i] = sc.nextInt(); y[i] = sc.nextInt(); } int best = -1;  int bestX = 0;  int bestY = 0; for ( int r = 1;(r <= R);r++) for ( int c = 1;(c <= C);c++) { int here = (R + C); for ( int i = 0;(i < K);i++) { int t = (abs((r - x[i])) + abs((c - y[i]))); here = min(here,t); }if ( (best < here)) {best = here; bestX = r; bestY = c; } }out.println(((bestX + " ") + bestY)); } void print( int[] a){ out.print(a[0]); for ( int i = 1;(i < a.length);i++) out.print((" " + a[i])); out.println(); } public static void main( String[] args)throws Exception { new Main().run(); } MyScanner sc = null; PrintWriter out = null; public void run()throws Exception { sc = new MyScanner(new FileInputStream(new File("input.txt"))); out = new PrintWriter(new File("output.txt")); for ( ;sc.hasNext();) {solve(); out.flush(); }out.close(); } class MyScanner{ String line ; BufferedReader reader ; StringTokenizer tokenizer ; public MyScanner( InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public void eat(){ while(((tokenizer == null) || !tokenizer.hasMoreTokens())){try{line = reader.readLine(); if ( (line == null)) {tokenizer = null; return ;} tokenizer = new StringTokenizer(line); }catch (IOException e){ throw (new RuntimeException(e));} }} public String next(){ eat(); return tokenizer.nextToken();} public boolean hasNext(){ eat(); return ((tokenizer != null) && tokenizer.hasMoreElements());} public int nextInt(){ return Integer.parseInt(next());} } }
4	@SuppressWarnings("unused") public class round35C{ static class state{ int x ,y ,time ; public state( int xx, int yy, int t){ x = xx; y = yy; time = t; } } static int N ,M ; static int[] dx = new int[]{1,-1,0,0}; static int[] dy = new int[]{0,0,1,-1}; static Queue<state> bfs = new LinkedList<round35C.state>(); public static Point runBFS(){ boolean[][] vis = new boolean[(N + 1)][(M + 1)];  int max = (int)1e9;  int bestx = -1;  int besty = -1; while(!bfs.isEmpty()){ state p = bfs.poll();  int x = p.x;  int y = p.y;  int time = p.time; if ( vis[x][y]) continue; vis[x][y] = true; if ( (time > max)) {max = time; bestx = (x + 1); besty = (y + 1); } for ( int i = 0;(i < 4);++i) { int nx = (x + dx[i]);  int ny = (y + dy[i]); if ( ((((nx < 0) || (ny < 0)) || (nx >= N)) || (ny >= M))) continue; if ( (vis[nx][ny] == false)) bfs.offer(new state(nx,ny,(time + 1))); }}return new Point(bestx,besty);} public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter("output.txt");  String[] use = null; use = br.readLine().split(" "); N = parseInt(use[0]); M = parseInt(use[1]); int K = parseInt(br.readLine()); use = br.readLine().split(" "); for ( int i = 0;(i < (2 * K));i += 2) { int f = (parseInt(use[i]) - 1);  int t = (parseInt(use[(i + 1)]) - 1); bfs.offer(new state(f,t,0)); } Point ans = runBFS(); out.println(((ans.x + " ") + ans.y)); out.flush(); out.close(); } }
5	public class P015A{ public static void main( String[] args){ Scanner inScanner = new Scanner(System.in);  int n = inScanner.nextInt();  int t = inScanner.nextInt();  House[] houses = new House[n]; for ( int i = 0;(i < n);i++) houses[i] = new House(inScanner.nextInt(),inScanner.nextInt()); Arrays.sort(houses); int sum = 2; for ( int i = 1;(i < n);i++) { double space = (houses[i].leftX - houses[(i - 1)].rightX); if ( (space >= t)) sum++; if ( (space > t)) sum++; }System.out.println(sum); } static private class House implements Comparable<House>{ int x ; double leftX ; double rightX ; public House( int x, int size){ super(); this.x = x; leftX = (x - ((double)size / 2)); rightX = (x + ((double)size / 2)); } } }
1	public class F{ static void solve()throws Exception { int n = scanInt();  long l[] = new long[n]; for ( int i = 0;(i < n);i++) {l[i] = scanLong(); } long e1 = 0,e2 = 0,ans = 0;  boolean water = false;  String types = scanString(); for ( int i = 0;(i < n);i++) { long li = l[i],cur ; switch(types.charAt(i)){ case 'G':cur = min(e1,li); e1 -= cur; li -= cur; e2 += (2 * cur); ans += (2 * cur); e2 += li; ans += (3 * li); break; case 'W':water = true; e1 += li; ans += (2 * li); break; case 'L':cur = min(e1,li); e1 -= cur; li -= cur; ans += (2 * cur); cur = min(e2,li); e2 -= cur; li -= cur; ans += (3 * cur); ans += ((water?4:6) * li); break; default :throw (new AssertionError()); } }out.print(ans); } 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); } } }
4	public class Solution{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new FileReader("input.txt"));  PrintWriter out = new PrintWriter("output.txt");  String[] raw = in.readLine().split(" ");  int n = Integer.parseInt(raw[0]);  int m = Integer.parseInt(raw[1]);  int k = Integer.parseInt(in.readLine()); raw = in.readLine().split(" "); boolean[][] map = new boolean[n][m];  LinkedList<Point> queue = new LinkedList<>(); for ( int i = 0;(i < k);i++) { Point fireStarter = new Point((Integer.parseInt(raw[(i * 2)]) - 1),(Integer.parseInt(raw[((i * 2) + 1)]) - 1)); queue.addLast(fireStarter); } int treesLeft = (n * m); while(true){ Point firepoint = queue.removeFirst(); if ( map[firepoint.x][firepoint.y]) continue; treesLeft--; map[firepoint.x][firepoint.y] = true; if ( (treesLeft == 0)) {out.printf("%d %d",(firepoint.x + 1),(firepoint.y + 1)); out.flush(); return ;} if ( ((firepoint.x > 0) && !map[(firepoint.x - 1)][firepoint.y])) queue.add(new Point((firepoint.x - 1),firepoint.y)); if ( ((firepoint.y > 0) && !map[firepoint.x][(firepoint.y - 1)])) queue.add(new Point(firepoint.x,(firepoint.y - 1))); if ( ((firepoint.x < (n - 1)) && !map[(firepoint.x + 1)][firepoint.y])) queue.add(new Point((firepoint.x + 1),firepoint.y)); if ( ((firepoint.y < (m - 1)) && !map[firepoint.x][(firepoint.y + 1)])) queue.add(new Point(firepoint.x,(firepoint.y + 1))); }} static private class Point{ public int x ; public int y ; public Point( int x, int y){ this.x = x; this.y = y; } } }
5	public class Main{ public static void main( String[] args){ InputStream inputStream = System.in;  OutputStream outputStream = System.out;  ReaderFastIO in = new ReaderFastIO(inputStream);  PrintWriter out = new PrintWriter(outputStream);  DConcatenatedMultiples solver = new DConcatenatedMultiples(); solver.solve(1,in,out); out.close(); } static class DConcatenatedMultiples{ public void solve( int testNumber, ReaderFastIO in, PrintWriter out){ Map<Integer,Integer>[] mapMods = new HashMap[11];  int n = in.nextInt();  int k = in.nextInt();  int[] a = in.readArrayInt(n); for ( int i = 0;(i < 11);i++) {mapMods[i] = new HashMap<>(); }for ( int i = 0;(i < n);i++) { int pot = getPot(a[i]); mapMods[pot].put((a[i] % k),(mapMods[pot].getOrDefault((a[i] % k),0) + 1)); } long ct = 0; for ( int i = 0;(i < n);i++) { int ownPot = getPot(a[i]);  long suffix = (a[i] * 10L); for ( int j = 1;(j <= 10);j++) { int mod = (int)(suffix % k);  int comMod = ((k - mod) % k);  int qt = mapMods[j].getOrDefault(comMod,0); if ( ((j == ownPot) && ((a[i] % k) == comMod))) {qt--; } ct += qt; suffix = ((suffix * 10L) % k); }}out.println(ct); } public int getPot( int x){ int ct = 0; while((x != 0)){x /= 10; ct++; }return ct;} } static class ReaderFastIO{ BufferedReader br ; StringTokenizer st ; public ReaderFastIO(){ br = new BufferedReader(new InputStreamReader(System.in)); } public ReaderFastIO( InputStream input){ br = new BufferedReader(new InputStreamReader(input)); } 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());} public int[] readArrayInt( int n){ int[] array = new int[n]; for ( int i = 0;(i < n);i++) {array[i] = nextInt(); }return array;} } }
2	public class taskB{ StringTokenizer st ; BufferedReader in ; PrintWriter out ; public static void main( String[] args)throws NumberFormatException,IOException { taskB solver = new taskB(); solver.open(); long time = System.currentTimeMillis(); solver.solve(); if ( !"true".equals(System.getProperty("ONLINE_JUDGE"))) {System.out.println(("Spent time: " + (System.currentTimeMillis() - time))); System.out.println(("Memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()))); } solver.close(); } public void open()throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } public String nextToken()throws IOException { while(((st == null) || !st.hasMoreTokens())){ String line = in.readLine(); if ( (line == null)) return null; st = new StringTokenizer(line); }return st.nextToken();} public int nextInt()throws NumberFormatException,IOException { return Integer.parseInt(nextToken());} long n ,x ,y ,c ; long sq( long n){ if ( (n <= 0)) return 0; return (n * n);} long lrsp( long len, long max){ long cnt = Math.min(len,max);  long arpr = (((1 + cnt) * cnt) / 2); if ( (len > max)) arpr += ((len - max) * max); return arpr;} long onn( long len){ long up ,down ,left ,right ;  long toup = (x - 1),todown = (n - x),toleft = (y - 1),toright = (n - y); left = Math.min(toleft,len); right = Math.min(toright,len); down = up = sq(len); up -= sq((len - toup)); down -= sq((len - todown)); len--; if ( (toright < len)) {up -= lrsp((len - toright),toup); down -= lrsp((len - toright),todown); } if ( (toleft < len)) {up -= lrsp((len - toleft),toup); down -= lrsp((len - toleft),todown); } return ((((1 + up) + down) + left) + right);} public void solve()throws NumberFormatException,IOException { n = nextInt(); x = nextInt(); y = nextInt(); c = nextInt(); long down = 0,up = ((2 * n) + 13); while(((up - down) > 2)){ long tmp = ((up + down) / 2); if ( (onn(tmp) >= c)) up = tmp; else down = tmp; }if ( (onn(down) >= c)) out.println(down); else if ( (onn((down + 1)) >= c)) out.println((down + 1)); else if ( (onn((down + 2)) >= c)) out.println((down + 2)); else out.println((down + 3)); } public void close(){ out.flush(); out.close(); } }
1	public class C{ public static void main( String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(in.readLine());  char[] ps = in.readLine().toCharArray();  HashMap<Character,TreeSet<Integer>> locs = new HashMap<Character,TreeSet<Integer>>();  HashSet<Character> poks = new HashSet<Character>();  int lastNew = n; for ( int i = 0;(i < n);i++) {if ( !poks.contains(ps[i])) {poks.add(ps[i]); locs.put(ps[i],new TreeSet<Integer>()); lastNew = i; } locs.get(ps[i]).add(i); } int max = lastNew;  int minRange = (max + 1); for ( int min = 0;(min < n);min++) { char pAtMin = ps[min];  Integer nextInd = locs.get(pAtMin).higher(min); if ( (nextInd == null)) break; max = Math.max(max,nextInd); minRange = Math.min(minRange,(max - min)); }System.out.println(minRange); } }
5	public class Abra{ void solve()throws IOException { int n = nextInt(),t = nextInt();  TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>(); for ( int i = 0;(i < n);i++) tm.put(nextInt(),nextInt()); double tx = -1e9;  int c = 2; for ( Map.Entry<Integer,Integer> m :tm.entrySet()) {if ( (tx == -1e9)) {tx = ((m.getKey() + (m.getValue() / 2.0)) + t); continue;} if ( ((m.getKey() - (m.getValue() / 2.0)) >= tx)) c++; if ( ((m.getKey() - (m.getValue() / 2.0)) > tx)) c++; tx = ((m.getKey() + (m.getValue() / 2.0)) + t); }out.print(c); } public static void main( String[] args)throws IOException { new Abra().run(); } StreamTokenizer in ; PrintWriter out ; boolean oj ; BufferedReader br ; void init()throws IOException { oj = (System.getProperty("ONLINE_JUDGE") != null); Reader reader = (oj?new InputStreamReader(System.in):new FileReader("input.txt"));  Writer writer = (oj?new OutputStreamWriter(System.out):new FileWriter("output.txt")); br = new BufferedReader(reader); in = new StreamTokenizer(br); out = new PrintWriter(writer); } long beginTime ; void run()throws IOException { beginTime = System.currentTimeMillis(); long beginMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); init(); solve(); long endMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());  long endTime = System.currentTimeMillis(); if ( !oj) {System.out.println(("Memory used = " + (endMem - beginMem))); System.out.println(("Total memory = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()))); System.out.println(("Running time = " + (endTime - beginTime))); } out.flush(); } int nextInt()throws IOException { in.nextToken(); return (int)in.nval;} myLib lib = new myLib(); static class myLib{ long gcd( long a, long b){ if ( ((a == 0) || (b == 0))) return 1; if ( (a < b)) { long c = b; b = a; a = c; } while(((a % b) != 0)){a = (a % b); if ( (a < b)) { long c = b; b = a; a = c; } }return b;} int gcd( int a, int b){ if ( ((a == 0) || (b == 0))) return 1; if ( (a < b)) { int c = b; b = a; a = c; } while(((a % b) != 0)){a = (a % b); if ( (a < b)) { int c = b; b = a; a = c; } }return b;} long lcm( long a, long b){ return ((a * b) / gcd(a,b));} int lcm( int a, int b){ return ((a * b) / gcd(a,b));} int partition( int n, int l, int m){ if ( (n < l)) return 0; if ( (n < (l + 2))) return 1; if ( (l == 1)) return 1; int c = 0; for ( int i = Math.min(((n - l) + 1),m);(i >= (((n + l) - 1) / l));i--) {c += partition((n - i),(l - 1),i); }return c;} String numSym = "0123456789ABCDEF"; static boolean stringContainsOf( String x, String c){ for ( int i = 0;(i < x.length());i++) {if ( (c.indexOf(x.charAt(i)) == -1)) return false; }return true;} long pow( long a, long n){ if ( (n == 0)) return 1; long k = n,b = 1,c = a; while((k != 0)){if ( ((k % 2) == 0)) {k /= 2; c *= c; } else {k--; b *= c; }}return b;} int pow( int a, int n){ if ( (n == 0)) return 1; int k = n,b = 1,c = a; while((k != 0)){if ( ((k % 2) == 0)) {k /= 2; c *= c; } else {k--; b *= c; }}return b;} double pow( double a, int n){ if ( (n == 0)) return 1; double k = n,b = 1,c = a; while((k != 0)){if ( ((k % 2) == 0)) {k /= 2; c *= c; } else {k--; b *= c; }}return b;} class NotANumberException extends Exception{ static private final long serialVersionUID = 1L; String mistake ; NotANumberException(){ mistake = "Unknown."; } NotANumberException( String message){ mistake = message; } } int[] rotateDice( int[] a, int n){ int[] c = new int[6]; if ( (n == 0)) {c[0] = a[1]; c[1] = a[5]; c[2] = a[2]; c[3] = a[0]; c[4] = a[4]; c[5] = a[3]; } if ( (n == 1)) {c[0] = a[2]; c[1] = a[1]; c[2] = a[5]; c[3] = a[3]; c[4] = a[0]; c[5] = a[4]; } if ( (n == 2)) {c[0] = a[3]; c[1] = a[0]; c[2] = a[2]; c[3] = a[5]; c[4] = a[4]; c[5] = a[1]; } if ( (n == 3)) {c[0] = a[4]; c[1] = a[1]; c[2] = a[0]; c[3] = a[3]; c[4] = a[5]; c[5] = a[2]; } if ( (n == 4)) {c[0] = a[0]; c[1] = a[2]; c[2] = a[3]; c[3] = a[4]; c[4] = a[1]; c[5] = a[5]; } if ( (n == 5)) {c[0] = a[0]; c[1] = a[4]; c[2] = a[1]; c[3] = a[2]; c[4] = a[3]; c[5] = a[5]; } return c;} int min( int... a){ int c = Integer.MAX_VALUE; for ( int d :a) if ( (d < c)) c = d; return c;} final double goldenRatio = ((1 + Math.sqrt(5)) / 2); final double aGoldenRatio = ((1 - Math.sqrt(5)) / 2); Random random = new Random(); } class myFraction{ long num = 0,den = 1; void reduce(){ long d = lib.gcd(num,den); num /= d; den /= d; } myFraction( long ch, long zn){ num = ch; den = zn; reduce(); } myFraction add( myFraction t){ long nd = lib.lcm(den,t.den);  myFraction r = new myFraction((((nd / den) * num) + ((nd / t.den) * t.num)),nd); r.reduce(); return r;} } }
2	public class B{ static long sum( long from, long to){ final long d = (to - from); return (((d * (d + 1)) / 2) + ((d + 1) * from));} static long howMany( long n, long k){ if ( (n == 1)) {return 0;} if ( (n > (((k * (k - 1)) / 2) + 1))) {return -1;} long hi = (k - 1);  long lo = 1; while((lo < hi)){final long mi = (((lo + hi) + 1) >> 1); final long sum = sum(mi,(k - 1)); if ( (((n - 1) - sum) < mi)) {lo = mi; } else {hi = (mi - 1); }} long res = (k - lo); final long sum = sum(lo,(k - 1)); if ( (((n - 1) - sum) > 0)) {res++; } return res;} public static void main( String[] args){ try(Scanner s=new Scanner(System.in)){final long n = s.nextLong(); final long k = s.nextLong(); System.out.println(howMany(n,k)); }} }
4	public class FireAgain{ Point[] coordinate ; Queue<Point> q = new LinkedList<>(); boolean[][] vis ; PrintStream out ; int x ,y ; void bfs( Point s){ while(!q.isEmpty()){s = q.poll(); Point p = new Point(); p.x = (s.x - 1); p.y = s.y; if ( ((((p.x >= 1) && (p.x <= x)) && (p.y >= 1)) && (p.y <= y))) {if ( !vis[p.x][p.y]) {vis[p.x][p.y] = true; q.add(p); } } p = new Point(); p.x = (s.x + 1); p.y = s.y; if ( ((((p.x >= 1) && (p.x <= x)) && (p.y >= 1)) && (p.y <= y))) {if ( !vis[p.x][p.y]) {vis[p.x][p.y] = true; q.add(p); } } p = new Point(); p.x = s.x; p.y = (s.y - 1); if ( ((((p.x >= 1) && (p.x <= x)) && (p.y >= 1)) && (p.y <= y))) {if ( !vis[p.x][p.y]) {vis[p.x][p.y] = true; q.add(p); } } p = new Point(); p.x = s.x; p.y = (s.y + 1); if ( ((((p.x >= 1) && (p.x <= x)) && (p.y >= 1)) && (p.y <= y))) {if ( !vis[p.x][p.y]) {vis[p.x][p.y] = true; q.add(p); } } if ( (q.size() == 0)) out.print(((s.x + " ") + s.y)); }} public static void main( String[] args)throws FileNotFoundException { FireAgain F = new FireAgain();  Scanner in = new Scanner(new FileReader("input.txt")); F.out = new PrintStream(new File("output.txt")); F.x = in.nextInt(); F.y = in.nextInt(); int l = 0; F.vis = new boolean[(F.x + 1)][(F.y + 1)]; int k = in.nextInt(); for ( int i = 0;(i < k);i++) { Point P = new Point(in.nextInt(),in.nextInt()); F.vis[P.x][P.y] = true; F.q.add(P); }F.bfs(F.q.peek()); } }
4	public class Main{ static int[] di = {-1,0,1,0}; static int[] dj = {0,1,0,-1}; public static void main( String[] args)throws IOException { Scanner sc = new Scanner("input.txt");  PrintWriter out = new PrintWriter("output.txt");  Queue<Pair> q = new LinkedList<Pair>();  int n = sc.nextInt(),m = sc.nextInt(),k = sc.nextInt();  boolean[][] vis = new boolean[n][m]; while((k-- > 0))q.add(new Pair((sc.nextInt() - 1),(sc.nextInt() - 1))); int ansX = 1,ansY = 1; while(!q.isEmpty()){ Pair cur = q.poll(); if ( vis[cur.i][cur.j]) continue; ansX = cur.i; ansY = cur.j; vis[cur.i][cur.j] = true; for ( int i = 0;(i < di.length);i++) { int ni = (cur.i + di[i]),nj = (cur.j + dj[i]); if ( (((((ni >= 0) && (ni < n)) && (nj >= 0)) && (nj < m)) && !vis[ni][nj])) q.add(new Pair(ni,nj)); }}out.append(((++ansX + " ") + ++ansY)); out.flush(); } static class Pair{ int i ,j ; public Pair( int a, int b){ i = a; j = b; } } 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 boolean ready()throws IOException { return br.ready();} } }
3	public class Test{ final int N = 5010; final int M = 1_000_000_007; long[][] dp = new long[2][N]; long[] sums = new long[N]; char[] p = new char[N]; Scanner sca = new Scanner(System.in); void start(){ int n = Integer.parseInt(sca.nextLine());  int idx = 0; Arrays.fill(dp[idx],0); dp[idx][0] = 1; for ( int i = 0;(i < n);i++) p[i] = sca.nextLine().charAt(0); for ( int i = 0;(i < n);) { int nidx = (idx ^ 1); Arrays.fill(dp[nidx],0); Arrays.fill(sums,0); int j = i; while((p[j] != 's'))j++; int levels = (j - i); i = (j + 1); for ( j = n;(j >= 0);j--) {sums[j] = (sums[(j + 1)] + dp[idx][j]); if ( (sums[j] >= M)) sums[j] -= M; }for ( j = 0;(j <= n);j++) { int ind = (j + levels); if ( (ind > n)) continue; dp[nidx][ind] = sums[j]; }idx = nidx; } long ans = 0; for ( int i = 0;(i <= n);i++) {ans += dp[idx][i]; if ( (ans >= M)) ans -= M; }System.out.println(ans); } public static void main( String[] args){ new Test().start(); } }
1	public class CF1082D{ public static void main( String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.parseInt(br.readLine());  StringTokenizer st = new StringTokenizer(br.readLine());  int[] aa = new int[n];  int[] i1 = new int[n];  int[] i2 = new int[n];  int n1 = 0,n2 = 0,m2 = 0; for ( int i = 0;(i < n);i++) { int a = Integer.parseInt(st.nextToken()); aa[i] = a; if ( (a == 1)) i1[n1++] = i; else {i2[n2++] = i; m2 += a; }}if ( (m2 < (((n2 - 1) * 2) + n1))) {System.out.println("NO"); return ;} int m = ((n2 - 1) + n1);  int d = ((n2 - 1) + Math.min(n1,2));  PrintWriter pw = new PrintWriter(System.out); pw.println(("YES " + d)); pw.println(m); for ( int i = 0;((i + 1) < n2);i++) {pw.println((((i2[i] + 1) + " ") + (i2[(i + 1)] + 1))); aa[i2[i]]--; aa[i2[(i + 1)]]--; }if ( (n1 > 0)) {while(((n2 > 0) && (aa[i2[(n2 - 1)]] == 0)))n2--; pw.println((((i2[(n2 - 1)] + 1) + " ") + (i1[(n1 - 1)] + 1))); aa[i2[(n2 - 1)]]--; n1--; } for ( int i = 0,j = 0;(j < n1);j++) {while((aa[i2[i]] == 0))i++; pw.println((((i2[i] + 1) + " ") + (i1[j] + 1))); aa[i2[i]]--; }pw.close(); } }
2	public class My{ public static void main( String[] args){ new My().go(); } void go(){ Scanner in = new Scanner(System.in);  long n = in.nextLong();  int k = in.nextInt();  int mn = 0,mx = (k + 1); while((mn < mx)){ int mid = ((mn + mx) / 2); if ( works(n,k,mid)) {mx = mid; } else {mn = (mid + 1); }}if ( (mn > k)) {pl("-1"); } else {pl(((mn - 1) + "")); }} boolean works( long n, int k, int use){ return (((1 + T((k - 1))) - T((k - use))) >= n);} long T( int n){ return ((n * (long)(n + 1)) / 2);} void pl( String s){ System.out.println(s); } }
3	public class Main{ long MOD = 1000000007; InputReader in ; BufferedReader br ; PrintWriter out ; public static void main( String[] args)throws java.lang.Exception { Main solver = new Main(); solver.in = new InputReader(System.in); solver.br = new BufferedReader(new InputStreamReader(System.in)); solver.out = new PrintWriter(System.out); solver.solve(); solver.out.flush(); solver.out.close(); } int[] A ; int N ; public void solve(){ int tc = 1; for ( int cas = 1;(cas <= tc);cas++) {N = in.readInt(); A = new int[N]; for ( int i = 0;(i < A.length);i++) { String str = in.readString(); if ( str.equals("f")) A[i] = 1; } long[][] dp = new long[(N + 1)][(N + 1)]; for ( int i = 0;(i < N);i++) {if ( (i == 0)) {dp[i][0] = 1; } else if ( (A[(i - 1)] != 1)) {dp[i][N] = dp[(i - 1)][N]; for ( int j = (N - 1);(j >= 0);j--) {dp[i][j] = ((dp[(i - 1)][j] + dp[i][(j + 1)]) % MOD); }} else {for ( int j = 1;(j <= N);j++) {dp[i][j] = (dp[(i - 1)][(j - 1)] % MOD); }}} long res = 0; for ( int i = 0;(i <= N);i++) {res = ((res + dp[(N - 1)][i]) % MOD); }out.println(res); }} } class InputReader{ private InputStream stream ; private byte[] buf = new byte[1024]; private int curChar ; private int numChars ; private SpaceCharFilter filter ; public InputReader( InputStream stream){ this.stream = stream; } public int read(){ if ( (numChars == -1)) throw (new InputMismatchException()); if ( (curChar >= numChars)) {curChar = 0; try{numChars = stream.read(buf); }catch (IOException e){ throw (new InputMismatchException());} if ( (numChars <= 0)) return -1; } return buf[curChar++];} public int readInt(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } int res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public void readInt( int[] A){ for ( int i = 0;(i < A.length);i++) A[i] = readInt(); } public long readLong(){ int c = read(); while(isSpaceChar(c))c = read(); int sgn = 1; if ( (c == '-')) {sgn = -1; c = read(); } long res = 0; do {if ( ((c < '0') || (c > '9'))) throw (new InputMismatchException()); res *= 10; res += (c - '0'); c = read(); }while(!isSpaceChar(c));return (res * sgn);} public void readLong( long[] A){ for ( int i = 0;(i < A.length);i++) A[i] = readLong(); } public String readString(){ int c = read(); while(isSpaceChar(c))c = read(); StringBuilder res = new StringBuilder(); do {res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c));return res.toString();} public boolean isSpaceChar( int c){ if ( (filter != null)) return filter.isSpaceChar(c); return (((((c == ' ') || (c == '\n')) || (c == '\r')) || (c == '\t')) || (c == -1));} public interface SpaceCharFilter{ public boolean isSpaceChar( int ch); } }
3	public class D{ private void solve(){ br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int n = nextInt(),m = nextInt();  boolean[][] used = new boolean[(n + 1)][(m + 1)]; for ( int j = 1;(j <= ((m + 1) / 2));j++) { int x1 = 1,x2 = n; for ( int i = 1;(i <= n);i++) {if ( ((x1 <= n) && !used[x1][j])) {out.println(((x1 + " ") + j)); used[x1++][j] = true; } if ( ((x2 > 0) && !used[x2][((m - j) + 1)])) {out.println(((x2 + " ") + ((m - j) + 1))); used[x2--][((m - j) + 1)] = true; } }}out.close(); } public static void main( String[] args){ new D().solve(); } private BufferedReader br ; private StringTokenizer st ; private PrintWriter out ; private String next(){ while(((st == null) || !st.hasMoreTokens())){try{st = new StringTokenizer(br.readLine()); }catch (Exception e){ throw (new RuntimeException(e));} }return st.nextToken();} private int nextInt(){ return Integer.parseInt(next());} }
1	public class C{ public static void main( String[] arg)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  int n = Integer.valueOf(in.readLine());  char[] s = in.readLine().toCharArray();  int i = 0,j = 0;  int[] ct = new int[256];  Set<Character> all = new HashSet<>(); for ( char c :s) {all.add(c); } int total = 0,res = Integer.MAX_VALUE; while((j < s.length)){while(((total < all.size()) && (j < s.length))){if ( (ct[s[j]] == 0)) {total++; } ct[s[j]]++; j++; }res = Math.min(res,(j - i)); while(((total == all.size()) && (i < s.length))){ct[s[i]]--; if ( (ct[s[i]] == 0)) {total--; } i++; if ( (total == all.size())) {res = Math.min(res,(j - i)); } }}System.out.println(res); } }
3	public class C{ int n ; char[] a ; long[][] memo ; long mod = ((long)1e9 + 7); boolean lastFor( int i){ if ( (i == 0)) return false; return (a[(i - 1)] == 'f');} long dp( int ind, int curIndent){ if ( (ind == n)) return 1; if ( (curIndent < 0)) return 0; if ( (memo[ind][curIndent] != -1)) return memo[ind][curIndent]; long ans = 0; if ( ((a[ind] == 'f') && lastFor(ind))) {ans += dp((ind + 1),(curIndent + 1)); } else if ( ((a[ind] == 'f') && !lastFor(ind))) {ans += dp(ind,(curIndent - 1)); ans += dp((ind + 1),(curIndent + 1)); } else if ( ((a[ind] == 's') && lastFor(ind))) {ans += dp((ind + 1),curIndent); } else if ( ((a[ind] == 's') && !lastFor(ind))) {ans += dp((ind + 1),curIndent); ans += dp(ind,(curIndent - 1)); } return memo[ind][curIndent] = (ans % mod);} public void solve( Scanner in, PrintWriter out){ n = in.nextInt(); a = new char[n]; int forCount = 0;  int[] fc = new int[(n + 1)]; for ( int i = 0;(i < n);++i) {a[i] = in.next().charAt(0); if ( (a[i] == 'f')) ++forCount; fc[i] = forCount; }fc[n] = fc[(n - 1)]; memo = new long[n][(forCount + 1)]; for ( long[] aa :memo) {Arrays.fill(aa,-1); }for ( int i = n;(i >= 0);--i) {for ( int indent = (fc[i] - 1);(indent >= 0);--indent) {dp(i,indent); }}out.println((dp(0,0) % mod)); } public static void main( String[] args){ Scanner in = new Scanner(System.in);  PrintWriter out = new PrintWriter(System.out); new C().solve(in,out); in.close(); out.close(); } }
6	public class G{ static int n ,t ; static int[] a ; static int[] g ; static long[][][] dp ; static final long MOD = 1000000007; public static void main( String[] args){ Scanner sc = new Scanner(System.in); n = sc.nextInt(); t = sc.nextInt(); a = new int[n]; g = new int[n]; for ( int i = 0;(i < n);i++) {a[i] = sc.nextInt(); g[i] = sc.nextInt(); }dp = new long[4][(1 << ((n - 1) + 1))][(t + 1)]; for ( int i = 0;(i < 4);i++) for ( int j = 0;(j < (1 << ((n - 1) + 1)));j++) for ( int k = 0;(k <= t);k++) dp[i][j][k] = -1; System.out.println(dp(0,0,t)); } static private long dp( int genre, int mask, int time){ if ( (time < 0)) return 0; if ( (dp[genre][mask][time] != -1)) return dp[genre][mask][time]; if ( (time == 0)) return 1; dp[genre][mask][time] = 0; for ( int i = 0;(i < n);i++) {if ( ((g[i] != genre) && (((1 << i) & mask) == 0))) dp[genre][mask][time] = ((dp[genre][mask][time] + dp(g[i],(mask | (1 << i)),(time - a[i]))) % MOD); }return dp[genre][mask][time];} }
3	public class Main{ public static void main( String[] args){ long MOD = 1000000007;  Scanner sc = new Scanner(System.in);  int n = sc.nextInt();  long[][] dp = new long[n][5010];  char[] program = new char[n]; for ( int i = 0;(i < n);i++) {program[i] = sc.next().charAt(0); }dp[0][0] = 1; long[] acc = new long[5010]; acc[0] = 1; for ( int i = 1;(i < n);i++) {for ( int j = 0;(j < 5010);j++) {if ( (program[(i - 1)] == 'f')) {if ( ((j - 1) >= 0)) {dp[i][j] = dp[(i - 1)][(j - 1)]; } } else {dp[i][j] = acc[j]; }}acc[5009] = dp[i][5009]; for ( int j = 5008;(j >= 0);j--) {acc[j] = ((acc[(j + 1)] + dp[i][j]) % MOD); }}System.out.println(acc[0]); } }
1	public class Main{ static final double eps = 1e-10; public static void main( String[] args)throws FileNotFoundException { new Main().solve(); } public void solve()throws FileNotFoundException { Scanner cin = new Scanner(System.in);  int n ; n = cin.nextInt(); String s ; s = cin.next(); int ans = Integer.MAX_VALUE;  int h = 0,t = 0; for ( int i = 0;(i < s.length());i++) {if ( (s.charAt(i) == 'H')) h++; else if ( (s.charAt(i) == 'T')) t++; }ans = Math.min(ans,fun(s,'H',h)); ans = Math.min(ans,fun(s,'T',t)); System.out.println(ans); } public int fun( String s, char c, int num){ int ans = Integer.MAX_VALUE;  int ret = num; for ( int i = 0;(i < num);i++) {if ( (s.charAt(i) == c)) {ret--; } }ans = ret; for ( int i = 0;((i + num) < s.length());i++) {if ( (s.charAt(i) != c)) ret--; if ( (s.charAt((i + num)) != c)) {ret++; } ans = Math.min(ans,ret); }return ans;} }