There are $$$n$$$ students in a school class, the rating of the $$$i$$$-th student on Codehorses is $$$a_i$$$. You have to form a team consisting of $$$k$$$ students ($$$1 \le k \le n$$$) such that the ratings of all team members are distinct.If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $$$k$$$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the number of students and the size of the team you have to form. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the rating of $$$i$$$-th student.

If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $$$1$$$ to $$$n$$$.

NoteAll possible answers for the first example:   {1 2 5}  {2 3 5}  {2 4 5} Note that the order does not matter.

import std.stdio ;

void main() {
	int n,k,x,r,i = 1;
	bool[105] arr ;

	readf("%s %s",&n,&k);
	int[105] arr2 ;

	while(i <= n) {
		readf(" %s",&x);
		if(arr[x] == false && r <k) {
			arr[x] = true ;
			arr2[r] = i ;
			r += 1 ;
		}
		i += 1 ;
	}
	i = 0 ;
	if(r < k) {
		writeln("NO");
	}
	else {
		writeln("YES");
		while(i < k) {
			write(arr2[i]," ");
			i += 1 ;
		}
	}
}

import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
    int n, k;
    readf("%s %s", &n, &k);
    readln;

    auto a = readln.chomp.split.map!(to!int).array;

    int [int] v;
    foreach (i, e; a.enumerate(1)) v[e] = i;

    auto gr = v.values.take(k);
    if (gr.length < k) {
        writeln("NO");
        return;
    }

    writeln("YES");
    gr.writefln!("%(%s %)");
}

void main(){
  import std.stdio, std.algorithm, std.string, std.conv;

  int n, k; rd(n, k);
  auto as=readln.split.to!(int[]);

  int cur=0;
  bool[int] set;
  int[] idx;
  foreach(int i, a; as){
    if(a in set) continue;
    set[a]=true;
    idx~=(i+1);
    if(set.length==k){
      writeln("YES");
      writefln("%(%s %)", idx);
      return;
    }
  }

  writeln("NO");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

import std.stdio ;

void main() {
	int n,k,x,r,i = 1;
	bool[100] arr ;

	readf("%s %s",&n,&k);
	int[100] arr2 ;

	while(i <= n) {
		readf(" %s",&x);
		if(arr[x] == false && r <k) {
			arr[x] = true ;
			arr2[r] = i ;
			r += 1 ;
		}
		i += 1 ;
	}
	i = 0 ;
	if(r < k) {
		writeln("NO");
	}
	else {
		writeln("YES");
		while(i < k) {
			write(arr2[i]," ");
			i += 1 ;
		}
	}
}


One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.

The single input line contains space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.

Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.

NoteIn the first sample the author has to get a 2 for all his exams.In the second sample he should get a 3 for two exams and a 2 for two more.In the third sample he should get a 3 for one exam.

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                int n = cin.readInt;
                int k = cin.readInt;
                writeln(k > 3 * n ? 0 : 3 * n - k);
        }
}


Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.After how many full years will Limak become strictly larger (strictly heavier) than Bob?

The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.

Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.

NoteIn the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.

import std.stdio;

void main() {
    int a, b;
    readf("%d %d\n", &a, &b);
    int year = 0;
    while (a <= b) {
        year++;
        a *= 3;
        b *= 2;
    }
    writefln("%d", year);
}

import std.stdio;

void main() {
	int a, b;
	readf("%d %d", &a, &b);
	int result = 0;
	while(a <= b) {
		a *= 3;
		b *= 2;
		result++;
	}
	writeln(result);
}

import std.stdio;
import std.string;
import std.conv;
import std.regex;
import std.algorithm.iteration;
import std.array;

void main()
{
  auto ab = stdin.readln.strip.split(regex(` +`)).map!(to!int);
  int a = ab[0], b = ab[1], y = 0;
  for (;a<=b; a*=3, b*=2, y++) {}
  write(y);
}

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

