import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

enum INF = 10L^^18;

int N;
int[] U, V;
long[] W;
int S;
int M;
int[] X;

int[][] G;

long[][][][] cache;

// arriving at u from p via ip, a above, b below
long calc(int u, int p, int ip, int a, int b) {
  assert(b > 0);
  auto ret = &cache[u][p][a][b];
  if (*ret == -1) {
    debug {
      writeln("calc ", u, " ", p, " ", ip, " ", a, " ", b);
    }
    if (G[u].length == 1) {
      // leaf
      if (a == 0) {
        *ret = 0;
      } else {
        *ret = W[G[u][0]] + calc(p, u, ip, 0, a);
      }
    } else {
      assert(b > 0);
      // c_j for j-th child
      // maximize min { W[i] + calc(u, v_j, i_j, a + b - c_j, c_j) | c_j > 0 }
      auto crt = new long[b + 1];
      crt[] = -INF;
      crt[0] = INF;
      foreach (i; G[u]) {
        const v = U[i] ^ V[i] ^ u;
        if (v != p) {
          auto nxt = crt.dup;
          foreach (c; 0 .. b + 1) {
            if (crt[c] >= -INF) {
              foreach (d; 0 .. b - c + 1) {
                if (nxt[c + d] < crt[c]) {
                  chmax(nxt[c + d], min(crt[c], W[i] + calc(v, u, i, a + b - d, d)));
                }
              }
            }
          }
          crt = nxt;
        }
      }
      *ret = crt[b];
    }
    debug {
      writeln(u, " ", p, " ", ip, " ", a, " ", b, ": ", *ret);
    }
  }
  return *ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      U = new int[N - 1];
      V = new int[N - 1];
      W = new long[N - 1];
      foreach (i; 0 .. N - 1) {
        U[i] = readInt() - 1;
        V[i] = readInt() - 1;
        W[i] = readLong();
      }
      S = readInt() - 1;
      M = readInt();
      X = new int[M];
      foreach (m; 0 .. M) {
        X[m] = readInt() - 1;
      }

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[U[i]] ~= i;
        G[V[i]] ~= i;
      }

      cache = new long[][][][](N, N, M + 1, M + 1);
      foreach (u; 0 .. N) foreach (p; 0 .. N) {
        foreach (a; 0 .. M + 1) foreach (b; 0 .. M + 1) {
          cache[u][p][a][b] = -1;
        }
      }

      auto d = new int[][](N, N);
      foreach (u; 0 .. N) {
        d[u][] = N;
        d[u][u] = 0;
      }
      foreach (i; 0 .. M - 1) {
        d[U[i]][V[i]] = d[V[i]][U[i]] = 1;
      }
      foreach (w; 0 .. N) foreach (u; 0 .. N) foreach (v; 0 .. N) {
        chmin(d[u][v], d[u][w] + d[w][v]);
      }
      auto nums = new int[N];
      foreach (x; X) {
        foreach (i; G[S]) {
          const v = U[i] ^ V[i] ^ S;
          if (d[S][x] == 1 + d[v][x]) {
            ++nums[v];
          }
        }
      }
      debug {
        writeln("nums = ", nums);
      }

      long ans = INF;
      foreach (i; G[S]) {
        const v = U[i] ^ V[i] ^ S;
        if (nums[v] > 0) {
          chmin(ans, W[i] + calc(v, S, i, M - nums[v], nums[v]));
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

You are given a tree (a connected non-oriented graph without cycles) with vertices numbered from 1 to n, and the length of the i-th edge is wi. In the vertex s there is a policeman, in the vertices x1,x2,...,xm (xj≠s) m criminals are located.The policeman can walk along the edges with speed 1, the criminals can move with arbitrary large speed. If a criminal at some moment is at the same point as the policeman, he instantly gets caught by the policeman. Determine the time needed for the policeman to catch all criminals, assuming everybody behaves optimally (i.e. the criminals maximize that time, the policeman minimizes that time). Everybody knows positions of everybody else at any moment of time.

The first line contains single integer n (1≤n≤50) — the number of vertices in the tree. The next n-1 lines contain three integers each: ui, vi, wi (1≤ui,vi≤n, 1≤wi≤50) denoting edges and their lengths. It is guaranteed that the given graph is a tree.
The next line contains single integer s (1≤s≤n) — the number of vertex where the policeman starts.
The next line contains single integer m (1≤m≤50) — the number of criminals. The next line contains m integers x1,x2,...,xm (1≤xj≤n, xj≠s) — the number of vertices where the criminals are located. xj are not necessarily distinct.

If the policeman can't catch criminals, print single line "Terrorists win" (without quotes).
Otherwise, print single integer — the time needed to catch all criminals.

In the first example one of the optimal scenarios is the following. The criminal number 2 moves to vertex 3, the criminal 4 — to vertex 4. The policeman goes to vertex 4 and catches two criminals. After that the criminal number 1 moves to the vertex 2. The policeman goes to vertex 3 and catches criminal 2, then goes to the vertex 2 and catches the remaining criminal.

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

enum INF = 10L^^18;

int N;
int[] U, V;
long[] W;
int S;
int M;
int[] X;

int[][] G;

long[][][][] cache;

// arriving at u from p via ip, a above, b below
long calc(int u, int p, int ip, int a, int b) {
  assert(b > 0);
  auto ret = &cache[u][p][a][b];
  if (*ret == -1) {
    debug {
      writeln("calc ", u, " ", p, " ", ip, " ", a, " ", b);
    }
    if (G[u].length == 1) {
      // leaf
      if (a == 0) {
        *ret = 0;
      } else {
        *ret = W[G[u][0]] + calc(p, u, ip, 0, a);
      }
    } else {
      assert(b > 0);
      // c_j for j-th child
      // maximize min { W[i] + calc(u, v_j, i_j, a + b - c_j, c_j) | c_j > 0 }
      auto dp = new long[b + 1];
      dp[] = -INF;
      dp[0] = INF;
      foreach (i; G[u]) {
        const v = U[i] ^ V[i] ^ u;
        if (v != p) {
          foreach_reverse (c; 0 .. b + 1) {
            if (dp[c] >= -INF) {
              foreach (d; 1 .. b - c + 1) {
                if (dp[c + d] < dp[c]) {
                  chmax(dp[c + d], min(dp[c], W[i] + calc(v, u, i, a + b - d, d)));
                }
              }
            }
          }
        }
      }
      *ret = dp[b];
    }
    debug {
      writeln(u, " ", p, " ", ip, " ", a, " ", b, ": ", *ret);
    }
  }
  return *ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      U = new int[N - 1];
      V = new int[N - 1];
      W = new long[N - 1];
      foreach (i; 0 .. N - 1) {
        U[i] = readInt() - 1;
        V[i] = readInt() - 1;
        W[i] = readLong();
      }
      S = readInt() - 1;
      M = readInt();
      X = new int[M];
      foreach (m; 0 .. M) {
        X[m] = readInt() - 1;
      }

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[U[i]] ~= i;
        G[V[i]] ~= i;
      }

      cache = new long[][][][](N, N, M + 1, M + 1);
      foreach (u; 0 .. N) foreach (p; 0 .. N) {
        foreach (a; 0 .. M + 1) foreach (b; 0 .. M + 1) {
          cache[u][p][a][b] = -1;
        }
      }

      auto d = new int[][](N, N);
      foreach (u; 0 .. N) {
        d[u][] = N;
        d[u][u] = 0;
      }
      foreach (i; 0 .. N - 1) {
        d[U[i]][V[i]] = d[V[i]][U[i]] = 1;
      }
      foreach (w; 0 .. N) foreach (u; 0 .. N) foreach (v; 0 .. N) {
        chmin(d[u][v], d[u][w] + d[w][v]);
      }

      long ans = INF;
      foreach (i; G[S]) {
        const v = U[i] ^ V[i] ^ S;
        int b;
        foreach (x; X) {
          if (d[S][x] == 1 + d[v][x]) {
            ++b;
          }
        }
        debug {
          writeln(v, " ", i, ": ", b);
        }
        if (b > 0) {
          chmin(ans, W[i] + calc(v, S, i, M - b, b));
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons, std.traits;

alias Query = Tuple!(long, "index", long, "l", long, "r", long, "ans");
void main() {
  long[long] cnt;
  long sum = 0;
  int n, t;
  readf(" %d %d\n", &n, &t);
  auto a = readln.split.map!(to!long);
  auto queries = new Query[](t);
  foreach(i; 0..t) {
    readf(" %d %d", &queries[i].l, &queries[i].r);
    queries[i].index = i;
    queries[i].l--;
  }
  long k = n.intsqrt;

  queries.sort!(delegate(a,b) {
      if (a.l/k < b.l/k) return true;
      return a.r < b.r;
      });

  int l,r;
  void add(long elem) {
    debug { writeln("add: ", elem); }
    if (elem in cnt) {
      sum += elem*((cnt[elem]+1)^^2 - cnt[elem]^^2);
    } else {
      sum += elem;
    }
    cnt[elem]++;
  }
  void del(long elem) {
    debug { writeln("del: ", elem); }
    assert(cnt[elem] > 0);
    cnt[elem]--;
    sum -= elem*((cnt[elem]+1)^^2 - cnt[elem]^^2);
  }

  foreach(ref q; queries) {
    debug { writeln("query: ", a[q.l..q.r]); }
    while (r < q.r) {
      add(a[r]);
      r++;
    }
    while (r > q.r) {
      del(a[r-1]);
      r--;
    }
    while (l < q.l) {
      del(a[l]);
      l++;
    }
    while (l > q.l) {
      add(a[l]);
      l--;
    }
    q.ans = sum;
  }
  queries.sort!((a,b) => a.index < b.index);
  queries.each!(a => writeln(a.ans));
}

T intsqrt(T)(T i) {
   T bitMask = 1;
   T result = 0;

   bitMask <<= T.sizeof * 4 - 1;

   while (bitMask) {
       result |= bitMask;
       if ((result * result) > i) {
           result &= ~bitMask;
       }
       bitMask >>= 1;
   }

   return result;
}

An array of positive integers a1,a2,...,an is given. Let us consider its arbitrary subarray al,al+1...,ar, where 1≤l≤r≤n. For every positive integer s denote by Ks the number of occurrences of s into the subarray. We call the power of the subarray the sum of products Ks·Ks·s for every positive integer s. The sum contains only finite number of nonzero summands as the number of different values in the array is indeed finite.You should calculate the power of t given subarrays.

First line contains two integers n and t (1≤n,t≤200000) — the array length and the number of queries correspondingly.
Second line contains n positive integers ai (1≤ai≤10^6) — the elements of the array.
Next t lines contain two positive integers l, r (1≤l≤r≤n) each — the indices of the left and the right ends of the corresponding subarray.

Output t lines, the i-th line of the output should contain single positive integer — the power of the i-th query subarray.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d).

Consider the following array (see the second sample) and its [2, 7] subarray (elements of the subarray are colored):

 Then K1=3, K2=2, K3=1, so the power is equal to 3^2·1+2^2·2+1^2·3=20.

import core.stdc.stdio : scanf;
import std.algorithm;
import std.math;
import std.range;
import std.stdio;

void main() {
    int N, T; scanf("%d %d\n", &N, &T);
    auto A = new int[N]; {
        foreach (ref a; A) {
            scanf("%d", &a);
        }
    }
    auto L = new int[T];
    auto R = new int[T]; {
        foreach (i; 0 .. T) {
            scanf("%d %d", &L[i], &R[i]);
            L[i]--;
        }
    }

    int p = cast(int)(sqrt(cast(real)N));
    auto I = iota(T).array.sort!((i, j) {
        int qi = L[i] / p, qj = L[j] / p;
        if (qi == qj) {
            return R[i] < R[j];
        } else {
            return qi < qj;
        }
    }).array;

    int x = 0, y = 0;
    long[] K = new long[A.reduce!max + 1];
    //long[long] K;
    long S = 0;
    auto ans = new long[T];
    foreach (i; I) {
        int l = L[i], r = R[i];
        int dy = (r - y > 0 ? +1 : -1);
        while (y != r) {
            int s = A[ dy > 0 ? y : y - 1 ];
            long pk = K[s];
            //long pk = K.get(s, 0);
            long nk = pk + (dy > 0 ? +1 : -1);
            S += s * (nk * nk - pk * pk);
            y += dy;
            K[s] = nk;
        }
        int dx = (l - x > 0 ? +1 : -1);
        while (x != l) {
            int s = A[ dx > 0 ? x : x - 1 ];
            long pk = K[s];
            //long pk = K.get(s, 0);
            long nk = pk + (dx > 0 ? -1 : +1);
            S += s * (nk * nk - pk * pk);
            x += dx;
            K[s] = nk;
        }
        ans[i] = S;
    }
    foreach (a; ans) writeln(a);
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    immutable int INF = 1 << 29;

    int[] unfold(int n) {
        return [n / 1000 % 10, n / 100 % 10, n / 10 % 10, n % 10];
    }

    int fold(int[] a) {
        int[] b = a.dup;
        b.sort!"a > b";
        return b[0] + b[1] * 10 + b[2] * 100 + b[3] * 1000;
    }

    auto N = readln.chomp.to!int;
    auto src = new int[](N);
    auto dst = new int[](N);
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!int);
        src[i] = s[0];
        dst[i] = s[1];
    }

    auto dp = new int[][](N+1, 10000);
    foreach (i; 0..N+1) dp[i].fill(INF);
    dp[0][0] = 0;

    foreach (i; 0..N) {
        int cur = i == 0 ? 1 : src[i-1];
        int tar = src[i];
        foreach (a; 0..10) {
            foreach (b; a..10) {
                foreach (c; b..10) {
                    foreach (d; c..10) {
                        foreach (k; 1..10) {
                            int[] v = [a, b, c, d];
                            int fv = fold(v);
                            if (dp[i][fv] >= INF) continue;
                            int hi = max(cur, tar, k);
                            int lo = min(cur, tar, k);
                            int cost = 1;
                            foreach (j; 0..4) if (lo <= v[j] && v[j] <= hi) v[j] = 0, cost += 1;
                            int z = -1;
                            foreach (j; 0..4) if (v[j] == 0) z = j;
                            if (z == -1) continue;
                            v[z] = dst[i];
                            int dist = abs(cur - k) + abs(k - tar);
                            dp[i+1][fv] = min(dp[i+1][fv], dp[i][d + c*10 + b*100 + a*1000] + dist + cost);
                        }
                    }
                }
            }
        }
    }

    int ans = INF;

    foreach (a; 0..10) {
        foreach (b; a..10) {
            foreach (c; b..10) {
                foreach (d; c..10) {
                    int[] v = [a, b, c, d];
                    if (v.all!"a == 0") {
                        ans = min(ans, dp[N][0]);
                        continue;
                    }
                    int hi = (src.back, v.filter!"a != 0".reduce!max);
                    int lo = (src.back, v.filter!"a != 0".reduce!min);
                    int cost = (a != 0) + (b != 0) + (c != 0) + (d != 0);
                    int dist = min(abs(src.back - hi) + abs(hi - lo), abs(src.back - lo) + abs(lo - hi));
                    ans = min(ans, dp[N][fold([a, b, c, d])] + dist + cost);
                }
            }
        }
    }

    ans.writeln;
}

You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator.Today you are late, so there are queues on some floors already. For each person you know the floor where he currently is and the floor he wants to reach. Also, you know the order in which people came to the elevator.According to the company's rules, if an employee comes to the elevator earlier than another one, he has to enter the elevator earlier too (even if these employees stay on different floors). Note that the employees are allowed to leave the elevator in arbitrary order.The elevator has two commands:   Go up or down one floor. The movement takes 1 second.  Open the doors on the current floor. During this operation all the employees who have reached their destination get out of the elevator. Then all the employees on the floor get in the elevator in the order they are queued up while it doesn't contradict the company's rules and there is enough space in the elevator. Each employee spends 1 second to get inside and outside the elevator. Initially the elevator is empty and is located on the floor 1.You are interested what is the minimum possible time you need to spend to deliver all the employees to their destination. It is not necessary to return the elevator to the floor 1.

The first line contains an integer n (1≤n≤2000) — the number of employees.
The i-th of the next n lines contains two integers ai and bi (1≤ai,bi≤9, ai≠bi) — the floor on which an employee initially is, and the floor he wants to reach.
The employees are given in the order they came to the elevator.

Print a single integer — the minimal possible time in seconds.

 Explaination for the first sample  t=0 t=2
 t=3
 t=5
 t=6
 t=7
 t=9
 t=10

import std.algorithm;
import std.conv;
import std.math;
import std.stdio;

immutable int infinity = int.max / 4;
immutable int totalLevels = 9;
immutable int NA = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto src = new int [n];
		auto dst = new int [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &src[i], &dst[i]);
		}
		src[] -= 1;
		dst[] -= 1;

		alias State = int [4];
		State [] states;
		int [State] stateNum;
		foreach (a; NA..totalLevels)
		{
			foreach (b; a..totalLevels)
			{
				foreach (c; b..totalLevels)
				{
					foreach (d; c..totalLevels)
					{
						State state = [a, b, c, d];
						do
						{
							stateNum[state] =
							    states.length
							    .to !(int);
						}
						while (nextPermutation
						    (state[]));
						states ~= state;
					}
				}
			}
		}
		immutable int totalStates = 715;
		assert (totalStates == states.length);

		auto f = new int [totalLevels] [] [] (n + 1, totalStates);
		foreach (i; 0..n + 1)
		{
			foreach (stateIndex; 0..totalStates)
			{
				f[i][stateIndex][] = infinity;
			}
		}
		f[0][0][0] = 0;

		int res = infinity;
		foreach (i; 0..n + 1)
		{
			foreach_reverse (stateIndex; 0..totalStates)
			{
				auto curState = states[stateIndex];
				foreach (level; 0..totalLevels)
				{
					auto cur = f[i][stateIndex][level];
					if (cur >= infinity)
					{
						continue;
					}
					foreach (j, v; curState)
					{
						if (v == NA)
						{
							continue;
						}
						auto nextValue = cur + abs
						    (level - v) + 1;
						auto nextState = curState;
						nextState[j] = NA;
						auto nextIndex =
						    stateNum[nextState];
						f[i][nextIndex][v] =
						    min (f[i][nextIndex][v],
						    nextValue);
					}

					if (i < n && curState[0] == NA)
					{
						auto u = src[i];
						auto nextValue = cur + abs
						    (level - u) + 1;
						auto nextState = curState;
						nextState[0] = dst[i];
						auto nextIndex =
						    stateNum[nextState];
						f[i + 1][nextIndex][u] =
						    min (f[i + 1][nextIndex]
						    [u], nextValue);
					}
				}
			}
		}

		writeln (minElement (f[n][0][]));
	}
}


