On one of the planets of Solar system, in Atmosphere University, many students are fans of bingo game.It is well known that one month on this planet consists of $$$n^2$$$ days, so calendars, represented as square matrix $$$n$$$ by $$$n$$$ are extremely popular.Weather conditions are even more unusual. Due to the unique composition of the atmosphere, when interacting with sunlight, every day sky takes one of three colors: blue, green or red.To play the bingo, you need to observe the sky for one month — after each day, its cell is painted with the color of the sky in that day, that is, blue, green or red.At the end of the month, students examine the calendar. If at least one row or column contains only cells of one color, that month is called lucky.Let's call two colorings of calendar different, if at least one cell has different colors in them. It is easy to see that there are $$$3^{n \cdot n}$$$ different colorings. How much of them are lucky? Since this number can be quite large, print it modulo $$$998244353$$$.

The first and only line of input contains a single integer $$$n$$$ ($$$1 \le n \le 1000\,000$$$) — the number of rows and columns in the calendar.

Print one number — number of lucky colorings of the calendar modulo $$$998244353$$$

In the first sample any coloring is lucky, since the only column contains cells of only one color.
In the second sample, there are a lot of lucky colorings, in particular, the following colorings are lucky:

While these colorings are not lucky:

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.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)); }

struct ModInt(int M_) {
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}

enum MO = 998244353;
alias Mint = ModInt!MO;

enum LIM = 10^^6 + 10;
Mint[] inv, fac, invFac;
void prepare() {
  inv = new Mint[LIM];
  fac = new Mint[LIM];
  invFac = new Mint[LIM];
  inv[1] = 1;
  foreach (i; 2 .. LIM) {
    inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];
  }
  fac[0] = invFac[0] = 1;
  foreach (i; 1 .. LIM) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(long n, long k) {
  if (0 <= k && k <= n) {
    assert(n < LIM);
    return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];
  } else {
    return Mint(0);
  }
}

void main() {
  prepare();
  try {
    for (; ; ) {
      const N = readInt();

      auto pw = new Mint[N + 1];
      pw[0] = 1;
      foreach (i; 1 .. N + 1) {
        pw[i] = pw[i - 1] * 3;
      }
      auto pwN = new Mint[N + 1];
      pwN[0] = 1;
      foreach (i; 1 .. N + 1) {
        pwN[i] = pwN[i - 1] * pw[N];
      }

      Mint ans;
      ans += pwN[N];
      foreach (a; 1 .. N + 1) {
        int s = 1;
        if (a % 2 != 0) s *= -1;
        ans += 2 * s * binom(N, a) * pw[a] * pwN[N - a];
      }
      foreach (a; 1 .. N + 1) {
        /*
          sum 3 (-1)^(a + b) binom(N, a) binom(N, b) 3^((N - a) (N - b))
        */
        int s = 1;
        if (a % 2 != 0) s *= -1;
        ans -= 3 * s * binom(N, a) * pwN[N - a];
        if (N % 2 != 0) s *= -1;
        ans += 3 * s * binom(N, a) * (1 - pw[N - a])^^N;
      }
      ans = Mint(3)^^(1L * N * N) - ans;
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?

The first line contains the only integer n (0≤n≤10^100000). It is guaranteed that n doesn't contain any leading zeroes.

Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.

In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991→19→10→1. After three transformations the number becomes one-digit.

#!/usr/bin/perl -w

chomp ($num = <>);
@arr = unpack('(A1)*', $num);
$count = 0;
while (@arr > 1) {
	$count++;
	$num = 0;
	for $i (0..@arr-1) {
		$num += $arr[$i];
	}
	@arr = unpack('(A1)*', $num);
}
print $count;


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).


Tattah's youngest brother, Tuftuf, is new to programming.Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1,a2,... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2^ai-1 inclusive. Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai<aj, then Tuftuf will stop using Gava.Your task is to determine Tuftuf's destiny.

The first line contains integer n (2≤n≤10^5) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1≤ai≤10^9) — sizes of datatypes in bits. Some datatypes may have equal sizes.

Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.

In the second example, x=7 (1112) fits in 3 bits, but x^2=49 (1100012) does not fit in 4 bits.

#!perl

$n = <STDIN>;
$str = <STDIN>;
@types = split /\D/, $str;
@types = sort {$a<=>$b} @types;
if ($n == 1) {
	print "NO";
} else {
	for ($i = 0; $i < $n-1; $i++) {
		if (($types[$i] != $types[$i+1]) && ($types[$i+1] / $types[$i] < 2)) {
			print "YES";
			goto end;
		}
	}
}
print "NO";
end:


There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3×3 with digits from 1 to 9.Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.

Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».

Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.

If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry

$a = '';
while(<>){chomp; $a .= $_;}

$a =~ s/\n//;

if($a eq (reverse($a))){
    print "YES";
}else{
    print "NO";
}


wHAT DO WE NEED cAPS LOCK FOR?Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:   either it only contains uppercase letters;  or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.

The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.

Print the result of the given word's processing.

[{'input': ['cAPS\r\n'], 'output': ['Caps']}, {'input': ['Lock\r\n'], 'output': ['Lock\r\n']}, {'input': ['cAPSlOCK\r\n'], 'output': ['cAPSlOCK\r\n']}, {'input': ['CAPs\r\n'], 'output': ['CAPs\r\n']}, {'input': ['LoCK\r\n'], 'output': ['LoCK\r\n']}, {'input': ['OOPS\r\n'], 'output': ['oops']}, {'input': ['oops\r\n'], 'output': ['oops\r\n']}, {'input': ['a\r\n'], 'output': ['A']}, {'input': ['A\r\n'], 'output': ['a']}, {'input': ['aA\r\n'], 'output': ['Aa']}, {'input': ['Zz\r\n'], 'output': ['Zz\r\n']}, {'input': ['Az\r\n'], 'output': ['Az\r\n']}, {'input': ['zA\r\n'], 'output': ['Za']}, {'input': ['AAA\r\n'], 'output': ['aaa']}, {'input': ['AAa\r\n'], 'output': ['AAa\r\n']}, {'input': ['AaR\r\n'], 'output': ['AaR\r\n']}, {'input': ['Tdr\r\n'], 'output': ['Tdr\r\n']}, {'input': ['aTF\r\n'], 'output': ['Atf']}, {'input': ['fYd\r\n'], 'output': ['fYd\r\n']}, {'input': ['dsA\r\n'], 'output': ['dsA\r\n']}, {'input': ['fru\r\n'], 'output': ['fru\r\n']}, {'input': ['hYBKF\r\n'], 'output': ['Hybkf']}, {'input': ['XweAR\r\n'], 'output': ['XweAR\r\n']}, {'input': ['mogqx\r\n'], 'output': ['mogqx\r\n']}, {'input': ['eOhEi\r\n'], 'output': ['eOhEi\r\n']}, {'input': ['nkdku\r\n'], 'output': ['nkdku\r\n']}, {'input': ['zcnko\r\n'], 'output': ['zcnko\r\n']}, {'input': ['lcccd\r\n'], 'output': ['lcccd\r\n']}, {'input': ['vwmvg\r\n'], 'output': ['vwmvg\r\n']}, {'input': ['lvchf\r\n'], 'output': ['lvchf\r\n']}, {'input': ['IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO\r\n'], 'output': ['iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo']}, {'input': ['OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG\r\n'], 'output': ['obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg']}, {'input': ['IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS\r\n'], 'output': ['ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs']}, {'input': ['cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE\r\n'], 'output': ['Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype']}, {'input': ['uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ\r\n'], 'output': ['Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq']}, {'input': ['KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR\r\n'], 'output': ['KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR\r\n']}, {'input': ['ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE\r\n'], 'output': ['ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE\r\n']}, {'input': ['TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ\r\n'], 'output': ['TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ\r\n']}, {'input': ['xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm\r\n'], 'output': ['xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm\r\n']}, {'input': ['udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm\r\n'], 'output': ['udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm\r\n']}, {'input': ['jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg\r\n'], 'output': ['jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg\r\n']}, {'input': ['vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc\r\n'], 'output': ['vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc\r\n']}, {'input': ['pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv\r\n'], 'output': ['pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv\r\n']}, {'input': ['upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect\r\n'], 'output': ['upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect\r\n']}, {'input': ['cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE\r\n'], 'output': ['Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype']}, {'input': ['JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu\r\n'], 'output': ['JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu\r\n']}, {'input': ['aBACABa\r\n'], 'output': ['aBACABa\r\n']}, {'input': ['AAAAAAAAAAAAAAAAAAAAAAAAaa\r\n'], 'output': ['AAAAAAAAAAAAAAAAAAAAAAAAaa\r\n']}, {'input': ['aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n'], 'output': ['aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n']}, {'input': ['dDDDDDDDDDDDDD\r\n'], 'output': ['Dddddddddddddd']}, {'input': ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n'], 'output': ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n']}, {'input': ['z\r\n'], 'output': ['Z']}, {'input': ['AZ\r\n'], 'output': ['az']}, {'input': ['Z\r\n'], 'output': ['z']}, {'input': ['aAAAA\r\n'], 'output': ['Aaaaa']}, {'input': ['F\r\n'], 'output': ['f']}]


Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti (-10≤ti≤10). Of course, one number can be assigned to any number of customers."Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of t. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence t1,t2,...,tn. For example, if t=(1,-1,1,-1), then any two elements ti and tj form a couple if i and j have different parity. Consequently, in this case the sought number equals 4.Of course, a client can't form a couple with him/herself.