void main() {
    int a, b;
    scan(a, b);

    int cnt;

    while (a <= b) {
        a *= 3;
        b *= 2;
        cnt++;
    }

    writeln(cnt);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const A = readInt();
      const B = readInt();

      int ans;
      int a = A, b = B;
      for (; !(a > b); ) {
        ++ans;
        a *= 3;
        b *= 2;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

import std.stdio;

int main()
{
	int a=0;
	int b=0;
	readf(" %d", &a);
	readf(" %d", &b);
	int i=0;
	while(a<=b)
	{
		a=a*3;
		b=b*2;
		i=i+1;
	}
	writeln(i);
	return 0;
}

import std.stdio, std.string, std.conv;
void main()
{
  byte[] arr = readln.chomp.split(' ').to!(byte[]);
  byte ret = 0;
  while(3^^ret * arr[0] <= 2^^ret * arr[1]) ret ++;
  writeln(ret);
}


An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the 2-nd one, the 2-nd one — to the 1-st and the 3-rd ones, the 3-rd one — only to the 2-nd one. The transitions are possible only between the adjacent sections.The spacecraft team consists of n aliens. Each of them is given a rank — an integer from 1 to n. The ranks of all astronauts are distinct. The rules established on the Saucer, state that an alien may move from section a to section b only if it is senior in rank to all aliens who are in the segments a and b (besides, the segments a and b are of course required to be adjacent). Any alien requires exactly 1 minute to make a move. Besides, safety regulations require that no more than one alien moved at the same minute along the ship.Alien A is senior in rank to alien B, if the number indicating rank A, is more than the corresponding number for B.At the moment the whole saucer team is in the 3-rd segment. They all need to move to the 1-st segment. One member of the crew, the alien with the identification number CFR-140, decided to calculate the minimum time (in minutes) they will need to perform this task.Help CFR-140, figure out the minimum time (in minutes) that all the astronauts will need to move from the 3-rd segment to the 1-st one. Since this number can be rather large, count it modulo m.

The first line contains two space-separated integers: n and m (1 ≤ n, m ≤ 109) — the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly.

Print a single number — the answer to the problem modulo m.

NoteIn the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes.To briefly describe the movements in the second sample we will use value , which would correspond to an alien with rank i moving from the segment in which it is at the moment, to the segment number j. Using these values, we will describe the movements between the segments in the second sample: , , , , , , , , , , , , , , , , , , , , , , , , , ; In total: the aliens need 26 moves. The remainder after dividing 26 by 8 equals 2, so the answer to this test is 2.

import std.stdio : readln, writeln;
import std.math : pow;
import std.conv : to;
import std.string : split;

/*
  拡張されたハノイの塔(3^n-1)
  と、べき乗余
 */
int _hanoi(long n, long m)
{
    long res = 1;
    long r = 3;

    while(0<n){
        if((n&1)==1) res = (res*r)%m;
        n >>= 1;
        r = (r*r)%m;
    }

    return (0<res ? res.to!int : m.to!int)-1;
}

void main()
{
    io();
}

void io()
{
    string[] str = readln().split();
    int n = str[0].to!int();
    int m = str[1].to!int();

    writeln = _hanoi(n, m)%m;
}

import std.stdio : readln, writeln;
import std.math : pow;
import std.conv : to;
import std.string : split;

int _hanoi(int n)
{
    return pow(3, n)-1;
}

void main()
{
    io();
}

void io()
{
    string[] str = readln().split();
    int n = str[0].to!int();
    int m = str[1].to!int();

    writeln = _hanoi(n)%m;
}

import std.stdio : readln, writeln;
import std.math : pow;
import std.conv : to;
import std.string : split;

/*
  拡張されたハノイの塔(3^n-1)
  と、べき乗余
 */
int _hanoi(long n, long m)
{
    long res = 1;
    long r = 3;

    while(0<n){
        if((n&1)==1) res = (res*r)%m;
        n >>= 1;
        r = (r*r)%m;
    }

    return res.to!int -1;
}

void main()
{
    io();
}

void io()
{
    string[] str = readln().split();
    int n = str[0].to!int();
    int m = str[1].to!int();

    writeln = _hanoi(n, m)%m;
}


A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that:  there are exactly n pixels on the display;  the number of rows does not exceed the number of columns, it means a ≤ b;  the difference b - a is as small as possible.

The first line contains the positive integer n (1 ≤ n ≤ 106) — the number of pixels display should have.

Print two integers — the number of rows and columns on the display.

NoteIn the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,
std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio:freopen;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow @property X binpow(X,Y)(X base,Y exp)
if(is(typeof(exp&1)))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(is(typeof(exp&1)))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
@property void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p)
	{
		fi=p.fi;
		se=p.se;
	}
	int opCmp(in pair!(X,Y) s_) const pure nothrow @safe
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}
X cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		int md=n,a,b;
		for(int i=1;i*i<=n;i++)
		{
			if(n%i==0 && n/i-i<md)
			{
				md=n/i-i;
				a=i;
				b=n/i;
			}
		}
		writeln(a,' ',b);
	}
	debug readln;
}


A frog is initially at position $$$0$$$ on the number line. The frog has two positive integers $$$a$$$ and $$$b$$$. From a position $$$k$$$, it can either jump to position $$$k+a$$$ or $$$k-b$$$.Let $$$f(x)$$$ be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval $$$[0, x]$$$. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from $$$0$$$.Given an integer $$$m$$$, find $$$\sum_{i=0}^{m} f(i)$$$. That is, find the sum of all $$$f(i)$$$ for $$$i$$$ from $$$0$$$ to $$$m$$$.

The first line contains three integers $$$m, a, b$$$ ($$$1 \leq m \leq 10^9, 1 \leq a,b \leq 10^5$$$).

Print a single integer, the desired sum.

NoteIn the first example, we must find $$$f(0)+f(1)+\ldots+f(7)$$$. We have $$$f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8$$$. The sum of these values is $$$19$$$.In the second example, we have $$$f(i) = i+1$$$, so we want to find $$$\sum_{i=0}^{10^9} i+1$$$.In the third example, the frog can't make any jumps in any case.

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, 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)); }

long M;
int A, B;