import core.bitop, std.bitmanip;
import std.algorithm, std.functional;
import std.array, std.container;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int INF = 10L ^^ 9 + 23;

void main()
{
    int le, r, x, y;
    readf("%s %s %s %s", &le, &r, &x, &y);
    readln;

    int g = y / x;

    int[] dvs;
    int k = 2;
    while (g > 1 && k <= g / k) {
        while (g % k == 0) {
            dvs ~= k;
            g /= k;
        }
        k += 1;
    }
    if (g > 1) dvs ~= g;

    int mx = 1 << dvs.length;
    bool[int] chckd;
    int ans = 0;
    for (int i = 0; i < mx; ++i) {
        int a = x, b = x;
        for (int j = 0; j < dvs.length; ++j) {
            if (i & (1 << j)) {
                a *= dvs[j];
            } else {
                b *= dvs[j];
            }
        }

        if (chckd.get(a, false)) continue;
        if (a < le || a > r) continue;
        if (b < le || b > r) continue;
        if (gcd(a, b) != x) continue;

        ++ans;
        chckd[a] = true;
        debug { a.writeln; }
    }

    ans.writeln;
}

Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.We define a pair of integers (a,b) good, if GCD(a,b)=x and LCM(a,b)=y, where GCD(a,b) denotes the greatest common divisor of a and b, and LCM(a,b) denotes the least common multiple of a and b.You are given two integers x and y. You are to find the number of good pairs of integers (a,b) such that l≤a,b≤r. Note that pairs (a,b) and (b,a) are considered different if a≠b.