The first line of the input data contains an integer n (1≤n≤10^5) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1,t2,...,tn (-10≤ti≤10), ti — is the parameter of the i-th customer that has been assigned to the customer by the result of the analysis of his interests.

Print the number of couples of customs with opposite t. The opposite number for x is number -x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

<>;
$_=<>;
$_[20]=0;
s/-?\d+/$_[$&]++/eg;
for (1..10){
	$ats += $_[-$_]*$_[$_]
	}
$ats += $_[0]*($_[0]-1)/2;
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}


You are given a sequence of positive integers a1,a2,...,an. Find all such indices i, that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one).

The first line contains the integer n (2≤n≤2·10^5). The second line contains elements of the sequence a1,a2,...,an (1≤ai≤1000). All the elements are positive integers.

Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to n.
If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line.


So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L".

[{'input': ['SANTACLAUS\r\nDEDMOROZ\r\nSANTAMOROZDEDCLAUS\r\n'], 'output': ['YES\r\n']}, {'input': ['PAPAINOEL\r\nJOULUPUKKI\r\nJOULNAPAOILELUPUKKI\r\n'], 'output': ['NO\r\n']}, {'input': ['BABBONATALE\r\nFATHERCHRISTMAS\r\nBABCHRISTMASBONATALLEFATHER\r\n'], 'output': ['NO\r\n']}, {'input': ['B\r\nA\r\nAB\r\n'], 'output': ['YES\r\n']}, {'input': ['ONDOL\r\nJNPB\r\nONLNJBODP\r\n'], 'output': ['YES\r\n']}, {'input': ['Y\r\nW\r\nYW\r\n'], 'output': ['YES\r\n']}, {'input': ['OI\r\nM\r\nIMO\r\n'], 'output': ['YES\r\n']}, {'input': ['VFQRWWWACX\r\nGHZJPOQUSXRAQDGOGMR\r\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF\r\n'], 'output': ['YES\r\n']}, {'input': ['JUTCN\r\nPIGMZOPMEUFADQBW\r\nNWQGZMAIPUPOMCDUB\r\n'], 'output': ['NO\r\n']}, {'input': ['Z\r\nO\r\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH\r\n'], 'output': ['NO\r\n']}, {'input': ['IQ\r\nOQ\r\nQOQIGGKFNHJSGCGM\r\n'], 'output': ['NO\r\n']}, {'input': ['ROUWANOPNIGTVMIITVMZ\r\nOQTUPZMTKUGY\r\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR\r\n'], 'output': ['YES\r\n']}, {'input': ['OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\r\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\r\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY\r\n'], 'output': ['YES\r\n']}, {'input': ['NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\r\nNSFQDFUMQDQWQ\r\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX\r\n'], 'output': ['YES\r\n']}, {'input': ['IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\r\nNJMWRMBCNPHXTDQQNZ\r\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW\r\n'], 'output': ['YES\r\n']}, {'input': ['SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\r\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\r\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU\r\n'], 'output': ['YES\r\n']}, {'input': ['H\r\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\r\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK\r\n'], 'output': ['YES\r\n']}, {'input': ['DSWNZRFVXQ\r\nPVULCZGOOU\r\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE\r\n'], 'output': ['NO\r\n']}, {'input': ['EUHTSCENIPXLTSBMLFHD\r\nIZAVSZPDLXOAGESUSE\r\nLXAELAZ\r\n'], 'output': ['NO\r\n']}, {'input': ['WYSJFEREGELSKRQRXDXCGBODEFZVSI\r\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\r\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI\r\n'], 'output': ['NO\r\n']}, {'input': ['EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\r\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\r\nECGXACVKEYMCEDOTMKAUFHLHOMT\r\n'], 'output': ['NO\r\n']}, {'input': ['NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\r\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\r\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY\r\n'], 'output': ['NO\r\n']}, {'input': ['VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\r\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\r\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT\r\n'], 'output': ['NO\r\n']}, {'input': ['PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\r\nFUPDLNVIHRWTEEEHOOEC\r\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY\r\n'], 'output': ['NO\r\n']}, {'input': ['GDSLNIIKTO\r\nJF\r\nPDQYFKDTNOLI\r\n'], 'output': ['NO\r\n']}, {'input': ['AHOKHEKKPJLJIIWJRCGY\r\nORELJCSIX\r\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE\r\n'], 'output': ['NO\r\n']}, {'input': ['ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\r\nTEV\r\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH\r\n'], 'output': ['NO\r\n']}, {'input': ['AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\r\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\r\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU\r\n'], 'output': ['NO\r\n']}, {'input': ['XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\r\nZKIWNDGBISDB\r\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG\r\n'], 'output': ['NO\r\n']}, {'input': ['PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\r\nTWRRAJLCQJTKOKWCGUH\r\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM\r\n'], 'output': ['NO\r\n']}, {'input': ['QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\r\nV\r\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW\r\n'], 'output': ['NO\r\n']}, {'input': ['XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\r\nLEXOPFPVPSZK\r\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ\r\n'], 'output': ['YES\r\n']}, {'input': ['OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\r\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\r\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS\r\n'], 'output': ['YES\r\n']}, {'input': ['VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\r\nFE\r\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH\r\n'], 'output': ['YES\r\n']}, {'input': ['WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\r\nBLQZRRWP\r\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB\r\n'], 'output': ['YES\r\n']}, {'input': ['MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\r\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\r\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP\r\n'], 'output': ['YES\r\n']}, {'input': ['OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\r\nDJBFVRTARTFZOWN\r\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR\r\n'], 'output': ['YES\r\n']}, {'input': ['OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\r\nOHBKWRFDRQUAFRCMT\r\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT\r\n'], 'output': ['YES\r\n']}, {'input': ['OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\r\nMYYDQKOOYPOOUELCRIT\r\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH\r\n'], 'output': ['YES\r\n']}, {'input': ['WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\r\nYOBMOVYTUATTFGJLYUQD\r\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG\r\n'], 'output': ['YES\r\n']}, {'input': ['CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\r\nMUFOSEUEXEQTOVLGDSCWM\r\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF\r\n'], 'output': ['YES\r\n']}, {'input': ['IDQRX\r\nWETHO\r\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA\r\n'], 'output': ['NO\r\n']}, {'input': ['IXFDY\r\nJRMOU\r\nDF\r\n'], 'output': ['NO\r\n']}, {'input': ['JPSPZ\r\nUGCUB\r\nJMZZZZZZZZ\r\n'], 'output': ['NO\r\n']}, {'input': ['AC\r\nA\r\nBBA\r\n'], 'output': ['NO\r\n']}, {'input': ['UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\r\nKZXQDWJJWRXFHKJDQHJK\r\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB\r\n'], 'output': ['NO\r\n']}, {'input': ['PXWRXRPFLR\r\nPJRWWXIVHODV\r\nXW\r\n'], 'output': ['NO\r\n']}, {'input': ['CHTAZVHGSHCVIBK\r\nEQINEBKXEPYJSAZIMLDF\r\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE\r\n'], 'output': ['NO\r\n']}, {'input': ['GXPZFSELJJNDAXYRV\r\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\r\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH\r\n'], 'output': ['NO\r\n']}, {'input': ['LFGJCJJDUTUP\r\nOVSBILTIYCJCRHKCIXCETJQJJ\r\nGIJJTJCLTJJJ\r\n'], 'output': ['NO\r\n']}, {'input': ['GIO\r\nPRL\r\nPRL\r\n'], 'output': ['NO\r\n']}, {'input': ['A\r\nB\r\nABC\r\n'], 'output': ['NO\r\n']}, {'input': ['KKK\r\nKKK\r\nZZZZZ\r\n'], 'output': ['NO\r\n']}, {'input': ['ZMYGQLDBLAPN\r\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\r\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA\r\n'], 'output': ['NO\r\n']}]


Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2×2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.