void main() {
  try {
    for (; ; ) {
      M = readLong();
      A = readInt();
      B = readInt();

      const V = 2 * (A + B) + 10;
      alias Node = Tuple!(int, "c", int, "u");
      BinaryHeap!(Array!Node, "a > b") que;
      auto dist = new int[V];
      dist[] = V;
      dist[0] = 0;
      que.insert(Node(0, 0));
      for (; !que.empty; ) {
        const c = que.front.c;
        const u = que.front.u;
        que.removeFront;
        if (dist[u] == c) {
          foreach (v; [u + A, u - B]) {
            if (0 <= v && v < V) {
              const cc = max(c, v);
              if (dist[v] > cc) {
                dist[v] = cc;
                que.insert(Node(cc, v));
              }
            }
          }
        }
      }
      auto f = new int[V];
      foreach (u; 0 .. V) {
        if (dist[u] < V) {
          ++f[dist[u]];
        }
      }
      foreach (u; 1 .. V) {
        f[u] += f[u - 1];
      }
      debug {
        if (V <= 100) {
          writeln("dist = ", dist);
          writeln("f = ", f);
        }
      }

      const long g = gcd(A, B);
      const long q = (M + 1) / g, r = (M + 1) % g;
      long ans;
      ans += g * q * (q + 1) / 2;
      ans += (q + 1) * r;
      foreach (u; 0 .. V) {
        if (u <= M) {
          ans -= (u / g + 1);
          ans += f[u];
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.

A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.

In a single line print the number of times Manao has to push a button in the worst-case scenario.

NoteConsider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int sum = 0;
	foreach (int i; 1..n)
	{
		sum += i * (n-i);
	}
	write(sum + n);
	return 0;
}

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

void main() {
    int n = readln.chomp.to!int;

    int ans = 0;
    for (int i = 1; i <= n - 1; i++) {
        ans += i * (n - i);
    }

    writeln(ans + n);
}

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

void main() {
    long n;
    scan(n);
    long ans = n * (n*n + 5) / 6;
    writeln(ans);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

import std.array : split;
import std.conv : to;
import std.stdio;
import std.string : strip;

private {
	string[] temp;
}

void main() {
	read();

	int n = get!int(0);

	int count = 0;

	foreach (i; 1 .. n + 1) {
		count += (n - (i - 1)) * i - i + 1;
	}

	stdout.write(count);
}

void read() {
	temp = split(strip(stdin.readln()));
}

T get(T)(int p) {
	return to!(T)(temp[p]);
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int sum = 0;
	foreach (int i; 0..n)
	{
		sum += (sum + 1);
	}
	write(sum);
	return 0;
}

import std.array : split;
import std.conv : to;
import std.stdio;
import std.string : strip;

private {
	string[] temp;
}

void main() {
	read();

	int n = get!int(0);

	int count = n;

	foreach (i; 1 .. n) {
		count += 2 * (n - i) - 1;
	}

	stdout.write(count);
}

void read() {
	temp = split(strip(stdin.readln()));
}

T get(T)(int p) {
	return to!(T)(temp[p]);
}


Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:  on this day the gym is closed and the contest is not carried out;  on this day the gym is closed and the contest is carried out;  on this day the gym is open and the contest is not carried out;  on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:    ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;  ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;  ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;  ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:   to do sport on any two consecutive days,  to write the contest on any two consecutive days.

NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;
import std.variant;

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

int n;
int[100] _a;
int[ ] a;

int[3][100] dp;

int dyn(int day, int prevMask) {
    if (day == n)
        return 0;
    if (~dp[day][prevMask])
        return dp[day][prevMask];
    int result = dyn(day + 1, 0x0) + 1;
    foreach (mask; 0x1 .. 0x3)
        if ((a[day] & mask) && !(prevMask & mask))
            result = min(result, dyn(day + 1, mask));
    return (dp[day][prevMask] = result);
}

void main() {
    while (read(&n)) {
        a = _a[0 .. n];
        foreach (ref x; a)
            read(&x);
        memset(dp.ptr, 0xFF, dp.sizeof);
        writeln(dyn(0, 0x0));
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
void main() {
    int d0 = 0, d1 = 0, d2 = 0;
    int n;
    readf("%d", &n);
    foreach (i; 0 .. n) {
    	//write(i);
        int c;
        readf(" %d", &c);
        int n0 = max(d0, max(d1, d2));
        int n1 = -1;
        int n2 = -1;
        if (c & 1) {
            n1 = max(n1, max(d0, d2) + 1);
        }
        if (c & 2) {
            n2 = max(n2, max(d0, d1) + 1);
        }
        d0 = n0, d1 = n1, d2 = n2;
        //writef("%d, %d, %d\n", d0, d1, d2);
    }
    write(n - max(d0, max(d1, d2)));
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		auto f = new int [3] [n + 1];
		foreach (i; 0..n)
		{
			auto prev = f[i].reduce !(max);
			f[i + 1][] = prev;
			foreach (j; [1, 2])
			{
				if (a[i] & j)
				{
					f[i + 1][j] = max (f[i + 1][j],
					    max (f[i][0], f[i][j ^ 3]) + 1);
				}
			}
		}
		auto res = f[n].reduce !(max);
		writeln (n - res);
	}
}

import std.stdio;
import std.algorithm;
void main() {
    int d0 = 0, d1 = 0, d2 = 0;
    int n;
    readf("%d", &n);
    foreach (i; 1 .. n) {
        int c;
        readf(" %d", &c);
        int n0 = max(d0, max(d1, d2));
        int n1 = d1;
        int n2 = d2;
        if (c & 1) {
            n1 = max(n1, max(d0, d2) + 1);
        }
        if (c & 2) {
            n2 = max(n2, max(d0, d1) + 1);
        }
        d0 = n0, d1 = n1, d2 = n2;
    }
    write(n - max(d0, max(d1, d2)));
}


Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity. What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.

The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 50) — number ai stands for the number of sockets on the i-th supply-line filter.

Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.

NoteIn the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.

import std.algorithm;
import std.stdio;

int main ()
{
	int k, m, n;
	main_loop:
	while ((readf (" %d %d %d", &n, &m, &k) >= 0) && !stdin.eof ())
	{
		auto a = new int [n];
	        foreach (i; 0..n)
	        {
	        	readf (" %d", &a[i]);
	        }
	        sort (a);
	        reverse (a);
	        auto s = k;
	        foreach (i; 0..n)
	        {
	        	if (s >= m)
	        	{
	        		writef ("%d\n", i);
	        		continue main_loop;
	        	}
	        	s += a[i] - 1;
	        }
		writef ("%d\n", (s >= m) ? n : -1);
	}
	return 0;
}


There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.

The input contains two lines. The first line contains the string s (1 ≤ |s| ≤ 50). The second line contains the string t (1 ≤ |t| ≤ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.

Print the final 1-based position of Liss in a single line.

module main;

import std.stdio : readln, writeln, write, writefln, writef;
import std.conv : to;
import std.array : split, replace;
import std.string : strip;
import std.algorithm : max, min, map, reduce, sort, reverse;
import std.functional : memoize;

version = A;

version (A)
{
    void main()
    {
        auto sequence = read_one!string();
        auto instructions = read_one!string();
        size_t position = 0;
        foreach (instruction; instructions)
        {
            if (sequence[position] == instruction)
            {
                position += 1;
            }
        }
        writeln(position + 1);
    }
}
version (B)
{
    void main()
    {
        auto n = read_one!int();
    }
}
version (C)
{
    void main()
    {
        auto n = read_one!int();
    }
}
version (D)
{
    void main()
    {
        auto n = read_one!int();
    }
}
version (E)
{
    void main()
    {
    }
}

T read_one(T)()
{
    return readln().strip().to!T();
}

T[] read_some(T)()
{
    T[] ret;
    foreach (e; readln().strip().split())
    {
        ret ~= e.to!T();
    }
    return ret;
}

T[m] read_fixed(int m, T)()
{
    T[m] ret;
    foreach (i, e; readln().strip().split())
    {
        ret[i] = e.to!T();
    }
    return ret;
}

import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

void main() {
    string s = readln.chomp;
    string t = readln.chomp;

    int cur = 0;
    foreach (c ; t) {
        if (c == s[cur]) cur++;
    }

    writeln(cur + 1);

    string _ = readln;
}

import std.stdio;

void main() {
	string land = stdin.readln();

	size_t position = 1;

	foreach (char command; stdin.readln()) {
		if (command == land[position - 1]) {
			++position;
		}
	}

	stdout.write(position);
}


Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't. Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar. The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

NoteIn the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.In the second sample you can break the bar in four ways:10|10|11|010|110|1|011|01|01

import std.stdio;
import std.conv;
import std.string;

void main()
{
	 auto s1 = split(strip(readln));
	 long[] b;
	 auto s2 = split(strip(readln));
	 foreach(idx, num; s2)
	 {
	 	if (num == "1")
	 		b ~= idx;
	 }
	 long prod = 1; long dif;
	 if (b.length == 0)
	 {
	 	write(0);
	 	return;
	 }
	 else if (b.length == 1)
	 {
	 	write(1);
	 	return;
	 }
	 foreach(idx, num; b[1 .. $])
	 {
	 	dif = num - b[idx];
		prod *= dif;
	 }
	 writeln(prod);
}

import std.stdio;

void main() {
	long n;
	readf!"%s\n"(n);

	long product=0;
	long count=1;
	for (int i=0; i<n; i++){
		int piece;
		readf!"%s "(piece);

		/* writeln(piece); */

		if (piece == 0){
			count++;
		} else if (piece == 1 && product == 0) {
			product = 1;
			count=1;
		} else if (piece == 1) {
			product = product * count;
			count=1;
		}
	}

	writeln(product);
}

import std.stdio;

void main() {
	int n;
	readf!"%s\n"(n);

	int product=1;
	int count=1;
	for (int i=0; i<n; i++){
		int piece;
		readf!"%s "(piece);

		/* writeln(piece); */

		if (piece == 0){
			count++;
		} else if (piece == 1) {
			product = product * count;
			count=1;
		}
	}

	writeln(product);
}

import std.stdio;

void main() {
	int n;
	readf!"%s\n"(n);

	int product=0;
	int count=1;
	for (int i=0; i<n; i++){
		int piece;
		readf!"%s "(piece);

		/* writeln(piece); */

		if (piece == 0){
			count++;
		} else if (piece == 1 && product == 0) {
			product = 1;
			count=1;
		} else if (piece == 1) {
			product = product * count;
			count=1;
		}
	}

	writeln(product);
}


Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword.    The example of encrypting of a single row of japanese crossword. Help Adaltik find the numbers encrypting the row he drew.

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).

The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.

NoteThe last sample case correspond to the picture in the statement.

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                string s = cin.read_string;
                int[] groups;
                for (int i = 0; i < s.length; i++) {
                        if (s[i] == 'B') {
                                int j = i;
                                int count = 0;
                                while (j < s.length && s[j] == 'B') {
                                        count++;
                                        j++;
                                }
                                i = j - 1;
                                groups ~= count;
                        }
                }
                writeln(groups.length);
                foreach(i; groups) {
                        write(i, " ");
                }
        }
}


Let's consider equation:x2 + s(x)·x - n = 0,  where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots.

A single line contains integer n (1 ≤ n ≤ 1018) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds.

NoteIn the first test case x = 1 is the minimum root. As s(1) = 1 and 12 + 1·1 - 2 = 0.In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 102 + 1·10 - 110 = 0.In the third test case the equation has no roots.

import std.stdio, std.math;

int s(long n) {
	int t = 0;
	while (n > 0) {
		t += n % 10;
		n /= 10;
	}
	return t;
}

int m(long n) {
	int t = 0;
	while (n > 0) { t++; n /= 10; }
	return t * 9;
}

/*
x^2 + tx > n
x^2 + tx + t^2/4 > n + t^2/4
x + t/2 > sqrt(4n^2+t^2)/2
x > sqrt(4n^2+t^2)/2-t/2
*/

long solve(long n) {
	long r = cast(long) sqrt(n * 1.0);
	long t = m(r);
	long l = cast(long) (sqrt(4.0 * n + 1.0 * t * t) / 2 - t / 2);
	if (l == 0) l++;
	while (l <= r) {
		if (n % l == 0) {
			if (l * (l + s(l)) == n) return l;
		}
		l++;
	}
	return -1;
}

void main() {
	long n;
	readf("%d", &n);
	writeln(solve(n));
}


An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.

The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.

Print the minimum number of steps that elephant needs to make to get from point 0 to point x.

NoteIn the first sample the elephant needs to make one step of length 5 to reach the point x.In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.

import std.stdio;
import std.uni;
import std.string;
import core.stdc.stdio;
import std.array;
import std.algorithm;
import std.string;
import std.math;

int main(string[] argv)
{
	int x;
	scanf("%d", &x);
	int r = 0;
	int s = 5;
	while (x > 0)
	{
		r += x / s;
		x = x % s;
		s--;
	}
	printf("%d", r);
	return 0;
}

import std.stdio;
import std.conv;
import std.string;

void main()
{
	 auto s1 = split(strip(readln));
	 long n = to!long(s1[0], 10);
	 if (n % 5 == 0)
	    writeln(n / 5 );
	 else
	    writeln(n / 5 + 1);
}

import std.stdio;

int main( ) {
    int n ;
	readf("%d",n);
	int[] ar = [5, 4 ,3 ,2 ,1];
	int c = 0;
	for (int i = 0 ; i < 5 ; i++ ) {
		int _c = n / ar[i];
		n -=  ar[i] * _c;
		c += _c;
		if (n == 0)
			break;
	}
	write(c , '\n');

	return 0;
}

import std.stdio: writeln, readf;

void main() {
    int coordinate = 0;
    int steps = 0;
    int moves = 5;

    readf(" %s", coordinate);

    for(int i = moves; i > 0; i--) {
    	if(coordinate >= i) {
    	steps += coordinate/i;
    	coordinate = coordinate % i;
    	}
    }

    writeln(steps);
}

import std.stdio, std.string, std.conv;

void main() {
    int x = readln.chomp.to!int;
    writeln((x + 4)/ 5);
}

import std.stdio;

int main()
{
	int a=0;
	readf(" %d", &a);
	if (a%5==0)
	{
		writeln(a/5);
	}
	else
	{
		writeln((a/5)+1);
	}
	return 0;
}

import std.stdio;
import std.conv;
import std.string;

void main()
{
	 auto s1 = split(strip(readln));
	 long n = to!long(s1[0], 10);
	 writeln(n / 5 + 1);
}


Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $$$360$$$ degrees and a pointer which initially points at zero:  Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $$$n$$$ times. The $$$i$$$-th rotation should be $$$a_i$$$ degrees, either clockwise or counterclockwise, and after all $$$n$$$ rotations the pointer should again point at zero.This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $$$n$$$ rotations the pointer will point at zero again.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 15$$$) — the number of rotations. Each of the following $$$n$$$ lines contains one integer $$$a_i$$$ ($$$1 \leq a_i \leq 180$$$) — the angle of the $$$i$$$-th rotation in degrees.

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower).

NoteIn the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $$$360$$$ degrees clockwise and the pointer will point at zero again.

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n];
		foreach (ref x; a)
		{
			readf (" %s", &x);
		}

		bool ok = false;
		foreach (s; 0..1 << n)
		{
			int cur = 0;
			foreach (i; 0..n)
			{
				if (s & (1 << i))
				{
					cur += a[i];
				}
				else
				{
					cur -= a[i];
				}
			}
			if (cur % 360 == 0)
			{
				ok = true;
			}
		}
		writeln (ok ? "YES" : "NO");
	}
}

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