The only line contains four integers l,r,x,y (1≤l≤r≤10^9, 1≤x≤y≤10^9).

In the only line print the only integer — the answer for the problem.

In the first example there are two suitable good pairs of integers (a,b): (1,2) and (2,1).
In the second example there are four suitable good pairs of integers (a,b): (1,12), (12,1), (3,4) and (4,3).
In the third example there are good pairs of integers, for example, (3,30), but none of them fits the condition l≤a,b≤r.

import std.algorithm;
import std.array;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	long l, r, x, y;
	while (readf (" %s %s %s %s", &l, &r, &x, &y) > 0)
	{
		auto total = x * y;
		long [] divsX;
		for (long d = 1; d * d <= x; d++)
		{
			if (x % d == 0)
			{
				divsX ~= d;
				if (d * d < x)
				{
					divsX ~= x / d;
				}
			}
		}
		long [] divsY;
		for (long d = 1; d * d <= y; d++)
		{
			if (y % d == 0)
			{
				divsY ~= d;
				if (d * d < y)
				{
					divsY ~= y / d;
				}
			}
		}
		int [long] v;
		foreach (p; divsX)
		{
			foreach (q; divsY)
			{
				v[p * q] += 1;
			}
		}
		int res = 0;
		foreach (key, value; v)
		{
			auto temp = total / key;
			debug {writeln (key, " ", temp);}
			if (gcd (key, temp) == x &&
			    l <= key && key <= r &&
			    l <= temp && temp <= r)
			{
				res += 1;
			}
		}
		writeln (res);
	}
}


There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump. The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.

The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").

Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).


#!/usr/bin/perl

use 5.012;
use warnings;

chomp(my $n = <>);
print ((length $n) =~ /^[47]+$/ ? 'YES' : 'NO');

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.

The only line contains an integer n (1≤n≤10^18).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).

In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO".

use POSIX;
my $line;
my %h;
my @input1;
my @input2;
my $dummy;
my $s = 0;
my $max = 0;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;

$line = <STDIN>;
chomp($line);
@input1 = split('', $line);
if ($line < 10) {
        print "NO";
        exit;
}
foreach $c (split('', $line)) {
        if ($c ne '4' && $c ne '7') {
                $flag = 1;
        } else {
                $s++;
        }
}
if ($s == 4 || $s == 7) {
        print "YES";
} else {
        print "NO";
}


#!/usr/bin/perl

$s1 = <STDIN>;
$s2 = <STDIN>;

$s1 gt $s2 && print 1;
$s1 lt $s2 && print -1;
$s1 eq $s2 && print 0;

Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.

Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.

If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.

If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
 http://en.wikipedia.org/wiki/Lexicographical_order