The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1≤r1,r2,c1,c2,d1,d2≤20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.

Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.

Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.


«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?

Input data contains integer numbers k,l,m,n and d, each number in a separate line (1≤k,l,m,n≤10, 1≤d≤10^5).

In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.


What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1≤i≤12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters.

The first line contains exactly one integer k (0≤k≤100). The next line contains twelve space-separated integers: the i-th (1≤i≤12) number in the line represents ai (0≤ai≤100).

Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1.

Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k=0). So, it is possible for Petya not to water the flower at all.

my $k = <>;
my @arr = reverse sort {$a <=> $b} split " ", <>;
my $ans = 0;
for(my $i = 0; $k > 0 && $i < scalar @arr; $i++) {
    $k -= $arr[$i];
    $ans++;
    last if ($k <= 0);
}
$ans = -1 if ($k > 0);
print $ans;


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


Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.As Petya is older, he wants to take the chores with complexity larger than some value x (hi>x) to leave to Vasya the chores with complexity less than or equal to x (hi≤x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a+b=n).In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?

The first input line contains three integers n,a and b (2≤n≤2000; a,b≥1; a+b=n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1,h2,...,hn (1≤hi≤10^9), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.

Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.

In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.


As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!

The first input line contains an integer n (1≤n≤10^9).

Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).

In the first sample number .
In the second sample number 512 can not be represented as a sum of two triangular numbers.

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