void main() {
    int n;
    scan(n);
    auto a = iota(n).map!(i => readln.chomp.to!int).array;

    foreach (s ; 0 .. 1<<n) {
        int deg;

        foreach (i ; 0 .. n) {
            if (s & (1 << i)) {
                deg += a[i];
                deg %= 360;
            }
            else {
                deg -= a[i];
                deg %= 360;
            }
        }

        if (deg == 0) {
            writeln("YES");
            return;
        }
    }

    writeln("NO");
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n];
		foreach (ref x; a)
		{
			readf (" %s", &x);
		}

		bool ok = false;
		foreach (s; 0..1 << n)
		{
			int cur = 0;
			foreach (i; 0..n)
			{
				if (s & (1 << i))
				{
					cur += a[i];
				}
				else
				{
					cur -= a[i];
				}
			}
			if (cur % 180 == 0)
			{
				ok = true;
			}
		}
		writeln (ok ? "YES" : "NO");
	}
}


One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.Lesha is tired now so he asked you to split the array. Help Lesha!

The first line contains single integer n (1 ≤ n ≤ 100) — the number of elements in the array A. The next line contains n integers a1, a2, ..., an ( - 103 ≤ ai ≤ 103) — the elements of the array A.

If it is not possible to split the array A and satisfy all the constraints, print single line containing "NO" (without quotes). Otherwise in the first line print "YES" (without quotes). In the next line print single integer k — the number of new arrays. In each of the next k lines print two integers li and ri which denote the subarray A[li... ri] of the initial array A being the i-th new array. Integers li, ri should satisfy the following conditions:   l1 = 1  rk = n  ri + 1 = li + 1 for each 1 ≤ i < k.  If there are multiple answers, print any of them.

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    if (A.map!(a => a == 0).all) {
        writeln("NO");
        return;
    }

    writeln("YES");

    if (A.sum == 0) {
        foreach (i; 0..N) if (A[i] != 0) {
            writeln(2);
            writeln(1, " ", i+1);
            writeln(i+2, " ", N);
            break;
        }
    } else {
        writeln(1);
        writeln(1, " ", N);
    }
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias mp=make_pair;
alias bins=binary_search;
alias orsq=orient_square;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	X binpow(X,Y)(X base,Y exp)
		if(is(typeof(exp&1)))
	{
		if(exp<0)return X(0);
		X res=X(1);
		while(exp>0)
		{
			if(exp&1)res*=base;
			base*=base;
			exp>>=1;
		}
		return res;
	}
	auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
		if(is(typeof(exp&1)))
	{
		if(mm==0) return binpow(base,exp);
		if(exp<0)return X(0);
		auto res=X(1)%mm;
		while(exp>0)
		{
			if(exp&1)res=(res*base)%mm;
			base*=base;
			base%=mm;
			exp>>=1;
		}
		return res;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
	{
		for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
		return nach;
	}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
	{
		size_t nach;
		for(;!range.empty;range.popFront()) nach+=fun(range.front);
		return nach;
	}
	T orient_square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		auto n=figure.front,t=figure.front;
		figure.popFront();
		T ans=0;
		for(;!figure.empty;figure.popFront())
		{
			ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
			t=figure.front;
		}
		return ans+(n.fi-t.fi)*(n.se+t.se);
	}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		return abs(orient_square(figure))/2.000000000000000;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const size_t n=size_t.max>>1;
	private T[size_t] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		size_t vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in size_t i,in T x)
	{
		upd(1,0,n,i,x);
	}
	private T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)
	{
		if(vl==l && r==vr) return t[v];
		size_t vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in size_t l,in size_t r){return cel(1,0,n,l,r);}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	loop:while(input(&n))
	{
		readln;
		auto a=arread!int;
		if(a.sum!=0)
		{
			writeln("YES");
			writeln(1);
			writeln(1,' ',n);
			continue loop;
		}
		else
		{
			foreach(i;1..n)
			{
				if(sum(a[0..i])!=0 && sum(a[i..n])!=0)
				{
					writeln("YES");
					writeln(2);
					writeln(1,' ',i);
					writeln(i+1,' ',n);
					continue loop;
				}
			}
		}
		writeln("NO");
	}
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
std.functional,std.math,std.numeric,std.string,std.range,std.complex,
std.typecons,std.regex,std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias orient_square orsq;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	X binpow(X,Y)(X base,Y exp)
		if(is(typeof(exp&1)))
		{
			if(exp<0)return X(0);
			X res=X(1);
			while(exp>0)
			{
				if(exp&1)res*=base;
				base*=base;
				exp>>=1;
			}
			return res;
		}
	auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
		if(is(typeof(exp&1)))
		{
			if(mm==0) return binpow(base,exp);
			if(exp<0)return X(0);
			auto res=X(1)%mm;
			while(exp>0)
			{
				if(exp&1)res=(res*base)%mm;
				base*=base;
				base%=mm;
				exp>>=1;
			}
			return res;
		}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (!(a[l]<g))?l:r;
		}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(g<a[m])r=m;
				else l=m;
			}
			return (g<a[l])?l:r;
		}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (g==a[l])?l:a.length;
		}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			return binf(a,g)!=a.length;
		}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
		{
			for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
			return nach;
		}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
		{
			size_t nach;
			for(;!range.empty;range.popFront()) nach+=fun(range.front);
			return nach;
		}
	T orient_square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
		{
			auto n=figure.front,t=figure.front;
			figure.popFront();
			T ans=0;
			for(;!figure.empty;figure.popFront())
			{
				ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
				t=figure.front;
			}
			return ans+(n.fi-t.fi)*(n.se+t.se);
		}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
		{
			return abs(orient_square(figure))/2.000000000000000;
		}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in int n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
		{
			int cmp=0-(fi<s_.fi)+(fi>s_.fi);
			if(cmp!=0)return cmp;
			else return (0-(se<s_.se)+(se>s_.se));
		}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const uint n=int.max;
	private T[uint] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in uint v,in uint vl,in uint vr,in uint i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		uint vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in uint i,in T x)
	{
		upd(1,0,n,i,x);
	}
	private T cel(in uint v,in uint vl,in uint vr,in uint l,in uint r)
	{
		if(vl==l && r==vr) return t[v];
		uint vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in uint l,in uint r){return cel(1,0,n,l,r);}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		readln;
		auto a=arread!int;
		if(a.sum!=0)
		{
			writeln("YES");
			writeln(1);
			writeln(1,' ',n);
			return;
		}
		else
		{
			foreach(i;1..n)
			{
				if(sum(a[0..i])!=0 && sum(a[i..n])!=0)
				{
					writeln("YES");
					writeln(2);
					writeln(1,' ',i);
					writeln(i+1,' ',n);
					return;
				}
			}
		}
		writeln("NO");
	}
	debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