[{'input': ['aaaa\r\naaaA\r\n'], 'output': ['0\r\n']}, {'input': ['abs\r\nAbz\r\n'], 'output': ['-1\r\n']}, {'input': ['abcdefg\r\nAbCdEfF\r\n'], 'output': ['1\r\n']}, {'input': ['asadasdasd\r\nasdwasdawd\r\n'], 'output': ['-1\r\n']}, {'input': ['aslkjlkasdd\r\nasdlkjdajwi\r\n'], 'output': ['1\r\n']}, {'input': ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n'], 'output': ['0\r\n']}, {'input': ['aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\r\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp\r\n'], 'output': ['0\r\n']}, {'input': ['bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\r\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH\r\n'], 'output': ['-1\r\n']}, {'input': ['kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\r\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt\r\n'], 'output': ['1\r\n']}, {'input': ['nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\r\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL\r\n'], 'output': ['1\r\n']}, {'input': ['ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\r\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo\r\n'], 'output': ['1\r\n']}, {'input': ['AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\r\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja\r\n'], 'output': ['-1\r\n']}, {'input': ['HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\r\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy\r\n'], 'output': ['1\r\n']}, {'input': ['mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\r\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR\r\n'], 'output': ['1\r\n']}, {'input': ['tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\r\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd\r\n'], 'output': ['1\r\n']}, {'input': ['AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\r\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI\r\n'], 'output': ['-1\r\n']}, {'input': ['HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\r\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC\r\n'], 'output': ['-1\r\n']}, {'input': ['OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\r\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl\r\n'], 'output': ['-1\r\n']}, {'input': ['tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\r\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo\r\n'], 'output': ['-1\r\n']}, {'input': ['cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\r\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV\r\n'], 'output': ['-1\r\n']}, {'input': ['sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\r\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ\r\n'], 'output': ['-1\r\n']}, {'input': ['hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\r\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK\r\n'], 'output': ['-1\r\n']}, {'input': ['ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\r\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys\r\n'], 'output': ['1\r\n']}, {'input': ['nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\r\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy\r\n'], 'output': ['-1\r\n']}, {'input': ['EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\r\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK\r\n'], 'output': ['-1\r\n']}, {'input': ['UG\r\nak\r\n'], 'output': ['1\r\n']}, {'input': ['JZR\r\nVae\r\n'], 'output': ['-1\r\n']}, {'input': ['a\r\nZ\r\n'], 'output': ['-1\r\n']}, {'input': ['rk\r\nkv\r\n'], 'output': ['1\r\n']}, {'input': ['RvuT\r\nbJzE\r\n'], 'output': ['1\r\n']}, {'input': ['PPS\r\nydq\r\n'], 'output': ['-1\r\n']}, {'input': ['q\r\nq\r\n'], 'output': ['0\r\n']}, {'input': ['peOw\r\nIgSJ\r\n'], 'output': ['1\r\n']}, {'input': ['PyK\r\noKN\r\n'], 'output': ['1\r\n']}, {'input': ['O\r\ni\r\n'], 'output': ['1\r\n']}, {'input': ['NmGY\r\npDlP\r\n'], 'output': ['-1\r\n']}, {'input': ['nG\r\nZf\r\n'], 'output': ['-1\r\n']}, {'input': ['m\r\na\r\n'], 'output': ['1\r\n']}, {'input': ['MWyB\r\nWZEV\r\n'], 'output': ['-1\r\n']}, {'input': ['Gre\r\nfxc\r\n'], 'output': ['1\r\n']}, {'input': ['Ooq\r\nwap\r\n'], 'output': ['-1\r\n']}, {'input': ['XId\r\nlbB\r\n'], 'output': ['1\r\n']}, {'input': ['lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\r\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF\r\n'], 'output': ['0\r\n']}, {'input': ['DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\r\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD\r\n'], 'output': ['0\r\n']}, {'input': ['tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\r\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA\r\n'], 'output': ['0\r\n']}, {'input': ['KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\r\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ\r\n'], 'output': ['0\r\n']}, {'input': ['cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\r\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG\r\n'], 'output': ['0\r\n']}, {'input': ['SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\r\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ\r\n'], 'output': ['0\r\n']}, {'input': ['kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\r\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\r\n'], 'output': ['0\r\n']}, {'input': ['nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\r\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi\r\n'], 'output': ['0\r\n']}, {'input': ['abac\r\nadaa\r\n'], 'output': ['-1\r\n']}, {'input': ['Bbc\r\nabc\r\n'], 'output': ['1\r\n']}, {'input': ['aaaba\r\naaaab\r\n'], 'output': ['1\r\n']}]


Little Petya loves playing with squares. Mum bought him a square 2n×2n in size. Petya marked a cell inside the square and now he is solving the following task.The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not have any common points with the marked cell and the resulting two parts should be equal up to rotation.Petya wants to determine whether it is possible to cut the square in the required manner given the sizes of the square side and the coordinates of the marked cell. Help him.

The first line contains three space-separated integers 2n, x and y (2≤2n≤100,1≤x,y≤2n), representing the length of a square's side and the coordinates of the marked cell. It is guaranteed that 2n is even.
The coordinates of the marked cell are represented by a pair of numbers x y, where x represents the number of the row and y represents the number of the column. The rows and columns are numbered by consecutive integers from 1 to 2n. The rows are numbered from top to bottom and the columns are numbered from the left to the right.

If the square is possible to cut, print "YES", otherwise print "NO" (without the quotes).

A sample test from the statement and one of the possible ways of cutting the square are shown in the picture:


When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k^2, petricium la petricium la petricium stands for k^3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.

The first input line contains integer number k, the second line contains integer number l (2≤k,l≤2^31-1).

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.


Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.

The single line contains an integer n (1≤n≤1000) — the number that needs to be checked.

In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.

use POSIX;
my $line;
my %h;
my @input1;
my @input2;
my $dummy;
my $s = 0;
my $max = 0;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;

$line = <STDIN>;
chomp($line);
@input1 = split('', $line);

for (my $i = 1; $i < 1000; $i++) {
        my $tmp = $i;
        $flag = 0;
        while ($tmp > 0) {
                if ($tmp % 10 != 4 && $tmp % 10 != 7) {
                        $flag = 1;
                }
                $tmp = POSIX::floor($tmp / 10);
        }
        if (!$flag) {
                push(@input2, $i);
                $s++;
        }
}
for ($i = 0; $i < $s; $i++) {
        if ($line % @input2[$i] == 0) {
                print "YES";
                exit;
        }
}
print "NO";


#!perl
$scookies = <STDIN>;
@cookies = split(/\D/,$scookies);
$odd = $even = 0;
foreach $i (@cookies) {
	if ($i % 2) {
		$odd++;
	} else {
		$even++;
	}
}
$result = ($odd % 2)? $odd: $even;
print $result;

Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?

The first line contains the only integer n (1≤n≤100) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1≤ai≤100) — the number of cookies in the i-th bag.

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5+3=8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2*9+99=117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.

#!perl
$_ = <STDIN>;
$scookies = <STDIN>;
@cookies = split(/\D/,$scookies);
$odd = $even = 0;
foreach $i (@cookies) {
	if ($i % 2) {
		$odd++;
	} else {
		$even++;
	}
}
$result = ($odd % 2)? $odd: $even;
print $result;


HQ9+ is a joke programming language which has only four one-character instructions: "H" prints "Hello, World!", "Q" prints the source code of the program itself, "9" prints the lyrics of "99 Bottles of Beer" song,  "+" increments the value stored in the internal accumulator.Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.

The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.

Output "YES", if executing the program will produce any output, and "NO" otherwise.

In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions.

[{'input': ['Hi!\r\n'], 'output': ['YES\r\n']}, {'input': ['Codeforces\r\n'], 'output': ['NO\r\n']}, {'input': ['a+b=c\r\n'], 'output': ['NO\r\n']}, {'input': ['hq-lowercase\r\n'], 'output': ['NO\r\n']}, {'input': ['Q\r\n'], 'output': ['YES\r\n']}, {'input': ['9\r\n'], 'output': ['YES\r\n']}, {'input': ['H\r\n'], 'output': ['YES\r\n']}, {'input': ['+\r\n'], 'output': ['NO\r\n']}, {'input': ['~\r\n'], 'output': ['NO\r\n']}, {'input': ['dEHsbM\'gS[\\brZ_dpjXw8f?L[4E"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR\r\n'], 'output': ['YES\r\n']}, {'input': ['tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC\r\n'], 'output': ['YES\r\n']}, {'input': ['@F%K2=%RyL/\r\n'], 'output': ['NO\r\n']}, {'input': ['juq)k(FT.^G=G\\zcqnO"uJIE1_]KFH9S=1c"mJ;F9F)%>&.WOdp09+k`Yc6}"6xw,Aos:M\\_^^:xBb[CcsHm?J\r\n'], 'output': ['YES\r\n']}, {'input': ['6G_"Fq#<AWyHG=Rci1t%#Jc#x<Fpg\'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)\r\n'], 'output': ['YES\r\n']}, {'input': ['Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C\r\n'], 'output': ['YES\r\n']}, {'input': ['p-UXsbd&f\r\n'], 'output': ['NO\r\n']}, {'input': ['<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S\'>yz8cKgVHWZ]kV0>_\r\n'], 'output': ['YES\r\n']}, {'input': ['f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf"!#qh]\r\n'], 'output': ['YES\r\n']}, {'input': ['}do5RU<(w<q["-NR)IAH_HyiD{\r\n'], 'output': ['YES\r\n']}, {'input': ["Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8\r\n"], 'output': ['YES\r\n']}, {'input': ['sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z"k2S{NF7btLa3_TyXG4XZ:`(t&"\'^M|@qObZxv\r\n'], 'output': ['YES\r\n']}, {'input': ['%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`\r\n'], 'output': ['YES\r\n']}, {'input': ['OKBB5z7ud81[Tn@P"nDUd,>@\r\n'], 'output': ['NO\r\n']}, {'input': ["y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv\r\n"], 'output': ['YES\r\n']}, {'input': ['EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh\r\n'], 'output': ['YES\r\n']}, {'input': ['UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp\r\n'], 'output': ['NO\r\n']}, {'input': ['!3YPv@2JQ44@)R2O_4`GO\r\n'], 'output': ['YES\r\n']}, {'input': ['Kba/Q,SL~FMd)3hOWU\'Jum{9"$Ld4:GW}D]%tr@G{hpG:PV5-c\'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\\r\n'], 'output': ['YES\r\n']}, {'input': ['NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e"C)q_L\r\n'], 'output': ['NO\r\n']}, {'input': ["y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&\r\n"], 'output': ['YES\r\n']}, {'input': ['+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}\r\n'], 'output': ['YES\r\n']}, {'input': ['Uh3>ER](J\r\n'], 'output': ['NO\r\n']}, {'input': ['!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,\r\n'], 'output': ['YES\r\n']}, {'input': ['KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!\r\n'], 'output': ['YES\r\n']}, {'input': ['[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@\r\n'], 'output': ['YES\r\n']}, {'input': ["'jdL(vX\r\n"], 'output': ['NO\r\n']}, {'input': ['Q;R+aay]cL?Zh*uG"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5\r\n'], 'output': ['YES\r\n']}, {'input': ['{Q@#<LU_v^qdh%gGxz*pu)Y"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s\r\n'], 'output': ['YES\r\n']}, {'input': ['~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J\'jJB)$ujfPAq"G<S9flGyakZg!2Z.-NJ|2{F>]\r\n'], 'output': ['YES\r\n']}, {'input': ['Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&"ioE&7zP"\'xHAY;:x%@SnS]Mr{R|})gU\r\n'], 'output': ['YES\r\n']}, {'input': ['ZA#:U)$RI^sE\\vuAt]x"2zipI!}YEu2<j$:H0_9/~eB?#->\r\n'], 'output': ['YES\r\n']}, {'input': ['&ppw0._:\\p-PuWM@l}%%=\r\n'], 'output': ['NO\r\n']}, {'input': ['P(^pix"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr\r\n'], 'output': ['YES\r\n']}, {'input': ['`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q\r\n'], 'output': ['YES\r\n']}, {'input': [",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0\r\n"], 'output': ['YES\r\n']}, {'input': ['VXB&r9Z)IlKOJ:??KDA\r\n'], 'output': ['YES\r\n']}, {'input': ['")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R\r\n'], 'output': ['YES\r\n']}, {'input': ["2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C\r\n"], 'output': ['YES\r\n']}, {'input': ['O.&=qt(`z(\r\n'], 'output': ['NO\r\n']}, {'input': ['_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB\'-scSg$$|"jAzY0N>QkHHGBZj2c"=fhRlWd5;5K|GgU?7h]!;wl@\r\n'], 'output': ['YES\r\n']}, {'input': ['+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp\r\n'], 'output': ['YES\r\n']}, {'input': ['U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8\r\n'], 'output': ['YES\r\n']}, {'input': ['!0WKT:$O\r\n'], 'output': ['NO\r\n']}, {'input': ["1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)\r\n"], 'output': ['YES\r\n']}, {'input': ['[u3"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12"`^\'/u*h%AFmPJ>e1#Yly\r\n'], 'output': ['YES\r\n']}, {'input': ["'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(\r\n"], 'output': ['NO\r\n']}, {'input': ['Qv)X8\r\n'], 'output': ['YES\r\n']}, {'input': ['aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%"R(?ouBD>_=y"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F\r\n'], 'output': ['YES\r\n']}, {'input': ['e{}2vQ+/r@p0}cLKNe4MCk\r\n'], 'output': ['YES\r\n']}, {'input': ['mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH\r\n'], 'output': ['YES\r\n']}, {'input': ['Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky\r\n'], 'output': ['YES\r\n']}, {'input': ['mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky\r\n'], 'output': ['YES\r\n']}, {'input': ['1H1\r\n'], 'output': ['YES\r\n']}, {'input': ['+Q\r\n'], 'output': ['YES\r\n']}, {'input': ['1ab\r\n'], 'output': ['NO\r\n']}, {'input': ['!\r\n'], 'output': ['NO\r\n']}, {'input': ['0+\r\n'], 'output': ['NO\r\n']}, {'input': ['+H\r\n'], 'output': ['YES\r\n']}, {'input': ['cH\r\n'], 'output': ['YES\r\n']}, {'input': ['+8\r\n'], 'output': ['NO\r\n']}, {'input': ['8+\r\n'], 'output': ['NO\r\n']}, {'input': ['++++++++++++++++++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['(+)\r\n'], 'output': ['NO\r\n']}, {'input': ['H+\r\n'], 'output': ['YES\r\n']}, {'input': ['a!\r\n'], 'output': ['NO\r\n']}, {'input': ['++++++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['8\r\n'], 'output': ['NO\r\n']}, {'input': ['3\r\n'], 'output': ['NO\r\n']}, {'input': ['HQ9\r\n'], 'output': ['YES\r\n']}, {'input': ['+++H\r\n'], 'output': ['YES\r\n']}, {'input': ['++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['HHHHHHH\r\n'], 'output': ['YES\r\n']}, {'input': ['abacabaH\r\n'], 'output': ['YES\r\n']}, {'input': ['+G\r\n'], 'output': ['NO\r\n']}]


Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n/2 digits) equals the sum of digits in the second half (the sum of the last n/2 digits). Check if the given ticket is lucky.

The first line contains an even integer n (2≤n≤50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n — the ticket number. The number may contain leading zeros.

On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).

In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4≠7).
In the second sample the ticket number is not the lucky number.


Sherlock Holmes and Dr. Watson played some game on a checkered board n×n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8+3+6+7=24, sum of its row numbers equals 9+5+3+2=19, and 24>19.

The first line contains an integer n (1≤n≤30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.

Print the single number — the number of the winning squares.

In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning:
5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3


#!/usr/bin/perl
# Codeforces Practice - 26 May 2012
use strict;
use warnings;

my $n = <STDIN>;
chomp($n);

my @tis = split(" ",<STDIN>);
my $tSum =0;
$tSum += $_ for @tis;
if($n%2==1 || $n<6) {print $tSum;}
else {
my ($sum1,$sum2) = (0,0);
my $toggle = 0;
foreach my $t (@tis) {
    if($toggle){
        $sum1 += $t;
    } else {
        $sum2 += $t;
    }
    $toggle = not $toggle;
}
if($sum1 >= $tSum && $sum1 >= $sum2){print $sum1;}
elsif($sum2 >= $tSum && $sum2 >= $sum1){print $sum2;}
else {print $tSum;}
}

The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:   the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),  the sum of the ti values of the remaining sculptures is maximized. Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.

The first input line contains an integer n (3≤n≤20000) — the initial number of sculptures. The second line contains a sequence of integers t1,t2,...,tn, ti — the degree of the i-th sculpture's attractiveness (-1000≤ti≤1000). The numbers on the line are separated by spaces.

Print the required maximum sum of the sculptures' attractiveness.

In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.


A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

The first line of the input data contains numbers n and t (1≤n,t≤1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side (-1000≤xi≤1000, 1≤ai≤1000).

Output the amount of possible positions of the new house.

It is possible for the x-coordinate of the new house to have non-integer value.


Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1,a2,...,an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.

The first line contains integer n (1≤n≤100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1≤ai≤100) — the coins' values. All numbers are separated with spaces.

In the single line print the single number — the minimum needed number of coins.

In the first sample you will have to take 2 coins (you and your twin have sums equal to 6,0 correspondingly). If you take 1 coin, you get sums 3,3. If you take 0 coins, you get sums 0,6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1,2 or 2,2. In any case, the minimum number of coins equals 2.

use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i;

$line = <STDIN>;
chomp($line);
@input1 = split('', $line);

$line = <STDIN>;
chomp($line);
@input2 = split(' ', $line);

# 1 5 10 10 1 1 5 25 10 1 5 5 5 1 1 1 10
# sum -> divide by 2 -> take from largest until half is surpassed
foreach $c (split(' ', $line)) {
        $s += $c;
}
$s = POSIX::floor($s / 2);
$i = 0;
$result = 0;
@input2 = sort { $b <=> $a } @input2;
while ($result <= $s) {
        $result += @input2[$i];
        $i++;
}
print $i;
exit;


#!/usr/bin/perl
use strict;
use warnings;
use bigint; # Hope for the best! Yeah, it's rather slow :-(

main();

sub main {
    my $years = <>;
    if (! $years) {
        print 1;
        goto end;
    }
    my $mod = 1000000007;
    my $h_amount = mpow(2, $years-1, $mod);
    my $last = ($h_amount * 2) % $mod;
    my $result = ((1 + $last) * $h_amount) % $mod;
    print $result;
end:
}

sub mpow {
    my ($x, $n, $mod) = @_;
    my $b = 1;
    while ($n > 0) {
        if ($n % 2) {
            $n--;
            $b *= $x;
            $b = $b % $mod;
        } else {
            $n /= 2;
            $x *= $x;
            $x = $x % $mod;
        }
    }
    return $b % $mod;
}

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.

The first line contains a single integer n (0≤n≤10^18) — the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (10^9+7).

The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.

#!/usr/bin/perl
use strict;
use warnings;
use bigint; # Hope for the best! Yeah, it's rather slow :-(

main();

sub main {
    my $years = <>;
    if ($years == 0) {
        print 1;
        goto end;
    }
    my $mod = 1000000007;
    my $h_amount = mpow(2, $years-1, $mod);
    my $last = ($h_amount * 2) % $mod;
    my $result = ((1 + $last) * $h_amount) % $mod;
    print $result;
end:
}

sub mpow {
    my ($x, $n, $mod) = @_;
    my $b = 1;
    while ($n > 0) {
        if ($n % 2) {
            $n--;
            $b *= $x;
            $b = $b % $mod;
        } else {
            $n /= 2;
            $x *= $x;
            $x = $x % $mod;
        }
    }
    return $b % $mod;
}


You are given two polynomials:  P(x)=a0·x^n+a1·x^n-1+...+an-1·x+an and  Q(x)=b0·x^m+b1·x^m-1+...+bm-1·x+bm.  Calculate limit .

The first line contains two space-separated integers n and m (0≤n,m≤100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n+1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an-1, an (-100≤ai≤100,a0≠0).
The third line contains m+1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm-1, bm (-100≤bi≤100,b0≠0).

If the limit equals +∞, print "Infinity" (without quotes). If the limit equals -∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q>0) is the denominator of the fraction.

Let's consider all samples:
           You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function


# LUOGU_RID: 110532149
dfgdfgdf
fghfg
hf
gh
fg
hf
gh
fg
h
fg
h
fg
h
fg
hfghfghfg

Theatre Square in the capital city of Berland has a rectangular shape with the size n×m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a×a.What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

The input contains three positive integer numbers in the first line: n,m and a (1≤n,m,a≤10^9).

#!/usr/bin/env perl
use 5.020;
use strict;
use warnings qw( all );

sub ceil {
    my ( $n ) = @_;
    my $_n = int( $n );
    return $_n == $n
        ? $n
        : $_n + 1;
}

chomp( my $input = <STDIN> );

my ( $n, $m, $a ) = split /\s+/x, $input;

$n = ceil( $n / $a );
$m = ceil( $m / $a );

say $n * $m;


#!/usr/bin/perl -w
use strict;
no warnings;

$_ = <>;
chomp ($_);
my ($size, $count) = split / /;

my $matrix;

# Fill matrix

for (my $xx = 1; $xx <= $size; $xx++) {
    for (my $yy = 1; $yy <= $size; $yy++) {
        $$matrix{$xx,$yy} = 0;
    }
}

sub print_matrix() {
    for (my $xx = 1; $xx <= $size; $xx++) {
        for (my $yy = 1; $yy <= $size; $yy++) {
            print "$$matrix{$xx,$yy} ";
        }

        print "\n";
    }
}

sub check_matrix() {
    my $ones = 0;

    my ($xx, $yy);

    for ($yy = 1; $yy <= $size-2; $yy++) {
        for ($xx = 1; $xx <= $size-2; $xx++) {
            $ones = 0;

            $ones++ if ($$matrix{$xx, $yy} eq 1);
            $ones++ if ($$matrix{$xx + 1, $yy} eq 1 and $ones eq 1);
            $ones++ if ($$matrix{$xx + 2, $yy} eq 1 and $ones eq 2);

            $ones++ if ($$matrix{$xx, $yy + 1} eq 1 and $ones eq 3);
            $ones++ if ($$matrix{$xx + 1, $yy + 1} eq 1 and $ones eq 4);
            $ones++ if ($$matrix{$xx + 2, $yy + 1} eq 1 and $ones eq 5);

            $ones++ if ($$matrix{$xx, $yy + 2} eq 1 and $ones eq 6);
            $ones++ if ($$matrix{$xx + 1, $yy + 2} eq 1 and $ones eq 7);
            $ones++ if ($$matrix{$xx + 2, $yy + 2} eq 1 and $ones eq 8);

            return 1 if ($ones eq 9);
        }

        $xx = 0;
    }

    return 0;
}

my $found = 0;

for (my $i = 1; $i <= $count; $i++) {
    $_ = <>;
    chomp($_);
    my ($x, $y) = split / /, $_;

    #print "($x;$y)\n";
    $$matrix{$x,$y} = 1;

    if (check_matrix()) {
        $found = 1;
        print $count-1, "\n";
        exit;
    }
}

#print_matrix();
print "-1\n" if (!$found);

One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.He took a checkered white square piece of paper, consisting of n×n cells. After that, he started to paint the white cells black one after the other. In total he painted m different cells on the piece of paper. Since Valera was keen on everything square, he wondered, how many moves (i.e. times the boy paints a square black) he should make till a black square with side 3 can be found on the piece of paper. But Valera does not know the answer to this question, so he asks you to help him.Your task is to find the minimum number of moves, till the checkered piece of paper has at least one black square with side of 3. Otherwise determine that such move does not exist.

The first line contains two integers n and m (1≤n≤1000, 1≤m≤min(n·n,10^5)) — the size of the squared piece of paper and the number of moves, correspondingly.
Then, m lines contain the description of the moves. The i-th line contains two integers xi, yi (1≤xi,yi≤n) — the number of row and column of the square that gets painted on the i-th move.
All numbers on the lines are separated by single spaces. It is guaranteed that all moves are different. The moves are numbered starting from 1 in the order, in which they are given in the input. The columns of the squared piece of paper are numbered starting from 1, from the left to the right. The rows of the squared piece of paper are numbered starting from 1, from top to bottom.

On a single line print the answer to the problem — the minimum number of the move after which the piece of paper has a black square with side 3. If no such move exists, print -1.

#!/bin/perl -w
use strict;
use warnings;
use List::Util qw[min max];

my ($n, $m) = map int, split /\D/, <>;

my @square = ('W' x $n) x $n;

for my $move (1..$m) {
    my ($i, $j) = map int, split /\D/, <>;
    map { $_-- } ($i, $j);
    substr($square[$i], $j, 1) = 'B';
    for (0..2) {
	my $indx = index $square[$i], 'BBB', max($j-$_, 0);
	if ($indx > -1) {
	    my $black_rows = '';
	    for (max($i-2, 0) .. min($i+2, $n-1)) {
		if (substr($square[$_], $indx, 3) eq 'BBB') {
		    $black_rows .= 1;
		} else {
		    $black_rows .= 0;
		}
	    }
	    if ($black_rows =~ /111/) {
		print "$move\n";
		exit;
	    }
	}
    }
}

print "-1\n";


Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.

The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.

Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.

In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".

[{'input': ['WUBWUBABCWUB\r\n'], 'output': ['ABC ']}, {'input': ['WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\r\n'], 'output': ['WE ARE THE CHAMPIONS MY FRIEND ']}, {'input': ['WUBWUBWUBSR\r\n'], 'output': ['SR ']}, {'input': ['RWUBWUBWUBLWUB\r\n'], 'output': ['R L ']}, {'input': ['ZJWUBWUBWUBJWUBWUBWUBL\r\n'], 'output': ['ZJ J L ']}, {'input': ['CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB\r\n'], 'output': ['C B E Q ']}, {'input': ['WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB\r\n'], 'output': ['JKD WBIRAQKF YE WV ']}, {'input': ['WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB\r\n'], 'output': ['KSDHEMIXUJ R S H ']}, {'input': ['OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB\r\n'], 'output': ['OG X I KO ']}, {'input': ['QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH\r\n'], 'output': ['Q QQ I WW JOPJPBRH ']}, {'input': ['VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB\r\n'], 'output': ['VSRNVEATZTLGQRFEGBFP AJ PQCHN C ']}, {'input': ['WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV\r\n'], 'output': ['E IQMJNIQ GZZBQZAUHYP PMR DCV ']}, {'input': ['WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB\r\n'], 'output': ['FV BPS RXNETCJ JDMBH B V B ']}, {'input': ['WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL\r\n'], 'output': ['FBQ IDFSY CTWDM SXO QI L ']}, {'input': ['IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL\r\n'], 'output': ['I QLHD YIIKZDFQ CX U K NL ']}, {'input': ['KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE\r\n'], 'output': ['K UPDYXGOKU AGOAH IZD IY V P E ']}, {'input': ['WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB\r\n'], 'output': ['O IPVCQAFWY Q XHDKCPYKCTWWY V FZ ']}, {'input': ['PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB\r\n'], 'output': ['PAMJGY XGPQM TKGSXUY E N H E ']}, {'input': ['WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB\r\n'], 'output': ['YYRTSMNWU C C FSYUINDWOBV F AU V JB ']}, {'input': ['WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM\r\n'], 'output': ['YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M ']}, {'input': ['WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW\r\n'], 'output': ['ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W ']}, {'input': ['WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG\r\n'], 'output': ['ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G ']}, {'input': ['WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN\r\n'], 'output': ['J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N ']}, {'input': ['WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG\r\n'], 'output': ['LC ZGEQUEATJVIXETVT EXMG RS V TA C QG ']}, {'input': ['WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB\r\n'], 'output': ['MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L ']}, {'input': ['WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB\r\n'], 'output': ['NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U ']}, {'input': ['WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB\r\n'], 'output': ['NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ ']}, {'input': ['SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB\r\n'], 'output': ['SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J ']}, {'input': ['TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO\r\n'], 'output': ['TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O ']}, {'input': ['WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR\r\n'], 'output': ['WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R ']}, {'input': ['WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB\r\n'], 'output': ['XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM ']}, {'input': ['BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB\r\n'], 'output': ['BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H ']}, {'input': ['CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB\r\n'], 'output': ['CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S ']}, {'input': ['DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB\r\n'], 'output': ['DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J ']}, {'input': ['WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF\r\n'], 'output': ['ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F ']}, {'input': ['WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY\r\n'], 'output': ['I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y ']}, {'input': ['WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB\r\n'], 'output': ['M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO ']}, {'input': ['WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW\r\n'], 'output': ['NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W ']}, {'input': ['WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD\r\n'], 'output': ['OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D ']}, {'input': ['WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB\r\n'], 'output': ['REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A ']}, {'input': ['WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB\r\n'], 'output': ['STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y ']}, {'input': ['WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB\r\n'], 'output': ['WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R ']}, {'input': ['YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY\r\n'], 'output': ['YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y ']}, {'input': ['WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE\r\n'], 'output': ['CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E ']}, {'input': ['WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS\r\n'], 'output': ['CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S ']}, {'input': ['WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP\r\n'], 'output': ['HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP ']}, {'input': ['WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB\r\n'], 'output': ['KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y ']}, {'input': ['REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL\r\n'], 'output': ['RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL ']}, {'input': ['CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO\r\n'], 'output': ['CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O ']}, {'input': ['WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU\r\n'], 'output': ['JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU ']}, {'input': ['A\r\n'], 'output': ['A ']}, {'input': ['WUBA\r\n'], 'output': ['A ']}, {'input': ['WUBWUBA\r\n'], 'output': ['A ']}, {'input': ['AWUBWUBWUB\r\n'], 'output': ['A ']}, {'input': ['AWUBBWUBCWUBD\r\n'], 'output': ['A B C D ']}, {'input': ['WUBWWUBWUBWUBUWUBWUBBWUB\r\n'], 'output': ['W U B ']}, {'input': ['AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n'], 'output': ['AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ']}, {'input': ['AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n'], 'output': ['AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ']}, {'input': ['WUWUBBWWUBUB\r\n'], 'output': ['WU BW UB ']}, {'input': ['WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB\r\n'], 'output': ['WUAB ']}, {'input': ['ZWUB\r\n'], 'output': ['Z ']}, {'input': ['WU\r\n'], 'output': ['WU ']}, {'input': ['UB\r\n'], 'output': ['UB ']}, {'input': ['U\r\n'], 'output': ['U ']}, {'input': ['WUBW\r\n'], 'output': ['W ']}, {'input': ['WUBWU\r\n'], 'output': ['WU ']}, {'input': ['WUWUB\r\n'], 'output': ['WU ']}, {'input': ['UBWUB\r\n'], 'output': ['UB ']}, {'input': ['WUWUBUBWUBUWUB\r\n'], 'output': ['WU UB U ']}, {'input': ['WUBWWUBAWUB\r\n'], 'output': ['W A ']}, {'input': ['WUUUUU\r\n'], 'output': ['WUUUUU ']}]


my $n = <STDIN>;
chomp $n;

my $int_list = <STDIN>;
chomp $int_list;

my @array = split(" ",$int_list);

my $min = $array[0];

my $sec = "NO";

for my $elem (@array){
    if ($elem < $min){
        $sec = $min;
        $min = $elem;
    }
    elsif (($elem > $min) && (($sec eq "NO") ||($sec > $elem))){
        $sec = $elem;
    }
}

Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

The first input line contains integer n (1≤n≤100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

If the given sequence has the second order statistics, output this order statistics, otherwise output NO.


We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

The first line contains a single positive integer, n (1≤n≤10^5), showing how many numbers are in the array. The next line contains n space-separated integers xi (1≤xi≤10^12).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".


#!/usr/bin/perl
use v5.10;
use integer;

($n, $d) = split / /, <>;
$tot+=$_ foreach (split / /, <>);
$tot += ($n-1) * 10;
$tot>$d and say -1 or say ($d-$tot)/5+($n-1)*2;

Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, i^th song will take ti minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:  The duration of the event must be no more than d minutes;  Devu must complete all his songs;  With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.

The first line contains two space separated integers n, d (1≤n≤100; 1≤d≤10000). The second line contains n space-separated integers: t1,t2,...,tn (1≤ti≤100).

If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.

Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
  First Churu cracks a joke in 5 minutes.  Then Devu performs the first song for 2 minutes.  Then Churu cracks 2 jokes in 10 minutes.  Now Devu performs second song for 2 minutes.  Then Churu cracks 2 jokes in 10 minutes.  Now finally Devu will perform his last song in 1 minutes.  Total time spent is 5+2+10+2+10+1=30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.


#!/bin/bash/perl
$input=<>;
@reference = split(" ",$input);
$input=<>;
@tofind=split(" ",$input);
#for($x=0;$x<@tofind;++$x){print length($tofind[$x])."\n";}
%hash;
for($var='a';$var ne 'aa';++$var){
    $hash{$var}=0;
}
for($var='A';$var ne 'AA';++$var){
    $hash{$var}=0;
}
#fill the hash
for($i=0;$i<@reference;++$i){
    @temp=split("",$reference[$i]);
    for($j=0;$j<@temp;++$j){
        ++$hash{$temp[$j]};
    }
}
#start checking the hash
$notfound=1;
for($i=0;$i<@tofind && $notfound==1;++$i){
    @temp=split("",$tofind[$$i]);
    for($j=0;$j<@temp;++$j){
        if($hash{$temp[$j]}<=0){
            $notfound=0;
            $j=@temp;
        }
        else{
            $hash{$temp[$j]}--;
        }
    }
}

if($notfound==0){
    print "NO";
}
else{
    print "YES";
}

Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.

The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 и s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.

If Vasya can write the given anonymous letter, print YES, otherwise print NO

Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog

Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears

Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears

[{'input': ['Instead of dogging Your footsteps it disappears but you dont notice anything\r\nwhere is your dog\r\n'], 'output': ['NO\r\n']}, {'input': ['Instead of dogging Your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n'], 'output': ['YES\r\n']}, {'input': ['Instead of dogging your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n'], 'output': ['NO\r\n']}, {'input': ['abcdefg hijk\r\nk j i h g f e d c b a\r\n'], 'output': ['YES\r\n']}, {'input': ['HpOKgo\r\neAtAVB\r\n'], 'output': ['NO\r\n']}, {'input': ['GRZGc\r\nLPzD\r\n'], 'output': ['NO\r\n']}, {'input': ['GtPXu\r\nd\r\n'], 'output': ['NO\r\n']}, {'input': ['FVF\r\nr \r\n'], 'output': ['NO\r\n']}, {'input': ['HpOKgo\r\nogK\r\n'], 'output': ['YES\r\n']}, {'input': ['GRZGc\r\nZG\r\n'], 'output': ['YES\r\n']}, {'input': ['HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT  MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\r\nAHN  XvoaNwV  AVBKwKjr u      U K wKE D K   Jy KiHsR h d W  Js IHyMPK Br iSqe  E fDA   g H\r\n'], 'output': ['YES\r\n']}, {'input': ['GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\r\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj  bCDgKF  jJxa RddtLFAi VGLHH SecObzG q  hPF \r\n'], 'output': ['YES\r\n']}, {'input': ['GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\r\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp\r\n'], 'output': ['YES\r\n']}, {'input': ['FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\r\nUzrU K  an GFGR        Wc zt iBa     P c    T K v p     V In   b           B   c\r\n'], 'output': ['YES\r\n']}, {'input': ['lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\r\nAoxe  jWZ u  yImg  o AZ FNI w lpj  tNhT g y  ZYcb rc J    w Dlv\r\n'], 'output': ['YES\r\n']}, {'input': ['kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\r\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc\r\n'], 'output': ['YES\r\n']}, {'input': ['kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\r\nBsH   bWHJD n Ca T xq  PRCv  tatn Wjy sm  I q s WCjFqdWe  t W XUs  Do  eb Pfh ii  hTbF  O Fll\r\n'], 'output': ['YES\r\n']}, {'input': ['OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\r\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK\r\n'], 'output': ['YES\r\n']}, {'input': ['NwcGaIeSkOva\r\naIa\r\n'], 'output': ['YES\r\n']}, {'input': ['gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\r\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui\r\n'], 'output': ['YES\r\n']}, {'input': ['ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\r\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy\r\n'], 'output': ['NO\r\n']}, {'input': ['hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\r\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW\r\n'], 'output': ['NO\r\n']}, {'input': ['yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\r\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw\r\n'], 'output': ['NO\r\n']}, {'input': ['jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\r\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL\r\n'], 'output': ['NO\r\n']}, {'input': ['zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\r\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl\r\n'], 'output': ['NO\r\n']}, {'input': ['kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\r\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh\r\n'], 'output': ['NO\r\n']}, {'input': ['AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\r\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ\r\n'], 'output': ['NO\r\n']}, {'input': ['lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\r\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl\r\n'], 'output': ['NO\r\n']}, {'input': ['BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\r\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk\r\n'], 'output': ['NO\r\n']}, {'input': ['KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\r\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk\r\n'], 'output': ['NO\r\n']}]


Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

The first line contains an integer n (1≤n≤100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

Output the single number — the number of Alyona's leaves.

5
birch yellow
maple red
birch yellow
maple yellow
maple green

$n = <>; chomp $n;
while($n--){
    $_=<>;chomp;
    $h{$_} = 1;
}
print (scalar keys %h);

[{'input': ['5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n'], 'output': ['4\r\n']}, {'input': ['3\r\noak yellow\r\noak yellow\r\noak yellow\r\n'], 'output': ['1\r\n']}, {'input': ['5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n'], 'output': ['5\r\n']}, {'input': ['1\r\nqvwli hz\r\n'], 'output': ['1\r\n']}, {'input': ['4\r\nsrhk x\r\nsrhk x\r\nqfoe vnrjuab\r\nqfoe vnrjuab\r\n'], 'output': ['2\r\n']}, {'input': ['4\r\nsddqllmmpk syded\r\nfprsq fnenjnaz\r\nn hdej\r\nsddqllmmpk syded\r\n'], 'output': ['3\r\n']}, {'input': ['17\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\njtbctslqq tosqzw\r\n'], 'output': ['1\r\n']}, {'input': ['18\r\nb d\r\nrfdb esp\r\nrfdb esp\r\nb d\r\nrfdb esp\r\nrfdb esp\r\nb d\r\nb d\r\nrfdb esp\r\nrfdb esp\r\nb d\r\nrfdb esp\r\nb d\r\nrfdb esp\r\nb d\r\nb d\r\nrfdb esp\r\nrfdb esp\r\n'], 'output': ['2\r\n']}, {'input': ['13\r\nsvpzwtwn rykzfdce\r\nqweiyeck jkreouy\r\nhk nnli\r\ntwxrnbbdt vtuv\r\nxokqjtylly sz\r\nesdt dbfidjslq\r\ng ybqgomvw\r\nxcpfjmf zcqvz\r\nifajadhj invzueip\r\nvdemdnxifb hckwebmi\r\nsdpnhipam wvowzavh\r\nuqdlfskhgo vunbpghae\r\ne dtigwnb\r\n'], 'output': ['13\r\n']}, {'input': ['20\r\nm vkfh\r\nvptikamead mvx\r\nitu mf\r\nklruxckw aqega\r\nekqkd enjllwol\r\ncc uybfdh\r\nimrfdngvo u\r\ne uh\r\ntwt jsslcfuogk\r\nbljwqsag tuqbdn\r\nqcv q\r\nasx gzhvwwmajj\r\nqcv q\r\nekqkd enjllwol\r\nasx gzhvwwmajj\r\nks vv\r\nkzyfi cn\r\ncc uybfdh\r\nitu mf\r\ncjbjhtbyvk vatwfmux\r\n'], 'output': ['15\r\n']}, {'input': ['2\r\nab ab\r\na bab\r\n'], 'output': ['2\r\n']}]


Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!

The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 10^5, inclusive. The representation of n doesn't contain any leading zeroes.

If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print -1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.


use strict;
use warnings;

my $n = <>;
chomp($n);

my ($x_sum, $y_sum, $z_sum);

while($n--){
    my $in = <>;
    my ($x, $y, $z) = split(' ', $in);
    $x_sum += $x;
    $y_sum += $y;
    $z_sum += $z;
}
print("$x_sum $y_sum $z_sum\n");
if($x_sum || $y_sum || $z_sum){
    print("NO\n");
}
else{
    print("YES\n");
}

A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.

The first line contains a positive integer n (1≤n≤100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body (-100≤xi,yi,zi≤100).

Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.

use strict;
use warnings;

my $n = <>;
chomp($n);

my ($x_sum, $y_sum, $z_sum);

while($n--){
    my $in = <>;
    my ($x, $y, $z) = split(' ', $in);
    $x_sum += $x;
    $y_sum += $y;
    $z_sum += $z;
}

if($x_sum || $y_sum || $z_sum){
    print("NO\n");
}
else{
    print("YES\n");
}