my $n = <>;
my $s = int ((sqrt $n) + 1) * 2;
my %tri = ();
my $i = 1;
my $result;
find: while ($i <= $s) {
	my $num = ($i * ($i + 1)) / 2;
	$tri{$num} = 1;
	if ($tri{$n-$num}) {
		$result = "YES";
		last find;
	} else {
		$i++;
	}
}
$result ||= "NO";
print $result;


This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 ≤ p1<p2<...<pk ≤ |s|) a subsequence of string s = s1s2... s|s|, where |s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| > |y| and x1=y1, x2=y2, ...,x|y|=y|y|, or there exists such number r (r<|x|, r<|y|) that x1=y1, x2=y2, ..., xr=yr and xr+1>yr+1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s|-1... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.

Print the lexicographically largest palindromic subsequence of string s.

Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".

#!perl

use strict;
use warnings;

main();

sub main {
    my $str = <>;
    chomp $str;
    my @sym = split //, $str;
    my $nmax = 0;
    my $max = $sym[0];
    foreach my $i (@sym) {
        if ( $i gt $max ) {
            $max = $i;
            $nmax = 1;
        } elsif ( $i eq $max ) {
            $nmax++;
        }
    }
    print $max x $nmax;
}

__END__

[{'input': ['radar\r\n'], 'output': ['rr\r\n']}, {'input': ['bowwowwow\r\n'], 'output': ['wwwww\r\n']}, {'input': ['codeforces\r\n'], 'output': ['s\r\n']}, {'input': ['mississipp\r\n'], 'output': ['ssss\r\n']}, {'input': ['tourist\r\n'], 'output': ['u\r\n']}, {'input': ['romka\r\n'], 'output': ['r\r\n']}, {'input': ['helloworld\r\n'], 'output': ['w\r\n']}, {'input': ['zzzzzzzazz\r\n'], 'output': ['zzzzzzzzz\r\n']}, {'input': ['testcase\r\n'], 'output': ['tt\r\n']}, {'input': ['hahahahaha\r\n'], 'output': ['hhhhh\r\n']}, {'input': ['abbbbbbbbb\r\n'], 'output': ['bbbbbbbbb\r\n']}, {'input': ['zaz\r\n'], 'output': ['zz\r\n']}, {'input': ['aza\r\n'], 'output': ['z\r\n']}, {'input': ['dcbaedcba\r\n'], 'output': ['e\r\n']}, {'input': ['abcdeabcd\r\n'], 'output': ['e\r\n']}, {'input': ['edcbabcde\r\n'], 'output': ['ee\r\n']}, {'input': ['aaaaaaaaab\r\n'], 'output': ['b\r\n']}, {'input': ['testzzzzzz\r\n'], 'output': ['zzzzzz\r\n']}, {'input': ['zzzzzzwait\r\n'], 'output': ['zzzzzz\r\n']}, {'input': ['rrrrrqponm\r\n'], 'output': ['rrrrr\r\n']}, {'input': ['zzyzyy\r\n'], 'output': ['zzz\r\n']}, {'input': ['aababb\r\n'], 'output': ['bbb\r\n']}, {'input': ['zanzibar\r\n'], 'output': ['zz\r\n']}, {'input': ['hhgfedcbaa\r\n'], 'output': ['hh\r\n']}, {'input': ['aabcdefghh\r\n'], 'output': ['hh\r\n']}, {'input': ['aruaru\r\n'], 'output': ['uu\r\n']}, {'input': ['uraura\r\n'], 'output': ['uu\r\n']}, {'input': ['aru\r\n'], 'output': ['u\r\n']}, {'input': ['aburvabur\r\n'], 'output': ['v\r\n']}, {'input': ['ura\r\n'], 'output': ['u\r\n']}, {'input': ['eurottat\r\n'], 'output': ['u\r\n']}, {'input': ['referee\r\n'], 'output': ['rr\r\n']}, {'input': ['joking\r\n'], 'output': ['o\r\n']}, {'input': ['seriously\r\n'], 'output': ['y\r\n']}, {'input': ['sets\r\n'], 'output': ['t\r\n']}, {'input': ['test\r\n'], 'output': ['tt\r\n']}, {'input': ['klmgameklm\r\n'], 'output': ['mmm\r\n']}, {'input': ['dfkjafdkdd\r\n'], 'output': ['kk\r\n']}, {'input': ['zzzzzzzzzz\r\n'], 'output': ['zzzzzzzzzz\r\n']}, {'input': ['aaaaaaaaaa\r\n'], 'output': ['aaaaaaaaaa\r\n']}, {'input': ['buzz\r\n'], 'output': ['zz\r\n']}, {'input': ['b\r\n'], 'output': ['b\r\n']}, {'input': ['y\r\n'], 'output': ['y\r\n']}, {'input': ['yy\r\n'], 'output': ['yy\r\n']}, {'input': ['zz\r\n'], 'output': ['zz\r\n']}, {'input': ['bb\r\n'], 'output': ['bb\r\n']}, {'input': ['aa\r\n'], 'output': ['aa\r\n']}, {'input': ['a\r\n'], 'output': ['a\r\n']}, {'input': ['z\r\n'], 'output': ['z\r\n']}, {'input': ['zz\r\n'], 'output': ['zz\r\n']}, {'input': ['zzazazzzaz\r\n'], 'output': ['zzzzzzz\r\n']}, {'input': ['hellhellhe\r\n'], 'output': ['llll\r\n']}, {'input': ['hellohello\r\n'], 'output': ['oo\r\n']}, {'input': ['refer\r\n'], 'output': ['rr\r\n']}]


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";


The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.

The first line contains a single integer n (1≤n≤10^5) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 10^9.
You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities.

Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).

In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".

#!perl
use strict;
use warnings;

<>;
my $istr = <>;
my @arr = map int, split /\D/, $istr;
my $min = shift @arr;
my $mini = 1;
my $double = 0;
my $index_shift = 2;
for my $i ( 0 .. @arr-1 ) {
    if ( $arr[$i] == $min ) {
        $double = 1;
    } elsif ( $arr[$i] < $min ) {
        $min = $arr[$i];
        $mini = $i + $index_shift;
        $double = 0;
    }
}
if ( $double ) {
    print 'Still Rozdil';
} else {
    print $mini;
}

__END__


You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.

The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (>0) and do not exceed 10^4. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.

Print a single number — the sum of all edges of the parallelepiped.