std.functional,std.math,std.numeric,std.string,std.range,std.complex,
std.typecons,std.regex,std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias orient_square orsq;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	X binpow(X,Y)(X base,Y exp)
		if(is(typeof(exp&1)))
		{
			if(exp<0)return X(0);
			X res=X(1);
			while(exp>0)
			{
				if(exp&1)res*=base;
				base*=base;
				exp>>=1;
			}
			return res;
		}
	auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
		if(is(typeof(exp&1)))
		{
			if(mm==0) return binpow(base,exp);
			if(exp<0)return X(0);
			auto res=X(1)%mm;
			while(exp>0)
			{
				if(exp&1)res=(res*base)%mm;
				base*=base;
				base%=mm;
				exp>>=1;
			}
			return res;
		}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (!(a[l]<g))?l:r;
		}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(g<a[m])r=m;
				else l=m;
			}
			return (g<a[l])?l:r;
		}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (g==a[l])?l:a.length;
		}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			return binf(a,g)!=a.length;
		}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
		{
			for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
			return nach;
		}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
		{
			size_t nach;
			for(;!range.empty;range.popFront()) nach+=fun(range.front);
			return nach;
		}
	T orient_square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
		{
			auto n=figure.front,t=figure.front;
			figure.popFront();
			T ans=0;
			for(;!figure.empty;figure.popFront())
			{
				ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
				t=figure.front;
			}
			return ans+(n.fi-t.fi)*(n.se+t.se);
		}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
		{
			return abs(orient_square(figure))/2.000000000000000;
		}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in int n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
		{
			int cmp=0-(fi<s_.fi)+(fi>s_.fi);
			if(cmp!=0)return cmp;
			else return (0-(se<s_.se)+(se>s_.se));
		}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const uint n=int.max;
	private T[uint] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in uint v,in uint vl,in uint vr,in uint i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		uint vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in uint i,in T x)
	{
		upd(1,0,n,i,x);
	}
	private T cel(in uint v,in uint vl,in uint vr,in uint l,in uint r)
	{
		if(vl==l && r==vr) return t[v];
		uint vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in uint l,in uint r){return cel(1,0,n,l,r);}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		readln;
		auto a=arread!int;
		if(a.sum!=0)
		{
			writeln("YES");
			writeln(1);
			writeln(1,' ',n);
			return;
		}
		else
		{
			foreach(i;1..n-1)
			{
				if(sum(a[0..i])!=0 && sum(a[i..n])!=0)
				{
					writeln("YES");
					writeln(2);
					writeln(1,' ',i);
					writeln(i+1,' ',n);
					return;
				}
			}
		}
		writeln("NO");
	}
	debug system("pause");
}


Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw $$$n$$$ squares in the snow with a side length of $$$1$$$. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length $$$1$$$, parallel to the coordinate axes, with vertices at integer points.In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends $$$(x, y)$$$ and $$$(x, y+1)$$$. Then Sofia looks if there is already a drawn segment with the coordinates of the ends $$$(x', y)$$$ and $$$(x', y+1)$$$ for some $$$x'$$$. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates $$$x$$$, $$$x+1$$$ and the differing coordinate $$$y$$$.For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:   After that, she can draw the remaining two segments, using the first two as a guide:   If Sofia needs to draw two squares, she will have to draw three segments using a ruler:   After that, she can draw the remaining four segments, using the first three as a guide:   Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.