In the first sample the parallelepiped has sizes 1×1×1, in the second one — 2×2×3.

use strict;
use warnings;
 use Math::Complex;
my ($area1, $area2, $area3) = split(" ", <STDIN>);

my $side3 = sqrt($area1*$area2/$area3);
my $side2 = sqrt($area1*$area3/$area2);
my $side1 = sqrt($area2*$area3/$area1);

my $total = 4*($side1+$side2+$side3);

print $total;


Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.

The first line contains four space-separated integers s1,s2,s3,s4 (1≤s1,s2,s3,s4≤10^9) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.

Print a single integer — the minimum number of horseshoes Valera needs to buy.

%h;
$i = <>;
chomp($i);
@a = split / /, $i;
@h{@a} = ();
print 4 - scalar keys %h;


«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri+1<li+1 for all i from 1 to k-1, and li≤ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li=ri, this element should be output as li, and not as «li-li».For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.

The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.

Output the sequence in the required format.

#!/usr/bin/env perl
package Codeforces::Task::_;
use v5.10;
use strict;
use warnings;

sub min{my($a,$b)=@_;if($a<$b){return$a;}else{return$b;}}
sub max{my($a,$b)=@_;if($a>$b){return$a;}else{return$b;}}

sub out {
    my @x = @_;
    print(shift(@x), " ") while (scalar(@x));
    print("\n");
}

sub solve {
    my @ans = ();
    my $prev = -1;
    foreach my $c (sub {
        my %s = ();
        my $input = <>; chomp $input;
        foreach my $el (split ",", $input) {
            $s{$el} = 1;
        }
        return sort {$a <=> $b} keys %s;
    }->()) {
        if ($prev + 1 == $c) {
            my ($beg) = $ans[$#ans] =~ m/(\d*)(-|$)/;
            $ans[$#ans] = ",$beg-$c";
        } else {
            push(@ans, ",$c");
        }
        $prev = $c;
 	}
    print substr join("", @ans), 1;
}

sub main {
    my $t = 1;
#    $t = int(<>);
    while ($t--) {
        solve();
    }
    return 0;
}

exit(main(@ARGV));


Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1,l2,...,lm (1≤li≤n). For each number li he wants to know how many distinct numbers are staying on the positions li, li+1, ..., n. Formally, he want to find the number of distinct numbers among ali,ali+1,...,an.?Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each li.

The first line contains two integers n and m (1≤n,m≤10^5). The second line contains n integers a1, a2, ..., an (1≤ai≤10^5) — the array elements.
Next m lines contain integers l1,l2,...,lm. The i-th line contains integer li (1≤li≤n).

Print m lines — on the i-th line print the answer to the number li.


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 National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 10^6. Thus, the system logs events of two forms:  "+ ri" — the reader with registration number ri entered the room;  "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

The first line contains a positive integer n (1≤n≤100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 10^6, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).
It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Print a single integer — the minimum possible capacity of the reading room.

In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.


Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:  Include a person to the chat ('Add' command).  Remove a person from the chat ('Remove' command).  Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.

Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
  +<name> for 'Add' command.  -<name> for 'Remove' command.  <sender_name>:<message_text> for 'Send' command. <name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.
It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.
All names are case-sensitive.

Print a single number — answer to the problem.

+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate

+Mike
-Mike
+Mike
Mike:Hi   I am here
-Mike
+Kate
-Kate

#!/usr/bin/perl

my @users;
my $total = 0;
my $len;

while (<>) {
    chomp $_;
    if (/\+/) {
	$_ =~ s/\+//;
	push @users, $_;
    } elsif (/\-/) {
	$_ =~ s/\-//;
	for my $i (0 .. $#users){
	    if ($users[$i] eq $_) {
		splice(@users, $i, 1, ());
	    }
	}
    } else {
	$_ =~ s/([\w]*:)//;
	$total += (scalar @users) * (length $_);
    }
}

print $total

[{'input': ['+Mike\r\nMike:hello\r\n+Kate\r\n+Dmitry\r\n-Dmitry\r\nKate:hi\r\n-Kate\r\n'], 'output': ['9\r\n']}, {'input': ['+Mike\r\n-Mike\r\n+Mike\r\nMike:Hi   I am here\r\n-Mike\r\n+Kate\r\n-Kate\r\n'], 'output': ['14\r\n']}, {'input': ['+Dmitry\r\n+Mike\r\nDmitry:All letters will be used\r\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\r\nDmitry:And digits too\r\nDmitry:1234567890 0987654321\r\n-Dmitry\r\n'], 'output': ['224\r\n']}, {'input': ['+Dmitry\r\n+Mike\r\n+Kate\r\nDmitry:\r\n'], 'output': ['0\r\n']}, {'input': ['+Dmitry\r\nDmitry:No phrases with spaces at the beginning and at the end\r\n+Mike\r\nDmitry:spaces    spaces\r\n-Dmitry\r\n'], 'output': ['86\r\n']}, {'input': ['+XqD\r\n+aT537\r\nXqD:x6ZPjMR1DDKG2\r\nXqD:lLCriywPnB\r\n-XqD\r\n'], 'output': ['46\r\n']}, {'input': ['+8UjgAJ\r\n8UjgAJ:02hR7UBc1tqqfL\r\n-8UjgAJ\r\n+zdi\r\n-zdi\r\n'], 'output': ['14\r\n']}, {'input': ['+6JPKkgXDrA\r\n+j6JHjv70An\r\n+QGtsceK0zJ\r\n6JPKkgXDrA:o4\r\n+CSmwi9zDra\r\nQGtsceK0zJ:Zl\r\nQGtsceK0zJ:0\r\nj6JHjv70An:7\r\nj6JHjv70An:B\r\nQGtsceK0zJ:OO\r\n'], 'output': ['34\r\n']}, {'input': ['+1aLNq9S7uLV\r\n-1aLNq9S7uLV\r\n+O9ykq3xDJv\r\n-O9ykq3xDJv\r\n+54Yq1xJq14F\r\n+0zJ5Vo0RDZ\r\n-54Yq1xJq14F\r\n-0zJ5Vo0RDZ\r\n+lxlH7sdolyL\r\n-lxlH7sdolyL\r\n'], 'output': ['0\r\n']}, {'input': ['+qlHEc2AuYy\r\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\r\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\r\nqlHEc2AuYy:zuCO6Opey L  eu7lTwysaSk00zjpv zrDfbt8l  hpHfu\r\n+pErDMxgVgh\r\nqlHEc2AuYy:I1FLis  mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\r\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\r\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\r\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\r\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb\r\n'], 'output': ['615\r\n']}, {'input': ['+adabacaba0\r\n'], 'output': ['0\r\n']}, {'input': ['+acabadab\r\n+caba0aba\r\n'], 'output': ['0\r\n']}, {'input': ['+dabaca\r\n-dabaca\r\n+aba0ab\r\n'], 'output': ['0\r\n']}, {'input': ['+cab\r\n+abac\r\n-abac\r\n+baca\r\n'], 'output': ['0\r\n']}, {'input': ['+cabadabac\r\n-cabadabac\r\n+abacaba1ab\r\n-abacaba1ab\r\n+ba0abaca\r\n'], 'output': ['0\r\n']}, {'input': ['+adabacaba\r\n-adabacaba\r\n+aca\r\naca:caba\r\n-aca\r\n+bacaba\r\n-bacaba\r\n+aba\r\n-aba\r\n+bad\r\n'], 'output': ['4\r\n']}, {'input': ['+acabadab\r\n-acabadab\r\n+aba0abacab\r\n+baca\r\n+abacaba0ab\r\n-baca\r\n-abacaba0ab\r\n-aba0abacab\r\n+cab\r\n-cab\r\n+abacabada\r\n-abacabada\r\n+badabaca\r\n-badabaca\r\n+badaba\r\n'], 'output': ['0\r\n']}, {'input': ['+badabac\r\nbadabac:abacabad\r\n-badabac\r\n+0ab\r\n-0ab\r\n+dabacab\r\n-dabacab\r\n+a0ab\r\n-a0ab\r\n+0abaca\r\n-0abaca\r\n+dabac\r\n-dabac\r\n+abaca\r\n-abaca\r\n+bacabada\r\n-bacabada\r\n+aca\r\n-aca\r\n+abadabaca\r\n-abadabaca\r\n+acaba\r\n-acaba\r\n+abacabadab\r\n-abacabadab\r\n'], 'output': ['8\r\n']}]


One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of n boxes. The boxes stand in one row, they are numbered from 1 to n from the left to the right. The roommate left hints like "Hidden to the left of the i-th box" ("To the left of i"), "Hidden to the right of the i-th box" ("To the right of i"). Such hints mean that there are no flakes in the i-th box as well. The Cereal Guy wants to know the minimal number of boxes he necessarily needs to check to find the flakes considering all the hints. Or he wants to find out that the hints are contradictory and the roommate lied to him, that is, no box has the flakes.

The first line contains two integers n and m (1≤n≤1000,0≤m≤1000) which represent the number of boxes and the number of hints correspondingly. Next m lines contain hints like "To the left of i" and "To the right of i", where i is integer (1≤i≤n). The hints may coincide.

The answer should contain exactly one integer — the number of boxes that should necessarily be checked or "-1" if the hints are contradictory.

($n, $m) = split (" ", <STDIN>);

$M = "1" x $n;

for (<STDIN>) {
	/To the (left|right) of (\d+)/ or die;
	($direction, $pos) = ($1, $2);
	if ($direction eq "left") {
		$left = 1; $right = 0;
	} else {
		$left = 0; $right = 1;
	}
	$m = ($left x ($pos - 1))."0".($right x ($n - $pos));
	$M = $M & $m;
}

$count = $M =~ y/1//;
$count = -1 if $count == 0;
print $count;

[{'input': ['2 1\r\nTo the left of 2\r\n'], 'output': ['1\r\n']}, {'input': ['3 2\r\nTo the right of 1\r\nTo the right of 2\r\n'], 'output': ['1\r\n']}, {'input': ['3 1\r\nTo the left of 3\r\n'], 'output': ['2\r\n']}, {'input': ['3 2\r\nTo the left of 2\r\nTo the right of 1\r\n'], 'output': ['-1\r\n']}, {'input': ['3 0\r\n'], 'output': ['3\r\n']}, {'input': ['2 2\r\nTo the left of 2\r\nTo the left of 2\r\n'], 'output': ['1\r\n']}, {'input': ['5 0\r\n'], 'output': ['5\r\n']}, {'input': ['6 2\r\nTo the right of 2\r\nTo the left of 4\r\n'], 'output': ['1\r\n']}, {'input': ['8 6\r\nTo the right of 3\r\nTo the left of 4\r\nTo the left of 4\r\nTo the right of 1\r\nTo the right of 5\r\nTo the left of 6\r\n'], 'output': ['-1\r\n']}, {'input': ['459 16\r\nTo the right of 9\r\nTo the right of 148\r\nTo the left of 406\r\nTo the left of 335\r\nTo the right of 240\r\nTo the left of 409\r\nTo the left of 365\r\nTo the left of 426\r\nTo the left of 416\r\nTo the right of 247\r\nTo the left of 284\r\nTo the right of 187\r\nTo the right of 134\r\nTo the right of 128\r\nTo the right of 98\r\nTo the left of 412\r\n'], 'output': ['36\r\n']}, {'input': ['1000 1\r\nTo the right of 117\r\n'], 'output': ['883\r\n']}, {'input': ['1000 0\r\n'], 'output': ['1000\r\n']}, {'input': ['1 0\r\n'], 'output': ['1\r\n']}, {'input': ['2 0\r\n'], 'output': ['2\r\n']}, {'input': ['1 1\r\nTo the right of 1\r\n'], 'output': ['-1\r\n']}, {'input': ['1 1\r\nTo the left of 1\r\n'], 'output': ['-1\r\n']}, {'input': ['2 1\r\nTo the right of 2\r\n'], 'output': ['-1\r\n']}]


In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.

The first line contains two integers n and k (1≤n,k≤100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1≤i≤n, 1≤ai≤k).

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins.


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");
}


Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.

The first line of the input contains a single integer n (1≤n≤92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains n integers ai (0≤ai≤15) — Vitya's records.
It's guaranteed that the input data is consistent.

If Vitya can be sure that the size of visible part of the moon on day n+1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.

In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.


Haiku is a genre of Japanese traditional poetry.A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".Three phases from a certain poem are given. Determine whether it is haiku or not.

The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.

Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).

on  codeforces
beta round is running
   a rustling of keys

how many gallons
of edo s rain did you drink
                                cuckoo

$s.=tr/aeiou// while <>;
print "575" eq $s?"YES":"NO"

[{'input': ['on  codeforces \r\nbeta round is running\r\n   a rustling of keys \r\n'], 'output': ['YES']}, {'input': ['how many gallons\r\nof edo s rain did you drink\r\n                                cuckoo\r\n'], 'output': ['NO']}, {'input': ['   hatsu shigure\r\n     saru   mo komino wo\r\nhoshige    nari\r\n'], 'output': ['YES']}, {'input': ['o vetus stagnum\r\n   rana    de ripa salit\r\n  ac   sonant     aquae\r\n'], 'output': ['NO']}, {'input': [' furuike ya\r\nkawazu tobikomu\r\nmizu no oto \r\n'], 'output': ['YES']}, {'input': ['  noch da leich\r\na   stamperl zum aufwaerma\r\n  da pfarrer   kimmt  a \r\n'], 'output': ['NO']}, {'input': ['  sommerfuglene        \r\n    hvorfor     bruge    mange ord\r\n et kan gore   det\r\n'], 'output': ['YES']}, {'input': ['     ab   der mittagszeit\r\n  ist es   etwas schattiger\r\n   ein  wolkenhimmel\r\n'], 'output': ['NO']}, {'input': ['tornando a vederli\r\ni fiori di ciliegio la sera\r\nson divenuti frutti\r\n'], 'output': ['NO']}, {'input': ['kutaburete\r\nyado karu koro ya\r\nfuji no hana\r\n'], 'output': ['YES']}, {'input': [' beginnings     of   poetry\r\n       the  rice       planting                songs                  \r\n    of    the interior\r\n'], 'output': ['NO']}, {'input': ['    door zomerregens\r\n    zijn de kraanvogelpoten\r\n    korter geworden\r\n'], 'output': ['NO']}, {'input': [' derevo na   srub\r\na     ptitsi    bezzabotno\r\n   gnezdishko tam vyut\r\n'], 'output': ['YES']}, {'input': ['writing in the dark\r\nunaware    that my pen\r\nhas   run out of ink\r\n'], 'output': ['NO']}, {'input': ['kusaaiu\r\nuieueua\r\nuo efaa\r\n'], 'output': ['YES']}, {'input': ['v\r\nh\r\np\r\n'], 'output': ['NO']}, {'input': ['i\r\ni\r\nu\r\n'], 'output': ['NO']}, {'input': ['awmio eoj\r\nabdoolceegood\r\nwaadeuoy\r\n'], 'output': ['YES']}, {'input': ['xzpnhhnqsjpxdboqojixmofawhdjcfbscq\r\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\r\nimtqryscsahrxpic agfjh  wvpmczjjdrnwj mcggxcdo\r\n'], 'output': ['YES']}, {'input': ['wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\r\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\r\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr\r\n'], 'output': ['YES']}, {'input': ['nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\r\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\r\nvcczq hddzd cvefmhxwxxyqcwkr  fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd\r\n'], 'output': ['YES']}, {'input': ['rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn  yciktbsbyscfypx x xhkxnfpdp\r\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\r\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch \r\n'], 'output': ['YES']}, {'input': ['brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\r\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\r\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs\r\n'], 'output': ['YES']}, {'input': ['nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\r\nnnebeaoiraga\r\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn\r\n'], 'output': ['NO']}, {'input': ['lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\r\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\r\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl\r\n'], 'output': ['NO']}, {'input': ['yxcboqmpwoevrdhvpxfzqmammak\r\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt  dtzcvnvwp\r\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr\r\n'], 'output': ['NO']}, {'input': ['qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\r\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\r\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf\r\n'], 'output': ['NO']}, {'input': ['g rguhqhcrzmuqthtmwzhfyhpmqzzosa\r\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\r\npcwbliftjcvuzrsqiswohi\r\n'], 'output': ['NO']}, {'input': [' ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\r\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\r\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu\r\n'], 'output': ['NO']}, {'input': ['ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\r\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\r\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt\r\n'], 'output': ['NO']}, {'input': ['ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\r\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\r\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo\r\n'], 'output': ['NO']}, {'input': ['mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\r\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\r\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau\r\n'], 'output': ['NO']}, {'input': ['ab\r\na\r\na\r\n'], 'output': ['NO']}, {'input': ['on  codeforcs\r\nbeta round is runnineg\r\na rustling of keys\r\n'], 'output': ['NO']}, {'input': ['coooooooooooooooood\r\nd\r\nd\r\n'], 'output': ['NO']}, {'input': ['on  codeforces \r\nbeta round is runninog\r\n   a rustling of keys\r\n'], 'output': ['NO']}, {'input': ['aaaaaaaaaaaaaaa\r\na\r\na\r\n'], 'output': ['NO']}, {'input': ['aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\n'], 'output': ['YES']}, {'input': ['cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\n'], 'output': ['NO']}, {'input': ['aaaaaa\r\naaaaaa\r\naaaaa\r\n'], 'output': ['NO']}]


In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part.  If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part. If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?

The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.

If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).