The only line of input contains a single integer $$$n$$$ ($$$1 \le n \le 10^{9}$$$), the number of squares that Sofia wants to draw.

Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw $$$n$$$ squares in the manner described above.

import std.algorithm;
import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.string;

void main() {
    long n = readln.strip.to!long;

    long l = 0, r = 200_000;
    while (r - l > 1) {
        long m = (l + r) / 2;
        if (m/2 * (m-m/2) >= n) {
            r = m;
        } else {
            l = m;
        }
    }

    writeln(r);
}


Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has a, b, c, a, b and c adjacent tiles, correspondingly.To better visualize the situation, look at the picture showing a similar hexagon for a = 2, b = 3 and c = 4.  According to the legend, as the King of Berland obtained the values a, b and c, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?

The first line contains three integers: a, b and c (2 ≤ a, b, c ≤ 1000).

Print a single number — the total number of tiles on the hall floor.

import std.stdio;

int main() {
    debug stdin = File("in.txt", "r");

    int a, b, c;
    readf(" %s %s %s\n", &a, &b, &c);
    int answer = 7;
    answer += (a - 2) * (2 + 2 - 1);
    answer += (b - 2) * (a + 2 - 1);
    answer += (c - 2) * (a + b - 1);
    writeln(answer);

    return 0;
}