You are given an undirected graph consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is $$$a_i$$$. Initially there are no edges in the graph.You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $$$x$$$ and $$$y$$$ is $$$a_x + a_y$$$ coins. There are also $$$m$$$ special offers, each of them is denoted by three numbers $$$x$$$, $$$y$$$ and $$$w$$$, and means that you can add an edge connecting vertices $$$x$$$ and $$$y$$$ and pay $$$w$$$ coins for it. You don't have to use special offers: if there is a pair of vertices $$$x$$$ and $$$y$$$ that has a special offer associated with it, you still may connect these two vertices paying $$$a_x + a_y$$$ coins for it.What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$, $$$0 \\le m \\le 2 \\cdot 10^5$$$) — the number of vertices in the graph and the number of special offers, respectively.
The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^{12}$$$) — the numbers written on the vertices.
Then $$$m$$$ lines follow, each containing three integers $$$x$$$, $$$y$$$ and $$$w$$$ ($$$1 \\le x, y \\le n$$$, $$$1 \\le w \\le 10^{12}$$$, $$$x \\ne y$$$) denoting a special offer: you may add an edge connecting vertex $$$x$$$ and vertex $$$y$$$, and this edge will cost $$$w$$$ coins.

Print one integer — the minimum number of coins you have to pay to make the graph connected.