module cf_216A;

import std.stdio;

void main() {
    int a, b, c;

    readf("%d %d %d", &a, &b, &c);

    int count = c * (a + b - 1) + (a - 1) * (b - 1);
    writeln(count);
}

module cf_216A;

import std.stdio;

void main() {
    int a, b, c;

    readf("%d %d %d", &a, &b, &c);
    writeln(2 * (a + b + c));
}


Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.    The picture illustrates the first and the second samples. Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!

The only line contains three integers n, m and k (1 ≤ n, m ≤ 10 000, 1 ≤ k ≤ 2nm) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.

Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.

NoteThe first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.file;

void main(string[] args)
{
    auto s = map!(to!int)(readln.strip.split);
    auto d = s[1] * 2;
    int n = 1;
    while(n <= s[0])
    {
        auto des = d * n;
        if (des >= s[2])
            break;
        n++;
    }

    auto p = (n -1) * s[1] * 2;
    if (s[2] % 2 == 0)
    {
        auto m = (s[2] - p) / 2;
        writeln(n, " ", m, " R");
    }
    else
    {
        auto m = ((s[2] + 1) - p) / 2;
        writeln(n, " ", m, " L");
    }

}


A new delivery of clothing has arrived today to the clothing store. This delivery consists of $$$a$$$ ties, $$$b$$$ scarves, $$$c$$$ vests and $$$d$$$ jackets.The store does not sell single clothing items — instead, it sells suits of two types:  a suit of the first type consists of one tie and one jacket;  a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs $$$e$$$ coins, and each suit of the second type costs $$$f$$$ coins.Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).

The first line contains one integer $$$a$$$ $$$(1 \le a \le 100\,000)$$$ — the number of ties. The second line contains one integer $$$b$$$ $$$(1 \le b \le 100\,000)$$$ — the number of scarves. The third line contains one integer $$$c$$$ $$$(1 \le c \le 100\,000)$$$ — the number of vests. The fourth line contains one integer $$$d$$$ $$$(1 \le d \le 100\,000)$$$ — the number of jackets. The fifth line contains one integer $$$e$$$ $$$(1 \le e \le 1\,000)$$$ — the cost of one suit of the first type. The sixth line contains one integer $$$f$$$ $$$(1 \le f \le 1\,000)$$$ — the cost of one suit of the second type.

Print one integer — the maximum total cost of some set of suits that can be composed from the delivered items.

NoteIt is possible to compose three suits of the second type in the first example, and their total cost will be $$$6$$$. Since all jackets will be used, it's impossible to add anything to this set.The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $$$9 \cdot 4 + 11 \cdot 6 = 102$$$.

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

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto a = RD!int;
	auto b = RD!int;
	auto c = RD!int;
	auto d = RD!int;
	auto e = RD!int;
	auto f = RD!int;
	long ans1, ans2;
	{
		auto aa = a;
		auto bb = b;
		auto cc = c;
		auto dd = d;
		auto ad = min(aa, dd);
		ans1 += ad * e;
		aa -= ad;
		dd -= ad;
		auto bcd = min(bb, cc, dd);
		ans1 += bcd * f;
	}
	{
		auto aa = a;
		auto bb = b;
		auto cc = c;
		auto dd = d;
		auto bcd = min(bb, cc, dd);
		ans2 += bcd * f;
		bb -= bcd;
		cc -= bcd;
		dd -= bcd;
		auto ad = min(aa, dd);
		ans2 += ad * e;
	}
	writeln(max(ans1, ans2));
	stdout.flush;
	debug readln;
}


You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.Initially the values of a and b are positive integers, and so the process will be finite.You have to determine the values of a and b after the process ends.

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.

Print two integers — the values of a and b after the end of the process.

NoteExplanations to the samples: a = 12, b = 5  a = 2, b = 5  a = 2, b = 1  a = 0, b = 1; a = 31, b = 12  a = 7, b = 12.

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.exception, std.random;

  long a, b; rd(a, b);
  // auto rnd=Random(unpredictableSeed);
  // long a=uniform(1, 100, rnd), b=uniform(1, 100, rnd);

  while(a>0 && b>0){
    if(a>=b*2){
      auto m=a/b;
      if(m&1) m--;
      enforce(m>=2);
      a-=b*m;
    }else if(a*2<=b){
      auto m=b/a;
      if(m&1) m--;
      enforce(m>=2);
      b-=a*m;
    }else{
      break;
    }
  }

  writeln(a, " ", b);
  // f(a, b);
}