#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min);

sub find {
    my ($x, $parent) = @_;
    if ($parent->[$x] != $x) {
        $parent->[$x] = find($parent->[$x], $parent);
    }
    return $parent->[$x];
}

sub union {
    my ($x, $y, $parent, $rank) = @_;
    my $px = find($x, $parent);
    my $py = find($y, $parent);
    if ($px != $py) {
        if ($rank->[$px] > $rank->[$py]) {
            $parent->[$py] = $px;
        } else {
            $parent->[$px] = $py;
            if ($rank->[$px] == $rank->[$py]) {
                $rank->[$py]++;
            }
        }
    }
}

my ($n, $m) = split / /, <>;
my @a = split / /, <>;
my @parent = (0..$n);
my @rank = (0) x ($n+1);
my @edges;
my $min_a = min @a;
my $min_i = 0;
for my $i (0..$#a) {
    if ($a[$i] == $min_a) {
        $min_i = $i;
        last;
    }
}
for my $i (0..$#a) {
    if ($i != $min_i) {
        push @edges, [$min_i+1, $i+1, $min_a + $a[$i]];
    }
}
for my $i (0..$m-1) {
    my ($x, $y, $w) = split / /, <>;
    push @edges, [$x, $y, $w];
}
@edges = sort {$a->[2] <=> $b->[2]} @edges;
my $res = 0;
for my $edge (@edges) {
    my ($x, $y, $w) = @$edge;
    if (find($x, \@parent) != find($y, \@parent)) {
        union($x, $y, \@parent, \@rank);
        $res += $w;
    }
}
print "$res\n";


This problem is same as the next one, but has smaller constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $$$(x_i, y_i)$$$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

The first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 50$$$) — the number of electric poles.
Each of the following $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^4 \\le x_i, y_i \\le 10^4$$$) — the coordinates of the poles.
It is guaranteed that all of these $$$n$$$ points are distinct.

Print a single integer — the number of pairs of wires that are intersecting.

#!/usr/bin/perl

use strict;
use warnings;

sub gcd {
    my ($a, $b) = @_;
    return $b == 0 ? $a : gcd($b, $a % $b);
}

my $n = <>;
chomp $n;
my @points;
my %lines;

for (1..$n) {
    my $line = <>;
    chomp $line;
    my ($x, $y) = split / /, $line;
    push @points, [$x, $y];
}

for my $i (0..$#points) {
    for my $j ($i+1..$#points) {
        my $dx = $points[$i][0] - $points[$j][0];
        my $dy = $points[$i][1] - $points[$j][1];
        my $g = gcd($dx, $dy);
        $dx /= $g; $dy /= $g;
        if ($dx < 0 || $dx == 0 && $dy < 0) {
            $dx = -$dx;
            $dy = -$dy;
        }
        my $c = $dx * $points[$i][1] - $dy * $points[$i][0];
        $lines{"$dx $dy"}{$c}++;
    }
}

my $total = 0;
my $pairs = 0;

for my $slope (keys %lines) {
    my $lines_on_slope = scalar keys %{$lines{$slope}};
    $total += $lines_on_slope;
    $pairs += $lines_on_slope * ($lines_on_slope - 1) / 2;
}

print $total * ($total - 1) / 2 - $pairs;


Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.

The input data consists of only one integer x (-10^9≤x≤10^9).

Output the minimal number of jumps that Jack requires to reach x.

#!/usr/bin/perl
use strict;
use warnings;

sub min_jumps {
    my ($x) = @_;
    $x = abs($x);
    my $jumps = 0;
    my $distance = 0;
    while ($distance < $x or ($distance - $x) % 2 != 0) {
        $jumps++;
        $distance += $jumps;
    }
    return $jumps;
}

my $input = <STDIN>;
chomp($input);
print min_jumps($input), "\n";


One day in the IT lesson Anna and Maria learned about the lexicographic order.String x is lexicographically less than string y, if either x is a prefix of y (and x≠y), or there exists such i (1≤i≤min(|x|,|y|)), that xi<yi, and for any j (1≤j<i) xj=yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages.The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework.

The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 10^5. The second line contains the only integer k (1≤k≤10^5).

Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).

In the second sample before string "bc" follow strings "a", "ab", "abc", "b".

#!/usr/bin/perl

use strict;
use warnings;

my $inp = <>;
chomp($inp);
my $k = <>;
chomp($k);

my @substrings;

for(my $len = 1; $len <= length($inp); $len++) {
    for(my $start = 0; $start <= length($inp)-$len; $start++) {
        push @substrings, substr($inp, $start, $len);
    }
}

@substrings = sort @substrings;

if($k > @substrings) {
    print "No such line.\n";
} else {
    print "$substrings[$k-1]\n";
}


N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can jump out of the window. He knows values of all ladies and wants to find out how many probable self-murderers will be on the ball. Lets denote beauty of the i-th lady by Bi, her intellect by Ii and her richness by Ri. Then i-th lady is a probable self-murderer if there is some j-th lady that Bi<Bj,Ii<Ij,Ri<Rj. Find the number of probable self-murderers.

The first line contains one integer N (1≤N≤500000). The second line contains N integer numbers Bi, separated by single spaces. The third and the fourth lines contain sequences Ii and Ri in the same format. It is guaranteed that 0≤Bi,Ii,Ri≤10^9.

use strict;
use warnings;

sub probable_self_murderers {
    my ($N, $beauty, $intellect, $richness) = @_;

    my $count = 0;

    for my $i (0..$N-1) {
        my $probable = 0;

        for my $j (0..$N-1) {
            next if $i == $j;

            if ($beauty->[$i] < $beauty->[$j] && $intellect->[$i] < $intellect->[$j] && $richness->[$i] < $richness->[$j]) {
                $probable = 1;
                last;
            }
        }

        $count++ if $probable;
    }

    return $count;
}

# Read input
my $N = <STDIN>;
chomp($N);

my @beauty = split(' ', <STDIN>);
chomp(@beauty);

my @intellect = split(' ', <STDIN>);
chomp(@intellect);

my @richness = split(' ', <STDIN>);
chomp(@richness);

# Call the function and print the result
my $result = probable_self_murderers($N, \@beauty, \@intellect, \@richness);
print "$result\n";