void f(long a, long b){
  import std.stdio;
  while(a>0 && b>0){
    if(a>=b*2) a-=b*2;
    else if(a*2<=b) b-=a*2;
    else break;
  }
  writeln(a, " ", b);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}


Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.

The first line of input will be a single string s (1 ≤ |s| ≤ 50), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z').

Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.

NoteFor the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias mp=make_pair;
alias bins=binary_search;
alias orsq=orient_square;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	X binpow(X,Y)(X base,Y exp)
		if(is(typeof(exp&1)))
	{
		if(exp<0)return X(0);
		X res=X(1);
		while(exp>0)
		{
			if(exp&1)res*=base;
			base*=base;
			exp>>=1;
		}
		return res;
	}
	auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
		if(is(typeof(exp&1)))
	{
		if(mm==0) return binpow(base,exp);
		if(exp<0)return X(0);
		auto res=X(1)%mm;
		while(exp>0)
		{
			if(exp&1)res=(res*base)%mm;
			base*=base;
			base%=mm;
			exp>>=1;
		}
		return res;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
	{
		for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
		return nach;
	}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
	{
		size_t nach;
		for(;!range.empty;range.popFront()) nach+=fun(range.front);
		return nach;
	}
	T orient_square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		auto n=figure.front,t=figure.front;
		figure.popFront();
		T ans=0;
		for(;!figure.empty;figure.popFront())
		{
			ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
			t=figure.front;
		}
		return ans+(n.fi-t.fi)*(n.se+t.se);
	}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		return abs(orient_square(figure))/2.000000000000000;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const size_t n=size_t.max>>1;
	private T[size_t] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		size_t vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in size_t i,in T x)
	{
		upd(1,0,n,i,x);
	}
	private T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)
	{
		if(vl==l && r==vr) return t[v];
		size_t vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in size_t l,in size_t r){return cel(1,0,n,l,r);}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	string n;
	loop:while((n=readln.strip)!="")
	{
		int[string] q;
		foreach(i;0..n.length+1)
		{
			q[n]++;
			n=n[$-1]~n[0..$-1];
		}
		writeln(q.length);
	}
}


Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.Write a program that will print the name of a man who will drink the n-th can.Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.

The input data consist of a single integer n (1 ≤ n ≤ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.

Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.

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

/// solve ==========================
string solve(int n){

  string[] persons = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
  int times;
  int start;
  string res;
  int personNum;

  auto xs = recurrence!("(a[n-1] + (a[n-1] - a[n-2])*2)")(1, 6);
  foreach(x; xs){
    if(x > n) break;
    start = x;
    times += 1;
  }
  personNum = (n - start) / (2^^(times-1));
  res = persons[personNum].to!string;
  return res;
}

/// main ====================
void main(){
  auto n = readln.strip.to!int;
  solve(n).writeln;
}

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

string solve(int n){

  string[] names = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
  int times;
  int start;
  string res;
  int modN;

  /// solve ==========================
  auto xs = recurrence!("(a[n-1] + (a[n-1] - a[n-2])*2)")(1, 6);
  foreach(x; xs){
    if(x > n) break;
    start = x;
    times += 1;
  }
  modN = (n - start) / (2^^(times-1));
  res = names[modN].to!string;
  return res;
}

/// unittest -------------------
unittest{
  assert( solve(1) == "S" );
  assert( solve(6) == "S" );
  assert( solve(1802) == "P" );
  writeln("---pass ---");
}

/// main ====================
void main(){
  auto n = readln.strip.to!int;
  solve(n).writeln;
}

import std.stdio;
import std.conv : to;

immutable names = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];

void main()
{
    ulong num;
    readf("%s", &num);

    ulong groupSize = 5;

    while(true)
    {
        if (num <= groupSize)
        {
            names[cast(uint)((num-1)/(groupSize/5))].writeln;
            break;
        }

        num -= groupSize;
        groupSize *= 2;
    }
}

import std.stdio;
import std.string;
import std.conv;

void main()
{
  auto n = stdin.readln.strip.to!int;
  int m=0, j=0;
  for(int i=1; i<=n; i+=5*(2^^j),j++) m=i;
  write(["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"][(n-m)/(2^^(--j))]);
}

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n); n--;
	long pm = 0;
	long m = 1;
	while ((pm + m * 5) <= n)
	{
		pm += m * 5;
		m = m * 2;
	}

	long l = (n - pm) / m;

	string[long] names;
	names[0] = "Sheldon";
	names[1] = "Leonard";
	names[2] = "Penny";
	names[3] = "Rajesh";
	names[4] = "Howard";
	write(names[l]);
	return 0;
}

import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.range;
import std.algorithm;
import std.container;
import std.math;

void main() {
    string[] p = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
    int n = readln.chomp.to!int;
    n--;
    while (n >= 5) {
        n -= 5;
        n /= 2;
    }
    writeln(p[n]);
}

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

string solve(int n){

  string names = "SLPRH";
  int times;
  int start;
  string res;
  int modN;

  /// solve ==========================
  auto xs = recurrence!("(a[n-1] + (a[n-1] - a[n-2])*2)")(1, 6);
  foreach(x; xs){
    if(x > n) break;
    start = x;
    times += 1;
  }
  modN = (n - start) / (2^^(times-1));
  res = names[modN].to!string;
  return res;
}

/// unittest -------------------
unittest{
  assert( solve(1) == "S" );
  assert( solve(6) == "S" );
  assert( solve(1802) == "P" );
  writeln("---pass ---");
}

/// main ====================
void main(){
  foreach(i; 1..25){
    writeln(i, " ", solve(i));
  }
}

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n); n--;
	long pm = 0;
	long m = 1;
	while (pm + m * 5 <= n)
	{
		pm = pm + m * 5;
		m++;
	}
	double l = cast(double)(n - pm) / cast(double)(m);

	string[long] names;
	names[0] = "Sheldon";
	names[1] = "Leonard";
	names[2] = "Penny";
	names[3] = "Rajesh";
	names[4] = "Howard";
	write(names[cast(long)round(l)]);
	return 0;
}